From 5ed236177ebb82d2eccb64e8e239ed72d3f64658 Mon Sep 17 00:00:00 2001 From: Mehdi Hamidi Date: Mon, 16 Jan 2017 10:09:23 -0500 Subject: [PATCH] Bug 17015 - Koha now uses the new DiscreteCalendar module --- C4/Circulation.pm | 8 ++++---- C4/HoldsQueue.pm | 8 ++++---- C4/Overdues.pm | 5 +++-- C4/Reserves.pm | 4 ++-- circ/returns.pl | 4 ++-- .../intranet-tmpl/prog/en/modules/tools/tools-home.tt | 5 +++++ misc/cronjobs/fines.pl | 4 ++-- misc/cronjobs/overdue_notices.pl | 18 +++++++----------- misc/cronjobs/staticfines.pl | 4 ++-- misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl | 4 ++-- 10 files changed, 33 insertions(+), 31 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 174b3ac..b5191ad 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -42,7 +42,7 @@ use Data::Dumper; use Koha::Account; use Koha::AuthorisedValues; use Koha::DateUtils; -use Koha::Calendar; +use Koha::DiscreteCalendar; use Koha::Checkouts; use Koha::IssuingRules; use Koha::Items; @@ -1205,7 +1205,7 @@ sub checkHighHolds { my $issuedate = DateTime->now( time_zone => C4::Context->tz() ); - my $calendar = Koha::Calendar->new( branchcode => $branch ); + my $calendar = Koha::DiscreteCalendar->new( branchcode => $branch ); my $itype = ( C4::Context->preference('item-level_itypes') ) @@ -2157,7 +2157,7 @@ sub MarkIssueReturned { my $query = 'UPDATE issues SET returndate='; my @bind; if ($dropbox_branch) { - my $calendar = Koha::Calendar->new( branchcode => $dropbox_branch ); + my $calendar = Koha::DiscreteCalendar->new( branchcode => $dropbox_branch ); my $dropboxdate = $calendar->addDate( DateTime->now( time_zone => C4::Context->tz), -1 ); $query .= ' ? '; push @bind, $dropboxdate->strftime('%Y-%m-%d %H:%M'); @@ -3514,7 +3514,7 @@ sub CalcDateDue { else { # days $dur = DateTime::Duration->new( days => $loanlength->{$length_key}); } - my $calendar = Koha::Calendar->new( branchcode => $branch ); + my $calendar = Koha::DiscreteCalendar->new( branchcode => $branch ); $datedue = $calendar->addDate( $datedue, $dur, $loanlength->{lengthunit} ); if ($loanlength->{lengthunit} eq 'days') { $datedue->set_hour(23); diff --git a/C4/HoldsQueue.pm b/C4/HoldsQueue.pm index 0f2ad22..c632d32 100755 --- a/C4/HoldsQueue.pm +++ b/C4/HoldsQueue.pm @@ -29,7 +29,7 @@ use C4::Circulation; use C4::Members; use C4::Biblio; use Koha::DateUtils; - +use Koha::DiscreteCalendar; use List::Util qw(shuffle); use List::MoreUtils qw(any); use Data::Dumper; @@ -76,7 +76,7 @@ sub TransportCostMatrix { }; if ( C4::Context->preference("HoldsQueueSkipClosed") ) { - $calendars->{$from} ||= Koha::Calendar->new( branchcode => $from ); + $calendars->{$from} ||= Koha::DiscreteCalendar->new( branchcode => $from ); $transport_cost_matrix{$to}{$from}{disable_transfer} ||= $calendars->{$from}->is_holiday( $today ); } @@ -205,7 +205,7 @@ sub CreateQueue { $total_requests += scalar(@$hold_requests); $total_available_items += scalar(@$available_items); - my $item_map = MapItemsToHoldRequests($hold_requests, $available_items, $branches_to_use, $transport_cost_matrix); + my $item_map = MapItemsToHoldRequests($hold_requests, $available_items, $branches_to_use, $transport_cost_matrix); $item_map or next; my $item_map_size = scalar(keys %$item_map) or next; @@ -741,7 +741,7 @@ sub load_branches_to_pull_from { my $today = dt_from_string(); if ( C4::Context->preference('HoldsQueueSkipClosed') ) { @branches_to_use = grep { - !Koha::Calendar->new( branchcode => $_ ) + !Koha::DiscreteCalendar->new( branchcode => $_ ) ->is_holiday( $today ) } @branches_to_use; } diff --git a/C4/Overdues.pm b/C4/Overdues.pm index 8509bfc..31a10c6 100644 --- a/C4/Overdues.pm +++ b/C4/Overdues.pm @@ -34,6 +34,7 @@ use C4::Accounts; use C4::Log; # logaction use C4::Debug; use Koha::DateUtils; +use Koha::DiscreteCalendar; use Koha::Account::Line; use Koha::Account::Lines; use Koha::IssuingRules; @@ -298,7 +299,7 @@ sub get_chargeable_units { my $charge_duration; if ($unit eq 'hours') { if(C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed') { - my $calendar = Koha::Calendar->new( branchcode => $branchcode ); + my $calendar = Koha::DiscreteCalendar->new( branchcode => $branchcode ); $charge_duration = $calendar->hours_between( $date_due, $date_returned ); } else { $charge_duration = $date_returned->delta_ms( $date_due ); @@ -310,7 +311,7 @@ sub get_chargeable_units { } else { # days if(C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed') { - my $calendar = Koha::Calendar->new( branchcode => $branchcode ); + my $calendar = Koha::DiscreteCalendar->new( branchcode => $branchcode ); $charge_duration = $calendar->days_between( $date_due, $date_returned ); } else { $charge_duration = $date_returned->delta_days( $date_due ); diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 3192d50..d142253 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -37,7 +37,7 @@ use C4::Letters; use C4::Log; use Koha::DateUtils; -use Koha::Calendar; +use Koha::DiscreteCalendar; use Koha::Database; use Koha::Hold; use Koha::Old::Hold; @@ -927,7 +927,7 @@ sub CancelExpiredReserves { while ( my $res = $sth->fetchrow_hashref ) { my $do_cancel = 1; unless ( $cancel_on_holidays ) { - my $calendar = Koha::Calendar->new( branchcode => $res->{'branchcode'} ); + my $calendar = Koha::DiscreteCalendar->new( branchcode => $res->{'branchcode'} ); my $is_holiday = $calendar->is_holiday( $today ); if ( $is_holiday ) { diff --git a/circ/returns.pl b/circ/returns.pl index d1b95e8..48c2d51 100755 --- a/circ/returns.pl +++ b/circ/returns.pl @@ -49,7 +49,7 @@ use C4::Koha; # FIXME : is it still useful ? use C4::RotatingCollections; use Koha::AuthorisedValues; use Koha::DateUtils; -use Koha::Calendar; +use Koha::DiscreteCalendar; use Koha::Checkouts; use Koha::BiblioFrameworks; @@ -203,7 +203,7 @@ my $dropboxmode = $query->param('dropboxmode'); my $dotransfer = $query->param('dotransfer'); my $canceltransfer = $query->param('canceltransfer'); my $dest = $query->param('dest'); -my $calendar = Koha::Calendar->new( branchcode => $userenv_branch ); +my $calendar = Koha::DiscreteCalendar->new( branchcode => $userenv_branch ); #dropbox: get last open day (today - 1) my $today = DateTime->now( time_zone => C4::Context->tz()); my $dropboxdate = $calendar->addDate($today, -1); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt index 4c8cca9..3642d4f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt @@ -79,6 +79,11 @@
Define days when the library is closed
[% END %] + [% IF ( CAN_user_tools_edit_calendar ) %] +
Discrete Calendar
+
Define days when the library is closed
+ [% END %] + [% IF ( CAN_user_tools_manage_csv_profiles ) %]
CSV profiles
Manage CSV export profiles
diff --git a/misc/cronjobs/fines.pl b/misc/cronjobs/fines.pl index 6c3f830..d544537 100755 --- a/misc/cronjobs/fines.pl +++ b/misc/cronjobs/fines.pl @@ -36,7 +36,7 @@ use Getopt::Long; use Carp; use File::Spec; -use Koha::Calendar; +use Koha::DiscreteCalendar; use Koha::DateUtils; use C4::Log; @@ -176,7 +176,7 @@ EOM sub set_holiday { my ( $branch, $dt ) = @_; - my $calendar = Koha::Calendar->new( branchcode => $branch ); + my $calendar = Koha::DiscreteCalendar->new( branchcode => $branch ); return $calendar->is_holiday($dt); } diff --git a/misc/cronjobs/overdue_notices.pl b/misc/cronjobs/overdue_notices.pl index cb95ee5..c0a0b92 100755 --- a/misc/cronjobs/overdue_notices.pl +++ b/misc/cronjobs/overdue_notices.pl @@ -40,7 +40,7 @@ use C4::Overdues qw(GetFine GetOverdueMessageTransportTypes parse_overdues_lette use C4::Log; use Koha::Patron::Debarments qw(AddUniqueDebarment); use Koha::DateUtils; -use Koha::Calendar; +use Koha::DiscreteCalendar; use Koha::Libraries; use Koha::Acquisition::Currencies; @@ -443,9 +443,8 @@ elsif ( defined $text_filename ) { } foreach my $branchcode (@branches) { - my $calendar; if ( C4::Context->preference('OverdueNoticeCalendar') ) { - $calendar = Koha::Calendar->new( branchcode => $branchcode ); + my $calendar = Koha::DiscreteCalendar->new( branchcode => $branchcode ); if ( $calendar->is_holiday($date_to_run) ) { next; } @@ -546,13 +545,11 @@ END_SQL my $days_between; if ( C4::Context->preference('OverdueNoticeCalendar') ) { - $days_between = - $calendar->days_between( dt_from_string($data->{date_due}), - $date_to_run ); + my $calendar = Koha::DiscreteCalendar->new( branchcode => $branchcode ); + $days_between = $calendar->days_between( dt_from_string($data->{date_due}), $date_to_run ); } else { - $days_between = - $date_to_run->delta_days( dt_from_string($data->{date_due}) ); + $days_between = $date_to_run->delta_days( dt_from_string($data->{date_due}) ); } $days_between = $days_between->in_units('days'); if ($triggered) { @@ -628,9 +625,8 @@ END_SQL my $exceededPrintNoticesMaxLines = 0; while ( my $item_info = $sth2->fetchrow_hashref() ) { if ( C4::Context->preference('OverdueNoticeCalendar') ) { - $days_between = - $calendar->days_between( - dt_from_string( $item_info->{date_due} ), $date_to_run ); + my $calendar = Koha::DiscreteCalendar->new( branchcode => $branchcode ); + $days_between = $calendar->days_between( dt_from_string( $item_info->{date_due} ), $date_to_run ); } else { $days_between = diff --git a/misc/cronjobs/staticfines.pl b/misc/cronjobs/staticfines.pl index c57e99e..1535790 100755 --- a/misc/cronjobs/staticfines.pl +++ b/misc/cronjobs/staticfines.pl @@ -40,7 +40,7 @@ use Date::Calc qw/Date_to_Days/; use C4::Context; use C4::Circulation; use C4::Overdues; -use C4::Calendar qw(); # don't need any exports from Calendar +use Koha::DiscreteCalendar qw(); # don't need any exports from Calendar use C4::Biblio; use C4::Debug; # supplying $debug and $cgi_debug use C4::Log; @@ -176,7 +176,7 @@ for ( my $i = 0 ; $i < scalar(@$data) ; $i++ ) { my $calendar; unless ( defined( $calendars{$branchcode} ) ) { - $calendars{$branchcode} = C4::Calendar->new( branchcode => $branchcode ); + $calendars{$branchcode} = Koha::DiscreteCalendar->new( branchcode => $branchcode ); } $calendar = $calendars{$branchcode}; my $isHoliday = $calendar->isHoliday( $tday, $tmonth, $tyear ); diff --git a/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl b/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl index 1299b7d..7138c15 100755 --- a/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl +++ b/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl @@ -35,7 +35,7 @@ use C4::Context; use C4::Items; use C4::Letters; use C4::Overdues; -use Koha::Calendar; +use Koha::DiscreteCalendar; use Koha::DateUtils; sub usage { @@ -291,7 +291,7 @@ sub GetWaitingHolds { $sth->execute(); my @results; while ( my $issue = $sth->fetchrow_hashref() ) { - my $calendar = Koha::Calendar->new( branchcode => $issue->{'site'} ); + my $calendar = Koha::DiscreteCalendar->new( branchcode => $issue->{'site'} ); my $waiting_date = dt_from_string( $issue->{waitingdate}, 'sql' ); my $pickup_date = $waiting_date->clone->add( days => $pickupdelay ); -- 1.9.1