diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index 622f8096462..930c6a985b3 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -3489,9 +3489,12 @@ class Form
}
$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";
+ $sql .= " pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.remise_percent, pfp.remise, pfp.unitprice";
+ if (isModEnabled('multicurrency')) {
+ $sql .= ", pfp.multicurrency_code, pfp.multicurrency_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";
// if we use supplier description of the products
if (getDolGlobalString('PRODUIT_FOURN_TEXTS')) {
$sql .= ", pfp.desc_fourn as description";
@@ -3814,6 +3817,10 @@ class Form
$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-supplier-ref="' . dol_escape_htmltag($objp->ref_fourn) . '"';
+ if (isModEnabled('multicurrency')) {
+ $optstart .= ' data-multicurrency-code="' . dol_escape_htmltag($objp->multicurrency_code) . '"';
+ $optstart .= ' data-multicurrency-up="' . dol_escape_htmltag($objp->multicurrency_unitprice) . '"';
+ }
}
$optstart .= ' data-description="' . dol_escape_htmltag($objp->description, 0, 1) . '"';
@@ -3835,6 +3842,10 @@ class Form
'disabled' => (empty($objp->idprodfournprice) ? true : false),
'description' => $objp->description
);
+ if (isModEnabled('multicurrency')) {
+ $outarrayentry['multicurrency_code'] = $objp->multicurrency_code;
+ $outarrayentry['multicurrency_unitprice'] = price2num($objp->multicurrency_unitprice, 'MU');
+ }
$parameters = array(
'objp' => &$objp,
@@ -3850,28 +3861,32 @@ class Form
// "key" value of json key array is used by jQuery automatically as selected value. Example: 'type' = product or service, 'price_ht' = unit price without tax
// "label" value of json key array is used by jQuery automatically as text for combo box
$out .= $optstart . ' data-html="' . dol_escape_htmltag($optlabel) . '">' . $optlabel . "\n";
- array_push(
- $outarray,
- array('key' => $outkey,
- 'value' => $outref,
- 'label' => $outvallabel,
- 'qty' => $outqty,
- 'price_qty_ht' => price2num($objp->fprice, 'MU'), // Keep higher resolution for price for the min qty
- '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),
- '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,
- 'duration_value' => $outdurationvalue,
- 'duration_unit' => $outdurationunit,
- 'disabled' => (empty($objp->idprodfournprice) ? true : false),
- 'description' => $objp->description
- )
+ $outarraypush = array(
+ 'key' => $outkey,
+ 'value' => $outref,
+ 'label' => $outvallabel,
+ 'qty' => $outqty,
+ 'price_qty_ht' => price2num($objp->fprice, 'MU'), // Keep higher resolution for price for the min qty
+ '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),
+ '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,
+ 'duration_value' => $outdurationvalue,
+ 'duration_unit' => $outdurationunit,
+ 'disabled' => (empty($objp->idprodfournprice) ? true : false),
+ 'description' => $objp->description
);
+ if (isModEnabled('multicurrency')) {
+ $outarraypush['multicurrency_code'] = $objp->multicurrency_code;
+ $outarraypush['multicurrency_unitprice'] = price2num($objp->multicurrency_unitprice, 'MU');
+ }
+ array_push($outarray, $outarraypush);
+
// Example of var_dump $outarray
// array(1) {[0]=>array(6) {[key"]=>string(1) "2" ["value"]=>string(3) "ppp"
// ["label"]=>string(76) "ppp (fff2) - ppp - 20,00 Euros/1unité (20,00 Euros/unité)"
diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php
index f78c59b7b41..136382d2d77 100644
--- a/htdocs/core/lib/ajax.lib.php
+++ b/htdocs/core/lib/ajax.lib.php
@@ -161,6 +161,14 @@ function ajax_autocompleter($selected, $htmlname, $url, $urloption = '', $minLen
price_ttc: item.price_ttc,
price_unit_ht: item.price_unit_ht,
price_unit_ht_locale: item.price_unit_ht_locale,
+ ';
+ if (isModEnabled('multicurrency')) {
+ $script .= '
+ multicurrency_code: item.multicurrency_code,
+ multicurrency_unitprice: item.multicurrency_unitprice,
+ ';
+ }
+ $script .= '
description : item.description,
ref_customer: item.ref_customer,
tva_tx: item.tva_tx,
@@ -192,6 +200,13 @@ function ajax_autocompleter($selected, $htmlname, $url, $urloption = '', $minLen
$("#'.$htmlnamejquery.'").attr("data-tvatx", ui.item.tva_tx);
$("#'.$htmlnamejquery.'").attr("data-default-vat-code", ui.item.default_vat_code);
';
+ if (isModEnabled('multicurrency')) {
+ $script .= '
+ // For multi-currency values
+ $("#'.$htmlnamejquery.'").attr("data-multicurrency-code", ui.item.multicurrency_code);
+ $("#'.$htmlnamejquery.'").attr("data-multicurrency-unitprice", ui.item.multicurrency_unitprice);
+ ';
+ }
if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
$script .= '
// For customer price when PRODUIT_CUSTOMER_PRICES_BY_QTY is on
diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php
index 0441eee03f4..3547747a1f4 100644
--- a/htdocs/core/tpl/objectline_create.tpl.php
+++ b/htdocs/core/tpl/objectline_create.tpl.php
@@ -1093,12 +1093,36 @@ if (!empty($usemargins) && $user->hasRight('margins', 'creer')) {
var supplier_ref = $('option:selected', this).attr('data-supplier-ref'); // When select is done from HTML select
if (typeof supplier_ref === 'undefined') { supplier_ref = jQuery('#idprodfournprice').attr('data-supplier-ref');} // When select is done from HTML input with ajax autocomplete
- console.log("objectline_create.tpl We find supplier price : up = "+up+", up_locale = "+up_locale+", supplier_ref = "+supplier_ref+" qty = "+qty+", tva_tx = "+tva_tx+", default_vat_code = "+default_vat_code+", stringforvatrateselection="+stringforvatrateselection+", discount = "+discount+" for product supplier ref id = "+jQuery('#idprodfournprice').val());
+ var has_multicurrency_up = false;
+ multicurrency_code != $conf->currency) {
+ ?>
+ var object_multicurrency_code = 'multicurrency_code); ?>';
- if (typeof up_locale === 'undefined') {
- jQuery("#price_ht").val(up);
- } else {
- jQuery("#price_ht").val(up_locale);
+ var multicurrency_code = $('option:selected', this).attr('data-multicurrency-code'); // When select is done from HTML select
+ if (multicurrency_code == undefined) { multicurrency_code = jQuery('#idprodfournprice').attr('data-multicurrency-code'); } // When select is done from HTML input with ajax autocomplete
+
+ var multicurrency_up = parseFloat($('option:selected', this).attr('data-multicurrency-unitprice')); // When select is done from HTML select
+ if (isNaN(multicurrency_up)) { multicurrency_up = parseFloat(jQuery('#idprodfournprice').attr('data-multicurrency-unitprice')); } // When select is done from HTML input with ajax autocomplete
+
+ if (multicurrency_code == object_multicurrency_code) {
+ has_multicurrency_up = true;
+ jQuery("#multicurrency_price_ht").val(multicurrency_up);
+ }
+
+ console.log("objectline_create.tpl Multicurrency values : object_multicurrency_code = "+object_multicurrency_code+", multicurrency_code = "+multicurrency_code+", multicurrency_up = "+multicurrency_up);
+
+
+ console.log("objectline_create.tpl We find supplier price : up = "+up+", up_locale = "+up_locale+", has_multicurrency_up = "+has_multicurrency_up+", supplier_ref = "+supplier_ref+" qty = "+qty+", tva_tx = "+tva_tx+", default_vat_code = "+default_vat_code+", stringforvatrateselection="+stringforvatrateselection+", discount = "+discount+" for product supplier ref id = "+jQuery('#idprodfournprice').val());
+
+ if (has_multicurrency_up === false) {
+ if (typeof up_locale === 'undefined') {
+ jQuery("#price_ht").val(up);
+ } else {
+ jQuery("#price_ht").val(up_locale);
+ }
}
// Set supplier_ref