-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathitemtypes.plugin
executable file
·116 lines (108 loc) · 3.2 KB
/
itemtypes.plugin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/perl
# Copyright 2000-2002 Katipo Communications
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with Koha; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use strict;
use C4::Auth;
use CGI;
use C4::Context;
use C4::Search;
use C4::Output;
use C4::Koha;
use C4::Branch; # GetBranches
=head1
=cut
sub set_parameters {
my ($template) = @_;
my $userbranch = '';
if (C4::Context->userenv && C4::Context->userenv->{'branch'}) {
$userbranch = C4::Context->userenv->{'branch'};
}
$template->param( branchloop => GetBranchesLoop($userbranch) );
return $template;
}
sub calculate {
my ($parameters) = @_;
my @results =();
my $branch = @$parameters[0];
my $dbh = C4::Context->dbh;
my $sth;
if ($branch) {
if (C4::Context->preference('item-level_itypes')) {
$sth = $dbh->prepare("
SELECT description, items.itype as itemtype, COUNT(*) AS total
FROM itemtypes,items
WHERE items.itype=itemtypes.itemtype
AND items.holdingbranch=?
GROUP BY items.itype
ORDER BY itemtypes.description");
}
else {
$sth = $dbh->prepare("
SELECT description, biblioitems.itemtype, COUNT(*) AS total
FROM itemtypes, biblioitems, items
WHERE biblioitems.itemtype=itemtypes.itemtype
AND items.biblioitemnumber=biblioitems.biblioitemnumber
AND items.holdingbranch=?
GROUP BY biblioitems.itemtype
ORDER BY itemtypes.description");
}
$sth->execute($branch);
} else {
if (C4::Context->preference('item-level_itypes')) {
$sth = $dbh->prepare("
SELECT description,items.itype AS itemtype, COUNT(*) AS total
FROM itemtypes,items
WHERE items.itype=itemtypes.itemtype
GROUP BY items.itype
ORDER BY itemtypes.description");
}
else {
$sth = $dbh->prepare("SELECT description, biblioitems.itemtype, COUNT(*) AS total
FROM itemtypes, biblioitems,items
WHERE biblioitems.itemtype=itemtypes.itemtype
AND biblioitems.biblioitemnumber = items.biblioitemnumber
GROUP BY biblioitems.itemtype
ORDER BY itemtypes.description");
}
$sth->execute;
}
my ($description,$biblioitems,$total);
my $grantotal = 0;
my $count = 0;
while (($description,$biblioitems,$total) = $sth->fetchrow) {
my %line;
if($count % 2){
$line{toggle} = 1;
} else {
$line{toggle} = 0;
}
$line{itemtype} = $description;
$line{count} = $total;
$grantotal += $total;
push @results,\%line;
$count ++;
}
my @mainloop;
my %globalline;
$globalline{loopitemtype} = \@results;
$globalline{total} = $grantotal;
$globalline{branch} = $branch;
$globalline{branchname} = GetBranchName($branch);
push @mainloop,\%globalline;
return \@mainloop;
}
1;