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 under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 use HTML
::Template
::Pro
;
31 use C4
::Branch
; # GetBranches
35 plugin that shows a table with issues for categories and borrower
39 this result is quite complex to build...
40 the 2D array contains :
42 * borrowers types on rows
44 If no issues are done, the array must be filled by 0 anyway.
45 So, the script works as this :
46 1- parse the itemtype table to get itemtype descriptions and set itemtype total to 0
47 2- for each borrower category :
48 ** create an array with total = 0 for each itemtype defined in 1
49 ** calculate the total for each itemtype (SQL request)
50 The big hash has the following structure :
53 ->{borrowercategorycode} => the total of issues for each cell of the table.
54 ->{total} => the total for the itemtype
55 ->{description} => the itemtype description
57 the borrowertype hash contains description and total for each borrowercategory.
59 the hashes are then translated to hash / arrays to be returned to manager.pl & send to the template
67 my $dbh = C4
::Context
->dbh;
68 my $branches=GetBranches
();
72 push @select_branch,"";
73 $select_branches{""} = "";
74 foreach my $branch (keys %$branches) {
75 push @select_branch, $branch;
76 $select_branches{$branch} = $branches->{$branch}->{'branchname'};
78 my $CGIbranch=CGI
::scrolling_list
( -name
=> 'value',
80 -values => \
@select_branch,
81 -labels
=> \
%select_branches,
84 $template->param(CGIbranch
=> $CGIbranch);
86 my ($codes,$labels)=GetborCatFromCatType
(undef,undef);
88 foreach my $thisborcat (sort keys %$labels) {
89 push @borcatloop, {value
=> $thisborcat,
90 description
=> $labels->{$thisborcat},
93 $template->param(loopcategories
=> \
@borcatloop);
97 my ($parameters) = @_;
100 my $borrower_category = @
$parameters[0];
101 my $branch = @
$parameters[1];
102 my $dbh = C4
::Context
->dbh;
103 # build the SQL query & execute it
105 # 1st, loop every itemtypes.
106 my $sth = $dbh->prepare("select itemtype,description from itemtypes");
109 while (my ($itemtype,$description) = $sth->fetchrow) {
110 $itemtypes{$itemtype}->{description
} = $description;
111 $itemtypes{$itemtype}->{total
} = 0;
113 # now, parse each category. Before filling the result array, fill it with 0 to have every itemtype column.
114 my $strsth="SELECT itemtype, count( * )
115 FROM issues, borrowers, biblioitems, items
116 WHERE issues.borrowernumber = borrowers.borrowernumber
117 AND items.itemnumber = issues.itemnumber
118 AND biblioitems.biblionumber = items.biblionumber
119 AND borrowers.categorycode = ?";
120 $strsth.= " AND borrowers.branchcode = ".$dbh->quote($branch) if ($branch);
121 $strsth .= " GROUP BY biblioitems.itemtype";
122 my $sth = $dbh->prepare($strsth);
123 my $sthcategories = $dbh->prepare("select categorycode,description from categories");
124 $sthcategories->execute;
126 my @categorycodeloop;
129 my $borrower_categorycode =0;
132 my @loopborrowertype;
133 my @loopborrowertotal;
137 #If no Borrower-category selected....
139 if (!$borrower_category) {
140 while ( ($categorycode,$description) = $sthcategories->fetchrow) {
141 $borrowertype{$categorycode}->{description
} = $description;
142 $borrowertype{$categorycode}->{total
} = 0;
144 $categorycode{categorycode
} = $description;
145 push @categorycodeloop,\
%categorycode;
146 foreach my $itemtype (keys %itemtypes) {
147 $itemtypes{$itemtype}->{results
}->{$categorycode} = 0;
149 $sth->execute($categorycode);
150 while (my ($itemtype, $total) = $sth->fetchrow) {
151 $itemtypes{$itemtype}->{results
}->{$categorycode} = $total;
152 $borrowertype{$categorycode}->{total
} += $total;
153 $itemtypes{$itemtype}->{total
} += $total;
154 $grantotal += $total;
158 foreach my $itemtype (keys %itemtypes) {
160 $sthcategories->execute;
161 while (($categorycode,$description) = $sthcategories->fetchrow ) {
163 $cell{issues
} = $itemtypes{$itemtype}->{results
}->{$categorycode};
164 #printf stderr "%s ",$categorycode;
165 push @loopitemtype,\
%cell;
169 $line{loopitemtype
} = \
@loopitemtype;
170 if ($itemtypes{$itemtype}->{description
}) {
171 $line{itemtype
} = $itemtypes{$itemtype}->{description
};
173 $line{itemtype
} = "$itemtype (no entry in itemtype table)";
175 $line{hilighted
} = 1 if $hilighted eq 1;
176 $line{totalitemtype
} = $itemtypes{$itemtype}->{total
};
177 $hilighted = -$hilighted;
178 push @loopborrowertype, \
%line;
180 $sthcategories->execute;
181 while (($categorycode,$description) = $sthcategories->fetchrow ) {
183 $line{issues
} = $borrowertype{$categorycode}->{total
};
184 push @loopborrowertotal, \
%line;
187 # A Borrower_category has been selected
188 # extracting corresponding data
189 $borrowertype{$categorycode}->{description
} = $borrower_category;
190 $borrowertype{$categorycode}->{total
} = 0;
191 while (($categorycode,$description) = $sthcategories->fetchrow) {
192 if ($description =~ /$borrower_category/ ) {
193 $borrower_categorycode = $categorycode;
195 $cc{categorycode
} = $description;
196 push @categorycodeloop,\
%cc;
197 foreach my $itemtype (keys %itemtypes) {
198 $itemtypes{$itemtype}->{results
}->{$categorycode} = 0;
200 $sth->execute($categorycode);
201 while (my ($itemtype, $total) = $sth->fetchrow) {
202 $itemtypes{$itemtype}->{results
}->{$categorycode} = $total;
203 $borrowertype{$categorycode}->{total
} += $total;
204 $itemtypes{$itemtype}->{total
} += $total;
210 foreach my $itemtype (keys %itemtypes) {
213 $cell{issues
}=$itemtypes{$itemtype}->{results
}->{$borrower_categorycode};
214 push @loopitemtype, \
%cell;
216 $line{loopitemtype
} = \
@loopitemtype;
217 if ($itemtypes{$itemtype}->{description
}) {
218 $line{itemtype
} = $itemtypes{$itemtype}->{description
};
220 $line{itemtype
} = "$itemtype (no entry in itemtype table)";
222 $line{hilighted
} = 1 if $hilighted eq 1;
223 $line{totalitemtype
} = $itemtypes{$itemtype}->{total
};
224 $hilighted = -$hilighted;
225 push @loopborrowertype, \
%line;
228 $cell{issues
} = $borrowertype{$borrower_categorycode}->{total
};
229 push @loopborrowertotal, \
%cell;
231 # the header of the table
232 $globalline{loopborrowertype
} = \
@loopborrowertype;
233 # the core of the table
234 $globalline{categorycodeloop
} = \
@categorycodeloop;
235 # the foot (totals by borrower type)
236 $globalline{loopborrowertotal
} = \
@loopborrowertotal;
237 $globalline{grantotal
}= $grantotal;
238 push @mainloop,\
%globalline;