Bug 11292 - barcode scanner clicking 'save'
[koha_fer] / misc / cronjobs / longoverdue.pl
index cd0cbd6..0f64712 100755 (executable)
@@ -35,18 +35,22 @@ BEGIN {
 }
 use C4::Context;
 use C4::Items;
-use C4::Accounts;
+use C4::Circulation qw/LostItem/;
 use Getopt::Long;
 
 my  $lost;  #  key=lost value,  value=num days.
-my ($charge, $verbose, $confirm);
-my $endrange = 366;  # FIXME hardcoded - don't deal with anything overdue by more than this num days.
+my ($charge, $verbose, $confirm, $quiet);
+my $endrange = 366;
+my $mark_returned = 0;
 
 GetOptions( 
-    'lost=s%'    => \$lost,
-    'c|charge=s' => \$charge,
-    'confirm'    => \$confirm,
-    'verbose'    => \$verbose,
+    'lost=s%'       => \$lost,
+    'c|charge=s'    => \$charge,
+    'confirm'       => \$confirm,
+    'verbose'       => \$verbose,
+    'quiet'         => \$quiet,
+    'maxdays=s'     => \$endrange,
+    'mark-returned' => \$mark_returned,
 );
 
 my $usage = << 'ENDUSAGE';
@@ -68,6 +72,13 @@ This script takes the following parameters :
     --confirm           confirm.  without this option, the script will report the number of affected items and
                         return without modifying any records.
 
+    --quiet             suppress summary output.
+
+    --maxdays           Specifies the end of the range of overdue days to deal with (defaults to 366).  This
+                        value is universal to all lost num days overdue passed.
+
+    --mark-returned     When an item is marked lost, remove it from the borrowers issued items.
+
   examples :
   $PERL5LIB/misc/cronjobs/longoverdue.pl --lost 30=1
     Would set LOST=1 after 30 days (up to one year), but not charge the account.
@@ -81,7 +92,7 @@ WARNING:  Flippant use of this script could set all or most of the items in your
 patrons for them!
 
 WARNING:  This script is known to be faulty.  It is NOT recommended to use multiple --lost options.
-          See http://bugs.koha.org/cgi-bin/bugzilla/show_bug.cgi?id=2881
+          See http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=2883
 
 ENDUSAGE
 
@@ -154,7 +165,7 @@ foreach my $startrange (sort keys %$lost) {
             printf ("Due %s: item %5s from borrower %5s to lost: %s\n", $row->{date_due}, $row->{itemnumber}, $row->{borrowernumber}, $lostvalue) if($verbose);
             if($confirm) {
                 ModItem({ itemlost => $lostvalue }, $row->{'biblionumber'}, $row->{'itemnumber'});
-                chargelostitem($row->{'itemnumber'}) if( $charge && $charge eq $lostvalue);
+                LostItem($row->{'itemnumber'}, $mark_returned) if( $charge && $charge eq $lostvalue);
             }
             $count++;
         }
@@ -184,6 +195,8 @@ sub summarize ($$) {
     }
 }
 
-print "\n### LONGOVERDUE SUMMARY ###";
-summarize (\@report, 1);
-print "\nTOTAL: $total items\n";
+if (!$quiet){
+    print "\n### LONGOVERDUE SUMMARY ###";
+    summarize (\@report, 1);
+    print "\nTOTAL: $total items\n";
+}