Bugzilla – Attachment 65771 Details for
Bug 19066
Add branchcode to accountlines
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 19066 - Add branchcode to accountlines
Bug-19066---Add-branchcode-to-accountlines.patch (text/plain), 15.82 KB, created by
Kyle M Hall (khall)
on 2017-08-09 17:04:36 UTC
(
hide
)
Description:
Bug 19066 - Add branchcode to accountlines
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2017-08-09 17:04:36 UTC
Size:
15.82 KB
patch
obsolete
>From f15ee8a5349a95d87f4d3319580243402b521a66 Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Wed, 9 Aug 2017 16:55:56 +0000 >Subject: [PATCH] Bug 19066 - Add branchcode to accountlines > >For the purposes of statistics, it appears that it would help many >libraries to have branchcode recorded in the accountlines table. For >payments, the field would contain the code for the branch the payment >was made at. For manual invoices, it would be the code of the library >that created the invoice. > >Test Plan: >1) Apply this patch set >2) Create and pay some fees >3) Note the branchcode for those fees and payments is set > to your logged in branch >--- > C4/Accounts.pm | 55 +++++++++++++++++++------------ > C4/Circulation.pm | 83 ++++++++++++++++++++++++++++++++--------------- > C4/Reserves.pm | 25 ++++++++++---- > Koha/Account.pm | 6 ++-- > t/db_dependent/Accounts.t | 51 +++++++++++++++++++++++++++-- > 5 files changed, 163 insertions(+), 57 deletions(-) > >diff --git a/C4/Accounts.pm b/C4/Accounts.pm >index c7b8191..06d8c3a 100644 >--- a/C4/Accounts.pm >+++ b/C4/Accounts.pm >@@ -27,6 +27,7 @@ use C4::Circulation qw(ReturnLostItem); > use C4::Log qw(logaction); > use Koha::Account; > use Koha::Account::Lines; >+use Koha::DateUtils qw(dt_from_string); > > use Data::Dumper qw(Dumper); > >@@ -136,15 +137,26 @@ sub chargelostitem{ > unless ($existing_charge_hashref) { > my $manager_id = 0; > $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; >+ my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef; >+ > # This item is on issue ... add replacement cost to the borrower's record and mark it returned > # Note that we add this to the account even if there's no replacement price, allowing some other > # process (or person) to update it, since we don't handle any defaults for replacement prices. > my $accountno = getnextacctno($borrowernumber); >- my $sth2=$dbh->prepare("INSERT INTO accountlines >- (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber,manager_id) >- VALUES (?,?,now(),?,?,'L',?,?,?)"); >- $sth2->execute($borrowernumber,$accountno,$amount, >- $description,$amount,$itemnumber,$manager_id); >+ Koha::Account::Line->new( >+ { >+ borrowernumber => $borrowernumber, >+ accountno => $accountno, >+ date => dt_from_string(), >+ amount => $amount, >+ description => $description, >+ accounttype => 'L', >+ amountoutstanding => $amount, >+ itemnumber => $itemnumber, >+ manager_id => $manager_id, >+ branchcode => $branchcode, >+ } >+ )->store(); > > if ( C4::Context->preference("FinesLog") ) { > logaction("FINES", 'CREATE', $borrowernumber, Dumper({ >@@ -208,21 +220,24 @@ sub manualinvoice { > $notifyid = 1; > } > >- if ( $itemnum ) { >- $desc .= ' ' . $itemnum; >- my $sth = $dbh->prepare( >- 'INSERT INTO accountlines >- (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding, itemnumber,notify_id, note, manager_id) >- VALUES (?, ?, now(), ?,?, ?,?,?,?,?,?)'); >- $sth->execute($borrowernumber, $accountno, $amount, $desc, $type, $amountleft, $itemnum,$notifyid, $note, $manager_id) || return $sth->errstr; >- } else { >- my $sth=$dbh->prepare("INSERT INTO accountlines >- (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding,notify_id, note, manager_id) >- VALUES (?, ?, now(), ?, ?, ?, ?,?,?,?)" >- ); >- $sth->execute( $borrowernumber, $accountno, $amount, $desc, $type, >- $amountleft, $notifyid, $note, $manager_id ); >- } >+ my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef; >+ >+ Koha::Account::Line->new( >+ { >+ borrowernumber => $borrowernumber, >+ accountno => $accountno, >+ date => dt_from_string(), >+ amount => $amount, >+ description => $desc, >+ accounttype => $type, >+ amountoutstanding => $amountleft, >+ itemnumber => $itemnum, >+ notify_id => $notifyid, >+ note => $note, >+ manager_id => $manager_id, >+ branchcode => $branchcode, >+ } >+ )->store(); > > if ( C4::Context->preference("FinesLog") ) { > logaction("FINES", 'CREATE',$borrowernumber,Dumper({ >diff --git a/C4/Circulation.pm b/C4/Circulation.pm >index fba723f..87e615f 100644 >--- a/C4/Circulation.pm >+++ b/C4/Circulation.pm >@@ -50,6 +50,7 @@ use Koha::Patrons; > use Koha::Patron::Debarments; > use Koha::Database; > use Koha::Libraries; >+use Koha::Account::Lines; > use Koha::Holds; > use Koha::RefundLostItemFeeRule; > use Koha::RefundLostItemFeeRules; >@@ -2395,7 +2396,7 @@ sub _FixAccountForLostAndReturned { > WHERE (accountlines_id = ?)"); > $usth->execute($data->{'accountlines_id'}); # We might be adjusting an account for some OTHER borrowernumber now. Not the one we passed in. > #check if any credit is left if so writeoff other accounts >- my $nextaccntno = getnextacctno($data->{'borrowernumber'}); >+ my $nextaccntno = C4::Accounts::getnextacctno($data->{'borrowernumber'}); > $amountleft *= -1 if ($amountleft < 0); > if ($amountleft > 0) { > my $msth = $dbh->prepare("SELECT * FROM accountlines WHERE (borrowernumber = ?) >@@ -2425,11 +2426,24 @@ sub _FixAccountForLostAndReturned { > } > } > $amountleft *= -1 if ($amountleft > 0); >+ >+ my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef; >+ > my $desc = "Item Returned " . $item_id; >- $usth = $dbh->prepare("INSERT INTO accountlines >- (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding) >- VALUES (?,?,now(),?,?,'CR',?)"); >- $usth->execute($data->{'borrowernumber'},$nextaccntno,0-$amount,$desc,$amountleft); >+ >+ Koha::Account::Line->new( >+ { >+ borrowernumber => $data->{borrowernumber}, >+ accountno => $nextaccntno, >+ date => dt_from_string(), >+ amount => 0 - $amount, >+ description => $desc, >+ accounttype => 'CR', >+ amountoutstanding => $amountleft, >+ branchcode => $branchcode, >+ } >+ )->store(); >+ > if ($borrowernumber) { > # FIXME: same as query above. use 1 sth for both > $usth = $dbh->prepare("INSERT INTO accountoffsets >@@ -2858,18 +2872,26 @@ sub AddRenewal { > # Charge a new rental fee, if applicable? > my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber ); > if ( $charge > 0 ) { >- my $accountno = getnextacctno( $borrowernumber ); >+ my $accountno = C4::Accounts::getnextacctno( $borrowernumber ); > my $manager_id = 0; > $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; >- $sth = $dbh->prepare( >- "INSERT INTO accountlines >- (date, borrowernumber, accountno, amount, manager_id, >- description,accounttype, amountoutstanding, itemnumber) >- VALUES (now(),?,?,?,?,?,?,?,?)" >- ); >- $sth->execute( $borrowernumber, $accountno, $charge, $manager_id, >- "Renewal of Rental Item " . $biblio->title . " $item->{'barcode'}", >- 'Rent', $charge, $itemnumber ); >+ my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef; >+ Koha::Account::Line->new( >+ { >+ date => dt_from_string(), >+ borrowernumber => $borrowernumber, >+ accountno => $accountno, >+ amount => $charge, >+ manager_id => $manager_id, >+ accounttype => 'Rent', >+ amountoutstanding => $charge, >+ itemnumber => $itemnumber, >+ branchcode => $branchcode, >+ description => 'Renewal of Rental Item ' >+ . $biblio->title >+ . " $item->{'barcode'}", >+ } >+ )->store(); > } > > # Send a renewal slip according to checkout alert preferencei >@@ -3194,19 +3216,28 @@ sub _get_discount_from_rule { > > sub AddIssuingCharge { > my ( $itemnumber, $borrowernumber, $charge ) = @_; >- my $dbh = C4::Context->dbh; >- my $nextaccntno = getnextacctno( $borrowernumber ); >+ >+ 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 $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef; >+ >+ Koha::Account::Line->new( >+ { >+ date => dt_from_string(), >+ borrowernumber => $borrowernumber, >+ accountno => $nextaccntno, >+ amount => $charge, >+ manager_id => $manager_id, >+ accounttype => 'Rent', >+ amountoutstanding => $charge, >+ itemnumber => $itemnumber, >+ branchcode => $branchcode, >+ description => 'Rental', >+ } >+ )->store(); > } > > =head2 GetTransfers >diff --git a/C4/Reserves.pm b/C4/Reserves.pm >index 5098230..72ffeff 100644 >--- a/C4/Reserves.pm >+++ b/C4/Reserves.pm >@@ -48,6 +48,7 @@ use Koha::IssuingRules; > use Koha::Items; > use Koha::ItemTypes; > use Koha::Patrons; >+use Koha::Account::Lines; > > use List::MoreUtils qw( firstidx any ); > use Carp; >@@ -559,13 +560,23 @@ sub GetOtherReserves { > > sub ChargeReserveFee { > my ( $borrowernumber, $fee, $title ) = @_; >- return if !$fee || $fee==0; # the last test is needed to include 0.00 >- my $accquery = qq{ >-INSERT INTO accountlines ( borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding ) VALUES (?, ?, NOW(), ?, ?, 'Res', ?) >- }; >- my $dbh = C4::Context->dbh; >- my $nextacctno = &getnextacctno( $borrowernumber ); >- $dbh->do( $accquery, undef, ( $borrowernumber, $nextacctno, $fee, "Reserve Charge - $title", $fee ) ); >+ >+ return if !$fee || $fee == 0; # the last test is needed to include 0.00 >+ >+ my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef; >+ my $nextacctno = C4::Accounts::getnextacctno($borrowernumber); >+ >+ Koha::Account::Line->new( >+ { >+ borrowernumber => $borrowernumber, >+ accountno => $nextacctno, >+ date => dt_from_string(), >+ amount => $fee, >+ description => "Reserve Charge - $title", >+ accounttype => 'Res', >+ amountoutstanding => $fee, >+ } >+ )->store(); > } > > =head2 GetReserveFee >diff --git a/Koha/Account.pm b/Koha/Account.pm >index 9ec1c1b..4c45943 100644 >--- a/Koha/Account.pm >+++ b/Koha/Account.pm >@@ -68,6 +68,9 @@ sub pay { > my $library_id = $params->{library_id}; > my $lines = $params->{lines}; > my $type = $params->{type} || 'payment'; >+ my $branchcode = $params->{branchcode}; >+ >+ $library_id ||= C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef; > > my $userenv = C4::Context->userenv; > >@@ -191,12 +194,11 @@ sub pay { > accounttype => $account_type, > amountoutstanding => 0 - $balance_remaining, > manager_id => $manager_id, >+ branchcode => $library_id, > note => $note, > } > )->store(); > >- $library_id ||= $userenv ? $userenv->{'branch'} : undef; >- > UpdateStats( > { > branch => $library_id, >diff --git a/t/db_dependent/Accounts.t b/t/db_dependent/Accounts.t >index fcc63d3..1f7c5c5 100644 >--- a/t/db_dependent/Accounts.t >+++ b/t/db_dependent/Accounts.t >@@ -18,7 +18,7 @@ > > use Modern::Perl; > >-use Test::More tests => 22; >+use Test::More tests => 35; > use Test::MockModule; > use Test::Warn; > >@@ -70,6 +70,52 @@ $context->mock( 'userenv', sub { > branch => $branchcode, > }; > }); >+my $userenv_branchcode = $branchcode; >+ >+# Test chargelostitem >+my $item = $builder->build( { source => 'Item' } ); >+my $patron = $builder->build( { source => 'Borrower' } ); >+my $amount = '5.000000'; >+my $description = "Test fee!"; >+chargelostitem( $patron->{borrowernumber}, $item->{itemnumber}, $amount, $description ); >+my ($accountline) = Koha::Account::Lines->search( >+ { >+ borrowernumber => $patron->{borrowernumber} >+ } >+); >+is( $accountline->amount, $amount, 'Accountline amount set correctly for chargelostitem' ); >+is( $accountline->description, $description, 'Accountline description set correctly for chargelostitem' ); >+is( $accountline->branchcode, $branchcode, 'Accountline branchcode set correctly for chargelostitem' ); >+$dbh->do(q|DELETE FROM accountlines|); >+ >+# Test manualinvoice, reuse some of the vars from testing chargelostitem >+my $type = 'L'; >+my $note = 'Test note!'; >+manualinvoice( $patron->{borrowernumber}, $item->{itemnumber}, $description, $type, $amount, $note ); >+($accountline) = Koha::Account::Lines->search( >+ { >+ borrowernumber => $patron->{borrowernumber} >+ } >+); >+is( $accountline->accounttype, $type, 'Accountline type set correctly for manualinvoice' ); >+is( $accountline->amount, $amount, 'Accountline amount set correctly for manualinvoice' ); >+ok( $accountline->description =~ /^$description/, 'Accountline description set correctly for manualinvoice' ); >+is( $accountline->note, $note, 'Accountline note set correctly for manualinvoice' ); >+is( $accountline->branchcode, $branchcode, 'Accountline branchcode set correctly for manualinvoice' ); >+ >+# Test _FixAccountForLostAndReturned, use the accountline from the manualinvoice to test >+C4::Circulation::_FixAccountForLostAndReturned( $item->{itemnumber} ); >+my ( $accountline_fee, $accountline_payment ) = Koha::Account::Lines->search( >+ { >+ borrowernumber => $patron->{borrowernumber} >+ } >+); >+is( $accountline_fee->accounttype, 'LR', 'Lost item fee account type updated to LR' ); >+is( $accountline_fee->amountoutstanding, '0.000000', 'Lost item fee amount outstanding updated to 0' ); >+is( $accountline_payment->accounttype, 'CR', 'Lost item fee account type is CR' ); >+is( $accountline_payment->amount, "-$amount", 'Lost item refund amount is correct' ); >+is( $accountline_payment->branchcode, $branchcode, 'Lost item refund branchcode is set correctly' ); >+$dbh->do(q|DELETE FROM accountlines|); > > # Testing purge_zero_balance_fees > >@@ -135,7 +181,7 @@ $dbh->do(q|DELETE FROM accountlines|); > > subtest "Koha::Account::pay tests" => sub { > >- plan tests => 12; >+ plan tests => 13; > > # Create a borrower > my $categorycode = $builder->build({ source => 'Category' })->{ categorycode }; >@@ -255,6 +301,7 @@ subtest "Koha::Account::pay tests" => sub { > is( $payment->amount(), '-42.000000', "Payment paid the specified fine" ); > $line3 = Koha::Account::Lines->find( $line3->id ); > is( $line3->amountoutstanding, '0.000000', "Specified fine is paid" ); >+ is( $payment->branchcode, $userenv_branchcode, 'Branchcode set correctly' ); > }; > > subtest "Koha::Account::pay particular line tests" => sub { >-- >2.10.2
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 19066
:
65769
|
65770
|
65771
|
67756
|
67757
|
71153
|
71154
|
71155
|
73185
|
73186
|
73187
|
73595
|
77281
|
77282
|
77283
|
78900
|
78901
|
81144
|
81145
|
81146
|
81253
|
81254
|
81255
|
81684
|
81912
|
81918
|
82047
|
82048
|
82084
|
82086
|
82087
|
82469
|
82470
|
82471
|
82473
|
82474
|
82475
|
82476
|
82477
|
82478
|
83067
|
83068
|
83069
|
83070
|
83071
|
83072
|
83073
|
83074
|
83075
|
83076
|
83077
|
83078
|
83079
|
83080
|
83081
|
83082
|
83083
|
83084
|
83275
|
83519
|
83520
|
83521
|
83522
|
83523
|
83524
|
83525
|
83526
|
83527
|
83528
|
83628