diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index f2148f8e063..983331bd412 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -1283,7 +1283,8 @@ if (empty($reshook)) // Ecrase $txtva par celui du produit // Ecrase $base_price_type par celui du produit // Replaces $fk_unit with the product's - if (! empty($idprod)) { + if (! empty($idprod)) + { $prod = new Product($db); $prod->fetch($idprod); @@ -1304,8 +1305,11 @@ if (empty($reshook)) $pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level]; $price_min = $prod->multiprices_min[$object->thirdparty->price_level]; $price_base_type = $prod->multiprices_base_type[$object->thirdparty->price_level]; - if (isset($prod->multiprices_tva_tx[$object->thirdparty->price_level])) $tva_tx=$prod->multiprices_tva_tx[$object->thirdparty->price_level]; - if (isset($prod->multiprices_recuperableonly[$object->thirdparty->price_level])) $tva_npr=$prod->multiprices_recuperableonly[$object->thirdparty->price_level]; + if (! empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) // using this option is a bug. kept for backward compatibility + { + if (isset($prod->multiprices_tva_tx[$object->thirdparty->price_level])) $tva_tx=$prod->multiprices_tva_tx[$object->thirdparty->price_level]; + if (isset($prod->multiprices_recuperableonly[$object->thirdparty->price_level])) $tva_npr=$prod->multiprices_recuperableonly[$object->thirdparty->price_level]; + } } elseif (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) { @@ -1318,26 +1322,30 @@ if (empty($reshook)) $result = $prodcustprice->fetch_all('', '', 0, 0, $filter); if ($result) { if (count($prodcustprice->lines) > 0) { - $pu_ht = price($prodcustprice->lines [0]->price); - $pu_ttc = price($prodcustprice->lines [0]->price_ttc); - $price_base_type = $prodcustprice->lines [0]->price_base_type; - $prod->tva_tx = $prodcustprice->lines [0]->tva_tx; + $pu_ht = price($prodcustprice->lines[0]->price); + $pu_ttc = price($prodcustprice->lines[0]->price_ttc); + $price_base_type = $prodcustprice->lines[0]->price_base_type; + $prod->tva_tx = $prodcustprice->lines[0]->tva_tx; } } } - // if price ht is forced (ie: calculated by margin rate and cost price) - if (! empty($price_ht)) { + // if price ht was forced (ie: from gui when calculated by margin rate and cost price) + if (! empty($price_ht)) + { $pu_ht = price2num($price_ht, 'MU'); $pu_ttc = price2num($pu_ht * (1 + ($tva_tx / 100)), 'MU'); } - // On reevalue prix selon taux tva car taux tva transaction peut etre different // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur). - elseif ($tva_tx != $prod->tva_tx) { - if ($price_base_type != 'HT') { + elseif ($tva_tx != $prod->tva_tx) + { + if ($price_base_type != 'HT') + { $pu_ht = price2num($pu_ttc / (1 + ($tva_tx / 100)), 'MU'); - } else { + } + else + { $pu_ttc = price2num($pu_ht * (1 + ($tva_tx / 100)), 'MU'); } } diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang index e108dfff52b..1759eb12e9f 100644 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -67,6 +67,8 @@ ProductStatusNotOnBuy=Not for purchase ProductStatusOnBuyShort=For purchase ProductStatusNotOnBuyShort=Not for purchase UpdatePrice=Update price +UpdateVAT=Update vat +UpdateDefaultPrice=Update default price AppliedPricesFrom=Applied prices from SellingPrice=Selling price SellingPriceHT=Selling price (net of tax) diff --git a/htdocs/product/price.php b/htdocs/product/price.php index 9c7defc4643..ac611faf5c3 100644 --- a/htdocs/product/price.php +++ b/htdocs/product/price.php @@ -84,8 +84,37 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e if (empty($reshook)) { - if ($action == 'update_price' && !$cancel && ($user->rights->produit->creer || $user->rights->service->creer)) + if (($action == 'update_vat') && !$cancel && ($user->rights->produit->creer || $user->rights->service->creer)) { + $object->tva_tx = GETPOST('tva_tx'); + + $db->begin(); + + $resql = $object->update($object->id, $user); + if (! $resql) + { + $error++; + } + + if ($error) + { + $object->updatePrice($newprice, $newpricebase, $user, $newvat, $newprice_min, $level, $newnpr, $newpsq); + } + + if (! $error) + { + $db->commit(); + } + else + { + $db->rollback(); + } + + $action=''; + } + + if (($action == 'update_price') && !$cancel && ($user->rights->produit->creer || $user->rights->service->creer)) + { $maxpricesupplier = $object->min_recommended_price(); $object->fk_price_expression = empty($eid) ? 0 : $eid; //0 discards expression @@ -399,6 +428,11 @@ if ($isphoto) { print ''; +// Status (to sell) +print '' . $langs->trans("Status") . ' (' . $langs->trans("Sell") . ')'; +print $object->getLibStatut(2, 0); +print ''; + // MultiPrix if (! empty($conf->global->PRODUIT_MULTIPRICES)) { @@ -433,14 +467,32 @@ if (! empty($conf->global->PRODUIT_MULTIPRICES)) print price($object->multiprices_min["$soc->price_level"]) . ' ' . $langs->trans(empty($object->multiprices_base_type["$soc->price_level"])?'HT':$object->multiprices_base_type["$soc->price_level"]); } print ''; - - // TVA - print '' . $langs->trans("VATRate") . '' . vatrate($object->multiprices_tva_tx["$soc->price_level"], true) . ''; + + 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) . ''; + } + else + { + // TVA + print '' . $langs->trans("VATRate") . '' . vatrate($object->tva_tx . ($object->tva_npr ? '*' : ''), true) . ''; + } + } else { - // We show only vat for level 1 - print '' . $langs->trans("VATRate") . '' . vatrate($object->multiprices_tva_tx [1], true) . ''; + if (! empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) // using this option is a bug. kept for backward compatibility + { + // We show only vat for level 1 + print '' . $langs->trans("VATRate") . '' . vatrate($object->multiprices_tva_tx [1], true) . ''; + } + else + { + // TVA + print '' . $langs->trans("VATRate") . '' . vatrate($object->tva_tx . ($object->tva_npr ? '*' : ''), true) . ''; + } + print ''.$langs->trans("PriceLevel").''.$langs->trans("SellingPrice").''.$langs->trans("MinPrice").''; for($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i ++) @@ -551,7 +603,9 @@ if (! empty($conf->global->PRODUIT_MULTIPRICES)) } } } -} else { +} +else +{ // TVA print '' . $langs->trans("VATRate") . '' . vatrate($object->tva_tx . ($object->tva_npr ? '*' : ''), true) . ''; @@ -649,11 +703,6 @@ if (! empty($conf->global->PRODUIT_MULTIPRICES)) } } -// Status (to sell) -print '' . $langs->trans("Status") . ' (' . $langs->trans("Sell") . ')'; -print $object->getLibStatut(2, 0); -print ''; - print "\n"; dol_fiche_end(); @@ -669,16 +718,69 @@ if (! $action || $action == 'delete' || $action == 'showlog_customer_price' || $ { print "\n" . '
' . "\n"; - if ($user->rights->produit->creer || $user->rights->service->creer) { - print '
' . $langs->trans("UpdatePrice") . '
'; + if (empty($conf->global->PRODUIT_MULTIPRICES)) + { + if ($user->rights->produit->creer || $user->rights->service->creer) { + print '
' . $langs->trans("UpdateDefaultPrice") . '
'; + } } - + else + { + if ($user->rights->produit->creer || $user->rights->service->creer) { + print '
' . $langs->trans("UpdateVAT") . '
'; + } + + if ($user->rights->produit->creer || $user->rights->service->creer) { + print '
' . $langs->trans("UpdateDefaultPrice") . '
'; + } + } + if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) + { + if ($user->rights->produit->creer || $user->rights->service->creer) { + print '
id . '">' . $langs->trans("AddCustomerPrice") . '
'; + } + } + print "\n
\n"; } + + /* - * Edition du prix + * Edit price area */ + +if ($action == 'edit_vat' && ($user->rights->produit->creer || $user->rights->service->creer)) +{ + print load_fiche_titre($langs->trans("UpdateVAT"), ''); + + print '
'; + print ''; + print ''; + print ''; + + dol_fiche_head(''); + + print ''; + + // VAT + print ''; + + print '
' . $langs->trans("VATRate") . ''; + print $form->load_tva("tva_tx", $object->tva_tx, $mysoc, '', $object->id, $object->tva_npr); + print '
'; + + dol_fiche_end(); + + print '
'; + print ''; + print '     '; + print ''; + print '
'; + + print '

'; +} + if ($action == 'edit_price' && ($user->rights->produit->creer || $user->rights->service->creer)) { print load_fiche_titre($langs->trans("NewPrice"), ''); @@ -785,26 +887,31 @@ if ($action == 'edit_price' && ($user->rights->produit->creer || $user->rights-> } else { - for($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i ++) + dol_fiche_head(''); + + for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i ++) { + if ($i > 1) print '
'; + print '
'; - print ''; + print ''; print ''; print ''; + if (empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) + { + print ''; + } - dol_fiche_head(''); - print ''; // VAT - if ($i == 1) { + if (! empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) + { print ''; - } else { // We always use the vat rate of price level 1 (A vat rate does not depends on customer) - print ''; } - + // Selling price print '
' . $langs->trans("VATRate") . ''; - print $form->load_tva("tva_tx_" . $i, $object->multiprices_tva_tx ["$i"], $mysoc, '', $object->id); + print $form->load_tva("tva_tx_" . $i, $object->multiprices_tva_tx["$i"], $mysoc, '', $object->id); print '
'; $text = $langs->trans('SellingPrice') . ' ' . $i; @@ -839,10 +946,10 @@ if ($action == 'edit_price' && ($user->rights->produit->creer || $user->rights-> print '
'; - dol_fiche_end(); - print '
'; } + + dol_fiche_end(); } } @@ -886,14 +993,14 @@ if ($result) print '' . $langs->trans("AppliedPricesFrom") . ''; if (! empty($conf->global->PRODUIT_MULTIPRICES)) { - print '' . $langs->trans("MultiPriceLevelsName") . ''; + print '' . $langs->trans("PriceLevel") . ''; } if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) { print '' . $langs->trans("Type") . ''; } print '' . $langs->trans("PriceBase") . ''; - print '' . $langs->trans("VAT") . ''; + if (! empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL) || ! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) print '' . $langs->trans("VATRate") . ''; print '' . $langs->trans("HT") . ''; print '' . $langs->trans("TTC") . ''; if (! empty($conf->dynamicprices->enabled)) { @@ -928,7 +1035,7 @@ if ($result) } print '' . $langs->trans($objp->price_base_type) . ""; - print '' . vatrate($objp->tva_tx, true, $objp->recuperableonly) . ""; + if (! empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL) || ! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) print '' . vatrate($objp->tva_tx, true, $objp->recuperableonly) . ""; //Price if (! empty($objp->fk_price_expression) && ! empty($conf->dynamicprices->enabled)) @@ -942,14 +1049,14 @@ if ($result) } else { - print '' . price($objp->price) . ""; - print '' . price($objp->price_ttc) . ""; + print '' . ($objp->price_base_type != 'TTC' ? price($objp->price) : ''). ""; + print '' . ($objp->price_base_type == 'TTC' ? price($objp->price_ttc) : '') . ""; if (! empty($conf->dynamicprices->enabled)) { //Only if module is enabled print ''; } } - print '' . price($objp->price_min) . ''; - print '' . price($objp->price_min_ttc) . ''; + print '' . ($objp->price_base_type != 'TTC' ? price($objp->price_min) : '') . ''; + print '' . ($objp->price_base_type == 'TTC' ? price($objp->price_min_ttc) : '') . ''; // User print '' . img_object($langs->trans("ShowUser"), 'user') . ' ' . $objp->login . ''; @@ -1202,7 +1309,7 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) print '' . $langs->trans("ThirdParty") . ''; print '' . $langs->trans("AppliedPricesFrom") . ''; print '' . $langs->trans("PriceBase") . ''; - print '' . $langs->trans("VAT") . ''; + print '' . $langs->trans("VATRate") . ''; print '' . $langs->trans("HT") . ''; print '' . $langs->trans("TTC") . ''; print '' . $langs->trans("MinPrice") . ' ' . $langs->trans("HT") . ''; @@ -1275,7 +1382,7 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) print '' . $langs->trans("ThirdParty") . ''; print '' . $langs->trans("AppliedPricesFrom") . ''; print '' . $langs->trans("PriceBase") . ''; - print '' . $langs->trans("VAT") . ''; + print '' . $langs->trans("VATRate") . ''; print '' . $langs->trans("HT") . ''; print '' . $langs->trans("TTC") . ''; print '' . $langs->trans("MinPrice") . ' ' . $langs->trans("HT") . ''; @@ -1355,19 +1462,6 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) print ""; print ""; - - /* ************************************************************************** */ - /* */ - /* Barre d'action */ - /* */ - /* ************************************************************************** */ - - print "\n" . '
' . "\n"; - - if ($user->rights->produit->creer || $user->rights->service->creer) { - print '
id . '">' . $langs->trans("AddCustomerPrice") . '
'; - } - print "\n

\n"; } }