Bugzilla – Attachment 64672 Details for
Bug 12310
Decimal separators issues in patrons payments/fines
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
BUG 12310 : Modified scripts in order to convert any string to the good format
BUG-12310--Modified-scripts-in-order-to-convert-an.patch (text/plain), 13.57 KB, created by
Baptiste Wojtkowski (bwoj)
on 2017-06-27 08:45:23 UTC
(
hide
)
Description:
BUG 12310 : Modified scripts in order to convert any string to the good format
Filename:
MIME Type:
Creator:
Baptiste Wojtkowski (bwoj)
Created:
2017-06-27 08:45:23 UTC
Size:
13.57 KB
patch
obsolete
>From 65e0b3851eef8dd9b13827f7432a7a952a5c3303 Mon Sep 17 00:00:00 2001 >From: Baptiste Wojtkowski <baptiste.wojtkowski@biblibre.com> >Date: Tue, 21 Feb 2017 15:47:36 +0000 >Subject: [PATCH] BUG 12310 : Modified scripts in order to convert any string > to the good format > >paxed's solution is obsolete since the form asks for a number. > >The script includes 2 function which check if it is possible to transform >properly into the format "XX.XX" and which do it. >The money symbols are ignored. >All other symbols are ignored. > >Test plan : >1) Check you can't enter any string except like "XX.XX" when > - you create a Budget (Administration->Budget) > - you write a fine (Circulation->[select a Borrower]->new fine ) > - you pay an existing fine >2) Apply patch >3) Check you can enter any string with > - anything you want > - a , or a . as separator (both are default) > - change the syspref DigitSeparator into the separator you with and check again > ex : XXX,XXX,XXX.XX => . > XXX XXX XXX,XX => ,. or , > XXX XXX XXX.XX => ,. or . > The string is immediately changed after you change the field >Please note that any other symbole is ignored >--- > .../atomicupdate/bug12310_added_DigitSeparator.sql | 2 + > installer/data/mysql/sysprefs.sql | 1 + > .../intranet-tmpl/prog/en/includes/prices.inc | 25 +++++++ > .../prog/en/modules/admin/aqbudgetperiods.tt | 26 +++++++- > .../en/modules/admin/preferences/i18n_l10n.pref | 4 ++ > .../prog/en/modules/members/maninvoice.tt | 30 ++++++++- > .../prog/en/modules/members/paycollect.tt | 78 +++++++++------------- > 7 files changed, 117 insertions(+), 49 deletions(-) > create mode 100644 installer/data/mysql/atomicupdate/bug12310_added_DigitSeparator.sql > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/prices.inc > >diff --git a/installer/data/mysql/atomicupdate/bug12310_added_DigitSeparator.sql b/installer/data/mysql/atomicupdate/bug12310_added_DigitSeparator.sql >new file mode 100644 >index 0000000..5022f3c >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug12310_added_DigitSeparator.sql >@@ -0,0 +1,2 @@ >+INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES >+('DigitSeparator', ',.', NULL , 'The separator between entire and decimal part', 'Free'); >diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql >index 46093e8..4173e16 100644 >--- a/installer/data/mysql/sysprefs.sql >+++ b/installer/data/mysql/sysprefs.sql >@@ -135,6 +135,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'), >+('DigitSeparator', '.,', NULL , 'The separator between entire and decimal part', '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/prices.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/prices.inc >new file mode 100644 >index 0000000..8952845 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/prices.inc >@@ -0,0 +1,25 @@ >+[% USE Koha %] >+<script type="text/javascript"> >+//<![CDATA[ >+ >+function isPrice(string){ >+ var reg ="[% Koha.Preference('DigitSeparator') %]"; >+ reg = "[0-9]{1,}(["+reg+"][0-9]{1,}|)"; >+ var prix = new RegExp(reg); >+ if (!prix.test(string)) { >+ return false; >+ } >+ return true; >+} >+ >+function Price_from_string(string){ >+ if (!isPrice(string)) { >+ return false; >+ } >+ string = string.replace(/[^0-9[% Koha.Preference('DigitSeparator') %]]/g, ''); >+ string = string.replace(/[% Koha.Preference('DigitSeparator') %]/g, '.'); >+ return string; >+} >+ >+//]]> >+</script> >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 76f0701..97f1cfd 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgetperiods.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgetperiods.tt >@@ -1,5 +1,6 @@ > [% USE KohaDates %] > [% USE Price %] >+[% USE Koha %] > > [%- BLOCK action_menu %] > <div class="dropdown"> >@@ -27,6 +28,7 @@ > [% END -%] > > [% INCLUDE 'doc-head-open.inc' %] >+[% INCLUDE 'prices.inc' %] > <link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables.css" /> > [% INCLUDE 'doc-head-close.inc' %] > [% INCLUDE 'calendar.inc' %] >@@ -66,6 +68,25 @@ > alert(alertString); > } > } >+ function CheckTot(f){ >+ var ok=1; >+ var _alertString=""; >+ var alertString2; >+ if (!(isPrice(f.value))) { >+ _alertString += "\n- " + _("Amount must be a valid number, or empty"); >+ }else{ >+ f.value=Price_from_string(f.value); >+ } >+ if (_alertString.length==0) { >+ return true; >+ } else { >+ alertString2 = _("Form not submitted because of the following problem(s)"); >+ alertString2 += "\n------------------------------------------------------------------------------------\n"; >+ alertString2 += _alertString; >+ alert(alertString2); >+ return false; >+ } >+ } > function Check(f) { > var ok=1; > var _alertString=""; >@@ -356,7 +377,8 @@ > <!-- ############################## --> > <label for="budget_period_total">Total amount: </label> > <input type="text" id="budget_period_total" name="budget_period_total" >- size="10" maxlength="80" value="[% budget_period_total | $Price on_editing => 1 %]" /> >+ size="10" maxlength="80" value="[% budget_period_total | $Price on_editing => 1 %]" onchange="CheckTot(budget_period_total)" /> >+ Please use the "[% Koha.Preference('DigitSeparator').substr(0,1) %]" as separator : ex "XX[% Koha.Preference('DigitSeparator').substr(0,1) %]XX" > </li> > > <li> >@@ -378,7 +400,7 @@ > <fieldset class="action"> > <!-- "save changes" button --> > <!-- ###################################### --> >- <input type="button" value="Save" onclick="Check(this.form)" /> >+ <input type="button" value="Save" onclick="Check(this.form)" /> > <!-- <input type="submit" value="Save Changes" /> --> > [% IF ( budget_period_id ) %] > <a href="/cgi-bin/koha/admin/aqbudgets.pl?budget_period_id=[% budget_period_id %]" class="cancel">Cancel</a> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/i18n_l10n.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/i18n_l10n.pref >index f7f4252..fbaca49 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/i18n_l10n.pref >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/i18n_l10n.pref >@@ -66,3 +66,7 @@ I18N/L10N: > no: "Don't allow" > - notices to be translated. > - If set, notices will be translatable from the "Notices and Slips" interface. The language used to send a notice to a patron will be the one defined for the patron. >+ - >+ - "The separator used between integer and decimal part" >+ - pref: DigitSeparator >+ class: long >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/maninvoice.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/maninvoice.tt >index 8fc1f68..826df17 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/maninvoice.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/maninvoice.tt >@@ -67,7 +67,9 @@ $(document).ready(function(){ > <li><label for="barcode">Barcode: </label><input type="text" name="barcode" id="barcode" /></li> > <li><label for="desc">Description: </label><input type="text" name="desc" id="desc" size="50" /></li> > <li><label for="note">Note: </label><input type="text" name="note" size="50" id="note" /></li> >- <li><label for="amount">Amount: </label><input type="number" name="amount" id="amount" required="required" value="" step="any" min="0" /> Example: 5.00</li> >+ <li><label for="amount">Amount: </label><input type="text" name="amount" id="amount" required="required"/> >+ Please use the "[% Koha.Preference('DigitSeparator').substr(0, 1) %]" as separator : ex "XX[% Koha.Preference('DigitSeparator').substr(0,1) %]XX" >+ </li> > </ol></fieldset> > <fieldset class="action"><input type="submit" name="add" value="Save" /> <a class="cancel" href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% borrowernumber %]">Cancel</a></fieldset> > </form> >@@ -82,4 +84,30 @@ $(document).ready(function(){ > [% INCLUDE 'circ-menu.inc' %] > </div> > </div> >+ >+[% INCLUDE 'prices.inc' %] >+ >+<script type="text/javascript"> >+$('#amount').on('change', function(){Check(this)}); >+function Check(f){ >+ var ok=1; >+ var _alertString=""; >+ var alertString2; >+ if (!(isPrice(f.value))) { >+ _alertString += "\n- " + _("Amount must be a valid number, or empty"); >+ }else{ >+ f.value=Price_from_string(f.value); >+ } >+ if (_alertString.length==0) { >+ return true; >+ } else { >+ alertString2 = _("Form not submitted because of the following problem(s)"); >+ alertString2 += "\n------------------------------------------------------------------------------------\n"; >+ alertString2 += _alertString; >+ alert(alertString2); >+ return false; >+ } >+} >+</script> >+ > [% 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 1e317bc..22fdbff 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt >@@ -11,57 +11,34 @@ $(document).ready(function() { > moneyFormat( this ); > }); > }); >+//]]> >+</script> > >-function moneyFormat(textObj) { >- var newValue = textObj.value; >- var decAmount = ""; >- var dolAmount = ""; >- var decFlag = 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; >- } >- else { >- dolAmount = "" + dolAmount + aChar; >- } >- } >- if (aChar == ".") { >- if (decFlag) { >- dolAmount = ""; >- break; >- } >- 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); >+[% INCLUDE 'prices.inc' %] >+ >+<script type="text/javascript"> >+function Check(f){ >+ var ok=1; >+ var _alertString=""; >+ var alertString2; >+ if (!(isPrice(f.value))) { >+ _alertString += "\n- " + _("Amount must be a valid number, or empty"); >+ }else{ >+ f.value=Price_from_string(f.value); > } >-// Pad right side >- if (decAmount.length == 1) { >- decAmount = decAmount + "0"; >+ if (_alertString.length==0) { >+ return true; >+ } else { >+ alertString2 = _("Form not submitted because of the following problem(s)"); >+ alertString2 += "\n------------------------------------------------------------------------------------\n"; >+ alertString2 += _alertString; >+ alert(alertString2); >+ return false; > } >- if (decAmount.length == 0) { >- decAmount = decAmount + "00"; >- } >- >- textObj.value = dolAmount + "." + decAmount; > } >-//]]> > </script> >+ >+ > </head> > <body id="pat_paycollect" class="pat"> > [% INCLUDE 'header.inc' %] >@@ -146,7 +123,11 @@ function moneyFormat(textObj) { > <li> > <label for="paid">Collect from patron: </label> > <!-- default to paying all --> >+<<<<<<< 16ee11980e3d1f0c5cbd3650d3a90b7d00d971e4 > <input name="paid" id="paid" value="[% amountoutstanding | format('%.2f') %]" /> >+======= >+ <input name="paid" id="paid" value="[% amountoutstanding | format('%.2f') %]" onchange="Check(document.payindivfine.paid)"/> >+>>>>>>> BUG 12310 : Modified scripts in order to convert any string to the good format > </li> > </ol> > </fieldset> >@@ -211,7 +192,12 @@ function moneyFormat(textObj) { > <li> > <label for="paid">Collect from patron: </label> > <!-- default to paying all --> >+<<<<<<< 16ee11980e3d1f0c5cbd3650d3a90b7d00d971e4 > <input name="paid" id="paid" value="[% total | format('%.2f') %]" /> >+======= >+ <input name="paid" id="paid" value="[% total | format('%.2f') %]" onchange="Check(document.payfine.paid)"/> >+ Please use the "[% Koha.Preference('DigitSeparator') %]" as separator : ex "XX[% Koha.Preference('DigitSeparator') %]XX" >+>>>>>>> BUG 12310 : Modified scripts in order to convert any string to the good format > </li> > <li> > <label for="selected_accts_notes">Note: </label> >-- >2.7.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 12310
:
28455
|
60530
|
60563
|
61357
|
61603
|
61604
|
62655
|
64671
|
64672
|
64673
|
64674
|
64675
|
64678
|
64679
|
64696
|
72104
|
72213
|
72983
|
73055
|
73215
|
73546
|
73657
|
73784
|
73785
|
73873
|
73874
|
73880
|
74524
|
74525
|
74526
|
74527
|
74528
|
74529
|
75123
|
75127
|
75128
|
75129
|
75130
|
75947
|
75948
|
75949
|
75950
|
75951
|
75952
|
75954
|
75955
|
75956
|
75957
|
75958
|
75959
|
76896
|
76933
|
77971
|
77972
|
77973
|
77995
|
78017
|
78631
|
78632
|
78633
|
78634
|
78635
|
78636
|
78637
|
78638