forked from Wavyzz/dolibarr
Fix regression. Restore old behaviour even if some case are not tested.
This commit is contained in:
@@ -1233,6 +1233,15 @@ if (empty($reshook)) {
|
||||
}
|
||||
}
|
||||
|
||||
$info_bits = 0;
|
||||
if ($tva_npr) {
|
||||
$info_bits |= 0x01;
|
||||
}
|
||||
|
||||
// Local Taxes
|
||||
$localtax1_tx = get_localtax($tva_tx, 1, $object->thirdparty, $tva_npr);
|
||||
$localtax2_tx = get_localtax($tva_tx, 2, $object->thirdparty, $tva_npr);
|
||||
|
||||
// Margin
|
||||
$fournprice = price2num(GETPOST('fournprice'.$predef) ? GETPOST('fournprice'.$predef) : '');
|
||||
$buyingprice = price2num(GETPOST('buying_price'.$predef) != '' ? GETPOST('buying_price'.$predef) : ''); // If buying_price is '0', we muste keep this value
|
||||
@@ -1245,7 +1254,7 @@ if (empty($reshook)) {
|
||||
$pu_equivalent_ttc = $pu_ttc;
|
||||
$currency_tx = $object->multicurrency_tx;
|
||||
|
||||
// Check if we have a foreing currency
|
||||
// Check if we have a foreign currency
|
||||
// If so, we update the pu_equiv as the equivalent price in base currency
|
||||
if ($pu_ht == '' && $pu_ht_devise != '' && $currency_tx != '') {
|
||||
$pu_equivalent = $pu_ht_devise * $currency_tx;
|
||||
@@ -1254,24 +1263,18 @@ if (empty($reshook)) {
|
||||
$pu_equivalent_ttc = $pu_ttc_devise * $currency_tx;
|
||||
}
|
||||
|
||||
// Local Taxes
|
||||
$localtax1_tx = get_localtax($tva_tx, 1, $object->thirdparty, $tva_npr);
|
||||
$localtax2_tx = get_localtax($tva_tx, 2, $object->thirdparty, $tva_npr);
|
||||
|
||||
$info_bits = 0;
|
||||
if ($tva_npr) {
|
||||
$info_bits |= 0x01;
|
||||
}
|
||||
// TODO $pu_equivalent or $pu_equivalent_ttc must be calculated from the one not null taking into account all taxes
|
||||
|
||||
//var_dump(price2num($price_min)); var_dump(price2num($pu_ht)); var_dump($remise_percent);
|
||||
//var_dump(price2num($price_min_ttc)); var_dump(price2num($pu_ttc)); var_dump($remise_percent);exit;
|
||||
|
||||
// Check price is not lower than minimum
|
||||
if ($usermustrespectpricemin) {
|
||||
if ($price_base_type == 'HT' && $pu_equivalent && $price_min && ((price2num($pu_equivalent) * (1 - $remise_percent / 100)) < price2num($price_min))) {
|
||||
if ($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 ($price_base_type == 'TTC' && $pu_equivalent_ttc && $price_min_ttc && ((price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) < price2num($price_min_ttc))) {
|
||||
} elseif ($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++;
|
||||
@@ -1341,22 +1344,23 @@ if (empty($reshook)) {
|
||||
}
|
||||
} elseif ($action == 'updateline' && $usercancreate && GETPOST('save')) {
|
||||
// Update a line within proposal
|
||||
|
||||
// Clean parameters
|
||||
$description = dol_htmlcleanlastbr(GETPOST('product_desc', 'restricthtml'));
|
||||
|
||||
// Define info_bits
|
||||
$info_bits = 0;
|
||||
if (preg_match('/\*/', GETPOST('tva_tx'))) {
|
||||
$info_bits |= 0x01;
|
||||
}
|
||||
|
||||
// Clean parameters
|
||||
$description = dol_htmlcleanlastbr(GETPOST('product_desc', 'restricthtml'));
|
||||
|
||||
// Define vat_rate
|
||||
$vat_rate = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0);
|
||||
$vat_rate = str_replace('*', '', $vat_rate);
|
||||
$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 = !empty(GETPOST('price_ttc', 'int')) ? price2num(GETPOST('price_ttc'), '', 2) : price2num(GETPOST('price_ht')) * (1 + $vat_rate);
|
||||
$pu_ttc = price2num(GETPOST('price_ttc'), '', 2);
|
||||
|
||||
// Add buying price
|
||||
$fournprice = price2num(GETPOST('fournprice') ? GETPOST('fournprice') : '');
|
||||
@@ -1376,9 +1380,10 @@ if (empty($reshook)) {
|
||||
// Prepare a price equivalent for minimum price check
|
||||
$pu_equivalent = $pu_ht;
|
||||
$pu_equivalent_ttc = $pu_ttc;
|
||||
|
||||
$currency_tx = $object->multicurrency_tx;
|
||||
|
||||
// Check if we have a foreing currency
|
||||
// Check if we have a foreign currency
|
||||
// If so, we update the pu_equiv as the equivalent price in base currency
|
||||
if ($pu_ht == '' && $pu_ht_devise != '' && $currency_tx != '') {
|
||||
$pu_equivalent = $pu_ht_devise * $currency_tx;
|
||||
@@ -1387,6 +1392,8 @@ if (empty($reshook)) {
|
||||
$pu_equivalent_ttc = $pu_ttc_devise * $currency_tx;
|
||||
}
|
||||
|
||||
// TODO $pu_equivalent or $pu_equivalent_ttc must be calculated from the one not null taking into account all taxes
|
||||
|
||||
// Extrafields
|
||||
$extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
|
||||
$array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
|
||||
@@ -1414,7 +1421,6 @@ 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 +1432,14 @@ if (empty($reshook)) {
|
||||
//var_dump(price2num($price_min)); var_dump(price2num($pu_ht)); var_dump($remise_percent);
|
||||
//var_dump(price2num($price_min_ttc)); var_dump(price2num($pu_ttc)); var_dump($remise_percent);exit;
|
||||
|
||||
// Check price is not lower than minimum
|
||||
if ($usermustrespectpricemin) {
|
||||
if ($price_base_type == 'HT' && $pu_equivalent && $price_min && ((price2num($pu_equivalent) * (1 - $remise_percent / 100)) < price2num($price_min))) {
|
||||
if ($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 ($price_base_type == 'TTC' && $pu_equivalent_ttc && $price_min_ttc && ((price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) < price2num($price_min_ttc))) {
|
||||
} elseif ($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++;
|
||||
|
||||
@@ -976,6 +976,15 @@ if (empty($reshook)) {
|
||||
}
|
||||
}
|
||||
|
||||
$info_bits = 0;
|
||||
if ($tva_npr) {
|
||||
$info_bits |= 0x01;
|
||||
}
|
||||
|
||||
// Local Taxes
|
||||
$localtax1_tx = get_localtax($tva_tx, 1, $object->thirdparty);
|
||||
$localtax2_tx = get_localtax($tva_tx, 2, $object->thirdparty);
|
||||
|
||||
// Margin
|
||||
$fournprice = price2num(GETPOST('fournprice'.$predef) ? GETPOST('fournprice'.$predef) : '');
|
||||
$buyingprice = price2num(GETPOST('buying_price'.$predef) != '' ? GETPOST('buying_price'.$predef) : ''); // If buying_price is '0', we muste keep this value
|
||||
@@ -983,9 +992,10 @@ if (empty($reshook)) {
|
||||
// Prepare a price equivalent for minimum price check
|
||||
$pu_equivalent = $pu_ht;
|
||||
$pu_equivalent_ttc = $pu_ttc;
|
||||
|
||||
$currency_tx = $object->multicurrency_tx;
|
||||
|
||||
// Check if we have a foreing currency
|
||||
// Check if we have a foreign currency
|
||||
// If so, we update the pu_equiv as the equivalent price in base currency
|
||||
if ($pu_ht == '' && $pu_ht_devise != '' && $currency_tx != '') {
|
||||
$pu_equivalent = $pu_ht_devise * $currency_tx;
|
||||
@@ -994,23 +1004,17 @@ if (empty($reshook)) {
|
||||
$pu_equivalent_ttc = $pu_ttc_devise * $currency_tx;
|
||||
}
|
||||
|
||||
// Local Taxes
|
||||
$localtax1_tx = get_localtax($tva_tx, 1, $object->thirdparty);
|
||||
$localtax2_tx = get_localtax($tva_tx, 2, $object->thirdparty);
|
||||
|
||||
$info_bits = 0;
|
||||
if ($tva_npr) {
|
||||
$info_bits |= 0x01;
|
||||
}
|
||||
// TODO $pu_equivalent or $pu_equivalent_ttc must be calculated from the one not null taking into account all taxes
|
||||
|
||||
$desc = dol_htmlcleanlastbr($desc);
|
||||
|
||||
// Check price is not lower than minimum
|
||||
if ($usermustrespectpricemin) {
|
||||
if ($price_base_type == 'HT' && $pu_equivalent && $price_min && ((price2num($pu_equivalent) * (1 - $remise_percent / 100)) < price2num($price_min))) {
|
||||
if ($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 ($price_base_type == 'TTC' && $pu_equivalent_ttc && $price_min_ttc && ((price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) < price2num($price_min_ttc))) {
|
||||
} elseif ($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++;
|
||||
@@ -1084,12 +1088,22 @@ if (empty($reshook)) {
|
||||
$date_end = '';
|
||||
$date_start = dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), GETPOST('date_startsec'), GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear'));
|
||||
$date_end = dol_mktime(GETPOST('date_endhour'), GETPOST('date_endmin'), GETPOST('date_endsec'), GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear'));
|
||||
|
||||
$description = dol_htmlcleanlastbr(GETPOST('product_desc', 'restricthtml'));
|
||||
|
||||
// Define info_bits
|
||||
$info_bits = 0;
|
||||
if (preg_match('/\*/', $vat_rate)) {
|
||||
$info_bits |= 0x01;
|
||||
}
|
||||
|
||||
// Define vat_rate
|
||||
$vat_rate = (GETPOST('tva_tx') ? GETPOST('tva_tx', 'alpha') : 0);
|
||||
$vat_rate = str_replace('*', '', $vat_rate);
|
||||
|
||||
$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 = !empty(GETPOST('price_ttc', 'int')) ? price2num(GETPOST('price_ttc'), '', 2) : price2num(GETPOST('price_ht')) * (1 + $vat_rate);
|
||||
$pu_ttc = price2num(GETPOST('price_ttc'), '', 2);
|
||||
|
||||
$pu_ht_devise = price2num(GETPOST('multicurrency_subprice'), '', 2);
|
||||
$pu_ttc_devise = price2num(GETPOST('multicurrency_subprice_ttc'), '', 2);
|
||||
@@ -1099,9 +1113,10 @@ if (empty($reshook)) {
|
||||
// Prepare a price equivalent for minimum price check
|
||||
$pu_equivalent = $pu_ht;
|
||||
$pu_equivalent_ttc = $pu_ttc;
|
||||
|
||||
$currency_tx = $object->multicurrency_tx;
|
||||
|
||||
// Check if we have a foreing currency
|
||||
// Check if we have a foreign currency
|
||||
// If so, we update the pu_equiv as the equivalent price in base currency
|
||||
if ($pu_ht == '' && $pu_ht_devise != '' && $currency_tx != '') {
|
||||
$pu_equivalent = $pu_ht_devise * $currency_tx;
|
||||
@@ -1110,16 +1125,7 @@ if (empty($reshook)) {
|
||||
$pu_equivalent_ttc = $pu_ttc_devise * $currency_tx;
|
||||
}
|
||||
|
||||
// Define info_bits
|
||||
$info_bits = 0;
|
||||
if (preg_match('/\*/', $vat_rate)) {
|
||||
$info_bits |= 0x01;
|
||||
}
|
||||
|
||||
// Define vat_rate
|
||||
$vat_rate = str_replace('*', '', $vat_rate);
|
||||
$localtax1_rate = get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
|
||||
$localtax2_rate = get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
|
||||
// TODO $pu_equivalent or $pu_equivalent_ttc must be calculated from the one not null taking into account all taxes
|
||||
|
||||
// Add buying price
|
||||
$fournprice = price2num(GETPOST('fournprice') ? GETPOST('fournprice') : '');
|
||||
@@ -1152,7 +1158,6 @@ 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 +1168,14 @@ if (empty($reshook)) {
|
||||
|
||||
$label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : '');
|
||||
|
||||
// Check price is not lower than minimum
|
||||
if ($usermustrespectpricemin) {
|
||||
if ($price_base_type == 'HT' && $pu_equivalent && $price_min && ((price2num($pu_equivalent) * (1 - $remise_percent / 100)) < price2num($price_min))) {
|
||||
if ($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 ($price_base_type == 'TTC' && $pu_equivalent_ttc && $price_min_ttc && ((price2num($pu_equivalent_ttc) * (1 - $remise_percent / 100)) < price2num($price_min_ttc))) {
|
||||
} elseif ($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++;
|
||||
|
||||
@@ -2171,6 +2171,7 @@ if (empty($reshook)) {
|
||||
$tmpprodvat = price2num(preg_replace('/\s*\(.*\)/', '', $prod->tva_tx));
|
||||
|
||||
// Set unit price to use
|
||||
// TODO We should not have this
|
||||
if (!empty($price_ht) || $price_ht === '0') {
|
||||
$pu_ht = price2num($price_ht, 'MU');
|
||||
$pu_ttc = price2num($pu_ht * (1 + ($tmpvat / 100)), 'MU');
|
||||
@@ -2277,28 +2278,45 @@ if (empty($reshook)) {
|
||||
$type = GETPOST('type');
|
||||
$fk_unit = GETPOST('units', 'alpha');
|
||||
|
||||
$pu_ht_devise = price2num($price_ht_devise, 'MU');
|
||||
$pu_ttc_devise = price2num($price_ttc_devise, 'MU');
|
||||
|
||||
if ($pu_ttc && !$pu_ht) {
|
||||
$price_base_type = 'TTC';
|
||||
}
|
||||
}
|
||||
|
||||
$pu_ht_devise = price2num($price_ht_devise, 'MU');
|
||||
|
||||
// Margin
|
||||
$fournprice = price2num(GETPOST('fournprice'.$predef) ? GETPOST('fournprice'.$predef) : '');
|
||||
$buyingprice = price2num(GETPOST('buying_price'.$predef) != '' ? GETPOST('buying_price'.$predef) : ''); // If buying_price is '0', we must keep this value
|
||||
// Define info_bits
|
||||
$info_bits = 0;
|
||||
if ($tva_npr) {
|
||||
$info_bits |= 0x01;
|
||||
}
|
||||
|
||||
// Local Taxes
|
||||
$localtax1_tx = get_localtax($tva_tx, 1, $object->thirdparty, $mysoc, $tva_npr);
|
||||
$localtax2_tx = get_localtax($tva_tx, 2, $object->thirdparty, $mysoc, $tva_npr);
|
||||
|
||||
$info_bits = 0;
|
||||
if ($tva_npr) {
|
||||
$info_bits |= 0x01;
|
||||
$pu_ht_devise = price2num(GETPOST('multicurrency_subprice'), '', 2);
|
||||
$pu_ttc_devise = price2num(GETPOST('multicurrency_subprice_ttc'), '', 2);
|
||||
|
||||
// Prepare a price equivalent for minimum price check
|
||||
$pu_equivalent = $pu_ht;
|
||||
$pu_equivalent_ttc = $pu_ttc;
|
||||
|
||||
$currency_tx = $object->multicurrency_tx;
|
||||
|
||||
// Check if we have a foreign currency
|
||||
// If so, we update the pu_equiv as the equivalent price in base currency
|
||||
if ($pu_ht == '' && $pu_ht_devise != '' && $currency_tx != '') {
|
||||
$pu_equivalent = $pu_ht_devise * $currency_tx;
|
||||
}
|
||||
if ($pu_ttc == '' && $pu_ttc_devise != '' && $currency_tx != '') {
|
||||
$pu_equivalent_ttc = $pu_ttc_devise * $currency_tx;
|
||||
}
|
||||
|
||||
// TODO $pu_equivalent or $pu_equivalent_ttc must be calculated from the one not null taking into account all taxes
|
||||
|
||||
// Margin
|
||||
$fournprice = price2num(GETPOST('fournprice'.$predef) ? GETPOST('fournprice'.$predef) : '');
|
||||
$buyingprice = price2num(GETPOST('buying_price'.$predef) != '' ? GETPOST('buying_price'.$predef) : ''); // If buying_price is '0', we must keep this value
|
||||
|
||||
|
||||
$price2num_pu_ht = price2num($pu_ht);
|
||||
$price2num_remise_percent = price2num($remise_percent);
|
||||
@@ -2319,11 +2337,11 @@ 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 ($price_base_type == 'HT' && $pu_ht && $price_min && ((price2num($pu_ht) * (1 - $remise_percent / 100)) < price2num($price_min))) {
|
||||
if ($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 ($price_base_type == 'TTC' && $pu_ttc && $price_min_ttc && ((price2num($pu_ttc) * (1 - $remise_percent / 100)) < price2num($price_min_ttc))) {
|
||||
} elseif ($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++;
|
||||
@@ -2425,7 +2443,7 @@ if (empty($reshook)) {
|
||||
$vat_rate = str_replace('*', '', $vat_rate);
|
||||
|
||||
$pu_ht = price2num(GETPOST('price_ht'), '', 2);
|
||||
$pu_ttc = GETPOSTISSET('price_ttc') ? price2num(GETPOST('price_ttc', 'int'), '', 2) : price2num(GETPOST('price_ht')) * (1 + $vat_rate);
|
||||
$pu_ttc = price2num(GETPOST('price_ttc'), '', 2);
|
||||
|
||||
$pu_ht_devise = price2num(GETPOST('multicurrency_subprice'), '', 2);
|
||||
$pu_ttc_devise = price2num(GETPOST('multicurrency_subprice_ttc'), '', 2);
|
||||
@@ -2447,6 +2465,23 @@ if (empty($reshook)) {
|
||||
$fournprice = price2num(GETPOST('fournprice') ? GETPOST('fournprice') : '');
|
||||
$buyingprice = price2num(GETPOST('buying_price') != '' ? GETPOST('buying_price') : ''); // If buying_price is '0', we muste keep this value
|
||||
|
||||
// Prepare a price equivalent for minimum price check
|
||||
$pu_equivalent = $pu_ht;
|
||||
$pu_equivalent_ttc = $pu_ttc;
|
||||
|
||||
$currency_tx = $object->multicurrency_tx;
|
||||
|
||||
// Check if we have a foreign currency
|
||||
// If so, we update the pu_equiv as the equivalent price in base currency
|
||||
if ($pu_ht == '' && $pu_ht_devise != '' && $currency_tx != '') {
|
||||
$pu_equivalent = $pu_ht_devise * $currency_tx;
|
||||
}
|
||||
if ($pu_ttc == '' && $pu_ttc_devise != '' && $currency_tx != '') {
|
||||
$pu_equivalent_ttc = $pu_ttc_devise * $currency_tx;
|
||||
}
|
||||
|
||||
// TODO $pu_equivalent or $pu_equivalent_ttc must be calculated from the one not null taking into account all taxes
|
||||
|
||||
// Extrafields
|
||||
$extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
|
||||
$array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
|
||||
@@ -2500,7 +2535,6 @@ 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];
|
||||
}
|
||||
@@ -2513,12 +2547,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 ($price_base_type == 'HT' && $pu_ht && $price_min && (((float) price2num($pu_ht) * (1 - (float) $remise_percent / 100)) < (float) price2num($price_min))) {
|
||||
if ($pu_equivalent && $price_min && (((float) price2num($pu_equivalent) * (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 ($price_base_type == 'TTC' && $pu_ttc && $price_min_ttc && ((price2num($pu_ttc) * (1 - (float) $remise_percent / 100)) < price2num($price_min_ttc))) {
|
||||
} elseif ($pu_equivalent_ttc && $price_min_ttc && ((price2num($pu_equivalent_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++;
|
||||
|
||||
Reference in New Issue
Block a user