X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=C4%2FSerials.pm;h=1f8c170445535d9a53f998d6aee93cf815ede7f0;hb=7c09c12e6a9fc0576fc807952fbae5625a4b9d5d;hp=9c22901dafcb2b16bdd1fffe449537a58e4363ca;hpb=c19a56f9cd149bb6b1e587954edbdc3db969bdcf;p=koha_fer diff --git a/C4/Serials.pm b/C4/Serials.pm index 9c22901daf..1f8c170445 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -1,6 +1,7 @@ package C4::Serials; # Copyright 2000-2002 Katipo Communications +# Parts Copyright 2010 Biblibre # # This file is part of Koha. # @@ -91,12 +92,12 @@ the array is in name order sub GetSuppliersWithLateIssues { my $dbh = C4::Context->dbh; - my $query = q| - SELECT DISTINCT aqbooksellerid as id, aqbooksellers.name as name + my $query = qq| + SELECT DISTINCT id, name FROM subscription LEFT JOIN serial ON serial.subscriptionid=subscription.subscriptionid LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id - WHERE id > 0 AND (planneddate < now() OR serial.STATUS = 3 OR serial.STATUS = 4) ORDER BY name|; + WHERE id > 0 AND ((planneddate < now() AND serial.status=1) OR serial.STATUS = 3 OR serial.STATUS = 4) ORDER BY name|; return $dbh->selectall_arrayref($query, { Slice => {} }); } @@ -124,10 +125,11 @@ sub GetLateIssues { LEFT JOIN biblio ON biblio.biblionumber = subscription.biblionumber LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id WHERE ((planneddate < now() AND serial.STATUS =1) OR serial.STATUS = 3) - AND subscription.aqbooksellerid=$supplierid + AND subscription.aqbooksellerid=? ORDER BY title |; $sth = $dbh->prepare($query); + $sth->execute($supplierid); } else { my $query = qq| SELECT name,title,planneddate,serialseq,serial.subscriptionid @@ -139,8 +141,8 @@ sub GetLateIssues { ORDER BY title |; $sth = $dbh->prepare($query); + $sth->execute; } - $sth->execute; my @issuelist; my $last_title; my $odd = 0; @@ -287,10 +289,10 @@ sub UpdateClaimdateIssues { my $dbh = C4::Context->dbh; $date = strftime( "%Y-%m-%d", localtime ) unless ($date); my $query = " - UPDATE serial SET claimdate=$date,status=7 - WHERE serialid in (" . join( ",", @$serialids ) . ")"; + UPDATE serial SET claimdate = ?, status = 7 + WHERE serialid in (" . join( ",", map { '?' } @$serialids ) . ")"; my $rq = $dbh->prepare($query); - $rq->execute; + $rq->execute($date, @$serialids); return $rq->rows; } @@ -439,7 +441,6 @@ sub PrepareSerialsData { foreach my $key ( sort { $b cmp $a } keys %tmpresults ) { push @res, $tmpresults{$key}; } - $res[0]->{'first'} = 1; return \@res; } @@ -607,15 +608,15 @@ sub GetSubscriptions { $sth = $dbh->prepare($sql); $sth->execute(@bind_params); my @results; - my $previoustitle = ""; + my $previousbiblio = ""; my $odd = 1; while ( my $line = $sth->fetchrow_hashref ) { - if ( $previoustitle eq $line->{title} ) { + if ( $previousbiblio eq $line->{biblionumber} ) { $line->{title} = ""; $line->{issn} = ""; } else { - $previoustitle = $line->{title}; + $previousbiblio = $line->{biblionumber}; $odd = -$odd; } $line->{toggle} = 1 if $odd == 1; @@ -659,8 +660,13 @@ sub GetSerials { while ( my $line = $sth->fetchrow_hashref ) { $line->{ "status" . $line->{status} } = 1; # fills a "statusX" value, used for template status select list - $line->{"publisheddate"} = format_date( $line->{"publisheddate"} ); - $line->{"planneddate"} = format_date( $line->{"planneddate"} ); + for my $datefield ( qw( planneddate publisheddate) ) { + if ($line->{$datefield} && $line->{$datefield}!~m/^00/) { + $line->{$datefield} = format_date( $line->{$datefield}); + } else { + $line->{$datefield} = q{}; + } + } push @serials, $line; } @@ -676,8 +682,14 @@ sub GetSerials { while ( ( my $line = $sth->fetchrow_hashref ) && $counter < $count ) { $counter++; $line->{ "status" . $line->{status} } = 1; # fills a "statusX" value, used for template status select list - $line->{"planneddate"} = format_date( $line->{"planneddate"} ); - $line->{"publisheddate"} = format_date( $line->{"publisheddate"} ); + for my $datefield ( qw( planneddate publisheddate) ) { + if ($line->{$datefield} && $line->{$datefield}!~m/^00/) { + $line->{$datefield} = format_date( $line->{$datefield}); + } else { + $line->{$datefield} = q{}; + } + } + push @serials, $line; } @@ -712,9 +724,16 @@ sub GetSerials2 { my @serials; 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->{"publisheddate"} = format_date( $line->{"publisheddate"} ); + $line->{ "status" . $line->{status} } = 1; # fills a "statusX" value, used for template status select list + # Format dates for display + for my $datefield ( qw( planneddate publisheddate ) ) { + if ($line->{$datefield} =~m/^00/) { + $line->{$datefield} = q{}; + } + else { + $line->{$datefield} = format_date( $line->{$datefield} ); + } + } push @serials, $line; } return @serials; @@ -898,7 +917,7 @@ sub GetSeq { =head2 GetExpirationDate -$sensddate = GetExpirationDate($subscriptionid, [$startdate]) +$enddate = GetExpirationDate($subscriptionid, [$startdate]) this function return the next expiration date for a subscription given on input args. @@ -1241,8 +1260,18 @@ sub NewSubscription { $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate ); - #then create the 1st waited number my $subscriptionid = $dbh->{'mysql_insertid'}; + unless ($enddate){ + $enddate = GetExpirationDate($subscriptionid,$startdate); + $query = q| + UPDATE subscription + SET enddate=? + WHERE subscriptionid=? + |; + $sth = $dbh->prepare($query); + $sth->execute( $enddate, $subscriptionid ); + } + #then create the 1st waited number $query = qq( INSERT INTO subscriptionhistory (biblionumber, subscriptionid, histstartdate, opacnote, librariannote) @@ -1451,9 +1480,9 @@ sub ItemizeSerials { my $fwk = GetFrameworkCode( $data->{'biblionumber'} ); if ( $info->{barcode} ) { my @errors; - my $exists = itemdata( $info->{'barcode'} ); - push @errors, "barcode_not_unique" if ($exists); - unless ($exists) { + if ( is_barcode_in_use( $info->{barcode} ) ) { + push @errors, 'barcode_not_unique'; + } else { my $marcrecord = MARC::Record->new(); my ( $tag, $subfield ) = GetMarcFromKohaField( "items.barcode", $fwk ); my $newField = MARC::Field->new( "$tag", '', '', "$subfield" => $info->{barcode} ); @@ -1593,7 +1622,7 @@ sub HasSubscriptionExpired { my $dbh = C4::Context->dbh; my $subscription = GetSubscription($subscriptionid); if ( ( $subscription->{periodicity} % 16 ) > 0 ) { - my $expirationdate = $subscription->{enddate}; + my $expirationdate = $subscription->{enddate} || GetExpirationDate($subscriptionid); if (!defined $expirationdate) { $expirationdate = q{}; } @@ -1739,7 +1768,8 @@ sub GetLateOrMissingIssues { "SELECT serialid, aqbooksellerid, name, biblio.title, planneddate, serialseq, - serial.status, serial.subscriptionid, claimdate + serial.status, serial.subscriptionid, claimdate, + subscription.branchcode FROM serial LEFT JOIN subscription ON serial.subscriptionid=subscription.subscriptionid LEFT JOIN biblio ON subscription.biblionumber=biblio.biblionumber @@ -1755,7 +1785,8 @@ sub GetLateOrMissingIssues { "SELECT serialid, aqbooksellerid, name, biblio.title, planneddate, serialseq, - serial.status, serial.subscriptionid, claimdate + serial.status, serial.subscriptionid, claimdate, + subscription.branchcode FROM serial LEFT JOIN subscription ON serial.subscriptionid=subscription.subscriptionid LEFT JOIN biblio ON subscription.biblionumber=biblio.biblionumber @@ -2306,29 +2337,24 @@ sub GetNextDate(@) { return "$resultdate"; } -=head2 itemdata - - $item = itemdata($barcode); +=head2 is_barcode_in_use -Looks up the item with the given barcode, and returns a -reference-to-hash containing information about that item. The keys of -the hash are the fields from the C and C tables in -the Koha database. +Returns number of occurence of the barcode in the items table +Can be used as a boolean test of whether the barcode has +been deployed as yet =cut -#' -sub itemdata { - my ($barcode) = @_; +sub is_barcode_in_use { + my $barcode = shift; my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare( - "Select * from items LEFT JOIN biblioitems ON items.biblioitemnumber=biblioitems.biblioitemnumber - WHERE barcode=?" + my $occurences = $dbh->selectall_arrayref( + 'SELECT itemnumber from items where barcode = ?', + {}, $barcode + ); - $sth->execute($barcode); - my $data = $sth->fetchrow_hashref; - $sth->finish; - return ($data); + + return @{$occurences}; } 1;