Bug fixes
[koha.git] / reports / itemtypes.plugin
1 #!/usr/bin/perl
2
3 # $Id$
4
5 # Copyright 2000-2002 Katipo Communications
6 #
7 # This file is part of Koha.
8 #
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
12 # version.
13 #
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License along with
19 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
20 # Suite 330, Boston, MA  02111-1307 USA
21
22 use strict;
23 use C4::Auth;
24 use CGI;
25 use C4::Context;
26 use HTML::Template;
27 use C4::Search;
28 use C4::Output;
29 use C4::Koha;
30
31 =head1
32
33 =cut
34
35 sub set_parameters {
36         my ($template) = @_;
37         my $dbh = C4::Context->dbh;
38         my $branches=getbranches();
39         my @branches;
40         my @select_branch;
41         my %select_branches;
42         push @select_branch,"";
43         $select_branches{""} = "";
44         foreach my $branch (keys %$branches) {
45                 push @select_branch, $branch;
46                 $select_branches{$branch} = $branches->{$branch}->{'branchname'};
47         }
48         my $CGIbranch=CGI::scrolling_list( -name     => 'value',
49                                 -id => 'value',
50                                 -values   => \@select_branch,
51                                 -labels   => \%select_branches,
52                                 -size     => 1,
53                                 -multiple => 0 );
54         $template->param(CGIbranch => $CGIbranch);
55         return $template;
56 }
57 sub calculate {
58         my ($parameters) = @_;
59         my @results =();
60         my $branch = @$parameters[0];
61         my $dbh = C4::Context->dbh;
62         my $sth;
63         if ($branch) {
64                 $sth = $dbh->prepare("select description, biblioitems.itemtype, count(*) as total from itemtypes, biblioitems, items 
65                                                 where biblioitems.itemtype=itemtypes.itemtype 
66                                                         and items.biblionumber=biblioitems.biblionumber
67                                                         and items.holdingbranch=?
68                                                 group by biblioitems.itemtype");
69                 $sth->execute($branch);
70         } else {
71                 $sth = $dbh->prepare("select description, biblioitems.itemtype, count(*) as total from itemtypes, biblioitems where biblioitems.itemtype=itemtypes.itemtype group by biblioitems.itemtype");
72                 $sth->execute;
73         }
74         my ($description,$biblioitems,$total);
75         my $grantotal = 0;
76         while (($description,$biblioitems,$total) = $sth->fetchrow) {
77                 my %line;
78                 $line{itemtype} = $description;
79                 $line{count} = $total;
80                 $grantotal += $total;
81                 push @results,\%line;
82         }
83         my @mainloop;
84         my %globalline;
85         $globalline{loopitemtype} = \@results;
86         $globalline{total} = $grantotal;
87         $globalline{branch} = $branch;
88         push @mainloop,\%globalline;
89         return \@mainloop;
90 }
91
92 1;