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('to');
55 my $subtype = $input->param('subtype');
56 my $sublength = $input->param('sublength');
57 my $custompattern = $input->param('custompattern');
61 if ( $frequencyid eq 'mana' ) {
64 'displayorder' => undef,
65 'description' => scalar $input->param('sfdescription') // '',
66 'unitsperissue' => scalar $input->param('unitsperissue') // '',
67 'issuesperunit' => scalar $input->param('issuesperunit') // '',
68 'unit' => scalar $input->param('unit') // ''
72 $frequency = GetSubscriptionFrequency
($frequencyid);
76 numberingmethod
=> scalar $input->param('numberingmethod') // '',
77 numbering1
=> scalar $input->param('numbering1') // '',
78 numbering2
=> scalar $input->param('numbering2') // '',
79 numbering3
=> scalar $input->param('numbering3') // '',
80 add1
=> scalar $input->param('add1') // '',
81 add2
=> scalar $input->param('add2') // '',
82 add3
=> scalar $input->param('add3') // '',
83 whenmorethan1
=> scalar $input->param('whenmorethan1') // '',
84 whenmorethan2
=> scalar $input->param('whenmorethan2') // '',
85 whenmorethan3
=> scalar $input->param('whenmorethan3') // '',
86 setto1
=> scalar $input->param('setto1') // '',
87 setto2
=> scalar $input->param('setto2') // '',
88 setto3
=> scalar $input->param('setto3') // '',
89 every1
=> scalar $input->param('every1') // '',
90 every2
=> scalar $input->param('every2') // '',
91 every3
=> scalar $input->param('every3') // '',
94 $firstacquidate = eval { output_pref
( { str
=> $firstacquidate, dateonly
=> 1, dateformat
=> 'iso' } ); }
95 or output_pref
( { dt
=> dt_from_string
, dateonly
=> 1, dateformat
=> 'iso' } );
97 $enddate = eval { output_pref
( { str
=> $enddate, dateonly
=> 1, dateformat
=> 'iso' } ); };
100 $nextacquidate = eval { output_pref
( { str
=> $nextacquidate, dateonly
=> 1, dateformat
=> 'iso' } ); };
102 $nextacquidate = $firstacquidate;
104 my $date = $nextacquidate;
107 locale
=> scalar $input->param('locale') // '',
108 lastvalue1
=> scalar $input->param('lastvalue1') // '',
109 lastvalue2
=> scalar $input->param('lastvalue2') // '',
110 lastvalue3
=> scalar $input->param('lastvalue3') // '',
111 innerloop1
=> scalar $input->param('innerloop1') // '',
112 innerloop2
=> scalar $input->param('innerloop2') // '',
113 innerloop3
=> scalar $input->param('innerloop3') // '',
115 countissuesperunit
=> 1,
116 firstacquidate
=> $firstacquidate,
120 if(defined $subscriptionid) {
121 ($issuenumber) = C4
::Serials
::GetFictiveIssueNumber
(\
%subscription, $date, $frequency);
126 my @predictions_loop;
127 my ($calculated) = GetSeq
(\
%subscription, \
%pattern);
128 push @predictions_loop, {
129 number
=> $calculated,
130 publicationdate
=> $date,
131 issuenumber
=> $issuenumber,
132 dow
=> Day_of_Week
(split /-/, $date),
135 if(defined $subscriptionid) {
136 @irreg = C4
::Serials
::GetSubscriptionIrregularities
($subscriptionid);
137 while(@irreg && $issuenumber > $irreg[0]) {
140 if(@irreg && $issuenumber == $irreg[0]){
141 $predictions_loop[0]->{'not_published'} = 1;
151 $date = GetNextDate
(\
%subscription, $date, $frequency);
154 $line{'publicationdate'} = $date;
155 $line{'dow'} = Day_of_Week
(split /-/, $date);
158 # Check if we don't have exceed end date
160 if($subtype eq "issues" && $i >= $sublength){
162 } elsif($subtype eq "weeks" && $date && Delta_Days
( split(/-/, $date), Add_Delta_Days
( split(/-/, $firstacquidate), 7*$sublength - 1 ) ) < 0) {
164 } elsif($subtype eq "months" && $date && (Delta_Days
( split(/-/, $date), Add_Delta_YM
( split(/-/, $firstacquidate), 0, $sublength) ) - 1) < 0 ) {
168 if($enddate && $date && Delta_Days
( split(/-/, $date), split(/-/, $enddate) ) <= 0 ) {
172 ($calculated, $subscription{'lastvalue1'}, $subscription{'lastvalue2'}, $subscription{'lastvalue3'}, $subscription{'innerloop1'}, $subscription{'innerloop2'}, $subscription{'innerloop3'}) = GetNextSeq
(\
%subscription, \
%pattern, $frequency);
174 $line{'number'} = $calculated;
175 $line{'issuenumber'} = $issuenumber;
176 if(@irreg && $issuenumber == $irreg[0]){
177 $line{'not_published'} = 1;
180 push @predictions_loop, \
%line;
186 predictions_loop
=> \
@predictions_loop,
189 if ( $frequency->{unit
} and not $custompattern ) {
190 $template->param( ask_for_irregularities
=> 1 );
191 if ( $frequency->{unit
} eq 'day' and $frequency->{unitsperissue
} == 1 ) {
192 $template->param( daily_options
=> 1 );
196 if ( ( $date && $enddate && $date ne $enddate )
197 or ( $subtype eq 'issues' && $i < $sublength ) )
199 $template->param( not_consistent_end_date
=> 1 );
202 output_html_with_http_headers
$input, $cookie, $template->output;