View | Details | Raw Unified | Return to bug 12310
Collapse All | Expand All

(-)a/installer/data/mysql/atomicupdate/bug12310_add_DecimalSeparators.sql (+2 lines)
Line 0 Link Here
1
INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
2
('DecimalSeparators',  ',.', NULL ,  'The allowed separators between entire and decimal parts of numbers',  'Free');
(-)a/installer/data/mysql/sysprefs.sql (+1 lines)
Lines 140-145 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
140
('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'),
140
('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'),
141
('DefaultToLoggedInLibraryOverdueTriggers',  '0', NULL ,  'If enabled, overdue status triggers editor will default to the logged in library''s rules, rather than the ''default'' rules.',  'YesNo'),
141
('DefaultToLoggedInLibraryOverdueTriggers',  '0', NULL ,  'If enabled, overdue status triggers editor will default to the logged in library''s rules, rather than the ''default'' rules.',  'YesNo'),
142
('delimiter',';',';|tabulation|,|/|\\|#||','Define the default separator character for exporting reports','Choice'),
142
('delimiter',';',';|tabulation|,|/|\\|#||','Define the default separator character for exporting reports','Choice'),
143
('DecimalSeparators',  '.,', NULL ,  'The allowed separators between entire and decimal parts of numbers',  'Free'),
143
('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'),
144
('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'),
144
('DisplayClearScreenButton','0','','If set to ON, a clear screen button will appear on the circulation page.','YesNo'),
145
('DisplayClearScreenButton','0','','If set to ON, a clear screen button will appear on the circulation page.','YesNo'),
145
('displayFacetCount','0',NULL,NULL,'YesNo'),
146
('displayFacetCount','0',NULL,NULL,'YesNo'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/decimal-input-js.inc (+47 lines)
Line 0 Link Here
1
[% USE Koha %]
2
[% USE JSON.Escape %]
3
4
<script type="text/javascript">
5
var decimal = (function() {
6
7
    var is_decimal = function(input) {
8
        // JSON escaping to handle the strange case of " in the syspref
9
        var separators = [% Koha.Preference('DecimalSeparators').json %];
10
        var regex = "[0-9]{1,}(["+separators+"][0-9]{1,}|)";
11
        var decimal = new RegExp(regex);
12
        if (decimal.test(input)) {
13
            return true;
14
        }
15
        return false;
16
    }
17
18
    var decimal_from_string = function(formatted_decimal) {
19
        // remove everything except digits, minuses, and the chars in DecimalSeparators syspref
20
        var formatted_decimal = formatted_decimal
21
                              .replace(/[^0-9-[% Koha.Preference('DecimalSeparators') %]]/g, '');
22
        var decimal = formatted_decimal
23
                    .replace(/[[% Koha.Preference('DecimalSeparators') %]]/g, '.');
24
        return decimal;
25
    }
26
27
    return {
28
        /**
29
         * Handler made to process an <input> field containing a decimal number
30
         * to unformat it. So it can be processed by the server without having
31
         * to care about decimal separators (see DecimalSeparators syspref) and
32
         * currency symbols for example.
33
         */
34
        handler_unformat_input: function(field) {
35
            if (is_decimal(field.value)) {
36
                field.value = decimal_from_string(field.value);
37
            }
38
        }
39
    };
40
41
})();
42
43
// equivalent of $(document).ready, jQuery hasn't load yet so vanilla JS version
44
document.addEventListener("DOMContentLoaded", function() {
45
    $(".decimal-unformating").on("change", function() {decimal.handler_unformat_input(this)});
46
});
47
</script>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/acquisitions.pref (-1 / +1 lines)
Lines 28-34 Acquisitions: Link Here
28
                  branch: from staff member's library.
28
                  branch: from staff member's library.
29
                  all: in system, regardless of owner.
29
                  all: in system, regardless of owner.
30
        -
30
        -
31
            - Display currencies using the following format
31
            - Display currencies using the following format. It you want to choose the possible decimal separators for price input, please use the system preference 'DecimalSeparators'.
32
            - pref: CurrencyFormat
32
            - pref: CurrencyFormat
33
              choices:
33
              choices:
34
                  US: 360,000.00 (US)
34
                  US: 360,000.00 (US)
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/i18n_l10n.pref (+4 lines)
Lines 68-70 I18N/L10N: Link Here
68
              no: "Don't allow"
68
              no: "Don't allow"
69
        - notices to be translated.
69
        - notices to be translated.
70
        - 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.
70
        - 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.
71
    -
72
        - "Any of these characters can be used as a 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'"
73
        - pref: DecimalSeparators
74
          class: long
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/mancredit.tt (-1 / +3 lines)
Lines 6-11 Link Here
6
[% INCLUDE 'doc-head-open.inc' %]
6
[% INCLUDE 'doc-head-open.inc' %]
7
<title>Koha &rsaquo; Patrons &rsaquo; Create manual credit</title>
7
<title>Koha &rsaquo; Patrons &rsaquo; Create manual credit</title>
8
[% INCLUDE 'doc-head-close.inc' %]
8
[% INCLUDE 'doc-head-close.inc' %]
9
[% INCLUDE 'decimal-input-js.inc' %]
9
</head>
10
</head>
10
11
11
<body id="pat_mancredit" class="pat">
12
<body id="pat_mancredit" class="pat">
Lines 44-50 Link Here
44
	<li><label for="barcode">Barcode: </label><input type="text" name="barcode" id="barcode" /></li>
45
	<li><label for="barcode">Barcode: </label><input type="text" name="barcode" id="barcode" /></li>
45
	<li><label for="desc">Description: </label><input type="text" name="desc" size="50" id="desc" /></li>
46
	<li><label for="desc">Description: </label><input type="text" name="desc" size="50" id="desc" /></li>
46
    <li><label for="note">Note: </label><input type="text" name="note" size="50" id="note" /></li>
47
    <li><label for="note">Note: </label><input type="text" name="note" size="50" id="note" /></li>
47
    <li><label for="amount">Amount: </label><input type="number" name="amount" id="amount" required="required" value="" step="any" min="0" /> Example: 5.00</li>
48
    <li><label for="amount">Amount: </label><input name="amount" id="amount" class="decimal-unformating" required="required" value="" step="any" min="0" /></li>
49
48
</ol></fieldset>
50
</ol></fieldset>
49
51
50
<fieldset class="action"><input type="submit" name="add" value="Add credit" /> <a class="cancel" href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% patron.borrowernumber | html %]">Cancel</a></fieldset>
52
<fieldset class="action"><input type="submit" name="add" value="Add credit" /> <a class="cancel" href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% patron.borrowernumber | html %]">Cancel</a></fieldset>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/maninvoice.tt (-1 / +2 lines)
Lines 57-63 Link Here
57
	<li><label for="barcode">Barcode: </label><input type="text" name="barcode" id="barcode" /></li>
57
	<li><label for="barcode">Barcode: </label><input type="text" name="barcode" id="barcode" /></li>
58
	<li><label for="desc">Description: </label><input type="text" name="desc" id="desc" size="50" /></li>
58
	<li><label for="desc">Description: </label><input type="text" name="desc" id="desc" size="50" /></li>
59
    <li><label for="note">Note: </label><input type="text" name="note" size="50" id="note" /></li>
59
    <li><label for="note">Note: </label><input type="text" name="note" size="50" id="note" /></li>
60
    <li><label for="amount">Amount: </label><input type="number" name="amount" id="amount" required="required" value="" step="any" min="0" /> Example: 5.00</li>
60
    <li><label for="amount">Amount: </label><input type="text" name="amount" id="amount" class="decimal-unformating" required="required"/></li>
61
	</ol></fieldset>
61
	</ol></fieldset>
62
<fieldset class="action"><input type="submit" name="add" value="Save" /> <a class="cancel" href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% patron.borrowernumber | html %]">Cancel</a></fieldset>
62
<fieldset class="action"><input type="submit" name="add" value="Save" /> <a class="cancel" href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% patron.borrowernumber | html %]">Cancel</a></fieldset>
63
</form>
63
</form>
Lines 73-78 Link Here
73
</div>
73
</div>
74
</div>
74
</div>
75
75
76
[% INCLUDE 'decimal-input-js.inc' %]
76
[% MACRO jsinclude BLOCK %]
77
[% MACRO jsinclude BLOCK %]
77
    [% INCLUDE 'str/members-menu.inc' %]
78
    [% INCLUDE 'str/members-menu.inc' %]
78
    [% Asset.js("js/members-menu.js") | $raw %]
79
    [% Asset.js("js/members-menu.js") | $raw %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt (-53 / +4 lines)
Lines 101-107 Link Here
101
    <li>
101
    <li>
102
        <label for="paid">Collect from patron: </label>
102
        <label for="paid">Collect from patron: </label>
103
            <!-- default to paying all -->
103
            <!-- default to paying all -->
104
        <input name="paid" id="paid" value="[% amountoutstanding | html %]" />
104
        <input name="paid" id="paid" class="decimal-unformating" value="[% amountoutstanding | html %]" />
105
    </li>
105
    </li>
106
    [% SET payment_types = AuthorisedValues.GetAuthValueDropbox('PAYMENT_TYPE') %]
106
    [% SET payment_types = AuthorisedValues.GetAuthValueDropbox('PAYMENT_TYPE') %]
107
    [% IF payment_types %]
107
    [% IF payment_types %]
Lines 198-204 Link Here
198
            <label for="paid">Collect from patron: </label>
198
            <label for="paid">Collect from patron: </label>
199
        [% END %]
199
        [% END %]
200
        <!-- default to paying all -->
200
        <!-- default to paying all -->
201
        <input name="paid" id="paid" value="[% total | format('%.2f') %]" />
201
        <input name="paid" id="paid" class="decimal-unformating" value="[% total | format('%.2f') %]" />
202
    </li>
202
    </li>
203
    [% SET payment_types = AuthorisedValues.GetAuthValueDropbox('PAYMENT_TYPE') %]
203
    [% SET payment_types = AuthorisedValues.GetAuthValueDropbox('PAYMENT_TYPE') %]
204
    [% IF payment_types %]
204
    [% IF payment_types %]
Lines 239-247 Link Here
239
    <script type= "text/javascript">
239
    <script type= "text/javascript">
240
        $(document).ready(function() {
240
        $(document).ready(function() {
241
            $('#payindivfine, #payfine').preventDoubleFormSubmit();
241
            $('#payindivfine, #payfine').preventDoubleFormSubmit();
242
            $("#paid").on("change",function(){
243
                moneyFormat( this );
244
            });
245
        });
242
        });
246
243
247
        prevent_default = 1;
244
        prevent_default = 1;
Lines 262-316 Link Here
262
            }
259
            }
263
        });
260
        });
264
261
265
        function moneyFormat(textObj) {
262
    </script>
266
            var newValue = textObj.value;
267
            var decAmount = "";
268
            var dolAmount = "";
269
            var decFlag   = false;
270
            var aChar     = "";
271
272
            for(i=0; i < newValue.length; i++) {
273
                aChar = newValue.substring(i, i+1);
274
                if (aChar >= "0" && aChar <= "9") {
275
                    if(decFlag) {
276
                        decAmount = "" + decAmount + aChar;
277
                    }
278
                    else {
279
                        dolAmount = "" + dolAmount + aChar;
280
                    }
281
                }
282
                if (aChar == ".") {
283
                    if (decFlag) {
284
                        dolAmount = "";
285
                        break;
286
                    }
287
                    decFlag = true;
288
                }
289
            }
290
263
291
            if (dolAmount == "") {
264
    [% INCLUDE 'decimal-input-js.inc' %]
292
                dolAmount = "0";
293
            }
294
        // Strip leading 0s
295
            if (dolAmount.length > 1) {
296
                while(dolAmount.length > 1 && dolAmount.substring(0,1) == "0") {
297
                    dolAmount = dolAmount.substring(1,dolAmount.length);
298
                }
299
            }
300
            if (decAmount.length > 2) {
301
                decAmount = decAmount.substring(0,2);
302
            }
303
        // Pad right side
304
            if (decAmount.length == 1) {
305
               decAmount = decAmount + "0";
306
            }
307
            if (decAmount.length == 0) {
308
               decAmount = decAmount + "00";
309
            }
310
265
311
            textObj.value = dolAmount + "." + decAmount;
312
        }
313
    </script>
314
[% END %]
266
[% END %]
315
267
316
[% INCLUDE 'intranet-bottom.inc' %]
268
[% INCLUDE 'intranet-bottom.inc' %]
317
- 

Return to bug 12310