@@ -, +, @@ calendar support --- ...4-add_LongOverdueNoticeCalendar_syspref.pl | 12 ++++ installer/data/mysql/mandatory/sysprefs.sql | 1 + .../admin/preferences/circulation.pref | 6 ++ misc/cronjobs/longoverdue.pl | 64 +++++++++++++++++-- 4 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_18064-add_LongOverdueNoticeCalendar_syspref.pl --- a/installer/data/mysql/atomicupdate/bug_18064-add_LongOverdueNoticeCalendar_syspref.pl +++ a/installer/data/mysql/atomicupdate/bug_18064-add_LongOverdueNoticeCalendar_syspref.pl @@ -0,0 +1,12 @@ +use Modern::Perl; + +return { + bug_number => "BUG_18064", + description => "Add new system preference LongOverdueNoticeCalendar", + up => sub { + my ($args) = @_; + my ($dbh, $out) = @$args{qw(dbh out)}; + + $dbh->do(q{INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES ('LongOverdueNoticeCalendar', '0', NULL, 'Take the calendar into consideration when generating long overdue notices', 'Yes/No') }); + }, +}; --- a/installer/data/mysql/mandatory/sysprefs.sql +++ a/installer/data/mysql/mandatory/sysprefs.sql @@ -514,6 +514,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('OverDrivePasswordRequired','0',NULL,'Does the library require passwords for OverDrive SIP authentication','YesNo'), ('OverDriveUsername','cardnumber','cardnumber|userid','Which patron information should be passed as OverDrive username','Choice'), ('OverdueNoticeCalendar',0,NULL,'Take the calendar into consideration when generating overdue notices','YesNo'), +('LongOverdueNoticeCalendar',0,NULL,'Take the calendar into consideration when generating long overdue notices','YesNo'), ('OverduesBlockCirc','noblock','noblock|confirmation|block','When checking out an item should overdues block checkout, generate a confirmation dialogue, or allow checkout','Choice'), ('OverduesBlockRenewing','allow','allow|blockitem|block','If any of patron checked out documents is late, should renewal be allowed, blocked only on overdue items or blocked on whatever checked out document','Choice'), ('PassItemMarcToXSLT','0',NULL,'If enabled, item fields in the MARC record will be made avaiable to XSLT sheets. Otherwise they will be removed.','YesNo'), --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref @@ -400,6 +400,12 @@ Circulation: - "Send all notices as a BCC to this email address:" - pref: NoticeBcc class: email + - + - pref: LongOverdueNoticeCalendar + choices: + 1: Use calendar + 0: Ignore calendar + - "when working out the period for long overdue notices." - - pref: OverdueNoticeCalendar choices: --- a/misc/cronjobs/longoverdue.pl +++ a/misc/cronjobs/longoverdue.pl @@ -30,6 +30,8 @@ use warnings; use Getopt::Long qw( GetOptions ); use Pod::Usage qw( pod2usage ); +use DateTime; +use DateTime::Duration; use C4::Circulation qw( LostItem MarkIssueReturned ); use C4::Context; @@ -38,6 +40,9 @@ use Koha::ItemTypes; use Koha::Patron::Categories; use Koha::Patrons; use Koha::Script -cron; +use Koha::Calendar; +use Koha::DateUtils qw( dt_from_string ); + my $lost; # key=lost value, value=num days. my ($charge, $verbose, $confirm, $quiet); @@ -312,6 +317,36 @@ sub longoverdue_sth { return C4::Context->dbh->prepare($query); } +my @holidays_by_branch; + +sub get_number_of_holidays { + my ( $start_date, $end_date ) = @_; + + $start_date = dt_from_string($start_date); + $end_date = dt_from_string($end_date); + + my @branches = Koha::Libraries->search( {}, { order_by => ['branchcode'] } ); + my $calendar; + + foreach my $branch ( @branches ) { + my $date_to_run = $start_date->clone(); + my $branchcode = $branch->branchcode; + my $i = 0; + + $calendar = Koha::Calendar->new( branchcode => $branchcode ); + + while ( $date_to_run ne $end_date ) { + # printf "\n Treatment of the day : %s \n", $date_to_run; + if ( $calendar->is_holiday( $date_to_run ) ) { + $i++; + } + $date_to_run->add( days => 1 ); + } + push @holidays_by_branch, { 'branchcode' => $branchcode, 'nb_holidays' => $i }; + } + return @holidays_by_branch; +} + my $dbh = C4::Context->dbh; my @available_categories = Koha::Patron::Categories->search()->get_column('categorycode'); @@ -384,11 +419,30 @@ foreach my $startrange (sort keys %$lost) { if( my $lostvalue = $lost->{$startrange} ) { my ($date1) = bounds($startrange); my ($date2) = bounds( $endrange); + + if ( C4::Context->preference( 'LongOverdueNoticeCalendar' ) ) { + get_number_of_holidays( $date2, $date1 ); + + foreach my $branch ( @holidays_by_branch ) { + + my $date2_with_holidays = dt_from_string($date2) + ->subtract( days => $branch->{'nb_holidays'} )->ymd; + my $endrange_with_holidays = + $endrange + $branch->{'nb_holidays'}; + + $verbose and + printf "\nBranchcode %s\nDue %3s - %3s days ago (%s to %s) - with %s holiday(s), lost => %s\n", $branch->{'branchcode'}, + $startrange, $endrange_with_holidays, $date2_with_holidays, $date1, $branch->{'nb_holidays'}, $lostvalue; + $sth_items->execute($startrange, $endrange_with_holidays, $lostvalue); + } + } else { + # print "\nRange ", ++$i, "\nDue $startrange - $endrange days ago ($date2 to $date1), lost => $lostvalue\n" if($verbose); $verbose and printf "\nRange %s\nDue %3s - %3s days ago (%s to %s), lost => %s\n", ++$i, $startrange, $endrange, $date2, $date1, $lostvalue; $sth_items->execute($startrange, $endrange, $lostvalue); + } $count=0; ITEM: while (my $row=$sth_items->fetchrow_hashref) { if( $filter_borrower_categories ) { @@ -438,8 +492,10 @@ sub summarize { } } -if (!$quiet){ - print "\n### LONGOVERDUE SUMMARY ###"; - summarize (\@report, 1); - print "\nTOTAL: $total items\n"; +if (!( C4::Context->preference( 'LongOverdueNoticeCalendar' ) )) { + if (!$quiet){ + print "\n### LONGOVERDUE SUMMARY ###"; + summarize (\@report, 1); + print "\nTOTAL: $total items\n"; + } } --