From 2354470f12e20e8c70f55eb1b17dd24b3382e175 Mon Sep 17 00:00:00 2001 From: Maryse Simard Date: Thu, 20 Oct 2022 16:51:21 -0400 Subject: [PATCH] Bug 17015: Allow holiday edits to be applied to all branches --- Koha/DiscreteCalendar.pm | 37 ++++++++----------- .../en/modules/tools/discrete_calendar.tt | 6 +++ tools/discrete_calendar.pl | 2 + 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/Koha/DiscreteCalendar.pm b/Koha/DiscreteCalendar.pm index 303ed502a7..fd80e1dd34 100644 --- a/Koha/DiscreteCalendar.pm +++ b/Koha/DiscreteCalendar.pm @@ -565,10 +565,9 @@ sub edit_holiday { 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' ); - my $branchcode = $self->{branchcode}; - # 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; @@ -591,15 +590,15 @@ sub edit_holiday { $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( - { - branchcode => $branchcode, - }, + $limits, { where => \[ 'DAYOFWEEK(date) = ? AND date >= DATE(?) AND date <= DATE(?)', $weekday, $start_date_string, $end_date_string], } @@ -617,9 +616,7 @@ sub edit_holiday { $where->{date}{'>='} = $today unless $override; my $rs = $schema->resultset('DiscreteCalendar')->search( - { - branchcode => $branchcode, - }, + $limits, { where => $where, } @@ -640,9 +637,7 @@ sub edit_holiday { 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( - { - branchcode => $branchcode, - }, + $limits, { where => $where, } @@ -660,9 +655,7 @@ sub edit_holiday { $where->{date}{'>='} = $today unless $override; my $rs = $schema->resultset('DiscreteCalendar')->search( - { - branchcode => $branchcode, - }, + $limits, { where => $where, } @@ -679,9 +672,9 @@ sub edit_holiday { while (my $date = $rs->next()) { if ($delete_type) { if ($date->holiday_type() eq $HOLIDAYS->{WEEKLY}) { - $self->remove_weekly_holidays($weekday, \%updateValues, $today); + $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); + $self->remove_repeatable_holidays($start_date, $end_date, \%updateValues, $today, $date->branchcode); } } else { $date->update(\%updateValues); @@ -694,18 +687,18 @@ sub edit_holiday { =head2 remove_weekly_holidays - $calendar->remove_weekly_holidays($weekday, $updateValues, $today); + $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) = @_; - my $branchcode = $self->{branchcode}; + my ($self, $weekday, $updateValues, $today, $branchcode) = @_; my $schema = Koha::Database->new->schema; my $rs = $schema->resultset('DiscreteCalendar')->search( @@ -726,19 +719,19 @@ sub remove_weekly_holidays { =head2 remove_repeatable_holidays - $calendar->remove_repeatable_holidays($startDate, $endDate, $today); + $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) = @_; - my $branchcode = $self->{branchcode}; + my ($self, $startDate, $endDate, $updateValues, $today, $branchcode) = @_; my $schema = Koha::Database->new->schema; my $parser = DateTime::Format::Strptime->new( pattern => '%m-%d', 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 index 75acc57204..863d39c0cf 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/discrete_calendar.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/discrete_calendar.tt @@ -170,6 +170,12 @@ +
  • + + . + [?] +
    If checked, this holiday will be copied to all libraries.
    +
  • diff --git a/tools/discrete_calendar.pl b/tools/discrete_calendar.pl index b85e470ef3..f7c041520f 100755 --- a/tools/discrete_calendar.pl +++ b/tools/discrete_calendar.pl @@ -95,6 +95,7 @@ if ($action eq 'copyBranch') { 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') }; @@ -118,6 +119,7 @@ if ($action eq 'copyBranch') { start_date => $startDate, end_date => $endDate, delete_type => $deleteType, + all_branches => $all_branches, today => $local_today }); } else { -- 2.25.1