|
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 |
sub get_number_of_holidays { |
| 323 |
my ( $start_date, $end_date ) = @_; |
| 324 |
|
| 325 |
my @holidays_by_branch; |
| 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'] } )->as_list; |
| 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 |
|
| 342 |
# printf "\n Treatment of the day : %s \n", $date_to_run; |
| 343 |
if ( $calendar->is_holiday($date_to_run) ) { |
| 344 |
$i++; |
| 345 |
} |
| 346 |
$date_to_run->add( days => 1 ); |
| 347 |
} |
| 348 |
push @holidays_by_branch, { 'branchcode' => $branchcode, 'nb_holidays' => $i }; |
| 349 |
} |
| 350 |
return @holidays_by_branch; |
| 351 |
} |
| 352 |
|
| 317 |
my $dbh = C4::Context->dbh; |
353 |
my $dbh = C4::Context->dbh; |
| 318 |
|
354 |
|
| 319 |
my @available_categories = Koha::Patron::Categories->search()->get_column('categorycode'); |
355 |
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} ) { |
422 |
if( my $lostvalue = $lost->{$startrange} ) { |
| 387 |
my ($date1) = bounds($startrange); |
423 |
my ($date1) = bounds($startrange); |
| 388 |
my ($date2) = bounds( $endrange); |
424 |
my ($date2) = bounds( $endrange); |
| 389 |
# print "\nRange ", ++$i, "\nDue $startrange - $endrange days ago ($date2 to $date1), lost => $lostvalue\n" if($verbose); |
425 |
|
| 390 |
$verbose and |
426 |
if ( C4::Context->preference('LongOverdueNoticeCalendar') ) { |
| 391 |
printf "\nRange %s\nDue %3s - %3s days ago (%s to %s), lost => %s\n", ++$i, |
427 |
my @holidays_by_branch = get_number_of_holidays( $date2, $date1 ); |
| 392 |
$startrange, $endrange, $date2, $date1, $lostvalue; |
428 |
|
| 393 |
$sth_items->execute($startrange, $endrange, $lostvalue); |
429 |
foreach my $branch (@holidays_by_branch) { |
|
|
430 |
|
| 431 |
my $date2_with_holidays = dt_from_string($date2)->subtract( days => $branch->{'nb_holidays'} )->ymd; |
| 432 |
my $endrange_with_holidays = $endrange + $branch->{'nb_holidays'}; |
| 433 |
|
| 434 |
$verbose |
| 435 |
and printf "\nBranchcode %s\nDue %3s - %3s days ago (%s to %s) - with %s holiday(s), lost => %s\n", |
| 436 |
$branch->{'branchcode'}, |
| 437 |
$startrange, $endrange_with_holidays, $date2_with_holidays, $date1, $branch->{'nb_holidays'}, |
| 438 |
$lostvalue; |
| 439 |
$sth_items->execute( $startrange, $endrange_with_holidays, $lostvalue ); |
| 440 |
} |
| 441 |
} else { |
| 442 |
# print "\nRange ", ++$i, "\nDue $startrange - $endrange days ago ($date2 to $date1), lost => $lostvalue\n" if($verbose); |
| 443 |
$verbose |
| 444 |
and printf "\nRange %s\nDue %3s - %3s days ago (%s to %s), lost => %s\n", ++$i, |
| 445 |
$startrange, $endrange, $date2, $date1, $lostvalue; |
| 446 |
$sth_items->execute( $startrange, $endrange, $lostvalue ); |
| 447 |
} |
| 448 |
|
| 394 |
$count=0; |
449 |
$count=0; |
| 395 |
ITEM: while (my $row=$sth_items->fetchrow_hashref) { |
450 |
ITEM: while (my $row=$sth_items->fetchrow_hashref) { |
| 396 |
if( $filter_borrower_categories ) { |
451 |
if( $filter_borrower_categories ) { |
|
Lines 414-419
foreach my $startrange (sort keys %$lost) {
Link Here
|
| 414 |
} |
469 |
} |
| 415 |
$count++; |
470 |
$count++; |
| 416 |
} |
471 |
} |
|
|
472 |
|
| 417 |
push @report, { |
473 |
push @report, { |
| 418 |
startrange => $startrange, |
474 |
startrange => $startrange, |
| 419 |
endrange => $endrange, |
475 |
endrange => $endrange, |
| 420 |
- |
|
|