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