mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
NEW Can enter price with tax for predefined products on purchase objects
This commit is contained in:
parent
e8a9a7b732
commit
bc938d86ba
|
|
@ -1034,18 +1034,18 @@ if (!empty($usemargins) && $user->rights->margins->creer) {
|
|||
jQuery("#multicurrency_price_ht").val('').show();
|
||||
jQuery("#title_up_ht, #title_up_ht_currency").show();
|
||||
<?php } else { ?>
|
||||
jQuery("#price_ht").val('').hide();
|
||||
//jQuery("#price_ht").val('').hide();
|
||||
jQuery("#multicurrency_price_ht").val('').hide();
|
||||
jQuery("#title_up_ht, #title_up_ht_currency").hide();
|
||||
<?php } ?>
|
||||
<?php if (empty($conf->global->MAIN_ENABLE_EDIT_PREDEF_PRICETTC)) { ?>
|
||||
jQuery("#price_ttc").val('').hide();
|
||||
jQuery("#multicurrency_price_ttc").val('').hide();
|
||||
jQuery("#title_up_ttc, #title_up_ttc_currency").hide();
|
||||
<?php } else { /* this option work great with supplier invoices */ ?>
|
||||
<?php if (empty($conf->global->MAIN_DISABLE_EDIT_PREDEF_PRICETTC)) { ?>
|
||||
jQuery("#price_ttc").val('').show();
|
||||
jQuery("#multicurrency_price_ttc").val('').show();
|
||||
jQuery("#title_up_ttc, #title_up_ttc_currency").show();
|
||||
<?php } else { ?>
|
||||
jQuery("#price_ttc").val('').hide();
|
||||
jQuery("#multicurrency_price_ttc").val('').hide();
|
||||
jQuery("#title_up_ttc, #title_up_ttc_currency").hide();
|
||||
<?php } ?>
|
||||
jQuery("#fourn_ref, #tva_tx, #title_vat").hide();
|
||||
/* jQuery("#title_fourn_ref").hide(); */
|
||||
|
|
|
|||
|
|
@ -1718,7 +1718,7 @@ class CommandeFournisseur extends CommonOrder
|
|||
* Add order line
|
||||
*
|
||||
* @param string $desc Description
|
||||
* @param float $pu_ht Unit price
|
||||
* @param float $pu_ht Unit price (used if $price_base_type is 'HT')
|
||||
* @param float $qty Quantity
|
||||
* @param float $txtva Taux tva
|
||||
* @param float $txlocaltax1 Localtax1 tax
|
||||
|
|
@ -1728,7 +1728,7 @@ class CommandeFournisseur extends CommonOrder
|
|||
* @param string $ref_supplier Supplier reference price
|
||||
* @param float $remise_percent Remise
|
||||
* @param string $price_base_type HT or TTC
|
||||
* @param float $pu_ttc Unit price TTC
|
||||
* @param float $pu_ttc Unit price TTC (used if $price_base_type is 'TTC')
|
||||
* @param int $type Type of line (0=product, 1=service)
|
||||
* @param int $info_bits More information
|
||||
* @param bool $notrigger Disable triggers
|
||||
|
|
|
|||
|
|
@ -412,10 +412,9 @@ if (empty($reshook)) {
|
|||
// Set if we used free entry or predefined product
|
||||
$predef = '';
|
||||
$product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : '');
|
||||
$price_ht = price2num(GETPOST('price_ht'), 'MU', 2);
|
||||
$price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CU', 2);
|
||||
$date_start = dol_mktime(GETPOST('date_start'.$predef.'hour'), GETPOST('date_start'.$predef.'min'), GETPOST('date_start'.$predef.'sec'), GETPOST('date_start'.$predef.'month'), GETPOST('date_start'.$predef.'day'), GETPOST('date_start'.$predef.'year'));
|
||||
$date_end = dol_mktime(GETPOST('date_end'.$predef.'hour'), GETPOST('date_end'.$predef.'min'), GETPOST('date_end'.$predef.'sec'), GETPOST('date_end'.$predef.'month'), GETPOST('date_end'.$predef.'day'), GETPOST('date_end'.$predef.'year'));
|
||||
|
||||
$prod_entry_mode = GETPOST('prod_entry_mode');
|
||||
if ($prod_entry_mode == 'free') {
|
||||
$idprod = 0;
|
||||
|
|
@ -425,6 +424,8 @@ if (empty($reshook)) {
|
|||
|
||||
$tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0); // Can be '1.2' or '1.2 (CODE)'
|
||||
|
||||
$price_ht = price2num(GETPOST('price_ht'), 'MU', 2);
|
||||
$price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CU', 2);
|
||||
$price_ttc = price2num(GETPOST('price_ttc'), 'MU', 2);
|
||||
$price_ttc_devise = price2num(GETPOST('multicurrency_price_ttc'), 'CU', 2);
|
||||
$qty = price2num(GETPOST('qty'.$predef, 'alpha'), 'MS');
|
||||
|
|
@ -461,7 +462,7 @@ if (empty($reshook)) {
|
|||
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Description')), null, 'errors');
|
||||
$error++;
|
||||
}
|
||||
if (GETPOST('qty', 'int') == '') {
|
||||
if (GETPOST('qty', 'alpha') == '') { // 0 is allowed for order
|
||||
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), null, 'errors');
|
||||
$error++;
|
||||
}
|
||||
|
|
@ -506,13 +507,14 @@ if (empty($reshook)) {
|
|||
}
|
||||
} elseif (GETPOST('idprodfournprice', 'alpha') > 0) {
|
||||
$qtytosearch = $qty; // Just to see if a price exists for the quantity. Not used to found vat.
|
||||
//$qtytosearch=-1; // We force qty to -1 to be sure to find if a supplier price exist
|
||||
//$qtytosearch = -1; // We force qty to -1 to be sure to find if a supplier price exist
|
||||
$idprod = $productsupplier->get_buyprice(GETPOST('idprodfournprice', 'alpha'), $qtytosearch);
|
||||
$res = $productsupplier->fetch($idprod);
|
||||
}
|
||||
|
||||
if ($idprod > 0) {
|
||||
$label = $productsupplier->label;
|
||||
|
||||
// Define output language
|
||||
if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
|
||||
$outputlangs = $langs;
|
||||
|
|
@ -550,41 +552,44 @@ if (empty($reshook)) {
|
|||
|
||||
$ref_supplier = $productsupplier->ref_supplier;
|
||||
|
||||
$type = $productsupplier->type;
|
||||
if (GETPOST('price_ht') != '' || GETPOST('price_ht_devise') != '') {
|
||||
$price_base_type = 'HT';
|
||||
$pu = price2num($price_ht, 'MU');
|
||||
$pu_ht_devise = price2num($price_ht_devise, 'CU');
|
||||
} elseif (GETPOST('price_ttc') != '' || GETPOST('price_ttc_devise') != '') {
|
||||
$price_base_type = 'TTC';
|
||||
$pu = price2num($price_ttc, 'MU');
|
||||
$pu_ht_devise = price2num($price_ttc_devise, 'CU');
|
||||
} else {
|
||||
$price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type : 'HT');
|
||||
if (empty($object->multicurrency_code) || ($productsupplier->fourn_multicurrency_code != $object->multicurrency_code)) { // If object is in a different currency and price not in this currency
|
||||
$pu = $productsupplier->fourn_pu;
|
||||
$pu_ht_devise = 0;
|
||||
} else {
|
||||
$pu = $productsupplier->fourn_pu;
|
||||
$pu_ht_devise = $productsupplier->fourn_multicurrency_unitprice;
|
||||
}
|
||||
// Get vat rate
|
||||
if (!GETPOSTISSET('tva_tx')) { // If vat rate not provided from the form (the form has the priority)
|
||||
$tva_tx = get_default_tva($object->thirdparty, $mysoc, $productsupplier->id, GETPOST('idprodfournprice', 'alpha'));
|
||||
$tva_npr = get_default_npr($object->thirdparty, $mysoc, $productsupplier->id, GETPOST('idprodfournprice', 'alpha'));
|
||||
}
|
||||
|
||||
$tva_tx = get_default_tva($object->thirdparty, $mysoc, $productsupplier->id, GETPOST('idprodfournprice', 'alpha'));
|
||||
$tva_npr = get_default_npr($object->thirdparty, $mysoc, $productsupplier->id, GETPOST('idprodfournprice', 'alpha'));
|
||||
if (empty($tva_tx)) {
|
||||
$tva_npr = 0;
|
||||
}
|
||||
$localtax1_tx = get_localtax($tva_tx, 1, $mysoc, $object->thirdparty, $tva_npr);
|
||||
$localtax2_tx = get_localtax($tva_tx, 2, $mysoc, $object->thirdparty, $tva_npr);
|
||||
|
||||
$type = $productsupplier->type;
|
||||
if (GETPOST('price_ht') != '' || GETPOST('price_ht_devise') != '') {
|
||||
$price_base_type = 'HT';
|
||||
$pu = price2num($price_ht, 'MU');
|
||||
$pu_devise = price2num($price_ht_devise, 'CU');
|
||||
} elseif (GETPOST('price_ttc') != '' || GETPOST('price_ttc_devise') != '') {
|
||||
$price_base_type = 'TTC';
|
||||
$pu = price2num($price_ttc, 'MU');
|
||||
$pu_devise = price2num($price_ttc_devise, 'CU');
|
||||
} else {
|
||||
$price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type : 'HT');
|
||||
if (empty($object->multicurrency_code) || ($productsupplier->fourn_multicurrency_code != $object->multicurrency_code)) { // If object is in a different currency and price not in this currency
|
||||
$pu = $productsupplier->fourn_pu;
|
||||
$pu_devise = 0;
|
||||
} else {
|
||||
$pu = $productsupplier->fourn_pu;
|
||||
$pu_devise = $productsupplier->fourn_multicurrency_unitprice;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($pu)) {
|
||||
$pu = 0; // If pu is '' or null, we force to have a numeric value
|
||||
}
|
||||
|
||||
$result = $object->addline(
|
||||
$desc,
|
||||
$pu,
|
||||
($price_base_type == 'HT' ? $pu : 0),
|
||||
$qty,
|
||||
$tva_tx,
|
||||
$localtax1_tx,
|
||||
|
|
@ -594,7 +599,7 @@ if (empty($reshook)) {
|
|||
$ref_supplier,
|
||||
$remise_percent,
|
||||
$price_base_type,
|
||||
$pu_ttc,
|
||||
($price_base_type == 'TTC' ? $pu : 0),
|
||||
$type,
|
||||
$tva_npr,
|
||||
'',
|
||||
|
|
@ -602,7 +607,7 @@ if (empty($reshook)) {
|
|||
$date_end,
|
||||
$array_options,
|
||||
$productsupplier->fk_unit,
|
||||
$pu_ht_devise,
|
||||
$pu_devise,
|
||||
'',
|
||||
0
|
||||
);
|
||||
|
|
@ -645,7 +650,7 @@ if (empty($reshook)) {
|
|||
}
|
||||
$price_base_type = 'HT';
|
||||
$pu_ht_devise = price2num($price_ht_devise, 'CU');
|
||||
// var_dump($pu_ht.' '.$tva_tx.' '.$pu_ttc.' '.$price_base_type.' '.$pu_ht_devise); exit;
|
||||
|
||||
$result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, $ref_supplier, $remise_percent, $price_base_type, $pu_ttc, $type, '', '', $date_start, $date_end, $array_options, $fk_unit, $pu_ht_devise);
|
||||
}
|
||||
|
||||
|
|
@ -759,6 +764,7 @@ if (empty($reshook)) {
|
|||
$price_base_type = 'HT';
|
||||
$ht = price2num(GETPOST('price_ht'), '', 2);
|
||||
} else {
|
||||
$reg = array();
|
||||
$vatratecleaned = $vat_rate;
|
||||
if (preg_match('/^(.*)\s*\((.*)\)$/', $vat_rate, $reg)) { // If vat is "xx (yy)"
|
||||
$vatratecleaned = trim($reg[1]);
|
||||
|
|
@ -770,7 +776,7 @@ if (empty($reshook)) {
|
|||
$price_base_type = 'HT';
|
||||
}
|
||||
|
||||
$pu_ht_devise = price2num(GETPOST('multicurrency_subprice'), '', 2);
|
||||
$pu_ht_devise = price2num(GETPOST('multicurrency_subprice'), 'CU', 2);
|
||||
|
||||
// Extrafields Lines
|
||||
$extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
|
||||
|
|
|
|||
|
|
@ -1447,7 +1447,7 @@ if (empty($reshook)) {
|
|||
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Description')), null, 'errors');
|
||||
$error++;
|
||||
}
|
||||
if (!GETPOST('qty')) {
|
||||
if (!GETPOST('qty', 'alpha')) { // 0 is NOT allowed for invoices
|
||||
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), null, 'errors');
|
||||
$error++;
|
||||
}
|
||||
|
|
@ -1499,12 +1499,27 @@ if (empty($reshook)) {
|
|||
|
||||
if ($idprod > 0) {
|
||||
$label = $productsupplier->label;
|
||||
|
||||
// Define output language
|
||||
if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
|
||||
$outputlangs = $langs;
|
||||
$newlang = '';
|
||||
if (empty($newlang) && GETPOST('lang_id', 'aZ09')) {
|
||||
$newlang = GETPOST('lang_id', 'aZ09');
|
||||
}
|
||||
if (empty($newlang)) {
|
||||
$newlang = $object->thirdparty->default_lang;
|
||||
}
|
||||
if (!empty($newlang)) {
|
||||
$outputlangs = new Translate("", $conf);
|
||||
$outputlangs->setDefaultLang($newlang);
|
||||
}
|
||||
$desc = (!empty($productsupplier->multilangs[$outputlangs->defaultlang]["description"])) ? $productsupplier->multilangs[$outputlangs->defaultlang]["description"] : $productsupplier->description;
|
||||
} else {
|
||||
$desc = $productsupplier->description;
|
||||
}
|
||||
// if we use supplier description of the products
|
||||
if (!empty($productsupplier->desc_supplier) && !empty($conf->global->PRODUIT_FOURN_TEXTS)) {
|
||||
$desc = $productsupplier->desc_supplier;
|
||||
} else {
|
||||
$desc = $productsupplier->description;
|
||||
}
|
||||
|
||||
//If text set in desc is the same as product descpription (as now it's preloaded) whe add it only one time
|
||||
|
|
@ -3555,7 +3570,7 @@ if ($action == 'create') {
|
|||
}
|
||||
|
||||
print '<div class="div-table-responsive-no-min">';
|
||||
print '<table id="tablelines" class="noborder noshadow" width="100%">';
|
||||
print '<table id="tablelines" class="noborder noshadow centpercent">';
|
||||
|
||||
global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax;
|
||||
$forceall = 1; $dateSelector = 0; $inputalsopricewithtax = 1;
|
||||
|
|
|
|||
|
|
@ -541,21 +541,28 @@ if (empty($reshook)) {
|
|||
$product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : '');
|
||||
$date_start = dol_mktime(GETPOST('date_start'.$predef.'hour'), GETPOST('date_start'.$predef.'min'), GETPOST('date_start'.$predef.'sec'), GETPOST('date_start'.$predef.'month'), GETPOST('date_start'.$predef.'day'), GETPOST('date_start'.$predef.'year'));
|
||||
$date_end = dol_mktime(GETPOST('date_end'.$predef.'hour'), GETPOST('date_end'.$predef.'min'), GETPOST('date_end'.$predef.'sec'), GETPOST('date_end'.$predef.'month'), GETPOST('date_end'.$predef.'day'), GETPOST('date_end'.$predef.'year'));
|
||||
|
||||
$ref_supplier = GETPOST('fourn_ref', 'alpha');
|
||||
|
||||
$prod_entry_mode = GETPOST('prod_entry_mode');
|
||||
if ($prod_entry_mode == 'free') {
|
||||
$idprod = 0;
|
||||
$price_ht = price2num(GETPOST('price_ht'), 'MU', 2);
|
||||
$tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0);
|
||||
} else {
|
||||
$idprod = GETPOST('idprod', 'int');
|
||||
$price_ht = price2num(GETPOST('price_ht'), 'MU', 2);
|
||||
$tva_tx = '';
|
||||
}
|
||||
|
||||
$qty = price2num(GETPOST('qty'.$predef, 'alpha'), 'MS');
|
||||
$remise_percent = price2num(GETPOST('remise_percent'.$predef), 2);
|
||||
$tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0); // Can be '1.2' or '1.2 (CODE)'
|
||||
|
||||
$price_ht = price2num(GETPOST('price_ht'), 'MU', 2);
|
||||
$price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CU', 2);
|
||||
$price_ttc = price2num(GETPOST('price_ttc'), 'MU', 2);
|
||||
$price_ttc_devise = price2num(GETPOST('multicurrency_price_ttc'), 'CU', 2);
|
||||
$qty = price2num(GETPOST('qty'.$predef, 'alpha'), 'MS');
|
||||
|
||||
$remise_percent = (GETPOSTISSET('remise_percent'.$predef) ? price2num(GETPOST('remise_percent'.$predef, 'alpha'), '', 2) : 0);
|
||||
if (empty($remise_percent)) {
|
||||
$remise_percent = 0;
|
||||
}
|
||||
|
||||
// Extrafields
|
||||
$extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
|
||||
|
|
@ -568,6 +575,10 @@ if (empty($reshook)) {
|
|||
}
|
||||
}
|
||||
|
||||
if ($prod_entry_mode == 'free' && GETPOST('price_ht') < 0 && $qty < 0) {
|
||||
setEventMessages($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPrice'), $langs->transnoentitiesnoconv('Qty')), null, 'errors');
|
||||
$error++;
|
||||
}
|
||||
if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && GETPOST('type') < 0) {
|
||||
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
|
||||
$error++;
|
||||
|
|
@ -589,10 +600,7 @@ if (empty($reshook)) {
|
|||
|
||||
$db->begin();
|
||||
|
||||
// Ecrase $pu par celui du produit
|
||||
// Ecrase $desc par celui du produit
|
||||
// Ecrase $txtva par celui du produit
|
||||
if (($prod_entry_mode != 'free') && empty($error)) { // With combolist mode idprodfournprice is > 0 or -1. With autocomplete, idprodfournprice is > 0 or ''
|
||||
if ($prod_entry_mode != 'free' && empty($error)) { // With combolist mode idprodfournprice is > 0 or -1. With autocomplete, idprodfournprice is > 0 or ''
|
||||
$productsupplier = new ProductFournisseur($db);
|
||||
|
||||
$idprod = 0;
|
||||
|
|
@ -603,7 +611,7 @@ if (empty($reshook)) {
|
|||
$reg = array();
|
||||
if (preg_match('/^idprod_([0-9]+)$/', GETPOST('idprodfournprice', 'alpha'), $reg)) {
|
||||
$idprod = $reg[1];
|
||||
$res = $productsupplier->fetch($idprod); // Load product from its ID
|
||||
$res = $productsupplier->fetch($idprod); // Load product from its id
|
||||
// Call to init some price properties of $productsupplier
|
||||
// So if a supplier price already exists for another thirdparty (first one found), we use it as reference price
|
||||
if (!empty($conf->global->SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER)) {
|
||||
|
|
@ -626,42 +634,85 @@ if (empty($reshook)) {
|
|||
if ($idprod > 0) {
|
||||
$label = $productsupplier->label;
|
||||
|
||||
// if we use supplier description of the products
|
||||
if (!empty($productsupplier->desc_supplier) && !empty($conf->global->PRODUIT_FOURN_TEXTS)) {
|
||||
$desc = $productsupplier->desc_supplier;
|
||||
// Define output language
|
||||
if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
|
||||
$outputlangs = $langs;
|
||||
$newlang = '';
|
||||
if (empty($newlang) && GETPOST('lang_id', 'aZ09')) {
|
||||
$newlang = GETPOST('lang_id', 'aZ09');
|
||||
}
|
||||
if (empty($newlang)) {
|
||||
$newlang = $object->thirdparty->default_lang;
|
||||
}
|
||||
if (!empty($newlang)) {
|
||||
$outputlangs = new Translate("", $conf);
|
||||
$outputlangs->setDefaultLang($newlang);
|
||||
}
|
||||
$desc = (!empty($productsupplier->multilangs[$outputlangs->defaultlang]["description"])) ? $productsupplier->multilangs[$outputlangs->defaultlang]["description"] : $productsupplier->description;
|
||||
} else {
|
||||
$desc = $productsupplier->description;
|
||||
}
|
||||
// if we use supplier description of the products
|
||||
if (!empty($productsupplier->desc_supplier) && !empty($conf->global->PRODUIT_FOURN_TEXTS)) {
|
||||
$desc = $productsupplier->desc_supplier;
|
||||
}
|
||||
|
||||
if (trim($product_desc) != trim($desc)) {
|
||||
//If text set in desc is the same as product descpription (as now it's preloaded) whe add it only one time
|
||||
if (trim($product_desc) == trim($desc) && !empty($conf->global->PRODUIT_AUTOFILL_DESC)) {
|
||||
$product_desc='';
|
||||
}
|
||||
|
||||
if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) {
|
||||
$desc = $product_desc;
|
||||
}
|
||||
if (!empty($product_desc) && trim($product_desc) != trim($desc)) {
|
||||
$desc = dol_concatdesc($desc, $product_desc, '', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
|
||||
}
|
||||
|
||||
$type = $productsupplier->type;
|
||||
$price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type : 'HT');
|
||||
|
||||
$ref_supplier = $productsupplier->ref_supplier;
|
||||
|
||||
$tva_tx = get_default_tva($object->thirdparty, $mysoc, $productsupplier->id, GETPOST('idprodfournprice', 'alpha'));
|
||||
$tva_npr = get_default_npr($object->thirdparty, $mysoc, $productsupplier->id, GETPOST('idprodfournprice', 'alpha'));
|
||||
// Get vat rate
|
||||
if (!GETPOSTISSET('tva_tx')) { // If vat rate not provided from the form (the form has the priority)
|
||||
$tva_tx = get_default_tva($object->thirdparty, $mysoc, $productsupplier->id, GETPOST('idprodfournprice', 'alpha'));
|
||||
$tva_npr = get_default_npr($object->thirdparty, $mysoc, $productsupplier->id, GETPOST('idprodfournprice', 'alpha'));
|
||||
}
|
||||
if (empty($tva_tx)) {
|
||||
$tva_npr = 0;
|
||||
}
|
||||
$localtax1_tx = get_localtax($tva_tx, 1, $mysoc, $object->thirdparty, $tva_npr);
|
||||
$localtax2_tx = get_localtax($tva_tx, 2, $mysoc, $object->thirdparty, $tva_npr);
|
||||
|
||||
if (empty($pu_ht)) {
|
||||
$pu_ht = 0; // If pu is '' or null, we force to have a numeric value
|
||||
$type = $productsupplier->type;
|
||||
if (GETPOST('price_ht') != '' || GETPOST('price_ht_devise') != '') {
|
||||
$price_base_type = 'HT';
|
||||
$pu = price2num($price_ht, 'MU');
|
||||
$pu_devise = price2num($price_ht_devise, 'CU');
|
||||
} elseif (GETPOST('price_ttc') != '' || GETPOST('price_ttc_devise') != '') {
|
||||
$price_base_type = 'TTC';
|
||||
$pu = price2num($price_ttc, 'MU');
|
||||
$pu_devise = price2num($price_ttc_devise, 'CU');
|
||||
} else {
|
||||
$price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type : 'HT');
|
||||
if (empty($object->multicurrency_code) || ($productsupplier->fourn_multicurrency_code != $object->multicurrency_code)) { // If object is in a different currency and price not in this currency
|
||||
$pu = $productsupplier->fourn_pu;
|
||||
$pu_devise = 0;
|
||||
} else {
|
||||
$pu = $productsupplier->fourn_pu;
|
||||
$pu_devise = $productsupplier->fourn_multicurrency_unitprice;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($pu)) {
|
||||
$pu = 0; // If pu is '' or null, we force to have a numeric value
|
||||
}
|
||||
|
||||
// If GETPOST('idprodfournprice') is a numeric, we can use it. If it is empty or if it is 'idprod_123', we should use -1 (not used)
|
||||
$fournprice = (is_numeric(GETPOST('idprodfournprice', 'alpha')) ? GETPOST('idprodfournprice', 'alpha') : -1);
|
||||
$buyingprice = 0;
|
||||
$pu_ht_devise = price2num($price_ht_devise, 'MU');
|
||||
|
||||
$result = $object->addline(
|
||||
$desc,
|
||||
$pu_ht,
|
||||
($price_base_type == 'HT' ? $pu : 0),
|
||||
$qty,
|
||||
$tva_tx,
|
||||
$localtax1_tx,
|
||||
|
|
@ -669,7 +720,7 @@ if (empty($reshook)) {
|
|||
$productsupplier->id,
|
||||
$remise_percent,
|
||||
$price_base_type,
|
||||
$pu_ttc,
|
||||
($price_base_type == 'TTC' ? $pu : 0),
|
||||
$tva_npr,
|
||||
$type,
|
||||
-1,
|
||||
|
|
@ -683,7 +734,7 @@ if (empty($reshook)) {
|
|||
$productsupplier->fk_unit,
|
||||
'',
|
||||
0,
|
||||
$pu_ht_devise,
|
||||
$pu_devise,
|
||||
$date_start,
|
||||
$date_end
|
||||
);
|
||||
|
|
@ -709,6 +760,7 @@ if (empty($reshook)) {
|
|||
} elseif ((GETPOST('price_ht') !== '' || GETPOST('price_ttc') !== '' || GETPOST('multicurrency_price_ht') != '') && empty($error)) { // Free product. // $price_ht is already set
|
||||
$pu_ht = price2num($price_ht, 'MU');
|
||||
$pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
|
||||
|
||||
$tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0);
|
||||
$tva_tx = str_replace('*', '', $tva_tx);
|
||||
$label = (GETPOST('product_label') ? GETPOST('product_label') : '');
|
||||
|
|
@ -718,21 +770,22 @@ if (empty($reshook)) {
|
|||
$fk_unit = GETPOST('units', 'alpha');
|
||||
|
||||
if (!preg_match('/\((.*)\)/', $tva_tx)) {
|
||||
$tva_tx = price2num($tva_tx); // When vat is text input field
|
||||
$tva_tx = price2num($tva_tx); // $txtva can have format '5,1' or '5.1' or '5.1(XXX)', we must clean only if '5,1'
|
||||
}
|
||||
|
||||
// Local Taxes
|
||||
$localtax1_tx = get_localtax($tva_tx, 1, $mysoc, $object->thirdparty);
|
||||
$localtax2_tx = get_localtax($tva_tx, 2, $mysoc, $object->thirdparty);
|
||||
|
||||
if ($price_ht !== '') {
|
||||
if (GETPOST('price_ht') != '' || GETPOST('price_ht_devise') != '') {
|
||||
$pu_ht = price2num($price_ht, 'MU'); // $pu_ht must be rounded according to settings
|
||||
} else {
|
||||
$pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
|
||||
$pu_ht = price2num($pu_ttc / (1 + ($tva_tx / 100)), 'MU'); // $pu_ht must be rounded according to settings
|
||||
}
|
||||
$price_base_type = 'HT';
|
||||
$pu_ht_devise = price2num($price_ht_devise, 'MU');
|
||||
$pu_ht_devise = price2num($price_ht_devise, 'CU');
|
||||
$info_bits = 0;
|
||||
|
||||
$result = $object->addline(
|
||||
$desc,
|
||||
|
|
@ -800,6 +853,7 @@ if (empty($reshook)) {
|
|||
unset($_POST['price_ht']);
|
||||
unset($_POST['multicurrency_price_ht']);
|
||||
unset($_POST['price_ttc']);
|
||||
unset($_POST['fourn_ref']);
|
||||
unset($_POST['tva_tx']);
|
||||
unset($_POST['label']);
|
||||
unset($_POST['product_ref']);
|
||||
|
|
@ -813,6 +867,8 @@ if (empty($reshook)) {
|
|||
unset($_POST['np_markRate']);
|
||||
unset($_POST['dp_desc']);
|
||||
unset($_POST['idprodfournprice']);
|
||||
unset($_POST['units']);
|
||||
|
||||
unset($_POST['idprod']);
|
||||
|
||||
unset($_POST['date_starthour']);
|
||||
|
|
@ -852,10 +908,9 @@ if (empty($reshook)) {
|
|||
$localtax2_rate = get_localtax($vat_rate, 2, $mysoc, $object->thirdparty);
|
||||
|
||||
if (GETPOST('price_ht') != '') {
|
||||
$price_base_type = 'HT';
|
||||
$ht = price2num(GETPOST('price_ht'), '', 2);
|
||||
}
|
||||
|
||||
if (GETPOST('price_ttc') != '') {
|
||||
} else {
|
||||
$reg = array();
|
||||
$vatratecleaned = $vat_rate;
|
||||
if (preg_match('/^(.*)\s*\((.*)\)$/', $vat_rate, $reg)) { // If vat is "xx (yy)"
|
||||
|
|
@ -865,10 +920,10 @@ if (empty($reshook)) {
|
|||
|
||||
$ttc = price2num(GETPOST('price_ttc'), '', 2);
|
||||
$ht = $ttc / (1 + ($vatratecleaned / 100));
|
||||
$price_base_type = 'HT';
|
||||
}
|
||||
|
||||
$price_base_type = 'HT';
|
||||
$pu_ht_devise = price2num(GETPOST('multicurrency_subprice'), 'CU');
|
||||
$pu_ht_devise = price2num(GETPOST('multicurrency_subprice'), 'CU', 2);
|
||||
|
||||
// Add buying price
|
||||
$fournprice = (GETPOST('fournprice') ? GETPOST('fournprice') : '');
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user