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
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
31 * modsubscriptionhistory :to modify the subscription history
32 * serialchangestatus :to modify the status of this subscription
68 use C4
::Dates qw
/format_date format_date_in_iso/;
75 use C4
::Branch
; # GetBranches
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
112 $manualdate = $query->param('planneddate');
113 $manualissue = $query->param('missingissue');
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")){
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);
144 # remove from missing list if item being checked in is on it
146 removeMissingIssue
($serialseqs[$i],$subscriptionid);
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)){
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);
166 # remove from missing list if item being checked in is on it
168 removeMissingIssue
($serialseqs[$i],$subscriptionid);
175 my ($template, $loggedinuser, $cookie)
176 = get_template_and_user
({template_name
=> "serials/serials-recieve.tmpl",
179 authnotrequired
=> 0,
180 flagsrequired
=> {serials
=> 1},
184 my $subs = &GetSubscription
($subscriptionid);
185 my ($totalissues,@serialslist) = GetSerials
($subscriptionid);
186 my $count = @serialslist;
187 for(my $i=0;$i<$count;$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
;
207 foreach my $thisbranch (keys %$branches) {
209 if($thisbranch eq $solhistory->{'lastbranch'}){
212 my %row =(value
=> $thisbranch,
213 branchname
=> $branches->{$thisbranch}->{'branchname'},
214 selected
=> $selected,
216 push @branchloop, \
%row;
218 my $itemstatushash = GetItemStatus
($fwk);
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));
252 $template->param(branchloop
=>[],itemstatusloop
=>[],itemlocationloop
=>[]) ;
255 $sth= C4
::Serials
::GetSubscriptionHistoryFromSubscriptionId
();
256 $sth->execute($subscriptionid);
257 $solhistory = $sth->fetchrow_hashref;
261 serialslist
=> \
@serialslist,
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,
276 missingseq
=> $manualissue,
277 frommissing
=> $manualstatus,
278 missingdate
=> $manualdate,
279 missingid
=> $manualid,
281 output_html_with_http_headers
$query, $cookie, $template->output;