3 # Copyright 2011 BibLibre SARL
4 # This file is part of Koha.
6 # Koha is free software; you can redistribute it and/or modify it under the
7 # terms of the GNU General Public License as published by the Free Software
8 # Foundation; either version 2 of the License, or (at your option) any later
11 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
12 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with Koha; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 showpredictionpattern.pl
25 This script calculate numbering of serials based on numbering pattern, and
26 publication date, based on frequency and first publication date.
33 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);
37 use C4::Serials::Frequency;
40 my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( {
41 template_name => 'serials/showpredictionpattern.tt',
45 flagsrequired => { 'serials' => '*' },
48 my $subscriptionid = $input->param('subscriptionid');
49 my $frequencyid = $input->param('frequency');
50 my $firstacquidate = $input->param('firstacquidate');
51 my $nextacquidate = $input->param('nextacquidate');
52 my $enddate = $input->param('enddate');
53 my $subtype = $input->param('subtype');
54 my $sublength = $input->param('sublength');
55 my $custompattern = $input->param('custompattern');
59 numberingmethod => $input->param('numberingmethod') // '',
60 numbering1 => $input->param('numbering1') // '',
61 numbering2 => $input->param('numbering2') // '',
62 numbering3 => $input->param('numbering3') // '',
63 add1 => $input->param('add1') // '',
64 add2 => $input->param('add2') // '',
65 add3 => $input->param('add3') // '',
66 whenmorethan1 => $input->param('whenmorethan1') // '',
67 whenmorethan2 => $input->param('whenmorethan2') // '',
68 whenmorethan3 => $input->param('whenmorethan3') // '',
69 setto1 => $input->param('setto1') // '',
70 setto2 => $input->param('setto2') // '',
71 setto3 => $input->param('setto3') // '',
72 every1 => $input->param('every1') // '',
73 every2 => $input->param('every2') // '',
74 every3 => $input->param('every3') // '',
77 if(!defined $firstacquidate || $firstacquidate eq ''){
78 my ($year, $month, $day) = Today();
79 $firstacquidate = sprintf "%04d-%02d-%02d", $year, $month, $day;
81 $firstacquidate = C4::Dates->new($firstacquidate)->output('iso');
85 $enddate = C4::Dates->new($enddate)->output('iso');
89 $nextacquidate = C4::Dates->new($nextacquidate)->output('iso');
91 $nextacquidate = $firstacquidate;
93 my $date = $nextacquidate;
96 locale => $input->param('locale') // '',
97 lastvalue1 => $input->param('lastvalue1') // '',
98 lastvalue2 => $input->param('lastvalue2') // '',
99 lastvalue3 => $input->param('lastvalue3') // '',
100 innerloop1 => $input->param('innerloop1') // '',
101 innerloop2 => $input->param('innerloop2') // '',
102 innerloop3 => $input->param('innerloop3') // '',
104 periodicity => $frequencyid,
105 countissuesperunit => 1,
106 firstacquidate => $firstacquidate,
110 if(defined $subscriptionid) {
111 ($issuenumber) = C4::Serials::GetFictiveIssueNumber(\%subscription, $date);
116 my @predictions_loop;
117 my ($calculated) = GetSeq(\%subscription, \%pattern);
118 push @predictions_loop, {
119 number => $calculated,
120 publicationdate => $date,
121 issuenumber => $issuenumber,
122 dow => Day_of_Week(split /-/, $date),
125 if(defined $subscriptionid) {
126 @irreg = C4::Serials::GetSubscriptionIrregularities($subscriptionid);
127 while(@irreg && $issuenumber > $irreg[0]) {
130 if(@irreg && $issuenumber == $irreg[0]){
131 $predictions_loop[0]->{'not_published'} = 1;
141 $date = GetNextDate(\%subscription, $date);
144 $line{'publicationdate'} = $date;
145 $line{'dow'} = Day_of_Week(split /-/, $date);
148 # Check if we don't have exceed end date
150 if($subtype eq "issues" && $i >= $sublength){
152 } elsif($subtype eq "weeks" && $date && Delta_Days( split(/-/, $date), Add_Delta_Days( split(/-/, $firstacquidate), 7*$sublength - 1 ) ) < 0) {
154 } elsif($subtype eq "months" && $date && (Delta_Days( split(/-/, $date), Add_Delta_YM( split(/-/, $firstacquidate), 0, $sublength) ) - 1) < 0 ) {
158 if($enddate && $date && Delta_Days( split(/-/, $date), split(/-/, $enddate) ) <= 0 ) {
162 ($calculated, $subscription{'lastvalue1'}, $subscription{'lastvalue2'}, $subscription{'lastvalue3'}, $subscription{'innerloop1'}, $subscription{'innerloop2'}, $subscription{'innerloop3'}) = GetNextSeq(\%subscription, \%pattern);
164 $line{'number'} = $calculated;
165 $line{'issuenumber'} = $issuenumber;
166 if(@irreg && $issuenumber == $irreg[0]){
167 $line{'not_published'} = 1;
170 push @predictions_loop, \%line;
176 predictions_loop => \@predictions_loop,
179 my $frequency = GetSubscriptionFrequency($frequencyid);
181 if ( $frequency->{unit} and not $custompattern ) {
182 $template->param( ask_for_irregularities => 1 );
183 if ( $frequency->{unit} eq 'day' and $frequency->{unitsperissue} == 1 ) {
184 $template->param( daily_options => 1 );
188 if ( ( $date && $enddate && $date ne $enddate )
189 or ( $subtype eq 'issues' && $i < $sublength ) )
191 $template->param( not_consistent_end_date => 1 );
194 output_html_with_http_headers $input, $cookie, $template->output;