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

(-)a/misc/cronjobs/longoverdue.pl (-1 / +65 lines)
Lines 45-50 my $endrange = 366; Link Here
45
my $mark_returned;
45
my $mark_returned;
46
my $borrower_category = [];
46
my $borrower_category = [];
47
my $skip_borrower_category = [];
47
my $skip_borrower_category = [];
48
my @branches;
49
my @skip_branches;
48
my $itemtype = [];
50
my $itemtype = [];
49
my $skip_itemtype = [];
51
my $skip_itemtype = [];
50
my $help=0;
52
my $help=0;
Lines 68-73 GetOptions( Link Here
68
    'category=s'        => $borrower_category,
70
    'category=s'        => $borrower_category,
69
    'skip-category=s'   => $skip_borrower_category,
71
    'skip-category=s'   => $skip_borrower_category,
70
    'list-categories'   => \$list_categories,
72
    'list-categories'   => \$list_categories,
73
    'branch=s'          => \@branches,
74
    'skip-branch=s'     => \@skip_branches,
71
    'itemtype=s'        => $itemtype,
75
    'itemtype=s'        => $itemtype,
72
    'skip-itemtype=s'   => $skip_itemtype,
76
    'skip-itemtype=s'   => $skip_itemtype,
73
    'list-itemtypes'    => \$list_itemtypes,
77
    'list-itemtypes'    => \$list_itemtypes,
Lines 94-99 if ( scalar @$borrower_category && scalar @$skip_borrower_category) { Link Here
94
            );
98
            );
95
}
99
}
96
100
101
if ( scalar @branches && scalar @skip_branches) {
102
    pod2usage( -verbose => 1,
103
               -message => "The options --branch and --skip-branch are mutually exclusive.\n"
104
                           . "Use one or the other.",
105
               -exitval => 1
106
            );
107
}
108
97
if ( scalar @$itemtype && scalar @$skip_itemtype) {
109
if ( scalar @$itemtype && scalar @$skip_itemtype) {
98
    pod2usage( -verbose => 1,
110
    pod2usage( -verbose => 1,
99
               -message => "The options --itemtype and --skip-itemtype are mutually exclusive.\n"
111
               -message => "The options --itemtype and --skip-itemtype are mutually exclusive.\n"
Lines 121-126 if ( $list_itemtypes ) { Link Here
121
   longoverdue.pl --lost | -l DAYS=LOST_CODE [ --charge | -c CHARGE_CODE ] [ --verbose | -v ] [ --quiet ]
133
   longoverdue.pl --lost | -l DAYS=LOST_CODE [ --charge | -c CHARGE_CODE ] [ --verbose | -v ] [ --quiet ]
122
                  [ --maxdays MAX_DAYS ] [ --mark-returned ] [ --category BORROWER_CATEGORY ] ...
134
                  [ --maxdays MAX_DAYS ] [ --mark-returned ] [ --category BORROWER_CATEGORY ] ...
123
                  [ --skip-category BORROWER_CATEGORY ] ...
135
                  [ --skip-category BORROWER_CATEGORY ] ...
136
                  [ --branch BRANCH_CODE ] [ --skip-branch BRANCH_CODE ] ...
124
                  [ --skip-lost-value LOST_VALUE [ --skip-lost-value LOST_VALUE ] ]
137
                  [ --skip-lost-value LOST_VALUE [ --skip-lost-value LOST_VALUE ] ]
125
                  [ --commit ]
138
                  [ --commit ]
126
139
Lines 185-190 May not be used with B<--category> Link Here
185
List borrower categories available for use by B<--category> or
198
List borrower categories available for use by B<--category> or
186
B<--skip-category>, and exit.
199
B<--skip-category>, and exit.
187
200
201
=item B<--branch>
202
203
Act on the listed branch codes.  Exclude all others.  This may be specified multiple times to include multiple branches.  Which branches are selected follows the CircControl system preference.
204
May not be used with B<--skip-branch>
205
206
=item B<--skip-branch>
207
208
Act on all branch codes except the ones listed.  This may be specified multiple times to exclude multiple branches.  Which branches are excluded follows the CircControl system preference.
209
May not be used with B<--branch>
210
188
=item B<--itemtype>
211
=item B<--itemtype>
189
212
190
Act on the listed itemtype code.
213
Act on the listed itemtype code.
Lines 315-320 sub longoverdue_sth { Link Here
315
}
338
}
316
339
317
my $dbh = C4::Context->dbh;
340
my $dbh = C4::Context->dbh;
341
my $circ_control_pref = C4::Context->preference('CircControl');
318
342
319
my @available_categories = Koha::Patron::Categories->search()->get_column('categorycode');
343
my @available_categories = Koha::Patron::Categories->search()->get_column('categorycode');
320
$borrower_category = [ map { uc $_ } @$borrower_category ];
344
$borrower_category = [ map { uc $_ } @$borrower_category ];
Lines 344-349 if ( @$skip_borrower_category ) { Link Here
344
368
345
my $filter_borrower_categories = ( scalar @$borrower_category || scalar @$skip_borrower_category );
369
my $filter_borrower_categories = ( scalar @$borrower_category || scalar @$skip_borrower_category );
346
370
371
my @available_branches = Koha::Libraries->search()->get_column('branchcode');
372
my %branches_to_process;
373
for my $lib ( @branches ) {
374
    unless ( grep { $_ eq $lib } @available_branches ) {
375
        pod2usage(
376
            '-exitval' => 1,
377
            '-message' => "The library $lib does not exist in the database",
378
        );
379
    }
380
    $branches_to_process{$lib} = 1;
381
}
382
if ( @skip_branches ) {
383
    for my $lib ( @skip_branches ) {
384
        unless ( grep { $_ eq $lib } @available_branches ) {
385
            pod2usage(
386
                '-exitval' => 1,
387
                '-message' => "The library $lib does not exist in the database",
388
            );
389
        }
390
    }
391
    %branches_to_process = map { $_ => 1 } @available_branches;
392
    %branches_to_process = ( %branches_to_process, map { $_ => 0 } @skip_branches );
393
}
394
395
my $filter_branches = ( scalar @branches || scalar @skip_branches );
396
347
my @available_itemtypes = Koha::ItemTypes->search()->get_column('itemtype');
397
my @available_itemtypes = Koha::ItemTypes->search()->get_column('itemtype');
348
$itemtype = [ map { uc $_ } @$itemtype ];
398
$itemtype = [ map { uc $_ } @$itemtype ];
349
$skip_itemtype = [ map { uc $_} @$skip_itemtype ];
399
$skip_itemtype = [ map { uc $_} @$skip_itemtype ];
Lines 397-402 foreach my $startrange (sort keys %$lost) { Link Here
397
                my $category = uc Koha::Patrons->find( $row->{borrowernumber} )->categorycode();
447
                my $category = uc Koha::Patrons->find( $row->{borrowernumber} )->categorycode();
398
                next ITEM unless ( $category_to_process{ $category } );
448
                next ITEM unless ( $category_to_process{ $category } );
399
            }
449
            }
450
            if ($filter_branches) {
451
                my $lib;
452
                for ($circ_control_pref) {
453
                    if ( $_ eq 'PatronLibrary' ) {
454
                        $lib = Koha::Patrons->find( $row->{borrowernumber} )->branchcode();
455
                    }
456
                    elsif ( $_ eq 'PickupLibrary' ) {
457
                        $lib = C4::Context->userenv->{'branch'};
458
                    }
459
                    else { # ( $_ eq 'ItemHomeLibrary' ) {
460
                        $lib = Koha::Items->find( $row->{itemnumber} )->homebranch();
461
                    }
462
                }
463
                next ITEM unless ( $branches_to_process{$lib} );
464
            }
400
            if ($filter_itemtypes) {
465
            if ($filter_itemtypes) {
401
                my $it = uc Koha::Items->find( $row->{itemnumber} )->effective_itemtype();
466
                my $it = uc Koha::Items->find( $row->{itemnumber} )->effective_itemtype();
402
                next ITEM unless ( $itemtype_to_process{$it} );
467
                next ITEM unless ( $itemtype_to_process{$it} );
403
- 

Return to bug 9596