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
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31 * modsubscriptionhistory :to modify the subscription history
32 * serialchangestatus :to modify the status of this subscription
69 use C4
::Dates qw
/format_date format_date_in_iso/;
76 use C4
::Branch
; # GetBranches
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);
103 my $subscription=GetSubscription
($subscriptionid);
106 my $auser = $subscription->{'librarian'}; # bob
107 my $routing = check_routing
($subscriptionid); # to see if routing list exists
113 $manualdate = $query->param('planneddate');
114 $manualissue = $query->param('missingissue');
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;
120 if ($op eq 'modsubscriptionhistory') {
121 ModSubscriptionHistory
($subscriptionid,$histstartdate,$enddate,$recievedlist,$missinglist,$opacnote,$librariannote);
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]);
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")){
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);
145 # remove from missing list if item being checked in is on it
147 removeMissingIssue
($serialseqs[$i],$subscriptionid);
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]));
155 if (($status[$i]==2) && C4
::Context
->preference("serialsadditems") && !hassubscriptionexpired
($subscriptionid)){
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);
167 # remove from missing list if item being checked in is on it
169 removeMissingIssue
($serialseqs[$i],$subscriptionid);
176 my ($template, $loggedinuser, $cookie)
177 = get_template_and_user
({template_name
=> "serials/serials-recieve.tt",
180 authnotrequired
=> 0,
181 flagsrequired
=> {serials
=> 1},
185 my $subs = &GetSubscription
($subscriptionid);
186 my ($totalissues,@serialslist) = GetSerials
($subscriptionid);
187 my $count = @serialslist;
188 for(my $i=0;$i<$count;$i++){
190 $serialslist[$i]->{'callnumber'} = $subscription->{'callnumber'};
191 my $temp = rand(10000000);
192 $serialslist[$i]->{'barcode'} = "TEMP" . sprintf("%.0f",$temp);
195 my $solhistory = GetSubscriptionHistoryFromSubscriptionId
($subscriptionid);
197 $subs = &GetSubscription
($subscriptionid);
198 ($totalissues,@serialslist) = GetSerials
($subscriptionid);
200 if (C4
::Context
->preference("serialsadditems")){
201 my $fwk=GetFrameworkCode
($subscription->{biblionumber
});
203 my $branches = GetBranches
;
205 foreach my $thisbranch (keys %$branches) {
207 if($thisbranch eq $solhistory->{'lastbranch'}){
210 my %row =(value
=> $thisbranch,
211 branchname
=> $branches->{$thisbranch}->{'branchname'},
212 selected
=> $selected,
214 push @branchloop, \
%row;
216 my $itemstatushash = GetItemStatus
($fwk);
218 my $itemstatusloopcount=0;
219 foreach my $thisitemstatus (keys %$itemstatushash) {
220 my %row =(itemval
=> $thisitemstatus,
221 itemlib
=> $itemstatushash->{$thisitemstatus},
223 # warn "".$row{'itemval'}.", ". $row{"itemlib"};
224 $itemstatusloopcount++;
225 push @itemstatusloop, \
%row;
227 my $itemlocationhash = GetItemLocation
($fwk);
228 my @itemlocationloop;
229 foreach my $thisitemlocation (keys %$itemlocationhash) {
230 my %row =(value
=> $thisitemlocation,
231 itemlocationname
=> $itemlocationhash->{$thisitemlocation},
233 push @itemlocationloop, \
%row;
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 ;
242 # warn "Choice: $choice";
243 $template->param(choice
=> $choice);
244 $template->param(serialadditems
=>C4
::Context
->preference("serialsadditems"),
245 branchloop
=> \
@branchloop,
247 $template->param( itemstatus
=>1, itemstatusloop
=>\
@itemstatusloop ) if (scalar(@itemstatusloop ));
248 $template->param(itemlocation
=>1,itemlocationloop
=>\
@itemlocationloop) if (scalar(@itemlocationloop));
250 $template->param(branchloop
=>[],itemstatusloop
=>[],itemlocationloop
=>[]) ;
253 $solhistory = GetSubscriptionHistoryFromSubscriptionId
($subscriptionid);
257 serialslist
=> \
@serialslist,
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,
272 missingseq
=> $manualissue,
273 frommissing
=> $manualstatus,
274 missingdate
=> $manualdate,
275 missingid
=> $manualid,
276 (uc(C4
::Context
->preference("marcflavour"))) => 1
278 output_html_with_http_headers
$query, $cookie, $template->output;