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 139-144 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
139
('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'),
139
('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
('DefaultToLoggedInLibraryOverdueTriggers',  '0', NULL ,  'If enabled, overdue status triggers editor will default to the logged in library''s rules, rather than the ''default'' rules.',  'YesNo'),
140
('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
('delimiter',';',';|tabulation|,|/|\\|#||','Define the default separator character for exporting reports','Choice'),
141
('delimiter',';',';|tabulation|,|/|\\|#||','Define the default separator character for exporting reports','Choice'),
142
('DecimalSeparators',  '.,', NULL ,  'The allowed separators between entire and decimal parts of numbers',  'Free'),
142
('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'),
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'),
143
('DisplayClearScreenButton','0','','If set to ON, a clear screen button will appear on the circulation page.','YesNo'),
144
('DisplayClearScreenButton','0','','If set to ON, a clear screen button will appear on the circulation page.','YesNo'),
144
('displayFacetCount','0',NULL,NULL,'YesNo'),
145
('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 5-10 Link Here
5
[% INCLUDE 'doc-head-open.inc' %]
5
[% INCLUDE 'doc-head-open.inc' %]
6
<title>Koha &rsaquo; Patrons &rsaquo; Create manual credit</title>
6
<title>Koha &rsaquo; Patrons &rsaquo; Create manual credit</title>
7
[% INCLUDE 'doc-head-close.inc' %]
7
[% INCLUDE 'doc-head-close.inc' %]
8
[% INCLUDE 'decimal-input-js.inc' %]
8
</head>
9
</head>
9
10
10
<body id="pat_mancredit" class="pat">
11
<body id="pat_mancredit" class="pat">
Lines 43-49 Link Here
43
	<li><label for="barcode">Barcode: </label><input type="text" name="barcode" id="barcode" /></li>
44
	<li><label for="barcode">Barcode: </label><input type="text" name="barcode" id="barcode" /></li>
44
	<li><label for="desc">Description: </label><input type="text" name="desc" size="50" id="desc" /></li>
45
	<li><label for="desc">Description: </label><input type="text" name="desc" size="50" id="desc" /></li>
45
    <li><label for="note">Note: </label><input type="text" name="note" size="50" id="note" /></li>
46
    <li><label for="note">Note: </label><input type="text" name="note" size="50" id="note" /></li>
46
    <li><label for="amount">Amount: </label><input type="number" name="amount" id="amount" required="required" value="" step="any" min="0" /> Example: 5.00</li>
47
    <li><label for="amount">Amount: </label><input name="amount" id="amount" class="decimal-unformating" required="required" value="" step="any" min="0" /></li>
48
47
</ol></fieldset>
49
</ol></fieldset>
48
50
49
<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>
51
<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>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/maninvoice.tt (-1 / +2 lines)
Lines 56-62 Link Here
56
	<li><label for="barcode">Barcode: </label><input type="text" name="barcode" id="barcode" /></li>
56
	<li><label for="barcode">Barcode: </label><input type="text" name="barcode" id="barcode" /></li>
57
	<li><label for="desc">Description: </label><input type="text" name="desc" id="desc" size="50" /></li>
57
	<li><label for="desc">Description: </label><input type="text" name="desc" id="desc" size="50" /></li>
58
    <li><label for="note">Note: </label><input type="text" name="note" size="50" id="note" /></li>
58
    <li><label for="note">Note: </label><input type="text" name="note" size="50" id="note" /></li>
59
    <li><label for="amount">Amount: </label><input type="number" name="amount" id="amount" required="required" value="" step="any" min="0" /> Example: 5.00</li>
59
    <li><label for="amount">Amount: </label><input type="text" name="amount" id="amount" class="decimal-unformating" required="required"/></li>
60
	</ol></fieldset>
60
	</ol></fieldset>
61
<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>
61
<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>
62
</form>
62
</form>
Lines 72-77 Link Here
72
</div>
72
</div>
73
</div>
73
</div>
74
74
75
[% INCLUDE 'decimal-input-js.inc' %]
75
[% MACRO jsinclude BLOCK %]
76
[% MACRO jsinclude BLOCK %]
76
    [% Asset.js("js/members-menu.js") %]
77
    [% Asset.js("js/members-menu.js") %]
77
    <script type="text/javascript">
78
    <script type="text/javascript">
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tt (-53 / +4 lines)
Lines 86-92 Link Here
86
    <li>
86
    <li>
87
        <label for="paid">Collect from patron: </label>
87
        <label for="paid">Collect from patron: </label>
88
            <!-- default to paying all -->
88
            <!-- default to paying all -->
89
        <input name="paid" id="paid" value="[% amountoutstanding %]" />
89
        <input name="paid" id="paid" class="decimal-unformating" value="[% amountoutstanding %]" />
90
    </li>
90
    </li>
91
    [% SET payment_types = AuthorisedValues.GetAuthValueDropbox('PAYMENT_TYPE') %]
91
    [% SET payment_types = AuthorisedValues.GetAuthValueDropbox('PAYMENT_TYPE') %]
92
    [% IF payment_types %]
92
    [% IF payment_types %]
Lines 169-175 Link Here
169
    <li>
169
    <li>
170
        <label for="paid">Collect from patron: </label>
170
        <label for="paid">Collect from patron: </label>
171
        <!-- default to paying all -->
171
        <!-- default to paying all -->
172
        <input name="paid" id="paid" value="[% total | format('%.2f') %]" />
172
        <input name="paid" id="paid" class="decimal-unformating" value="[% total | format('%.2f') %]" />
173
    </li>
173
    </li>
174
    [% SET payment_types = AuthorisedValues.GetAuthValueDropbox('PAYMENT_TYPE') %]
174
    [% SET payment_types = AuthorisedValues.GetAuthValueDropbox('PAYMENT_TYPE') %]
175
    [% IF payment_types %]
175
    [% IF payment_types %]
Lines 207-215 Link Here
207
    <script type= "text/javascript">
207
    <script type= "text/javascript">
208
        $(document).ready(function() {
208
        $(document).ready(function() {
209
            $('#payindivfine, #payfine').preventDoubleFormSubmit();
209
            $('#payindivfine, #payfine').preventDoubleFormSubmit();
210
            $("#paid").on("change",function(){
211
                moneyFormat( this );
212
            });
213
        });
210
        });
214
211
215
        prevent_default = 1;
212
        prevent_default = 1;
Lines 230-284 Link Here
230
            }
227
            }
231
        });
228
        });
232
229
233
        function moneyFormat(textObj) {
230
    </script>
234
            var newValue = textObj.value;
235
            var decAmount = "";
236
            var dolAmount = "";
237
            var decFlag   = false;
238
            var aChar     = "";
239
240
            for(i=0; i < newValue.length; i++) {
241
                aChar = newValue.substring(i, i+1);
242
                if (aChar >= "0" && aChar <= "9") {
243
                    if(decFlag) {
244
                        decAmount = "" + decAmount + aChar;
245
                    }
246
                    else {
247
                        dolAmount = "" + dolAmount + aChar;
248
                    }
249
                }
250
                if (aChar == ".") {
251
                    if (decFlag) {
252
                        dolAmount = "";
253
                        break;
254
                    }
255
                    decFlag = true;
256
                }
257
            }
258
231
259
            if (dolAmount == "") {
232
    [% INCLUDE 'decimal-input-js.inc' %]
260
                dolAmount = "0";
261
            }
262
        // Strip leading 0s
263
            if (dolAmount.length > 1) {
264
                while(dolAmount.length > 1 && dolAmount.substring(0,1) == "0") {
265
                    dolAmount = dolAmount.substring(1,dolAmount.length);
266
                }
267
            }
268
            if (decAmount.length > 2) {
269
                decAmount = decAmount.substring(0,2);
270
            }
271
        // Pad right side
272
            if (decAmount.length == 1) {
273
               decAmount = decAmount + "0";
274
            }
275
            if (decAmount.length == 0) {
276
               decAmount = decAmount + "00";
277
            }
278
233
279
            textObj.value = dolAmount + "." + decAmount;
280
        }
281
    </script>
282
[% END %]
234
[% END %]
283
235
284
[% INCLUDE 'intranet-bottom.inc' %]
236
[% INCLUDE 'intranet-bottom.inc' %]
285
- 

Return to bug 12310