From 701692b5fd747199b7bf00fad131e329584c1f90 Mon Sep 17 00:00:00 2001 From: Maryse Simard Date: Wed, 11 Nov 2020 19:42:48 -0500 Subject: [PATCH] Bug 17015: cronjob to add days must repeat weekly holidays --- misc/cronjobs/add_days_discrete_calendar.pl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/misc/cronjobs/add_days_discrete_calendar.pl b/misc/cronjobs/add_days_discrete_calendar.pl index 2e4f3a94da..feb5a61c98 100755 --- a/misc/cronjobs/add_days_discrete_calendar.pl +++ b/misc/cronjobs/add_days_discrete_calendar.pl @@ -91,7 +91,7 @@ for ($newDay->add(days => 1); $newDay <= $latestedDate; $newDay->add(days => 1)) 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 FROM discrete_calendar WHERE DAYOFWEEK(date)=DAYOFWEEK(?) and date < ? order by date desc limit 1"; + 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 (?,?,?,?,?)'; my $note =''; #insert into discrete_calendar for each branch @@ -112,7 +112,15 @@ for ($newDay->add(days => 1); $newDay <= $latestedDate; $newDay->add(days => 1)) $holiday_type = '' if $is_opened; $statement = $dbh->prepare($day_last_week); $statement->execute($newDay, $newDay); - my ($open_hour,$close_hour ) = $statement->fetchrow_array; + my ( $open_hour, $close_hour, $weekly_holiday_type, $weekly_note ) = $statement->fetchrow_array; + + # weekly repeatable holidays + if ( $weekly_holiday_type eq 'W' ) { + $is_opened = 0; + $holiday_type = $weekly_holiday_type unless $holiday_type; + $note = $weekly_note unless $note; + } + my $add_Day = 'INSERT INTO discrete_calendar (date,branchcode,is_opened,holiday_type, note,open_hour,close_hour) VALUES (?,?,?,?,?,?,?)'; $statement = $dbh->prepare($add_Day); $statement->execute($newDay,$branchCode,$is_opened,$holiday_type,$note, $open_hour,$close_hour); -- 2.17.1