View | Details | Raw Unified | Return to bug 15538
Collapse All | Expand All

(-)a/misc/cronjobs/longoverdue.pl (-14 / +13 lines)
Lines 40-48 use Getopt::Long; Link Here
40
use C4::Log;
40
use C4::Log;
41
use Pod::Usage;
41
use Pod::Usage;
42
use Koha::Borrowers;
42
use Koha::Borrowers;
43
use Koha::Logger;
43
44
44
my  $lost;  #  key=lost value,  value=num days.
45
my  $lost;  #  key=lost value,  value=num days.
45
my ($charge, $verbose, $confirm, $quiet);
46
my ($charge, $confirm, $quiet);
46
my $endrange = 366;
47
my $endrange = 366;
47
my $mark_returned = 0;
48
my $mark_returned = 0;
48
my $borrower_category = [];
49
my $borrower_category = [];
Lines 55-61 GetOptions( Link Here
55
    'lost=s%'         => \$lost,
56
    'lost=s%'         => \$lost,
56
    'c|charge=s'      => \$charge,
57
    'c|charge=s'      => \$charge,
57
    'confirm'         => \$confirm,
58
    'confirm'         => \$confirm,
58
    'v|verbose'         => \$verbose,
59
    'quiet'           => \$quiet,
59
    'quiet'           => \$quiet,
60
    'maxdays=s'       => \$endrange,
60
    'maxdays=s'       => \$endrange,
61
    'mark-returned'   => \$mark_returned,
61
    'mark-returned'   => \$mark_returned,
Lines 95-101 if ( $list_categories ) { Link Here
95
=head1 SYNOPSIS
95
=head1 SYNOPSIS
96
96
97
   longoverdue.pl [ --help | -h | --man | --list-categories ]
97
   longoverdue.pl [ --help | -h | --man | --list-categories ]
98
   longoverdue.pl --lost | -l DAYS=LOST_CODE [ --charge | -c CHARGE_CODE ] [ --verbose | -v ] [ --quiet ]
98
   longoverdue.pl --lost | -l DAYS=LOST_CODE [ --charge | -c CHARGE_CODE ] [ --quiet ]
99
                  [ --maxdays MAX_DAYS ] [ --mark-returned ] [ --category BORROWER_CATEGORY ] ...
99
                  [ --maxdays MAX_DAYS ] [ --mark-returned ] [ --category BORROWER_CATEGORY ] ...
100
                  [ --skip-category BORROWER_CATEGORY ] ...
100
                  [ --skip-category BORROWER_CATEGORY ] ...
101
                  [ --commit ]
101
                  [ --commit ]
Lines 123-132 This option takes the form of n=lv, where n is num days overdue, and lv is the l Link Here
123
123
124
This specifies what lost value triggers Koha to charge the account for the lost item.  Replacement costs are not charged if this is not specified.
124
This specifies what lost value triggers Koha to charge the account for the lost item.  Replacement costs are not charged if this is not specified.
125
125
126
=item B<--verbose | -v>
127
128
verbose.
129
130
=item B<--confirm>
126
=item B<--confirm>
131
127
132
confirm.  without this option, the script will report the number of affected items and return without modifying any records.
128
confirm.  without this option, the script will report the number of affected items and return without modifying any records.
Lines 194-199 near-term release, so this script is not intended to have a long lifetime. Link Here
194
190
195
=cut
191
=cut
196
192
193
my $logger = Koha::Logger->get({category => 'longoverdue'});
194
197
# FIXME: We need three pieces of data to operate:
195
# FIXME: We need three pieces of data to operate:
198
#         ~ lower bound (number of days),
196
#         ~ lower bound (number of days),
199
#         ~ upper bound (number of days),
197
#         ~ upper bound (number of days),
Lines 223-229 if ( ! defined($charge) ) { Link Here
223
    }
221
    }
224
}
222
}
225
unless ($confirm) {
223
unless ($confirm) {
226
    $verbose = 1;     # If you're not running it for real, then the whole point is the print output.
227
    print "### TEST MODE -- NO ACTIONS TAKEN ###\n";
224
    print "### TEST MODE -- NO ACTIONS TAKEN ###\n";
228
}
225
}
229
226
Lines 294-303 foreach my $startrange (sort keys %$lost) { Link Here
294
    if( my $lostvalue = $lost->{$startrange} ) {
291
    if( my $lostvalue = $lost->{$startrange} ) {
295
        my ($date1) = bounds($startrange);
292
        my ($date1) = bounds($startrange);
296
        my ($date2) = bounds(  $endrange);
293
        my ($date2) = bounds(  $endrange);
297
        # print "\nRange ", ++$i, "\nDue $startrange - $endrange days ago ($date2 to $date1), lost => $lostvalue\n" if($verbose);
294
        $logger->debug(
298
        $verbose and
295
            sprintf "\nRange %s\nDue %3s - %3s days ago (%s to %s), lost => %s",
299
            printf "\nRange %s\nDue %3s - %3s days ago (%s to %s), lost => %s\n", ++$i,
296
                ++$i, $startrange, $endrange, $date2, $date1, $lostvalue
300
            $startrange, $endrange, $date2, $date1, $lostvalue;
297
        );
301
        $sth_items->execute($startrange, $endrange, $lostvalue);
298
        $sth_items->execute($startrange, $endrange, $lostvalue);
302
        $count=0;
299
        $count=0;
303
        ITEM: while (my $row=$sth_items->fetchrow_hashref) {
300
        ITEM: while (my $row=$sth_items->fetchrow_hashref) {
Lines 305-311 foreach my $startrange (sort keys %$lost) { Link Here
305
                my $category = uc Koha::Borrowers->find( $row->{borrowernumber} )->categorycode();
302
                my $category = uc Koha::Borrowers->find( $row->{borrowernumber} )->categorycode();
306
                next ITEM unless ( $category_to_process{ $category } );
303
                next ITEM unless ( $category_to_process{ $category } );
307
            }
304
            }
308
            printf ("Due %s: item %5s from borrower %5s to lost: %s\n", $row->{date_due}, $row->{itemnumber}, $row->{borrowernumber}, $lostvalue) if($verbose);
305
            $logger->debug(
306
                sprintf "Due %s: item %5s from borrower %5s to lost: %s",
307
                    $row->{date_due}, $row->{itemnumber}, $row->{borrowernumber}, $lostvalue
308
            );
309
            if($confirm) {
309
            if($confirm) {
310
                ModItem({ itemlost => $lostvalue }, $row->{'biblionumber'}, $row->{'itemnumber'});
310
                ModItem({ itemlost => $lostvalue }, $row->{'biblionumber'}, $row->{'itemnumber'});
311
                LostItem($row->{'itemnumber'}, $mark_returned) if( $charge && $charge eq $lostvalue);
311
                LostItem($row->{'itemnumber'}, $mark_returned) if( $charge && $charge eq $lostvalue);
312
- 

Return to bug 15538