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 314-319
sub longoverdue_sth {
Link Here
|
314 |
return C4::Context->dbh->prepare($query); |
319 |
return C4::Context->dbh->prepare($query); |
315 |
} |
320 |
} |
316 |
|
321 |
|
|
|
322 |
my @holidays_by_branch; |
323 |
|
324 |
sub get_number_of_holidays { |
325 |
my ( $start_date, $end_date ) = @_; |
326 |
|
327 |
$start_date = dt_from_string($start_date); |
328 |
$end_date = dt_from_string($end_date); |
329 |
|
330 |
my @branches = Koha::Libraries->search( {}, { order_by => ['branchcode'] } ); |
331 |
my $calendar; |
332 |
|
333 |
foreach my $branch ( @branches ) { |
334 |
my $date_to_run = $start_date->clone(); |
335 |
my $branchcode = $branch->branchcode; |
336 |
my $i = 0; |
337 |
|
338 |
$calendar = Koha::Calendar->new( branchcode => $branchcode ); |
339 |
|
340 |
while ( $date_to_run ne $end_date ) { |
341 |
# printf "\n Treatment of the day : %s \n", $date_to_run; |
342 |
if ( $calendar->is_holiday( $date_to_run ) ) { |
343 |
$i++; |
344 |
} |
345 |
$date_to_run->add( days => 1 ); |
346 |
} |
347 |
push @holidays_by_branch, { 'branchcode' => $branchcode, 'nb_holidays' => $i }; |
348 |
} |
349 |
return @holidays_by_branch; |
350 |
} |
351 |
|
317 |
my $dbh = C4::Context->dbh; |
352 |
my $dbh = C4::Context->dbh; |
318 |
|
353 |
|
319 |
my @available_categories = Koha::Patron::Categories->search()->get_column('categorycode'); |
354 |
my @available_categories = Koha::Patron::Categories->search()->get_column('categorycode'); |
Lines 386-396
foreach my $startrange (sort keys %$lost) {
Link Here
|
386 |
if( my $lostvalue = $lost->{$startrange} ) { |
421 |
if( my $lostvalue = $lost->{$startrange} ) { |
387 |
my ($date1) = bounds($startrange); |
422 |
my ($date1) = bounds($startrange); |
388 |
my ($date2) = bounds( $endrange); |
423 |
my ($date2) = bounds( $endrange); |
|
|
424 |
|
425 |
if ( C4::Context->preference( 'LongOverdueNoticeCalendar' ) ) { |
426 |
get_number_of_holidays( $date2, $date1 ); |
427 |
|
428 |
foreach my $branch ( @holidays_by_branch ) { |
429 |
|
430 |
my $date2_with_holidays = dt_from_string($date2) |
431 |
->subtract( days => $branch->{'nb_holidays'} )->ymd; |
432 |
my $endrange_with_holidays = |
433 |
$endrange + $branch->{'nb_holidays'}; |
434 |
|
435 |
$verbose and |
436 |
printf "\nBranchcode %s\nDue %3s - %3s days ago (%s to %s) - with %s holiday(s), lost => %s\n", $branch->{'branchcode'}, |
437 |
$startrange, $endrange_with_holidays, $date2_with_holidays, $date1, $branch->{'nb_holidays'}, $lostvalue; |
438 |
$sth_items->execute($startrange, $endrange_with_holidays, $lostvalue); |
439 |
} |
440 |
} else { |
441 |
|
389 |
# print "\nRange ", ++$i, "\nDue $startrange - $endrange days ago ($date2 to $date1), lost => $lostvalue\n" if($verbose); |
442 |
# print "\nRange ", ++$i, "\nDue $startrange - $endrange days ago ($date2 to $date1), lost => $lostvalue\n" if($verbose); |
390 |
$verbose and |
443 |
$verbose and |
391 |
printf "\nRange %s\nDue %3s - %3s days ago (%s to %s), lost => %s\n", ++$i, |
444 |
printf "\nRange %s\nDue %3s - %3s days ago (%s to %s), lost => %s\n", ++$i, |
392 |
$startrange, $endrange, $date2, $date1, $lostvalue; |
445 |
$startrange, $endrange, $date2, $date1, $lostvalue; |
393 |
$sth_items->execute($startrange, $endrange, $lostvalue); |
446 |
$sth_items->execute($startrange, $endrange, $lostvalue); |
|
|
447 |
} |
394 |
$count=0; |
448 |
$count=0; |
395 |
ITEM: while (my $row=$sth_items->fetchrow_hashref) { |
449 |
ITEM: while (my $row=$sth_items->fetchrow_hashref) { |
396 |
if( $filter_borrower_categories ) { |
450 |
if( $filter_borrower_categories ) { |
Lines 440-449
sub summarize {
Link Here
|
440 |
} |
494 |
} |
441 |
} |
495 |
} |
442 |
|
496 |
|
443 |
if (!$quiet){ |
497 |
if (!( C4::Context->preference( 'LongOverdueNoticeCalendar' ) )) { |
444 |
print "\n### LONGOVERDUE SUMMARY ###"; |
498 |
if (!$quiet){ |
445 |
summarize (\@report, 1); |
499 |
print "\n### LONGOVERDUE SUMMARY ###"; |
446 |
print "\nTOTAL: $total items\n"; |
500 |
summarize (\@report, 1); |
|
|
501 |
print "\nTOTAL: $total items\n"; |
502 |
} |
447 |
} |
503 |
} |
448 |
|
504 |
|
449 |
cronlogaction({ action => 'End', info => "COMPLETED" }); |
505 |
cronlogaction({ action => 'End', info => "COMPLETED" }); |
450 |
- |
|
|