From de24a9ce140f688cfdd957a1466ac675d4a0aaf2 Mon Sep 17 00:00:00 2001 From: Baptiste Wojtkowski Date: Tue, 21 Feb 2017 15:47:36 +0000 Subject: [PATCH] Bug 12310 : Decimal separators issues: some fixes in fines and acquisitions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The main aim is to prevent - x100 or /100 of the amounts - decimal part truncation Fixes Bug 19521 - Partial fine payment is not working with comma decimal separator But not Bug 18723 - Dot not recognized as decimal separator (aquisitions) It will be done in a follow up patch. This one is already too huge to test. Bonuses: - get rid of the spaces, currency symbols, names (EUR) It handles: - by default comma and dot as decimal separators on the same instance - dot or comma as thousands separators if choose to use only one of them as decimal separator. See DigitSeparator syspref. == Test plan == 1. In the manual invoice (cgi-bin/koha/members/maninvoice.pl) 2. Apply the annex 1 to the "Amount" field 3. When paying a fine (cgi-bin/koha/members/paycollect.pl) 4. Click on "Pay amount" to go to the page to pay all fines 5. Apply the annex 1 to the "Collect from patron" field 6. Click on "Pay" to go to the page to pay fine 7. Apply the annex 1 to the "Collect from patron" field 8. Go to "Create manual credit" (staff://cgi-bin/koha/members/mancredit.pl) 9. Apply the annex 1 to the "Amount" field 10. Go to the "Add budget" page staff://cgi-bin/koha/admin/aqbudgetperiods.pl?op=add_form 11. Apply the annex 1 to the "Total amount" field 12. Create an active budget 13. Go to the "Add Fund" page for this budget 14. Apply the annex 1 to the "Amount" field 15. Apply the annex 1 to the "Warning at (amount)" field 16. If you have ideas of stuff to try to find *regressions* from the previous versions, then try. You might spare librarian tears by finding something before it's released. 17. Express your happiness. This is important, otherwise the signoff spell won't work! The details of expressing your happinnes depends on your culture and habits. === Annex 1: Subpart for each concerned page === 1. Set DigitSeparator syspref to ",." 2. Input "12,34" 3. Press the "Tab/Tabulation" key. It will unfocus the field and trigger the conversion. Validating the form does the same but it's a trick to test more quickly by not changing the page. 4. Ensure that it's converted to 12.34 5. Do the same with "12.34 EUR" and ensure that it's converted to "12.34" 6. Same with "EUR 12.34" → "12.34" 7. "123 456,7" → "123456.7" 8. "EUR 12.34 hi lyon3" → "12.34" 9. "2" → "2" 10. "2,0" → "2.0" XX. TODO WIP thousands sep and other relevant cases XX. Finally validate the form and check that the final value with the dot was well handled. XX. Thinks about Koalas and smile. --- .../bug12310_add_DecimalSeparators.sql | 2 + installer/data/mysql/sysprefs.sql | 1 + .../prog/en/includes/decimal-input-js.inc | 45 ++++++++++++++++++++++ .../prog/en/modules/admin/aqbudgetperiods.tt | 8 +++- .../prog/en/modules/admin/aqbudgets.tt | 13 +++++-- .../en/modules/admin/preferences/acquisitions.pref | 2 +- .../en/modules/admin/preferences/i18n_l10n.pref | 4 ++ .../prog/en/modules/members/mancredit.tt | 14 ++++--- .../prog/en/modules/members/maninvoice.tt | 5 ++- .../prog/en/modules/members/paycollect.tt | 29 +++----------- 10 files changed, 87 insertions(+), 36 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug12310_add_DecimalSeparators.sql create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/decimal-input-js.inc diff --git a/installer/data/mysql/atomicupdate/bug12310_add_DecimalSeparators.sql b/installer/data/mysql/atomicupdate/bug12310_add_DecimalSeparators.sql new file mode 100644 index 0000000..e25582d --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug12310_add_DecimalSeparators.sql @@ -0,0 +1,2 @@ +INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES +('DecimalSeparators', ',.', NULL , 'The allowed separators between entire and decimal parts of numbers', 'Free'); diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 76bb2cc..3047f7a 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -138,6 +138,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('DefaultToLoggedInLibraryNoticesSlips', '0', NULL , 'If enabled,slips and notices editor will default to the logged in library''s rules, rather than the ''all libraries'' rules.', 'YesNo'), ('DefaultToLoggedInLibraryOverdueTriggers', '0', NULL , 'If enabled, overdue status triggers editor will default to the logged in library''s rules, rather than the ''default'' rules.', 'YesNo'), ('delimiter',';',';|tabulation|,|/|\\|#||','Define the default separator character for exporting reports','Choice'), +('DecimalSeparators', '.,', NULL , 'The allowed separators between entire and decimal parts of numbers', 'Free'), ('Display856uAsImage','OFF','OFF|Details|Results|Both','Display the URI in the 856u field as an image, the corresponding Staff Client XSLT option must be on','Choice'), ('DisplayClearScreenButton','0','','If set to ON, a clear screen button will appear on the circulation page.','YesNo'), ('displayFacetCount','0',NULL,NULL,'YesNo'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/decimal-input-js.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/decimal-input-js.inc new file mode 100644 index 0000000..3eec80e --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/decimal-input-js.inc @@ -0,0 +1,45 @@ +[% USE Koha %] +[% USE JSON.Escape %] + + diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgetperiods.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgetperiods.tt index afd893f..58f0473 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgetperiods.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgetperiods.tt @@ -1,6 +1,8 @@ [% USE KohaDates %] [% USE Price %] +[% USE Koha %] [% SET footerjs = 1 %] + [%- BLOCK action_menu %] +[% INCLUDE 'decimal-input-js.inc' %] [% MACRO jsinclude BLOCK %] [% END %] + [% INCLUDE 'intranet-bottom.inc' %] 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 39df143..0c355b3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt @@ -83,7 +83,7 @@
  • - +
  • @@ -150,7 +150,7 @@
  • - +
  • @@ -206,30 +206,11 @@ decFlag = true; } } - - if (dolAmount == "") { - dolAmount = "0"; - } - // Strip leading 0s - if (dolAmount.length > 1) { - while(dolAmount.length > 1 && dolAmount.substring(0,1) == "0") { - dolAmount = dolAmount.substring(1,dolAmount.length); - } - } - if (decAmount.length > 2) { - decAmount = decAmount.substring(0,2); - } - // Pad right side - if (decAmount.length == 1) { - decAmount = decAmount + "0"; - } - if (decAmount.length == 0) { - decAmount = decAmount + "00"; - } - - textObj.value = dolAmount + "." + decAmount; } + + [% INCLUDE 'decimal-input-js.inc' %] + [% END %] [% INCLUDE 'intranet-bottom.inc' %] -- 2.7.4