Clean code. Prepare for inputing prices with taxes

This commit is contained in:
Laurent Destailleur 2022-08-13 19:30:26 +02:00
parent d510e3ffcc
commit 24b1085639
6 changed files with 160 additions and 61 deletions

View File

@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
/* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2022 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
@ -9,12 +9,12 @@
* Copyright (C) 2010-2021 Philippe Grand <philippe.grand@atoo-net.com>
* Copyright (C) 2012-2013 Christophe Battarel <christophe.battarel@altairis.fr>
* Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2014 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2020 Nicolas ZABOURI <info@inovea-conseil.com>
* Copyright (C) 2022 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
* Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2014 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2020 Nicolas ZABOURI <info@inovea-conseil.com>
* Copyright (C) 2022 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -88,9 +88,6 @@ $hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') :
$hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
$hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
// Nombre de ligne pour choix de produit/service predefinis
$NBLINES = 4;
$object = new Propal($db);
$extrafields = new ExtraFields($db);
@ -120,6 +117,7 @@ $usercanclose = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreat
$usercanvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->propal->propal_advance->validate)));
$usercansend = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->propal->propal_advance->send)));
$usermustrespectpricemin = ((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS));
$usercancreateorder = $user->hasRight('commande', 'creer');
$usercancreateinvoice = $user->hasRight('facture', 'creer');
$usercancreatecontract = $user->hasRight('contrat', 'creer');
@ -898,6 +896,9 @@ if (empty($reshook)) {
$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);
$price_ttc = price2num(GETPOST('price_ttc'), 'MU', 2);
$price_ttc_devise = price2num(GETPOST('multicurrency_price_ttc'), 'CU', 2);
$prod_entry_mode = GETPOST('prod_entry_mode');
if ($prod_entry_mode == 'free') {
$idprod = 0;
@ -956,6 +957,7 @@ if (empty($reshook)) {
$pu_ht = 0;
$pu_ttc = 0;
$price_min = 0;
$price_min_ttc = 0;
$price_base_type = (GETPOST('price_base_type', 'alpha') ? GETPOST('price_base_type', 'alpha') : 'HT');
$db->begin();
@ -983,6 +985,7 @@ if (empty($reshook)) {
$pu_ht = $prod->price;
$pu_ttc = $prod->price_ttc;
$price_min = $prod->price_min;
$price_min_ttc = $prod->price_min_ttc;
$price_base_type = $prod->price_base_type;
// If price per segment
@ -990,6 +993,7 @@ if (empty($reshook)) {
$pu_ht = $prod->multiprices[$object->thirdparty->price_level];
$pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level];
$price_min = $prod->multiprices_min[$object->thirdparty->price_level];
$price_min_ttc = $prod->multiprices_min_ttc[$object->thirdparty->price_level];
$price_base_type = $prod->multiprices_base_type[$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])) {
@ -1014,6 +1018,7 @@ if (empty($reshook)) {
$pu_ht = price($prodcustprice->lines[0]->price);
$pu_ttc = price($prodcustprice->lines[0]->price_ttc);
$price_min = price($prodcustprice->lines[0]->price_min);
$price_min_ttc = price($prodcustprice->lines[0]->price_min_ttc);
$price_base_type = $prodcustprice->lines[0]->price_base_type;
$tva_tx = ($prodcustprice->lines[0]->default_vat_code ? $prodcustprice->lines[0]->tva_tx.' ('.$prodcustprice->lines[0]->default_vat_code.' )' : $prodcustprice->lines[0]->tva_tx);
if ($prodcustprice->lines[0]->default_vat_code && !preg_match('/\(.*\)/', $tva_tx)) {
@ -1119,18 +1124,6 @@ if (empty($reshook)) {
$desc = dol_concatdesc($desc, $product_desc, '', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
}
// Add dimensions into product description
/*if (empty($conf->global->MAIN_PRODUCT_DISABLE_AUTOADD_DIM))
{
$text='';
if ($prod->weight) $text.=($text?"\n":"").$outputlangs->trans("Weight").': '.$prod->weight.' '.$prod->weight_units;
if ($prod->length) $text.=($text?"\n":"").$outputlangs->trans("Length").': '.$prod->length.' '.$prod->length_units;
if ($prod->surface) $text.=($text?"\n":"").$outputlangs->trans("Surface").': '.$prod->surface.' '.$prod->surface_units;
if ($prod->volume) $text.=($text?"\n":"").$outputlangs->trans("Volume").': '.$prod->volume.' '.$prod->volume_units;
$desc = dol_concatdesc($desc, $text);
}*/
// Add custom code and origin country into description
if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (!empty($prod->customcode) || !empty($prod->country_code))) {
$tmptxt = '(';
@ -1186,6 +1179,7 @@ if (empty($reshook)) {
$fk_unit = GETPOST('units', 'alpha');
$pu_ht_devise = price2num($price_ht_devise, 'MU');
$pu_ttc_devise = price2num($price_ttc_devise, 'MU');
}
// Margin
@ -1204,10 +1198,22 @@ if (empty($reshook)) {
$info_bits |= 0x01;
}
if (((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS)) && (!empty($price_min) && (price2num($pu_ht) * (1 - price2num($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');
} else {
//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;
if ($usermustrespectpricemin) {
if ($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));
setEventMessages($mesg, null, 'errors');
$error++;
}
}
if (!$error) {
// Insert line
$result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $price_base_type, $pu_ttc, $info_bits, $type, min($rank, count($object->lines) + 1), 0, GETPOST('fk_parent_line'), $fournprice, $buyingprice, $label, $date_start, $date_end, $array_options, $fk_unit, '', 0, $pu_ht_devise);
@ -1285,12 +1291,14 @@ 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);
// Add buying price
$fournprice = price2num(GETPOST('fournprice') ? GETPOST('fournprice') : '');
$buyingprice = price2num(GETPOST('buying_price') != '' ? GETPOST('buying_price') : ''); // If buying_price is '0', we muste keep this value
$pu_ht_devise = price2num(GETPOST('multicurrency_subprice'), '', 2);
//$pu_ttc_devise = price2num(GETPOST('multicurrency_subprice_ttc'), '', 2);
$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'));
@ -1321,16 +1329,32 @@ if (empty($reshook)) {
$res = $product->fetch($productid);
$type = $product->type;
$label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : '');
$price_min = $product->price_min;
if (!empty($conf->global->PRODUIT_MULTIPRICES) && !empty($object->thirdparty->price_level)) {
$price_min = $product->multiprices_min [$object->thirdparty->price_level];
$price_min = $product->multiprices_min[$object->thirdparty->price_level];
}
$price_min_ttc = $product->price_min_ttc;
if (!empty($conf->global->PRODUIT_MULTIPRICES) && !empty($object->thirdparty->price_level)) {
$price_min_ttc = $product->multiprices_min_ttc[$object->thirdparty->price_level];
}
$label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : '');
if (((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS)) && ($price_min && (price2num($pu_ht) * (1 - $remise_percent / 100) < price2num($price_min)))) {
setEventMessages($langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency)), null, 'errors');
$error++;
//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;
if ($usermustrespectpricemin) {
if ($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++;
$action = 'editline';
} 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));
setEventMessages($mesg, null, 'errors');
$error++;
$action = 'editline';
}
}
} else {
$type = GETPOST('type');
@ -2675,6 +2699,11 @@ if ($action == 'create') {
// Show object lines
$result = $object->getLinesArray();
// Add products/services form
//$forceall = 1;
global $inputalsopricewithtax;
$inputalsopricewithtax = 1;
print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '' : '#line_'.GETPOST('lineid', 'int')).'" method="POST">
<input type="hidden" name="token" value="' . newToken().'">
<input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">
@ -2699,8 +2728,6 @@ if ($action == 'create') {
// Form to add new line
if ($object->statut == Propal::STATUS_DRAFT && $usercancreate && $action != 'selectlines') {
if ($action != 'editline') {
// Add products/services form
$parameters = array();
$reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');

View File

@ -119,6 +119,7 @@ $usercancancel = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancrea
$usercansend = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->hasRight('commande', 'order_advance', 'send'));
$usercangeneretedoc = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->hasRight('commande', 'order_advance', 'generetedoc'));
$usermustrespectpricemin = ((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS));
$usercancreatepurchaseorder = ($user->hasRight('fournisseur', 'commande', 'creer') || $user->hasRight('supplier_order', 'creer'));
$permissionnote = $usercancreate; // Used by the include of actions_setnotes.inc.php
@ -647,6 +648,9 @@ if (empty($reshook)) {
$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);
$price_ttc = price2num(GETPOST('price_ttc'), 'MU', 2);
$price_ttc_devise = price2num(GETPOST('multicurrency_price_ttc'), 'CU', 2);
$prod_entry_mode = GETPOST('prod_entry_mode');
if ($prod_entry_mode == 'free') {
$idprod = 0;
@ -739,6 +743,7 @@ if (empty($reshook)) {
$pu_ht = $prod->price;
$pu_ttc = $prod->price_ttc;
$price_min = $prod->price_min;
$price_min_ttc = $prod->price_min_ttc;
$price_base_type = $prod->price_base_type;
// If price per segment
@ -746,6 +751,7 @@ if (empty($reshook)) {
$pu_ht = $prod->multiprices[$object->thirdparty->price_level];
$pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level];
$price_min = $prod->multiprices_min[$object->thirdparty->price_level];
$price_min_ttc = $prod->multiprices_min_ttc[$object->thirdparty->price_level];
$price_base_type = $prod->multiprices_base_type[$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])) {
@ -769,6 +775,7 @@ if (empty($reshook)) {
$pu_ht = price($prodcustprice->lines[0]->price);
$pu_ttc = price($prodcustprice->lines[0]->price_ttc);
$price_min = price($prodcustprice->lines[0]->price_min);
$price_min_ttc = price($prodcustprice->lines[0]->price_min_ttc);
$price_base_type = $prodcustprice->lines[0]->price_base_type;
$tva_tx = $prodcustprice->lines[0]->tva_tx;
if ($prodcustprice->lines[0]->default_vat_code && !preg_match('/\(.*\)/', $tva_tx)) {
@ -946,10 +953,19 @@ if (empty($reshook)) {
$info_bits |= 0x01;
}
if (((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS)) && (!empty($price_min) && (price2num($pu_ht) * (1 - price2num($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');
} else {
if ($usermustrespectpricemin) {
if ($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));
setEventMessages($mesg, null, 'errors');
$error++;
}
}
if (!$error) {
// Insert line
$result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $info_bits, 0, $price_base_type, $pu_ttc, $date_start, $date_end, $type, min($rank, count($object->lines) + 1), 0, GETPOST('fk_parent_line'), $fournprice, $buyingprice, $label, $array_options, $fk_unit, '', 0, $pu_ht_devise);
@ -1017,9 +1033,12 @@ if (empty($reshook)) {
$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'));
$pu_ht = price2num(GETPOST('price_ht'), '', 2);
$vat_rate = (GETPOST('tva_tx') ? GETPOST('tva_tx', 'alpha') : 0);
$vat_rate = str_replace('*', '', $vat_rate);
$pu_ht = price2num(GETPOST('price_ht'), '', 2);
$pu_ttc = price2num(GETPOST('price_ttc'), '', 2);
$pu_ht_devise = price2num(GETPOST('multicurrency_subprice'), '', 2);
//$pu_ttc_devise = price2num(GETPOST('multicurrency_subprice_ttc'), '', 2);
$qty = price2num(GETPOST('qty'), 'MS');
@ -1068,13 +1087,25 @@ if (empty($reshook)) {
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];
}
$price_min_ttc = $product->price_min_ttc;
if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && !empty($object->thirdparty->price_level)) {
$price_min_ttc = $product->multiprices_min_ttc[$object->thirdparty->price_level];
}
$label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : '');
if (((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS)) && ($price_min && (price2num($pu_ht) * (1 - $remise_percent / 100) < price2num($price_min)))) {
setEventMessages($langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency)), null, 'errors');
$error++;
$action = 'editline';
if ($usermustrespectpricemin) {
if ($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++;
$action = 'editline';
} 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));
setEventMessages($mesg, null, 'errors');
$error++;
$action = 'editline';
}
}
} else {
$type = GETPOST('type');

View File

@ -141,7 +141,7 @@ if (!empty($conf->global->INVOICE_DISALLOW_REOPEN)) {
}
$usercanunvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($usercancreate)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->facture->invoice_advance->unvalidate)));
$usercanproductignorepricemin = ((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS));
$usermustrespectpricemin = ((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS));
$usercancreatemargin = (!empty($user->rights->margins->creer) ? $user->rights->margins->creer : 0);
$usercanreadallmargin = (!empty($user->rights->margins->liretous) ? $user->rights->margins->liretous : 0);
$usercancreatewithdrarequest = (!empty($user->rights->prelevement->bons->creer) ? $user->rights->prelevement->bons->creer : 0);
@ -2010,6 +2010,9 @@ if (empty($reshook)) {
$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);
$price_ttc = price2num(GETPOST('price_ttc'), 'MU', 2);
$price_ttc_devise = price2num(GETPOST('multicurrency_price_ttc'), 'CU', 2);
$prod_entry_mode = GETPOST('prod_entry_mode', 'alpha');
if ($prod_entry_mode == 'free') {
$idprod = 0;
@ -2126,6 +2129,7 @@ if (empty($reshook)) {
$pu_ht = $datapriceofproduct['pu_ht'];
$pu_ttc = $datapriceofproduct['pu_ttc'];
$price_min = $datapriceofproduct['price_min'];
$price_min_ttc = $datapriceofproduct['price_min_ttc'];
$price_base_type = $datapriceofproduct['price_base_type'];
$tva_tx = $datapriceofproduct['tva_tx'];
$tva_npr = $datapriceofproduct['tva_npr'];
@ -2238,6 +2242,7 @@ 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');
}
// Margin
@ -2256,6 +2261,7 @@ if (empty($reshook)) {
$price2num_pu_ht = price2num($pu_ht);
$price2num_remise_percent = price2num($remise_percent);
$price2num_price_min = price2num($price_min);
$price2num_price_min_ttc = price2num($price_min_ttc);
if (empty($price2num_pu_ht)) {
$price2num_pu_ht = 0;
}
@ -2265,11 +2271,24 @@ if (empty($reshook)) {
if (empty($price2num_price_min)) {
$price2num_price_min = 0;
}
if (empty($price2num_price_min_ttc)) {
$price2num_price_min_ttc = 0;
}
if ($usercanproductignorepricemin && (!empty($price_min) && ($price2num_pu_ht * (1 - $price2num_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');
} else {
// 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))) {
$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));
setEventMessages($mesg, null, 'errors');
$error++;
}
}
if (!$error) {
// Add batchinfo if the detail_batch array is defined
if (!empty($conf->productbatch->enabled) && !empty($lines[$i]->detail_batch) && is_array($lines[$i]->detail_batch) && !empty($conf->global->INVOICE_INCUDE_DETAILS_OF_LOTS_SERIALS)) {
$langs->load('productbatch');
@ -2360,10 +2379,14 @@ if (empty($reshook)) {
$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') ? GETPOST('product_desc', 'restricthtml') : GETPOST('desc', 'restricthtml'));
$pu_ht = price2num(GETPOST('price_ht'), '', 2);
$vat_rate = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0);
$qty = GETPOST('qty');
$vat_rate = str_replace('*', '', $vat_rate);
$pu_ht = price2num(GETPOST('price_ht'), '', 2);
$pu_ttc = price2num(GETPOST('price_ttc'), '', 2);
$pu_ht_devise = price2num(GETPOST('multicurrency_subprice'), '', 2);
//$pu_ttc_devise = price2num(GETPOST('multicurrency_subprice_ttc'), '', 2);
$qty = GETPOST('qty');
// Define info_bits
$info_bits = 0;
@ -2434,15 +2457,28 @@ if (empty($reshook)) {
$price_min = $product->price_min;
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];
$price_min = $product->multiprices_min[$object->thirdparty->price_level];
}
$price_min_ttc = $product->price_min_ttc;
if ((!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && !empty($object->thirdparty->price_level)) {
$price_min_ttc = $product->multiprices_min_ttc[$object->thirdparty->price_level];
}
$label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : '');
// Check price is not lower than minimum (check is done only for standard or replacement invoices)
if ($usercanproductignorepricemin && (($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT) && $price_min && (price2num($pu_ht) * (1 - $remise_percent / 100) < price2num($price_min)))) {
setEventMessages($langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency)), null, 'errors');
$error++;
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))) {
$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 - $remise_percent / 100)) < price2num($price_min_ttc))) {
$mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min_ttc, 'MU'), 0, $langs, 0, 0, -1, $conf->currency));
setEventMessages($mesg, null, 'errors');
$error++;
$action = 'editline';
}
}
} else {
$type = GETPOST('type');

View File

@ -4941,7 +4941,7 @@ abstract class CommonObject
*
* @param string $action GET/POST action
* @param CommonObjectLine $line Selected object line to output
* @param string $var Is it a an odd line (true)
* @param string $var Not used
* @param int $num Number of line (0)
* @param int $i I
* @param int $dateSelector 1=Show also date range input fields

View File

@ -48,6 +48,7 @@ if (!isset($dateSelector)) {
global $dateSelector; // Take global var only if not already defined into function calling (for example formAddObjectLine)
}
global $forceall, $forcetoshowtitlelines, $senderissupplier, $inputalsopricewithtax;
if (!isset($dateSelector)) {
$dateSelector = 1; // For backward compatibility
} elseif (empty($dateSelector)) {
@ -734,7 +735,7 @@ if (!empty($usemargins) && $user->rights->margins->creer) {
$.post('<?php echo DOL_URL_ROOT; ?>/product/ajax/products.php?action=fetch',
{ 'id': $(this).val(), 'socid': <?php print $object->socid; ?> },
function(data) {
console.log("Load unit price end, we got value "+data.price_ht);
console.log("Load unit price end, we got value ht="+data.price_ht+" ttc="+data.price_ttc+" pricebasetype="+data.pricebasetype);
$('#date_start').removeAttr('type');
$('#date_end').removeAttr('type');
@ -755,7 +756,11 @@ if (!empty($usemargins) && $user->rights->margins->creer) {
jQuery('#date_end').removeClass('inputmandatory');
}
jQuery("#price_ht").val(data.price_ht);
if (<?php echo (int) $inputalsopricewithtax; ?> == 1 && data.pricebasetype == 'TTC') {
jQuery("#price_ttc").val(data.price_ttc);
} else {
jQuery("#price_ht").val(data.price_ht);
}
<?php
if (!empty($conf->global->PRODUIT_AUTOFILL_DESC) && $conf->global->PRODUIT_AUTOFILL_DESC == 1) {
if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) { ?>

View File

@ -280,17 +280,17 @@ print vatrate($positiverates.($line->vat_src_code ? ' ('.$line->vat_src_code.')'
//print vatrate($line->tva_tx.($line->vat_src_code?(' ('.$line->vat_src_code.')'):''), '%', $line->info_bits);
?></td>
<td class="linecoluht nowrap right"><?php $coldisplay++; ?><?php print price($sign * $line->subprice); ?></td>
<td class="linecoluht nowraponall right"><?php $coldisplay++; ?><?php print price($sign * $line->subprice); ?></td>
<?php if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) { ?>
<td class="linecoluht_currency nowrap right"><?php $coldisplay++; ?><?php print price($sign * $line->multicurrency_subprice); ?></td>
<td class="linecoluht_currency nowraponall right"><?php $coldisplay++; ?><?php print price($sign * $line->multicurrency_subprice); ?></td>
<?php }
if ($inputalsopricewithtax) { ?>
<td class="linecoluttc nowrap right"><?php $coldisplay++; ?><?php print (isset($line->pu_ttc) ? price($sign * $line->pu_ttc) : price($sign * $line->subprice)); ?></td>
<td class="linecoluttc nowraponall right"><?php $coldisplay++; ?><?php print (isset($line->pu_ttc) ? price($sign * $line->pu_ttc) : price($sign * $line->subprice)); ?></td>
<?php } ?>
<td class="linecolqty nowrap right"><?php $coldisplay++; ?>
<td class="linecolqty nowraponall right"><?php $coldisplay++; ?>
<?php
if ((($line->info_bits & 2) != 2) && $line->special_code != 3) {
// I comment this because it shows info even when not required