Bug 20291: Add a StaffLoginInstructions preference for adding text to staff client...
[koha.git] / reports / itemtypes.plugin
blobffa6fb7a43f8e6c760429122fb306e42ba74304b
1 #!/usr/bin/perl
4 # Copyright 2000-2002 Katipo Communications
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
21 use strict;
22 use C4::Auth;
23 use CGI qw ( -utf8 );
24 use C4::Context;
25 use C4::Search;
26 use C4::Output;
27 use C4::Koha;
28 =head1
30 =cut
32 sub set_parameters {
33 my ($template) = @_;
34 return $template;
37 sub calculate {
38 my ($parameters) = @_;
39 my @results =();
40 my $branch = @$parameters[0];
41 my $dbh = C4::Context->dbh;
42 my $sth;
43 if ($branch) {
44 if (C4::Context->preference('item-level_itypes')) {
45 $sth = $dbh->prepare("
46 SELECT itemtype, description, items.itype as itemtype, COUNT(*) AS total
47 FROM itemtypes,items
48 WHERE items.itype=itemtypes.itemtype
49 AND items.holdingbranch=?
50 GROUP BY items.itype
51 ORDER BY itemtypes.description");
54 else {
55 $sth = $dbh->prepare("
56 SELECT itemtype, description, biblioitems.itemtype, COUNT(*) AS total
57 FROM itemtypes, biblioitems, items
58 WHERE biblioitems.itemtype=itemtypes.itemtype
59 AND items.biblioitemnumber=biblioitems.biblioitemnumber
60 AND items.holdingbranch=?
61 GROUP BY biblioitems.itemtype
62 ORDER BY itemtypes.description");
64 $sth->execute($branch);
65 } else {
66 if (C4::Context->preference('item-level_itypes')) {
67 $sth = $dbh->prepare("
68 SELECT itemtype, description,items.itype AS itemtype, COUNT(*) AS total
69 FROM itemtypes,items
70 WHERE items.itype=itemtypes.itemtype
71 GROUP BY items.itype
72 ORDER BY itemtypes.description");
74 else {
75 $sth = $dbh->prepare("SELECT itemtype, description, biblioitems.itemtype, COUNT(*) AS total
76 FROM itemtypes, biblioitems,items
77 WHERE biblioitems.itemtype=itemtypes.itemtype
78 AND biblioitems.biblioitemnumber = items.biblioitemnumber
79 GROUP BY biblioitems.itemtype
80 ORDER BY itemtypes.description");
82 $sth->execute;
84 my ($itemtype, $description,$biblioitems,$total);
85 my $grantotal = 0;
86 my $count = 0;
87 while (($itemtype, $description,$biblioitems,$total) = $sth->fetchrow) {
88 my %line;
89 if($count % 2){
90 $line{toggle} = 1;
91 } else {
92 $line{toggle} = 0;
94 $line{itemtype} = $itemtype;
95 $line{count} = $total;
96 $grantotal += $total;
97 push @results,\%line;
98 $count ++;
100 my @mainloop;
101 my %globalline;
102 $globalline{loopitemtype} = \@results;
103 $globalline{total} = $grantotal;
104 $globalline{branch} = $branch;
105 push @mainloop,\%globalline;
106 return \@mainloop;