diff --git a/C4/Bull.pm b/C4/Bull.pm index def1114a80..29683e5a3b 100755 --- a/C4/Bull.pm +++ b/C4/Bull.pm @@ -53,7 +53,152 @@ Give all XYZ functions &getserials &getlatestserials &serialchangestatus &Find_Next_Date, &Get_Next_Seq &hassubscriptionexpired &subscriptionexpirationdate &subscriptionrenew - &getSupplierListWithLateIssues &GetLateIssues); + &getSupplierListWithLateIssues &GetLateIssues &GetMissingIssues + &getroutinglist &delroutingmember &addroutingmember &reorder_members + &check_routing &getsupplierbyserialid &updateClaim &removeMissingIssue &abouttoexpire + &old_getserials &old_newsubscription &old_modsubscription &old_serialchangestatus); + +# for removing the missing issue sequence from the box on check-in page +sub removeMissingIssue { + my ($sequence,$subscriptionid) = @_; + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare("SELECT * FROM subscriptionhistory WHERE subscriptionid = ?"); + $sth->execute($subscriptionid); + my $data = $sth->fetchrow_hashref; + my $missinglist = $data->{'missinglist'}; + my $missinglistbefore = $missinglist; + # warn $missinglist." before"; + $missinglist =~ s/($sequence)//; + # warn $missinglist." after"; + if($missinglist ne $missinglistbefore){ + $missinglist =~ s/\|\s\|/\|/g; + $missinglist =~ s/^\| //g; + $missinglist =~ s/\|$//g; + my $sth2= $dbh->prepare("UPDATE subscriptionhistory + SET missinglist = ? + WHERE subscriptionid = ?"); + $sth2->execute($missinglist,$subscriptionid); + } +} + +sub updateClaim { + my ($serialid) = @_; + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare("UPDATE serial SET claimdate = now() + WHERE serialid = ? + "); + $sth->execute($serialid); +} + +sub getsupplierbyserialid { + my ($serialid) = @_; + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare("SELECT serialid, serial.subscriptionid, aqbooksellerid + FROM serial, subscription + WHERE serial.subscriptionid = subscription.subscriptionid + AND serialid = ? + "); + $sth->execute($serialid); + my $line = $sth->fetchrow_hashref; + my $result = $line->{'aqbooksellerid'}; + return $result; +} + +sub check_routing { + my ($subscriptionid) = @_; + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare("SELECT count(routingid) routingids FROM subscriptionroutinglist, subscription + WHERE subscription.subscriptionid = subscriptionroutinglist.subscriptionid + AND subscription.subscriptionid = ? ORDER BY ranking ASC + "); + $sth->execute($subscriptionid); + my $line = $sth->fetchrow_hashref; + my $result = $line->{'routingids'}; + return $result; +} + +sub addroutingmember { + my ($bornum,$subscriptionid) = @_; + my $rank; + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare("SELECT max(ranking) rank FROM subscriptionroutinglist WHERE subscriptionid = ?"); + $sth->execute($subscriptionid); + while(my $line = $sth->fetchrow_hashref){ + if($line->{'rank'}>0){ + $rank = $line->{'rank'}+1; + } else { + $rank = 1; + } + } + $sth = $dbh->prepare("INSERT INTO subscriptionroutinglist VALUES (null,?,?,?,null)"); + $sth->execute($subscriptionid,$bornum,$rank); +} + +sub reorder_members { + # updates the ranks for the unique routingids for a subscription + # if $rank is specified then it changes the ranking of the routingid to the new rank + my ($subscriptionid,$routingid,$rank) = @_; + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare("SELECT * FROM subscriptionroutinglist WHERE subscriptionid = ? ORDER BY ranking ASC"); + $sth->execute($subscriptionid); + my @result; + while(my $line = $sth->fetchrow_hashref){ + push(@result,$line->{'routingid'}); + } + + # To find the matching index + my $i; + my $key = -1; # to allow for 0 being a valid response + for ($i = 0; $i < @result; $i++) { + if ($routingid == $result[$i]) { + $key = $i; # save the index + last; + } + } + # warn "key: $key"; + # if index exists in array then move it to new position + if($key > -1 && $rank > 0){ + my $new_rank = $rank-1; # $new_rank is what you want the new index to be in the array + my $moving_item = splice(@result, $key, 1); + splice(@result, $new_rank, 0, $moving_item); + } + for(my $j = 0; $j < @result; $j++){ + my $sth = $dbh->prepare("UPDATE subscriptionroutinglist SET ranking = '" . ($j+1) . "' WHERE routingid = '". $result[$j]."'"); + $sth->execute; + } +} + +sub delroutingmember { + # if $routingid exists then deletes that row otherwise deletes all with $subscriptionid + my ($routingid,$subscriptionid) = @_; + my $dbh = C4::Context->dbh; + if($routingid){ + my $sth = $dbh->prepare("DELETE FROM subscriptionroutinglist WHERE routingid = ?"); + $sth->execute($routingid); + reorder_members($subscriptionid,$routingid); + } else { + my $sth = $dbh->prepare("DELETE FROM subscriptionroutinglist WHERE subscriptionid = ?"); + $sth->execute($subscriptionid); + } +} + +sub getroutinglist { + my ($subscriptionid) = @_; + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare("SELECT routingid, borrowernumber, + ranking, biblionumber FROM subscriptionroutinglist, subscription + WHERE subscription.subscriptionid = subscriptionroutinglist.subscriptionid + AND subscription.subscriptionid = ? ORDER BY ranking ASC + "); + $sth->execute($subscriptionid); + my @routinglist; + my $count=0; + while (my $line = $sth->fetchrow_hashref) { + $count++; + push(@routinglist,$line); + } + return ($count,@routinglist); +} sub getSupplierListWithLateIssues { my $dbh = C4::Context->dbh; @@ -61,13 +206,14 @@ sub getSupplierListWithLateIssues { FROM subscription, serial LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id WHERE subscription.subscriptionid = serial.subscriptionid AND - (planneddate < now( ) OR serial.STATUS = 3) + (planneddate < now( ) OR serial.STATUS = 3 OR serial.STATUS = 4) "); $sth->execute; my %supplierlist; while (my ($id,$name) = $sth->fetchrow) { $supplierlist{$id} = $name; } + $supplierlist{''} = "All Suppliers"; return %supplierlist; } sub GetLateIssues { @@ -96,15 +242,62 @@ sub GetLateIssues { my @issuelist; my $last_title; my $odd=0; + my $count=0; while (my $line = $sth->fetchrow_hashref) { $odd++ unless $line->{title} eq $last_title; $line->{title} = "" if $line->{title} eq $last_title; $last_title = $line->{title} if ($line->{title}); $line->{planneddate} = format_date($line->{planneddate}); $line->{'odd'} = 1 if $odd %2 ; + $count++; push @issuelist,$line; } - return @issuelist; + return $count,@issuelist; +} + +sub GetMissingIssues { + my ($supplierid,$serialid) = @_; + my $dbh = C4::Context->dbh; + my $sth; + my $byserial=''; + if($serialid) { + $byserial = "and serialid = ".$serialid; + } + + if ($supplierid) { + $sth = $dbh->prepare("SELECT serialid,aqbooksellerid,name,title,planneddate,serialseq,serial.subscriptionid,claimdate + FROM subscription, serial, biblio + LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id + WHERE subscription.subscriptionid = serial.subscriptionid AND + serial.STATUS = 4 and + subscription.aqbooksellerid=$supplierid and + biblio.biblionumber = subscription.biblionumber ".$byserial." order by title + "); + } else { + $sth = $dbh->prepare("SELECT serialid,aqbooksellerid,name,title,planneddate,serialseq,serial.subscriptionid,claimdate + FROM subscription, serial, biblio + LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id + WHERE subscription.subscriptionid = serial.subscriptionid AND + serial.STATUS =4 and + biblio.biblionumber = subscription.biblionumber ".$byserial." order by title + "); + } + $sth->execute; + my @issuelist; + my $last_title; + my $odd=0; + my $count=0; + while (my $line = $sth->fetchrow_hashref) { + $odd++ unless $line->{title} eq $last_title; + # $line->{title} = "" if $line->{title} eq $last_title; + $last_title = $line->{title} if ($line->{title}); + $line->{planneddate} = format_date($line->{planneddate}); + $line->{claimdate} = format_date($line->{claimdate}); + $line->{'odd'} = 1 if $odd %2 ; + $count++; + push @issuelist,$line; + } + return $count,@issuelist; } sub newsubscription { @@ -121,7 +314,7 @@ sub newsubscription { add1,every1,whenmorethan1,setto1,lastvalue1,innerloop1, add2,every2,whenmorethan2,setto2,lastvalue2,innerloop2, add3,every3,whenmorethan3,setto3,lastvalue3,innerloop3, - numberingmethod, status, notes) values + numberingmethod, status, notes) values (?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?,?,?,?,?)"); @@ -293,6 +486,19 @@ sub modsubscription { $numberingmethod, $status, $biblionumber, $notes, $subscriptionid); $sth->finish; + $sth = $dbh->prepare("select * from subscription where subscriptionid = ? "); + $sth->execute($subscriptionid); + my $val = $sth->fetchrow_hashref; + + # calculate issue number + my $serialseq = Get_Seq($val); + $sth = $dbh->prepare("UPDATE serial SET serialseq = ? WHERE subscriptionid = ?"); + $sth->execute($serialseq,$subscriptionid); + + my $enddate = subscriptionexpirationdate($subscriptionid); + $sth = $dbh->prepare("update subscriptionhistory set enddate=?"); + $sth->execute(format_date_in_iso($enddate)); + } sub delsubscription { @@ -314,20 +520,20 @@ sub getsubscriptions { } else { if ($ISSN and $title) { - $sth = $dbh->prepare("SELECT subscription.subscriptionid,biblio.title,biblioitems.issn,subscription.notes,biblio.biblionumber from subscription,biblio,biblioitems where biblio.biblionumber = biblioitems.biblionumber and biblio.biblionumber=subscription.biblionumber and (biblio.title like ? or biblioitems.issn = ? order by title )"); + $sth = $dbh->prepare("SELECT subscription.subscriptionid,biblio.title,biblioitems.issn,subscription.notes,biblio.biblionumber from subscription,biblio,biblioitems where biblio.biblionumber = biblioitems.biblionumber and biblio.biblionumber=subscription.biblionumber and (biblio.title like ? or biblioitems.issn = ? group by subscriptionid order by title )"); $sth->execute("%$title%",$ISSN); } else { if ($ISSN) { - $sth = $dbh->prepare("SELECT subscription.subscriptionid,biblio.title,biblioitems.issn,subscription.notes,biblio.biblionumber from subscription,biblio,biblioitems where biblio.biblionumber = biblioitems.biblionumber and biblio.biblionumber=subscription.biblionumber and biblioitems.issn = ? order by title"); + $sth = $dbh->prepare("SELECT subscription.subscriptionid,biblio.title,biblioitems.issn,subscription.notes,biblio.biblionumber from subscription,biblio,biblioitems where biblio.biblionumber = biblioitems.biblionumber and biblio.biblionumber=subscription.biblionumber and biblioitems.issn = ? group by subscriptionid order by title"); $sth->execute($ISSN); } else { $sth = $dbh->prepare("SELECT subscription.subscriptionid,biblio.title,biblioitems.issn,subscription.notes,biblio.biblionumber from subscription,biblio,biblioitems where biblio.biblionumber = biblioitems.biblionumber and - biblio.biblionumber=subscription.biblionumber and biblio.title like ? order by title"); + biblio.biblionumber=subscription.biblionumber and biblio.title like ? group by subscriptionid order by title"); $sth->execute("%$title%"); } } @@ -357,9 +563,9 @@ sub modsubscriptionhistory { UPDATE subscriptionhistory SET histstartdate=?,enddate=?,recievedlist=?,missinglist=?,opacnote=?,librariannote=? WHERE subscriptionid=?"); - $recievedlist =~ s/^,//g; - $missinglist =~ s/^,//g; - $opacnote =~ s/^,//g; + $recievedlist =~ s/^\| ,//g; + $missinglist =~ s/^\| ,//g; + $opacnote =~ s/^\| ,//g; $sth->execute($histstartdate,$enddate,$recievedlist,$missinglist,$opacnote,$librariannote,$subscriptionid); } # get every serial not arrived for a given subscription @@ -497,11 +703,51 @@ sub newissue { =cut sub serialsitemize { my ($serialid, $info) =@_; + my $now = ParseDate("today"); + $now = UnixDate( $now, "%Y-%m-%d" ); my $dbh= C4::Context->dbh; my $sth=$dbh->prepare("SELECT * from serial WHERE serialid=?"); $sth->execute($serialid); my $data=$sth->fetchrow_hashref; + if ( C4::Context->preference("RoutingSerials") ) { + + # check for existing biblioitem relating to serial issue + my ( $count, @results ) = + getbiblioitembybiblionumber( $data->{'biblionumber'} ); + my $bibitemno = 0; + for ( my $i = 0 ; $i < $count ; $i++ ) { + if ( $results[$i]->{'volumeddesc'} eq $data->{'serialseq'} . ' (' + . $data->{'planneddate'} + . ')' ) + { + $bibitemno = $results[$i]->{'biblioitemnumber'}; + last; + } + } + if ( $bibitemno == 0 ) { + + # warn "need to add new biblioitem so copy last one and make minor changes"; + my $sth = + $dbh->prepare( + "SELECT * FROM biblioitems WHERE biblionumber = ? ORDER BY biblioitemnumber DESC" + ); + $sth->execute( $data->{'biblionumber'} ); + my $biblioitem = $sth->fetchrow_hashref; + $biblioitem->{'volumedate'} = + format_date_in_iso( $data->{planneddate} ); + $biblioitem->{'volumeddesc'} = + $data->{serialseq} . ' (' + . format_date( $data->{'planneddate'} ) . ')'; + $biblioitem->{'dewey'} = $info->{itemcallnumber}; + + if ( $info->{barcode} ) + { # only make biblioitem if we are going to make item also + $bibitemno = newbiblioitem($biblioitem); + } + } + } + # warn "biblionumber : ".$data->{biblionumber}; my $bibid=MARCfind_MARCbibid_from_oldbiblionumber($dbh,$data->{biblionumber}); my $fwk=MARCfind_frameworkcode($dbh,$bibid); @@ -594,6 +840,18 @@ sub serialsitemize { $marcrecord->insert_fields_ordered($newField); } } + if ( C4::Context->preference("RoutingSerials") ) { + my ( $tag, $subfield ) = + MARCfind_marc_from_kohafield( $dbh, "items.dateaccessioned", + $fwk ); + if ( $marcrecord->field($tag) ) { + $marcrecord->field($tag)->add_subfields( "$subfield" => $now ); + } + else { + my $newField = MARC::Field->new( "$tag", '', '', "$subfield" => $now ); + $marcrecord->insert_fields_ordered($newField); + } + } NEWnewitem($dbh,$marcrecord,$bibid); return 1; } @@ -608,6 +866,16 @@ sub delissue { $sth->execute($serialseq,$subscriptionid); } +sub in_array { # used in next sub down + my ($val,@elements) = @_; + foreach my $elem(@elements) { + if($val == $elem) { + return 1; + } + } + return 0; + } + sub Get_Next_Date(@) { my ($planneddate,$subscription) = @_; @@ -654,10 +922,24 @@ sub Get_Seq { my $x=$val->{'lastvalue1'}; $calculated =~ s/\{X\}/$x/g; my $y=$val->{'lastvalue2'}; - $calculated =~ s/\{Y\}/$y/g; - my $z=$val->{'lastvalue3'}; - $calculated =~ s/\{Z\}/$z/g; - return $calculated; + my $pattern = $val->{numberpattern}; + my @seasons = ('','Winter','Spring','Summer','Fall'); + my @southern_seasons = ('','Summer','Autumn','Winter','Spring'); + my @months = ('','January','February','March','April','May','June','July','August','September','October','November','December'); + if($pattern == 6){ + if($val->{hemisphere} == 2){ + $y = $southern_seasons[$y]; + } else { + $y = $seasons[$y]; + } + } + if($pattern ==8){ + $y = $months[$y]; + } + $calculated =~ s/\{Y\}/$y/g; + my $z=$val->{'lastvalue3'}; + $calculated =~ s/\{Z\}/$z/g; + return $calculated; } sub Get_Next_Seq { @@ -691,6 +973,85 @@ sub Get_Next_Seq { return ($calculated,$newlastvalue1,$newlastvalue2,$newlastvalue3,$newinnerloop1,$newinnerloop2,$newinnerloop3); } +sub New_Get_Next_Seq { + my ($val,$nextplanneddate) =@_; + my ($calculated,$newlastvalue1,$newlastvalue2,$newlastvalue3,$newinnerloop1,$newinnerloop2,$newinnerloop3); + my $pattern = $val->{numberpattern}; + my @seasons = ('nothing','Winter','Spring','Summer','Autumn'); + my @southern_seasons = ('','Summer','Autumn','Winter','Spring'); + my @months = ('','January','February','March','April','May','June','July','August','September','October','November','December'); + + my $new_month = UnixDate($nextplanneddate,"%m"); # for the month/year calculations + my $new_year = UnixDate($nextplanneddate,"%Y"); # for the month/year calculations + $calculated = $val->{numberingmethod}; + $newlastvalue1 = $val->{lastvalue1}; + $newlastvalue2 = $val->{lastvalue2}; + $newlastvalue3 = $val->{lastvalue3}; + if($newlastvalue3 > 0){ # if x y and z columns are used + $newlastvalue3 = $newlastvalue3+1; + if($newlastvalue3 > $val->{whenmorethan3}){ + $newlastvalue3 = $val->{setto3}; + $newlastvalue2++; + if($newlastvalue2 > $val->{whenmorethan2}){ + $newlastvalue1++; + $newlastvalue2 = $val->{setto2}; + } + } + $calculated =~ s/\{X\}/$newlastvalue1/g; + if($pattern == 6){ + if($val->{hemisphere} == 2){ + my $newlastvalue2seq = $southern_seasons[$newlastvalue2]; + $calculated =~ s/\{Y\}/$newlastvalue2seq/g; + } else { + my $newlastvalue2seq = $seasons[$newlastvalue2]; + $calculated =~ s/\{Y\}/$newlastvalue2seq/g; + } + } else { + $calculated =~ s/\{Y\}/$newlastvalue2/g; + } + $calculated =~ s/\{Z\}/$newlastvalue3/g; + } + + if($newlastvalue2 > 0 && $newlastvalue3 < 1){ # if x and y columns are used + $newlastvalue2 = $newlastvalue2+1; + # warn "y val: $newlastvalue2"; + # warn "x val: $newlastvalue1"; + if($newlastvalue2 > $val->{whenmorethan2}){ + $newlastvalue2 = $val->{setto2}; + $newlastvalue1++; + } + if($pattern == 8){ + $calculated =~ s/\{X\}/$new_year/g; + } else { + $calculated =~ s/\{X\}/$newlastvalue1/g; + } + if($pattern == 6){ + if($val->{hemisphere} == 2){ + my $newlastvalue2seq = $southern_seasons[$newlastvalue2]; + $calculated =~ s/\{Y\}/$newlastvalue2seq/g; + } else { + my $newlastvalue2seq = $seasons[$newlastvalue2]; + $calculated =~ s/\{Y\}/$newlastvalue2seq/g; + } + } elsif($pattern == 8){ + my $newlastvalue2seq = $months[$new_month]; + $calculated =~ s/\{Y\}/$newlastvalue2seq/g; + } else { + $calculated =~ s/\{Y\}/$newlastvalue2/g; + } + } + + if($newlastvalue1 > 0 && $newlastvalue2 < 1 && $newlastvalue3 < 1){ # if column x only + $newlastvalue1 = $newlastvalue1+1; + if($newlastvalue1 > $val->{whenmorethan1}){ + $newlastvalue1 = $val->{setto2}; + } + $calculated =~ s/\{X\}/$newlastvalue1/g; + } + warn $calculated.' '.$newlastvalue1.' '.$newlastvalue2.' '.$newlastvalue3; + return ($calculated,$newlastvalue1,$newlastvalue2,$newlastvalue3); +} + # the subscription has expired when the next issue to arrive is out of subscription limit. sub hassubscriptionexpired { my ($subscriptionid) = @_; @@ -719,6 +1080,50 @@ sub hassubscriptionexpired { } } +# is the subscription about to expire? - check if penultimate issue. +sub abouttoexpire { + my ($subscriptionid) = @_; + my $dbh = C4::Context->dbh; + my $subscription = getsubscription($subscriptionid); + # we don't do the same test if the subscription is based on X numbers or on X weeks/months + if ($subscription->{numberlength}) { + my $sth = $dbh->prepare("select count(*) from serial where subscriptionid=? and planneddate>=?"); + $sth->execute($subscriptionid,$subscription->{startdate}); + my $res = $sth->fetchrow; + # warn "length: ".$subscription->{numberlength}." vs count: ".$res; + if ($subscription->{numberlength}==$res) { + return 1; + } else { + return 0; + } + } else { + # a little bit more tricky if based on X weeks/months : search if the latest issue waited is not after subscription startdate + duration + my $sth = $dbh->prepare("select max(planneddate) from serial where subscriptionid=?"); + $sth->execute($subscriptionid); + my $res = ParseDate(format_date_in_iso($sth->fetchrow)); + my $endofsubscriptiondate; + $endofsubscriptiondate = DateCalc(format_date_in_iso($subscription->{startdate}),$subscription->{monthlength}." months") if ($subscription->{monthlength}); + $endofsubscriptiondate = DateCalc(format_date_in_iso($subscription->{startdate}),$subscription->{weeklength}." weeks") if ($subscription->{weeklength}); + warn "last: ".$endofsubscriptiondate." vs currentdate: ".$res; + my $per = $subscription->{'periodicity'}; + my $x = 0; + if ($per == 1) { $x = '1 day'; } + if ($per == 2) { $x = '1 week'; } + if ($per == 3) { $x = '2 weeks'; } + if ($per == 4) { $x = '3 weeks'; } + if ($per == 5) { $x = '1 month'; } + if ($per == 6) { $x = '2 months'; } + if ($per == 7 || $per == 8) { $x = '3 months'; } + if ($per == 9) { $x = '6 months'; } + if ($per == 10) { $x = '1 year'; } + if ($per == 11) { $x = '2 years'; } + my $datebeforeend = DateCalc($endofsubscriptiondate,"- ".$x); # if ($subscription->{weeklength}); + warn "DATE BEFORE END: $datebeforeend"; + return 1 if ($res >= $datebeforeend && $res < $endofsubscriptiondate); + return 0; + } +} + sub subscriptionexpirationdate { my ($subscriptionid) = @_; my $dbh = C4::Context->dbh; @@ -751,4 +1156,473 @@ sub subscriptionrenew { $sth=$dbh->prepare("update subscription set startdate=?,numberlength=?,weeklength=?,monthlength=? where subscriptionid=?"); $sth->execute(format_date_in_iso($startdate),$numberlength,$weeklength,$monthlength, $subscriptionid); } + +=head2 old_newsubscription + +=over 4 + +($subscriptionid) = &old_newsubscription($auser,$aqbooksellerid,$cost,$aqbudgetid,$biblionumber, + $startdate,$periodicity,$firstacquidate,$dow,$irregularity,$numberpattern,$numberlength,$weeklength,$monthlength, + $add1,$every1,$whenmorethan1,$setto1,$lastvalue1, + $add2,$every2,$whenmorethan2,$setto2,$lastvalue2, + $add3,$every3,$whenmorethan3,$setto3,$lastvalue3, + $numberingmethod, $status, $callnumber, $notes, $hemisphere) + +this function is similar to the NewSubscription subroutine but has a few different +values passed in +$firstacquidate - date of first serial issue to arrive +$irregularity - the issues not expected separated by a '|' +- eg. monthly issue but not expecting issue for june and july would have $irregularity of '6|7' +$numberpattern - the number for an array of labels to reconstruct the javascript correctly in the + subscription-add.tmpl file +$callnumber - display the callnumber of the serial +$hemisphere - either 2 = southern hemisphere or 1 = northern hemisphere - used for quarterly serials + +return : +the $subscriptionid number of the new subscription + +=back + +=cut + +sub old_newsubscription { + my ( + $auser, $aqbooksellerid, $cost, $aqbudgetid, + $biblionumber, $startdate, $periodicity, $firstacquidate, + $dow, $irregularity, $numberpattern, $numberlength, + $weeklength, $monthlength, $add1, $every1, + $whenmorethan1, $setto1, $lastvalue1, $add2, + $every2, $whenmorethan2, $setto2, $lastvalue2, + $add3, $every3, $whenmorethan3, $setto3, + $lastvalue3, $numberingmethod, $status, $callnumber, + $notes, $hemisphere + ) = @_; + my $dbh = C4::Context->dbh; + + #save subscription + my $sth = $dbh->prepare( + "INSERT INTO subscription (librarian,aqbooksellerid,cost,aqbudgetid,biblionumber, + startdate,periodicity,firstacquidate,dow,irregularity,numberpattern,numberlength,weeklength,monthlength, + add1,every1,whenmorethan1,setto1,lastvalue1, + add2,every2,whenmorethan2,setto2,lastvalue2, + add3,every3,whenmorethan3,setto3,lastvalue3, + numberingmethod, status, callnumber, notes, hemisphere) values + (?,?,?,?,?,?,?,?,?,?,?, + ?,?,?,?,?,?,?,?,?,?,?, + ?,?,?,?,?,?,?,?,?,?,?,?)" + ); + $sth->execute( + $auser, $aqbooksellerid, + $cost, $aqbudgetid, + $biblionumber, format_date_in_iso($startdate), + $periodicity, format_date_in_iso($firstacquidate), + $dow, $irregularity, + $numberpattern, $numberlength, + $weeklength, $monthlength, + $add1, $every1, + $whenmorethan1, $setto1, + $lastvalue1, $add2, + $every2, $whenmorethan2, + $setto2, $lastvalue2, + $add3, $every3, + $whenmorethan3, $setto3, + $lastvalue3, $numberingmethod, + $status, $callnumber, + $notes, $hemisphere + ); + + #then create the 1st waited number + my $subscriptionid = $dbh->{'mysql_insertid'}; + my $enddate = GetSubscriptionExpirationDate($subscriptionid); + + $sth = + $dbh->prepare( + "insert into subscriptionhistory (biblionumber, subscriptionid, histstartdate, enddate, missinglist, recievedlist, opacnote, librariannote) values (?,?,?,?,?,?,?,?)" + ); + $sth->execute( + $biblionumber, $subscriptionid, + format_date_in_iso($startdate), + format_date_in_iso($enddate), + "", "", "", $notes + ); + + # reread subscription to get a hash (for calculation of the 1st issue number) + $sth = + $dbh->prepare("select * from subscription where subscriptionid = ? "); + $sth->execute($subscriptionid); + my $val = $sth->fetchrow_hashref; + + # calculate issue number + my $serialseq = Get_Seq($val); + $sth = + $dbh->prepare( + "insert into serial (serialseq,subscriptionid,biblionumber,status, planneddate) values (?,?,?,?,?)" + ); + $sth->execute( $serialseq, $subscriptionid, $val->{'biblionumber'}, + 1, format_date_in_iso($startdate) ); +warn "sub ID: $subscriptionid"; + return $subscriptionid; +} + +=head2 old_modsubscription + +=over 4 + +($subscriptionid) = &old_modsubscription($auser,$aqbooksellerid,$cost,$aqbudgetid,$biblionumber, + $startdate,$periodicity,$firstacquidate,$dow,$irregularity,$numberpattern,$numberlength,$weeklength,$monthlength, + $add1,$every1,$whenmorethan1,$setto1,$lastvalue1, + $add2,$every2,$whenmorethan2,$setto2,$lastvalue2, + $add3,$every3,$whenmorethan3,$setto3,$lastvalue3, + $numberingmethod, $status, $callnumber, $notes, $hemisphere, $subscriptionid) + +this function is similar to the ModSubscription subroutine but has a few different +values passed in +$firstacquidate - date of first serial issue to arrive +$irregularity - the issues not expected separated by a '|' +- eg. monthly issue but not expecting issue for june and july would have $irregularity of '6|7' +$numberpattern - the number for an array of labels to reconstruct the javascript correctly in the + subscription-add.tmpl file +$callnumber - display the callnumber of the serial +$hemisphere - either 2 = southern hemisphere or 1 = northern hemisphere - used for quarterly serials + +=back + +=cut + +sub old_modsubscription { + my ( $auser, $aqbooksellerid, $cost, $aqbudgetid, + $startdate, $periodicity, $firstacquidate, $dow, + $irregularity, $numberpattern, $numberlength, $weeklength, + $monthlength, $add1, $every1, $whenmorethan1, + $setto1, $lastvalue1, $innerloop1, $add2, + $every2, $whenmorethan2, $setto2, $lastvalue2, + $innerloop2, $add3, $every3, $whenmorethan3, + $setto3, $lastvalue3, $innerloop3, $numberingmethod, + $status, $biblionumber, $callnumber, $notes, + $hemisphere, $subscriptionid + ) = @_; + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare("update subscription set librarian=?, aqbooksellerid=?,cost=?,aqbudgetid=?,startdate=?, + periodicity=?,firstacquidate=?,dow=?,irregularity=?,numberpattern=?,numberlength=?,weeklength=?,monthlength=?, + add1=?,every1=?,whenmorethan1=?,setto1=?,lastvalue1=?,innerloop1=?, + add2=?,every2=?,whenmorethan2=?,setto2=?,lastvalue2=?,innerloop2=?, + add3=?,every3=?,whenmorethan3=?,setto3=?,lastvalue3=?,innerloop3=?, + numberingmethod=?, status=?, biblionumber=?, callnumber=?, notes=?, hemisphere=? where subscriptionid = ?" + ); + $sth->execute( + $auser, $aqbooksellerid, $cost, $aqbudgetid, + $startdate, $periodicity, $firstacquidate, $dow, + $irregularity, $numberpattern, $numberlength, $weeklength, + $monthlength, $add1, $every1, $whenmorethan1, + $setto1, $lastvalue1, $innerloop1, $add2, + $every2, $whenmorethan2, $setto2, $lastvalue2, + $innerloop2, $add3, $every3, $whenmorethan3, + $setto3, $lastvalue3, $innerloop3, $numberingmethod, + $status, $biblionumber, $callnumber, $notes, + $hemisphere, $subscriptionid + ); + $sth->finish; + + $sth = + $dbh->prepare("select * from subscription where subscriptionid = ? "); + $sth->execute($subscriptionid); + my $val = $sth->fetchrow_hashref; + + # calculate issue number + my $serialseq = Get_Seq($val); + $sth = + $dbh->prepare("UPDATE serial SET serialseq = ? WHERE subscriptionid = ?"); + $sth->execute( $serialseq, $subscriptionid ); + + my $enddate = subscriptionexpirationdate($subscriptionid); + $sth = $dbh->prepare("update subscriptionhistory set enddate=?"); + $sth->execute( format_date_in_iso($enddate) ); +} + +=head2 old_getserials + +=over 4 + +($totalissues,@serials) = &old_getserials($subscriptionid) + +this function get a hashref of serials and the total count of them + +return : +$totalissues - number of serial lines +the serials into a table. Each line of this table containts a ref to a hash which it containts +serialid, serialseq, status,planneddate,notes,routingnotes from tables : serial where status is not 2, 4, or 5 + +=back + +=cut + +sub old_getserials { + my ($subscriptionid) = @_; + my $dbh = C4::Context->dbh; + + # status = 2 is "arrived" + my $sth = + $dbh->prepare( + "select serialid,serialseq, status, planneddate,notes,routingnotes from serial where subscriptionid = ? and status <>2 and status <>4 and status <>5" + ); + $sth->execute($subscriptionid); + my @serials; + my $num = 1; + while ( my $line = $sth->fetchrow_hashref ) { + $line->{ "status" . $line->{status} } = + 1; # fills a "statusX" value, used for template status select list + $line->{"planneddate"} = format_date( $line->{"planneddate"} ); + $line->{"num"} = $num; + $num++; + push @serials, $line; + } + $sth = $dbh->prepare("select count(*) from serial where subscriptionid=?"); + $sth->execute($subscriptionid); + my ($totalissues) = $sth->fetchrow; + return ( $totalissues, @serials ); + } + +=head2 GetNextDate + +=over 4 + +($resultdate) = &GetNextDate($planneddate,$subscription) + +this function is an extension of GetNextDate which allows for checking for irregularity + +it takes the planneddate and will return the next issue's date and will skip dates if there +exists an irregularity +- eg if periodicity is monthly and $planneddate is 2007-02-10 but if March and April is to be +skipped then the returned date will be 2007-05-10 + +return : +$resultdate - then next date in the sequence + +=back + +=cut + +sub GetNextDate(@) { + my ( $planneddate, $subscription ) = @_; + my @irreg = split( /\|/, $subscription->{irregularity} ); + + my ( $year, $month, $day ) = UnixDate( $planneddate, "%Y", "%m", "%d" ); + my $dayofweek = Date_DayOfWeek( $month, $day, $year ); + my $resultdate; + + # warn "DOW $dayofweek"; + if ( $subscription->{periodicity} == 1 ) { + for ( my $i = 0 ; $i < @irreg ; $i++ ) { + if ( $dayofweek == 7 ) { $dayofweek = 0; } + if ( in_array( ( $dayofweek + 1 ), @irreg ) ) { + $planneddate = DateCalc( $planneddate, "1 day" ); + $dayofweek++; + } + } + $resultdate = DateCalc( $planneddate, "1 day" ); + } + if ( $subscription->{periodicity} == 2 ) { + my $wkno = Date_WeekOfYear( $month, $day, $year, 1 ); + for ( my $i = 0 ; $i < @irreg ; $i++ ) { + if ( $wkno > 52 ) { $wkno = 0; } # need to rollover at January + if ( $irreg[$i] == ( $wkno + 1 ) ) { + $planneddate = DateCalc( $planneddate, "1 week" ); + $wkno++; + } + } + $resultdate = DateCalc( $planneddate, "1 week" ); + } + if ( $subscription->{periodicity} == 3 ) { + my $wkno = Date_WeekOfYear( $month, $day, $year, 1 ); + for ( my $i = 0 ; $i < @irreg ; $i++ ) { + if ( $wkno > 52 ) { $wkno = 0; } # need to rollover at January + if ( $irreg[$i] == ( $wkno + 1 ) ) { + $planneddate = DateCalc( $planneddate, "2 weeks" ); + $wkno++; + } + } + $resultdate = DateCalc( $planneddate, "2 weeks" ); + } + if ( $subscription->{periodicity} == 4 ) { + my $wkno = Date_WeekOfYear( $month, $day, $year, 1 ); + for ( my $i = 0 ; $i < @irreg ; $i++ ) { + if ( $wkno > 52 ) { $wkno = 0; } # need to rollover at January + if ( $irreg[$i] == ( $wkno + 1 ) ) { + $planneddate = DateCalc( $planneddate, "3 weeks" ); + $wkno++; + } + } + $resultdate = DateCalc( $planneddate, "3 weeks" ); + } + if ( $subscription->{periodicity} == 5 ) { + for ( my $i = 0 ; $i < @irreg ; $i++ ) { + + # warn $irreg[$i]; + # warn $month; + if ( $month == 12 ) { + $month = 0; + } # need to rollover to check January + if ( $irreg[$i] == ( $month + 1 ) ) + { # check next one to see if is to be skipped + $planneddate = DateCalc( $planneddate, "1 month" ); + $month++; # to check if following ones are to be skipped too + } + } + $resultdate = DateCalc( $planneddate, "1 month" ); + + # warn "Planneddate2: $planneddate"; + } + if ( $subscription->{periodicity} == 6 ) { + for ( my $i = 0 ; $i < @irreg ; $i++ ) { + if ( $month == 12 ) { + $month = 0; + } # need to rollover to check January + if ( $irreg[$i] == ( $month + 1 ) ) + { # check next one to see if is to be skipped + $planneddate = DateCalc( $planneddate, "2 months" ); + $month++; # to check if following ones are to be skipped too + } + } + $resultdate = DateCalc( $planneddate, "2 months" ); + } + if ( $subscription->{periodicity} == 7 ) { + for ( my $i = 0 ; $i < @irreg ; $i++ ) { + if ( $month == 12 ) { + $month = 0; + } # need to rollover to check January + if ( $irreg[$i] == ( $month + 1 ) ) + { # check next one to see if is to be skipped + $planneddate = DateCalc( $planneddate, "3 months" ); + $month++; # to check if following ones are to be skipped too + } + } + $resultdate = DateCalc( $planneddate, "3 months" ); + } + if ( $subscription->{periodicity} == 8 ) { + for ( my $i = 0 ; $i < @irreg ; $i++ ) { + if ( $month == 12 ) { + $month = 0; + } # need to rollover to check January + if ( $irreg[$i] == ( $month + 1 ) ) + { # check next one to see if is to be skipped + $planneddate = DateCalc( $planneddate, "3 months" ); + $month++; # to check if following ones are to be skipped too + } + } + $resultdate = DateCalc( $planneddate, "3 months" ); + } + if ( $subscription->{periodicity} == 9 ) { + for ( my $i = 0 ; $i < @irreg ; $i++ ) { + if ( $month == 12 ) { + $month = 0; + } # need to rollover to check January + if ( $irreg[$i] == ( $month + 1 ) ) + { # check next one to see if is to be skipped + $planneddate = DateCalc( $planneddate, "6 months" ); + $month++; # to check if following ones are to be skipped too + } + } + $resultdate = DateCalc( $planneddate, "6 months" ); + } + if ( $subscription->{periodicity} == 10 ) { + $resultdate = DateCalc( $planneddate, "1 year" ); + } + if ( $subscription->{periodicity} == 11 ) { + $resultdate = DateCalc( $planneddate, "2 years" ); + } + + # warn "date: ".$resultdate; + return format_date_in_iso($resultdate); + } + +sub old_serialchangestatus { + my ($serialid,$serialseq,$planneddate,$status,$notes)=@_; + # warn "($serialid,$serialseq,$planneddate,$status)"; + # 1st, get previous status : if we change from "waited" to something else, then we will have to create a new "waited" entry + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare("select subscriptionid,status from serial where serialid=?"); + $sth->execute($serialid); + my ($subscriptionid,$oldstatus) = $sth->fetchrow; + # change status & update subscriptionhistory + if ($status eq 6){ + delissue($serialseq, $subscriptionid) + }else{ + $sth = $dbh->prepare("update serial set serialseq=?,planneddate=?,status=?,notes=? where serialid = ?"); + $sth->execute($serialseq,$planneddate,$status,$notes,$serialid); + $sth = $dbh->prepare("select missinglist,recievedlist from subscriptionhistory where subscriptionid=?"); + $sth->execute($subscriptionid); + my ($missinglist,$recievedlist) = $sth->fetchrow; + if ($status eq 2) { + $recievedlist .= "| $serialseq"; + $recievedlist =~ s/^\| //g; + } + $missinglist .= "| $serialseq" if ($status eq 4) ; + $missinglist .= "| not issued $serialseq" if ($status eq 5); + $missinglist =~ s/^\| //g; + $sth=$dbh->prepare("update subscriptionhistory set recievedlist=?, missinglist=? where subscriptionid=?"); + $sth->execute($recievedlist,$missinglist,$subscriptionid); + } + # create new waited entry if needed (ie : was a "waited" and has changed) + if ($oldstatus eq 1 && $status ne 1) { + $sth = $dbh->prepare("select * from subscription where subscriptionid = ? "); + $sth->execute($subscriptionid); + my $val = $sth->fetchrow_hashref; + # next date (calculated from actual date & frequency parameters) + my $nextplanneddate = Get_Next_Date($planneddate,$val); + # next issue number + # my ($newserialseq,$newlastvalue1,$newlastvalue2,$newlastvalue3,$newinnerloop1,$newinnerloop2,$newinnerloop3) = Get_Next_Seq($val); + my ($newserialseq,$newlastvalue1,$newlastvalue2,$newlastvalue3) = New_Get_Next_Seq($val,$nextplanneddate); + newissue($newserialseq, $subscriptionid, $val->{'biblionumber'}, 1, $nextplanneddate); + # $sth = $dbh->prepare("update subscription set lastvalue1=?, lastvalue2=?,lastvalue3=?, + # innerloop1=?,innerloop2=?,innerloop3=? + # where subscriptionid = ?"); + # $sth->execute($newlastvalue1,$newlastvalue2,$newlastvalue3,$newinnerloop1,$newinnerloop2,$newinnerloop3,$subscriptionid); + $sth = $dbh->prepare("update subscription set lastvalue1=?, lastvalue2=?,lastvalue3=? + where subscriptionid = ?"); + $sth->execute($newlastvalue1,$newlastvalue2,$newlastvalue3,$subscriptionid); + } +} + +=head2 GetSubscriptionExpirationDate + +=over 4 + +$sensddate = GetSubscriptionExpirationDate($subscriptionid) + +this function return the expiration date for a subscription given on input args. + +return +the enddate + +=back + +=cut + +sub GetSubscriptionExpirationDate { + my ($subscriptionid) = @_; + my $dbh = C4::Context->dbh; + my $subscription = getsubscription($subscriptionid); + my $enddate = $subscription->{startdate}; + + # we don't do the same test if the subscription is based on X numbers or on X weeks/months + if ( $subscription->{numberlength} ) { + + #calculate the date of the last issue. + for ( my $i = 1 ; $i <= $subscription->{numberlength} ; $i++ ) { + $enddate = GetNextDate( $enddate, $subscription ); + } + } + else { + $enddate = DateCalc( + format_date_in_iso( $subscription->{startdate} ), + $subscription->{monthlength} . " months" + ) if ( $subscription->{monthlength} ); + $enddate = DateCalc( + format_date_in_iso( $subscription->{startdate} ), + $subscription->{weeklength} . " weeks" + ) if ( $subscription->{weeklength} ); + } + return $enddate; + } + END { } # module clean-up code here (global destructor) diff --git a/bull-home.pl b/bull-home.pl index d8d0d3bd9d..83bee6a607 100755 --- a/bull-home.pl +++ b/bull-home.pl @@ -12,6 +12,8 @@ use HTML::Template; my $query = new CGI; my $title = $query->param('title'); my $ISSN = $query->param('ISSN'); +my $routing = $query->param('routing'); +my $searched = $query->param('searched'); my $biblionumber = $query->param('biblionumber'); my @subscriptions = getsubscriptions($title,$ISSN,$biblionumber); my ($template, $loggedinuser, $cookie) @@ -23,10 +25,21 @@ my ($template, $loggedinuser, $cookie) debug => 1, }); +# to toggle between create or edit routing list options +if($routing){ + for(my $i=0;$i<@subscriptions;$i++){ + my $checkrouting = check_routing($subscriptions[$i]->{'subscriptionid'}); + $subscriptions[$i]->{'routingedit'} = $checkrouting; + # warn "check $checkrouting"; + } +} + $template->param( - subscriptions => \@subscriptions, - title => $title, - ISSN => $ISSN, + subscriptions => \@subscriptions, + title => $title, + ISSN => $ISSN, + done_searched => $searched, + routing => $routing, intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"), intranetstylesheet => C4::Context->preference("intranetstylesheet"), IntranetNav => C4::Context->preference("IntranetNav"), diff --git a/bull/lateissues.pl b/bull/lateissues.pl index 845e7352b2..5a11563dfd 100755 --- a/bull/lateissues.pl +++ b/bull/lateissues.pl @@ -18,23 +18,28 @@ my $query = new CGI; my $supplierid = $query->param('supplierid'); my %supplierlist = getSupplierListWithLateIssues; my @select_supplier; -push @select_supplier,""; + +my ($nothing,@supplierinfo)=bookseller($supplierid) if $supplierid; + foreach my $supplierid (keys %supplierlist){ + my ($count, @dummy) = GetLateIssues($supplierid); + my ($count2, @dummy2) = GetMissingIssues($supplierid); + my $counting = $count+$count2; + $supplierlist{$supplierid} = $supplierlist{$supplierid}." ($counting)"; push @select_supplier, $supplierid } + +my ($count, @lateissues) = GetLateIssues($supplierid); +my ($count2, @missingissues) = GetMissingIssues($supplierid); + + my $CGIsupplier=CGI::scrolling_list( -name => 'supplierid', -values => \@select_supplier, -default => $supplierid, -labels => \%supplierlist, -size => 1, - -tabindex=>'', -multiple => 0 ); -my @lateissues; -@lateissues = GetLateIssues($supplierid) if $supplierid; -my @supplierinfo; -my $nothing; -($nothing,@supplierinfo)=bookseller($supplierid) if $supplierid; my ($template, $loggedinuser, $cookie) = get_template_and_user({template_name => "bull/lateissues.tmpl", @@ -48,6 +53,8 @@ my ($template, $loggedinuser, $cookie) $template->param( CGIsupplier => $CGIsupplier, lateissues => \@lateissues, + missingissues => \@missingissues, + supplierid => $supplierid, phone => $supplierinfo[0]->{phone}, booksellerfax => $supplierinfo[0]->{booksellerfax}, contemail => $supplierinfo[0]->{contemail}, diff --git a/bull/statecollection.pl b/bull/statecollection.pl index 14162cdd6e..68b12d5442 100755 --- a/bull/statecollection.pl +++ b/bull/statecollection.pl @@ -35,12 +35,26 @@ 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 $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); } + # 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=?"); @@ -50,7 +64,11 @@ if ($op eq 'serialchangestatus') { my ($oldstatus) = $sth->fetchrow; if ($serialids[$i]) { my $planneddate = ($planneddates[$i]?format_date_in_iso($planneddates[$i]):format_date_in_iso("today")); + if(C4::Context->preference("RoutingSerials")){ + old_serialchangestatus($serialids[$i],$serialseqs[$i],format_date_in_iso($planneddates[$i]),$status[$i],$notes[$i]) unless ($hassubscriptionexpired && $oldstatus == 1); + } else { serialchangestatus($serialids[$i],$serialseqs[$i],format_date_in_iso($publisheddates[$i]),$planneddate,$status[$i],$notes[$i]) unless ($hassubscriptionexpired && $oldstatus == 1); + } if (($status[$i]==2) && C4::Context->preference("serialsadditems")){ my %info; $info{branch}=$homebranches[$i]; @@ -58,8 +76,15 @@ if ($op eq 'serialchangestatus') { $info{itemcallnumber}=$itemcallnumbers[$i]; $info{location}=$locations[$i]; $info{status}=$itemstatus[$i]; - $info{notes}=$serialseqs[$i]; + $info{notes}=$serialseqs[$i]." (".$planneddates[$i].")"; my ($status, @errors)= serialsitemize($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 ($status ==1){ + removeMissingIssue($serialseqs[$i],$subscriptionid); + } } } else { # add a special issue @@ -77,14 +102,23 @@ if ($op eq 'serialchangestatus') { $info{itemcallnumber}=$itemcallnumbers[$i]; $info{location}=$locations[$i]; $info{status}=$itemstatus[$i]; - $info{notes}=$serialseqs[$i]; - my ($status, @errors)= serialsitemize($newserialid,\%info); + $info{notes}=$serialseqs[$i]." (".$planneddates[$i].")"; + my ($status2, @errors)= serialsitemize($newserialid,\%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 => "bull/statecollection.tmpl", query => $query, @@ -95,8 +129,25 @@ my ($template, $loggedinuser, $cookie) }); my $subs = &getsubscription($subscriptionid); -my ($totalissues,@serialslist) = getserials($subscriptionid); +my ($totalissues,@serialslist); +if(C4::Context->preference("RoutingSerials")){ + ($totalissues,@serialslist) = old_getserials($subscriptionid); +} else { + ($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); +} + +my $sth=$dbh->prepare("select * from subscriptionhistory where subscriptionid = ?"); +$sth->execute($subscriptionid); +my $solhistory = $sth->fetchrow_hashref; + + if (C4::Context->preference("serialsadditems")){ my $bibid=MARCfind_MARCbibid_from_oldbiblionumber($dbh,$subscription->{biblionumber}); my $fwk=MARCfind_frameworkcode($dbh,$bibid); @@ -104,18 +155,25 @@ if (C4::Context->preference("serialsadditems")){ 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}, ); + $itemstatusloopcount++; push @itemstatusloop, \%row; } @@ -127,6 +185,8 @@ if (C4::Context->preference("serialsadditems")){ ); push @itemlocationloop, \%row; } + my $choice = 0; + if($itemstatusloopcount == 1){ $choice = 1;} foreach my $data (@serialslist){ if (scalar(@itemstatusloop)){$data->{"itemstatusloop"}=\@itemstatusloop;} else { $data->{"itemstatusloop"}=[];} @@ -134,6 +194,7 @@ if (C4::Context->preference("serialsadditems")){ else {$data->{"itemlocationloop"}=[];} $data->{"branchloop"}=\@branchloop ; } + $template->param(choice => $choice); $template->param(serialadditems =>C4::Context->preference("serialsadditems"), branchloop => \@branchloop, ) ; @@ -142,14 +203,12 @@ if (C4::Context->preference("serialsadditems")){ }else{ $template->param(branchloop=>[],itemstatusloop=>[],itemlocationloop=>[]) ; } - -my $sth=$dbh->prepare("select * from subscriptionhistory where subscriptionid = ?"); -$sth->execute($subscriptionid); -my $solhistory = $sth->fetchrow_hashref; - + $template->param( + user => $auser, serialslist => \@serialslist, + count => $count, biblionumber => $subscription->{biblionumber}, histstartdate => format_date($solhistory->{'histstartdate'}), enddate => format_date($solhistory->{'enddate'}), @@ -161,8 +220,16 @@ $template->param( 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; + + diff --git a/bull/subscription-add.pl b/bull/subscription-add.pl index 92b8e55237..fc351a281d 100755 --- a/bull/subscription-add.pl +++ b/bull/subscription-add.pl @@ -7,23 +7,23 @@ use C4::Koha; use C4::Auth; use C4::Date; use C4::Output; -use C4::Bull; use C4::Acquisition; use C4::Interface::CGI::Output; use C4::Context; use HTML::Template; use C4::Bull; +use Date::Manip; my $query = new CGI; my $op = $query->param('op'); my $dbh = C4::Context->dbh; my ($subscriptionid,$auser,$librarian,$cost,$aqbooksellerid, $aqbooksellername,$aqbudgetid, $bookfundid, $startdate, $periodicity, - $dow, $numberlength, $weeklength, $monthlength, + $firstacquidate, $dow, $irregularity, $numberpattern, $numberlength, $weeklength, $monthlength, $sublength, $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,$innerloop1, $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2, $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3, $numberingmethod, $status, $biblionumber, - $bibliotitle, $notes); + $bibliotitle, $callnumber, $notes, $hemisphere); my @budgets; my ($template, $loggedinuser, $cookie) @@ -36,6 +36,29 @@ my ($template, $loggedinuser, $cookie) }); +my $weekarrayjs=''; +my $count = 0; +my ($year, $month, $day) = UnixDate("today", "%Y", "%m", "%d"); +my $firstday = Date_DayOfYear($month,$day,$year); +my $wkno = Date_WeekOfYear($month,$day,$year,1); # week starting monday +my $weekno = $wkno; +for(my $i=$firstday;$i<($firstday+365);$i=$i+7){ + $count = $i; + if($wkno > 52){$year++; $wkno=1;} + if($count>365){$count=$i-365;} + my ($y,$m,$d) = Date_NthDayOfYear($year,$count); + my $output = "$y-$m-$d"; + $weekarrayjs .= "'Wk $wkno: ".format_date($output)."',"; + $wkno++; +} +chop($weekarrayjs); +# warn $weekarrayjs; + +my $sub_on; +my @subscription_types = ( + 'issues', 'weeks', 'months' + ); +my @sub_type_data; if ($op eq 'mod') { my $subscriptionid = $query->param('subscriptionid'); my $subs = &getsubscription($subscriptionid); @@ -47,11 +70,38 @@ if ($op eq 'mod') { $bookfundid = $subs->{'bookfundid'}; $aqbudgetid = $subs->{'aqbudgetid'}; $startdate = $subs->{'startdate'}; + $firstacquidate = $subs->{'firstacquidate'}; $periodicity = $subs->{'periodicity'}; $dow = $subs->{'dow'}; + $irregularity = $subs->{'irregularity'}; + $numberpattern = $subs->{'numberpattern'}; $numberlength = $subs->{'numberlength'}; $weeklength = $subs->{'weeklength'}; $monthlength = $subs->{'monthlength'}; + + if($monthlength > 0){ + $sublength = $monthlength; + $sub_on = $subscription_types[2]; + } elsif ($weeklength>0){ + $sublength = $weeklength; + $sub_on = $subscription_types[1]; + } else { + $sublength = $numberlength; + $sub_on = $subscription_types[0]; + } + + + while (@subscription_types) { + my $sub_type = shift @subscription_types; + my %row = ( 'name' => $sub_type ); + if ( $sub_on eq $sub_type ) { + $row{'selected'} = ' selected'; + } else { + $row{'selected'} = ''; + } + push( @sub_type_data, \%row ); + } + $add1 = $subs->{'add1'}; $every1 = $subs->{'every1'}; $whenmorethan1 = $subs->{'whenmorethan1'}; @@ -73,8 +123,10 @@ if ($op eq 'mod') { $numberingmethod = $subs->{'numberingmethod'}; $status = $subs->{status}; $biblionumber = $subs->{'biblionumber'}; - $bibliotitle = $subs->{'bibliotitle'}, + $bibliotitle = $subs->{'bibliotitle'}; + $callnumber = $subs->{'callnumber'}; $notes = $subs->{'notes'}; + $hemisphere = $subs->{'hemisphere'}; $template->param( $op => 1, user => $auser, @@ -85,11 +137,13 @@ if ($op eq 'mod') { aqbudgetid => $aqbudgetid, bookfundid => $bookfundid, startdate => format_date($startdate), + firstacquidate => format_date($firstacquidate), periodicity => $periodicity, dow => $dow, - numberlength => $numberlength, - weeklength => $weeklength, - monthlength => $monthlength, + irregularity => $irregularity, + numberpattern => $numberpattern, + sublength => $sublength, + subtype => \@sub_type_data, add1 => $add1, every1 => $every1, whenmorethan1 => $whenmorethan1, @@ -112,12 +166,18 @@ if ($op eq 'mod') { status => $status, biblionumber => $biblionumber, bibliotitle => $bibliotitle, + callnumber => $callnumber, notes => $notes, subscriptionid => $subscriptionid, + weekarrayjs => $weekarrayjs, + weekno => $weekno, + hemisphere => $hemisphere, ); + $template->param( "periodicity$periodicity" => 1, "dow$dow" => 1, + "numberpattern$numberpattern" => 1, ); } (my $temp,@budgets) = bookfunds(); @@ -134,46 +194,92 @@ $template->param(budgets => \@budgets, ); if ($op eq 'addsubscription') { + my @irregular = $query->param('irregular'); + my $irregular_count = @irregular; + for(my $i =0;$i<$irregular_count;$i++){ + $irregularity .=$irregular[$i]."|"; + } + $irregularity =~ s/\|$//; + my $auser = $query->param('user'); my $aqbooksellerid = $query->param('aqbooksellerid'); my $cost = $query->param('cost'); my $aqbudgetid = $query->param('aqbudgetid'); my $startdate = $query->param('startdate'); + my $firstacquidate = $query->param('firstacquidate'); my $periodicity = $query->param('periodicity'); my $dow = $query->param('dow'); - my $numberlength = $query->param('numberlength'); - my $weeklength = $query->param('weeklength'); - my $monthlength = $query->param('monthlength'); + # my $irregularity = $query->param('irregularity'); + my $numberlength = 0; + my $weeklength = 0; + my $monthlength = 0; + my $numberpattern = $query->param('numbering_pattern'); + my $sublength = $query->param('sublength'); + my $subtype = $query->param('subtype'); + if ($subtype eq 'months'){ + $monthlength = $sublength; + } elsif ($subtype eq 'weeks'){ + $weeklength = $sublength; + } else { + $numberlength = $sublength; + } + my $add1 = $query->param('add1'); my $every1 = $query->param('every1'); my $whenmorethan1 = $query->param('whenmorethan1'); my $setto1 = $query->param('setto1'); my $lastvalue1 = $query->param('lastvalue1'); - my $innerloop1 = $query->param('innerloop1'); my $add2 = $query->param('add2'); my $every2 = $query->param('every2'); my $whenmorethan2 = $query->param('whenmorethan2'); my $setto2 = $query->param('setto2'); my $lastvalue2 = $query->param('lastvalue2'); - my $innerloop2 = $query->param('innerloop2'); my $add3 = $query->param('add3'); my $every3 = $query->param('every3'); my $whenmorethan3 = $query->param('whenmorethan3'); my $setto3 = $query->param('setto3'); my $lastvalue3 = $query->param('lastvalue3'); - my $innerloop3 = $query->param('innerloop3'); my $numberingmethod = $query->param('numberingmethod'); my $status = 1; my $biblionumber = $query->param('biblionumber'); + my $callnumber = $query->param('callnumber'); my $notes = $query->param('notes'); - my $subscriptionid = newsubscription($auser,$aqbooksellerid,$cost,$aqbudgetid,$biblionumber, - $startdate,$periodicity,$dow,$numberlength,$weeklength,$monthlength, - $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,$innerloop1, - $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2, - $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3, - $numberingmethod, $status, $notes + my $hemisphere = $query->param('hemisphere') || 1; + my $subscriptionid; +if(C4::Context->preference("RoutingSerials")){ + $subscriptionid = old_newsubscription($auser,$aqbooksellerid,$cost,$aqbudgetid,$biblionumber, + $startdate,$periodicity,$firstacquidate,$dow,$irregularity,$numberpattern,$numberlength,$weeklength,$monthlength, + $add1,$every1,$whenmorethan1,$setto1,$lastvalue1, + $add2,$every2,$whenmorethan2,$setto2,$lastvalue2, + $add3,$every3,$whenmorethan3,$setto3,$lastvalue3, + $numberingmethod, $status, $callnumber, $notes, $hemisphere ); + } else { + $subscriptionid = newsubscription($auser,$aqbooksellerid,$cost,$aqbudgetid,$biblionumber, + $startdate,$periodicity,$dow,$numberlength,$weeklength,$monthlength, + $add1,$every1,$whenmorethan1,$setto1,$lastvalue1, + $add2,$every2,$whenmorethan2,$setto2,$lastvalue2, + $add3,$every3,$whenmorethan3,$setto3,$lastvalue3, + $numberingmethod, $status, $notes + ); + + } print $query->redirect("/cgi-bin/koha/bull/subscription-detail.pl?subscriptionid=$subscriptionid"); } else { + + while (@subscription_types) { + my $sub_type = shift @subscription_types; + my %row = ( 'name' => $sub_type ); + if ( $sub_on eq $sub_type ) { + $row{'selected'} = ' selected'; + } else { + $row{'selected'} = ''; + } + push( @sub_type_data, \%row ); + } + $template->param(subtype => \@sub_type_data, + weekarrayjs => $weekarrayjs, + weekno => $weekno, + ); output_html_with_http_headers $query, $cookie, $template->output; } diff --git a/bull/subscription-detail.pl b/bull/subscription-detail.pl index 7d07e85daf..d0d48fe942 100755 --- a/bull/subscription-detail.pl +++ b/bull/subscription-detail.pl @@ -10,6 +10,7 @@ use C4::Output; use C4::Interface::CGI::Output; use C4::Context; use HTML::Template; +use Date::Manip; my $query = new CGI; my $op = $query->param('op'); @@ -18,15 +19,22 @@ my $sth; # my $id; my ($template, $loggedinuser, $cookie, $subs); my ($subscriptionid,$auser,$librarian,$cost,$aqbooksellerid, $aqbooksellername,$aqbudgetid, $bookfundid, $startdate, $periodicity, - $dow, $numberlength, $weeklength, $monthlength, + $firstacquidate, $dow, $irregularity, $sublength, $subtype, $numberpattern, $numberlength, $weeklength, $monthlength, $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,$innerloop1, $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2, $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3, - $numberingmethod, $status, $biblionumber, $bibliotitle, $notes); + $numberingmethod, $status, $biblionumber, $bibliotitle, $callnumber, $notes, $hemisphere); $subscriptionid = $query->param('subscriptionid'); if ($op eq 'modsubscription') { + my @irregular = $query->param('irregular'); + my $irregular_count = @irregular; + for(my $i =0;$i<$irregular_count;$i++){ + $irregularity .=$irregular[$i]."|"; + } + $irregularity =~ s/\|$//; + $auser = $query->param('user'); $librarian => $query->param('librarian'), $cost = $query->param('cost'); @@ -35,10 +43,24 @@ if ($op eq 'modsubscription') { $aqbudgetid = $query->param('aqbudgetid'); $startdate = format_date_in_iso($query->param('startdate')); $periodicity = $query->param('periodicity'); + $firstacquidate = format_date_in_iso($query->param('firstacquidate')); $dow = $query->param('dow'); + $numberpattern = $query->param('numbering_pattern'); + if(C4::Context->preference("RoutingSerials")){ + $sublength = $query->param('sublength'); + $subtype = $query->param('subtype'); + if($subtype eq 'months'){ + $monthlength = $sublength; + } elsif ($subtype eq 'weeks'){ + $weeklength = $sublength; + } else { + $numberlength = $sublength; + } + } else { $numberlength = $query->param('numberlength'); $weeklength = $query->param('weeklength'); $monthlength = $query->param('monthlength'); + } $add1 = $query->param('add1'); $every1 = $query->param('every1'); $whenmorethan1 = $query->param('whenmorethan1'); @@ -59,14 +81,24 @@ if ($op eq 'modsubscription') { $innerloop3 = $query->param('innerloop3'); $numberingmethod = $query->param('numberingmethod'); $status = 1; + $callnumber = $query->param('callnumber'); + $hemisphere = $query->param('hemisphere'); $notes = $query->param('notes'); - + if(C4::Context->preference("RoutingSerials")){ + &old_modsubscription($auser,$aqbooksellerid,$cost,$aqbudgetid,$startdate, + $periodicity,$firstacquidate,$dow,$irregularity,$numberpattern,$numberlength,$weeklength,$monthlength, + $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,$innerloop1, + $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2, + $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3, + $numberingmethod, $status, $biblionumber, $callnumber, $notes, $hemisphere, $subscriptionid); + } else { &modsubscription($auser,$aqbooksellerid,$cost,$aqbudgetid,$startdate, $periodicity,$dow,$numberlength,$weeklength,$monthlength, $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,$innerloop1, $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2, $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3, $numberingmethod, $status, $biblionumber, $notes, $subscriptionid); + } } if ($op eq 'del') { @@ -92,6 +124,23 @@ $totalissues-- if $totalissues; # the -1 is to have 0 if this is a new subscript my ($user, $cookie, $sessionID, $flags) = checkauth($query, 0, {catalogue => 1}, "intranet"); +my $weekarrayjs=''; +my $count = 0; +my ($year, $month, $day) = UnixDate("today", "%Y", "%m", "%d"); +my $firstday = Date_DayOfYear($month,$day,$year); +my $wkno = Date_WeekOfYear($month,$day,$year,1); # week starting monday +my $weekno = $wkno; +for(my $i=$firstday;$i<($firstday+365);$i=$i+7){ + $count = $i; + if($wkno > 52){$year++; $wkno=1;} + if($count>365){$count=$i-365;} + my ($y,$m,$d) = Date_NthDayOfYear($year,$count); + my $output = "$y-$m-$d"; + $weekarrayjs .= "'Wk $wkno: ".format_date($output)."',"; + $wkno++; + } +chop($weekarrayjs); + $template->param( user => $subs->{auser}, librarian => $subs->{librarian}, @@ -102,10 +151,13 @@ $template->param( bookfundid => $subs->{bookfundid}, startdate => format_date($subs->{startdate}), periodicity => $subs->{periodicity}, + firstacquidate => format_date($subs->{firstacquidate}), dow => $subs->{dow}, - numberlength => $subs->{numberlength}, - weeklength => $subs->{weeklength}, - monthlength => $subs->{monthlength}, + irregularity => $subs->{irregularity}, + numberlength => $subs->{numberlength}, + weeklength => $subs->{weeklength}, + monthlength => $subs->{monthlength}, + numberpattern => $subs->{numberpattern}, add1 => $subs->{add1}, every1 => $subs->{every1}, whenmorethan1 => $subs->{whenmorethan1}, @@ -132,8 +184,12 @@ $template->param( subscriptionid => $subs->{subscriptionid}, serialslist => \@serialslist, totalissues => $totalissues, + weekarrayjs => $weekarrayjs, + callnumber => $subs->{callnumber}, + hemisphere => $hemisphere, ); $template->param( + "numberpattern$subs->{numberpattern}" => 1, "periodicity$subs->{periodicity}" => 1, "arrival$subs->{dow}" => 1, intranetstylesheet => C4::Context->preference("intranetstylesheet"), diff --git a/bull/subscription-renew.pl b/bull/subscription-renew.pl index 513c5a2bc1..5f2ec79b37 100755 --- a/bull/subscription-renew.pl +++ b/bull/subscription-renew.pl @@ -37,7 +37,7 @@ my $dbh = C4::Context->dbh; my $op = $query->param('op'); my $subscriptionid = $query->param('subscriptionid'); - +my $done = 0; # for after form has been submitted my ($template, $loggedinuser, $cookie) = get_template_and_user({template_name => "bull/subscription-renew.tmpl", query => $query, @@ -48,6 +48,7 @@ my ($template, $loggedinuser, $cookie) }); if ($op eq "renew") { subscriptionrenew($subscriptionid,$loggedinuser,$query->param('startdate'),$query->param('numberlength'),$query->param('weeklength'),$query->param('monthlength'),$query->param('note')); + $done = 1; } my $subscription= getsubscription($subscriptionid); @@ -59,6 +60,7 @@ $template->param(startdate => format_date(subscriptionexpirationdate($subscripti subscriptionid => $subscriptionid, bibliotitle => $subscription->{bibliotitle}, $op => 1, + done => $done, intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"), intranetstylesheet => C4::Context->preference("intranetstylesheet"), IntranetNav => C4::Context->preference("IntranetNav"), diff --git a/koha-tmpl/intranet-tmpl/npl/en/bull/bull-home.tmpl b/koha-tmpl/intranet-tmpl/npl/en/bull/bull-home.tmpl index b60fe329e0..e02b33b9b2 100644 --- a/koha-tmpl/intranet-tmpl/npl/en/bull/bull-home.tmpl +++ b/koha-tmpl/intranet-tmpl/npl/en/bull/bull-home.tmpl @@ -1,68 +1,86 @@ -Koha -- Serials Subscriptions +Koha -- Subscriptions +