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