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