Bugzilla – Attachment 7520 Details for
Bug 7477
Duplicate calendar
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
patch
0001-bug_7477-Copy-holidays-from-one-branch-to-another.patch (text/plain), 8.75 KB, created by
Srdjan Jankovic
on 2012-02-09 01:12:04 UTC
(
hide
)
Description:
patch
Filename:
MIME Type:
Creator:
Srdjan Jankovic
Created:
2012-02-09 01:12:04 UTC
Size:
8.75 KB
patch
obsolete
>From 3cc0ef0322de9b744a0db4034dab2483c49809f5 Mon Sep 17 00:00:00 2001 >From: Srdjan Jankovic <srdjan@catalyst.net.nz> >Date: Thu, 9 Feb 2012 14:08:36 +1300 >Subject: [PATCH] bug_7477: Copy holidays from one branch to another > >--- > C4/Calendar.pm | 103 ++++++++++++++------ > .../prog/en/modules/tools/holidays.tt | 15 +++ > tools/copy-holidays.pl | 40 ++++++++ > 3 files changed, 129 insertions(+), 29 deletions(-) > create mode 100755 tools/copy-holidays.pl > >diff --git a/C4/Calendar.pm b/C4/Calendar.pm >index dc9037b..d13d238 100644 >--- a/C4/Calendar.pm >+++ b/C4/Calendar.pm >@@ -20,34 +20,11 @@ use warnings; > use vars qw($VERSION @EXPORT); > > use Carp; >-use Date::Calc qw( Date_to_Days ); >+use Date::Calc qw( Date_to_Days Today); > > use C4::Context; > >-BEGIN { >- # set the version for version checking >- $VERSION = 3.01; >- require Exporter; >- @EXPORT = qw( >- &get_week_days_holidays >- &get_day_month_holidays >- &get_exception_holidays >- &get_single_holidays >- &insert_week_day_holiday >- &insert_day_month_holiday >- &insert_single_holiday >- &insert_exception_holiday >- &ModWeekdayholiday >- &ModDaymonthholiday >- &ModSingleholiday >- &ModExceptionholiday >- &delete_holiday >- &isHoliday >- &addDate >- &daysBetween >- ); >-} >- >+use constant ISO_DATE_FORMAT => "%04d-%02d-%02d"; > =head1 NAME > > C4::Calendar::Calendar - Koha module dealing with holidays. >@@ -123,7 +100,7 @@ sub _init { > $exception_holidays{"$year/$month/$day"}{title} = $title; > $exception_holidays{"$year/$month/$day"}{description} = $description; > $exception_holidays{"$year/$month/$day"}{date} = >- sprintf("%04d-%02d-%02d", $year, $month, $day); >+ sprintf(ISO_DATE_FORMAT, $year, $month, $day); > } > $self->{'exception_holidays'} = \%exception_holidays; > >@@ -133,7 +110,7 @@ sub _init { > $single_holidays{"$year/$month/$day"}{title} = $title; > $single_holidays{"$year/$month/$day"}{description} = $description; > $single_holidays{"$year/$month/$day"}{date} = >- sprintf("%04d-%02d-%02d", $year, $month, $day); >+ sprintf(ISO_DATE_FORMAT, $year, $month, $day); > } > $self->{'single_holidays'} = \%single_holidays; > return $self; >@@ -218,9 +195,11 @@ sub insert_week_day_holiday { > my $self = shift @_; > my %options = @_; > >+ my $weekday = $options{weekday} or croak "No weekday"; >+ > my $dbh = C4::Context->dbh(); > my $insertHoliday = $dbh->prepare("insert into repeatable_holidays (id,branchcode,weekday,day,month,title,description) values ( '',?,?,NULL,NULL,?,? )"); >- $insertHoliday->execute( $self->{branchcode}, $options{weekday},$options{title}, $options{description}); >+ $insertHoliday->execute( $self->{branchcode}, $weekday, $options{title}, $options{description}); > $self->{'week_days_holidays'}->{$options{weekday}}{title} = $options{title}; > $self->{'week_days_holidays'}->{$options{weekday}}{description} = $options{description}; > return $self; >@@ -283,6 +262,9 @@ sub insert_single_holiday { > my $self = shift @_; > my %options = @_; > >+ @options{qw(year month day)} = ( $options{date} =~ m/(\d+)-(\d+)-(\d+)/o ) >+ if $options{date} && !$options{day}; >+ > my $dbh = C4::Context->dbh(); > my $isexception = 0; > my $insertHoliday = $dbh->prepare("insert into special_holidays (id,branchcode,day,month,year,isexception,title,description) values ('', ?,?,?,?,?,?,?)"); >@@ -318,6 +300,9 @@ sub insert_exception_holiday { > my $self = shift @_; > my %options = @_; > >+ @options{qw(year month day)} = ( $options{date} =~ m/(\d+)-(\d+)-(\d+)/o ) >+ if $options{date} && !$options{day}; >+ > my $dbh = C4::Context->dbh(); > my $isexception = 1; > my $insertException = $dbh->prepare("insert into special_holidays (id,branchcode,day,month,year,isexception,title,description) values ('', ?,?,?,?,?,?,?)"); >@@ -567,6 +552,66 @@ sub isHoliday { > > } > >+=head2 copy_to_branch >+ >+ $calendar->copy_to_branch($target_branch) >+ >+=cut >+ >+sub copy_to_branch { >+ my ($self, $target_branch) = @_; >+ >+ croak "No target_branch" unless $target_branch; >+ >+ my $target_calendar = C4::Calendar->new(branchcode => $target_branch); >+ >+ my ($y, $m, $d) = Today(); >+ my $today = sprintf ISO_DATE_FORMAT, $y,$m,$d; >+ >+ my $wdh = $self->get_week_days_holidays; >+ $target_calendar->insert_week_day_holiday( weekday => $_, %{ $wdh->{$_} } ) >+ foreach keys %$wdh; >+ $target_calendar->insert_day_month_holiday(%$_) >+ foreach values %{ $self->get_day_month_holidays }; >+ $target_calendar->insert_exception_holiday(%$_) >+ foreach grep { $_->{date} gt $today } values %{ $self->get_exception_holidays }; >+ $target_calendar->insert_single_holiday(%$_) >+ foreach grep { $_->{date} gt $today } values %{ $self->get_single_holidays }; >+ >+ return 1; >+} >+ >+=head2 daysBetween >+ >+ my $daysBetween = $calendar->daysBetween($startdate, $enddate) >+ >+C<$startdate> and C<$enddate> are C4::Dates objects that define the interval. >+ >+Returns the number of non-holiday days in the interval. >+useDaysMode syspref has no effect here. >+=cut >+ >+sub daysBetween ($$$) { >+ my $self = shift or return undef; >+ my $startdate = shift or return undef; >+ my $enddate = shift or return undef; >+ my ($yearFrom,$monthFrom,$dayFrom) = split("-",$startdate->output('iso')); >+ my ($yearTo, $monthTo, $dayTo ) = split("-", $enddate->output('iso')); >+ if (Date_to_Days($yearFrom,$monthFrom,$dayFrom) > Date_to_Days($yearTo,$monthTo,$dayTo)) { >+ return 0; >+ # we don't go backwards ( FIXME - handle this error better ) >+ } >+ my $count = 0; >+ while (1) { >+ ($yearFrom != $yearTo or $monthFrom != $monthTo or $dayFrom != $dayTo) or last; # if they all match, it's the last day >+ unless ($self->isHoliday($dayFrom, $monthFrom, $yearFrom)) { >+ $count++; >+ } >+ ($yearFrom, $monthFrom, $dayFrom) = &Date::Calc::Add_Delta_Days($yearFrom, $monthFrom, $dayFrom, 1); >+ } >+ return($count); >+} >+ > =head2 addDate > > my ($day, $month, $year) = $calendar->addDate($date, $offset) >@@ -601,7 +646,7 @@ sub addDate { > } else { ## ($daysMode eq 'Days') > ($year, $month, $day) = &Date::Calc::Add_Delta_Days($year, $month, $day, $offset ); > } >- return(C4::Dates->new( sprintf("%04d-%02d-%02d",$year,$month,$day),'iso')); >+ return(C4::Dates->new( sprintf(ISO_DATE_FORMAT,$year,$month,$day),'iso')); > } > > =head2 daysBetween >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/holidays.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/holidays.tt >index 686e3af..6ee87df 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/holidays.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/holidays.tt >@@ -388,6 +388,21 @@ > > > </div> >+ >+<div style="margin-top: 2em;"> >+<form action="copy-holidays.pl" method="post"> >+ <input type="hidden" name="from_branchcode" value="[% branch %]" /> >+ <label for="branchcode">Copy holidays to:</label> >+ <select id="branchcode" name="branchcode"> >+ <option value=""></option> >+ [% FOREACH branchloo IN branchloop %] >+ <option value="[% branchloo.value %]">[% branchloo.branchname %]</option> >+ [% END %] >+ </select> >+ <input type="submit" value="Copy" /> >+</form> >+</div> >+ > </div> > <div class="yui-u"> > <div class="help"> >diff --git a/tools/copy-holidays.pl b/tools/copy-holidays.pl >new file mode 100755 >index 0000000..9de4b8c >--- /dev/null >+++ b/tools/copy-holidays.pl >@@ -0,0 +1,40 @@ >+#!/usr/bin/perl >+ >+# Copyright 2012 Catalyst IT >+# >+# 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 2 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, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use strict; >+use warnings; >+ >+use CGI; >+ >+use C4::Auth; >+use C4::Output; >+ >+ >+use C4::Calendar; >+ >+my $input = new CGI; >+my $dbh = C4::Context->dbh(); >+ >+my $branchcode = $input->param('branchcode'); >+my $from_branchcode = $input->param('from_branchcode'); >+ >+C4::Calendar->new(branchcode => $from_branchcode)->copy_to_branch($branchcode) if $from_branchcode && $branchcode; >+ >+print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=".($branchcode || $from_branchcode)); >+ >-- >1.6.5 >
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 7477
:
7401
|
7494
|
7495
|
7520
|
7521
|
7547
|
7626
|
7627
|
8013
|
8083
|
8105