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