From 1b0d35fa162f66639b0926a35e972e03facb75d0 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 11 Mar 2013 13:52:23 -0400 Subject: [PATCH] Bug 7560 - SIP Self Checkout Ignoring Fines Thresholds for Not Being able to Check Out Books - QA Followup 2 --- C4/Accounts.pm | 108 ++++++++++++++++--------------- C4/ILSDI/Services.pm | 2 +- circ/stats.pl | 2 +- reports/stats.print.pl | 4 +- reports/stats.screen.pl | 8 +- t/db_dependent/lib/KohaTest/Accounts.pm | 6 +- 6 files changed, 68 insertions(+), 62 deletions(-) diff --git a/C4/Accounts.pm b/C4/Accounts.pm index 8b293d8..b7fe39b 100644 --- a/C4/Accounts.pm +++ b/C4/Accounts.pm @@ -38,10 +38,10 @@ BEGIN { &manualinvoice &getnextacctno &reconcileaccount - &getcharges + &GetCharges &ModNote - &getcredits - &getrefunds + &GetCredits + &GetRefunds &chargelostitem &ReversePayment &makepartialpayment @@ -585,21 +585,24 @@ sub refund { return ($amountleft); } -sub getcharges { - my ( $borrowerno, $timestamp, $accountno ) = @_; - my $dbh = C4::Context->dbh; - my $timestamp2 = $timestamp - 1; - my $query = ""; - my $sth = $dbh->prepare( - "SELECT * FROM accountlines WHERE borrowernumber=? AND accountno = ?" - ); - $sth->execute( $borrowerno, $accountno ); - - my @results; - while ( my $data = $sth->fetchrow_hashref ) { - push @results,$data; - } - return (@results); +sub GetCharges { + my ( $borrowerno, $timestamp, $accountno ) = @_; + + my $dbh = C4::Context->dbh; + + my $timestamp2 = $timestamp - 1; + + my $sth = $dbh->prepare(" + SELECT * + FROM accountlines + WHERE borrowernumber = ? + AND accountno = ? + "); + $sth->execute( $borrowerno, $accountno ); + + my $results = $sth->fetchall_arrayref({}); + + return @$results; } sub ModNote { @@ -609,45 +612,48 @@ sub ModNote { $sth->execute( $note, $accountlines_id ); } -sub getcredits { - my ( $date, $date2 ) = @_; - my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare( - "SELECT * FROM accountlines,borrowers - WHERE amount < 0 AND accounttype <> 'Pay' AND accountlines.borrowernumber = borrowers.borrowernumber - AND timestamp >=TIMESTAMP(?) AND timestamp < TIMESTAMP(?)" - ); - - $sth->execute( $date, $date2 ); - my @results; - while ( my $data = $sth->fetchrow_hashref ) { - $data->{'date'} = $data->{'timestamp'}; - push @results,$data; - } - return (@results); +sub GetCredits { + my ( $date, $date2 ) = @_; + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare(" + SELECT * + FROM accountlines, + borrowers + WHERE amount < 0 + AND accounttype <> 'Pay' + AND accountlines.borrowernumber = borrowers.borrowernumber + AND TIMESTAMP >= TIMESTAMP(?) + AND TIMESTAMP < TIMESTAMP(?) + "); + + $sth->execute( $date, $date2 ); + + my $results = $sth->fetchall_arrayref({}); + + return @$results; } -sub getrefunds { - my ( $date, $date2 ) = @_; - my $dbh = C4::Context->dbh; - - my $sth = $dbh->prepare( - "SELECT *,timestamp AS datetime - FROM accountlines,borrowers - WHERE (accounttype = 'REF' - AND accountlines.borrowernumber = borrowers.borrowernumber - AND date >=? AND date dbh; + my $sth = $dbh->prepare(" + SELECT *, + TIMESTAMP AS datetime + FROM accountlines, + borrowers + WHERE accounttype = 'REF' + AND accountlines.borrowernumber = borrowers.borrowernumber + AND date >= ? + AND date < ? + "); $sth->execute( $date, $date2 ); - my @results; - while ( my $data = $sth->fetchrow_hashref ) { - push @results,$data; - - } - return (@results); + my $results = $sth->fetchall_arrayref({}); + + return @$results; } sub ReversePayment { diff --git a/C4/ILSDI/Services.pm b/C4/ILSDI/Services.pm index 68cbdb3..c58eadf 100644 --- a/C4/ILSDI/Services.pm +++ b/C4/ILSDI/Services.pm @@ -392,7 +392,7 @@ sub GetPatronInfo { # Fines management if ( $cgi->param('show_fines') eq "1" ) { my @charges; - for ( my $i = 1 ; my @charge = getcharges( $borrowernumber, undef, $i ) ; $i++ ) { + for ( my $i = 1 ; my @charge = GetCharges( $borrowernumber, undef, $i ) ; $i++ ) { push( @charges, @charge ); } $borrower->{'fines'}->{'fine'} = \@charges; diff --git a/circ/stats.pl b/circ/stats.pl index 558a985..889c1f4 100755 --- a/circ/stats.pl +++ b/circ/stats.pl @@ -96,7 +96,7 @@ while ( $i < $count ) { my @temp = split(/ /, $payments[$i]{'datetime'}); my $date = $temp[0]; my @charges = - getcharges( $payments[$i]{'borrowernumber'}, $payments[$i]{'timestamp'} ); + GetCharges( $payments[$i]{'borrowernumber'}, $payments[$i]{'timestamp'} ); my $count = @charges; my $temptotalf = 0; my $temptotalr = 0; diff --git a/reports/stats.print.pl b/reports/stats.print.pl index 066aafa..aced5f9 100755 --- a/reports/stats.print.pl +++ b/reports/stats.print.pl @@ -86,7 +86,7 @@ while ($i<$count ){ my @charges; if ($payments[$i]{'type'} ne 'writeoff'){ # lets ignore writeoff payments!. - @charges=getcharges($payments[$i]{'borrowernumber'}, $payments[$i]{'timestamp'}, $payments[$i]{'proccode'}); + @charges=GetCharges($payments[$i]{'borrowernumber'}, $payments[$i]{'timestamp'}, $payments[$i]{'proccode'}); $totalcharges++; $count=@charges; @@ -124,7 +124,7 @@ while ($i<$count ){ } #get credits and append to the bottom of payments -my @credits=getcredits($date,$date2); +my @credits=GetCredits($date,$date2); my $count=@credits; my $i=0; diff --git a/reports/stats.screen.pl b/reports/stats.screen.pl index 16b8f8a..0978ac8 100755 --- a/reports/stats.screen.pl +++ b/reports/stats.screen.pl @@ -77,7 +77,7 @@ foreach my $payment (@payments) { my @charges; if ( $payment->{'type'} ne 'writeoff' ) { - @charges = getcharges( + @charges = GetCharges( $payment->{'borrowernumber'}, $payment->{'timestamp'}, $payment->{'proccode'} @@ -124,7 +124,7 @@ foreach my $payment (@payments) { } #get credits and append to the bottom of payments -my @credits = getcredits( $date, $date2 ); +my @credits = GetCredits( $date, $date2 ); my $count = @credits; my $i = 0; @@ -133,7 +133,7 @@ while ( $i < $count ) { my %rows2 = ( creditbranch => $credits[$i]->{'branchcode'}, - creditdate => $credits[$i]->{'date'}, + creditdate => $credits[$i]->{'timestamp'}, creditsurname => $credits[$i]->{'surname'}, creditfirstname => $credits[$i]->{'firstname'}, creditdescription => $credits[$i]->{'description'}, @@ -151,7 +151,7 @@ $totalcredits = substr( $totalcredits, 1 ); my $totalrefunds = 0; my @loop3; -my @refunds = getrefunds( $date, $date2 ); +my @refunds = GetRefunds( $date, $date2 ); $count = @refunds; $i = 0; diff --git a/t/db_dependent/lib/KohaTest/Accounts.pm b/t/db_dependent/lib/KohaTest/Accounts.pm index ac3a78e..766afe9 100644 --- a/t/db_dependent/lib/KohaTest/Accounts.pm +++ b/t/db_dependent/lib/KohaTest/Accounts.pm @@ -18,9 +18,9 @@ sub methods : Test( 1 ) { manualinvoice fixcredit refund - getcharges - getcredits - getrefunds + GetCharges + GetCredits + GetRefunds ); # removed fixaccounts (unused by codebase) can_ok( $self->testing_class, @methods ); -- 1.7.2.5