Bugzilla – Attachment 81880 Details for
Bug 21002
Add Koha::Account::add_debit
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 21002: Add ->add_debit method to Koha::Account
Bug-21002-Add--adddebit-method-to-KohaAccount.patch (text/plain), 8.18 KB, created by
Martin Renvoize (ashimema)
on 2018-11-02 10:58:16 UTC
(
hide
)
Description:
Bug 21002: Add ->add_debit method to Koha::Account
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2018-11-02 10:58:16 UTC
Size:
8.18 KB
patch
obsolete
>From 84b5d394c80434710f916b8674cbc4dc7d5da1f1 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Sat, 27 Oct 2018 09:52:38 +0100 >Subject: [PATCH] Bug 21002: Add ->add_debit method to Koha::Account > >--- > Koha/Account.pm | 166 +++++++++++++++++++++++++++++++++++-- > Koha/Exceptions/Account.pm | 17 ++++ > 2 files changed, 178 insertions(+), 5 deletions(-) > >diff --git a/Koha/Account.pm b/Koha/Account.pm >index 6f41b3bbd2..8a5cee891f 100644 >--- a/Koha/Account.pm >+++ b/Koha/Account.pm >@@ -32,6 +32,7 @@ use Koha::Patrons; > use Koha::Account::Lines; > use Koha::Account::Offsets; > use Koha::DateUtils qw( dt_from_string ); >+use Koha::Exceptions::Account; > > =head1 NAME > >@@ -340,7 +341,7 @@ sub add_credit { > > my $schema = Koha::Database->new->schema; > >- my $account_type = $Koha::Account::account_type->{$type}; >+ my $account_type = $Koha::Account::account_type_credit->{$type}; > $account_type .= $sip > if defined $sip && > $type eq 'payment'; >@@ -411,6 +412,138 @@ sub add_credit { > return $line; > } > >+=head3 add_debit >+ >+This method allows adding debits to a patron's account >+ >+my $debit_line = Koha::Account->new({ patron_id => $patron_id })->add_debit( >+ { >+ amount => $amount, >+ description => $description, >+ note => $note, >+ user_id => $user_id, >+ library_id => $library_id, >+ type => $debit_type, >+ item_id => $item_id, >+ issue_id => $issue_id >+ } >+); >+ >+$debit_type can be any of: >+ - fine >+ - lost_item >+ - new_card >+ - account >+ - sundry >+ - processing >+ - rent >+ - reserve >+ - overdue >+ >+=cut >+ >+sub add_debit { >+ >+ my ( $self, $params ) = @_; >+ >+ # amount should always be a positive value >+ my $amount = $params->{amount}; >+ >+ unless ( $amount > 0 ) { >+ Koha::Exceptions::Account::AmountNotPositive->throw( >+ error => 'Debit amount passed is not positive' >+ ); >+ } >+ >+ my $description = $params->{description} // q{}; >+ my $note = $params->{note} // q{}; >+ my $user_id = $params->{user_id}; >+ my $library_id = $params->{library_id}; >+ my $type = $params->{type}; >+ my $item_id = $params->{item_id}; >+ my $issue_id = $params->{issue_id}; >+ >+ my $schema = Koha::Database->new->schema; >+ >+ unless ( exists($Koha::Account::account_type_debit->{$type}) ) { >+ Koha::Exceptions::Account::UnrecognisedType->throw( >+ error => 'Type of debit not recognised' >+ ); >+ } >+ >+ my $account_type = $Koha::Account::account_type_debit->{$type}; >+ >+ my $line; >+ >+ $schema->txn_do( >+ sub { >+ # We should remove accountno, it is no longer needed >+ my $last = Koha::Account::Lines->search( { borrowernumber => $self->{patron_id} }, >+ { order_by => 'accountno' } )->next(); >+ my $accountno = $last ? $last->accountno + 1 : 1; >+ >+ # Insert the account line >+ $line = Koha::Account::Line->new( >+ { borrowernumber => $self->{patron_id}, >+ date => \'NOW()', >+ amount => $amount, >+ description => $description, >+ accounttype => $account_type, >+ amountoutstanding => $amount, >+ payment_type => undef, >+ note => $note, >+ manager_id => $user_id, >+ itemnumber => $item_id, >+ issue_id => $issue_id, >+ ( $type eq 'fine' ? ( lastincrement => $amount ) : ()), >+ } >+ )->store(); >+ >+ # Record the account offset >+ my $account_offset = Koha::Account::Offset->new( >+ { debit_id => $line->id, >+ type => $Koha::Account::offset_type->{$type}, >+ amount => $amount >+ } >+ )->store(); >+ >+ UpdateStats( >+ { branch => $library_id, >+ type => $type, >+ amount => $amount, >+ borrowernumber => $self->{patron_id}, >+ accountno => $accountno, >+ } >+ ) if grep { $type eq $_ } ('renew', 'issue', 'localuse', 'return', 'onsite_checkout' ); >+ >+ if ( C4::Context->preference("FinesLog") ) { >+ logaction( >+ "FINES", 'CREATE', >+ $self->{patron_id}, >+ Dumper( >+ { action => "create_$type", #create_fee in chargelostitem will become create_processing and create_lost_item >+ #not recorded in AddIssuingCharge will become create_rent >+ #not recorded in AddRenewal will become create_rent >+ #undef in UpdateFine will become create_fine >+ borrowernumber => $self->{patron_id}, >+ accountno => $accountno, >+ amount => $amount, >+ description => $description, >+ amountoutstanding => $amount, >+ accounttype => $account_type, >+ note => $note, >+ itemnumber => $item_id, >+ manager_id => $user_id, >+ } >+ ) >+ ); >+ } >+ } >+ ); >+ >+ return $line; >+} >+ > =head3 balance > > my $balance = $self->balance >@@ -555,14 +688,19 @@ our $offset_type = { > 'forgiven' => 'Writeoff', > 'lost_item_return' => 'Lost Item', > 'payment' => 'Payment', >- 'writeoff' => 'Writeoff' >+ 'writeoff' => 'Writeoff', >+ 'reserve' => 'Reserve Fee', >+ 'processing' => 'Processing Fee', >+ 'lost_item' => 'Lost Item', >+ 'rent' => 'Rental Fee', >+ 'fine' => 'Fine', > }; > >-=head3 $account_type >+=head3 $account_type_credit > > =cut > >-our $account_type = { >+our $account_type_credit = { > 'credit' => 'C', > 'forgiven' => 'FOR', > 'lost_item_return' => 'CR', >@@ -570,8 +708,26 @@ our $account_type = { > 'writeoff' => 'W' > }; > >-=head1 AUTHOR >+=head3 $account_type_debit >+ >+=cut >+ >+our $account_type_debit = { >+ 'fine' => 'FU', >+ 'lost_item' => 'L', >+ 'new_card' => 'N', >+ 'account' => 'A', >+ 'sundry' => 'M', >+ 'processing' => 'PF', >+ 'rent' => 'R', >+ 'reserve' => 'Res', >+ 'overdue' => 'O' >+}; >+ >+=head1 AUTHORS > > Kyle M Hall <kyle.m.hall@gmail.com> >+Tomás Cohen Arazi <tomascohen@gmail.com> >+Martin Renvoize <martin.renvoize@ptfs-europe.com> > > =cut >diff --git a/Koha/Exceptions/Account.pm b/Koha/Exceptions/Account.pm >index 5cafe5f9ab..7413c0dcbc 100644 >--- a/Koha/Exceptions/Account.pm >+++ b/Koha/Exceptions/Account.pm >@@ -33,6 +33,14 @@ use Exception::Class ( > 'Koha::Exceptions::Account::NoAvailableCredit' => { > isa => 'Koha::Exceptions::Account', > description => 'No outstanding credit' >+ }, >+ 'Koha::Exceptions::Account::AmountNotPositive' => { >+ isa => 'Koha::Exceptions::Account', >+ description => 'Amount should be a positive decimal' >+ }, >+ 'Koha::Exceptions::Account::UnrecognisedType' => { >+ isa => 'Koha::Exceptions::Account', >+ description => 'Account type was not recognised' > } > ); > >@@ -61,6 +69,15 @@ debit and it isn't. > Exception to be used when a credit has no amount outstanding and is required > to be applied to outstanding debits. > >+=head2 Koha::Exceptions::Account::AmountNotPositive >+ >+Exception to be used when a passed credit or debit amount is not a positive >+decimal value. >+ >+=head2 Koha::Exceptions::Account::UnrecognisedType >+ >+Exception to be used when a passed credit or debit is not of a recognised type. >+ > =cut > > 1; >-- >2.19.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 21002
:
81614
|
81620
|
81880
|
82772
|
82773
|
82785
|
82786
|
83009
|
83010
|
83086
|
83087
|
83099
|
83100
|
83228
|
83229
|
83273
|
83274
|
83706
|
83707