Bug 16268: Add confirm message for deleting circ and fines rules
[koha.git] / reports / itemtypes.plugin
blob2da9a88ef30912ba25b0ad9e6b1b6b822b23b263
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 use C4::Branch; # GetBranches
29 =head1
31 =cut
33 sub set_parameters {
34 my ($template) = @_;
35 my $userbranch = '';
36 if (C4::Context->userenv && C4::Context->userenv->{'branch'}) {
37 $userbranch = C4::Context->userenv->{'branch'};
39 $template->param( branchloop => GetBranchesLoop($userbranch) );
40 return $template;
43 sub calculate {
44 my ($parameters) = @_;
45 my @results =();
46 my $branch = @$parameters[0];
47 my $dbh = C4::Context->dbh;
48 my $sth;
49 if ($branch) {
50 if (C4::Context->preference('item-level_itypes')) {
51 $sth = $dbh->prepare("
52 SELECT itemtype, description, items.itype as itemtype, COUNT(*) AS total
53 FROM itemtypes,items
54 WHERE items.itype=itemtypes.itemtype
55 AND items.holdingbranch=?
56 GROUP BY items.itype
57 ORDER BY itemtypes.description");
60 else {
61 $sth = $dbh->prepare("
62 SELECT itemtype, description, biblioitems.itemtype, COUNT(*) AS total
63 FROM itemtypes, biblioitems, items
64 WHERE biblioitems.itemtype=itemtypes.itemtype
65 AND items.biblioitemnumber=biblioitems.biblioitemnumber
66 AND items.holdingbranch=?
67 GROUP BY biblioitems.itemtype
68 ORDER BY itemtypes.description");
70 $sth->execute($branch);
71 } else {
72 if (C4::Context->preference('item-level_itypes')) {
73 $sth = $dbh->prepare("
74 SELECT itemtype, description,items.itype AS itemtype, COUNT(*) AS total
75 FROM itemtypes,items
76 WHERE items.itype=itemtypes.itemtype
77 GROUP BY items.itype
78 ORDER BY itemtypes.description");
80 else {
81 $sth = $dbh->prepare("SELECT itemtype, description, biblioitems.itemtype, COUNT(*) AS total
82 FROM itemtypes, biblioitems,items
83 WHERE biblioitems.itemtype=itemtypes.itemtype
84 AND biblioitems.biblioitemnumber = items.biblioitemnumber
85 GROUP BY biblioitems.itemtype
86 ORDER BY itemtypes.description");
88 $sth->execute;
90 my ($itemtype, $description,$biblioitems,$total);
91 my $grantotal = 0;
92 my $count = 0;
93 while (($itemtype, $description,$biblioitems,$total) = $sth->fetchrow) {
94 my %line;
95 if($count % 2){
96 $line{toggle} = 1;
97 } else {
98 $line{toggle} = 0;
100 $line{itemtype} = $itemtype;
101 $line{count} = $total;
102 $grantotal += $total;
103 push @results,\%line;
104 $count ++;
106 my @mainloop;
107 my %globalline;
108 $globalline{loopitemtype} = \@results;
109 $globalline{total} = $grantotal;
110 $globalline{branch} = $branch;
111 $globalline{branchname} = GetBranchName($branch);
112 push @mainloop,\%globalline;
113 return \@mainloop;