From 2532c0a3fad64109f77889c590a74f2c82a9a13a Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 18 Jul 2018 11:36:36 +0000 Subject: [PATCH] Bug 12001: [17.11.X] Remove simple calls to GetMemberAccountRecords I chose not to backport the main patchset as it was big and didn't apply clean, however, this problem seems to be an issue in 17.11.x This patchset removes the calls where only the total is fetched/used Please consider for backport To test: 1 - Have a patron with some fines 2 - View these pages and confirm fine amounts display: circ/circulation.pl opac/opac-main.pl opac/opac-reserve.pl opac/opac-user.pl reserve/request.pl 3 - Apply patch 4 - View pages again, confirm fines display correctly and no errors --- C4/Members.pm | 8 ++++++-- Koha/Account.pm | 38 ++++++++++++++++++++++++++++++++++++++ circ/circulation.pl | 2 +- opac/opac-main.pl | 4 +++- opac/opac-reserve.pl | 3 ++- opac/opac-user.pl | 4 +++- reserve/request.pl | 2 +- 7 files changed, 54 insertions(+), 7 deletions(-) diff --git a/C4/Members.pm b/C4/Members.pm index 49c559c9e7..62bd8170b2 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -181,7 +181,11 @@ sub patronflags { my %flags; my ( $patroninformation) = @_; my $dbh=C4::Context->dbh; - my ($balance, $owing) = GetMemberAccountBalance( $patroninformation->{'borrowernumber'}); + + my $patron = Koha::Patrons->find( $patroninformation->{borrowernumber} ); + my $account = $patron->account; + my $owing = $account->non_issues_charges; + if ( $owing > 0 ) { my %flaginfo; my $noissuescharge = C4::Context->preference("noissuescharge") || 5; @@ -192,7 +196,7 @@ sub patronflags { } $flags{'CHARGES'} = \%flaginfo; } - elsif ( $balance < 0 ) { + elsif ( ( my $balance = $account->balance ) < 0 ) { my %flaginfo; $flaginfo{'message'} = sprintf 'Patron has credit of %.02f', -$balance; $flaginfo{'amount'} = sprintf "%.02f", $balance; diff --git a/Koha/Account.pm b/Koha/Account.pm index ed1fd3cea7..ea7a5975d1 100644 --- a/Koha/Account.pm +++ b/Koha/Account.pm @@ -21,6 +21,7 @@ use Modern::Perl; use Carp; use Data::Dumper; +use List::MoreUtils qw(uniq); use C4::Log qw( logaction ); use C4::Stats qw( UpdateStats ); @@ -284,6 +285,43 @@ sub balance { : 0; } +sub non_issues_charges { + my ($self) = @_; + + # FIXME REMOVE And add a warning in the about page + update DB if length(MANUAL_INV) > 5 + my $ACCOUNT_TYPE_LENGTH = 5; # this is plain ridiculous... + + my @not_fines; + push @not_fines, 'Res' + unless C4::Context->preference('HoldsInNoissuesCharge'); + push @not_fines, 'Rent' + unless C4::Context->preference('RentalsInNoissuesCharge'); + unless ( C4::Context->preference('ManInvInNoissuesCharge') ) { + my $dbh = C4::Context->dbh; + push @not_fines, + @{ + $dbh->selectcol_arrayref(q| + SELECT authorised_value FROM authorised_values WHERE category = 'MANUAL_INV' + |) + }; + } + @not_fines = map { substr( $_, 0, $ACCOUNT_TYPE_LENGTH ) } uniq(@not_fines); + + my $non_issues_charges = Koha::Account::Lines->search( + { + borrowernumber => $self->{patron_id}, + accounttype => { -not_in => \@not_fines } + }, + { + select => [ { sum => 'amountoutstanding' } ], + as => ['non_issues_charges'], + } + ); + return $non_issues_charges->count + ? $non_issues_charges->next->get_column('non_issues_charges') + 0 + : 0; +} + 1; =head1 AUTHOR diff --git a/circ/circulation.pl b/circ/circulation.pl index 74ce477d1f..1326246027 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -543,7 +543,7 @@ foreach my $flag ( sort keys %$flags ) { my $amountold = $flags ? $flags->{'CHARGES'}->{'message'} || 0 : 0; $amountold =~ s/^.*\$//; # remove upto the $, if any -my ( $total, $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber ); +my $total = $patron ? $patron->account->balance : 0; if ( $patron && $patron->category->category_type eq 'C') { my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']}); diff --git a/opac/opac-main.pl b/opac/opac-main.pl index a397627059..37b9292ff3 100755 --- a/opac/opac-main.pl +++ b/opac/opac-main.pl @@ -29,6 +29,7 @@ use C4::Members; use C4::Overdues; use Koha::Checkouts; use Koha::Holds; +use Koha::Patrons; my $input = new CGI; my $dbh = C4::Context->dbh; @@ -72,7 +73,8 @@ if ( defined $borrowernumber ){ my ( $overdues_count, $overdues ) = checkoverdues($borrowernumber); my $holds_pending = Koha::Holds->search({ borrowernumber => $borrowernumber, found => undef })->count; my $holds_waiting = Koha::Holds->search({ borrowernumber => $borrowernumber })->waiting->count; - my ( $total , $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber ); + my $patron = Koha::Patrons->find( $borrowernumber ); + my $total = $patron ? $patron->account->balance : 0; if ( $checkouts > 0 || $overdues_count > 0 || $holds_pending > 0 || $holds_waiting > 0 || $total > 0 ) { $template->param( dashboard_info => 1 ); diff --git a/opac/opac-reserve.pl b/opac/opac-reserve.pl index 95204b3f5c..68128de76f 100755 --- a/opac/opac-reserve.pl +++ b/opac/opac-reserve.pl @@ -329,7 +329,8 @@ if ( $query->param('place_reserve') ) { my $noreserves = 0; my $maxoutstanding = C4::Context->preference("maxoutstanding"); $template->param( noreserve => 1 ) unless $maxoutstanding; -my ( $amountoutstanding ) = GetMemberAccountRecords($borrowernumber); +my $amountoutstanding = $patron ? $patron->account->balance : 0; + if ( $amountoutstanding && ($amountoutstanding > $maxoutstanding) ) { my $amount = sprintf "%.02f", $amountoutstanding; $template->param( message => 1 ); diff --git a/opac/opac-user.pl b/opac/opac-user.pl index 55c04a3a78..b051ecdbaa 100755 --- a/opac/opac-user.pl +++ b/opac/opac-user.pl @@ -116,7 +116,9 @@ if ( $userdebarred || $borr->{'gonenoaddress'} || $borr->{'lost'} ) { $canrenew = 0; } -my ( $amountoutstanding ) = GetMemberAccountRecords($borrowernumber); +my $patron = Koha::Patrons->find( $borrowernumber ); +my $amountoutstanding = $patron ? $patron->account->balance : 0; + if ( $amountoutstanding > 5 ) { $borr->{'amountoverfive'} = 1; } diff --git a/reserve/request.pl b/reserve/request.pl index 8cedeac598..2ea19ba816 100755 --- a/reserve/request.pl +++ b/reserve/request.pl @@ -198,7 +198,7 @@ if ($borrowernumber_hold && !$action) { messages => $messages, warnings => $warnings, restricted => $is_debarred, - amount_outstanding => GetMemberAccountRecords($patron->borrowernumber), + amount_outstanding => $patron->account->balance, ); } -- 2.17.1