New XML API
[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 C4::Search;
27 use C4::Output;
28 use C4::Koha;
29
30 =head1
31
32 =cut
33
34 sub set_parameters {
35         my ($template) = @_;
36         my $dbh = C4::Context->dbh;
37         my $branches=GetBranches();
38         my @branches;
39         my @select_branch;
40         my %select_branches;
41         push @select_branch,"";
42         $select_branches{""} = "";
43         foreach my $branch (keys %$branches) {
44                 push @select_branch, $branch;
45                 $select_branches{$branch} = $branches->{$branch}->{'branchname'};
46         }
47         my $CGIbranch=CGI::scrolling_list( -name     => 'value',
48                                 -id => 'value',
49                                 -values   => \@select_branch,
50                                 -labels   => \%select_branches,
51                                 -size     => 1,
52                                 -multiple => 0 );
53         $template->param(CGIbranch => $CGIbranch);
54         return $template;
55 }
56 sub calculate {
57         my ($parameters) = @_;
58         my @results =();
59         my $branch = @$parameters[0];
60         my $dbh = C4::Context->dbh;
61         my $sth;
62         if ($branch) {
63                 $sth = $dbh->prepare("select description, biblio.itemtype, count(*) as total from itemtypes, biblio, items 
64                                                 where biblio.itemtype=itemtypes.itemtype 
65                                                         and items.biblionumber=biblio.biblionumber
66                                                         and items.holdingbranch=?
67                                                 group by biblio.itemtype");
68                 $sth->execute($branch);
69         } else {
70                 $sth = $dbh->prepare("select description, biblio.itemtype, count(*) as total from itemtypes, biblio where biblio.itemtype=itemtypes.itemtype group by biblio.itemtype");
71                 $sth->execute;
72         }
73         my ($description,$biblioitems,$total);
74         my $grantotal = 0;
75         my $count = 0;
76         while (($description,$biblioitems,$total) = $sth->fetchrow) {
77                 my %line;
78                 if($count % 2){
79                         $line{toggle} = 1;
80                         } else {
81                                 $line{toggle} = 0;
82                         }
83                 $line{itemtype} = $description;
84                 $line{count} = $total;
85                 $grantotal += $total;
86                 push @results,\%line;
87                 $count ++;
88         }
89         my @mainloop;
90         my %globalline;
91         $globalline{loopitemtype} = \@results;
92         $globalline{total} = $grantotal;
93         $globalline{branch} = $branch;
94         push @mainloop,\%globalline;
95         return \@mainloop;
96 }
97
98 1;