diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index df190abc43e..93e2e859196 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -3275,7 +3275,7 @@ class Form
$langs->load('other');
}
- $sql = "SELECT p.rowid, p.ref, p.label, p.price, p.duration, p.fk_product_type, p.stock,";
+ $sql = "SELECT p.rowid, p.ref, p.label, p.price, p.duration, p.fk_product_type, p.stock, p.tva_tx as tva_tx_sale, p.default_vat_code as default_vat_code_sale,";
$sql .= " pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.remise_percent, pfp.remise, pfp.unitprice,";
$sql .= " pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, pfp.default_vat_code, pfp.fk_soc, s.nom as name,";
$sql .= " pfp.supplier_reputation";
@@ -3371,6 +3371,12 @@ class Form
while ($i < $num) {
$objp = $this->db->fetch_object($result);
+ if (is_null($objp->idprodfournprice)) {
+ // There is no supplier price found, we will use the vat rate for sale
+ $objp->tva_tx = $objp->tva_tx_sale;
+ $objp->default_vat_code = $objp->default_vat_code_sale;
+ }
+
$outkey = $objp->idprodfournprice; // id in table of price
if (!$outkey && $alsoproductwithnosupplierprice) {
$outkey = 'idprod_'.$objp->rowid; // id of product
@@ -3566,14 +3572,17 @@ class Form
if (empty($objp->idprodfournprice) && empty($alsoproductwithnosupplierprice)) {
$optstart .= ' disabled';
}
+
if (!empty($objp->idprodfournprice) && $objp->idprodfournprice > 0) {
- $opt .= ' data-product-id="'.dol_escape_htmltag($objp->rowid).'"';
- $opt .= ' data-price-id="'.dol_escape_htmltag($objp->idprodfournprice).'"';
- $opt .= ' data-qty="'.dol_escape_htmltag($objp->quantity).'"';
- $opt .= ' data-up="'.dol_escape_htmltag($objp->unitprice).'"';
- $opt .= ' data-up-locale="'.dol_escape_htmltag(price($objp->unitprice)).'"';
- $opt .= ' data-discount="'.dol_escape_htmltag($outdiscount).'"';
- $opt .= ' data-tvatx="'.dol_escape_htmltag($objp->tva_tx).'"';
+ $optstart .= ' data-product-id="'.dol_escape_htmltag($objp->rowid).'"';
+ $optstart .= ' data-price-id="'.dol_escape_htmltag($objp->idprodfournprice).'"';
+ $optstart .= ' data-qty="'.dol_escape_htmltag($objp->quantity).'"';
+ $optstart .= ' data-up="'.dol_escape_htmltag(price2num($objp->unitprice)).'"';
+ $optstart .= ' data-up-locale="'.dol_escape_htmltag(price($objp->unitprice)).'"';
+ $optstart .= ' data-discount="'.dol_escape_htmltag($outdiscount).'"';
+ $optstart .= ' data-tvatx="'.dol_escape_htmltag(price2num($objp->tva_tx)).'"';
+ $optstart .= ' data-tvatx-formated="'.dol_escape_htmltag(price($objp->tva_tx, 0, $langs, 1, -1, 2)).'"';
+ $optstart .= ' data-default-vat-code="'.dol_escape_htmltag($objp->default_vat_code).'"';
}
$optstart .= ' data-description="'.dol_escape_htmltag($objp->description, 0, 1).'"';
@@ -3585,7 +3594,8 @@ class Form
'price_qty_ht' => price2num($objp->fprice, 'MU'), // Keep higher resolution for price for the min qty
'price_unit_ht' => price2num($objp->unitprice, 'MU'), // This is used to fill the Unit Price
'price_ht' => price2num($objp->unitprice, 'MU'), // This is used to fill the Unit Price (for compatibility)
- 'tva_tx' => $objp->tva_tx,
+ 'tva_tx_formated' => price($objp->tva_tx, 0, $langs, 1, -1, 2),
+ 'tva_tx' => price2num($objp->tva_tx),
'default_vat_code' => $objp->default_vat_code,
'discount' => $outdiscount,
'type' => $outtype,
@@ -3613,14 +3623,15 @@ class Form
$outarray,
array('key'=>$outkey,
'value'=>$outref,
- 'label'=>$outval,
+ 'label'=>$outvallabel,
'qty'=>$outqty,
'price_qty_ht'=>price2num($objp->fprice, 'MU'), // Keep higher resolution for price for the min qty
- 'price_unit_ht'=>price2num($objp->unitprice, 'MU'), // This is used to fill the Unit Price
- 'price_ht'=>price2num($objp->unitprice, 'MU'), // This is used to fill the Unit Price (for compatibility)
'price_qty_ht_locale'=>price($objp->fprice),
+ 'price_unit_ht'=>price2num($objp->unitprice, 'MU'), // This is used to fill the Unit Price
'price_unit_ht_locale'=>price($objp->unitprice),
- 'tva_tx'=>$objp->tva_tx,
+ 'price_ht'=>price2num($objp->unitprice, 'MU'), // This is used to fill the Unit Price (for compatibility)
+ 'tva_tx_formated' => price($objp->tva_tx),
+ 'tva_tx'=>price2num($objp->tva_tx),
'default_vat_code'=>$objp->default_vat_code,
'discount'=>$outdiscount,
'type'=>$outtype,
diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php
index cc871de9709..856c94c5b70 100644
--- a/htdocs/core/lib/ajax.lib.php
+++ b/htdocs/core/lib/ajax.lib.php
@@ -197,6 +197,7 @@ function ajax_autocompleter($selected, $htmlname, $url, $urloption = '', $minLen
if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) {
$script .= '
// For customer price when PRODUIT_CUSTOMER_PRICES_BY_QTY is on
+ console.log("PRODUIT_CUSTOMER_PRICES_BY_QTY is on, propagate also prices by quantity into data-pbqxxx properties");
$("#'.$htmlnamejquery.'").attr("data-pbq", ui.item.pbq);
$("#'.$htmlnamejquery.'").attr("data-pbqup", ui.item.price_ht);
$("#'.$htmlnamejquery.'").attr("data-pbqbase", ui.item.pricebasetype);
diff --git a/htdocs/core/modules/product/doc/doc_generic_product_odt.modules.php b/htdocs/core/modules/product/doc/doc_generic_product_odt.modules.php
index 821b6a24e10..d5321b92ceb 100644
--- a/htdocs/core/modules/product/doc/doc_generic_product_odt.modules.php
+++ b/htdocs/core/modules/product/doc/doc_generic_product_odt.modules.php
@@ -153,7 +153,7 @@ class doc_generic_product_odt extends ModelePDFProduct
$texte .= $form->textwithpicto($texttitle, $texthelp, 1, 'help', '', 1);
$texte .= '
';
$texte .= '';
$texte .= '
';
$texte .= '';
diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php
index c0382a39de4..c3b94332909 100644
--- a/htdocs/core/tpl/objectline_create.tpl.php
+++ b/htdocs/core/tpl/objectline_create.tpl.php
@@ -971,10 +971,11 @@ if (!empty($usemargins) && $user->rights->margins->creer) {
}
?>
- // Deal with supplier ref price
+
+ // Deal with supplier ref price (idprodfournprice = int)
if (jQuery('#idprodfournprice').val() > 0)
{
- console.log("objectline_create.tpl #idprodfournprice is > 0, so we set some properties into page");
+ console.log("objectline_create.tpl #idprodfournprice is is an ID > 0, so we set some properties into page");
var up = parseFloat($('option:selected', this).attr('data-up')); // When select is done from HTML select
if (isNaN(up)) { up = parseFloat(jQuery('#idprodfournprice').attr('data-up'));} // When select is done from HTML input with ajax autocomplete
@@ -1023,14 +1024,15 @@ if (!empty($usemargins) && $user->rights->margins->creer) {
}
global->PRODUIT_AUTOFILL_DESC) && $conf->global->PRODUIT_AUTOFILL_DESC == 1) {
+ if (getDolGlobalInt('PRODUIT_AUTOFILL_DESC') == 1) {
?>
var description = $('option:selected', this).attr('data-description');
if (typeof description == 'undefined') { description = jQuery('#idprodfournprice').attr('data-description'); }
console.log("Load desciption into text area : "+description);
global->FCKEDITOR_ENABLE_DETAILS)) { ?>
+ if (!empty($conf->global->FCKEDITOR_ENABLE_DETAILS)) {
+ ?>
if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined")
{
var editor = CKEDITOR.instances['dp_desc'];
@@ -1039,15 +1041,41 @@ if (!empty($usemargins) && $user->rights->margins->creer) {
}
}
+ } else {
+ ?>
jQuery('#dp_desc').text(description);
+ }
+ ?>
} else if (jQuery('#idprodfournprice').length > 0) {
+ console.log("objectline_create.tpl #idprodfournprice is not an int but is a string so we set only few properties into page");
+
+ var tva_tx = parseFloat($('option:selected', this).attr('data-tvatx')); // When select is done from HTML select
+ if (isNaN(tva_tx)) { tva_tx = parseFloat(jQuery('#idprodfournprice').attr('data-tvatx'));} // When select is done from HTML input with ajax autocomplete
+
+ var default_vat_code = $('option:selected', this).attr('data-default-vat-code'); // When select is done from HTML select
+ if (typeof default_vat_code === 'undefined') { default_vat_code = jQuery('#idprodfournprice').attr('data-default-vat-code');} // When select is done from HTML input with ajax autocomplete
+
+ var stringforvatrateselection = tva_tx;
+ if (typeof default_vat_code != 'undefined' && default_vat_code != null) {
+ stringforvatrateselection = stringforvatrateselection+' ('+default_vat_code+')';
+ }
+
+ console.log("objectline_create.tpl We find data for price : tva_tx = "+tva_tx+", default_vat_code = "+default_vat_code+", stringforvatrateselection="+stringforvatrateselection+" for product id = "+jQuery('#idprodfournprice').val());
+
+ // Set vat rate if field is an input box
+ $('#tva_tx').val(tva_tx);
+ // Set vat rate by selecting the combo
+ //$('#tva_tx option').val(tva_tx); // This is bugged, it replaces the vat key of all options
+ $('#tva_tx option').removeAttr('selected');
+ console.log("stringforvatrateselection="+stringforvatrateselection+" -> value of option label for this key="+$('#tva_tx option[value="'+stringforvatrateselection+'"]').val());
+ $('#tva_tx option[value="'+stringforvatrateselection+'"]').prop('selected', true);
+
global->PRODUIT_AUTOFILL_DESC) && $conf->global->PRODUIT_AUTOFILL_DESC == 1) {
- if (!empty($conf->global->FCKEDITOR_ENABLE_DETAILS)) { ?>
+ if (getDolGlobalInt('PRODUIT_AUTOFILL_DESC') == 1) {
+ if (!empty($conf->global->FCKEDITOR_ENABLE_DETAILS)) {
+ ?>
if (typeof CKEDITOR == "object" && typeof CKEDITOR.instances != "undefined")
{
var editor = CKEDITOR.instances['dp_desc'];
@@ -1056,11 +1084,13 @@ if (!empty($usemargins) && $user->rights->margins->creer) {
}
}
+ } else {
+ ?>
jQuery('#dp_desc').text('');
+ }
+ ?>
}
diff --git a/htdocs/product/admin/product.php b/htdocs/product/admin/product.php
index 069029d074b..40f67137acd 100644
--- a/htdocs/product/admin/product.php
+++ b/htdocs/product/admin/product.php
@@ -204,7 +204,7 @@ if ($action == 'set') {
if ($action == 'del') {
$ret = delDocumentModel($value, $type);
if ($ret > 0) {
- if ($conf->global->PRODUCT_ADDON_PDF == "$value") {
+ if (getDolGlobalString('PRODUCT_ADDON_PDF') == "$value") {
dolibarr_del_const($db, 'PRODUCT_ADDON_PDF', $conf->entity);
}
}
@@ -461,7 +461,7 @@ foreach ($dirmodels as $reldir) {
// Defaut
print '
';
- if ($conf->global->PRODUCT_ADDON_PDF == $name) {
+ if (getDolGlobalString('PRODUCT_ADDON_PDF') == $name) {
print img_picto($langs->trans("Default"), 'on');
} else {
print 'scandir).'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'';
diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php
index bb6d9b2a084..8d3fe718458 100644
--- a/htdocs/product/class/product.class.php
+++ b/htdocs/product/class/product.class.php
@@ -5156,11 +5156,7 @@ class Product extends CommonObject
// Positionne le modele sur le nom du modele a utiliser
if (!dol_strlen($modele)) {
- if (!empty($conf->global->PRODUCT_ADDON_PDF)) {
- $modele = $conf->global->PRODUCT_ADDON_PDF;
- } else {
- $modele = 'strato';
- }
+ $modele = getDolGlobalString('PRODUCT_ADDON_PDF', 'strato');
}
$modelpath = "core/modules/product/doc/";
diff --git a/htdocs/product/price.php b/htdocs/product/price.php
index 5a386792d1c..0424ddaf830 100644
--- a/htdocs/product/price.php
+++ b/htdocs/product/price.php
@@ -465,7 +465,8 @@ if (empty($reshook)) {
break;
}
- if ($object->multiprices[$key] != $newprice || $object->multiprices_min[$key] != $newprice_min || $object->multiprices_base_type[$key] != $val['price_base_type'] || $object->multiprices_tva_tx[$key] != $newvattx) {
+ // If price has changed, we update it
+ if (!array_key_exists($key, $object->multiprices) || $object->multiprices[$key] != $newprice || $object->multiprices_min[$key] != $newprice_min || $object->multiprices_base_type[$key] != $val['price_base_type'] || $object->multiprices_tva_tx[$key] != $newvattx) {
$res = $object->updatePrice($newprice, $val['price_base_type'], $user, $val['vat_tx'], $newprice_min, $key, $val['npr'], $psq, 0, $val['localtaxes_array'], $val['default_vat_code']);
} else {
$res = 0;