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