Bugzilla – Attachment 81879 Details for
Bug 21727
Add Koha::Account::Line->adjust
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 21727: Add ->adjust to Koha::Account::Line
Bug-21727-Add--adjust-to-KohaAccountLine.patch (text/plain), 4.04 KB, created by
Martin Renvoize (ashimema)
on 2018-11-02 10:46:29 UTC
(
hide
)
Description:
Bug 21727: Add ->adjust to Koha::Account::Line
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2018-11-02 10:46:29 UTC
Size:
4.04 KB
patch
obsolete
>From 7d3187f6ed7bcdb0fe00745f030c8c5238f83264 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Thu, 1 Nov 2018 17:12:14 +0000 >Subject: [PATCH] Bug 21727: Add ->adjust to Koha::Account::Line > >--- > Koha/Account/Line.pm | 111 +++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 111 insertions(+) > >diff --git a/Koha/Account/Line.pm b/Koha/Account/Line.pm >index 3573e604e6..c1ccdb681b 100644 >--- a/Koha/Account/Line.pm >+++ b/Koha/Account/Line.pm >@@ -205,6 +205,95 @@ sub apply { > return $available_credit; > } > >+=head3 adjust >+ >+This method allows updating a debit or credit on a patron's account >+ >+my $account_line = Koha::Account->find({ accountlines_id => $line_id })->update( >+ { >+ amount => $amount, >+ type => $update_type, >+ } >+); >+ >+$update_type can be any of: >+ - fine_increment >+ >+=cut >+ >+sub adjust { >+ my ( $self, $params ) = @_; >+ >+ my $amount = $params->{amount}; >+ my $update_type = $params->{type}; >+ >+ unless ( exists($Koha::Account::Line::offset_type->{$update_type}) ) { >+ Koha::Exceptions::Account::UnrecognisedType->throw( >+ error => 'Update type not recognised' >+ ); >+ } >+ >+ my $account_type = $self->accounttype; >+ unless ( $Koha::Account::Line::allowed_update->{$update_type} eq $account_type ) { >+ Koha::Exceptions::Account::UnrecognisedType->throw( >+ error => 'Update type not allowed on this accounttype' >+ ); >+ } >+ >+ my $schema = Koha::Database->new->schema; >+ >+ $schema->txn_do( >+ sub { >+ >+ my $amount_before = $self->amount; >+ my $amount_outstanding_before = $self->amountoutstanding; >+ my $difference = $amount - $amount_before; >+ my $new_outstanding = $amount_outstanding_before + $difference; >+ >+ # Update the account line >+ $self->set( >+ { >+ date => \'NOW()', >+ amount => $amount, >+ amountoutstanding => $new_outstanding, >+ ( $update_type eq 'fine_increment' ? ( lastincrement => $difference ) : ()), >+ } >+ )->store(); >+ >+ # Record the account offset >+ my $account_offset = Koha::Account::Offset->new( >+ { >+ debit_id => $self->id, >+ type => $Koha::Account::Line::offset_type->{$update_type}, >+ amount => $difference >+ } >+ )->store(); >+ >+ if ( C4::Context->preference("FinesLog") ) { >+ logaction( >+ "FINES", 'UPDATE', #undef becomes UPDATE in UpdateFine >+ $self->borrowernumber, >+ Dumper( >+ { action => $update_type, >+ borrowernumber => $self->borrowernumber, >+ accountno => $self->accountno, >+ amount => $amount, >+ description => undef, >+ amountoutstanding => $new_outstanding, >+ accounttype => $self->accounttype, >+ note => undef, >+ itemnumber => $self->itemnumber, >+ manager_id => undef, >+ } >+ ) >+ ) if ( $update_type eq 'fine_increment' ); >+ } >+ } >+ ); >+ >+ return $self; >+} >+ > =head3 is_credit > > my $bool = $line->is_credit; >@@ -242,3 +331,25 @@ sub _type { > } > > 1; >+ >+=head2 Name mappings >+ >+=head3 $offset_type >+ >+=cut >+ >+our $offset_type = { 'fine_increment' => 'Fine Update', }; >+ >+=head3 $allowed_update >+ >+=cut >+ >+our $allowed_update = { 'fine_increment' => 'FU', }; >+ >+=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 >-- >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 21727
:
81879
|
82777
|
82778
|
83054
|
83055
|
83056
|
83058
|
83088
|
83089
|
83090
|
83091
|
83095
|
83096
|
83097
|
83098
|
83101
|
83117
|
83118
|
83121
|
83122
|
83818