FIX autocalculation of the supplier price in main currency.
This commit is contained in:
parent
9918873719
commit
f26601e836
@ -623,7 +623,7 @@ if ($id > 0 || $ref) {
|
||||
// Currency
|
||||
print '<tr><td class="fieldrequired">'.$langs->trans("Currency").'</td>';
|
||||
print '<td>';
|
||||
$currencycodetouse = GETPOST('multicurrency_code') ?GETPOST('multicurrency_code') : (isset($object->fourn_multicurrency_code) ? $object->fourn_multicurrency_code : '');
|
||||
$currencycodetouse = GETPOST('multicurrency_code') ? GETPOST('multicurrency_code') : (isset($object->fourn_multicurrency_code) ? $object->fourn_multicurrency_code : '');
|
||||
if (empty($currencycodetouse) && $object->fourn_multicurrency_tx == 1) {
|
||||
$currencycodetouse = $conf->currency;
|
||||
}
|
||||
@ -635,7 +635,7 @@ if ($id > 0 || $ref) {
|
||||
|
||||
// Currency price qty min
|
||||
print '<tr><td class="fieldrequired">'.$langs->trans("PriceQtyMinCurrency").'</td>';
|
||||
$pricesupplierincurrencytouse = (GETPOST('multicurrency_price') ?GETPOST('multicurrency_price') : (isset($object->fourn_multicurrency_price) ? $object->fourn_multicurrency_price : ''));
|
||||
$pricesupplierincurrencytouse = (GETPOST('multicurrency_price') ? GETPOST('multicurrency_price') : (isset($object->fourn_multicurrency_price) ? $object->fourn_multicurrency_price : ''));
|
||||
print '<td><input class="flat" name="multicurrency_price" size="8" value="'.price($pricesupplierincurrencytouse).'">';
|
||||
print ' ';
|
||||
print $form->selectPriceBaseType((GETPOST('multicurrency_price_base_type') ?GETPOST('multicurrency_price_base_type') : 'HT'), "multicurrency_price_base_type"); // We keep 'HT' here, multicurrency_price_base_type is not yet supported for supplier prices
|
||||
@ -651,43 +651,45 @@ if ($id > 0 || $ref) {
|
||||
print '</td></tr>';
|
||||
|
||||
$currencies = array();
|
||||
$sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'multicurrency WHERE entity = '.$conf->entity;
|
||||
$sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'multicurrency WHERE entity = '.((int) $conf->entity);
|
||||
$resql = $db->query($sql);
|
||||
if ($resql) {
|
||||
$currency = new MultiCurrency($db);
|
||||
while ($obj = $db->fetch_object($resql)) {
|
||||
$currency->fetch($obj->rowid);
|
||||
$currencies[$currency->code] = $currency->rate->rate;
|
||||
$currencies[$currency->code] = ((float) $currency->rate->rate);
|
||||
}
|
||||
}
|
||||
$currencies = json_encode($currencies);
|
||||
|
||||
print <<<END
|
||||
<!-- javascript to autocalculate the minimum price -->
|
||||
<script type="text/javascript">
|
||||
function update_price_from_multicurrency() {
|
||||
var multicurrency_price = $('input[name="multicurrency_price"]').val();
|
||||
var multicurrency_tx = $('input[name="multicurrency_tx"]').val();
|
||||
$('input[name="price"]').val(multicurrency_price / multicurrency_tx);
|
||||
$('input[name="disabled_price"]').val(multicurrency_price / multicurrency_tx);
|
||||
console.log("update_price_from_multicurrency");
|
||||
var multicurrency_price = price2numjs($('input[name="multicurrency_price"]').val());
|
||||
var multicurrency_tx = price2numjs($('input[name="multicurrency_tx"]').val());
|
||||
if (multicurrency_tx != 0) {
|
||||
$('input[name="price"]').val(multicurrency_price / multicurrency_tx);
|
||||
$('input[name="disabled_price"]').val(multicurrency_price / multicurrency_tx);
|
||||
} else {
|
||||
$('input[name="price"]').val('');
|
||||
$('input[name="disabled_price"]').val('');
|
||||
}
|
||||
}
|
||||
|
||||
jQuery(document).ready(function () {
|
||||
$('input[name="disabled_price"]').prop('disabled', true);
|
||||
$('select[name="disabled_price_base_type"]').prop('disabled', true);
|
||||
update_price_from_multicurrency();
|
||||
|
||||
$('input[name="multicurrency_price"]').keyup(function () {
|
||||
update_price_from_multicurrency();
|
||||
}).change(function () {
|
||||
update_price_from_multicurrency();
|
||||
}).on('paste', function () {
|
||||
$('input[name="multicurrency_price"], input[name="multicurrency_tx"]').keyup(function () {
|
||||
update_price_from_multicurrency();
|
||||
});
|
||||
|
||||
$('input[name="multicurrency_tx"]').keyup(function () {
|
||||
$('input[name="multicurrency_price"], input[name="multicurrency_tx"]').change(function () {
|
||||
update_price_from_multicurrency();
|
||||
}).change(function () {
|
||||
update_price_from_multicurrency();
|
||||
}).on('paste', function () {
|
||||
});
|
||||
$('input[name="multicurrency_price"], input[name="multicurrency_tx"]').on('paste', function () {
|
||||
update_price_from_multicurrency();
|
||||
});
|
||||
|
||||
@ -698,7 +700,9 @@ if ($id > 0 || $ref) {
|
||||
|
||||
var currencies_array = $currencies;
|
||||
$('select[name="multicurrency_code"]').change(function () {
|
||||
console.log("We change the currency");
|
||||
$('input[name="multicurrency_tx"]').val(currencies_array[$(this).val()]);
|
||||
update_price_from_multicurrency();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user