Bug 24082: Add access to historical transactions
[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 alert">
27                 You must have at least one cash register associated with this branch before you can record payments.
28             </div>
29             [% ELSE %]
30
31             [% IF ( CAN_user_cash_management_cashup ) %]
32             <div id="toolbar" class="btn-toolbar">
33                 <button type="button" class="btn btn-default" data-toggle="modal" data-target="#confirmCashupModal" ><i class="fa fa-money"></i> Record cashup</button>
34             </div>
35             [% END %]
36
37             <h1>Register transaction details for [% register.name | html %]</h1>
38
39             <h2>Summary</h2>
40             <ul>
41                 [% IF register.last_cashup %]
42                 <li>Last cashup: [% register.last_cashup.timestamp | $KohaDates with_hours => 1 %]</li>
43                 [% END %]
44                 <li>Float: [% register.starting_float | $Price %]</li>
45                 <li>Total income (cash): [% accountlines.credits_total * -1 | $Price %] ([% accountlines.credits_total(payment_type => 'CASH') * -1 | $Price %])</li>
46                 <li>Total outgoing (cash): [% accountlines.debits_total * -1 | $Price %] ([% accountlines.debits_total( payment_type => 'CASH') * -1 | $Price %])</li>
47                 <li>Total bankable: [% accountlines.total( payment_type => 'CASH') * -1 | $Price %]</li>
48             </ul>
49
50             [% IF register.last_cashup %]
51             <h2>Transactions since [% register.last_cashup.timestamp | $KohaDates with_hours => 1 %]</h2>
52             [% ELSE %]
53             <h2>Transactions to date</h2>
54             [% END %]
55             <table id="sales" class="table_sales">
56                 <thead>
57                     <th>ID</th>
58                     <th>DATA</th>
59                     <th>Transaction</th>
60                     <th>Description</th>
61                     <th>Price</th>
62                     <th>Total</th>
63                     <th>Actions</th>
64                 </thead>
65                 <tbody>
66                     [% FOREACH accountline IN accountlines %]
67                         [% IF accountline.is_credit %]
68                             [% FOREACH credit IN accountline.credit_offsets %]
69                             [% IF credit.debit %]
70                             <tr>
71                                 <td>[% accountline.accountlines_id | html %]</td>
72                                 <td>{ "type": "credit", "description": "[%- PROCESS account_type_description account=accountline -%] ([% accountline.payment_type | html %])", "amount": "[% accountline.amount * -1 | $Price %]" }</td>
73                                 <td></td>
74                                 <td>
75                                     [%- PROCESS account_type_description account=credit.debit -%]
76                                     [%- IF credit.debit.description -%] ([% credit.debit.description | html %])[%- END -%]
77                                     [%- 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 -%]
78                                 </td>
79                                 <td>[% credit.debit.amount | $Price %]</td>
80                                 <td></td>
81                                 <td>
82                                     [% IF CAN_user_cash_management_anonymous_refund && !(credit.debit.status == 'REFUNDED' ) %]
83                                     <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>
84                                     [% ELSIF CAN_user_updatecharges_refund && !(credit.debit.status == 'REFUNDED') && credit.debit.borrowernumber %]
85                                     <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>
86                                     [% END %]
87                                 </td>
88                             </tr>
89                             [% END %]
90                             [% END %]
91                         [% ELSE %]
92                             [% FOREACH debit IN accountline.debit_offsets %]
93                             [% IF debit.credit %]
94                             <tr>
95                                 <td>[% accountline.accountlines_id | html %]</td>
96                                 <td>{ "type": "debit", "description": "[%- PROCESS account_type_description account=accountline -%] ([% accountline.payment_type | html %])", "amount": "[% accountline.amount * -1 | $Price %]" }</td>
97                                 <td></td>
98                                 <td>[%- PROCESS account_type_description account=debit.credit -%]</td>
99                                 <td>
100                                     [%- IF debit.credit.description %][% debit.credit.description | html %][%- END -%]
101                                     [%- 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 -%]
102                                 </td>
103                                 <td>[% debit.credit.amount | $Price %]</td>
104                                 <td></td>
105                             </tr>
106                             [% END %]
107                             [% END %]
108                         [% END %]
109                     [% END %]
110                 </tbody>
111                 <tfoot>
112                     <tr>
113                         <td colspan="5">Total income: </td>
114                         <td>[% accountlines.total * -1 | $Price %]</td>
115                         <td></td>
116                     </tr>
117                 </tfoot>
118             </table>
119             [% END %]
120
121             [% IF register.cashups %]
122             <h2>Older transactions</h2>
123             <form method="GET" action="/cgi-bin/koha/pos/register.pl">
124                         <fieldset class="rows">
125                             Please select a date range to display transactions for:
126                             <ol>
127                                 <li>
128                                     <label for="trange_f">From: </label>
129                                     <input type="text" size="10" id="from" name="trange_f" value="[% trange_f | html %]"/>
130                                     <label class="inline" for="trange_t">To: </label>
131                                     [% IF trange_t %]
132                                     <input size="10" id="to" name="trange_t" value="[% trange_t | html %]" type="text"/>
133                                     [% ELSE %]
134                                     <input size="10" id="to" name="trange_t" value="[% register.last_cashup.timestamp | $KohaDates with_hours => 0, dateformat => 'metric' %]" type="text"/>
135                                     [% END %]
136                                     <span class="hint">[% INCLUDE 'date-format.inc' %]</span>
137                                 </li>
138                             </ol>
139                         </fieldset>
140
141             <div class="action">
142                     <input type="hidden" name="registerid" value="[% register.id | html %]">
143                     <input type="submit" value="Display" />
144             </div>
145             </form>
146
147             [% IF trange_f %]
148             <table id="past_sales" class="past_sales_table">
149                 <thead>
150                     <th>
151                         ID
152                     </th>
153                     <th>
154                         DATA
155                     </th>
156                     <th>
157                         Transaction
158                     </th>
159                     <th>
160                         Description
161                     </th>
162                     <th>
163                         Price
164                     </th>
165                     <th>
166                         Total
167                     </th>
168                     <th>
169                         Actions
170                     </th>
171                 </thead>
172                 <tbody>
173                     [% FOREACH accountline IN past_accountlines %]
174                         [% IF accountline.is_credit %]
175                             [% FOREACH credit IN accountline.credit_offsets %]
176                             [% IF credit.debit %]
177                             <tr>
178                                 <td>[% accountline.accountlines_id %]</td>
179                                 <td>{ "type": "credit", "description": "[%- PROCESS account_type_description account=accountline -%] ([% accountline.payment_type | html %])", "amount": "[% accountline.amount * -1 | $Price %]" }</td>
180                                 <td></td>
181                                 <td>[%- PROCESS account_type_description account=credit.debit -%]
182                                     [%- IF credit.debit.description -%] ([% credit.debit.description | html %])[%- END -%]
183                                     [%- 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 -%]
184                                 </td>
185                                 <td>[% credit.debit.amount | $Price %]</td>
186                                 <td></td>
187                                 <td>
188                                     [% IF CAN_user_cash_management_refund_cash_registers && !(credit.debit.status == 'REFUNDED' ) %]
189                                     <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>
190                                     [% END %]
191                                 </td>
192                             </tr>
193                             [% END %]
194                             [% END %]
195                         [% ELSE %]
196                             [% FOREACH debit IN accountline.debit_offsets %]
197                             [% IF debit.credit %]
198                             <tr>
199                                 <td>[% accountline.accountlines_id %]</td>
200                                 <td>{ "type": "debit", "description": "[%- PROCESS account_type_description account=accountline -%] ([% accountline.payment_type | html %])", "amount": "[% accountline.amount * -1 | $Price %]" }</td>
201                                 <td></td>
202                                 <td>[%- PROCESS account_type_description account=debit.credit -%]</td>
203                                 <td>[%- IF debit.credit.description %][% debit.credit.description | html %][% END %]
204         &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>
205                                 <td>[% debit.credit.amount | $Price %]</td>
206                                 <td></td>
207                             </tr>
208                             [% END %]
209                             [% END %]
210                         [% END %]
211                     [% END %]
212                 </tbody>
213                 <tfoot>
214                     <tr>
215                         <td colspan="5">Total income: </td>
216                         <td>[% past_accountlines.total * -1 | $Price %]</td>
217                         <td></td>
218                     </tr>
219                 </tfoot>
220             </table>
221             [% END %]
222
223             [% END %]
224         </div>
225
226         <div class="col-sm-2 col-sm-pull-10">
227             <aside>
228                 [% INCLUDE 'pos-menu.inc' %]
229             </aside>
230         </div>
231     </div><!-- /.row -->
232
233     <!-- Confirm cashup modal -->
234     <div class="modal" id="confirmCashupModal" tabindex="-1" role="dialog" aria-labelledby="confirmCashupLabel">
235         <div class="modal-dialog" role="document">
236             <div class="modal-content">
237                 <div class="modal-header">
238                     <button type="button" class="closebtn" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
239                     <h4 class="modal-title" id="confirmCashupLabel">Confirm cashup of <em>[% register.description | html %]</em></h4>
240                 </div>
241                 <div class="modal-body">
242                     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 %].
243                 </div> <!-- /.modal-body -->
244                 <div class="modal-footer">
245                     <a href="/cgi-bin/koha/pos/register.pl?op=cashup" class="btn btn-default">Confirm</a>
246                     <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
247                 </div> <!-- /.modal-footer -->
248             </div> <!-- /.modal-content -->
249         </div> <!-- /.modal-dialog -->
250     </div> <!-- /#confirmCashupModal -->
251
252     <!-- Issue refund modal -->
253     <div class="modal" id="issueRefundModal" tabindex="-1" role="dialog" aria-labelledby="issueRefundLabel">
254         <form id="refund_form" method="post" enctype="multipart/form-data" class="validated">
255             <input type="hidden" name="accountline" value="" id="refundline">
256             <div class="modal-dialog" role="document">
257                 <div class="modal-content">
258                     <div class="modal-header">
259                         <button type="button" class="closebtn" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
260                         <h4 class="modal-title" id="issueRefundLabel">Issue refund from <em>[% register.description | html %]</em></h4>
261                     </div>
262                     <div class="modal-body">
263                         <fieldset class="rows">
264                             <ol>
265                                 <li>
266                                     <span id="item" class="label">Item: </span><span></span>
267                                 </li>
268                                 <li>
269                                     <span id="paid" class="label">Amount paid: </span><span></span>
270                                 </li>
271                                 <li>
272                                     <label class="required" for="amount">Returned to patron: </label>
273                                     <input type="number" step="0.01" id="returned" name="amount" min="0.00" required="required">
274                                     <span class="required">Required</span>
275                                 </li>
276                                 [% SET payment_types = [] %]
277                                 [% FOR pt IN AuthorisedValues.GetAuthValueDropbox('PAYMENT_TYPE') %]
278                                     [% NEXT IF pt.authorised_value.grep("^SIP[[:digit:]]{2}$").size() %]
279                                     [% payment_types.push(pt) %]
280                                 [% END %]
281                                 <li>
282                                     <label for="transaction_type">Transaction type: </label>
283                                     <select name="transaction_type" id="transaction_type">
284                                         [% FOREACH pt IN payment_types %]
285                                             <option value="[% pt.authorised_value | html %]">[% pt.lib | html %]</option>
286                                         [% END %]
287                                     </select>
288                                 </li>
289                             </ol>
290                         </fieldset> <!-- /.rows -->
291                     </div> <!-- /.modal-body -->
292                     <div class="modal-footer">
293                         <input type="hidden" name="registerid" value="[% register.id | html %]">
294                         <input type="hidden" name="op" value="refund">
295                         <button type="submit" class="btn btn-default">Confirm</button>
296                         <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
297                     </div> <!-- /.modal-footer -->
298                 </div> <!-- /.modal-content -->
299             </div> <!-- /.modal-dialog -->
300         </form> <!-- /#refund_form -->
301     </div> <!-- /#issueRefundModal -->
302
303 [% MACRO jsinclude BLOCK %]
304     [% INCLUDE 'datatables.inc' %]
305     [% Asset.js("lib/jquery/plugins/rowGroup/dataTables.rowGroup.min.js") | $raw %]
306     [% INCLUDE 'calendar.inc' %]
307     <script>
308         var sales_table = $("#sales").dataTable($.extend(true, {}, dataTablesDefaults, {
309             orderFixed: [ 0, 'asc'],
310             columnDefs: [ {
311                 targets: [ 0, 1 ],
312                 visible: false
313             }],
314             rowGroup: {
315                 dataSrc: 0,
316                 startRender: function ( rows, group ) {
317                     var details = JSON.parse(rows.data().pluck(1).pop());
318                     return $('<tr class="'+details.type+'"/>')
319                         .append( '<td>'+group+'</td>' )
320                         .append( '<td colspan="2">'+details.description+'</td>' )
321                         .append( '<td>'+details.amount+'</td>' )
322                         .append( '<td><button class="printReceipt btn btn-default btn-xs" data-accountline="'+group+'"><i class="fa fa-print"></i> ' + _("Print receipt") + '</button></td>');
323                 },
324                 endRender: null,
325             }
326         }));
327
328         var past_sales_table = $("#past_sales").dataTable($.extend(true, {}, dataTablesDefaults, {
329             orderFixed: [ 0, 'asc'],
330             columnDefs: [ {
331                 targets: [ 0, 1 ],
332                 visible: false
333             }],
334             rowGroup: {
335                 dataSrc: 0,
336                 startRender: function ( rows, group ) {
337                     var details = JSON.parse(rows.data().pluck(1).pop());
338                     return $('<tr class="'+details.type+'"/>')
339                         .append( '<td>'+group+'</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         }));
347
348         $("#issueRefundModal").on("shown.bs.modal", function(e){
349            var button = $(e.relatedTarget);
350            var item = button.data('item');
351            $("#item + span").replaceWith(item);
352            var accountline = button.data('accountline');
353            $('#refundline').val(accountline);
354            var amount = button.data('amount');
355            $("#paid + span").replaceWith(amount);
356            $("#returned").attr({ "value": amount, "max": amount });
357            $("#returned, #transaction_type").focus();
358         });
359
360         $(".printReceipt").click(function() {
361             var accountlines_id = $(this).data('accountline');
362             var win = window.open('/cgi-bin/koha/pos/printreceipt.pl?action=print&accountlines_id=' + accountlines_id, '_blank');
363             win.focus();
364         });
365
366         $(document).ready(function() {
367             // http://jqueryui.com/demos/datepicker/#date-range
368             var dates = $( "#from, #to" ).datepicker({
369                 changeMonth: true,
370                 numberOfMonths: 1,
371                 onSelect: function( selectedDate ) {
372                     var option = this.id == "from" ? "minDate" : "maxDate",
373                         instance = $( this ).data( "datepicker" );
374                         date = $.datepicker.parseDate(
375                             instance.settings.dateFormat ||
376                             $.datepicker._defaults.dateFormat,
377                             selectedDate, instance.settings );
378                     dates.not( this ).datepicker( "option", option, date );
379                 }
380             });
381         });
382     </script>
383 [% END %]
384
385 [% INCLUDE 'intranet-bottom.inc' %]