From ed1dafebbd60aca6337df40fc879b7259397100d Mon Sep 17 00:00:00 2001 From: toins Date: Fri, 21 Jul 2006 09:19:38 +0000 Subject: [PATCH] merged with statecollection.pl --- serials/serials-recieve.pl | 233 +++++++++++++++++++++++++------------ 1 file changed, 158 insertions(+), 75 deletions(-) diff --git a/serials/serials-recieve.pl b/serials/serials-recieve.pl index b00d18d647..3cb8375ad2 100755 --- a/serials/serials-recieve.pl +++ b/serials/serials-recieve.pl @@ -79,7 +79,7 @@ my $query = new CGI; my $op = $query->param('op'); my $dbh = C4::Context->dbh; my $subscriptionid = $query->param('subscriptionid'); -my $auser = $query->param('user'); +# my $auser = $query->param('user'); my $histstartdate = format_date_in_iso($query->param('histstartdate')); my $enddate = format_date_in_iso($query->param('enddate')); my $recievedlist = $query->param('recievedlist'); @@ -89,46 +89,108 @@ my $librariannote = $query->param('librariannote'); my @serialids = $query->param('serialid'); my @serialseqs = $query->param('serialseq'); my @planneddates = $query->param('planneddate'); -my @notes = $query->param('notes'); my @status = $query->param('status'); -# my @publisheddates = $query->param('publisheddates'); - - -my ($template, $loggedinuser, $cookie) -= get_template_and_user({template_name => "serials/serials-recieve.tmpl", - query => $query, - type => "intranet", - authnotrequired => 0, - flagsrequired => {catalogue => 1}, - debug => 1, - }); - +my @notes = $query->param('notes'); +my @barcodes = $query->param('barcode'); +my @itemcallnumbers = $query->param('itemcallnumber'); +my @locations = $query->param('location'); +my @itemstatus = $query->param('itemstatus'); +my @homebranches = $query->param('branch'); my $hassubscriptionexpired = HasSubscriptionExpired($subscriptionid); +my $abouttoexpire = abouttoexpire($subscriptionid); + my $subscription=GetSubscription($subscriptionid); +my $auser = $subscription->{'librarian'}; # bob +my $routing = check_routing($subscriptionid); # to see if routing list exists +my $manualdate =''; +my $manualissue =''; +my $manualstatus =0; +my $manualid =''; +if ($op eq 'found'){ + $manualdate = $query->param('planneddate'); + $manualissue = $query->param('missingissue'); + $manualstatus = 1; + my $sth = $dbh->prepare("select serialid from serial where subscriptionid = ? AND serialseq = ? AND planneddate = ?"); + $sth->execute($subscriptionid,$manualissue,format_date_in_iso($manualdate)); + $manualid = $sth->fetchrow; +} if ($op eq 'modsubscriptionhistory') { - ModSubscriptionHistory($subscriptionid,$histstartdate,$enddate,$recievedlist,$missinglist,$opacnote,$librariannote); + ModSubscriptionHistory($subscriptionid,$histstartdate,$enddate,$recievedlist,$missinglist,$opacnote,$librariannote); } + # change status except, if subscription has expired, for the "waited" issue. if ($op eq 'serialchangestatus') { my $sth = $dbh->prepare("select status from serial where serialid=?"); for (my $i=0;$i<=$#serialids;$i++) { $sth->execute($serialids[$i]); + my ($oldstatus) = $sth->fetchrow; if ($serialids[$i]) { ModSerialStatus($serialids[$i],$serialseqs[$i],format_date_in_iso($planneddates[$i]),$status[$i],$notes[$i]) unless ($hassubscriptionexpired && $oldstatus == 1); + if (($status[$i]==2) && C4::Context->preference("serialsadditems")){ + my %info; + $info{branch}=$homebranches[$i]; + $info{barcode}=$barcodes[$i]; + $info{itemcallnumber}=$itemcallnumbers[$i]; + $info{location}=$locations[$i]; + $info{status}=$itemstatus[$i]; + $info{notes}=$serialseqs[$i]." (".$planneddates[$i].")"; + my ($status2, @errors)= ItemizeSerials($serialids[$i],\%info); + my $sth2 = $dbh->prepare("UPDATE subscriptionhistory SET lastbranch = ? WHERE subscriptionid = ?"); + $sth2->execute($homebranches[$i],$subscriptionid); + $sth2->finish; + # remove from missing list if item being checked in is on it + if ($status2 ==1){ + removeMissingIssue($serialseqs[$i],$subscriptionid); + } + } } else { # add a special issue if ($serialseqs[$i]) { - my $subscription=getsubscription($subscriptionid); - newissue($serialseqs[$i],$subscriptionid,$subscription->{biblionumber},$status[$i], format_date_in_iso($planneddates[$i])); + NewIssue($serialseqs[$i],$subscriptionid,$subscription->{biblionumber},$status[$i], format_date_in_iso($planneddates[$i])); + } + if (($status[$i]==2) && C4::Context->preference("serialsadditems") && !hassubscriptionexpired($subscriptionid)){ + my %info; + $info{branch}=$homebranches[$i]; + $info{barcode}=$barcodes[$i]; + $info{itemcallnumber}=$itemcallnumbers[$i]; + $info{location}=$locations[$i]; + $info{status}=$itemstatus[$i]; + $info{notes}=$serialseqs[$i]." (".$planneddates[$i].")"; + my ($status2, @errors)= ItemizeSerials($serialids[$i],\%info); + my $sth2 = $dbh->prepare("UPDATE subscriptionhistory SET lastbranch = ? WHERE subscriptionid = ?"); + $sth2->execute($homebranches[$i],$subscriptionid); + $sth2->finish; + # remove from missing list if item being checked in is on it + if ($status2 ==1){ + removeMissingIssue($serialseqs[$i],$subscriptionid); + } } + } } } +my ($template, $loggedinuser, $cookie) += get_template_and_user({template_name => "serials/statecollection.tmpl", + query => $query, + type => "intranet", + authnotrequired => 0, + flagsrequired => {catalogue => 1}, + debug => 1, + }); + my $subs = &GetSubscription($subscriptionid); -my ($totalissues,@serialslist) = GetSerials($subscriptionid,10); +my ($totalissues,@serialslist) = GetSerials($subscriptionid); +my $count = @serialslist; +for(my $i=0;$i<$count;$i++){ + $serialslist[$i]->{'callnumber'} = $subscription->{'callnumber'}; + my $temp = rand(10000000); + $serialslist[$i]->{'barcode'} = "TEMP" . sprintf("%.0f",$temp); +} +# use Data::Dumper; +# warn Dumper(@serialslist); my $sth= C4::Serials::GetSubscriptionHistoryFromSubscriptionId(); @@ -139,47 +201,60 @@ my $subs = &GetSubscription($subscriptionid); my ($totalissues,@serialslist) = GetSerials($subscriptionid); if (C4::Context->preference("serialsadditems")){ - my $bibid=MARCfind_MARCbibid_from_oldbiblionumber($dbh,$subscription->{biblionumber}); - my $fwk=MARCfind_frameworkcode($dbh,$bibid); - - my $branches = GetBranches; - my @branchloop; - foreach my $thisbranch (keys %$branches) { - my %row =(value => $thisbranch, - branchname => $branches->{$thisbranch}->{'branchname'}, - ); - push @branchloop, \%row; - } - - my $itemstatushash = getitemstatus($fwk); - my @itemstatusloop; - foreach my $thisitemstatus (keys %$itemstatushash) { - my %row =(itemval => $thisitemstatus, - itemlib => $itemstatushash->{$thisitemstatus}, - ); - push @itemstatusloop, \%row; - } - - my $itemlocationhash = getitemlocation($fwk); - my @itemlocationloop; - foreach my $thisitemlocation (keys %$itemlocationhash) { - my %row =(value => $thisitemlocation, - itemlocationname => $itemlocationhash->{$thisitemlocation}, - ); - push @itemlocationloop, \%row; - } - foreach my $data (@serialslist){ - if (scalar(@itemstatusloop)){$data->{"itemstatusloop"}=\@itemstatusloop;} - else { $data->{"itemstatusloop"}=[];} - if (scalar(@itemlocationloop)){$data->{"itemlocationloop"}=\@itemlocationloop;} - else {$data->{"itemlocationloop"}=[];} - $data->{"branchloop"}=\@branchloop ; - } - $template->param(serialadditems =>C4::Context->preference("serialsadditems"), - branchloop => \@branchloop, - ) ; - $template->param(itemstatus=>1,itemstatusloop=>\@itemstatusloop) if (scalar(@itemstatusloop)); - $template->param(itemlocation=>1,itemlocationloop=>\@itemlocationloop) if (scalar(@itemlocationloop)); + my $bibid=MARCfind_MARCbibid_from_oldbiblionumber($dbh,$subscription->{biblionumber}); + my $fwk=MARCfind_frameworkcode($dbh,$bibid); + + my $branches = GetBranches; + my @branchloop; + foreach my $thisbranch (keys %$branches) { + my $selected = 0; + if($thisbranch eq $solhistory->{'lastbranch'}){ + $selected = 1; + } + my %row =(value => $thisbranch, + branchname => $branches->{$thisbranch}->{'branchname'}, + selected => $selected, + ); + push @branchloop, \%row; + } + + my $itemstatushash = getitemstatus($fwk); + my @itemstatusloop; + my $itemstatusloopcount=0; + foreach my $thisitemstatus (keys %$itemstatushash) { + my %row =(itemval => $thisitemstatus, + itemlib => $itemstatushash->{$thisitemstatus}, + ); +# warn "".$row{'itemval'}.", ". $row{"itemlib"}; + $itemstatusloopcount++; + push @itemstatusloop, \%row; + } + + my $itemlocationhash = getitemlocation($fwk); + my @itemlocationloop; + foreach my $thisitemlocation (keys %$itemlocationhash) { + my %row =(value => $thisitemlocation, + itemlocationname => $itemlocationhash->{$thisitemlocation}, + ); + push @itemlocationloop, \%row; + } + + my $choice = 0; + if($itemstatusloopcount == 1){ $choice = 1;} + foreach my $data (@serialslist){ + if (scalar(@itemstatusloop)){$data->{"itemstatusloop"}=\@itemstatusloop;} + else { $data->{"itemstatusloop"}=[];} + if (scalar(@itemlocationloop)){$data->{"itemlocationloop"}=\@itemlocationloop;} + else {$data->{"itemlocationloop"}=[];} + $data->{"branchloop"}=\@branchloop ; + } +# warn "Choice: $choice"; + $template->param(choice => $choice); + $template->param(serialadditems =>C4::Context->preference("serialsadditems"), + branchloop => \@branchloop, + ) ; + $template->param(itemstatus=>1,itemstatusloop=>\@itemstatusloop) if (scalar(@itemstatusloop)); + $template->param(itemlocation=>1,itemlocationloop=>\@itemlocationloop) if (scalar(@itemlocationloop)); }else{ $template->param(branchloop=>[],itemstatusloop=>[],itemlocationloop=>[]) ; } @@ -190,20 +265,28 @@ my $solhistory = $sth->fetchrow_hashref; $template->param( - serialslist => \@serialslist, - biblionumber => $subscription->{biblionumber}, - histstartdate => format_date($solhistory->{'histstartdate'}), - enddate => format_date($solhistory->{'enddate'}), - recievedlist => $solhistory->{'recievedlist'}, - missinglist => $solhistory->{'missinglist'}, - opacnote => $solhistory->{'opacnote'}, - librariannote => $solhistory->{'librariannote'}, - subscriptionid => $subscriptionid, - bibliotitle => $subs->{bibliotitle}, - biblionumber => $subs->{biblionumber}, - hassubscriptionexpired =>$hassubscriptionexpired, - intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"), - intranetstylesheet => C4::Context->preference("intranetstylesheet"), - IntranetNav => C4::Context->preference("IntranetNav"), - ); + user => $auser, + serialslist => \@serialslist, + count => $count, + biblionumber => $subscription->{biblionumber}, + histstartdate => format_date($solhistory->{'histstartdate'}), + enddate => format_date($solhistory->{'enddate'}), + recievedlist => $solhistory->{'recievedlist'}, + missinglist => $solhistory->{'missinglist'}, + opacnote => $solhistory->{'opacnote'}, + librariannote => $solhistory->{'librariannote'}, + subscriptionid => $subscriptionid, + bibliotitle => $subs->{bibliotitle}, + biblionumber => $subs->{biblionumber}, + hassubscriptionexpired =>$hassubscriptionexpired, + abouttoexpire =>$abouttoexpire, + intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"), + intranetstylesheet => C4::Context->preference("intranetstylesheet"), + IntranetNav => C4::Context->preference("IntranetNav"), + routing => $routing, + missingseq => $manualissue, + frommissing => $manualstatus, + missingdate => $manualdate, + missingid => $manualid, + ); output_html_with_http_headers $query, $cookie, $template->output; -- 2.39.5