From d2c555bb32c7b29b9896e6751ac665076317c3ee Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 15 Feb 2017 16:24:57 +0000 Subject: [PATCH] Bug 14826: Add offset for rental fees Signed-off-by: Josef Moravec Signed-off-by: Tomas Cohen Arazi Signed-off-by: Jonathan Druart --- C4/Circulation.pm | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 9aee06efd9..3572718d31 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -3184,19 +3184,33 @@ sub _get_discount_from_rule { sub AddIssuingCharge { my ( $itemnumber, $borrowernumber, $charge ) = @_; - my $dbh = C4::Context->dbh; - my $nextaccntno = getnextacctno( $borrowernumber ); - my $manager_id = 0; + + my $nextaccntno = getnextacctno($borrowernumber); + + my $manager_id = 0; $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; - my $query =" - INSERT INTO accountlines - (borrowernumber, itemnumber, accountno, - date, amount, description, accounttype, - amountoutstanding, manager_id) - VALUES (?, ?, ?,now(), ?, 'Rental', 'Rent',?,?) - "; - my $sth = $dbh->prepare($query); - $sth->execute( $borrowernumber, $itemnumber, $nextaccntno, $charge, $charge, $manager_id ); + + my $accountline = Koha::Account::Line->new( + { + borrowernumber => $borrowernumber, + itemnumber => $itemnumber, + accountno => $nextaccntno, + amount => $charge, + amountoutstanding => $charge, + manager_id => $manager_id, + description => 'Rental', + accounttype => 'Rent', + date => \'NOW()', + } + )->store(); + + Koha::Account::Offset->new( + { + debit_id => $accountline->id, + type => 'Rental Fee', + amount => $charge, + } + )->store(); } =head2 GetTransfers -- 2.39.5