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 |
} |