From 8191a3b1a4fb5642005c72ed9b42924d65bfbc18 Mon Sep 17 00:00:00 2001
From: Kyle M Hall <kyle@bywatersolutions.com>
Date: Thu, 5 Mar 2015 11:46:37 +0100
Subject: [PATCH] Bug 12768 [QA Followup] - Fix unit tests

Signed-off-by: Eivin Giske Skaaren <eivin@sysmystic.com>
---
 C4/Accounts.pm                              |   24 ++++++++++++++++--------
 t/db_dependent/Circulation/Chargelostitem.t |    6 +++---
 2 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/C4/Accounts.pm b/C4/Accounts.pm
index 614bf8e..6540869 100644
--- a/C4/Accounts.pm
+++ b/C4/Accounts.pm
@@ -469,17 +469,25 @@ sub manualinvoice {
 
 sub getcharges {
     my ( $borrowerno, $accountno ) = @_;
-	my $dbh        = C4::Context->dbh;
-	my $query      = "";
-	my $sth = $dbh->prepare(
-			"SELECT * FROM accountlines WHERE borrowernumber=? AND accountno = ?"
-          );
-	$sth->execute( $borrowerno, $accountno );
+    my $dbh = C4::Context->dbh;
+
+    my @params;
+
+    my $query = "SELECT * FROM accountlines WHERE borrowernumber = ?";
+    push( @params, $borrowerno );
+
+    if ( $accountno ) {
+        $query .= " AND accountno = ?";
+        push( @params, $accountno );
+    }
+
+    my $sth = $dbh->prepare( $query );
+    $sth->execute( @params );
 	
     my @results;
     while ( my $data = $sth->fetchrow_hashref ) {
-		push @results,$data;
-	}
+        push @results,$data;
+    }
     return (@results);
 }
 
diff --git a/t/db_dependent/Circulation/Chargelostitem.t b/t/db_dependent/Circulation/Chargelostitem.t
index e9d9694..06770c9 100644
--- a/t/db_dependent/Circulation/Chargelostitem.t
+++ b/t/db_dependent/Circulation/Chargelostitem.t
@@ -76,9 +76,9 @@ my $issues;
 $issues = C4::Circulation::GetIssues({biblionumber => $biblionumber1});
 my $issue=$issues->[0];
 $issue->{'processfee'} = $processfee;
-my $accountlineId = C4::Accounts::chargelostitem($issue, 'test');
+C4::Accounts::chargelostitem($issue, 'test');
 
-my @accountline = C4::Accounts::getcharges($borrowernumber, $accountlineId);
+my @accountline = C4::Accounts::getcharges($borrowernumber);
 
 is( scalar(@accountline), 1, 'accountline should have 1 row' );
 is( int($accountline[0]->{amount}), $processfee, "The accountline amount should be precessfee value " );
@@ -86,4 +86,4 @@ is( $accountline[0]->{accounttype}, 'PF', "The accountline accounttype should be
 is( $accountline[0]->{borrowernumber}, $borrowernumber, "The accountline borrowernumber should be the exemple borrownumber" );
 my $itemnumber = C4::Items::GetItemnumberFromBarcode('0101');
 is( $accountline[0]->{itemnumber}, $itemnumber, "The accountline itemnumber should the linked with barcode '0101'" );
-is( $accountline[0]->{description}, 'test', "The accountline description should be 'test'" );
+is( $accountline[0]->{description}, 'test ' . $issue->{itemnumber}, "The accountline description should be 'test'" );
-- 
1.7.10.4