Bugzilla – Attachment 116393 Details for
Bug 27636
Replace Koha::Account::pay with a simpler method
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27636: Add offset_amount to Koha::Accounts
Bug-27636-Add-offsetamount-to-KohaAccounts.patch (text/plain), 3.46 KB, created by
Martin Renvoize
on 2021-02-05 13:10:18 UTC
(
hide
)
Description:
Bug 27636: Add offset_amount to Koha::Accounts
Filename:
MIME Type:
Creator:
Martin Renvoize
Created:
2021-02-05 13:10:18 UTC
Size:
3.46 KB
patch
obsolete
>From 9860f9765ba3e773efc9632380b0a4e8377b7c29 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Fri, 5 Feb 2021 12:56:43 +0000 >Subject: [PATCH] Bug 27636: Add offset_amount to Koha::Accounts > >--- > Koha/Account.pm | 92 +++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 92 insertions(+) > >diff --git a/Koha/Account.pm b/Koha/Account.pm >index b4838bcdf2..78a6d628dc 100644 >--- a/Koha/Account.pm >+++ b/Koha/Account.pm >@@ -485,6 +485,98 @@ sub add_credit { > return $line; > } > >+=head3 offset_amount >+ >+ my $credit = $account->offset_amount( >+ { >+ amount => $amount, >+ credit_type => $credit_type, >+ payment_type => $payment_type, >+ cash_register => $register_id, >+ interface => $interface, >+ library_id => $branchcode, >+ user_id => $staff_id, >+ debts => $debit_lines, >+ description => $description, >+ note => $note >+ } >+ ); >+ >+This method allows an amount to be offset into a patrons account and immediately applied against debts. >+ >+You can optionally pass a debts parameter which consists of an arrayref of Koha::Account::Line debit lines. >+ >+$credit_type can be any of: >+ - 'PAYMENT' >+ - 'WRITEOFF' >+ - 'FORGIVEN' >+ >+=cut >+ >+sub offset_amount { >+ my ( $self, $params ) = @_; >+ >+ # check for mandatory params >+ my @mandatory = ( 'interface', 'amount', 'credit_type' ); >+ for my $param (@mandatory) { >+ unless ( defined( $params->{$param} ) ) { >+ Koha::Exceptions::MissingParameter->throw( >+ error => "The $param parameter is mandatory" ); >+ } >+ } >+ >+ # amount should always be passed as a positive value >+ my $amount = $params->{amount} * -1; >+ unless ( $amount < 0 ) { >+ Koha::Exceptions::Account::AmountNotPositive->throw( >+ error => 'Debit amount passed is not positive' ); >+ } >+ >+ my $credit; >+ my $schema = Koha::Database->new->schema; >+ try { >+ $schema->txn_do( >+ sub { >+ >+ # Add payin credit >+ $credit = $self->add_credit($params); >+ >+ # Offset debts passed first >+ if ( exists( $params->{debts} ) ) { >+ $credit->apply( >+ { >+ debits => $params->{debts}, >+ offset_type => $params->{credit_type} >+ } >+ ); >+ $credit->discard_changes; >+ } >+ >+ # Offset against remaining balance if AutoReconcile >+ $credit->apply( >+ { >+ debits => [ $self->outstanding_debits->as_list ], >+ offset_type => $params->{credit_type} >+ } >+ ) if ( C4::Context->preference("AccountAutoReconcile") ); >+ } >+ ); >+ } >+ catch { >+ if ( ref($_) eq 'Koha::Exceptions::Object::FKConstraint' ) { >+ if ( $_->broken_fk eq 'credit_type_code' ) { >+ Koha::Exceptions::Account::UnrecognisedType->throw( >+ error => 'Type of credit not recognised' ); >+ } >+ else { >+ $_->rethrow; >+ } >+ } >+ }; >+ >+ return $credit->discard_changes; >+} >+ > =head3 add_debit > > This method allows adding debits to a patron's account >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 27636
:
116393
|
118471
|
118515
|
118516
|
118522
|
118523
|
119205
|
119206
|
119207
|
119242
|
119243
|
119244
|
120022
|
120023
|
120024
|
120089
|
120090
|
120091
|
120257
|
120258
|
120259
|
120262
|
120263
|
120270
|
120271
|
120272
|
120276
|
120294
|
120343
|
120344
|
120345