Bugzilla – Attachment 193658 Details for
Bug 17015
New Koha Calendar
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17015: DiscreteCalendar UI, Back-End and necessary scripts
Bug-17015-DiscreteCalendar-UI-Back-End-and-necessa.patch (text/plain), 134.71 KB, created by
Hammat wele
on 2026-02-23 17:45:23 UTC
(
hide
)
Description:
Bug 17015: DiscreteCalendar UI, Back-End and necessary scripts
Filename:
MIME Type:
Creator:
Hammat wele
Created:
2026-02-23 17:45:23 UTC
Size:
134.71 KB
patch
obsolete
>From aad01df68bf89ba1247db3cb992f58aaf355efb6 Mon Sep 17 00:00:00 2001 >From: Charles Farmer <charles.farmer@inLibro.com> >Date: Wed, 4 Sep 2019 14:56:01 -0400 >Subject: [PATCH] Bug 17015: DiscreteCalendar UI, Back-End and necessary > scripts > >Replace the current Calendar. Use Discrete Calendar in Tools->Calendar. > >TEST PLAN: >1- Apply the patch >2- Run installer/data/mysql/updatedatabase.pl >3- Run misc/cronjobs/add_days_discrete_calendar.pl >4- Check that the max date is today + 1 day >5- Run t/db_dependent/DiscreteCalendar.t (prove -l t/db_dependent/DiscreteCalendar.t) >6- Run all koha test in t/ (prove t). All tests should pass > >USING THE DISCRETE CALENDAR: >1- New UI > a) Calendar on the left > b) Holidays list on the right >2- New color system for holiday types: > a) Working day : white > b) Unique holiday: red > c) Holiday repeating weekly: yellow > d) Holiday repeating yearly: orange > e) Floating holiday: green > f) Need validation: blue >3- When clicking on a date in the calendar, opening, closing hours and holiday type are displayed. >4- All the fields are editable >5- New radio button to Edit selected dates or Copy to different dates >6- Option to copy the calendar to another branch >--- > C4/Circulation.pm | 15 +- > C4/HoldsQueue.pm | 9 +- > C4/Overdues.pm | 4 +- > C4/Reserves.pm | 4 +- > Koha/Charges/Fees.pm | 4 +- > Koha/Checkouts.pm | 4 +- > Koha/CurbsidePickup.pm | 4 +- > Koha/DiscreteCalendar.pm | 1399 +++++++++++++++++ > Koha/Hold.pm | 6 +- > Koha/Patron.pm | 2 +- > Koha/Schema/Result/DiscreteCalendar.pm | 12 +- > admin/branches.pl | 3 + > circ/returns.pl | 1 - > .../intranet-tmpl/prog/css/src/calendar.scss | 44 + > .../prog/en/includes/tools-menu.inc | 2 +- > .../en/modules/tools/discrete_calendar.tt | 809 ++++++++++ > .../prog/en/modules/tools/tools-home.tt | 2 +- > misc/cronjobs/add_days_discrete_calendar.pl | 166 ++ > misc/cronjobs/fines.pl | 4 +- > misc/cronjobs/holds/cancel_unfilled_holds.pl | 3 +- > misc/cronjobs/holds/holds_reminder.pl | 4 +- > misc/cronjobs/overdue_notices.pl | 4 +- > misc/cronjobs/staticfines.pl | 4 +- > .../thirdparty/TalkingTech_itiva_outbound.pl | 4 +- > .../benchmark_checkins.pl | 0 > tools/discrete_calendar.pl | 171 ++ > tools/exceptionHolidays.pl | 206 --- > 27 files changed, 2646 insertions(+), 244 deletions(-) > create mode 100644 Koha/DiscreteCalendar.pm > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/tools/discrete_calendar.tt > create mode 100755 misc/cronjobs/add_days_discrete_calendar.pl > mode change 100644 => 100755 tmp/DiscreteCalendar_performance/benchmark_checkins.pl > create mode 100755 tools/discrete_calendar.pl > delete mode 100755 tools/exceptionHolidays.pl > >diff --git a/C4/Circulation.pm b/C4/Circulation.pm >index 9fa3c9e8745..e5253a12443 100644 >--- a/C4/Circulation.pm >+++ b/C4/Circulation.pm >@@ -102,7 +102,7 @@ use Koha::AuthorisedValues; > use Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue; > use Koha::Biblioitems; > use Koha::DateUtils qw( dt_from_string ); >-use Koha::Calendar; >+use Koha::DiscreteCalendar; > use Koha::Checkouts; > use Koha::ILL::Requests; > use Koha::Items; >@@ -1527,7 +1527,7 @@ sub checkHighHolds { > branchcode => $branchcode, > } > ); >- my $calendar = Koha::Calendar->new( branchcode => $branchcode, days_mode => $daysmode ); >+ my $calendar = Koha::DiscreteCalendar->new({ branchcode => $branchcode, days_mode => $daysmode }); > > my $orig_due = C4::Circulation::CalcDateDue( $issuedate, $itype, $branchcode, $patron ); > >@@ -2984,10 +2984,10 @@ sub _calculate_new_debar_dt { > > # Use the calendar or not to calculate the debarment date > if ( C4::Context->preference('SuspensionsCalendar') eq 'noSuspensionsWhenClosed' ) { >- my $calendar = Koha::Calendar->new( >+ my $calendar = Koha::DiscreteCalendar->new({ > branchcode => $branchcode, > days_mode => 'Calendar' >- ); >+ }); > $new_debar_dt = $calendar->addDuration( $return_date, $suspension_days ); > } else { > $new_debar_dt = $return_date->clone()->add_duration($suspension_days); >@@ -4266,7 +4266,7 @@ sub CalcDateDue { > } else { # days > $dur = DateTime::Duration->new( days => $loanlength->{$length_key} ); > } >- my $calendar = Koha::Calendar->new( branchcode => $branch, days_mode => $daysmode ); >+ my $calendar = Koha::DiscreteCalendar->new({ branchcode => $branch, days_mode => $daysmode }); > $datedue = $calendar->addDuration( $datedue, $dur, $loanlength->{lengthunit} ) if $dur; > if ( $loanlength->{lengthunit} eq 'days' ) { > $datedue->set_hour(23); >@@ -4304,15 +4304,14 @@ sub CalcDateDue { > } > } > if ( $daysmode ne 'Days' ) { >- my $calendar = Koha::Calendar->new( branchcode => $branch, days_mode => $daysmode ); >+ my $calendar = Koha::DiscreteCalendar->new({ branchcode => $branch, days_mode => $daysmode }); > if ( $calendar->is_holiday($datedue) ) { > > # Don't return on a closed day >- $datedue = $calendar->prev_open_days( $datedue, 1 ); >+ $datedue = $calendar->prev_open_day( $datedue )->set(hour => 23, minute => 59); > } > } > } >- > return $datedue; > } > >diff --git a/C4/HoldsQueue.pm b/C4/HoldsQueue.pm >index c1d46954d1d..4bcb0797fcf 100644 >--- a/C4/HoldsQueue.pm >+++ b/C4/HoldsQueue.pm >@@ -77,6 +77,13 @@ sub TransportCostMatrix { > cost => $cost, > disable_transfer => $disabled > }; >+ >+ if ( !my $ignore_holds_queue_skip_closed && C4::Context->preference("HoldsQueueSkipClosed") ) { >+ my $calendars->{$from} ||= Koha::DiscreteCalendar->new({ branchcode => $from }); >+ $transport_cost_matrix{$to}{$from}{disable_transfer} ||= >+ $calendars->{$from}->is_holiday( $today ); >+ } >+ > } > > return \%transport_cost_matrix; >@@ -1163,7 +1170,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 => $_ )->is_holiday($today) } @branches_to_use; >+ @branches_to_use = grep { !Koha::DiscreteCalendar->new({ branchcode => $_ })->is_holiday($today) } @branches_to_use; > } > > return \@branches_to_use; >diff --git a/C4/Overdues.pm b/C4/Overdues.pm >index 33776e4a146..2ffbfefb63e 100644 >--- a/C4/Overdues.pm >+++ b/C4/Overdues.pm >@@ -348,7 +348,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); >@@ -359,7 +359,7 @@ sub get_chargeable_units { > return $charge_duration->in_units('hours'); > } 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 de50ce5c930..844ed0e284c 100644 >--- a/C4/Reserves.pm >+++ b/C4/Reserves.pm >@@ -76,11 +76,11 @@ use C4::Members; > use Koha::Account::Lines; > use Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue; > use Koha::Biblios; >-use Koha::Calendar; > use Koha::Cache::Memory::Lite; > use Koha::CirculationRules; > use Koha::Database; > use Koha::DateUtils qw( dt_from_string output_pref ); >+use Koha::DiscreteCalendar; > use Koha::Holds; > use Koha::HoldGroup; > use Koha::ItemTypes; >@@ -1012,7 +1012,7 @@ sub CancelExpiredReserves { > my $cache_key = sprintf "Calendar_CancelExpiredReserves:%s", $hold->branchcode; > my $calendar = $cache->get_from_cache($cache_key); > if ( !$calendar ) { >- $calendar = Koha::Calendar->new( branchcode => $hold->branchcode ); >+ my $calendar = Koha::DiscreteCalendar->new({ branchcode => $hold->branchcode }); > $cache->set_in_cache( $cache_key, $calendar ); > } > >diff --git a/Koha/Charges/Fees.pm b/Koha/Charges/Fees.pm >index 53ff799d1cf..db49a2d90ca 100644 >--- a/Koha/Charges/Fees.pm >+++ b/Koha/Charges/Fees.pm >@@ -21,7 +21,7 @@ use Modern::Perl; > > use Carp; > >-use Koha::Calendar; >+use Koha::DiscreteCalendar; > use Koha::DateUtils qw( dt_from_string ); > use Koha::Exceptions; > >@@ -108,7 +108,7 @@ sub accumulate_rentalcharge { > return 0 unless $rentalcharge_increment && $rentalcharge_increment > 0; > > my $duration; >- my $calendar = Koha::Calendar->new( branchcode => $self->library->id ); >+ my $calendar = Koha::DiscreteCalendar->new({ branchcode => $self->library->id }); > > if ( $units eq 'hours' ) { > if ( $itemtype->rentalcharge_hourly_calendar ) { >diff --git a/Koha/Checkouts.pm b/Koha/Checkouts.pm >index 11a97d9e60e..2e2d2593501 100644 >--- a/Koha/Checkouts.pm >+++ b/Koha/Checkouts.pm >@@ -55,9 +55,11 @@ sub calculate_dropbox_date { > branchcode => $branchcode, > } > ); >- my $calendar = Koha::Calendar->new( branchcode => $branchcode, days_mode => $daysmode ); >+ my $calendar = Koha::DiscreteCalendar->new({ branchcode => $branchcode, days_mode => $daysmode }); > my $today = dt_from_string; > my $dropbox_date = $calendar->addDuration( $today, -1 ); >+ my $dateInfo = $calendar->get_date_info($dropbox_date); >+ $dropbox_date = dt_from_string($dateInfo->{date} ." ". $dateInfo->{close_hour}, 'iso', C4::Context->tz()); > > return $dropbox_date; > } >diff --git a/Koha/CurbsidePickup.pm b/Koha/CurbsidePickup.pm >index 01d1b88d10b..bcf56518570 100644 >--- a/Koha/CurbsidePickup.pm >+++ b/Koha/CurbsidePickup.pm >@@ -26,7 +26,7 @@ use base qw(Koha::Object); > use C4::Circulation qw( CanBookBeIssued AddIssue ); > use C4::Members::Messaging qw( GetMessagingPreferences ); > use C4::Letters qw( GetPreparedLetter EnqueueLetter ); >-use Koha::Calendar; >+use Koha::DiscreteCalendar; > use Koha::DateUtils qw( dt_from_string ); > use Koha::Patron; > use Koha::Library; >@@ -56,7 +56,7 @@ sub new { > Koha::Exceptions::CurbsidePickup::NotEnabled->throw > unless $policy && $policy->enabled; > >- my $calendar = Koha::Calendar->new( branchcode => $params->{branchcode} ); >+ my $calendar = Koha::DiscreteCalendar->new({ branchcode => $params->{branchcode} }); > Koha::Exceptions::CurbsidePickup::LibraryIsClosed->throw > if $calendar->is_holiday( $params->{scheduled_pickup_datetime} ); > >diff --git a/Koha/DiscreteCalendar.pm b/Koha/DiscreteCalendar.pm >new file mode 100644 >index 00000000000..178e2b1dfe5 >--- /dev/null >+++ b/Koha/DiscreteCalendar.pm >@@ -0,0 +1,1399 @@ >+package Koha::DiscreteCalendar; >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+#####Sets holiday periods for each branch. Datedues will be extended if branch is closed -TG >+use Modern::Perl; >+ >+use CGI qw ( -utf8 ); >+use Carp; >+use DateTime; >+use DateTime::Format::Strptime; >+use Data::Dumper; >+ >+use C4::Context; >+use C4::Output; >+use Koha::Database; >+use Koha::DateUtils qw ( dt_from_string output_pref ); >+ >+# Global variables to make code more readable >+our $HOLIDAYS = { >+ EXCEPTION => 'E', >+ REPEATABLE => 'R', >+ SINGLE => 'S', >+ NEED_VALIDATION => 'N', >+ FLOAT => 'F', >+ WEEKLY => 'W', >+ NONE => 'none' >+}; >+ >+=head1 NAME >+ >+Koha::DiscreteCalendar - Object containing a branches calendar, working with the SQL database >+ >+=head1 SYNOPSIS >+ >+ use Koha::DiscreteCalendar >+ >+ my $c = Koha::DiscreteCalendar->new({ branchcode => 'MAIN' }); >+ my $dt = dt_from_string(); >+ >+ # are we open >+ $open = $c->is_holiday($dt); >+ # when will item be due if loan period = $dur (a DateTime::Duration object) >+ $duedate = $c->addDuration($dt, $dur, 'days'); >+ >+ >+=head1 DESCRIPTION >+ >+ Implements a new Calendar object, but uses the SQL database to keep track of days and holidays. >+ This results in a performance gain since the optimization is done by the MySQL database/team. >+ >+=head1 METHODS >+ >+=head2 new : Create a (discrete) calendar object >+ >+my $calendar = Koha::DiscreteCalendar->new({ branchcode => 'MAIN' }); >+ >+The option branchcode is required >+ >+=cut >+ >+sub new { >+ my ( $classname, $options ) = @_; >+ my $self = {}; >+ bless $self, $classname; >+ for my $o_name ( keys %{ $options } ) { >+ my $o = lc $o_name; >+ $self->{$o} = $options->{$o_name}; >+ } >+ if ( !defined $self->{branchcode} ) { >+ croak 'No branchcode argument passed to Koha::DiscreteCalendar->new'; >+ } >+ if ( ref $self->{branchcode} eq 'Koha::Library' ) { >+ $self->{branchcode} = $self->{branchcode}->branchcode; >+ } >+ $self->_init(); >+ >+ return $self; >+} >+ >+sub _init { >+ my $self = shift; >+ $self->{days_mode} ||= C4::Context->preference('useDaysMode'); >+ #If the branchcode doesn't exist we use the default calendar. >+ my $schema = Koha::Database->new->schema; >+ my $branchcode = $self->{branchcode}; >+ my $dtf = $schema->storage->datetime_parser; >+ my $today = $dtf->format_datetime(DateTime->today); >+ my $rs = $schema->resultset('DiscreteCalendar')->single( >+ { >+ branchcode => $branchcode, >+ date => $today >+ } >+ ); >+ #use default if no calendar is found >+ if (!$rs) { >+ $self->{branchcode} = undef; >+ $self->{no_branch_selected} = 1; >+ } >+ >+} >+ >+=head2 get_dates_info >+ >+ my @dates = $calendar->get_dates_info(); >+ >+Returns an array of hashes representing the dates in this calendar. The hash >+contains the fields C<$date>, C<$outputdate>, C<$holiday_type>, C<$open_hour>, >+C<$close_hour> and C<$note>. >+ >+=cut >+ >+sub get_dates_info { >+ my $self = shift; >+ my $branchcode = $self->{branchcode}; >+ my @datesInfos =(); >+ my $schema = Koha::Database->new->schema; >+ >+ my $rs = $schema->resultset('DiscreteCalendar')->search( >+ { >+ branchcode => $branchcode >+ }, >+ { >+ select => [ 'date', { DATE => 'date' } ], >+ as => [qw/ date date /], >+ columns =>[ qw/ holiday_type open_hour close_hour note description/] >+ }, >+ ); >+ >+ while (my $date = $rs->next()) { >+ my $outputdate = dt_from_string( $date->date(), 'iso'); >+ $outputdate = output_pref( { dt => $outputdate, dateonly => 1 } ); >+ push @datesInfos, { >+ date => $date->date(), >+ outputdate => $outputdate, >+ holiday_type => $date->holiday_type() , >+ open_hour => $date->open_hour(), >+ close_hour => $date->close_hour(), >+ note => $date->note(), >+ description => $date->description(), >+ }; >+ } >+ >+ return @datesInfos; >+} >+ >+=head2 add_new_branch >+ >+ Koha::DiscreteCalendar->add_new_branch($copyBranch, $newBranch) >+ >+This method will copy everything from a given branch to a new branch >+C<$copyBranch> is the branch to copy from >+C<$newBranch> is the branch to be created, and copy into >+ >+=cut >+ >+sub add_new_branch { >+ my ( $classname, $copyBranch, $newBranch) = @_; >+ >+ my $schema = Koha::Database->new->schema; >+ >+ my $branch_rs = $schema->resultset('DiscreteCalendar')->search({ >+ branchcode => $copyBranch >+ }); >+ >+ unless ($branch_rs->count) { >+ $copyBranch = $schema->resultset('DiscreteCalendar')->next->branchcode; >+ $branch_rs = $schema->resultset('DiscreteCalendar')->search({ >+ branchcode => $copyBranch >+ }); >+ } >+ >+ $schema->{AutoCommit} = 0; >+ $schema->storage->txn_begin; >+ >+ while (my $row = $branch_rs->next()) { >+ $schema->resultset('DiscreteCalendar')->create({ >+ date => $row->date(), >+ branchcode => $newBranch, >+ is_opened => $row->is_opened(), >+ holiday_type => $row->holiday_type(), >+ open_hour => $row->open_hour(), >+ close_hour => $row->close_hour(), >+ }); >+ } >+ >+ eval { $schema->storage->txn_commit; }; >+ >+ if ($@) { >+ $schema->storage->rollback; >+ } >+ >+ $schema->{AutoCommit} = 1; >+} >+ >+=head2 delete_branch >+ >+ Koha::DiscreteCalendar->delete_branch($branchcode) >+ >+This method will delete every discrete_calendar entry for a given branch >+C<$branchcode> is the code of the branch we want to remove from the table >+ >+=cut >+ >+sub delete_branch { >+ my ( $classname, $branchcode ) = @_; >+ >+ my $schema = Koha::Database->new->schema; >+ >+ my $branch_rs = $schema->resultset('DiscreteCalendar')->search({ >+ branchcode => $branchcode >+ }); >+ >+ if ($branch_rs->count) { >+ $branch_rs->delete; >+ } >+} >+ >+ >+=head2 get_date_info >+ >+ my $date = $calendar->get_date_info; >+ >+Returns a reference-to-hash representing a DiscreteCalendar date data object. >+The hash contains the fields C<$date>, C<$outputdate>, C<$holiday_type>, >+C<$open_hour>, C<$close_hour> and C<$note>. >+ >+=cut >+ >+sub get_date_info { >+ my ($self, $date) = @_; >+ my $branchcode = $self->{branchcode}; >+ my $schema = Koha::Database->new->schema; >+ my $dtf = $schema->storage->datetime_parser; >+ #String dates for Database usage >+ my $date_string = $dtf->format_datetime($date); >+ >+ my $rs = $schema->resultset('DiscreteCalendar')->search( >+ { >+ branchcode => $branchcode, >+ }, >+ { >+ select => [ 'date', { DATE => 'date' } ], >+ as => [qw/ date date /], >+ where => \['DATE(?) = date', $date_string ], >+ columns =>[ qw/ branchcode holiday_type open_hour close_hour note description/] >+ }, >+ ); >+ my $dateDTO; >+ while (my $date = $rs->next()) { >+ $dateDTO = { >+ date => $date->date(), >+ branchcode => $date->branchcode(), >+ holiday_type => $date->holiday_type() , >+ open_hour => $date->open_hour(), >+ close_hour => $date->close_hour(), >+ note => $date->note(), >+ description => $date->description(), >+ }; >+ } >+ >+ return $dateDTO; >+} >+ >+=head2 get_max_date >+ >+ my $maxDate = $calendar->get_max_date(); >+ >+Returns the furthest date available in the database of current branch. >+ >+=cut >+ >+sub get_max_date { >+ my $self = shift; >+ my $branchcode = $self->{branchcode}; >+ my $schema = Koha::Database->new->schema; >+ >+ my $rs = $schema->resultset('DiscreteCalendar')->search( >+ { >+ branchcode => $branchcode >+ }, >+ { >+ select => [{ MAX => 'date' } ], >+ as => [qw/ max /], >+ } >+ ); >+ >+ return $rs->next()->get_column('max'); >+} >+ >+=head2 get_min_date >+ >+ my $minDate = $calendar->get_min_date(); >+ >+Returns the oldest date available in the database of current branch. >+ >+=cut >+ >+sub get_min_date { >+ my $self = shift; >+ my $branchcode = $self->{branchcode}; >+ my $schema = Koha::Database->new->schema; >+ >+ my $rs = $schema->resultset('DiscreteCalendar')->search( >+ { >+ branchcode => $branchcode >+ }, >+ { >+ select => [{ MIN => 'date' } ], >+ as => [qw/ min /], >+ } >+ ); >+ >+ return $rs->next()->get_column('min'); >+} >+ >+=head2 get_unique_holidays >+ >+ my @unique_holidays = $calendar->get_unique_holidays(); >+ >+Returns an array of all the date objects that are unique holidays. >+ >+=cut >+ >+sub get_unique_holidays { >+ my $self = shift; >+ my $exclude_past = shift // 1; >+ my $branchcode = $self->{branchcode}; >+ my @unique_holidays; >+ my $schema = Koha::Database->new->schema; >+ >+ my $rs = $schema->resultset('DiscreteCalendar')->search( >+ { >+ branchcode => $branchcode, >+ holiday_type => $HOLIDAYS->{EXCEPTION} >+ }, >+ { >+ select => [{ DATE => 'date' }, 'note', 'description' ], >+ as => [qw/ date note description/], >+ where => ($exclude_past ? \[' date >= CURRENT_DATE()'] : {} ), >+ } >+ ); >+ while (my $date = $rs->next()) { >+ my $outputdate = dt_from_string($date->date(), 'iso'); >+ $outputdate = output_pref( { dt => $outputdate, dateonly => 1 } ); >+ push @unique_holidays, { >+ date => $date->date(), >+ outputdate => $outputdate, >+ note => $date->note(), >+ description => $date->description(), >+ } >+ } >+ >+ return @unique_holidays; >+} >+ >+=head2 get_float_holidays >+ >+ my @float_holidays = $calendar->get_float_holidays(); >+ >+Returns an array of all the date objects that are float holidays. >+ >+=cut >+ >+sub get_float_holidays { >+ my $self = shift; >+ my $exclude_past = shift // 1; >+ my $branchcode = $self->{branchcode}; >+ my @float_holidays; >+ my $schema = Koha::Database->new->schema; >+ >+ my $rs = $schema->resultset('DiscreteCalendar')->search( >+ { >+ branchcode => $branchcode, >+ holiday_type => $HOLIDAYS->{FLOAT} >+ }, >+ { >+ select => [{ DATE => 'date' }, 'note', 'description' ], >+ as => [qw/ date note description/], >+ where => ($exclude_past ? \[' date >= CURRENT_DATE()'] : {} ), >+ } >+ ); >+ while (my $date = $rs->next()) { >+ my $outputdate = dt_from_string($date->date(), 'iso'); >+ $outputdate = output_pref( { dt => $outputdate, dateonly => 1 } ); >+ push @float_holidays, { >+ date => $date->date(), >+ outputdate => $outputdate, >+ note => $date->note(), >+ description => $date->description(), >+ } >+ } >+ >+ return @float_holidays; >+} >+ >+=head2 get_need_validation_holidays >+ >+ my @need_validation_holidays = $calendar->get_need_validation_holidays(); >+ >+Returns an array of all the date objects that are float holidays in need of validation. >+ >+=cut >+ >+sub get_need_validation_holidays { >+ my $self = shift; >+ my $exclude_past = shift // 1; >+ my $branchcode = $self->{branchcode}; >+ my @need_validation_holidays; >+ my $schema = Koha::Database->new->schema; >+ >+ my $rs = $schema->resultset('DiscreteCalendar')->search( >+ { >+ branchcode => $branchcode, >+ holiday_type => $HOLIDAYS->{NEED_VALIDATION} >+ }, >+ { >+ select => [{ DATE => 'date' }, 'note', 'description' ], >+ as => [qw/ date note description/], >+ where => ($exclude_past ? \[' date >= CURRENT_DATE()'] : {} ), >+ } >+ ); >+ while (my $date = $rs->next()) { >+ my $outputdate = dt_from_string($date->date(), 'iso'); >+ $outputdate = output_pref( { dt => $outputdate, dateonly => 1 } ); >+ push @need_validation_holidays, { >+ date => $date->date(), >+ outputdate => $outputdate, >+ note => $date->note(), >+ description => $date->description(), >+ } >+ } >+ >+ return @need_validation_holidays; >+} >+ >+=head2 get_repeatable_holidays >+ >+ my @repeatable_holidays = $calendar->get_repeatable_holidays(); >+ >+Returns an array of all the date objects that are repeatable holidays. >+ >+=cut >+ >+sub get_repeatable_holidays { >+ my $self = shift; >+ my $exclude_past = shift // 1; >+ my $branchcode = $self->{branchcode}; >+ my @repeatable_holidays; >+ my $schema = Koha::Database->new->schema; >+ >+ my $rs = $schema->resultset('DiscreteCalendar')->search( >+ { >+ branchcode => $branchcode, >+ holiday_type => $HOLIDAYS->{'REPEATABLE'}, >+ >+ }, >+ { >+ select => \[ 'distinct DAY(date), MONTH(date), note, description'], >+ as => [qw/ day month note description/], >+ where => ($exclude_past ? \[' date >= CURRENT_DATE()'] : {} ), >+ } >+ ); >+ >+ while (my $date = $rs->next()) { >+ push @repeatable_holidays, { >+ day => $date->get_column('day'), >+ month => $date->get_column('month'), >+ note => $date->note(), >+ description => $date->description(), >+ }; >+ } >+ >+ return @repeatable_holidays; >+} >+ >+=head2 get_week_days_holidays >+ >+ my @week_days_holidays = $calendar->get_week_days_holidays; >+ >+Returns an array of all the date objects that are weekly holidays. >+ >+=cut >+ >+sub get_week_days_holidays { >+ my $self = shift; >+ my $exclude_past = shift // 1; >+ my $branchcode = $self->{branchcode}; >+ my @week_days; >+ my $schema = Koha::Database->new->schema; >+ >+ my $rs = $schema->resultset('DiscreteCalendar')->search( >+ { >+ holiday_type => $HOLIDAYS->{WEEKLY}, >+ branchcode => $branchcode, >+ }, >+ { >+ select => \[ 'distinct DAYOFWEEK(date), note, description'], >+ as => [qw/ weekday note description /], >+ where => ($exclude_past ? \[' date >= CURRENT_DATE()'] : {} ), >+ } >+ ); >+ >+ while (my $date = $rs->next()) { >+ push @week_days, { >+ weekday => $date->get_column('weekday'), >+ note => $date->note(), >+ description => $date->description(), >+ }; >+ } >+ >+ return @week_days; >+} >+ >+=head2 edit_holiday >+ >+Modifies a date or a range of dates >+ >+C<$title> Is the title to be modified for the holiday formed by $year/$month/$day. >+ >+C<$weekday> Is the day of week for the holiday or the value everyday when it's for the whole range. >+ >+C<$holiday_type> Is the type of the holiday : >+ E : Exception holiday, single day. >+ F : Floating holiday, different day each year. >+ N : Needs validation, copied float holiday from the past >+ R : Repeatable holiday, repeated on same date. >+ W : Weekly holiday, same day of the week. >+ >+C<$open_hour> Is the opening hour. >+C<$close_hour> Is the closing hour. >+C<$start_date> Is the start of the range of dates. >+C<$end_date> Is the end of the range of dates. >+C<$delete_type> Delete all >+C<$today> Today based on the local date, using JavaScript. >+ >+=cut >+ >+sub edit_holiday { >+ my $self = shift; >+ my ($params) = @_; >+ >+ my $title = $params->{title}; >+ my $description = $params->{description}; >+ my $weekday = $params->{weekday} || ''; >+ my $holiday_type = $params->{holiday_type}; >+ >+ my $start_date = $params->{start_date}; >+ my $end_date = $params->{end_date}; >+ >+ my $open_hour = $params->{open_hour} || ''; >+ my $close_hour = $params->{close_hour} || ''; >+ >+ my $delete_type = $params->{delete_type} || undef; >+ my $all_branches = $params->{all_branches} // 0; >+ my $today = $params->{today} || dt_from_string()->truncate( to => 'day' ); >+ >+ # When override param is set, this function will allow past dates to be set as holidays, >+ # otherwise it will not. This is meant to only be used for testing. >+ my $override = $params->{override} || 0; >+ >+ my $schema = Koha::Database->new->schema; >+ $schema->{AutoCommit} = 0; >+ $schema->storage->txn_begin; >+ my $dtf = DateTime::Format::Strptime->new(pattern => "%F %T"); >+ >+ #String dates for Database usage >+ my $start_date_string = $dtf->format_datetime($start_date->clone->truncate(to => 'day')); >+ my $end_date_string = $dtf->format_datetime($end_date->clone->truncate(to => 'day')); >+ $today = $dtf->format_datetime($today->clone->truncate(to => 'day')); >+ my %updateValues = ( >+ is_opened => 0, >+ note => $title, >+ description => $description, >+ holiday_type => $holiday_type, >+ ); >+ $updateValues{open_hour} = $open_hour if $open_hour ne ''; >+ $updateValues{close_hour} = $close_hour if $close_hour ne ''; >+ >+ my $limits = ( $all_branches ) ? {} : { branchcode => $self->{branchcode} }; >+ >+ if ($holiday_type eq $HOLIDAYS->{WEEKLY}) { >+ #Update weekly holidays >+ if ($start_date_string eq $end_date_string) { >+ $end_date_string = $self->get_max_date(); >+ } >+ my $rs = $schema->resultset('DiscreteCalendar')->search( >+ $limits, >+ { >+ where => \[ 'DAYOFWEEK(date) = ? AND date >= DATE(?) AND date <= DATE(?)', $weekday, $start_date_string, $end_date_string], >+ } >+ ); >+ >+ while (my $date = $rs->next()) { >+ $date->update(\%updateValues); >+ } >+ } elsif ($holiday_type eq $HOLIDAYS->{EXCEPTION} || $holiday_type eq $HOLIDAYS->{FLOAT} || $holiday_type eq $HOLIDAYS->{NEED_VALIDATION}) { >+ #Update Exception Float and Needs Validation holidays >+ my $where = { date => { -between => [$start_date_string, $end_date_string]}}; >+ if ($start_date_string ne $end_date_string && $weekday && $weekday ne 'everyday') { >+ $where = {-and => [ \["DAYOFWEEK(date) = ?", $weekday], date => { -between => [$start_date_string, $end_date_string]}]}; >+ } >+ $where->{date}{'>='} = $today unless $override; >+ >+ my $rs = $schema->resultset('DiscreteCalendar')->search( >+ $limits, >+ { >+ where => $where, >+ } >+ ); >+ while (my $date = $rs->next()) { >+ $date->update(\%updateValues); >+ } >+ >+ } elsif ($holiday_type eq $HOLIDAYS->{REPEATABLE}) { >+ #Update repeatable holidays >+ my $parser = DateTime::Format::Strptime->new( >+ pattern => '%m-%d', >+ on_error => 'croak', >+ ); >+ #Format the dates to have only month-day ex: 01-04 for January 4th >+ $start_date = $parser->format_datetime($start_date); >+ $end_date = $parser->format_datetime($end_date); >+ my $where = { -and => [ \["(DATE_FORMAT(date, '\%m-\%d') BETWEEN ? AND ?)", $start_date, $end_date] ] }; >+ push @{$where->{'-and'}}, { 'date' => { '>=' => $today } } unless $override; >+ my $rs = $schema->resultset('DiscreteCalendar')->search( >+ $limits, >+ { >+ where => $where, >+ } >+ ); >+ while (my $date = $rs->next()) { >+ $date->update(\%updateValues); >+ } >+ >+ } else { >+ #Update date(s)/Remove holidays >+ my $where = { date => { -between => [$start_date_string, $end_date_string]}}; >+ if ($start_date_string ne $end_date_string && $weekday && $weekday ne 'everyday') { >+ $where = {-and => [ \["DAYOFWEEK(date) = ?", $weekday], date => { -between => [$start_date_string, $end_date_string]}]}; >+ } >+ $where->{date}{'>='} = $today unless $override; >+ >+ my $rs = $schema->resultset('DiscreteCalendar')->search( >+ $limits, >+ { >+ where => $where, >+ } >+ ); >+ #If none, the date(s) will be normal days, else, >+ if ($holiday_type eq 'none') { >+ $updateValues{holiday_type} =''; >+ $updateValues{is_opened} =1; >+ } else { >+ delete $updateValues{holiday_type}; >+ delete $updateValues{is_opened}; >+ } >+ >+ while (my $date = $rs->next()) { >+ if ($delete_type) { >+ if ($date->holiday_type() eq $HOLIDAYS->{WEEKLY}) { >+ $self->remove_weekly_holidays($weekday, \%updateValues, $today, $date->branchcode); >+ } elsif ($date->holiday_type() eq $HOLIDAYS->{REPEATABLE}) { >+ $self->remove_repeatable_holidays($start_date, $end_date, \%updateValues, $today, $date->branchcode); >+ } >+ } else { >+ $date->update(\%updateValues); >+ } >+ } >+ } >+ $schema->storage->txn_commit; >+ $schema->{AutoCommit} = 1; >+} >+ >+=head2 remove_weekly_holidays >+ >+ $calendar->remove_weekly_holidays($weekday, $updateValues, $today, $branchcode); >+ >+Removes a weekly holiday and updates the days' parameters >+C<$weekday> is the weekday to un-holiday >+C<$updatevalues> is hashref containing the new parameters >+C<$today> is today's date >+C<$branchcode> is the branchcode of the library >+ >+=cut >+ >+sub remove_weekly_holidays { >+ my ($self, $weekday, $updateValues, $today, $branchcode) = @_; >+ my $schema = Koha::Database->new->schema; >+ >+ my $rs = $schema->resultset('DiscreteCalendar')->search( >+ { >+ branchcode => $branchcode, >+ is_opened => 0, >+ holiday_type => $HOLIDAYS->{WEEKLY} >+ }, >+ { >+ where => {-and => [ \["DAYOFWEEK(date) = ?", $weekday], date => { '>=' => $today}]}, >+ } >+ ); >+ >+ while (my $date = $rs->next()) { >+ $date->update($updateValues); >+ } >+} >+ >+=head2 remove_repeatable_holidays >+ >+ $calendar->remove_repeatable_holidays($startDate, $endDate, $today, $branchcode); >+ >+Removes a repeatable holiday and updates the days' parameters >+C<$startDatey> is the start date of the repeatable holiday >+C<$endDate> is the end date of the repeatble holiday >+C<$updatevalues> is hashref containing the new parameters >+C<$today> is today's date >+C<$branchcode> is the branchcode of the library >+ >+=cut >+ >+sub remove_repeatable_holidays { >+ my ($self, $startDate, $endDate, $updateValues, $today, $branchcode) = @_; >+ my $schema = Koha::Database->new->schema; >+ my $parser = DateTime::Format::Strptime->new( >+ pattern => '%m-%d', >+ on_error => 'croak', >+ ); >+ #Format the dates to have only month-day ex: 01-04 for January 4th >+ $startDate = $parser->format_datetime($startDate); >+ $endDate = $parser->format_datetime($endDate); >+ >+ my $rs = $schema->resultset('DiscreteCalendar')->search( >+ { >+ branchcode => $branchcode, >+ is_opened => 0, >+ holiday_type => $HOLIDAYS->{REPEATABLE}, >+ }, >+ { >+ where => { -and => [date => { '>=' => $today}, \["(DATE_FORMAT(date, '\%m-\%d') BETWEEN ? AND ?)", $startDate, $endDate]]}, >+ } >+ ); >+ >+ while (my $date = $rs->next()) { >+ $date->update($updateValues); >+ } >+} >+ >+=head2 copy_to_branch >+ >+ $calendar->copy_to_branch($branch2); >+ >+Copies the days and holidays from this branch to $branch2, ignoring dates in C<$self> >+but not in C<$branch2> >+ >+C<$branch2> the branch to copy into >+ >+=cut >+ >+sub copy_to_branch { >+ my ($self, $newBranch) =@_; >+ my $branchcode = $self->{branchcode}; >+ my $schema = Koha::Database->new->schema; >+ >+ my $copyFrom = $schema->resultset('DiscreteCalendar')->search( >+ { >+ branchcode => $branchcode >+ }, >+ { >+ columns => [ qw/ date is_opened note holiday_type open_hour close_hour /] >+ } >+ ); >+ while (my $copyDate = $copyFrom->next()) { >+ my $copyTo = $schema->resultset('DiscreteCalendar')->search( >+ { >+ branchcode => $newBranch, >+ date => $copyDate->date(), >+ }, >+ { >+ columns => [ qw/ date branchcode is_opened note holiday_type open_hour close_hour /] >+ } >+ ); >+ #if the date does not exist in the copyTO branch, than skip it. >+ if ($copyTo->count ==0) { >+ next; >+ } >+ $copyTo->next()->update({ >+ is_opened => $copyDate->is_opened(), >+ holiday_type => $copyDate->holiday_type(), >+ note => $copyDate->note(), >+ open_hour => $copyDate->open_hour(), >+ close_hour => $copyDate->close_hour() >+ }); >+ } >+} >+ >+=head2 is_opened >+ >+ $calendar->is_opened($date) >+ >+Returns whether the library is open on C<$date> >+ >+=cut >+ >+sub is_opened { >+ my($self, $date) = @_; >+ my $branchcode = $self->{branchcode}; >+ my $schema = Koha::Database->new->schema; >+ my $dtf = $schema->storage->datetime_parser; >+ $date= $dtf->format_datetime($date); >+ #if the date is not found >+ my $is_opened = -1; >+ my $rs = $schema->resultset('DiscreteCalendar')->search( >+ { >+ branchcode => $branchcode, >+ }, >+ { >+ where => \['date = DATE(?)', $date] >+ } >+ ); >+ $is_opened = $rs->next()->is_opened() if $rs->count() != 0; >+ >+ return $is_opened; >+} >+ >+=head2 is_holiday >+ >+ $calendar->is_holiday($date) >+ >+Returns whether C<$date> is a holiday or not >+ >+=cut >+ >+sub is_holiday { >+ my($self, $date) = @_; >+ my $branchcode = $self->{branchcode}; >+ my $schema = Koha::Database->new->schema; >+ my $dtf = $schema->storage->datetime_parser; >+ $date= $dtf->format_datetime($date); >+ #if the date is not found >+ my $isHoliday = -1; >+ my $rs = $schema->resultset('DiscreteCalendar')->search( >+ { >+ branchcode => $branchcode, >+ }, >+ { >+ where => \['date = DATE(?)', $date] >+ } >+ ); >+ >+ if ($rs->count() != 0) { >+ $isHoliday = ($rs->first()->is_opened() ? 0 : 1); >+ } >+ >+ return $isHoliday; >+} >+ >+=head2 copy_holiday >+ >+ $calendar->copy_holiday($from_startDate, $from_endDate, $to_startDate, $to_endDate, $daysnumber); >+ >+Copies a holiday's parameters from a range to a new range >+C<$from_startDate> the source holiday's start date >+C<$from_endDate> the source holiday's end date >+C<$to_startDate> the destination holiday's start date >+C<$to_endDate> the destination holiday's end date >+C<$daysnumber> the number of days in the range. >+ >+Both ranges should have the same number of days in them. >+ >+=cut >+ >+sub copy_holiday { >+ my ($self, $from_startDate, $from_endDate, $to_startDate, $to_endDate, $daysnumber) = @_; >+ my $branchcode = $self->{branchcode}; >+ my $copyFromType = $from_startDate && $from_endDate eq '' ? 'oneDay': 'range'; >+ my $schema = Koha::Database->new->schema; >+ my $dtf = $schema->storage->datetime_parser; >+ >+ if ($copyFromType eq 'oneDay') { >+ my $where; >+ $to_startDate = $dtf->format_datetime($to_startDate); >+ if ($to_startDate && $to_endDate) { >+ $to_endDate = $dtf->format_datetime($to_endDate); >+ $where = { date => { -between => [$to_startDate, $to_endDate]}}; >+ } else { >+ $where = { date => $to_startDate }; >+ } >+ >+ $from_startDate = $dtf->format_datetime($from_startDate); >+ my $fromDate = $schema->resultset('DiscreteCalendar')->search( >+ { >+ branchcode => $branchcode, >+ date => $from_startDate >+ } >+ ); >+ my $toDates = $schema->resultset('DiscreteCalendar')->search( >+ { >+ branchcode => $branchcode, >+ }, >+ { >+ where => $where >+ } >+ ); >+ >+ my $copyDate = $fromDate->next(); >+ while (my $date = $toDates->next()) { >+ $date->update({ >+ is_opened => $copyDate->is_opened(), >+ holiday_type => $copyDate->holiday_type(), >+ note => $copyDate->note(), >+ open_hour => $copyDate->open_hour(), >+ close_hour => $copyDate->close_hour() >+ }) >+ } >+ >+ } else { >+ my $endDate = dt_from_string($from_endDate); >+ $to_startDate = $dtf->format_datetime($to_startDate); >+ $to_endDate = $dtf->format_datetime($to_endDate); >+ if ($daysnumber == 7) { >+ for (my $tempDate = $from_startDate->clone(); $tempDate <= $endDate;$tempDate->add(days => 1)) { >+ my $formatedDate = $dtf->format_datetime($tempDate); >+ my $fromDate = $schema->resultset('DiscreteCalendar')->search( >+ { >+ branchcode => $branchcode, >+ date => $formatedDate, >+ }, >+ { >+ select => [{ DAYOFWEEK => 'date' }], >+ as => [qw/ weekday /], >+ columns =>[ qw/ holiday_type note open_hour close_hour note description/] >+ } >+ ); >+ my $copyDate = $fromDate->next(); >+ my $weekday = $copyDate->get_column('weekday'); >+ >+ my $toDate = $schema->resultset('DiscreteCalendar')->search( >+ { >+ branchcode => $branchcode, >+ >+ }, >+ { >+ where => {date => {-between => [$to_startDate, $to_endDate]}, "DAYOFWEEK(date)" => $weekday}, >+ } >+ ); >+ my $copyToDate = $toDate->next(); >+ $copyToDate->update({ >+ is_opened => $copyDate->is_opened(), >+ holiday_type => $copyDate->holiday_type(), >+ note => $copyDate->note(), >+ open_hour => $copyDate->open_hour(), >+ close_hour => $copyDate->close_hour() >+ }); >+ >+ } >+ } else { >+ my $to_startDate = dt_from_string($to_startDate); >+ my $to_endDate = dt_from_string($to_endDate); >+ for (my $tempDate = $from_startDate->clone(); $tempDate <= $endDate;$tempDate->add(days => 1)) { >+ my $from_formatedDate = $dtf->format_datetime($tempDate); >+ my $fromDate = $schema->resultset('DiscreteCalendar')->search( >+ { >+ branchcode => $branchcode, >+ date => $from_formatedDate, >+ }, >+ { >+ order_by => { -asc => 'date' } >+ } >+ ); >+ my $to_formatedDate = $dtf->format_datetime($to_startDate); >+ my $toDate = $schema->resultset('DiscreteCalendar')->search( >+ { >+ branchcode => $branchcode, >+ date => $to_formatedDate >+ }, >+ { >+ order_by => { -asc => 'date' } >+ } >+ ); >+ my $copyDate = $fromDate->next(); >+ $toDate->next()->update({ >+ is_opened => $copyDate->is_opened(), >+ holiday_type => $copyDate->holiday_type(), >+ note => $copyDate->note(), >+ open_hour => $copyDate->open_hour(), >+ close_hour => $copyDate->close_hour() >+ }); >+ $to_startDate->add(days =>1); >+ } >+ } >+ >+ >+ } >+} >+ >+=head2 days_between >+ >+ $cal->days_between( $start_date, $end_date ) >+ >+Calculates the number of days the library is opened between C<$start_date> and C<$end_date> >+ >+=cut >+ >+sub days_between { >+ my ($self, $start_date, $end_date, ) = @_; >+ my $branchcode = $self->{branchcode}; >+ >+ if ( $start_date->compare($end_date) > 0 ) { >+ # swap dates >+ ($start_date, $end_date) = ($end_date, $start_date); >+ } >+ >+ my $schema = Koha::Database->new->schema; >+ my $dtf = $schema->storage->datetime_parser; >+ $start_date = $dtf->format_datetime($start_date->clone->truncate(to => 'day')); >+ $end_date = $dtf->format_datetime($end_date->clone->truncate(to => 'day')); >+ >+ my $days_between = $schema->resultset('DiscreteCalendar')->search( >+ { >+ branchcode => $branchcode, >+ is_opened => 1, >+ }, >+ { >+ where => \['date >= date(?) AND date < date(?)', $start_date, $end_date] >+ } >+ ); >+ >+ return DateTime::Duration->new( days => $days_between->count()); >+} >+ >+=head2 next_open_day >+ >+ $open_date = $self->next_open_day($base_date); >+ >+Returns a string representing the next day the library is open, starting from C<$base_date> >+ >+=cut >+ >+sub next_open_day { >+ my ( $self, $date, $dayweek ) = @_; >+ my $branchcode = $self->{branchcode}; >+ my $schema = Koha::Database->new->schema; >+ my $dtf = $schema->storage->datetime_parser; >+ my $formatted_date = $dtf->format_datetime($date); >+ >+ my $options = { >+ order_by => { -asc => 'date' }, >+ rows => 1, >+ }; >+ $options->{where} = \['DAYOFWEEK(date) = DAYOFWEEK(?)', $formatted_date] if $dayweek; >+ >+ my $rs = $schema->resultset('DiscreteCalendar')->search( >+ { >+ branchcode => $branchcode, >+ is_opened => 1, >+ date => { '>' => \['DATE(?)', $formatted_date] }, >+ }, >+ $options >+ ); >+ >+ my $next = $rs->next(); >+ unless ( $next ) { >+ warn "No next opened date in calendar. Reduced to current date: $formatted_date."; >+ return $date; >+ } >+ return dt_from_string( $next->date(), 'iso'); >+} >+ >+=head2 prev_open_day >+ >+ $open_date = $self->prev_open_day($base_date); >+ >+Returns a string representing the closest previous day the library was open, starting from C<$base_date> >+ >+=cut >+ >+sub prev_open_day { >+ my ( $self, $date, $dayweek ) = @_; >+ my $branchcode = $self->{branchcode}; >+ my $schema = Koha::Database->new->schema; >+ my $dtf = $schema->storage->datetime_parser; >+ my $formatted_date = $dtf->format_datetime($date); >+ >+ my $options = { >+ order_by => { -desc => 'date' }, >+ rows => 1, >+ }; >+ $options->{where} = \['DAYOFWEEK(date) = DAYOFWEEK(?)', $formatted_date] if $dayweek; >+ >+ my $rs = $schema->resultset('DiscreteCalendar')->search( >+ { >+ branchcode => $branchcode, >+ is_opened => 1, >+ date => { '<' => \['DATE(?)', $formatted_date] }, >+ }, >+ $options >+ ); >+ >+ my $prev = $rs->next(); >+ unless ( $prev ) { >+ warn "No previous opened date in calendar. Reduced to current date: $formatted_date."; >+ return $date; >+ } >+ return dt_from_string( $prev->date(), 'iso'); >+} >+ >+=head2 days_forward >+ >+ $fwrd_date = $calendar->days_forward($start, $count) >+ >+Returns the date C<$count> days in the future from C<$start>, ignoring days where the library is closed. >+ >+=cut >+ >+sub days_forward { >+ my $self = shift; >+ my $start_dt = shift; >+ my $num_days = shift; >+ >+ return $start_dt unless $num_days > 0; >+ >+ my $base_dt = $start_dt->clone(); >+ >+ while ($num_days--) { >+ $base_dt = $self->next_open_day($base_dt); >+ } >+ >+ return $base_dt; >+} >+ >+=head2 hours_between >+ >+ $hours = $calendar->hours_between($start_dt, $end_dt) >+ >+Returns the number of hours between C<$start_dt> and C<$end_dt>. This is the imprecise >+version, which simply calculates the number of day times 24. To take opening hours into account >+see C<open_hours_between>/ >+ >+=cut >+ >+sub hours_between { >+ my ($self, $start_dt, $end_dt) = @_; >+ my $branchcode = $self->{branchcode}; >+ my $schema = Koha::Database->new->schema; >+ my $dtf = $schema->storage->datetime_parser; >+ my $start_date = $start_dt->clone(); >+ my $end_date = $end_dt->clone(); >+ my $duration = $end_date->delta_ms($start_date); >+ $start_date->truncate( to => 'day' ); >+ $end_date->truncate( to => 'day' ); >+ >+ # NB this is a kludge in that it assumes all days are 24 hours >+ # However for hourly loans the logic should be expanded to >+ # take into account open/close times then it would be a duration >+ # of library open hours >+ my $skipped_days = 0; >+ $start_date = $dtf->format_datetime($start_date); >+ $end_date = $dtf->format_datetime($end_date); >+ my $hours_between = $schema->resultset('DiscreteCalendar')->search( >+ { >+ branchcode => $branchcode, >+ is_opened => 0, >+ date => { >+ '>=' => $start_date, >+ '<' => $end_date, >+ }, >+ }, >+ ); >+ >+ if ($skipped_days = $hours_between->count()) { >+ $duration->subtract_duration(DateTime::Duration->new( hours => 24 * $skipped_days)); >+ } >+ >+ return $duration; >+} >+ >+=head2 open_hours_between >+ >+ $hours = $calendar->open_hours_between($start_date, $end_date) >+ >+Returns the number of hours between C<$start_date> and C<$end_date>, taking into >+account the opening hours of the library. >+ >+=cut >+ >+sub open_hours_between { >+ my ($self, $start_date, $end_date) = @_; >+ my $branchcode = $self->{branchcode}; >+ my $schema = Koha::Database->new->schema; >+ my $dtf = DateTime::Format::Strptime->new(pattern => "%F %T"); >+ $start_date = $dtf->format_datetime($start_date); >+ $end_date = $dtf->format_datetime($end_date); >+ >+ my $working_hours_between = $schema->resultset('DiscreteCalendar')->search( >+ { >+ branchcode => $branchcode, >+ is_opened => 1, >+ }, >+ { >+ select => \['sum(time_to_sec(timediff(close_hour, open_hour)) / 3600)'], >+ as => [qw /hours_between/], >+ where => \['date BETWEEN DATE(?) AND DATE(?)', $start_date, $end_date] >+ } >+ ); >+ >+ my $loan_day = $schema->resultset('DiscreteCalendar')->search( >+ { >+ branchcode => $branchcode, >+ }, >+ { >+ order_by => \[ 'ABS(DATEDIFF(date, ?))', $start_date ], >+ rows => 1, >+ } >+ ); >+ >+ my $return_day = $schema->resultset('DiscreteCalendar')->search( >+ { >+ branchcode => $branchcode, >+ }, >+ { >+ order_by => \[ 'ABS(DATEDIFF(date, ?))', $end_date ], >+ rows => 1, >+ } >+ ); >+ >+ #Capture the time portion of the date >+ $start_date =~ /\s(.*)/; >+ my $loan_date_time = $1; >+ $end_date =~ /\s(.*)/; >+ my $return_date_time = $1; >+ >+ my $not_used_hours = $schema->resultset('DiscreteCalendar')->search( >+ { >+ branchcode => $branchcode, >+ is_opened => 1, >+ }, >+ { >+ select => \[ '(time_to_sec(timediff(?, ?)) + time_to_sec(timediff(?, ?)) ) / 3600', $return_day->next()->close_hour(), $return_date_time, $loan_date_time, $loan_day->next()->open_hour()], >+ as => [qw /not_used_hours/], >+ } >+ ); >+ >+ return ($working_hours_between->next()->get_column('hours_between') - $not_used_hours->next()->get_column('not_used_hours')); >+} >+ >+=head2 addDuration >+ >+ my $dt = $calendar->addDuration($date, $dur, $unit) >+ >+C<$date> is a DateTime object representing the starting date of the interval. >+C<$offset> is a duration to add to it (DateTime::Duration objects are supported as legacy) >+C<$unit> is a string value 'days' or 'hours' toflag granularity of duration >+ >+=cut >+ >+sub addDuration { >+ my ( $self, $startdate, $add_duration, $unit ) = @_; >+ >+ # Default to days duration (legacy support I guess) >+ if ( ref $add_duration ne 'DateTime::Duration' ) { >+ $add_duration = DateTime::Duration->new( days => $add_duration ); >+ } >+ >+ $unit ||= 'days'; # default days ? >+ my $dt; >+ >+ if ( $unit eq 'hours' ) { >+ # Fixed for legacy support. Should be set as a branch parameter >+ my $return_by_hour = 10; >+ >+ $dt = $self->addHours($startdate, $add_duration, $return_by_hour); >+ } else { >+ # days >+ $dt = $self->addDays($startdate, $add_duration); >+ } >+ >+ return $dt; >+} >+ >+=head2 addHours >+ >+ $end = $calendar->addHours($start, $hours_duration, $return_by_hour) >+ >+Add C<$hours_duration> to C<$start> date. >+C<$return_by_hour> is an integer value representing the opening hour for the branch >+ >+=cut >+ >+sub addHours { >+ my ( $self, $startdate, $hours_duration, $return_by_hour ) = @_; >+ my $base_date = $startdate->clone(); >+ >+ $base_date->add_duration($hours_duration); >+ >+ # If we are using the calendar behave for now as if Datedue >+ # was the chosen option (current intended behaviour) >+ >+ if ( $self->{days_mode} ne 'Days' && >+ $self->is_holiday($base_date) ) { >+ >+ if ( $hours_duration->is_negative() ) { >+ $base_date = $self->prev_open_day($base_date); >+ } else { >+ $base_date = $self->next_open_day($base_date); >+ } >+ >+ $base_date->set_hour($return_by_hour); >+ >+ } >+ >+ return $base_date; >+} >+ >+=head2 addDays >+ >+ $date = $calendar->addDays($start, $duration) >+ >+Add C<$days_duration> to C<$start> date. If the calendar's days_mode is set >+to 'Calendar', it ignores closed days. Else if the calendar is set to 'Datedue' >+it calculates the date normally, and then pushes to result to the next open day. >+ >+=cut >+ >+sub addDays { >+ my ( $self, $startdate, $days_duration ) = @_; >+ my $base_date = $startdate->clone(); >+ >+ $self->{days_mode} ||= q{}; >+ >+ if ( $self->{days_mode} eq 'Calendar' ) { >+ # use the calendar to skip all days the library is closed >+ # when adding >+ my $days = abs $days_duration->in_units('days'); >+ >+ if ( $days_duration->is_negative() ) { >+ while ($days) { >+ $base_date = $self->prev_open_day($base_date); >+ --$days; >+ } >+ } else { >+ while ($days) { >+ $base_date = $self->next_open_day($base_date); >+ --$days; >+ } >+ } >+ >+ } else { # Days or Datedue >+ # use straight days, then use calendar to push >+ # the date to the next open day as appropriate >+ # if Datedue or Dayweek >+ $base_date->add_duration($days_duration); >+ >+ if ( $self->{days_mode} eq 'Datedue' || >+ $self->{days_mode} eq 'Dayweek') { >+ # Datedue or Dayweek, then use the calendar to push >+ # the date to the next open day if holiday >+ if ( $self->is_holiday($base_date) ) { >+ my $days = $days_duration->in_units('days'); >+ >+ my $dayweek = 0; >+ if ( >+ $self->{days_mode} eq 'Dayweek' && >+ $days % 7 == 0 # Is it a period based on weeks >+ ) { >+ my $dow = $base_date->day_of_week; >+ # Representation fix >+ # DateTime object dow (1-7) where Monday is 1 >+ # in Koha::DiscreteCalendar 1 = Sunday, not 7. >+ $dow = ( $dow == 7 ) ? 1 : $dow + 1; >+ >+ my @weekly_holidays = $self->get_week_days_holidays(); >+ $dayweek = !(@weekly_holidays && grep $_->{weekday} == $dow, @weekly_holidays); >+ } >+ >+ if ( $days_duration->is_negative() ) { >+ $base_date = $self->prev_open_day($base_date, $dayweek); >+ } else { >+ $base_date = $self->next_open_day($base_date, $dayweek); >+ } >+ } >+ } >+ } >+ >+ return $base_date; >+} >+ >+1; >diff --git a/Koha/Hold.pm b/Koha/Hold.pm >index d886f7d8b55..d8f1d62466c 100644 >--- a/Koha/Hold.pm >+++ b/Koha/Hold.pm >@@ -34,7 +34,7 @@ use Koha::Biblios; > use Koha::Hold::CancellationRequests; > use Koha::Items; > use Koha::Libraries; >-use Koha::Calendar; >+use Koha::DiscreteCalendar; > use Koha::Plugins; > > use Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue; >@@ -71,7 +71,7 @@ sub age { > my $age; > > if ($use_calendar) { >- my $calendar = Koha::Calendar->new( branchcode => $self->branchcode ); >+ my $calendar = Koha::DiscreteCalendar->new({ branchcode => $self->branchcode }); > $age = $calendar->days_between( dt_from_string( $self->reservedate ), $today ); > } else { > $age = $today->delta_days( dt_from_string( $self->reservedate ) ); >@@ -399,7 +399,7 @@ sub set_waiting { > branchcode => $self->branchcode, > } > ); >- my $calendar = Koha::Calendar->new( branchcode => $self->branchcode, days_mode => $daysmode ); >+ my $calendar = Koha::DiscreteCalendar->new({ branchcode => $self->branchcode, days_mode => $daysmode }); > > $new_expiration_date = $calendar->days_forward( dt_from_string( $self->waitingdate ), $max_pickup_delay ); > } >diff --git a/Koha/Patron.pm b/Koha/Patron.pm >index c0ef6e292c5..0cf4dae492a 100644 >--- a/Koha/Patron.pm >+++ b/Koha/Patron.pm >@@ -1254,7 +1254,7 @@ sub has_restricting_overdues { > > my $calendar; > if ( C4::Context->preference('OverdueNoticeCalendar') ) { >- $calendar = Koha::Calendar->new( branchcode => $params->{issue_branchcode} ); >+ $calendar = Koha::DiscreteCalendar->new( branchcode => $params->{issue_branchcode} ); > } > > my $dtf = Koha::Database->new->schema->storage->datetime_parser; >diff --git a/Koha/Schema/Result/DiscreteCalendar.pm b/Koha/Schema/Result/DiscreteCalendar.pm >index 6db32c892ed..777ac4952db 100644 >--- a/Koha/Schema/Result/DiscreteCalendar.pm >+++ b/Koha/Schema/Result/DiscreteCalendar.pm >@@ -55,6 +55,12 @@ __PACKAGE__->table("discrete_calendar"); > is_nullable: 1 > size: 30 > >+=head2 description >+ >+ data_type: 'mediumtext' >+ default_value: '''' >+ is_nullable: 1 >+ > =head2 open_hour > > data_type: 'time' >@@ -82,6 +88,8 @@ __PACKAGE__->add_columns( > { data_type => "varchar", default_value => "", is_nullable => 1, size => 1 }, > "note", > { data_type => "varchar", default_value => "", is_nullable => 1, size => 30 }, >+ "description", >+ { data_type => "mediumtext", default_value => "''", is_nullable => 1 }, > "open_hour", > { data_type => "time", is_nullable => 0 }, > "close_hour", >@@ -103,8 +111,8 @@ __PACKAGE__->add_columns( > __PACKAGE__->set_primary_key("branchcode", "date"); > > >-# Created by DBIx::Class::Schema::Loader v0.07045 @ 2017-04-19 10:07:41 >-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:wtctW8ZzCkyCZFZmmavFEw >+# Created by DBIx::Class::Schema::Loader v0.07049 @ 2022-10-20 11:37:37 >+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:/w9T8ShNcZsKRpeGaePHoA > > > # You can replace this text with custom code or comments, and it will be preserved on regeneration >diff --git a/admin/branches.pl b/admin/branches.pl >index d157d8fbd8c..fd1a9edd5ea 100755 >--- a/admin/branches.pl >+++ b/admin/branches.pl >@@ -226,6 +226,8 @@ if ( $op eq 'add_form' ) { > my @additional_fields = $library->prepare_cgi_additional_field_values( $input, 'branches' ); > $library->set_additional_fields( \@additional_fields ); > >+ Koha::DiscreteCalendar->add_new_branch(undef, $branchcode); >+ > push @messages, { type => 'message', code => 'success_on_insert' }; > } > ); >@@ -270,6 +272,7 @@ if ( $op eq 'add_form' ) { > if ( $@ or not $deleted ) { > push @messages, { type => 'alert', code => 'error_on_delete' }; > } else { >+ Koha::DiscreteCalendar->delete_branch($branchcode); > push @messages, { type => 'message', code => 'success_on_delete' }; > } > $op = 'list'; >diff --git a/circ/returns.pl b/circ/returns.pl >index 97b23534900..709a5b04e09 100755 >--- a/circ/returns.pl >+++ b/circ/returns.pl >@@ -45,7 +45,6 @@ use C4::RotatingCollections; > use Koha::AuthorisedValues; > use Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue; > use Koha::BiblioFrameworks; >-use Koha::Calendar; > use Koha::Checkouts; > use Koha::CirculationRules; > use Koha::DateUtils qw( dt_from_string ); >diff --git a/koha-tmpl/intranet-tmpl/prog/css/src/calendar.scss b/koha-tmpl/intranet-tmpl/prog/css/src/calendar.scss >index 910130b3385..988b2ddc94c 100644 >--- a/koha-tmpl/intranet-tmpl/prog/css/src/calendar.scss >+++ b/koha-tmpl/intranet-tmpl/prog/css/src/calendar.scss >@@ -1,8 +1,11 @@ > $daySize: 45px; >+$pastdate_bg: #E6E6E6; >+$normalday_bg: #F4F8F9; > $exception_bg: #B3D4FF; > $holiday_bg: #FFAEAE; > $repeatableweekly_bg: #FFFF99; > $repeatableyearly_bg: #FFCC66; >+$float_bg: #66FF33; > $selected: #B9DB88; > > @import "flatpickr"; >@@ -32,6 +35,10 @@ $selected: #B9DB88; > &.repeatableyearly { > background-color: $repeatableyearly_bg; > } >+ >+ &.float { >+ background-color: $float_bg; >+ } > } > > .flatpickr-day { >@@ -40,6 +47,18 @@ $selected: #B9DB88; > border: 0; > } > >+ &.past-date { >+ background-color: $pastdate_bg; >+ >+ &.selected { >+ border:3px solid $selected; >+ } >+ >+ &:hover { >+ background-color: #CCC; >+ } >+ } >+ > &.exception { > background-color: $exception_bg; > >@@ -71,6 +90,14 @@ $selected: #B9DB88; > border: 3px solid $selected; > } > } >+ >+ &.float { >+ background-color: $float_bg; >+ >+ .selected { >+ border: 3px solid $selected; >+ } >+ } > } > > #holidayexceptions th.exception { >@@ -93,6 +120,10 @@ $selected: #B9DB88; > background-color: $repeatableyearly_bg; > } > >+#holidaysfloat th.float { >+ background-color: $float_bg; >+} >+ > .panel { > border: 1px solid #8AC363; > box-shadow: none; >@@ -146,3 +177,16 @@ fieldset.brief li.radio { > .dayContainer { > gap: 3px; > } >+ >+.calendar { >+ display: flex; >+ align-items: start; >+ gap: 10px; >+ flex-wrap: wrap; >+} >+ >+#newHoliday { >+ flex-grow: 1; >+ margin-top: 2px; >+ border-radius: 0; >+} >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/tools-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/tools-menu.inc >index d436580537f..a1293939d58 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/tools-menu.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/tools-menu.inc >@@ -58,7 +58,7 @@ > <h5>Additional tools</h5> > <ul> > [% IF ( CAN_user_tools_edit_calendar ) %] >- <li><a href="/cgi-bin/koha/tools/holidays.pl">Calendar</a></li> >+ <li><a href="/cgi-bin/koha/tools/discrete_calendar.pl">Calendar</a></li> > [% END %] > [% IF ( CAN_user_tools_manage_csv_profiles ) %] > <li><a href="/cgi-bin/koha/tools/csv-profiles.pl">CSV profiles</a></li> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/discrete_calendar.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/discrete_calendar.tt >new file mode 100644 >index 00000000000..78f0a5e44a3 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/discrete_calendar.tt >@@ -0,0 +1,809 @@ >+[% USE raw %] >+[% USE Asset %] >+[% USE Branches %] >+[% SET footerjs = 1 %] >+[% INCLUDE 'doc-head-open.inc' %] >+<title>[% Branches.GetName( branch ) | html %] calendar › Tools › Koha</title> >+[% INCLUDE 'doc-head-close.inc' %] >+[% Asset.css("css/calendar.css") | $raw %] >+</head> >+ >+<body id="tools_holidays" class="tools"> >+[% WRAPPER 'header.inc' %] >+ [% INCLUDE 'cat-search.inc' %] >+[% END %] >+ >+[% WRAPPER 'sub-header.inc' %] >+ [% WRAPPER breadcrumbs %] >+ [% WRAPPER breadcrumb_item %] >+ <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> >+ [% END %] >+ [% WRAPPER breadcrumb_item bc_active= 1 %] >+ <span>[% Branches.GetName( branch ) | html %] calendar</span> >+ [% END %] >+ [% END #/ WRAPPER breadcrumbs %] >+[% END #/ WRAPPER sub-header.inc %] >+ >+<div id="main" class="main container-fluid"> >+ <div class="row"> >+ <div class="col-sm-10 col-sm-push-2"> >+ <main> >+ [% IF no_branch_selected %] >+ <div class="dialog alert"> >+ <strong>No library set!</strong> >+ </div> >+ [% END %] >+ >+ [% UNLESS datesInfos %] >+ <div class="dialog alert"> >+ <strong>Error!</strong> You have to run add_days_discrete_calendar.pl in order to use Discrete Calendar. >+ </div> >+ [% END %] >+ >+ [% IF date_format_error %] >+ <div class="dialog alert"> >+ <strong>Error!</strong> Date format error. Please try again. >+ </div> >+ [% END %] >+ >+ [% IF cannot_edit_past_dates %] >+ <div class="alert alert-danger"> >+ <strong>Error!</strong> You cannot edit the past. The date '[% error_date | html %]' was out of range for the requested action. >+ </div> >+ [% END %] >+ >+ <h1>[% Branches.GetName( branch ) | html %] calendar</h1> >+ >+ <div class="row"> >+ <div class="col-sm-6"> >+ <div class="page-section"> >+ <label for="branch">Define the holidays for:</label> >+ <form id="copyCalendar-form" method="post"> >+ <select id="branch" name="branch"> >+ [% PROCESS options_for_libraries libraries => Branches.all( selected => branch ) %] >+ </select> >+ Copy calendar to >+ <select id='newBranch' name ='newBranch'> >+ <option value=""></option> >+ [% FOREACH l IN Branches.all() %] >+ [% UNLESS branch == l.branchcode %] >+ <option value="[% l.branchcode | html %]">[% l.branchname | html %]</option> >+ [% END %] >+ [% END %] >+ </select> >+ <input type="hidden" name="action" value="copyBranch" /> >+ <input type="submit" value="Clone"> >+ </form> >+ >+ <h3>Calendar information</h3> >+ >+ <div class="calendar"> >+ <span id="calendar-anchor"></span> >+ >+ <!-- ***************************** Panel to deal with new holidays ********************** --> >+ <div class="panel newHoliday" id="newHoliday"> >+ <form id="newHoliday-form" method="post"> >+ <fieldset class="brief"> >+ <h3>Edit date details</h3> >+ <span id="holtype"></span> >+ <ol> >+ <li> >+ <strong>Library:</strong> >+ <span id="newBranchNameOutput"></span> >+ <input type="hidden" id="branch" name="branch" value="[% branch | html %]" /> >+ </li> >+ <li> >+ <strong>From date:</strong> >+ <span id="newDaynameOutput"></span>, >+ >+ [% IF ( dateformat == "us" ) %] >+ <span id="newMonthOutput"></span>/<span id="newDayOutput"></span>/<span id="newYearOutput"></span> >+ [% ELSIF ( dateformat == "metric" ) %] >+ <span id="newDayOutput"></span>/<span id="newMonthOutput"></span>/<span id="newYearOutput"></span> >+ [% ELSIF ( dateformat == "dmydot" ) %] >+ <span id="newDayOutput"></span>.<span id="newMonthOutput"></span>.<span id="newYearOutput"></span> >+ [% ELSE %] >+ <span id="newYearOutput"></span>/<span id="newMonthOutput"></span>/<span id="newDayOutput"></span> >+ [% END %] >+ >+ <input type="hidden" id="newDayname" name="showDayname" /> >+ <input type="hidden" id="Day" name="Day" /> >+ <input type="hidden" id="Month" name="Month" /> >+ <input type="hidden" id="Year" name="Year" /> >+ </li> >+ <li class="dateinsert"> >+ <strong>To date:</strong> >+ <input type="text" id="to_date_flatpickr" size="20" /> >+ </li> >+ <li> >+ <label for="title">Title: </label> >+ <input type="text" name="Title" id="title" size="35" /> >+ </li> >+ <li> >+ <label for="description">Description: </label> >+ <textarea id="description" name="description" rows="2" cols="40"></textarea> >+ </li> >+ <li id="holidayType"> >+ <label for="holidayType">Date type</label> >+ <select name ='holidayType'> >+ <option value="empty"></option> >+ <option value="none">Working day</option> >+ <option value="E">Unique holiday</option> >+ <option value="W">Weekly holiday</option> >+ <option value="R">Repeatable holiday</option> >+ <option value="F">Floating holiday</option> >+ <option value="N" disabled>Need validation</option> >+ </select> >+ <a href="#" class="helptext">[?]</a> >+ <div class="hint"> >+ <ol> >+ <li><strong>Working day:</strong> the library is open on that day.</li> >+ <li><strong>Unique holiday:</strong> make a single holiday. For example, selecting August 1, 2012 will make it a holiday, but will not affect August 1 in other years.</li> >+ <li><strong>Weekly holiday:</strong> make this weekday a holiday, every week. For example, if your library is closed on Saturdays, use this option to make every Saturday a holiday.</li> >+ <li><strong>Repeatable holiday:</strong> this will take this day and month as a reference to make it a holiday. Through this option, you can repeat this rule for every year. For example, selecting August 1 will make August 1 a holiday every year.</li> >+ <li><strong>Floating holiday:</strong> this will take this day and month as a reference to make it a floating holiday. Through this option, you can add a holiday that repeats every year but not necessarily on the exact same day. On subsequent years the date will need validation.</li> >+ <li><strong>Need validation:</strong> this holiday has been added automatically, but needs to be validated.</li> >+ </ol> >+ </div> >+ </li> >+ <li id="days_of_week"> >+ <label for="day_of_week">Week day</label> >+ <select name ='day_of_week'> >+ <option value="everyday">Everyday</option> >+ <option value="1">Sundays</option> >+ <option value="2">Mondays</option> >+ <option value="3">Tuesdays</option> >+ <option value="4">Wednesdays</option> >+ <option value="5">Thursdays</option> >+ <option value="6">Fridays</option> >+ <option value="7">Saturdays</option> >+ </select> >+ </li> >+ <li class="radio" id="deleteType"> >+ <input type="checkbox" name="deleteType" id="deleteType_checkbox" value="1" ><label for="deleteType_checkbox"> Delete this type</label> >+ <a href="#" class="helptext">[?]</a> >+ <div class="hint">Remove all repeated or weekly holidays of the selected date or week day <br> if working day is selected.</div> >+ </li> >+ <li> >+ <label for="openHour">Open hours: </label><input type="text" name="openHour" id='openHour' /> >+ </li> >+ <li> >+ <label for="closeHour">Close hours: </label><input type="text" name="closeHour" id='closeHour' /> >+ </li> >+ <li class="radio"> >+ <input type="radio" name="action" id="EditRadioButton" value="edit" checked/> >+ <label for="EditRadioButton">Edit selected dates</label> >+ </li> >+ <li class="radio"> >+ <input type="radio" name="action" id="CopyRadioButton" value="copyDates" /> >+ <label for="CopyRadioButton">Copy to different dates</label> >+ </li> >+ <li class="CopyDatePanel"> >+ <label>From:</label> >+ <input type="text" id="copyto_from_flatpickr" size="20"/> >+ <label>To:</label> >+ <input type="text" id="copyto_to_flatpickr" size="20"/> >+ </li> >+ <li class="checkbox"> >+ <input type="checkbox" name="all_branches" id="all_branches" /> >+ <label for="all_branches">Copy to all libraries</label>. >+ <a href="#" class="helptext">[?]</a> >+ <div class="hint">If checked, this holiday will be copied to all libraries.</div> >+ </li> >+ </ol> >+ >+ <!-- These yyyy-mm-dd --> >+ <input type="hidden" name="from_date" id='from_date'> >+ <input type="hidden" name="to_date" id='to_date'> >+ <input type="hidden" name="copyto_from" id='copyto_from'> >+ <input type="hidden" name="copyto_to" id='copyto_to'> >+ <input type="hidden" name="daysnumber" id='daysnumber'> >+ <input type="hidden" name="local_today" id='local_today'> >+ >+ <fieldset class="action"> >+ <input type="submit" name="submit" value="Save" /> >+ <a href="#" class="cancel hidePanel newHoliday">Cancel</a> >+ </fieldset> >+ </fieldset> >+ </form> >+ </div> >+ </div> >+ </div> <!-- /.page-section --> >+ </div> <!-- /.col-sm-6 --> >+ >+ <div class="col-sm-6"> >+ <div class="page-section"> >+ <div class="help"> >+ <h4>Hints</h4> >+ <ul> >+ <li>Search in the calendar the day you want to set as holiday.</li> >+ <li>Click the date to add or edit a holiday.</li> >+ <li>Enter a title and description for the holiday.</li> >+ <li>Specify how the holiday should repeat.</li> >+ <li>Click Save to finish.</li> >+ <li>PS: >+ <ul> >+ <li>Past dates cannot be changed</li> >+ <li>Weekly holidays change open/close hours for all the days affected unless inputs are empty</li> >+ </ul> >+ </li> >+ </ul> >+ <h4>Key</h4> >+ <p> >+ <span class="key normalday">Working day</span> >+ <span class="key holiday">Unique holiday</span> >+ <span class="key repeatableweekly">Holiday repeating weekly</span> >+ <span class="key repeatableyearly">Holiday repeating yearly</span> >+ <span class="key float">Floating holiday</span> >+ <span class="key exception">Need validation</span> >+ </p> >+ </div> <!-- /#help --> >+ >+ <div id="holiday-list"> >+ [% IF ( NEED_VALIDATION_HOLIDAYS ) %] >+ <h3>Need validation holidays</h3> >+ <table id="holidayexceptions" class="dataTable no-footer"> >+ <thead> >+ <tr> >+ <th class="exception">Date</th> >+ <th class="exception">Title</th> >+ <th class="exception">Description</th> >+ </tr> >+ </thead> >+ <tbody> >+ [% FOREACH need_validation_holiday IN NEED_VALIDATION_HOLIDAYS %] >+ <tr> >+ <td><a href="#main" onclick="go_to_date('[% need_validation_holiday.date | html %]')"><span title="[% need_validation_holiday.DATE_SORT | html %]">[% need_validation_holiday.outputdate | html %]</span></a></td> >+ <td>[% need_validation_holiday.note | html %]</td> >+ <td>[% need_validation_holiday.description.replace('\\\r\\\n', '<br />') | html %]</td> >+ </tr> >+ [% END %] >+ </tbody> >+ </table> <!-- /#holidayexceptions --> >+ [% END # /IF ( EXCEPTION_HOLIDAYS_LOOP ) %] >+ >+ [% IF ( WEEKLY_HOLIDAYS ) %] >+ <h3>Weekly - Repeatable holidays</h3> >+ <table id="holidayweeklyrepeatable" class="dataTable no-footer"> >+ <thead> >+ <tr> >+ <th class="repeatableweekly">Day of week</th> >+ <th class="repeatableweekly">Title</th> >+ <th class="repeatableweekly">Description</th> >+ </tr> >+ </thead> >+ <tbody> >+ [% FOREACH WEEK_DAYS_LOO IN WEEKLY_HOLIDAYS %] >+ <tr> >+ <td>[% WEEK_DAYS_LOO.weekday | html %]</td> >+ <td>[% WEEK_DAYS_LOO.note | html %]</td> >+ <td>[% WEEK_DAYS_LOO.description.replace('\\\r\\\n', '<br />') | html %]</td> >+ </tr> >+ [% END %] >+ </tbody> >+ </table> <!-- /#holidayweeklyrepeatable --> >+ [% END # / IF ( WEEKLY_HOLIDAYS ) %] >+ >+ [% IF ( REPEATABLE_HOLIDAYS ) %] >+ <h3>Yearly - Repeatable holidays</h3> >+ <table id="holidaysyearlyrepeatable" class="dataTable no-footer"> >+ <thead> >+ <tr> >+ [% IF ( dateformat == "metric" ) %] >+ <th class="repeatableyearly">Day/month</th> >+ [% ELSE %] >+ <th class="repeatableyearly">Month/day</th> >+ [% END %] >+ <th class="repeatableyearly">Title</th> >+ <th class="repeatableyearly">Description</th> >+ </tr> >+ </thead> >+ <tbody> >+ [% FOREACH DAY_MONTH_HOLIDAYS_LOO IN REPEATABLE_HOLIDAYS %] >+ <tr> >+ [% IF ( dateformat == "metric" ) %] >+ <td><span title="[% DAY_MONTH_HOLIDAYS_LOO.DATE_SORT | html %]">[% DAY_MONTH_HOLIDAYS_LOO.day | html %]/[% DAY_MONTH_HOLIDAYS_LOO.month | html %]</span></td> >+ [% ELSE %] >+ <td><span title="[% DAY_MONTH_HOLIDAYS_LOO.DATE_SORT | html %]">[% DAY_MONTH_HOLIDAYS_LOO.month | html %]/[% DAY_MONTH_HOLIDAYS_LOO.day | html %]</span></td> >+ [% END %] >+ <td>[% DAY_MONTH_HOLIDAYS_LOO.note | html %]</td> >+ <td>[% DAY_MONTH_HOLIDAYS_LOO.description.replace('\\\r\\\n', '<br />') | html %]</td> >+ </tr> >+ [% END %] >+ </tbody> >+ </table> <!-- /#holidaysyearlyrepeatable --> >+ [% END # /IF ( REPEATABLE_HOLIDAYS ) %] >+ >+ [% IF ( UNIQUE_HOLIDAYS ) %] >+ <h3>Unique holidays</h3> >+ <label class="controls"> >+ <input type="checkbox" name="show_past" id="show_past_holidaysunique" class="show_past" /> >+ Show past entries >+ </label> >+ <table id="holidaysunique" class="dataTable no-footer"> >+ <thead> >+ <tr> >+ <th class="holiday">Date</th> >+ <th class="holiday">Title</th> >+ <th class="holiday">Description</th> >+ </tr> >+ </thead> >+ <tbody> >+ [% FOREACH HOLIDAYS_LOO IN UNIQUE_HOLIDAYS %] >+ <tr data-date="[% HOLIDAYS_LOO.date | html %]"> >+ <td><a href="#main" onclick="go_to_date('[% HOLIDAYS_LOO.date | html %]')"><span title="[% HOLIDAYS_LOO.DATE_SORT | html %]">[% HOLIDAYS_LOO.outputdate | html %]</span></a></td> >+ <td>[% HOLIDAYS_LOO.note | html %]</td> >+ <td>[% HOLIDAYS_LOO.description.replace('\\\r\\\n', '<br />') | html %]</td> >+ </tr> >+ [% END %] >+ </tbody> >+ </table> <!-- /#holidaysunique --> >+ [% END # /IF ( UNIQUE_HOLIDAYS ) %] >+ >+ [% IF ( FLOAT_HOLIDAYS ) %] >+ <h3>Floating holidays</h3> >+ <label class="controls"> >+ <input type="checkbox" name="show_past" id="show_past_holidaysfloat" class="show_past" /> >+ Show past entries >+ </label> >+ <table id="holidaysfloat" class="dataTable no-footer"> >+ <thead> >+ <tr> >+ <th class="float">Date</th> >+ <th class="float">Title</th> >+ <th class="float">Description</th> >+ </tr> >+ </thead> >+ <tbody> >+ [% FOREACH float_holiday IN FLOAT_HOLIDAYS %] >+ <tr data-date="[% float_holiday.date | html %]"> >+ <td><a href="#main" onclick="go_to_date('[% float_holiday.date | html %]')"><span title="[% float_holiday.DATE_SORT | html %]">[% float_holiday.outputdate | html %]</span></a></td> >+ <td>[% float_holiday.note | html %]</td> >+ <td>[% float_holiday.description.replace('\\\r\\\n', '<br />') | html %]</td> >+ </tr> >+ [% END %] >+ </tbody> >+ </table> <!-- /#holidaysfloat --> >+ [% END # /IF ( FLOAT_HOLIDAYS ) %] >+ </div> <!-- /#holiday-list --> >+ </div> <!-- /.page-section --> >+ </div> <!-- /.col-sm-6 --> >+ </div> <!-- /.row --> >+ </main> >+ </div> <!-- /.col-sm-10.col-sm-push-2 --> >+ >+ <div class="col-sm-2 col-sm-pull-10"> >+ <aside> >+ [% INCLUDE 'tools-menu.inc' %] >+ </aside> >+ </div> <!-- .col-sm-2.col-sm-pull-10 --> >+ </div> <!-- /.row --> >+ >+[% MACRO jsinclude BLOCK %] >+ [% INCLUDE 'calendar.inc' %] >+ [% INCLUDE 'datatables.inc' %] >+ [% Asset.js("js/tools-menu.js") | $raw %] >+ <script> >+ var weekdays = new Array(_("Sundays"),_("Mondays"),_("Tuesdays"),_("Wednesdays"),_("Thursdays"),_("Fridays"),_("Saturdays")); >+ >+ // Array containing all the information about each date in the calendar. >+ var datesInfos = new Array(); >+ [% FOREACH date IN datesInfos %] >+ datesInfos["[% date.date | html %]"] = { >+ title : "[% date.note | replace('"','\"') | html %]", >+ description : "[% date.description | replace('"','\"') | replace( '\n', '\\n' ) | replace( '\r', '\\r' ) | html %]", >+ outputdate : "[% date.outputdate | html %]", >+ holiday_type:"[% date.holiday_type | html %]", >+ open_hour: "[% date.open_hour | html %]", >+ close_hour: "[% date.close_hour | html %]" >+ }; >+ [% END %] >+ >+ /* >+ * Displays the details of the selected date on a side panel >+ */ >+ function showHoliday (date_obj, dateString, dayName, day, month, year, weekDay, title, description, holidayType) { >+ $("#newHoliday").slideDown("fast"); >+ $("#copyHoliday").slideUp("fast"); >+ $('#newDaynameOutput').html(dayName); >+ $('#newDayname').val(dayName); >+ $('#newBranchNameOutput').html($("#branch :selected").text()); >+ $(".newHoliday").val($('#branch').val()); >+ $('#newDayOutput').html(day); >+ $(".newHoliday #Day").val(day); >+ $(".newHoliday #Month").val(month); >+ $(".newHoliday #Year").val(year); >+ $("#newMonthOutput").html(month); >+ $("#newYearOutput").html(year); >+ $(".newHoliday, #Weekday").val(weekDay); >+ >+ $('.newHoliday #title').val(title); >+ $('.newHoliday #description').val(description); >+ $('#HolidayType').val(holidayType); >+ $('#days_of_week option[value="'+ (weekDay + 1) +'"]').attr('selected', true); >+ $('#openHour').val(datesInfos[dateString].open_hour); >+ $('#closeHour').val(datesInfos[dateString].close_hour); >+ $('#local_today').val(getSeparetedDate(new Date()).dateString); >+ >+ // This changes the label of the date type on the edit panel >+ if (holidayType == 'W') { >+ $("#holtype").attr("class","key repeatableweekly").html(_("Holiday repeating weekly")); >+ } else if (holidayType == 'R') { >+ $("#holtype").attr("class","key repeatableyearly").html(_("Holiday repeating yearly")); >+ } else if (holidayType == 'F') { >+ $("#holtype").attr("class","key float").html(_("Floating holiday")); >+ } else if (holidayType == 'N') { >+ $("#holtype").attr("class","key exception").html(_("Needs validation")); >+ } else if (holidayType == 'E') { >+ $("#holtype").attr("class","key holiday").html(_("Unique holiday")); >+ } else { >+ $("#holtype").attr("class","key normalday").html(_("Working day ")); >+ } >+ >+ // Select the correct holiday type on the dropdown menu >+ if (datesInfos[dateString].holiday_type !='') { >+ var type = datesInfos[dateString].holiday_type; >+ $('#holidayType option[value="'+ type +'"]').attr('selected', true) >+ } else { >+ $('#holidayType option[value="none"]').attr('selected', true) >+ } >+ >+ // If it is a weekly or repeatable holiday show the option to delete the type >+ if (datesInfos[dateString].holiday_type == 'W' || datesInfos[dateString].holiday_type == 'R') { >+ $('#deleteType').show("fast"); >+ } else { >+ $('#deleteType').hide("fast"); >+ } >+ >+ // This value is to disable and hide input when the date is in the past, because you can't edit it. >+ var value = false; >+ var today = new Date(); >+ today.setHours(0, 0, 0, 0); >+ if (date_obj < today ) { >+ $("#holtype").attr("class","key past-date").html(_("Past date")); >+ $("#CopyRadioButton").attr("checked", "checked"); >+ value = true; >+ $(".CopyDatePanel").toggle(value); >+ } >+ $("#title").prop('disabled', value); >+ $("#description").prop('disabled', value); >+ $("#holidayType select").prop('disabled', value); >+ $("#openHour").prop('disabled', value); >+ $("#closeHour").prop('disabled', value); >+ $("#EditRadioButton").parent().toggle(!value); >+ >+ // clear some fields >+ $("#to_date_flatpickr").val(''); >+ document.querySelector('#to_date_flatpickr')._flatpickr.set('minDate', date_obj); >+ $("#copyto_from_flatpickr").val(''); >+ $("#copyto_to_flatpickr").val(''); >+ $("#all_branches").prop('checked', ''); >+ } >+ >+ // This function gives css classes to each kind of day >+ function dateStatusHandler(dayElem) { >+ date = getSeparetedDate(dayElem.dateObj); >+ var dateString = date.dateString; >+ var today = new Date(); >+ today.setHours(0, 0, 0, 0); >+ >+ if (date.date_obj < today) { >+ formatDay( [ "past-date", _("Past day")], dayElem ); >+ } else { >+ formatDay( [ "normalday", _("Normal day")], dayElem ); >+ } >+ >+ if (datesInfos[dateString] && datesInfos[dateString].holiday_type =='W') { >+ formatDay( [ "repeatableweekly", _("Weekly holiday: %s").format(datesInfos[dateString].title)], dayElem ); >+ } else if (datesInfos[dateString] && datesInfos[dateString].holiday_type == 'R') { >+ formatDay( [ "repeatableyearly", _("Yearly holiday: %s").format(datesInfos[dateString].title)], dayElem ); >+ } else if (datesInfos[dateString] && datesInfos[dateString].holiday_type == 'N') { >+ formatDay( [ "exception", _("Need validation: %s").format(datesInfos[dateString].title)], dayElem ); >+ } else if (datesInfos[dateString] && datesInfos[dateString].holiday_type == 'F') { >+ formatDay( [ "float", _("Floating holiday: %s").format(datesInfos[dateString].title)], dayElem ); >+ } else if (datesInfos[dateString] && datesInfos[dateString].holiday_type == 'E') { >+ formatDay( [ "holiday", _("Single holiday: %s").format(datesInfos[dateString].title)], dayElem ); >+ } >+ } >+ >+ function formatDay( settings, dayElem ){ >+ $(dayElem).attr("title", settings[1]).addClass( settings[0]); >+ } >+ >+ /* >+ * This function separate a given date object and returns an array containing all needed information about the date. >+ */ >+ function getSeparetedDate(date) { >+ var mydate = new Array(); >+ var day = (date.getDate() < 10 ? '0' : '') + date.getDate(); >+ var month = ((date.getMonth()+1) < 10 ? '0' : '') + (date.getMonth() +1); >+ var year = date.getFullYear(); >+ var weekDay = date.getDay(); >+ // iso date string >+ var dateString = year + '-' + month + '-' + day; >+ mydate = { >+ date_obj : date, >+ dateString : dateString, >+ weekDay: weekDay, >+ year: year, >+ month: month, >+ day: day >+ }; >+ >+ return mydate; >+ } >+ >+ /* >+ * Validate the forms before sending them to the backend >+ */ >+ function validateForm(form) { >+ if (form =='newHoliday-form' && $('#CopyRadioButton').is(':checked')) { >+ if ($('#copyto_from_flatpickr').val() =='' || $('#copyto_to_flatpickr').val() =='') { >+ alert("You have to pick a FROM and TO in the Copy to different dates."); >+ return false; >+ } else if ($('#to_date_flatpickr').val()) { >+ var from_DateFrom = new Date(document.querySelector("#calendar-anchor")._flatpickr.selectedDates[0]); >+ var from_DateTo = new Date(document.querySelector('#to_date_flatpickr')._flatpickr.selectedDates[0]); >+ var to_DateFrom = new Date(document.querySelector('#copyto_from_flatpickr')._flatpickr.selectedDates[0]); >+ var to_DateTo = new Date(document.querySelector('#copyto_to_flatpickr')._flatpickr.selectedDates[0]); >+ >+ var from_start = Math.round( from_DateFrom.getTime() / (3600*24*1000)); // days as integer from.. >+ var from_end = Math.round( from_DateTo.getTime() / (3600*24*1000)); >+ var to_start = Math.round( to_DateFrom.getTime() / (3600*24*1000)); >+ var to_end = Math.round( to_DateTo.getTime() / (3600*24*1000)); >+ >+ var from_daysDiff = from_end - from_start +1; >+ var to_daysDiff = to_end - to_start + 1; >+ if (from_daysDiff == to_daysDiff) { >+ $('#daysnumber').val(to_daysDiff); >+ return true; >+ } else { >+ alert("You have to pick the same number of days if you choose 2 ranges"); >+ return false; >+ } >+ } >+ } else if (form == 'copyCalendar-form') { >+ if ($('#newBranch').val() =='') { >+ alert("Please select a copy to calendar."); >+ return false; >+ } else { >+ return true; >+ } >+ } else { >+ return true; >+ } >+ } >+ >+ function go_to_date(isoDate) { >+ // I added the time to get around the timezone >+ var date = getSeparetedDate(new Date(isoDate + " 00:00:00")); >+ var day = date.day; >+ var month = date.month; >+ var year = date.year; >+ var weekDay = date.weekDay; >+ var dayName = weekdays[weekDay]; >+ var dateString = date.dateString; >+ var date_obj = date.date_obj; >+ >+ document.querySelector("#calendar-anchor")._flatpickr.setDate(date_obj); >+ showHoliday(date_obj, dateString, dayName, day, month, year, weekDay, datesInfos[dateString].title, datesInfos[dateString].description, datesInfos[dateString].holiday_type); >+ } >+ >+ /* >+ * Check if date range have the same opening, closing hours and holiday type if there's one. >+ */ >+ function checkRange(date) { >+ date = new Date(date); >+ $('#to_date').val(getSeparetedDate(date).dateString); >+ var fromDate = new Date(document.querySelector("#calendar-anchor")._flatpickr.selectedDates[0]); >+ var sameHoliday =true; >+ var sameOpenHours =true; >+ var sameCloseHours =true; >+ >+ $('#days_of_week option[value="everyday"]').attr('selected', true); >+ for (var i = fromDate; i <= date; i.setDate(i.getDate() + 1)) { >+ var myDate1 = getSeparetedDate(i); >+ var date1 = myDate1.dateString; >+ var holidayType1 = datesInfos[date1].holiday_type; >+ var open_hours1 = datesInfos[date1].open_hour; >+ var close_hours1 = datesInfos[date1].close_hour; >+ for (var j = fromDate; j <= date; j.setDate(j.getDate() + 1)) { >+ var myDate2 = getSeparetedDate(j); >+ var date2 = myDate2.dateString; >+ var holidayType2 = datesInfos[date2].holiday_type; >+ var open_hours2 = datesInfos[date2].open_hour; >+ var close_hours2 = datesInfos[date2].close_hour; >+ >+ if (sameHoliday && holidayType1 != holidayType2) { >+ $('#holidayType option[value="empty"]').attr('selected', true); >+ sameHoliday=false; >+ } >+ if (sameOpenHours && (open_hours1 != open_hours2)) { >+ $('#openHour').val(''); >+ sameOpenHours=false; >+ } >+ if (sameCloseHours && (close_hours1 != close_hours2)) { >+ $('#closeHour').val(''); >+ sameCloseHours=false; >+ } >+ } >+ if (!sameOpenHours && !sameCloseHours && !sameHoliday) { >+ return false; >+ } >+ } >+ return true; >+ } >+ >+ /* Custom table search configuration: If a table row >+ has an "expired" class, hide it UNLESS the >+ show_expired checkbox is checked */ >+ $.fn.dataTable.ext.search.push( >+ function( settings, searchData, index, rowData, counter ) { >+ var table = settings.nTable.id; >+ var row = $(settings.aoData[index].nTr); >+ if( row.hasClass("date_past") && !$("#show_past_" + table ).prop("checked") ){ >+ return false; >+ } else { >+ return true; >+ } >+ } >+ ); >+ >+ // Create current date variable >+ var date = new Date(); >+ var datestring = date.toISOString().substring(0, 10); >+ >+ $(document).ready(function() { >+ $(".hint").hide(); >+ $("#days_of_week").hide(); >+ $("#deleteType").hide(); >+ $(".CopyDatePanel").hide(); >+ >+ $("#branch").change(function() { >+ var branch = $(this).find("option:selected").val(); >+ location.href = '/cgi-bin/koha/tools/discrete_calendar.pl?branch=' + branch + '&calendardate=' + "[% calendardate | html %]"; >+ }); >+ >+ $("#holidayweeklyrepeatable>tbody>tr").each(function() { >+ var first_td = $(this).find('td').first(); >+ var date_index = parseInt(first_td.html()) - 1; >+ first_td.html(weekdays[date_index]); >+ }); >+ $("#holidayweeklyrepeatable").dataTable($.extend(true, {}, dataTablesDefaults, { >+ "sDom": 't', >+ "bPaginate": false >+ })); >+ var tables = $("#holidaysyearlyrepeatable, #holidaysunique, #holidaysfloat").DataTable($.extend(true, {}, dataTablesDefaults, { >+ "sDom": 't', >+ "bPaginate": false, >+ "createdRow": function( row, data, dataIndex ) { >+ var holiday = $(row).data("date"); >+ if( holiday < datestring ){ >+ $(row).addClass("date_past"); >+ } >+ } >+ })); >+ >+ $(".show_past").on("change", function(){ >+ tables.draw(); >+ }); >+ >+ $("a.helptext").click(function () { >+ $(this).parent().find(".hint") >+ .css("max-width", ($(this).closest("#newHoliday").width() - 20)+"px") >+ .toggle(); >+ return false; >+ }); >+ >+ $("form").on("submit", function() { >+ return validateForm($(this).attr("id")); >+ }); >+ >+ flatpickr.setDefaults({ >+ onDayCreate: function( dObj, dStr, fp, dayElem ){ >+ /* for each day on the calendar, get the >+ correct status information for the date */ >+ dateStatusHandler( dayElem ); >+ }, >+ minDate: new Date("[% minDate | html %]"), >+ maxDate: new Date("[% maxDate | html %]") >+ }); >+ >+ // Main flatpickr >+ $("#calendar-anchor").flatpickr({ >+ inline: true, >+ onReady: function( selectedDates, dateStr, instance ){ >+ // We do not want to display the 'close' icon in this case >+ $(instance.input).siblings('.flatpickr-input').hide(); >+ }, >+ onChange: function(selectedDates, dateStr, instance) { >+ [% IF datesInfos %] >+ var date = getSeparetedDate(selectedDates[0]); >+ var weekDay = date.weekDay; >+ var dayName = weekdays[weekDay]; >+ var dateString = date.dateString; >+ >+ // set value of form hidden field >+ $('#from_date').val(dateStr); >+ showHoliday(date.date_obj, dateString, dayName, date.day, date.month, date.year, weekDay, datesInfos[dateString].title, datesInfos[dateString].description, datesInfos[dateString].holiday_type); >+ [% END %] >+ } >+ }); >+ >+ $('#to_date_flatpickr').flatpickr(); >+ $("#to_date_flatpickr").change(function() { >+ checkRange(document.querySelector("#to_date_flatpickr")._flatpickr.selectedDates[0]); >+ $('#to_date').val(($("#to_date_flatpickr").val())); >+ if ($('#to_date_flatpickr').val()) { >+ $('#days_of_week').show("fast"); >+ } else { >+ $('#days_of_week').hide("fast"); >+ } >+ }); >+ >+ // Flatpickrs for copy dates feature >+ $('#copyto_from_flatpickr').flatpickr({ >+ onChange: function(selectedDates, dateStr, instance) { >+ document.querySelector('#copyto_to_flatpickr')._flatpickr.set('minDate', dateStr); >+ } >+ }); >+ $("#copyto_from_flatpickr").change(function() { >+ $('#copyto_from').val(($(this).val())); >+ }); >+ >+ $('#copyto_to_flatpickr').flatpickr(); >+ $("#copyto_to_flatpickr").change(function() { >+ $('#copyto_to').val(($(this).val())); >+ }); >+ >+ // Flatpickrs for open and close hours >+ timeoptions = { >+ plugins: [], >+ enableTime: true, >+ noCalendar: true, >+ dateFormat: "H:i:S", >+ altInput: false, >+ defaultHour: 12, >+ defaultMinute: 0, >+ onOpen: function( selectedDates, dateStr, instance ) { >+ instance.setDate(instance.input.value, false); >+ } >+ } >+ $('#openHour').flatpickr(timeoptions); >+ $('#closeHour').flatpickr(timeoptions); >+ >+ $('.newHoliday input[type="radio"]').click(function() { >+ if ($(this).attr("id") == "CopyRadioButton") { >+ $(".CopyToBranchPanel").hide('fast'); >+ $(".CopyDatePanel").show('fast'); >+ } else if ($(this).attr("id") == "CopyToBranchRadioButton") { >+ $(".CopyDatePanel").hide('fast'); >+ $(".CopyToBranchPanel").show('fast'); >+ } else { >+ $(".CopyDatePanel").hide('fast'); >+ $(".CopyToBranchPanel").hide('fast'); >+ } >+ }); >+ >+ $(".hidePanel").on("click", function() { >+ $(this).closest(".panel").slideUp("fast"); >+ }); >+ >+ $("#deleteType_checkbox").on("change", function() { >+ if ($("#deleteType_checkbox").is(':checked')) { >+ $('#holidayType option[value="none"]').attr('selected', true); >+ } >+ }); >+ >+ $("#holidayType select").on("change", function() { >+ if ($("#holidayType select").val() == "R") { >+ $('#days_of_week').hide("fast"); >+ } else if ($('#to_date_flatpickr').val()) { >+ $('#days_of_week').show("fast"); >+ } >+ }); >+ }); >+ </script> >+[% END %] >+ >+[% INCLUDE 'intranet-bottom.inc' %] >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 6f12d5fc69a..01e6d2e2f19 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 >@@ -122,7 +122,7 @@ > [% END %] > <dl> > [% IF ( CAN_user_tools_edit_calendar ) %] >- <dt><a href="/cgi-bin/koha/tools/holidays.pl">Calendar</a></dt> >+ <dt><a href="/cgi-bin/koha/tools/discrete_calendar.pl">Calendar</a></dt> > <dd>Define days when the library is closed</dd> > [% END %] > >diff --git a/misc/cronjobs/add_days_discrete_calendar.pl b/misc/cronjobs/add_days_discrete_calendar.pl >new file mode 100755 >index 00000000000..08cce1b25d2 >--- /dev/null >+++ b/misc/cronjobs/add_days_discrete_calendar.pl >@@ -0,0 +1,166 @@ >+#!/usr/bin/perl >+ >+# >+# This script adds one day into discrete_calendar table based on the same day from the week before >+# >+use Modern::Perl; >+use DateTime; >+use DateTime::Format::Strptime; >+use Data::Dumper; >+use Getopt::Long; >+use C4::Context; >+use Koha::Database; >+use Koha::DiscreteCalendar; >+use Koha::DateUtils qw ( output_pref ); >+ >+# Options >+my $help = 0; >+my $daysInFuture = 1; >+my $branch = undef; >+my $debug = 0; >+GetOptions ( >+ 'help|?|h' => \$help, >+ 'n=i' => \$daysInFuture, >+ 'b|branch=s' => \$branch, >+ 'd|debug' => \$debug >+); >+ >+my $usage = << 'ENDUSAGE'; >+ >+This script adds days into discrete_calendar table based on the same day from the week before. >+ >+Examples : >+ The latest date on discrete_calendar is : 28-07-2017 >+ The current date : 01-08-2016 >+ The dates that will be added are : 29-07-2017, 30-07-2017, 31-07-2017, 01-08-2017 >+Open close examples : >+ Date added is : 29-07-2017 >+ Opening/closing hours will be base on : 22-07-2017 (- 7 days) >+ Library open or closed will be based on : 29-07-2017 (- 1 year) >+This script has the following parameters: >+ -h --help: this message >+ -n : number of days to add in the futre, default : 1 >+ -b --branch: branchcode of the library to which days will be added >+ -d --debug: displays all added days and errors if there is any >+ >+ENDUSAGE >+ >+if ($help) { >+ print $usage; >+ exit; >+} >+ >+my $schema = Koha::Database->new->schema; >+$schema->storage->txn_begin; >+my $dbh = C4::Context->dbh; >+ >+# Predeclaring variables that will be used several times in the code >+my $query; >+my $statement; >+ >+#getting the all the branches >+my @branches = (); >+if ( $branch ) { >+ push @branches, $branch; >+} else { >+ $query = 'SELECT branchcode FROM discrete_calendar GROUP BY branchcode'; >+ $statement = $dbh->prepare($query); >+ $statement->execute(); >+ for my $branchcode ( @{$statement->fetchall_arrayref} ) { >+ push @branches, $branchcode->[0]; >+ } >+} >+ >+foreach my $branchCode (@branches) { >+ #get the latest date in the table >+ $query = "SELECT MAX(date) FROM discrete_calendar WHERE branchcode = ?"; >+ $statement = $dbh->prepare($query); >+ $statement->execute($branchCode); >+ my $latestDate = $statement->fetchrow_array; >+ >+ if ( $latestDate ) { >+ my $parser = DateTime::Format::Strptime->new( >+ pattern => '%Y-%m-%d %H:%M:%S', >+ on_error => 'croak', >+ ); >+ $latestDate = $parser->parse_datetime($latestDate); >+ } else { >+ $latestDate = dt_from_string(); >+ } >+ >+ my $newDay = $latestDate->clone(); >+ $latestDate->add(days => $daysInFuture); >+ >+ for ($newDay->add(days => 1); $newDay <= $latestDate; $newDay->add(days => 1)) { >+ my $lastWeekDay = $newDay->clone(); >+ $lastWeekDay->add(days=> -8); >+ my $dayOfWeek = $lastWeekDay->day_of_week; >+ # Representation fix >+ # DateTime object dow (1-7) where Monday is 1 >+ # Arrays are 0-based where 0 = Sunday, not 7. >+ $dayOfWeek -= 1 unless $dayOfWeek == 7; >+ $dayOfWeek = 0 if $dayOfWeek == 7; >+ >+ #checking if it was open on the same day from last year >+ my $yearAgo = $newDay->clone(); >+ $yearAgo = $yearAgo->add(years => -1); >+ my $last_year = 'SELECT is_opened, holiday_type, note FROM discrete_calendar WHERE date=? AND branchcode=?'; >+ my $day_last_week = "SELECT open_hour, close_hour, holiday_type, note FROM discrete_calendar WHERE DAYOFWEEK(date)=DAYOFWEEK(?) and date < ? order by date desc limit 1"; >+ my $add_Day = 'INSERT INTO discrete_calendar (date, branchcode, is_opened, open_hour, close_hour) VALUES (?, ?, ?, ?, ?)'; >+ >+ #insert into discrete_calendar >+ $statement = $dbh->prepare($last_year); >+ $statement->execute($yearAgo, $branchCode); >+ my ($is_opened, $holiday_type, $note) = $statement->fetchrow_array; >+ #weekly and unique holidays are not replicated in the future >+ if ( $holiday_type && $holiday_type ne "R" ) { >+ $is_opened = 1; >+ if ( $holiday_type eq "W" || $holiday_type eq "E" ) { >+ $holiday_type=''; >+ $note=''; >+ } elsif ( $holiday_type eq "F" ) { >+ $holiday_type = 'N'; >+ $is_opened = 0; >+ } >+ } >+ $holiday_type = '' if $is_opened; >+ $statement = $dbh->prepare($day_last_week); >+ $statement->execute($newDay, $newDay); >+ my ( $open_hour, $close_hour, $weekly_holiday_type, $weekly_note ) = $statement->fetchrow_array; >+ >+ # weekly repeatable holidays >+ if ( $weekly_holiday_type && $weekly_holiday_type eq 'W' ) { >+ $is_opened = 0; >+ $holiday_type = $weekly_holiday_type unless $holiday_type; >+ $note = $weekly_note unless $note; >+ } >+ >+ my $data = { >+ date => output_pref( { dt => $newDay, dateformat => 'iso', timeformat => '24hr' }), >+ branchcode => $branchCode, >+ }; >+ >+ $data->{is_opened} = $is_opened if ( defined $is_opened ); >+ $data->{holiday_type} = $holiday_type if ( defined $holiday_type ); >+ $data->{note} = $note if ( defined $note ); >+ $data->{open_hour} = $open_hour // "09:00:00"; >+ $data->{close_hour} = $close_hour // "17:00:00"; >+ >+ my $calendar_date = $schema->resultset( "DiscreteCalendar" )->create( $data )->get_from_storage(); >+ >+ if ( $debug && !$@ ) { >+ warn "Added day " . $calendar_date->date >+ . " to " . $calendar_date->branchcode >+ . " is opened: " . $calendar_date->is_opened >+ . ", holiday_type: " . $calendar_date->holiday_type >+ . ", note: " . $calendar_date->note >+ . ", open_hour: " . $calendar_date->open_hour >+ . ", close_hour: " . $calendar_date->close_hour >+ . " \n"; >+ } elsif ( $@ ) { >+ warn "Failed to add day $newDay to $branchCode : $_\n"; >+ } >+ } >+} >+# If everything went well we commit to the database >+$schema->storage->txn_commit; >diff --git a/misc/cronjobs/fines.pl b/misc/cronjobs/fines.pl >index 4765eff3cdf..a96acd64585 100755 >--- a/misc/cronjobs/fines.pl >+++ b/misc/cronjobs/fines.pl >@@ -38,8 +38,8 @@ use Carp qw( carp croak ); > use File::Spec; > use Try::Tiny qw( catch try ); > >-use Koha::Calendar; > use Koha::DateUtils qw( dt_from_string output_pref ); >+use Koha::DiscreteCalendar; > use Koha::Patrons; > use C4::Log qw( cronlogaction ); > >@@ -217,7 +217,7 @@ cronlogaction( { action => 'End', info => "COMPLETED" } ); > 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/holds/cancel_unfilled_holds.pl b/misc/cronjobs/holds/cancel_unfilled_holds.pl >index 99961e8e997..793aa117d4a 100755 >--- a/misc/cronjobs/holds/cancel_unfilled_holds.pl >+++ b/misc/cronjobs/holds/cancel_unfilled_holds.pl >@@ -25,7 +25,8 @@ use Koha::Script -cron; > use C4::Reserves; > use C4::Log qw( cronlogaction ); > use Koha::Holds; >-use Koha::Calendar; >+use Koha::DiscreteCalendar; >+use Koha::DateUtils; > use Koha::Libraries; > > cronlogaction(); >diff --git a/misc/cronjobs/holds/holds_reminder.pl b/misc/cronjobs/holds/holds_reminder.pl >index 33ccfb37c8d..d3a0be6c89f 100755 >--- a/misc/cronjobs/holds/holds_reminder.pl >+++ b/misc/cronjobs/holds/holds_reminder.pl >@@ -26,7 +26,7 @@ use C4::Context; > use C4::Letters; > use C4::Log qw( cronlogaction ); > use Koha::DateUtils qw( dt_from_string ); >-use Koha::Calendar; >+use Koha::DiscreteCalendar; > use Koha::Libraries; > use Koha::Notice::Templates; > use Koha::Patrons; >@@ -242,7 +242,7 @@ foreach my $branchcode (@branchcodes) { #BEGIN BRANCH LOOP > # If respecting calendar get the correct waiting since date > my $waiting_date; > if ($use_calendar) { >- my $calendar = Koha::Calendar->new( branchcode => $branchcode, days_mode => 'Calendar' ); >+ my $calendar = Koha::DiscreteCalendar->new({ branchcode => $branchcode, days_mode => 'Calendar' }); > > #if today is a holiday skip sending the message > next if $calendar->is_holiday($date_to_run); >diff --git a/misc/cronjobs/overdue_notices.pl b/misc/cronjobs/overdue_notices.pl >index f6bd9b2449e..8ed4fe94a1e 100755 >--- a/misc/cronjobs/overdue_notices.pl >+++ b/misc/cronjobs/overdue_notices.pl >@@ -33,7 +33,7 @@ use C4::Overdues qw( GetOverdueMessageTransportTypes parse_overdues_ > use C4::Log qw( cronlogaction ); > use Koha::Patron::Debarments qw( AddUniqueDebarment ); > use Koha::DateUtils qw( dt_from_string output_pref ); >-use Koha::Calendar; >+use Koha::DiscreteCalendar; > use Koha::Libraries; > use Koha::Acquisition::Currencies; > use Koha::Patrons; >@@ -486,7 +486,7 @@ my %seen = map { $_ => 1 } @branches; > foreach my $branchcode (@branches) { > my $calendar; > if ( C4::Context->preference('OverdueNoticeCalendar') ) { >- $calendar = Koha::Calendar->new( branchcode => $branchcode ); >+ $calendar = Koha::DiscreteCalendar->new({ branchcode => $branchcode }); > if ( $calendar->is_holiday($date_to_run) ) { > next; > } >diff --git a/misc/cronjobs/staticfines.pl b/misc/cronjobs/staticfines.pl >index 966109b5978..42aede4eda8 100755 >--- a/misc/cronjobs/staticfines.pl >+++ b/misc/cronjobs/staticfines.pl >@@ -32,7 +32,7 @@ use Date::Calc qw( Date_to_Days ); > use Koha::Script -cron; > use C4::Context; > use C4::Overdues qw( CalcFine checkoverdues GetFine Getoverdues ); >-use C4::Calendar qw(); # don't need any exports from Calendar >+use C4::DiscreteCalendar qw(); # don't need any exports from Calendar > use C4::Log qw( cronlogaction ); > use Getopt::Long qw( GetOptions ); > use List::MoreUtils qw( none ); >@@ -178,7 +178,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 d9412c24da4..f2d246af891 100755 >--- a/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl >+++ b/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl >@@ -27,8 +27,8 @@ use Koha::Script -cron; > use C4::Context; > use C4::Letters; > use C4::Overdues; >-use Koha::Calendar; > use Koha::DateUtils qw( dt_from_string output_pref ); >+use Koha::DiscreteCalendar; > use Koha::Patrons; > use Koha::Libraries; > >@@ -364,7 +364,7 @@ sub GetWaitingHolds { > } > ); > >- my $calendar = Koha::Calendar->new( branchcode => $issue->{'site'}, days_mode => $daysmode ); >+ my $calendar = Koha::DiscreteCalendar->new({ branchcode => $issue->{'site'}, days_mode => $daysmode }); > > my $waiting_date = dt_from_string( $issue->{waitingdate}, 'sql' ); > >diff --git a/tmp/DiscreteCalendar_performance/benchmark_checkins.pl b/tmp/DiscreteCalendar_performance/benchmark_checkins.pl >old mode 100644 >new mode 100755 >diff --git a/tools/discrete_calendar.pl b/tools/discrete_calendar.pl >new file mode 100755 >index 00000000000..71c46a9e8d7 >--- /dev/null >+++ b/tools/discrete_calendar.pl >@@ -0,0 +1,171 @@ >+#!/usr/bin/perl >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+#####Sets holiday periods for each branch. Datedues will be extended if branch is closed -TG >+use Modern::Perl; >+ >+use CGI qw ( -utf8 ); >+ >+use C4::Auth qw( get_template_and_user ); >+use C4::Output qw( output_html_with_http_headers ); >+ >+use Koha::DateUtils qw ( dt_from_string output_pref ); >+use Koha::DiscreteCalendar; >+ >+my $input = CGI->new; >+ >+# Get the template to use >+my ($template, $loggedinuser, $cookie) = get_template_and_user( >+ { >+ template_name => "tools/discrete_calendar.tt", >+ type => "intranet", >+ query => $input, >+ flagsrequired => {tools => 'edit_calendar'}, >+ } >+); >+ >+my $branch = $input->param('branch') || C4::Context->userenv->{'branch'}; >+my $calendar = Koha::DiscreteCalendar->new({branchcode => $branch}); >+#alert the user that they are using the default calendar because they do not have a library set >+my $no_branch_selected = $calendar->{no_branch_selected}; >+ >+my $weekday = $input->param('day_of_week'); >+ >+my $holiday_type = $input->param('holidayType'); >+my $allbranches = $input->param('allBranches'); >+ >+my $title = $input->param('Title'); >+my $description = $input->param('description'); >+ >+my $action = $input->param('action') || ''; >+ >+# calendardate - date passed in url for human readability (syspref) >+# if the url has an invalid date default to 'now.' >+# FIXME There is something to improve in the date handling here >+my $calendarinput_dt = eval { dt_from_string( scalar $input->param('calendardate') ); } || dt_from_string; >+my $calendardate = output_pref( { dt => $calendarinput_dt, dateonly => 1 } ); >+ >+if ($action eq 'copyBranch') { >+ my $new_branch = scalar $input->param('newBranch'); >+ $calendar->copy_to_branch($new_branch) if $new_branch; >+} elsif($action eq 'copyDates') { >+ my $from_startDate = $input->param('from_date') ||''; >+ my $from_endDate = $input->param('to_date') || ''; >+ my $to_startDate = $input->param('copyto_from') || ''; >+ my $to_endDate = $input->param('copyto_to') || ''; >+ my $local_today = $input->param('local_today'); >+ my $daysnumber = $input->param('daysnumber'); >+ >+ $from_startDate = eval { dt_from_string(scalar $from_startDate) } if $from_startDate ne ''; >+ $from_endDate = eval { dt_from_string(scalar $from_endDate) } if $from_endDate ne ''; >+ $to_startDate = eval { dt_from_string(scalar $to_startDate) } if $to_startDate ne ''; >+ $to_endDate = eval { dt_from_string(scalar $to_endDate) } if $to_endDate ne ''; >+ $local_today = eval { dt_from_string( $local_today, 'iso') }; >+ >+ unless ($@) { >+ my $diff_from_today = $local_today - $to_startDate; >+ if ( $diff_from_today->is_positive ) { >+ $template->param( >+ cannot_edit_past_dates => 1, >+ error_date => $to_startDate >+ ); >+ } >+ else { >+ $calendar->copy_holiday($from_startDate, $from_endDate, $to_startDate, $to_endDate, $daysnumber); >+ } >+ } else { >+ $template->param( date_format_error => 1 ); >+ } >+} elsif ($action eq 'edit') { >+ my $openHour = $input->param('openHour'); >+ my $closeHour = $input->param('closeHour'); >+ my $startDate = $input->param('from_date'); >+ my $endDate = $input->param('to_date'); >+ my $deleteType = $input->param('deleteType') || 0; >+ my $all_branches = $input->param('all_branches') || 0; >+ #Get today from javascript for a precise local time >+ my $local_today = $input->param('local_today'); >+ $local_today = eval { dt_from_string( $local_today, 'iso') }; >+ >+ $startDate = eval { dt_from_string(scalar $startDate) }; >+ >+ unless ($@) { >+ if($endDate ne '' ) { >+ $endDate = eval { dt_from_string(scalar $endDate) }; >+ } else { >+ $endDate = $startDate->clone(); >+ } >+ >+ $calendar->edit_holiday({ >+ title => $title, >+ description => $description, >+ weekday => $weekday, >+ holiday_type => $holiday_type, >+ open_hour => $openHour, >+ close_hour => $closeHour, >+ start_date => $startDate, >+ end_date => $endDate, >+ delete_type => $deleteType, >+ all_branches => $all_branches, >+ today => $local_today >+ }); >+ } else { >+ $template->param( date_format_error => 1 ); >+ } >+} >+ >+# keydate - date passed to calendar.js. calendar.js does not process dashes within a date. >+ >+my $keydate = output_pref( { dt => $calendarinput_dt, dateonly => 1, dateformat => 'iso' } ); >+$keydate =~ s/-/\//g; >+ >+# Set all the branches. >+if ( C4::Context->only_my_library ) { >+ $branch = C4::Context->userenv->{'branch'}; >+} >+ >+# Get all the holidays >+ >+my @week_days = $calendar->get_week_days_holidays(); >+my @repeatable_holidays = $calendar->get_repeatable_holidays(); >+my @unique_holidays = $calendar->get_unique_holidays(0); >+my @float_holidays = $calendar->get_float_holidays(0); >+my @need_validation_holidays = $calendar->get_need_validation_holidays(); >+ >+#Calendar minimum & maximum dates >+my $minDate = $calendar->get_min_date(); >+my $maxDate = $calendar->get_max_date(); >+ >+my @datesInfos = $calendar->get_dates_info(); >+ >+$template->param( >+ WEEKLY_HOLIDAYS => \@week_days, >+ REPEATABLE_HOLIDAYS => \@repeatable_holidays, >+ UNIQUE_HOLIDAYS => \@unique_holidays, >+ FLOAT_HOLIDAYS => \@float_holidays, >+ NEED_VALIDATION_HOLIDAYS => \@need_validation_holidays, >+ calendardate => $calendardate, >+ keydate => $keydate, >+ branch => $branch, >+ minDate => $minDate, >+ maxDate => $maxDate, >+ datesInfos => \@datesInfos, >+ no_branch_selected => $no_branch_selected, >+); >+ >+# Shows the template with the real values replaced >+output_html_with_http_headers $input, $cookie, $template->output; >diff --git a/tools/exceptionHolidays.pl b/tools/exceptionHolidays.pl >deleted file mode 100755 >index e00b26bc8de..00000000000 >--- a/tools/exceptionHolidays.pl >+++ /dev/null >@@ -1,206 +0,0 @@ >-#!/usr/bin/perl >- >-use Modern::Perl; >- >-use CGI qw ( -utf8 ); >- >-use C4::Auth qw( checkauth ); >-use C4::Output; >-use DateTime; >- >-use C4::Calendar; >-use Koha::DateUtils qw( dt_from_string ); >- >-my $input = CGI->new; >-my $op = $input->param('op') // q{}; >-my $dbh = C4::Context->dbh(); >- >-checkauth( $input, 0, { tools => 'edit_calendar' }, 'intranet' ); >- >-our $branchcode = $input->param('showBranchName'); >-my $originalbranchcode = $branchcode; >-our $weekday = $input->param('showWeekday'); >-our $day = $input->param('showDay'); >-our $month = $input->param('showMonth'); >-our $year = $input->param('showYear'); >-our $title = $input->param('showTitle'); >-our $description = $input->param('showDescription'); >-our $holidaytype = $input->param('showHolidayType'); >-my $datecancelrange_dt = eval { dt_from_string( scalar $input->param('datecancelrange') ) }; >-my $calendardate = sprintf( "%04d-%02d-%02d", $year, $month, $day ); >-our $showoperation = $input->param('showOperation'); >-my $allbranches = $input->param('allBranches'); >- >-$title || ( $title = '' ); >-if ($description) { >- $description =~ s/\r/\\r/g; >- $description =~ s/\n/\\n/g; >-} else { >- $description = ''; >-} >- >-# We make an array with holiday's days >-our @holiday_list; >-if ($datecancelrange_dt) { >- my $first_dt = DateTime->new( year => $year, month => $month, day => $day ); >- >- for ( my $dt = $first_dt->clone() ; $dt <= $datecancelrange_dt ; $dt->add( days => 1 ) ) { >- push @holiday_list, $dt->clone(); >- } >-} >- >-if ( $op eq 'cud-edit' && $allbranches ) { >- my $libraries = Koha::Libraries->search; >- while ( my $library = $libraries->next ) { >- edit_holiday( >- $showoperation, $library->branchcode, $weekday, $day, $month, $year, $title, $description, >- $holidaytype, @holiday_list >- ); >- } >-} elsif ( $op eq 'cud-edit' ) { >- edit_holiday( >- $showoperation, $branchcode, $weekday, $day, $month, $year, $title, $description, $holidaytype, >- @holiday_list >- ); >-} >- >-print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$originalbranchcode&calendardate=$calendardate"); >- >-sub edit_holiday { >- ( $showoperation, $branchcode, $weekday, $day, $month, $year, $title, $description, $holidaytype, @holiday_list ) = >- @_; >- my $calendar = C4::Calendar->new( branchcode => $branchcode ); >- >- if ( $showoperation eq 'exception' ) { >- $calendar->insert_exception_holiday( >- day => $day, >- month => $month, >- year => $year, >- title => $title, >- description => $description >- ); >- } elsif ( $showoperation eq 'exceptionrange' ) { >- if (@holiday_list) { >- foreach my $date (@holiday_list) { >- $calendar->insert_exception_holiday( >- day => $date->{local_c}->{day}, >- month => $date->{local_c}->{month}, >- year => $date->{local_c}->{year}, >- title => $title, >- description => $description >- ); >- } >- } >- } elsif ( $showoperation eq 'cud-edit' ) { >- if ( $holidaytype eq 'weekday' ) { >- my $isHoliday = $calendar->isHoliday( $day, $month, $year ); >- if ($isHoliday) { >- $calendar->ModWeekdayholiday( >- weekday => $weekday, >- title => $title, >- description => $description >- ); >- } else { >- $calendar->insert_week_day_holiday( >- weekday => $weekday, >- title => $title, >- description => $description >- ); >- } >- } elsif ( $holidaytype eq 'daymonth' ) { >- my $isHoliday = $calendar->isHoliday( $day, $month, $year ); >- if ($isHoliday) { >- $calendar->ModDaymonthholiday( >- day => $day, >- month => $month, >- title => $title, >- description => $description >- ); >- } else { >- $calendar->insert_day_month_holiday( >- day => $day, >- month => $month, >- title => $title, >- description => $description >- ); >- } >- } elsif ( $holidaytype eq 'ymd' ) { >- my $isHoliday = $calendar->isHoliday( $day, $month, $year ); >- if ($isHoliday) { >- $calendar->ModSingleholiday( >- day => $day, >- month => $month, >- year => $year, >- title => $title, >- description => $description >- ); >- } else { >- $calendar->insert_single_holiday( >- day => $day, >- month => $month, >- year => $year, >- title => $title, >- description => $description >- ); >- } >- } elsif ( $holidaytype eq 'exception' ) { >- my $isHoliday = $calendar->isHoliday( $day, $month, $year ); >- if ($isHoliday) { >- $calendar->ModExceptionholiday( >- day => $day, >- month => $month, >- year => $year, >- title => $title, >- description => $description >- ); >- } else { >- $calendar->insert_exception_holiday( >- day => $day, >- month => $month, >- year => $year, >- title => $title, >- description => $description >- ); >- } >- } >- } elsif ( $showoperation eq 'cud-delete' ) { >- $calendar->delete_holiday( >- weekday => $weekday, >- day => $day, >- month => $month, >- year => $year >- ); >- } elsif ( $showoperation eq 'deleterange' ) { >- if (@holiday_list) { >- foreach my $date (@holiday_list) { >- $calendar->delete_holiday_range( >- weekday => $weekday, >- day => $date->{local_c}->{day}, >- month => $date->{local_c}->{month}, >- year => $date->{local_c}->{year} >- ); >- } >- } >- } elsif ( $showoperation eq 'deleterangerepeat' ) { >- if (@holiday_list) { >- foreach my $date (@holiday_list) { >- $calendar->delete_holiday_range_repeatable( >- weekday => $weekday, >- day => $date->{local_c}->{day}, >- month => $date->{local_c}->{month} >- ); >- } >- } >- } elsif ( $showoperation eq 'deleterangerepeatexcept' ) { >- if (@holiday_list) { >- foreach my $date (@holiday_list) { >- $calendar->delete_exception_holiday_range( >- weekday => $weekday, >- day => $date->{local_c}->{day}, >- month => $date->{local_c}->{month}, >- year => $date->{local_c}->{year} >- ); >- } >- } >- } >-} >-- >2.34.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 17015
:
53859
|
54318
|
54419
|
59166
|
59167
|
59168
|
59169
|
59170
|
59171
|
59267
|
59268
|
59269
|
59270
|
59271
|
59463
|
59516
|
59517
|
59518
|
59519
|
59520
|
59561
|
59562
|
59586
|
59587
|
59888
|
59889
|
60902
|
60903
|
60904
|
60905
|
60906
|
60986
|
61737
|
62375
|
62376
|
62380
|
63257
|
63282
|
63362
|
63363
|
63364
|
63365
|
63366
|
63367
|
64235
|
65073
|
65074
|
65075
|
65076
|
65077
|
67721
|
67722
|
67723
|
67724
|
67725
|
67879
|
67929
|
67930
|
67931
|
67932
|
67933
|
67934
|
68392
|
68393
|
68394
|
68395
|
68396
|
68397
|
71634
|
71635
|
71636
|
71637
|
71638
|
72890
|
73145
|
74859
|
74860
|
74861
|
74862
|
74863
|
74864
|
74865
|
74866
|
75444
|
75479
|
76594
|
77249
|
77250
|
77607
|
77608
|
77609
|
77610
|
77611
|
77612
|
77613
|
77770
|
77771
|
77772
|
77773
|
77774
|
79035
|
80523
|
80524
|
80525
|
80526
|
80527
|
80528
|
80529
|
80530
|
80531
|
80532
|
80533
|
80534
|
80535
|
83547
|
85394
|
85677
|
85678
|
85679
|
85680
|
85681
|
85682
|
85683
|
85684
|
85685
|
85686
|
85687
|
85688
|
85689
|
85690
|
85691
|
92595
|
92596
|
92597
|
92598
|
100079
|
110383
|
110384
|
110386
|
110387
|
110388
|
110389
|
113541
|
113905
|
115501
|
115502
|
115503
|
115504
|
115505
|
115506
|
115507
|
115508
|
115509
|
115510
|
115511
|
118554
|
118555
|
118556
|
118557
|
118558
|
118559
|
119095
|
119097
|
119099
|
119100
|
119101
|
119102
|
131619
|
131620
|
131621
|
131622
|
131623
|
131624
|
131625
|
131626
|
131634
|
131635
|
131636
|
131637
|
131638
|
131639
|
131640
|
131641
|
131667
|
132199
|
133596
|
133597
|
133598
|
133599
|
133600
|
133601
|
133602
|
133603
|
133604
|
133605
|
133678
|
137219
|
137220
|
137221
|
137222
|
137223
|
137224
|
137225
|
137226
|
137227
|
137228
|
137229
|
139378
|
139379
|
139380
|
139381
|
139382
|
139599
|
139600
|
139601
|
139602
|
139603
|
139851
|
140150
|
141176
|
144257
|
144258
|
144259
|
144260
|
144261
|
144262
|
144264
|
144268
|
144269
|
144270
|
144271
|
144272
|
144273
|
151438
|
151439
|
151440
|
151441
|
151442
|
151443
|
151444
|
151445
|
151446
|
151447
|
151448
|
151449
|
151450
|
156340
|
156341
|
156342
|
156343
|
156344
|
156345
|
156346
|
156347
|
156348
|
156349
|
156350
|
156351
|
156352
|
156353
|
156354
|
156355
|
157656
|
157657
|
157658
|
157659
|
157660
|
157661
|
157662
|
157663
|
157664
|
157665
|
157666
|
157667
|
157668
|
157669
|
157670
|
157671
|
157672
|
167805
|
167806
|
167807
|
167808
|
167809
|
180312
|
180313
|
180314
|
180315
|
180316
|
180552
|
180962
|
181466
|
183006
|
185569
|
185570
|
185571
|
185572
|
185573
|
185574
|
185575
|
185576
|
185577
|
193656
|
193657
| 193658 |
193659
|
193660
|
193661
|
193662
|
193663
|
193664
|
193665