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