3 # Copyright 2000-2002 Katipo Communications
4 # Parts Copyright 2010 Biblibre
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
31 use Koha
::DateUtils
qw( dt_from_string );
33 use List
::MoreUtils qw
/uniq/;
37 my $op = $query->param('op') || q{};
38 my $nbissues=$query->param('nbissues');
39 my $date_received_today = $query->param('date_received_today') || 0;
40 my $dbh = C4
::Context
->dbh;
42 my ($template, $loggedinuser, $cookie)
43 = get_template_and_user
({template_name
=> "serials/serials-collection.tt",
47 flagsrequired
=> {serials
=> '*'},
50 my $biblionumber = $query->param('biblionumber');
51 my @subscriptionid = $query->multi_param('subscriptionid');
53 @subscriptionid= uniq
@subscriptionid;
54 @subscriptionid= sort @subscriptionid;
55 my $subscriptiondescs;
58 if($op eq 'gennext' && @subscriptionid){
59 my $subscriptionid = $subscriptionid[0];
60 my $sth = $dbh->prepare("
61 SELECT publisheddate, publisheddatetext, serialid, serialseq,
64 WHERE status = 1 AND subscriptionid = ?
66 my $status = defined( $nbissues ) ?
2 : 3;
68 for ( my $i = 0; $i < $nbissues; $i++ ){
69 $sth->execute($subscriptionid);
70 # modify actual expected issue, to generate the next
71 if ( my $issue = $sth->fetchrow_hashref ) {
72 my $planneddate = $date_received_today ? dt_from_string
: $issue->{planneddate
};
73 ModSerialStatus
( $issue->{serialid
}, $issue->{serialseq
},
74 $planneddate, $issue->{publisheddate
},
75 $issue->{publisheddatetext
}, $status, "" );
77 require C4
::Serials
::Numberpattern
;
78 my $subscription = GetSubscription
($subscriptionid);
79 my $pattern = C4
::Serials
::Numberpattern
::GetSubscriptionNumberpattern
($subscription->{numberpattern
});
80 my $expected = GetNextExpected
($subscriptionid);
82 $newserialseq, $newlastvalue1, $newlastvalue2, $newlastvalue3,
83 $newinnerloop1, $newinnerloop2, $newinnerloop3
84 ) = GetNextSeq
($subscription, $pattern, $expected->{publisheddate
});
86 ## We generate the next publication date
87 my $nextpublisheddate = GetNextDate
($subscription, $expected->{publisheddate
}, 1);
88 my $planneddate = $date_received_today ? dt_from_string
: $nextpublisheddate;
89 ## Creating the new issue
90 NewIssue
( $newserialseq, $subscriptionid, $subscription->{'biblionumber'},
91 1, $planneddate, $nextpublisheddate );
93 ## Updating the subscription seq status
94 my $squery = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=?
95 WHERE subscriptionid = ?";
96 my $seqsth = $dbh->prepare($squery);
98 $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1,
99 $newinnerloop2, $newinnerloop3, $subscriptionid
103 last if $nbissues == 1;
104 last if HasSubscriptionExpired
($subscriptionid) > 0;
106 print $query->redirect('/cgi-bin/koha/serials/serials-collection.pl?subscriptionid='.$subscriptionid);
110 my $subscriptioncount;
111 my ($location, $callnumber);
112 if (@subscriptionid){
113 my @subscriptioninformation=();
115 foreach my $subscriptionid (@subscriptionid){
116 my $subs= GetSubscription
($subscriptionid);
118 $closed = 1 if $subs->{closed
};
120 $subs->{opacnote
} =~ s/\n/\<br\/\
>/g
;
121 $subs->{missinglist
} =~ s/\n/\<br\/\
>/g
;
122 $subs->{recievedlist
} =~ s/\n/\<br\/\
>/g
;
124 ##these are display information
125 $subs->{'abouttoexpire'}=abouttoexpire
($subs->{'subscriptionid'});
126 $subs->{'subscriptionexpired'}=HasSubscriptionExpired
($subs->{'subscriptionid'});
127 $subs->{'subscriptionid'} = $subscriptionid; # FIXME - why was this lost ?
128 $location = $subs->{'location'};
129 $callnumber = $subs->{callnumber
};
130 my $frequency = C4
::Serials
::Frequency
::GetSubscriptionFrequency
($subs->{periodicity
});
131 my $numberpattern = C4
::Serials
::Numberpattern
::GetSubscriptionNumberpattern
($subs->{numberpattern
});
132 $subs->{frequency
} = $frequency;
133 $subs->{numberpattern
} = $numberpattern;
134 $subs->{'hasRouting'} = check_routing
($subscriptionid);
135 push @
$subscriptiondescs,$subs;
136 my $tmpsubscription= GetFullSubscription
($subscriptionid);
137 @subscriptioninformation=(@
$tmpsubscription,@subscriptioninformation);
140 output_and_exit
( $query, $cookie, $template, 'unknown_subscription') unless @subscriptioninformation;
142 $template->param(closed
=> $closed);
143 $subscriptions=PrepareSerialsData
(\
@subscriptioninformation);
144 $subscriptioncount = CountSubscriptionFromBiblionumber
($subscriptiondescs->[0]{'biblionumber'});
146 $subscriptiondescs = GetSubscriptionsFromBiblionumber
($biblionumber);
147 foreach my $s (@
$subscriptiondescs) {
148 my $frequency = C4
::Serials
::Frequency
::GetSubscriptionFrequency
($s->{periodicity
});
149 my $numberpattern = C4
::Serials
::Numberpattern
::GetSubscriptionNumberpattern
($s->{numberpattern
});
150 $s->{frequency
} = $frequency;
151 $s->{numberpattern
} = $numberpattern;
153 my $subscriptioninformation = GetFullSubscriptionsFromBiblionumber
($biblionumber);
154 $subscriptions=PrepareSerialsData
($subscriptioninformation);
157 my $title = $subscriptiondescs->[0]{bibliotitle
};
158 my $yearmax=($subscriptions->[0]{year
} eq "manage" && scalar(@
$subscriptions)>1)?
$subscriptions->[1]{year
} :$subscriptions->[0]{year
};
159 my $yearmin=$subscriptions->[scalar(@
$subscriptions)-1]{year
};
160 my $subscriptionidlist="";
161 foreach my $subscription (@
$subscriptiondescs){
162 $subscriptionidlist.=$subscription->{'subscriptionid'}."," ;
163 $biblionumber = $subscription->{'bibnum'} unless ($biblionumber);
164 $subscription->{'hasRouting'} = check_routing
($subscription->{'subscriptionid'});
167 chop $subscriptionidlist;
169 subscriptionidlist
=> $subscriptionidlist,
170 biblionumber
=> $biblionumber,
171 subscriptions
=> $subscriptiondescs,
172 years
=> $subscriptions,
175 bibliotitle
=> $title,
176 suggestion
=> C4
::Context
->preference("suggestion"),
177 virtualshelves
=> C4
::Context
->preference("virtualshelves"),
178 routing
=> C4
::Context
->preference("RoutingSerials"),
179 subscr
=>scalar $query->param('subscriptionid'),
180 subscriptioncount
=> $subscriptioncount,
181 location
=> $location,
182 callnumber
=> $callnumber,
183 uc(C4
::Context
->preference("marcflavour")) => 1,
184 serialsadditems
=> $subscriptiondescs->[0]{'serialsadditems'},
187 output_html_with_http_headers
$query, $cookie, $template->output;