|
Lines 565-574
sub edit_holiday {
Link Here
|
| 565 |
my $close_hour = $params->{close_hour} || ''; |
565 |
my $close_hour = $params->{close_hour} || ''; |
| 566 |
|
566 |
|
| 567 |
my $delete_type = $params->{delete_type} || undef; |
567 |
my $delete_type = $params->{delete_type} || undef; |
|
|
568 |
my $all_branches = $params->{all_branches} // 0; |
| 568 |
my $today = $params->{today} || dt_from_string()->truncate( to => 'day' ); |
569 |
my $today = $params->{today} || dt_from_string()->truncate( to => 'day' ); |
| 569 |
|
570 |
|
| 570 |
my $branchcode = $self->{branchcode}; |
|
|
| 571 |
|
| 572 |
# When override param is set, this function will allow past dates to be set as holidays, |
571 |
# When override param is set, this function will allow past dates to be set as holidays, |
| 573 |
# otherwise it will not. This is meant to only be used for testing. |
572 |
# otherwise it will not. This is meant to only be used for testing. |
| 574 |
my $override = $params->{override} || 0; |
573 |
my $override = $params->{override} || 0; |
|
Lines 591-605
sub edit_holiday {
Link Here
|
| 591 |
$updateValues{open_hour} = $open_hour if $open_hour ne ''; |
590 |
$updateValues{open_hour} = $open_hour if $open_hour ne ''; |
| 592 |
$updateValues{close_hour} = $close_hour if $close_hour ne ''; |
591 |
$updateValues{close_hour} = $close_hour if $close_hour ne ''; |
| 593 |
|
592 |
|
|
|
593 |
my $limits = ( $all_branches ) ? {} : { branchcode => $self->{branchcode} }; |
| 594 |
|
| 594 |
if ($holiday_type eq $HOLIDAYS->{WEEKLY}) { |
595 |
if ($holiday_type eq $HOLIDAYS->{WEEKLY}) { |
| 595 |
#Update weekly holidays |
596 |
#Update weekly holidays |
| 596 |
if ($start_date_string eq $end_date_string) { |
597 |
if ($start_date_string eq $end_date_string) { |
| 597 |
$end_date_string = $self->get_max_date(); |
598 |
$end_date_string = $self->get_max_date(); |
| 598 |
} |
599 |
} |
| 599 |
my $rs = $schema->resultset('DiscreteCalendar')->search( |
600 |
my $rs = $schema->resultset('DiscreteCalendar')->search( |
| 600 |
{ |
601 |
$limits, |
| 601 |
branchcode => $branchcode, |
|
|
| 602 |
}, |
| 603 |
{ |
602 |
{ |
| 604 |
where => \[ 'DAYOFWEEK(date) = ? AND date >= DATE(?) AND date <= DATE(?)', $weekday, $start_date_string, $end_date_string], |
603 |
where => \[ 'DAYOFWEEK(date) = ? AND date >= DATE(?) AND date <= DATE(?)', $weekday, $start_date_string, $end_date_string], |
| 605 |
} |
604 |
} |
|
Lines 617-625
sub edit_holiday {
Link Here
|
| 617 |
$where->{date}{'>='} = $today unless $override; |
616 |
$where->{date}{'>='} = $today unless $override; |
| 618 |
|
617 |
|
| 619 |
my $rs = $schema->resultset('DiscreteCalendar')->search( |
618 |
my $rs = $schema->resultset('DiscreteCalendar')->search( |
| 620 |
{ |
619 |
$limits, |
| 621 |
branchcode => $branchcode, |
|
|
| 622 |
}, |
| 623 |
{ |
620 |
{ |
| 624 |
where => $where, |
621 |
where => $where, |
| 625 |
} |
622 |
} |
|
Lines 640-648
sub edit_holiday {
Link Here
|
| 640 |
my $where = { -and => [ \["(DATE_FORMAT(date, '\%m-\%d') BETWEEN ? AND ?)", $start_date, $end_date] ] }; |
637 |
my $where = { -and => [ \["(DATE_FORMAT(date, '\%m-\%d') BETWEEN ? AND ?)", $start_date, $end_date] ] }; |
| 641 |
push @{$where->{'-and'}}, { 'date' => { '>=' => $today } } unless $override; |
638 |
push @{$where->{'-and'}}, { 'date' => { '>=' => $today } } unless $override; |
| 642 |
my $rs = $schema->resultset('DiscreteCalendar')->search( |
639 |
my $rs = $schema->resultset('DiscreteCalendar')->search( |
| 643 |
{ |
640 |
$limits, |
| 644 |
branchcode => $branchcode, |
|
|
| 645 |
}, |
| 646 |
{ |
641 |
{ |
| 647 |
where => $where, |
642 |
where => $where, |
| 648 |
} |
643 |
} |
|
Lines 660-668
sub edit_holiday {
Link Here
|
| 660 |
$where->{date}{'>='} = $today unless $override; |
655 |
$where->{date}{'>='} = $today unless $override; |
| 661 |
|
656 |
|
| 662 |
my $rs = $schema->resultset('DiscreteCalendar')->search( |
657 |
my $rs = $schema->resultset('DiscreteCalendar')->search( |
| 663 |
{ |
658 |
$limits, |
| 664 |
branchcode => $branchcode, |
|
|
| 665 |
}, |
| 666 |
{ |
659 |
{ |
| 667 |
where => $where, |
660 |
where => $where, |
| 668 |
} |
661 |
} |
|
Lines 679-687
sub edit_holiday {
Link Here
|
| 679 |
while (my $date = $rs->next()) { |
672 |
while (my $date = $rs->next()) { |
| 680 |
if ($delete_type) { |
673 |
if ($delete_type) { |
| 681 |
if ($date->holiday_type() eq $HOLIDAYS->{WEEKLY}) { |
674 |
if ($date->holiday_type() eq $HOLIDAYS->{WEEKLY}) { |
| 682 |
$self->remove_weekly_holidays($weekday, \%updateValues, $today); |
675 |
$self->remove_weekly_holidays($weekday, \%updateValues, $today, $date->branchcode); |
| 683 |
} elsif ($date->holiday_type() eq $HOLIDAYS->{REPEATABLE}) { |
676 |
} elsif ($date->holiday_type() eq $HOLIDAYS->{REPEATABLE}) { |
| 684 |
$self->remove_repeatable_holidays($start_date, $end_date, \%updateValues, $today); |
677 |
$self->remove_repeatable_holidays($start_date, $end_date, \%updateValues, $today, $date->branchcode); |
| 685 |
} |
678 |
} |
| 686 |
} else { |
679 |
} else { |
| 687 |
$date->update(\%updateValues); |
680 |
$date->update(\%updateValues); |
|
Lines 694-711
sub edit_holiday {
Link Here
|
| 694 |
|
687 |
|
| 695 |
=head2 remove_weekly_holidays |
688 |
=head2 remove_weekly_holidays |
| 696 |
|
689 |
|
| 697 |
$calendar->remove_weekly_holidays($weekday, $updateValues, $today); |
690 |
$calendar->remove_weekly_holidays($weekday, $updateValues, $today, $branchcode); |
| 698 |
|
691 |
|
| 699 |
Removes a weekly holiday and updates the days' parameters |
692 |
Removes a weekly holiday and updates the days' parameters |
| 700 |
C<$weekday> is the weekday to un-holiday |
693 |
C<$weekday> is the weekday to un-holiday |
| 701 |
C<$updatevalues> is hashref containing the new parameters |
694 |
C<$updatevalues> is hashref containing the new parameters |
| 702 |
C<$today> is today's date |
695 |
C<$today> is today's date |
|
|
696 |
C<$branchcode> is the branchcode of the library |
| 703 |
|
697 |
|
| 704 |
=cut |
698 |
=cut |
| 705 |
|
699 |
|
| 706 |
sub remove_weekly_holidays { |
700 |
sub remove_weekly_holidays { |
| 707 |
my ($self, $weekday, $updateValues, $today) = @_; |
701 |
my ($self, $weekday, $updateValues, $today, $branchcode) = @_; |
| 708 |
my $branchcode = $self->{branchcode}; |
|
|
| 709 |
my $schema = Koha::Database->new->schema; |
702 |
my $schema = Koha::Database->new->schema; |
| 710 |
|
703 |
|
| 711 |
my $rs = $schema->resultset('DiscreteCalendar')->search( |
704 |
my $rs = $schema->resultset('DiscreteCalendar')->search( |
|
Lines 726-744
sub remove_weekly_holidays {
Link Here
|
| 726 |
|
719 |
|
| 727 |
=head2 remove_repeatable_holidays |
720 |
=head2 remove_repeatable_holidays |
| 728 |
|
721 |
|
| 729 |
$calendar->remove_repeatable_holidays($startDate, $endDate, $today); |
722 |
$calendar->remove_repeatable_holidays($startDate, $endDate, $today, $branchcode); |
| 730 |
|
723 |
|
| 731 |
Removes a repeatable holiday and updates the days' parameters |
724 |
Removes a repeatable holiday and updates the days' parameters |
| 732 |
C<$startDatey> is the start date of the repeatable holiday |
725 |
C<$startDatey> is the start date of the repeatable holiday |
| 733 |
C<$endDate> is the end date of the repeatble holiday |
726 |
C<$endDate> is the end date of the repeatble holiday |
| 734 |
C<$updatevalues> is hashref containing the new parameters |
727 |
C<$updatevalues> is hashref containing the new parameters |
| 735 |
C<$today> is today's date |
728 |
C<$today> is today's date |
|
|
729 |
C<$branchcode> is the branchcode of the library |
| 736 |
|
730 |
|
| 737 |
=cut |
731 |
=cut |
| 738 |
|
732 |
|
| 739 |
sub remove_repeatable_holidays { |
733 |
sub remove_repeatable_holidays { |
| 740 |
my ($self, $startDate, $endDate, $updateValues, $today) = @_; |
734 |
my ($self, $startDate, $endDate, $updateValues, $today, $branchcode) = @_; |
| 741 |
my $branchcode = $self->{branchcode}; |
|
|
| 742 |
my $schema = Koha::Database->new->schema; |
735 |
my $schema = Koha::Database->new->schema; |
| 743 |
my $parser = DateTime::Format::Strptime->new( |
736 |
my $parser = DateTime::Format::Strptime->new( |
| 744 |
pattern => '%m-%d', |
737 |
pattern => '%m-%d', |