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; } }