Fixing page numbering in searchresultlist-auth.tmpl
[koha.git] / serials / serials-recieve.pl
blob6df5b94b5bec3097077a528495c9548ead276af9
1 #!/usr/bin/perl
3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
21 =head1 NAME
23 serials-recieve.pl
25 =head1 Parameters
27 =over 4
29 =item op
30 op can be :
31 * modsubscriptionhistory :to modify the subscription history
32 * serialchangestatus :to modify the status of this subscription
34 =item subscriptionid
36 =item user
38 =item histstartdate
40 =item enddate
42 =item recievedlist
44 =item missinglist
46 =item opacnote
48 =item librariannote
50 =item serialid
52 =item serialseq
54 =item planneddate
56 =item notes
58 =item status
60 =back
62 =cut
65 use strict;
66 use CGI;
67 use C4::Auth;
68 use C4::Dates qw/format_date format_date_in_iso/;
69 use C4::Biblio;
70 use C4::Items;
71 use C4::Koha;
72 use C4::Output;
73 use C4::Context;
74 use C4::Serials;
75 use C4::Branch; # GetBranches
77 my $query = new CGI;
78 my $op = $query->param('op') || q{};
79 my $dbh = C4::Context->dbh;
80 my $subscriptionid = $query->param('subscriptionid');
81 # my $auser = $query->param('user');
82 my $histstartdate = format_date_in_iso($query->param('histstartdate'));
83 my $enddate = format_date_in_iso($query->param('enddate'));
84 my $recievedlist = $query->param('recievedlist');
85 my $missinglist = $query->param('missinglist');
86 my $opacnote = $query->param('opacnote');
87 my $librariannote = $query->param('librariannote');
88 my @serialids = $query->param('serialid');
89 my @serialseqs = $query->param('serialseq');
90 my @planneddates = $query->param('planneddate');
91 my @publisheddates = $query->param('publisheddate');
92 my @status = $query->param('status');
93 my @notes = $query->param('notes');
94 my @barcodes = $query->param('barcode');
95 my @itemcallnumbers = $query->param('itemcallnumber');
96 my @locations = $query->param('location');
97 my @itemstatus = $query->param('itemstatus');
98 my @homebranches = $query->param('branch');
99 my $hassubscriptionexpired = HasSubscriptionExpired($subscriptionid);
100 my $abouttoexpire = abouttoexpire($subscriptionid);
102 my $subscription=GetSubscription($subscriptionid);
105 my $auser = $subscription->{'librarian'}; # bob
106 my $routing = check_routing($subscriptionid); # to see if routing list exists
107 my $manualdate ='';
108 my $manualissue ='';
109 my $manualstatus =0;
110 my $manualid ='';
111 if ($op eq 'found'){
112 $manualdate = $query->param('planneddate');
113 $manualissue = $query->param('missingissue');
114 $manualstatus = 1;
115 my $sth = $dbh->prepare("select serialid from serial where subscriptionid = ? AND serialseq = ? AND planneddate = ?");
116 $sth->execute($subscriptionid,$manualissue,format_date_in_iso($manualdate));
117 $manualid = $sth->fetchrow;
119 if ($op eq 'modsubscriptionhistory') {
120 ModSubscriptionHistory($subscriptionid,$histstartdate,$enddate,$recievedlist,$missinglist,$opacnote,$librariannote);
123 # change status except, if subscription has expired, for the "waited" issue.
124 if ($op eq 'serialchangestatus') {
125 my $sth = $dbh->prepare("select status from serial where serialid=?");
126 for (my $i=0;$i<=$#serialids;$i++) {
127 $sth->execute($serialids[$i]);
129 my ($oldstatus) = $sth->fetchrow;
130 if ($serialids[$i]) {
131 ModSerialStatus($serialids[$i],$serialseqs[$i],format_date_in_iso($planneddates[$i]),format_date_in_iso($publisheddates[$i]),$status[$i],$notes[$i]) unless ($hassubscriptionexpired && $oldstatus == 1);
132 if (($status[$i]==2) && C4::Context->preference("serialsadditems")){
133 my %info;
134 $info{branch}=$homebranches[$i];
135 $info{barcode}=$barcodes[$i];
136 $info{itemcallnumber}=$itemcallnumbers[$i];
137 $info{location}=$locations[$i];
138 $info{status}=$itemstatus[$i];
139 $info{notes}=$serialseqs[$i]." (".$planneddates[$i].")";
140 my ($status2, @errors)= ItemizeSerials($serialids[$i],\%info);
141 my $sth2 = $dbh->prepare("UPDATE subscriptionhistory SET lastbranch = ? WHERE subscriptionid = ?");
142 $sth2->execute($homebranches[$i],$subscriptionid);
143 $sth2->finish;
144 # remove from missing list if item being checked in is on it
145 if ($status2 ==1){
146 removeMissingIssue($serialseqs[$i],$subscriptionid);
149 } else {
150 # add a special issue
151 if ($serialseqs[$i]) {
152 NewIssue($serialseqs[$i],$subscriptionid,$subscription->{biblionumber},$status[$i] ,format_date_in_iso($publisheddates[$i]),format_date_in_iso($planneddates[$i]));
154 if (($status[$i]==2) && C4::Context->preference("serialsadditems") && !hassubscriptionexpired($subscriptionid)){
155 my %info;
156 $info{branch}=$homebranches[$i];
157 $info{barcode}=$barcodes[$i];
158 $info{itemcallnumber}=$itemcallnumbers[$i];
159 $info{location}=$locations[$i];
160 $info{status}=$itemstatus[$i];
161 $info{notes}=$serialseqs[$i]." (".$planneddates[$i].")";
162 my ($status2, @errors)= ItemizeSerials($serialids[$i],\%info);
163 my $sth2 = $dbh->prepare("UPDATE subscriptionhistory SET lastbranch = ? WHERE subscriptionid = ?");
164 $sth2->execute($homebranches[$i],$subscriptionid);
165 $sth2->finish;
166 # remove from missing list if item being checked in is on it
167 if ($status2 ==1){
168 removeMissingIssue($serialseqs[$i],$subscriptionid);
175 my ($template, $loggedinuser, $cookie)
176 = get_template_and_user({template_name => "serials/serials-recieve.tmpl",
177 query => $query,
178 type => "intranet",
179 authnotrequired => 0,
180 flagsrequired => {serials => 1},
181 debug => 1,
184 my $subs = &GetSubscription($subscriptionid);
185 my ($totalissues,@serialslist) = GetSerials($subscriptionid);
186 my $count = @serialslist;
187 for(my $i=0;$i<$count;$i++){
188 warn "la : $i";
189 $serialslist[$i]->{'callnumber'} = $subscription->{'callnumber'};
190 my $temp = rand(10000000);
191 $serialslist[$i]->{'barcode'} = "TEMP" . sprintf("%.0f",$temp);
194 my $sth= C4::Serials::GetSubscriptionHistoryFromSubscriptionId();
196 $sth->execute($subscriptionid);
197 my $solhistory = $sth->fetchrow_hashref;
199 $subs = &GetSubscription($subscriptionid);
200 ($totalissues,@serialslist) = GetSerials($subscriptionid);
202 if (C4::Context->preference("serialsadditems")){
203 my $fwk=GetFrameworkCode($subscription->{biblionumber});
205 my $branches = GetBranches;
206 my @branchloop;
207 foreach my $thisbranch (keys %$branches) {
208 my $selected = 0;
209 if($thisbranch eq $solhistory->{'lastbranch'}){
210 $selected = 1;
212 my %row =(value => $thisbranch,
213 branchname => $branches->{$thisbranch}->{'branchname'},
214 selected => $selected,
216 push @branchloop, \%row;
218 my $itemstatushash = GetItemStatus($fwk);
219 my @itemstatusloop;
220 my $itemstatusloopcount=0;
221 foreach my $thisitemstatus (keys %$itemstatushash) {
222 my %row =(itemval => $thisitemstatus,
223 itemlib => $itemstatushash->{$thisitemstatus},
225 # warn "".$row{'itemval'}.", ". $row{"itemlib"};
226 $itemstatusloopcount++;
227 push @itemstatusloop, \%row;
229 my $itemlocationhash = GetItemLocation($fwk);
230 my @itemlocationloop;
231 foreach my $thisitemlocation (keys %$itemlocationhash) {
232 my %row =(value => $thisitemlocation,
233 itemlocationname => $itemlocationhash->{$thisitemlocation},
235 push @itemlocationloop, \%row;
238 my $choice = ($itemstatusloopcount == 1) ? 1 : 0;
239 foreach my $data (@serialslist){
240 $data->{"itemstatusloop"} = (scalar(@itemstatusloop )) ? \@itemstatusloop : [];
241 $data->{"itemlocationloop"} = (scalar(@itemlocationloop)) ? \@itemlocationloop : [];
242 $data->{"branchloop"} = \@branchloop ;
244 # warn "Choice: $choice";
245 $template->param(choice => $choice);
246 $template->param(serialadditems =>C4::Context->preference("serialsadditems"),
247 branchloop => \@branchloop,
249 $template->param( itemstatus=>1, itemstatusloop=>\@itemstatusloop ) if (scalar(@itemstatusloop ));
250 $template->param(itemlocation=>1,itemlocationloop=>\@itemlocationloop) if (scalar(@itemlocationloop));
251 } else {
252 $template->param(branchloop=>[],itemstatusloop=>[],itemlocationloop=>[]) ;
255 $sth= C4::Serials::GetSubscriptionHistoryFromSubscriptionId();
256 $sth->execute($subscriptionid);
257 $solhistory = $sth->fetchrow_hashref;
259 $template->param(
260 user => $auser,
261 serialslist => \@serialslist,
262 count => $count,
263 biblionumber => $subscription->{biblionumber},
264 histstartdate => format_date($solhistory->{'histstartdate'}),
265 enddate => format_date($solhistory->{'enddate'}),
266 recievedlist => $solhistory->{'recievedlist'},
267 missinglist => $solhistory->{'missinglist'},
268 opacnote => $solhistory->{'opacnote'},
269 librariannote => $solhistory->{'librariannote'},
270 subscriptionid => $subscriptionid,
271 bibliotitle => $subs->{bibliotitle},
272 biblionumber => $subs->{biblionumber},
273 hassubscriptionexpired =>$hassubscriptionexpired,
274 abouttoexpire =>$abouttoexpire,
275 routing => $routing,
276 missingseq => $manualissue,
277 frommissing => $manualstatus,
278 missingdate => $manualdate,
279 missingid => $manualid,
281 output_html_with_http_headers $query, $cookie, $template->output;