X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=C4%2FSerials.pm;h=7e6147bbe2433d5cc9b507f97ee27102ec79ea8f;hb=0c66ac6702e2a8841ffa002ceabef2bca07aaa87;hp=4170865198e48025c4429974c22f30607cc798be;hpb=5431e7eb3cfb5d31191949e8559e8b2429e7375b;p=koha_fer diff --git a/C4/Serials.pm b/C4/Serials.pm index 4170865198..7e6147bbe2 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -47,7 +47,7 @@ BEGIN { &GetLatestSerials &ModSerialStatus &GetNextDate &GetSerials2 &ReNewSubscription &GetLateIssues &GetLateOrMissingIssues &GetSerialInformation &AddItem2Serial - &PrepareSerialsData + &PrepareSerialsData &GetNextExpected &ModNextExpected &UpdateClaimdateIssues &GetSuppliersWithLateIssues &getsupplierbyserialid @@ -256,17 +256,18 @@ sub GetSerialInformation { my $data = $rq->fetchrow_hashref; # create item information if we have serialsadditems for this subscription if ( $data->{'serialsadditems'} ) { - if ( $data->{'itemnumber'} ) { - my @itemnumbers = split /,/, $data->{'itemnumber'}; - foreach my $itemnum (@itemnumbers) { - + my $queryitem=$dbh->prepare("SELECT itemnumber from serialitems where serialid=?"); + $queryitem->execute($serialid); + my $itemnumbers=$queryitem->fetchall_arrayref([0]); + if (scalar(@$itemnumbers)>0){ + foreach my $itemnum (@$itemnumbers) { #It is ASSUMED that GetMarcItem ALWAYS WORK... #Maybe GetMarcItem should return values on failure - $debug and warn "itemnumber :$itemnum, bibnum :".$data->{'biblionumber'}; + $debug and warn "itemnumber :$itemnum->[0], bibnum :".$data->{'biblionumber'}; my $itemprocessed = - PrepareItemrecordDisplay( $data->{'biblionumber'}, $itemnum ); - $itemprocessed->{'itemnumber'} = $itemnum; - $itemprocessed->{'itemid'} = $itemnum; + PrepareItemrecordDisplay( $data->{'biblionumber'}, $itemnum->[0] ); + $itemprocessed->{'itemnumber'} = $itemnum->[0]; + $itemprocessed->{'itemid'} = $itemnum->[0]; $itemprocessed->{'serialid'} = $serialid; $itemprocessed->{'biblionumber'} = $data->{'biblionumber'}; push @{ $data->{'items'} }, $itemprocessed; @@ -721,6 +722,7 @@ this function get every serial not arrived for a given subscription as well as the number of issues registered in the database (all types) this number is used to see if a subscription can be deleted (=it must have only 1 issue) +FIXME: We should return \@serials. =back =cut @@ -1214,6 +1216,61 @@ sub ModSerialStatus { } } +=head2 GetNextExpected + +=over 4 + +$nextexpected = GetNextExpected($subscriptionid) + +Get the planneddate for the current expected issue of the subscription. + +returns a hashref: + +$nextexepected = { + serialid => int + planneddate => C4::Dates object + } + +=back + +=cut + +sub GetNextExpected($) { + my ($subscriptionid) = @_; + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare('SELECT serialid, planneddate FROM serial WHERE subscriptionid=? AND status=?'); + # Each subscription has only one 'expected' issue, with serial.status==1. + $sth->execute( $subscriptionid, 1 ); + my ( $nextissue ) = $sth->fetchrow_hashref; + $nextissue->{planneddate} = C4::Dates->new($nextissue->{planneddate},'iso'); + return $nextissue; +} +=head2 ModNextExpected + +=over 4 + +ModNextExpected($subscriptionid,$date) + +Update the planneddate for the current expected issue of the subscription. +This will modify all future prediction results. + +C<$date> is a C4::Dates object. + +=back + +=cut + +sub ModNextExpected($$) { + my ($subscriptionid,$date) = @_; + my $dbh = C4::Context->dbh; + #FIXME: Would expect to only set planneddate, but we set both on new issue creation, so updating it here + my $sth = $dbh->prepare('UPDATE serial SET planneddate=?,publisheddate=? WHERE subscriptionid=? AND status=?'); + # Each subscription has only one 'expected' issue, with serial.status==1. + $sth->execute( $date->output('iso'),$date->output('iso'), $subscriptionid, 1); + return 0; + +} + =head2 ModSubscription =over 4 @@ -1746,7 +1803,7 @@ sub HasSubscriptionExpired { } else { if ($subscription->{'numberlength'}){ my $countreceived=countissuesfrom($subscriptionid,$subscription->{'startdate'}); - return 1 if ($countreceived >$subscription->{'numberlentgh'}); + return 1 if ($countreceived >$subscription->{'numberlength'}); return 0; } else { return 0; @@ -2592,10 +2649,13 @@ sub GetNextDate(@) { my @resultdate; # warn "DOW $dayofweek"; - if ( $subscription->{periodicity} % 16 == 0 ) { + if ( $subscription->{periodicity} % 16 == 0 ) { # 'without regularity' || 'irregular' return 0; } - if ( $subscription->{periodicity} == 1 ) { + # daily : n / week + # Since we're interpreting irregularity here as which days of the week to skip an issue, + # renaming this pattern from 1/day to " n / week ". + if ( $subscription->{periodicity} == 1 ) { my $dayofweek = eval{Day_of_Week( $year,$month, $day )}; if ($@){warn "year month day : $year $month $day $subscription->{subscriptionid} : $@";} else { @@ -2609,11 +2669,13 @@ sub GetNextDate(@) { @resultdate = Add_Delta_Days($year,$month, $day , 1 ); } } + # 1 week if ( $subscription->{periodicity} == 2 ) { my ($wkno,$year) = eval {Week_of_Year( $year,$month, $day )}; if ($@){warn "year month day : $year $month $day $subscription->{subscriptionid} : $@";} else { for ( my $i = 0 ; $i < @irreg ; $i++ ) { + #FIXME: if two consecutive irreg, do we only skip one? if ( $irreg[$i] == (($wkno!=51)?($wkno +1) % 52 :52)) { ($year,$month,$day) = Add_Delta_Days($year,$month, $day , 7 ); $wkno=(($wkno!=51)?($wkno +1) % 52 :52); @@ -2622,6 +2684,7 @@ sub GetNextDate(@) { @resultdate = Add_Delta_Days( $year,$month, $day, 7); } } + # 1 / 2 weeks if ( $subscription->{periodicity} == 3 ) { my ($wkno,$year) = eval {Week_of_Year( $year,$month, $day )}; if ($@){warn "year month day : $year $month $day $subscription->{subscriptionid} : $@";} @@ -2636,6 +2699,7 @@ sub GetNextDate(@) { @resultdate = Add_Delta_Days($year,$month, $day , 14 ); } } + # 1 / 3 weeks if ( $subscription->{periodicity} == 4 ) { my ($wkno,$year) = eval {Week_of_Year( $year,$month, $day )}; if ($@){warn "année mois jour : $year $month $day $subscription->{subscriptionid} : $@";}