Lines 2-7
Link Here
|
2 |
|
2 |
|
3 |
# Copyright 2000-2002 Katipo Communications |
3 |
# Copyright 2000-2002 Katipo Communications |
4 |
# Copyright 2010 BibLibre |
4 |
# Copyright 2010 BibLibre |
|
|
5 |
# Copyright 2010,2011 PTFS-Europe Ltd |
5 |
# |
6 |
# |
6 |
# This file is part of Koha. |
7 |
# This file is part of Koha. |
7 |
# |
8 |
# |
Lines 18-24
Link Here
|
18 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
19 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
19 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
20 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
20 |
|
21 |
|
21 |
|
|
|
22 |
=head1 pay.pl |
22 |
=head1 pay.pl |
23 |
|
23 |
|
24 |
written 11/1/2000 by chris@katipo.oc.nz |
24 |
written 11/1/2000 by chris@katipo.oc.nz |
Lines 38-233
use C4::Accounts;
Link Here
|
38 |
use C4::Stats; |
38 |
use C4::Stats; |
39 |
use C4::Koha; |
39 |
use C4::Koha; |
40 |
use C4::Overdues; |
40 |
use C4::Overdues; |
41 |
use C4::Branch; # GetBranches |
41 |
use C4::Branch; |
42 |
|
42 |
|
43 |
my $input = new CGI; |
43 |
my $input = CGI->new; |
44 |
|
44 |
|
45 |
my ( $template, $loggedinuser, $cookie ) = get_template_and_user( |
45 |
my ( $template, $loggedinuser, $cookie ) = get_template_and_user( |
46 |
{ |
46 |
{ template_name => 'members/pay.tmpl', |
47 |
template_name => "members/pay.tmpl", |
|
|
48 |
query => $input, |
47 |
query => $input, |
49 |
type => "intranet", |
48 |
type => 'intranet', |
50 |
authnotrequired => 0, |
49 |
authnotrequired => 0, |
51 |
flagsrequired => { borrowers => 1, updatecharges => 1 }, |
50 |
flagsrequired => { borrowers => 1, updatecharges => 1 }, |
52 |
debug => 1, |
51 |
debug => 1, |
53 |
} |
52 |
} |
54 |
); |
53 |
); |
55 |
|
54 |
|
|
|
55 |
my $writeoff_sth; |
56 |
my $add_writeoff_sth; |
57 |
|
58 |
my @names = $input->param; |
59 |
|
56 |
my $borrowernumber = $input->param('borrowernumber'); |
60 |
my $borrowernumber = $input->param('borrowernumber'); |
57 |
if ( $borrowernumber eq '' ) { |
61 |
if ( !$borrowernumber ) { |
58 |
$borrowernumber = $input->param('borrowernumber0'); |
62 |
$borrowernumber = $input->param('borrowernumber0'); |
59 |
} |
63 |
} |
60 |
|
64 |
|
61 |
# get borrower details |
65 |
# get borrower details |
62 |
my $data = GetMember( borrowernumber => $borrowernumber ); |
66 |
my $borrower = GetMember( borrowernumber => $borrowernumber ); |
63 |
my $user = $input->remote_user; |
67 |
my $user = $input->remote_user; |
|
|
68 |
$user ||= q{}; |
64 |
|
69 |
|
65 |
# get account details |
|
|
66 |
my $branches = GetBranches(); |
70 |
my $branches = GetBranches(); |
67 |
my $branch = GetBranch( $input, $branches ); |
71 |
my $branch = GetBranch( $input, $branches ); |
68 |
|
72 |
|
69 |
my @names = $input->param; |
73 |
my $writeoff_item = $input->param('confirm_writeoff'); |
70 |
my %inp; |
74 |
my $paycollect = $input->param('paycollect'); |
71 |
my $check = 0; |
75 |
if ($paycollect) { |
72 |
for ( my $i = 0 ; $i < @names ; $i++ ) { |
76 |
print $input->redirect( |
73 |
my $temp = $input->param( $names[$i] ); |
77 |
"/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber"); |
74 |
if ( $temp eq 'wo' ) { |
78 |
} |
75 |
$inp{ $names[$i] } = $temp; |
79 |
my $payselected = $input->param('payselected'); |
76 |
$check = 1; |
80 |
if ($payselected) { |
77 |
} |
81 |
payselected(@names); |
78 |
if ( $temp eq 'yes' ) { |
|
|
79 |
|
80 |
# FIXME : using array +4, +5, +6 is dirty. Should use arrays for each accountline |
81 |
my $amount = $input->param( $names[ $i + 4 ] ); |
82 |
my $borrowernumber = $input->param( $names[ $i + 5 ] ); |
83 |
my $accountno = $input->param( $names[ $i + 6 ] ); |
84 |
makepayment( $borrowernumber, $accountno, $amount, $user, $branch ); |
85 |
$check = 2; |
86 |
} |
87 |
if ( $temp eq 'no'||$temp eq 'yes'||$temp eq 'wo') { |
88 |
my $borrowernumber = $input->param( $names[ $i + 5 ] ); |
89 |
my $accountno = $input->param( $names[ $i + 6 ] ); |
90 |
my $note = $input->param( $names[ $i + 10 ] ); |
91 |
ModNote( $borrowernumber, $accountno, $note ); |
92 |
} |
93 |
} |
82 |
} |
94 |
|
83 |
|
95 |
my $total = $input->param('total') || ''; |
84 |
my $writeoff_all = $input->param('woall'); # writeoff all fines |
96 |
if ( $check == 0 ) { |
85 |
if ($writeoff_all) { |
97 |
if ( $total ne '' ) { |
86 |
writeoff_all(@names); |
98 |
recordpayment( $borrowernumber, $total ); |
87 |
} elsif ($writeoff_item) { |
|
|
88 |
my $accountno = $input->param('accountno'); |
89 |
my $itemno = $input->param('itemnumber'); |
90 |
my $account_type = $input->param('accounttype'); |
91 |
my $amount = $input->param('amount'); |
92 |
writeoff( $accountno, $itemno, $account_type, $amount ); |
93 |
} |
94 |
|
95 |
for (@names) { |
96 |
if (/^pay_indiv_(\d+)$/) { |
97 |
my $line_no = $1; |
98 |
redirect_to_paycollect( 'pay_individual', $line_no ); |
99 |
} elsif (/^wo_indiv_(\d+)$/) { |
100 |
my $line_no = $1; |
101 |
redirect_to_paycollect( 'writeoff_individual', $line_no ); |
99 |
} |
102 |
} |
|
|
103 |
} |
100 |
|
104 |
|
101 |
my ( $total, $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber ); |
105 |
add_accounts_to_template(); |
102 |
|
|
|
103 |
my @allfile; |
104 |
my @notify = NumberNotifyId($borrowernumber); |
105 |
|
106 |
my $numberofnotify = scalar(@notify); |
107 |
for ( my $j = 0 ; $j < scalar(@notify) ; $j++ ) { |
108 |
my @loop_pay; |
109 |
my ( $total , $accts, $numaccts) = |
110 |
GetBorNotifyAcctRecord( $borrowernumber, $notify[$j] ); |
111 |
for ( my $i = 0 ; $i < $numaccts ; $i++ ) { |
112 |
my %line; |
113 |
if ( $accts->[$i]{'amountoutstanding'} != 0 ) { |
114 |
$accts->[$i]{'amount'} += 0.00; |
115 |
$accts->[$i]{'amountoutstanding'} += 0.00; |
116 |
$line{i} = $j . "" . $i; |
117 |
$line{itemnumber} = $accts->[$i]{'itemnumber'}; |
118 |
$line{accounttype} = $accts->[$i]{'accounttype'}; |
119 |
$line{amount} = sprintf( "%.2f", $accts->[$i]{'amount'} ); |
120 |
$line{amountoutstanding} = |
121 |
sprintf( "%.2f", $accts->[$i]{'amountoutstanding'} ); |
122 |
$line{borrowernumber} = $borrowernumber; |
123 |
$line{accountno} = $accts->[$i]{'accountno'}; |
124 |
$line{description} = $accts->[$i]{'description'}; |
125 |
$line{note} = $accts->[$i]{'note'}; |
126 |
$line{title} = $accts->[$i]{'title'}; |
127 |
$line{notify_id} = $accts->[$i]{'notify_id'}; |
128 |
$line{notify_level} = $accts->[$i]{'notify_level'}; |
129 |
$line{net_balance} = 1 if($accts->[$i]{'amountoutstanding'} > 0); # you can't pay a credit. |
130 |
push( @loop_pay, \%line ); |
131 |
} |
132 |
} |
133 |
|
106 |
|
134 |
my $totalnotify = AmountNotify( $notify[$j], $borrowernumber ); |
107 |
output_html_with_http_headers $input, $cookie, $template->output; |
135 |
( $totalnotify = '0' ) if ( $totalnotify =~ /^0.00/ ); |
108 |
|
136 |
push @allfile, |
109 |
sub writeoff { |
137 |
{ |
110 |
my ( $accountnum, $itemnum, $accounttype, $amount ) = @_; |
138 |
'loop_pay' => \@loop_pay, |
111 |
|
139 |
'notify' => $notify[$j], |
112 |
# if no item is attached to fine, make sure to store it as a NULL |
140 |
'total' => sprintf( "%.2f",$totalnotify), |
113 |
$itemnum ||= undef; |
141 |
|
114 |
get_writeoff_sth(); |
142 |
}; |
115 |
$writeoff_sth->execute( $accountnum, $borrowernumber ); |
143 |
} |
116 |
|
144 |
|
117 |
my $acct = getnextacctno($borrowernumber); |
145 |
if ( $data->{'category_type'} eq 'C') { |
118 |
$add_writeoff_sth->execute( $borrowernumber, $acct, $itemnum, $amount ); |
146 |
my ( $catcodes, $labels ) = GetborCatFromCatType( 'A', 'WHERE category_type = ?' ); |
119 |
|
147 |
my $cnt = scalar(@$catcodes); |
120 |
UpdateStats( $branch, 'writeoff', $amount, q{}, q{}, q{}, $borrowernumber ); |
148 |
$template->param( 'CATCODE_MULTI' => 1) if $cnt > 1; |
121 |
|
149 |
$template->param( 'catcode' => $catcodes->[0]) if $cnt == 1; |
122 |
return; |
150 |
} |
123 |
} |
151 |
|
124 |
|
152 |
$template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' ); |
125 |
sub add_accounts_to_template { |
153 |
my ($picture, $dberror) = GetPatronImage($data->{'cardnumber'}); |
126 |
|
154 |
$template->param( picture => 1 ) if $picture; |
127 |
my ( $total, undef, undef ) = GetMemberAccountRecords($borrowernumber); |
155 |
|
128 |
my $accounts = []; |
|
|
129 |
my @notify = NumberNotifyId($borrowernumber); |
130 |
|
131 |
my $notify_groups = []; |
132 |
for my $notify_id (@notify) { |
133 |
my ( $acct_total, $accountlines, undef ) = |
134 |
GetBorNotifyAcctRecord( $borrowernumber, $notify_id ); |
135 |
if ( @{$accountlines} ) { |
136 |
my $totalnotify = AmountNotify( $notify_id, $borrowernumber ); |
137 |
push @{$accounts}, |
138 |
{ accountlines => $accountlines, |
139 |
notify => $notify_id, |
140 |
total => $totalnotify, |
141 |
}; |
142 |
} |
143 |
} |
144 |
borrower_add_additional_fields($borrower); |
156 |
$template->param( |
145 |
$template->param( |
157 |
allfile => \@allfile, |
146 |
accounts => $accounts, |
158 |
firstname => $data->{'firstname'}, |
147 |
borrower => $borrower, |
159 |
surname => $data->{'surname'}, |
148 |
total => $total, |
160 |
borrowernumber => $borrowernumber, |
|
|
161 |
cardnumber => $data->{'cardnumber'}, |
162 |
categorycode => $data->{'categorycode'}, |
163 |
category_type => $data->{'category_type'}, |
164 |
categoryname => $data->{'description'}, |
165 |
address => $data->{'address'}, |
166 |
address2 => $data->{'address2'}, |
167 |
city => $data->{'city'}, |
168 |
state => $data->{'state'}, |
169 |
zipcode => $data->{'zipcode'}, |
170 |
country => $data->{'country'}, |
171 |
phone => $data->{'phone'}, |
172 |
email => $data->{'email'}, |
173 |
branchcode => $data->{'branchcode'}, |
174 |
branchname => GetBranchName($data->{'branchcode'}), |
175 |
is_child => ($data->{'category_type'} eq 'C'), |
176 |
total => sprintf( "%.2f", $total ) |
177 |
); |
149 |
); |
178 |
output_html_with_http_headers $input, $cookie, $template->output; |
150 |
return; |
179 |
|
151 |
|
180 |
} |
152 |
} |
181 |
else { |
153 |
|
182 |
|
154 |
sub get_for_redirect { |
183 |
my %inp; |
155 |
my ( $name, $name_in, $money ) = @_; |
184 |
my @name = $input->param; |
156 |
my $s = q{&} . $name . q{=}; |
185 |
for ( my $i = 0 ; $i < @name ; $i++ ) { |
157 |
my $value = $input->param($name_in); |
186 |
my $test = $input->param( $name[$i] ); |
158 |
if ( !defined $value ) { |
187 |
if ( $test eq 'wo' ) { |
159 |
$value = ( $money == 1 ) ? 0 : q{}; |
188 |
my $temp = $name[$i]; |
160 |
} |
189 |
$temp =~ s/payfine//; |
161 |
if ($money) { |
190 |
$inp{ $name[$i] } = $temp; |
162 |
$s .= sprintf '%.2f', $value; |
191 |
} |
163 |
} else { |
|
|
164 |
$s .= $value; |
192 |
} |
165 |
} |
193 |
my $borrowernumber; |
166 |
return $s; |
194 |
while ( my ( $key, $value ) = each %inp ) { |
167 |
} |
195 |
|
168 |
|
196 |
my $accounttype = $input->param("accounttype$value"); |
169 |
sub redirect_to_paycollect { |
197 |
$borrowernumber = $input->param("borrowernumber$value"); |
170 |
my ( $action, $line_no ) = @_; |
198 |
my $itemno = $input->param("itemnumber$value"); |
171 |
my $redirect = |
199 |
my $amount = $input->param("amount$value"); |
172 |
"/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber"; |
200 |
my $accountno = $input->param("accountno$value"); |
173 |
$redirect .= q{&}; |
201 |
writeoff( $borrowernumber, $accountno, $itemno, $accounttype, $amount ); |
174 |
$redirect .= "$action=1"; |
|
|
175 |
$redirect .= get_for_redirect( 'accounttype', "accounttype$line_no", 0 ); |
176 |
$redirect .= get_for_redirect( 'amount', "amount$line_no", 1 ); |
177 |
$redirect .= |
178 |
get_for_redirect( 'amountoutstanding', "amountoutstanding$line_no", 1 ); |
179 |
$redirect .= get_for_redirect( 'accountno', "accountno$line_no", 0 ); |
180 |
$redirect .= get_for_redirect( 'description', "description$line_no", 0 ); |
181 |
$redirect .= get_for_redirect( 'title', "title$line_no", 0 ); |
182 |
$redirect .= get_for_redirect( 'itemnumber', "itemnumber$line_no", 0 ); |
183 |
$redirect .= get_for_redirect( 'notify_id', "notify_id$line_no", 0 ); |
184 |
$redirect .= get_for_redirect( 'notify_level', "notify_level$line_no", 0 ); |
185 |
$redirect .= '&remote_user='; |
186 |
$redirect .= $user; |
187 |
return print $input->redirect($redirect); |
188 |
} |
189 |
|
190 |
sub writeoff_all { |
191 |
my @params = @_; |
192 |
my @wo_lines = grep { /^accountno\d+$/ } @params; |
193 |
for (@wo_lines) { |
194 |
if (/(\d+)/) { |
195 |
my $value = $1; |
196 |
my $accounttype = $input->param("accounttype$value"); |
197 |
|
198 |
# my $borrowernum = $input->param("borrowernumber$value"); |
199 |
my $itemno = $input->param("itemnumber$value"); |
200 |
my $amount = $input->param("amount$value"); |
201 |
my $accountno = $input->param("accountno$value"); |
202 |
writeoff( $accountno, $itemno, $accounttype, $amount ); |
203 |
} |
202 |
} |
204 |
} |
|
|
205 |
|
203 |
$borrowernumber = $input->param('borrowernumber'); |
206 |
$borrowernumber = $input->param('borrowernumber'); |
204 |
print $input->redirect( |
207 |
print $input->redirect( |
205 |
"/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber"); |
208 |
"/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber"); |
|
|
209 |
return; |
206 |
} |
210 |
} |
207 |
|
211 |
|
208 |
sub writeoff { |
212 |
sub borrower_add_additional_fields { |
209 |
my ( $borrowernumber, $accountnum, $itemnum, $accounttype, $amount ) = @_; |
213 |
my $b_ref = shift; |
210 |
my $user = $input->remote_user; |
214 |
|
211 |
my $dbh = C4::Context->dbh; |
215 |
# some borrower info is not returned in the standard call despite being assumed |
212 |
undef $itemnum unless $itemnum; # if no item is attached to fine, make sure to store it as a NULL |
216 |
# in a number of templates. It should not be the business of this script but in lieu of |
213 |
my $sth = |
217 |
# a revised api here it is ... |
214 |
$dbh->prepare( |
218 |
if ( $b_ref->{category_type} eq 'C' ) { |
215 |
"Update accountlines set amountoutstanding=0 where accountno=? and borrowernumber=?" |
219 |
my ( $catcodes, $labels ) = |
216 |
); |
220 |
GetborCatFromCatType( 'A', 'WHERE category_type = ?' ); |
217 |
$sth->execute( $accountnum, $borrowernumber ); |
221 |
if ( @{$catcodes} ) { |
218 |
$sth->finish; |
222 |
if ( @{$catcodes} > 1 ) { |
219 |
$sth = $dbh->prepare("select max(accountno) from accountlines"); |
223 |
$b_ref->{CATCODE_MULTI} = 1; |
220 |
$sth->execute; |
224 |
} elsif ( @{$catcodes} == 1 ) { |
221 |
my $account = $sth->fetchrow_hashref; |
225 |
$b_ref->{catcode} = $catcodes->[0]; |
222 |
$sth->finish; |
226 |
} |
223 |
$account->{'max(accountno)'}++; |
227 |
} |
224 |
$sth = $dbh->prepare( |
228 |
} elsif ( $b_ref->{category_type} eq 'A' ) { |
225 |
"insert into accountlines (borrowernumber,accountno,itemnumber,date,amount,description,accounttype) |
229 |
$b_ref->{adultborrower} = 1; |
226 |
values (?,?,?,now(),?,'Writeoff','W')" |
230 |
} |
227 |
); |
231 |
my ( $picture, $dberror ) = GetPatronImage( $b_ref->{cardnumber} ); |
228 |
$sth->execute( $borrowernumber, $account->{'max(accountno)'}, |
232 |
if ($picture) { |
229 |
$itemnum, $amount ); |
233 |
$b_ref->{has_picture} = 1; |
230 |
$sth->finish; |
234 |
} |
231 |
UpdateStats( $branch, 'writeoff', $amount, '', '', '', |
235 |
|
232 |
$borrowernumber ); |
236 |
$b_ref->{branchname} = GetBranchName( $b_ref->{branchcode} ); |
|
|
237 |
return; |
238 |
} |
239 |
|
240 |
sub payselected { |
241 |
my @params = @_; |
242 |
my $amt = 0; |
243 |
my @lines_to_pay; |
244 |
foreach (@params) { |
245 |
if (/^incl_par_(\d+)$/) { |
246 |
my $index = $1; |
247 |
push @lines_to_pay, $input->param("accountno$index"); |
248 |
$amt += $input->param("amountoutstanding$index"); |
249 |
} |
250 |
} |
251 |
$amt = '&amt=' . $amt; |
252 |
my $sel = '&selected=' . join ',', @lines_to_pay; |
253 |
my $redirect = |
254 |
"/cgi-bin/koha/members/paycollect.pl?borrowernumber=$borrowernumber" |
255 |
. $amt |
256 |
. $sel; |
257 |
|
258 |
print $input->redirect($redirect); |
259 |
return; |
260 |
} |
261 |
|
262 |
sub get_writeoff_sth { |
263 |
|
264 |
# lets prepare these statement handles only once |
265 |
if ($writeoff_sth) { |
266 |
return; |
267 |
} else { |
268 |
my $dbh = C4::Context->dbh; |
269 |
|
270 |
# Do we need to validate accounttype |
271 |
my $sql = 'Update accountlines set amountoutstanding=0 ' |
272 |
. 'WHERE accountno=? and borrowernumber=?'; |
273 |
$writeoff_sth = $dbh->prepare($sql); |
274 |
my $insert = |
275 |
q{insert into accountlines (borrowernumber,accountno,itemnumber,date,amount,description,accounttype)} |
276 |
. q{values (?,?,?,now(),?,'Writeoff','W')}; |
277 |
$add_writeoff_sth = $dbh->prepare($insert); |
278 |
} |
279 |
return; |
233 |
} |
280 |
} |