Skip to content

Commit

Permalink
Fix # - Discount Calculation incorrect when changing Currency
Browse files Browse the repository at this point in the history
  • Loading branch information
serhiisamko091184 committed Aug 26, 2024
1 parent 1a114a9 commit e1135af
Showing 1 changed file with 31 additions and 27 deletions.
58 changes: 31 additions & 27 deletions modules/Currencies/ListCurrency.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
<?php
if (!defined('sugarEntry') || !sugarEntry) {
die('Not A Valid Entry Point');
}
/**
*
* SugarCRM Community Edition is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
*
* SuiteCRM is an extension to SugarCRM Community Edition developed by SalesAgility Ltd.
* Copyright (C) 2011 - 2018 SalesAgility Ltd.
* Copyright (C) 2011 - 2024 SalesAgility Ltd.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
Expand Down Expand Up @@ -41,6 +38,9 @@
* display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM".
*/

if (!defined('sugarEntry') || !sugarEntry) {
die('Not A Valid Entry Point');
}

#[\AllowDynamicProperties]
class ListCurrency
Expand Down Expand Up @@ -115,50 +115,54 @@ public function getJavascript()
function get_rate(id){
return ConversionRates[id];
}
function ConvertToDollar(amount, rate){
return amount / rate;
}
function ConvertFromDollar(amount, rate){
return amount * rate;
}
function ConvertRate(id,fields){
for(var i = 0; i < fields.length; i++){
fields[i].value = toDecimal(ConvertFromDollar(toDecimal(ConvertToDollar(toDecimal(fields[i].value), lastRate)), ConversionRates[id]));
}
lastRate = ConversionRates[id];
for(var i = 0; i < fields.length; i++){
fields[i].value = toDecimal(ConvertFromDollar(toDecimal(ConvertToDollar(toDecimal(fields[i].value), lastRate)), ConversionRates[id]));
}
lastRate = ConversionRates[id];
}
function ConvertRateSingle(id,field){
var temp = field.innerHTML.substring(1, field.innerHTML.length);
unformattedNumber = unformatNumber(temp, num_grp_sep, dec_sep);
field.innerHTML = CurrencySymbols[id] + formatNumber(toDecimal(ConvertFromDollar(ConvertToDollar(unformattedNumber, lastRate), ConversionRates[id])), num_grp_sep, dec_sep, 2, 2);
lastRate = ConversionRates[id];
}
function CurrencyConvertAll(form){
try {
var id = form.currency_id.options[form.currency_id.selectedIndex].value;
var fields = new Array();
for(i in currencyFields){
var field = currencyFields[i];
if(typeof(form[field]) != 'undefined'){
form[field].value = unformatNumber(form[field].value, num_grp_sep, dec_sep);
fields.push(form[field]);
}
}
ConvertRate(id, fields);
for(i in fields){
fields[i].value = formatNumber(fields[i].value, num_grp_sep, dec_sep);
}
var id = form.currency_id.options[form.currency_id.selectedIndex].value;
var fields = new Array();
for(i in currencyFields){
var field = currencyFields[i];
if(typeof(form[field]) != 'undefined'){
form[field].value = unformatNumber(form[field].value, num_grp_sep, dec_sep);
fields.push(form[field]);
}
}
ConvertRate(id, fields);
for(i in fields){
fields[i].value = formatNumber(fields[i].value, num_grp_sep, dec_sep);
}
calculateAllLines();
} catch (err) {
// Do nothing, if we can't find the currency_id field we will just not attempt to convert currencies
// This typically only happens in lead conversion and quick creates, where the currency_id field may be named somethnig else or hidden deep inside a sub-form.
}
}
</script>
EOQ;
Expand Down

0 comments on commit e1135af

Please sign in to comment.