|
Lines 278-283
sub apply {
Link Here
|
| 278 |
return $available_credit; |
278 |
return $available_credit; |
| 279 |
} |
279 |
} |
| 280 |
|
280 |
|
|
|
281 |
=head3 payout |
| 282 |
|
| 283 |
$credit_accountline->payout( |
| 284 |
{ |
| 285 |
payout_type => $payout_type, |
| 286 |
register_id => $register_id, |
| 287 |
amount => $amount |
| 288 |
} |
| 289 |
); |
| 290 |
|
| 291 |
Used to 'pay out' a credit to a user. |
| 292 |
|
| 293 |
Payout type may be one of any existing payment types |
| 294 |
|
| 295 |
=cut |
| 296 |
|
| 297 |
sub payout { |
| 298 |
my ( $self, $params ) = @_; |
| 299 |
|
| 300 |
# Make sure it is a credit we are paying out |
| 301 |
unless ( $self->is_credit ) { |
| 302 |
Koha::Exceptions::Account::IsNotCredit->throw( |
| 303 |
error => 'Account line ' . $self->id . ' is not a credit' ); |
| 304 |
} |
| 305 |
|
| 306 |
unless ( $params->{interface} ) { |
| 307 |
Koha::Exceptions::MissingParameter->throw( |
| 308 |
error => 'The interface parameter is mandatory' ); |
| 309 |
} |
| 310 |
|
| 311 |
# Make sure there is outstanding credit to pay out |
| 312 |
my $amount = |
| 313 |
$params->{amount} ? $params->{amount} : $self->amountoutstanding; |
| 314 |
return unless $self->amountoutstanding >= $amount; |
| 315 |
|
| 316 |
# Make sure we record the cash register for cash transactions |
| 317 |
Koha::Exceptions::Account::RegisterRequired->throw() |
| 318 |
if ( C4::Context->preference("UseCashRegisters") |
| 319 |
&& defined( $params->{payout_type} ) |
| 320 |
&& ( $params->{payout_type} eq 'CASH' ) |
| 321 |
&& !defined( $params->{cash_register} ) ); |
| 322 |
|
| 323 |
$params->{branch} //= $self->branchcode; |
| 324 |
|
| 325 |
my $payout; |
| 326 |
$self->_result->result_source->schema->txn_do( |
| 327 |
sub { |
| 328 |
|
| 329 |
# A 'payout' is a 'debit' |
| 330 |
$payout = Koha::Account::Line->new( |
| 331 |
{ |
| 332 |
date => \'NOW()', |
| 333 |
amount => 0 - $amount, |
| 334 |
debit_type_code => 'PAYOUT', |
| 335 |
payment_type => $params->{payout_type}, |
| 336 |
amountoutstanding => 0, |
| 337 |
manager_id => $params->{staff_id}, |
| 338 |
borrowernumber => $params->{patron_id}, |
| 339 |
interface => $params->{interface}, |
| 340 |
branchcode => $params->{branch}, |
| 341 |
register_id => $params->{cash_register}, |
| 342 |
note => $params->{quantity} |
| 343 |
} |
| 344 |
)->store(); |
| 345 |
|
| 346 |
my $payout_offset = Koha::Account::Offset->new( |
| 347 |
{ |
| 348 |
debit_id => $payout->accountlines_id, |
| 349 |
type => 'PAYOUT', |
| 350 |
amount => 0 - $amount |
| 351 |
} |
| 352 |
)->store(); |
| 353 |
|
| 354 |
my $application_offset = Koha::Account::Offset->new( |
| 355 |
{ |
| 356 |
debit_id => $payout->accountlines_id, |
| 357 |
credit_id => $self->accountlines_id, |
| 358 |
type => 'PAYOUT', |
| 359 |
amount => 0 - $amount |
| 360 |
} |
| 361 |
)->store(); |
| 362 |
|
| 363 |
$self->status('PAID')->store; |
| 364 |
} |
| 365 |
); |
| 366 |
|
| 367 |
return $payout; |
| 368 |
} |
| 369 |
|
| 281 |
=head3 adjust |
370 |
=head3 adjust |
| 282 |
|
371 |
|
| 283 |
This method allows updating a debit or credit on a patron's account |
372 |
This method allows updating a debit or credit on a patron's account |
| 284 |
- |
|
|