diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 5020077cd26..a9e2c6b3aca 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -266,7 +266,7 @@ class Propal extends CommonObject } /** - * \brief Add new line in database + * Add a proposal line into database (linked to product/service or not) * \param propalid Id de la propale * \param desc Description de la ligne * \param pu_ht Prix unitaire @@ -279,8 +279,10 @@ class Propal extends CommonObject * \param price_base_type HT or TTC * \param pu_ttc Prix unitaire TTC * \param info_bits Bits de type de lignes + * \param type Type of line (product, service) + * \param rang Position of line * \return int >0 if OK, <0 if KO - * \see add_product + * @see add_product * \remarks Les parametres sont deja cense etre juste et avec valeurs finales a l'appel * de cette methode. Aussi, pour le taux tva, il doit deja avoir ete defini * par l'appelant par la methode get_default_tva(societe_vendeuse,societe_acheteuse,'',produit) @@ -293,28 +295,35 @@ class Propal extends CommonObject dol_syslog("Propal::Addline propalid=$propalid, desc=$desc, pu_ht=$pu_ht, qty=$qty, txtva=$txtva, fk_product=$fk_product, remise_except=$remise_percent, price_base_type=$price_base_type, pu_ttc=$pu_ttc, info_bits=$info_bits, type=$type"); include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php'); + // Clean parameters + if (empty($remise_percent)) $remise_percent=0; + if (empty($qty)) $qty=0; + if (empty($info_bits)) $info_bits=0; + if (empty($rang)) $rang=0; + + $remise_percent=price2num($remise_percent); + $qty=price2num($qty); + $pu_ht=price2num($pu_ht); + $pu_ttc=price2num($pu_ttc); + $txtva=price2num($txtva); + $txlocaltax1=price2num($txlocaltax1); + $txlocaltax2=price2num($txlocaltax2); + if ($price_base_type=='HT') + { + $pu=$pu_ht; + } + else + { + $pu=$pu_ttc; + } + + // Check parameters + if ($type < 0) return -1; + if ($this->statut == 0) { $this->db->begin(); - // Clean parameters - $remise_percent=price2num($remise_percent); - $qty=price2num($qty); - if (empty($qty)) $qty=0; // If qty='' - $pu_ht=price2num($pu_ht); - $pu_ttc=price2num($pu_ttc); - $txtva=price2num($txtva); - $txlocaltax1=price2num($txlocaltax1); - $txlocaltax2=price2num($txlocaltax2); - if ($price_base_type=='HT') - { - $pu=$pu_ht; - } - else - { - $pu=$pu_ttc; - } - // Calcul du total TTC et de la TVA pour la ligne a partir de // qty, pu, remise_percent et txtva // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker @@ -325,7 +334,7 @@ class Propal extends CommonObject $total_ttc = $tabprice[2]; $total_localtax1 = $tabprice[9]; $total_localtax2 = $tabprice[10]; - + // Rang to use $rangtouse = $rang; if ($rangtouse == -1) @@ -423,29 +432,18 @@ class Propal extends CommonObject dol_syslog("Propal::UpdateLine $rowid, $pu, $qty, $remise_percent, $txtva, $desc, $price_base_type, $info_bits"); include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php'); + // Clean parameters + $remise_percent=price2num($remise_percent); + $qty=price2num($qty); + $pu = price2num($pu); + $txtva = price2num($txtva); + $txlocaltax1=price2num($txlocaltax1); + $txlocaltax2=price2num($txlocaltax2); + if ($this->statut == 0) { $this->db->begin(); - // Nettoyage param�tres - $remise_percent=price2num($remise_percent); - $qty=price2num($qty); - /* - if ($conf->global->PROPALE_USE_OPTION_LINE && !$qty) - { - $qty=0; - $remise_percent=0; - } - else if (! $qty) - { - $qty=1; - } - */ - $pu = price2num($pu); - $txtva = price2num($txtva); - $txlocaltax1=price2num($txlocaltax1); - $txlocaltax2=price2num($txlocaltax2); - // Calcul du total TTC et de la TVA pour la ligne a partir de // qty, pu, remise_percent et txtva // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker @@ -502,7 +500,7 @@ class Propal extends CommonObject // Fin appel triggers } - $this->db->commit(); + $this->db->commit(); return $result; } else @@ -1414,7 +1412,7 @@ class Propal extends CommonObject * \param limit For pagination * \param offset For pagination * \param sortfield Sort criteria - * \param sortorder Sort order + * \param sortorder Sort order * \return int -1 if KO, array with result if OK */ function liste_array($shortlist=0, $draft=0, $notcurrentuser=0, $socid=0, $limit=0, $offset=0, $sortfield='p.datep', $sortorder='DESC') @@ -1463,7 +1461,7 @@ class Propal extends CommonObject } else { - dol_print_error($this->db); + dol_print_error($this->db); return -1; } } @@ -2260,19 +2258,23 @@ class PropaleLigne */ function insert() { - global $conf; + global $conf; dol_syslog("PropaleLigne::insert rang=".$this->rang); - $this->db->begin(); // Clean parameters - if (! $this->remise) $this->remise=0; - if (! $this->remise_percent) $this->remise_percent=0; - if (! $this->info_bits) $this->info_bits=0; if (empty($this->tva_tx)) $this->tva_tx=0; + if (empty($this->localtax1_tx)) $this->localtax1_tx=0; + if (empty($this->localtax2_tx)) $this->localtax2_tx=0; + if (empty($this->rang)) $this->rang=0; + if (empty($this->remise)) $this->remise=0; + if (empty($this->remise_percent)) $this->remise_percent=0; + if (empty($this->info_bits)) $this->info_bits=0; // Check parameters - if ($this->type < 0) return -1; + if ($this->product_type < 0) return -1; + + $this->db->begin(); // Insert line into database $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'propaldet'; diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index e619b6117d3..4bae867cad3 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -804,27 +804,28 @@ class Commande extends CommonObject /** - * \brief Add a line - * \param commandeid Id de la commande - * \param desc Description de la ligne - * \param pu_ht Prix unitaire HT - * \param qty Quantite - * \param txtva Taux de tva force, sinon -1 - * \param txlocaltax1 Local tax 1 rate - * \param txlocaltax2 Local tax 2 rate - * \param fk_product Id du produit/service predefini - * \param remise_percent Pourcentage de remise de la ligne - * \param info_bits Bits de type de lignes - * \param fk_remise_except Id remise - * \param price_base_type HT or TTC - * \param pu_ttc Prix unitaire TTC - * \param date_start Start date of the line - Added by Matelli (See http://matelli.fr/showcases/patchs-dolibarr/add-dates-in-order-lines.html) - * \param date_end End date of the line - Added by Matelli (See http://matelli.fr/showcases/patchs-dolibarr/add-dates-in-order-lines.html) - * \param type Type of line (0=product, 1=service) - * \return int >0 si ok, <0 si ko - * \see add_product - * \remarks Les parametres sont deja cense etre juste et avec valeurs finales a l'appel - * de cette methode. Aussi, pour le taux tva, il doit deja avoir ete defini + * Add an order line into database (linked to product/service or not) + * @param commandeid Id of line + * @param desc Description of line + * @param pu_ht Unit price (without tax) + * @param qty Quantite + * @param txtva Taux de tva force, sinon -1 + * @param txlocaltax1 Local tax 1 rate + * @param txlocaltax2 Local tax 2 rate + * @param fk_product Id du produit/service predefini + * @param remise_percent Pourcentage de remise de la ligne + * @param info_bits Bits de type de lignes + * @param fk_remise_except Id remise + * @param price_base_type HT or TTC + * @param pu_ttc Prix unitaire TTC + * @param date_start Start date of the line - Added by Matelli (See http://matelli.fr/showcases/patchs-dolibarr/add-dates-in-order-lines.html) + * @param date_end End date of the line - Added by Matelli (See http://matelli.fr/showcases/patchs-dolibarr/add-dates-in-order-lines.html) + * @param type Type of line (0=product, 1=service) + * @param rang Position of line + * @return int >0 si ok, <0 si ko + * @see add_product + * @remarks Les parametres sont deja cense etre juste et avec valeurs finales a l'appel + * de cette methode. Aussi, pour le taux tva, il doit deja avoir ete defini * 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) */ @@ -838,6 +839,7 @@ class Commande extends CommonObject if (empty($remise_percent)) $remise_percent=0; if (empty($qty)) $qty=0; if (empty($info_bits)) $info_bits=0; + if (empty($rang)) $rang=0; $remise_percent=price2num($remise_percent); $qty=price2num($qty); @@ -873,7 +875,7 @@ class Commande extends CommonObject $total_ttc = $tabprice[2]; $total_localtax1 = $tabprice[9]; $total_localtax2 = $tabprice[10]; - + // Rang to use $rangtouse = $rang; if ($rangtouse == -1) @@ -2624,8 +2626,15 @@ class OrderLine if (empty($this->tva_tx)) $this->tva_tx=0; if (empty($this->localtax1_tx)) $this->localtax1_tx=0; if (empty($this->localtax2_tx)) $this->localtax2_tx=0; + if (empty($this->rang)) $this->rang=0; + if (empty($this->remise)) $this->remise=0; + if (empty($this->remise_percent)) $this->remise_percent=0; + if (empty($this->info_bits)) $this->info_bits=0; - $this->db->begin(); + // Check parameters + if ($this->product_type < 0) return -1; + + $this->db->begin(); // Insertion dans base de la ligne $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'commandedet'; diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 2d5523efb4d..77f65bb6b72 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1565,7 +1565,7 @@ class Facture extends CommonObject /** - * \brief Add an invoice line into database (linked to product/service or not) + * Add an invoice line into database (linked to product/service or not) * \param facid Id de la facture * \param desc Description de la ligne * \param pu_ht Prix unitaire HT @@ -1583,6 +1583,7 @@ class Facture extends CommonObject * \param price_base_type HT or TTC * \param pu_ttc Prix unitaire TTC * \param type Type of line (0=product, 1=service) + * \param rang Position of line * \return int >0 if OK, <0 if KO * \remarks Les parametres sont deja cense etre juste et avec valeurs finales a l'appel * de cette methode. Aussi, pour le taux tva, il doit deja avoir ete defini @@ -1594,6 +1595,30 @@ class Facture extends CommonObject dol_syslog("Facture::Addline facid=$facid,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); include_once(DOL_DOCUMENT_ROOT.'/lib/price.lib.php'); + // Clean parameters + if (empty($remise_percent)) $remise_percent=0; + if (empty($qty)) $qty=0; + if (empty($info_bits)) $info_bits=0; + if (empty($rang)) $rang=0; + if (empty($ventil)) $ventil=0; + + $remise_percent=price2num($remise_percent); + $qty=price2num($qty); + $pu_ht=price2num($pu_ht); + $pu_ttc=price2num($pu_ttc); + $txtva=price2num($txtva); + $txlocaltax1=price2num($txlocaltax1); + $txlocaltax2=price2num($txlocaltax2); + + if ($price_base_type=='HT') + { + $pu=$pu_ht; + } + else + { + $pu=$pu_ttc; + } + // Check parameters if ($type < 0) return -1; @@ -1601,28 +1626,6 @@ class Facture extends CommonObject { $this->db->begin(); - // Clean parameters - if (empty($remise_percent)) $remise_percent=0; - if (empty($qty)) $qty=0; - if (empty($ventil)) $ventil=0; - if (empty($info_bits)) $info_bits=0; - $remise_percent=price2num($remise_percent); - $qty=price2num($qty); - $pu_ht=price2num($pu_ht); - $pu_ttc=price2num($pu_ttc); - $txtva=price2num($txtva); - $txlocaltax1=price2num($txlocaltax1); - $txlocaltax2=price2num($txlocaltax2); - - if ($price_base_type=='HT') - { - $pu=$pu_ht; - } - else - { - $pu=$pu_ttc; - } - // Calcul du total TTC et de la TVA pour la ligne a partir de // qty, pu, remise_percent et txtva // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker @@ -1633,7 +1636,7 @@ class Facture extends CommonObject $total_ttc = $tabprice[2]; $total_localtax1 = $tabprice[9]; $total_localtax2 = $tabprice[10]; - + // Rang to use $rangtouse = $rang; if ($rangtouse == -1) @@ -2640,8 +2643,8 @@ class Facture extends CommonObject $sql.= ' WHERE fk_facture = '.$this->id; $sql.= ' AND traite = 0'; - $resql=$this->db->query($sql); - if ($resql) + $resql=$this->db->query($sql); + if ($resql) { $row = $this->db->fetch_row($resql); if ($row[0] == 0) @@ -3024,16 +3027,20 @@ class FactureLigne dol_syslog("FactureLigne::Insert rang=".$this->rang, LOG_DEBUG); - // Clean parameters - $this->desc=trim($this->desc); - if (empty($this->subprice)) $this->subprice=0; - if (empty($this->price)) $this->price=0; - if (empty($this->tva_tx)) $this->tva_tx=0; - if (empty($this->localtax1_tx)) $this->localtax1_tx=0; - if (empty($this->localtax2_tx)) $this->localtax2_tx=0; + // Clean parameters + $this->desc=trim($this->desc); + if (empty($this->tva_tx)) $this->tva_tx=0; + if (empty($this->localtax1_tx)) $this->localtax1_tx=0; + if (empty($this->localtax2_tx)) $this->localtax2_tx=0; + if (empty($this->rang)) $this->rang=0; + if (empty($this->remise)) $this->remise=0; + if (empty($this->remise_percent)) $this->remise_percent=0; + if (empty($this->info_bits)) $this->info_bits=0; + if (empty($this->subprice)) $this->subprice=0; + if (empty($this->price)) $this->price=0; - // Check parameters - if ($this->product_type < 0) return -1; + // Check parameters + if ($this->product_type < 0) return -1; $this->db->begin(); diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 129b424eaa3..5f89f65f9a6 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -35,7 +35,7 @@ class CommonObject { // Instantiate classes of thirdparty module var $objModules=array(); - + /** * \brief Check if ref is used. * \return int <0 if KO, 0 if not found, >0 if found @@ -802,7 +802,8 @@ class CommonObject } /** - * \brief Get max value for rang + * Get max value used for position of line (rang) + * @result int Max value of rang in table of lines */ function line_max() { @@ -1143,7 +1144,7 @@ class CommonObject print $sql; } } - + /** * Instantiate hooks of thirdparty module * @param $type Type of hook @@ -1151,7 +1152,7 @@ class CommonObject function callHooks($type='objectcard') { global $conf; - + foreach($conf->hooks_modules as $module => $hooks) { if ($conf->$module->enabled && in_array($type,$hooks)) @@ -1165,13 +1166,13 @@ class CommonObject { require_once(DOL_DOCUMENT_ROOT.'/'.$module.'/lib/'.$module.'.lib.php'); } - + $classname = ucfirst($module); $this->objModules[] = new $classname($this->db); } } } - + /** * Show add predefined products/services form */ @@ -1182,7 +1183,7 @@ class CommonObject include(DOL_DOCUMENT_ROOT.'/core/tpl/addpredefinedproductform.tpl.php'); } - + /** * Show add free products/services form */ @@ -1220,15 +1221,15 @@ class CommonObject return $num; } } - + /** * Return HTML table with title list - * TODO mettre le html dans un template + * TODO mettre le html dans un template */ function print_title_list() { global $conf,$langs; - + print '