Bug 26273: (follow-up) Add 'Cashier' to the cashups table
[koha-ffzg.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>Cashier</th>
233                         <th>Amount</th>
234                         <th data-class-name="actions">Actions</th>
235                     </tr>
236                 </thead>
237             </table>
238             [% END %]
239         </div>
240
241         <div class="col-sm-2 col-sm-pull-10">
242             <aside>
243                 [% INCLUDE 'pos-menu.inc' %]
244             </aside>
245         </div>
246     </div><!-- /.row -->
247
248     <!-- Confirm cashup modal -->
249     <div class="modal" id="confirmCashupModal" tabindex="-1" role="dialog" aria-labelledby="confirmCashupLabel">
250         <div class="modal-dialog" role="document">
251             <div class="modal-content">
252                 <div class="modal-header">
253                     <button type="button" class="closebtn" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
254                     <h4 class="modal-title" id="confirmCashupLabel">Confirm cashup of <em>[% register.description | html %]</em></h4>
255                 </div>
256                 <div class="modal-body">
257                     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 %].
258                 </div> <!-- /.modal-body -->
259                 <div class="modal-footer">
260                     <a href="/cgi-bin/koha/pos/register.pl?op=cashup" class="btn btn-default" id="pos_cashup_confirm">Confirm</a>
261                     <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
262                 </div> <!-- /.modal-footer -->
263             </div> <!-- /.modal-content -->
264         </div> <!-- /.modal-dialog -->
265     </div> <!-- /#confirmCashupModal -->
266
267     <!-- Issue refund modal -->
268     <div class="modal" id="issueRefundModal" tabindex="-1" role="dialog" aria-labelledby="issueRefundLabel">
269         <form id="refund_form" method="post" enctype="multipart/form-data" class="validated">
270             <input type="hidden" name="accountline" value="" id="refundline">
271             <div class="modal-dialog" role="document">
272                 <div class="modal-content">
273                     <div class="modal-header">
274                         <button type="button" class="closebtn" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
275                         <h4 class="modal-title" id="issueRefundLabel">Issue refund from <em>[% register.description | html %]</em></h4>
276                     </div>
277                     <div class="modal-body">
278                         <fieldset class="rows">
279                             <ol>
280                                 <li>
281                                     <span id="item" class="label">Item: </span><span></span>
282                                 </li>
283                                 <li>
284                                     <span id="paid" class="label">Amount paid: </span><span></span>
285                                 </li>
286                                 <li>
287                                     <label class="required" for="amount">Returned to patron: </label>
288                                     <input type="text" inputmode="decimal" pattern="^\d+(\.\d{2})?$" id="returned" name="amount" required="required">
289                                     <span class="required">Required</span>
290                                 </li>
291                                 [% SET payment_types = [] %]
292                                 [% FOR pt IN AuthorisedValues.GetAuthValueDropbox('PAYMENT_TYPE') %]
293                                     [% NEXT IF pt.authorised_value.grep("^SIP[[:digit:]]{2}$").size() %]
294                                     [% payment_types.push(pt) %]
295                                 [% END %]
296                                 <li>
297                                     <label for="transaction_type">Transaction type: </label>
298                                     <select name="transaction_type" id="transaction_type">
299                                         [% FOREACH pt IN payment_types %]
300                                             <option value="[% pt.authorised_value | html %]">[% pt.lib | html %]</option>
301                                         [% END %]
302                                     </select>
303                                 </li>
304                             </ol>
305                         </fieldset> <!-- /.rows -->
306                     </div> <!-- /.modal-body -->
307                     <div class="modal-footer">
308                         <input type="hidden" name="registerid" value="[% register.id | html %]">
309                         <input type="hidden" name="op" value="refund">
310                         <button type="submit" class="btn btn-default" id="pos_refund_confirm">Confirm</button>
311                         <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
312                     </div> <!-- /.modal-footer -->
313                 </div> <!-- /.modal-content -->
314             </div> <!-- /.modal-dialog -->
315         </form> <!-- /#refund_form -->
316     </div> <!-- /#issueRefundModal -->
317
318     [% INCLUDE 'modals/cashup_summary.inc' %]
319
320     [% MACRO jsinclude BLOCK %]
321     [% INCLUDE 'datatables.inc' %]
322     [% Asset.js("lib/jquery/plugins/rowGroup/dataTables.rowGroup.min.js") | $raw %]
323     [% Asset.js("js/cashup_modal.js") | $raw %]
324     [% INCLUDE 'calendar.inc' %]
325     [% INCLUDE 'js-date-format.inc' %]
326     <script>
327         var sales_table = $("#sales").dataTable($.extend(true, {}, dataTablesDefaults, {
328             orderFixed: [ 0, 'asc'],
329             columnDefs: [ {
330                 targets: [ 0, 1 ],
331                 visible: false
332             }],
333             rowGroup: {
334                 dataSrc: 0,
335                 startRender: function ( rows, group ) {
336                     var details = JSON.parse(rows.data().pluck(1).pop());
337                     var identifier = details.identifier || group;
338                     return $('<tr class="'+details.type+'"/>')
339                         .append( '<td>'+identifier+'</td>' )
340                         .append( '<td colspan="2">'+details.description+'</td>' )
341                         .append( '<td>'+details.amount+'</td>' )
342                         .append( '<td><button class="printReceipt btn btn-default btn-xs" data-accountline="'+group+'"><i class="fa fa-print"></i> ' + _("Print receipt") + '</button></td>');
343                 },
344                 endRender: null,
345             },
346             initComplete: function() {
347                 $("#sales").show();
348             }
349         }));
350
351         var past_sales_table = $("#past_sales").dataTable($.extend(true, {}, dataTablesDefaults, {
352             orderFixed: [ 0, 'asc'],
353             columnDefs: [ {
354                 targets: [ 0, 1 ],
355                 visible: false
356             }],
357             rowGroup: {
358                 dataSrc: 0,
359                 startRender: function ( rows, group ) {
360                     var details = JSON.parse(rows.data().pluck(1).pop());
361                     var identifier = details.identifier || group;
362                     return $('<tr class="'+details.type+'"/>')
363                         .append( '<td>'+identifier+'</td>' )
364                         .append( '<td colspan="2">'+details.description+'</td>' )
365                         .append( '<td>'+details.amount+'</td>' )
366                         .append( '<td><button class="printReceipt btn btn-default btn-xs" data-accountline="'+group+'"><i class="fa fa-print"></i> Print receipt</button></td>');
367                 },
368                 endRender: null,
369             }
370         }));
371
372         $("#issueRefundModal").on("shown.bs.modal", function(e){
373            var button = $(e.relatedTarget);
374            var item = button.data('item');
375            $("#item + span").replaceWith(item);
376            var accountline = button.data('accountline');
377            $('#refundline').val(accountline);
378            var amount = button.data('amount');
379            $("#paid + span").replaceWith(amount);
380            $("#returned").attr({ "value": amount, "max": amount });
381            $("#returned, #transaction_type").focus();
382         });
383
384         $(".printReceipt").click(function() {
385             var accountlines_id = $(this).data('accountline');
386             var win = window.open('/cgi-bin/koha/pos/printreceipt.pl?action=print&accountlines_id=' + accountlines_id, '_blank');
387             win.focus();
388         });
389
390         $('.modal.printable').on('shown.bs.modal', function() {
391             $('.modal-dialog', this).addClass('focused');
392             $('body').addClass('modalprinter');
393
394             if ($(this).hasClass('autoprint')) {
395                 window.print();
396             }
397         }).on('hidden.bs.modal', function () {
398             $('.modal-dialog', this).removeClass('focused');
399             $('body').removeClass('modalprinter');
400         });
401
402         $('.printModal').click(function() {
403             window.print();
404         });
405
406
407         var cashups_table_url = "/api/v1/cash_registers/[% register.id | html %]/cashups?";
408         var cashups_table = $("#table_cashups").api({
409             "ajax": {
410                 "url": cashups_table_url
411             },
412             "header_filter": true,
413             "embed": [
414                "manager"
415             ],
416             "order": [[ 0, "asc" ]],
417             "columnDefs": [ {
418                 "targets": [0,1,2],
419                 "render": function (data, type, row, meta) {
420                     if ( type == 'display' ) {
421                         return data.escapeHtml();
422                     }
423                     return data;
424                 }
425             } ],
426             "columns": [
427                 {
428                     "data": "timestamp",
429                     "searchable": true,
430                     "orderable": true,
431                     "render": function(data, type, row, meta) {
432                         return $datetime(row.timestamp);
433                     }
434                 },
435                 {
436                     "data": "manager.firstname:manager.surname",
437                     "searchable": true,
438                     "orderable": true,
439                     "render": function(data, type, row, meta) {
440                         var fullname;
441                         if ( row.manager.firstname == null ) {
442                             fullname = row.manager.surname;
443                         }
444                         else {
445                             fullname = row.manager.firstname + " " + row.manager.surname;
446                         }
447                         return fullname;
448                     }
449                 },
450                 {
451                     "data": "amount",
452                     "searchable": true,
453                     "orderable": true,
454                     "render": function(data, type, row, meta) {
455                         var amt = row.amount * -1;
456                         return (amt).format_price();
457                     }
458                 },
459                 {
460                     "data": function( row, type, val, meta ) {
461                         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';
462                         return result;
463                     },
464                     "searchable": false,
465                     "orderable": false
466                 }
467             ]
468         }, [], 1);
469
470         $(document).ready(function() {
471             // http://jqueryui.com/demos/datepicker/#date-range
472             var dates = $( "#from, #to" ).datepicker({
473                 changeMonth: true,
474                 numberOfMonths: 1,
475                 onSelect: function( selectedDate ) {
476                     var option = this.id == "from" ? "minDate" : "maxDate",
477                         instance = $( this ).data( "datepicker" );
478                         date = $.datepicker.parseDate(
479                             instance.settings.dateFormat ||
480                             $.datepicker._defaults.dateFormat,
481                             selectedDate, instance.settings );
482                     dates.not( this ).datepicker( "option", option, date );
483                 }
484             });
485         });
486     </script>
487 [% END %]
488
489 [% INCLUDE 'intranet-bottom.inc' %]