3 # Copyright 2011-2013 Biblibre SARL
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 showpredictionpattern.pl
26 This script calculate numbering of serials based on numbering pattern, and
27 publication date, based on frequency and first publication date.
34 use Date
::Calc
qw(Today Day_of_Year Week_of_Year Day_of_Week Days_in_Year Delta_Days Add_Delta_Days Add_Delta_YM);
38 use C4
::Serials
::Frequency
;
42 my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user
( {
43 template_name
=> 'serials/showpredictionpattern.tt',
47 flagsrequired
=> { 'serials' => '*' },
50 my $subscriptionid = $input->param('subscriptionid');
51 my $frequencyid = $input->param('frequency');
52 my $firstacquidate = $input->param('firstacquidate');
53 my $nextacquidate = $input->param('nextacquidate');
54 my $enddate = $input->param('enddate');
55 my $subtype = $input->param('subtype');
56 my $sublength = $input->param('sublength');
57 my $custompattern = $input->param('custompattern');
59 my $frequency = GetSubscriptionFrequency
($frequencyid);
62 numberingmethod
=> $input->param('numberingmethod') // '',
63 numbering1
=> $input->param('numbering1') // '',
64 numbering2
=> $input->param('numbering2') // '',
65 numbering3
=> $input->param('numbering3') // '',
66 add1
=> $input->param('add1') // '',
67 add2
=> $input->param('add2') // '',
68 add3
=> $input->param('add3') // '',
69 whenmorethan1
=> $input->param('whenmorethan1') // '',
70 whenmorethan2
=> $input->param('whenmorethan2') // '',
71 whenmorethan3
=> $input->param('whenmorethan3') // '',
72 setto1
=> $input->param('setto1') // '',
73 setto2
=> $input->param('setto2') // '',
74 setto3
=> $input->param('setto3') // '',
75 every1
=> $input->param('every1') // '',
76 every2
=> $input->param('every2') // '',
77 every3
=> $input->param('every3') // '',
80 $firstacquidate = eval { output_pref
( { str
=> $firstacquidate, dateonly
=> 1, dateformat
=> 'iso' } ); }
81 or output_pref
( { dt
=> dt_from_string
, dateonly
=> 1, dateformat
=> 'iso' } );
83 $enddate = eval { output_pref
( { str
=> $enddate, dateonly
=> 1, dateformat
=> 'iso' } ); };
86 $nextacquidate = eval { output_pref
( { str
=> $nextacquidate, dateonly
=> 1, dateformat
=> 'iso' } ); };
88 $nextacquidate = $firstacquidate;
90 my $date = $nextacquidate;
93 locale
=> $input->param('locale') // '',
94 lastvalue1
=> $input->param('lastvalue1') // '',
95 lastvalue2
=> $input->param('lastvalue2') // '',
96 lastvalue3
=> $input->param('lastvalue3') // '',
97 innerloop1
=> $input->param('innerloop1') // '',
98 innerloop2
=> $input->param('innerloop2') // '',
99 innerloop3
=> $input->param('innerloop3') // '',
101 periodicity
=> $frequencyid,
102 countissuesperunit
=> 1,
103 firstacquidate
=> $firstacquidate,
107 if(defined $subscriptionid) {
108 ($issuenumber) = C4
::Serials
::GetFictiveIssueNumber
(\
%subscription, $date);
113 my @predictions_loop;
114 my ($calculated) = GetSeq
(\
%subscription, \
%pattern);
115 push @predictions_loop, {
116 number
=> $calculated,
117 publicationdate
=> $date,
118 issuenumber
=> $issuenumber,
119 dow
=> Day_of_Week
(split /-/, $date),
122 if(defined $subscriptionid) {
123 @irreg = C4
::Serials
::GetSubscriptionIrregularities
($subscriptionid);
124 while(@irreg && $issuenumber > $irreg[0]) {
127 if(@irreg && $issuenumber == $irreg[0]){
128 $predictions_loop[0]->{'not_published'} = 1;
138 $date = GetNextDate
(\
%subscription, $date);
141 $line{'publicationdate'} = $date;
142 $line{'dow'} = Day_of_Week
(split /-/, $date);
145 # Check if we don't have exceed end date
147 if($subtype eq "issues" && $i >= $sublength){
149 } elsif($subtype eq "weeks" && $date && Delta_Days
( split(/-/, $date), Add_Delta_Days
( split(/-/, $firstacquidate), 7*$sublength - 1 ) ) < 0) {
151 } elsif($subtype eq "months" && $date && (Delta_Days
( split(/-/, $date), Add_Delta_YM
( split(/-/, $firstacquidate), 0, $sublength) ) - 1) < 0 ) {
155 if($enddate && $date && Delta_Days
( split(/-/, $date), split(/-/, $enddate) ) <= 0 ) {
159 ($calculated, $subscription{'lastvalue1'}, $subscription{'lastvalue2'}, $subscription{'lastvalue3'}, $subscription{'innerloop1'}, $subscription{'innerloop2'}, $subscription{'innerloop3'}) = GetNextSeq
(\
%subscription, \
%pattern);
161 $line{'number'} = $calculated;
162 $line{'issuenumber'} = $issuenumber;
163 if(@irreg && $issuenumber == $irreg[0]){
164 $line{'not_published'} = 1;
167 push @predictions_loop, \
%line;
173 predictions_loop
=> \
@predictions_loop,
176 if ( $frequency->{unit
} and not $custompattern ) {
177 $template->param( ask_for_irregularities
=> 1 );
178 if ( $frequency->{unit
} eq 'day' and $frequency->{unitsperissue
} == 1 ) {
179 $template->param( daily_options
=> 1 );
183 if ( ( $date && $enddate && $date ne $enddate )
184 or ( $subtype eq 'issues' && $i < $sublength ) )
186 $template->param( not_consistent_end_date
=> 1 );
189 output_html_with_http_headers
$input, $cookie, $template->output;