5 # Copyright 2000-2002 Katipo Communications
7 # This file is part of Koha.
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
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.
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
33 plugin that shows a table with issues for categories and borrower
37 this result is quite complex to build...
38 the 2D array contains :
40 * borrowers types on rows
42 If no issues are done, the array must be filled by 0 anyway.
43 So, the script works as this :
44 1- parse the itemtype table to get itemtype descriptions and set itemtype total to 0
45 2- for each borrower category :
46 ** create an array with total = 0 for each itemtype defined in 1
47 ** calculate the total for each itemtype (SQL request)
48 The big hash has the following structure :
51 ->{borrowercategorycode} => the total of issues for each cell of the table.
52 ->{total} => the total for the itemtype
53 ->{description} => the itemtype description
55 the borrowertype hash contains description and total for each borrowercategory.
57 the hashes are then translated to hash / arrays to be returned to manager.pl & send to the template
65 my $dbh = C4::Context->dbh;
66 my $branches=getbranches();
70 push @select_branch,"";
71 $select_branches{""} = "";
72 foreach my $branch (keys %$branches) {
73 push @select_branch, $branch;
74 $select_branches{$branch} = $branches->{$branch}->{'branchname'};
76 my $CGIbranch=CGI::scrolling_list( -name => 'value',
78 -values => \@select_branch,
79 -labels => \%select_branches,
82 $template->param(CGIbranch => $CGIbranch);
86 my ($parameters) = @_;
89 my $borrower_category = @$parameters[0];
90 my $branch = @$parameters[1];
91 my $dbh = C4::Context->dbh;
92 # build the SQL query & execute it
94 # 1st, loop every itemtypes.
95 my $sth = $dbh->prepare("select itemtype,description from itemtypes");
98 while (my ($itemtype,$description) = $sth->fetchrow) {
99 $itemtypes{$itemtype}->{description} = $description;
100 $itemtypes{$itemtype}->{total} = 0;
102 # now, parse each category. Before filling the result array, fill it with 0 to have every itemtype column.
103 my $sth = $dbh->prepare("SELECT itemtype, count( * )
104 FROM issues, borrowers, biblioitems, items
105 WHERE issues.borrowernumber = borrowers.borrowernumber
106 AND items.itemnumber = issues.itemnumber
107 AND biblioitems.biblionumber = items.biblionumber
108 AND borrowers.categorycode = ?
109 GROUP BY biblioitems.itemtype");
110 my $sthcategories = $dbh->prepare("select categorycode,description from categories");
111 $sthcategories->execute;
113 my @categorycodeloop;
114 while (my ($categorycode,$description) = $sthcategories->fetchrow) {
115 $borrowertype{$categorycode}->{description} = $description;
116 $borrowertype{$categorycode}->{total} = 0;
118 $categorycode{categorycode} = $description;
119 push @categorycodeloop,\%categorycode;
120 foreach my $itemtype (keys %itemtypes) {
121 $itemtypes{$itemtype}->{results}->{$categorycode} = 0;
123 $sth->execute($categorycode);
124 while (my ($itemtype, $total) = $sth->fetchrow) {
125 $itemtypes{$itemtype}->{results}->{$categorycode} = $total;
126 $borrowertype{$categorycode}->{total} += $total;
127 $itemtypes{$itemtype}->{total} += $total;
134 my @loopborrowertype;
137 foreach my $itemtype (keys %itemtypes) {
139 foreach my $categorycode (keys %{$itemtypes{$itemtype}->{results}}) {
141 $cell{issues} = $itemtypes{$itemtype}->{results}->{$categorycode};
142 push @loopitemtype,\%cell;
145 $line{loopitemtype} = \@loopitemtype;
146 $line{itemtype} = $itemtypes{$itemtype}->{description};
147 $line{hilighted} = 1 if $hilighted eq 1;
148 $line{totalitemtype} = $itemtypes{$itemtype}->{total};
149 $hilighted = -$hilighted;
150 push @loopborrowertype, \%line;
152 # the header of the table
153 $globalline{loopborrowertype} = \@loopborrowertype;
154 # the core of the table
155 $globalline{categorycodeloop} = \@categorycodeloop;
156 # the foot (totals by borrower type)
157 my @loopborrowertotal;
158 foreach my $categorycode (keys %borrowertype) {
160 $line{issues} = $borrowertype{$categorycode}->{total};
161 push @loopborrowertotal, \%line;
163 $globalline{loopborrowertotal} = \@loopborrowertotal;
164 # $globalline{total} = $grantotal;
165 # $globalline{borrower_category} = $borrower_category;
166 push @mainloop,\%globalline;