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