FIX The price per level just never correctly manage the vat. Vat is not
per level but depends on seller and supplyer. I kept a hidden option to keep old behaviour that was bugged.
This commit is contained in:
parent
9a4b62c279
commit
080ba15e0d
@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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 '</tr>';
|
||||
|
||||
// Status (to sell)
|
||||
print '<tr><td>' . $langs->trans("Status") . ' (' . $langs->trans("Sell") . ')</td><td colspan="2">';
|
||||
print $object->getLibStatut(2, 0);
|
||||
print '</td></tr>';
|
||||
|
||||
// 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 '</td></tr>';
|
||||
|
||||
// TVA
|
||||
print '<tr><td>' . $langs->trans("VATRate") . '</td><td colspan="2">' . vatrate($object->multiprices_tva_tx["$soc->price_level"], true) . '</td></tr>';
|
||||
|
||||
if (! empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) // using this option is a bug. kept for backward compatibility
|
||||
{
|
||||
// TVA
|
||||
print '<tr><td>' . $langs->trans("VATRate") . '</td><td colspan="2">' . vatrate($object->multiprices_tva_tx["$soc->price_level"], true) . '</td></tr>';
|
||||
}
|
||||
else
|
||||
{
|
||||
// TVA
|
||||
print '<tr><td>' . $langs->trans("VATRate") . '</td><td>' . vatrate($object->tva_tx . ($object->tva_npr ? '*' : ''), true) . '</td></tr>';
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// We show only vat for level 1
|
||||
print '<tr><td>' . $langs->trans("VATRate") . '</td><td colspan="2">' . vatrate($object->multiprices_tva_tx [1], true) . '</td></tr>';
|
||||
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 '<tr><td>' . $langs->trans("VATRate") . '</td><td colspan="2">' . vatrate($object->multiprices_tva_tx [1], true) . '</td></tr>';
|
||||
}
|
||||
else
|
||||
{
|
||||
// TVA
|
||||
print '<tr><td>' . $langs->trans("VATRate") . '</td><td>' . vatrate($object->tva_tx . ($object->tva_npr ? '*' : ''), true) . '</td></tr>';
|
||||
}
|
||||
|
||||
print '<tr class="liste_titre"><td style="text-align: center">'.$langs->trans("PriceLevel").'</td><td style="text-align: center">'.$langs->trans("SellingPrice").'</td><td style="text-align: center">'.$langs->trans("MinPrice").'</td></tr>';
|
||||
|
||||
for($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i ++)
|
||||
@ -551,7 +603,9 @@ if (! empty($conf->global->PRODUIT_MULTIPRICES))
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
// TVA
|
||||
print '<tr><td>' . $langs->trans("VATRate") . '</td><td>' . vatrate($object->tva_tx . ($object->tva_npr ? '*' : ''), true) . '</td></tr>';
|
||||
|
||||
@ -649,11 +703,6 @@ if (! empty($conf->global->PRODUIT_MULTIPRICES))
|
||||
}
|
||||
}
|
||||
|
||||
// Status (to sell)
|
||||
print '<tr><td>' . $langs->trans("Status") . ' (' . $langs->trans("Sell") . ')</td><td colspan="2">';
|
||||
print $object->getLibStatut(2, 0);
|
||||
print '</td></tr>';
|
||||
|
||||
print "</table>\n";
|
||||
|
||||
dol_fiche_end();
|
||||
@ -669,16 +718,69 @@ if (! $action || $action == 'delete' || $action == 'showlog_customer_price' || $
|
||||
{
|
||||
print "\n" . '<div class="tabsAction">' . "\n";
|
||||
|
||||
if ($user->rights->produit->creer || $user->rights->service->creer) {
|
||||
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER['PHP_SELF'] . '?action=edit_price&id=' . $object->id . '">' . $langs->trans("UpdatePrice") . '</a></div>';
|
||||
if (empty($conf->global->PRODUIT_MULTIPRICES))
|
||||
{
|
||||
if ($user->rights->produit->creer || $user->rights->service->creer) {
|
||||
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER['PHP_SELF'] . '?action=edit_price&id=' . $object->id . '">' . $langs->trans("UpdateDefaultPrice") . '</a></div>';
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if ($user->rights->produit->creer || $user->rights->service->creer) {
|
||||
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER['PHP_SELF'] . '?action=edit_vat&id=' . $object->id . '">' . $langs->trans("UpdateVAT") . '</a></div>';
|
||||
}
|
||||
|
||||
if ($user->rights->produit->creer || $user->rights->service->creer) {
|
||||
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER['PHP_SELF'] . '?action=edit_price&id=' . $object->id . '">' . $langs->trans("UpdateDefaultPrice") . '</a></div>';
|
||||
}
|
||||
}
|
||||
if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES))
|
||||
{
|
||||
if ($user->rights->produit->creer || $user->rights->service->creer) {
|
||||
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?action=add_customer_price&id=' . $object->id . '">' . $langs->trans("AddCustomerPrice") . '</a></div>';
|
||||
}
|
||||
}
|
||||
|
||||
print "\n</div>\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 '<form action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '" method="POST">';
|
||||
print '<input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">';
|
||||
print '<input type="hidden" name="action" value="update_vat">';
|
||||
print '<input type="hidden" name="id" value="' . $object->id . '">';
|
||||
|
||||
dol_fiche_head('');
|
||||
|
||||
print '<table class="border" width="100%">';
|
||||
|
||||
// VAT
|
||||
print '<tr><td>' . $langs->trans("VATRate") . '</td><td>';
|
||||
print $form->load_tva("tva_tx", $object->tva_tx, $mysoc, '', $object->id, $object->tva_npr);
|
||||
print '</td></tr>';
|
||||
|
||||
print '</table>';
|
||||
|
||||
dol_fiche_end();
|
||||
|
||||
print '<div class="center">';
|
||||
print '<input type="submit" class="button" value="' . $langs->trans("Save") . '">';
|
||||
print ' ';
|
||||
print '<input type="submit" class="button" name="cancel" value="' . $langs->trans("Cancel") . '">';
|
||||
print '</div>';
|
||||
|
||||
print '<br></form><br>';
|
||||
}
|
||||
|
||||
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 '<br>';
|
||||
|
||||
print '<form action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '" method="POST">';
|
||||
print '<input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">';
|
||||
print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
|
||||
print '<input type="hidden" name="action" value="update_price">';
|
||||
print '<input type="hidden" name="id" value="' . $object->id . '">';
|
||||
if (empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL))
|
||||
{
|
||||
print '<input type="hidden" name="tva_tx_' . $i . '" value="' . $object->tva_tx . '">';
|
||||
}
|
||||
|
||||
dol_fiche_head('');
|
||||
|
||||
print '<table class="border" width="100%">';
|
||||
|
||||
// VAT
|
||||
if ($i == 1) {
|
||||
if (! empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL))
|
||||
{
|
||||
print '<tr><td>' . $langs->trans("VATRate") . '</td><td>';
|
||||
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 '</td></tr>';
|
||||
} else { // We always use the vat rate of price level 1 (A vat rate does not depends on customer)
|
||||
print '<input type="hidden" name="tva_tx_' . $i . '" value="' . $object->multiprices_tva_tx [1] . '">';
|
||||
}
|
||||
|
||||
|
||||
// Selling price
|
||||
print '<tr><td width="20%">';
|
||||
$text = $langs->trans('SellingPrice') . ' ' . $i;
|
||||
@ -839,10 +946,10 @@ if ($action == 'edit_price' && ($user->rights->produit->creer || $user->rights->
|
||||
|
||||
print '</table>';
|
||||
|
||||
dol_fiche_end();
|
||||
|
||||
print '</form>';
|
||||
}
|
||||
|
||||
dol_fiche_end();
|
||||
}
|
||||
}
|
||||
|
||||
@ -886,14 +993,14 @@ if ($result)
|
||||
print '<td>' . $langs->trans("AppliedPricesFrom") . '</td>';
|
||||
|
||||
if (! empty($conf->global->PRODUIT_MULTIPRICES)) {
|
||||
print '<td align="center">' . $langs->trans("MultiPriceLevelsName") . '</td>';
|
||||
print '<td align="center">' . $langs->trans("PriceLevel") . '</td>';
|
||||
}
|
||||
if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) {
|
||||
print '<td align="center">' . $langs->trans("Type") . '</td>';
|
||||
}
|
||||
|
||||
print '<td align="center">' . $langs->trans("PriceBase") . '</td>';
|
||||
print '<td align="right">' . $langs->trans("VAT") . '</td>';
|
||||
if (! empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL) || ! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) print '<td align="right">' . $langs->trans("VATRate") . '</td>';
|
||||
print '<td align="right">' . $langs->trans("HT") . '</td>';
|
||||
print '<td align="right">' . $langs->trans("TTC") . '</td>';
|
||||
if (! empty($conf->dynamicprices->enabled)) {
|
||||
@ -928,7 +1035,7 @@ if ($result)
|
||||
}
|
||||
|
||||
print '<td align="center">' . $langs->trans($objp->price_base_type) . "</td>";
|
||||
print '<td align="right">' . vatrate($objp->tva_tx, true, $objp->recuperableonly) . "</td>";
|
||||
if (! empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL) || ! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) print '<td align="right">' . vatrate($objp->tva_tx, true, $objp->recuperableonly) . "</td>";
|
||||
|
||||
//Price
|
||||
if (! empty($objp->fk_price_expression) && ! empty($conf->dynamicprices->enabled))
|
||||
@ -942,14 +1049,14 @@ if ($result)
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<td align="right">' . price($objp->price) . "</td>";
|
||||
print '<td align="right">' . price($objp->price_ttc) . "</td>";
|
||||
print '<td align="right">' . ($objp->price_base_type != 'TTC' ? price($objp->price) : ''). "</td>";
|
||||
print '<td align="right">' . ($objp->price_base_type == 'TTC' ? price($objp->price_ttc) : '') . "</td>";
|
||||
if (! empty($conf->dynamicprices->enabled)) { //Only if module is enabled
|
||||
print '<td align="right"></td>';
|
||||
}
|
||||
}
|
||||
print '<td align="right">' . price($objp->price_min) . '</td>';
|
||||
print '<td align="right">' . price($objp->price_min_ttc) . '</td>';
|
||||
print '<td align="right">' . ($objp->price_base_type != 'TTC' ? price($objp->price_min) : '') . '</td>';
|
||||
print '<td align="right">' . ($objp->price_base_type == 'TTC' ? price($objp->price_min_ttc) : '') . '</td>';
|
||||
|
||||
// User
|
||||
print '<td align="right"><a href="' . DOL_URL_ROOT . '/user/card.php?id=' . $objp->user_id . '">' . img_object($langs->trans("ShowUser"), 'user') . ' ' . $objp->login . '</a></td>';
|
||||
@ -1202,7 +1309,7 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES))
|
||||
print '<td>' . $langs->trans("ThirdParty") . '</td>';
|
||||
print '<td>' . $langs->trans("AppliedPricesFrom") . '</td>';
|
||||
print '<td align="center">' . $langs->trans("PriceBase") . '</td>';
|
||||
print '<td align="right">' . $langs->trans("VAT") . '</td>';
|
||||
print '<td align="right">' . $langs->trans("VATRate") . '</td>';
|
||||
print '<td align="right">' . $langs->trans("HT") . '</td>';
|
||||
print '<td align="right">' . $langs->trans("TTC") . '</td>';
|
||||
print '<td align="right">' . $langs->trans("MinPrice") . ' ' . $langs->trans("HT") . '</td>';
|
||||
@ -1275,7 +1382,7 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES))
|
||||
print '<td>' . $langs->trans("ThirdParty") . '</td>';
|
||||
print '<td>' . $langs->trans("AppliedPricesFrom") . '</td>';
|
||||
print '<td align="center">' . $langs->trans("PriceBase") . '</td>';
|
||||
print '<td align="right">' . $langs->trans("VAT") . '</td>';
|
||||
print '<td align="right">' . $langs->trans("VATRate") . '</td>';
|
||||
print '<td align="right">' . $langs->trans("HT") . '</td>';
|
||||
print '<td align="right">' . $langs->trans("TTC") . '</td>';
|
||||
print '<td align="right">' . $langs->trans("MinPrice") . ' ' . $langs->trans("HT") . '</td>';
|
||||
@ -1355,19 +1462,6 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES))
|
||||
print "</table>";
|
||||
|
||||
print "</form>";
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* Barre d'action */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
print "\n" . '<div class="tabsAction">' . "\n";
|
||||
|
||||
if ($user->rights->produit->creer || $user->rights->service->creer) {
|
||||
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?action=add_customer_price&id=' . $object->id . '">' . $langs->trans("AddCustomerPrice") . '</a></div>';
|
||||
}
|
||||
print "\n</div><br>\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user