Bug 26273: Add historic cashups table to register page
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / pos / register.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE Koha %]
4 [% USE KohaDates %]
5 [% USE AuthorisedValues %]
6 [% USE Price %]
7 [% SET footerjs = 1 %]
8 [% PROCESS 'accounts.inc' %]
9 [% INCLUDE 'doc-head-open.inc' %]
10 <title>Koha &rsaquo; Cashup</title>
11 [% INCLUDE 'doc-head-close.inc' %]
12 [% Asset.css("lib/jquery/plugins/rowGroup/stylesheets/rowGroup.dataTables.min.css") | $raw %]
13 </head>
14
15 <body id="register" class="pos">
16 [% INCLUDE 'header.inc' %]
17 [% INCLUDE 'circ-search.inc' %]
18
19 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/pos/pay.pl">Point of sale</a> &rsaquo; Register details</div>
20
21 <div class="main container-fluid">
22     <div class="row">
23         <div class="col-sm-10 col-sm-push-2">
24
25             [% IF ( error_registers ) %]
26                 <div id="error_message" class="dialog message">
27                     <p>
28                         You must have at least one cash register associated with the library before you can record payments.
29                     </p>
30                     [% IF ( CAN_user_parameters_manage_cash_registers ) %]
31                         <form action="/cgi-bin/koha/admin/cash_registers.pl" method="get">
32                             <input type="hidden" name="op" value="add_form" />
33                             <button class="new" type="submit"><i class="fa fa-plus"></i> Create a new cash register</button>
34                         </form>
35                     [% END %]
36                 </div>
37             [% ELSE %]
38
39             [% IF ( error_cashup_permission ) %]
40             <div id="error_message" class="dialog alert">
41                 You do not have permission to perform cashup actions.
42             </div>
43             [% END %]
44
45             [% IF ( error_refund_permission ) %]
46             <div id="error_message" class="dialog alert">
47                 You do not have permission to perform refund actions.
48             </div>
49             [% END %]
50
51             [% IF ( CAN_user_cash_management_cashup ) %]
52             <div id="toolbar" class="btn-toolbar">
53                 <button id="pos_cashup" type="button" class="btn btn-default" data-toggle="modal" data-target="#confirmCashupModal" ><i class="fa fa-money"></i> Record cashup</button>
54             </div>
55             [% END %]
56
57             <h1>Register transaction details for [% register.name | html %]</h1>
58
59             <h2>Summary</h2>
60             <ul>
61                 [% IF register.last_cashup %]
62                 <li>Last cashup: [% register.last_cashup.timestamp | $KohaDates with_hours => 1 %] (<a data-toggle="modal" data-cashup="[% register.last_cashup.id | html %]" data-register="[% register.description | html %]" href="#cashupSummaryModal" class="button">Summary</a>)</li>
63                 [% END %]
64                 <li>Float: [% register.starting_float | $Price %]</li>
65                 <li>Total income (cash): [% accountlines.credits_total * -1 | $Price %] ([% accountlines.credits_total(payment_type => 'CASH') * -1 | $Price %])</li>
66                 <li>Total outgoing (cash): [% accountlines.debits_total * -1 | $Price %] ([% accountlines.debits_total( payment_type => 'CASH') * -1 | $Price %])</li>
67                 <li>Total bankable: [% accountlines.total( payment_type => 'CASH') * -1 | $Price %]</li>
68             </ul>
69
70             [% IF register.last_cashup %]
71             <h2>Transactions since [% register.last_cashup.timestamp | $KohaDates with_hours => 1 %]</h2>
72             [% ELSE %]
73             <h2>Transactions to date</h2>
74             [% END %]
75             <table id="sales" class="table_sales">
76                 <thead>
77                     <th>ID</th>
78                     <th>DATA</th>
79                     <th>Transaction</th>
80                     <th>Description</th>
81                     <th>Price</th>
82                     <th>Total</th>
83                     <th class="noExport">Actions</th>
84                 </thead>
85                 <tbody>
86                     [% FOREACH accountline IN accountlines %]
87                         [% IF accountline.is_credit %]
88                             [% FOREACH credit IN accountline.credit_offsets %]
89                             [% IF credit.debit %]
90                             <tr>
91                                 <td>[% accountline.accountlines_id | html %]</td>
92                                 <td>{ "type": "credit", "identifier": "[%- accountline.credit_number | html -%]", "description": "[%- PROCESS account_type_description account=accountline -%] ([% AuthorisedValues.GetByCode( 'PAYMENT_TYPE', accountline.payment_type ) | html %])", "amount": "[% accountline.amount * -1 | $Price %]" }</td>
93                                 <td></td>
94                                 <td>
95                                     [%- PROCESS account_type_description account=credit.debit -%]
96                                     [%- IF credit.debit.description -%] ([% credit.debit.description | html %])[%- END -%]
97                                     [%- IF ( credit.debit.itemnumber ) -%] (<a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=[% credit.debit.item.biblionumber | uri %]&amp;itemnumber=[% credit.debit.itemnumber | uri %]">[% credit.debit.item.biblio.title | html %]</a>)[%- END -%]
98                                 </td>
99                                 <td>[% credit.debit.amount | $Price %]</td>
100                                 <td></td>
101                                 <td>
102                                     [% IF CAN_user_cash_management_anonymous_refund && !(credit.debit.status == 'REFUNDED' ) %]
103                                     <button type="button" class="btn btn-default btn-xs" data-toggle="modal" data-target="#issueRefundModal" data-item="[%- PROCESS account_type_description account=credit.debit -%]" data-accountline="[% credit.debit.accountlines_id | html %]" data-amount="[% credit.debit.amount | $Price %]" data-quantity="[% credit.debit.note | html %]"><i class="fa fa-money"></i> Issue refund</button>
104                                     [% ELSIF CAN_user_updatecharges_refund && !(credit.debit.status == 'REFUNDED') && credit.debit.borrowernumber %]
105                                     <button type="button" class="btn btn-default btn-xs" data-toggle="modal" data-target="#issueRefundModal" data-item="[%- PROCESS account_type_description account=credit.debit -%]" data-accountline="[% credit.debit.accountlines_id | html %]" data-amount="[% credit.debit.amount | $Price %]" data-quantity="[% credit.debit.note | html %]"><i class="fa fa-money"></i> Issue refund</button>
106                                     [% END %]
107                                 </td>
108                             </tr>
109                             [% END %]
110                             [% END %]
111                         [% ELSE %]
112                             [% FOREACH debit IN accountline.debit_offsets %]
113                             [% IF debit.credit %]
114                             <tr>
115                                 <td>[% accountline.accountlines_id | html %]</td>
116                                 <td>{ "type": "debit", "identifier": "[%- accountline.credit_number | html -%]", "description": "[%- PROCESS account_type_description account=accountline -%] ([% AuthorisedValues.GetByCode( 'PAYMENT_TYPE', accountline.payment_type ) | html %])", "amount": "[% accountline.amount * -1 | $Price %]" }</td>
117                                 <td></td>
118                                 <td>[%- PROCESS account_type_description account=debit.credit -%]</td>
119                                 <td>
120                                     [%- IF debit.credit.description %][% debit.credit.description | html %][%- END -%]
121                                     [%- IF ( debit.credit.itemnumber ) -%] (<a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=[% debit.credit.item.biblionumber | uri %]&amp;itemnumber=[% debit.credit.itemnumber | uri %]">[% debit.credit.item.biblio.title | html %]</a>)[%- END -%]
122                                 </td>
123                                 <td>[% debit.credit.amount | $Price %]</td>
124                                 <td></td>
125                             </tr>
126                             [% END %]
127                             [% END %]
128                         [% END %]
129                     [% END %]
130                 </tbody>
131                 <tfoot>
132                     <tr>
133                         <td colspan="5">Total income: </td>
134                         <td>[% accountlines.total * -1 | $Price %]</td>
135                         <td></td>
136                     </tr>
137                 </tfoot>
138             </table>
139             [% END %]
140
141             [% IF register.cashups %]
142             <h2>Older transactions</h2>
143             <form method="GET" action="/cgi-bin/koha/pos/register.pl">
144                 <fieldset class="rows">
145                     Please select a date range to display transactions for:
146                     <ol>
147                         <li>
148                             <label for="trange_f">From: </label>
149                             <input type="text" size="10" id="from" class="datepickerfrom" name="trange_f" value="[% trange_f | html %]"/>
150                             <label class="inline" for="trange_t">To: </label>
151                             <input type="text" size="10" id="to" class="datepickerto" name="trange_t" value="[% trange_t | html %]" />
152                             <span class="hint">[% INCLUDE 'date-format.inc' %]</span>
153                         </li>
154                     </ol>
155                 </fieldset>
156
157                 <div class="action">
158                     <input type="hidden" name="registerid" value="[% register.id | html %]">
159                     <input type="submit" value="Display" />
160                 </div>
161             </form>
162
163             [% IF trange_f %]
164             <table id="past_sales" class="past_sales_table">
165                 <thead>
166                     <th>ID</th>
167                     <th>DATA</th>
168                     <th>Transaction</th>
169                     <th>Description</th>
170                     <th>Price</th>
171                     <th>Total</th>
172                     <th class="noExport">Actions</th>
173                 </thead>
174                 <tbody>
175                     [% FOREACH accountline IN past_accountlines %]
176                         [% IF accountline.is_credit %]
177                             [% FOREACH credit IN accountline.credit_offsets %]
178                             [% IF credit.debit %]
179                             <tr>
180                                 <td>[% accountline.accountlines_id | html %]</td>
181                                 <td>{ "type": "credit", "identifier": "[%- accountline.credit_number | html -%]", "description": "[%- PROCESS account_type_description account=accountline -%] ([% accountline.payment_type | html %])", "amount": "[% accountline.amount * -1 | $Price %]" }</td>
182                                 <td></td>
183                                 <td>
184                                     [%- PROCESS account_type_description account=credit.debit -%]
185                                     [%- IF credit.debit.description -%] ([% credit.debit.description | html %])[%- END -%]
186                                     [%- IF ( credit.debit.itemnumber ) -%] (<a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=[% credit.debit.item.biblionumber | uri %]&amp;itemnumber=[% credit.debit.itemnumber | uri %]">[% credit.debit.item.biblio.title | html %]</a>)[%- END -%]
187                                 </td>
188                                 <td>[% credit.debit.amount | $Price %]</td>
189                                 <td></td>
190                                 <td>
191                                     [% IF CAN_user_cash_management_refund_cash_registers && !(credit.debit.status == 'REFUNDED' ) %]
192                                     <button type="button" class="btn btn-default btn-xs pos_refund" data-toggle="modal" data-target="#issueRefundModal" data-item="[%- PROCESS account_type_description account=credit.debit -%]" data-accountline="[% credit.debit.accountlines_id | html %]" data-amount="[% credit.debit.amount | $Price %]" data-quantity="[% credit.debit.note | html %]"><i class="fa fa-money"></i> Issue refund</button>
193                                     [% END %]
194                                 </td>
195                             </tr>
196                             [% END %]
197                             [% END %]
198                         [% ELSE %]
199                             [% FOREACH debit IN accountline.debit_offsets %]
200                             [% IF debit.credit %]
201                             <tr>
202                                 <td>[% accountline.accountlines_id | html %]</td>
203                                 <td>{ "type": "debit", "identifier": "[%- accountline.credit_number | html -%]", "description": "[%- PROCESS account_type_description account=accountline -%] ([% accountline.payment_type | html %])", "amount": "[% accountline.amount * -1 | $Price %]" }</td>
204                                 <td></td>
205                                 <td>[%- PROCESS account_type_description account=debit.credit -%]</td>
206                                 <td>[%- IF debit.credit.description %][% debit.credit.description | html %][% END %]
207         &nbsp;[% IF ( debit.credit.itemnumber ) %]<a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=[% debit.credit.item.biblionumber | uri %]&amp;itemnumber=[% debit.credit.itemnumber | uri %]">[% debit.credit.item.biblio.title | html %]</a>[% END %]</td>
208                                 <td>[% debit.credit.amount | $Price %]</td>
209                                 <td></td>
210                             </tr>
211                             [% END %]
212                             [% END %]
213                         [% END %]
214                     [% END %]
215                 </tbody>
216                 <tfoot>
217                     <tr>
218                         <td colspan="5">Total income: </td>
219                         <td>[% past_accountlines.total * -1 | $Price %]</td>
220                         <td></td>
221                     </tr>
222                 </tfoot>
223             </table>
224             [% END %]
225
226             <hr/>
227             <h2>Cashup history</h2>
228             <table id="table_cashups">
229                 <thead>
230                     <tr>
231                         <th>Date</th>
232                         <th>Amount</th>
233                         <th data-class-name="actions">Actions</th>
234                     </tr>
235                 </thead>
236             </table>
237             [% END %]
238         </div>
239
240         <div class="col-sm-2 col-sm-pull-10">
241             <aside>
242                 [% INCLUDE 'pos-menu.inc' %]
243             </aside>
244         </div>
245     </div><!-- /.row -->
246
247     <!-- Confirm cashup modal -->
248     <div class="modal" id="confirmCashupModal" tabindex="-1" role="dialog" aria-labelledby="confirmCashupLabel">
249         <div class="modal-dialog" role="document">
250             <div class="modal-content">
251                 <div class="modal-header">
252                     <button type="button" class="closebtn" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
253                     <h4 class="modal-title" id="confirmCashupLabel">Confirm cashup of <em>[% register.description | html %]</em></h4>
254                 </div>
255                 <div class="modal-body">
256                     Please confirm that you have removed [% accountlines.total( payment_type => 'CASH') * -1 | $Price %] from the cash register and left a float of [% register.starting_float | $Price %].
257                 </div> <!-- /.modal-body -->
258                 <div class="modal-footer">
259                     <a href="/cgi-bin/koha/pos/register.pl?op=cashup" class="btn btn-default" id="pos_cashup_confirm">Confirm</a>
260                     <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
261                 </div> <!-- /.modal-footer -->
262             </div> <!-- /.modal-content -->
263         </div> <!-- /.modal-dialog -->
264     </div> <!-- /#confirmCashupModal -->
265
266     <!-- Issue refund modal -->
267     <div class="modal" id="issueRefundModal" tabindex="-1" role="dialog" aria-labelledby="issueRefundLabel">
268         <form id="refund_form" method="post" enctype="multipart/form-data" class="validated">
269             <input type="hidden" name="accountline" value="" id="refundline">
270             <div class="modal-dialog" role="document">
271                 <div class="modal-content">
272                     <div class="modal-header">
273                         <button type="button" class="closebtn" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
274                         <h4 class="modal-title" id="issueRefundLabel">Issue refund from <em>[% register.description | html %]</em></h4>
275                     </div>
276                     <div class="modal-body">
277                         <fieldset class="rows">
278                             <ol>
279                                 <li>
280                                     <span id="item" class="label">Item: </span><span></span>
281                                 </li>
282                                 <li>
283                                     <span id="paid" class="label">Amount paid: </span><span></span>
284                                 </li>
285                                 <li>
286                                     <label class="required" for="amount">Returned to patron: </label>
287                                     <input type="text" inputmode="decimal" pattern="^\d+(\.\d{2})?$" id="returned" name="amount" required="required">
288                                     <span class="required">Required</span>
289                                 </li>
290                                 [% SET payment_types = [] %]
291                                 [% FOR pt IN AuthorisedValues.GetAuthValueDropbox('PAYMENT_TYPE') %]
292                                     [% NEXT IF pt.authorised_value.grep("^SIP[[:digit:]]{2}$").size() %]
293                                     [% payment_types.push(pt) %]
294                                 [% END %]
295                                 <li>
296                                     <label for="transaction_type">Transaction type: </label>
297                                     <select name="transaction_type" id="transaction_type">
298                                         [% FOREACH pt IN payment_types %]
299                                             <option value="[% pt.authorised_value | html %]">[% pt.lib | html %]</option>
300                                         [% END %]
301                                     </select>
302                                 </li>
303                             </ol>
304                         </fieldset> <!-- /.rows -->
305                     </div> <!-- /.modal-body -->
306                     <div class="modal-footer">
307                         <input type="hidden" name="registerid" value="[% register.id | html %]">
308                         <input type="hidden" name="op" value="refund">
309                         <button type="submit" class="btn btn-default" id="pos_refund_confirm">Confirm</button>
310                         <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
311                     </div> <!-- /.modal-footer -->
312                 </div> <!-- /.modal-content -->
313             </div> <!-- /.modal-dialog -->
314         </form> <!-- /#refund_form -->
315     </div> <!-- /#issueRefundModal -->
316
317     [% INCLUDE 'modals/cashup_summary.inc' %]
318
319     [% MACRO jsinclude BLOCK %]
320     [% INCLUDE 'datatables.inc' %]
321     [% Asset.js("lib/jquery/plugins/rowGroup/dataTables.rowGroup.min.js") | $raw %]
322     [% Asset.js("js/cashup_modal.js") | $raw %]
323     [% INCLUDE 'calendar.inc' %]
324     <script>
325         var sales_table = $("#sales").dataTable($.extend(true, {}, dataTablesDefaults, {
326             orderFixed: [ 0, 'asc'],
327             columnDefs: [ {
328                 targets: [ 0, 1 ],
329                 visible: false
330             }],
331             rowGroup: {
332                 dataSrc: 0,
333                 startRender: function ( rows, group ) {
334                     var details = JSON.parse(rows.data().pluck(1).pop());
335                     var identifier = details.identifier || group;
336                     return $('<tr class="'+details.type+'"/>')
337                         .append( '<td>'+identifier+'</td>' )
338                         .append( '<td colspan="2">'+details.description+'</td>' )
339                         .append( '<td>'+details.amount+'</td>' )
340                         .append( '<td><button class="printReceipt btn btn-default btn-xs" data-accountline="'+group+'"><i class="fa fa-print"></i> ' + _("Print receipt") + '</button></td>');
341                 },
342                 endRender: null,
343             },
344             initComplete: function() {
345                 $("#sales").show();
346             }
347         }));
348
349         var past_sales_table = $("#past_sales").dataTable($.extend(true, {}, dataTablesDefaults, {
350             orderFixed: [ 0, 'asc'],
351             columnDefs: [ {
352                 targets: [ 0, 1 ],
353                 visible: false
354             }],
355             rowGroup: {
356                 dataSrc: 0,
357                 startRender: function ( rows, group ) {
358                     var details = JSON.parse(rows.data().pluck(1).pop());
359                     var identifier = details.identifier || group;
360                     return $('<tr class="'+details.type+'"/>')
361                         .append( '<td>'+identifier+'</td>' )
362                         .append( '<td colspan="2">'+details.description+'</td>' )
363                         .append( '<td>'+details.amount+'</td>' )
364                         .append( '<td><button class="printReceipt btn btn-default btn-xs" data-accountline="'+group+'"><i class="fa fa-print"></i> Print receipt</button></td>');
365                 },
366                 endRender: null,
367             }
368         }));
369
370         $("#issueRefundModal").on("shown.bs.modal", function(e){
371            var button = $(e.relatedTarget);
372            var item = button.data('item');
373            $("#item + span").replaceWith(item);
374            var accountline = button.data('accountline');
375            $('#refundline').val(accountline);
376            var amount = button.data('amount');
377            $("#paid + span").replaceWith(amount);
378            $("#returned").attr({ "value": amount, "max": amount });
379            $("#returned, #transaction_type").focus();
380         });
381
382         $(".printReceipt").click(function() {
383             var accountlines_id = $(this).data('accountline');
384             var win = window.open('/cgi-bin/koha/pos/printreceipt.pl?action=print&accountlines_id=' + accountlines_id, '_blank');
385             win.focus();
386         });
387
388         $('.modal.printable').on('shown.bs.modal', function() {
389             $('.modal-dialog', this).addClass('focused');
390             $('body').addClass('modalprinter');
391
392             if ($(this).hasClass('autoprint')) {
393                 window.print();
394             }
395         }).on('hidden.bs.modal', function () {
396             $('.modal-dialog', this).removeClass('focused');
397             $('body').removeClass('modalprinter');
398         });
399
400         $('.printModal').click(function() {
401             window.print();
402         });
403
404
405         var cashups_table_url = "/api/v1/cash_registers/[% register.id | html %]/cashups?";
406         var cashups_table = $("#table_cashups").api({
407             "ajax": {
408                 "url": cashups_table_url
409             },
410             "order": [[ 1, "asc" ]],
411             "columnDefs": [ {
412                 "targets": [0,1],
413                 "render": function (data, type, row, meta) {
414                     if ( type == 'display' ) {
415                         return data.escapeHtml();
416                     }
417                     return data;
418                 }
419             } ],
420             "columns": [
421                 {
422                     "data": "timestamp",
423                     "searchable": true,
424                     "orderable": true
425                 },
426                 {
427                     "data": "amount",
428                     "searchable": true,
429                     "orderable": true
430                 },
431                 {
432                     "data": function( row, type, val, meta ) {
433                         var result = '<a class="btn btn-default btn-xs" role="button" data-toggle="modal" data-cashup="'+encodeURIComponent(row.cashup_id)+'" data-register="[% register.description | html %]" href="#cashupSummaryModal"><i class="fa fa-pencil" aria-hidden="true"></i> '+_("Summary")+'</a>\n';
434                         return result;
435
436                     },
437                     "searchable": false,
438                     "orderable": false
439                 }
440             ]
441         }, [], 1);
442
443         $(document).ready(function() {
444             // http://jqueryui.com/demos/datepicker/#date-range
445             var dates = $( "#from, #to" ).datepicker({
446                 changeMonth: true,
447                 numberOfMonths: 1,
448                 onSelect: function( selectedDate ) {
449                     var option = this.id == "from" ? "minDate" : "maxDate",
450                         instance = $( this ).data( "datepicker" );
451                         date = $.datepicker.parseDate(
452                             instance.settings.dateFormat ||
453                             $.datepicker._defaults.dateFormat,
454                             selectedDate, instance.settings );
455                     dates.not( this ).datepicker( "option", option, date );
456                 }
457             });
458         });
459     </script>
460 [% END %]
461
462 [% INCLUDE 'intranet-bottom.inc' %]