Merge pull request #2538 from marcosgdf/units

NEW [ task 977 ] New option to manage product unit Migrated code from GPCSolutions/dolibarr:3.2-units branch and adapted for 3.8 with some improvements
This commit is contained in:
Laurent Destailleur 2015-04-21 11:14:50 +02:00
commit 9d1c609c4f
55 changed files with 1112 additions and 131 deletions

View File

@ -70,7 +70,7 @@ $hookmanager->initHooks(array('admin'));
// Put here declaration of dictionaries properties
// Sort order to show dictionary (0 is space). All other dictionaries (added by modules) will be at end of this.
$taborder=array(9,0,4,3,2,0,1,8,19,16,0,5,11,0,6,0,10,23,12,13,0,14,0,7,17,0,22,20,18,21,0,15,0,24,0,25);
$taborder=array(9,0,4,3,2,0,1,8,19,16,0,5,11,0,6,0,10,23,12,13,0,14,0,7,17,0,22,20,18,21,0,15,0,24,0,25,0,26);
// Name of SQL tables of dictionaries
$tabname=array();
@ -99,6 +99,7 @@ $tabname[22]= MAIN_DB_PREFIX."c_input_reason";
$tabname[23]= MAIN_DB_PREFIX."c_revenuestamp";
$tabname[24]= MAIN_DB_PREFIX."c_type_resource";
$tabname[25]= MAIN_DB_PREFIX."c_email_templates";
$tabname[26]= MAIN_DB_PREFIX."c_units";
// Dictionary labels
$tablib=array();
@ -127,6 +128,7 @@ $tablib[22]= "DictionarySource";
$tablib[23]= "DictionaryRevenueStamp";
$tablib[24]= "DictionaryResourceType";
$tablib[25]= "DictionaryEMailTemplates";
$tablib[26]= "DictionnaryUnits";
// Requests to extract data
$tabsql=array();
@ -155,6 +157,7 @@ $tabsql[22]= "SELECT rowid as rowid, code, label, active FROM ".MAIN_DB_PREFIX
$tabsql[23]= "SELECT t.rowid, t.taux, c.label as country, c.code as country_code, t.fk_pays as country_id, t.note, t.active, t.accountancy_code_sell, t.accountancy_code_buy FROM ".MAIN_DB_PREFIX."c_revenuestamp as t, ".MAIN_DB_PREFIX."c_country as c WHERE t.fk_pays=c.rowid";
$tabsql[24]= "SELECT rowid as rowid, code, label, active FROM ".MAIN_DB_PREFIX."c_type_resource";
$tabsql[25]= "SELECT rowid as rowid, label, type_template, private, position, topic, content, active FROM ".MAIN_DB_PREFIX."c_email_templates";
$tabsql[26]= "SELECT rowid as rowid, code, label, short_label, active FROM ".MAIN_DB_PREFIX."c_units";
// Criteria to sort dictionaries
$tabsqlsort=array();
@ -183,6 +186,7 @@ $tabsqlsort[22]="code ASC, label ASC";
$tabsqlsort[23]="country ASC, taux ASC";
$tabsqlsort[24]="code ASC,label ASC";
$tabsqlsort[25]="label ASC";
$tabsqlsort[26]="code ASC";
// Nom des champs en resultat de select pour affichage du dictionnaire
$tabfield=array();
@ -211,6 +215,7 @@ $tabfield[22]= "code,label";
$tabfield[23]= "country_id,country,taux,accountancy_code_sell,accountancy_code_buy,note";
$tabfield[24]= "code,label";
$tabfield[25]= "label,type_template,private,position,topic,content";
$tabfield[26]= "code,label,short_label";
// Nom des champs d'edition pour modification d'un enregistrement
$tabfieldvalue=array();
@ -239,6 +244,7 @@ $tabfieldvalue[22]= "code,label";
$tabfieldvalue[23]= "country,taux,accountancy_code_sell,accountancy_code_buy,note";
$tabfieldvalue[24]= "code,label";
$tabfieldvalue[25]= "label,type_template,private,position,topic,content";
$tabfieldvalue[26]= "code,label,short_label";
// Nom des champs dans la table pour insertion d'un enregistrement
$tabfieldinsert=array();
@ -267,6 +273,7 @@ $tabfieldinsert[22]= "code,label";
$tabfieldinsert[23]= "fk_pays,taux,accountancy_code_sell,accountancy_code_buy,note";
$tabfieldinsert[24]= "code,label";
$tabfieldinsert[25]= "label,type_template,private,position,topic,content";
$tabfieldinsert[26]= "code,label,short_label";
// Nom du rowid si le champ n'est pas de type autoincrement
// Example: "" if id field is "rowid" and has autoincrement on
@ -297,6 +304,7 @@ $tabrowid[22]= "rowid";
$tabrowid[23]= "";
$tabrowid[24]= "";
$tabrowid[25]= "";
$tabrowid[26]= "";
// Condition to show dictionary in setup page
$tabcond=array();
@ -325,6 +333,7 @@ $tabcond[22]= (! empty($conf->commande->enabled) || ! empty($conf->propal->enabl
$tabcond[23]= true;
$tabcond[24]= ! empty($conf->resource->enabled);
$tabcond[25]= true; // && ! empty($conf->global->MAIN_EMAIL_EDIT_TEMPLATE_FROM_DIC);
$tabcond[26]= $conf->product->enabled;
// List of help for fields
$tabhelp=array();
@ -858,6 +867,7 @@ if ($id)
if ($fieldlist[$field]=='pcg_type') { $valuetoshow=$langs->trans("Pcg_type"); }
if ($fieldlist[$field]=='pcg_subtype') { $valuetoshow=$langs->trans("Pcg_subtype"); }
if ($fieldlist[$field]=='sortorder') { $valuetoshow=$langs->trans("SortOrder"); }
if ($fieldlist[$field]=='short_label') { $valuetoshow=$langs->trans("ShortLabel"); }
if ($id == 2) // Special cas for state page
{
@ -995,6 +1005,7 @@ if ($id)
if ($fieldlist[$field]=='pcg_type') { $valuetoshow=$langs->trans("Pcg_type"); }
if ($fieldlist[$field]=='pcg_subtype') { $valuetoshow=$langs->trans("Pcg_subtype"); }
if ($fieldlist[$field]=='sortorder') { $valuetoshow=$langs->trans("SortOrder"); }
if ($fieldlist[$field]=='short_label') { $valuetoshow=$langs->trans("ShortLabel"); }
// Affiche nom du champ
if ($showfield)
@ -1159,7 +1170,14 @@ if ($id)
else if ($fieldlist[$field]=='unicode') {
$valuetoshow = $langs->getCurrencySymbol($obj->code,1);
}
else if ($fieldlist[$field]=='label' && $tabname[$_GET["id"]]==MAIN_DB_PREFIX.'c_units') {
$langs->load("products");
$valuetoshow=$langs->trans($obj->$fieldlist[$field]);
}
else if ($fieldlist[$field]=='short_label' && $tabname[$_GET["id"]]==MAIN_DB_PREFIX.'c_units') {
$langs->load("products");
$valuetoshow = $langs->trans($obj->$fieldlist[$field]);
}
else if (($fieldlist[$field] == 'unit') && ($tabname[$id] == MAIN_DB_PREFIX.'c_paper_format'))
{
$key = $langs->trans('SizeUnit'.strtolower($obj->unit));

View File

@ -8,6 +8,7 @@
* Copyright (C) 2010-2014 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2010-2011 Philippe Grand <philippe.grand@atoo-net.com>
* Copyright (C) 2012-2013 Christophe Battarel <christophe.battarel@altairis.fr>
* Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2014 Ferran Marcet <fmarcet@2byte.es>
*
@ -451,7 +452,7 @@ if (empty($reshook))
$tva_tx=get_default_tva($mysoc, $object->thirdparty);
$result = $object->addline($desc, $lines[$i]->subprice, $lines[$i]->qty, $tva_tx, $lines[$i]->localtax1_tx, $lines[$i]->localtax2_tx, $lines[$i]->fk_product, $lines[$i]->remise_percent, 'HT', 0, $lines[$i]->info_bits, $product_type, $lines[$i]->rang, $lines[$i]->special_code, $fk_parent_line, $lines[$i]->fk_fournprice, $lines[$i]->pa_ht, $label, $date_start, $date_end, $array_options);
$result = $object->addline($desc, $lines[$i]->subprice, $lines[$i]->qty, $tva_tx, $lines[$i]->localtax1_tx, $lines[$i]->localtax2_tx, $lines[$i]->fk_product, $lines[$i]->remise_percent, 'HT', 0, $lines[$i]->info_bits, $product_type, $lines[$i]->rang, $lines[$i]->special_code, $fk_parent_line, $lines[$i]->fk_fournprice, $lines[$i]->pa_ht, $label, $date_start, $date_end, $array_options, $lines[$i]->fk_unit);
if ($result > 0) {
$lineid = $result;
@ -726,6 +727,7 @@ if (empty($reshook))
// Ecrase $pu par celui du produit
// Ecrase $desc par celui du produit
// Ecrase $txtva par celui du produit
// Replaces $fk_unit with the product unit
if (! empty($idprod)) {
$prod = new Product($db);
$prod->fetch($idprod);
@ -834,6 +836,7 @@ if (empty($reshook))
}
$type = $prod->type;
$fk_unit = $prod->fk_unit;
} else {
$pu_ht = price2num($price_ht, 'MU');
$pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
@ -842,6 +845,12 @@ if (empty($reshook))
$label = (GETPOST('product_label') ? GETPOST('product_label') : '');
$desc = $product_desc;
$type = GETPOST('type');
$fk_unit = GETPOST('units', 'int');
if ($fk_unit <= 0) {
$fk_unit = null;
}
}
// Margin
@ -864,7 +873,7 @@ if (empty($reshook))
setEventMessage($mesg, 'errors');
} else {
// Insert line
$result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $price_base_type, $pu_ttc, $info_bits, $type, - 1, 0, GETPOST('fk_parent_line'), $fournprice, $buyingprice, $label, $date_start, $date_end, $array_options);
$result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $price_base_type, $pu_ttc, $info_bits, $type, - 1, 0, GETPOST('fk_parent_line'), $fournprice, $buyingprice, $label, $date_start, $date_end, $array_options, $fk_unit);
if ($result > 0) {
$db->commit();
@ -898,6 +907,7 @@ if (empty($reshook))
unset($_POST['np_markRate']);
unset($_POST['dp_desc']);
unset($_POST['idprod']);
unset($_POST['units']);
unset($_POST['date_starthour']);
unset($_POST['date_startmin']);
@ -992,7 +1002,7 @@ if (empty($reshook))
if (! $error) {
$db->begin();
$result = $object->updateline(GETPOST('lineid'), $pu_ht, GETPOST('qty'), GETPOST('remise_percent'), $vat_rate, $localtax1_rate, $localtax2_rate, $description, 'HT', $info_bits, $special_code, GETPOST('fk_parent_line'), 0, $fournprice, $buyingprice, $label, $type, $date_start, $date_end, $array_options);
$result = $object->updateline(GETPOST('lineid'), $pu_ht, GETPOST('qty'), GETPOST('remise_percent'), $vat_rate, $localtax1_rate, $localtax2_rate, $description, 'HT', $info_bits, $special_code, GETPOST('fk_parent_line'), 0, $fournprice, $buyingprice, $label, $type, $date_start, $date_end, $array_options, $_POST["units"]);
if ($result >= 0) {
$db->commit();

View File

@ -9,6 +9,7 @@
* Copyright (C) 2010-2014 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2010-2011 Philippe Grand <philippe.grand@atoo-net.com>
* Copyright (C) 2012-2014 Christophe Battarel <christophe.battarel@altairis.fr>
* Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2014-2015 Marcos García <marcosgdf@gmail.com>
*
@ -32,6 +33,7 @@
*/
require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php';
require_once DOL_DOCUMENT_ROOT ."/core/class/commonobjectline.class.php";
require_once DOL_DOCUMENT_ROOT .'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT .'/contact/class/contact.class.php';
require_once DOL_DOCUMENT_ROOT .'/margin/lib/margins.lib.php';
@ -284,6 +286,7 @@ class Propal extends CommonObject
$line->subprice=$price;
$line->remise_percent=$remise_percent;
$line->tva_tx=$tva_tx;
$line->fk_unit=$prod->fk_unit;
$this->lines[]=$line;
}
@ -396,11 +399,12 @@ class Propal extends CommonObject
* @param int $date_start Start date of the line
* @param int $date_end End date of the line
* @param array $array_options extrafields array
* @param int $fk_unit Id of the unit to use. Null to use the default one
* @return int >0 if OK, <0 if KO
*
* @see add_product
*/
function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0.0, $txlocaltax2=0.0, $fk_product=0, $remise_percent=0.0, $price_base_type='HT', $pu_ttc=0.0, $info_bits=0, $type=0, $rang=-1, $special_code=0, $fk_parent_line=0, $fk_fournprice=0, $pa_ht=0, $label='',$date_start='', $date_end='',$array_options=0)
function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0.0, $txlocaltax2=0.0, $fk_product=0, $remise_percent=0.0, $price_base_type='HT', $pu_ttc=0.0, $info_bits=0, $type=0, $rang=-1, $special_code=0, $fk_parent_line=0, $fk_fournprice=0, $pa_ht=0, $label='',$date_start='', $date_end='',$array_options=0, $fk_unit = null)
{
global $mysoc;
@ -497,6 +501,7 @@ class Propal extends CommonObject
$this->line->product_type=$type;
$this->line->special_code=$special_code;
$this->line->fk_parent_line=$fk_parent_line;
$this->line->fk_unit=$fk_unit;
$this->line->date_start=$date_start;
$this->line->date_end=$date_end;
@ -578,9 +583,10 @@ class Propal extends CommonObject
* @param int $date_start Start date of the line
* @param int $date_end End date of the line
* @param array $array_options extrafields array
* @param int $fk_unit Id of the unit to use. Null to use the default one
* @return int 0 if OK, <0 if KO
*/
function updateline($rowid, $pu, $qty, $remise_percent, $txtva, $txlocaltax1=0.0, $txlocaltax2=0.0, $desc='', $price_base_type='HT', $info_bits=0, $special_code=0, $fk_parent_line=0, $skip_update_total=0, $fk_fournprice=0, $pa_ht=0, $label='', $type=0, $date_start='', $date_end='', $array_options=0)
function updateline($rowid, $pu, $qty, $remise_percent, $txtva, $txlocaltax1=0.0, $txlocaltax2=0.0, $desc='', $price_base_type='HT', $info_bits=0, $special_code=0, $fk_parent_line=0, $skip_update_total=0, $fk_fournprice=0, $pa_ht=0, $label='', $type=0, $date_start='', $date_end='', $array_options=0, $fk_unit = null)
{
global $mysoc;
@ -662,6 +668,7 @@ class Propal extends CommonObject
$this->line->special_code = $special_code;
$this->line->fk_parent_line = $fk_parent_line;
$this->line->skip_update_total = $skip_update_total;
$this->line->fk_unit = $fk_unit;
// infos marge
if (!empty($fk_product) && empty($fk_fournprice) && empty($pa_ht)) {
@ -914,7 +921,8 @@ class Propal extends CommonObject
$this->lines[$i]->label,
$this->lines[$i]->date_start,
$this->lines[$i]->date_end,
$this->lines[$i]->array_options
$this->lines[$i]->array_options,
$this->lines[$i]->fk_unit
);
if ($result < 0)
@ -1286,6 +1294,7 @@ class Propal extends CommonObject
*/
$sql = "SELECT d.rowid, d.fk_propal, d.fk_parent_line, d.label as custom_label, d.description, d.price, d.tva_tx, d.localtax1_tx, d.localtax2_tx, d.qty, d.fk_remise_except, d.remise_percent, d.subprice, d.fk_product,";
$sql.= " d.info_bits, d.total_ht, d.total_tva, d.total_localtax1, d.total_localtax2, d.total_ttc, d.fk_product_fournisseur_price as fk_fournprice, d.buy_price_ht as pa_ht, d.special_code, d.rang, d.product_type,";
$sql.= " d.fk_unit,";
$sql.= ' p.ref as product_ref, p.description as product_desc, p.fk_product_type, p.label as product_label,';
$sql.= ' d.date_start, d.date_end';
$sql.= " FROM ".MAIN_DB_PREFIX."propaldet as d";
@ -1348,6 +1357,7 @@ class Propal extends CommonObject
$line->product_label = $objp->product_label;
$line->product_desc = $objp->product_desc; // Description produit
$line->fk_product_type = $objp->fk_product_type;
$line->fk_unit = $objp->fk_unit;
$line->date_start = $objp->date_start;
$line->date_end = $objp->date_end;
@ -2770,6 +2780,7 @@ class Propal extends CommonObject
$sql.= ' pt.qty, pt.tva_tx, pt.remise_percent, pt.subprice, pt.info_bits,';
$sql.= ' pt.total_ht, pt.total_tva, pt.total_ttc, pt.fk_product_fournisseur_price as fk_fournprice, pt.buy_price_ht as pa_ht, pt.special_code, pt.localtax1_tx, pt.localtax2_tx,';
$sql.= ' pt.date_start, pt.date_end, pt.product_type, pt.rang, pt.fk_parent_line,';
$sql.= ' pt.fk_unit,';
$sql.= ' p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid,';
$sql.= ' p.description as product_desc,';
$sql.= ' p.entity';
@ -2820,6 +2831,7 @@ class Propal extends CommonObject
$this->lines[$i]->rang = $obj->rang;
$this->lines[$i]->date_start = $this->db->jdate($obj->date_start);
$this->lines[$i]->date_end = $this->db->jdate($obj->date_end);
$this->lines[$i]->fk_unit = $obj->fk_unit;
$i++;
}
@ -2891,7 +2903,7 @@ class Propal extends CommonObject
* \class PropaleLigne
* \brief Class to manage commercial proposal lines
*/
class PropaleLigne extends CommonObject
class PropaleLigne extends CommonObjectLine
{
public $element='propaldet';
public $table_element='propaldet';
@ -2981,6 +2993,7 @@ class PropaleLigne extends CommonObject
$sql = 'SELECT pd.rowid, pd.fk_propal, pd.fk_parent_line, pd.fk_product, pd.label as custom_label, pd.description, pd.price, pd.qty, pd.tva_tx,';
$sql.= ' pd.remise, pd.remise_percent, pd.fk_remise_except, pd.subprice,';
$sql.= ' pd.info_bits, pd.total_ht, pd.total_tva, pd.total_ttc, pd.fk_product_fournisseur_price as fk_fournprice, pd.buy_price_ht as pa_ht, pd.special_code, pd.rang,';
$sql.= ' pd.fk_unit,';
$sql.= ' pd.localtax1_tx, pd.localtax2_tx, pd.total_localtax1, pd.total_localtax2,';
$sql.= ' p.ref as product_ref, p.label as product_label, p.description as product_desc,';
$sql.= ' pd.date_start, pd.date_end, pd.product_type';
@ -3028,6 +3041,7 @@ class PropaleLigne extends CommonObject
$this->libelle = $objp->product_label; // deprecated
$this->product_label = $objp->product_label;
$this->product_desc = $objp->product_desc;
$this->fk_unit = $objp->fk_unit;
$this->date_start = $this->db->jdate($objp->date_start);
$this->date_end = $this->db->jdate($objp->date_end);
@ -3090,6 +3104,7 @@ class PropaleLigne extends CommonObject
$sql.= ' subprice, remise_percent, ';
$sql.= ' info_bits, ';
$sql.= ' total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, fk_product_fournisseur_price, buy_price_ht, special_code, rang,';
$sql.= ' fk_unit,';
$sql.= ' date_start, date_end)';
$sql.= " VALUES (".$this->fk_propal.",";
$sql.= " ".($this->fk_parent_line>0?"'".$this->fk_parent_line."'":"null").",";
@ -3116,6 +3131,7 @@ class PropaleLigne extends CommonObject
$sql.= " ".(isset($this->pa_ht)?"'".price2num($this->pa_ht)."'":"null").",";
$sql.= ' '.$this->special_code.',';
$sql.= ' '.$this->rang.',';
$sql.= ' '.(!$this->fk_unit ? 'NULL' : $this->fk_unit).',';
$sql.= " ".(! empty($this->date_start)?"'".$this->db->idate($this->date_start)."'":"null").',';
$sql.= " ".(! empty($this->date_end)?"'".$this->db->idate($this->date_end)."'":"null");
$sql.= ')';
@ -3281,6 +3297,7 @@ class PropaleLigne extends CommonObject
if (! empty($this->rang)) $sql.= ", rang=".$this->rang;
$sql.= " , date_start=".(! empty($this->date_start)?"'".$this->db->idate($this->date_start)."'":"null");
$sql.= " , date_end=".(! empty($this->date_end)?"'".$this->db->idate($this->date_end)."'":"null");
$sql.= " , fk_unit=".(!$this->fk_unit ? 'NULL' : $this->fk_unit);
$sql.= " WHERE rowid = ".$this->rowid;
dol_syslog(get_class($this)."::update", LOG_DEBUG);

View File

@ -8,6 +8,7 @@
* Copyright (C) 2011 Philippe Grand <philippe.grand@atoo-net.com>
* Copyright (C) 2012-2013 Christophe Battarel <christophe.battarel@altairis.fr>
* Copyright (C) 2012 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2014 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
@ -348,7 +349,7 @@ if (empty($reshook))
$array_options = $lines[$i]->array_options;
}
$result = $object->addline($desc, $lines[$i]->subprice, $lines[$i]->qty, $lines[$i]->tva_tx, $lines[$i]->localtax1_tx, $lines[$i]->localtax2_tx, $lines[$i]->fk_product, $lines[$i]->remise_percent, $lines[$i]->info_bits, $lines[$i]->fk_remise_except, 'HT', 0, $date_start, $date_end, $product_type, $lines[$i]->rang, $lines[$i]->special_code, $fk_parent_line, $lines[$i]->fk_fournprice, $lines[$i]->pa_ht, $label, $array_options);
$result = $object->addline($desc, $lines[$i]->subprice, $lines[$i]->qty, $lines[$i]->tva_tx, $lines[$i]->localtax1_tx, $lines[$i]->localtax2_tx, $lines[$i]->fk_product, $lines[$i]->remise_percent, $lines[$i]->info_bits, $lines[$i]->fk_remise_except, 'HT', 0, $date_start, $date_end, $product_type, $lines[$i]->rang, $lines[$i]->special_code, $fk_parent_line, $lines[$i]->fk_fournprice, $lines[$i]->pa_ht, $label, $array_options, $lines[$i]->fk_unit);
if ($result < 0) {
$error++;
@ -713,6 +714,7 @@ if (empty($reshook))
}
$type = $prod->type;
$fk_unit = $prod->fk_unit;
} else {
$pu_ht = price2num($price_ht, 'MU');
$pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
@ -721,6 +723,11 @@ if (empty($reshook))
$label = (GETPOST('product_label') ? GETPOST('product_label') : '');
$desc = $product_desc;
$type = GETPOST('type');
$fk_unit=GETPOST('units', 'int');
if ($fk_unit <= 0) {
$fk_unit = null;
}
}
// Margin
@ -742,7 +749,7 @@ if (empty($reshook))
setEventMessage($mesg, 'errors');
} else {
// Insert line
$result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $info_bits, 0, $price_base_type, $pu_ttc, $date_start, $date_end, $type, - 1, 0, GETPOST('fk_parent_line'), $fournprice, $buyingprice, $label, $array_options);
$result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $info_bits, 0, $price_base_type, $pu_ttc, $date_start, $date_end, $type, - 1, 0, GETPOST('fk_parent_line'), $fournprice, $buyingprice, $label, $array_options, $fk_unit);
if ($result > 0) {
$ret = $object->fetch($object->id); // Reload to get new records
@ -778,6 +785,7 @@ if (empty($reshook))
unset($_POST['np_markRate']);
unset($_POST['dp_desc']);
unset($_POST['idprod']);
unset($_POST['units']);
unset($_POST['date_starthour']);
unset($_POST['date_startmin']);
@ -867,7 +875,7 @@ if (empty($reshook))
}
if (! $error) {
$result = $object->updateline(GETPOST('lineid'), $description, $pu_ht, GETPOST('qty'), GETPOST('remise_percent'), $vat_rate, $localtax1_rate, $localtax2_rate, 'HT', $info_bits, $date_start, $date_end, $type, GETPOST('fk_parent_line'), 0, $fournprice, $buyingprice, $label, 0, $array_options);
$result = $object->updateline(GETPOST('lineid'), $description, $pu_ht, GETPOST('qty'), GETPOST('remise_percent'), $vat_rate, $localtax1_rate, $localtax2_rate, 'HT', $info_bits, $date_start, $date_end, $type, GETPOST('fk_parent_line'), 0, $fournprice, $buyingprice, $label, 0, $array_options, GETPOST('units'));
if ($result >= 0) {
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {

View File

@ -6,6 +6,7 @@
* Copyright (C) 2010-2015 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2011 Jean Heimburger <jean@tiaris.info>
* Copyright (C) 2012-2014 Christophe Battarel <christophe.battarel@altairis.fr>
* Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2014-2015 Marcos García <marcosgdf@gmail.com>
*
@ -29,6 +30,7 @@
* \brief Fichier des classes de commandes
*/
include_once DOL_DOCUMENT_ROOT.'/core/class/commonorder.class.php';
require_once DOL_DOCUMENT_ROOT ."/core/class/commonobjectline.class.php";
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT .'/margin/lib/margins.lib.php';
@ -802,7 +804,8 @@ class Commande extends CommonOrder
$this->lines[$i]->fk_fournprice,
$this->lines[$i]->pa_ht,
$this->lines[$i]->label,
$this->lines[$i]->array_options
$this->lines[$i]->array_options,
$this->lines[$i]->fk_unit
);
if ($result < 0)
{
@ -1062,6 +1065,7 @@ class Commande extends CommonOrder
$line->rang = $object->lines[$i]->rang;
$line->special_code = $object->lines[$i]->special_code;
$line->fk_parent_line = $object->lines[$i]->fk_parent_line;
$line->fk_unit = $object->lines[$i]->fk_unit;
$line->date_start = $object->lines[$i]->date_start;
$line->date_end = $object->lines[$i]->date_end;
@ -1165,6 +1169,7 @@ class Commande extends CommonOrder
* @param int $pa_ht Buying price (without tax)
* @param string $label Label
* @param array $array_options extrafields array
* @param int $fk_unit Id of the unit to use. Null to use the default one
* @return int >0 if OK, <0 if KO
*
* @see add_product
@ -1174,11 +1179,11 @@ class Commande extends CommonOrder
* par l'appelant par la methode get_default_tva(societe_vendeuse,societe_acheteuse,produit)
* et le desc doit deja avoir la bonne valeur (a l'appelant de gerer le multilangue)
*/
function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $info_bits=0, $fk_remise_except=0, $price_base_type='HT', $pu_ttc=0, $date_start='', $date_end='', $type=0, $rang=-1, $special_code=0, $fk_parent_line=0, $fk_fournprice=null, $pa_ht=0, $label='',$array_options=0)
function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $info_bits=0, $fk_remise_except=0, $price_base_type='HT', $pu_ttc=0, $date_start='', $date_end='', $type=0, $rang=-1, $special_code=0, $fk_parent_line=0, $fk_fournprice=null, $pa_ht=0, $label='',$array_options=0, $fk_unit = null)
{
global $mysoc, $conf, $langs;
dol_syslog(get_class($this)."::addline commandeid=$this->id, desc=$desc, pu_ht=$pu_ht, qty=$qty, txtva=$txtva, fk_product=$fk_product, remise_percent=$remise_percent, info_bits=$info_bits, fk_remise_except=$fk_remise_except, price_base_type=$price_base_type, pu_ttc=$pu_ttc, date_start=$date_start, date_end=$date_end, type=$type", LOG_DEBUG);
dol_syslog(get_class($this)."::addline commandeid=$this->id, desc=$desc, pu_ht=$pu_ht, qty=$qty, txtva=$txtva, fk_product=$fk_product, remise_percent=$remise_percent, info_bits=$info_bits, fk_remise_except=$fk_remise_except, price_base_type=$price_base_type, pu_ttc=$pu_ttc, date_start=$date_start, date_end=$date_end, type=$type, fk_unit=$fk_unit", LOG_DEBUG);
include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
@ -1295,6 +1300,7 @@ class Commande extends CommonOrder
$this->line->product_type=$type;
$this->line->special_code=$special_code;
$this->line->fk_parent_line=$fk_parent_line;
$this->line->fk_unit=$fk_unit;
$this->line->date_start=$date_start;
$this->line->date_end=$date_end;
@ -1398,6 +1404,7 @@ class Commande extends CommonOrder
$line->ref=$prod->ref;
$line->libelle=$prod->libelle;
$line->product_desc=$prod->description;
$line->fk_unit=$prod->fk_unit;
// Added by Matelli (See http://matelli.fr/showcases/patchs-dolibarr/add-dates-in-order-lines.html)
// Save the start and end date of the line in the object
@ -1654,6 +1661,7 @@ class Commande extends CommonOrder
$sql = 'SELECT l.rowid, l.fk_product, l.fk_parent_line, l.product_type, l.fk_commande, l.label as custom_label, l.description, l.price, l.qty, l.tva_tx,';
$sql.= ' l.localtax1_tx, l.localtax2_tx, l.fk_remise_except, l.remise_percent, l.subprice, l.fk_product_fournisseur_price as fk_fournprice, l.buy_price_ht as pa_ht, l.rang, l.info_bits, l.special_code,';
$sql.= ' l.total_ht, l.total_ttc, l.total_tva, l.total_localtax1, l.total_localtax2, l.date_start, l.date_end,';
$sql.= ' l.fk_unit,';
$sql.= ' p.ref as product_ref, p.description as product_desc, p.fk_product_type, p.label as product_label';
$sql.= ' FROM '.MAIN_DB_PREFIX.'commandedet as l';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON (p.rowid = l.fk_product)';
@ -1711,6 +1719,7 @@ class Commande extends CommonOrder
$line->product_label = $objp->product_label;
$line->product_desc = $objp->product_desc;
$line->fk_product_type = $objp->fk_product_type; // Produit ou service
$line->fk_unit = $objp->fk_unit;
$line->date_start = $this->db->jdate($objp->date_start);
$line->date_end = $this->db->jdate($objp->date_end);
@ -2420,9 +2429,10 @@ class Commande extends CommonOrder
* @param string $label Label
* @param int $special_code Special code (also used by externals modules!)
* @param array $array_options extrafields array
* @param int $fk_unit Id of the unit to use. Null to use the default one
* @return int < 0 if KO, > 0 if OK
*/
function updateline($rowid, $desc, $pu, $qty, $remise_percent, $txtva, $txlocaltax1=0.0,$txlocaltax2=0.0, $price_base_type='HT', $info_bits=0, $date_start='', $date_end='', $type=0, $fk_parent_line=0, $skip_update_total=0, $fk_fournprice=null, $pa_ht=0, $label='', $special_code=0, $array_options=0)
function updateline($rowid, $desc, $pu, $qty, $remise_percent, $txtva, $txlocaltax1=0.0,$txlocaltax2=0.0, $price_base_type='HT', $info_bits=0, $date_start='', $date_end='', $type=0, $fk_parent_line=0, $skip_update_total=0, $fk_fournprice=null, $pa_ht=0, $label='', $special_code=0, $array_options=0, $fk_unit = null)
{
global $conf, $mysoc;
@ -2442,6 +2452,7 @@ class Commande extends CommonOrder
if (empty($remise)) $remise=0;
if (empty($remise_percent)) $remise_percent=0;
if (empty($special_code) || $special_code == 3) $special_code=0;
$remise_percent=price2num($remise_percent);
$qty=price2num($qty);
$pu = price2num($pu);
@ -2514,6 +2525,7 @@ class Commande extends CommonOrder
$this->line->product_type=$type;
$this->line->fk_parent_line=$fk_parent_line;
$this->line->skip_update_total=$skip_update_total;
$this->line->fk_unit=$fk_unit;
// infos marge
if (!empty($fk_product) && empty($fk_fournprice) && empty($pa_ht)) {
@ -3194,6 +3206,7 @@ class Commande extends CommonOrder
$sql.= ' l.fk_remise_except, l.remise_percent, l.subprice, l.info_bits, l.rang, l.special_code, l.fk_parent_line,';
$sql.= ' l.total_ht, l.total_tva, l.total_ttc, l.fk_product_fournisseur_price as fk_fournprice, l.buy_price_ht as pa_ht, l.localtax1_tx, l.localtax2_tx,';
$sql.= ' l.date_start, l.date_end,';
$sql.= ' l.fk_unit,';
$sql.= ' p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid, ';
$sql.= ' p.description as product_desc, p.stock as stock_reel,';
$sql.= ' p.entity';
@ -3243,6 +3256,7 @@ class Commande extends CommonOrder
$this->lines[$i]->pa_ht = $marginInfos[0];
$this->lines[$i]->marge_tx = $marginInfos[1];
$this->lines[$i]->marque_tx = $marginInfos[2];
$this->lines[$i]->fk_unit = $obj->fk_unit;
$i++;
}
@ -3385,6 +3399,7 @@ class OrderLine extends CommonOrderLine
$sql = 'SELECT cd.rowid, cd.fk_commande, cd.fk_parent_line, cd.fk_product, cd.product_type, cd.label as custom_label, cd.description, cd.price, cd.qty, cd.tva_tx, cd.localtax1_tx, cd.localtax2_tx,';
$sql.= ' cd.remise, cd.remise_percent, cd.fk_remise_except, cd.subprice,';
$sql.= ' cd.info_bits, cd.total_ht, cd.total_tva, cd.total_localtax1, cd.total_localtax2, cd.total_ttc, cd.fk_product_fournisseur_price as fk_fournprice, cd.buy_price_ht as pa_ht, cd.rang, cd.special_code,';
$sql.= ' cd.fk_unit,';
$sql.= ' p.ref as product_ref, p.label as product_libelle, p.description as product_desc,';
$sql.= ' cd.date_start, cd.date_end';
$sql.= ' FROM '.MAIN_DB_PREFIX.'commandedet as cd';
@ -3430,6 +3445,7 @@ class OrderLine extends CommonOrderLine
$this->libelle = $objp->product_libelle; // deprecated
$this->product_label = $objp->product_libelle;
$this->product_desc = $objp->product_desc;
$this->fk_unit = $objp->fk_unit;
$this->date_start = $this->db->jdate($objp->date_start);
$this->date_end = $this->db->jdate($objp->date_end);
@ -3546,7 +3562,8 @@ class OrderLine extends CommonOrderLine
$sql.= ' tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type,';
$sql.= ' fk_product, product_type, remise_percent, subprice, price, remise, fk_remise_except,';
$sql.= ' special_code, rang, fk_product_fournisseur_price, buy_price_ht,';
$sql.= ' info_bits, total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, date_start, date_end)';
$sql.= ' info_bits, total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, date_start, date_end,';
$sql.= ' fk_unit)';
$sql.= " VALUES (".$this->fk_commande.",";
$sql.= " ".($this->fk_parent_line>0?"'".$this->fk_parent_line."'":"null").",";
$sql.= " ".(! empty($this->label)?"'".$this->db->escape($this->label)."'":"null").",";
@ -3575,7 +3592,8 @@ class OrderLine extends CommonOrderLine
$sql.= " '".price2num($this->total_localtax2)."',";
$sql.= " '".price2num($this->total_ttc)."',";
$sql.= " ".(! empty($this->date_start)?"'".$this->db->idate($this->date_start)."'":"null").',';
$sql.= " ".(! empty($this->date_end)?"'".$this->db->idate($this->date_end)."'":"null");
$sql.= " ".(! empty($this->date_end)?"'".$this->db->idate($this->date_end)."'":"null").',';
$sql.= ' '.(!$this->fk_unit ? 'NULL' : $this->fk_unit);
$sql.= ')';
dol_syslog(get_class($this)."::insert", LOG_DEBUG);
@ -3693,6 +3711,7 @@ class OrderLine extends CommonOrderLine
$sql.= " , product_type=".$this->product_type;
$sql.= " , fk_parent_line=".(! empty($this->fk_parent_line)?$this->fk_parent_line:"null");
if (! empty($this->rang)) $sql.= ", rang=".$this->rang;
$sql.= " , fk_unit=".(!$this->fk_unit ? 'NULL' : $this->fk_unit);
$sql.= " WHERE rowid = ".$this->rowid;
dol_syslog(get_class($this)."::update", LOG_DEBUG);

View File

@ -1083,7 +1083,7 @@ if (empty($reshook))
$localtax1_tx = get_localtax($lines[$i]->tva_tx, 1, $object->client);
$localtax2_tx = get_localtax($lines[$i]->tva_tx, 2, $object->client);
$result = $object->addline($desc, $lines[$i]->subprice, $lines[$i]->qty, $lines[$i]->tva_tx, $localtax1_tx, $localtax2_tx, $lines[$i]->fk_product, $lines[$i]->remise_percent, $date_start, $date_end, 0, $lines[$i]->info_bits, $lines[$i]->fk_remise_except, 'HT', 0, $product_type, $lines[$i]->rang, $lines[$i]->special_code, $object->origin, $lines[$i]->rowid, $fk_parent_line, $lines[$i]->fk_fournprice, $lines[$i]->pa_ht, $label, $array_options, $lines[$i]->situation_percent, $lines[$i]->fk_prev_id);
$result = $object->addline($desc, $lines[$i]->subprice, $lines[$i]->qty, $lines[$i]->tva_tx, $localtax1_tx, $localtax2_tx, $lines[$i]->fk_product, $lines[$i]->remise_percent, $date_start, $date_end, 0, $lines[$i]->info_bits, $lines[$i]->fk_remise_except, 'HT', 0, $product_type, $lines[$i]->rang, $lines[$i]->special_code, $object->origin, $lines[$i]->rowid, $fk_parent_line, $lines[$i]->fk_fournprice, $lines[$i]->pa_ht, $label, $array_options, $lines[$i]->situation_percent, $lines[$i]->fk_prev_id, $lines[$i]->fk_unit);
if ($result > 0) {
$lineid = $result;
@ -1125,7 +1125,7 @@ if (empty($reshook))
$product->fetch($_POST['idprod' . $i]);
$startday = dol_mktime(12, 0, 0, $_POST['date_start' . $i . 'month'], $_POST['date_start' . $i . 'day'], $_POST['date_start' . $i . 'year']);
$endday = dol_mktime(12, 0, 0, $_POST['date_end' . $i . 'month'], $_POST['date_end' . $i . 'day'], $_POST['date_end' . $i . 'year']);
$result = $object->addline($product->description, $product->price, $_POST['qty' . $i], $product->tva_tx, $product->localtax1_tx, $product->localtax2_tx, $_POST['idprod' . $i], $_POST['remise_percent' . $i], $startday, $endday, 0, 0, '', $product->price_base_type, $product->price_ttc, $product->type);
$result = $object->addline($product->description, $product->price, $_POST['qty' . $i], $product->tva_tx, $product->localtax1_tx, $product->localtax2_tx, $_POST['idprod' . $i], $_POST['remise_percent' . $i], $startday, $endday, 0, 0, '', $product->price_base_type, $product->price_ttc, $product->type, -1, 0, '', 0, 0, null, 0, '', 0, 100, '', $product->fk_unit);
}
}
}
@ -1271,6 +1271,7 @@ if (empty($reshook))
// Ecrase $desc par celui du produit
// Ecrase $txtva par celui du produit
// Ecrase $base_price_type par celui du produit
// Replaces $fk_unit with the product's
if (! empty($idprod)) {
$prod = new Product($db);
$prod->fetch($idprod);
@ -1366,6 +1367,7 @@ if (empty($reshook))
}
$type = $prod->type;
$fk_unit = $prod->fk_unit;
} else {
$pu_ht = price2num($price_ht, 'MU');
$pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
@ -1374,6 +1376,11 @@ if (empty($reshook))
$label = (GETPOST('product_label') ? GETPOST('product_label') : '');
$desc = $product_desc;
$type = GETPOST('type');
$fk_unit= GETPOST('units', 'int');
if ($fk_unit <= 0) {
$fk_unit = null;
}
}
// Margin
@ -1393,7 +1400,7 @@ if (empty($reshook))
setEventMessage($mesg, 'errors');
} else {
// Insert line
$result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $date_start, $date_end, 0, $info_bits, '', $price_base_type, $pu_ttc, $type, - 1, $special_code, '', 0, GETPOST('fk_parent_line'), $fournprice, $buyingprice, $label, $array_options, $_POST['progress']);
$result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $date_start, $date_end, 0, $info_bits, '', $price_base_type, $pu_ttc, $type, - 1, $special_code, '', 0, GETPOST('fk_parent_line'), $fournprice, $buyingprice, $label, $array_options, $_POST['progress'], '', $fk_unit);
if ($result > 0)
{
@ -1431,6 +1438,7 @@ if (empty($reshook))
unset($_POST['np_markRate']);
unset($_POST['dp_desc']);
unset($_POST['idprod']);
unset($_POST['units']);
unset($_POST['date_starthour']);
unset($_POST['date_startmin']);
@ -1547,7 +1555,10 @@ if (empty($reshook))
// Update line
if (! $error) {
$result = $object->updateline(GETPOST('lineid'), $description, $pu_ht, $qty, GETPOST('remise_percent'), $date_start, $date_end, $vat_rate, $localtax1_rate, $localtax2_rate, 'HT', $info_bits, $type, GETPOST('fk_parent_line'), 0, $fournprice, $buyingprice, $label, 0, $array_options, GETPOST('progress'));
$result = $object->updateline(GETPOST('lineid'), $description, $pu_ht, $qty, GETPOST('remise_percent'),
$date_start, $date_end, $vat_rate, $localtax1_rate, $localtax2_rate, 'HT', $info_bits, $type,
GETPOST('fk_parent_line'), 0, $fournprice, $buyingprice, $label, 0, $array_options, GETPOST('progress'),
$_POST['units']);
if ($result >= 0) {
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
@ -1584,6 +1595,7 @@ if (empty($reshook))
unset($_POST['dp_desc']);
unset($_POST['idprod']);
unset($_POST['units']);
unset($_POST['date_starthour']);
unset($_POST['date_startmin']);

View File

@ -3,6 +3,7 @@
* Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2009-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
*
@ -162,7 +163,8 @@ class FactureRec extends Facture
$facsrc->lines[$i]->product_type,
$facsrc->lines[$i]->rang,
$facsrc->lines[$i]->special_code,
$facsrc->lines[$i]->label
$facsrc->lines[$i]->label,
$facsrc->lines[$i]->fk_unit
);
if ($result_insert < 0)
@ -300,6 +302,7 @@ class FactureRec extends Facture
$sql.= ' l.remise, l.remise_percent, l.subprice,';
$sql.= ' l.total_ht, l.total_tva, l.total_ttc,';
$sql.= ' l.rang, l.special_code,';
$sql.= ' l.fk_unit,';
$sql.= ' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc';
$sql.= ' FROM '.MAIN_DB_PREFIX.'facturedet_rec as l';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
@ -342,6 +345,7 @@ class FactureRec extends Facture
$line->code_ventilation = $objp->fk_code_ventilation;
$line->rang = $objp->rang;
$line->special_code = $objp->special_code;
$line->fk_unit = $objp->fk_unit;
// Ne plus utiliser
$line->price = $objp->price;
@ -413,11 +417,11 @@ class FactureRec extends Facture
* @param string $label Label of the line
* @return int <0 if KO, Id of line if OK
*/
function addline($desc, $pu_ht, $qty, $txtva, $fk_product=0, $remise_percent=0, $price_base_type='HT', $info_bits=0, $fk_remise_except='', $pu_ttc=0, $type=0, $rang=-1, $special_code=0, $label='')
function addline($desc, $pu_ht, $qty, $txtva, $fk_product=0, $remise_percent=0, $price_base_type='HT', $info_bits=0, $fk_remise_except='', $pu_ttc=0, $type=0, $rang=-1, $special_code=0, $label='', $fk_unit= null)
{
$facid=$this->id;
dol_syslog("FactureRec::addline facid=$facid,desc=$desc,pu_ht=$pu_ht,qty=$qty,txtva=$txtva,fk_product=$fk_product,remise_percent=$remise_percent,date_start=$date_start,date_end=$date_end,ventil=$ventil,info_bits=$info_bits,fk_remise_except=$fk_remise_except,price_base_type=$price_base_type,pu_ttc=$pu_ttc,type=$type", LOG_DEBUG);
dol_syslog("FactureRec::addline facid=$facid,desc=$desc,pu_ht=$pu_ht,qty=$qty,txtva=$txtva,fk_product=$fk_product,remise_percent=$remise_percent,date_start=$date_start,date_end=$date_end,ventil=$ventil,info_bits=$info_bits,fk_remise_except=$fk_remise_except,price_base_type=$price_base_type,pu_ttc=$pu_ttc,type=$type,fk_unit=$fk_unit", LOG_DEBUG);
include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
// Check parameters
@ -477,6 +481,7 @@ class FactureRec extends Facture
$sql.= ", total_ttc";
$sql.= ", rang";
$sql.= ", special_code";
$sql.= ", fk_unit";
$sql.= ") VALUES (";
$sql.= "'".$facid."'";
$sql.= ", ".(! empty($label)?"'".$this->db->escape($label)."'":"null");
@ -493,7 +498,8 @@ class FactureRec extends Facture
$sql.= ", '".price2num($total_tva)."'";
$sql.= ", '".price2num($total_ttc)."'";
$sql.= ", ".$rang;
$sql.= ", ".$special_code.")";
$sql.= ", ".$special_code;
$sql.= ", ".$fk_unit.")";
dol_syslog(get_class($this)."::addline", LOG_DEBUG);
if ($this->db->query($sql))

View File

@ -36,6 +36,7 @@
*/
include_once DOL_DOCUMENT_ROOT.'/core/class/commoninvoice.class.php';
require_once DOL_DOCUMENT_ROOT ."/core/class/commonobjectline.class.php";
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
require_once DOL_DOCUMENT_ROOT.'/margin/lib/margins.lib.php';
@ -484,7 +485,8 @@ class Facture extends CommonInvoice
$this->lines[$i]->label,
$this->lines[$i]->array_options,
$this->lines[$i]->situation_percent,
$this->lines[$i]->fk_prev_id
$this->lines[$i]->fk_prev_id,
$this->lines[$i]->fk_unit
);
if ($result < 0)
{
@ -538,7 +540,9 @@ class Facture extends CommonInvoice
0,
$_facrec->lines[$i]->label,
null,
$_facrec->lines[$i]->situation_percent
$_facrec->lines[$i]->situation_percent,
'',
$_facrec->lines[$i]->fk_unit
);
if ( $result_insert < 0)
@ -830,6 +834,7 @@ class Facture extends CommonInvoice
$line->rang = $object->lines[$i]->rang;
$line->special_code = $object->lines[$i]->special_code;
$line->fk_parent_line = $object->lines[$i]->fk_parent_line;
$line->fk_unit = $object->lines[$i]->fk_unit;
$line->fk_fournprice = $object->lines[$i]->fk_fournprice;
$marginInfos = getMarginInfos($object->lines[$i]->subprice, $object->lines[$i]->remise_percent, $object->lines[$i]->tva_tx, $object->lines[$i]->localtax1_tx, $object->lines[$i]->localtax2_tx, $object->lines[$i]->fk_fournprice, $object->lines[$i]->pa_ht);
@ -1096,6 +1101,7 @@ class Facture extends CommonInvoice
$sql.= ' l.rang, l.special_code,';
$sql.= ' l.date_start as date_start, l.date_end as date_end,';
$sql.= ' l.info_bits, l.total_ht, l.total_tva, l.total_localtax1, l.total_localtax2, l.total_ttc, l.fk_code_ventilation, l.fk_product_fournisseur_price as fk_fournprice, l.buy_price_ht as pa_ht,';
$sql.= ' l.fk_unit,';
$sql.= ' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc';
$sql.= ' FROM '.MAIN_DB_PREFIX.'facturedet as l';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
@ -1153,6 +1159,7 @@ class Facture extends CommonInvoice
$line->fk_parent_line = $objp->fk_parent_line;
$line->situation_percent= $objp->situation_percent;
$line->fk_prev_id = $objp->fk_prev_id;
$line->fk_unit = $objp->fk_unit;
$this->lines[$i] = $line;
@ -2093,13 +2100,14 @@ class Facture extends CommonInvoice
* @param array $array_options extrafields array
* @param int $situation_percent Situation advance percentage
* @param int $fk_prev_id Previous situation line id reference
* @param int $fk_unit Id of the unit to use. Null to use the default one
* @return int <0 if KO, Id of line if OK
*/
function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits=0, $fk_remise_except='', $price_base_type='HT', $pu_ttc=0, $type=self::TYPE_STANDARD, $rang=-1, $special_code=0, $origin='', $origin_id=0, $fk_parent_line=0, $fk_fournprice=null, $pa_ht=0, $label='', $array_options=0, $situation_percent=100, $fk_prev_id='')
function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits=0, $fk_remise_except='', $price_base_type='HT', $pu_ttc=0, $type=self::TYPE_STANDARD, $rang=-1, $special_code=0, $origin='', $origin_id=0, $fk_parent_line=0, $fk_fournprice=null, $pa_ht=0, $label='', $array_options=0, $situation_percent=100, $fk_prev_id='', $fk_unit = null)
{
global $mysoc, $conf, $langs;
dol_syslog(get_class($this)."::addline facid=$this->id,desc=$desc,pu_ht=$pu_ht,qty=$qty,txtva=$txtva, txlocaltax1=$txlocaltax1, txlocaltax2=$txlocaltax2, fk_product=$fk_product,remise_percent=$remise_percent,date_start=$date_start,date_end=$date_end,ventil=$ventil,info_bits=$info_bits,fk_remise_except=$fk_remise_except,price_base_type=$price_base_type,pu_ttc=$pu_ttc,type=$type", LOG_DEBUG);
dol_syslog(get_class($this)."::addline facid=$this->id,desc=$desc,pu_ht=$pu_ht,qty=$qty,txtva=$txtva, txlocaltax1=$txlocaltax1, txlocaltax2=$txlocaltax2, fk_product=$fk_product,remise_percent=$remise_percent,date_start=$date_start,date_end=$date_end,ventil=$ventil,info_bits=$info_bits,fk_remise_except=$fk_remise_except,price_base_type=$price_base_type,pu_ttc=$pu_ttc,type=$type, fk_unit=$fk_unit", LOG_DEBUG);
include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
// Clean parameters
@ -2213,6 +2221,7 @@ class Facture extends CommonInvoice
$this->line->origin_id=$origin_id;
$this->line->situation_percent = $situation_percent;
$this->line->fk_prev_id = $fk_prev_id;
$this->line->fk_unit=$fk_unit;
// infos marge
$this->line->fk_fournprice = $fk_fournprice;
@ -2275,15 +2284,16 @@ class Facture extends CommonInvoice
* @param int $special_code Special code (also used by externals modules!)
* @param array $array_options extrafields array
* @param int $situation_percent Situation advance percentage
* @param int $fk_unit Id of the unit to use. Null to use the default one
* @return int < 0 if KO, > 0 if OK
*/
function updateline($rowid, $desc, $pu, $qty, $remise_percent, $date_start, $date_end, $txtva, $txlocaltax1=0, $txlocaltax2=0, $price_base_type='HT', $info_bits=0, $type= self::TYPE_STANDARD, $fk_parent_line=0, $skip_update_total=0, $fk_fournprice=null, $pa_ht=0, $label='', $special_code=0, $array_options=0, $situation_percent=0)
function updateline($rowid, $desc, $pu, $qty, $remise_percent, $date_start, $date_end, $txtva, $txlocaltax1=0, $txlocaltax2=0, $price_base_type='HT', $info_bits=0, $type= self::TYPE_STANDARD, $fk_parent_line=0, $skip_update_total=0, $fk_fournprice=null, $pa_ht=0, $label='', $special_code=0, $array_options=0, $situation_percent=0, $fk_unit = null)
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
global $mysoc;
dol_syslog(get_class($this)."::updateline $rowid, $desc, $pu, $qty, $remise_percent, $date_start, $date_end, $txtva, $txlocaltax1, $txlocaltax2, $price_base_type, $info_bits, $type, $fk_parent_line", LOG_DEBUG);
dol_syslog(get_class($this)."::updateline $rowid, $desc, $pu, $qty, $remise_percent, $date_start, $date_end, $txtva, $txlocaltax1, $txlocaltax2, $price_base_type, $info_bits, $type, $fk_parent_line, $fk_unit", LOG_DEBUG);
if ($this->brouillon)
{
@ -2295,7 +2305,6 @@ class Facture extends CommonInvoice
if (empty($special_code) || $special_code == 3) $special_code=0;
if ($situation_percent > 100 || is_null($situation_percent) || $situation_percent == "") $situation_percent = 100;
$remise_percent = price2num($remise_percent);
$qty = price2num($qty);
$pu = price2num($pu);
@ -2364,7 +2373,7 @@ class Facture extends CommonInvoice
$this->line->fk_parent_line = $fk_parent_line;
$this->line->skip_update_total = $skip_update_total;
$this->line->situation_percent = $situation_percent;
$this->line->fk_unit = $fk_unit;
// infos marge
if (!empty($fk_product) && empty($fk_fournprice) && empty($pa_ht)) {
@ -3425,6 +3434,7 @@ class Facture extends CommonInvoice
$sql.= ' l.remise_percent, l.subprice, l.info_bits, l.rang, l.special_code, l.fk_parent_line,';
$sql.= ' l.total_ht, l.total_tva, l.total_ttc, l.fk_product_fournisseur_price as fk_fournprice, l.buy_price_ht as pa_ht,';
$sql.= ' l.date_start, l.date_end,';
$sql.= ' l.fk_unit,';
$sql.= ' p.ref as product_ref, p.fk_product_type, p.label as product_label,';
$sql.= ' p.description as product_desc,';
$sql.= ' p.entity';
@ -3476,6 +3486,7 @@ class Facture extends CommonInvoice
$this->lines[$i]->pa_ht = $marginInfos[0];
$this->lines[$i]->marge_tx = $marginInfos[1];
$this->lines[$i]->marque_tx = $marginInfos[2];
$this->lines[$i]->fk_unit = $obj->fk_unit;
$i++;
}
@ -3734,6 +3745,7 @@ class FactureLigne extends CommonInvoiceLine
$sql.= ' fd.date_start as date_start, fd.date_end as date_end, fd.fk_product_fournisseur_price as fk_fournprice, fd.buy_price_ht as pa_ht,';
$sql.= ' fd.info_bits, fd.special_code, fd.total_ht, fd.total_tva, fd.total_ttc, fd.total_localtax1, fd.total_localtax2, fd.rang,';
$sql.= ' fd.fk_code_ventilation,';
$sql.= ' fd.fk_unit,';
$sql.= ' fd.situation_percent, fd.fk_prev_id,';
$sql.= ' p.ref as product_ref, p.label as product_libelle, p.description as product_desc';
$sql.= ' FROM '.MAIN_DB_PREFIX.'facturedet as fd';
@ -3781,6 +3793,7 @@ class FactureLigne extends CommonInvoiceLine
$this->libelle = $objp->product_libelle; // deprecated
$this->product_label = $objp->product_libelle;
$this->product_desc = $objp->product_desc;
$this->fk_unit = $objp->fk_unit;
$this->situation_percent = $objp->situation_percent;
$this->fk_prev_id = $objp->fk_prev_id;
@ -3868,7 +3881,8 @@ class FactureLigne extends CommonInvoiceLine
$sql.= ' date_start, date_end, fk_code_ventilation, ';
$sql.= ' rang, special_code, fk_product_fournisseur_price, buy_price_ht,';
$sql.= ' info_bits, total_ht, total_tva, total_ttc, total_localtax1, total_localtax2,';
$sql.= ' situation_percent, fk_prev_id)';
$sql.= ' situation_percent, fk_prev_id,';
$sql.= ' fk_unit)';
$sql.= " VALUES (".$this->fk_facture.",";
$sql.= " ".($this->fk_parent_line>0?"'".$this->fk_parent_line."'":"null").",";
$sql.= " ".(! empty($this->label)?"'".$this->db->escape($this->label)."'":"null").",";
@ -3899,6 +3913,7 @@ class FactureLigne extends CommonInvoiceLine
$sql.= " ".price2num($this->total_localtax2);
$sql .= ", " . $this->situation_percent;
$sql .= ", " . $this->fk_prev_id;
$sql .= ", ".(!$this->fk_unit ? 'NULL' : $this->fk_unit);
$sql.= ')';
dol_syslog(get_class($this)."::insert", LOG_DEBUG);
@ -4063,6 +4078,7 @@ class FactureLigne extends CommonInvoiceLine
$sql.= ",fk_parent_line=".($this->fk_parent_line>0?$this->fk_parent_line:"null");
if (! empty($this->rang)) $sql.= ", rang=".$this->rang;
$sql .= ", situation_percent=" . $this->situation_percent;
$sql .= ", fk_unit=".(!$this->fk_unit ? 'NULL' : $this->fk_unit);
$sql.= " WHERE rowid = ".$this->rowid;
dol_syslog(get_class($this)."::update", LOG_DEBUG);

View File

@ -5,6 +5,7 @@
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
* Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -202,6 +203,7 @@ if ($action == 'create')
$sql.= ' l.date_start,';
$sql.= ' l.date_end,';
$sql.= ' l.product_type,';
$sql.= ' l.fk_unit,';
$sql.= ' p.ref, p.fk_product_type, p.label as product_label,';
$sql.= ' p.description as product_desc';
$sql.= " FROM ".MAIN_DB_PREFIX."facturedet as l";
@ -222,6 +224,9 @@ if ($action == 'create')
print '<td>'.$langs->trans("Description").'</td>';
print '<td align="center">'.$langs->trans("VAT").'</td>';
print '<td align="center">'.$langs->trans("Qty").'</td>';
if ($conf->global->PRODUCT_USE_UNITS) {
print '<td width="8%" align="left">'.$langs->trans("Unit").'</td>';
}
print '<td>'.$langs->trans("ReductionShort").'</td>';
print '<td align="right">'.$langs->trans("TotalHT").'</td>';
print '<td align="right">'.$langs->trans("TotalVAT").'</td>';
@ -246,6 +251,7 @@ if ($action == 'create')
// Show product and description
$type=(isset($objp->product_type)?$objp->product_type:$objp->fk_product_type);
$product_static->fk_unit=$objp->fk_unit;
if ($objp->fk_product > 0)
{
@ -299,6 +305,10 @@ if ($action == 'create')
// Qty
print '<td align="center">'.$objp->qty.'</td>';
if ($conf->global->PRODUCT_USE_UNITS) {
print '<td align="left">'.$product_static->get_unit_label().'</td>';
}
// Percent
if ($objp->remise_percent > 0)
{
@ -445,7 +455,11 @@ else
print '<td>'.$langs->trans("Description").'</td>';
print '<td align="right">'.$langs->trans("Price").'</td>';
print '<td align="center">'.$langs->trans("ReductionShort").'</td>';
print '<td align="center">'.$langs->trans("Qty").'</td></tr>';
print '<td align="center">'.$langs->trans("Qty").'</td>';
if ($conf->global->PRODUCT_USE_UNITS) {
print '<td align="left">'.$langs->trans("Unit").'</td>';
}
print '</tr>';
$num = count($object->lines);
$i = 0;
@ -512,7 +526,11 @@ else
}
print '<td align="right">'.price($object->lines[$i]->price).'</td>';
print '<td align="center">'.$object->lines[$i]->remise_percent.' %</td>';
print '<td align="center">'.$object->lines[$i]->qty.'</td></tr>'."\n";
print '<td align="center">'.$object->lines[$i]->qty.'</td>';
if ($conf->global->PRODUCT_USE_UNITS) {
print "<td align=\"left\">".$object->lines[$i]->get_unit_label()."</td>";
}
print "</tr>\n";
$i++;
}
print '</table>';

View File

@ -338,7 +338,9 @@ if ($action == 'add' && $user->rights->contrat->creer)
0,
$lines[$i]->info_bits,
$lines[$i]->fk_fournprice,
$lines[$i]->pa_ht
$lines[$i]->pa_ht,
array(),
$lines[$i]->fk_unit
);
if ($result < 0)
@ -494,6 +496,7 @@ else if ($action == 'addline' && $user->rights->contrat->creer)
$desc=$prod->description;
$desc=dol_concatdesc($desc,$product_desc);
$fk_unit = $prod->fk_unit;
}
else
{
@ -502,6 +505,11 @@ else if ($action == 'addline' && $user->rights->contrat->creer)
$tva_tx=GETPOST('tva_tx')?str_replace('*','',GETPOST('tva_tx')):0; // tva_tx field may be disabled, so we use vat rate 0
$tva_npr=preg_match('/\*/',GETPOST('tva_tx'))?1:0;
$desc=$product_desc;
$fk_unit= GETPOST('units', 'int');
if ($fk_unit <= 0) {
$fk_unit = null;
}
}
$localtax1_tx=get_localtax($tva_tx,1,$object->thirdparty);
@ -541,7 +549,8 @@ else if ($action == 'addline' && $user->rights->contrat->creer)
$info_bits,
$fk_fournprice,
$pa_ht,
$array_options
$array_options,
$fk_unit
);
}
@ -622,6 +631,8 @@ else if ($action == 'updateligne' && $user->rights->contrat->creer && ! GETPOST(
else
$pa_ht = null;
$fk_unit = GETPOST('unit', 'int');
$objectline->description=GETPOST('product_desc');
$objectline->price_ht=GETPOST('elprice');
$objectline->subprice=GETPOST('elprice');
@ -638,6 +649,12 @@ else if ($action == 'updateligne' && $user->rights->contrat->creer && ! GETPOST(
$objectline->fk_fournprice=$fk_fournprice;
$objectline->pa_ht=$pa_ht;
if ($fk_unit > 0) {
$objectline->fk_unit = $_POST['unit'];
} else {
$objectline->fk_unit = null;
}
// Extrafields
$extrafieldsline = new ExtraFields($db);
$extralabelsline = $extrafieldsline->fetch_name_optionals_label($objectline->table_element);
@ -1294,6 +1311,7 @@ else
$sql.= " cd.date_ouverture_prevue as date_debut, cd.date_ouverture as date_debut_reelle,";
$sql.= " cd.date_fin_validite as date_fin, cd.date_cloture as date_fin_reelle,";
$sql.= " cd.commentaire as comment, cd.fk_product_fournisseur_price as fk_fournprice, cd.buy_price_ht as pa_ht,";
$sql.= " cd.fk_unit,";
$sql.= " p.rowid as pid, p.ref as pref, p.label as label, p.fk_product_type as ptype";
$sql.= " FROM ".MAIN_DB_PREFIX."contratdet as cd";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
@ -1309,6 +1327,7 @@ else
print '<td width="50" align="center">'.$langs->trans("VAT").'</td>';
print '<td width="50" align="right">'.$langs->trans("PriceUHT").'</td>';
print '<td width="30" align="center">'.$langs->trans("Qty").'</td>';
if($conf->global->PRODUCT_USE_UNITS) print '<td width="30" align="left">'.$langs->trans("Unit").'</td>';
print '<td width="50" align="right">'.$langs->trans("ReductionShort").'</td>';
if (! empty($conf->margin->enabled) && ! empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) print '<td width="50" align="right">'.$langs->trans("BuyingPrice").'</td>';
print '<td width="30">&nbsp;</td>';
@ -1349,6 +1368,8 @@ else
print '<td align="right">'.($objp->subprice != '' ? price($objp->subprice) : '')."</td>\n";
// Quantite
print '<td align="center">'.$objp->qty.'</td>';
//Unit
if($conf->global->PRODUCT_USE_UNITS) print '<td align="left">'.$langs->trans($object->lines[$cursorline-1]->get_unit_label()).'</td>';
// Remise
if ($objp->remise_percent > 0)
{
@ -1396,8 +1417,16 @@ else
// Dates de en service prevues et effectives
if ($objp->subprice >= 0)
{
$colspan = 6;
if ($conf->margin->enabled && $conf->global->PRODUCT_USE_UNITS) {
$colspan = 8;
} elseif ($conf->margin->enabled || $conf->global->PRODUCT_USE_UNITS) {
$colspan = 7;
}
print '<tr '.$bc[$var].'>';
print '<td colspan="'.($conf->margin->enabled?7:6).'">';
print '<td colspan="'.$colspan.'">';
// Date planned
print $langs->trans("DateStartPlanned").': ';
@ -1465,6 +1494,12 @@ else
print '</td>';
print '<td align="right"><input size="5" type="text" name="elprice" value="'.price($objp->subprice).'"></td>';
print '<td align="center"><input size="2" type="text" name="elqty" value="'.$objp->qty.'"></td>';
if($conf->global->PRODUCT_USE_UNITS)
{
print '<td align="left">';
$form->select_units($objp->fk_unit, "unit");
print '</td>';
}
print '<td align="right" class="nowrap"><input size="1" type="text" name="elremise_percent" value="'.$objp->remise_percent.'">%</td>';
if (! empty($usemargins))
{
@ -1478,6 +1513,7 @@ else
$colspan=5;
if (! empty($conf->margin->enabled) && ! empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) $colspan++;
if($conf->global->PRODUCT_USE_UNITS) $colspan++;
// Ligne dates prevues
print "<tr ".$bc[$var].">";

View File

@ -30,6 +30,7 @@
*/
require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php';
require_once DOL_DOCUMENT_ROOT."/core/class/commonobjectline.class.php";
require_once DOL_DOCUMENT_ROOT . '/core/lib/price.lib.php';
require_once DOL_DOCUMENT_ROOT . '/margin/lib/margins.lib.php';
@ -635,7 +636,8 @@ class Contrat extends CommonObject
$sql.= " d.date_fin_validite, d.date_cloture,";
$sql.= " d.fk_user_author,";
$sql.= " d.fk_user_ouverture,";
$sql.= " d.fk_user_cloture";
$sql.= " d.fk_user_cloture,";
$sql.= " d.fk_unit";
$sql.= " FROM ".MAIN_DB_PREFIX."contratdet as d, ".MAIN_DB_PREFIX."product as p";
$sql.= " WHERE d.fk_contrat = ".$this->id ." AND d.fk_product = p.rowid";
$sql.= " ORDER by d.rowid ASC";
@ -680,6 +682,7 @@ class Contrat extends CommonObject
$line->fk_user_author = $objp->fk_user_author;
$line->fk_user_ouverture= $objp->fk_user_ouverture;
$line->fk_user_cloture = $objp->fk_user_cloture;
$line->fk_unit = $objp->fk_unit;
$line->ref = $objp->ref;
$line->libelle = $objp->label; // Label produit
@ -738,7 +741,8 @@ class Contrat extends CommonObject
$sql.= " d.date_fin_validite, d.date_cloture,";
$sql.= " d.fk_user_author,";
$sql.= " d.fk_user_ouverture,";
$sql.= " d.fk_user_cloture";
$sql.= " d.fk_user_cloture,";
$sql.= " d.fk_unit";
$sql.= " FROM ".MAIN_DB_PREFIX."contratdet as d";
$sql.= " WHERE d.fk_contrat = ".$this->id;
$sql.= " AND (d.fk_product IS NULL OR d.fk_product = 0)"; // fk_product = 0 gardee pour compatibilitee
@ -791,6 +795,7 @@ class Contrat extends CommonObject
$line->date_debut_reel = $this->db->jdate($objp->date_ouverture);
$line->date_fin_prevue = $this->db->jdate($objp->date_fin_validite);
$line->date_fin_reel = $this->db->jdate($objp->date_cloture);
$line->fk_unit = $objp->fk_unit;
if ($line->statut == 0) $this->nbofserviceswait++;
if ($line->statut == 4 && (empty($line->date_fin_prevue) || $line->date_fin_prevue >= $now)) $this->nbofservicesopened++;
@ -1231,9 +1236,10 @@ class Contrat extends CommonObject
* @param int $fk_fournprice Fourn price id
* @param int $pa_ht Buying price HT
* @param array $array_options extrafields array
* @param int $fk_unit Id of the unit to use. Null to use the default one
* @return int <0 si erreur, >0 si ok
*/
function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2, $fk_product, $remise_percent, $date_start, $date_end, $price_base_type='HT', $pu_ttc=0.0, $info_bits=0, $fk_fournprice=null, $pa_ht = 0,$array_options=0)
function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2, $fk_product, $remise_percent, $date_start, $date_end, $price_base_type='HT', $pu_ttc=0.0, $info_bits=0, $fk_fournprice=null, $pa_ht = 0,$array_options=0, $fk_unit = null)
{
global $user, $langs, $conf, $mysoc;
@ -1250,6 +1256,7 @@ class Contrat extends CommonObject
if (! $info_bits) $info_bits=0;
if (! $pu_ht) $pu_ht=0;
if (! $pu_ttc) $pu_ttc=0;
$pu_ht=price2num($pu_ht);
$pu_ttc=price2num($pu_ttc);
$pa_ht=price2num($pa_ht);
@ -1313,6 +1320,7 @@ class Contrat extends CommonObject
$sql.= " price_ht, remise, fk_product_fournisseur_price, buy_price_ht";
if ($date_start > 0) { $sql.= ",date_ouverture_prevue"; }
if ($date_end > 0) { $sql.= ",date_fin_validite"; }
$sql.= ", fk_unit";
$sql.= ") VALUES ($this->id, '', '" . $this->db->escape($desc) . "',";
$sql.= ($fk_product>0 ? $fk_product : "null").",";
$sql.= " '".$qty."',";
@ -1331,6 +1339,7 @@ class Contrat extends CommonObject
else $sql.= ' null';
if ($date_start > 0) { $sql.= ",'".$this->db->idate($date_start)."'"; }
if ($date_end > 0) { $sql.= ",'".$this->db->idate($date_end)."'"; }
$sql.= ", ".$fk_unit;
$sql.= ")";
dol_syslog(get_class($this)."::addline", LOG_DEBUG);
@ -1409,9 +1418,10 @@ class Contrat extends CommonObject
* @param int $fk_fournprice Fourn price id
* @param int $pa_ht Buying price HT
* @param array $array_options extrafields array
* @param int $fk_unit Id of the unit to use. Null to use the default one
* @return int < 0 si erreur, > 0 si ok
*/
function updateline($rowid, $desc, $pu, $qty, $remise_percent, $date_start, $date_end, $tvatx, $localtax1tx=0.0, $localtax2tx=0.0, $date_debut_reel='', $date_fin_reel='', $price_base_type='HT', $info_bits=0, $fk_fournprice=null, $pa_ht = 0,$array_options=0)
function updateline($rowid, $desc, $pu, $qty, $remise_percent, $date_start, $date_end, $tvatx, $localtax1tx=0.0, $localtax2tx=0.0, $date_debut_reel='', $date_fin_reel='', $price_base_type='HT', $info_bits=0, $fk_fournprice=null, $pa_ht = 0,$array_options=0, $fk_unit = null)
{
global $user, $conf, $langs, $mysoc;
@ -1502,6 +1512,7 @@ class Contrat extends CommonObject
else { $sql.=",date_ouverture=null"; }
if ($date_fin_reel > 0) { $sql.= ",date_cloture='".$this->db->idate($date_fin_reel)."'"; }
else { $sql.=",date_cloture=null"; }
$sql .= ", fk_unit=".$fk_unit;
$sql .= " WHERE rowid = ".$rowid;
dol_syslog(get_class($this)."::updateline", LOG_DEBUG);
@ -2135,7 +2146,7 @@ class Contrat extends CommonObject
/**
* Classe permettant la gestion des lignes de contrats
*/
class ContratLigne extends CommonObject
class ContratLigne extends CommonObjectLine
{
var $id;
@ -2355,7 +2366,8 @@ class ContratLigne extends CommonObject
$sql.= " t.fk_user_author,";
$sql.= " t.fk_user_ouverture,";
$sql.= " t.fk_user_cloture,";
$sql.= " t.commentaire";
$sql.= " t.commentaire,";
$sql.= " t.fk_unit";
$sql.= " FROM ".MAIN_DB_PREFIX."contratdet as t";
if ($id) $sql.= " WHERE t.rowid = ".$id;
if ($ref) $sql.= " WHERE t.rowid = '".$this->db->escape($ref)."'";
@ -2404,6 +2416,7 @@ class ContratLigne extends CommonObject
$this->fk_fournprice = $obj->fk_fournprice;
$marginInfos = getMarginInfos($obj->subprice, $obj->remise_percent, $obj->tva_tx, $obj->localtax1_tx, $obj->localtax2_tx, $this->fk_fournprice, $obj->pa_ht);
$this->pa_ht = $marginInfos[0];
$this->fk_unit = $obj->fk_unit;
}
$this->db->free($resql);
@ -2519,6 +2532,7 @@ class ContratLigne extends CommonObject
$sql.= " fk_user_ouverture=".($this->fk_user_ouverture > 0?$this->fk_user_ouverture:"NULL").",";
$sql.= " fk_user_cloture=".($this->fk_user_cloture > 0?$this->fk_user_cloture:"NULL").",";
$sql.= " commentaire='".$this->db->escape($this->commentaire)."'";
$sql.= ", fk_unit=".(!$this->fk_unit ? 'NULL' : $this->fk_unit);
$sql.= " WHERE rowid=".$this->id;
dol_syslog(get_class($this)."::update", LOG_DEBUG);

View File

@ -8,6 +8,7 @@
* Copyright (C) 2011-2014 Philippe Grand <philippe.grand@atoo-net.com>
* Copyright (C) 2012-2015 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2012-2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -2719,6 +2720,11 @@ abstract class CommonObject
// Qty
print '<td align="right" width="50">'.$langs->trans('Qty').'</td>';
if($conf->global->PRODUCT_USE_UNITS)
{
print '<td align="left" width="50">'.$langs->trans('Unit').'</td>';
}
// Reduction short
print '<td align="right" width="50">'.$langs->trans('ReductionShort').'</td>';
@ -2918,7 +2924,7 @@ abstract class CommonObject
*/
function printOriginLinesList()
{
global $langs, $hookmanager;
global $langs, $hookmanager, $conf;
print '<tr class="liste_titre">';
print '<td>'.$langs->trans('Ref').'</td>';
@ -2926,6 +2932,10 @@ abstract class CommonObject
print '<td align="right">'.$langs->trans('VAT').'</td>';
print '<td align="right">'.$langs->trans('PriceUHT').'</td>';
print '<td align="right">'.$langs->trans('Qty').'</td>';
if($conf->global->PRODUCT_USE_UNITS)
{
print '<td align="left">'.$langs->trans('Unit').'</td>';
}
print '<td align="right">'.$langs->trans('ReductionShort').'</td></tr>';
$num = count($this->lines);
@ -2966,7 +2976,7 @@ abstract class CommonObject
*/
function printOriginLine($line,$var)
{
global $conf,$langs,$bc;
global $conf,$langs,$bc, $conf;
//var_dump($line);
if (!empty($line->date_start))
@ -3053,6 +3063,7 @@ abstract class CommonObject
$this->tpl['vat_rate'] = vatrate($line->tva_tx, true);
$this->tpl['price'] = price($line->subprice);
$this->tpl['qty'] = (($line->info_bits & 2) != 2) ? $line->qty : '&nbsp;';
if($conf->global->PRODUCT_USE_UNITS) $this->tpl['unit'] = $line->get_unit_label('long');
$this->tpl['remise_percent'] = (($line->info_bits & 2) != 2) ? vatrate($line->remise_percent, true) : '&nbsp;';
// Output template part (modules that overwrite templates must declare this into descriptor)

View File

@ -1,5 +1,6 @@
<?php
/* Copyright (C) 2006-2008 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -41,8 +42,57 @@ abstract class CommonObjectLine extends CommonObject
*/
public $rowid;
//! Database handler
public $db;
/**
* Product/service unit
* @var int
*/
public $fk_unit;
// TODO
/**
* Returns the text label from units dictionnary
*
* @param string $type Label type (long or short)
* @return string|int <0 if ko, label if ok
*/
public function get_unit_label($type='long')
{
global $langs;
if (!$this->fk_unit) {
return '';
}
$langs->load('products');
$this->db->begin();
$label_type = 'label';
if ($type == 'short')
{
$label_type = 'short_label';
}
$sql = 'select '.$label_type.' from '.MAIN_DB_PREFIX.'c_units where rowid='.$this->fk_unit;
$resql = $this->db->query($sql);
if($resql && $this->db->num_rows($resql) > 0)
{
$res = $this->db->fetch_array($resql);
$label = $res[$label_type];
$this->db->free($resql);
return $label;
}
else
{
$this->error=$this->db->error().' sql='.$sql;
dol_syslog(get_class($this)."::get_unit_label Error ".$this->error, LOG_ERR);
return -1;
}
}
// Currently we need function at end of file CommonObject for all object lines. Should find a way to avoid duplicate code.
// For the moment we use the extends on CommonObject until PHP min is 5.4 so use Traits.

View File

@ -2822,6 +2822,54 @@ class Form
return $opt;
}
/**
* Prints units selector
*
* @param string $selected Preselected ID
* @param string $htmlname Select name
* @return void
*/
function select_units($selected = '', $htmlname = 'units')
{
print $this->load_units($selected, $htmlname);
}
/**
* Creates HTML units selector
*
* @param string $selected Preselected ID
* @param string $htmlname Select name
* @return string HTML select
*/
function load_units($selected = '', $htmlname = 'units')
{
global $langs;
$langs->load('products');
$return= '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">';
$sql = 'select rowid, label from '.MAIN_DB_PREFIX.'c_units where active=1';
$resql = $this->db->query($sql);
if($resql && $this->db->num_rows($resql) > 0)
{
$return .= '<option value=""></option>';
while($res = $this->db->fetch_array($resql))
{
if ($selected == $res[0])
{
$return.='<option value="'.$res[0].'" selected="selected">'.$langs->trans($res[1]).'</option>';
}
else
{
$return.='<option value="'.$res[0].'">'.$langs->trans($res[1]).'</option>';
}
}
$return.='</select>';
}
return $return;
}
/**
* Return a HTML select list of bank accounts
*

View File

@ -1433,6 +1433,43 @@ function pdf_getlineqty_keeptoship($object,$i,$outputlangs,$hidedetails=0)
}
}
/**
* Return line unit
*
* @param Object $object Object
* @param int $i Current line number
* @param Translate $outputlangs Object langs for output
* @param int $hidedetails Hide details (0=no, 1=yes, 2=just special lines)
* @param HookManager $hookmanager Hook manager instance
* @return void
*/
function pdf_getlineunit($object, $i, $outputlangs, $hidedetails = 0, $hookmanager = false)
{
global $langs;
if ($object->lines[$i]->special_code != 3) {
if (is_object($hookmanager) && (($object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code)) || !empty($object->lines[$i]->fk_parent_line))) {
$special_code = $object->lines[$i]->special_code;
if (!empty($object->lines[$i]->fk_parent_line)) {
$special_code = $object->getSpecialCode($object->lines[$i]->fk_parent_line);
}
$parameters = array(
'i' => $i,
'outputlangs' => $outputlangs,
'hidedetails' => $hidedetails,
'special_code' => $special_code
);
$action = '';
return $hookmanager->executeHooks('pdf_getlineunit', $parameters, $object,
$action); // Note that $action and $object may have been modified by some hooks
} else {
if (empty($hidedetails) || $hidedetails > 1) {
return $langs->transnoentitiesnoconv($object->lines[$i]->get_unit_label('short'));
}
}
}
}
/**
* Return line remise percent
*

View File

@ -4,6 +4,7 @@
* Copyright (C) 2008 Raphael Bertrand <raphael.bertrand@resultic.fr>
* Copyright (C) 2010-2013 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
* Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -68,6 +69,7 @@ class pdf_einstein extends ModelePDFCommandes
$langs->load("main");
$langs->load("bills");
$langs->load("products");
$this->db = $db;
$this->name = "einstein";
@ -103,9 +105,19 @@ class pdf_einstein extends ModelePDFCommandes
// Define position of columns
$this->posxdesc=$this->marge_gauche+1;
$this->posxtva=112;
$this->posxup=126;
$this->posxqty=145;
if($conf->global->PRODUCT_USE_UNITS)
{
$this->posxtva=99;
$this->posxup=114;
$this->posxqty=133;
$this->posxunit=150;
}
else
{
$this->posxtva=112;
$this->posxup=126;
$this->posxqty=145;
}
$this->posxdiscount=162;
$this->postotalht=174;
if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) $this->posxtva=$this->posxup;
@ -239,7 +251,7 @@ class pdf_einstein extends ModelePDFCommandes
$this->atleastonediscount++;
}
}
if (empty($this->atleastonediscount))
if (empty($this->atleastonediscount) && empty($conf->global->PRODUCT_USE_UNITS))
{
$this->posxpicture+=($this->postotalht - $this->posxdiscount);
$this->posxtva+=($this->postotalht - $this->posxdiscount);
@ -403,9 +415,26 @@ class pdf_einstein extends ModelePDFCommandes
// Quantity
$qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
$pdf->SetXY($this->posxqty, $curY);
$pdf->MultiCell($this->posxdiscount-$this->posxqty-0.8, 3, $qty, 0, 'R'); // Enough for 6 chars
// Enough for 6 chars
if($conf->global->PRODUCT_USE_UNITS)
{
$pdf->MultiCell($this->posxunit-$this->posxqty-0.8, 4, $qty, 0, 'R');
}
else
{
$pdf->MultiCell($this->posxdiscount-$this->posxqty-0.8, 4, $qty, 0, 'R');
}
// Unit
if($conf->global->PRODUCT_USE_UNITS)
{
$unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
$pdf->SetXY($this->posxunit, $curY);
$pdf->MultiCell($this->posxdiscount-$this->posxunit-0.8, 4, $unit, 0, 'L');
}
// Discount on line
$pdf->SetXY($this->posxdiscount, $curY);
if ($object->lines[$i]->remise_percent)
{
$pdf->SetXY($this->posxdiscount-2, $curY);
@ -563,7 +592,7 @@ class pdf_einstein extends ModelePDFCommandes
/**
* Show payments table
*
* @param PDF $pdf Object PDF
* @param TCPDF $pdf Object PDF
* @param Object $object Object order
* @param int $posy Position y in PDF
* @param Translate $outputlangs Object langs for output
@ -578,7 +607,7 @@ class pdf_einstein extends ModelePDFCommandes
/**
* Show miscellaneous information (payment mode, payment term, ...)
*
* @param PDF $pdf Object PDF
* @param TCPDF $pdf Object PDF
* @param Object $object Object to show
* @param int $posy Y
* @param Translate $outputlangs Langs object
@ -763,7 +792,7 @@ class pdf_einstein extends ModelePDFCommandes
/**
* Show total to pay
*
* @param PDF $pdf Object PDF
* @param TCPDF $pdf Object PDF
* @param Facture $object Object invoice
* @param int $deja_regle Montant deja regle
* @param int $posy Position depart
@ -1020,7 +1049,7 @@ class pdf_einstein extends ModelePDFCommandes
/**
* Show table for lines
*
* @param PDF $pdf Object PDF
* @param TCPDF $pdf Object PDF
* @param string $tab_top Top position of table
* @param string $tab_height Height of table (rectangle)
* @param int $nexY Y (not used)
@ -1088,7 +1117,23 @@ class pdf_einstein extends ModelePDFCommandes
if (empty($hidetop))
{
$pdf->SetXY($this->posxqty-1, $tab_top+1);
$pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
if($conf->global->PRODUCT_USE_UNITS)
{
$pdf->MultiCell($this->posxunit-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
}
else
{
$pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
}
}
if($conf->global->PRODUCT_USE_UNITS) {
$pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
if (empty($hidetop)) {
$pdf->SetXY($this->posxunit - 1, $tab_top + 1);
$pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities("Unit"), '',
'C');
}
}
$pdf->line($this->posxdiscount-1, $tab_top, $this->posxdiscount-1, $tab_top + $tab_height);
@ -1115,7 +1160,7 @@ class pdf_einstein extends ModelePDFCommandes
/**
* Show top header of page.
*
* @param PDF $pdf Object PDF
* @param TCPDF $pdf Object PDF
* @param Object $object Object to show
* @param int $showaddress 0=no, 1=yes
* @param Translate $outputlangs Object lang for output
@ -1294,7 +1339,7 @@ class pdf_einstein extends ModelePDFCommandes
/**
* Show footer of page. Need this->emetteur object
*
* @param PDF $pdf PDF
* @param TCPDF $pdf PDF
* @param Object $object Object to show
* @param Translate $outputlangs Object lang for output
* @param int $hidefreetext 1=Hide free text

View File

@ -115,9 +115,19 @@ class pdf_crabe extends ModelePDFFactures
// Define position of columns
$this->posxdesc=$this->marge_gauche+1;
$this->posxtva=112;
$this->posxup=126;
$this->posxqty=145;
if($conf->global->PRODUCT_USE_UNITS)
{
$this->posxtva=99;
$this->posxup=114;
$this->posxqty=133;
$this->posxunit=150;
}
else
{
$this->posxtva=112;
$this->posxup=126;
$this->posxqty=145;
}
$this->posxdiscount=162;
$this->posxprogress=174; // Only displayed for situation invoices
$this->postotalht=174;
@ -282,7 +292,7 @@ class pdf_crabe extends ModelePDFFactures
$this->atleastonediscount++;
}
}
if (empty($this->atleastonediscount))
if (empty($this->atleastonediscount) && empty($conf->global->PRODUCT_USE_UNITS))
{
$this->posxpicture+=($this->postotalht - $this->posxdiscount);
$this->posxtva+=($this->postotalht - $this->posxdiscount);
@ -486,7 +496,23 @@ class pdf_crabe extends ModelePDFFactures
// Quantity
$qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
$pdf->SetXY($this->posxqty, $curY);
$pdf->MultiCell($this->posxdiscount-$this->posxqty-0.8, 3, $qty, 0, 'R'); // Enough for 6 chars
// Enough for 6 chars
if($conf->global->PRODUCT_USE_UNITS)
{
$pdf->MultiCell($this->posxunit-$this->posxqty-0.8, 4, $qty, 0, 'R');
}
else
{
$pdf->MultiCell($this->posxdiscount-$this->posxqty-0.8, 4, $qty, 0, 'R');
}
// Unit
if($conf->global->PRODUCT_USE_UNITS)
{
$unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
$pdf->SetXY($this->posxunit, $curY);
$pdf->MultiCell($this->posxdiscount-$this->posxunit-0.8, 4, $unit, 0, 'L');
}
// Discount on line
if ($object->lines[$i]->remise_percent)
@ -1326,7 +1352,23 @@ class pdf_crabe extends ModelePDFFactures
if (empty($hidetop))
{
$pdf->SetXY($this->posxqty-1, $tab_top+1);
$pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
if($conf->global->PRODUCT_USE_UNITS)
{
$pdf->MultiCell($this->posxunit-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
}
else
{
$pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
}
}
if($conf->global->PRODUCT_USE_UNITS) {
$pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
if (empty($hidetop)) {
$pdf->SetXY($this->posxunit - 1, $tab_top + 1);
$pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities("Unit"), '',
'C');
}
}
$pdf->line($this->posxdiscount-1, $tab_top, $this->posxdiscount-1, $tab_top + $tab_height);

View File

@ -4,6 +4,7 @@
* Copyright (C) 2008 Raphael Bertrand <raphael.bertrand@resultic.fr>
* Copyright (C) 2010-2014 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
* Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -102,9 +103,19 @@ class pdf_azur extends ModelePDFPropales
// Define position of columns
$this->posxdesc=$this->marge_gauche+1;
$this->posxtva=112;
$this->posxup=126;
$this->posxqty=145;
if($conf->global->PRODUCT_USE_UNITS)
{
$this->posxtva=99;
$this->posxup=114;
$this->posxqty=133;
$this->posxunit=150;
}
else
{
$this->posxtva=112;
$this->posxup=126;
$this->posxqty=145;
}
$this->posxdiscount=162;
$this->postotalht=174;
if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) $this->posxtva=$this->posxup;
@ -265,7 +276,7 @@ class pdf_azur extends ModelePDFPropales
$this->atleastonediscount++;
}
}
if (empty($this->atleastonediscount))
if (empty($this->atleastonediscount) && empty($conf->global->PRODUCT_USE_UNITS))
{
$this->posxpicture+=($this->postotalht - $this->posxdiscount);
$this->posxtva+=($this->postotalht - $this->posxdiscount);
@ -459,9 +470,26 @@ class pdf_azur extends ModelePDFPropales
// Quantity
$qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails);
$pdf->SetXY($this->posxqty, $curY);
$pdf->MultiCell($this->posxdiscount-$this->posxqty-0.8, 3, $qty, 0, 'R'); // Enough for 6 chars
// Enough for 6 chars
if($conf->global->PRODUCT_USE_UNITS)
{
$pdf->MultiCell($this->posxunit-$this->posxqty-0.8, 4, $qty, 0, 'R');
}
else
{
$pdf->MultiCell($this->posxdiscount-$this->posxqty-0.8, 4, $qty, 0, 'R');
}
// Unit
if($conf->global->PRODUCT_USE_UNITS)
{
$unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
$pdf->SetXY($this->posxunit, $curY);
$pdf->MultiCell($this->posxdiscount-$this->posxunit-0.8, 4, $unit, 0, 'L');
}
// Discount on line
$pdf->SetXY($this->posxdiscount, $curY);
if ($object->lines[$i]->remise_percent)
{
$pdf->SetXY($this->posxdiscount-2, $curY);
@ -1217,7 +1245,23 @@ class pdf_azur extends ModelePDFPropales
if (empty($hidetop))
{
$pdf->SetXY($this->posxqty-1, $tab_top+1);
$pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
if($conf->global->PRODUCT_USE_UNITS)
{
$pdf->MultiCell($this->posxunit-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
}
else
{
$pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
}
}
if($conf->global->PRODUCT_USE_UNITS) {
$pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
if (empty($hidetop)) {
$pdf->SetXY($this->posxunit - 1, $tab_top + 1);
$pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities("Unit"), '',
'C');
}
}
$pdf->line($this->posxdiscount-1, $tab_top, $this->posxdiscount-1, $tab_top + $tab_height);

View File

@ -97,6 +97,13 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
$this->posxqty=145;
$this->posxdiscount=162;
$this->postotalht=174;
if($conf->global->PRODUCT_USE_UNITS) {
$this->posxtva=99;
$this->posxup=114;
$this->posxqty=133;
$this->posxunit=150;
}
//if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) $this->posxtva=$this->posxup;
$this->posxpicture=$this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH); // width of images
if ($this->page_largeur < 210) // To work with US executive format
@ -237,7 +244,7 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
$this->atleastonediscount++;
}
}
if (empty($this->atleastonediscount))
if (empty($this->atleastonediscount) && empty($conf->global->PRODUCT_USE_UNITS))
{
$this->posxpicture+=($this->postotalht - $this->posxdiscount);
$this->posxtva+=($this->postotalht - $this->posxdiscount);
@ -382,9 +389,30 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
$pdf->SetXY($this->posxup, $curY);
$pdf->MultiCell($this->posxqty-$this->posxup-0.8, 3, price($object->lines[$i]->pu_ht), 0, 'R', 0);
// Unit price before discount
$up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails);
$pdf->SetXY($this->posxup, $curY);
$pdf->MultiCell($this->posxqty-$this->posxup-0.8, 3, $up_excl_tax, 0, 'R', 0);
// Quantity
$pdf->SetXY($this->posxqty, $curY);
$pdf->MultiCell($this->posxdiscount-$this->posxqty-0.8, 3, $object->lines[$i]->qty, 0, 'R');
// Enough for 6 chars
if($conf->global->PRODUCT_USE_UNITS)
{
$pdf->MultiCell($this->posxunit-$this->posxqty-0.8, 4, $object->lines[$i]->qty, 0, 'R');
}
else
{
$pdf->MultiCell($this->posxdiscount-$this->posxqty-0.8, 4, $object->lines[$i]->qty, 0, 'R');
}
// Unit
if($conf->global->PRODUCT_USE_UNITS)
{
$unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
$pdf->SetXY($this->posxunit, $curY);
$pdf->MultiCell($this->posxdiscount-$this->posxunit-0.8, 4, $unit, 0, 'L');
}
// Discount on line
$pdf->SetXY($this->posxdiscount, $curY);
@ -790,7 +818,23 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
if (empty($hidetop))
{
$pdf->SetXY($this->posxqty-1, $tab_top+1);
$pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
if($conf->global->PRODUCT_USE_UNITS)
{
$pdf->MultiCell($this->posxunit-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
}
else
{
$pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
}
}
if($conf->global->PRODUCT_USE_UNITS) {
$pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
if (empty($hidetop)) {
$pdf->SetXY($this->posxunit - 1, $tab_top + 1);
$pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities("Unit"), '',
'C');
}
}
$pdf->line($this->posxdiscount-1, $tab_top, $this->posxdiscount-1, $tab_top + $tab_height);

View File

@ -103,11 +103,21 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
// Defini position des colonnes
$this->posxdesc=$this->marge_gauche+1;
$this->posxtva=112;
$this->posxup=126;
$this->posxqty=145;
$this->posxdiscount=162;
$this->postotalht=174;
if ($conf->global->PRODUCT_USE_UNITS)
{
$this->posxtva=99;
$this->posxup=114;
$this->posxqty=133;
$this->posxunit=150;
} else {
$this->posxtva=112;
$this->posxup=126;
$this->posxqty=145;
}
//if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) $this->posxtva=$this->posxup;
$this->posxpicture=$this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH); // width of images
if ($this->page_largeur < 210) // To work with US executive format
@ -245,7 +255,7 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
$this->atleastonediscount++;
}
}
if (empty($this->atleastonediscount))
if (empty($this->atleastonediscount) && empty($conf->global->PRODUCT_USE_UNITS))
{
$this->posxpicture+=($this->postotalht - $this->posxdiscount);
$this->posxtva+=($this->postotalht - $this->posxdiscount);
@ -392,7 +402,23 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
// Quantity
$pdf->SetXY($this->posxqty, $curY);
$pdf->MultiCell($this->posxdiscount-$this->posxqty-0.8, 3, $object->lines[$i]->qty, 0, 'R');
// Enough for 6 chars
if($conf->global->PRODUCT_USE_UNITS)
{
$pdf->MultiCell($this->posxunit-$this->posxqty-0.8, 4, $object->lines[$i]->qty, 0, 'R');
}
else
{
$pdf->MultiCell($this->posxdiscount-$this->posxqty-0.8, 4, $object->lines[$i]->qty, 0, 'R');
}
// Unit
if($conf->global->PRODUCT_USE_UNITS)
{
$unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager);
$pdf->SetXY($this->posxunit, $curY);
$pdf->MultiCell($this->posxdiscount-$this->posxunit-0.8, 4, $unit, 0, 'L');
}
// Discount on line
$pdf->SetXY($this->posxdiscount, $curY);
@ -910,7 +936,23 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
if (empty($hidetop))
{
$pdf->SetXY($this->posxqty-1, $tab_top+1);
$pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
if($conf->global->PRODUCT_USE_UNITS)
{
$pdf->MultiCell($this->posxunit-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
}
else
{
$pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C');
}
}
if($conf->global->PRODUCT_USE_UNITS) {
$pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height);
if (empty($hidetop)) {
$pdf->SetXY($this->posxunit - 1, $tab_top + 1);
$pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities("Unit"), '',
'C');
}
}
$pdf->line($this->posxdiscount-1, $tab_top, $this->posxdiscount-1, $tab_top + $tab_height);

View File

@ -61,6 +61,15 @@ if (in_array($object->element,array('propal', 'askpricesupplier','facture','invo
<td align="right"><span id="title_up_ttc"><?php echo $langs->trans('PriceUTTC'); ?></span></td>
<?php } ?>
<td align="right"><?php echo $langs->trans('Qty'); ?></td>
<?php
if($conf->global->PRODUCT_USE_UNITS)
{
print '<td align="left">';
print '<span id="title_units">';
print $langs->trans('Unit');
print '</span></td>';
}
?>
<td align="right"><?php echo $langs->trans('ReductionShort'); ?></td>
<?php
if ($this->situation_cycle_ref) {
@ -220,6 +229,14 @@ else {
<?php } ?>
<td align="right"><input type="text" size="2" name="qty" id="qty" class="flat" value="<?php echo (isset($_POST["qty"])?$_POST["qty"]:1); ?>">
</td>
<?php
if($conf->global->PRODUCT_USE_UNITS)
{
print '<td align="left">';
print $form->select_units($line->fk_unit, "units");
print '</td>';
}
?>
<td align="right" class="nowrap"><input type="text" size="1" name="remise_percent" id="remise_percent" class="flat" value="<?php echo (isset($_POST["remise_percent"])?$_POST["remise_percent"]:$buyer->remise_percent); ?>"><span class="hideonsmartphone">%</span></td>
<?php
if ($this->situation_cycle_ref) {
@ -303,6 +320,9 @@ if ((! empty($conf->service->enabled) || ($object->element == 'contrat')) && $da
if($this->situation_cycle_ref) $colspan++;
if (! empty($inputalsopricewithtax)) $colspan++; // We add 1 if col total ttc
if (in_array($object->element,array('propal','askpricesupplier','facture','invoice','commande','order','order_supplier','invoice_supplier'))) $colspan++; // With this, there is a column move button
if ($conf->global->PRODUCT_USE_UNITS) {
$colspan++;
}
if (! empty($usemargins))
{
@ -577,6 +597,7 @@ function setforfree() {
jQuery("#np_markRate").show(); // May no exists
jQuery(".np_marginRate").show(); // May no exists
jQuery(".np_markRate").show(); // May no exists
jQuery("#units, #title_units").show();
}
function setforpredef() {
jQuery("#select_type").val(-1);
@ -593,6 +614,8 @@ function setforpredef() {
jQuery("#np_markRate").hide(); // May no exists
jQuery(".np_marginRate").hide(); // May no exists
jQuery(".np_markRate").hide(); // May no exists
jQuery(".np_markRate").hide(); // May no exists
jQuery("#units, #title_units").hide();
}
</script>

View File

@ -129,7 +129,6 @@ $coldisplay=-1; // We remove first td
print '></td>';
}
?>
<td align="right"><?php $coldisplay++; ?>
<?php if (($line->info_bits & 2) != 2) {
// I comment this because it shows info even when not required
@ -144,6 +143,15 @@ $coldisplay=-1; // We remove first td
<?php } ?>
</td>
<?php
if($conf->global->PRODUCT_USE_UNITS)
{
print '<td align="left">';
$form->select_units($line->fk_unit, "units");
print '</td>';
}
?>
<td align="right" nowrap><?php $coldisplay++; ?>
<?php if (($line->info_bits & 2) != 2) {
print '<input size="1" type="text" class="flat" name="remise_percent" id="remise_percent" value="' . $line->remise_percent . '"';

View File

@ -145,6 +145,18 @@ if (empty($usemargins)) $usemargins=0;
} else echo '&nbsp;'; ?>
</td>
<?php
if($conf->global->PRODUCT_USE_UNITS)
{
print '<td align="left" nowrap="nowrap">';
$label = $line->get_unit_label('short');
if ($label !== '') {
print $langs->trans($label);
}
print '</td>';
}
?>
<?php if (!empty($line->remise_percent) && $line->special_code != 3) { ?>
<td align="right"><?php
$coldisplay++;

View File

@ -24,6 +24,9 @@
<td align="right"><?php echo $this->tpl['vat_rate']; ?></td>
<td align="right"><?php echo $this->tpl['price']; ?></td>
<td align="right"><?php echo $this->tpl['qty']; ?></td>
<?php
if($conf->global->PRODUCT_USE_UNITS) echo '<td align="left">'.$langs->trans($this->tpl['unit']).'</td>';
?>
<td align="right"><?php echo $this->tpl['remise_percent']; ?></td>
</tr>
<!-- END PHP TEMPLATE originproductline.tpl.php -->
<!-- END PHP TEMPLATE originproductline.tpl.php -->

View File

@ -247,6 +247,7 @@ class CommandeFournisseur extends CommonOrder
$sql.= " l.localtax1_tx, l. localtax2_tx, l.total_localtax1, l.total_localtax2,";
$sql.= " l.total_ht, l.total_tva, l.total_ttc, l.special_code, l.fk_parent_line, l.rang,";
$sql.= " p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.description as product_desc,";
$sql.= " l.fk_unit,";
$sql.= " l.date_start, l.date_end";
$sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as l";
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
@ -297,9 +298,10 @@ class CommandeFournisseur extends CommonOrder
$line->date_start = $this->db->jdate($objp->date_start);
$line->date_end = $this->db->jdate($objp->date_end);
$line->fk_unit = $objp->fk_unit;
$this->special_line = $objp->special_line;
$this->fk_parent_line = $objp->fk_parent_line;
$this->special_line = $objp->special_line;
$this->fk_parent_line = $objp->fk_parent_line;
$this->rang = $objp->rang;
@ -1196,13 +1198,14 @@ class CommandeFournisseur extends CommonOrder
* @param int $date_start Date start of service
* @param int $date_end Date end of service
* @param array $array_options extrafields array
* @param int $fk_unit Id of the unit to use. Null to use the default one
* @return int <=0 if KO, >0 if OK
*/
function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0.0, $txlocaltax2=0.0, $fk_product=0, $fk_prod_fourn_price=0, $fourn_ref='', $remise_percent=0.0, $price_base_type='HT', $pu_ttc=0.0, $type=0, $info_bits=0, $notrigger=false, $date_start=null, $date_end=null, $array_options=0)
function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0.0, $txlocaltax2=0.0, $fk_product=0, $fk_prod_fourn_price=0, $fourn_ref='', $remise_percent=0.0, $price_base_type='HT', $pu_ttc=0.0, $type=0, $info_bits=0, $notrigger=false, $date_start=null, $date_end=null, $array_options=0, $fk_unit = null)
{
global $langs,$mysoc;
dol_syslog(get_class($this)."::addline $desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2. $fk_product, $fk_prod_fourn_price, $fourn_ref, $remise_percent, $price_base_type, $pu_ttc, $type");
dol_syslog(get_class($this)."::addline $desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2. $fk_product, $fk_prod_fourn_price, $fourn_ref, $remise_percent, $price_base_type, $pu_ttc, $type, $fk_unit");
include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
// Clean parameters
@ -1305,7 +1308,7 @@ class CommandeFournisseur extends CommonOrder
$sql.= " (fk_commande, label, description, date_start, date_end,";
$sql.= " fk_product, product_type,";
$sql.= " qty, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, remise_percent, subprice, ref,";
$sql.= " total_ht, total_tva, total_localtax1, total_localtax2, total_ttc";
$sql.= " total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, fk_unit";
$sql.= ")";
$sql.= " VALUES (".$this->id.", '" . $this->db->escape($label) . "','" . $this->db->escape($desc) . "',";
$sql.= " ".($date_start?"'".$this->db->idate($date_start)."'":"null").",";
@ -1323,7 +1326,8 @@ class CommandeFournisseur extends CommonOrder
$sql.= "'".price2num($total_tva)."',";
$sql.= "'".price2num($total_localtax1)."',";
$sql.= "'".price2num($total_localtax2)."',";
$sql.= "'".price2num($total_ttc)."'";
$sql.= "'".price2num($total_ttc)."',";
$sql.= (!$fk_unit ? 'NULL' : $fk_unit);
$sql.= ")";
dol_syslog(get_class($this)."::addline", LOG_DEBUG);
@ -1989,12 +1993,13 @@ class CommandeFournisseur extends CommonOrder
* @param timestamp $date_start Date start of service
* @param timestamp $date_end Date end of service
* @param array $array_options extrafields array
* @param int $fk_unit Id of the unit to use. Null to use the default one
* @return int < 0 if error, > 0 if ok
*/
function updateline($rowid, $desc, $pu, $qty, $remise_percent, $txtva, $txlocaltax1=0, $txlocaltax2=0, $price_base_type='HT', $info_bits=0, $type=0, $notrigger=false, $date_start='', $date_end='', $array_options=0)
function updateline($rowid, $desc, $pu, $qty, $remise_percent, $txtva, $txlocaltax1=0, $txlocaltax2=0, $price_base_type='HT', $info_bits=0, $type=0, $notrigger=false, $date_start='', $date_end='', $array_options=0, $fk_unit = null)
{
global $mysoc;
dol_syslog(get_class($this)."::updateline $rowid, $desc, $pu, $qty, $remise_percent, $txtva, $price_base_type, $info_bits, $type");
dol_syslog(get_class($this)."::updateline $rowid, $desc, $pu, $qty, $remise_percent, $txtva, $price_base_type, $info_bits, $type, $fk_unit");
include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
if ($this->brouillon)
@ -2061,6 +2066,7 @@ class CommandeFournisseur extends CommonOrder
$sql.= ",total_localtax2='".price2num($total_localtax2)."'";
$sql.= ",total_ttc='".price2num($total_ttc)."'";
$sql.= ",product_type=".$type;
$sql.= ",fk_unit=".(!$fk_unit ? 'NULL' : $fk_unit);
$sql.= " WHERE rowid = ".$rowid;
dol_syslog(get_class($this)."::updateline", LOG_DEBUG);
@ -2493,7 +2499,7 @@ class CommandeFournisseurLigne extends CommonOrderLine
$sql.= ' cd.info_bits, cd.total_ht, cd.total_tva, cd.total_ttc,';
$sql.= ' cd.total_localtax1, cd.total_localtax2,';
$sql.= ' p.ref as product_ref, p.label as product_libelle, p.description as product_desc,';
$sql.= ' cd.date_start, cd.date_end';
$sql.= ' cd.date_start, cd.date_end, cd.fk_unit';
$sql.= ' FROM '.MAIN_DB_PREFIX.'commande_fournisseurdet as cd';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON cd.fk_product = p.rowid';
$sql.= ' WHERE cd.rowid = '.$rowid;
@ -2526,6 +2532,7 @@ class CommandeFournisseurLigne extends CommonOrderLine
$this->date_start = $this->db->jdate($objp->date_start);
$this->date_end = $this->db->jdate($objp->date_end);
$this->fk_unit = $objp->fk_unit;
$this->db->free($result);
return 1;

View File

@ -480,7 +480,7 @@ class FactureFournisseur extends CommonInvoice
{
$sql = 'SELECT f.rowid, f.ref as ref_supplier, f.description, f.pu_ht, f.pu_ttc, f.qty, f.remise_percent, f.tva_tx';
$sql.= ', f.localtax1_tx, f.localtax2_tx, f.total_localtax1, f.total_localtax2 ';
$sql.= ', f.total_ht, f.tva as total_tva, f.total_ttc, f.fk_product, f.product_type, f.info_bits, f.rang, f.special_code, f.fk_parent_line';
$sql.= ', f.total_ht, f.tva as total_tva, f.total_ttc, f.fk_product, f.product_type, f.info_bits, f.rang, f.special_code, f.fk_parent_line, f.fk_unit';
$sql.= ', p.rowid as product_id, p.ref as product_ref, p.label as label, p.description as product_desc';
$sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn_det as f';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON f.fk_product = p.rowid';
@ -531,6 +531,7 @@ class FactureFournisseur extends CommonInvoice
$this->lines[$i]->fk_parent_line = $obj->fk_parent_line;
$this->lines[$i]->special_code = $obj->special_code;
$this->lines[$i]->rang = $obj->rang;
$this->lines[$i]->fk_unit = $obj->fk_unit;
$i++;
}
@ -1117,13 +1118,14 @@ class FactureFournisseur extends CommonInvoice
* @param int $rang Position of line
* @param int $notrigger Disable triggers
* @param array $array_options extrafields array
* @param int $fk_unit Id of the unit to use. Null to use the default one
* @return int >0 if OK, <0 if KO
*
* FIXME Add field ref (that should be named ref_supplier) and label into update. For example can be filled when product line created from order.
*/
function addline($desc, $pu, $txtva, $txlocaltax1, $txlocaltax2, $qty, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits='', $price_base_type='HT', $type=0, $rang=-1, $notrigger=false, $array_options=0)
function addline($desc, $pu, $txtva, $txlocaltax1, $txlocaltax2, $qty, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits='', $price_base_type='HT', $type=0, $rang=-1, $notrigger=false, $array_options=0, $fk_unit = null)
{
dol_syslog(get_class($this)."::addline $desc,$pu,$qty,$txtva,$fk_product,$remise_percent,$date_start,$date_end,$ventil,$info_bits,$price_base_type,$type", LOG_DEBUG);
dol_syslog(get_class($this)."::addline $desc,$pu,$qty,$txtva,$fk_product,$remise_percent,$date_start,$date_end,$ventil,$info_bits,$price_base_type,$type,$fk_unit", LOG_DEBUG);
include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
// Clean parameters
@ -1158,7 +1160,7 @@ class FactureFournisseur extends CommonInvoice
{
$idligne = $this->db->last_insert_id(MAIN_DB_PREFIX.'facture_fourn_det');
$result=$this->updateline($idligne, $desc, $pu, $txtva, $txlocaltax1, $txlocaltax2, $qty, $fk_product, $price_base_type, $info_bits, $type, $remise_percent, true, '', '', $array_options);
$result=$this->updateline($idligne, $desc, $pu, $txtva, $txlocaltax1, $txlocaltax2, $qty, $fk_product, $price_base_type, $info_bits, $type, $remise_percent, true, '', '', $array_options, $fk_unit);
if ($result > 0)
{
$this->rowid = $idligne;
@ -1213,12 +1215,13 @@ class FactureFournisseur extends CommonInvoice
* @param timestamp $date_start Date start of service
* @param timestamp $date_end Date end of service
* @param array $array_options extrafields array
* @param int $fk_unit Id of the unit to use. Null to use the default one
* @return int <0 if KO, >0 if OK
*/
function updateline($id, $desc, $pu, $vatrate, $txlocaltax1=0, $txlocaltax2=0, $qty=1, $idproduct=0, $price_base_type='HT', $info_bits=0, $type=0, $remise_percent=0, $notrigger=false, $date_start='', $date_end='', $array_options=0)
function updateline($id, $desc, $pu, $vatrate, $txlocaltax1=0, $txlocaltax2=0, $qty=1, $idproduct=0, $price_base_type='HT', $info_bits=0, $type=0, $remise_percent=0, $notrigger=false, $date_start='', $date_end='', $array_options=0, $fk_unit = null)
{
global $mysoc;
dol_syslog(get_class($this)."::updateline $id,$desc,$pu,$vatrate,$qty,$idproduct,$price_base_type,$info_bits,$type,$remise_percent", LOG_DEBUG);
dol_syslog(get_class($this)."::updateline $id,$desc,$pu,$vatrate,$qty,$idproduct,$price_base_type,$info_bits,$type,$remise_percent,$fk_unit", LOG_DEBUG);
include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
$pu = price2num($pu);
@ -1288,6 +1291,7 @@ class FactureFournisseur extends CommonInvoice
else $sql.= ", fk_product = null";
$sql.= ", product_type = ".$product_type;
$sql.= ", info_bits = ".$info_bits;
$sql .= ", fk_unit=".(!$fk_unit ? 'NULL' : $fk_unit);
$sql.= " WHERE rowid = ".$id;
dol_syslog(get_class($this)."::updateline", LOG_DEBUG);
@ -1877,7 +1881,7 @@ class FactureFournisseur extends CommonInvoice
/**
* Class to manage line invoices
*/
class SupplierInvoiceLine extends CommonInvoice
class SupplierInvoiceLine extends CommonObjectLine
{
public $element='facture_fourn_det';
public $table_element='facture_fourn_det';

View File

@ -347,7 +347,8 @@ if (empty($reshook))
'',
$date_start,
$date_end,
$array_options
$array_options,
$productsupplier->fk_unit
);
}
if ($idprod == -99 || $idprod == 0)
@ -375,6 +376,12 @@ if (empty($reshook))
$desc = $product_desc;
$type = GETPOST('type');
$fk_unit= GETPOST('units', 'int');
if ($fk_unit <= 0) {
$fk_unit = null;
}
$tva_tx = price2num($tva_tx); // When vat is text input field
// Local Taxes
@ -385,15 +392,16 @@ if (empty($reshook))
{
$price_base_type = 'HT';
$ht = price2num(GETPOST('price_ht'));
$result=$object->addline($desc, $ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', $remise_percent, $price_base_type, 0, $type,'','', $date_start, $date_end, $array_options);
$ttc = 0;
}
else
{
$ttc = price2num(GETPOST('price_ttc'));
$ht = $ttc / (1 + ($tva_tx / 100));
$price_base_type = 'HT';
$result=$object->addline($desc, $ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', $remise_percent, $price_base_type, $ttc, $type,'','', $date_start, $date_end, $array_options);
}
$result=$object->addline($desc, $ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', $remise_percent, $price_base_type, $ttc, $type,'','', $date_start, $date_end, $array_options, $fk_unit);
}
//print "xx".$tva_tx; exit;
@ -513,7 +521,8 @@ if (empty($reshook))
false,
$date_start,
$date_end,
$array_options
$array_options,
$_POST['units']
);
unset($_POST['qty']);
unset($_POST['type']);
@ -525,6 +534,7 @@ if (empty($reshook))
unset($_POST['tva_tx']);
unset($_POST['date_start']);
unset($_POST['date_end']);
unset($_POST['units']);
unset($localtax1_tx);
unset($localtax2_tx);
@ -989,7 +999,9 @@ if (empty($reshook))
'',
'',
null,
null
null,
array(),
$lines[$i]->fk_unit
);
if ($result < 0) {

View File

@ -207,7 +207,7 @@ if (($action == 'create' || $action == 'add') && empty($mesgs)) {
$fk_parent_line = 0;
}
// FIXME Missing $lines[$i]->ref_supplier and $lines[$i]->label into addline and updateline methods. They are filled when coming from order for example.
$result = $object->addline($desc, $lines[$i]->subprice, $lines[$i]->tva_tx, $lines[$i]->localtax1_tx, $lines[$i]->localtax2_tx, $lines[$i]->qty, $lines[$i]->fk_product, $lines[$i]->remise_percent, $date_start, $date_end, 0, $lines[$i]->info_bits, 'HT', $product_type);
$result = $object->addline($desc, $lines[$i]->subprice, $lines[$i]->tva_tx, $lines[$i]->localtax1_tx, $lines[$i]->localtax2_tx, $lines[$i]->qty, $lines[$i]->fk_product, $lines[$i]->remise_percent, $date_start, $date_end, 0, $lines[$i]->info_bits, 'HT', $product_type, -1, false, 0, $lines[$i]->fk_unit);
if ($result > 0) {
$lineid = $result;

View File

@ -444,7 +444,8 @@ if (empty($reshook))
$product_type,
$lines[$i]->rang,
1,
$lines[$i]->array_options
$lines[$i]->array_options,
$lines[$i]->fk_unit
);
if ($result < 0)
@ -587,7 +588,7 @@ if (empty($reshook))
}
}
$result=$object->updateline(GETPOST('lineid'), $label, $up, $tva_tx, $localtax1_tx, $localtax2_tx, GETPOST('qty'), GETPOST('productid'), $price_base_type, 0, $type, $remise_percent, 0, $date_start, $date_end, $array_options);
$result=$object->updateline(GETPOST('lineid'), $label, $up, $tva_tx, $localtax1_tx, $localtax2_tx, GETPOST('qty'), GETPOST('productid'), $price_base_type, 0, $type, $remise_percent, 0, $date_start, $date_end, $array_options, $_POST['units']);
if ($result >= 0)
{
unset($_POST['label']);
@ -684,6 +685,7 @@ if (empty($reshook))
$idprod=$productsupplier->get_buyprice(GETPOST('idprodfournprice'), $qty); // Just to see if a price exists for the quantity. Not used to found vat.
}
//Replaces $fk_unit with the product's
if ($idprod > 0)
{
$result=$productsupplier->fetch($idprod);
@ -703,7 +705,7 @@ if (empty($reshook))
$price_base_type = 'HT';
// TODO Save the product supplier ref into database into field ref_supplier (must rename field ref into ref_supplier first)
$result=$object->addline($desc, $productsupplier->fourn_pu, $tvatx, $localtax1_tx, $localtax2_tx, $qty, $idprod, $remise_percent, '', '', 0, $npr, $price_base_type, $type, -1, 0, $array_options);
$result=$object->addline($desc, $productsupplier->fourn_pu, $tvatx, $localtax1_tx, $localtax2_tx, $qty, $idprod, $remise_percent, '', '', 0, $npr, $price_base_type, $type, -1, 0, $array_options, $productsupplier->fk_unit);
}
if ($idprod == -2 || $idprod == 0)
{
@ -730,6 +732,12 @@ if (empty($reshook))
$desc = $product_desc;
$type = GETPOST('type');
$fk_unit= GETPOST('units', 'int');
if ($fk_unit <= 0) {
$fk_unit = null;
}
$tva_tx = price2num($tva_tx); // When vat is text input field
// Local Taxes
@ -740,18 +748,15 @@ if (empty($reshook))
{
$ht = price2num($_POST['price_ht']);
$price_base_type = 'HT';
//print $product_desc, $pu, $txtva, $qty, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits='', $price_base_type='HT', $type=0
$result=$object->addline($product_desc, $ht, $tva_tx, $localtax1_tx, $localtax2_tx, $qty, 0, $remise_percent, $datestart, $dateend, 0, $npr, $price_base_type, $type, -1, 0, $array_options);
}
else
{
$ttc = price2num($_POST['price_ttc']);
$ht = $ttc / (1 + ($tva_tx / 100));
$price_base_type = 'HT';
//print $product_desc, $pu, $txtva, $qty, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits='', $price_base_type='HT', $type=0
$result=$object->addline($product_desc, $ht, $tva_tx,$localtax1_tx, $localtax2_tx, $qty, 0, $remise_percent, $datestart, $dateend, 0, $npr, $price_base_type, $type, -1, 0, $array_options);
}
$result=$object->addline($product_desc, $ht, $tva_tx, $localtax1_tx, $localtax2_tx, $qty, 0, $remise_percent, $datestart, $dateend, 0, $npr, $price_base_type, $type, -1, 0, $array_options, $fk_unit);
}
//print "xx".$tva_tx; exit;
@ -793,6 +798,7 @@ if (empty($reshook))
unset($_POST['np_markRate']);
unset($_POST['dp_desc']);
unset($_POST['idprodfournprice']);
unset($_POST['units']);
unset($_POST['date_starthour']);
unset($_POST['date_startmin']);

View File

@ -0,0 +1,31 @@
-- ========================================================================
-- Copyright (C) 2001-2002,2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
-- Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net>
-- Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
-- ========================================================================
INSERT INTO llx_c_units ( code, label, short_label, active) VALUES ('P','piece','p', 1);
INSERT INTO llx_c_units ( code, label, short_label, active) VALUES ('SET','set','se', 1);
INSERT INTO llx_c_units ( code, label, short_label, active) VALUES ('S','second','s', 1);
INSERT INTO llx_c_units ( code, label, short_label, active) VALUES ('H','hour','h', 1);
INSERT INTO llx_c_units ( code, label, short_label, active) VALUES ('D','day','d', 1);
INSERT INTO llx_c_units ( code, label, short_label, active) VALUES ('KG','kilogram','kg', 1);
INSERT INTO llx_c_units ( code, label, short_label, active) VALUES ('G','gram','g', 1);
INSERT INTO llx_c_units ( code, label, short_label, active) VALUES ('M','meter','m', 1);
INSERT INTO llx_c_units ( code, label, short_label, active) VALUES ('LM','linear meter','lm', 1);
INSERT INTO llx_c_units ( code, label, short_label, active) VALUES ('M2','square meter','m2', 1);
INSERT INTO llx_c_units ( code, label, short_label, active) VALUES ('M3','cubic meter','m3', 1);
INSERT INTO llx_c_units ( code, label, short_label, active) VALUES ('L','liter','l', 1);

46
htdocs/install/mysql/migration/3.7.0-3.8.0.sql Normal file → Executable file
View File

@ -538,3 +538,49 @@ ALTER TABLE llx_categorie_societe CHANGE COLUMN fk_societe fk_soc INTEGER NOT NU
ALTER TABLE llx_categorie_fournisseur CHANGE COLUMN fk_societe fk_soc INTEGER NOT NULL;
ALTER TABLE llx_societe CHANGE COLUMN fk_societe fk_soc INTEGER NOT NULL;
ALTER TABLE llx_user CHANGE COLUMN fk_societe fk_soc INTEGER NOT NULL;
-- Units
create table llx_c_units(
rowid integer AUTO_INCREMENT PRIMARY KEY,
code varchar(3),
label varchar(50),
short_label varchar(5),
active tinyint DEFAULT 1 NOT NULL
)ENGINE=innodb;
ALTER TABLE llx_c_units ADD UNIQUE uk_c_units_code(code);
INSERT INTO llx_c_units ( code, label, short_label, active) VALUES ('P','piece','p', 1);
INSERT INTO llx_c_units ( code, label, short_label, active) VALUES ('SET','set','se', 1);
INSERT INTO llx_c_units ( code, label, short_label, active) VALUES ('S','second','s', 1);
INSERT INTO llx_c_units ( code, label, short_label, active) VALUES ('H','hour','h', 1);
INSERT INTO llx_c_units ( code, label, short_label, active) VALUES ('D','day','d', 1);
INSERT INTO llx_c_units ( code, label, short_label, active) VALUES ('KG','kilogram','kg', 1);
INSERT INTO llx_c_units ( code, label, short_label, active) VALUES ('G','gram','g', 1);
INSERT INTO llx_c_units ( code, label, short_label, active) VALUES ('M','meter','m', 1);
INSERT INTO llx_c_units ( code, label, short_label, active) VALUES ('LM','linear meter','lm', 1);
INSERT INTO llx_c_units ( code, label, short_label, active) VALUES ('M2','square meter','m2', 1);
INSERT INTO llx_c_units ( code, label, short_label, active) VALUES ('M3','cubic meter','m3', 1);
INSERT INTO llx_c_units ( code, label, short_label, active) VALUES ('L','liter','l', 1);
alter table llx_product add fk_unit integer default NULL;
ALTER TABLE llx_product ADD CONSTRAINT fk_product_fk_unit FOREIGN KEY (fk_unit) REFERENCES llx_c_units (rowid);
alter table llx_facturedet_rec add fk_unit integer default NULL;
ALTER TABLE llx_facturedet_rec ADD CONSTRAINT fk_facturedet_rec_fk_unit FOREIGN KEY (fk_unit) REFERENCES llx_c_units (rowid);
alter table llx_facturedet add fk_unit integer default NULL;
ALTER TABLE llx_facturedet ADD CONSTRAINT fk_facturedet_fk_unit FOREIGN KEY (fk_unit) REFERENCES llx_c_units (rowid);
alter table llx_propaldet add fk_unit integer default NULL;
ALTER TABLE llx_propaldet ADD CONSTRAINT fk_propaldet_fk_unit FOREIGN KEY (fk_unit) REFERENCES llx_c_units (rowid);
alter table llx_commandedet add fk_unit integer default NULL;
ALTER TABLE llx_commandedet ADD CONSTRAINT fk_commandedet_fk_unit FOREIGN KEY (fk_unit) REFERENCES llx_c_units (rowid);
alter table llx_contratdet add fk_unit integer default NULL;
ALTER TABLE llx_contratdet ADD CONSTRAINT fk_contratdet_fk_unit FOREIGN KEY (fk_unit) REFERENCES llx_c_units (rowid);
alter table llx_commande_fournisseurdet add fk_unit integer default NULL;
ALTER TABLE llx_commande_fournisseurdet ADD CONSTRAINT fk_commande_fournisseurdet_fk_unit FOREIGN KEY (fk_unit) REFERENCES llx_c_units (rowid);
alter table llx_facture_fourn_det add fk_unit integer default NULL;
ALTER TABLE llx_facture_fourn_det ADD CONSTRAINT fk_facture_fourn_det_fk_unit FOREIGN KEY (fk_unit) REFERENCES llx_c_units (rowid);

View File

@ -0,0 +1,21 @@
-- ========================================================================
-- Copyright (C) 2005 Laurent Destailleur <eldy@users.sourceforge.net>
-- Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
-- ========================================================================
ALTER TABLE llx_c_units ADD UNIQUE uk_c_units_code(code);

View File

@ -0,0 +1,27 @@
-- ========================================================================
-- Copyright (C) 2001-2002,2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
-- Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net>
-- Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
-- ========================================================================
create table llx_c_units(
rowid integer AUTO_INCREMENT PRIMARY KEY,
code varchar(3),
label varchar(50),
short_label varchar(5),
active tinyint DEFAULT 1 NOT NULL
)ENGINE=innodb;

View File

@ -66,5 +66,5 @@ create table llx_commande_fournisseur
location_incoterms varchar(255), -- for incoterms
import_key varchar(14),
extraparams varchar(255) -- for stock other parameters with json format
)ENGINE=innodb;

View File

@ -0,0 +1,19 @@
-- ============================================================================
-- Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
-- ============================================================================
ALTER TABLE llx_commande_fournisseurdet ADD CONSTRAINT fk_commande_fournisseurdet_fk_unit FOREIGN KEY (fk_unit) REFERENCES llx_c_units (rowid);

View File

@ -2,6 +2,7 @@
-- Copyright (C) 2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
-- Copyright (C) 2007-2009 Laurent Destailleur <eldy@users.sourceforge.net>
-- Copyright (C) 2010-2012 Juanjo Menent <jmenent@2byte.es>
-- Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
@ -47,5 +48,6 @@ create table llx_commande_fournisseurdet
info_bits integer DEFAULT 0, -- TVA NPR ou non
special_code integer DEFAULT 0, -- code pour les lignes speciales
rang integer DEFAULT 0,
import_key varchar(14)
import_key varchar(14),
fk_unit integer DEFAULT NULL
)ENGINE=innodb;

View File

@ -1,6 +1,7 @@
-- ===================================================================
-- Copyright (C) 2006 Laurent Destailleur <eldy@users.sourceforge.net>
-- Copyright (C) 2011 Regis Houssin <regis.houssin@capnetworks.com>
-- Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
@ -22,4 +23,5 @@
ALTER TABLE llx_commandedet ADD INDEX idx_commandedet_fk_commande (fk_commande);
ALTER TABLE llx_commandedet ADD INDEX idx_commandedet_fk_product (fk_product);
ALTER TABLE llx_commandedet ADD CONSTRAINT fk_commandedet_fk_unit FOREIGN KEY (fk_unit) REFERENCES llx_c_units (rowid);
ALTER TABLE llx_commandedet ADD CONSTRAINT fk_commandedet_fk_commande FOREIGN KEY (fk_commande) REFERENCES llx_commande (rowid);

View File

@ -3,6 +3,7 @@
-- Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
-- Copyright (C) 2006-2009 Laurent Destailleur <eldy@users.sourceforge.net>
-- Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
-- Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
@ -53,6 +54,7 @@ create table llx_commandedet
special_code integer DEFAULT 0, -- code pour les lignes speciales
rang integer DEFAULT 0,
fk_unit integer DEFAULT NULL, -- lien vers table des unités
import_key varchar(14)
)ENGINE=innodb;

View File

@ -27,3 +27,5 @@ ALTER TABLE llx_contratdet ADD INDEX idx_contratdet_date_fin_validite (date_fin_
ALTER TABLE llx_contratdet ADD CONSTRAINT fk_contratdet_fk_contrat FOREIGN KEY (fk_contrat) REFERENCES llx_contrat (rowid);
ALTER TABLE llx_contratdet ADD CONSTRAINT fk_contratdet_fk_product FOREIGN KEY (fk_product) REFERENCES llx_product (rowid);
ALTER TABLE llx_contratdet ADD CONSTRAINT fk_contratdet_fk_unit FOREIGN KEY (fk_unit) REFERENCES llx_c_units (rowid);

View File

@ -61,6 +61,7 @@ create table llx_contratdet
fk_user_author integer NOT NULL DEFAULT 0,
fk_user_ouverture integer,
fk_user_cloture integer,
commentaire text
commentaire text,
fk_unit integer DEFAULT NULL
)ENGINE=innodb;

View File

@ -22,3 +22,4 @@
ALTER TABLE llx_facture_fourn_det ADD INDEX idx_facture_fourn_det_fk_facture (fk_facture_fourn);
ALTER TABLE llx_facture_fourn_det ADD CONSTRAINT fk_facture_fourn_det_fk_facture FOREIGN KEY (fk_facture_fourn) REFERENCES llx_facture_fourn (rowid);
ALTER TABLE llx_facture_fourn_det ADD CONSTRAINT fk_facture_fourn_det_fk_unit FOREIGN KEY (fk_unit) REFERENCES llx_c_units (rowid);

View File

@ -48,5 +48,6 @@ create table llx_facture_fourn_det
fk_code_ventilation integer DEFAULT 0 NOT NULL,
special_code integer DEFAULT 0, -- code pour les lignes speciales
rang integer DEFAULT 0,
import_key varchar(14)
import_key varchar(14),
fk_unit integer DEFAULT NULL
)ENGINE=innodb;

View File

@ -1,6 +1,7 @@
-- ===================================================================
-- Copyright (C) 2005 Laurent Destailleur <eldy@users.sourceforge.net>
-- Copyright (C) 2011 Regis Houssin <regis.houssin@capnetworks.com>
-- Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
@ -25,3 +26,4 @@ ALTER TABLE llx_facturedet ADD INDEX idx_facturedet_fk_facture (fk_facture);
ALTER TABLE llx_facturedet ADD INDEX idx_facturedet_fk_product (fk_product);
ALTER TABLE llx_facturedet ADD UNIQUE INDEX uk_fk_remise_except (fk_remise_except, fk_facture);
ALTER TABLE llx_facturedet ADD CONSTRAINT fk_facturedet_fk_facture FOREIGN KEY (fk_facture) REFERENCES llx_facture (rowid);
ALTER TABLE llx_facturedet ADD CONSTRAINT fk_facturedet_fk_unit FOREIGN KEY (fk_unit) REFERENCES llx_c_units (rowid);

View File

@ -60,7 +60,8 @@ create table llx_facturedet
import_key varchar(14),
situation_percent real, -- % progression of lines invoicing
fk_prev_id integer -- id of the line in the previous situation
fk_prev_id integer, -- id of the line in the previous situation,
fk_unit integer DEFAULT NULL -- id of the unit code¡
)ENGINE=innodb;

View File

@ -0,0 +1,21 @@
-- ===================================================================
-- Copyright (C) 2005 Laurent Destailleur <eldy@users.sourceforge.net>
-- Copyright (C) 2011 Regis Houssin <regis@dolibarr.fr>
-- Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
-- ===================================================================
ALTER TABLE llx_facturedet_rec ADD CONSTRAINT fk_facturedet_rec_fk_unit FOREIGN KEY (fk_unit) REFERENCES llx_c_units (rowid);

View File

@ -3,6 +3,7 @@
-- Copyright (C) 2009-2014 Laurent Destailleur <eldy@users.sourceforge.net>
-- Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
-- Copyright (C) 2010-2012 Regis Houssin <regis.houssin@capnetworks.com>
-- Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
@ -46,5 +47,6 @@ create table llx_facturedet_rec
info_bits integer DEFAULT 0, -- TVA NPR ou non
special_code integer UNSIGNED DEFAULT 0, -- code pour les lignes speciales
rang integer DEFAULT 0, -- ordre d'affichage
fk_contract_line integer NULL -- id of contract line when predefined invoice comes from contract lines
fk_contract_line integer NULL, -- id of contract line when predefined invoice comes from contract lines
fk_unit integer DEFAULT NULL
)ENGINE=innodb;

View File

@ -2,6 +2,7 @@
-- Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
-- Copyright (C) 2004-2013 Laurent Destailleur <eldy@users.sourceforge.net>
-- Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
-- Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
-- Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
--
-- This program is free software; you can redistribute it and/or modify
@ -30,7 +31,7 @@ ALTER TABLE llx_product ADD INDEX idx_product_fk_country (fk_country);
ALTER TABLE llx_product ADD INDEX idx_product_fk_user_author (fk_user_author);
ALTER TABLE llx_product ADD INDEX idx_product_fk_barcode_type (fk_barcode_type);
ALTER TABLE llx_product ADD UNIQUE INDEX uk_product_barcode (barcode, fk_barcode_type, entity);
ALTER TABLE llx_product ADD CONSTRAINT fk_product_fk_unit FOREIGN KEY (fk_unit) REFERENCES llx_c_units (rowid);
ALTER TABLE llx_product ADD CONSTRAINT fk_product_fk_country FOREIGN KEY (fk_country) REFERENCES llx_c_country (rowid);
ALTER TABLE llx_product ADD CONSTRAINT fk_product_barcode_type FOREIGN KEY (fk_barcode_type) REFERENCES llx_c_barcode_type (rowid);

View File

@ -2,8 +2,8 @@
-- Copyright (C) 2002-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
-- Copyright (C) 2008-2010 Laurent Destailleur <eldy@users.sourceforge.net>
-- Copyright (C) 2005-2010 Regis Houssin <regis.houssin@capnetworks.com>
-- Copyright (C) 2010 juanjo Menent <jmenent@2byte.es>
-- Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
-- Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
-- Copyright (C) 2012-2013 Cédric Salvador <csalvador@gpcsolutions.fr>
-- Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
--
-- This program is free software; you can redistribute it and/or modify
@ -77,5 +77,6 @@ create table llx_product
hidden tinyint DEFAULT 0, -- Not used. Deprecated.
import_key varchar(14), -- Import key
fk_price_expression integer, -- Link to the rule for dynamic price calculation
desiredstock integer DEFAULT 0
desiredstock integer DEFAULT 0,
fk_unit integer DEFAULT NULL
)ENGINE=innodb;

View File

@ -1,5 +1,6 @@
-- ===================================================================
-- Copyright (C) 2009-2011 Regis Houssin <regis.houssin@capnetworks.com>
-- Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
@ -21,4 +22,5 @@
ALTER TABLE llx_propaldet ADD INDEX idx_propaldet_fk_propal (fk_propal);
ALTER TABLE llx_propaldet ADD INDEX idx_propaldet_fk_product (fk_product);
ALTER TABLE llx_propaldet ADD CONSTRAINT fk_propaldet_fk_unit FOREIGN KEY (fk_unit) REFERENCES llx_c_units (rowid);
ALTER TABLE llx_propaldet ADD CONSTRAINT fk_propaldet_fk_propal FOREIGN KEY (fk_propal) REFERENCES llx_propal (rowid);

View File

@ -2,6 +2,7 @@
-- Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
-- Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
-- Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
-- Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
@ -51,7 +52,8 @@ create table llx_propaldet
fk_product_fournisseur_price integer DEFAULT NULL, -- reference of supplier price when line was added (may be used to update buy_price_ht current price when future invoice will be created)
special_code integer DEFAULT 0, -- code pour les lignes speciales
rang integer DEFAULT 0 -- ordre affichage sur la propal
rang integer DEFAULT 0, -- ordre affichage sur la propal
fk_unit integer DEFAULT NULL -- lien vers table des unités
)ENGINE=innodb;

View File

@ -1391,6 +1391,7 @@ UseSearchToSelectProduct=Use a search form to choose a product (rather than a dr
UseEcoTaxeAbility=Support Eco-Taxe (WEEE)
SetDefaultBarcodeTypeProducts=Default barcode type to use for products
SetDefaultBarcodeTypeThirdParties=Default barcode type to use for third parties
UseUnits=Support units
ProductCodeChecker= Module for product code generation and checking (product or service)
ProductOtherConf= Product / Service configuration
##### Syslog #####

View File

@ -189,6 +189,32 @@ CustomCode=Customs code
CountryOrigin=Origin country
HiddenIntoCombo=Hidden into select lists
Nature=Nature
DictionnaryUnits=Units
ShortLabel=Short label
Unit=Unit
p=u.
set=set
se=set
second=second
s=s
hour=hour
h=h
day=day
d=d
kilogram=kilogram
kg=Kg
gram=gram
g=g
meter=meter
m=m
linear meter=linear meter
lm=lm
square meter=square meter
m2=m²
cubic meter=cubic meter
m3=m³
liter=liter
l=L
ProductCodeModel=Product ref template
ServiceCodeModel=Service ref template
AddThisProductCard=Create product card

View File

@ -6,7 +6,8 @@
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2011-2012 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
**
* Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
@ -180,6 +181,12 @@ else if ($action == 'set')
$res = dolibarr_set_const($db, "PRODUIT_USE_ECOTAXE", $ecotaxe,'chaine',0,'',$conf->entity);
}*/
else if ($action == 'useUnits')
{
$useUnits = GETPOST('activate_units', 'alpha');
$res = dolibarr_set_const($db, "PRODUCT_USE_UNITS", $useUnits, 'chaine', 0, '', $conf->entity);
}
if($action)
{
if (! $res > 0) $error++;
@ -447,6 +454,21 @@ print '</td>';
print '</tr>';
print '</form>';
// Use units
$var=!$var;
print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="useUnits">';
print '<tr '.$bc[$var].'>';
print '<td>'.$langs->trans("UseUnits").'</td>';
print '<td width="60" align="right">';
print $form->selectyesno("activate_units",$conf->global->PRODUCT_USE_UNITS,1);
print '</td><td align="right">';
print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
print '</td>';
print '</tr>';
print '</form>';
// View product description in thirdparty language
if (! empty($conf->global->MAIN_MULTILANGS))
{

View File

@ -7,7 +7,7 @@
* Copyright (C) 2006 Auguria SARL <info@auguria.org>
* Copyright (C) 2010-2014 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2013-2014 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2012-2013 Cédric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2011-2014 Alexandre Spangaro <alexandre.spangaro@gmail.com>
* Copyright (C) 2014 Cédric Gross <c.gross@kreiz-it.fr>
* Copyright (C) 2014 Ferran Marcet <fmarcet@2byte.es>
@ -181,6 +181,8 @@ if (empty($reshook))
if (! $error)
{
$units = GETPOST('units', 'int');
$object->ref = $ref;
$object->libelle = GETPOST('libelle');
$object->price_base_type = GETPOST('price_base_type');
@ -242,6 +244,10 @@ if (empty($reshook))
$object->volume_units = GETPOST('volume_units');
$object->finished = GETPOST('finished');
$object->hidden = GETPOST('hidden')=='yes'?1:0;
$object->fk_unit = GETPOST('units');
if ($fk_unit > 0) {
$object->fk_unit = $fk_unit;
}
$object->accountancy_code_sell = GETPOST('accountancy_code_sell');
$object->accountancy_code_buy = GETPOST('accountancy_code_buy');
@ -334,6 +340,14 @@ if (empty($reshook))
$object->finished = GETPOST('finished');
$object->hidden = GETPOST('hidden')=='yes'?1:0;
$units = GETPOST('units', 'int');
if ($units > 0) {
$object->fk_unit = $units;
} else {
$object->fk_unit = null;
}
$object->barcode_type = GETPOST('fk_barcode_type');
$object->barcode = GETPOST('barcode');
// Set barcode_type_xxx from barcode_type id
@ -588,7 +602,19 @@ if (empty($reshook))
$object->id,
GETPOST('remise_percent'),
$price_base_type,
$pu_ttc
$pu_ttc,
0,
0,
-1,
0,
0,
0,
0,
'',
'',
'',
0,
$object->fk_unit
);
if ($result > 0)
{
@ -680,7 +706,18 @@ if (empty($reshook))
'',
'',
$price_base_type,
$pu_ttc
$pu_ttc,
'',
'',
0,
-1,
0,
0,
null,
0,
'',
0,
$object->fk_unit
);
if ($result > 0)
@ -773,7 +810,20 @@ if (empty($reshook))
'',
'',
$price_base_type,
$pu_ttc
$pu_ttc,
Facture::TYPE_STANDARD,
-1,
0,
'',
0,
0,
null,
0,
'',
0,
100,
'',
$object->fk_unit
);
if ($result > 0)
@ -1030,7 +1080,7 @@ else
// We use dolibarr_details as type of DolEditor here, because we must not accept images as description is included into PDF and not accepted by TCPDF.
$doleditor = new DolEditor('note', GETPOST('note'), '', 140, 'dolibarr_details', '', false, true, $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC, 8, 70);
$doleditor->Create();
$doleditor->Create();
print "</td></tr>";
@ -1040,6 +1090,15 @@ else
print $form->multiselectarray('categories', $cate_arbo, $arrayselected, '', 0, '', 0, 250);
print "</td></tr>";
// Units
if($conf->global->PRODUCT_USE_UNITS)
{
print '<tr><td>'.$langs->trans('Unit').'</td>';
print '<td colspan="3">';
$form->select_units("units");
print '</td></tr>';
}
print '</table>';
print '<br>';
@ -1320,6 +1379,15 @@ else
}
print $form->multiselectarray('categories', $cate_arbo, $arrayselected, '', 0, '', 0, 250);
print "</td></tr>";
// Units
if($conf->global->PRODUCT_USE_UNITS)
{
print '<tr><td>'.$langs->trans('Unit').'</td>';
print '<td colspan="3">';
$form->select_units($object->fk_unit);
print '</td></tr>';
}
print '</table>';
@ -1588,6 +1656,18 @@ else
print "</td></tr>\n";
}
// Unit
if($conf->global->PRODUCT_USE_UNITS)
{
$unit = $object->get_unit_label();
print '<tr><td>'.$langs->trans('Unit').'</td><td>';
if ($unit !== '') {
print $langs->trans($unit);
}
print '</td></tr>';
}
// Custom code
if (empty($conf->global->PRODUCT_DISABLE_CUSTOM_INFO))
{

View File

@ -5,6 +5,7 @@
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
* Copyright (C) 2007-2011 Jean Heimburger <jean@tiaris.info>
* Copyright (C) 2010-2013 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2013-2014 Cedric GROSS <c.gross@kreiz-it.fr>
* Copyright (C) 2013-2015 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2011-2014 Alexandre Spangaro <alexandre.spangaro@gmail.com>
@ -175,6 +176,12 @@ class Product extends CommonObject
var $fk_price_expression;
/**
* Unit
* @var int
*/
public $fk_unit;
/**
* Regular product
*/
@ -382,6 +389,7 @@ class Product extends CommonObject
$sql.= ", canvas";
$sql.= ", finished";
$sql.= ", tobatch";
$sql.= ", fk_unit";
$sql.= ") VALUES (";
$sql.= "'".$this->db->idate($now)."'";
$sql.= ", ".$conf->entity;
@ -402,6 +410,7 @@ class Product extends CommonObject
$sql.= ", '".$this->canvas."'";
$sql.= ", ".((! isset($this->finished) || $this->finished < 0 || $this->finished == '') ? 'null' : (int) $this->finished);
$sql.= ", ".((empty($this->status_batch) || $this->status_batch < 0)? '0':$this->status_batch);
$sql.= ", ".(!$this->fk_unit ? 'NULL' : $this->fk_unit);
$sql.= ")";
dol_syslog(get_class($this)."::Create", LOG_DEBUG);
@ -691,6 +700,7 @@ class Product extends CommonObject
$sql.= ", accountancy_code_buy = '" . $this->accountancy_code_buy."'";
$sql.= ", accountancy_code_sell= '" . $this->accountancy_code_sell."'";
$sql.= ", desiredstock = " . ((isset($this->desiredstock) && $this->desiredstock != '') ? $this->desiredstock : "null");
$sql.= ", fk_unit= " . (!$this->fk_unit ? 'NULL' : $this->fk_unit);
$sql.= " WHERE rowid = " . $id;
dol_syslog(get_class($this)."::update", LOG_DEBUG);
@ -1503,7 +1513,7 @@ class Product extends CommonObject
$sql.= " tobuy, fk_product_type, duration, seuil_stock_alerte, canvas,";
$sql.= " weight, weight_units, length, length_units, surface, surface_units, volume, volume_units, barcode, fk_barcode_type, finished,";
$sql.= " accountancy_code_buy, accountancy_code_sell, stock, pmp,";
$sql.= " datec, tms, import_key, entity, desiredstock, tobatch";
$sql.= " datec, tms, import_key, entity, desiredstock, tobatch, fk_unit";
$sql.= " ,ref_ext, fk_price_expression";
$sql.= " FROM ".MAIN_DB_PREFIX."product";
if ($id) $sql.= " WHERE rowid = ".$this->db->escape($id);
@ -1582,6 +1592,7 @@ class Product extends CommonObject
$this->ref_ext = $obj->ref_ext;
$this->fk_price_expression = $obj->fk_price_expression;
$this->fk_unit = $obj->fk_unit;
$this->db->free($resql);
@ -3803,6 +3814,48 @@ class Product extends CommonObject
$this->barcode=-1; // Create barcode automatically
}
/**
* Returns the text label from units dictionnary
*
* @param string $type Label type (long or short)
* @return string|int <0 if ko, label if ok
*/
function get_unit_label($type='long')
{
global $langs;
if (!$this->fk_unit) {
return '';
}
$langs->load('products');
$this->db->begin();
$label_type = 'label';
if ($type == 'short')
{
$label_type = 'short_label';
}
$sql = 'select '.$label_type.' from '.MAIN_DB_PREFIX.'c_units where rowid='.$this->fk_unit;
$resql = $this->db->query($sql);
if($resql && $this->db->num_rows($resql) > 0)
{
$res = $this->db->fetch_array($resql);
$label = $res[$label_type];
$this->db->free($resql);
return $label;
}
else
{
$this->error=$this->db->error().' sql='.$sql;
dol_syslog(get_class($this)."::get_unit_label Error ".$this->error, LOG_ERR);
return -1;
}
}
/**
* Return if object has a sell-by date or eat-by date
*