FIX check tva_tx before comparing price_min_ttc (#25220)
* FIX check tva_tx before comparing price_min_ttc * better price_ttc comparison for propal, commande, facture lines * price_ht must be transformed into number before using it for calculating
This commit is contained in:
parent
c24e3bbe90
commit
a92458ebbc
5 changed files with 26 additions and 21 deletions
|
|
@ -1267,12 +1267,12 @@ if (empty($reshook)) {
|
|||
//var_dump(price2num($price_min_ttc)); var_dump(price2num($pu_ttc)); var_dump($remise_percent);exit;
|
||||
|
||||
if ($usermustrespectpricemin) {
|
||||
if ($pu_equivalent && $price_min && ((price2num($pu_equivalent) * (1 - $remise_percent / 100)) < price2num($price_min))) {
|
||||
if ($price_base_type == 'HT' && $pu_equivalent && $price_min && ((price2num($pu_equivalent) * (1 - $remise_percent / 100)) < price2num($price_min))) {
|
||||
$mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency));
|
||||
setEventMessages($mesg, null, 'errors');
|
||||
$error++;
|
||||
} elseif ($pu_equivalent_ttc && $price_min_ttc && ((price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) < price2num($price_min_ttc))) {
|
||||
$mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min_ttc, 'MU'), 0, $langs, 0, 0, -1, $conf->currency));
|
||||
} elseif ($price_base_type == 'TTC' && $pu_equivalent_ttc && $price_min_ttc && ((price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) < price2num($price_min_ttc))) {
|
||||
$mesg = $langs->trans("CantBeLessThanMinPriceInclTax", price(price2num($price_min_ttc, 'MU'), 0, $langs, 0, 0, -1, $conf->currency));
|
||||
setEventMessages($mesg, null, 'errors');
|
||||
$error++;
|
||||
}
|
||||
|
|
@ -1356,7 +1356,7 @@ if (empty($reshook)) {
|
|||
$localtax1_rate = get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
|
||||
$localtax2_rate = get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
|
||||
$pu_ht = price2num(GETPOST('price_ht'), '', 2);
|
||||
$pu_ttc = price2num(GETPOST('price_ttc'), '', 2);
|
||||
$pu_ttc = !empty(GETPOST('price_ttc', 'int')) ? price2num(GETPOST('price_ttc'), '', 2) : price2num(GETPOST('price_ht')) * (1 + $vat_rate);
|
||||
|
||||
// Add buying price
|
||||
$fournprice = price2num(GETPOST('fournprice') ? GETPOST('fournprice') : '');
|
||||
|
|
@ -1414,6 +1414,7 @@ if (empty($reshook)) {
|
|||
$label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : '');
|
||||
|
||||
$price_min = $product->price_min;
|
||||
$price_base_type = $product->price_base_type;
|
||||
if (!empty($conf->global->PRODUIT_MULTIPRICES) && !empty($object->thirdparty->price_level)) {
|
||||
$price_min = $product->multiprices_min[$object->thirdparty->price_level];
|
||||
}
|
||||
|
|
@ -1426,13 +1427,13 @@ if (empty($reshook)) {
|
|||
//var_dump(price2num($price_min_ttc)); var_dump(price2num($pu_ttc)); var_dump($remise_percent);exit;
|
||||
|
||||
if ($usermustrespectpricemin) {
|
||||
if ($pu_equivalent && $price_min && ((price2num($pu_equivalent) * (1 - $remise_percent / 100)) < price2num($price_min))) {
|
||||
if ($price_base_type == 'HT' && $pu_equivalent && $price_min && ((price2num($pu_equivalent) * (1 - $remise_percent / 100)) < price2num($price_min))) {
|
||||
$mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency));
|
||||
setEventMessages($mesg, null, 'errors');
|
||||
$error++;
|
||||
$action = 'editline';
|
||||
} elseif ($pu_equivalent_ttc && $price_min_ttc && ((price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) < price2num($price_min_ttc))) {
|
||||
$mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min_ttc, 'MU'), 0, $langs, 0, 0, -1, $conf->currency));
|
||||
} elseif ($price_base_type == 'TTC' && $pu_equivalent_ttc && $price_min_ttc && ((price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) < price2num($price_min_ttc))) {
|
||||
$mesg = $langs->trans("CantBeLessThanMinPriceInclTax", price(price2num($price_min_ttc, 'MU'), 0, $langs, 0, 0, -1, $conf->currency));
|
||||
setEventMessages($mesg, null, 'errors');
|
||||
$error++;
|
||||
$action = 'editline';
|
||||
|
|
|
|||
|
|
@ -1006,12 +1006,12 @@ if (empty($reshook)) {
|
|||
$desc = dol_htmlcleanlastbr($desc);
|
||||
|
||||
if ($usermustrespectpricemin) {
|
||||
if ($pu_equivalent && $price_min && ((price2num($pu_equivalent) * (1 - $remise_percent / 100)) < price2num($price_min))) {
|
||||
if ($price_base_type == 'HT' && $pu_equivalent && $price_min && ((price2num($pu_equivalent) * (1 - $remise_percent / 100)) < price2num($price_min))) {
|
||||
$mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency));
|
||||
setEventMessages($mesg, null, 'errors');
|
||||
$error++;
|
||||
} elseif ($pu_equivalent_ttc && $price_min_ttc && ((price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) < price2num($price_min_ttc))) {
|
||||
$mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min_ttc, 'MU'), 0, $langs, 0, 0, -1, $conf->currency));
|
||||
} elseif ($price_base_type == 'TTC' && $pu_equivalent_ttc && $price_min_ttc && ((price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) < price2num($price_min_ttc))) {
|
||||
$mesg = $langs->trans("CantBeLessThanMinPriceInclTax", price(price2num($price_min_ttc, 'MU'), 0, $langs, 0, 0, -1, $conf->currency));
|
||||
setEventMessages($mesg, null, 'errors');
|
||||
$error++;
|
||||
}
|
||||
|
|
@ -1089,7 +1089,7 @@ if (empty($reshook)) {
|
|||
$vat_rate = str_replace('*', '', $vat_rate);
|
||||
|
||||
$pu_ht = price2num(GETPOST('price_ht'), '', 2);
|
||||
$pu_ttc = price2num(GETPOST('price_ttc'), '', 2);
|
||||
$pu_ttc = !empty(GETPOST('price_ttc', 'int')) ? price2num(GETPOST('price_ttc'), '', 2) : price2num(GETPOST('price_ht')) * (1 + $vat_rate);
|
||||
|
||||
$pu_ht_devise = price2num(GETPOST('multicurrency_subprice'), '', 2);
|
||||
$pu_ttc_devise = price2num(GETPOST('multicurrency_subprice_ttc'), '', 2);
|
||||
|
|
@ -1152,6 +1152,7 @@ if (empty($reshook)) {
|
|||
$type = $product->type;
|
||||
|
||||
$price_min = $product->price_min;
|
||||
$price_base_type = $product->price_base_type;
|
||||
if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && !empty($object->thirdparty->price_level)) {
|
||||
$price_min = $product->multiprices_min[$object->thirdparty->price_level];
|
||||
}
|
||||
|
|
@ -1163,13 +1164,13 @@ if (empty($reshook)) {
|
|||
$label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : '');
|
||||
|
||||
if ($usermustrespectpricemin) {
|
||||
if ($pu_equivalent && $price_min && ((price2num($pu_equivalent) * (1 - $remise_percent / 100)) < price2num($price_min))) {
|
||||
if ($price_base_type == 'HT' && $pu_equivalent && $price_min && ((price2num($pu_equivalent) * (1 - $remise_percent / 100)) < price2num($price_min))) {
|
||||
$mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency));
|
||||
setEventMessages($mesg, null, 'errors');
|
||||
$error++;
|
||||
$action = 'editline';
|
||||
} elseif ($pu_equivalent_ttc && $price_min_ttc && ((price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) < price2num($price_min_ttc))) {
|
||||
$mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min_ttc, 'MU'), 0, $langs, 0, 0, -1, $conf->currency));
|
||||
} elseif ($price_base_type == 'TTC' && $pu_equivalent_ttc && $price_min_ttc && ((price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) < price2num($price_min_ttc))) {
|
||||
$mesg = $langs->trans("CantBeLessThanMinPriceInclTax", price(price2num($price_min_ttc, 'MU'), 0, $langs, 0, 0, -1, $conf->currency));
|
||||
setEventMessages($mesg, null, 'errors');
|
||||
$error++;
|
||||
$action = 'editline';
|
||||
|
|
|
|||
|
|
@ -2319,12 +2319,12 @@ if (empty($reshook)) {
|
|||
|
||||
// Check price is not lower than minimum (check is done only for standard or replacement invoices)
|
||||
if ($usermustrespectpricemin && ($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT)) {
|
||||
if ($pu_ht && $price_min && ((price2num($pu_ht) * (1 - $remise_percent / 100)) < price2num($price_min))) {
|
||||
if ($price_base_type == 'HT' && $pu_ht && $price_min && ((price2num($pu_ht) * (1 - $remise_percent / 100)) < price2num($price_min))) {
|
||||
$mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency));
|
||||
setEventMessages($mesg, null, 'errors');
|
||||
$error++;
|
||||
} elseif ($pu_ttc && $price_min_ttc && ((price2num($pu_ttc) * (1 - $remise_percent / 100)) < price2num($price_min_ttc))) {
|
||||
$mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min_ttc, 'MU'), 0, $langs, 0, 0, -1, $conf->currency));
|
||||
} elseif ($price_base_type == 'TTC' && $pu_ttc && $price_min_ttc && ((price2num($pu_ttc) * (1 - $remise_percent / 100)) < price2num($price_min_ttc))) {
|
||||
$mesg = $langs->trans("CantBeLessThanMinPriceInclTax", price(price2num($price_min_ttc, 'MU'), 0, $langs, 0, 0, -1, $conf->currency));
|
||||
setEventMessages($mesg, null, 'errors');
|
||||
$error++;
|
||||
}
|
||||
|
|
@ -2425,7 +2425,7 @@ if (empty($reshook)) {
|
|||
$vat_rate = str_replace('*', '', $vat_rate);
|
||||
|
||||
$pu_ht = price2num(GETPOST('price_ht'), '', 2);
|
||||
$pu_ttc = price2num(GETPOST('price_ttc'), '', 2);
|
||||
$pu_ttc = GETPOSTISSET('price_ttc') ? price2num(GETPOST('price_ttc', 'int'), '', 2) : price2num(GETPOST('price_ht')) * (1 + $vat_rate);
|
||||
|
||||
$pu_ht_devise = price2num(GETPOST('multicurrency_subprice'), '', 2);
|
||||
$pu_ttc_devise = price2num(GETPOST('multicurrency_subprice_ttc'), '', 2);
|
||||
|
|
@ -2500,6 +2500,7 @@ if (empty($reshook)) {
|
|||
$type = $product->type;
|
||||
|
||||
$price_min = $product->price_min;
|
||||
$price_base_type = $product->price_base_type;
|
||||
if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && !empty($object->thirdparty->price_level)) {
|
||||
$price_min = $product->multiprices_min[$object->thirdparty->price_level];
|
||||
}
|
||||
|
|
@ -2512,13 +2513,13 @@ if (empty($reshook)) {
|
|||
|
||||
// Check price is not lower than minimum (check is done only for standard or replacement invoices)
|
||||
if ($usermustrespectpricemin && ($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT)) {
|
||||
if ($pu_ht && $price_min && (((float) price2num($pu_ht) * (1 - (float) $remise_percent / 100)) < (float) price2num($price_min))) {
|
||||
if ($price_base_type == 'HT' && $pu_ht && $price_min && (((float) price2num($pu_ht) * (1 - (float) $remise_percent / 100)) < (float) price2num($price_min))) {
|
||||
$mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency));
|
||||
setEventMessages($mesg, null, 'errors');
|
||||
$error++;
|
||||
$action = 'editline';
|
||||
} elseif ($pu_ttc && $price_min_ttc && ((price2num($pu_ttc) * (1 - (float) $remise_percent / 100)) < price2num($price_min_ttc))) {
|
||||
$mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min_ttc, 'MU'), 0, $langs, 0, 0, -1, $conf->currency));
|
||||
} elseif ($price_base_type == 'TTC' && $pu_ttc && $price_min_ttc && ((price2num($pu_ttc) * (1 - (float) $remise_percent / 100)) < price2num($price_min_ttc))) {
|
||||
$mesg = $langs->trans("CantBeLessThanMinPriceInclTax", price(price2num($price_min_ttc, 'MU'), 0, $langs, 0, 0, -1, $conf->currency));
|
||||
setEventMessages($mesg, null, 'errors');
|
||||
$error++;
|
||||
$action = 'editline';
|
||||
|
|
|
|||
|
|
@ -82,6 +82,7 @@ NewPrice=New price
|
|||
MinPrice=Min. selling price
|
||||
EditSellingPriceLabel=Edit selling price label
|
||||
CantBeLessThanMinPrice=The selling price can't be lower than minimum allowed for this product (%s without tax). This message can also appears if you type a too important discount.
|
||||
CantBeLessThanMinPriceInclTax=The selling price can't be lower than minimum allowed for this product (%s including taxes). This message can also appears if you type a too important discount.
|
||||
ContractStatusClosed=Closed
|
||||
ErrorProductAlreadyExists=A product with reference %s already exists.
|
||||
ErrorProductBadRefOrLabel=Wrong value for reference or label.
|
||||
|
|
|
|||
|
|
@ -82,6 +82,7 @@ NewPrice=Nouveau prix
|
|||
MinPrice=Prix de vente min.
|
||||
EditSellingPriceLabel=Modifier le libellé du prix de vente
|
||||
CantBeLessThanMinPrice=Le prix de vente ne doit pas être inférieur au minimum pour ce produit (%s HT). Ce message peut aussi être provoqué par une remise trop importante.
|
||||
CantBeLessThanMinPriceInclTax=Le prix de vente ne doit pas être inférieur au minimum pour ce produit (%s TTC). Ce message peut aussi être provoqué par une remise trop importante.
|
||||
ContractStatusClosed=Clôturé
|
||||
ErrorProductAlreadyExists=Un produit avec la référence %s existe déjà.
|
||||
ErrorProductBadRefOrLabel=La valeur de la référence ou du libellé est incorrecte.
|
||||
|
|
|
|||
Loading…
Reference in a new issue