From d8010e172fea579c5adb133f64f1d2e6f95ed26a Mon Sep 17 00:00:00 2001 From: Shi Yao Wang Date: Tue, 10 May 2022 13:34:15 -0400 Subject: [PATCH] Bug 30139: Fix javascript moneyFormat to be compatible with FR format New way of formatting money amount to make it work with FR format Test plan: 1- Set CurrencyFormat pref to FR 2- Activate Point of sale and cash register features 3- Add cash register 4- Add debit type that 'can be sold' with a price of 10.00 5- Go to point of sale, click on the item to purchase 6- Verify the Amount to be paid shows the wrong amount and can't be fixed on the interface 7- Apply the patch 8- Refresh the page and do step 5 again 9- Notice it now shows the right amount Signed-off-by: David Nind Signed-off-by: Katrin Fischer --- .../prog/en/modules/members/paycollect.tt | 31 ++++++++++--------- .../intranet-tmpl/prog/en/modules/pos/pay.tt | 27 ++++++++-------- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt index b153e3b91a..cd823fddd5 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt @@ -476,28 +476,29 @@ var newValue = textObj.value; var decAmount = ""; var dolAmount = ""; - var decFlag = false; + var dolFlag = false; var aChar = ""; - for(i=0; i < newValue.length; i++) { - aChar = newValue.substring(i, i+1); - if (aChar >= "0" && aChar <= "9") { - if(decFlag) { - decAmount = "" + decAmount + aChar; + for(var i = newValue.length; 0 < i; i--) { + aChar = newValue.substring(i-1, i); + if ("0" <= aChar && aChar <= "9") { + if(dolFlag) { + dolAmount = "" + aChar + dolAmount; } else { - dolAmount = "" + dolAmount + aChar; + decAmount = "" + aChar + decAmount; } } - if (aChar == ".") { - if (decFlag) { - dolAmount = ""; - break; - } - decFlag = true; + if (aChar == "." || aChar == ",") { + dolFlag = true; } } + if (!dolFlag) { + dolAmount = decAmount; + decAmount = ""; + } + if (dolAmount == "") { dolAmount = "0"; } @@ -512,10 +513,10 @@ } // Pad right side if (decAmount.length == 1) { - decAmount = decAmount + "0"; + decAmount = decAmount + "0"; } if (decAmount.length == 0) { - decAmount = decAmount + "00"; + decAmount = decAmount + "00"; } textObj.value = dolAmount + "." + decAmount; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/pos/pay.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/pos/pay.tt index 531869cb25..905ed4c0f0 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/pos/pay.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/pos/pay.tt @@ -203,28 +203,29 @@ var newValue = textObj.value; var decAmount = ""; var dolAmount = ""; - var decFlag = false; + var dolFlag = false; var aChar = ""; - for(var i=0; i < newValue.length; i++) { - aChar = newValue.substring(i, i+1); - if (aChar >= "0" && aChar <= "9") { - if(decFlag) { - decAmount = "" + decAmount + aChar; + for(var i = newValue.length; 0 < i; i--) { + aChar = newValue.substring(i-1, i); + if ("0" <= aChar && aChar <= "9") { + if(dolFlag) { + dolAmount = "" + aChar + dolAmount; } else { - dolAmount = "" + dolAmount + aChar; + decAmount = "" + aChar + decAmount; } } - if (aChar == ".") { - if (decFlag) { - dolAmount = ""; - break; - } - decFlag = true; + if (aChar == "." || aChar == ",") { + dolFlag = true; } } + if (!dolFlag) { + dolAmount = decAmount; + decAmount = ""; + } + if (dolAmount == "") { dolAmount = "0"; } -- 2.25.1