FIX autocalculation of the supplier price in main currency.

This commit is contained in:
Laurent Destailleur 2021-09-16 13:17:00 +02:00
parent 9918873719
commit f26601e836

View File

@ -651,43 +651,45 @@ if ($id > 0 || $ref) {
print '</td></tr>'; print '</td></tr>';
$currencies = array(); $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); $resql = $db->query($sql);
if ($resql) { if ($resql) {
$currency = new MultiCurrency($db); $currency = new MultiCurrency($db);
while ($obj = $db->fetch_object($resql)) { while ($obj = $db->fetch_object($resql)) {
$currency->fetch($obj->rowid); $currency->fetch($obj->rowid);
$currencies[$currency->code] = $currency->rate->rate; $currencies[$currency->code] = ((float) $currency->rate->rate);
} }
} }
$currencies = json_encode($currencies); $currencies = json_encode($currencies);
print <<<END print <<<END
<!-- javascript to autocalculate the minimum price -->
<script type="text/javascript"> <script type="text/javascript">
function update_price_from_multicurrency() { function update_price_from_multicurrency() {
var multicurrency_price = $('input[name="multicurrency_price"]').val(); console.log("update_price_from_multicurrency");
var multicurrency_tx = $('input[name="multicurrency_tx"]').val(); 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="price"]').val(multicurrency_price / multicurrency_tx);
$('input[name="disabled_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 () { jQuery(document).ready(function () {
$('input[name="disabled_price"]').prop('disabled', true); $('input[name="disabled_price"]').prop('disabled', true);
$('select[name="disabled_price_base_type"]').prop('disabled', true); $('select[name="disabled_price_base_type"]').prop('disabled', true);
update_price_from_multicurrency(); update_price_from_multicurrency();
$('input[name="multicurrency_price"]').keyup(function () { $('input[name="multicurrency_price"], input[name="multicurrency_tx"]').keyup(function () {
update_price_from_multicurrency();
}).change(function () {
update_price_from_multicurrency();
}).on('paste', function () {
update_price_from_multicurrency(); update_price_from_multicurrency();
}); });
$('input[name="multicurrency_price"], input[name="multicurrency_tx"]').change(function () {
$('input[name="multicurrency_tx"]').keyup(function () {
update_price_from_multicurrency(); update_price_from_multicurrency();
}).change(function () { });
update_price_from_multicurrency(); $('input[name="multicurrency_price"], input[name="multicurrency_tx"]').on('paste', function () {
}).on('paste', function () {
update_price_from_multicurrency(); update_price_from_multicurrency();
}); });
@ -698,7 +700,9 @@ if ($id > 0 || $ref) {
var currencies_array = $currencies; var currencies_array = $currencies;
$('select[name="multicurrency_code"]').change(function () { $('select[name="multicurrency_code"]').change(function () {
console.log("We change the currency");
$('input[name="multicurrency_tx"]').val(currencies_array[$(this).val()]); $('input[name="multicurrency_tx"]').val(currencies_array[$(this).val()]);
update_price_from_multicurrency();
}); });
}); });
</script> </script>