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.tmpl",
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 $sth= C4::Serials::GetSubscriptionHistoryFromSubscriptionId();
197 $sth->execute($subscriptionid);
198 my $solhistory = $sth->fetchrow_hashref;
200 $subs = &GetSubscription($subscriptionid);
201 ($totalissues,@serialslist) = GetSerials($subscriptionid);
203 if (C4::Context->preference("serialsadditems")){
204 my $fwk=GetFrameworkCode($subscription->{biblionumber});
206 my $branches = GetBranches;
208 foreach my $thisbranch (keys %$branches) {
210 if($thisbranch eq $solhistory->{'lastbranch'}){
213 my %row =(value => $thisbranch,
214 branchname => $branches->{$thisbranch}->{'branchname'},
215 selected => $selected,
217 push @branchloop, \%row;
219 my $itemstatushash = GetItemStatus($fwk);
221 my $itemstatusloopcount=0;
222 foreach my $thisitemstatus (keys %$itemstatushash) {
223 my %row =(itemval => $thisitemstatus,
224 itemlib => $itemstatushash->{$thisitemstatus},
226 # warn "".$row{'itemval'}.", ". $row{"itemlib"};
227 $itemstatusloopcount++;
228 push @itemstatusloop, \%row;
230 my $itemlocationhash = GetItemLocation($fwk);
231 my @itemlocationloop;
232 foreach my $thisitemlocation (keys %$itemlocationhash) {
233 my %row =(value => $thisitemlocation,
234 itemlocationname => $itemlocationhash->{$thisitemlocation},
236 push @itemlocationloop, \%row;
239 my $choice = ($itemstatusloopcount == 1) ? 1 : 0;
240 foreach my $data (@serialslist){
241 $data->{"itemstatusloop"} = (scalar(@itemstatusloop )) ? \@itemstatusloop : [];
242 $data->{"itemlocationloop"} = (scalar(@itemlocationloop)) ? \@itemlocationloop : [];
243 $data->{"branchloop"} = \@branchloop ;
245 # warn "Choice: $choice";
246 $template->param(choice => $choice);
247 $template->param(serialadditems =>C4::Context->preference("serialsadditems"),
248 branchloop => \@branchloop,
250 $template->param( itemstatus=>1, itemstatusloop=>\@itemstatusloop ) if (scalar(@itemstatusloop ));
251 $template->param(itemlocation=>1,itemlocationloop=>\@itemlocationloop) if (scalar(@itemlocationloop));
253 $template->param(branchloop=>[],itemstatusloop=>[],itemlocationloop=>[]) ;
256 $sth= C4::Serials::GetSubscriptionHistoryFromSubscriptionId();
257 $sth->execute($subscriptionid);
258 $solhistory = $sth->fetchrow_hashref;
262 serialslist => \@serialslist,
264 biblionumber => $subscription->{biblionumber},
265 histstartdate => format_date($solhistory->{'histstartdate'}),
266 enddate => format_date($solhistory->{'enddate'}),
267 recievedlist => $solhistory->{'recievedlist'},
268 missinglist => $solhistory->{'missinglist'},
269 opacnote => $solhistory->{'opacnote'},
270 librariannote => $solhistory->{'librariannote'},
271 subscriptionid => $subscriptionid,
272 bibliotitle => $subs->{bibliotitle},
273 biblionumber => $subs->{biblionumber},
274 hassubscriptionexpired =>$hassubscriptionexpired,
275 abouttoexpire =>$abouttoexpire,
277 missingseq => $manualissue,
278 frommissing => $manualstatus,
279 missingdate => $manualdate,
280 missingid => $manualid,
282 output_html_with_http_headers $query, $cookie, $template->output;