Bug 23507: Add ability to show change given on auto-popup fee receipt from FinePaymen...
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / members / paycollect.tt
1 [% USE raw %]
2 [% USE Asset %]
3 [% USE Koha %]
4 [% USE Branches %]
5 [% USE AuthorisedValues %]
6 [% USE Price %]
7 [% SET footerjs = 1 %]
8 [% INCLUDE 'doc-head-open.inc' %]
9 <title>Koha &rsaquo; Patrons &rsaquo; Collect fine payment for  [% patron.firstname | html %] [% patron.surname | html %]</title>
10 [% INCLUDE 'doc-head-close.inc' %]
11 </head>
12
13 <body id="pat_paycollect" class="pat">
14 [% INCLUDE 'header.inc' %]
15 [% INCLUDE 'patron-search.inc' %]
16 <div id="breadcrumbs">
17     <a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo;
18     <a href="/cgi-bin/koha/members/members-home.pl">Patrons</a> &rsaquo;
19     <a href="/cgi-bin/koha/members/pay.pl?borrowernumber=[% patron.borrowernumber | uri %]">Pay fines for [% patron.firstname | html %] [% patron.surname | html %]</a> &rsaquo;
20     [% IF    ( pay_individual )      %]Pay an individual fine
21     [% ELSIF ( writeoff_individual ) %]Write off an individual fine
22     [% ELSE %]
23         [% IF ( selected_accts ) %]
24             [% IF type == 'writeoff' %]Write off an amount toward selected fines
25             [% ELSE                  %]Pay an amount toward selected fines
26             [% END %]
27         [% ELSE                      %]Pay an amount toward all fines
28         [% END %]
29     [% END %]
30 </div>
31
32 <div class="main container-fluid">
33     <div class="row">
34         <div class="col-sm-10 col-sm-push-2">
35             <main>
36
37 [% INCLUDE 'members-toolbar.inc' borrowernumber=patron.borrowernumber %]
38
39
40 <!-- The manual invoice and credit buttons -->
41 <div class="statictabs">
42 <ul>
43     <li>
44     <a href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% patron.borrowernumber | uri %]">Transactions</a>
45     </li>
46     <li class="active">
47     <a href="/cgi-bin/koha/members/pay.pl?borrowernumber=[% patron.borrowernumber | uri %]" >Make a payment</a>
48     </li>
49     <li>
50     <a href="/cgi-bin/koha/members/maninvoice.pl?borrowernumber=[% patron.borrowernumber | uri %]" >Create manual invoice</a>
51     </li>
52     <li>
53     <a href="/cgi-bin/koha/members/mancredit.pl?borrowernumber=[% patron.borrowernumber | uri %]" >Create manual credit</a>
54     </li>
55 </ul>
56 <div class="tabs-container">
57 [% IF ( error_over ) %]
58     <div id="error_message" class="dialog alert">
59     You must pay a value less than or equal to [% total_due | format('%.2f') %].
60     </div>
61 [% END %]
62
63 [% IF ( pay_individual ) %]
64     [% IF ( error_registers ) %]
65     <div id="error_message" class="dialog alert">
66         You must have at least one cash register associated with this branch before you can record payments.
67     </div>
68     [% ELSE %]
69
70     <form name="payindivfine" id="payindivfine" method="post" action="/cgi-bin/koha/members/paycollect.pl">
71     <input type="hidden" name="csrf_token" value="[% csrf_token | html %]" />
72     <input type="hidden" name="borrowernumber" id="borrowernumber" value="[% patron.borrowernumber | html %]" />
73     <input type="hidden" name="pay_individual" id="pay_individual" value="[% pay_individual | html %]" />
74     <input type="hidden" name="itemnumber" id="itemnumber" value="[% itemnumber | html %]" />
75     <input type="hidden" name="description" id="description" value="[% description | html %]" />
76     <input type="hidden" name="accounttype" id="accounttype" value="[% accounttype | html %]" />
77     <input type="hidden" name="amount" id="amount" value="[% amount | html %]" />
78     <input type="hidden" name="amountoutstanding" id="amountoutstanding" value="[% amountoutstanding | html %]" />
79     <input type="hidden" name="accountlines_id" id="accountlines_id" value="[% accountlines_id | html %]" />
80     <input type="hidden" name="title" id="title" value="[% title | html %]" />
81     <input type="hidden" name="change_given" id="change_given" />
82
83 <fieldset class="rows">
84     <legend>Pay an individual fine</legend>
85     <input type="hidden" name="payment_note" id="payment_note" value="[% payment_note | html %]" />
86     <table>
87     <thead><tr>
88             <th>Description</th>
89             <th>Account type</th>
90             <th>Amount</th>
91             <th>Amount outstanding</th>
92         </tr></thead>
93     <tfoot>
94         <tr><td colspan="3">Total amount payable:</td><td>[% amountoutstanding | format('%.2f') %]</td></tr>
95     </tfoot>
96     <tbody><tr>
97             <td>
98                 [% individual_description | html %]
99             </td>
100             <td>[% accounttype | html %]</td>
101             <td class="debit">[% amount | format('%.2f') %]</td>
102             <td class="debit">[% amountoutstanding | format('%.2f') %]</td>
103         </tr></tbody>
104 </table>
105
106 <ol>
107
108     <li>
109         <label for="paid">Amount being paid: </label>
110         <input name="paid" id="paid" value="[% amountoutstanding | $Price on_editing => 1 %]"/>
111     </li>
112     <li>
113         <label for="collected">Collected from patron: </label>
114         <input id="collected" value="[% amountoutstanding | $Price on_editing => 1 %]"/>
115     </li>
116     <li>
117         <label>Change to give: </label>
118         <span id="change">0.00</span>
119     </li>
120     [% SET payment_types = AuthorisedValues.GetAuthValueDropbox('PAYMENT_TYPE') %]
121     [% IF payment_types %]
122         <li>
123             <label for="payment_type">Payment type: </label>
124             <select name="payment_type" id="payment_type">
125                 <option value=""></option>
126                 [% FOREACH pt IN payment_types %]
127                     <option value="[% pt.authorised_value | html %]">[% pt.lib | html %]</option>
128                 [% END %]
129             </select>
130         </li>
131     [% END %]
132     [% IF Koha.Preference('UseCashRegisters') %]
133     <li>
134         <label for="cash_register">Cash register: </label>
135         <select name="cash_register" id="cash_register">
136             [% FOREACH register IN registers %]
137               [% IF register.id == registerid %]
138             <option value="[% register.id | html %]" selected="selected">[% register.name | html %]</option>
139               [% ELSE %]
140             <option value="[% register.id | html %]">[% register.name | html %]</option>
141               [% END %]
142             [% END %]
143         </select>
144     </li>
145     [% END %]
146 </ol>
147 </fieldset>
148
149         <div class="action">
150             <input type="submit" name="submitbutton" value="Confirm" />
151             <a class="cancel" href="/cgi-bin/koha/members/pay.pl?borrowernumber=[% patron.borrowernumber | html %]">Cancel</a>
152         </div>
153     </form>
154     [% END %]
155 [% ELSIF ( writeoff_individual ) %]
156     <form name="woindivfine" id="woindivfine" action="/cgi-bin/koha/members/pay.pl" method="post" >
157     <input type="hidden" name="csrf_token" value="[% csrf_token | html %]" />
158     <fieldset class="rows">
159     <legend>Write off an individual fine</legend>
160     <input type="hidden" name="borrowernumber" id="borrowernumber" value="[% patron.borrowernumber | html %]" />
161     <input type="hidden" name="pay_individual" id="pay_individual" value="[% pay_individual | html %]" />
162     <input type="hidden" name="itemnumber" id="itemnumber" value="[% itemnumber | html %]" />
163     <input type="hidden" name="description" id="description" value="[% description | html %]" />
164     <input type="hidden" name="accounttype" id="accounttype" value="[% accounttype | html %]" />
165     <input type="hidden" name="amount" id="amount" value="[% amount | html %]" />
166     <input type="hidden" name="accountlines_id" id="accountlines_id" value="[% accountlines_id | html %]" />
167     <input type="hidden" name="title" id="title" value="[% title | html %]" />
168     <input type="hidden" name="payment_note" id="payment_note" value="[% payment_note | html %]" />
169     <input type="hidden" name="amountoutstanding" id="amountoutstanding" value="[% amountoutstanding | html %]" />
170     <input type="hidden" name="confirm_writeoff" id="confirm_writeoff" value="1" />
171     <input type="hidden" name="change_given" id="change_given" />
172     <table>
173     <thead><tr>
174             <th>Description</th>
175             <th>Account type</th>
176             <th>Amount</th>
177             <th>Amount outstanding</th>
178         </tr></thead>
179     <tfoot><tr><td colspan="3">Total amount outstanding:</td><td>[% amountoutstanding | format('%.2f') %]</td></tr></tfoot>
180     <tbody><tr>
181             <td>[% description | html %] [% title | html %]</td>
182             <td>[% accounttype | html %]</td>
183             <td class="debit">[% amount | format('%.2f') %]</td>
184             <td class="debit">[% amountoutstanding | format('%.2f') %]</td>
185         </tr></tbody>
186     </table>
187
188             <ol>
189                 <li>
190                     <label for="paid">Writeoff amount: </label>
191                     <!-- default to writing off all -->
192                     <input name="amountwrittenoff" id="amountwrittenoff" value="[% amountoutstanding | $Price on_editing => 1 %]" type="text" />
193                 </li>
194             </ol>
195         </fieldset>
196         <div class="action">
197             <input type="submit" value="Write off this charge" />
198             <a class="cancel" href="/cgi-bin/koha/members/pay.pl?borrowernumber=[% patron.borrowernumber | html %]">Cancel</a>
199         </div>
200     </form>
201 [% ELSE %]
202     [% IF ( error_registers && type != 'writeoff' ) %]
203     <div id="error_message" class="dialog alert">
204         You must have at least one cash register associated with this branch before you can record payments.
205     </div>
206     [% ELSE %]
207
208     <form name="payfine" id="payfine" method="post" action="/cgi-bin/koha/members/paycollect.pl">
209     <input type="hidden" name="csrf_token" value="[% csrf_token | html %]" />
210     <input type="hidden" name="borrowernumber" id="borrowernumber" value="[% patron.borrowernumber | html %]" />
211     <input type="hidden" name="selected_accts" id="selected_accts" value="[% selected_accts | html %]" />
212     <input type="hidden" name="total" id="total" value="[% total | html %]" />
213     <input type="hidden" name="type" value="[% type | html %]" />
214     <input type="hidden" name="change_given" id="change_given" />
215
216     <fieldset class="rows">
217     [% IF ( selected_accts ) %]
218         [% IF type == 'writeoff' %]
219             <legend>Write off an amount toward selected fines</legend>
220         [% ELSE %]
221             <legend>Pay an amount toward selected fines</legend>
222         [% END %]
223     [% ELSE %]
224         <legend>Pay an amount toward all fines</legend>
225     [% END %]
226
227     <ol>
228         <li>
229             <span class="label">Total amount outstanding: </span>
230             <span class="debit">[% total | format('%.2f') %]</span>
231         </li>
232     <li>
233         <label for="paid">Amount paid :</label>
234         <input name="paid" id="paid" value="[% total | $Price on_editing => 1 %]"/>
235     </li>
236     <li>
237         [% IF type == 'writeoff' %]
238             <label for="collected">Writeoff amount: </label>
239         [% ELSE %]
240             <label for="collected">Collect from patron: </label>
241         [% END %]
242         <input id="collected" value="[% total | $Price on_editing => 1 %]"/>
243     </li>
244     <li>
245         <label>Change to give: </label>
246         <span id="change">0.00</span>
247     </li>
248
249     [% IF type != 'writeoff' %]
250     [% SET payment_types = AuthorisedValues.GetAuthValueDropbox('PAYMENT_TYPE') %]
251     [% IF payment_types %]
252         <li>
253             <label for="payment_type">Payment type: </label>
254             <select name="payment_type" id="payment_type">
255                 <option value=""></option>
256                 [% FOREACH pt IN payment_types %]
257                     <option value="[% pt.authorised_value | html %]">[% pt.lib | html %]</option>
258                 [% END %]
259             </select>
260         </li>
261     [% END %]
262
263     [% IF Koha.Preference('UseCashRegisters') %]
264     <li>
265         <label for="cash_register">Cash register: </label>
266         <select name="cash_register" id="cash_register">
267             [% FOREACH register IN registers %]
268               [% IF register.id == registerid %]
269             <option value="[% register.id | html %]" selected="selected">[% register.name | html %]</option>
270               [% ELSE %]
271             <option value="[% register.id | html %]">[% register.name | html %]</option>
272               [% END %]
273             [% END %]
274         </select>
275     </li>
276     [% END %]
277     [% END %]
278
279     <li>
280         <label for="selected_accts_notes">Note: </label>
281         <textarea name="selected_accts_notes" id="selected_accts_notes">[% selected_accts_notes | html %]</textarea>
282     </li>
283     </ol>
284     </fieldset>
285     <div class="action">
286         <input type="submit" name="submitbutton" value="Confirm" />
287         <a class="cancel" href="/cgi-bin/koha/members/pay.pl?borrowernumber=[% patron.borrowernumber | html %]">Cancel</a>
288     </div>
289     </form>
290     [% END %]
291 [% END %]
292 </div></div>
293
294             </main>
295         </div> <!-- /.col-sm-10.col-sm-push-2 -->
296
297         <div class="col-sm-2 col-sm-pull-10">
298             <aside>
299                 [% INCLUDE 'circ-menu.inc' %]
300             </aside>
301         </div> <!-- /.col-sm-2.col-sm-pull-10 -->
302      </div> <!-- /.row -->
303
304 <!-- Modal -->
305 <div id="confirm_change_form" class="modal" tabindex="-1" role="dialog" aria-hidden="true">
306     <div class="modal-dialog">
307         <div class="modal-content">
308             <div class="modal-header">
309                 <h3>The amount collected is more than the outstanding charge</h3>
310             </div>
311             <div class="modal-body">
312                 <p>The amount collected from the patron is higher than the amount to be paid.</p>
313                 <p>The change to give is <b><span id="modal_change">0.00</span></b>.</p>
314                 <p>Confirm this payment?</p>
315             </div>
316             <div class="modal-footer">
317                 <button class="btn btn-default approve" id="modal_submit" type="button"><i class="fa fa-check"></i> Yes</button>
318                 <button class="btn btn-default deny cancel" href="#" data-dismiss="modal" aria-hidden="true"><i class="fa fa-times"></i> No</button>
319             </div>
320         </div>
321     </div>
322 </div>
323
324 [% MACRO jsinclude BLOCK %]
325     [% INCLUDE 'str/members-menu.inc' %]
326     [% Asset.js("js/members-menu.js") | $raw %]
327     <script>
328         $(document).ready(function() {
329             [% IF payment_id && Koha.Preference('FinePaymentAutoPopup') %]
330                 window.open('/cgi-bin/koha/members/printfeercpt.pl?action=print&accountlines_id=[% payment_id | html %]&change_given=[% change_given | html %]&borrowernumber=[% patron.borrowernumber | html %]', '_blank');
331             [% END %]
332
333             var forms = $('#payindivfine, #payfine');
334             var change = $('#change')[0];
335
336             $('#payindivfine, #payfine').preventDoubleFormSubmit();
337             $("#paid, #collected").on("change",function() {
338                 moneyFormat( this );
339                 if (change != undefined) {
340                     updateChangeValues();
341                 }
342             });
343
344             if (change != undefined) {
345                 forms.on("submit", function(e) {
346                     if (change.innerHTML > 0.00) {
347                         e.preventDefault();
348                         $("#confirm_change_form").modal("show");
349                     } else {
350                         return true;
351                     }
352                 });
353             }
354
355             $("#confirm_change_form").on("hidden.bs.modal", function(){
356                 // remove class added by preventDoubleFormSubmit if necessary
357                 $("body, form input[type='submit'], form button[type='submit'], form a").removeClass('waiting');
358             });
359
360             $('#modal_submit').click(function() {
361                 forms[0].submit();
362             });
363         });
364
365         prevent_default = 1;
366         $('#woindivfine').on('submit', function(e){
367             if ( prevent_default ) {
368                 e.preventDefault();
369
370                 let amount_outstanding = parseFloat( $('#amountoutstanding').attr('value') );
371                 let amount_writeoff = parseFloat( $('#amountwrittenoff').attr('value') );
372                 if ( amount_writeoff > amount_outstanding ) {
373                     alert(_("You are attemping to writeoff more than the value of the fee."));
374                     $('#woindivfine').beenSubmitted = false;
375                 } else {
376                     prevent_default = 0;
377                     $('#woindivfine').preventDoubleFormSubmit();
378                     $('#woindivfine').submit();
379                 }
380             }
381         });
382
383         function moneyFormat(textObj) {
384             var newValue = textObj.value;
385             var decAmount = "";
386             var dolAmount = "";
387             var decFlag   = false;
388             var aChar     = "";
389
390             for(i=0; i < newValue.length; i++) {
391                 aChar = newValue.substring(i, i+1);
392                 if (aChar >= "0" && aChar <= "9") {
393                     if(decFlag) {
394                         decAmount = "" + decAmount + aChar;
395                     }
396                     else {
397                         dolAmount = "" + dolAmount + aChar;
398                     }
399                 }
400                 if (aChar == ".") {
401                     if (decFlag) {
402                         dolAmount = "";
403                         break;
404                     }
405                     decFlag = true;
406                 }
407             }
408
409             if (dolAmount == "") {
410                 dolAmount = "0";
411             }
412         // Strip leading 0s
413             if (dolAmount.length > 1) {
414                 while(dolAmount.length > 1 && dolAmount.substring(0,1) == "0") {
415                     dolAmount = dolAmount.substring(1,dolAmount.length);
416                 }
417             }
418             if (decAmount.length > 2) {
419                 decAmount = decAmount.substring(0,2);
420             }
421         // Pad right side
422             if (decAmount.length == 1) {
423                decAmount = decAmount + "0";
424             }
425             if (decAmount.length == 0) {
426                decAmount = decAmount + "00";
427             }
428
429             textObj.value = dolAmount + "." + decAmount;
430         }
431
432         function updateChangeValues() {
433             var change = $('#change')[0];
434             change.innerHTML = Math.round(($('#collected')[0].value - $('#paid')[0].value) * 100) / 100;
435             if (change.innerHTML <= 0) {
436                 change.innerHTML = "0.00";
437                 $('input[name="change_given"]').val('0.00');
438             } else {
439                 change.value = change.innerHTML;
440                 moneyFormat(change);
441                 change.innerHTML = change.value;
442                 $('input[name="change_given"]').val(change.value);
443             }
444
445             $('#modal_change').html(change.innerHTML);
446         }
447     </script>
448 [% END %]
449
450 [% INCLUDE 'intranet-bottom.inc' %]