Bug 19617: Allow 'writeoff of selected'
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / members / paycollect.tt
1 [% USE Asset %]
2 [% USE Koha %]
3 [% USE Branches %]
4 [% USE AuthorisedValues %]
5 [% USE Price %]
6 [% SET footerjs = 1 %]
7 [% INCLUDE 'doc-head-open.inc' %]
8 <title>Koha &rsaquo; Patrons &rsaquo; Collect fine payment for  [% patron.firstname %] [% patron.surname %]</title>
9 [% INCLUDE 'doc-head-close.inc' %]
10 </head>
11
12 <body id="pat_paycollect" class="pat">
13 [% INCLUDE 'header.inc' %]
14 [% INCLUDE 'patron-search.inc' %]
15 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/members/members-home.pl">Patrons</a>  &rsaquo; <a href="/cgi-bin/koha/members/pay.pl?borrowernumber=[% patron.borrowernumber %]">Pay fines for [% patron.firstname %] [% patron.surname %]</a> &rsaquo; [% IF ( pay_individual ) %]Pay an individual fine[% ELSIF ( writeoff_individual ) %]Write off an individual fine[% ELSE %][% IF ( selected_accts ) %][% IF type == 'write    off' %]Write off an amount toward selected fines[% ELSE %]Pay an amount toward selected fines[% END %][% ELSE %]Pay an amount toward all fines[% END %][% END %]</div>
16
17 <div id="doc3" class="yui-t2">
18
19 <div id="bd">
20 <div id="yui-main">
21 <div class="yui-b">
22 [% INCLUDE 'members-toolbar.inc' borrowernumber=patron.borrowernumber %]
23
24
25 <!-- The manual invoice and credit buttons -->
26 <div class="statictabs">
27 <ul>
28     <li>
29     <a href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% patron.borrowernumber %]">Account</a>
30     </li>
31     <li class="active">
32     <a href="/cgi-bin/koha/members/pay.pl?borrowernumber=[% patron.borrowernumber %]" >Pay fines</a>
33     </li>
34     <li>
35     <a href="/cgi-bin/koha/members/maninvoice.pl?borrowernumber=[% patron.borrowernumber %]" >Create manual invoice</a>
36     </li>
37     <li>
38     <a href="/cgi-bin/koha/members/mancredit.pl?borrowernumber=[% patron.borrowernumber %]" >Create manual credit</a>
39     </li>
40 </ul>
41 <div class="tabs-container">
42 [% IF ( error_over ) %]
43     <div id="error_message" class="dialog alert">
44     You must pay a value less than or equal to [% total_due | format('%.2f') %].
45     </div>
46 [% END %]
47
48 [% IF ( pay_individual ) %]
49     <form name="payindivfine" id="payindivfine" method="post" action="/cgi-bin/koha/members/paycollect.pl">
50     <input type="hidden" name="csrf_token" value="[% csrf_token %]" />
51     <input type="hidden" name="borrowernumber" id="borrowernumber" value="[% patron.borrowernumber %]" />
52     <input type="hidden" name="pay_individual" id="pay_individual" value="[% pay_individual %]" />
53     <input type="hidden" name="itemnumber" id="itemnumber" value="[% itemnumber %]" />
54     <input type="hidden" name="description" id="description" value="[% description %]" />
55     <input type="hidden" name="accounttype" id="accounttype" value="[% accounttype %]" />
56     <input type="hidden" name="amount" id="amount" value="[% amount %]" />
57     <input type="hidden" name="amountoutstanding" id="amountoutstanding" value="[% amountoutstanding %]" />
58     <input type="hidden" name="accountlines_id" id="accountlines_id" value="[% accountlines_id %]" />
59     <input type="hidden" name="title" id="title" value="[% title %]" />
60
61 <fieldset class="rows">
62     <legend>Pay an individual fine</legend>
63     <input type="hidden" name="payment_note" id="payment_note" value="[% payment_note %]" />
64     <table>
65     <thead><tr>
66             <th>Description</th>
67             <th>Account type</th>
68             <th>Amount</th>
69             <th>Amount outstanding</th>
70         </tr></thead>
71     <tfoot>
72         <td colspan="3">Total amount payable:</td><td>[% amountoutstanding | format('%.2f') %]</td>
73     </tfoot>
74     <tbody><tr>
75             <td>
76                 [% individual_description %]
77             </td>
78             <td>[% accounttype %]</td>
79             <td class="debit">[% amount | format('%.2f') %]</td>
80             <td class="debit">[% amountoutstanding | format('%.2f') %]</td>
81         </tr></tbody>
82 </table>
83
84 <ol>
85
86     <li>
87         <label for="paid">Collect from patron: </label>
88             <!-- default to paying all -->
89         <input name="paid" id="paid" value="[% amountoutstanding %]" />
90     </li>
91     [% SET payment_types = AuthorisedValues.GetAuthValueDropbox('PAYMENT_TYPE') %]
92     [% IF payment_types %]
93         <li>
94             <label for="payment_type">Payment type: </label>
95             <select name="payment_type" id="payment_type">
96                 <option value=""></option>
97                 [% FOREACH pt IN payment_types %]
98                     <option value="[% pt.authorised_value %]">[% pt.lib %]</option>
99                 [% END %]
100             </select>
101         </li>
102     [% END %]
103 </ol>
104 </fieldset>
105
106     <div class="action"><input type="submit" name="submitbutton" value="Confirm" />
107         <a class="cancel" href="/cgi-bin/koha/members/pay.pl?borrowernumber=[% patron.borrowernumber %]">Cancel</a></div>
108     </form>
109 [% ELSIF ( writeoff_individual ) %]
110     <form name="woindivfine" id="woindivfine" action="/cgi-bin/koha/members/pay.pl" method="post" >
111     <input type="hidden" name="csrf_token" value="[% csrf_token %]" />
112     <fieldset class="rows">
113     <legend>Write off an individual fine</legend>
114     <input type="hidden" name="borrowernumber" id="borrowernumber" value="[% patron.borrowernumber %]" />
115     <input type="hidden" name="pay_individual" id="pay_individual" value="[% pay_individual %]" />
116     <input type="hidden" name="itemnumber" id="itemnumber" value="[% itemnumber %]" />
117     <input type="hidden" name="description" id="description" value="[% description %]" />
118     <input type="hidden" name="accounttype" id="accounttype" value="[% accounttype %]" />
119     <input type="hidden" name="amount" id="amount" value="[% amount %]" />
120     <input type="hidden" name="accountlines_id" id="accountlines_id" value="[% accountlines_id %]" />
121     <input type="hidden" name="title" id="title" value="[% title %]" />
122     <input type="hidden" name="payment_note" id="payment_note" value="[% payment_note %]" />
123     <input type="hidden" name="amountoutstanding" id="amountoutstanding" value="[% amountoutstanding %]" />
124     <input type="hidden" name="confirm_writeoff" id="confirm_writeoff" value="1" />
125     <table>
126     <thead><tr>
127             <th>Description</th>
128             <th>Account type</th>
129             <th>Amount</th>
130             <th>Amount outstanding</th>
131         </tr></thead>
132     <tfoot><td colspan="3">Total amount outstanding:</td><td>[% amountoutstanding | format('%.2f') %]</td></tfoot>
133     <tbody><tr>
134             <td>[% description %] [% title %]</td>
135             <td>[% accounttype %]</td>
136             <td class="debit">[% amount | format('%.2f') %]</td>
137             <td class="debit">[% amountoutstanding | format('%.2f') %]</td>
138         </tr></tbody>
139     </table>
140
141             <ol>
142                 <li>
143                     <label for="paid">Writeoff amount: </label>
144                     <!-- default to writing off all -->
145                     <input name="amountwrittenoff" id="amountwrittenoff" value="[% amountoutstanding | $Price on_editing => 1 %]" />
146                 </li>
147             </ol>
148         </fieldset>
149         <div class="action">
150             <input type="submit" value="Write off this charge" />
151             <a class="cancel" href="/cgi-bin/koha/members/pay.pl?borrowernumber=[% patron.borrowernumber %]">Cancel</a>
152         </div>
153     </form>
154 [% ELSE %]
155
156     <form name="payfine" id="payfine" method="post" action="/cgi-bin/koha/members/paycollect.pl">
157     <input type="hidden" name="csrf_token" value="[% csrf_token %]" />
158     <input type="hidden" name="borrowernumber" id="borrowernumber" value="[% patron.borrowernumber %]" />
159     <input type="hidden" name="selected_accts" id="selected_accts" value="[% selected_accts %]" />
160     <input type="hidden" name="total" id="total" value="[% total %]" />
161     <input type="hidden" name="type" value="[% type %]" />
162
163     <fieldset class="rows">
164     [% IF ( selected_accts ) %]
165         [% IF type == 'writeoff' %]
166             <legend>Write off an amount toward selected fines</legend>
167         [% ELSE %]
168             <legend>Pay an amount toward selected fines</legend>
169         [% END %]
170     [% ELSE %]
171         <legend>Pay an amount toward all fines</legend>
172     [% END %]
173
174     <ol>
175         <li>
176             <span class="label">Total amount outstanding: </span>
177             <span class="debit">[% total | format('%.2f') %]</span>
178         </li>
179     <li>
180         [% IF type == 'writeoff' %]
181             <label for="paid">Writeoff amount: </label>
182         [% ELSE %]
183             <label for="paid">Collect from patron: </label>
184         [% END %]
185         <!-- default to paying all -->
186         <input name="paid" id="paid" value="[% total | format('%.2f') %]" />
187     </li>
188     [% SET payment_types = AuthorisedValues.GetAuthValueDropbox('PAYMENT_TYPE') %]
189     [% IF payment_types %]
190         <li>
191             <label for="payment_type">Payment type: </label>
192             <select name="payment_type" id="payment_type">
193                 <option value=""></option>
194                 [% FOREACH pt IN payment_types %]
195                     <option value="[% pt.authorised_value %]">[% pt.lib %]</option>
196                 [% END %]
197             </select>
198         </li>
199     [% END %]
200     <li>
201         <label for="selected_accts_notes">Note: </label>
202         <textarea name="selected_accts_notes" id="selected_accts_notes">[% selected_accts_notes %]</textarea>
203     </li>
204     </ol>
205     </fieldset>
206     <div class="action">
207         <input type="submit" name="submitbutton" value="Confirm" />
208         <a class="cancel" href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=[% patron.borrowernumber %]">Cancel</a>
209     </div>
210     </form>
211 [% END %]
212 </div></div>
213 </div>
214 </div>
215
216 <div class="yui-b">
217 [% INCLUDE 'circ-menu.inc' %]
218 </div>
219 </div>
220
221 [% MACRO jsinclude BLOCK %]
222     [% Asset.js("js/members-menu.js") %]
223     <script type= "text/javascript">
224         $(document).ready(function() {
225             $('#payindivfine, #payfine').preventDoubleFormSubmit();
226             $("#paid").on("change",function(){
227                 moneyFormat( this );
228             });
229         });
230
231         prevent_default = 1;
232         $('#woindivfine').on('submit', function(e){
233             if ( prevent_default ) {
234                 e.preventDefault();
235
236                 let amount_outstanding = parseFloat( $('#amountoutstanding').attr('value') );
237                 let amount_writeoff = parseFloat( $('#amountwrittenoff').attr('value') );
238                 if ( amount_writeoff > amount_outstanding ) {
239                     alert(_("You are attemping to writeoff more than the value of the fee."));
240                     $('#woindivfine').beenSubmitted = false;
241                 } else {
242                     prevent_default = 0;
243                     $('#woindivfine').preventDoubleFormSubmit();
244                     $('#woindivfine').submit();
245                 }
246             }
247         });
248
249         function moneyFormat(textObj) {
250             var newValue = textObj.value;
251             var decAmount = "";
252             var dolAmount = "";
253             var decFlag   = false;
254             var aChar     = "";
255
256             for(i=0; i < newValue.length; i++) {
257                 aChar = newValue.substring(i, i+1);
258                 if (aChar >= "0" && aChar <= "9") {
259                     if(decFlag) {
260                         decAmount = "" + decAmount + aChar;
261                     }
262                     else {
263                         dolAmount = "" + dolAmount + aChar;
264                     }
265                 }
266                 if (aChar == ".") {
267                     if (decFlag) {
268                         dolAmount = "";
269                         break;
270                     }
271                     decFlag = true;
272                 }
273             }
274
275             if (dolAmount == "") {
276                 dolAmount = "0";
277             }
278         // Strip leading 0s
279             if (dolAmount.length > 1) {
280                 while(dolAmount.length > 1 && dolAmount.substring(0,1) == "0") {
281                     dolAmount = dolAmount.substring(1,dolAmount.length);
282                 }
283             }
284             if (decAmount.length > 2) {
285                 decAmount = decAmount.substring(0,2);
286             }
287         // Pad right side
288             if (decAmount.length == 1) {
289                decAmount = decAmount + "0";
290             }
291             if (decAmount.length == 0) {
292                decAmount = decAmount + "00";
293             }
294
295             textObj.value = dolAmount + "." + decAmount;
296         }
297     </script>
298 [% END %]
299
300 [% INCLUDE 'intranet-bottom.inc' %]