From 5a65c60683c2c33cb4a464fa6ce17a6739dbb758 Mon Sep 17 00:00:00 2001 From: Ryan Higgins Date: Wed, 7 Nov 2007 12:12:21 -0600 Subject: [PATCH] further item-level itype changes Signed-off-by: Chris Cormack Signed-off-by: Joshua Ferraro --- C4/Biblio.pm | 50 ++++++++++++++++++++++++++++---------------------- C4/Koha.pm | 2 ++ C4/Overdues.pm | 29 ++++++++++++++++++----------- 3 files changed, 48 insertions(+), 33 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index f0257fc5b5..fc0f8e71d1 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -652,12 +652,17 @@ sub GetBiblioData { my ( $bibnum ) = @_; my $dbh = C4::Context->dbh; - my $query = " - SELECT * , biblioitems.notes AS bnotes, itemtypes.notforloan as bi_notforloan, biblio.notes - FROM biblio + my $query = C4::Context->preference('item-level_itype') + ? " SELECT * , biblioitems.notes AS bnotes, itemtypes.notforloan as bi_notforloan, biblio.notes + FROM biblio LEFT JOIN biblioitems ON biblio.biblionumber = biblioitems.biblionumber LEFT JOIN itemtypes ON biblioitems.itemtype = itemtypes.itemtype - WHERE biblio.biblionumber = ? + WHERE biblio.biblionumber = ? + AND biblioitems.biblionumber = biblio.biblionumber " + : " SELECT * , biblioitems.notes AS bnotes, biblio.notes + FROM biblio + LEFT JOIN biblioitems ON biblio.biblionumber = biblioitems.biblionumber + WHERE biblio.biblionumber = ? AND biblioitems.biblionumber = biblio.biblionumber "; my $sth = $dbh->prepare($query); @@ -726,25 +731,25 @@ sub GetItemsInfo { my $query = "SELECT *,items.notforloan as itemnotforloan FROM items LEFT JOIN biblio ON biblio.biblionumber = items.biblionumber - LEFT JOIN biblioitems ON biblioitems.biblioitemnumber = items.biblioitemnumber - LEFT JOIN itemtypes on biblioitems.itemtype = itemtypes.itemtype - WHERE items.biblionumber = ? - ORDER BY items.dateaccessioned desc - "; + LEFT JOIN biblioitems ON biblioitems.biblioitemnumber = items.biblioitemnumber"; + $query .= (C4::Context->preference('item-level_itype')) ? + " LEFT JOIN itemtypes on items.ccode = itemtypes.itemtype " + : " LEFT JOIN itemtypes on biblioitems.itemtype = itemtypes.itemtype "; + $query .= "WHERE items.biblionumber = ? ORDER BY items.dateaccessioned desc" ; my $sth = $dbh->prepare($query); $sth->execute($biblionumber); my $i = 0; my @results; my ( $date_due, $count_reserves ); + my $isth = $dbh->prepare( + "SELECT issues.*,borrowers.cardnumber,borrowers.surname,borrowers.firstname + FROM issues LEFT JOIN borrowers ON issues.borrowernumber=borrowers.borrowernumber + WHERE itemnumber = ? + AND returndate IS NULL" + ); while ( my $data = $sth->fetchrow_hashref ) { my $datedue = ''; - my $isth = $dbh->prepare( - "SELECT issues.*,borrowers.cardnumber,borrowers.surname,borrowers.firstname - FROM issues LEFT JOIN borrowers ON issues.borrowernumber=borrowers.borrowernumber - WHERE itemnumber = ? - AND returndate IS NULL" - ); $isth->execute( $data->{'itemnumber'} ); if ( my $idata = $isth->fetchrow_hashref ) { $data->{borrowernumber} = $idata->{borrowernumber}; @@ -1135,13 +1140,14 @@ that C is given as C<$itemdata-E{bnotes}>. sub GetBiblioItemData { my ($biblioitemnumber) = @_; my $dbh = C4::Context->dbh; - my $sth = - $dbh->prepare( - "SELECT *,biblioitems.notes AS bnotes - FROM biblioitems,biblio,itemtypes - WHERE biblio.biblionumber = biblioitems.biblionumber - AND biblioitemnumber = ? " - ); + my $query = "SELECT *,biblioitems.notes AS bnotes + FROM biblio, biblioitems "; + if(C4::Context->preference('item-level_itype')) { + $query .= "LEFT JOIN itemtypes on biblioitems.itemtype=itemtypes.itemtype "; + } + $query .= " WHERE biblio.biblionumber = biblioitems.biblionumber + AND biblioitemnumber = ? "; + my $sth = $dbh->prepare($query); my $data; $sth->execute($biblioitemnumber); $data = $sth->fetchrow_hashref; diff --git a/C4/Koha.pm b/C4/Koha.pm index 3d15b9169b..1593ce7d2c 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -704,6 +704,8 @@ labels. =cut +# FIXME - why not use GetAuthorisedValues ?? +# sub get_notforloan_label_of { my $dbh = C4::Context->dbh; diff --git a/C4/Overdues.pm b/C4/Overdues.pm index 99cf3b8234..fb9305b0cb 100644 --- a/C4/Overdues.pm +++ b/C4/Overdues.pm @@ -115,15 +115,21 @@ Koha database. #' sub Getoverdues { my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare( - "SELECT issues.*,biblioitems.itemtype FROM issues - LEFT JOIN items USING (itemnumber) - LEFT JOIN biblioitems USING (biblioitemnumber) - WHERE date_due < now() - AND returndate IS - NULL ORDER BY borrowernumber - " - ); + my $itype_q = (C4::context->preference('item-level_itype')) ? " items.ccode as itemtype " + my $sth = (C4::context->preference('item-level_itype')) ? + $dbh->prepare( + "SELECT issues.*,items.ccode as itemtype FROM issues + LEFT JOIN items USING (itemnumber) + WHERE date_due < now() + AND returndate IS NULL ORDER BY borrowernumber " ) + : + $dbh->prepare( + "SELECT issues.*,biblioitems.itemtype,items.ccode FROM issues + LEFT JOIN items USING (itemnumber) + LEFT JOIN biblioitems USING (biblioitemnumber) + WHERE date_due < now() + AND returndate IS + NULL ORDER BY borrowernumber " ); $sth->execute; my @results; @@ -1144,6 +1150,7 @@ display is filtered by branch sub GetOverduesForBranch { my ( $branch, $location) = @_; + my $itype_link = (C4::context->preference('item-level_itype')) ? " items.ccode " : " biblioitems.itemtype "; if ( not $location ) { my $dbh = C4::Context->dbh; my $sth = $dbh->prepare(" @@ -1173,7 +1180,7 @@ sub GetOverduesForBranch { LEFT JOIN items ON items.itemnumber = issues.itemnumber LEFT JOIN biblio ON biblio.biblionumber = items.biblionumber LEFT JOIN biblioitems ON biblioitems.biblioitemnumber=items.biblioitemnumber - LEFT JOIN itemtypes ON itemtypes.itemtype = biblioitems.itemtype + LEFT JOIN itemtypes ON itemtypes.itemtype = $itype_link LEFT JOIN branches ON branches.branchcode = issues.branchcode WHERE ( issues.returndate is null) AND ( accountlines.amountoutstanding != '0.000000') @@ -1224,7 +1231,7 @@ sub GetOverduesForBranch { LEFT JOIN items ON items.itemnumber = issues.itemnumber LEFT JOIN biblio ON biblio.biblionumber = items.biblionumber LEFT JOIN biblioitems ON biblioitems.biblioitemnumber=items.biblioitemnumber - LEFT JOIN itemtypes ON itemtypes.itemtype = biblioitems.itemtype + LEFT JOIN itemtypes ON itemtypes.itemtype = $itype_link LEFT JOIN branches ON branches.branchcode = issues.branchcode WHERE ( issues.returndate is null ) AND ( accountlines.amountoutstanding != '0.000000') -- 2.39.2