|
Lines 57-63
Koha::Account->new( { patron_id => $borrowernumber } )->pay(
Link Here
|
| 57 |
library_id => $branchcode, |
57 |
library_id => $branchcode, |
| 58 |
lines => $lines, # Arrayref of Koha::Account::Line objects to pay |
58 |
lines => $lines, # Arrayref of Koha::Account::Line objects to pay |
| 59 |
account_type => $type, # accounttype code |
59 |
account_type => $type, # accounttype code |
| 60 |
offset_type => $offset_type, # offset type code |
60 |
offset_type => $offset_type, # offset type code |
|
|
61 |
credit_id => credit_id, # pay from balance of existing credit |
| 61 |
} |
62 |
} |
| 62 |
); |
63 |
); |
| 63 |
|
64 |
|
|
Lines 76-81
sub pay {
Link Here
|
| 76 |
my $payment_type = $params->{payment_type} || undef; |
77 |
my $payment_type = $params->{payment_type} || undef; |
| 77 |
my $account_type = $params->{account_type}; |
78 |
my $account_type = $params->{account_type}; |
| 78 |
my $offset_type = $params->{offset_type} || $type eq 'writeoff' ? 'Writeoff' : 'Payment'; |
79 |
my $offset_type = $params->{offset_type} || $type eq 'writeoff' ? 'Writeoff' : 'Payment'; |
|
|
80 |
my $credit_id = $params->{credit_id}; |
| 79 |
|
81 |
|
| 80 |
my $userenv = C4::Context->userenv; |
82 |
my $userenv = C4::Context->userenv; |
| 81 |
|
83 |
|
|
Lines 209-228
sub pay {
Link Here
|
| 209 |
|
211 |
|
| 210 |
$description ||= $type eq 'writeoff' ? 'Writeoff' : q{}; |
212 |
$description ||= $type eq 'writeoff' ? 'Writeoff' : q{}; |
| 211 |
|
213 |
|
| 212 |
my $payment = Koha::Account::Line->new( |
214 |
my $payment; |
| 213 |
{ |
215 |
if ($credit_id) { |
| 214 |
borrowernumber => $self->{patron_id}, |
216 |
$payment = Koha::Account::Lines->find($credit_id); |
| 215 |
accountno => $accountno, |
217 |
$payment->amountoutstanding( $balance_remaining * -1 ); |
| 216 |
date => dt_from_string(), |
218 |
$payment->store(); |
| 217 |
amount => 0 - $amount, |
219 |
} |
| 218 |
description => $description, |
220 |
else { |
| 219 |
accounttype => $account_type, |
221 |
$payment = Koha::Account::Line->new( |
| 220 |
payment_type => $payment_type, |
222 |
{ |
| 221 |
amountoutstanding => 0 - $balance_remaining, |
223 |
borrowernumber => $self->{patron_id}, |
| 222 |
manager_id => $manager_id, |
224 |
accountno => $accountno, |
| 223 |
note => $note, |
225 |
date => dt_from_string(), |
| 224 |
} |
226 |
amount => 0 - $amount, |
| 225 |
)->store(); |
227 |
description => $description, |
|
|
228 |
accounttype => $account_type, |
| 229 |
payment_type => $payment_type, |
| 230 |
amountoutstanding => 0 - $balance_remaining, |
| 231 |
manager_id => $manager_id, |
| 232 |
note => $note, |
| 233 |
} |
| 234 |
)->store(); |
| 235 |
} |
| 226 |
|
236 |
|
| 227 |
foreach my $o ( @account_offsets ) { |
237 |
foreach my $o ( @account_offsets ) { |
| 228 |
$o->credit_id( $payment->id() ); |
238 |
$o->credit_id( $payment->id() ); |
|
Lines 231-263
sub pay {
Link Here
|
| 231 |
|
241 |
|
| 232 |
$library_id ||= $userenv ? $userenv->{'branch'} : undef; |
242 |
$library_id ||= $userenv ? $userenv->{'branch'} : undef; |
| 233 |
|
243 |
|
| 234 |
UpdateStats( |
244 |
unless ( $credit_id ) { |
| 235 |
{ |
245 |
UpdateStats( |
| 236 |
branch => $library_id, |
246 |
{ |
| 237 |
type => $type, |
247 |
branch => $library_id, |
| 238 |
amount => $amount, |
248 |
type => $type, |
| 239 |
borrowernumber => $self->{patron_id}, |
249 |
amount => $amount, |
| 240 |
accountno => $accountno, |
250 |
borrowernumber => $self->{patron_id}, |
| 241 |
} |
251 |
accountno => $accountno, |
| 242 |
); |
252 |
} |
| 243 |
|
|
|
| 244 |
if ( C4::Context->preference("FinesLog") ) { |
| 245 |
logaction( |
| 246 |
"FINES", 'CREATE', |
| 247 |
$self->{patron_id}, |
| 248 |
Dumper( |
| 249 |
{ |
| 250 |
action => "create_$type", |
| 251 |
borrowernumber => $self->{patron_id}, |
| 252 |
accountno => $accountno, |
| 253 |
amount => 0 - $amount, |
| 254 |
amountoutstanding => 0 - $balance_remaining, |
| 255 |
accounttype => $account_type, |
| 256 |
accountlines_paid => \@fines_paid, |
| 257 |
manager_id => $manager_id, |
| 258 |
} |
| 259 |
) |
| 260 |
); |
253 |
); |
|
|
254 |
|
| 255 |
if ( C4::Context->preference("FinesLog") ) { |
| 256 |
logaction( |
| 257 |
"FINES", 'CREATE', |
| 258 |
$self->{patron_id}, |
| 259 |
Dumper( |
| 260 |
{ |
| 261 |
action => "create_$type", |
| 262 |
borrowernumber => $self->{patron_id}, |
| 263 |
accountno => $accountno, |
| 264 |
amount => 0 - $amount, |
| 265 |
amountoutstanding => 0 - $balance_remaining, |
| 266 |
accounttype => $account_type, |
| 267 |
accountlines_paid => \@fines_paid, |
| 268 |
manager_id => $manager_id, |
| 269 |
} |
| 270 |
) |
| 271 |
); |
| 272 |
} |
| 261 |
} |
273 |
} |
| 262 |
|
274 |
|
| 263 |
return $payment->id; |
275 |
return $payment->id; |
|
Lines 287-292
sub balance {
Link Here
|
| 287 |
: 0; |
299 |
: 0; |
| 288 |
} |
300 |
} |
| 289 |
|
301 |
|
|
|
302 |
=head3 normalize_balance |
| 303 |
|
| 304 |
$account->normalize_balance(); |
| 305 |
|
| 306 |
Find outstanding credits and use them to pay outstanding debits |
| 307 |
|
| 308 |
=cut |
| 309 |
|
| 310 |
sub normalize_balance { |
| 311 |
my ($self) = @_; |
| 312 |
my @credits = Koha::Account::Lines->search( |
| 313 |
{ |
| 314 |
borrowernumber => $self->{patron_id}, |
| 315 |
amountoutstanding => { '<' => 0 }, |
| 316 |
} |
| 317 |
); |
| 318 |
|
| 319 |
foreach my $credit (@credits) { |
| 320 |
$self->pay( |
| 321 |
{ |
| 322 |
credit_id => $credit->id, |
| 323 |
amount => $credit->amountoutstanding * -1, |
| 324 |
} |
| 325 |
); |
| 326 |
} |
| 327 |
|
| 328 |
return $self; |
| 329 |
} |
| 330 |
|
| 290 |
1; |
331 |
1; |
| 291 |
|
332 |
|
| 292 |
=head1 AUTHOR |
333 |
=head1 AUTHOR |