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 under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 use C4::Dates qw/format_date/;
32 use List::MoreUtils qw/uniq/;
36 my $op = $query->param('op') || q{};
37 my $dbh = C4::Context->dbh;
39 my ($template, $loggedinuser, $cookie);
40 ($template, $loggedinuser, $cookie)
41 = get_template_and_user({template_name => "serials/serials-collection.tmpl",
45 flagsrequired => {serials => 'receive_serials'},
48 my $biblionumber = $query->param('biblionumber');
49 my @subscriptionid = $query->param('subscriptionid');
51 @subscriptionid= uniq @subscriptionid;
52 my $subscriptiondescs;
55 if($op eq 'gennext' && @subscriptionid){
56 my $subscriptionid = $subscriptionid[0];
57 my $subscription = GetSubscription($subscriptionid);
59 my $sth = $dbh->prepare("SELECT publisheddate, serialid, serialseq, planneddate
60 FROM serial WHERE status = 1 AND subscriptionid = ?");
61 $sth->execute($subscriptionid);
63 # modify actual expected issue, to generate the next
64 if ( my $issue = $sth->fetchrow_hashref ) {
65 ModSerialStatus( $issue->{serialid}, $issue->{serialseq},
66 $issue->{planneddate}, $issue->{publisheddate},
69 my $expected = GetNextExpected($subscriptionid);
71 $newserialseq, $newlastvalue1, $newlastvalue2, $newlastvalue3,
72 $newinnerloop1, $newinnerloop2, $newinnerloop3
73 ) = GetNextSeq($subscription);
75 ## We generate the next publication date
76 my $nextpublisheddate = GetNextDate( $expected->{planneddate}->output('iso'), $subscription );
77 ## Creating the new issue
78 NewIssue( $newserialseq, $subscriptionid, $subscription->{'biblionumber'},
79 1, $nextpublisheddate, $nextpublisheddate );
81 ## Updating the subscription seq status
82 my $squery = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=?
83 WHERE subscriptionid = ?";
84 $sth = $dbh->prepare($squery);
86 $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1,
87 $newinnerloop2, $newinnerloop3, $subscriptionid
92 print $query->redirect('/cgi-bin/koha/serials/serials-collection.pl?subscriptionid='.$subscriptionid);
95 my ($location, $callnumber);
97 my @subscriptioninformation=();
98 foreach my $subscriptionid (@subscriptionid){
99 my $subs= GetSubscription($subscriptionid);
100 $subs->{opacnote} =~ s/\n/\<br\/\>/g;
101 $subs->{missinglist} =~ s/\n/\<br\/\>/g;
102 $subs->{recievedlist} =~ s/\n/\<br\/\>/g;
103 ##these are display information
104 $subs->{ "periodicity" . $subs->{periodicity} } = 1;
105 $subs->{ "numberpattern" . $subs->{numberpattern} } = 1;
106 $subs->{ "status" . $subs->{'status'} } = 1;
107 $subs->{startdate} = format_date( $subs->{startdate} );
108 $subs->{histstartdate} = format_date( $subs->{histstartdate} );
109 if ( !defined $subs->{enddate} || $subs->{enddate} eq '0000-00-00' ) {
110 $subs->{enddate} = '';
113 $subs->{enddate} = format_date( $subs->{enddate} );
115 $subs->{'abouttoexpire'}=abouttoexpire($subs->{'subscriptionid'});
116 $subs->{'subscriptionexpired'}=HasSubscriptionExpired($subs->{'subscriptionid'});
117 $subs->{'subscriptionid'} = $subscriptionid; # FIXME - why was this lost ?
118 $location = GetAuthorisedValues('LOC', $subs->{'location'});
119 $callnumber = $subs->{callnumber};
120 push @$subscriptiondescs,$subs;
121 my $tmpsubscription= GetFullSubscription($subscriptionid);
122 @subscriptioninformation=(@$tmpsubscription,@subscriptioninformation);
124 $subscriptions=PrepareSerialsData(\@subscriptioninformation);
126 $subscriptiondescs = GetSubscriptionsFromBiblionumber($biblionumber) ;
127 my $subscriptioninformation = GetFullSubscriptionsFromBiblionumber($biblionumber);
128 $subscriptions=PrepareSerialsData($subscriptioninformation);
131 my $title = $subscriptiondescs->[0]{bibliotitle};
132 my $yearmax=($subscriptions->[0]{year} eq "manage" && scalar(@$subscriptions)>1)? $subscriptions->[1]{year} :$subscriptions->[0]{year};
133 my $yearmin=$subscriptions->[scalar(@$subscriptions)-1]{year};
134 my $subscriptionidlist="";
135 foreach my $subscription (@$subscriptiondescs){
136 $subscriptionidlist.=$subscription->{'subscriptionid'}."," ;
137 $biblionumber = $subscription->{'bibnum'} unless ($biblionumber);
140 # warn "title : $title yearmax : $yearmax nombre d'elements dans le tableau :".scalar(@$subscriptions);
141 # use Data::Dumper; warn Dumper($subscriptions);
143 foreach (@$location) {
144 $locationlib = $_->{'lib'} if $_->{'selected'};
147 chop $subscriptionidlist;
149 onesubscription => (scalar(@$subscriptiondescs)==1),
150 subscriptionidlist => $subscriptionidlist,
151 biblionumber => $biblionumber,
152 subscriptions => $subscriptiondescs,
153 years => $subscriptions,
156 bibliotitle => $title,
157 suggestion => C4::Context->preference("suggestion"),
158 virtualshelves => C4::Context->preference("virtualshelves"),
159 subscr=>$query->param('subscriptionid'),
160 location => $locationlib,
161 callnumber => $callnumber,
164 output_html_with_http_headers $query, $cookie, $template->output;