diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php index 7d89551c8ad..2dfb60a255a 100644 --- a/htdocs/lib/functions.lib.php +++ b/htdocs/lib/functions.lib.php @@ -1903,13 +1903,13 @@ function print_fleche_navigation($page,$file,$options='',$nextpage,$betweenarrow * \param info_bits Miscellanous information on vat * \return string Chaine avec montant formaté (19,6 ou 19,6% ou 8.5% *) */ -function vatrate($rate,$foundpercent=false,$info_bits=0) +function vatrate($rate,$addpercent=false,$info_bits=0) { // Test for compatibility if (eregi('%',$rate)) { $rate=eregi_replace('%','',$rate); - $foundpercent=true; + $addpercent=true; } if (eregi('\*',$rate) || eregi(MAIN_LABEL_MENTION_NPR,$rate)) { @@ -1917,7 +1917,7 @@ function vatrate($rate,$foundpercent=false,$info_bits=0) $info_bits |= 1; } - $ret=price($rate,0,'',0,0).($foundpercent?'%':''); + $ret=price($rate,0,'',0,0).($addpercent?'%':''); if ($info_bits & 1) $ret.=' '.MAIN_LABEL_MENTION_NPR; return $ret; } diff --git a/htdocs/product.class.php b/htdocs/product.class.php index c9ed533c8de..a51642c7a4b 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -43,7 +43,7 @@ class Product extends CommonObject //! Identifiant unique var $id ; - //! R�f�rence + //! Ref var $ref; var $libelle; var $description; @@ -761,40 +761,45 @@ class Product extends CommonObject /** - \brief Modifie le prix d'un produit/service - \param id Id du produit/service � modifier - \param newprice Nouveau prix - \param newpricebase HT ou TTC - \param user Objet utilisateur qui modifie le prix + * \brief Modifie le prix d'un produit/service + * \param id Id du produit/service a modifier + * \param newprice Nouveau prix + * \param newpricebase HT ou TTC + * \param user Objet utilisateur qui modifie le prix + * \param newvat New VAT Rate + * \return int <0 if KO, >0 if OK */ - function update_price($id, $newprice, $newpricebase, $user) + function update_price($id, $newprice, $newpricebase, $user, $newvat='') { //multiprix global $conf,$langs; dolibarr_syslog("Product::update_price id=".$id." newprice=".$newprice." newpricebase=".$newpricebase); + if ($newvat == '') $newvat=$this->tva_tx; + if ($newprice) { if ($newpricebase == 'TTC') { $price_ttc = price2num($newprice,'MU'); - $price = price2num($newprice) / (1 + ($this->tva_tx / 100)); + $price = price2num($newprice) / (1 + ($newvat / 100)); $price = price2num($price,'MU'); } else { $price = price2num($newprice,'MU'); - $price_ttc = price2num($newprice) * (1 + ($this->tva_tx / 100)); + $price_ttc = price2num($newprice) * (1 + ($newvat / 100)); $price_ttc = price2num($price_ttc,'MU'); } // Ne pas mettre de quote sur le num�riques decimaux. // Ceci provoque des sotckage avec arrondis en base au lieu des valeurs exactes. - $sql = "UPDATE ".MAIN_DB_PREFIX."product "; - $sql .= " SET price=".$price.""; - $sql .= " , price_base_type='".$newpricebase."'"; - $sql .= " , price_ttc=".$price_ttc.""; - $sql .= " WHERE rowid = " . $id; + $sql = "UPDATE ".MAIN_DB_PREFIX."product SET"; + $sql.= " price_base_type='".$newpricebase."',"; + $sql.= " price=".$price.","; + $sql.= " price_ttc=".$price_ttc.","; + $sql.= " tva_tx='".price2num($newvat)."'"; + $sql.= " WHERE rowid = " . $id; dolibarr_syslog("Product::update_price sql=".$sql); $resql=$this->db->query($sql); @@ -803,7 +808,8 @@ class Product extends CommonObject $this->price = $price; $this->price_ttc = $price_ttc; $this->price_base_type = $newpricebase; - + $this->tva_tx = $newvat; + $this->_log_price($user); return 1; } diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php index ad821a37675..120cee81bb7 100644 --- a/htdocs/product/fiche.php +++ b/htdocs/product/fiche.php @@ -136,9 +136,6 @@ if ($_POST["action"] == 'update' && { $product->ref = $_POST["ref"]; $product->libelle = $_POST["libelle"]; - if ( isset( $_POST["price"] ) ) - $product->price = $_POST["price"]; - $product->tva_tx = $_POST["tva_tx"]; $product->description = $_POST["desc"]; $product->note = $_POST["note"]; $product->status = $_POST["statut"]; @@ -572,34 +569,6 @@ if ($_GET["action"] == 'create' && $user->rights->produit->creer) // Label print ''.$langs->trans("Label").''; - if($conf->global->PRODUIT_MULTIPRICES == 1) - { - print ''.$langs->trans("SellingPrice").' 1'; - print ''; - print $html->select_PriceBaseType($product->price_base_type, "price_base_type"); - print ''; - for($i=2;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++) - { - print ''.$langs->trans("SellingPrice").' '.$i.''; - print ''; - print $html->select_PriceBaseType($product->multiprices_base_type["$i"], "multiprices_base_type_".$i); - print ''; - } - } - // PRIX - else - { - print ''.$langs->trans("SellingPrice").''; - print ''; - print $html->select_PriceBaseType($product->price_base_type, "price_base_type"); - print ''; - } - - // VAT - print ''.$langs->trans("VATRate").''; - print $html->select_tva("tva_tx",$conf->defaulttx,$mysoc,''); - print ''; - // Status print ''.$langs->trans("Status").''; $statutarray=array('1' => $langs->trans("OnSell"), '0' => $langs->trans("NotOnSell")); @@ -672,9 +641,47 @@ if ($_GET["action"] == 'create' && $user->rights->produit->creer) print ''; } print ""; - - print ''; print ''; + + print '
'; + + print ''; + if($conf->global->PRODUIT_MULTIPRICES == 1) + { + print ''; + print ''; + for($i=2;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++) + { + print ''; + print ''; + } + } + // PRIX + else + { + print ''; + print ''; + } + + // VAT + print ''; + + print '
'.$langs->trans("SellingPrice").' 1'; + print $html->select_PriceBaseType($product->price_base_type, "price_base_type"); + print '
'.$langs->trans("SellingPrice").' '.$i.''; + print $html->select_PriceBaseType($product->multiprices_base_type["$i"], "multiprices_base_type_".$i); + print '
'.$langs->trans("SellingPrice").''; + print $html->select_PriceBaseType($product->price_base_type, "price_base_type"); + print '
'.$langs->trans("VATRate").''; + print $html->select_tva("tva_tx",$conf->defaulttx,$mysoc,''); + print '
'; + + print '
'; + + print ''; + print ''; + print '
'; + print ''; } else @@ -846,14 +853,14 @@ if ($_GET["id"] || $_GET["ref"]) print ''; } + // TVA + print ''.$langs->trans("VATRate").''.vatrate($product->tva_tx,true).''; + // Statut print ''.$langs->trans("Status").''; print $product->getLibStatut(2); print ''; - // TVA - print ''.$langs->trans("VATRate").''.price2num($product->tva_tx,'MU').'%'; - // Description print ''.$langs->trans("Description").''.nl2br($product->description).''; @@ -930,10 +937,6 @@ if ($_GET["id"] || $_GET["ref"]) print ''.$langs->trans("Ref").''; print ''.$langs->trans("Label").''; - print ''.$langs->trans("VATRate").''; - print $html->select_tva("tva_tx", $product->tva_tx, $mysoc, '', $product->tva_tx); - print ''; - // Status print ''.$langs->trans("Status").''; print '