Commit 01cde5d3 authored by Baptiste Wojtkowski's avatar Baptiste Wojtkowski Committed by Victor Grousset

Bug 12310 : Decimal separators issues: some fixes in fines and acquisitions

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.
parent 2201fda6
INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
('DecimalSeparators', ',.', NULL , 'The allowed separators between entire and decimal parts of numbers', 'Free');
......@@ -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'),
......
[% USE Koha %]
[% USE JSON.Escape %]
<script type="text/javascript">
var decimal = (function() {
var is_decimal = function(input) {
// JSON escaping to handle the strange case of " in the syspref
var separators = [% Koha.Preference('DecimalSeparators').json %];
var regex = "[0-9]{1,}(["+separators+"][0-9]{1,}|)";
var decimal = new RegExp(regex);
if (decimal.test(input)) {
return true;
}
return false;
}
var decimal_from_string = function(formatted_decimal) {
if (!is_decimal(formatted_decimal)) {
return false;
}
// remove everything except digits, minuses, and the chars in DecimalSeparators syspref
var formatted_decimal = formatted_decimal
.replace(/[^0-9-[% Koha.Preference('DecimalSeparators') %]]/g, '');
var decimal = formatted_decimal
.replace(/[[% Koha.Preference('DecimalSeparators') %]]/g, '.');
return decimal;
}
return {
/**
* Handler made to process an <input> field containing a decimal number
* to unformat it. So it can be processed by the server without having
* to care about decimal separators (see DecimalSeparators syspref) and
* currency symbols for example.
*/
handler_unformat_input: function(field) {
if (is_decimal(field.value)) {
field.value = decimal_from_string(field.value);
}
}
};
})();
</script>
[% USE KohaDates %]
[% USE Price %]
[% USE Koha %]
[% SET footerjs = 1 %]
[%- BLOCK action_menu %]
<div class="dropdown">
<a class="btn btn-default btn-xs dropdown-toggle" id="budgetmenu_[% block_budget.budget_period_id %]" role="button" data-toggle="dropdown" href="#">
......@@ -33,6 +35,7 @@
[% END -%]
[% INCLUDE 'doc-head-open.inc' %]
[% INCLUDE 'decimal-input-js.inc' %]
[% INCLUDE 'doc-head-close.inc' %]
<link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables_[% KOHA_VERSION %].css" />
[% IF close_form %]
......@@ -243,7 +246,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>
......@@ -528,6 +531,7 @@
alert(alertString);
}
}
function Check(f) {
var ok=1;
var _alertString="";
......@@ -577,6 +581,9 @@
'bAutoWidth': false
} ) );
[% IF add_form %]
$("#budget_period_total").on("change", function(){decimal.handler_unformat_input(this)});
[% END %]
[% IF close_form %]
$("#budgeth").dataTable($.extend(true, {}, dataTablesDefaults, {
sDom: "t"
......
[% USE AuthorisedValues %]
[% USE Branches %]
[% USE Price %]
[% USE Koha %]
[% SET footerjs = 1 %]
[% INCLUDE 'doc-head-open.inc' %]
<title>Koha &rsaquo; Administration &rsaquo; Funds[% IF op == 'add_form' %] &rsaquo; [% IF ( budget_id ) %]Modify fund[% IF ( budget_name ) %] '[% budget_name %]'[% END %][% ELSE %]Add fund [% END %][% END %]</title>
......@@ -243,7 +244,7 @@
<li>
<label for="budget_expend">Warning at (amount): </label>
<input type="text" name="budget_expend" id="budget_expend" value="[% budget_expend | $Price on_editing => 1 %]" size="10" />
<span class="hint">0 to disable</span>
<span class="hint">0 to disable.</span>
</li>
<li>
......@@ -449,6 +450,7 @@
<script type="text/javascript" src="[% interface %]/[% theme %]/js/acq_[% KOHA_VERSION %].js"></script>
[% IF op == 'add_form' %]
[% INCLUDE 'decimal-input-js.inc' %]
<script type="text/javascript">
//<![CDATA[
......@@ -563,7 +565,7 @@
}
}
// else do lookup
// else do lookup
var budgetTotal = Math.abs(f.budget_amount.value);
var result = budgetExceedsParent (budgetTotal, budgetId, newBudgetParent, f.budget_period_id.value)
if (result) {
......@@ -579,7 +581,12 @@
alert(alertString2);
}
}
$(document).ready(function(){
$('#budget_expend').on('change', function(){decimal.handler_unformat_input(this)});
$('#budget_amount').on('change', function(){decimal.handler_unformat_input(this)});
$("#remove_owner").on("click",function(e){
e.preventDefault();
ownerRemove();
......@@ -692,5 +699,5 @@
//]]>
</script>
[% END %]
[% END %]
[% END %][%# end of MACRO jsinclude %]
[% INCLUDE 'intranet-bottom.inc' %]
......@@ -28,7 +28,7 @@ Acquisitions:
branch: from staff member's library.
all: in system, regardless of owner.
-
- Display currencies using the following format
- Display currencies using the following format. It you want to choose the possible decimal separators for price input, please use the system preference 'DecimalSeparators'.
- pref: CurrencyFormat
choices:
US: 360,000.00 (US)
......
......@@ -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.
-
- "Any of these characters can be used as separator between integer and decimal parts in the price fields. To work well with thousands separators you must (usually) choose between dot and comma to avoid ambiguity. So thousands separators come at the expense of handling both dots and commas. It you want to format price output, please use the system preference 'CurrencyFormat'"
- pref: DecimalSeparators
class: long
......@@ -3,9 +3,11 @@
[% INCLUDE 'doc-head-open.inc' %]
<title>Koha &rsaquo; Patrons &rsaquo; Create manual credit</title>
[% INCLUDE 'doc-head-close.inc' %]
[% INCLUDE 'decimal-input-js.inc' %]
</head>
<body id="pat_mancredit" class="pat">
[% INCLUDE 'header.inc' %]
[% INCLUDE 'patron-search.inc' %]
......@@ -33,14 +35,15 @@
<fieldset class="rows">
<legend>Manual credit</legend><ol>
<li><label for="type">Credit type: </label><select name="type" id="type">
<li><label for="type">Credit type: </label><select name="type" id="type">
<option value="C">Credit</option>
<option value="FOR">Forgiven</option>
</select></li>
<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" size="50" id="desc" /></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="barcode">Barcode: </label><input type="text" name="barcode" id="barcode" /></li>
<li><label for="desc">Description: </label><input type="text" name="desc" size="50" id="desc" /></li>
<li><label for="note">Note: </label><input type="text" name="note" size="50" id="note" /></li>
<li><label for="amount">Amount: </label><input name="amount" id="amount" required="required" value="" step="any" min="0" /></li>
</ol></fieldset>
<fieldset class="action"><input type="submit" name="add" value="Add credit" /> <a class="cancel" href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% patron.borrowernumber %]">Cancel</a></fieldset>
......@@ -62,6 +65,7 @@
$(document).ready(function(){
$('#mancredit').preventDoubleFormSubmit();
$("fieldset.rows input, fieldset.rows select").addClass("noEnterSubmit");
$('#amount').on('change', function(){decimal.handler_unformat_input(this)});
});
</script>
[% END %]
......
......@@ -53,7 +53,7 @@
<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"/></li>
</ol></fieldset>
<fieldset class="action"><input type="submit" name="add" value="Save" /> <a class="cancel" href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% patron.borrowernumber %]">Cancel</a></fieldset>
</form>
......@@ -69,6 +69,7 @@
</div>
</div>
[% INCLUDE 'decimal-input-js.inc' %]
[% MACRO jsinclude BLOCK %]
<script type="text/javascript" src="[% interface %]/[% theme %]/js/members-menu_[% KOHA_VERSION %].js"></script>
<script type="text/javascript">
......@@ -83,8 +84,10 @@
this.form.desc.value = this.options[this.selectedIndex].value;
this.form.amount.value = type_fees[this.options[this.selectedIndex].value];
});
$('#amount').on('change', function(){decimal.handler_unformat_input(this)});
});
</script>
[% END %]
[% INCLUDE 'intranet-bottom.inc' %]
......@@ -83,7 +83,7 @@
<li>
<label for="paid">Collect from patron: </label>
<!-- default to paying all -->
<input name="paid" id="paid" value="[% amountoutstanding %]" />
<input name="paid" id="paid" value="[% amountoutstanding %]" onchange="decimal.handler_unformat_input(document.payindivfine.paid)"/>
</li>
</ol>
</fieldset>
......@@ -150,7 +150,7 @@
<li>
<label for="paid">Collect from patron: </label>
<!-- default to paying all -->
<input name="paid" id="paid" value="[% total | format('%.2f') %]" />
<input name="paid" id="paid" value="[% total | format('%.2f') %]" onchange="decimal.handler_unformat_input(document.payfine.paid)"/>
</li>
<li>
<label for="selected_accts_notes">Note: </label>
......@@ -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;
}
</script>
[% INCLUDE 'decimal-input-js.inc' %]
[% END %]
[% INCLUDE 'intranet-bottom.inc' %]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment