View | Details | Raw Unified | Return to bug 17015
Collapse All | Expand All

(-)a/installer/data/mysql/atomicupdate/bug_17015_table_discrete_calendar.sql (+9 lines)
Line 0 Link Here
1
CREATE TABLE `discrete_calendar` (
2
  `date` datetime DEFAULT NULL,
3
  `branchcode` varchar(10) NOT NULL,
4
  `isopened` tinyint(1) DEFAULT 1,
5
  `note` varchar(30) DEFAULT NULL,
6
   openhour time,
7
   closehour time,
8
 PRIMARY KEY (`branchcode`,`date`)
9
)
(-)a/misc/cronjobs/add_days_discrete_calendar.pl (+103 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
#
4
#   This script adds one day into discrete_calendar table based on the same day from the week before
5
#
6
use strict;
7
use warnings;
8
use DateTime;
9
use DateTime::Format::Strptime;
10
use Getopt::Long;
11
use C4::Context;
12
# Options
13
my $help = 0;
14
GetOptions (
15
    'help|?|h' => \$help);
16
17
my $usage = << 'ENDUSAGE';
18
19
This script adds days into discrete_calendar table based on the same day from the week before.
20
21
Examples :
22
    The latest date on discrete_calendar is : 28-07-2017
23
    The current date : 01-08-2016
24
    The dates that will be added are : 29-07-2017, 30-07-2017, 31-07-2017, 01-08-2017
25
Open close exemples :
26
    Date added is : 29-07-2017
27
    Opening/closing hours will be base on : 22-07-2017 (- 7 days)
28
    Library open or closed will be based on : 29-07-2017 (- 1 year)
29
This script has the following parameters:
30
    -h --help: this message
31
32
PS: This is for testing purposes, the method of knowing whether it's opened or not may be changed.
33
34
ENDUSAGE
35
my $dbh = C4::Context->dbh;
36
37
if ($help) {
38
    print $usage;
39
    exit;
40
}
41
#getting the all the branches
42
my $selectBranchesSt = 'SELECT branchcode FROM branches';
43
my $selectBranchesSth = $dbh->prepare($selectBranchesSt);
44
$selectBranchesSth->execute();
45
my @branches = ();
46
while ( my $branchCode = $selectBranchesSth->fetchrow_array ) {
47
48
    push @branches,$branchCode;
49
}
50
51
#get the latest date in the table
52
my $query = "select max(date) from discrete_calendar";
53
my $stmt = $dbh->prepare($query);
54
$stmt->execute();
55
my $latestedDate = $stmt->fetchrow_array;
56
my $parser = DateTime::Format::Strptime->new(
57
    pattern => '%Y-%m-%d %H:%M:%S',
58
    on_error => 'croak',
59
);
60
$latestedDate = $parser->parse_datetime($latestedDate);
61
62
my $endDate = DateTime->today;
63
$endDate->add(years => 1, days=>1);
64
my $newDay = $latestedDate->clone();
65
66
for ($newDay->add(days => 1);$newDay <= $endDate;$newDay->add(days => 1)){
67
    my $lastWeekDay = $newDay->clone();
68
    $lastWeekDay->add(days=> -8);
69
    my $dayOfWeek = $lastWeekDay->day_of_week;
70
    # Representation fix
71
    # DateTime object dow (1-7) where Monday is 1
72
    # Arrays are 0-based where 0 = Sunday, not 7.
73
    $dayOfWeek -= 1 unless $dayOfWeek == 7;
74
    $dayOfWeek = 0 if $dayOfWeek == 7;
75
76
    #getting the close and opening hour of the same day from last week
77
    my $openhour = "select openhour from openinghours where weekcode=?";
78
    $stmt = $dbh->prepare($openhour);
79
    $stmt->execute($dayOfWeek);
80
    $openhour = $stmt->fetchrow_array;
81
82
    my $closehour = "select closehour from openinghours where weekcode=?";
83
    $stmt = $dbh->prepare($closehour);
84
    $stmt->execute($dayOfWeek);
85
    $closehour = $stmt->fetchrow_array;
86
87
    #checking if it was open on the same day from last year
88
    my $yearAgo = $newDay->clone();
89
    $yearAgo = $yearAgo->add(years => -1);
90
    my $isOpened = "select isopened from discrete_calendar where date=? and branchcode=?";
91
    my $add_Day = 'INSERT INTO discrete_calendar (date,branchcode,isopened,openhour,closehour) VALUES (?,?,?,?,?)';
92
93
    #insert into discrete_calendar for each branch
94
    foreach my $branchCode(@branches){
95
        $stmt = $dbh->prepare($isOpened);
96
        $stmt->execute($yearAgo,$branchCode);
97
        $isOpened = $stmt->fetchrow_array;
98
99
        my $add_Day = 'INSERT INTO discrete_calendar (date,branchcode,isopened,openhour,closehour) VALUES (?,?,?,?,?)';
100
        $stmt = $dbh->prepare($add_Day);
101
        $stmt->execute($newDay,$branchCode,$isOpened,$openhour,$closehour);
102
    }
103
}
(-)a/misc/generate_discrete_calendar.pl (+159 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
#
4
#   Script that fills the discrete_calendar table with dates, using the other date-related tables
5
#
6
use strict;
7
use warnings;
8
use DateTime;
9
use DateTime::Format::Strptime;
10
use Getopt::Long;
11
use C4::Context;
12
13
# Options
14
my $generate = 0;
15
my $help = 0;
16
my $daysInFuture = 365;
17
GetOptions (
18
            'days|?|d=i' => \$daysInFuture,
19
            'generate' => \$generate,
20
            'help|?|h' => \$help);
21
my $usage = << 'ENDUSAGE';
22
23
Script that manages the discrete_calendar table.
24
25
This script has the following parameters :
26
    --days --d : how many days in the future will be created, by default it's 365
27
    -h --help: this message
28
    --generate: fills discrete_calendar table with dates from the last two years and the next one
29
30
ENDUSAGE
31
32
if ($help) {
33
    print $usage;
34
    exit;
35
}
36
#if ($generate) {
37
38
    my $dbh = C4::Context->dbh;
39
40
    my $currentDate = DateTime->today;
41
42
    # two years ago
43
    my $startDate = DateTime->new(
44
            day       => $currentDate->day(),
45
            month     => $currentDate->month(),
46
            year      => $currentDate->year()-2,
47
            time_zone => C4::Context->tz()
48
          )->truncate( to => 'day' );
49
50
    # a year into the future
51
    my $endDate = DateTime->new(
52
            day       => $currentDate->day(),
53
            month     => $currentDate->month(),
54
            year      => $currentDate->year(),
55
            time_zone => C4::Context->tz()
56
          )->truncate( to => 'day' );
57
    $endDate->add(days=> $daysInFuture);
58
59
    # finds branches;
60
    my $selectBranchesSt = 'SELECT branchcode FROM branches';
61
    my $selectBranchesSth = $dbh->prepare($selectBranchesSt);
62
    $selectBranchesSth->execute();
63
    my @branches = ();
64
    while ( my $branchCode = $selectBranchesSth->fetchrow_array ) {
65
66
        push @branches,$branchCode;
67
    }
68
69
    # finds what days are closed for each branch
70
    my %repeatableHolidaysPerBranch = ();
71
    my %specialHolidaysPerBranch = ();
72
    my $selectWeeklySt;
73
    my $selectWeeklySth;
74
75
76
    foreach my $branch (@branches){
77
78
        $selectWeeklySt = 'SELECT weekday, title FROM repeatable_holidays WHERE branchcode = ? AND weekday IS NOT NULL';
79
        $selectWeeklySth = $dbh->prepare($selectWeeklySt);
80
        $selectWeeklySth->execute($branch);
81
82
        my @weeklyHolidays = ();
83
84
        while ( my ($weekDay, $title) = $selectWeeklySth->fetchrow_array ) {
85
            push @weeklyHolidays,{weekday => $weekDay, title=> $title};
86
87
        }
88
89
        $repeatableHolidaysPerBranch{$branch} = \@weeklyHolidays;
90
91
        my $selectSpecialHolidayDateSt = 'SELECT day,month,year,title FROM special_holidays WHERE branchcode = ? AND isexception = 0';
92
        my $specialHolidayDatesSth = $dbh->prepare($selectSpecialHolidayDateSt);
93
        $specialHolidayDatesSth -> execute($branch);
94
        # Tranforms dates from specialHolidays table in DateTime for our new table
95
        my @specialHolidayDates = ();
96
        while ( my ($day, $month, $year, $title) = $specialHolidayDatesSth->fetchrow_array ) {
97
98
            my $specialHolidayDate = DateTime->new(
99
                day       => $day,
100
                month     => $month,
101
                year      => $year,
102
                time_zone => C4::Context->tz()
103
              )->truncate( to => 'day' );
104
            push @specialHolidayDates,{date=>$specialHolidayDate, title=> $title};
105
        }
106
107
        $specialHolidaysPerBranch{$branch} = \@specialHolidayDates;
108
    }
109
    # Fills table with dates and sets 'isopened' according to the branch's weekly restrictions (repeatable_holidays)
110
    my $insertDateSt;
111
    my $insertDateSth;
112
113
    # Loop that does everything in the world
114
    for (my $tempDate = $startDate->clone(); $tempDate <= $endDate;$tempDate->add(days => 1)){
115
116
        my $isOpened;
117
        my $specialDescription;
118
119
        foreach my $branch (@branches){
120
            my $dayOfWeek = $tempDate->day_of_week;
121
            # Representation fix
122
            # DateTime object dow (1-7) where Monday is 1
123
            # Arrays are 0-based where 0 = Sunday, not 7.
124
            $dayOfWeek -=1 unless $dayOfWeek ==7;
125
            $dayOfWeek =0 if $dayOfWeek ==7;
126
127
            my $openhour = "select openhour from openinghours where branchcode=? and weekcode=?";
128
            my $stmt = $dbh->prepare($openhour);
129
            $stmt->execute($branch,$dayOfWeek);
130
            $openhour = $stmt->fetchrow_array;
131
            my $closehour = "select closehour from openinghours where branchcode=? and weekcode=?";
132
            $stmt = $dbh->prepare($closehour);
133
            $stmt->execute($branch,$dayOfWeek);
134
            $closehour = $stmt->fetchrow_array;
135
136
            # Finds closed days
137
            $isOpened =1;
138
            $specialDescription = "";
139
            foreach my $holidayWeekDay (@{$repeatableHolidaysPerBranch{$branch}}){
140
                if($dayOfWeek == $holidayWeekDay->{weekday}){
141
                    $isOpened = 0;
142
                    $specialDescription = $holidayWeekDay->{title};
143
                }
144
            }
145
146
            foreach my $specialDate (@{$specialHolidaysPerBranch{$branch}}){
147
                if($tempDate->datetime() eq $specialDate->{date}->datetime() ){
148
                    $isOpened = 0;
149
                    $specialDescription = $specialDate->{title};
150
                }
151
            }
152
153
            #final insert statement
154
            $insertDateSt = 'INSERT INTO discrete_calendar (date,branchcode,isopened,note,openhour,closehour) VALUES (?,?,?,?,?,?)';
155
            $insertDateSth = $dbh->prepare($insertDateSt);
156
            $insertDateSth->execute($tempDate,$branch,$isOpened,$specialDescription,$openhour,$closehour);
157
        }
158
    }
159
#}
(-)a/tools/exceptionHolidays.pl (-2 / +96 lines)
Lines 11-17 use DateTime; Link Here
11
11
12
use C4::Calendar;
12
use C4::Calendar;
13
use Koha::DateUtils;
13
use Koha::DateUtils;
14
14
use DateTime::Format::Strptime;
15
my $input = new CGI;
15
my $input = new CGI;
16
my $dbh = C4::Context->dbh();
16
my $dbh = C4::Context->dbh();
17
17
Lines 34-40 if ($description) { Link Here
34
    $description =~ s/\n/\\n/g;
34
    $description =~ s/\n/\\n/g;
35
} else {
35
} else {
36
    $description = '';
36
    $description = '';
37
}   
37
}
38
39
40
my $startDate = DateTime->new(year => $year, month  => $month,  day => $day);
41
my $endDate = dt_from_string( scalar $input->param('datecancelrange') ) || '' if $input->param('datecancelrange');
42
43
sub delete_holidays{
44
    my ($branchcode, $weekday, $day, $month) = @_;
45
    $weekday+=1;
46
    my $today = DateTime->today;
47
    my $query;
48
    my $stmt;
49
50
    if($holidaytype eq 'weekday') {
51
        #This one deletes a weekly repeated holiday from the full table
52
        $query = "update discrete_calendar set isOpened=1, note='' where branchcode=? and DAYOFWEEK(date)=? and date >=?";
53
        $stmt = $dbh->prepare($query);
54
55
        $stmt->execute($branchcode,$weekday,$today);
56
    }elsif ($holidaytype eq 'ymd'){
57
        unless($input->param('showOperation') eq 'deleterange'){
58
            $query = "update discrete_calendar set isOpened=1, note='' where branchcode=? and date=?";
59
            $stmt = $dbh->prepare($query);
60
61
            $stmt->execute($branchcode, $startDate);
62
        }else{
63
            $startDate = output_pref( { dt => $startDate, dateonly => 1, dateformat => 'iso' } );
64
            $endDate = output_pref( { dt => $endDate, dateonly => 1, dateformat => 'iso' } );
65
            $query = "update discrete_calendar set isOpened=1, note='' where branchcode=? and (date between ? and ?)";
66
            $stmt = $dbh->prepare($query);
67
68
            $stmt->execute($branchcode, $startDate, $endDate);
69
        }
70
71
    }elsif ($holidaytype eq 'daymonth'){
72
        unless($endDate){
73
            #This one deletes a given holiday day and repeats for the ful calendar ex: 03 august of every year in the table
74
            $query = "update discrete_calendar set isOpened=1, note='' where branchcode=? and MONTH(date)=? and DAY(date)=? and  date >=?";
75
            $stmt = $dbh->prepare($query);
76
            $stmt->execute($branchcode, $month, $day, $today);
77
        }elsif($input->param('showOperation') eq 'deleterangerepeat'){
78
            #This one deletes a range from startDate to endDate and repeats it for the full table
79
            my $parser = DateTime::Format::Strptime->new(
80
                pattern => '%m-%d',
81
                on_error => 'croak',
82
            );
83
            $startDate = $parser->format_datetime($startDate);
84
            $endDate = $parser->format_datetime($endDate);
85
86
            $query = "update discrete_calendar set isOpened=1, note='' where branchcode=? and (DATE_FORMAT(date,'\%m-\%d') BETWEEN ? AND ? ) and date > ?";
87
            $stmt = $dbh->prepare($query);
88
            $stmt->execute($branchcode, $startDate, $endDate, $today);
89
        } elsif($input->param('showOperation') eq 'deleterange'){
90
            #This one deletes a range from startDate to endDate
91
            $startDate = output_pref( { dt => $startDate, dateonly => 1, dateformat => 'iso' } );
92
            $endDate = output_pref( { dt => $endDate, dateonly => 1, dateformat => 'iso' } );
93
            $query = "update discrete_calendar set isOpened=1, note='' where branchcode=? and (date between ? and ?)";
94
            $stmt = $dbh->prepare($query);
95
96
            $stmt->execute($branchcode, $startDate, $endDate);
97
        }
98
    }
99
}
100
101
sub edit_holiday{
102
    my ($branchcode, $title, $weekday, $day, $month) = @_;
103
    $weekday+=1;
104
    my $today = DateTime->today;
105
    my $query;
106
    my $stmt;
107
108
    if($holidaytype eq 'weekday') {
109
        #This one deletes a weekly repeated holiday from the full table
110
        $query = "update discrete_calendar set note=? where branchcode=? and DAYOFWEEK(date)=? and date >=?";
111
        $stmt = $dbh->prepare($query);
112
113
        $stmt->execute($title, $branchcode,$weekday,$today);
114
    } elsif ($holidaytype eq 'daymonth') {
115
        #This one deletes a given holiday day and repeats for the ful calendar ex: 03 august of every year in the table
116
        $query = "update discrete_calendar set note=? where branchcode=? and MONTH(date)=? and DAY(date)=? and  date >=?";
117
        $stmt = $dbh->prepare($query);
118
        $stmt->execute($title, $branchcode, $month, $day, $today);
119
    } elsif ($holidaytype eq 'ymd') {
120
        #This one deletes only a holiday based on a given date
121
        $query = "update discrete_calendar set note=? where branchcode=? and date=?";
122
        $stmt = $dbh->prepare($query);
123
124
        $stmt->execute($title,$branchcode, $startDate);
125
    }
126
}
38
127
39
# We make an array with holiday's days
128
# We make an array with holiday's days
40
my @holiday_list;
129
my @holiday_list;
Lines 89-99 if ($input->param('showOperation') eq 'exception') { Link Here
89
                                  title => $title,
178
                                  title => $title,
90
                                  description => $description);
179
                                  description => $description);
91
    }
180
    }
181
    edit_holiday($branchcode, $title, $weekday, $day, $month);
92
} elsif ($input->param('showOperation') eq 'delete') {
182
} elsif ($input->param('showOperation') eq 'delete') {
93
	$calendar->delete_holiday(weekday => $weekday,
183
	$calendar->delete_holiday(weekday => $weekday,
94
	                          day => $day,
184
	                          day => $day,
95
  	                          month => $month,
185
  	                          month => $month,
96
				              year => $year);
186
				              year => $year);
187
   delete_holidays($branchcode, $weekday, $day, $month);
97
}elsif ($input->param('showOperation') eq 'deleterange') {
188
}elsif ($input->param('showOperation') eq 'deleterange') {
98
    if (@holiday_list){
189
    if (@holiday_list){
99
        foreach my $date (@holiday_list){
190
        foreach my $date (@holiday_list){
Lines 103-108 if ($input->param('showOperation') eq 'exception') { Link Here
103
                                            year => $date->{local_c}->{year});
194
                                            year => $date->{local_c}->{year});
104
            }
195
            }
105
    }
196
    }
197
    delete_holidays($branchcode, $weekday, $day, $month);
106
}elsif ($input->param('showOperation') eq 'deleterangerepeat') {
198
}elsif ($input->param('showOperation') eq 'deleterangerepeat') {
107
    if (@holiday_list){
199
    if (@holiday_list){
108
        foreach my $date (@holiday_list){
200
        foreach my $date (@holiday_list){
Lines 111-116 if ($input->param('showOperation') eq 'exception') { Link Here
111
                                         month => $date->{local_c}->{month});
203
                                         month => $date->{local_c}->{month});
112
        }
204
        }
113
    }
205
    }
206
    delete_holidays($branchcode, $weekday, $day, $month);
114
}elsif ($input->param('showOperation') eq 'deleterangerepeatexcept') {
207
}elsif ($input->param('showOperation') eq 'deleterangerepeatexcept') {
115
    if (@holiday_list){
208
    if (@holiday_list){
116
        foreach my $date (@holiday_list){
209
        foreach my $date (@holiday_list){
Lines 120-124 if ($input->param('showOperation') eq 'exception') { Link Here
120
                                         year => $date->{local_c}->{year});
213
                                         year => $date->{local_c}->{year});
121
        }
214
        }
122
    }
215
    }
216
    delete_holidays($branchcode, $weekday, $day, $month);
123
}
217
}
124
print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$branchcode&calendardate=$calendardate");
218
print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$branchcode&calendardate=$calendardate");
(-)a/tools/newHolidays.pl (-6 / +97 lines)
Lines 9-20 use CGI qw ( -utf8 ); Link Here
9
9
10
use C4::Auth;
10
use C4::Auth;
11
use C4::Output;
11
use C4::Output;
12
13
use Koha::Cache;
12
use Koha::Cache;
14
15
use C4::Calendar;
13
use C4::Calendar;
16
use DateTime;
14
use DateTime;
17
use Koha::DateUtils;
15
use Koha::DateUtils;
16
use DateTime::Format::Strptime;
18
17
19
my $input               = new CGI;
18
my $input               = new CGI;
20
my $dbh                 = C4::Context->dbh();
19
my $dbh                 = C4::Context->dbh();
Lines 58-80 if ($end_dt){ Link Here
58
57
59
if($allbranches) {
58
if($allbranches) {
60
	my $branch;
59
	my $branch;
61
	my @branchcodes = split(/\|/, $input->param('branchCodes')); 
60
	my @branchcodes = split(/\|/, $input->param('branchCodes'));
62
	foreach $branch (@branchcodes) {
61
	foreach $branch (@branchcodes) {
63
		add_holiday($newoperation, $branch, $weekday, $day, $month, $year, $title, $description);
62
		add_holiday($newoperation, $branch, $weekday, $day, $month, $year, $title, $description);
63
		addHoliday($newoperation, $branch, $weekday, $day, $month, $title);
64
	}
64
	}
65
} else {
65
} else {
66
	add_holiday($newoperation, $branchcode, $weekday, $day, $month, $year, $title, $description);
66
	add_holiday($newoperation, $branchcode, $weekday, $day, $month, $year, $title, $description);
67
	addHoliday($newoperation, $branchcode, $weekday, $day, $month, $title);
67
}
68
}
68
69
69
print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$originalbranchcode&calendardate=$calendardate");
70
print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$originalbranchcode&calendardate=$calendardate");
70
71
72
sub isOpened{
73
	my ($branchcode, $date) = @_;
74
	my $isopened;
75
	my $query = "select isopened from discrete_calendar where branchcode=? and date=?";
76
	my $stmt = $dbh->prepare($query);
77
	$stmt->execute($branchcode, $date);
78
	$isopened = $stmt->fetchrow_array;
79
80
	return $isopened;
81
}
82
sub addHoliday{
83
	my ($newoperation, $branchcode, $weekday, $day, $month, $title) = @_;
84
	my $startDate = output_pref( { dt => $first_dt, dateonly => 1, dateformat => 'iso' } );
85
	my $endDate = output_pref( { dt => $end_dt, dateonly => 1, dateformat => 'iso' } );
86
87
	if($newoperation eq 'holiday'){
88
		if (isOpened($branchcode,$startDate)) {
89
			insert_single_day($branchcode, $title);
90
		}
91
	}elsif($newoperation eq 'weekday'){
92
		if (isOpened($branchcode,$startDate)) {
93
			insert_weekday_day($branchcode, $weekday, $title);
94
		}
95
	}elsif($newoperation eq 'repeatable'){
96
		if (isOpened($branchcode,$startDate)) {
97
			insert_yearly_holiday($branchcode, $day, $month, $title);
98
		}
99
	}elsif($newoperation eq 'holidayrange'){
100
		insert_range_holiday($branchcode, $title);
101
	}elsif($newoperation eq 'holidayrangerepeat'){
102
		insert_range_holiday_repeat($branchcode, $title);
103
	}
104
}
105
106
sub insert_single_day{
107
	my ($branchcode,$title) = @_;
108
	my $startDate = output_pref( { dt => $first_dt, dateonly => 1, dateformat => 'iso' } );
109
	my $today = DateTime->today;
110
    my $query = "update discrete_calendar set isOpened=0, note=? where branchcode=? and date=? and date>=?";
111
	my $stmt = $dbh->prepare($query);
112
    
113
	$stmt->execute($title, $branchcode, $startDate, $today);
114
115
}
116
117
sub insert_weekday_day{
118
	my ($branchcode, $weekday, $title) = @_;
119
	$weekday+=1;
120
	my $startDate = output_pref( { dt => $first_dt, dateonly => 1, dateformat => 'iso' } );
121
	my $today = DateTime->today;
122
	my $query = "update discrete_calendar set isOpened=0, note=? where branchcode=? and DAYOFWEEK(date)=? and date >=?";
123
	my $stmt = $dbh->prepare($query);
124
125
	$stmt->execute($title,$branchcode,$weekday,$today);
126
}
127
128
sub insert_yearly_holiday{
129
	my ($branchcode, $day, $month, $title) = @_;
130
	my $startDate = output_pref( { dt => $first_dt, dateonly => 1, dateformat => 'iso' } );
131
	my $today = DateTime->today;
132
	my $query = "update discrete_calendar set isOpened=0, note=? where branchcode=? and MONTH(date)=? and DAY(date)=? and  date >=?";
133
	my $stmt = $dbh->prepare($query);
134
135
	$stmt->execute($title,$branchcode,$month,$day,$today);
136
}
137
138
sub insert_range_holiday{
139
	my ($branchcode, $title) = @_;
140
	my $startDate = output_pref( { dt => $first_dt, dateonly => 1, dateformat => 'iso' } );
141
	my $endDate = output_pref( { dt => $end_dt, dateonly => 1, dateformat => 'iso' } );
142
	my $query = "update discrete_calendar set isOpened=0, note=? where branchcode=? and (date between ? and ?)";
143
	my $stmt = $dbh->prepare($query);
144
145
	$stmt->execute($title,$branchcode, $startDate, $endDate);
146
}
147
148
sub insert_range_holiday_repeat{
149
	my ($branchcode, $title) = @_;
150
	my $parser = DateTime::Format::Strptime->new(
151
	  pattern => '%m-%d',
152
	  on_error => 'croak',
153
	);
154
	my $startDate = $parser->format_datetime($first_dt);
155
	my $endDate = $parser->format_datetime($end_dt);
156
	my $today = DateTime->today;
157
	my $query = "update discrete_calendar set isOpened=0, note=? where branchcode=? and isOpened=1 and (DATE_FORMAT(date,'\%m-\%d') BETWEEN ? AND ? ) and date > ?";
158
	my $stmt = $dbh->prepare($query);
159
160
	$stmt->execute($title,$branchcode, $startDate, $endDate,$today);
161
}
162
71
#FIXME: move add_holiday() to a better place
163
#FIXME: move add_holiday() to a better place
72
sub add_holiday {
164
sub add_holiday {
73
	($newoperation, $branchcode, $weekday, $day, $month, $year, $title, $description) = @_;  
165
	($newoperation, $branchcode, $weekday, $day, $month, $year, $title, $description) = @_;
74
	my $calendar = C4::Calendar->new(branchcode => $branchcode);
166
	my $calendar = C4::Calendar->new(branchcode => $branchcode);
75
167
76
	if ($newoperation eq 'weekday') {
168
	if ($newoperation eq 'weekday') {
77
		unless ( $weekday && ($weekday ne '') ) { 
169
		unless ( $weekday && ($weekday ne '') ) {
78
			# was dow calculated by javascript?  original code implies it was supposed to be.
170
			# was dow calculated by javascript?  original code implies it was supposed to be.
79
			# if not, we need it.
171
			# if not, we need it.
80
			$weekday = &Date::Calc::Day_of_Week($year, $month, $day) % 7 unless($weekday);
172
			$weekday = &Date::Calc::Day_of_Week($year, $month, $day) % 7 unless($weekday);
81
- 

Return to bug 17015