Lines 30-35
use warnings;
Link Here
|
30 |
|
30 |
|
31 |
use Getopt::Long qw( GetOptions ); |
31 |
use Getopt::Long qw( GetOptions ); |
32 |
use Pod::Usage qw( pod2usage ); |
32 |
use Pod::Usage qw( pod2usage ); |
|
|
33 |
use DateTime; |
34 |
use DateTime::Duration; |
33 |
|
35 |
|
34 |
use C4::Circulation qw( LostItem MarkIssueReturned ); |
36 |
use C4::Circulation qw( LostItem MarkIssueReturned ); |
35 |
use C4::Context; |
37 |
use C4::Context; |
Lines 38-43
use Koha::ItemTypes;
Link Here
|
38 |
use Koha::Patron::Categories; |
40 |
use Koha::Patron::Categories; |
39 |
use Koha::Patrons; |
41 |
use Koha::Patrons; |
40 |
use Koha::Script -cron; |
42 |
use Koha::Script -cron; |
|
|
43 |
use Koha::Calendar; |
44 |
use Koha::DateUtils qw( dt_from_string ); |
45 |
|
41 |
|
46 |
|
42 |
my $lost; # key=lost value, value=num days. |
47 |
my $lost; # key=lost value, value=num days. |
43 |
my ($charge, $verbose, $confirm, $quiet); |
48 |
my ($charge, $verbose, $confirm, $quiet); |
Lines 312-317
sub longoverdue_sth {
Link Here
|
312 |
return C4::Context->dbh->prepare($query); |
317 |
return C4::Context->dbh->prepare($query); |
313 |
} |
318 |
} |
314 |
|
319 |
|
|
|
320 |
my @holidays_by_branch; |
321 |
|
322 |
sub get_number_of_holidays { |
323 |
my ( $start_date, $end_date ) = @_; |
324 |
|
325 |
$start_date = dt_from_string($start_date); |
326 |
$end_date = dt_from_string($end_date); |
327 |
|
328 |
my @branches = Koha::Libraries->search( {}, { order_by => ['branchcode'] } ); |
329 |
my $calendar; |
330 |
|
331 |
foreach my $branch ( @branches ) { |
332 |
my $date_to_run = $start_date->clone(); |
333 |
my $branchcode = $branch->branchcode; |
334 |
my $i = 0; |
335 |
|
336 |
$calendar = Koha::Calendar->new( branchcode => $branchcode ); |
337 |
|
338 |
while ( $date_to_run ne $end_date ) { |
339 |
# printf "\n Treatment of the day : %s \n", $date_to_run; |
340 |
if ( $calendar->is_holiday( $date_to_run ) ) { |
341 |
$i++; |
342 |
} |
343 |
$date_to_run->add( days => 1 ); |
344 |
} |
345 |
push @holidays_by_branch, { 'branchcode' => $branchcode, 'nb_holidays' => $i }; |
346 |
} |
347 |
return @holidays_by_branch; |
348 |
} |
349 |
|
315 |
my $dbh = C4::Context->dbh; |
350 |
my $dbh = C4::Context->dbh; |
316 |
|
351 |
|
317 |
my @available_categories = Koha::Patron::Categories->search()->get_column('categorycode'); |
352 |
my @available_categories = Koha::Patron::Categories->search()->get_column('categorycode'); |
Lines 384-394
foreach my $startrange (sort keys %$lost) {
Link Here
|
384 |
if( my $lostvalue = $lost->{$startrange} ) { |
419 |
if( my $lostvalue = $lost->{$startrange} ) { |
385 |
my ($date1) = bounds($startrange); |
420 |
my ($date1) = bounds($startrange); |
386 |
my ($date2) = bounds( $endrange); |
421 |
my ($date2) = bounds( $endrange); |
|
|
422 |
|
423 |
if ( C4::Context->preference( 'LongOverdueNoticeCalendar' ) ) { |
424 |
get_number_of_holidays( $date2, $date1 ); |
425 |
|
426 |
foreach my $branch ( @holidays_by_branch ) { |
427 |
|
428 |
my $date2_with_holidays = dt_from_string($date2) |
429 |
->subtract( days => $branch->{'nb_holidays'} )->ymd; |
430 |
my $endrange_with_holidays = |
431 |
$endrange + $branch->{'nb_holidays'}; |
432 |
|
433 |
$verbose and |
434 |
printf "\nBranchcode %s\nDue %3s - %3s days ago (%s to %s) - with %s holiday(s), lost => %s\n", $branch->{'branchcode'}, |
435 |
$startrange, $endrange_with_holidays, $date2_with_holidays, $date1, $branch->{'nb_holidays'}, $lostvalue; |
436 |
$sth_items->execute($startrange, $endrange_with_holidays, $lostvalue); |
437 |
} |
438 |
} else { |
439 |
|
387 |
# print "\nRange ", ++$i, "\nDue $startrange - $endrange days ago ($date2 to $date1), lost => $lostvalue\n" if($verbose); |
440 |
# print "\nRange ", ++$i, "\nDue $startrange - $endrange days ago ($date2 to $date1), lost => $lostvalue\n" if($verbose); |
388 |
$verbose and |
441 |
$verbose and |
389 |
printf "\nRange %s\nDue %3s - %3s days ago (%s to %s), lost => %s\n", ++$i, |
442 |
printf "\nRange %s\nDue %3s - %3s days ago (%s to %s), lost => %s\n", ++$i, |
390 |
$startrange, $endrange, $date2, $date1, $lostvalue; |
443 |
$startrange, $endrange, $date2, $date1, $lostvalue; |
391 |
$sth_items->execute($startrange, $endrange, $lostvalue); |
444 |
$sth_items->execute($startrange, $endrange, $lostvalue); |
|
|
445 |
} |
392 |
$count=0; |
446 |
$count=0; |
393 |
ITEM: while (my $row=$sth_items->fetchrow_hashref) { |
447 |
ITEM: while (my $row=$sth_items->fetchrow_hashref) { |
394 |
if( $filter_borrower_categories ) { |
448 |
if( $filter_borrower_categories ) { |
Lines 438-445
sub summarize {
Link Here
|
438 |
} |
492 |
} |
439 |
} |
493 |
} |
440 |
|
494 |
|
441 |
if (!$quiet){ |
495 |
if (!( C4::Context->preference( 'LongOverdueNoticeCalendar' ) )) { |
442 |
print "\n### LONGOVERDUE SUMMARY ###"; |
496 |
if (!$quiet){ |
443 |
summarize (\@report, 1); |
497 |
print "\n### LONGOVERDUE SUMMARY ###"; |
444 |
print "\nTOTAL: $total items\n"; |
498 |
summarize (\@report, 1); |
|
|
499 |
print "\nTOTAL: $total items\n"; |
500 |
} |
445 |
} |
501 |
} |
446 |
- |
|
|