View | Details | Raw Unified | Return to bug 3498
Collapse All | Expand All

(-)a/C4/Accounts.pm (-1 / +100 lines)
Lines 35-42 BEGIN { Link Here
35
	@EXPORT = qw(
35
	@EXPORT = qw(
36
		&recordpayment &makepayment &manualinvoice
36
		&recordpayment &makepayment &manualinvoice
37
		&getnextacctno &reconcileaccount &getcharges &getcredits
37
		&getnextacctno &reconcileaccount &getcharges &getcredits
38
		&getrefunds &chargelostitem
38
		&getrefunds &chargelostitem makepartialpayment
39
		&ReversePayment
39
		&ReversePayment
40
        recordpayment_selectaccts
40
	); # removed &fixaccounts
41
	); # removed &fixaccounts
41
}
42
}
42
43
Lines 132-137 sub recordpayment { Link Here
132
    $sth->finish;
133
    $sth->finish;
133
}
134
}
134
135
136
=head2 recordpayment_selectaccts
137
138
  recordpayment_selectaccts($borrowernumber, $payment,$accts);
139
140
Record payment by a patron. C<$borrowernumber> is the patron's
141
borrower number. C<$payment> is a floating-point number, giving the
142
amount that was paid. C<$accts> is an array ref to a list of
143
accountnos which the payment can be recorded against
144
145
Amounts owed are paid off oldest first. That is, if the patron has a
146
$1 fine from Feb. 1, another $1 fine from Mar. 1, and makes a payment
147
of $1.50, then the oldest fine will be paid off in full, and $0.50
148
will be credited to the next one.
149
150
=cut
151
152
sub recordpayment_selectaccts {
153
    my ( $borrowernumber, $amount, $accts ) = @_;
154
155
    my $dbh        = C4::Context->dbh;
156
    my $newamtos   = 0;
157
    my $accdata    = q{};
158
    my $branch     = C4::Context->userenv->{branch};
159
    my $amountleft = $amount;
160
    my $sql = 'SELECT * FROM accountlines WHERE (borrowernumber = ?) ' .
161
    'AND (amountoutstanding<>0) ';
162
    if (@{$accts} ) {
163
        $sql .= ' AND accountno IN ( ' .  join ',', @{$accts};
164
        $sql .= ' ) ';
165
    }
166
    $sql .= ' ORDER BY date';
167
    # begin transaction
168
    my $nextaccntno = getnextacctno($borrowernumber);
169
170
    # get lines with outstanding amounts to offset
171
    my $rows = $dbh->selectall_arrayref($sql, { Slice => {} }, $borrowernumber);
172
173
    # offset transactions
174
    my $sth     = $dbh->prepare('UPDATE accountlines SET amountoutstanding= ? ' .
175
        'WHERE (borrowernumber = ?) AND (accountno=?)');
176
    for my $accdata ( @{$rows} ) {
177
        if ($amountleft == 0) {
178
            last;
179
        }
180
        if ( $accdata->{amountoutstanding} < $amountleft ) {
181
            $newamtos = 0;
182
            $amountleft -= $accdata->{amountoutstanding};
183
        }
184
        else {
185
            $newamtos   = $accdata->{amountoutstanding} - $amountleft;
186
            $amountleft = 0;
187
        }
188
        my $thisacct = $accdata->{accountno};
189
        $sth->execute( $newamtos, $borrowernumber, $thisacct );
190
    }
191
192
    # create new line
193
    $sql = 'INSERT INTO accountlines ' .
194
    '(borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding) ' .
195
    q|VALUES (?,?,now(),?,'Payment,thanks','Pay',?)|;
196
    $dbh->do($sql,{},$borrowernumber, $nextaccntno, 0 - $amount, 0 - $amountleft );
197
    UpdateStats( $branch, 'payment', $amount, '', '', '', $borrowernumber, $nextaccntno );
198
    return;
199
}
135
=head2 makepayment
200
=head2 makepayment
136
201
137
  &makepayment($borrowernumber, $acctnumber, $amount, $branchcode);
202
  &makepayment($borrowernumber, $acctnumber, $amount, $branchcode);
Lines 207-212 sub makepayment { Link Here
207
    }
272
    }
208
}
273
}
209
274
275
# makepayment needs to be fixed to handle partials till then this separate subroutine
276
# fills in
277
sub makepartialpayment {
278
    my ( $borrowernumber, $accountno, $amount, $user, $branch ) = @_;
279
    if (!$amount || $amount < 0) {
280
        return;
281
    }
282
    my $dbh = C4::Context->dbh;
283
284
    my $nextaccntno = getnextacctno($borrowernumber);
285
    my $newamtos    = 0;
286
287
    my $data = $dbh->selectrow_hashref(
288
        'SELECT * FROM accountlines WHERE  borrowernumber=? AND accountno=?',undef,$borrowernumber,$accountno);
289
    my $new_outstanding = $data->{amountoutstanding} - $amount;
290
291
    my $update = 'UPDATE  accountlines SET amountoutstanding = ?  WHERE   borrowernumber = ? '
292
    . ' AND   accountno = ?';
293
    $dbh->do( $update, undef, $new_outstanding, $borrowernumber, $accountno);
294
295
    # create new line
296
    my $insert = 'INSERT INTO accountlines (borrowernumber, accountno, date, amount, '
297
    .  'description, accounttype, amountoutstanding) '
298
    . ' VALUES (?, ?, now(), ?, ?, ?, 0)';
299
300
    $dbh->do(  $insert, undef, $borrowernumber, $nextaccntno, $amount,
301
        "Payment, thanks - $user", 'Pay');
302
303
    UpdateStats( $user, 'payment', $amount, '', '', '', $borrowernumber, $accountno );
304
305
    return;
306
}
307
210
=head2 getnextacctno
308
=head2 getnextacctno
211
309
212
  $nextacct = &getnextacctno($borrowernumber);
310
  $nextacct = &getnextacctno($borrowernumber);
Lines 227-232 sub getnextacctno ($) { Link Here
227
		 LIMIT 1"
325
		 LIMIT 1"
228
    );
326
    );
229
    $sth->execute($borrowernumber);
327
    $sth->execute($borrowernumber);
328
230
    return ($sth->fetchrow || 1);
329
    return ($sth->fetchrow || 1);
231
}
330
}
232
331
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/pay.tmpl (-8 / +31 lines)
Lines 9-15 Link Here
9
<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; Pay Fines for <!-- TMPL_VAR name="firstname" --> <!-- TMPL_VAR name="surname" --></div>
9
<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; Pay Fines for <!-- TMPL_VAR name="firstname" --> <!-- TMPL_VAR name="surname" --></div>
10
10
11
<div id="doc3" class="yui-t2">
11
<div id="doc3" class="yui-t2">
12
   
12
13
   <div id="bd">
13
   <div id="bd">
14
	<div id="yui-main">
14
	<div id="yui-main">
15
	<div class="yui-b">
15
	<div class="yui-b">
Lines 31-36 Link Here
31
<table>
31
<table>
32
<tr>
32
<tr>
33
	<th>Fines &amp; Charges</th>
33
	<th>Fines &amp; Charges</th>
34
    <th>Sel</th>
34
	<th>Description</th>
35
	<th>Description</th>
35
	<th>Account Type</th>
36
	<th>Account Type</th>
36
	<th>Notify id</th>
37
	<th>Notify id</th>
Lines 44-56 Link Here
44
<tr>
45
<tr>
45
	<td>
46
	<td>
46
	<!-- TMPL_IF NAME="net_balance" -->
47
	<!-- TMPL_IF NAME="net_balance" -->
47
	<select name="payfine<!-- TMPL_VAR name="i" -->">
48
	<!--<select name="payfine<!-- TMPL_VAR name="i" -->">
48
	<option value="no">Unpaid</option>
49
	<option value="no">Unpaid</option>
49
	<option value="yes">Paid</option>
50
	<option value="yes">Paid</option> -->
50
	<option value="wo">Writeoff</option>
51
    <input type="submit" name="pay_indiv<!-- TMPL_VAR name="i" -->"i value="Pay" />
51
	</select>
52
    <!-- TMPL_IF NAME="CAN_user_updatecharges_writeoff_charges" -->
53
    <input type="submit" name="wo_indiv<!-- TMPL_VAR name="i" -->"i value="Writeoff" />
54
	<!--<option value="wo">Writeoff</option> -->
55
    <!--  /TMPL_IF -->
56
	<!--</select> -->
52
	<!-- /TMPL_IF -->
57
	<!-- /TMPL_IF -->
58
	<input type="hidden" name="line_id<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="i" -->" />
53
	<input type="hidden" name="itemnumber<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="itemnumber" -->" />
59
	<input type="hidden" name="itemnumber<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="itemnumber" -->" />
60
	<input type="hidden" name="description<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="description" -->" />
61
	<input type="hidden" name="title<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="title" -->" />
54
	<input type="hidden" name="accounttype<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="accounttype" -->" />
62
	<input type="hidden" name="accounttype<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="accounttype" -->" />
55
	<input type="hidden" name="amount<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="amount" -->" />
63
	<input type="hidden" name="amount<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="amount" -->" />
56
	<input type="hidden" name="out<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="amountoutstanding" -->" />
64
	<input type="hidden" name="out<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="amountoutstanding" -->" />
Lines 60-65 Link Here
60
	<input type="hidden" name="notify_level<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="notify_level" -->" />
68
	<input type="hidden" name="notify_level<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="notify_level" -->" />
61
	<input type="hidden" name="totals<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="totals" -->" />
69
	<input type="hidden" name="totals<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="totals" -->" />
62
	</td>
70
	</td>
71
    <td>
72
	<!-- TMPL_IF NAME="net_balance" -->
73
    <input type="checkbox" checked="checked" name="incl_par<!-- TMPL_VAR name="i" -->" />
74
    <!--  /TMPL_IF -->
75
    </td>
63
	<td><!-- TMPL_VAR name="description" --> <!-- TMPL_VAR name="title" escape="html" --></td>
76
	<td><!-- TMPL_VAR name="description" --> <!-- TMPL_VAR name="title" escape="html" --></td>
64
	<td><!-- TMPL_VAR name="accounttype" --></td>
77
	<td><!-- TMPL_VAR name="accounttype" --></td>
65
	<td><!-- TMPL_VAR name="notify_id" --></td>
78
	<td><!-- TMPL_VAR name="notify_id" --></td>
Lines 71-87 Link Here
71
<!-- TMPL_IF  NAME="total"-->
84
<!-- TMPL_IF  NAME="total"-->
72
<tr>
85
<tr>
73
86
74
	<td colspan="6">Sub Total</td>
87
	<td colspan="7">Sub Total</td>
75
	<td><!-- TMPL_VAR name="total" --></td>
88
	<td><!-- TMPL_VAR name="total" --></td>
76
</tr>
89
</tr>
77
<!--/TMPL_IF-->
90
<!--/TMPL_IF-->
78
<!-- /TMPL_LOOP  -->
91
<!-- /TMPL_LOOP  -->
79
<tr>
92
<tr>
80
	<td colspan="6">Total Due</td>
93
	<td colspan="7">Total Due</td>
81
	<td><!-- TMPL_VAR name="total" --></td>
94
	<td><!-- TMPL_VAR name="total" --></td>
82
</tr>
95
</tr>
83
</table>
96
</table>
84
<fieldset class="action"><input type="submit" name="submit"  value="Make Payment" class="submit" /> <a class="cancel" href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=<!-- TMPL_VAR NAME="borrowernumber" -->">Cancel</a></fieldset></form><!-- TMPL_ELSE --><p><!-- TMPL_VAR NAME="firstname" --> <!-- TMPL_VAR NAME="surname" --> has no outstanding fines.</p><!-- /TMPL_IF -->
97
<!-- <p>On All Or Part Of The Total Sum Due:</p> -->
98
<fieldset class="action">
99
 <input type="submit" name="paycollect"  value="Pay Amount" class="submit" />
100
<!-- TMPL_IF NAME="CAN_user_updatecharges_writeoff_charges" -->
101
 <input type="submit" name="woall"  value="Writeoff All" class="submit" />
102
<!-- /TMPL_IF -->
103
 <input type="submit" name="payselected"  value="Pay Selected" class="submit" />
104
 <a class="cancel" href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=<!-- TMPL_VAR NAME="borrowernumber" -->">
105
  Cancel</a>
106
</fieldset>
107
</form><!-- TMPL_ELSE --><p><!-- TMPL_VAR NAME="firstname" --> <!-- TMPL_VAR NAME="surname" --> has no outstanding fines.</p><!-- /TMPL_IF -->
85
</div></div>
108
</div></div>
86
109
87
</div>
110
</div>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/paycollect.tmpl (+221 lines)
Line 0 Link Here
1
<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
2
<title>Koha &rsaquo; Patrons &rsaquo; Collect Fine Payment for  <!-- TMPL_VAR NAME="firstname" --> <!-- TMPL_VAR NAME="surname" --></title>
3
<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
4
<script type= "text/javascript">
5
//<![CDATA[
6
function moneyFormat(textObj) {
7
    var newValue = textObj.value;
8
    var decAmount = "";
9
    var dolAmount = "";
10
    var decFlag   = false;
11
    var aChar     = "";
12
13
    for(i=0; i < newValue.length; i++) {
14
        aChar = newValue.substring(i, i+1);
15
        if (aChar >= "0" && aChar <= "9") {
16
            if(decFlag) {
17
                decAmount = "" + decAmount + aChar;
18
            }
19
            else {
20
                dolAmount = "" + dolAmount + aChar;
21
            }
22
        }
23
        if (aChar == ".") {
24
            if (decFlag) {
25
                dolAmount = "";
26
                break;
27
            }
28
            decFlag = true;
29
        }
30
    }
31
32
    if (dolAmount == "") {
33
        dolAmount = "0";
34
    }
35
// Strip leading 0s
36
    if (dolAmount.length > 1) {
37
        while(dolAmount.length > 1 && dolAmount.substring(0,1) == "0") {
38
            dolAmount = dolAmount.substring(1,dolAmount.length);
39
        }
40
    }
41
    if (decAmount.length > 2) {
42
        decAmount = decAmount.substring(0,2);
43
    }
44
// Pad right side
45
    if (decAmount.length == 1) {
46
       decAmount = decAmount + "0";
47
    }
48
    if (decAmount.length == 0) {
49
       decAmount = decAmount + "00";
50
    }
51
52
    textObj.value = dolAmount + "." + decAmount;
53
}
54
//]]>
55
</script>
56
</head>
57
<body>
58
<!-- TMPL_INCLUDE NAME="header.inc" -->
59
<!-- TMPL_INCLUDE NAME="patron-search.inc" -->
60
<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; Pay Fines for <!-- TMPL_VAR name="firstname" --> <!-- TMPL_VAR name="surname" --></div>
61
62
<div id="doc3" class="yui-t2">
63
64
<div id="bd">
65
<div id="yui-main">
66
<div class="yui-b">
67
<!-- TMPL_INCLUDE NAME="members-toolbar.inc" -->
68
69
70
<!-- The manual invoice and credit buttons -->
71
<div class="toptabs">
72
<ul class="ui-tabs-nav">
73
<li><a href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=<!-- TMPL_VAR NAME="borrowernumber" -->">Account</a></li>
74
<li class="ui-tabs-selected"><a href="/cgi-bin/koha/members/pay.pl?borrowernumber=<!-- TMPL_VAR NAME="borrowernumber" -->" >Pay fines</a></li>
75
<li><a href="/cgi-bin/koha/members/maninvoice.pl?borrowernumber=<!-- TMPL_VAR NAME="borrowernumber" -->" >Create Manual Invoice</a></li>
76
<li><a href="/cgi-bin/koha/members/mancredit.pl?borrowernumber=<!-- TMPL_VAR NAME="borrowernumber" -->" >Create Manual Credit</a></li>
77
</ul>
78
<div class="tabs-container">
79
80
<!--<form action="/cgi-bin/koha/members/paycollect.pl" method="post"> -->
81
<!-- TMPL_IF NAME="pay_individual" -->
82
<form name="payindivfine" onsubmit="return validatePayment(this);" method="post" action="/cgi-bin/koha/members/paycollect.pl">
83
<input type="hidden" name="borrowernumber" id="borrowernumber" value="<!-- TMPL_VAR name="borrowernumber" -->" />
84
<input type="hidden" name="pay_individual" id="pay_individual" value="<!-- TMPL_VAR name="pay_individual" -->" />
85
<input type="hidden" name="description" id="description" value="<!-- TMPL_VAR name="description" -->" />
86
<input type="hidden" name="accounttype" id="accounttype" value="<!-- TMPL_VAR name="accounttype" -->" />
87
<input type="hidden" name="notify_id" id="notify_id" value="<!-- TMPL_VAR name="notify_id" -->" />
88
<input type="hidden" name="notify_level" id="notify_level" value="<!-- TMPL_VAR name="notify_level" -->" />
89
<input type="hidden" name="amount" id="amount" value="<!-- TMPL_VAR name="amount" -->" />
90
<input type="hidden" name="amountoutstanding" id="amountoutstanding" value="<!-- TMPL_VAR name="amountoutstanding" -->" />
91
<input type="hidden" name="accountno" id="accountno" value="<!-- TMPL_VAR name="accountno" -->" />
92
<input type="hidden" name="title" id="title" value="<!-- TMPL_VAR name="title" -->" />
93
<table>
94
<tr>
95
<th>Description</th>
96
<th>Account Type</th>
97
<th>Notify id</th>
98
<th>Level</th>
99
<th>Amount</th>
100
<th>Amount Outstanding</th>
101
</tr>
102
<tr>
103
<td>
104
<!-- TMPL_VAR NAME="description" --> <!-- TMPL_VAR="title" escape="html" -->
105
</td>
106
<td><!-- TMPL_VAR name="accounttype" --></td>
107
<td><!-- TMPL_VAR name="notify_id" --></td>
108
<td><!-- TMPL_VAR name="notify_level" --></td>
109
<td class="debit"><!-- TMPL_VAR name="amount" --></td>
110
<td class="debit"><!-- TMPL_VAR name="amountoutstanding" --></td>
111
</tr>
112
<tr>
113
<td>Total Amount Payable : </td>
114
<td>
115
<!-- TMPL_VAR NAME="amountoutstanding" -->
116
</td>
117
</tr>
118
<tr><td> </td></tr>
119
<tr>
120
<td>Collect From Patron: </td>
121
<td>
122
<!-- default to paying all -->
123
<input name="paid" id="paid" value="<!-- TMPL_VAR NAME="amountoutstanding" -->" onchange="moneyFormat(document.payindivfine.paid)"/>
124
</td>
125
</tr>
126
<tr><td>  </td></tr>
127
<tr>
128
<td rowspan="2">
129
<input type="submit" name="submitbutton" value="Confirm" />
130
<a class="cancel" href="/cgi-bin/koha/members/pay.pl?borrowernumber=<!-- TMPL_VAR NAME="borrowernumber" -->">Cancel</a>
131
</td>
132
</tr>
133
134
</table>
135
<!-- TMPL_ELSIF NAME="writeoff_individual"-->
136
<form name="woindivfine" action="/cgi-bin/koha/members/pay.pl" method="post" >
137
<input type="hidden" name="borrowernumber" id="borrowernumber" value="<!-- TMPL_VAR name="borrowernumber" -->" />
138
<input type="hidden" name="pay_individual" id="pay_individual" value="<!-- TMPL_VAR name="pay_individual" -->" />
139
<input type="hidden" name="description" id="description" value="<!-- TMPL_VAR name="description" -->" />
140
<input type="hidden" name="accounttype" id="accounttype" value="<!-- TMPL_VAR name="accounttype" -->" />
141
<input type="hidden" name="notify_id" id="notify_id" value="<!-- TMPL_VAR name="notify_id" -->" />
142
<input type="hidden" name="notify_level" id="notify_level" value="<!-- TMPL_VAR name="notify_level" -->" />
143
<input type="hidden" name="amount" id="amount" value="<!-- TMPL_VAR name="amount" -->" />
144
<input type="hidden" name="amountoutstanding" id="amountoutstanding" value="<!-- TMPL_VAR name="amountoutstanding" -->" />
145
<input type="hidden" name="accountno" id="accountno" value="<!-- TMPL_VAR name="accountno" -->" />
146
<input type="hidden" name="title" id="title" value="<!-- TMPL_VAR name="title" -->" />
147
<table>
148
<tr>
149
<th>Description</th>
150
<th>Account Type</th>
151
<th>Notify id</th>
152
<th>Level</th>
153
<th>Amount</th>
154
<th>Amount Outstanding</th>
155
</tr>
156
<tr>
157
<td>
158
<!-- TMPL_VAR NAME="description" --> <!-- TMPL_VAR="title" escape="html" -->
159
</td>
160
<td><!-- TMPL_VAR name="accounttype" --></td>
161
<td><!-- TMPL_VAR name="notify_id" --></td>
162
<td><!-- TMPL_VAR name="notify_level" --></td>
163
<td class="debit"><!-- TMPL_VAR name="amount" --></td>
164
<td class="debit"><!-- TMPL_VAR name="amountoutstanding" --></td>
165
</tr>
166
<tr><td> </td></tr>
167
<tr><td rowspan="2"><strong>Writeoff This Charge?</strong></td></tr>
168
<tr><td> </td></tr>
169
<tr>
170
<td rowspan="2">
171
<input type="submit" name="confirm_writeoff" id="confirm_writeoff" value="Confirm" />
172
<a class="cancel" href="/cgi-bin/koha/members/pay.pl?borrowernumber=<!-- TMPL_VAR NAME="borrowernumber" -->">Cancel</a>
173
</td>
174
</tr>
175
176
</table>
177
<!-- TMPL_ELSE -->
178
179
<form name="payfine" onsubmit="return validatePayment(this);" method="post" action="/cgi-bin/koha/members/paycollect.pl">
180
<input type="hidden" name="borrowernumber" id="borrowernumber" value="<!-- TMPL_VAR name="borrowernumber" -->" />
181
<input type="hidden" name="selected_accts" id="selected_accts" value="<!-- TMPL_VAR name="selected_accts" --> />
182
<input type="hidden" name="total" id="total" value="<!-- TMPL_VAR name="total" -->" />
183
184
<table>
185
<!-- TMPL_IF NAME="error" -->
186
<tr><td><!-- TMPL_VAR NAME="error" --></td></tr>
187
<!-- /TMPL_IF -->
188
<tr>
189
<td>Total Amount Outstanding : </td>
190
<td>
191
<!-- TMPL_VAR NAME="total" -->
192
</td>
193
</tr>
194
<tr><td> </td></tr>
195
<tr>
196
<td>Collect From Patron: </td>
197
<td>
198
<!-- default to paying all -->
199
<input name="paid" id="paid" value="<!-- TMPL_VAR NAME="total" -->" onchange="moneyFormat(document.payfine.paid)"/>
200
</td>
201
</tr>
202
<tr><td>  </td></tr>
203
<tr>
204
<td rowspan="2">
205
<input type="submit" name="submitbutton" value="Confirm" />
206
<a class="cancel" href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=<!-- TMPL_VAR NAME="borrowernumber" -->">Cancel</a>
207
</td>
208
</tr>
209
</table>
210
</form>
211
<!-- /TMPL_IF -->
212
</div></div>
213
214
</div>
215
</div>
216
217
<div class="yui-b">
218
<!-- TMPL_INCLUDE NAME="circ-menu.inc" -->
219
</div>
220
</div>
221
<!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->
(-)a/members/pay.pl (-128 / +243 lines)
Lines 39-223 use C4::Koha; Link Here
39
use C4::Overdues;
39
use C4::Overdues;
40
use C4::Branch; # GetBranches
40
use C4::Branch; # GetBranches
41
41
42
my $input = new CGI;
42
my $input = CGI->new();
43
43
44
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
44
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
45
    {
45
    {
46
        template_name   => "members/pay.tmpl",
46
        template_name   => 'members/pay.tmpl',
47
        query           => $input,
47
        query           => $input,
48
        type            => "intranet",
48
        type            => 'intranet',
49
        authnotrequired => 0,
49
        authnotrequired => 0,
50
        flagsrequired   => { borrowers => 1, updatecharges => 1 },
50
        flagsrequired   => { borrowers => 1, updatecharges => 1 },
51
        debug           => 1,
51
        debug           => 1,
52
    }
52
    }
53
);
53
);
54
54
55
my @nam = $input->param;
55
my $borrowernumber = $input->param('borrowernumber');
56
my $borrowernumber = $input->param('borrowernumber');
56
if ( $borrowernumber eq '' ) {
57
if ( !$borrowernumber  ) {
57
    $borrowernumber = $input->param('borrowernumber0');
58
    $borrowernumber = $input->param('borrowernumber0');
58
}
59
}
59
60
60
# get borrower details
61
# get borrower details
61
my $data = GetMember( borrowernumber => $borrowernumber );
62
my $data = GetMember( borrowernumber => $borrowernumber );
62
my $user = $input->remote_user;
63
my $user = $input->remote_user;
64
$user ||= q{};
63
65
64
# get account details
66
# get account details
65
my $branches = GetBranches();
67
my $branches = GetBranches();
66
my $branch   = GetBranch( $input, $branches );
68
my $branch   = GetBranch( $input, $branches );
67
69
70
my $co_wr = $input->param('confirm_writeoff');
71
my $paycollect = $input->param('paycollect');
72
if ($paycollect) {
73
    print $input->redirect("/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber" );
74
}
75
my $payselected = $input->param('payselected');
76
if ($payselected) {
77
    my @lines;
78
    foreach (@nam) {
79
        if ( /^incl_par_(\d+)$/) {
80
            push @lines, $1;
81
        }
82
    }
83
    my @lines_to_pay;
84
    my $amt = 0;
85
    for (@lines) {
86
        push @lines_to_pay, $input->param("accountno_$_");
87
        $amt += $input->param("out_$_");
88
    }
89
    $amt = '&amt=' . $amt;
90
    my $sel = '&selected=' . join ',', @lines_to_pay;
91
    my $redirect = "/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber" . $amt . $sel;
92
93
    print $input->redirect($redirect);
94
95
}
96
97
my $wo_all = $input->param('woall'); # writeoff all fines
98
if ($wo_all) {
99
    writeoff_all();
100
} elsif ($co_wr) {
101
    my $accountno = $input->param('accountno');
102
    my $itemno = $input->param('itemnumber');
103
    my $account_type =  $input->param('accounttype');
104
    my $amount = $input->param('amount');
105
    writeoff($borrowernumber, $accountno, $itemno, $account_type, $amount);
106
}
107
68
my @names = $input->param;
108
my @names = $input->param;
69
my %inp;
70
my $check = 0;
109
my $check = 0;
110
111
## Create a structure
71
for ( my $i = 0 ; $i < @names ; $i++ ) {
112
for ( my $i = 0 ; $i < @names ; $i++ ) {
72
    my $temp = $input->param( $names[$i] );
113
    my $temp = $input->param( $names[$i] );
73
    if ( $temp eq 'wo' ) {
74
        $inp{ $names[$i] } = $temp;
75
        $check = 1;
76
    }
77
    if ( $temp eq 'yes' ) {
114
    if ( $temp eq 'yes' ) {
78
115
79
# FIXME : using array +4, +5, +6 is dirty. Should use arrays for each accountline
116
# FIXME : using array +4, +5, +6 is dirty. Should use arrays for each accountline
80
        my $amount         = $input->param( $names[ $i + 4 ] );
117
        my $amount         = $input->param( $names[ $i + 4 ] ); # out
81
        my $borrowernumber = $input->param( $names[ $i + 5 ] );
118
        my $borrowerno     = $input->param( $names[ $i + 5 ] );
82
        my $accountno      = $input->param( $names[ $i + 6 ] );
119
        my $accountno      = $input->param( $names[ $i + 6 ] );
83
        makepayment( $borrowernumber, $accountno, $amount, $user, $branch );
120
        makepayment( $borrowerno, $accountno, $amount, $user, $branch );
84
        $check = 2;
121
        $check = 2;
85
    }
122
    }
86
}
123
}
87
my $total = $input->param('total') || '';
124
88
if ( $check == 0 ) {
125
for ( @names ) {
89
    if ( $total ne '' ) {
126
    if (/^pay_indiv_(\d+)$/) {
90
        recordpayment( $borrowernumber, $total );
127
        my $line_no = $1;
128
        redirect_to_paycollect('pay_individual', $line_no);
129
    }
130
    if (/^wo_indiv_(\d+)$/) {
131
        my $line_no = $1;
132
        redirect_to_paycollect('writeoff_individual', $line_no);
91
    }
133
    }
134
}
92
135
93
    my ( $total, $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
136
if ( $check == 0 ) {  # fetch and display accounts
94
137
    add_accounts_to_template($borrowernumber);
95
    my @allfile;
138
96
    my @notify = NumberNotifyId($borrowernumber);
139
    output_html_with_http_headers $input, $cookie, $template->output;
97
140
98
    my $numberofnotify = scalar(@notify);
141
}else {
99
    for ( my $j = 0 ; $j < scalar(@notify) ; $j++ ) {
142
100
        my @loop_pay;
143
    my %inputs;
101
        my ( $total , $accts, $numaccts) =
144
    my @name = $input->param;
102
          GetBorNotifyAcctRecord( $borrowernumber, $notify[$j] );
145
    for my $name (@name) {
103
        for ( my $i = 0 ; $i < $numaccts ; $i++ ) {
146
        my $test = $input->param( $name );
104
            my %line;
147
        if ($test eq 'wo' ) {
105
            if ( $accts->[$i]{'amountoutstanding'} != 0 ) {
148
            my $temp = $name;
106
                $accts->[$i]{'amount'}            += 0.00;
149
            $temp=~s/payfine//;
107
                $accts->[$i]{'amountoutstanding'} += 0.00;
150
            $inputs{ $name } = $temp;
108
                $line{i}           = $j . "" . $i;
109
                $line{itemnumber}  = $accts->[$i]{'itemnumber'};
110
                $line{accounttype} = $accts->[$i]{'accounttype'};
111
                $line{amount}      = sprintf( "%.2f", $accts->[$i]{'amount'} );
112
                $line{amountoutstanding} =
113
                  sprintf( "%.2f", $accts->[$i]{'amountoutstanding'} );
114
                $line{borrowernumber} = $borrowernumber;
115
                $line{accountno}      = $accts->[$i]{'accountno'};
116
                $line{description}    = $accts->[$i]{'description'};
117
                $line{title}          = $accts->[$i]{'title'};
118
                $line{notify_id}      = $accts->[$i]{'notify_id'};
119
                $line{notify_level}   = $accts->[$i]{'notify_level'};
120
                $line{net_balance} = 1 if($accts->[$i]{'amountoutstanding'} > 0); # you can't pay a credit.
121
                push( @loop_pay, \%line );
122
            }
123
        }
151
        }
152
    }
153
154
    while ( my ( $key, $value ) = each %inputs ) {
124
155
125
        my $totalnotify = AmountNotify( $notify[$j], $borrowernumber );
156
        my $accounttype    = $input->param("accounttype$value");
126
        ( $totalnotify = '0' ) if ( $totalnotify =~ /^0.00/ );
157
        my $borrower_number = $input->param("borrowernumber$value");
127
        push @allfile,
158
        my $itemno         = $input->param("itemnumber$value");
128
          {
159
        my $amount         = $input->param("amount$value");
129
            'loop_pay' => \@loop_pay,
160
        my $accountno      = $input->param("accountno$value");
130
            'notify'   => $notify[$j],
161
        writeoff( $borrower_number, $accountno, $itemno, $accounttype, $amount );
131
            'total'    =>  sprintf( "%.2f",$totalnotify),
132
			
133
          };
134
    }
162
    }
135
	
163
    $borrowernumber = $input->param('borrowernumber');
136
if ( $data->{'category_type'} eq 'C') {
164
    print $input->redirect(
137
   my  ( $catcodes, $labels ) =  GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
165
        "/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber");
138
   my $cnt = scalar(@$catcodes);
166
}
139
   $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
167
140
   $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
168
sub writeoff {
169
    my ( $b_number, $accountnum, $itemnum, $accounttype, $amount ) = @_;
170
    my $usr = $input->remote_user;
171
    my $dbh  = C4::Context->dbh;
172
    $itemnum ||= undef; # if no item is attached to fine, make sure to store it as a NULL
173
174
    my $update =
175
    'Update accountlines set amountoutstanding=0 ' .
176
    q|where (accounttype='Res' OR accounttype='FU' OR accounttype ='IP' OR accounttype='CH' OR accounttype='N' | .
177
    q|OR accounttype='F' OR accounttype='A' OR accounttype='M' OR accounttype='L' OR accounttype='RE' | .
178
    q|OR accounttype='RL') and accountno=? and borrowernumber=?|;
179
    $dbh->do($update, undef, $accountnum, $b_number );
180
181
    my $account =
182
    $dbh->selectall_arrayref('select max(accountno) as max_accountno from accountlines');
183
    my $max = 1 + $account->[0]->[0];
184
    my $insert = q{insert into accountlines (borrowernumber,accountno,itemnumber,date,amount,description,accounttype)}
185
    .  q{values (?,?,?,now(),?,'Writeoff','W')};
186
    $dbh->do($insert, undef, $b_number, $max, $itemnum, $amount );
187
188
    UpdateStats( $branch, 'writeoff', $amount, q{}, q{}, q{}, $b_number );
189
190
    return;
141
}
191
}
142
	
192
143
$template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' );
193
sub add_accounts_to_template {
144
my ($picture, $dberror) = GetPatronImage($data->{'cardnumber'});
194
    my $b_number = shift;
145
$template->param( picture => 1 ) if $picture;
195
146
	
196
    my ( $total, $accts, $numaccts);
197
    ( $total, $accts, $numaccts) = GetMemberAccountRecords( $b_number );
198
199
200
    my $allfile = [];
201
    my @notify = NumberNotifyId($b_number);
202
203
    my $line_id = 0;
204
    for my $n (@notify) {
205
        my $pay_loop = [];
206
        my ($acct_total, $acct_accts, $acct_numaccts) =
207
        GetBorNotifyAcctRecord( $b_number, $n );
208
        if (!$acct_numaccts) {
209
            next;
210
        }
211
        for my $acct ( @{$acct_accts} ) {
212
            if ( $acct->{amountoutstanding} != 0 ) {
213
                $acct->{amount}            += 0.00;
214
                $acct->{amountoutstanding} += 0.00;
215
                my $line = {
216
                    i                 => "_$line_id",
217
                    itemnumber        => $acct->{itemnumber},
218
                    accounttype       => $acct->{accounttype},
219
                    amount            => sprintf('%.2f', $acct->{amount}),
220
                    amountoutstanding => sprintf('%.2f', $acct->{amountoutstanding}),
221
                    borrowernumber    => $b_number,
222
                    accountno         => $acct->{accountno},
223
                    description       => $acct->{description},
224
                    title             => $acct->{title},
225
                    notify_id         => $acct->{notify_id},
226
                    notify_level      => $acct->{notify_level},
227
                };
228
                if ($acct->{amountoutstanding} > 0 ) {
229
                    $line->{net_balance} = 1;
230
                }
231
                push @{ $pay_loop}, $line;
232
                ++$line_id;
233
            }
234
        }
235
        my $totalnotify = AmountNotify( $n, $b_number );
236
        if (!$totalnotify || $totalnotify=~/^0.00/ ) {
237
            $totalnotify = '0';
238
        }
239
        push @{$allfile}, {
240
            loop_pay => $pay_loop,
241
            notify   => $n,
242
            total    => sprintf( '%.2f', $totalnotify),
243
        };
244
    }
245
246
    if ( $data->{'category_type'} eq 'C') {
247
        my  ( $catcodes, $labels ) =  GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
248
        my $cnt = scalar @{$catcodes};
249
        if ($cnt > 1) {
250
            $template->param( 'CATCODE_MULTI' => 1);
251
        } elsif ($cnt == 1) {
252
            $template->param( 'catcode' =>    $catcodes->[0]);
253
        }
254
    } elsif ($data->{'category_type'} eq 'A') {
255
        $template->param( adultborrower => 1 );
256
    }
257
258
    my ($picture, $dberror) = GetPatronImage($data->{'cardnumber'});
259
    if ($picture ) {
260
        $template->param( picture => 1 );
261
    }
262
147
    $template->param(
263
    $template->param(
148
        allfile        => \@allfile,
264
        allfile        => $allfile,
149
        firstname      => $data->{'firstname'},
265
        firstname      => $data->{'firstname'},
150
        surname        => $data->{'surname'},
266
        surname        => $data->{'surname'},
151
        borrowernumber => $borrowernumber,
267
        borrowernumber => $b_number,
152
	cardnumber => $data->{'cardnumber'},
268
        cardnumber     => $data->{'cardnumber'},
153
	categorycode => $data->{'categorycode'},
269
        categorycode   => $data->{'categorycode'},
154
	category_type => $data->{'category_type'},
270
        category_type  => $data->{'category_type'},
155
	categoryname  => $data->{'description'},
271
        categoryname   => $data->{'description'},
156
	address => $data->{'address'},
272
        address        => $data->{'address'},
157
	address2 => $data->{'address2'},
273
        address2       => $data->{'address2'},
158
	city => $data->{'city'},
274
        city           => $data->{'city'},
159
	zipcode => $data->{'zipcode'},
275
        zipcode        => $data->{'zipcode'},
160
	country => $data->{'country'},
276
        phone          => $data->{'phone'},
161
	phone => $data->{'phone'},
277
        email          => $data->{'email'},
162
	email => $data->{'email'},
278
        branchcode     => $data->{'branchcode'},
163
	branchcode => $data->{'branchcode'},
279
        branchname     => GetBranchName($data->{'branchcode'}),
164
	branchname => GetBranchName($data->{'branchcode'}),
280
        is_child       => ($data->{'category_type'} eq 'C'),
165
	is_child        => ($data->{'category_type'} eq 'C'),
281
        total          => sprintf '%.2f', $total
166
        total          => sprintf( "%.2f", $total )
167
    );
282
    );
168
    output_html_with_http_headers $input, $cookie, $template->output;
283
    return;
284
}
169
285
286
sub get_for_redirect {
287
    my ($name, $name_in, $money) = @_;
288
    my $s = q{&} . $name . q{=};
289
    my $value = $input->param($name_in);
290
    if (!defined $value) {
291
        $value = ($money == 1) ? 0 : q{};
292
    }
293
    if ($money) {
294
        $s .= sprintf '%.2f', $value;
295
    } else {
296
        $s .= $value;
297
    }
298
    return $s;
170
}
299
}
171
else {
172
300
173
    my %inp;
301
sub redirect_to_paycollect {
302
    my ($action, $line_no) = @_;
303
    my $redirect = "/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber";
304
    $redirect .= q{&};
305
    $redirect .= "$action=1";
306
    $redirect .= get_for_redirect('accounttype',"accounttype_$line_no",0);
307
    $redirect .= get_for_redirect('amount',"amount_$line_no",1);
308
    $redirect .= get_for_redirect('amountoutstanding',"out_$line_no",1);
309
    $redirect .= get_for_redirect('accountno',"accountno_$line_no",0);
310
    $redirect .= get_for_redirect('description',"description_$line_no",0);
311
    $redirect .= get_for_redirect('title',"title_$line_no",0);
312
    $redirect .= get_for_redirect('itemnumber',"itemnumber_$line_no",0);
313
    $redirect .= get_for_redirect('notify_id',"notify_id_$line_no",0);
314
    $redirect .= get_for_redirect('notify_level',"notify_level_$line_no",0);
315
    $redirect .= '&remote_user=';
316
    $redirect .= $user;
317
    return print $input->redirect( $redirect );
318
}
319
sub writeoff_all {
320
    my @wo_lines;
174
    my @name = $input->param;
321
    my @name = $input->param;
175
    for ( my $i = 0 ; $i < @name ; $i++ ) {
322
    for (@name) {
176
        my $test = $input->param( $name[$i] );
323
        if (/^line_id_\d+$/) {
177
        if ( $test eq 'wo' ) {
324
            push @wo_lines, $input->param($_);
178
            my $temp = $name[$i];
179
            $temp =~ s/payfine//;
180
            $inp{ $name[$i] } = $temp;
181
        }
325
        }
182
    }
326
    }
183
    my $borrowernumber;
327
    for my $value (@wo_lines) {
184
    while ( my ( $key, $value ) = each %inp ) {
328
        my $accounttype    = $input->param("accounttype$value");
185
329
        my $borrowernum    = $input->param("borrowernumber$value");
186
        my $accounttype = $input->param("accounttype$value");
330
        my $itemno         = $input->param("itemnumber$value");
187
        $borrowernumber = $input->param("borrowernumber$value");
331
        my $amount         = $input->param("amount$value");
188
        my $itemno    = $input->param("itemnumber$value");
332
        my $accountno      = $input->param("accountno$value");
189
        my $amount    = $input->param("amount$value");
333
        writeoff( $borrowernum, $accountno, $itemno, $accounttype, $amount );
190
        my $accountno = $input->param("accountno$value");
191
        writeoff( $borrowernumber, $accountno, $itemno, $accounttype, $amount );
192
    }
334
    }
193
    $borrowernumber = $input->param('borrowernumber');
335
    $borrowernumber = $input->param('borrowernumber');
194
    print $input->redirect(
336
    print $input->redirect(
195
        "/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber");
337
        "/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber");
196
}
338
}
197
198
sub writeoff {
199
    my ( $borrowernumber, $accountnum, $itemnum, $accounttype, $amount ) = @_;
200
    my $user = $input->remote_user;
201
    my $dbh  = C4::Context->dbh;
202
    undef $itemnum unless $itemnum; # if no item is attached to fine, make sure to store it as a NULL
203
    my $sth =
204
      $dbh->prepare(
205
"Update accountlines set amountoutstanding=0 where accountno=? and borrowernumber=?"
206
      );
207
    $sth->execute( $accountnum, $borrowernumber );
208
    $sth->finish;
209
    $sth = $dbh->prepare("select max(accountno) from accountlines");
210
    $sth->execute;
211
    my $account = $sth->fetchrow_hashref;
212
    $sth->finish;
213
    $account->{'max(accountno)'}++;
214
    $sth = $dbh->prepare(
215
"insert into accountlines (borrowernumber,accountno,itemnumber,date,amount,description,accounttype)
216
						values (?,?,?,now(),?,'Writeoff','W')"
217
    );
218
    $sth->execute( $borrowernumber, $account->{'max(accountno)'},
219
        $itemnum, $amount );
220
    $sth->finish;
221
    UpdateStats( $branch, 'writeoff', $amount, '', '', '',
222
        $borrowernumber );
223
}
(-)a/members/paycollect.pl (-1 / +188 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
# Copyright 2009,2010 PTFS Inc.
3
#
4
# This file is part of Koha.
5
#
6
# Koha is free software; you can redistribute it and/or modify it under the
7
# terms of the GNU General Public License as published by the Free Software
8
# Foundation; either version 2 of the License, or (at your option) any later
9
# version.
10
#
11
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
12
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License along
16
# with Koha; if not, write to the Free Software Foundation, Inc.,
17
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19
use strict;
20
use warnings;
21
use C4::Context;
22
use C4::Auth;
23
use C4::Output;
24
use CGI;
25
use C4::Members;
26
use C4::Accounts;
27
use C4::Koha;
28
use C4::Branch;
29
30
my $input = CGI->new();
31
32
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
33
    {
34
        template_name   => 'members/paycollect.tmpl',
35
        query           => $input,
36
        type            => 'intranet',
37
        authnotrequired => 0,
38
        flagsrequired   => { borrowers => 1, updatecharges => 1 },
39
        debug           => 1,
40
    }
41
);
42
43
# get borrower details
44
my $borrowernumber = $input->param('borrowernumber');
45
my $borrower       = GetMember( $borrowernumber, 'borrowernumber' );
46
my $user           = $input->remote_user;
47
48
# get account details
49
my $branch = GetBranch( $input, GetBranches() );
50
51
my ( $total_due, $accts, $numaccts ) = GetMemberAccountRecords($borrowernumber);
52
my $total_paid = $input->param('paid');
53
54
my $individual   = $input->param('pay_individual');
55
my $writeoff     = $input->param('writeoff_individual');
56
my $select_lines = $input->param('selected');
57
my $select       = $input->param('selected_accts');
58
my $accountno;
59
60
if ( $individual || $writeoff ) {
61
    if ($individual) {
62
        $template->param( pay_individual => 1 );
63
    }
64
    elsif ($writeoff) {
65
        $template->param( writeoff_individual => 1 );
66
    }
67
    my $accounttype       = $input->param('accounttype');
68
    my $amount            = $input->param('amount');
69
    my $amountoutstanding = $input->param('amountoutstanding');
70
    $accountno = $input->param('accountno');
71
    my $description  = $input->param('description');
72
    my $title        = $input->param('title');
73
    my $notify_id    = $input->param('notify_id');
74
    my $notify_level = $input->param('notify_level');
75
    $total_due = $amountoutstanding;
76
    $template->param(
77
        accounttype       => $accounttype,
78
        accountno         => $accountno,
79
        amount            => $amount,
80
        amountoutstanding => $amountoutstanding,
81
        title             => $title,
82
        description       => $description,
83
        notify_id         => $notify_id,
84
        notify_level      => $notify_level,
85
    );
86
}
87
elsif ($select_lines) {
88
    $total_due = $input->param('amt');
89
    $template->param(
90
        selected_accts => $select_lines,
91
        amt            => $total_due
92
    );
93
}
94
95
if ( $total_paid and $total_paid ne '0.00' ) {
96
    if ( $total_paid < 0 or $total_paid > $total_due ) {
97
        $template->param(
98
            error => "You must pay a value less than or equal to $total_due" );
99
    }
100
    else {
101
        if ($individual) {
102
            if ( $total_paid == $total_due ) {
103
                makepayment( $borrowernumber, $accountno, $total_paid, $user,
104
                    $branch );
105
            }
106
            else {
107
                makepartialpayment( $borrowernumber, $accountno, $total_paid,
108
                    $user, $branch );
109
            }
110
            print $input->redirect(
111
                "/cgi-bin/koha/members/pay.pl?borrowernumber=$borrowernumber");
112
        }
113
        else {
114
            if ($select) {
115
                if ( $select =~ /^([\d,]*).+/ ) {
116
                    $select = $1;    # ensure passing no junk
117
                }
118
                my @acc = split /,/, $select;
119
                recordpayment_selectaccts( $borrowernumber, $total_paid,
120
                    \@acc );
121
            }
122
            else {
123
                recordpayment( $borrowernumber, $total_paid );
124
            }
125
126
# recordpayment does not return success or failure so lets redisplay the boraccount
127
128
            print $input->redirect(
129
"/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber"
130
            );
131
        }
132
    }
133
}
134
else {
135
    $total_paid = '0.00';    #TODO not right with pay_individual
136
}
137
138
get_borrower_photo($borrower);
139
my $is_child =  ( $borrower->{category_type} && $borrower->{category_type} eq 'C' );
140
141
$template->param(
142
    firstname      => $borrower->{firstname},
143
    surname        => $borrower->{surname},
144
    borrowernumber => $borrowernumber,
145
    cardnumber     => $borrower->{cardnumber},
146
    categorycode   => $borrower->{categorycode},
147
    category_type  => $borrower->{category_type},
148
    categoryname   => $borrower->{description},
149
    address        => $borrower->{address},
150
    address2       => $borrower->{address2},
151
    city           => $borrower->{city},
152
    zipcode        => $borrower->{zipcode},
153
    phone          => $borrower->{phone},
154
    email          => $borrower->{email},
155
    branchcode     => $borrower->{branchcode},
156
    branchname     => GetBranchName( $borrower->{branchcode} ),
157
    is_child       => $is_child,
158
    total          => sprintf( '%.2f', $total_due ),
159
);
160
161
output_html_with_http_headers $input, $cookie, $template->output;
162
163
sub get_borrower_photo {
164
    my $borr = shift;
165
166
    if ($borr->{category_type}) {
167
        if ( $borr->{category_type} eq 'C' ) {
168
            my ( $catcodes, $labels ) =
169
            GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
170
            my $num_catcodes = scalar @{$catcodes};
171
            if ( $num_catcodes == 1 ) {
172
                $template->param( 'catcode' => $catcodes->[0] );
173
            }
174
            elsif ( $num_catcodes > 1 ) {
175
                $template->param( 'CATCODE_MULTI' => 1 );
176
            }
177
        }
178
179
        if ( $borr->{'category_type'} eq 'A' ) {
180
            $template->param( adultborrower => 1 );
181
        }
182
    }
183
    my ( $picture, undef ) = GetPatronImage( $borr->{'cardnumber'} );
184
    if ($picture) {
185
        $template->param( picture => 1 );
186
    }
187
    return;
188
}

Return to bug 3498