Bug 17600: Standardize our EXPORT_OK
[srvgit] / C4 / Overdues.pm
index 2f1212b..54a4264 100644 (file)
@@ -20,45 +20,38 @@ package C4::Overdues;
 # along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 use Modern::Perl;
-use Date::Calc qw/Today Date_to_Days/;
-use Date::Manip qw/UnixDate/;
+use Date::Calc qw( Today );
+use Date::Manip qw( UnixDate );
 use List::MoreUtils qw( uniq );
-use POSIX qw( floor ceil );
-use Locale::Currency::Format 1.28;
-use Carp;
+use POSIX qw( ceil floor );
+use Locale::Currency::Format 1.28 qw( currency_format FMT_SYMBOL );
+use Carp qw( carp );
 
-use C4::Circulation;
 use C4::Context;
 use C4::Accounts;
-use C4::Log; # logaction
-use C4::Debug;
-use Koha::DateUtils;
+use Koha::Logger;
 use Koha::Account::Lines;
 use Koha::Account::Offsets;
 use Koha::Libraries;
 
-use vars qw(@ISA @EXPORT);
-
+our (@ISA, @EXPORT_OK);
 BEGIN {
     require Exporter;
     @ISA = qw(Exporter);
 
     # subs to rename (and maybe merge some...)
-    push @EXPORT, qw(
-      &CalcFine
-      &Getoverdues
-      &checkoverdues
-      &UpdateFine
-      &GetFine
-      &get_chargeable_units
-      &GetOverduesForBranch
-      &GetOverdueMessageTransportTypes
-      &parse_overdues_letter
-    );
-
-    # subs to move to Circulation.pm
-    push @EXPORT, qw(
-      &GetIssuesIteminfo
+    @EXPORT_OK = qw(
+      CalcFine
+      Getoverdues
+      checkoverdues
+      UpdateFine
+      GetFine
+      GetBranchcodesWithOverdueRules
+      get_chargeable_units
+      GetOverduesForBranch
+      GetOverdueMessageTransportTypes
+      parse_overdues_letter
+      GetIssuesIteminfo
     );
 }
 
@@ -275,7 +268,6 @@ sub CalcFine {
 
     $amount = $item->{replacementprice} if ( $issuing_rule->{cap_fine_to_replacement_price} && $item->{replacementprice} && $amount > $item->{replacementprice} );
 
-    $debug and warn sprintf("CalcFine returning (%s, %s, %s)", $amount, $units_minus_grace, $chargeable_units);
     return ($amount, $units_minus_grace, $chargeable_units);
 }
 
@@ -522,8 +514,6 @@ sub UpdateFine {
     my $amount         = $params->{amount};
     my $due            = $params->{due} // q{};
 
-    $debug and warn "UpdateFine({ itemnumber => $itemnum, borrowernumber => $borrowernumber, due => $due, issue_id => $issue_id})";
-
     unless ( $issue_id ) {
         carp("No issue_id passed in!");
         return;
@@ -545,14 +535,13 @@ sub UpdateFine {
     # - accumulate fines for other items
     # so we can update $itemnum fine taking in account fine caps
     while (my $overdue = $overdues->next) {
-        if ( $overdue->issue_id == $issue_id && $overdue->status eq 'UNRETURNED' ) {
+        if ( defined $overdue->issue_id && $overdue->issue_id == $issue_id && $overdue->status eq 'UNRETURNED' ) {
             if ($accountline) {
-                $debug and warn "Not a unique accountlines record for issue_id $issue_id";
+                Koha::Logger->get->debug("Not a unique accountlines record for issue_id $issue_id"); # FIXME Do we really need to log that?
                 #FIXME Should we still count this one in total_amount ??
             }
             else {
                 $accountline = $overdue;
-                next;
             }
         }
         $total_amount_other += $overdue->amountoutstanding;
@@ -560,22 +549,22 @@ sub UpdateFine {
 
     if ( my $maxfine = C4::Context->preference('MaxFine') ) {
         my $maxIncrease = $maxfine - $total_amount_other;
-        return if $maxIncrease <= 0.00;
+        return if Koha::Number::Price->new($maxIncrease)->round <= 0.00;
         if ($accountline) {
             if ( ( $amount - $accountline->amount ) > $maxIncrease ) {
                 my $new_amount = $accountline->amount + $maxIncrease;
-                $debug and warn "Reducing fine for item $itemnum borrower $borrowernumber from $amount to $new_amount - MaxFine reached";
+                Koha::Logger->get->debug("Reducing fine for item $itemnum borrower $borrowernumber from $amount to $new_amount - MaxFine reached");
                 $amount = $new_amount;
             }
         }
         elsif ( $amount > $maxIncrease ) {
-            $debug and warn "Reducing fine for item $itemnum borrower $borrowernumber from $amount to $maxIncrease - MaxFine reached";
+            Koha::Logger->get->debug("Reducing fine for item $itemnum borrower $borrowernumber from $amount to $maxIncrease - MaxFine reached");
             $amount = $maxIncrease;
         }
     }
 
     if ( $accountline ) {
-        if ( $accountline->amount != $amount ) {
+        if ( Koha::Number::Price->new($accountline->amount)->round != Koha::Number::Price->new($amount)->round ) {
             $accountline->adjust(
                 {
                     amount    => $amount,