Line 0
Link Here
|
|
|
1 |
#!/usr/bin/perl |
2 |
|
3 |
# Copyright 2000-2002 Katipo Communications |
4 |
# |
5 |
# This file is part of Koha. |
6 |
# |
7 |
# Koha is free software; you can redistribute it and/or modify it |
8 |
# under the terms of the GNU General Public License as published by |
9 |
# the Free Software Foundation; either version 3 of the License, or |
10 |
# (at your option) any later version. |
11 |
# |
12 |
# Koha is distributed in the hope that it will be useful, but |
13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
# GNU General Public License for more details. |
16 |
# |
17 |
# You should have received a copy of the GNU General Public License |
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
19 |
|
20 |
use Modern::Perl; |
21 |
use C4::Auth qw( get_template_and_user ); |
22 |
use CGI qw ( -utf8 ); |
23 |
use C4::Context; |
24 |
use C4::Output qw( output_html_with_http_headers ); |
25 |
|
26 |
my $input = CGI->new; |
27 |
my $report_name = $input->param("report_name"); |
28 |
my $do_it = $input->param('do_it'); |
29 |
my $fullreportname = "reports/itemtypes.tt"; |
30 |
my @values = $input->multi_param("value"); |
31 |
my ( $template, $borrowernumber, $cookie ) = get_template_and_user( |
32 |
{ |
33 |
template_name => $fullreportname, |
34 |
query => $input, |
35 |
type => "intranet", |
36 |
flagsrequired => { reports => '*' }, |
37 |
} |
38 |
); |
39 |
$template->param( |
40 |
do_it => $do_it, |
41 |
); |
42 |
if ($do_it) { |
43 |
my $results = calculate( \@values ); |
44 |
$template->param( mainloop => $results ); |
45 |
} |
46 |
output_html_with_http_headers $input, $cookie, $template->output; |
47 |
|
48 |
sub calculate { |
49 |
my ($parameters) = @_; |
50 |
my @results = (); |
51 |
my $branch = @$parameters[0]; |
52 |
my $dbh = C4::Context->dbh; |
53 |
my $sth; |
54 |
if ( C4::Context->preference('item-level_itypes') ) { |
55 |
$sth = $dbh->prepare( |
56 |
q| |
57 |
SELECT itemtypes.itemtype, description, COUNT(*) AS total |
58 |
FROM itemtypes, items |
59 |
WHERE items.itype=itemtypes.itemtype |
60 |
| . ( $branch ? q| AND items.holdingbranch=? | : () ) . q| |
61 |
GROUP BY itemtypes.itemtype, description, items.itype |
62 |
ORDER BY itemtypes.description |
63 |
| |
64 |
); |
65 |
} else { |
66 |
$sth = $dbh->prepare( |
67 |
q| |
68 |
SELECT itemtypes.itemtype, description, COUNT(*) AS total |
69 |
FROM itemtypes, biblioitems, items |
70 |
WHERE biblioitems.itemtype=itemtypes.itemtype |
71 |
AND items.biblioitemnumber=biblioitems.biblioitemnumber |
72 |
| . ( $branch ? q| AND items.holdingbranch=? | : () ) . q| |
73 |
GROUP BY itemtypes.itemtype, description |
74 |
ORDER BY itemtypes.description |
75 |
| |
76 |
); |
77 |
} |
78 |
$sth->execute( $branch || () ); |
79 |
my ( $itemtype, $description, $total ); |
80 |
my $grantotal = 0; |
81 |
my $count = 0; |
82 |
while ( ( $itemtype, $description, $total ) = $sth->fetchrow ) { |
83 |
my %line; |
84 |
$line{itemtype} = $itemtype; |
85 |
$line{count} = $total; |
86 |
$grantotal += $total; |
87 |
push @results, \%line; |
88 |
$count++; |
89 |
} |
90 |
my @mainloop; |
91 |
my %globalline; |
92 |
$globalline{loopitemtype} = \@results; |
93 |
$globalline{total} = $grantotal; |
94 |
$globalline{branch} = $branch; |
95 |
push @mainloop, \%globalline; |
96 |
return \@mainloop; |
97 |
} |
98 |
|
99 |
1; |