Bug 15758: Koha::Libraries - Remove GetBranches
[srvgit] / C4 / Overdues.pm
index 3f0c32d..d0df426 100644 (file)
@@ -36,6 +36,7 @@ use C4::Debug;
 use Koha::DateUtils;
 use Koha::Account::Line;
 use Koha::Account::Lines;
+use Koha::Libraries;
 
 use vars qw(@ISA @EXPORT);
 
@@ -537,8 +538,9 @@ sub UpdateFine {
     #   "REF" is Cash Refund
     my $sth = $dbh->prepare(
         "SELECT * FROM accountlines
-        WHERE borrowernumber=?
-        AND   accounttype IN ('FU','O','F','M')"
+        WHERE borrowernumber=? AND
+        (( accounttype IN ('O','F','M') AND amountoutstanding<>0 ) OR
+           accounttype = 'FU' )"
     );
     $sth->execute( $borrowernumber );
     my $data;
@@ -549,9 +551,10 @@ sub UpdateFine {
     # - accumulate fines for other items
     # so we can update $itemnum fine taking in account fine caps
     while (my $rec = $sth->fetchrow_hashref) {
-        if ( $rec->{issue_id} == $issue_id ) {
+        if ( $rec->{issue_id} == $issue_id && $rec->{accounttype} eq 'FU' ) {
             if ($data) {
                 warn "Not a unique accountlines record for issue_id $issue_id";
+                #FIXME Should we still count this one in total_amount ??
             }
             else {
                 $data = $rec;
@@ -786,8 +789,7 @@ sub GetBranchcodesWithOverdueRules {
     |);
     if ( $branchcodes->[0] eq '' ) {
         # If a default rule exists, all branches should be returned
-        my $availbranches = C4::Branch::GetBranches();
-        return keys %$availbranches;
+        return map { $_->branchcode } Koha::Libraries->search({}, { order_by => 'branchname' });
     }
     return @$branchcodes;
 }