Lines 39-44
use C4::Circulation qw/LostItem/;
Link Here
|
39 |
use Getopt::Long; |
39 |
use Getopt::Long; |
40 |
use C4::Log; |
40 |
use C4::Log; |
41 |
use Pod::Usage; |
41 |
use Pod::Usage; |
|
|
42 |
use Koha::Borrowers; |
42 |
|
43 |
|
43 |
my $lost; # key=lost value, value=num days. |
44 |
my $lost; # key=lost value, value=num days. |
44 |
my ($charge, $verbose, $confirm, $quiet); |
45 |
my ($charge, $verbose, $confirm, $quiet); |
Lines 53-63
GetOptions(
Link Here
|
53 |
'lost=s%' => \$lost, |
54 |
'lost=s%' => \$lost, |
54 |
'c|charge=s' => \$charge, |
55 |
'c|charge=s' => \$charge, |
55 |
'confirm' => \$confirm, |
56 |
'confirm' => \$confirm, |
56 |
'verbose' => \$verbose, |
57 |
'v|verbose' => \$verbose, |
57 |
'quiet' => \$quiet, |
58 |
'quiet' => \$quiet, |
58 |
'maxdays=s' => \$endrange, |
59 |
'maxdays=s' => \$endrange, |
59 |
'mark-returned' => \$mark_returned, |
60 |
'mark-returned' => \$mark_returned, |
60 |
'help' => \$help, |
61 |
'h|help' => \$help, |
61 |
'man|manual' => \$man, |
62 |
'man|manual' => \$man, |
62 |
'category=s' => $borrower_category, |
63 |
'category=s' => $borrower_category, |
63 |
'skip-category=s' => $skip_borrower_category |
64 |
'skip-category=s' => $skip_borrower_category |
Lines 77-83
if ( $help ) {
Link Here
|
77 |
|
78 |
|
78 |
longoverdue.pl [ --help | -h | --man ] |
79 |
longoverdue.pl [ --help | -h | --man ] |
79 |
longoverdue.pl --lost | -l DAYS=LOST_CODE [ --charge | -c CHARGE_CODE ] [ --verbose | -v ] [ --quiet ] |
80 |
longoverdue.pl --lost | -l DAYS=LOST_CODE [ --charge | -c CHARGE_CODE ] [ --verbose | -v ] [ --quiet ] |
80 |
[ --maxdays MAX_DAYS ] [ --mark-returned ] [ --category BORROWER_CATEGOERY ] ... |
81 |
[ --maxdays MAX_DAYS ] [ --mark-returned ] [ --category BORROWER_CATEGORY ] ... |
81 |
[ --skip-category BORROWER_CATEGOERY ] ... [ --commit ] |
82 |
[ --skip-category BORROWER_CATEGOERY ] ... [ --commit ] |
82 |
|
83 |
|
83 |
|
84 |
|
Lines 184-191
if ( ! defined($lost) ) {
Link Here
|
184 |
$lost->{$longoverdue_days} = $longoverdue_value; |
185 |
$lost->{$longoverdue_days} = $longoverdue_value; |
185 |
} |
186 |
} |
186 |
else { |
187 |
else { |
187 |
pod2usage(1); |
188 |
pod2usage( { |
188 |
die "ERROR: No --lost (-l) option defined"; |
189 |
-exitval => 1, |
|
|
190 |
-msg => q|ERROR: No --lost (-l) option defined|, |
191 |
} ); |
189 |
} |
192 |
} |
190 |
} |
193 |
} |
191 |
if ( ! defined($charge) ) { |
194 |
if ( ! defined($charge) ) { |
Lines 223-245
sub longoverdue_sth {
Link Here
|
223 |
return C4::Context->dbh->prepare($query); |
226 |
return C4::Context->dbh->prepare($query); |
224 |
} |
227 |
} |
225 |
|
228 |
|
226 |
# The following two functions can and should replaced by a call to |
|
|
227 |
# Koha::Database. |
228 |
sub borrower_categories_sth { |
229 |
my $query = "select distinct categorycode from categories"; |
230 |
return C4::Context->dbh->prepare($query); |
231 |
} |
232 |
|
233 |
sub defined_borrower_categories { |
234 |
my $sth = borrower_categories_sth(); |
235 |
my @categories = (); |
236 |
$sth->execute(); |
237 |
CATEGORY: while ( my $row = $sth->fetchrow_hashref ) { |
238 |
push @categories, uc( $row->{categorycode} ); |
239 |
} |
240 |
return @categories; |
241 |
} |
242 |
|
243 |
# returns a hash of borrower category codes to test for long-overdue-ness. |
229 |
# returns a hash of borrower category codes to test for long-overdue-ness. |
244 |
# The key is the borrower category, upper case. The value is 1. This |
230 |
# The key is the borrower category, upper case. The value is 1. This |
245 |
# will make a fast look-up of valid borrower category codes. |
231 |
# will make a fast look-up of valid borrower category codes. |
Lines 248-254
sub get_borrower_categories {
Link Here
|
248 |
|
234 |
|
249 |
return () unless ( scalar @$borrower_category || scalar @$skip_borrower_category ); |
235 |
return () unless ( scalar @$borrower_category || scalar @$skip_borrower_category ); |
250 |
|
236 |
|
251 |
my @categories = defined_borrower_categories(); |
237 |
my $dbh = C4::Context->dbh; |
|
|
238 |
my @categories = map { uc $_->[0] } @{ $dbh->selectall_arrayref(q|SELECT categorycode FROM categories|) }; |
252 |
if( @$borrower_category ) { |
239 |
if( @$borrower_category ) { |
253 |
my %borcat = map { ( uc($_) => 1 ) } @$borrower_category; |
240 |
my %borcat = map { ( uc($_) => 1 ) } @$borrower_category; |
254 |
@categories = grep { $borcat{$_} } @categories; |
241 |
@categories = grep { $borcat{$_} } @categories; |
Lines 270-279
sub get_borrower_categories {
Link Here
|
270 |
my %category_to_process = get_borrower_categories( $borrower_category, $skip_borrower_category ); |
257 |
my %category_to_process = get_borrower_categories( $borrower_category, $skip_borrower_category ); |
271 |
my $filter_borrower_categories = ( scalar @$borrower_category || scalar @$skip_borrower_category ); |
258 |
my $filter_borrower_categories = ( scalar @$borrower_category || scalar @$skip_borrower_category ); |
272 |
|
259 |
|
273 |
#FIXME - Should add a 'system' user and get suitable userenv for it for logging, etc. |
|
|
274 |
|
275 |
my $count; |
260 |
my $count; |
276 |
# my @ranges = map { |
|
|
277 |
my @report; |
261 |
my @report; |
278 |
my $total = 0; |
262 |
my $total = 0; |
279 |
my $i = 0; |
263 |
my $i = 0; |
Lines 295-301
foreach my $startrange (sort keys %$lost) {
Link Here
|
295 |
$count=0; |
279 |
$count=0; |
296 |
ITEM: while (my $row=$sth_items->fetchrow_hashref) { |
280 |
ITEM: while (my $row=$sth_items->fetchrow_hashref) { |
297 |
if( $filter_borrower_categories ) { |
281 |
if( $filter_borrower_categories ) { |
298 |
my $category = uc Koha::Database->new()->schema->resultset('Borrower')->find( $row->{borrowernumber} )->get_column('categorycode'); |
282 |
my $category = uc Koha::Borrowers->find( $row->{borrowernumber} )->categorycode(); |
299 |
next ITEM unless ( $category_to_process{ $category } ); |
283 |
next ITEM unless ( $category_to_process{ $category } ); |
300 |
} |
284 |
} |
301 |
printf ("Due %s: item %5s from borrower %5s to lost: %s\n", $row->{date_due}, $row->{itemnumber}, $row->{borrowernumber}, $lostvalue) if($verbose); |
285 |
printf ("Due %s: item %5s from borrower %5s to lost: %s\n", $row->{date_due}, $row->{itemnumber}, $row->{borrowernumber}, $lostvalue) if($verbose); |
302 |
- |
|
|