|
@@ -981,6 +981,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
|
|
@@ -988,9 +997,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;
|
|
@@ -999,24 +1009,27 @@ 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 defined
|
|
|
+ /*
|
|
|
+ if ($pu_equivalent) {
|
|
|
+ $tmp = calcul_price_total(1, $pu_equivalent, 0, $tva_tx, -1, -1, 0, 'HT', $info_bits, $type);
|
|
|
+ $pu_equivalent_ttc = ...
|
|
|
+ } else {
|
|
|
+ $tmp = calcul_price_total(1, $pu_equivalent_ttc, 0, $tva_tx, -1, -1, 0, 'TTC', $info_bits, $type);
|
|
|
+ $pu_equivalent_ht = ...
|
|
|
}
|
|
|
+ */
|
|
|
|
|
|
$desc = dol_htmlcleanlastbr($desc);
|
|
|
|
|
|
+ // Check price is not lower than minimum
|
|
|
if ($usermustrespectpricemin) {
|
|
|
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 ($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));
|
|
|
+ $mesg = $langs->trans("CantBeLessThanMinPriceInclTax", price(price2num($price_min_ttc, 'MU'), 0, $langs, 0, 0, -1, $conf->currency));
|
|
|
setEventMessages($mesg, null, 'errors');
|
|
|
$error++;
|
|
|
}
|
|
@@ -1089,10 +1102,20 @@ 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('/\*/', GETPOST('tva_tx'))) {
|
|
|
+ $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 = price2num(GETPOST('price_ttc'), '', 2);
|
|
|
|
|
@@ -1104,9 +1127,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;
|
|
@@ -1115,16 +1139,16 @@ 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
|
|
|
+ /*
|
|
|
+ if ($pu_equivalent) {
|
|
|
+ $tmp = calcul_price_total(1, $pu_equivalent, 0, $vat_rate, -1, -1, 0, 'HT', $info_bits, $type);
|
|
|
+ $pu_equivalent_ttc = ...
|
|
|
+ } else {
|
|
|
+ $tmp = calcul_price_total(1, $pu_equivalent_ttc, 0, $vat_rate, -1, -1, 0, 'TTC', $info_bits, $type);
|
|
|
+ $pu_equivalent_ht = ...
|
|
|
+ }
|
|
|
+ */
|
|
|
|
|
|
// Add buying price
|
|
|
$fournprice = price2num(GETPOST('fournprice') ? GETPOST('fournprice') : '');
|
|
@@ -1167,6 +1191,7 @@ if (empty($reshook)) {
|
|
|
|
|
|
$label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : '');
|
|
|
|
|
|
+ // Check price is not lower than minimum
|
|
|
if ($usermustrespectpricemin) {
|
|
|
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));
|
|
@@ -1174,7 +1199,7 @@ if (empty($reshook)) {
|
|
|
$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));
|
|
|
+ $mesg = $langs->trans("CantBeLessThanMinPriceInclTax", price(price2num($price_min_ttc, 'MU'), 0, $langs, 0, 0, -1, $conf->currency));
|
|
|
setEventMessages($mesg, null, 'errors');
|
|
|
$error++;
|
|
|
$action = 'editline';
|