Bug 24525: Remove SIP payment types from point of sale
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / pos / pay.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE Koha %]
4 [% USE AuthorisedValues %]
5 [% USE Price %]
6 [% SET footerjs = 1 %]
7 [% INCLUDE 'doc-head-open.inc' %]
8 <title>Koha &rsaquo; Payments</title>
9 [% INCLUDE 'doc-head-close.inc' %]
10 </head>
11
12 <body id="payments" class="pos">
13 [% INCLUDE 'header.inc' %]
14 [% INCLUDE 'circ-search.inc' %]
15
16 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; Point of sale</div>
17
18 <div class="main container-fluid">
19     <div class="row">
20         <div class="col-sm-10 col-sm-push-2">
21
22         [% IF ( error_registers ) %]
23         <div id="error_message" class="dialog alert">
24             You must have at least one cash register associated with this branch before you can record payments.
25         </div>
26         [% ELSE %]
27
28         [% IF payment_id && !Koha.Preference('FinePaymentAutoPopup') %]
29         <div class="dialog alert audio-alert-action">
30             Payment received: <a target="_blank" href="/cgi-bin/koha/pos/printreceipt.pl?action=print&accountlines_id=[% payment_id | uri %]&collected=[% collected | uri %]&change=[% change | uri %]" class="btn btn-default btn-xs"><i class="fa fa-print"></i> Print receipt</a>
31         </div>
32         [% END %]
33
34         <form name="payForm" id="payForm" method="post" action="/cgi-bin/koha/pos/pay.pl">
35             <div class="row">
36
37                 <div class="col-sm-6">
38                     <fieldset class="rows">
39                         <legend>Items for purchase</legend>
40                             Please select items from below to add to this transaction:
41                             [% IF invoice_types %]
42                             <table id="invoices">
43                             <thead>
44                                 <tr>
45                                     <th>Code</th>
46                                     <th>Description</th>
47                                     <th>Cost</th>
48                                     <th>Action</th>
49                                 </tr>
50                             </thead>
51                             <tbody>
52                             [% FOREACH invoice IN invoice_types %]
53                                 <tr>
54                                     <td>[% invoice.code | html %]</td>
55                                     <td>[% invoice.description | html %]</td>
56                                     <td>[% invoice.default_amount | $Price %]</td>
57                                     <td>
58                                         <button class="add_button" data-invoice-code="[% invoice.code | html %]" data-invoice-title="[% invoice.description | html %]" data-invoice-price="[% invoice.default_amount | html %]"><i class="fa fa-plus"></i> Add</button>
59                                     </td>
60                                 </tr>
61                             [% END %]
62                             </table>
63                             [% ELSE %]
64                             You have no manual invoice types defined
65                             [% END %]
66                     </fieldset>
67                 </div>
68
69                 <div class="col-sm-6">
70
71                     <fieldset class="rows">
72                         <legend>This sale</legend>
73                         <p>Click to edit item cost or quantities</p>
74                         <table id="sale" class="table_sale">
75                             <thead>
76                                 <tr>
77                                     <th>Item</th>
78                                     <th>Cost</th>
79                                     <th>Quantity</th>
80                                     <th>Total</th>
81                                     <th>Action</th>
82                                     <th>CODE</th>
83                                 </tr>
84                             </thead>
85                             <tbody>
86                             </tbody>
87                             <tfoot>
88                                 <tr>
89                                     <td colspan="3">Total payable:</td>
90                                     <td></td>
91                                     <td></td>
92                                     <td></td>
93                                 </tr>
94                             </tfoot>
95                         </table>
96                     </fieldset>
97
98                     <fieldset class="rows">
99                         <legend>Collect payment</legend>
100                         <ol>
101                             <li>
102                                 <label for="paid">Amount being paid: </label>
103                                 <input type="number" min="0.00" max="10000.00" step="0.01" name="paid" id="paid" value="[% amountoutstanding | $Price on_editing => 1 %]" readonly/>
104                             </li>
105                             <li>
106                                 <label for="collected">Collected from patron: </label>
107                                 <input type="number" min="0.00" max="10000.00" step="0.01" name="collected" id="collected" value=""/>
108                             </li>
109                             <li>
110                                 <label>Change to give: </label>
111                                 <span id="change">0.00</span>
112                                 <input type="hidden" name="change" value="0.00"/>
113                             </li>
114
115                             [% SET payment_types = [] %]
116                             [% FOR pt IN AuthorisedValues.GetAuthValueDropbox('PAYMENT_TYPE') %]
117                                 [% NEXT IF pt.authorised_value.grep("^SIP[[:digit:]]{2}$").size() %]
118                                 [% payment_types.push(pt) %]
119                             [% END %]
120                             <li>
121                                 <label for="payment_type">Payment type: </label>
122                                 <select name="payment_type" id="payment_type">
123                                     [% FOREACH pt IN payment_types %]
124                                         <option value="[% pt.authorised_value | html %]">[% pt.lib | html %]</option>
125                                     [% END %]
126                                 </select>
127                             </li>
128
129                             [% IF Koha.Preference('UseCashRegisters') %]
130                             <li>
131                                 <label for="cash_register">Cash register: </label>
132                                 <select name="cash_register" id="cash_register">
133                                     [% FOREACH register IN registers %]
134                                       [% IF register.id == registerid %]
135                                     <option value="[% register.id | html %]" selected="selected">[% register.name | html %]</option>
136                                       [% ELSE %]
137                                     <option value="[% register.id | html %]">[% register.name | html %]</option>
138                                       [% END %]
139                                     [% END %]
140                                 </select>
141                             </li>
142                             [% END %]
143                         </ol>
144
145                     </fieldset>
146                 </div>
147
148                 <div class="action">
149                     <input type="submit" name="submitbutton" value="Confirm" />
150                     <a class="cancel" href="/cgi-bin/koha/pos/pay.pl">Cancel</a>
151                 </div>
152             </div>
153         </form>
154         [% END %]
155     </div>
156
157     <div class="col-sm-2 col-sm-pull-10">
158         <aside>
159             [% INCLUDE 'pos-menu.inc' %]
160         </aside>
161     </div>
162 </div> <!-- /.row -->
163
164 <!-- Modal -->
165 <div id="confirm_change_form" class="modal" tabindex="-1" role="dialog" aria-hidden="true">
166     <div class="modal-dialog">
167         <div class="modal-content">
168             <div class="modal-header">
169                 <h3>The amount collected is more than the outstanding charge</h3>
170             </div>
171             <div class="modal-body">
172                 <p>The amount collected from the patron is higher than the amount to be paid.</p>
173                 <p>The change to give is <b><span id="modal_change">0.00</span></b>.</p>
174                 <p>Confirm this payment?</p>
175             </div>
176             <div class="modal-footer">
177                 <button class="btn btn-default approve" id="modal_submit" type="button"><i class="fa fa-check"></i> Yes</button>
178                 <button class="btn btn-default deny cancel" href="#" data-dismiss="modal" aria-hidden="true"><i class="fa fa-times"></i> No</button>
179             </div>
180         </div>
181     </div>
182 </div>
183
184 [% IF payment_id && Koha.Preference('FinePaymentAutoPopup') %]
185 <!-- Automatic Print Receipt -->
186       <a id="printReceipt" style="display: none" href="#"></a>
187 [% END %]
188
189 [% MACRO jsinclude BLOCK %]
190     [% Asset.js("js/admin-menu.js") | $raw %]
191     [% INCLUDE 'format_price.inc' %]
192     [% INCLUDE 'datatables.inc' %]
193     [% Asset.js("lib/jquery/plugins/jquery.jeditable.mini.js") | $raw %]
194     <script>
195     function moneyFormat(textObj) {
196         var newValue = textObj.value;
197         var decAmount = "";
198         var dolAmount = "";
199         var decFlag   = false;
200         var aChar     = "";
201
202         for(var i=0; i < newValue.length; i++) {
203             aChar = newValue.substring(i, i+1);
204             if (aChar >= "0" && aChar <= "9") {
205                 if(decFlag) {
206                     decAmount = "" + decAmount + aChar;
207                 }
208                 else {
209                     dolAmount = "" + dolAmount + aChar;
210                 }
211             }
212             if (aChar == ".") {
213                 if (decFlag) {
214                     dolAmount = "";
215                     break;
216                 }
217                 decFlag = true;
218             }
219         }
220
221         if (dolAmount == "") {
222             dolAmount = "0";
223         }
224     // Strip leading 0s
225         if (dolAmount.length > 1) {
226             while(dolAmount.length > 1 && dolAmount.substring(0,1) == "0") {
227                 dolAmount = dolAmount.substring(1,dolAmount.length);
228             }
229         }
230         if (decAmount.length > 2) {
231             decAmount = decAmount.substring(0,2);
232         }
233     // Pad right side
234         if (decAmount.length == 1) {
235            decAmount = decAmount + "0";
236         }
237         if (decAmount.length == 0) {
238            decAmount = decAmount + "00";
239         }
240
241         textObj.value = dolAmount + "." + decAmount;
242     }
243
244     function fnClickAddRow( table, invoiceCode, invoiceTitle, invoicePrice ) {
245       var defaultPrice = { value: invoicePrice };
246       moneyFormat(defaultPrice);
247       table.fnAddData( [
248         invoiceTitle,
249         defaultPrice.value,
250         1,
251         null,
252         '<button class="drop"><i class="fa fa-trash"></i> Remove</button>',
253         invoiceCode
254         ]
255       );
256     }
257
258     function updateChangeValues() {
259         var change = $('#change')[0];
260         change.innerHTML = Math.round(($('#collected')[0].value - $('#paid')[0].value) * 100) / 100;
261         if (change.innerHTML <= 0) {
262             change.innerHTML = "0.00";
263         } else {
264             change.value = change.innerHTML;
265             moneyFormat(change);
266             change.innerHTML = change.value;
267         }
268
269         $(':input[name="change"]').val(change.value);
270         $('#modal_change').html(change.innerHTML);
271     }
272
273     $(document).ready(function() {
274         var sale_table = $("#sale").dataTable($.extend(true, {}, dataTablesDefaults, {
275             "bPaginate": false,
276             "bFilter": false,
277             "bInfo": false,
278             "bAutoWidth": false,
279             "aoColumnDefs": [{
280                 "aTargets": [-3],
281                 "bSortable": false,
282                 "bSearchable": false,
283             }, {
284                 "aTargets": [-3],
285                 "mRender": function ( data, type, full ) {
286                     var price = Number.parseFloat(data);
287                     return price.format_price();
288                 }
289             }, {
290                 "aTargets": [-5],
291                 "sClass" : "editable",
292             }, {
293                 "aTargets": [-4],
294                 "sClass" : "editable_int",
295             }, {
296                 "targets": [-1],
297                 "visible": false,
298                 "searchable": false
299             }],
300             "aaSorting": [
301                 [1, "asc"]
302             ],
303             "fnDrawCallback": function (oSettings) {
304                 var local = this;
305                 local.$('.editable').editable( function(value, settings) {
306                     var aPos = local.fnGetPosition( this );
307                     local.fnUpdate( value, aPos[0], aPos[1], true, false );
308                     return value;
309                 },{
310                     type    : 'number',
311                     step    : '0.01',
312                     min     : '0',
313                     onblur  : 'submit'
314                 });
315                 local.$('.editable_int').editable( function(value, settings) {
316                     var aPos = local.fnGetPosition( this );
317                     local.fnUpdate( value, aPos[0], aPos[1], true, false );
318                     return value;
319                 },{
320                     type    : 'number',
321                     step    : '1',
322                     min     : '0',
323                     onblur  : 'submit'
324                 });
325             },
326             "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
327                 var iTotal = aData[1] * aData[2];
328                 this.fnUpdate( iTotal, nRow, 3, false, false );
329             },
330             "fnFooterCallback": function(nFoot, aData, iStart, iEnd, aiDisplay) {
331                 var iTotalPrice = 0;
332                 for ( var i=0 ; i<aData.length ; i++ )
333                 {
334                     iTotalPrice += aData[i][3]*1;
335                 }
336                 nFoot.getElementsByTagName('td')[1].innerHTML = iTotalPrice.format_price();
337                 $('#paid').val(iTotalPrice);
338                 $('#paid').trigger('change');
339             }
340         }));
341
342         $("#sale").on("click", "button.drop", function(){
343                 sale_table.DataTable().row($(this).parents('tr')).remove().draw(false);
344         });
345
346         var items_table = $("#invoices").dataTable($.extend(true,{}, dataTablesDefaults, {
347                "aoColumnDefs": [
348                   { "aTargets": [ -1, -2 ], "bSortable": false, "bSearchable":false },
349                ],
350                "aaSorting": [[ 0, "asc" ]],
351                "paginationType": "full",
352         }));
353
354         $(".add_button").on("click", function(e) {
355             e.preventDefault();
356             fnClickAddRow(sale_table, $( this ).data('invoiceCode'), $( this ).data('invoiceTitle'), $( this ).data('invoicePrice') );
357             items_table.fnFilter( '' );
358         });
359
360         // Change calculation and modal
361         var change = $('#change')[0];
362         $("#paid, #collected").on("change",function() {
363             moneyFormat( this );
364             if (change != undefined) {
365                 updateChangeValues();
366             }
367         });
368
369         var checked = false;
370         $('#modal_submit').click(function() {
371             checked = true;
372             $('#payForm').submit();
373         });
374
375         $('#payForm').submit(function(e){
376             if (change != undefined && change.innerHTML > 0.00 && !checked) {
377                 e.preventDefault();
378                 $("#confirm_change_form").modal("show");
379             } else {
380                 var rows = sale_table.fnGetData();
381                 rows.forEach(function (row, index) {
382                     var sale = {
383                         code: row[5],
384                         price: row[1],
385                         quantity: row[2]
386                     };
387                     $('<input>').attr({
388                         type: 'hidden',
389                         name: 'sales',
390                         value: JSON.stringify(sale)
391                     }).appendTo('#payForm');
392                 });
393                 return true;
394             }
395         });
396
397         [% IF payment_id && Koha.Preference('FinePaymentAutoPopup') %]
398             $("#printReceipt").click(function() {
399                 var win = window.open('/cgi-bin/koha/pos/printreceipt.pl?action=print&accountlines_id=[% payment_id | uri %]&collected=[% collected | uri %]&change=[% change | uri %]', '_blank');
400                 win.focus();
401             });
402             $("#printReceipt").click();
403         [% END %]
404     });
405     </script>
406 [% END %]
407
408 [% INCLUDE 'intranet-bottom.inc' %]