[Patches] [PATCH] bug_7243: C4::Members::GetMemberAccountRecords() changes

koha-patchbot at kohaaloha.com koha-patchbot at kohaaloha.com
Tue Dec 13 22:05:25 NZDT 2011


From: Srdjan Jankovic <srdjan at catalyst.net.nz>
Date: Fri, 18 Nov 2011 18:52:02 +1300
Subject: [PATCH] bug_7243: C4::Members::GetMemberAccountRecords() changes

Input params: $borrowernumber, $fines_only
If $fines_only is true, discard assount records of type 'Rent', 'Res'
and authorised_values MANUAL_INV
Dropped input param $date, it is not used

Set $fines_only to true when calling GetMemberAccountRecords() from
C4::Circulation::CanBookBeIssued() and C4::Members::patronflags(). That
way only fines decide whether an item can be issued, and not other
non-fine charges

Signed-off-by: Duncan Tyler <duncan at duncan-SoT.wgtn.cat-it.co.nz>
---
 C4/Circulation.pm   |    2 +-
 C4/Members.pm       |   20 ++++++++++++--------
 circ/circulation.pl |   13 ++++++-------
 3 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/C4/Circulation.pm b/C4/Circulation.pm
index 3d63224..f900744 100644
--- a/C4/Circulation.pm
+++ b/C4/Circulation.pm
@@ -729,7 +729,7 @@ sub CanBookBeIssued {
 
     # DEBTS
     my ($amount) =
-      C4::Members::GetMemberAccountRecords( $borrower->{'borrowernumber'}, '' && $duedate->output('iso') );
+      C4::Members::GetMemberAccountRecords( $borrower->{'borrowernumber'}, 'FINES ONLY' );
     my $amountlimit = C4::Context->preference("noissuescharge");
     my $allowfineoverride = C4::Context->preference("AllowFineOverride");
     my $allfinesneedoverride = C4::Context->preference("AllFinesNeedOverride");
diff --git a/C4/Members.pm b/C4/Members.pm
index 8bd7b47..f273c7d 100644
--- a/C4/Members.pm
+++ b/C4/Members.pm
@@ -420,7 +420,7 @@ sub patronflags {
     my %flags;
     my ( $patroninformation) = @_;
     my $dbh=C4::Context->dbh;
-    my ($amount) = GetMemberAccountRecords( $patroninformation->{'borrowernumber'});
+    my ($amount) = GetMemberAccountRecords( $patroninformation->{'borrowernumber'}, 'FINES ONLY');
     if ( $amount > 0 ) {
         my %flaginfo;
         my $noissuescharge = C4::Context->preference("noissuescharge") || 5;
@@ -1094,7 +1094,7 @@ sub GetAllIssues {
 
 =head2 GetMemberAccountRecords
 
-  ($total, $acctlines, $count) = &GetMemberAccountRecords($borrowernumber);
+  ($total, $acctlines, $count) = &GetMemberAccountRecords($borrowernumber, $fines_only);
 
 Looks up accounting data for the patron with the given borrowernumber.
 
@@ -1104,11 +1104,13 @@ keys are the fields of the C<accountlines> table in the Koha database.
 C<$count> is the number of elements in C<$acctlines>. C<$total> is the
 total amount outstanding for all of the account lines.
 
+If C<$fines_only> flag is set to true, only fines are taken in account
+
 =cut
 
 #'
 sub GetMemberAccountRecords {
-    my ($borrowernumber,$date) = @_;
+    my ($borrowernumber, $fines_only) = @_;
     my $dbh = C4::Context->dbh;
     my @acctlines;
     my $numlines = 0;
@@ -1116,14 +1118,16 @@ sub GetMemberAccountRecords {
                         SELECT * 
                         FROM accountlines 
                         WHERE borrowernumber=?);
-    my @bind = ($borrowernumber);
-    if ($date && $date ne ''){
-            $strsth.=" AND date < ? ";
-            push(@bind,$date);
+    if ($fines_only) {
+        $strsth .= " AND accounttype NOT IN (
+                         'Res',
+                         'Rent',
+                         (SELECT authorised_value FROM authorised_values WHERE category = 'MANUAL_INV')
+                     )";
     }
     $strsth.=" ORDER BY date desc,timestamp DESC";
     my $sth= $dbh->prepare( $strsth );
-    $sth->execute( @bind );
+    $sth->execute( $borrowernumber );
     my $total = 0;
     while ( my $data = $sth->fetchrow_hashref ) {
         if ( $data->{itemnumber} ) {
diff --git a/circ/circulation.pl b/circ/circulation.pl
index fa043dd..b6fbbea 100755
--- a/circ/circulation.pl
+++ b/circ/circulation.pl
@@ -188,8 +188,7 @@ if ( $print eq 'yes' && $borrowernumber ne '' ) {
 my $borrowerslist;
 my $message;
 if ($findborrower) {
-    my $borrowers = Search($findborrower, 'cardnumber');
-    my @borrowers = @$borrowers;
+    my $borrowers = Search($findborrower, 'cardnumber') || [];
     if (C4::Context->preference("AddPatronLists")) {
         $template->param(
             "AddPatronLists_".C4::Context->preference("AddPatronLists")=> "1",
@@ -200,17 +199,17 @@ if ($findborrower) {
             $template->param(categories=>$categories);
         }
     }
-    if ( $#borrowers == -1 ) {
+    if ( @$borrowers == 0 ) {
         $query->param( 'findborrower', '' );
         $message = "'$findborrower'";
     }
-    elsif ( $#borrowers == 0 ) {
-        $query->param( 'borrowernumber', $borrowers[0]->{'borrowernumber'} );
+    elsif ( @$borrowers == 1 ) {
+        $borrowernumber = $borrowers->[0]->{'borrowernumber'};
+        $query->param( 'borrowernumber', $borrowernumber );
         $query->param( 'barcode',           '' );
-        $borrowernumber = $borrowers[0]->{'borrowernumber'};
     }
     else {
-        $borrowerslist = \@borrowers;
+        $borrowerslist = $borrowers;
     }
 }
 
-- 
1.7.5.4




More information about the Patches mailing list