|
Lines 28-33
use C4::Output;
Link Here
|
| 28 |
use C4::Koha; |
28 |
use C4::Koha; |
| 29 |
use C4::Reports; |
29 |
use C4::Reports; |
| 30 |
use C4::Circulation; |
30 |
use C4::Circulation; |
|
|
31 |
use C4::Biblio qw/GetMarcSubfieldStructureFromKohaField/; |
| 31 |
|
32 |
|
| 32 |
=head1 NAME |
33 |
=head1 NAME |
| 33 |
|
34 |
|
|
Lines 35-42
plugin that shows a stats on borrowers
Link Here
|
| 35 |
|
36 |
|
| 36 |
=head1 DESCRIPTION |
37 |
=head1 DESCRIPTION |
| 37 |
|
38 |
|
| 38 |
=over 2 |
|
|
| 39 |
|
| 40 |
=cut |
39 |
=cut |
| 41 |
|
40 |
|
| 42 |
our $debug = 0; |
41 |
our $debug = 0; |
|
Lines 45-50
my $fullreportname = "reports/catalogue_stats.tt";
Link Here
|
| 45 |
my $do_it = $input->param('do_it'); |
44 |
my $do_it = $input->param('do_it'); |
| 46 |
my $line = $input->param("Line"); |
45 |
my $line = $input->param("Line"); |
| 47 |
my $column = $input->param("Column"); |
46 |
my $column = $input->param("Column"); |
|
|
47 |
my $cellvalue = $input->param("Cellvalue"); # one of 'items', 'biblios', 'deleteditems' |
| 48 |
my @filters = $input->param("Filter"); |
48 |
my @filters = $input->param("Filter"); |
| 49 |
my $deweydigits = $input->param("deweydigits"); |
49 |
my $deweydigits = $input->param("deweydigits"); |
| 50 |
my $lccndigits = $input->param("lccndigits"); |
50 |
my $lccndigits = $input->param("lccndigits"); |
|
Lines 76-115
my ($template, $borrowernumber, $cookie)
Link Here
|
| 76 |
}); |
76 |
}); |
| 77 |
$template->param(do_it => $do_it); |
77 |
$template->param(do_it => $do_it); |
| 78 |
if ($do_it) { |
78 |
if ($do_it) { |
| 79 |
my $results = calculate($line, $column, $deweydigits, $lccndigits, $cotedigits, \@filters); |
79 |
my $results = calculate( $line, $column, $cellvalue, $deweydigits, $lccndigits, $cotedigits, \@filters ); |
| 80 |
if ($output eq "screen"){ |
80 |
if ( $output eq "screen" ) { |
| 81 |
$template->param(mainloop => $results); |
81 |
$template->param( mainloop => $results ); |
| 82 |
output_html_with_http_headers $input, $cookie, $template->output; |
82 |
output_html_with_http_headers $input, $cookie, $template->output; |
| 83 |
exit; |
83 |
exit; |
| 84 |
} else { |
84 |
} else { |
| 85 |
print $input->header(-type => 'application/vnd.sun.xml.calc', |
85 |
print $input->header( |
| 86 |
-encoding => 'utf-8', |
86 |
-type => 'application/vnd.sun.xml.calc', |
| 87 |
-attachment=>"$basename.csv", |
87 |
-encoding => 'utf-8', |
| 88 |
-name=>"$basename.csv" ); |
88 |
-attachment => "$basename.csv", |
| 89 |
my $cols = @$results[0]->{loopcol}; |
89 |
-name => "$basename.csv" |
| 90 |
my $lines = @$results[0]->{looprow}; |
90 |
); |
| 91 |
print @$results[0]->{line} ."/". @$results[0]->{column} .$sep; |
91 |
my $cols = @$results[0]->{loopcol}; |
| 92 |
foreach my $col ( @$cols ) { |
92 |
my $lines = @$results[0]->{looprow}; |
| 93 |
print $col->{coltitle}.$sep; |
93 |
print @$results[0]->{line} . "/" . @$results[0]->{column} . $sep; |
| 94 |
} |
94 |
foreach my $col (@$cols) { |
| 95 |
print "Total\n"; |
95 |
print $col->{coltitle} . $sep; |
| 96 |
foreach my $line ( @$lines ) { |
96 |
} |
| 97 |
my $x = $line->{loopcell}; |
97 |
print "Total\n"; |
| 98 |
print $line->{rowtitle}.$sep; |
98 |
foreach my $line (@$lines) { |
| 99 |
foreach my $cell (@$x) { |
99 |
my $x = $line->{loopcell}; |
| 100 |
print $cell->{value}.$sep; |
100 |
print $line->{rowtitle} . $sep; |
| 101 |
} |
101 |
foreach my $cell (@$x) { |
| 102 |
print $line->{totalrow}; |
102 |
print $cell->{value} . $sep; |
| 103 |
print "\n"; |
103 |
} |
| 104 |
} |
104 |
print $line->{totalrow}; |
| 105 |
print "TOTAL"; |
105 |
print "\n"; |
| 106 |
$cols = @$results[0]->{loopfooter}; |
106 |
} |
| 107 |
foreach my $col ( @$cols ) { |
107 |
print "TOTAL"; |
| 108 |
print $sep.$col->{totalcol}; |
108 |
$cols = @$results[0]->{loopfooter}; |
| 109 |
} |
109 |
foreach my $col (@$cols) { |
| 110 |
print $sep.@$results[0]->{total}; |
110 |
print $sep. $col->{totalcol}; |
| 111 |
exit; |
111 |
} |
| 112 |
} |
112 |
print $sep. @$results[0]->{total}; |
|
|
113 |
exit; |
| 114 |
} |
| 113 |
} else { |
115 |
} else { |
| 114 |
my $dbh = C4::Context->dbh; |
116 |
my $dbh = C4::Context->dbh; |
| 115 |
my @values; |
117 |
my @values; |
|
Lines 148-178
if ($do_it) {
Link Here
|
| 148 |
|
150 |
|
| 149 |
my $itemtypes = GetItemTypes( style => 'array' ); |
151 |
my $itemtypes = GetItemTypes( style => 'array' ); |
| 150 |
|
152 |
|
| 151 |
my $authvals = GetKohaAuthorisedValues("items.ccode"); |
153 |
my $authvals = GetKohaAuthorisedValues("items.ccode"); |
| 152 |
my @authvals; |
154 |
my @authvals; |
| 153 |
foreach (sort {$authvals->{$a} cmp $authvals->{$b} || $a cmp $b} keys %$authvals) { |
155 |
foreach ( sort { $authvals->{$a} cmp $authvals->{$b} || $a cmp $b } keys %$authvals ) { |
| 154 |
push @authvals, { code => $_, description => $authvals->{$_} }; |
156 |
push @authvals, { code => $_, description => $authvals->{$_} }; |
| 155 |
} |
157 |
} |
| 156 |
|
158 |
|
| 157 |
my $locations = GetKohaAuthorisedValues("items.location"); |
159 |
my $locations = GetKohaAuthorisedValues("items.location"); |
| 158 |
my @locations; |
160 |
my @locations; |
| 159 |
foreach (sort keys %$locations) { |
161 |
foreach ( sort keys %$locations ) { |
| 160 |
push @locations, { code => $_, description => "$_ - " . $locations->{$_} }; |
162 |
push @locations, { code => $_, description => "$_ - " . $locations->{$_} }; |
| 161 |
} |
163 |
} |
| 162 |
|
164 |
|
| 163 |
my @mime = ( map { +{type =>$_} } (split /[;:]/, 'CSV') ); # FIXME translation |
165 |
foreach my $kohafield (qw(items.notforloan items.materials)) { |
| 164 |
|
166 |
my $subfield_structure = GetMarcSubfieldStructureFromKohaField($kohafield); |
| 165 |
$template->param(hasdewey=>$hasdewey, |
167 |
if($subfield_structure) { |
| 166 |
haslccn => $haslccn, |
168 |
my $avlist; |
| 167 |
hascote => $hascote, |
169 |
my $avcategory = $subfield_structure->{authorised_value}; |
| 168 |
itemtypes => $itemtypes, |
170 |
if($avcategory) { |
| 169 |
CGIBranch => GetBranchesLoop(C4::Context->userenv->{'branch'}), |
171 |
$avlist = GetAuthorisedValues($avcategory); |
| 170 |
locationloop => \@locations, |
172 |
} |
| 171 |
authvals => \@authvals, |
173 |
my $kf = $kohafield; |
| 172 |
CGIextChoice => \@mime, |
174 |
$kf =~ s/^items\.//; |
| 173 |
CGIsepChoice => GetDelimiterChoices, |
175 |
$template->param( |
| 174 |
item_itype => $item_itype |
176 |
$kf => 1, |
| 175 |
); |
177 |
$kf."_label" => $subfield_structure->{liblibrarian}, |
|
|
178 |
$kf."_avlist" => $avlist |
| 179 |
); |
| 180 |
} |
| 181 |
} |
| 182 |
|
| 183 |
my @mime = ( map { +{type =>$_} } (split /[;:]/, 'CSV') ); # FIXME translation |
| 184 |
|
| 185 |
$template->param( |
| 186 |
hasdewey => $hasdewey, |
| 187 |
haslccn => $haslccn, |
| 188 |
hascote => $hascote, |
| 189 |
itemtypes => $itemtypes, |
| 190 |
CGIBranch => GetBranchesLoop( C4::Context->userenv->{'branch'} ), |
| 191 |
locationloop => \@locations, |
| 192 |
authvals => \@authvals, |
| 193 |
CGIextChoice => \@mime, |
| 194 |
CGIsepChoice => GetDelimiterChoices, |
| 195 |
item_itype => $item_itype, |
| 196 |
); |
| 176 |
|
197 |
|
| 177 |
} |
198 |
} |
| 178 |
output_html_with_http_headers $input, $cookie, $template->output; |
199 |
output_html_with_http_headers $input, $cookie, $template->output; |
|
Lines 181-536
output_html_with_http_headers $input, $cookie, $template->output;
Link Here
|
| 181 |
|
202 |
|
| 182 |
|
203 |
|
| 183 |
sub calculate { |
204 |
sub calculate { |
| 184 |
my ($line, $column, $deweydigits, $lccndigits, $cotedigits, $filters) = @_; |
205 |
my ( $line, $column, $cellvalue, $deweydigits, $lccndigits, $cotedigits, $filters ) = @_; |
| 185 |
my @mainloop; |
206 |
my @mainloop; |
| 186 |
my @loopfooter; |
207 |
my @loopfooter; |
| 187 |
my @loopcol; |
208 |
my @loopcol; |
| 188 |
my @loopline; |
209 |
my @loopline; |
| 189 |
my @looprow; |
210 |
my @looprow; |
| 190 |
my %globalline; |
211 |
my %globalline; |
| 191 |
my $grantotal =0; |
212 |
my $grantotal = 0; |
| 192 |
my $barcodelike = @$filters[13]; |
213 |
my $barcodelike = @$filters[16]; |
| 193 |
my $barcodefilter = @$filters[14]; |
214 |
my $barcodefilter = @$filters[17]; |
| 194 |
my $not; |
215 |
my $not; |
| 195 |
|
216 |
my $itemstable = ($cellvalue eq 'deleteditems') ? 'deleteditems' : 'items'; |
| 196 |
# extract parameters |
217 |
|
| 197 |
my $dbh = C4::Context->dbh; |
218 |
my $dbh = C4::Context->dbh; |
| 198 |
|
219 |
|
| 199 |
# if barcodefilter is empty set as % |
220 |
# if barcodefilter is empty set as % |
| 200 |
if($barcodefilter){ |
221 |
if ($barcodefilter) { |
| 201 |
# Check if barcodefilter is "like" or "not like" |
222 |
|
| 202 |
if(!$barcodelike){ |
223 |
# Check if barcodefilter is "like" or "not like" |
| 203 |
$not = "not"; |
224 |
if ( !$barcodelike ) { |
|
|
225 |
$not = "not"; |
| 226 |
} |
| 227 |
|
| 228 |
# Change * to % |
| 229 |
$barcodefilter =~ s/\*/%/g; |
| 204 |
} |
230 |
} |
| 205 |
# Change * to % |
|
|
| 206 |
$barcodefilter =~ s/\*/%/g; |
| 207 |
} |
| 208 |
|
231 |
|
| 209 |
# Filters |
232 |
# Filters |
| 210 |
# Checking filters |
233 |
# Checking filters |
| 211 |
# |
234 |
# |
| 212 |
my @loopfilter; |
235 |
my @loopfilter; |
| 213 |
for (my $i=0;$i<=12;$i++) { |
236 |
for ( my $i = 0 ; $i <= @$filters ; $i++ ) { |
| 214 |
my %cell; |
237 |
my %cell; |
| 215 |
if ( @$filters[$i] ) { |
238 |
if ( defined @$filters[$i] and @$filters[$i] ne '' and $i != 15 ) { |
| 216 |
if ((($i==1) or ($i==3) or ($i==5) or ($i==9)) and (@$filters[$i-1])) { |
239 |
if ( ( ( $i == 1 ) or ( $i == 3 ) or ( $i == 5 ) or ( $i == 9 ) ) and ( @$filters[ $i - 1 ] ) ) { |
| 217 |
$cell{err} = 1 if (@$filters[$i]<@$filters[$i-1]) ; |
240 |
$cell{err} = 1 if ( @$filters[$i] < @$filters[ $i - 1 ] ); |
| 218 |
} |
241 |
} |
| 219 |
$cell{filter} .= @$filters[$i]; |
242 |
$cell{filter} .= @$filters[$i]; |
| 220 |
$cell{crit} .= |
243 |
$cell{crit} .= |
| 221 |
($i== 0) ? "Dewey Classification From" : |
244 |
( $i == 0 ) ? "Dewey Classification From" |
| 222 |
($i== 1) ? "Dewey Classification To" : |
245 |
: ( $i == 1 ) ? "Dewey Classification To" |
| 223 |
($i== 2) ? "Lccn Classification From" : |
246 |
: ( $i == 2 ) ? "Lccn Classification From" |
| 224 |
($i== 3) ? "Lccn Classification To" : |
247 |
: ( $i == 3 ) ? "Lccn Classification To" |
| 225 |
($i== 4) ? "Item CallNumber From" : |
248 |
: ( $i == 4 ) ? "Item CallNumber From" |
| 226 |
($i== 5) ? "Item CallNumber To" : |
249 |
: ( $i == 5 ) ? "Item CallNumber To" |
| 227 |
($i== 6) ? "Item type" : |
250 |
: ( $i == 6 ) ? "Item type" |
| 228 |
($i== 7) ? "Publisher" : |
251 |
: ( $i == 7 ) ? "Publisher" |
| 229 |
($i== 8) ? "Publication year From" : |
252 |
: ( $i == 8 ) ? "Publication year From" |
| 230 |
($i== 9) ? "Publication year To" : |
253 |
: ( $i == 9 ) ? "Publication year To" |
| 231 |
($i==10) ? "Library :" : |
254 |
: ( $i == 10 ) ? "Library" |
| 232 |
($i==11) ? "Shelving Location :" : |
255 |
: ( $i == 11 ) ? "Shelving Location" |
| 233 |
($i==12) ? "Collection Code :" : ''; |
256 |
: ( $i == 12 ) ? "Collection Code" |
| 234 |
push @loopfilter, \%cell; |
257 |
: ( $i == 13 ) ? "Status" |
| 235 |
} |
258 |
: ( $i == 14 ) ? "Materials" |
| 236 |
} |
259 |
: ( $i == 16 and $filters->[15] == 0 ) ? "Barcode (not like)" |
| 237 |
|
260 |
: ( $i == 16 and $filters->[15] == 1 ) ? "Barcode (like)" |
| 238 |
# warn map {"filtres $_\n"} @filters[0..3]; |
261 |
: ( $i == 17 ) ? "Acquired date from" |
| 239 |
|
262 |
: ( $i == 18 ) ? "Acquired date to" |
| 240 |
my @linefilter; |
263 |
: ( $i == 19 ) ? "Removed date from" |
| 241 |
$linefilter[0] = @$filters[0] if ($line =~ /dewey/ ) ; |
264 |
: ( $i == 20 ) ? "Removed date to" |
| 242 |
$linefilter[1] = @$filters[1] if ($line =~ /dewey/ ) ; |
265 |
: ''; |
| 243 |
$linefilter[0] = @$filters[2] if ($line =~ /lccn/ ) ; |
266 |
|
| 244 |
$linefilter[1] = @$filters[3] if ($line =~ /lccn/ ) ; |
267 |
push @loopfilter, \%cell; |
| 245 |
$linefilter[0] = @$filters[4] if ($line =~ /items\.itemcallnumber/ ) ; |
268 |
} |
| 246 |
$linefilter[1] = @$filters[5] if ($line =~ /items\.itemcallnumber/ ) ; |
269 |
} |
| 247 |
if (C4::Context->preference('item-level_itypes')) { |
270 |
|
| 248 |
$linefilter[0] = @$filters[6] if ($line =~ /items\.itype/ ) ; |
271 |
@$filters[18] = C4::Dates->new(@$filters[18])->output('iso') if @$filters[18]; |
| 249 |
} else { |
272 |
@$filters[19] = C4::Dates->new(@$filters[19])->output('iso') if @$filters[19]; |
| 250 |
$linefilter[0] = @$filters[6] if ($line =~ /itemtype/ ) ; |
273 |
@$filters[20] = C4::Dates->new(@$filters[20])->output('iso') if @$filters[20]; |
| 251 |
} |
274 |
@$filters[21] = C4::Dates->new(@$filters[21])->output('iso') if @$filters[21]; |
| 252 |
$linefilter[0] = @$filters[7] if ($line =~ /publishercode/ ) ; |
275 |
|
| 253 |
$linefilter[0] = @$filters[8] if ($line =~ /publicationyear/ ) ; |
276 |
my @linefilter; |
| 254 |
$linefilter[1] = @$filters[9] if ($line =~ /publicationyear/ ) ; |
277 |
$linefilter[0] = @$filters[0] if ( $line =~ /dewey/ ); |
| 255 |
$linefilter[0] = @$filters[10] if ($line =~ /items\.homebranch/ ) ; |
278 |
$linefilter[1] = @$filters[1] if ( $line =~ /dewey/ ); |
| 256 |
$linefilter[0] = @$filters[11] if ($line =~ /items\.location/ ) ; |
279 |
$linefilter[0] = @$filters[2] if ( $line =~ /lccn/ ); |
| 257 |
$linefilter[0] = @$filters[12] if ($line =~ /items\.ccode/ ) ; |
280 |
$linefilter[1] = @$filters[3] if ( $line =~ /lccn/ ); |
| 258 |
|
281 |
$linefilter[0] = @$filters[4] if ( $line =~ /items\.itemcallnumber/ ); |
| 259 |
my @colfilter ; |
282 |
$linefilter[1] = @$filters[5] if ( $line =~ /items\.itemcallnumber/ ); |
| 260 |
$colfilter[0] = @$filters[0] if ($column =~ /dewey/ ) ; |
283 |
if ( C4::Context->preference('item-level_itypes') ) { |
| 261 |
$colfilter[1] = @$filters[1] if ($column =~ /dewey/ ) ; |
284 |
$linefilter[0] = @$filters[6] if ( $line =~ /items\.itype/ ); |
| 262 |
$colfilter[0] = @$filters[2] if ($column =~ /lccn/ ) ; |
285 |
} else { |
| 263 |
$colfilter[1] = @$filters[3] if ($column =~ /lccn/ ) ; |
286 |
$linefilter[0] = @$filters[6] if ( $line =~ /itemtype/ ); |
| 264 |
$colfilter[0] = @$filters[4] if ($column =~ /items\.itemcallnumber/ ) ; |
287 |
} |
| 265 |
$colfilter[1] = @$filters[5] if ($column =~ /items\.itemcallnumber/ ) ; |
288 |
$linefilter[0] = @$filters[7] if ( $line =~ /publishercode/ ); |
| 266 |
if (C4::Context->preference('item-level_itypes')) { |
289 |
$linefilter[0] = @$filters[8] if ( $line =~ /publicationyear/ ); |
| 267 |
$colfilter[0] = @$filters[6] if ($column =~ /items\.itype/ ) ; |
290 |
$linefilter[1] = @$filters[9] if ( $line =~ /publicationyear/ ); |
| 268 |
} else { |
291 |
|
| 269 |
$colfilter[0] = @$filters[6] if ($column =~ /itemtype/ ) ; |
292 |
$linefilter[0] = @$filters[10] if ( $line =~ /items\.homebranch/ ); |
| 270 |
} |
293 |
$linefilter[0] = @$filters[11] if ( $line =~ /items\.location/ ); |
| 271 |
$colfilter[0] = @$filters[7] if ($column =~ /publishercode/ ) ; |
294 |
$linefilter[0] = @$filters[12] if ( $line =~ /items\.ccode/ ); |
| 272 |
$colfilter[0] = @$filters[8] if ($column =~ /publicationyear/ ) ; |
295 |
$linefilter[0] = @$filters[13] if ( $line =~ /items\.notforloan/ ); |
| 273 |
$colfilter[1] = @$filters[9] if ($column =~ /publicationyear/ ) ; |
296 |
$linefilter[0] = @$filters[14] if ( $line =~ /items\.materials/ ); |
| 274 |
$colfilter[0] = @$filters[10] if ($column =~ /items\.homebranch/ ) ; |
297 |
$linefilter[0] = @$filters[17] if ( $line =~ /items\.dateaccessioned/ ); |
| 275 |
$colfilter[0] = @$filters[11] if ($column =~ /items\.location/ ) ; |
298 |
$linefilter[1] = @$filters[18] if ( $line =~ /items\.dateaccessioned/ ); |
| 276 |
$colfilter[0] = @$filters[12] if ($column =~ /items\.ccode/ ) ; |
299 |
$linefilter[0] = @$filters[19] if ( $line =~ /deleteditems\.timestamp/ ); |
| 277 |
|
300 |
$linefilter[1] = @$filters[20] if ( $line =~ /deleteditems\.timestamp/ ); |
| 278 |
# 1st, loop rows. |
301 |
|
| 279 |
my $linefield; |
302 |
my @colfilter; |
| 280 |
if (($line =~/dewey/) and ($deweydigits)) { |
303 |
$colfilter[0] = @$filters[0] if ( $column =~ /dewey/ ); |
| 281 |
$linefield .="left($line,$deweydigits)"; |
304 |
$colfilter[1] = @$filters[1] if ( $column =~ /dewey/ ); |
| 282 |
} elsif (($line=~/lccn/) and ($lccndigits)) { |
305 |
$colfilter[0] = @$filters[2] if ( $column =~ /lccn/ ); |
| 283 |
$linefield .="left($line,$lccndigits)"; |
306 |
$colfilter[1] = @$filters[3] if ( $column =~ /lccn/ ); |
| 284 |
} elsif (($line=~/items.itemcallnumber/) and ($cotedigits)) { |
307 |
$colfilter[0] = @$filters[4] if ( $column =~ /items\.itemcallnumber/ ); |
| 285 |
$linefield .="left($line,$cotedigits)"; |
308 |
$colfilter[1] = @$filters[5] if ( $column =~ /items\.itemcallnumber/ ); |
| 286 |
}else { |
309 |
if ( C4::Context->preference('item-level_itypes') ) { |
| 287 |
$linefield .= $line; |
310 |
$colfilter[0] = @$filters[6] if ( $column =~ /items\.itype/ ); |
| 288 |
} |
311 |
} else { |
| 289 |
|
312 |
$colfilter[0] = @$filters[6] if ( $column =~ /itemtype/ ); |
| 290 |
my $strsth = "SELECT DISTINCTROW $linefield FROM biblioitems |
313 |
} |
| 291 |
INNER JOIN items USING (biblioitemnumber) |
314 |
$colfilter[0] = @$filters[7] if ( $column =~ /publishercode/ ); |
| 292 |
INNER JOIN biblio ON (biblioitems.biblionumber = biblio.biblionumber) |
315 |
$colfilter[0] = @$filters[8] if ( $column =~ /publicationyear/ ); |
| 293 |
WHERE $line IS NOT NULL "; |
316 |
$colfilter[1] = @$filters[9] if ( $column =~ /publicationyear/ ); |
|
|
317 |
$colfilter[0] = @$filters[10] if ( $column =~ /items\.homebranch/ ); |
| 318 |
$colfilter[0] = @$filters[11] if ( $column =~ /items\.location/ ); |
| 319 |
$colfilter[0] = @$filters[12] if ( $column =~ /items\.ccode/ ); |
| 320 |
$colfilter[0] = @$filters[13] if ( $column =~ /items\.notforloan/ ); |
| 321 |
$colfilter[0] = @$filters[14] if ( $column =~ /items\.materials/ ); |
| 322 |
$colfilter[0] = @$filters[17] if ( $column =~ /items.dateaccessioned/ ); |
| 323 |
$colfilter[1] = @$filters[18] if ( $column =~ /items\.dateaccessioned/ ); |
| 324 |
$colfilter[0] = @$filters[19] if ( $column =~ /deleteditems\.timestamp/ ); |
| 325 |
$colfilter[1] = @$filters[20] if ( $column =~ /deleteditems\.timestamp/ ); |
| 326 |
|
| 327 |
# 1st, loop rows. |
| 328 |
my $origline = $line; |
| 329 |
$line =~ s/^items\./deleteditems./ if($cellvalue eq "deleteditems"); |
| 330 |
my $linefield; |
| 331 |
if ( ( $line =~ /dewey/ ) and ($deweydigits) ) { |
| 332 |
$linefield = "left($line,$deweydigits)"; |
| 333 |
} elsif ( ( $line =~ /lccn/ ) and ($lccndigits) ) { |
| 334 |
$linefield = "left($line,$lccndigits)"; |
| 335 |
} elsif ( ( $line =~ /itemcallnumber/ ) and ($cotedigits) ) { |
| 336 |
$linefield = "left($line,$cotedigits)"; |
| 337 |
} elsif ( $line =~ /^deleteditems\.timestamp$/ ) { |
| 338 |
$linefield = "DATE($line)"; |
| 339 |
} else { |
| 340 |
$linefield = $line; |
| 341 |
} |
| 342 |
|
| 343 |
my $strsth = "SELECT DISTINCTROW $linefield FROM $itemstable |
| 344 |
LEFT JOIN biblioitems USING (biblioitemnumber) |
| 345 |
LEFT JOIN biblio ON (biblioitems.biblionumber = biblio.biblionumber) |
| 346 |
WHERE 1 "; |
| 294 |
$strsth .= " AND barcode $not LIKE ? " if ($barcodefilter); |
347 |
$strsth .= " AND barcode $not LIKE ? " if ($barcodefilter); |
| 295 |
if ( @linefilter ) { |
348 |
if (@linefilter) { |
| 296 |
if ($linefilter[1]){ |
349 |
if ( $linefilter[1] ) { |
| 297 |
$strsth .= " AND $line >= ? " ; |
350 |
$strsth .= " AND $line >= ? "; |
| 298 |
$strsth .= " AND $line <= ? " ; |
351 |
$strsth .= " AND $line <= ? "; |
| 299 |
} elsif ($linefilter[0]) { |
352 |
} elsif ( defined $linefilter[0] and $linefilter[0] ne '' ) { |
| 300 |
$linefilter[0] =~ s/\*/%/g; |
353 |
$linefilter[0] =~ s/\*/%/g; |
| 301 |
$strsth .= " AND $line LIKE ? " ; |
354 |
$strsth .= " AND $line LIKE ? "; |
| 302 |
} |
355 |
} |
| 303 |
} |
356 |
} |
| 304 |
$strsth .=" ORDER BY $linefield"; |
357 |
$strsth .= " ORDER BY $linefield"; |
| 305 |
$debug and print STDERR "catalogue_stats SQL: $strsth\n"; |
358 |
$debug and print STDERR "catalogue_stats SQL: $strsth\n"; |
| 306 |
|
359 |
|
| 307 |
my $sth = $dbh->prepare( $strsth ); |
360 |
my $sth = $dbh->prepare($strsth); |
| 308 |
if (( @linefilter ) and ($linefilter[1])){ |
361 |
if ( $barcodefilter and (@linefilter) and ( $linefilter[1] ) ) { |
| 309 |
$sth->execute($barcodefilter,$linefilter[0],$linefilter[1]); |
362 |
$sth->execute( $barcodefilter, $linefilter[0], $linefilter[1] ); |
| 310 |
} elsif ($barcodefilter,$linefilter[0]) { |
363 |
} elsif ( (@linefilter) and ( $linefilter[1] ) ) { |
| 311 |
$sth->execute($barcodefilter,$linefilter[0]); |
364 |
$sth->execute( $linefilter[0], $linefilter[1] ); |
| 312 |
} elsif ($barcodefilter) { |
365 |
} elsif ( $barcodefilter and $linefilter[0] ) { |
| 313 |
$sth->execute($barcodefilter); |
366 |
$sth->execute( $barcodefilter, $linefilter[0] ); |
| 314 |
}else{ |
367 |
} elsif ( $linefilter[0] ) { |
| 315 |
$sth->execute(); |
368 |
$sth->execute($linefilter[0]); |
| 316 |
} |
369 |
} elsif ($barcodefilter) { |
| 317 |
while ( my ($celvalue) = $sth->fetchrow) { |
370 |
$sth->execute($barcodefilter); |
| 318 |
my %cell; |
371 |
} else { |
| 319 |
if ($celvalue) { |
372 |
$sth->execute(); |
| 320 |
$cell{rowtitle} = $celvalue; |
373 |
} |
| 321 |
# } else { |
374 |
my $rowauthvals = GetKohaAuthorisedValues($origline); |
| 322 |
# $cell{rowtitle} = ""; |
375 |
while ( my ($celvalue) = $sth->fetchrow ) { |
| 323 |
} |
376 |
my %cell; |
| 324 |
$cell{totalrow} = 0; |
377 |
if (defined $celvalue and $celvalue ne '') { |
| 325 |
push @loopline, \%cell; |
378 |
if($rowauthvals and $rowauthvals->{$celvalue}) { |
| 326 |
} |
379 |
$cell{rowtitle} = $rowauthvals->{$celvalue}; |
| 327 |
|
380 |
} else { |
| 328 |
# 2nd, loop cols. |
381 |
$cell{rowtitle} = $celvalue; |
| 329 |
my $colfield; |
382 |
} |
| 330 |
if (($column =~/dewey/) and ($deweydigits)) { |
383 |
$cell{value} = $celvalue; |
| 331 |
$colfield = "left($column,$deweydigits)"; |
384 |
} |
| 332 |
}elsif (($column=~/lccn/) and ($lccndigits)) { |
385 |
else { |
| 333 |
$colfield = "left($column,$lccndigits)"; |
386 |
$cell{rowtitle} = "NULL"; |
| 334 |
}elsif (($column=~/itemcallnumber/) and ($cotedigits)) { |
387 |
$cell{value} = "zzEMPTY"; |
| 335 |
$colfield = "left($column,$cotedigits)"; |
388 |
} |
| 336 |
}else { |
389 |
$cell{totalrow} = 0; |
| 337 |
$colfield = $column; |
390 |
push @loopline, \%cell; |
| 338 |
} |
391 |
} |
| 339 |
|
392 |
|
| 340 |
my $strsth2 = " |
393 |
# 2nd, loop cols. |
| 341 |
SELECT distinctrow $colfield |
394 |
my $origcolumn = $column; |
| 342 |
FROM biblioitems |
395 |
$column =~ s/^items\./deleteditems./ if($cellvalue eq "deleteditems"); |
| 343 |
INNER JOIN items |
396 |
my $colfield; |
| 344 |
USING (biblioitemnumber) |
397 |
if ( ( $column =~ /dewey/ ) and ($deweydigits) ) { |
| 345 |
INNER JOIN biblio |
398 |
$colfield = "left($column,$deweydigits)"; |
| 346 |
ON (biblioitems.biblionumber = biblio.biblionumber) |
399 |
} elsif ( ( $column =~ /lccn/ ) and ($lccndigits) ) { |
| 347 |
WHERE $column IS NOT NULL "; |
400 |
$colfield = "left($column,$lccndigits)"; |
| 348 |
$strsth2 .= " AND barcode $not LIKE ?" if $barcodefilter; |
401 |
} elsif ( ( $column =~ /itemcallnumber/ ) and ($cotedigits) ) { |
| 349 |
|
402 |
$colfield = "left($column,$cotedigits)"; |
| 350 |
if (( @colfilter ) and ($colfilter[1])) { |
403 |
} elsif ( $column =~ /^deleteditems\.timestamp$/ ) { |
| 351 |
$strsth2 .= " AND $column> ? AND $column< ?"; |
404 |
$colfield = "DATE($column)"; |
| 352 |
}elsif ($colfilter[0]){ |
405 |
} else { |
| 353 |
$colfilter[0] =~ s/\*/%/g; |
406 |
$colfield = $column; |
| 354 |
$strsth2 .= " AND $column LIKE ? "; |
407 |
} |
| 355 |
} |
408 |
|
| 356 |
$strsth2 .= " ORDER BY $colfield"; |
409 |
my $strsth2 = " |
| 357 |
$debug and print STDERR "SQL: $strsth2"; |
410 |
SELECT distinctrow $colfield |
| 358 |
my $sth2 = $dbh->prepare( $strsth2 ); |
411 |
FROM $itemstable |
| 359 |
if ((@colfilter) and ($colfilter[1])) { |
412 |
LEFT JOIN biblioitems |
| 360 |
$sth2->execute($barcodefilter,$colfilter[0],$colfilter[1]); |
413 |
USING (biblioitemnumber) |
| 361 |
} elsif ($colfilter[0]){ |
414 |
LEFT JOIN biblio |
| 362 |
$sth2->execute($barcodefilter,$colfilter[0]); |
415 |
ON (biblioitems.biblionumber = biblio.biblionumber) |
| 363 |
} elsif ($barcodefilter){ |
416 |
WHERE 1 "; |
| 364 |
$sth2->execute($barcodefilter); |
417 |
$strsth2 .= " AND barcode $not LIKE ?" if $barcodefilter; |
| 365 |
} else { |
418 |
|
| 366 |
$sth2->execute(); |
419 |
if ( (@colfilter) and ( $colfilter[1] ) ) { |
| 367 |
} |
420 |
$strsth2 .= " AND $column >= ? AND $column <= ?"; |
| 368 |
while (my ($celvalue) = $sth2->fetchrow) { |
421 |
} elsif ( defined $colfilter[0] and $colfilter[0] ne '' ) { |
| 369 |
my %cell; |
422 |
$colfilter[0] =~ s/\*/%/g; |
| 370 |
my %ft; |
423 |
$strsth2 .= " AND $column LIKE ? "; |
| 371 |
if ($celvalue) { |
424 |
} |
| 372 |
$cell{coltitle} = $celvalue; |
425 |
$strsth2 .= " ORDER BY $colfield"; |
| 373 |
# } else { |
426 |
$debug and print STDERR "SQL: $strsth2"; |
| 374 |
# $cell{coltitle} = ""; |
427 |
my $sth2 = $dbh->prepare($strsth2); |
| 375 |
} |
428 |
if ( $barcodefilter and (@colfilter) and ( $colfilter[1] ) ) { |
| 376 |
$ft{totalcol} = 0; |
429 |
$sth2->execute( $barcodefilter, $colfilter[0], $colfilter[1] ); |
| 377 |
push @loopcol, \%cell; |
430 |
} elsif ( (@colfilter) and ( $colfilter[1] ) ) { |
| 378 |
} |
431 |
$sth2->execute( $colfilter[0], $colfilter[1] ); |
| 379 |
|
432 |
} elsif ( $barcodefilter && $colfilter[0] ) { |
| 380 |
my $i=0; |
433 |
$sth2->execute( $barcodefilter , $colfilter[0] ); |
| 381 |
my @totalcol; |
434 |
} elsif ( $colfilter[0]) { |
| 382 |
my $hilighted=-1; |
435 |
$sth2->execute( $colfilter[0] ); |
| 383 |
|
436 |
} elsif ($barcodefilter) { |
| 384 |
#Initialization of cell values..... |
437 |
$sth2->execute($barcodefilter); |
| 385 |
my %table; |
438 |
} else { |
| 386 |
# warn "init table"; |
439 |
$sth2->execute(); |
| 387 |
foreach my $row ( @loopline ) { |
440 |
} |
| 388 |
foreach my $col ( @loopcol ) { |
441 |
my $colauthvals = GetKohaAuthorisedValues($origcolumn); |
| 389 |
# warn " init table : $row->{rowtitle} / $col->{coltitle} "; |
442 |
while ( my ($celvalue) = $sth2->fetchrow ) { |
| 390 |
$table{$row->{rowtitle}}->{$col->{coltitle}}=0; |
443 |
my %cell; |
| 391 |
} |
444 |
if (defined $celvalue and $celvalue ne '') { |
| 392 |
$table{$row->{rowtitle}}->{totalrow}=0; |
445 |
if($colauthvals and $colauthvals->{$celvalue}) { |
| 393 |
} |
446 |
$cell{coltitle} = $colauthvals->{$celvalue}; |
| 394 |
|
447 |
} else { |
| 395 |
# preparing calculation |
448 |
$cell{coltitle} = $celvalue; |
|
|
449 |
} |
| 450 |
$cell{value} = $celvalue; |
| 451 |
} |
| 452 |
else { |
| 453 |
$cell{coltitle} = "NULL"; |
| 454 |
$cell{value} = "zzEMPTY"; |
| 455 |
} |
| 456 |
$cell{totalcol} = 0; |
| 457 |
push @loopcol, \%cell; |
| 458 |
} |
| 459 |
|
| 460 |
my $i = 0; |
| 461 |
my @totalcol; |
| 462 |
my $hilighted = -1; |
| 463 |
|
| 464 |
#Initialization of cell values..... |
| 465 |
my %table; |
| 466 |
|
| 467 |
foreach my $row (@loopline) { |
| 468 |
foreach my $col (@loopcol) { |
| 469 |
$table{ $row->{value} }->{ $col->{value} } = 0; |
| 470 |
} |
| 471 |
$table{ $row->{value} }->{totalrow} = 0; |
| 472 |
} |
| 473 |
|
| 474 |
# preparing calculation |
| 475 |
my $select_cellvalue = " COUNT(*) "; |
| 476 |
$select_cellvalue = " COUNT(DISTINCT biblioitems.biblionumber) " if($cellvalue eq 'biblios'); |
| 396 |
my $strcalc = " |
477 |
my $strcalc = " |
| 397 |
SELECT $linefield, $colfield, count(*) |
478 |
SELECT $linefield, $colfield, $select_cellvalue |
| 398 |
FROM biblioitems |
479 |
FROM $itemstable |
| 399 |
INNER JOIN items ON (items.biblioitemnumber = biblioitems.biblioitemnumber) |
480 |
LEFT JOIN biblioitems ON ($itemstable.biblioitemnumber = biblioitems.biblioitemnumber) |
| 400 |
INNER JOIN biblio ON (biblioitems.biblionumber = biblio.biblionumber) |
481 |
LEFT JOIN biblio ON (biblioitems.biblionumber = biblio.biblionumber) |
| 401 |
WHERE 1 "; |
482 |
WHERE 1 "; |
| 402 |
$strcalc .= "AND barcode $not like ? " if ($barcodefilter); |
483 |
$strcalc .= "AND barcode $not like ? " if ($barcodefilter); |
| 403 |
|
484 |
|
| 404 |
if (@$filters[0]){ |
485 |
if ( @$filters[0] ) { |
| 405 |
@$filters[0]=~ s/\*/%/g; |
486 |
@$filters[0] =~ s/\*/%/g; |
| 406 |
$strcalc .= " AND dewey >" . @$filters[0]; |
487 |
$strcalc .= " AND dewey >" . @$filters[0]; |
| 407 |
} |
488 |
} |
| 408 |
if (@$filters[1]){ |
489 |
if ( @$filters[1] ) { |
| 409 |
@$filters[1]=~ s/\*/%/g ; |
490 |
@$filters[1] =~ s/\*/%/g; |
| 410 |
$strcalc .= " AND dewey <" . @$filters[1]; |
491 |
$strcalc .= " AND dewey <" . @$filters[1]; |
| 411 |
} |
492 |
} |
| 412 |
if (@$filters[2]){ |
493 |
if ( @$filters[2] ) { |
| 413 |
@$filters[2]=~ s/\*/%/g ; |
494 |
@$filters[2] =~ s/\*/%/g; |
| 414 |
$strcalc .= " AND lccn >" . @$filters[2]; |
495 |
$strcalc .= " AND lccn >" . @$filters[2]; |
| 415 |
} |
496 |
} |
| 416 |
if (@$filters[3]){ |
497 |
if ( @$filters[3] ) { |
| 417 |
@$filters[3]=~ s/\*/%/g; |
498 |
@$filters[3] =~ s/\*/%/g; |
| 418 |
$strcalc .= " AND lccn <" . @$filters[3]; |
499 |
$strcalc .= " AND lccn <" . @$filters[3]; |
| 419 |
} |
500 |
} |
| 420 |
if (@$filters[4]){ |
501 |
if ( @$filters[4] ) { |
| 421 |
@$filters[4]=~ s/\*/%/g ; |
502 |
@$filters[4] =~ s/\*/%/g; |
| 422 |
$strcalc .= " AND items.itemcallnumber >=" . $dbh->quote(@$filters[4]); |
503 |
$strcalc .= " AND $itemstable.itemcallnumber >=" . $dbh->quote( @$filters[4] ); |
| 423 |
} |
504 |
} |
| 424 |
|
505 |
|
| 425 |
if (@$filters[5]){ |
506 |
if ( @$filters[5] ) { |
| 426 |
@$filters[5]=~ s/\*/%/g; |
507 |
@$filters[5] =~ s/\*/%/g; |
| 427 |
$strcalc .= " AND items.itemcallnumber <=" . $dbh->quote(@$filters[5]); |
508 |
$strcalc .= " AND $itemstable.itemcallnumber <=" . $dbh->quote( @$filters[5] ); |
| 428 |
} |
509 |
} |
| 429 |
|
510 |
|
| 430 |
if (@$filters[6]){ |
511 |
if ( @$filters[6] ) { |
| 431 |
@$filters[6]=~ s/\*/%/g; |
512 |
@$filters[6] =~ s/\*/%/g; |
| 432 |
$strcalc .= " AND " . |
513 |
$strcalc .= " AND " . ( C4::Context->preference('item-level_itypes') ? "$itemstable.itype" : 'biblioitems.itemtype' ) . " LIKE '" . @$filters[6] . "'"; |
| 433 |
(C4::Context->preference('item-level_itypes') ? 'items.itype' : 'biblioitems.itemtype') |
514 |
} |
| 434 |
. " LIKE '" . @$filters[6] ."'"; |
515 |
|
| 435 |
} |
516 |
if ( @$filters[7] ) { |
| 436 |
|
517 |
@$filters[7] =~ s/\*/%/g; |
| 437 |
if (@$filters[7]){ |
518 |
@$filters[7] .= "%" unless @$filters[7] =~ /%/; |
| 438 |
@$filters[7]=~ s/\*/%/g; |
519 |
$strcalc .= " AND biblioitems.publishercode LIKE \"" . @$filters[7] . "\""; |
| 439 |
@$filters[7].="%" unless @$filters[7]=~/%/; |
520 |
} |
| 440 |
$strcalc .= " AND biblioitems.publishercode LIKE \"" . @$filters[7] ."\""; |
521 |
if ( @$filters[8] ) { |
| 441 |
} |
522 |
@$filters[8] =~ s/\*/%/g; |
| 442 |
if (@$filters[8]){ |
|
|
| 443 |
@$filters[8]=~ s/\*/%/g; |
| 444 |
$strcalc .= " AND " . |
523 |
$strcalc .= " AND " . |
| 445 |
(C4::Context->preference('marcflavour') eq 'UNIMARC' ? 'publicationyear' : 'copyrightdate') |
524 |
(C4::Context->preference('marcflavour') eq 'UNIMARC' ? 'publicationyear' : 'copyrightdate') |
| 446 |
. ">" . @$filters[8]; |
525 |
. ">" . @$filters[8]; |
| 447 |
} |
526 |
} |
| 448 |
if (@$filters[9]){ |
527 |
if ( @$filters[9] ) { |
| 449 |
@$filters[9]=~ s/\*/%/g; |
528 |
@$filters[9] =~ s/\*/%/g; |
| 450 |
$strcalc .= " AND " . |
529 |
$strcalc .= " AND " . |
| 451 |
(C4::Context->preference('marcflavour') eq 'UNIMARC' ? 'publicationyear' : 'copyrightdate') |
530 |
(C4::Context->preference('marcflavour') eq 'UNIMARC' ? 'publicationyear' : 'copyrightdate') |
| 452 |
. "<" . @$filters[9]; |
531 |
. "<" . @$filters[9]; |
| 453 |
} |
532 |
} |
| 454 |
if (@$filters[10]){ |
533 |
if ( @$filters[10] ) { |
| 455 |
@$filters[10]=~ s/\*/%/g; |
534 |
@$filters[10] =~ s/\*/%/g; |
| 456 |
$strcalc .= " AND items.homebranch LIKE '" . @$filters[10] ."'"; |
535 |
$strcalc .= " AND $itemstable.homebranch LIKE '" . @$filters[10] . "'"; |
| 457 |
} |
536 |
} |
| 458 |
if (@$filters[11]){ |
537 |
if ( @$filters[11] ) { |
| 459 |
@$filters[11]=~ s/\*/%/g; |
538 |
@$filters[11] =~ s/\*/%/g; |
| 460 |
$strcalc .= " AND items.location LIKE '" . @$filters[11] ."'"; |
539 |
$strcalc .= " AND $itemstable.location LIKE '" . @$filters[11] . "'"; |
| 461 |
} |
540 |
} |
| 462 |
if (@$filters[12]){ |
541 |
if ( @$filters[12] ) { |
| 463 |
@$filters[12]=~ s/\*/%/g; |
542 |
@$filters[12] =~ s/\*/%/g; |
| 464 |
$strcalc .= " AND items.ccode LIKE '" . @$filters[12] ."'"; |
543 |
$strcalc .= " AND $itemstable.ccode LIKE '" . @$filters[12] . "'"; |
| 465 |
} |
544 |
} |
| 466 |
|
545 |
if ( defined @$filters[13] and @$filters[13] ne '' ) { |
| 467 |
$strcalc .= " group by $linefield, $colfield order by $linefield,$colfield"; |
546 |
@$filters[13] =~ s/\*/%/g; |
| 468 |
$debug and warn "SQL: $strcalc"; |
547 |
$strcalc .= " AND $itemstable.notforloan LIKE '" . @$filters[13] . "'"; |
| 469 |
my $dbcalc = $dbh->prepare($strcalc); |
548 |
} |
| 470 |
if($barcodefilter){ |
549 |
if ( defined @$filters[14] and @$filters[14] ne '' ) { |
| 471 |
$dbcalc->execute($barcodefilter); |
550 |
@$filters[14] =~ s/\*/%/g; |
| 472 |
}else{ |
551 |
$strcalc .= " AND $itemstable.materials LIKE '" . @$filters[14] . "'"; |
| 473 |
$dbcalc->execute(); |
552 |
} |
| 474 |
} |
553 |
if ( @$filters[17] ) { |
| 475 |
# warn "filling table"; |
554 |
@$filters[17] =~ s/\*/%/g; |
| 476 |
my $emptycol; |
555 |
$strcalc .= " AND $itemstable.dateaccessioned >= '@$filters[17]' "; |
| 477 |
while (my ($row, $col, $value) = $dbcalc->fetchrow) { |
556 |
} |
| 478 |
# warn "filling table $row / $col / $value "; |
557 |
if ( @$filters[18] ) { |
| 479 |
$emptycol = 1 if (!defined($col)); |
558 |
@$filters[18] =~ s/\*/%/g; |
| 480 |
$col = "zzEMPTY" if (!defined($col)); |
559 |
$strcalc .= " AND $itemstable.dateaccessioned <= '@$filters[18]' "; |
| 481 |
$row = "zzEMPTY" if (!defined($row)); |
560 |
} |
| 482 |
|
561 |
if ( $cellvalue eq 'deleteditems' and @$filters[19] ) { |
| 483 |
$table{$row}->{$col}+=$value; |
562 |
@$filters[19] =~ s/\*/%/g; |
| 484 |
$table{$row}->{totalrow}+=$value; |
563 |
$strcalc .= " AND DATE(deleteditems.timestamp) >= '@$filters[19]' "; |
| 485 |
$grantotal += $value; |
564 |
} |
| 486 |
} |
565 |
if ( $cellvalue eq 'deleteditems' and @$filters[20] ) { |
| 487 |
|
566 |
@$filters[20] =~ s/\*/%/g; |
| 488 |
# my %cell = {rowtitle => 'zzROWEMPTY'}; |
567 |
$strcalc .= " AND DATE(deleteditems.timestamp) <= '@$filters[20]' "; |
| 489 |
# push @loopline,\%cell; |
568 |
} |
| 490 |
# undef %cell; |
569 |
$strcalc .= " group by $linefield, $colfield order by $linefield,$colfield"; |
| 491 |
# my %cell; |
570 |
$debug and warn "SQL: $strcalc"; |
| 492 |
# %cell = {coltitle => "zzEMPTY"}; |
571 |
my $dbcalc = $dbh->prepare($strcalc); |
| 493 |
push @loopcol,{coltitle => "NULL"} if ($emptycol); |
572 |
if ($barcodefilter) { |
| 494 |
|
573 |
$dbcalc->execute($barcodefilter); |
| 495 |
foreach my $row ( sort keys %table ) { |
574 |
} else { |
| 496 |
my @loopcell; |
575 |
$dbcalc->execute(); |
| 497 |
#@loopcol ensures the order for columns is common with column titles |
576 |
} |
| 498 |
# and the number matches the number of columns |
577 |
|
| 499 |
foreach my $col ( @loopcol ) { |
578 |
while ( my ( $row, $col, $value ) = $dbcalc->fetchrow ) { |
| 500 |
my $value =$table{$row}->{($col->{coltitle} eq "NULL")?"zzEMPTY":$col->{coltitle}}; |
579 |
|
| 501 |
push @loopcell, {value => $value } ; |
580 |
$col = "zzEMPTY" if ( !defined($col) ); |
| 502 |
} |
581 |
$row = "zzEMPTY" if ( !defined($row) ); |
| 503 |
push @looprow,{ 'rowtitle' => ($row eq "zzEMPTY")?"NULL":$row, |
582 |
|
| 504 |
'loopcell' => \@loopcell, |
583 |
$table{$row}->{$col} += $value; |
| 505 |
'hilighted' => ($hilighted *= -1 > 0), |
584 |
$table{$row}->{totalrow} += $value; |
| 506 |
'totalrow' => $table{$row}->{totalrow} |
585 |
$grantotal += $value; |
| 507 |
}; |
586 |
} |
| 508 |
} |
587 |
|
| 509 |
|
588 |
foreach my $row ( @loopline ) { |
| 510 |
# warn "footer processing"; |
589 |
my @loopcell; |
| 511 |
foreach my $col ( @loopcol ) { |
590 |
|
| 512 |
my $total=0; |
591 |
#@loopcol ensures the order for columns is common with column titles |
| 513 |
foreach my $row ( @looprow ) { |
592 |
# and the number matches the number of columns |
| 514 |
$total += $table{($row->{rowtitle} eq "NULL")?"zzEMPTY":$row->{rowtitle}}->{($col->{coltitle} eq "NULL")?"zzEMPTY":$col->{coltitle}}; |
593 |
foreach my $col (@loopcol) { |
| 515 |
# warn "value added ".$table{$row->{rowtitle}}->{$col->{coltitle}}. "for line ".$row->{rowtitle}; |
594 |
my $value = $table{$row->{value}}->{ $col->{value} }; |
| 516 |
} |
595 |
push @loopcell, { value => $value }; |
| 517 |
# warn "summ for column ".$col->{coltitle}." = ".$total; |
596 |
} |
| 518 |
push @loopfooter, {'totalcol' => $total}; |
597 |
push @looprow, |
| 519 |
} |
598 |
{ 'rowtitle' => $row->{rowtitle}, |
| 520 |
|
599 |
'value' => $row->{value}, |
| 521 |
|
600 |
'loopcell' => \@loopcell, |
| 522 |
# the header of the table |
601 |
'hilighted' => ( $hilighted *= -1 > 0 ), |
| 523 |
$globalline{loopfilter}=\@loopfilter; |
602 |
'totalrow' => $table{$row->{value}}->{totalrow} |
| 524 |
# the core of the table |
603 |
}; |
| 525 |
$globalline{looprow} = \@looprow; |
604 |
} |
| 526 |
$globalline{loopcol} = \@loopcol; |
605 |
|
| 527 |
# # the foot (totals by borrower type) |
606 |
foreach my $col (@loopcol) { |
| 528 |
$globalline{loopfooter} = \@loopfooter; |
607 |
my $total = 0; |
| 529 |
$globalline{total}= $grantotal; |
608 |
foreach my $row (@looprow) { |
| 530 |
$globalline{line} = $line; |
609 |
$total += $table{ $row->{value} }->{ $col->{value} }; |
| 531 |
$globalline{column} = $column; |
610 |
} |
| 532 |
push @mainloop,\%globalline; |
|
|
| 533 |
return \@mainloop; |
| 534 |
} |
| 535 |
|
611 |
|
| 536 |
1; |
612 |
push @loopfooter, { 'totalcol' => $total }; |
|
|
613 |
} |
| 614 |
|
| 615 |
# the header of the table |
| 616 |
$globalline{loopfilter} = \@loopfilter; |
| 617 |
|
| 618 |
# the core of the table |
| 619 |
$globalline{looprow} = \@looprow; |
| 620 |
$globalline{loopcol} = \@loopcol; |
| 621 |
|
| 622 |
# the foot (totals by borrower type) |
| 623 |
$globalline{loopfooter} = \@loopfooter; |
| 624 |
$globalline{total} = $grantotal; |
| 625 |
$globalline{line} = $line; |
| 626 |
$globalline{column} = $column; |
| 627 |
push @mainloop, \%globalline; |
| 628 |
return \@mainloop; |
| 629 |
} |