diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 33ad6a48ca3..bfddc4b4921 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -3711,7 +3711,7 @@ function vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0) if (! preg_match('/\//', $rate)) $ret=price($rate,0,'',0,0).($addpercent?'%':''); else { - // TODO Split on / and output with a price2num to have clean numbers with ton of 000. + // TODO Split on / and output with a price2num to have clean numbers without ton of 000. $ret=$rate.($addpercent?'%':''); } if ($info_bits & 1) $ret.=' *'; diff --git a/htdocs/core/tpl/objectline_view.tpl.php b/htdocs/core/tpl/objectline_view.tpl.php index f968fdcbfc7..94c05fd9ffe 100644 --- a/htdocs/core/tpl/objectline_view.tpl.php +++ b/htdocs/core/tpl/objectline_view.tpl.php @@ -145,7 +145,7 @@ if (empty($outputalsopricetotalwithtax)) $outputalsopricetotalwithtax=0; tva_tx)) $positiverates.=($positiverates?'/':'').price2num($line->tva_tx); + if (price2num($line->tva_tx)) $positiverates.=($positiverates?'/':'').price2num($line->tva_tx); if (price2num($line->total_localtax1)) $positiverates.=($positiverates?'/':'').price2num($line->localtax1_tx); if (price2num($line->total_localtax2)) $positiverates.=($positiverates?'/':'').price2num($line->localtax2_tx); if (empty($positiverates)) $positiverates='0'; diff --git a/htdocs/fourn/class/fournisseur.product.class.php b/htdocs/fourn/class/fournisseur.product.class.php index 5184c8ffe80..17f8b2615ee 100644 --- a/htdocs/fourn/class/fournisseur.product.class.php +++ b/htdocs/fourn/class/fournisseur.product.class.php @@ -180,16 +180,18 @@ class ProductFournisseur extends Product * @param Societe $fourn Supplier * @param int $availability Product availability * @param string $ref_fourn Supplier ref - * @param float $tva_tx VAT rate + * @param float $tva_tx New VAT Rate (For example 8.5. Should not be a string) * @param string $charges costs affering to product * @param float $remise_percent Discount regarding qty (percent) * @param float $remise Discount regarding qty (amount) * @param int $newnpr Set NPR or not * @param int $delivery_time_days Delay in days for delivery (max). May be '' if not defined. * @param string $supplier_reputation Reputation with this product to the defined supplier (empty, FAVORITE, DONOTORDER) + * @param array $localtaxes_array Array with localtaxes info array('0'=>type1,'1'=>rate1,'2'=>type2,'3'=>rate2) (loaded by getLocalTaxesFromRate(vatrate, 0, ...) function). + * @param string $newdefaultvatcode Default vat code * @return int <0 if KO, >=0 if OK */ - function update_buyprice($qty, $buyprice, $user, $price_base_type, $fourn, $availability, $ref_fourn, $tva_tx, $charges=0, $remise_percent=0, $remise=0, $newnpr=0, $delivery_time_days=0, $supplier_reputation='') + function update_buyprice($qty, $buyprice, $user, $price_base_type, $fourn, $availability, $ref_fourn, $tva_tx, $charges=0, $remise_percent=0, $remise=0, $newnpr=0, $delivery_time_days=0, $supplier_reputation='', $localtaxes_array=array(), $newdefaultvatcode='') { global $conf, $langs; //global $mysoc; @@ -217,6 +219,25 @@ class ProductFournisseur extends Product $now=dol_now(); + $newvat = $tva_tx; + + if (count($localtaxes_array) > 0) + { + $localtaxtype1=$localtaxes_array['0']; + $localtax1=$localtaxes_array['1']; + $localtaxtype2=$localtaxes_array['2']; + $localtax2=$localtaxes_array['3']; + } + else // old method. deprecated because ot can't retreive type + { + $localtaxtype1='0'; + $localtax1=get_localtax($newvat,1); + $localtaxtype2='0'; + $localtax2=get_localtax($newvat,2); + } + if (empty($localtax1)) $localtax1=0; // If = '' then = 0 + if (empty($localtax2)) $localtax2=0; // If = '' then = 0 + $this->db->begin(); if ($this->product_fourn_price_id > 0) @@ -230,9 +251,15 @@ class ProductFournisseur extends Product $sql.= " remise = ".$remise.","; $sql.= " unitprice = ".$unitBuyPrice.","; $sql.= " unitcharges = ".$unitCharges.","; // deprecated - $sql.= " tva_tx = ".$tva_tx.","; $sql.= " fk_availability = ".$availability.","; $sql.= " entity = ".$conf->entity.","; + $sql.= " tva_tx = ".price2num($tva_tx).","; + // TODO Add localtax1 and localtax2 + //$sql.= " localtax1_tx=".($localtax1>=0?$localtax1:'NULL').","; + //$sql.= " localtax2_tx=".($localtax2>=0?$localtax2:'NULL').","; + //$sql.= " localtax1_type=".($localtaxtype1!=''?"'".$localtaxtype1."'":"'0'").","; + //$sql.= " localtax2_type=".($localtaxtype2!=''?"'".$localtaxtype2."'":"'0'").","; + $sql.= " default_vat_code=".($newdefaultvatcode?"'".$this->db->escape($newdefaultvatcode)."'":"null").","; $sql.= " info_bits = ".$newnpr.","; $sql.= " charges = ".$charges.","; // deprecated $sql.= " delivery_time_days = ".($delivery_time_days != '' ? $delivery_time_days : 'null').","; @@ -279,7 +306,7 @@ class ProductFournisseur extends Product if ($resql) { // Add price for this quantity to supplier $sql = "INSERT INTO " . MAIN_DB_PREFIX . "product_fournisseur_price("; - $sql .= "datec, fk_product, fk_soc, ref_fourn, fk_user, price, quantity, remise_percent, remise, unitprice, tva_tx, charges, unitcharges, fk_availability, info_bits, entity, delivery_time_days,supplier_reputation)"; + $sql .= "datec, fk_product, fk_soc, ref_fourn, fk_user, price, quantity, remise_percent, remise, unitprice, tva_tx, charges, unitcharges, fk_availability, default_vat_code, info_bits, entity, delivery_time_days, supplier_reputation)"; $sql .= " values('" . $this->db->idate($now) . "',"; $sql .= " " . $this->id . ","; $sql .= " " . $fourn->id . ","; @@ -294,6 +321,7 @@ class ProductFournisseur extends Product $sql .= " " . $charges . ","; $sql .= " " . $unitCharges . ","; $sql .= " " . $availability . ","; + $sql .= " ".($newdefaultvatcode?"'".$this->db->escape($newdefaultvatcode)."'":"null").","; $sql .= " " . $newnpr . ","; $sql .= $conf->entity . ","; $sql .= $delivery_time_days . ","; @@ -364,9 +392,9 @@ class ProductFournisseur extends Product function fetch_product_fournisseur_price($rowid, $ignore_expression = 0) { global $conf; - $sql = "SELECT pfp.rowid, pfp.price, pfp.quantity, pfp.unitprice, pfp.remise_percent, pfp.remise, pfp.tva_tx, pfp.fk_availability,"; + $sql = "SELECT pfp.rowid, pfp.price, pfp.quantity, pfp.unitprice, pfp.remise_percent, pfp.remise, pfp.tva_tx, pfp.default_vat_code, pfp.fk_availability,"; $sql.= " pfp.fk_soc, pfp.ref_fourn, pfp.fk_product, pfp.charges, pfp.unitcharges, pfp.fk_supplier_price_expression, pfp.delivery_time_days,"; // , pfp.recuperableonly as fourn_tva_npr"; FIXME this field not exist in llx_product_fournisseur_price - $sql.=" pfp.supplier_reputation"; + $sql.= " pfp.supplier_reputation"; $sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp"; $sql.= " WHERE pfp.rowid = ".$rowid; @@ -392,11 +420,14 @@ class ProductFournisseur extends Product $this->fourn_unitprice = $obj->unitprice; $this->fourn_unitcharges = $obj->unitcharges; // deprecated $this->fourn_tva_tx = $obj->tva_tx; - //$this->fourn_tva_npr = $obj->fourn_tva_npr; // TODO this field not exist in llx_product_fournisseur_price. We should add it ? + // TODO + // $this->fourn_tva_npr = $obj->fourn_tva_npr; // TODO this field not exist in llx_product_fournisseur_price. We should add it ? + // Add also localtaxes $this->fk_availability = $obj->fk_availability; $this->delivery_time_days = $obj->delivery_time_days; $this->fk_supplier_price_expression = $obj->fk_supplier_price_expression; - $this->supplier_reputation = $obj->supplier_reputation; + $this->supplier_reputation = $obj->supplier_reputation; + $this->default_vat_code = $obj->default_vat_code; if (empty($ignore_expression) && !empty($this->fk_supplier_price_expression)) { diff --git a/htdocs/product/admin/product_tools.php b/htdocs/product/admin/product_tools.php index 85351a0fb2a..f19f672a25e 100644 --- a/htdocs/product/admin/product_tools.php +++ b/htdocs/product/admin/product_tools.php @@ -38,8 +38,8 @@ $langs->load("products"); if (! $user->admin) accessforbidden(); $action = GETPOST('action','alpha'); -$oldvatrate=GETPOST('oldvatrate'); -$newvatrate=GETPOST('newvatrate'); +$oldvatrate=GETPOST('oldvatrate', 'alpha'); +$newvatrate=GETPOST('newvatrate', 'alpha'); //$price_base_type=GETPOST('price_base_type'); @@ -67,13 +67,31 @@ if ($action == 'convert') $db->begin(); + // Clean vat code old + $vat_src_code_old=''; + if (preg_match('/\((.*)\)/', $oldvatrate, $reg)) + { + $vat_src_code_old = $reg[1]; + $oldvatrateclean = preg_replace('/\s*\(.*\)/', '', $oldvatrate); // Remove code into vatrate. + } + + // Clean vat code new + $vat_src_code_new=''; + if (preg_match('/\((.*)\)/', $newvatrate, $reg)) + { + $vat_src_code_new = $reg[1]; + $newvatrateclean = preg_replace('/\s*\(.*\)/', '', $newvatrate); // Remove code into vatrate. + } + // If country to edit is my country, so we change customer prices if ($country_id == $mysoc->country_id) { $sql = 'SELECT rowid'; $sql.= ' FROM '.MAIN_DB_PREFIX.'product'; $sql.= ' WHERE entity IN ('.getEntity('product').')'; - $sql.= " AND tva_tx = '".$db->escape($oldvatrate)."'"; + $sql.= " AND tva_tx = '".$db->escape($oldvatrateclean)."'"; + if ($vat_src_code_old) $sql.= " AND default_vat_code = '".$vat_src_code_old."'"; + else " AND default_vat_code = IS NULL"; $resql=$db->query($sql); if ($resql) @@ -109,12 +127,15 @@ if ($action == 'convert') $newminprice=$objectstatic->multiprices_min[$level]; } if ($newminprice > $newprice) $newminprice=$newprice; + $newvat=str_replace('*','',$newvatrate); + $localtaxes_type=getLocalTaxesFromRate($newvat, 0, $mysoc, $mysoc); $newnpr=$objectstatic->multiprices_recuperableonly[$level]; + $newdefaultvatcode=$vat_src_code_new; $newlevel=$level; //print "$objectstatic->id $newprice, $price_base_type, $newvat, $newminprice, $newlevel, $newnpr
\n"; - $retm=$objectstatic->updatePrice($newprice, $price_base_type, $user, $newvat, $newminprice, $newlevel, $newnpr); + $retm=$objectstatic->updatePrice($newprice, $price_base_type, $user, $newvatratclean, $newminprice, $newlevel, $newnpr, 0, 0, $localtaxes_type, $newdefaultvatcode); if ($retm < 0) { $error++; @@ -138,19 +159,21 @@ if ($action == 'convert') } if ($newminprice > $newprice) $newminprice=$newprice; $newvat=str_replace('*','',$newvatrate); + $localtaxes_type=getLocalTaxesFromRate($newvat, 0, $mysoc, $mysoc); $newnpr=$objectstatic->recuperableonly; + $newdefaultvatcode=$vat_src_code_new; $newlevel=0; if (! empty($price_base_type) && ! $updatelevel1) { //print "$objectstatic->id $newprice, $price_base_type, $newvat, $newminprice, $newlevel, $newnpr
\n"; - $ret=$objectstatic->updatePrice($newprice, $price_base_type, $user, $newvat, $newminprice, $newlevel, $newnpr); + $ret=$objectstatic->updatePrice($newprice, $price_base_type, $user, $newvatrateclean, $newminprice, $newlevel, $newnpr, 0, 0, $localtaxes_type, $newdefaultvatcode); } if ($ret < 0 || $retm < 0) $error++; else $nbrecordsmodified++; } unset($objectstatic); - + $i++; } } @@ -164,6 +187,8 @@ if ($action == 'convert') $sql.= ' FROM '.MAIN_DB_PREFIX.'product_fournisseur_price as pfp, '.MAIN_DB_PREFIX.'societe as s'; $sql.= ' WHERE pfp.fk_soc = s.rowid AND pfp.entity IN ('.getEntity('product').')'; $sql.= " AND tva_tx = '".$db->escape($oldvatrate)."'"; + if ($vat_src_code_old) $sql.= " AND default_vat_code = '".$vat_src_code_old."'"; + else " AND default_vat_code = IS NULL"; $sql.= " AND s.fk_pays = '".$country_id."'"; //print $sql; $resql=$db->query($sql); @@ -196,26 +221,33 @@ if ($action == 'convert') //} //if ($newminprice > $newprice) $newminprice=$newprice; $newvat=str_replace('*','',$newvatrate); + $localtaxes_type=getLocalTaxesFromRate($newvat, 0, $mysoc, $mysoc); //$newnpr=$objectstatic2->recuperableonly; + $newnpr=0; + $newdefaultvatcode=$vat_src_code_new; + + $newpercent = $objectstatic2->fourn_remise_percent; + $newdeliverydelay = $objectstatic2->delivery_time_days; + $newsupplierreputation = $objectstatic2->supplier_reputation; + $newlevel=0; if (! empty($price_base_type) && ! $updatelevel1) { //print "$objectstatic2->id $newprice, $price_base_type, $newvat, $newminprice, $newlevel, $newnpr
\n"; $fourn->id=$obj->fk_soc; - $ret=$objectstatic2->update_buyprice($obj->qty, $newprice, $user, $price_base_type, $fourn, $obj->fk_availability, $obj->ref_fourn, $newvat); + $ret=$objectstatic2->update_buyprice($obj->qty, $newprice, $user, $price_base_type, $fourn, $obj->fk_availability, $obj->ref_fourn, $newvat, '', $newpercent, 0, $newnpr, $newdeliverydelay, $newsupplierreputation, $localtaxes_type, $newdefaultvatcode); } if ($ret < 0 || $retm < 0) $error++; else $nbrecordsmodified++; } unset($objectstatic2); - + $i++; } } else dol_print_error($db); - if (! $error) { $db->commit(); @@ -274,24 +306,24 @@ else print ''.$langs->trans("Value").''."\n"; print ''."\n"; - + print ''."\n"; print ''.$langs->trans("OldVATRates").''."\n"; print ''."\n"; - print $form->load_tva('oldvatrate', $oldvatrate, $mysoc); + print $form->load_tva('oldvatrate', $oldvatrate, $mysoc, null, 0, 0, '', false, 1); print ''."\n"; print ''."\n"; - + print ''."\n"; print ''.$langs->trans("NewVATRates").''."\n"; print ''."\n"; - print $form->load_tva('newvatrate', $newvatrate, $mysoc); + print $form->load_tva('newvatrate', $newvatrate, $mysoc, null, 0, 0, '', false, 1); print ''."\n"; print ''."\n"; /* - + print ''."\n"; print ''.$langs->trans("PriceBaseTypeToChange").''."\n"; print ''."\n"; @@ -303,7 +335,7 @@ else print ''; print '
'; - + // Boutons actions print '
'; print ''; diff --git a/htdocs/product/class/productcustomerprice.class.php b/htdocs/product/class/productcustomerprice.class.php index 441b865e255..4ff018bf031 100644 --- a/htdocs/product/class/productcustomerprice.class.php +++ b/htdocs/product/class/productcustomerprice.class.php @@ -329,6 +329,8 @@ class Productcustomerprice extends CommonObject $sql .= " t.recuperableonly,"; $sql .= " t.localtax1_tx,"; $sql .= " t.localtax2_tx,"; + $sql .= " t.localtax1_type,"; + $sql .= " t.localtax2_type,"; $sql .= " t.fk_user,"; $sql .= " t.import_key,"; $sql .= " soc.nom as socname,"; @@ -386,6 +388,8 @@ class Productcustomerprice extends CommonObject $line->recuperableonly = $obj->recuperableonly; $line->localtax1_tx = $obj->localtax1_tx; $line->localtax2_tx = $obj->localtax2_tx; + $line->localtax1_type = $obj->localtax1_type; + $line->localtax2_type = $obj->localtax2_type; $line->fk_user = $obj->fk_user; $line->import_key = $obj->import_key; $line->socname = $obj->socname; diff --git a/htdocs/product/price.php b/htdocs/product/price.php index 949711b4a1b..f16b716c9cc 100644 --- a/htdocs/product/price.php +++ b/htdocs/product/price.php @@ -107,8 +107,15 @@ if (empty($reshook)) $tva_tx_txt = GETPOST('tva_tx', 'alpha'); // tva_tx can be '8.5' or '8.5*' or '8.5 (XXX)' or '8.5* (XXX)' // We must define tva_tx, npr and local taxes + $tva_tx = $tva_tx_txt; $vatratecode = ''; - $tva_tx = preg_replace('/[^0-9\.].*$/', '', $tva_tx_txt); // keep remove all after the numbers and dot + if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) + { + $vat_src_code = $reg[1]; + $tva_tx = preg_replace('/\s*\(.*\)/', '', $tva_tx_txt); // Remove code into vatrate. + } + + $tva_tx = price2num(preg_replace('/\*/', '', $tva_tx)); // keep remove all after the numbers and dot $npr = preg_match('/\*/', $tva_tx_txt) ? 1 : 0; $localtax1 = 0; $localtax2 = 0; $localtax1_type = '0'; $localtax2_type = '0'; // If value contains the unique code of vat line (new recommanded method), we use it to find npr and local taxes @@ -217,8 +224,15 @@ if (empty($reshook)) $tva_tx_txt = $newvattx[$i]; + $tva_tx = $tva_tx_txt; $vatratecode = ''; - $tva_tx = preg_replace('/[^0-9\.].*$/', '', $tva_tx_txt); // keep remove all after the numbers and dot + if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) + { + $vat_src_code = $reg[1]; + $tva_tx = preg_replace('/\s*\(.*\)/', '', $tva_tx_txt); // Remove code into vatrate. + } + $tva_tx = price2num(preg_replace('/\*/', '', $tva_tx)); // keep remove all after the numbers and dot + $npr = preg_match('/\*/', $tva_tx_txt) ? 1 : 0; $localtax1 = $newlocaltax1_tx[$i]; $localtax1_type = $newlocaltax1_type[$i]; @@ -266,9 +280,15 @@ if (empty($reshook)) { $tva_tx_txt = GETPOST('tva_tx', 'alpha'); // tva_tx can be '8.5' or '8.5*' or '8.5 (XXX)' or '8.5* (XXX)' + $tva_tx = $tva_tx_txt; $vatratecode = ''; - // We must define tva_tx, npr and local taxes - $tva_tx = preg_replace('/[^0-9\.].*$/', '', $tva_tx_txt); // keep remove all after the numbers and dot + if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) + { + $vat_src_code = $reg[1]; + $tva_tx = preg_replace('/\s*\(.*\)/', '', $tva_tx_txt); // Remove code into vatrate. + } + $tva_tx = price2num(preg_replace('/\*/', '', $tva_tx)); // keep remove all after the numbers and dot + $npr = preg_match('/\*/', $tva_tx_txt) ? 1 : 0; $localtax1 = 0; $localtax2 = 0; $localtax1_type = '0'; $localtax2_type = '0'; // If value contains the unique code of vat line (new recommanded method), we use it to find npr and local taxes @@ -280,7 +300,7 @@ if (empty($reshook)) $sql = "SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type"; $sql.= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c"; $sql.= " WHERE t.fk_pays = c.rowid AND c.code = '".$mysoc->country_code."'"; - $sql.= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1"; + $sql.= " AND t.taux = ".$tva_tx." AND t.active = 1"; $sql.= " AND t.code ='".$vatratecode."'"; $resql=$db->query($sql); if ($resql) @@ -469,11 +489,17 @@ if (empty($reshook)) $prodcustprice->price_min = price2num(GETPOST("price_min"), 'MU'); $prodcustprice->price_base_type = GETPOST("price_base_type", 'alpha'); - $tva_tx_txt = GETPOST("tva_tx"); + $tva_tx_txt = GETPOST("tva_tx",'alpha'); + $tva_tx = $tva_tx_txt; $vatratecode = ''; - // We must define tva_tx, npr and local taxes - $tva_tx = preg_replace('/[^0-9\.].*$/', '', $tva_tx_txt); // keep remove all after the numbers and dot + if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) + { + $vat_src_code = $reg[1]; + $tva_tx = preg_replace('/\s*\(.*\)/', '', $tva_tx_txt); // Remove code into vatrate. + } + $tva_tx = price2num(preg_replace('/\*/', '', $tva_tx)); // keep remove all after the numbers and dot + $npr = preg_match('/\*/', $tva_tx_txt) ? 1 : 0; $localtax1 = 0; $localtax2 = 0; $localtax1_type = '0'; $localtax2_type = '0'; // If value contains the unique code of vat line (new recommanded method), we use it to find npr and local taxes @@ -485,7 +511,7 @@ if (empty($reshook)) $sql = "SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type"; $sql.= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c"; $sql.= " WHERE t.fk_pays = c.rowid AND c.code = '".$mysoc->country_code."'"; - $sql.= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1"; + $sql.= " AND t.taux = ".$tva_tx." AND t.active = 1"; $sql.= " AND t.code ='".$vatratecode."'"; $resql=$db->query($sql); if ($resql) @@ -565,9 +591,15 @@ if (empty($reshook)) $tva_tx_txt = GETPOST("tva_tx"); - $vatratecode=''; - // We must define tva_tx, npr and local taxes - $tva_tx = preg_replace('/[^0-9\.].*$/', '', $tva_tx_txt); // keep remove all after the numbers and dot + $tva_tx = $tva_tx_txt; + $vatratecode = ''; + if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) + { + $vat_src_code = $reg[1]; + $tva_tx = preg_replace('/\s*\(.*\)/', '', $tva_tx_txt); // Remove code into vatrate. + } + $tva_tx = price2num(preg_replace('/\*/', '', $tva_tx)); // keep remove all after the numbers and dot + $npr = preg_match('/\*/', $tva_tx_txt) ? 1 : 0; $localtax1 = 0; $localtax2 = 0; $localtax1_type = '0'; $localtax2_type = '0'; // If value contains the unique code of vat line (new recommanded method), we use it to find npr and local taxes @@ -579,7 +611,7 @@ if (empty($reshook)) $sql = "SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type"; $sql.= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c"; $sql.= " WHERE t.fk_pays = c.rowid AND c.code = '".$mysoc->country_code."'"; - $sql.= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1"; + $sql.= " AND t.taux = ".$tva_tx." AND t.active = 1"; $sql.= " AND t.code ='".$vatratecode."'"; $resql=$db->query($sql); if ($resql) @@ -712,17 +744,34 @@ if (! empty($conf->global->PRODUIT_MULTIPRICES)) if (! empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) // using this option is a bug. kept for backward compatibility { // TVA - print '' . $langs->trans("VATRate") . '' . vatrate($object->multiprices_tva_tx[$soc->price_level], true) . ''; + print '' . $langs->trans("VATRate") . ''; + + $positiverates=''; + if (price2num($object->multiprices_tva_tx[$soc->price_level])) $positiverates.=($positiverates?'/':'').price2num($object->multiprices_tva_tx[$soc->price_level]); + if (price2num($object->multiprices_localtax1_type[$soc->price_level])) $positiverates.=($positiverates?'/':'').price2num($object->multiprices_localtax1_tx[$soc->price_level]); + if (price2num($object->multiprices_localtax2_type[$soc->price_level])) $positiverates.=($positiverates?'/':'').price2num($object->multiprices_localtax2_tx[$soc->price_level]); + if (empty($positiverates)) $positiverates='0'; + echo vatrate($positiverates.($object->default_vat_code?' ('.$object->default_vat_code.')':''), '%', $object->tva_npr); + //print vatrate($object->multiprices_tva_tx[$soc->price_level], true); + print ''; } else { // TVA print '' . $langs->trans("VATRate") . ''; + + $positiverates=''; + if (price2num($object->tva_tx)) $positiverates.=($positiverates?'/':'').price2num($object->tva_tx); + if (price2num($object->localtax1_type)) $positiverates.=($positiverates?'/':'').price2num($object->localtax1_tx); + if (price2num($object->localtax2_type)) $positiverates.=($positiverates?'/':'').price2num($object->localtax2_tx); + if (empty($positiverates)) $positiverates='0'; + echo vatrate($positiverates.($object->default_vat_code?' ('.$object->default_vat_code.')':''), '%', $object->tva_npr); + /* if ($object->default_vat_code) { print vatrate($object->tva_tx, true) . ' ('.$object->default_vat_code.')'; } - else print vatrate($object->tva_tx . ($object->tva_npr ? '*' : ''), true); + else print vatrate($object->tva_tx . ($object->tva_npr ? '*' : ''), true);*/ print ''; } @@ -740,11 +789,19 @@ if (! empty($conf->global->PRODUIT_MULTIPRICES)) { // TVA print '' . $langs->trans("VATRate") . ''; + + $positiverates=''; + if (price2num($object->tva_tx)) $positiverates.=($positiverates?'/':'').price2num($object->tva_tx); + if (price2num($object->localtax1_type)) $positiverates.=($positiverates?'/':'').price2num($object->localtax1_tx); + if (price2num($object->localtax2_type)) $positiverates.=($positiverates?'/':'').price2num($object->localtax2_tx); + if (empty($positiverates)) $positiverates='0'; + echo vatrate($positiverates.($object->default_vat_code?' ('.$object->default_vat_code.')':''), '%', $object->tva_npr); + /* if ($object->default_vat_code) { print vatrate($object->tva_tx, true) . ' ('.$object->default_vat_code.')'; } - else print vatrate($object->tva_tx . ($object->tva_npr ? '*' : ''), true); + else print vatrate($object->tva_tx . ($object->tva_npr ? '*' : ''), true);*/ print ''; } print ''; @@ -889,11 +946,19 @@ else { // TVA print '' . $langs->trans("VATRate") . ''; + + $positiverates=''; + if (price2num($object->tva_tx)) $positiverates.=($positiverates?'/':'').price2num($object->tva_tx); + if (price2num($object->localtax1_type)) $positiverates.=($positiverates?'/':'').price2num($object->localtax1_tx); + if (price2num($object->localtax2_type)) $positiverates.=($positiverates?'/':'').price2num($object->localtax2_tx); + if (empty($positiverates)) $positiverates='0'; + echo vatrate($positiverates.($object->default_vat_code?' ('.$object->default_vat_code.')':''), '%', $object->tva_npr); + /* if ($object->default_vat_code) { print vatrate($object->tva_tx, true) . ' ('.$object->default_vat_code.')'; } - else print vatrate($object->tva_tx, true, $object->tva_npr, true); + else print vatrate($object->tva_tx, true, $object->tva_npr, true);*/ print ''; // Price @@ -1314,7 +1379,7 @@ if ($action == 'edit_price' && $object->getRights()->creer) if ((empty($conf->global->PRODUIT_CUSTOMER_PRICES) || $action=='showlog_default_price') && ! in_array($action, array('edit_price','edit_vat'))) { - $sql = "SELECT p.rowid, p.price, p.price_ttc, p.price_base_type, p.tva_tx, p.default_vat_code, p.recuperableonly,"; + $sql = "SELECT p.rowid, p.price, p.price_ttc, p.price_base_type, p.tva_tx, p.default_vat_code, p.recuperableonly, p.localtax1_tx, p.localtax1_type, p.localtax2_tx, p.localtax2_type,"; $sql .= " p.price_level, p.price_min, p.price_min_ttc,p.price_by_qty,"; $sql .= " p.date_price as dp, p.fk_price_expression, u.rowid as user_id, u.login"; $sql .= " FROM " . MAIN_DB_PREFIX . "product_price as p,"; @@ -1410,11 +1475,19 @@ if ((empty($conf->global->PRODUIT_CUSTOMER_PRICES) || $action=='showlog_default_ if (empty($conf->global->PRODUIT_MULTIPRICES)) { print ''; + + $positiverates=''; + if (price2num($objp->tva_tx)) $positiverates.=($positiverates?'/':'').price2num($objp->tva_tx); + if (price2num($objp->localtax1_type)) $positiverates.=($positiverates?'/':'').price2num($objp->localtax1_tx); + if (price2num($objp->localtax2_type)) $positiverates.=($positiverates?'/':'').price2num($objp->localtax2_tx); + if (empty($positiverates)) $positiverates='0'; + echo vatrate($positiverates.($objp->default_vat_code?' ('.$objp->default_vat_code.')':''), '%', $objp->tva_npr); + /* if ($objp->default_vat_code) { print vatrate($objp->tva_tx, true) . ' ('.$objp->default_vat_code.')'; } - else print vatrate($objp->tva_tx, true, $objp->recuperableonly); + else print vatrate($objp->tva_tx, true, $objp->recuperableonly);*/ print ""; } @@ -1769,7 +1842,17 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) print "" . $staticsoc->getNomUrl(1) . ""; print "" . dol_print_date($line->datec, "dayhour") . ""; print '' . $langs->trans($line->price_base_type) . ""; - print '' . vatrate($tva_tx, true, $line->recuperableonly) . ""; + print ''; +var_dump($prodcustprice);exit; + $positiverates=''; + if (price2num($objp->tva_tx)) $positiverates.=($positiverates?'/':'').price2num($objp->tva_tx); + if (price2num($objp->localtax1_type)) $positiverates.=($positiverates?'/':'').price2num($objp->localtax1_tx); + if (price2num($objp->localtax2_type)) $positiverates.=($positiverates?'/':'').price2num($objp->localtax2_tx); + if (empty($positiverates)) $positiverates='0'; + echo vatrate($positiverates.($objp->default_vat_code?' ('.$objp->default_vat_code.')':''), '%', $objp->tva_npr); + + //. vatrate($tva_tx, true, $line->recuperableonly) . + print ""; print '' . price($line->price) . ""; print '' . price($line->price_ttc) . ""; @@ -1873,8 +1956,16 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) print '' . $langs->trans($object->price_base_type) . ""; print ''; - print vatrate($object->tva_tx, true, $object->recuperableonly); - print $object->default_vat_code?' ('.$object->default_vat_code.')':''; + + $positiverates=''; + if (price2num($object->tva_tx)) $positiverates.=($positiverates?'/':'').price2num($object->tva_tx); + if (price2num($object->localtax1_type)) $positiverates.=($positiverates?'/':'').price2num($object->localtax1_tx); + if (price2num($object->localtax2_type)) $positiverates.=($positiverates?'/':'').price2num($object->localtax2_tx); + if (empty($positiverates)) $positiverates='0'; + echo vatrate($positiverates.($object->default_vat_code?' ('.$object->default_vat_code.')':''), '%', $object->tva_npr); + + //print vatrate($object->tva_tx, true, $object->tva_npr); + //print $object->default_vat_code?' ('.$object->default_vat_code.')':''; print ""; print '' . price($object->price) . ""; @@ -1939,7 +2030,16 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) print "" . dol_print_date($line->datec, "dayhour") . ""; print '' . $langs->trans($line->price_base_type) . ""; - print '' . vatrate($tva_tx, true, $line->recuperableonly) . ""; + print ''; + + $positiverates=''; + if (price2num($line->tva_tx)) $positiverates.=($positiverates?'/':'').price2num($line->tva_tx); + if (price2num($line->localtax1_type)) $positiverates.=($positiverates?'/':'').price2num($line->localtax1_tx); + if (price2num($line->localtax2_type)) $positiverates.=($positiverates?'/':'').price2num($line->localtax2_tx); + if (empty($positiverates)) $positiverates='0'; + echo vatrate($positiverates.($line->default_vat_code?' ('.$line->default_vat_code.')':''), '%', $line->tva_npr); + + print ""; print '' . price($line->price) . ""; print '' . price($line->price_ttc) . "";