From b4c84fac9deac7820af9c20c3fe5ae82d3b727ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Thu, 26 Feb 2015 14:15:33 +0100 Subject: [PATCH 01/18] 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 --- htdocs/admin/dict.php | 22 ++++- htdocs/comm/propal.php | 14 ++- htdocs/comm/propal/class/propal.class.php | 25 ++++- htdocs/commande/card.php | 14 ++- htdocs/commande/class/commande.class.php | 31 ++++-- htdocs/compta/facture.php | 20 +++- .../facture/class/facture-rec.class.php | 14 ++- htdocs/compta/facture/class/facture.class.php | 34 +++++-- htdocs/compta/facture/fiche-rec.php | 22 ++++- htdocs/contrat/card.php | 38 ++++++- htdocs/contrat/class/contrat.class.php | 26 +++-- htdocs/core/class/commonobject.class.php | 15 ++- htdocs/core/class/commonobjectline.class.php | 50 ++++++++++ htdocs/core/class/commonorder.class.php | 3 +- htdocs/core/class/html.form.class.php | 48 +++++++++ htdocs/core/lib/pdf.lib.php | 37 +++++++ .../commande/doc/pdf_einstein.modules.php | 69 ++++++++++--- .../modules/facture/doc/pdf_crabe.modules.php | 54 ++++++++-- .../modules/propale/doc/pdf_azur.modules.php | 56 +++++++++-- htdocs/core/tpl/objectline_create.tpl.php | 23 +++++ htdocs/core/tpl/objectline_edit.tpl.php | 9 ++ htdocs/core/tpl/objectline_view.tpl.php | 12 +++ htdocs/core/tpl/originproductline.tpl.php | 5 +- htdocs/install/mysql/data/llx_c_units.sql | 31 ++++++ .../install/mysql/migration/3.7.0-3.8.0.sql | 43 +++++++- .../install/mysql/tables/llx_c_units.key.sql | 21 ++++ htdocs/install/mysql/tables/llx_c_units.sql | 27 +++++ .../mysql/tables/llx_commandedet.key.sql | 2 + .../install/mysql/tables/llx_commandedet.sql | 2 + .../mysql/tables/llx_contratdet.key.sql | 2 + .../install/mysql/tables/llx_contratdet.sql | 3 +- .../mysql/tables/llx_facturedet.key.sql | 2 + .../install/mysql/tables/llx_facturedet.sql | 3 +- .../mysql/tables/llx_facturedet_rec.key.sql | 21 ++++ .../mysql/tables/llx_facturedet_rec.sql | 4 +- .../install/mysql/tables/llx_product.key.sql | 3 +- htdocs/install/mysql/tables/llx_product.sql | 7 +- .../mysql/tables/llx_propaldet.key.sql | 2 + htdocs/install/mysql/tables/llx_propaldet.sql | 4 +- htdocs/langs/en_US/admin.lang | 1 + htdocs/langs/en_US/products.lang | 26 +++++ htdocs/product/admin/product.php | 24 ++++- htdocs/product/card.php | 99 +++++++++++++++++-- htdocs/product/class/product.class.php | 55 ++++++++++- 44 files changed, 931 insertions(+), 92 deletions(-) create mode 100644 htdocs/install/mysql/data/llx_c_units.sql create mode 100644 htdocs/install/mysql/tables/llx_c_units.key.sql create mode 100644 htdocs/install/mysql/tables/llx_c_units.sql create mode 100644 htdocs/install/mysql/tables/llx_facturedet_rec.key.sql diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php index 05402898ee6..4f193ed76f2 100644 --- a/htdocs/admin/dict.php +++ b/htdocs/admin/dict.php @@ -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)); diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 302b49fbdb7..a2c578fcaa9 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -8,6 +8,7 @@ * Copyright (C) 2010-2014 Juanjo Menent * Copyright (C) 2010-2011 Philippe Grand * Copyright (C) 2012-2013 Christophe Battarel + * Copyright (C) 2012 Cedric Salvador * Copyright (C) 2013-2014 Florian Henry * Copyright (C) 2014 Ferran Marcet * @@ -687,6 +688,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); @@ -782,6 +784,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'); @@ -790,6 +793,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 @@ -812,7 +821,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_option); + $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_option, $fk_unit); if ($result > 0) { $db->commit(); @@ -846,6 +855,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']); @@ -940,7 +950,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_option); + $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_option, $_POST["units"]); if ($result >= 0) { $db->commit(); diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index dc1184b7490..306df930523 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -9,6 +9,7 @@ * Copyright (C) 2010-2014 Juanjo Menent * Copyright (C) 2010-2011 Philippe Grand * Copyright (C) 2012-2014 Christophe Battarel + * Copyright (C) 2012 Cedric Salvador * Copyright (C) 2013 Florian Henry * Copyright (C) 2014-2015 Marcos García * @@ -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'; @@ -203,6 +205,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; } @@ -315,11 +318,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_option 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_option=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_option=0, $fk_unit = null) { global $mysoc; @@ -416,6 +420,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; @@ -497,9 +502,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_option 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_option=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_option=0, $fk_unit = null) { global $mysoc; @@ -581,6 +587,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)) { @@ -829,7 +836,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) @@ -1193,6 +1201,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"; @@ -1249,6 +1258,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; @@ -2674,6 +2684,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'; @@ -2724,6 +2735,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++; } @@ -2780,7 +2792,7 @@ class Propal extends CommonObject * \class PropaleLigne * \brief Class to manage commercial proposal lines */ -class PropaleLigne extends CommonObject +class PropaleLigne extends CommonObjectLine { var $db; var $error; @@ -2866,6 +2878,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'; @@ -2913,6 +2926,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); @@ -2975,6 +2989,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").","; @@ -3001,6 +3016,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.= ')'; @@ -3166,6 +3182,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); diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index bda67f809fa..a11ea9cf154 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -8,6 +8,7 @@ * Copyright (C) 2011 Philippe Grand * Copyright (C) 2012-2013 Christophe Battarel * Copyright (C) 2012 Marcos García + * Copyright (C) 2012 Cedric Salvador * Copyright (C) 2013 Florian Henry * Copyright (C) 2014 Ferran Marcet * @@ -341,7 +342,7 @@ if (empty($reshook)) $array_option = $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_option); + $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_option, $lines[$i]->fk_unit); if ($result < 0) { $error ++; @@ -700,6 +701,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'); @@ -708,6 +710,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 @@ -729,7 +736,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_option); + $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_option, $fk_unit); if ($result > 0) { $ret = $object->fetch($object->id); // Reload to get new records @@ -765,6 +772,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']); @@ -853,7 +861,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_option); + $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_option, GETPOST('units')); if ($result >= 0) { if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index dd0d3163bba..d0c7e14fc9c 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -6,6 +6,7 @@ * Copyright (C) 2010-2014 Juanjo Menent * Copyright (C) 2011 Jean Heimburger * Copyright (C) 2012-2014 Christophe Battarel + * Copyright (C) 2012 Cedric Salvador * Copyright (C) 2013 Florian Henry * Copyright (C) 2014-2015 Marcos García * @@ -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'; @@ -740,7 +742,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) { @@ -999,6 +1002,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; @@ -1102,6 +1106,7 @@ class Commande extends CommonOrder * @param int $pa_ht Buying price (without tax) * @param string $label Label * @param array $array_option 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 @@ -1111,11 +1116,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_option=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_option=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'; @@ -1230,6 +1235,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; @@ -1333,6 +1339,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 @@ -1581,6 +1588,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)'; @@ -1638,6 +1646,7 @@ class Commande extends CommonOrder $line->product_label = $objp->product_label; $line->product_desc = $objp->product_desc; // Description produit $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); @@ -2347,9 +2356,10 @@ class Commande extends CommonOrder * @param string $label Label * @param int $special_code Special code (also used by externals modules!) * @param array $array_option 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_option=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_option=0, $fk_unit = null) { global $conf, $mysoc; @@ -2369,6 +2379,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); @@ -2441,6 +2452,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)) { @@ -3121,6 +3133,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'; @@ -3170,6 +3183,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++; } @@ -3307,6 +3321,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'; @@ -3352,6 +3367,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); @@ -3468,7 +3484,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").","; @@ -3497,7 +3514,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); @@ -3615,6 +3633,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); diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 3c194a522d3..1804763760d 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -1064,7 +1064,7 @@ if (empty($reshook)) $array_option = $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, $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_option, $lines[$i]->situation_percent, $lines[$i]->fk_prev_id); + $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, $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_option, $lines[$i]->situation_percent, $lines[$i]->fk_prev_id, $lines[$i]->fk_unit); if ($result > 0) { $lineid = $result; @@ -1106,7 +1106,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); } } } @@ -1252,6 +1252,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); @@ -1347,6 +1348,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'); @@ -1355,6 +1357,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 @@ -1374,7 +1381,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_option, $_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_option, $_POST['progress'], '', $fk_unit); if ($result > 0) { @@ -1412,6 +1419,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']); @@ -1528,7 +1536,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_option, 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_option, GETPOST('progress'), + $_POST['units']); if ($result >= 0) { if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { @@ -1565,6 +1576,7 @@ if (empty($reshook)) unset($_POST['dp_desc']); unset($_POST['idprod']); + unset($_POST['units']); unset($_POST['date_starthour']); unset($_POST['date_startmin']); diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php index 40ab9119998..111fcf2b684 100644 --- a/htdocs/compta/facture/class/facture-rec.class.php +++ b/htdocs/compta/facture/class/facture-rec.class.php @@ -3,6 +3,7 @@ * Copyright (C) 2004-2012 Laurent Destailleur * Copyright (C) 2009-2012 Regis Houssin * Copyright (C) 2010-2011 Juanjo Menent + * Copyright (C) 2012 Cedric Salvador * Copyright (C) 2013 Florian Henry * * This program is free software; you can redistribute it and/or modify @@ -161,7 +162,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) @@ -299,6 +301,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'; @@ -341,6 +344,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; @@ -412,11 +416,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 @@ -476,6 +480,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"); @@ -492,7 +497,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)) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 0c277014a64..25c70392647 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -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'; @@ -436,7 +437,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) { @@ -490,7 +492,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) @@ -782,6 +786,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); @@ -1040,6 +1045,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'; @@ -1097,6 +1103,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; @@ -2037,13 +2044,14 @@ class Facture extends CommonInvoice * @param array $array_option 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_option=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_option=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 @@ -2157,6 +2165,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; @@ -2219,15 +2228,16 @@ class Facture extends CommonInvoice * @param int $special_code Special code (also used by externals modules!) * @param array $array_option 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_option=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_option=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) { @@ -2239,7 +2249,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); @@ -2308,7 +2317,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)) { @@ -3367,6 +3376,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'; @@ -3418,6 +3428,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++; } @@ -3694,6 +3705,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'; @@ -3741,6 +3753,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; @@ -3828,7 +3841,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").","; @@ -3859,6 +3873,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); @@ -4023,6 +4038,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); diff --git a/htdocs/compta/facture/fiche-rec.php b/htdocs/compta/facture/fiche-rec.php index 1fd4d2c80fc..95fd7121998 100644 --- a/htdocs/compta/facture/fiche-rec.php +++ b/htdocs/compta/facture/fiche-rec.php @@ -2,6 +2,7 @@ /* Copyright (C) 2002-2003 Rodolphe Quiedeville * Copyright (C) 2004-2014 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2012 Cedric Salvador * Copyright (C) 2013 Florian Henry * Copyright (C) 2013 Juanjo Menent * @@ -201,6 +202,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"; @@ -221,6 +223,9 @@ if ($action == 'create') print ''.$langs->trans("Description").''; print ''.$langs->trans("VAT").''; print ''.$langs->trans("Qty").''; + if ($conf->global->PRODUCT_USE_UNITS) { + print ''.$langs->trans("Unit").''; + } print ''.$langs->trans("ReductionShort").''; print ''.$langs->trans("TotalHT").''; print ''.$langs->trans("TotalVAT").''; @@ -245,6 +250,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) { @@ -298,6 +304,10 @@ if ($action == 'create') // Qty print ''.$objp->qty.''; + if ($conf->global->PRODUCT_USE_UNITS) { + print ''.$product_static->get_unit_label().''; + } + // Percent if ($objp->remise_percent > 0) { @@ -444,7 +454,11 @@ else print ''.$langs->trans("Description").''; print ''.$langs->trans("Price").''; print ''.$langs->trans("ReductionShort").''; - print ''.$langs->trans("Qty").''; + print ''.$langs->trans("Qty").''; + if ($conf->global->PRODUCT_USE_UNITS) { + print ''.$langs->trans("Unit").''; + } + print ''; $num = count($object->lines); $i = 0; @@ -511,7 +525,11 @@ else } print ''.price($object->lines[$i]->price).''; print ''.$object->lines[$i]->remise_percent.' %'; - print ''.$object->lines[$i]->qty.''."\n"; + print ''.$object->lines[$i]->qty.''; + if ($conf->global->PRODUCT_USE_UNITS) { + print "".$object->lines[$i]->get_unit_label().""; + } + print "\n"; $i++; } print ''; diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index 731ad1c6cc1..3a38c8e4ffb 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -490,6 +490,7 @@ else if ($action == 'addline' && $user->rights->contrat->creer) $desc=$prod->description; $desc=dol_concatdesc($desc,$product_desc); + $fk_unit = $prod->fk_unit; } else { @@ -498,6 +499,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); @@ -537,7 +543,8 @@ else if ($action == 'addline' && $user->rights->contrat->creer) $info_bits, $fk_fournprice, $pa_ht, - $array_option + $array_option, + $fk_unit ); } @@ -618,6 +625,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'); @@ -634,6 +643,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); @@ -1286,6 +1301,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"; @@ -1301,6 +1317,7 @@ else print ''.$langs->trans("VAT").''; print ''.$langs->trans("PriceUHT").''; print ''.$langs->trans("Qty").''; + if($conf->global->PRODUCT_USE_UNITS) print ''.$langs->trans("Unit").''; print ''.$langs->trans("ReductionShort").''; if (! empty($conf->margin->enabled) && ! empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) print ''.$langs->trans("BuyingPrice").''; print ' '; @@ -1343,6 +1360,8 @@ else print ''.price($objp->subprice)."\n"; // Quantite print ''.$objp->qty.''; + //Unit + if($conf->global->PRODUCT_USE_UNITS) print ''.$langs->trans($object->lines[$cursorline-1]->get_unit_label()).''; // Remise if ($objp->remise_percent > 0) { @@ -1390,8 +1409,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 ''; - print ''; + print ''; // Date planned print $langs->trans("DateStartPlanned").': '; @@ -1459,6 +1486,12 @@ else print ''; print ''; print ''; + if($conf->global->PRODUCT_USE_UNITS) + { + print ''; + $form->select_units($objp->fk_unit, "unit"); + print ''; + } print '%'; if (! empty($usemargins)) { @@ -1472,6 +1505,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 ""; diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index bb00a5d9838..8031ca85ebe 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -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'; @@ -655,7 +656,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"; @@ -700,6 +702,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 @@ -754,7 +757,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 @@ -807,6 +811,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++; @@ -1240,9 +1245,10 @@ class Contrat extends CommonObject * @param int $fk_fournprice Fourn price id * @param int $pa_ht Buying price HT * @param array $array_option 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_option=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_option=0, $fk_unit = null) { global $user, $langs, $conf, $mysoc; @@ -1259,6 +1265,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); @@ -1322,6 +1329,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."',"; @@ -1340,6 +1348,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); @@ -1418,9 +1427,10 @@ class Contrat extends CommonObject * @param int $fk_fournprice Fourn price id * @param int $pa_ht Buying price HT * @param array $array_option 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_option=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_option=0, $fk_unit = null) { global $user, $conf, $langs, $mysoc; @@ -1511,6 +1521,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); @@ -2127,7 +2138,7 @@ class Contrat extends CommonObject /** * Classe permettant la gestion des lignes de contrats */ -class ContratLigne extends CommonObject +class ContratLigne extends CommonObjectLine { var $id; @@ -2347,7 +2358,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)."'"; @@ -2396,6 +2408,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); @@ -2506,6 +2519,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); diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index da9971b1b4e..51dbbbe9c6e 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -8,6 +8,7 @@ * Copyright (C) 2011-2014 Philippe Grand * Copyright (C) 2012-2014 Marcos García * Copyright (C) 2012-2014 Raphaël Doursenaud + * Copyright (C) 2012 Cedric Salvador * * 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 @@ -2592,6 +2593,11 @@ abstract class CommonObject // Qty print ''; + if($conf->global->PRODUCT_USE_UNITS) + { + print ''.$langs->trans('Unit').''; + } + // Reduction short print ''; @@ -2794,7 +2800,7 @@ abstract class CommonObject */ function printOriginLinesList() { - global $langs, $hookmanager; + global $langs, $hookmanager, $conf; print ''; print ''.$langs->trans('Ref').''; @@ -2802,6 +2808,10 @@ abstract class CommonObject print ''.$langs->trans('VAT').''; print ''.$langs->trans('PriceUHT').''; print ''.$langs->trans('Qty').''; + if($conf->global->PRODUCT_USE_UNITS) + { + print ''.$langs->trans('Unit').''; + } print ''.$langs->trans('ReductionShort').''; $num = count($this->lines); @@ -2842,7 +2852,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)) @@ -2929,6 +2939,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 : ' '; + 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) : ' '; // Output template part (modules that overwrite templates must declare this into descriptor) diff --git a/htdocs/core/class/commonobjectline.class.php b/htdocs/core/class/commonobjectline.class.php index c3c8d823a34..b72a2d28681 100644 --- a/htdocs/core/class/commonobjectline.class.php +++ b/htdocs/core/class/commonobjectline.class.php @@ -1,5 +1,6 @@ + * Copyright (C) 2012 Cedric Salvador * * 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 @@ -28,8 +29,57 @@ */ abstract class CommonObjectLine extends CommonObject { + //! 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. diff --git a/htdocs/core/class/commonorder.class.php b/htdocs/core/class/commonorder.class.php index 469e1676a53..3e30b0a9ca6 100644 --- a/htdocs/core/class/commonorder.class.php +++ b/htdocs/core/class/commonorder.class.php @@ -22,6 +22,7 @@ */ require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php'; +require_once DOL_DOCUMENT_ROOT .'/core/class/commonobjectline.class.php'; /** * \class CommonOrder @@ -36,7 +37,7 @@ abstract class CommonOrder extends CommonObject * \class CommonOrderLine * \brief Superclass for orders classes */ -abstract class CommonOrderLine extends CommonObject +abstract class CommonOrderLine extends CommonObjectLine { } diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 6a6474c8306..13035b145e8 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -2728,6 +2728,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= ''; + } + return $return; + } + /** * Return a HTML select list of bank accounts * diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index 1c5ae62d014..ca1be2c7604 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -1420,6 +1420,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 * diff --git a/htdocs/core/modules/commande/doc/pdf_einstein.modules.php b/htdocs/core/modules/commande/doc/pdf_einstein.modules.php index f6d28a4f135..70b8c8f2dfe 100644 --- a/htdocs/core/modules/commande/doc/pdf_einstein.modules.php +++ b/htdocs/core/modules/commande/doc/pdf_einstein.modules.php @@ -4,6 +4,7 @@ * Copyright (C) 2008 Raphael Bertrand * Copyright (C) 2010-2013 Juanjo Menent * Copyright (C) 2012 Christophe Battarel + * Copyright (C) 2012 Cedric Salvador * * 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); @@ -380,9 +392,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); @@ -540,7 +569,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 @@ -555,7 +584,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 @@ -739,7 +768,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 @@ -996,7 +1025,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) @@ -1064,7 +1093,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); @@ -1091,7 +1136,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 @@ -1270,7 +1315,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 diff --git a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php index 4c340a12cfa..1c0fa822bb9 100644 --- a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php @@ -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); @@ -463,7 +473,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) @@ -1303,7 +1329,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); diff --git a/htdocs/core/modules/propale/doc/pdf_azur.modules.php b/htdocs/core/modules/propale/doc/pdf_azur.modules.php index 35953b8521f..402cfcae8fc 100644 --- a/htdocs/core/modules/propale/doc/pdf_azur.modules.php +++ b/htdocs/core/modules/propale/doc/pdf_azur.modules.php @@ -4,6 +4,7 @@ * Copyright (C) 2008 Raphael Bertrand * Copyright (C) 2010-2014 Juanjo Menent * Copyright (C) 2012 Christophe Battarel + * Copyright (C) 2012 Cedric Salvador * * 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); @@ -436,9 +447,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); @@ -1143,7 +1171,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); diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php index bce94c70a57..ede2b522ecd 100644 --- a/htdocs/core/tpl/objectline_create.tpl.php +++ b/htdocs/core/tpl/objectline_create.tpl.php @@ -58,6 +58,15 @@ if (in_array($object->element,array('propal','facture','invoice','commande','ord trans('PriceUTTC'); ?> trans('Qty'); ?> + global->PRODUCT_USE_UNITS) + { + print ''; + print ''; + print $langs->trans('Unit'); + print ''; + } + ?> trans('ReductionShort'); ?> situation_cycle_ref) { @@ -218,6 +227,14 @@ else { "> + global->PRODUCT_USE_UNITS) + { + print ''; + print $form->select_units($line->fk_unit, "units"); + print ''; + } + ?> remise_percent); ?>">% situation_cycle_ref) { @@ -291,6 +308,9 @@ if (! empty($conf->service->enabled) && $dateSelector && GETPOST('type') != '0') if($this->situation_cycle_ref) $colspan++; if (! empty($inputalsopricewithtax)) $colspan++; // We add 1 if col total ttc if (in_array($object->element,array('propal','facture','invoice','commande','order'))) $colspan++; // With this, there is a column move button + if ($conf->global->PRODUCT_USE_UNITS) { + $colspan++; + } if (! empty($usemargins)) { @@ -560,6 +580,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); @@ -576,6 +597,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(); } diff --git a/htdocs/core/tpl/objectline_edit.tpl.php b/htdocs/core/tpl/objectline_edit.tpl.php index ae2238e06f2..81af7385efc 100644 --- a/htdocs/core/tpl/objectline_edit.tpl.php +++ b/htdocs/core/tpl/objectline_edit.tpl.php @@ -140,6 +140,15 @@ $coldisplay=-1; // We remove first td + global->PRODUCT_USE_UNITS) + { + print ''; + $form->select_units($line->fk_unit, "units"); + print ''; + } + ?> + info_bits & 2) != 2) { print ' + global->PRODUCT_USE_UNITS) + { + print ''; + $label = $line->get_unit_label('short'); + if ($label !== '') { + print $langs->trans($label); + } + print ''; + } + ?> + remise_percent) && $line->special_code != 3) { ?> remise_percent,$langs); ?> diff --git a/htdocs/core/tpl/originproductline.tpl.php b/htdocs/core/tpl/originproductline.tpl.php index 878166bb40d..7919668ae53 100644 --- a/htdocs/core/tpl/originproductline.tpl.php +++ b/htdocs/core/tpl/originproductline.tpl.php @@ -24,6 +24,9 @@ tpl['vat_rate']; ?> tpl['price']; ?> tpl['qty']; ?> + global->PRODUCT_USE_UNITS) echo ''.$langs->trans($this->tpl['unit']).''; + ?> tpl['remise_percent']; ?> - \ No newline at end of file + diff --git a/htdocs/install/mysql/data/llx_c_units.sql b/htdocs/install/mysql/data/llx_c_units.sql new file mode 100644 index 00000000000..835c0ab06eb --- /dev/null +++ b/htdocs/install/mysql/data/llx_c_units.sql @@ -0,0 +1,31 @@ +-- ======================================================================== +-- Copyright (C) 2001-2002,2004 Rodolphe Quiedeville +-- Copyright (C) 2004 Laurent Destailleur +-- Copyright (C) 2012 Cédric Salvador +-- 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 . +-- +-- ======================================================================== + +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); diff --git a/htdocs/install/mysql/migration/3.7.0-3.8.0.sql b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql index c09c434d27e..e8d4f77d5f8 100755 --- a/htdocs/install/mysql/migration/3.7.0-3.8.0.sql +++ b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql @@ -1,4 +1,4 @@ --- +NULL- -- Be carefull to requests order. -- This file must be loaded by calling /install/index.php page -- when current version is 3.8.0 or higher. @@ -209,3 +209,44 @@ create table llx_commande_fournisseurdet_extrafields ALTER TABLE llx_commande_fournisseurdet_extrafields ADD INDEX idx_commande_fournisseurdet_extrafields (fk_object); +-- 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 ('NA','aucune','', 1); +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); \ No newline at end of file diff --git a/htdocs/install/mysql/tables/llx_c_units.key.sql b/htdocs/install/mysql/tables/llx_c_units.key.sql new file mode 100644 index 00000000000..f97ea9f709f --- /dev/null +++ b/htdocs/install/mysql/tables/llx_c_units.key.sql @@ -0,0 +1,21 @@ +-- ======================================================================== +-- Copyright (C) 2005 Laurent Destailleur +-- Copyright (C) 2012 Cédric Salvador +-- +-- 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 . +-- +-- ======================================================================== + + +ALTER TABLE llx_c_units ADD UNIQUE uk_c_units_code(code); diff --git a/htdocs/install/mysql/tables/llx_c_units.sql b/htdocs/install/mysql/tables/llx_c_units.sql new file mode 100644 index 00000000000..44c5b812483 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_c_units.sql @@ -0,0 +1,27 @@ +-- ======================================================================== +-- Copyright (C) 2001-2002,2004 Rodolphe Quiedeville +-- Copyright (C) 2004 Laurent Destailleur +-- Copyright (C) 2012 Cédric Salvador +-- +-- 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 . +-- +-- ======================================================================== + +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; diff --git a/htdocs/install/mysql/tables/llx_commandedet.key.sql b/htdocs/install/mysql/tables/llx_commandedet.key.sql index 4d3f8223f79..21765a6ad1b 100644 --- a/htdocs/install/mysql/tables/llx_commandedet.key.sql +++ b/htdocs/install/mysql/tables/llx_commandedet.key.sql @@ -1,6 +1,7 @@ -- =================================================================== -- Copyright (C) 2006 Laurent Destailleur -- Copyright (C) 2011 Regis Houssin +-- Copyright (C) 2012 Cédric Salvador -- -- 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); diff --git a/htdocs/install/mysql/tables/llx_commandedet.sql b/htdocs/install/mysql/tables/llx_commandedet.sql index 7562b694b99..76bd75f17c8 100644 --- a/htdocs/install/mysql/tables/llx_commandedet.sql +++ b/htdocs/install/mysql/tables/llx_commandedet.sql @@ -3,6 +3,7 @@ -- Copyright (C) 2005-2012 Regis Houssin -- Copyright (C) 2006-2009 Laurent Destailleur -- Copyright (C) 2010 Juanjo Menent +-- Copyright (C) 2012 Cédric Salvador -- -- 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 UNSIGNED 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; diff --git a/htdocs/install/mysql/tables/llx_contratdet.key.sql b/htdocs/install/mysql/tables/llx_contratdet.key.sql index e749c09df51..6f65271ebb7 100644 --- a/htdocs/install/mysql/tables/llx_contratdet.key.sql +++ b/htdocs/install/mysql/tables/llx_contratdet.key.sql @@ -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); diff --git a/htdocs/install/mysql/tables/llx_contratdet.sql b/htdocs/install/mysql/tables/llx_contratdet.sql index 78091d3a3d9..b4e13fb99c2 100644 --- a/htdocs/install/mysql/tables/llx_contratdet.sql +++ b/htdocs/install/mysql/tables/llx_contratdet.sql @@ -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; diff --git a/htdocs/install/mysql/tables/llx_facturedet.key.sql b/htdocs/install/mysql/tables/llx_facturedet.key.sql index 52c7ec7668d..8a8ecf1da9c 100644 --- a/htdocs/install/mysql/tables/llx_facturedet.key.sql +++ b/htdocs/install/mysql/tables/llx_facturedet.key.sql @@ -1,6 +1,7 @@ -- =================================================================== -- Copyright (C) 2005 Laurent Destailleur -- Copyright (C) 2011 Regis Houssin +-- Copyright (C) 2012 Cédric Salvador -- -- 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); diff --git a/htdocs/install/mysql/tables/llx_facturedet.sql b/htdocs/install/mysql/tables/llx_facturedet.sql index d663adf4e1c..63cd9ab3bc1 100644 --- a/htdocs/install/mysql/tables/llx_facturedet.sql +++ b/htdocs/install/mysql/tables/llx_facturedet.sql @@ -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; diff --git a/htdocs/install/mysql/tables/llx_facturedet_rec.key.sql b/htdocs/install/mysql/tables/llx_facturedet_rec.key.sql new file mode 100644 index 00000000000..45619e94727 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_facturedet_rec.key.sql @@ -0,0 +1,21 @@ +-- =================================================================== +-- Copyright (C) 2005 Laurent Destailleur +-- Copyright (C) 2011 Regis Houssin +-- Copyright (C) 2012 Cedric Salvador +-- +-- 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 . +-- +-- =================================================================== + +ALTER TABLE llx_facturedet_rec ADD CONSTRAINT fk_facturedet_rec_fk_unit FOREIGN KEY (fk_unit) REFERENCES llx_c_units (rowid); diff --git a/htdocs/install/mysql/tables/llx_facturedet_rec.sql b/htdocs/install/mysql/tables/llx_facturedet_rec.sql index 05bfa71ec2e..164dc2f94d5 100644 --- a/htdocs/install/mysql/tables/llx_facturedet_rec.sql +++ b/htdocs/install/mysql/tables/llx_facturedet_rec.sql @@ -3,6 +3,7 @@ -- Copyright (C) 2009-2014 Laurent Destailleur -- Copyright (C) 2010 Juanjo Menent -- Copyright (C) 2010-2012 Regis Houssin +-- Copyright (C) 2012 Cédric Salvador -- -- 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; diff --git a/htdocs/install/mysql/tables/llx_product.key.sql b/htdocs/install/mysql/tables/llx_product.key.sql index fb471910230..5157861ba4b 100644 --- a/htdocs/install/mysql/tables/llx_product.key.sql +++ b/htdocs/install/mysql/tables/llx_product.key.sql @@ -2,6 +2,7 @@ -- Copyright (C) 2002-2004 Rodolphe Quiedeville -- Copyright (C) 2004-2013 Laurent Destailleur -- Copyright (C) 2005-2009 Regis Houssin +-- Copyright (C) 2012 Cédric Salvador -- Copyright (C) 2014 Marcos García -- -- 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); diff --git a/htdocs/install/mysql/tables/llx_product.sql b/htdocs/install/mysql/tables/llx_product.sql index 03c5c5edd3c..5abbdcdde97 100755 --- a/htdocs/install/mysql/tables/llx_product.sql +++ b/htdocs/install/mysql/tables/llx_product.sql @@ -2,8 +2,8 @@ -- Copyright (C) 2002-2006 Rodolphe Quiedeville -- Copyright (C) 2008-2010 Laurent Destailleur -- Copyright (C) 2005-2010 Regis Houssin --- Copyright (C) 2010 juanjo Menent --- Copyright (C) 2013 Cédric Salvador +-- Copyright (C) 2010 Juanjo Menent +-- Copyright (C) 2012-2013 Cédric Salvador -- Copyright (C) 2014 Marcos García -- -- 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; diff --git a/htdocs/install/mysql/tables/llx_propaldet.key.sql b/htdocs/install/mysql/tables/llx_propaldet.key.sql index eb56554a60f..3d3467ea888 100644 --- a/htdocs/install/mysql/tables/llx_propaldet.key.sql +++ b/htdocs/install/mysql/tables/llx_propaldet.key.sql @@ -1,5 +1,6 @@ -- =================================================================== -- Copyright (C) 2009-2011 Regis Houssin +-- Copyright (C) 2012 Cédric Salvador -- -- 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); diff --git a/htdocs/install/mysql/tables/llx_propaldet.sql b/htdocs/install/mysql/tables/llx_propaldet.sql index 624292decd6..299767ae2ed 100644 --- a/htdocs/install/mysql/tables/llx_propaldet.sql +++ b/htdocs/install/mysql/tables/llx_propaldet.sql @@ -2,6 +2,7 @@ -- Copyright (C) 2002-2003 Rodolphe Quiedeville -- Copyright (C) 2005-2012 Regis Houssin -- Copyright (C) 2010 Juanjo Menent +-- Copyright (C) 2012 Cédric Salvador -- -- 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; diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 017c819d85e..33842e1ed8e 100755 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1371,6 +1371,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 ##### diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang index eb7261ab613..793fd40a2ce 100755 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -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 diff --git a/htdocs/product/admin/product.php b/htdocs/product/admin/product.php index 2d0c1cca468..fa7dc78092c 100644 --- a/htdocs/product/admin/product.php +++ b/htdocs/product/admin/product.php @@ -6,7 +6,8 @@ * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2011-2012 Juanjo Menent * Copyright (C) 2012 Christophe Battarel -** + * Copyright (C) 2012 Cedric Salvador + * * 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 @@ -172,6 +173,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++; @@ -424,6 +431,21 @@ print ''; print ''; print ''; +// Use units +$var=!$var; +print '
'; +print ''; +print ''; +print ''; +print ''.$langs->trans("UseUnits").''; +print ''; +print $form->selectyesno("activate_units",$conf->global->PRODUCT_USE_UNITS,1); +print ''; +print ''; +print ''; +print ''; +print '
'; + // View product description in thirdparty language if (! empty($conf->global->MAIN_MULTILANGS)) { diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 50ed04a29df..03f62221c05 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -7,7 +7,7 @@ * Copyright (C) 2006 Auguria SARL * Copyright (C) 2010-2014 Juanjo Menent * Copyright (C) 2013-2014 Marcos García - * Copyright (C) 2013 Cédric Salvador + * Copyright (C) 2012-2013 Cédric Salvador * Copyright (C) 2011-2014 Alexandre Spangaro * Copyright (C) 2014 Cédric Gross * Copyright (C) 2014 Ferran Marcet @@ -179,6 +179,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'); @@ -240,6 +242,9 @@ if (empty($reshook)) $object->volume_units = GETPOST('volume_units'); $object->finished = GETPOST('finished'); $object->hidden = GETPOST('hidden')=='yes'?1:0; + 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'); @@ -318,6 +323,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 @@ -554,7 +567,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) { @@ -646,7 +671,18 @@ if (empty($reshook)) '', '', $price_base_type, - $pu_ttc + $pu_ttc, + '', + '', + 0, + -1, + 0, + 0, + null, + 0, + '', + 0, + $object->fk_unit ); if ($result > 0) @@ -739,7 +775,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) @@ -993,10 +1042,20 @@ 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 ""; - print ''; + print ""; + + // Units + if($conf->global->PRODUCT_USE_UNITS) + { + print ''.$langs->trans('Unit').''; + print ''; + $form->select_units("units"); + print ''; print '
'; @@ -1261,8 +1320,18 @@ else $doleditor = new DolEditor('note', $object->note, '', 140, 'dolibarr_notes', '', false, true, $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC, 4, 80); $doleditor->Create(); - print ""; - print ''; + print ""; + + // Units + if($conf->global->PRODUCT_USE_UNITS) + { + print ''.$langs->trans('Unit').''; + print ''; + $form->select_units($object->fk_unit); + print ''; + } + + print ''; print '
'; @@ -1529,6 +1598,18 @@ else print "\n"; } + // Unit + if($conf->global->PRODUCT_USE_UNITS) + { + $unit = $object->get_unit_label(); + + print ''.$langs->trans('Unit').''; + if ($unit !== '') { + print $langs->trans($unit); + } + print ''; + } + // Custom code if (empty($conf->global->PRODUCT_DISABLE_CUSTOM_INFO)) { diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 43da5af3cea..10b0599e371 100755 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -5,6 +5,7 @@ * Copyright (C) 2006 Andre Cianfarani * Copyright (C) 2007-2011 Jean Heimburger * Copyright (C) 2010-2013 Juanjo Menent + * Copyright (C) 2012 Cedric Salvador * Copyright (C) 2013-2014 Cedric GROSS * Copyright (C) 2013-2014 Marcos García * Copyright (C) 2011-2014 Alexandre Spangaro @@ -169,6 +170,12 @@ class Product extends CommonObject var $fk_price_expression; + /** + * Unit + * @var int + */ + public $fk_unit; + /** * Constructor * @@ -360,6 +367,7 @@ class Product extends CommonObject $sql.= ", canvas"; $sql.= ", finished"; $sql.= ", tobatch"; + $sql.= ", fk_unit"; $sql.= ") VALUES ("; $sql.= "'".$this->db->idate($now)."'"; $sql.= ", ".$conf->entity; @@ -380,6 +388,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); @@ -669,6 +678,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); @@ -1467,7 +1477,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); @@ -1546,6 +1556,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); @@ -3727,6 +3738,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 * From eb99202dc22cb568b7019f9ea4839f78355101f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Mon, 2 Mar 2015 01:10:31 +0100 Subject: [PATCH 02/18] Little changes --- htdocs/install/mysql/migration/3.7.0-3.8.0.sql | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/htdocs/install/mysql/migration/3.7.0-3.8.0.sql b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql index e8d4f77d5f8..1b780fc8469 100755 --- a/htdocs/install/mysql/migration/3.7.0-3.8.0.sql +++ b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql @@ -1,4 +1,4 @@ -NULL- +-- -- Be carefull to requests order. -- This file must be loaded by calling /install/index.php page -- when current version is 3.8.0 or higher. @@ -219,7 +219,6 @@ create table llx_c_units( )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 ('NA','aucune','', 1); 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); From 5a68cba0137ecc62f9ef09baba42fd6497ec80d0 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Sun, 19 Apr 2015 13:25:43 +0200 Subject: [PATCH 03/18] Create salaries.lib.php add lib salaries for menu management --- htdocs/core/lib/salaries.lib.php | 53 ++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 htdocs/core/lib/salaries.lib.php diff --git a/htdocs/core/lib/salaries.lib.php b/htdocs/core/lib/salaries.lib.php new file mode 100644 index 00000000000..cff64bbf31f --- /dev/null +++ b/htdocs/core/lib/salaries.lib.php @@ -0,0 +1,53 @@ + + * + * 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 . + * or see http://www.gnu.org/ + */ + +/** + * Returns an array with the tabs for the "salaries" section + * It loads tabs from modules looking for the entity salaries + * + * @param Paiement $object Current salaries object + * @return array Tabs for the salaries section + */ +function salaries_prepare_head($object) { + + global $langs, $conf; + + $h = 0; + $head = array(); + + $head[$h][0] = DOL_URL_ROOT.'/compta/salaries/card.php?id='.$object->id; + $head[$h][1] = $langs->trans("Card"); + $head[$h][2] = 'salaries'; + $h++; + + // Show more tabs from modules + // Entries must be declared in modules descriptor with line + // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab + // $this->tabs = array('entity:-tabname); to remove a tab + complete_head_from_modules($conf,$langs,$object,$head,$h,'salaries'); + + $head[$h][0] = DOL_URL_ROOT.'/compta/salaries/info.php?id='.$object->id; + $head[$h][1] = $langs->trans("Info"); + $head[$h][2] = 'info'; + $h++; + + complete_head_from_modules($conf,$langs,$object,$head,$h,'salaries', 'remove'); + + return $head; +} From a151defc4b2c4906c2d3f8daa77e935aad652363 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Sun, 19 Apr 2015 13:28:51 +0200 Subject: [PATCH 04/18] Add tabs management --- htdocs/compta/salaries/card.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/htdocs/compta/salaries/card.php b/htdocs/compta/salaries/card.php index 5c943aacbca..1fd3e1e59e0 100644 --- a/htdocs/compta/salaries/card.php +++ b/htdocs/compta/salaries/card.php @@ -2,6 +2,7 @@ /* Copyright (C) 2011-2014 Alexandre Spangaro * Copyright (C) 2014 Laurent Destailleur * Copyright (C) 2015 Jean-François Ferry + * Copyright (C) 2015 Charlie BENKE * * 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 @@ -27,6 +28,8 @@ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/compta/salaries/class/paymentsalary.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/salaries.lib.php'; + $langs->load("compta"); $langs->load("banks"); @@ -298,11 +301,8 @@ if ($action == 'create') if ($id) { - $h = 0; - $head[$h][0] = DOL_URL_ROOT.'/compta/salaries/card.php?id='.$salpayment->id; - $head[$h][1] = $langs->trans('Card'); - $head[$h][2] = 'card'; - $h++; + + $head=salaries_prepare_head($object); dol_fiche_head($head, 'card', $langs->trans("SalaryPayment"), 0, 'payment'); From 51cb680f19208c2b61ebba6bc25a2bc385b50b6c Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Sun, 19 Apr 2015 13:32:59 +0200 Subject: [PATCH 05/18] Create info.php add info tabs --- htdocs/compta/salaries/info.php | 68 +++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 htdocs/compta/salaries/info.php diff --git a/htdocs/compta/salaries/info.php b/htdocs/compta/salaries/info.php new file mode 100644 index 00000000000..4d060685d54 --- /dev/null +++ b/htdocs/compta/salaries/info.php @@ -0,0 +1,68 @@ + + * Copyright (C) 2015 Charlie BENKE + * + * 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 . + */ + +/** + * \file htdocs/compta/salaries/info.php + * \ingroup salaries + * \brief Page with info about salaries contribution + */ + +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/salaries.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; + +$langs->load("compta"); +$langs->load("bills"); +$langs->load("salaries"); + +$id=GETPOST('id','int'); +$action=GETPOST("action"); + +// Security check +$socid = GETPOST('socid','int'); +if ($user->societe_id) $socid=$user->societe_id; +$result = restrictedArea($user, 'salaries', '', '', ''); + + +/* + * View + */ + +$help_url='EN:Module_Salaries|FR:Module Fiche de paie|ES:Módulo Salarios'; +llxHeader("",$langs->trans("Salaries"),$help_url); + + +$salpayment = new PaymentSalary($db); +$result = $salpayment->fetch($id); +$salpayment->info($id); + +$head = salaries_prepare_head($salpayment); + +dol_fiche_head($head, 'info', $langs->trans("SalaryPayment"), 0, 'payment'); + + +print '
'; +dol_print_object_info($salpayment); +print '
'; + +print ''; + +llxFooter(); + +$db->close(); From 7be7a770c1ffe2129e24968bd00e4f83ed1db4b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Sun, 19 Apr 2015 15:59:49 +0200 Subject: [PATCH 06/18] Implemented units for CommandeFournisseur and FactureFournisseur --- htdocs/comm/propal.php | 2 +- htdocs/contrat/card.php | 4 +- .../pdf/pdf_canelle.modules.php | 50 +++++++++++++++-- .../pdf/pdf_muscadet.modules.php | 54 ++++++++++++++++--- htdocs/core/tpl/objectline_edit.tpl.php | 1 - .../class/fournisseur.commande.class.php | 25 +++++---- .../fourn/class/fournisseur.facture.class.php | 18 ++++--- htdocs/fourn/commande/card.php | 22 ++++++-- htdocs/fourn/commande/orderstoinvoice.php | 2 +- htdocs/fourn/facture/card.php | 22 +++++--- .../install/mysql/migration/3.7.0-3.8.0.sql | 8 ++- .../mysql/tables/llx_commande_fournisseur.sql | 2 +- .../llx_commande_fournisseurdet.key.sql | 19 +++++++ .../tables/llx_commande_fournisseurdet.sql | 4 +- .../tables/llx_facture_fourn_det.key.sql | 1 + .../mysql/tables/llx_facture_fourn_det.sql | 3 +- htdocs/product/card.php | 1 + 17 files changed, 192 insertions(+), 46 deletions(-) create mode 100644 htdocs/install/mysql/tables/llx_commande_fournisseurdet.key.sql diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 10d51feb798..4143f2b8ffd 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -452,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; diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index d9afbe892ad..2841c709fcc 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -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) diff --git a/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php b/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php index 8b803eece33..c01dfacd1c3 100644 --- a/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php +++ b/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php @@ -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); diff --git a/htdocs/core/modules/supplier_order/pdf/pdf_muscadet.modules.php b/htdocs/core/modules/supplier_order/pdf/pdf_muscadet.modules.php index ef34c1bf50b..0089790f804 100644 --- a/htdocs/core/modules/supplier_order/pdf/pdf_muscadet.modules.php +++ b/htdocs/core/modules/supplier_order/pdf/pdf_muscadet.modules.php @@ -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); diff --git a/htdocs/core/tpl/objectline_edit.tpl.php b/htdocs/core/tpl/objectline_edit.tpl.php index f93595456d2..eb9c7521236 100644 --- a/htdocs/core/tpl/objectline_edit.tpl.php +++ b/htdocs/core/tpl/objectline_edit.tpl.php @@ -129,7 +129,6 @@ $coldisplay=-1; // We remove first td print '>'; } ?> - info_bits & 2) != 2) { // I comment this because it shows info even when not required diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 3b6de210928..ddddcf059a3 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -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; diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 59ea5544681..dd4e5f598d2 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -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'; diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index fe6751c28f2..113758b7ee9 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -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) { diff --git a/htdocs/fourn/commande/orderstoinvoice.php b/htdocs/fourn/commande/orderstoinvoice.php index 6cd0dfb02c2..d35d318d4a2 100644 --- a/htdocs/fourn/commande/orderstoinvoice.php +++ b/htdocs/fourn/commande/orderstoinvoice.php @@ -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; diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index 4c401c2c540..edac67e3fbf 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -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']); diff --git a/htdocs/install/mysql/migration/3.7.0-3.8.0.sql b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql index 586ee98150d..68f918d7605 100755 --- a/htdocs/install/mysql/migration/3.7.0-3.8.0.sql +++ b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql @@ -576,4 +576,10 @@ 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); \ No newline at end of file +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); \ No newline at end of file diff --git a/htdocs/install/mysql/tables/llx_commande_fournisseur.sql b/htdocs/install/mysql/tables/llx_commande_fournisseur.sql index 33588d8bf66..3b1dee31b9e 100644 --- a/htdocs/install/mysql/tables/llx_commande_fournisseur.sql +++ b/htdocs/install/mysql/tables/llx_commande_fournisseur.sql @@ -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; diff --git a/htdocs/install/mysql/tables/llx_commande_fournisseurdet.key.sql b/htdocs/install/mysql/tables/llx_commande_fournisseurdet.key.sql new file mode 100644 index 00000000000..99d953ec17c --- /dev/null +++ b/htdocs/install/mysql/tables/llx_commande_fournisseurdet.key.sql @@ -0,0 +1,19 @@ +-- ============================================================================ +-- Copyright (C) 2015 Marcos García +-- +-- 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 . +-- +-- ============================================================================ + +ALTER TABLE llx_commande_fournisseurdet ADD CONSTRAINT fk_commande_fournisseurdet_fk_unit FOREIGN KEY (fk_unit) REFERENCES llx_c_units (rowid); \ No newline at end of file diff --git a/htdocs/install/mysql/tables/llx_commande_fournisseurdet.sql b/htdocs/install/mysql/tables/llx_commande_fournisseurdet.sql index cb2ec488272..a3dbd87d359 100644 --- a/htdocs/install/mysql/tables/llx_commande_fournisseurdet.sql +++ b/htdocs/install/mysql/tables/llx_commande_fournisseurdet.sql @@ -2,6 +2,7 @@ -- Copyright (C) 2007 Rodolphe Quiedeville -- Copyright (C) 2007-2009 Laurent Destailleur -- Copyright (C) 2010-2012 Juanjo Menent +-- Copyright (C) 2015 Marcos García -- -- 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; diff --git a/htdocs/install/mysql/tables/llx_facture_fourn_det.key.sql b/htdocs/install/mysql/tables/llx_facture_fourn_det.key.sql index 907f09360a1..2048cf06024 100644 --- a/htdocs/install/mysql/tables/llx_facture_fourn_det.key.sql +++ b/htdocs/install/mysql/tables/llx_facture_fourn_det.key.sql @@ -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); \ No newline at end of file diff --git a/htdocs/install/mysql/tables/llx_facture_fourn_det.sql b/htdocs/install/mysql/tables/llx_facture_fourn_det.sql index 3985d0d3483..ad066752ea0 100644 --- a/htdocs/install/mysql/tables/llx_facture_fourn_det.sql +++ b/htdocs/install/mysql/tables/llx_facture_fourn_det.sql @@ -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; diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 475be8fdf79..eaef488dac3 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -244,6 +244,7 @@ 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; } From 28b89a2decd3bf76f2935dc488ebd90153ed2594 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Sun, 19 Apr 2015 18:58:56 +0200 Subject: [PATCH 07/18] Fix [ bug #1786 ] Spanish localtax2 calculation errors with corrective invoices --- htdocs/compta/facture/class/facture.class.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 83210476a13..ddd31a18aaa 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -2201,9 +2201,9 @@ class Facture extends CommonInvoice $this->line->info_bits=$info_bits; $this->line->fk_remise_except=$fk_remise_except; $this->line->total_ht= (($this->type==self::TYPE_CREDIT_NOTE||$qty<0)?-abs($total_ht):$total_ht); // For credit note and if qty is negative, total is negative - $this->line->total_tva= (($this->type==self::TYPE_CREDIT_NOTE||$qty<0)?-abs($total_tva):$total_tva); - $this->line->total_localtax1=(($this->type==self::TYPE_CREDIT_NOTE||$qty<0)?-abs($total_localtax1):$total_localtax1); - $this->line->total_localtax2=(($this->type==self::TYPE_CREDIT_NOTE||$qty<0)?-abs($total_localtax2):$total_localtax2); + $this->line->total_tva= $total_tva; + $this->line->total_localtax1=$total_localtax1; + $this->line->total_localtax2=$total_localtax2; $this->line->localtax1_type = $localtaxes_type[0]; $this->line->localtax2_type = $localtaxes_type[2]; $this->line->total_ttc= (($this->type==self::TYPE_CREDIT_NOTE||$qty<0)?-abs($total_ttc):$total_ttc); @@ -2354,9 +2354,9 @@ class Facture extends CommonInvoice $this->line->date_start = $date_start; $this->line->date_end = $date_end; $this->line->total_ht = (($this->type==self::TYPE_CREDIT_NOTE||$qty<0)?-abs($total_ht):$total_ht); // For credit note and if qty is negative, total is negative - $this->line->total_tva = (($this->type==self::TYPE_CREDIT_NOTE||$qty<0)?-abs($total_tva):$total_tva); - $this->line->total_localtax1 = (($this->type==self::TYPE_CREDIT_NOTE||$qty<0)?-abs($total_localtax1):$total_localtax1); - $this->line->total_localtax2 = (($this->type==self::TYPE_CREDIT_NOTE||$qty<0)?-abs($total_localtax2):$total_localtax2); + $this->line->total_tva = $total_tva; + $this->line->total_localtax1 = $total_localtax1; + $this->line->total_localtax2 = $total_localtax2; $this->line->total_ttc = (($this->type==self::TYPE_CREDIT_NOTE||$qty<0)?-abs($total_ttc):$total_ttc); $this->line->info_bits = $info_bits; $this->line->special_code = $special_code; From f2d05ce75473266eab98889ba512c0042f312a69 Mon Sep 17 00:00:00 2001 From: jfefe Date: Mon, 20 Apr 2015 16:20:04 +0200 Subject: [PATCH 08/18] Add missing value for object line type (product or service) --- htdocs/core/class/commondocgenerator.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php index bf11c4fea13..22a33f4d2a8 100644 --- a/htdocs/core/class/commondocgenerator.class.php +++ b/htdocs/core/class/commondocgenerator.class.php @@ -408,6 +408,7 @@ abstract class CommonDocGenerator 'line_fulldesc'=>doc_getlinedesc($line,$outputlangs), 'line_product_ref'=>$line->product_ref, 'line_product_label'=>$line->product_label, + 'line_product_type'=>$line->product_type, 'line_desc'=>$line->desc, 'line_vatrate'=>vatrate($line->tva_tx,true,$line->info_bits), 'line_up'=>price2num($line->subprice), From 9f899c93ef4217a72191ab0d5e7977ad8d9af3c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Mon, 20 Apr 2015 17:11:09 +0200 Subject: [PATCH 09/18] Update .travis.yml --- .travis.yml | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b5d73fc763f..14b55443c26 100644 --- a/.travis.yml +++ b/.travis.yml @@ -66,7 +66,24 @@ before_script: - sh -c "if [ '$PHPV' = '5.4' ]; then echo 'zend_extension_ts = xdebug.so' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi" - cat ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini - echo Mysql version + # INSTALL MYSQL 5.6 + # (https://github.com/piwik/piwik/commit/20bd2e1c24e5d673dce3feb256204ad48c29f160) + # TODO: Remove when mysql 5.6 is provided by travis. + # Otherwise, our migrations will raise a syntax error. + - "sudo apt-get remove mysql-common mysql-server-5.5 mysql-server-core-5.5 mysql-client-5.5 mysql-client-core-5.5" + - "sudo apt-get autoremove" + - "sudo apt-get install libaio1" + - "wget -O mysql-5.6.14.deb http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.14-debian6.0-x86_64.deb/from/http://cdn.mysql.com/" + - "sudo dpkg -i mysql-5.6.14.deb" + - "sudo cp /opt/mysql/server-5.6/support-files/mysql.server /etc/init.d/mysql.server" + - "sudo ln -s /opt/mysql/server-5.6/bin/* /usr/bin/" + - "sudo sed -i'' 's/table_cache/table_open_cache/' /etc/mysql/my.cnf" + - "sudo sed -i'' 's/log_slow_queries/slow_query_log/' /etc/mysql/my.cnf" + - "sudo sed -i'' 's/basedir[^=]\\+=.*$/basedir = \\/opt\\/mysql\\/server-5.6/' /etc/mysql/my.cnf" + - "sudo /etc/init.d/mysql.server start" - mysql --version + - mysql -e "SELECT VERSION();" + # /END MYSQL 5.6- mysql --version - echo Init database - sh -c "if [ '$DB' = 'pgsql' ]; then psql -c 'DROP DATABASE IF EXISTS myapp_test;' -U postgres; fi" - sh -c "if [ '$DB' = 'pgsql' ]; then psql -c 'CREATE DATABASE myapp_test;' -U postgres; fi" @@ -90,7 +107,6 @@ before_script: - echo Install apache server - sudo apt-get update - sudo apt-get install -y --force-yes apache2 libapache2-mod-php5 php5-curl php5-mysql php5-pgsql php5-intl - - sudo apt-get install mysql-server-5.6 mysql-client-5.6 - sudo sed -i -e "s,/var/www,$(pwd)/htdocs,g" /etc/apache2/sites-available/default - echo Show default virtual host - sudo cat /etc/apache2/sites-available/default From 7a4d1d990e47e5969eb2e3e289ee7e1b6e86d6fe Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 21 Apr 2015 11:41:21 +0200 Subject: [PATCH 10/18] Fix security hole --- htdocs/filefunc.inc.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/htdocs/filefunc.inc.php b/htdocs/filefunc.inc.php index 13b2d8d1669..a5fdcbd24d3 100644 --- a/htdocs/filefunc.inc.php +++ b/htdocs/filefunc.inc.php @@ -67,12 +67,15 @@ $conffiletoshow = "htdocs/conf/conf.php"; //$conffile = "/etc/dolibarr/conf.php"; //$conffiletoshow = "/etc/dolibarr/conf.php"; -//replace conf filename with "conf" parameter on url by GET -if (!empty($_GET['conf'])) { - setcookie('dolconf', $_GET['conf'],0,'/'); - $conffile = 'conf/' . $_GET['conf'] . '.php'; +// Replace conf filename with "conf" parameter on url by GET +if (! empty($_GET['conf'])) +{ + $confname=basename($_GET['conf']); + setcookie('dolconf', $confname, 0, '/'); + $conffile = 'conf/'.$confname.'.php'; } else { - $conffile = 'conf/' . (!empty($_COOKIE['dolconf']) ? $_COOKIE['dolconf'] : 'conf') . '.php'; + $confname=basename(empty($_COOKIE['dolconf']) ? 'conf' : $_COOKIE['dolconf']); + $conffile = 'conf/'.$confname.'.php'; } From 5a9c40eb5916f64e54f4b0466025b92eff8c730a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 21 Apr 2015 12:03:51 +0200 Subject: [PATCH 11/18] Fix minor look and security errors --- htdocs/comm/propal.php | 24 ++++++++++++------------ htdocs/filefunc.inc.php | 2 ++ htdocs/theme/eldy/style.css.php | 4 ++-- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index c5cd570c241..856f39c2c58 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -1374,7 +1374,7 @@ if ($action == 'create') $absolute_discount = $soc->getAvailableDiscounts(); print '. '; if ($absolute_discount) - print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount), $langs->trans("Currency" . $conf->currency)); + print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount, 0, $langs, 1, -1, -1, $conf->currency)); else print $langs->trans("CompanyHasNoAbsoluteDiscount"); print '.'; @@ -1516,18 +1516,18 @@ if ($action == 'create') $newclassname = 'Intervention'; print '' . $langs->trans($newclassname) . '' . $objectsrc->getNomUrl(1) . ''; - print '' . $langs->trans('TotalHT') . '' . price($objectsrc->total_ht) . ''; - print '' . $langs->trans('TotalVAT') . '' . price($objectsrc->total_tva) . ""; + print '' . $langs->trans('TotalHT') . '' . price($objectsrc->total_ht, 0, $langs, 1, -1, -1, $conf->currency) . ''; + print '' . $langs->trans('TotalVAT') . '' . price($objectsrc->total_tva, 0, $langs, 1, -1, -1, $conf->currency) . ""; if ($mysoc->localtax1_assuj == "1" || $objectsrc->total_localtax1 != 0 ) // Localtax1 { - print '' . $langs->transcountry("AmountLT1", $mysoc->country_code) . '' . price($objectsrc->total_localtax1) . ""; + print '' . $langs->transcountry("AmountLT1", $mysoc->country_code) . '' . price($objectsrc->total_localtax1, 0, $langs, 1, -1, -1, $conf->currency) . ""; } if ($mysoc->localtax2_assuj == "1" || $objectsrc->total_localtax2 != 0) // Localtax2 { - print '' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '' . price($objectsrc->total_localtax2) . ""; + print '' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '' . price($objectsrc->total_localtax2, 0, $langs, 1, -1, -1, $conf->currency) . ""; } - print '' . $langs->trans('TotalTTC') . '' . price($objectsrc->total_ttc) . ""; + print '' . $langs->trans('TotalTTC') . '' . price($objectsrc->total_ttc, 0, $langs, 1, -1, -1, $conf->currency) . ""; } print "\n"; @@ -1990,7 +1990,7 @@ if ($action == 'create') print $langs->trans('OutstandingBill'); print ''; print price($soc->get_OutstandingBill()) . ' / '; - print price($soc->outstanding_limit, 0, '', 1, - 1, - 1, $conf->currency); + print price($soc->outstanding_limit, 0, $langs, 1, - 1, - 1, $conf->currency); print ''; print ''; } @@ -2044,7 +2044,7 @@ if ($action == 'create') // Amount HT print '' . $langs->trans('AmountHT') . ''; - print '' . price($object->total_ht, '', $langs, 0, - 1, - 1, $conf->currency) . ''; + print '' . price($object->total_ht, '', $langs, 0, - 1, - 1, $conf->currency) . ''; // Margin Infos if (! empty($conf->margin->enabled)) { @@ -2056,26 +2056,26 @@ if ($action == 'create') // Amount VAT print '' . $langs->trans('AmountVAT') . ''; - print '' . price($object->total_tva, '', $langs, 0, - 1, - 1, $conf->currency) . ''; + print '' . price($object->total_tva, '', $langs, 0, - 1, - 1, $conf->currency) . ''; print ''; // Amount Local Taxes if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) // Localtax1 { print '' . $langs->transcountry("AmountLT1", $mysoc->country_code) . ''; - print '' . price($object->total_localtax1, '', $langs, 0, - 1, - 1, $conf->currency) . ''; + print '' . price($object->total_localtax1, '', $langs, 0, - 1, - 1, $conf->currency) . ''; print ''; } if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) // Localtax2 { print '' . $langs->transcountry("AmountLT2", $mysoc->country_code) . ''; - print '' . price($object->total_localtax2, '', $langs, 0, - 1, - 1, $conf->currency) . ''; + print '' . price($object->total_localtax2, '', $langs, 0, - 1, - 1, $conf->currency) . ''; print ''; } // Amount TTC print '' . $langs->trans('AmountTTC') . ''; - print '' . price($object->total_ttc, '', $langs, 0, - 1, - 1, $conf->currency) . ''; + print '' . price($object->total_ttc, '', $langs, 0, - 1, - 1, $conf->currency) . ''; print ''; // Statut diff --git a/htdocs/filefunc.inc.php b/htdocs/filefunc.inc.php index a5fdcbd24d3..7dfc7ef1e71 100644 --- a/htdocs/filefunc.inc.php +++ b/htdocs/filefunc.inc.php @@ -84,6 +84,8 @@ $result=@include_once $conffile; // Keep @ because with some error reporting thi if (! $result && ! empty($_SERVER["GATEWAY_INTERFACE"])) // If install not done and we are in a web session { + // Note: If calling page was not into htdocs (index.php, ...), then this redirect will fails. + // There is no real solution, because the only way to know the apache url relative path is to have into conf file. header("Location: install/index.php"); exit; } diff --git a/htdocs/theme/eldy/style.css.php b/htdocs/theme/eldy/style.css.php index 2d9f51bb2aa..8ab891d388d 100644 --- a/htdocs/theme/eldy/style.css.php +++ b/htdocs/theme/eldy/style.css.php @@ -1796,11 +1796,11 @@ table.nobordernopadding { } table.nobordernopadding tr { border: 0px !important; - padding: 0px 0px; + padding: 0px 0px !important; } table.nobordernopadding td { border: 0px !important; - padding: 0px 0px; + padding: 0px 0px !important; } /* For lists */ From a69027606057913c9035218aff700dbd88f8248a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 21 Apr 2015 12:08:36 +0200 Subject: [PATCH 12/18] Fix js warnings, select2 css was not loaded. --- htdocs/core/class/conf.class.php | 2 +- htdocs/main.inc.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php index ef0bef87c4b..6370062a6a9 100644 --- a/htdocs/core/class/conf.class.php +++ b/htdocs/core/class/conf.class.php @@ -448,7 +448,7 @@ class Conf if (! isset($this->global->MAIN_MODULES_FOR_EXTERNAL)) $this->global->MAIN_MODULES_FOR_EXTERNAL='user,askpricesupplier,facture,categorie,commande,fournisseur,contact,propal,projet,contrat,societe,ficheinter,expedition,agenda,adherent'; // '' means 'all'. Note that contact is added here as it should be a module later. // Enable select2 - if (empty($this->global->MAIN_USE_JQUERY_MULTISELECT)) $this->global->MAIN_USE_JQUERY_MULTISELECT='select2.min'; + if (empty($this->global->MAIN_USE_JQUERY_MULTISELECT)) $this->global->MAIN_USE_JQUERY_MULTISELECT='select2'; // Timeouts if (empty($this->global->MAIN_USE_CONNECT_TIMEOUT)) $this->global->MAIN_USE_CONNECT_TIMEOUT=10; diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index d0b80db1190..4ae94b276fa 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -1189,10 +1189,10 @@ function top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs print ''."\n"; print ''."\n"; } - if (! empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) || defined('REQUIRE_JQUERY_MULTISELECT')) // jQuery plugin "mutiselect", "multiple-select", "select2"... + if (! empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) || defined('REQUIRE_JQUERY_MULTISELECT')) // jQuery plugin "mutiselect", "multiple-select", "select2", ... { $tmpplugin=empty($conf->global->MAIN_USE_JQUERY_MULTISELECT)?constant('REQUIRE_JQUERY_MULTISELECT'):$conf->global->MAIN_USE_JQUERY_MULTISELECT; - print ''."\n"; + print ''."\n"; } // jQuery jMobile if (! empty($conf->global->MAIN_USE_JQUERY_JMOBILE) || defined('REQUIRE_JQUERY_JMOBILE') || (! empty($conf->dol_use_jmobile) && $conf->dol_use_jmobile > 0)) From d5e40057e7bf7949a30cd137dda1c0b5a0a73b84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Doursenaud?= Date: Tue, 21 Apr 2015 14:29:16 +0200 Subject: [PATCH 13/18] Added a mailmap for better git statistics --- .mailmap | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 .mailmap diff --git a/.mailmap b/.mailmap new file mode 100644 index 00000000000..5452dfd7ece --- /dev/null +++ b/.mailmap @@ -0,0 +1,49 @@ +Laurent Destailleur Laurent Destailleur +Laurent Destailleur eldy +Laurent Destailleur Laurent Destailleur +Laurent Destailleur eldy10 +Laurent Destailleur Laurent Destailleur +Regis Houssin Regis Houssin +Regis Houssin Régis Houssin +Juanjo Menent simnandez +Juanjo Menent Juanjo Menent +Juanjo Menent Simnandez +Juanjo Menent juanjo +Juanjo Menent juanjo +Marcos García de La Fuente Marcos García +Marcos García de La Fuente Marcos García +Florian Henry fhenry +Florian Henry Florian HENRY +Florian Henry FHenry +Florian Henry Florian HENRY +Florian Henry FHenry +Florian Henry HENRY Florian +Alexandre Spangaro aspangaro +Alexandre Spangaro Spangaro Alexandre +Alexandre Spangaro Alexandre SPANGARO +Raphaël Doursenaud Raphaël Doursenaud +Philippe Grand Grand Philippe +Philippe Grand Philippe GRAND +Philippe Grand philippe grand +Philippe Grand philippe +Philippe Grand unknown +Philippe Grand philippe +Philippe Grand Philippe Grand +Jean-François Ferry jfefe +Jean-François Ferry jfefe +Jean-François Ferry JF FERRY +Jean-François Ferry JF FERRY +Charles Benke BENKE Charles +Charles Benke BENKE Charlie +Charles Benke defrance69 +Maxime Kohlhaas MAxime Kohlhaas +Frédéric France Frédéric FRANCE +Frédéric France frederic34 +Frédéric France FRANCE Frédéric +Frédéric France frederic34 +Cyrille de Lambert cdelambert +Cédric Gross KreizIT +Cédric Gross Cedric +Cédric Gross Cedric GROSS +Jean Heimburger jean +Jean Heimburger tiaris From 96a33bbe8adcb8c1a2fdade61804e5c9d27cb316 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 21 Apr 2015 15:49:58 +0200 Subject: [PATCH 14/18] First clean of code after devcamp --- .travis.yml | 4 +-- htdocs/comm/propal.php | 6 +--- htdocs/comm/propal/class/propal.class.php | 10 +++--- htdocs/commande/card.php | 6 +--- htdocs/commande/class/commande.class.php | 8 ++--- htdocs/compta/facture.php | 6 +--- .../facture/class/facture-rec.class.php | 13 +++---- htdocs/compta/facture/class/facture.class.php | 6 ++-- htdocs/compta/facture/fiche-rec.php | 4 +-- htdocs/contrat/card.php | 34 ++++++++----------- htdocs/contrat/class/contrat.class.php | 10 +++--- htdocs/core/class/commonobject.class.php | 2 +- htdocs/core/class/commonobjectline.class.php | 12 +++---- htdocs/core/class/html.form.class.php | 34 +++++++------------ htdocs/core/lib/pdf.lib.php | 2 +- htdocs/core/tpl/objectline_create.tpl.php | 2 +- htdocs/core/tpl/objectline_edit.tpl.php | 2 +- htdocs/core/tpl/objectline_view.tpl.php | 2 +- .../class/fournisseur.commande.class.php | 14 ++++---- .../fourn/class/fournisseur.facture.class.php | 8 ++--- htdocs/fourn/commande/card.php | 6 +--- htdocs/fourn/facture/card.php | 6 +--- .../install/mysql/tables/llx_c_units.key.sql | 2 +- htdocs/product/card.php | 29 +++++++--------- htdocs/product/class/product.class.php | 8 ++--- 25 files changed, 100 insertions(+), 136 deletions(-) diff --git a/.travis.yml b/.travis.yml index 14b55443c26..5bc5f49b2e5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -128,9 +128,9 @@ script: - php upgrade.php 3.6.0 3.7.0 ignoredbversion > upgrade360370.log - php upgrade2.php 3.6.0 3.7.0 ignoredbversion > upgrade360370-2.log - php upgrade.php 3.7.0 3.8.0 ignoredbversion > upgrade370380.log - - cat upgrade370380.log +# - cat upgrade370380.log - php upgrade2.php 3.7.0 3.8.0 ignoredbversion > upgrade370380-2.log - - cat upgrade370380-2.log +# - cat upgrade370380-2.log - cd ../.. - date - phpunit -d memory_limit=-1 --configuration test/phpunit/phpunittest.xml test/phpunit/AllTests.php diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 4dbcd43c332..c4ef27645d4 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -846,11 +846,7 @@ if (empty($reshook)) $desc = $product_desc; $type = GETPOST('type'); - $fk_unit = GETPOST('units', 'int'); - - if ($fk_unit <= 0) { - $fk_unit = null; - } + $fk_unit = GETPOST('units', 'alpha'); } // Margin diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 43379eb221c..1a86a8ceb09 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -399,12 +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 + * @param string $fk_unit Code 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, $fk_unit = null) + 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; @@ -583,10 +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 + * @param string $fk_unit Code 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, $fk_unit = null) + 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; @@ -1923,7 +1923,7 @@ class Propal extends CommonObject if ( ! $error ) { $this->statut = $statut; - + $this->db->commit(); return 1; } diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index 1628f79abaa..a4d6d8d3a37 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -723,11 +723,7 @@ 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; - } + $fk_unit=GETPOST('units', 'alpha'); } // Margin diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 91b17273513..2f85461887e 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1169,7 +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 + * @param string $fk_unit Code of the unit to use. Null to use the default one * @return int >0 if OK, <0 if KO * * @see add_product @@ -1179,7 +1179,7 @@ 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, $fk_unit = null) + 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; @@ -2429,10 +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 + * @param string $fk_unit Code 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, $fk_unit = null) + 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; diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 19f4335b685..a78e64f675e 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -1376,11 +1376,7 @@ 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; - } + $fk_unit= GETPOST('units', 'alpha'); } // Margin diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php index 077299baa7d..7d0de20ce0b 100644 --- a/htdocs/compta/facture/class/facture-rec.class.php +++ b/htdocs/compta/facture/class/facture-rec.class.php @@ -1,9 +1,9 @@ - * Copyright (C) 2004-2012 Laurent Destailleur + * Copyright (C) 2004-2015 Laurent Destailleur * Copyright (C) 2009-2012 Regis Houssin * Copyright (C) 2010-2011 Juanjo Menent - * Copyright (C) 2012 Cedric Salvador + * Copyright (C) 2012 Cedric Salvador * Copyright (C) 2013 Florian Henry * Copyright (C) 2015 Marcos García * @@ -98,7 +98,7 @@ class FactureRec extends Facture // Clean parameters $this->titre=trim($this->titre); $this->usenewprice=empty($this->usenewprice)?0:$this->usenewprice; - + $this->db->begin(); // Charge facture modele @@ -415,9 +415,10 @@ class FactureRec extends Facture * @param int $rang Position of line * @param int $special_code Special code * @param string $label Label of the line + * @param string $fk_unit Unit * @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='', $fk_unit= null) + 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; @@ -499,7 +500,7 @@ class FactureRec extends Facture $sql.= ", '".price2num($total_ttc)."'"; $sql.= ", ".$rang; $sql.= ", ".$special_code; - $sql.= ", ".$fk_unit.")"; + $sql.= ", ".($fk_unit?"'".$this->db->escape($fk_unit)."'":"null").")"; dol_syslog(get_class($this)."::addline", LOG_DEBUG); if ($this->db->query($sql)) @@ -579,7 +580,7 @@ class FactureRec extends Facture return $result; } - + /** * Initialise an instance with random values. * Used to build previews or test instances. diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 920f165f83f..f97011acc57 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -2100,7 +2100,7 @@ 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 + * @param string $fk_unit Code 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='', $fk_unit = null) @@ -2283,8 +2283,8 @@ class Facture extends CommonInvoice * @param string $label Label of the line (deprecated, do not use) * @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 + * @param int $situation_percent Situation advance percentage + * @param string $fk_unit Code 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, $fk_unit = null) diff --git a/htdocs/compta/facture/fiche-rec.php b/htdocs/compta/facture/fiche-rec.php index c94e4961482..6a3bc3ab72d 100644 --- a/htdocs/compta/facture/fiche-rec.php +++ b/htdocs/compta/facture/fiche-rec.php @@ -306,7 +306,7 @@ if ($action == 'create') print ''.$objp->qty.''; if ($conf->global->PRODUCT_USE_UNITS) { - print ''.$product_static->get_unit_label().''; + print ''.$product_static->getLabelOfUnit().''; } // Percent @@ -528,7 +528,7 @@ else print ''.$object->lines[$i]->remise_percent.' %'; print ''.$object->lines[$i]->qty.''; if ($conf->global->PRODUCT_USE_UNITS) { - print "".$object->lines[$i]->get_unit_label().""; + print "".$object->lines[$i]->getLabelOfUnit().""; } print "\n"; $i++; diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index 2841c709fcc..7193634af54 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -505,11 +505,7 @@ 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; - } + $fk_unit= GETPOST('units', 'alpha'); } $localtax1_tx=get_localtax($tva_tx,1,$object->thirdparty); @@ -631,7 +627,7 @@ else if ($action == 'updateligne' && $user->rights->contrat->creer && ! GETPOST( else $pa_ht = null; - $fk_unit = GETPOST('unit', 'int'); + $fk_unit = GETPOST('unit', 'alpha'); $objectline->description=GETPOST('product_desc'); $objectline->price_ht=GETPOST('elprice'); @@ -650,7 +646,7 @@ else if ($action == 'updateligne' && $user->rights->contrat->creer && ! GETPOST( $objectline->pa_ht=$pa_ht; if ($fk_unit > 0) { - $objectline->fk_unit = $_POST['unit']; + $objectline->fk_unit = GETPOST('unit'); } else { $objectline->fk_unit = null; } @@ -977,7 +973,7 @@ if ($action == 'create') print ''; dol_fiche_head(); - + print ''; // Ref @@ -1087,7 +1083,7 @@ if ($action == 'create') print '
'.$langs->trans("Note").': '.$langs->trans("OnlyLinesWithTypeServiceAreUsed"); } } - + print "\n"; } else @@ -1291,7 +1287,7 @@ else if (! empty($conf->margin->enabled) && ! empty($object->element) && in_array($object->element,array('facture','propal','commande'))) $usemargins=1; $var=false; - + // Title line for service $cursorline=1; while ($cursorline <= $nbofservices) @@ -1327,7 +1323,7 @@ else print ''; print ''; print ''; - if($conf->global->PRODUCT_USE_UNITS) print ''; + if ($conf->global->PRODUCT_USE_UNITS) print ''; print ''; if (! empty($conf->margin->enabled) && ! empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) print ''; print ''; @@ -1368,8 +1364,8 @@ else print '\n"; // Quantite print ''; - //Unit - if($conf->global->PRODUCT_USE_UNITS) print ''; + // Unit + if($conf->global->PRODUCT_USE_UNITS) print ''; // Remise if ($objp->remise_percent > 0) { @@ -1494,12 +1490,12 @@ else print ''; print ''; print ''; - if($conf->global->PRODUCT_USE_UNITS) - { - print ''; - } + if ($conf->global->PRODUCT_USE_UNITS) + { + print ''; + } print ''; if (! empty($usemargins)) { diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index ac01abe6cd1..cdf2d789d09 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -1236,7 +1236,7 @@ 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 + * @param string $fk_unit Code 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, $fk_unit = null) @@ -1339,7 +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.= ", ".($fk_unit?"'".$this->db->escape($fk_unit)."'":"null"); $sql.= ")"; dol_syslog(get_class($this)."::addline", LOG_DEBUG); @@ -1418,7 +1418,7 @@ 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 + * @param string $fk_unit Code 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, $fk_unit = null) @@ -1512,7 +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 .= ", fk_unit=".($fk_unit?"'".$this->db->escape($fk_unit)."'":"null"); $sql .= " WHERE rowid = ".$rowid; dol_syslog(get_class($this)."::updateline", LOG_DEBUG); @@ -2474,7 +2474,7 @@ class ContratLigne extends CommonObjectLine if (empty($this->total_ht)) $this->total_ht = 0; if (empty($this->total_tva)) $this->total_tva = 0; if (empty($this->total_ttc)) $this->total_ttc = 0; - + // Check parameters // Put here code to add control on parameters values diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 775596735d5..e84aa42edee 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -3063,7 +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 : ' '; - if($conf->global->PRODUCT_USE_UNITS) $this->tpl['unit'] = $line->get_unit_label('long'); + if($conf->global->PRODUCT_USE_UNITS) $this->tpl['unit'] = $line->getLabelOfUnit('long'); $this->tpl['remise_percent'] = (($line->info_bits & 2) != 2) ? vatrate($line->remise_percent, true) : ' '; // Output template part (modules that overwrite templates must declare this into descriptor) diff --git a/htdocs/core/class/commonobjectline.class.php b/htdocs/core/class/commonobjectline.class.php index cfad5d09796..07019a0fa1d 100644 --- a/htdocs/core/class/commonobjectline.class.php +++ b/htdocs/core/class/commonobjectline.class.php @@ -38,7 +38,7 @@ abstract class CommonObjectLine extends CommonObject /** * Id of the line * @var int - * @deprecated Try to use id property as possible + * @deprecated Try to use id property as possible (even if field into database is still rowid) */ public $rowid; @@ -46,11 +46,11 @@ abstract class CommonObjectLine extends CommonObject public $db; /** - * Product/service unit - * @var int + * Product/service unit code ('km', 'm', 'p', ...) + * @var string */ public $fk_unit; - // TODO + /** * Returns the text label from units dictionnary @@ -58,7 +58,7 @@ abstract class CommonObjectLine extends CommonObject * @param string $type Label type (long or short) * @return string|int <0 if ko, label if ok */ - public function get_unit_label($type='long') + public function getLabelOfUnit($type='long') { global $langs; @@ -89,7 +89,7 @@ abstract class CommonObjectLine extends CommonObject else { $this->error=$this->db->error().' sql='.$sql; - dol_syslog(get_class($this)."::get_unit_label Error ".$this->error, LOG_ERR); + dol_syslog(get_class($this)."::getLabelOfUnit Error ".$this->error, LOG_ERR); return -1; } } diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 41c3fbf86c9..0d9db23a306 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -2823,46 +2823,36 @@ class Form } /** - * Prints units selector + * Creates HTML units selector (code => label) * - * @param string $selected Preselected ID - * @param string $htmlname Select name - * @return void + * @param string $selected Preselected code ('km', 'm', 'l', 'p', ...) + * @param string $htmlname Select name + * @param int $showempty Add a nempty line + * @return string HTML select */ - 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') + function selectUnits($selected = '', $htmlname = 'units', $showempty=0) { global $langs; $langs->load('products'); $return= ''; @@ -3009,7 +2999,7 @@ class Form $add = ''; } $output.= ''; - + $outarray[$cate_arbo[$key]['id']] = $cate_arbo[$key]['fulllabel']; } } diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index 369ef15cd88..6c94d5595dd 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -1463,7 +1463,7 @@ function pdf_getlineunit($object, $i, $outputlangs, $hidedetails = 0, $hookmanag $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 $langs->transnoentitiesnoconv($object->lines[$i]->getLabelOfUnit('short')); } } } diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php index 56106dae1d1..2bda2eb6b91 100644 --- a/htdocs/core/tpl/objectline_create.tpl.php +++ b/htdocs/core/tpl/objectline_create.tpl.php @@ -233,7 +233,7 @@ else { if($conf->global->PRODUCT_USE_UNITS) { print ''; } ?> diff --git a/htdocs/core/tpl/objectline_edit.tpl.php b/htdocs/core/tpl/objectline_edit.tpl.php index eb9c7521236..bc23438dfbc 100644 --- a/htdocs/core/tpl/objectline_edit.tpl.php +++ b/htdocs/core/tpl/objectline_edit.tpl.php @@ -147,7 +147,7 @@ $coldisplay=-1; // We remove first td if($conf->global->PRODUCT_USE_UNITS) { print ''; } ?> diff --git a/htdocs/core/tpl/objectline_view.tpl.php b/htdocs/core/tpl/objectline_view.tpl.php index c2b66778d33..593421fe527 100644 --- a/htdocs/core/tpl/objectline_view.tpl.php +++ b/htdocs/core/tpl/objectline_view.tpl.php @@ -149,7 +149,7 @@ if (empty($usemargins)) $usemargins=0; if($conf->global->PRODUCT_USE_UNITS) { print ''; print ''; } @@ -1379,13 +1376,13 @@ else } print $form->multiselectarray('categories', $cate_arbo, $arrayselected, '', 0, '', 0, 250); print ""; - + // Units if($conf->global->PRODUCT_USE_UNITS) { print ''; print ''; } @@ -1659,7 +1656,7 @@ else // Unit if($conf->global->PRODUCT_USE_UNITS) { - $unit = $object->get_unit_label(); + $unit = $object->getLabelOfUnit(); print '
'.$langs->trans("VAT").''.$langs->trans("PriceUHT").''.$langs->trans("Qty").''.$langs->trans("Unit").''.$langs->trans("Unit").''.$langs->trans("ReductionShort").''.$langs->trans("BuyingPrice").' '.($objp->subprice != '' ? price($objp->subprice) : '')."'.$objp->qty.''.$langs->trans($object->lines[$cursorline-1]->get_unit_label()).''.$langs->trans($object->lines[$cursorline-1]->getLabelOfUnit()).''; - $form->select_units($objp->fk_unit, "unit"); - print ''; + print $form->selectUnits($objp->fk_unit, "unit"); + print '%'; - print $form->select_units($line->fk_unit, "units"); + print $form->selectUnits($line->fk_unit, "units"); print ''; - $form->select_units($line->fk_unit, "units"); + print $form->selectUnits($line->fk_unit, "units"); print ''; - $label = $line->get_unit_label('short'); + $label = $line->getLabelOfUnit('short'); if ($label !== '') { print $langs->trans($label); } diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index ddddcf059a3..b1b9e74266e 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -1198,10 +1198,10 @@ 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 + * @param string $fk_unit Code 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, $fk_unit = null) + 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; @@ -1327,7 +1327,7 @@ class CommandeFournisseur extends CommonOrder $sql.= "'".price2num($total_localtax1)."',"; $sql.= "'".price2num($total_localtax2)."',"; $sql.= "'".price2num($total_ttc)."',"; - $sql.= (!$fk_unit ? 'NULL' : $fk_unit); + $sql.= ($fk_unit ? "'".$this->db->escape($fk_unit)."'":"null"); $sql.= ")"; dol_syslog(get_class($this)."::addline", LOG_DEBUG); @@ -1992,11 +1992,11 @@ class CommandeFournisseur extends CommonOrder * @param int $notrigger Disable triggers * @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 + * @param array $array_options Extrafields array + * @param string $fk_unit Code 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, $fk_unit = null) + 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, $fk_unit"); @@ -2066,7 +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.= ($fk_unit ? "'".$this->db->escape($fk_unit)."'":"null"); $sql.= " WHERE rowid = ".$rowid; dol_syslog(get_class($this)."::updateline", LOG_DEBUG); diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index dd4e5f598d2..c02728b1d29 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -1118,12 +1118,12 @@ 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 + * @param string $fk_unit Code 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, $fk_unit = null) + 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,$fk_unit", LOG_DEBUG); include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; @@ -1215,7 +1215,7 @@ 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 + * @param string $fk_unit Code 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, $fk_unit = null) @@ -1291,7 +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.= ", ".($fk_unit ? "'".$this->db->escape($fk_unit)."'":"null"); $sql.= " WHERE rowid = ".$id; dol_syslog(get_class($this)."::updateline", LOG_DEBUG); diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index 113758b7ee9..725cd35a6cb 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -376,11 +376,7 @@ if (empty($reshook)) $desc = $product_desc; $type = GETPOST('type'); - $fk_unit= GETPOST('units', 'int'); - - if ($fk_unit <= 0) { - $fk_unit = null; - } + $fk_unit= GETPOST('units', 'alpha'); $tva_tx = price2num($tva_tx); // When vat is text input field diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index edac67e3fbf..ab67027884f 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -732,11 +732,7 @@ if (empty($reshook)) $desc = $product_desc; $type = GETPOST('type'); - $fk_unit= GETPOST('units', 'int'); - - if ($fk_unit <= 0) { - $fk_unit = null; - } + $fk_unit= GETPOST('units', 'alpha'); $tva_tx = price2num($tva_tx); // When vat is text input field diff --git a/htdocs/install/mysql/tables/llx_c_units.key.sql b/htdocs/install/mysql/tables/llx_c_units.key.sql index f97ea9f709f..3ec5b9ba6fb 100644 --- a/htdocs/install/mysql/tables/llx_c_units.key.sql +++ b/htdocs/install/mysql/tables/llx_c_units.key.sql @@ -1,6 +1,6 @@ -- ======================================================================== -- Copyright (C) 2005 Laurent Destailleur --- Copyright (C) 2012 Cédric Salvador +-- Copyright (C) 2012 Cédric Salvador -- -- 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 diff --git a/htdocs/product/card.php b/htdocs/product/card.php index eaef488dac3..8d0d4484a2e 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -225,14 +225,14 @@ if (empty($reshook)) $object->barcode_type_label = $stdobject->barcode_type_label; $object->description = dol_htmlcleanlastbr(GETPOST('desc')); - $object->url = GETPOST('url'); + $object->url = GETPOST('url'); $object->note = dol_htmlcleanlastbr(GETPOST('note')); - $object->customcode = GETPOST('customcode'); - $object->country_id = GETPOST('country_id'); + $object->customcode = GETPOST('customcode'); + $object->country_id = GETPOST('country_id'); $object->duration_value = GETPOST('duration_value'); $object->duration_unit = GETPOST('duration_unit'); $object->seuil_stock_alerte = GETPOST('seuil_stock_alerte')?GETPOST('seuil_stock_alerte'):0; - $object->desiredstock = GETPOST('desiredstock')?GETPOST('desiredstock'):0; + $object->desiredstock = GETPOST('desiredstock')?GETPOST('desiredstock'):0; $object->canvas = GETPOST('canvas'); $object->weight = GETPOST('weight'); $object->weight_units = GETPOST('weight_units'); @@ -245,9 +245,6 @@ if (empty($reshook)) $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'); @@ -288,7 +285,7 @@ if (empty($reshook)) $cat->add_type($object, 'product'); } } - + header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); exit; } @@ -380,18 +377,18 @@ if (empty($reshook)) $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_product"; $sql .= " WHERE fk_product = ".$object->id; $db->query($sql); - + // Then we add the associated categories $categories = GETPOST('categories'); if(!empty($categories)) { $cat = new Categorie($db); - + foreach($categories as $id_category) { $cat->fetch($id_category); $cat->add_type($object, 'product'); } } - + $action = 'view'; } else @@ -1095,7 +1092,7 @@ else { print '
'.$langs->trans('Unit').''; - $form->select_units("units"); + print $form->selectUnits("units"); print '
'.$langs->trans('Unit').''; - $form->select_units($object->fk_unit); + print $form->selectUnits($object->fk_unit); print '
'.$langs->trans('Unit').''; if ($unit !== '') { @@ -1695,7 +1692,7 @@ else $cat = new Categorie($db); $categories = $cat->containing($object->id,0); $catarray = $form->select_all_categories(0, '', 'parent', 64, 0, 1); - + $toprint = array(); foreach($categories as $c) { $toprint[] = $catarray[$c->id]; diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index ce07c25a515..1f32e0a328f 100755 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -177,8 +177,8 @@ class Product extends CommonObject var $fk_price_expression; /** - * Unit - * @var int + * Unit code ('km', 'm', 'l', 'p', ...) + * @var string */ public $fk_unit; @@ -3820,7 +3820,7 @@ class Product extends CommonObject * @param string $type Label type (long or short) * @return string|int <0 if ko, label if ok */ - function get_unit_label($type='long') + function getLabelOfUnit($type='long') { global $langs; @@ -3851,7 +3851,7 @@ class Product extends CommonObject else { $this->error=$this->db->error().' sql='.$sql; - dol_syslog(get_class($this)."::get_unit_label Error ".$this->error, LOG_ERR); + dol_syslog(get_class($this)."::getLabelOfUnit Error ".$this->error, LOG_ERR); return -1; } } From f06255e9d26b974e89c0c906d08fc287fbbb25cf Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 21 Apr 2015 16:57:45 +0200 Subject: [PATCH 15/18] Complete the mailmap file. --- .mailmap | 42 +++++++++++++++++++++++++++++++++++++++ test/phpunit/UserTest.php | 6 +++--- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/.mailmap b/.mailmap index 5452dfd7ece..e8821f0f8eb 100644 --- a/.mailmap +++ b/.mailmap @@ -1,3 +1,6 @@ +# This is mapping list between real user name/email and entry into sources files +# If you don't want to have your real email appears here, just send a Pull Request to +# replace the second field between <> with Laurent Destailleur Laurent Destailleur Laurent Destailleur eldy Laurent Destailleur Laurent Destailleur @@ -47,3 +50,42 @@ Cédric Gross Cedric Cédric Gross Cedric GROSS Jean Heimburger jean Jean Heimburger tiaris +Benoit Mortier opensides +Eric Seigne erics +Jean-Louis Bergamo jlb +Remco Gerbrands r2gnl +Phf phf +Yannick Warnier ywarnier +Jerome Warnier jwarnier +Franky Van Liedekerke liedekef +Lalaina Rasamoelina lalaina rasamoelina +Marc Ocebo marc_ocebo +Unknown box7890 +Unknown beedauchon +Loic loic +Christophe Combelle +Unknown activdev +Unknown bouba +Unknown bcroq +Unknown dutoit +Unknown bureau2crea +Unknown unknown +Simon Tosser simontosser +Unknown tipaul +Raphaël Bertrand raphael_bertrand +Claudio Aschieri cla +Tommaso Basilici kaos +Tommaso Basilici Tommaso Basilici +Faust faust +Ferran Marcet fmarcet +Geoffrey Girard geoffrey.girard +Bernard Paquier BadPixxel +Patrick Delcroix delcroix Patrick +Damien Clochard damien clochard +Damien Clochard damien clochard +Grégory David Grégory DAVID +Grégory David Gregory DAVID +Baffir Abbes bafbes +Kevin Guerrier GUERRIER Kevin +Remy Younes remy +Estephe Loridan Estephe L. diff --git a/test/phpunit/UserTest.php b/test/phpunit/UserTest.php index 1e171737a6b..4e0c0ba58ca 100644 --- a/test/phpunit/UserTest.php +++ b/test/phpunit/UserTest.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2010-2015 Laurent Destailleur * * 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 @@ -187,7 +187,7 @@ class UserTest extends PHPUnit_Framework_TestCase $newlocalobject=new User($this->savdb); $newlocalobject->initAsSpecimen(); $this->changeProperties($newlocalobject); - $this->assertEquals($this->objCompare($localobject,$newlocalobject,true,array('id','ref','pass_indatabase','pass_indatabase_crypted','datec','datem','datelastlogin','datepreviouslogin')), array()); // Actual, Expected + $this->assertEquals($this->objCompare($localobject,$newlocalobject,true,array('id','socid','societe_id','ref','pass_indatabase','pass_indatabase_crypted','datec','datem','datelastlogin','datepreviouslogin')), array()); // Actual, Expected return $localobject; } @@ -301,7 +301,7 @@ class UserTest extends PHPUnit_Framework_TestCase $oVarsB=get_object_vars($oB); $aKeys=array_keys($oVarsA); foreach($aKeys as $sKey) { - if (in_array($sKey,$fieldstoignorearray)) + if (in_array($sKey,$fieldstoignorearray)) continue; if (! $ignoretype && $oVarsA[$sKey] !== $oVarsB[$sKey]) { $retAr[]=$sKey.' : '.(is_object($oVarsA[$sKey])?get_class($oVarsA[$sKey]):$oVarsA[$sKey]).' <> '.(is_object($oVarsB[$sKey])?get_class($oVarsB[$sKey]):$oVarsB[$sKey]); From bce952fa9bf60d5304b4e754b15503310fc095ee Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 21 Apr 2015 17:06:13 +0200 Subject: [PATCH 16/18] Fix bad link --- htdocs/core/boxes/box_actions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/boxes/box_actions.php b/htdocs/core/boxes/box_actions.php index 0f6e48a1520..fdd69a26a5b 100644 --- a/htdocs/core/boxes/box_actions.php +++ b/htdocs/core/boxes/box_actions.php @@ -118,7 +118,7 @@ class box_actions extends ModeleBoxes $this->info_box_contents[$line][] = array( 'td' => 'align="left"', - 'text' => $societestatic->getNomUrl(1), + 'text' => ($societestatic->id > 0 ? $societestatic->getNomUrl(1) : ''), 'asis' => 1, ); From ad31f0110ae805b1be60a9cd25fb9767c6c1217f Mon Sep 17 00:00:00 2001 From: Juanjo Menent Date: Tue, 21 Apr 2015 22:01:53 +0200 Subject: [PATCH 17/18] Improve PHPUnit Prices test for Spanish localtax1 and localtax2 --- test/phpunit/PricesTest.php | 105 ++++++++++++++++++++++++++++-------- 1 file changed, 83 insertions(+), 22 deletions(-) diff --git a/test/phpunit/PricesTest.php b/test/phpunit/PricesTest.php index 654f908beff..e7c566ad79d 100755 --- a/test/phpunit/PricesTest.php +++ b/test/phpunit/PricesTest.php @@ -1,5 +1,6 @@ +/* Copyright (C) 2010 Laurent Destailleur + * Copyright (C) 2015 Juanjo Menent * * 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 @@ -135,52 +136,112 @@ class PricesTest extends PHPUnit_Framework_TestCase global $mysoc; $mysoc=new Societe($db); + /* + * Country France + */ + // qty=1, unit_price=1.24, discount_line=0, vat_rate=10, price_base_type='HT' (method we provide value) $mysoc->country_code='FR'; $mysoc->country_id=1; $result1=calcul_price_total(1, 1.24, 0, 10, 0, 0, 0, 'HT', 0, 0); print __METHOD__." result1=".join(', ',$result1)."\n"; // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) - $this->assertEquals(array(1.24, 0.12, 1.36, 1.24, 0.124, 1.364, 1.24, 0.12, 1.36, 0, 0, 0, 0, 0, 0, 0),$result1,'Test1'); + $this->assertEquals(array(1.24, 0.12, 1.36, 1.24, 0.124, 1.364, 1.24, 0.12, 1.36, 0, 0, 0, 0, 0, 0, 0),$result1,'Test1 FR'); - // 10 * 10 HT - 0% discount with 10% vat and 1.4% localtax1 type 1, 0% localtax2 type 0 (method we provide value) + + /* + * Country Spain + */ + + // 10 * 10 HT - 0% discount with 10% vat, seller not using localtax1, not localtax2 (method we provide value) + $mysoc->country_code='ES'; + $mysoc->country_id=4; + $mysoc->localtax1_assuj=0; + $mysoc->localtax2_assuj=0; + $result2=calcul_price_total(10, 10, 0, 10, 0, 0, 0, 'HT', 0, 0); // 10 * 10 HT - 0% discount with 10% vat and 1.4% localtax1, 0% localtax2 + print __METHOD__." result2=".join(', ',$result2)."\n"; + // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) + $this->assertEquals(array(100, 10, 110, 10, 1, 11, 100, 10, 110, 0, 0, 0, 0, 0, 0, 0),$result2,'Test1 ES'); + + // 10 * 10 HT - 0% discount with 10% vat, seller not using localtax1, not localtax2 (other method autodetect) + $mysoc->country_code='ES'; + $mysoc->country_id=4; + $mysoc->localtax1_assuj=0; + $mysoc->localtax2_assuj=0; + $result2=calcul_price_total(10, 10, 0, 10, -1, -1, 0, 'HT', 0, 0); // 10 * 10 HT - 0% discount with 10% vat and 1.4% localtax1, 0% localtax2 + print __METHOD__." result2=".join(', ',$result2)."\n"; + // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) + $this->assertEquals(array(100, 10, 110, 10, 1, 11, 100, 10, 110, 0, 0, 0, 0, 0, 0, 0),$result2,'Test2 ES'); + + // -------------------------------------------------------- + + // 10 * 10 HT - 0% discount with 10% vat and 1.4% localtax1 type 3, 0% localtax2 type 5 (method we provide value) $mysoc->country_code='ES'; $mysoc->country_id=4; $mysoc->localtax1_assuj=1; $mysoc->localtax2_assuj=0; $result2=calcul_price_total(10, 10, 0, 10, 1.4, 0, 0, 'HT', 0, 0); print __METHOD__." result2=".join(', ',$result2)."\n"; - $this->assertEquals(array(100, 10, 111.4, 10, 1, 11.14, 100, 10, 111.4, 1.4, 0, 0.14, 0, 0, 1.4, 0),$result2,'Test2'); - - // 10 * 10 HT - 0% discount with 10% vat and 1.4% localtax1 type 1, 0% localtax2 type 0 (other method autodetect) + // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) + $this->assertEquals(array(100, 10, 111.4, 10, 1, 11.14, 100, 10, 111.4, 1.4, 0, 0.14, 0, 0, 1.4, 0),$result2,'Test3 ES'); + + // 10 * 10 HT - 0% discount with 10% vat and 1.4% localtax1 type 3, 0% localtax2 type 5 (other method autodetect) $mysoc->country_code='ES'; $mysoc->country_id=4; $mysoc->localtax1_assuj=1; $mysoc->localtax2_assuj=0; $result2=calcul_price_total(10, 10, 0, 10, -1, -1, 0, 'HT', 0, 0); print __METHOD__." result2=".join(', ',$result2)."\n"; - $this->assertEquals(array(100, 10, 111.4, 10, 1, 11.14, 100, 10, 111.4, 1.4, 0, 0.14, 0, 0, 1.4, 0),$result2,'Test3 ES'); - - // 10 * 10 HT - 0% discount with 10% vat, seller not using localtax1, nor localtax2 (method we provide value) + // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) + $this->assertEquals(array(100, 10, 111.4, 10, 1, 11.14, 100, 10, 111.4, 1.4, 0, 0.14, 0, 0, 1.4, 0),$result2,'Test4 ES'); + + // -------------------------------------------------------- + + // 10 * 10 HT - 0% discount with 10% vat and 0% localtax1 type 3, 19% localtax2 type 5 (method we provide value) $mysoc->country_code='ES'; $mysoc->country_id=4; $mysoc->localtax1_assuj=0; - $mysoc->localtax2_assuj=0; - $result3=calcul_price_total(10, 10, 0, 10, 0, 0, 0, 'HT', 0, 0); // 10 * 10 HT - 0% discount with 10% vat and 1.4% localtax1, 0% localtax2 - print __METHOD__." result3=".join(', ',$result3)."\n"; - // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) - $this->assertEquals(array(100, 10, 110, 10, 1, 11, 100, 10, 110, 0, 0, 0, 0, 0, 0, 0),$result3,'Test4'); + $mysoc->localtax2_assuj=1; + $result2=calcul_price_total(10, 10, 0, 10, 0, -19, 0, 'HT', 0, 0); + // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) + $this->assertEquals(array(100, 10, 91, 10, 1, 9.1, 100, 10, 91, 0, -19, 0, -1.90, 0, 0, -19),$result2,'Test5 ES'); - // 10 * 10 HT - 0% discount with 10% vat, seller not using localtax1, nor localtax2 (other method autodetect) + // 10 * 10 HT - 0% discount with 10% vat and 1.4% localtax1 type 3, 0% localtax2 type 5 (other method autodetect) $mysoc->country_code='ES'; $mysoc->country_id=4; $mysoc->localtax1_assuj=0; - $mysoc->localtax2_assuj=0; - $result3=calcul_price_total(10, 10, 0, 10, -1, -1, 0, 'HT', 0, 0); // 10 * 10 HT - 0% discount with 10% vat and 1.4% localtax1, 0% localtax2 - print __METHOD__." result3=".join(', ',$result3)."\n"; - // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) - $this->assertEquals(array(100, 10, 110, 10, 1, 11, 100, 10, 110, 0, 0, 0, 0, 0, 0, 0),$result3,'Test5'); + $mysoc->localtax2_assuj=1; + $result2=calcul_price_total(10, 10, 0, 10, -1, -1, 0, 'HT', 0, 0); + print __METHOD__." result2=".join(', ',$result2)."\n"; + // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) + $this->assertEquals(array(100, 10, 91, 10, 1, 9.1, 100, 10, 91, 0, -19, 0, -1.90, 0, 0, -19),$result2,'Test6 ES'); + + // -------------------------------------------------------- + + // Credit Note: 10 * -10 HT - 0% discount with 10% vat and 0% localtax1 type 3, 19% localtax2 type 5 (method we provide value) + $mysoc->country_code='ES'; + $mysoc->country_id=4; + $mysoc->localtax1_assuj=0; + $mysoc->localtax2_assuj=1; + $result2=calcul_price_total(10, -10, 0, 10, 0, 19, 0, 'HT', 0, 0); + print __METHOD__." result2=".join(', ',$result2)."\n"; + // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) + $this->assertEquals(array(-100, -10, -91, -10, -1, -9.1, -100, -10,- 91, 0, 19, 0, 1.90, 0, 0, 19),$result2,'Test7 ES'); + // Credit Note: 10 * -10 HT - 0% discount with 10% vat and 1.4% localtax1 type 3, 0% localtax2 type 5 (other method autodetect) + $mysoc->country_code='ES'; + $mysoc->country_id=4; + $mysoc->localtax1_assuj=0; + $mysoc->localtax2_assuj=1; + $result2=calcul_price_total(10, -10, 0, 10, -1, -1, 0, 'HT', 0, 0); + print __METHOD__." result2=".join(', ',$result2)."\n"; + $this->assertEquals(array(-100, -10, -91, -10, -1, -9.1, -100, -10,- 91, 0, 19, 0, 1.90, 0, 0, 19),$result2,'Test8 ES'); + + + /* + * Country Côte d'Ivoire + */ + // 10 * 10 HT - 0% discount with 18% vat, seller using localtax1 type 2, not localtax2 (method we provide value) $mysoc->country_code='CI'; $mysoc->country_id=21; @@ -191,7 +252,7 @@ class PricesTest extends PHPUnit_Framework_TestCase $result3=calcul_price_total(10, 10, 0, 18, 7.5, 0, 0, 'HT', 0, 0); // 10 * 10 HT - 0% discount with 18% vat and 7.5% localtax1, 0% localtax2 print __METHOD__." result3=".join(', ',$result3)."\n"; // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) - $this->assertEquals(array(100, 18, 126.85, 10, 1.8, 12.685, 100, 18, 126.85, 8.85, 0, 0.885, 0, 0, 8.85, 0),$result3,'Test6 CI'); + $this->assertEquals(array(100, 18, 126.85, 10, 1.8, 12.685, 100, 18, 126.85, 8.85, 0, 0.885, 0, 0, 8.85, 0),$result3,'Test9 CI'); // 10 * 10 HT - 0% discount with 18% vat, seller using localtax1 type 2, not localtax2 (other method autodetect) $mysoc->country_code='CI'; @@ -201,7 +262,7 @@ class PricesTest extends PHPUnit_Framework_TestCase $result3=calcul_price_total(10, 10, 0, 18, -1, -1, 0, 'HT', 0, 0); // 10 * 10 HT - 0% discount with 18% vat and 7.5% localtax1, 0% localtax2 print __METHOD__." result3=".join(', ',$result3)."\n"; // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) - $this->assertEquals(array(100, 18, 126.85, 10, 1.8, 12.685, 100, 18, 126.85, 8.85, 0, 0.885, 0, 0, 8.85, 0),$result3,'Test7 CI'); + $this->assertEquals(array(100, 18, 126.85, 10, 1.8, 12.685, 100, 18, 126.85, 8.85, 0, 0.885, 0, 0, 8.85, 0),$result3,'Test10 CI'); return true; } From 5b758e0e166267515372a804b3da96701d9afa67 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 22 Apr 2015 00:17:03 +0200 Subject: [PATCH 18/18] Fix migration process --- .../install/mysql/migration/3.7.0-3.8.0.sql | 26 ++++++++++++++----- htdocs/install/mysql/tables/llx_user.key.sql | 2 +- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/htdocs/install/mysql/migration/3.7.0-3.8.0.sql b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql index a341b31d013..53cf461fe37 100755 --- a/htdocs/install/mysql/migration/3.7.0-3.8.0.sql +++ b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql @@ -533,11 +533,6 @@ CREATE TABLE IF NOT EXISTS llx_propal_merge_pdf_product ( ) ENGINE=InnoDB; --- Feature request: A page to merge two thirdparties into one #2613 -ALTER TABLE llx_categorie_societe CHANGE COLUMN fk_societe fk_soc INTEGER NOT NULL; -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, @@ -583,4 +578,23 @@ 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); \ No newline at end of file +ALTER TABLE llx_facture_fourn_det ADD CONSTRAINT fk_facture_fourn_det_fk_unit FOREIGN KEY (fk_unit) REFERENCES llx_c_units (rowid); + + +ALTER TABLE llx_user DROP INDEX uk_user_fk_societe; +ALTER TABLE llx_user ADD INDEX idx_user_fk_societe (fk_soc); + + +-- Feature request: A page to merge two thirdparties into one #2613 +ALTER TABLE llx_categorie_societe DROP FOREIGN KEY fk_categorie_societe_fk_soc; +ALTER TABLE llx_categorie_societe CHANGE COLUMN fk_societe fk_soc INTEGER NOT NULL; +ALTER TABLE llx_categorie_societe ADD CONSTRAINT fk_categorie_societe_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid); + +ALTER TABLE llx_categorie_fournisseur DROP FOREIGN KEY fk_categorie_fournisseur_fk_soc; +ALTER TABLE llx_categorie_fournisseur CHANGE COLUMN fk_societe fk_soc INTEGER NOT NULL; +ALTER TABLE llx_categorie_fournisseur ADD CONSTRAINT fk_categorie_fournisseur_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid); + +ALTER TABLE llx_user CHANGE COLUMN fk_societe fk_soc INTEGER NOT NULL; +ALTER TABLE llx_societe CHANGE COLUMN fk_societe fk_soc INTEGER NOT NULL; + + diff --git a/htdocs/install/mysql/tables/llx_user.key.sql b/htdocs/install/mysql/tables/llx_user.key.sql index 8232e7cacb7..127d45046d6 100644 --- a/htdocs/install/mysql/tables/llx_user.key.sql +++ b/htdocs/install/mysql/tables/llx_user.key.sql @@ -21,7 +21,7 @@ ALTER TABLE llx_user ADD UNIQUE INDEX uk_user_login (login, entity); -ALTER TABLE llx_user ADD INDEX uk_user_fk_societe (fk_soc); +ALTER TABLE llx_user ADD INDEX idx_user_fk_societe (fk_soc); ALTER TABLE llx_user ADD UNIQUE INDEX uk_user_fk_socpeople (fk_socpeople); ALTER TABLE llx_user ADD UNIQUE INDEX uk_user_fk_member (fk_member);