From b989b8326433df36cbde57954919d55e907d76c6 Mon Sep 17 00:00:00 2001 From: Chris Cormack Date: Sun, 30 Sep 2007 17:49:53 -0500 Subject: [PATCH] Fix for bug 1437, items not showing on moredetail.pl Signed-off-by: Chris Cormack --- C4/Biblio.pm | 63 +++++++++++++++++++ catalogue/moredetail.pl | 28 ++++----- .../prog/en/modules/catalogue/moredetail.tmpl | 2 +- 3 files changed, 77 insertions(+), 16 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 71c7e09a74..6f5e280da8 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -68,6 +68,7 @@ push @EXPORT, qw( &GetUsedMarcStructure &GetItemsInfo + &GetItemsByBiblioitemnumber &GetItemnumberFromBarcode &get_itemnumbers_of &GetXmlBiblio @@ -1392,6 +1393,68 @@ sub GetItemInfosOf { return get_infos_of( $query, 'itemnumber' ); } +=head2 GetItemsByBiblioitemnumber + +=over 4 + +GetItemsByBiblioitemnumber($biblioitemnumber); + +Returns an arrayref of hashrefs suitable for use in a TMPL_LOOP +Called by moredetail.pl + +=back + +=cut + +sub GetItemsByBiblioitemnumber { + my ( $bibitem ) = @_; + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare("SELECT * FROM items WHERE items.biblioitemnumber = ?") || die $dbh->errstr; + # Get all items attached to a biblioitem + my $i = 0; + my @results; + $sth->execute($bibitem) || die $sth->errstr; + while ( my $data = $sth->fetchrow_hashref ) { + # Foreach item, get circulation information + my $sth2 = $dbh->prepare( "SELECT * FROM issues,borrowers + WHERE itemnumber = ? + AND returndate is NULL + AND issues.borrowernumber = borrowers.borrowernumber" + ); + $sth2->execute( $data->{'itemnumber'} ); + if ( my $data2 = $sth2->fetchrow_hashref ) { + # if item is out, set the due date and who it is out too + $data->{'date_due'} = $data2->{'date_due'}; + $data->{'cardnumber'} = $data2->{'cardnumber'}; + $data->{'borrowernumber'} = $data2->{'borrowernumber'}; + } + else { + # set date_due to blank, so in the template we check itemlost, and wthdrawn + $data->{'date_due'} = ''; + } # else + $sth2->finish; + # Find the last 3 people who borrowed this item. + my $query2 = "SELECT * FROM issues, borrowers WHERE itemnumber = ? + AND issues.borrowernumber = borrowers.borrowernumber + AND returndate is not NULL + ORDER BY returndate desc,timestamp desc LIMIT 3"; + $sth2 = $dbh->prepare($query2) || die $dbh->errstr; + $sth2->execute( $data->{'itemnumber'} ) || die $sth2->errstr; + my $i2 = 0; + while ( my $data2 = $sth2->fetchrow_hashref ) { + $data->{"timestamp$i2"} = $data2->{'timestamp'}; + $data->{"card$i2"} = $data2->{'cardnumber'}; + $data->{"borrower$i2"} = $data2->{'borrowernumber'}; + $i2++; + } + $sth2->finish; + push(@results,$data); + } + $sth->finish; + return (\@results); +} + + =head2 GetBiblioItemInfosOf =over 4 diff --git a/catalogue/moredetail.pl b/catalogue/moredetail.pl index 86e004855b..d8835869ff 100755 --- a/catalogue/moredetail.pl +++ b/catalogue/moredetail.pl @@ -23,7 +23,7 @@ use strict; require Exporter; use C4::Koha; use CGI; -use C4::Biblio; # to use &GetBiblioItemData &itemissues +use C4::Biblio; # to use &GetBiblioItemData &GetItemsByBiblioitemnumber use C4::Acquisition; use C4::Output; # contains gettemplate use C4::Auth; @@ -54,19 +54,19 @@ my $bi=$query->param('bi'); my $data=GetBiblioItemData($bi); my $dewey = $data->{'dewey'}; # FIXME Dewey is a string, not a number, & we should use a function -$dewey =~ s/0+$//; -if ($dewey eq "000.") { $dewey = "";}; -if ($dewey < 10){$dewey='00'.$dewey;} -if ($dewey < 100 && $dewey > 10){$dewey='0'.$dewey;} -if ($dewey <= 0){ - $dewey=''; -} -$dewey=~ s/\.$//; -$data->{'dewey'}=$dewey; +# $dewey =~ s/0+$//; +# if ($dewey eq "000.") { $dewey = "";}; +# if ($dewey < 10){$dewey='00'.$dewey;} +# if ($dewey < 100 && $dewey > 10){$dewey='0'.$dewey;} +# if ($dewey <= 0){ +# $dewey=''; +# } +# $dewey=~ s/\.$//; +# $data->{'dewey'}=$dewey; my @results; -my $items= GetItemIssues($bi); +my $items= GetItemsByBiblioitemnumber($bi); my $count=@$items; $data->{'count'}=$count; @@ -83,18 +83,16 @@ foreach my $item (@$items){ $item->{'ordernumber'} = $ordernum; $item->{'booksellerinvoicenumber'} = $order->{'booksellerinvoicenumber'}; - if ($item->{'date_due'} eq 'Available'){ + if ($item->{'date_due'} eq ''){ $item->{'issue'}= 0; } else { $item->{'date_due'} = format_date($item->{'date_due'}); $item->{'issue'}= 1; - $item->{'borrowernumber'} = $item->{'borrower'}; - $item->{'cardnumber'} = $item->{'card'}; } } $template->param(BIBITEM_DATA => \@results); -$template->param(ITEM_DATA => \@$items); +$template->param(ITEM_DATA => $items); $template->param(loggedinuser => $loggedinuser); output_html_with_http_headers $query, $cookie, $template->output; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tmpl index 73496d4d64..9c70749620 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tmpl @@ -84,4 +84,4 @@ NAME="biblionumber"-->&itemnumber=">Modif - \ No newline at end of file + -- 2.39.5