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',
46 flagsrequired
=> { 'serials' => '*' },
49 my $subscriptionid = $input->param('subscriptionid');
50 my $frequencyid = $input->param('frequency');
51 my $firstacquidate = $input->param('firstacquidate');
52 my $nextacquidate = $input->param('nextacquidate');
53 my $enddate = $input->param('to');
54 my $subtype = $input->param('subtype');
55 my $sublength = $input->param('sublength');
56 my $custompattern = $input->param('custompattern');
60 if ( $frequencyid eq 'mana' ) {
63 'displayorder' => undef,
64 'description' => scalar $input->param('sfdescription') // '',
65 'unitsperissue' => scalar $input->param('unitsperissue') // '',
66 'issuesperunit' => scalar $input->param('issuesperunit') // '',
67 'unit' => scalar $input->param('unit') // ''
71 $frequency = GetSubscriptionFrequency
($frequencyid);
75 numberingmethod
=> scalar $input->param('numberingmethod') // '',
76 numbering1
=> scalar $input->param('numbering1') // '',
77 numbering2
=> scalar $input->param('numbering2') // '',
78 numbering3
=> scalar $input->param('numbering3') // '',
79 add1
=> scalar $input->param('add1') // '',
80 add2
=> scalar $input->param('add2') // '',
81 add3
=> scalar $input->param('add3') // '',
82 whenmorethan1
=> scalar $input->param('whenmorethan1') // '',
83 whenmorethan2
=> scalar $input->param('whenmorethan2') // '',
84 whenmorethan3
=> scalar $input->param('whenmorethan3') // '',
85 setto1
=> scalar $input->param('setto1') // '',
86 setto2
=> scalar $input->param('setto2') // '',
87 setto3
=> scalar $input->param('setto3') // '',
88 every1
=> scalar $input->param('every1') // '',
89 every2
=> scalar $input->param('every2') // '',
90 every3
=> scalar $input->param('every3') // '',
93 $firstacquidate = eval { output_pref
( { str
=> $firstacquidate, dateonly
=> 1, dateformat
=> 'iso' } ); }
94 or output_pref
( { dt
=> dt_from_string
, dateonly
=> 1, dateformat
=> 'iso' } );
96 $enddate = eval { output_pref
( { str
=> $enddate, dateonly
=> 1, dateformat
=> 'iso' } ); };
99 $nextacquidate = eval { output_pref
( { str
=> $nextacquidate, dateonly
=> 1, dateformat
=> 'iso' } ); };
101 $nextacquidate = $firstacquidate;
103 my $date = $nextacquidate;
106 locale
=> scalar $input->param('locale') // '',
107 lastvalue1
=> scalar $input->param('lastvalue1') // '',
108 lastvalue2
=> scalar $input->param('lastvalue2') // '',
109 lastvalue3
=> scalar $input->param('lastvalue3') // '',
110 innerloop1
=> scalar $input->param('innerloop1') // '',
111 innerloop2
=> scalar $input->param('innerloop2') // '',
112 innerloop3
=> scalar $input->param('innerloop3') // '',
114 countissuesperunit
=> 1,
115 firstacquidate
=> $firstacquidate,
119 if(defined $subscriptionid) {
120 ($issuenumber) = C4
::Serials
::GetFictiveIssueNumber
(\
%subscription, $date, $frequency);
125 my @predictions_loop;
126 my ($calculated) = GetSeq
(\
%subscription, \
%pattern);
127 push @predictions_loop, {
128 number
=> $calculated,
129 publicationdate
=> $date,
130 issuenumber
=> $issuenumber,
131 dow
=> Day_of_Week
(split /-/, $date),
134 if(defined $subscriptionid) {
135 @irreg = C4
::Serials
::GetSubscriptionIrregularities
($subscriptionid);
136 while(@irreg && $issuenumber > $irreg[0]) {
139 if(@irreg && $issuenumber == $irreg[0]){
140 $predictions_loop[0]->{'not_published'} = 1;
150 $date = GetNextDate
(\
%subscription, $date, $frequency);
153 $line{'publicationdate'} = $date;
154 $line{'dow'} = Day_of_Week
(split /-/, $date);
157 # Check if we don't have exceed end date
159 if($subtype eq "issues" && $i >= $sublength){
161 } elsif($subtype eq "weeks" && $date && Delta_Days
( split(/-/, $date), Add_Delta_Days
( split(/-/, $firstacquidate), 7*$sublength - 1 ) ) < 0) {
163 } elsif($subtype eq "months" && $date && (Delta_Days
( split(/-/, $date), Add_Delta_YM
( split(/-/, $firstacquidate), 0, $sublength) ) - 1) < 0 ) {
167 if($enddate && $date && Delta_Days
( split(/-/, $date), split(/-/, $enddate) ) <= 0 ) {
171 ($calculated, $subscription{'lastvalue1'}, $subscription{'lastvalue2'}, $subscription{'lastvalue3'}, $subscription{'innerloop1'}, $subscription{'innerloop2'}, $subscription{'innerloop3'}) = GetNextSeq
(\
%subscription, \
%pattern, $frequency);
173 $line{'number'} = $calculated;
174 $line{'issuenumber'} = $issuenumber;
175 if(@irreg && $issuenumber == $irreg[0]){
176 $line{'not_published'} = 1;
179 push @predictions_loop, \
%line;
185 predictions_loop
=> \
@predictions_loop,
188 if ( $frequency->{unit
} and not $custompattern ) {
189 $template->param( ask_for_irregularities
=> 1 );
190 if ( $frequency->{unit
} eq 'day' and $frequency->{unitsperissue
} == 1 ) {
191 $template->param( daily_options
=> 1 );
195 if ( ( $date && $enddate && $date ne $enddate )
196 or ( $subtype eq 'issues' && $i < $sublength ) )
198 $template->param( not_consistent_end_date
=> 1 );
201 output_html_with_http_headers
$input, $cookie, $template->output;