Bug 24082: Add refund action to relevant lines
[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 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         </div>
121
122         <div class="col-sm-2 col-sm-pull-10">
123             <aside>
124                 [% INCLUDE 'pos-menu.inc' %]
125             </aside>
126         </div>
127     </div><!-- /.row -->
128
129     <!-- Confirm cashup modal -->
130     <div class="modal" id="confirmCashupModal" tabindex="-1" role="dialog" aria-labelledby="confirmCashupLabel">
131         <div class="modal-dialog" role="document">
132             <div class="modal-content">
133                 <div class="modal-header">
134                     <button type="button" class="closebtn" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
135                     <h4 class="modal-title" id="confirmCashupLabel">Confirm cashup of <em>[% register.description | html %]</em></h4>
136                 </div>
137                 <div class="modal-body">
138                     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 %].
139                 </div> <!-- /.modal-body -->
140                 <div class="modal-footer">
141                     <a href="/cgi-bin/koha/pos/register.pl?op=cashup" class="btn btn-default">Confirm</a>
142                     <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
143                 </div> <!-- /.modal-footer -->
144             </div> <!-- /.modal-content -->
145         </div> <!-- /.modal-dialog -->
146     </div> <!-- /#confirmCashupModal -->
147
148     <!-- Issue refund modal -->
149     <div class="modal" id="issueRefundModal" tabindex="-1" role="dialog" aria-labelledby="issueRefundLabel">
150         <form id="refund_form" method="post" enctype="multipart/form-data" class="validated">
151             <input type="hidden" name="accountline" value="" id="refundline">
152             <div class="modal-dialog" role="document">
153                 <div class="modal-content">
154                     <div class="modal-header">
155                         <button type="button" class="closebtn" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
156                         <h4 class="modal-title" id="issueRefundLabel">Issue refund from <em>[% register.description | html %]</em></h4>
157                     </div>
158                     <div class="modal-body">
159                         <fieldset class="rows">
160                             <ol>
161                                 <li>
162                                     <span id="item" class="label">Item: </span><span></span>
163                                 </li>
164                                 <li>
165                                     <span id="paid" class="label">Amount paid: </span><span></span>
166                                 </li>
167                                 <li>
168                                     <label class="required" for="amount">Returned to patron: </label>
169                                     <input type="number" step="0.01" id="returned" name="amount" min="0.00" required="required">
170                                     <span class="required">Required</span>
171                                 </li>
172                                 [% SET payment_types = [] %]
173                                 [% FOR pt IN AuthorisedValues.GetAuthValueDropbox('PAYMENT_TYPE') %]
174                                     [% NEXT IF pt.authorised_value.grep("^SIP[[:digit:]]{2}$").size() %]
175                                     [% payment_types.push(pt) %]
176                                 [% END %]
177                                 <li>
178                                     <label for="transaction_type">Transaction type: </label>
179                                     <select name="transaction_type" id="transaction_type">
180                                         [% FOREACH pt IN payment_types %]
181                                             <option value="[% pt.authorised_value | html %]">[% pt.lib | html %]</option>
182                                         [% END %]
183                                     </select>
184                                 </li>
185                             </ol>
186                         </fieldset> <!-- /.rows -->
187                     </div> <!-- /.modal-body -->
188                     <div class="modal-footer">
189                         <input type="hidden" name="registerid" value="[% register.id | html %]">
190                         <input type="hidden" name="op" value="refund">
191                         <button type="submit" class="btn btn-default">Confirm</button>
192                         <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
193                     </div> <!-- /.modal-footer -->
194                 </div> <!-- /.modal-content -->
195             </div> <!-- /.modal-dialog -->
196         </form> <!-- /#refund_form -->
197     </div> <!-- /#issueRefundModal -->
198
199 [% MACRO jsinclude BLOCK %]
200     [% INCLUDE 'datatables.inc' %]
201     [% Asset.js("lib/jquery/plugins/rowGroup/dataTables.rowGroup.min.js") | $raw %]
202     <script>
203         var sales_table = $("#sales").dataTable($.extend(true, {}, dataTablesDefaults, {
204             orderFixed: [ 0, 'asc'],
205             columnDefs: [ {
206                 targets: [ 0, 1 ],
207                 visible: false
208             }],
209             rowGroup: {
210                 dataSrc: 0,
211                 startRender: function ( rows, group ) {
212                     var details = JSON.parse(rows.data().pluck(1).pop());
213                     return $('<tr class="'+details.type+'"/>')
214                         .append( '<td>'+group+'</td>' )
215                         .append( '<td colspan="2">'+details.description+'</td>' )
216                         .append( '<td>'+details.amount+'</td>' )
217                         .append( '<td><button class="printReceipt btn btn-default btn-xs" data-accountline="'+group+'"><i class="fa fa-print"></i> ' + _("Print receipt") + '</button></td>');
218                 },
219                 endRender: null,
220             }
221         }));
222
223         $("#issueRefundModal").on("shown.bs.modal", function(e){
224            var button = $(e.relatedTarget);
225            var item = button.data('item');
226            $("#item + span").replaceWith(item);
227            var accountline = button.data('accountline');
228            $('#refundline').val(accountline);
229            var amount = button.data('amount');
230            $("#paid + span").replaceWith(amount);
231            $("#returned").attr({ "value": amount, "max": amount });
232            $("#returned, #transaction_type").focus();
233         });
234
235         $(".printReceipt").click(function() {
236             var accountlines_id = $(this).data('accountline');
237             var win = window.open('/cgi-bin/koha/pos/printreceipt.pl?action=print&accountlines_id=' + accountlines_id, '_blank');
238             win.focus();
239         });
240     </script>
241 [% END %]
242
243 [% INCLUDE 'intranet-bottom.inc' %]