- if ($branch) {
- $sth = $dbh->prepare("select description, biblioitems.itemtype, count(*) as total from itemtypes, biblioitems, items
- where biblioitems.itemtype=itemtypes.itemtype
- and items.biblionumber=biblioitems.biblionumber
- and items.holdingbranch=?
- group by biblioitems.itemtype");
- $sth->execute($branch);
- } else {
- $sth = $dbh->prepare("select description, biblioitems.itemtype, count(*) as total from itemtypes, biblioitems where biblioitems.itemtype=itemtypes.itemtype group by biblioitems.itemtype");
- $sth->execute;
- }
- my ($description,$biblioitems,$total);
+ if ( C4::Context->preference('item-level_itypes') ) {
+ $sth = $dbh->prepare( q|
+ SELECT itemtypes.itemtype, description, COUNT(*) AS total
+ FROM itemtypes, items
+ WHERE items.itype=itemtypes.itemtype
+ | . ( $branch ? q| AND items.holdingbranch=? | : () ) . q|
+ GROUP BY itemtypes.itemtype, description, items.itype
+ ORDER BY itemtypes.description
+ |);
+ }
+ else {
+ $sth = $dbh->prepare( q|
+ SELECT itemtypes.itemtype, description, COUNT(*) AS total
+ FROM itemtypes, biblioitems, items
+ WHERE biblioitems.itemtype=itemtypes.itemtype
+ AND items.biblioitemnumber=biblioitems.biblioitemnumber
+ | . ( $branch ? q| AND items.holdingbranch=? | : () ) . q|
+ GROUP BY itemtypes.itemtype, description
+ ORDER BY itemtypes.description
+ |);
+ }
+ $sth->execute($branch || ());
+ my ($itemtype, $description,$total);