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