Bug 7309 - Add NORMARCslim2intranetDetail.xsl for detail view in intranet
[koha.git] / reports / itemtypes.plugin
blobf543f2d0fe97997b0b00d8f3702676319558a267
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 under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
11 # version.
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 use strict;
22 use C4::Auth;
23 use CGI;
24 use C4::Context;
25 use C4::Search;
26 use C4::Output;
27 use C4::Koha;
28 use C4::Branch; # GetBranches
29 =head1
31 =cut
33 sub set_parameters {
34 my ($template) = @_;
35 my $dbh = C4::Context->dbh;
36 my $branches=GetBranches();
37 my @branches;
38 my @select_branch;
39 my %select_branches;
40 push @select_branch,"";
41 $select_branches{""} = "";
42 foreach my $branch (keys %$branches) {
43 push @select_branch, $branch;
44 $select_branches{$branch} = $branches->{$branch}->{'branchname'};
46 my $CGIbranch=CGI::scrolling_list( -name => 'value',
47 -id => 'value',
48 -values => \@select_branch,
49 -labels => \%select_branches,
50 -size => 1,
51 -multiple => 0 );
52 $template->param(CGIbranch => $CGIbranch);
53 return $template;
55 sub calculate {
56 my ($parameters) = @_;
57 my @results =();
58 my $branch = @$parameters[0];
59 my $dbh = C4::Context->dbh;
60 my $sth;
61 if ($branch) {
62 if (C4::Context->preference('item-level_itypes')) {
63 $sth = $dbh->prepare("
64 SELECT description, items.itype as itemtype, COUNT(*) AS total
65 FROM itemtypes,items
66 WHERE items.itype=itemtypes.itemtype
67 AND items.holdingbranch=?
68 GROUP BY items.itype");
71 else {
72 $sth = $dbh->prepare("
73 SELECT description, biblioitems.itemtype, COUNT(*) AS total
74 FROM itemtypes, biblioitems, items
75 WHERE biblioitems.itemtype=itemtypes.itemtype
76 AND items.biblioitemnumber=biblioitems.biblioitemnumber
77 AND items.holdingbranch=?
78 GROUP BY biblioitems.itemtype");
80 $sth->execute($branch);
81 } else {
82 if (C4::Context->preference('item-level_itypes')) {
83 $sth = $dbh->prepare("
84 SELECT description,items.itype AS itemtype, COUNT(*) AS total
85 FROM itemtypes,items
86 WHERE items.itype=itemtypes.itemtype
87 GROUP BY items.itype");
89 else {
90 $sth = $dbh->prepare("SELECT description, biblioitems.itemtype, COUNT(*) AS total
91 FROM itemtypes, biblioitems,items
92 WHERE biblioitems.itemtype=itemtypes.itemtype
93 AND biblioitems.biblioitemnumber = items.biblioitemnumber
94 GROUP BY biblioitems.itemtype");
96 $sth->execute;
98 my ($description,$biblioitems,$total);
99 my $grantotal = 0;
100 my $count = 0;
101 while (($description,$biblioitems,$total) = $sth->fetchrow) {
102 my %line;
103 if($count % 2){
104 $line{toggle} = 1;
105 } else {
106 $line{toggle} = 0;
108 $line{itemtype} = $description;
109 $line{count} = $total;
110 $grantotal += $total;
111 push @results,\%line;
112 $count ++;
114 my @mainloop;
115 my %globalline;
116 $globalline{loopitemtype} = \@results;
117 $globalline{total} = $grantotal;
118 $globalline{branch} = $branch;
119 push @mainloop,\%globalline;
120 return \@mainloop;