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.
30 use C4
::Branch
; # GetBranches
34 plugin that shows a table with issues for categories and borrower
38 this result is quite complex to build...
39 the 2D array contains :
41 * borrowers types on rows
43 If no issues are done, the array must be filled by 0 anyway.
44 So, the script works as this :
45 1- parse the itemtype table to get itemtype descriptions and set itemtype total to 0
46 2- for each borrower category :
47 ** create an array with total = 0 for each itemtype defined in 1
48 ** calculate the total for each itemtype (SQL request)
49 The big hash has the following structure :
52 ->{borrowercategorycode} => the total of issues for each cell of the table.
53 ->{total} => the total for the itemtype
54 ->{description} => the itemtype description
56 the borrowertype hash contains description and total for each borrowercategory.
58 the hashes are then translated to hash / arrays to be returned to manager.pl & send to the template
67 $template->param( branchloop
=> GetBranchesLoop
() );
69 my ($codes,$labels)=GetborCatFromCatType
(undef,undef);
71 foreach my $thisborcat (sort keys %$labels) {
74 description
=> $labels->{$thisborcat},
77 $template->param(loopcategories
=> \
@borcatloop);
82 my ($parameters) = @_;
85 my $borrower_category = @
$parameters[0];
86 my $branch = @
$parameters[1];
87 my $dbh = C4
::Context
->dbh;
88 # build the SQL query & execute it
90 # 1st, loop every itemtypes.
91 my $sth = $dbh->prepare("select itemtype,description from itemtypes");
94 while (my ($itemtype,$description) = $sth->fetchrow) {
95 $itemtypes{$itemtype}->{description
} = $description;
96 $itemtypes{$itemtype}->{total
} = 0;
98 # now, parse each category. Before filling the result array, fill it with 0 to have every itemtype column.
99 my $strsth="SELECT itemtype, count( * )
100 FROM issues, borrowers, biblioitems, items
101 WHERE issues.borrowernumber = borrowers.borrowernumber
102 AND items.itemnumber = issues.itemnumber
103 AND biblioitems.biblionumber = items.biblionumber
104 AND borrowers.categorycode = ?";
105 $strsth.= " AND borrowers.branchcode = ".$dbh->quote($branch) if ($branch);
106 $strsth .= " GROUP BY biblioitems.itemtype";
107 my $sth = $dbh->prepare($strsth);
108 my $sthcategories = $dbh->prepare("select categorycode,description from categories");
109 $sthcategories->execute;
111 my @categorycodeloop;
114 my $borrower_categorycode =0;
117 my @loopborrowertype;
118 my @loopborrowertotal;
122 #If no Borrower-category selected....
124 if (!$borrower_category) {
125 while ( ($categorycode,$description) = $sthcategories->fetchrow) {
126 $borrowertype{$categorycode}->{description
} = $description;
127 $borrowertype{$categorycode}->{total
} = 0;
129 $categorycode{categorycode
} = $description;
130 push @categorycodeloop,\
%categorycode;
131 foreach my $itemtype (keys %itemtypes) {
132 $itemtypes{$itemtype}->{results
}->{$categorycode} = 0;
134 $sth->execute($categorycode);
135 while (my ($itemtype, $total) = $sth->fetchrow) {
136 $itemtypes{$itemtype}->{results
}->{$categorycode} = $total;
137 $borrowertype{$categorycode}->{total
} += $total;
138 $itemtypes{$itemtype}->{total
} += $total;
139 $grantotal += $total;
143 foreach my $itemtype (keys %itemtypes) {
145 $sthcategories->execute;
146 while (($categorycode,$description) = $sthcategories->fetchrow ) {
148 $cell{issues
} = $itemtypes{$itemtype}->{results
}->{$categorycode};
149 #printf stderr "%s ",$categorycode;
150 push @loopitemtype,\
%cell;
154 $line{loopitemtype
} = \
@loopitemtype;
155 if ($itemtypes{$itemtype}->{description
}) {
156 $line{itemtype
} = $itemtypes{$itemtype}->{description
};
158 $line{itemtype
} = "$itemtype (no entry in itemtype table)";
160 $line{hilighted
} = 1 if $hilighted eq 1;
161 $line{totalitemtype
} = $itemtypes{$itemtype}->{total
};
162 $hilighted = -$hilighted;
163 push @loopborrowertype, \
%line;
165 $sthcategories->execute;
166 while (($categorycode,$description) = $sthcategories->fetchrow ) {
168 $line{issues
} = $borrowertype{$categorycode}->{total
};
169 push @loopborrowertotal, \
%line;
172 # A Borrower_category has been selected
173 # extracting corresponding data
174 $borrowertype{$categorycode}->{description
} = $borrower_category;
175 $borrowertype{$categorycode}->{total
} = 0;
176 while (($categorycode,$description) = $sthcategories->fetchrow) {
177 if ($description =~ /$borrower_category/ ) {
178 $borrower_categorycode = $categorycode;
180 $cc{categorycode
} = $description;
181 push @categorycodeloop,\
%cc;
182 foreach my $itemtype (keys %itemtypes) {
183 $itemtypes{$itemtype}->{results
}->{$categorycode} = 0;
185 $sth->execute($categorycode);
186 while (my ($itemtype, $total) = $sth->fetchrow) {
187 $itemtypes{$itemtype}->{results
}->{$categorycode} = $total;
188 $borrowertype{$categorycode}->{total
} += $total;
189 $itemtypes{$itemtype}->{total
} += $total;
195 foreach my $itemtype (keys %itemtypes) {
198 $cell{issues
}=$itemtypes{$itemtype}->{results
}->{$borrower_categorycode};
199 push @loopitemtype, \
%cell;
201 $line{loopitemtype
} = \
@loopitemtype;
202 if ($itemtypes{$itemtype}->{description
}) {
203 $line{itemtype
} = $itemtypes{$itemtype}->{description
};
205 $line{itemtype
} = "$itemtype (no entry in itemtype table)";
207 $line{hilighted
} = 1 if $hilighted eq 1;
208 $line{totalitemtype
} = $itemtypes{$itemtype}->{total
};
209 $hilighted = -$hilighted;
210 push @loopborrowertype, \
%line;
213 $cell{issues
} = $borrowertype{$borrower_categorycode}->{total
};
214 push @loopborrowertotal, \
%cell;
216 # the header of the table
217 $globalline{loopborrowertype
} = \
@loopborrowertype;
218 # the core of the table
219 $globalline{categorycodeloop
} = \
@categorycodeloop;
220 # the foot (totals by borrower type)
221 $globalline{loopborrowertotal
} = \
@loopborrowertotal;
222 $globalline{grantotal
}= $grantotal;
223 push @mainloop,\
%globalline;