Bug 21235: Remove table services_throttle
[koha.git] / misc / cronjobs / staticfines.pl
index 0d819a5..c57e99e 100755 (executable)
@@ -3,7 +3,7 @@
 #  This script loops through each overdue item, determines the fine,
 #  and updates the total amount of fines due by each user.  It relies on
 #  the existence of /tmp/fines, which is created by ???
-# Doesnt really rely on it, it relys on being able to write to /tmp/
+# Doesn't really rely on it, it relies on being able to write to /tmp/
 # It creates the fines file
 #
 #  This script is meant to be run nightly out of cron.
 #
 # This file is part of Koha.
 #
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
 #
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 use Modern::Perl;
 
@@ -43,6 +43,7 @@ use C4::Overdues;
 use C4::Calendar qw();    # don't need any exports from Calendar
 use C4::Biblio;
 use C4::Debug;            # supplying $debug and $cgi_debug
+use C4::Log;
 use Getopt::Long;
 use List::MoreUtils qw/none/;
 use Koha::DateUtils;
@@ -90,6 +91,8 @@ This script has the following parameters :
 ENDUSAGE
 die $usage if $help;
 
+cronlogaction();
+
 my $dbh = C4::Context->dbh;
 
 # Processing categories
@@ -132,23 +135,24 @@ if (defined $borrowernumberlimit) {
 }
 my $overdueItemsCounted = 0;
 my %calendars           = ();
-$today      = C4::Dates->new();
-$today_iso  = $today->output('iso');
+$today      = dt_from_string;
+$today_iso  = output_pref( { dt => $today, dateonly => 1, dateformat => 'iso' } );
 my ($tyear, $tmonth, $tday) = split( /-/, $today_iso );
 $today_days = Date_to_Days( $tyear, $tmonth, $tday );
 
 for ( my $i = 0 ; $i < scalar(@$data) ; $i++ ) {
-    my $datedue;
-    my $datedue_days;
+    next if $data->[$i]->{'itemlost'};
+    my ( $datedue, $datedue_days );
     eval {
-    $datedue = C4::Dates->new( $data->[$i]->{'date_due'}, 'iso' );
-    $datedue_days = Date_to_Days( split( /-/, $datedue->output('iso') ) );
+        $datedue = dt_from_string( $data->[$i]->{'date_due'} );
+        my $datedue_iso = output_pref( { dt => $datedue, dateonly => 1, dateformat => 'iso' } );
+        $datedue_days = Date_to_Days( split( /-/, $datedue_iso ) );
     };
     if ($@) {
     warn "Error on date for borrower " . $data->[$i]->{'borrowernumber'} .  ": $@date_due: " . $data->[$i]->{'date_due'} . "\ndatedue_days: " . $datedue_days . "\nSkipping";
     next;
     }
-    my $due_str = $datedue->output();
+    my $due_str = output_pref( { dt => $datedue, dateonly => 1 } );
     unless ( defined $data->[$i]->{'borrowernumber'} ) {
         print STDERR "ERROR in Getoverdues line $i: issues.borrowernumber IS NULL.  Repair 'issues' table now!  Skipping record.\n";
         next;    # Note: this doesn't solve everything.  After NULL borrowernumber, multiple issues w/ real borrowernumbers can pile up.
@@ -188,15 +192,15 @@ for ( my $i = 0 ; $i < scalar(@$data) ; $i++ ) {
         $data->[$i],
         $borrower->{'categorycode'},
         $branchcode,
-        dt_from_string($datedue->output('iso')),
-        dt_from_string($today->output('iso')),
+        $datedue,
+        $today,
     );
 
     # Reassign fine's amount if specified in command-line
     $amount = $catamounts{$borrower->{'categorycode'}} if (defined $catamounts{$borrower->{'categorycode'}});
 
     # We check if there is already a fine for the given borrower
-    my $fine = GetFine($data->[$i]->{'borrowernumber'});
+    my $fine = GetFine(undef, $data->[$i]->{'borrowernumber'});
     if ($fine > 0) {
         $debug and warn "There is already a fine for borrower " . $data->[$i]->{'borrowernumber'} . ". Nothing to do here. Skipping this borrower";
         next;