3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
34 use Koha::AuthorisedValues;
37 use Koha::Patron::Attribute::Types;
41 reports/issues_stats.pl
45 Plugin that shows circulation stats
49 # my $debug = 1; # override for now.
51 my $fullreportname = "reports/issues_stats.tt";
52 my $do_it = $input->param('do_it');
53 my $line = $input->param("Line");
54 my $column = $input->param("Column");
55 my @filters = $input->multi_param("Filter");
56 $filters[0] = eval { output_pref( { dt => dt_from_string( $filters[0]), dateonly => 1, dateformat => 'iso' } ); }
58 $filters[1] = eval { output_pref( { dt => dt_from_string( $filters[1]), dateonly => 1, dateformat => 'iso' } ); }
60 my $podsp = $input->param("DisplayBy");
61 my $type = $input->param("PeriodTypeSel");
62 my $daysel = $input->param("PeriodDaySel");
63 my $monthsel = $input->param("PeriodMonthSel");
64 my $calc = $input->param("Cellvalue");
65 my $output = $input->param("output");
66 my $basename = $input->param("basename");
68 my $attribute_filters;
69 my $vars = $input->Vars;
70 foreach(keys %$vars) {
71 if(/^Filter_borrower_attributes\.(.*)/) {
72 $attribute_filters->{$1} = $vars->{$_};
77 my ($template, $borrowernumber, $cookie) = get_template_and_user({
78 template_name => $fullreportname,
81 flagsrequired => {reports => '*'},
84 our $sep = $input->param("sep") // ';';
85 $sep = "\t" if ($sep eq 'tabulation');
86 $template->param(do_it => $do_it,
89 our $itemtypes = Koha::ItemTypes->search_with_localization->unblessed;
91 our @patron_categories = Koha::Patron::Categories->search_with_library_limits({}, {order_by => ['description']});
93 our $locations = { map { ( $_->{authorised_value} => $_->{lib} ) } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => 'items.location' }, { order_by => ['description'] } ) };
94 our $ccodes = { map { ( $_->{authorised_value} => $_->{lib} ) } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => 'items.ccode' }, { order_by => ['description'] } ) };
96 our $Bsort1 = GetAuthorisedValues("Bsort1");
97 our $Bsort2 = GetAuthorisedValues("Bsort2");
98 my ($hassort1,$hassort2);
99 $hassort1=1 if $Bsort1;
100 $hassort2=1 if $Bsort2;
104 my $results = calculate( $line, $column, $podsp, $type, $daysel, $monthsel, $calc, \@filters, $attribute_filters);
105 if ( $output eq "screen" ) {
107 # Printing results to screen
108 $template->param( mainloop => $results );
109 output_html_with_http_headers $input, $cookie, $template->output;
112 # Printing to a csv file
113 print $input->header(
114 -type => 'application/vnd.sun.xml.calc',
115 -encoding => 'utf-8',
116 -attachment => "$basename.csv",
117 -filename => "$basename.csv"
119 my $cols = @$results[0]->{loopcol};
120 my $lines = @$results[0]->{looprow};
123 print @$results[0]->{line} . "/" . @$results[0]->{column} . $sep;
126 foreach my $col (@$cols) {
127 print $col->{coltitle} . $sep;
132 foreach my $line (@$lines) {
133 my $x = $line->{loopcell};
134 print $line->{rowtitle} . $sep;
135 print map { $_->{value} . $sep } @$x;
136 print $line->{totalrow}, "\n";
141 $cols = @$results[0]->{loopfooter};
142 print map {$sep.$_->{totalcol}} @$cols;
143 print $sep.@$results[0]->{total};
149 my $dbh = C4::Context->dbh;
153 foreach (sort keys %$locations) {
154 push @locations, { code => $_, description => "$_ - " . $locations->{$_} };
158 foreach (sort {$ccodes->{$a} cmp $ccodes->{$b}} keys %$ccodes) {
159 push @ccodes, { code => $_, description => $ccodes->{$_} };
162 my $CGIextChoice = ( 'CSV' ); # FIXME translation
163 my $CGIsepChoice=GetDelimiterChoices;
165 my $library_id = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
166 my $attribute_types = Koha::Patron::Attribute::Types->search_with_library_limits({}, {}, $library_id);
167 my %attribute_types_by_class;
168 while ( my ( $attribute_type ) = $attribute_types->next ) {
169 $attribute_type = $attribute_type->unblessed;
170 if ($attribute_type->{authorised_value_category}) {
171 my $authorised_values = C4::Koha::GetAuthorisedValues(
172 $attribute_type->{authorised_value_category});
174 foreach my $authorised_value (@$authorised_values) {
175 push @{ $attribute_type->{authorised_values} }, $authorised_value;
178 push @{ $attribute_types_by_class{$attribute_type->{class}} }, $attribute_type;
182 categoryloop => \@patron_categories,
183 itemtypes => $itemtypes,
184 locationloop => \@locations,
185 ccodeloop => \@ccodes,
186 hassort1 => $hassort1,
187 hassort2 => $hassort2,
190 CGIextChoice => $CGIextChoice,
191 CGIsepChoice => $CGIsepChoice,
192 attribute_types_by_class => \%attribute_types_by_class,
194 output_html_with_http_headers $input, $cookie, $template->output;
197 my ( $line, $column, $dsp, $type, $daysel, $monthsel, $process, $filters, $attribute_filters ) = @_;
206 my $dbh = C4::Context->dbh;
208 my ($line_attribute_type, $column_attribute_type);
209 if($line =~ /^borrower_attributes\.(.*)/) {
210 $line_attribute_type = $1;
211 $line = "borrower_attributes.attribute";
213 if($column =~ /^borrower_attributes\.(.*)/) {
214 $column_attribute_type = $1;
215 $column = "borrower_attributes.attribute";
222 for ( my $i = 0 ; $i <= @$filters ; $i++ ) {
224 ( @$filters[$i] ) or next;
225 if ( ( $i == 1 ) and ( @$filters[ $i - 1 ] ) ) {
226 $cell{err} = 1 if ( @$filters[$i] < @$filters[ $i - 1 ] );
228 # format the dates filters, otherwise just fill as is
230 $cell{filter} = @$filters[$i];
232 $cell{filter} = eval { output_pref( { dt => dt_from_string( @$filters[$i] ), dateonly => 1 }); }
233 if ( @$filters[$i] );
237 push @loopfilter, \%cell;
239 foreach (keys %$attribute_filters) {
240 next unless $attribute_filters->{$_};
241 push @loopfilter, { crit => "$_ =", filter => $attribute_filters->{$_} };
243 push @loopfilter, { crit => "Event", filter => $type };
244 push @loopfilter, { crit => "Display by", filter => $dsp } if ($dsp);
245 push @loopfilter, { crit => "Select Day", filter => $daysel } if ($daysel);
246 push @loopfilter, { crit => "Select Month", filter => $monthsel } if ($monthsel);
249 $debug and warn "filtres " . join "|", @$filters;
250 my ( $colsource, $linesource ) = ('', '');
251 $linefilter[1] = @$filters[1] if ( $line =~ /datetime/ );
253 ( $line =~ /datetime/ ) ? @$filters[0]
254 : ( $line =~ /category/ ) ? @$filters[2]
255 : ( $line =~ /itemtype/ ) ? @$filters[3]
256 : ( $line =~ /^branch/ ) ? @$filters[4]
257 : ( $line =~ /ccode/ ) ? @$filters[5]
258 : ( $line =~ /location/ ) ? @$filters[6]
259 : ( $line =~ /sort1/ ) ? @$filters[9]
260 : ( $line =~ /sort2/ ) ? @$filters[10]
261 : ( $line =~ /homebranch/) ? @$filters[11]
262 : ( $line =~ /holdingbranch/) ? @$filters[12]
263 : ( $line =~ /borrowers.branchcode/ ) ? @$filters[13]
264 : ( $line_attribute_type ) ? $attribute_filters->{$line_attribute_type}
267 if ( $line =~ /ccode/ or $line =~ /location/ or $line =~ /homebranch/ or $line =~ /holdingbranch/ ) {
268 $linesource = 'items';
272 $colfilter[1] = @$filters[1] if ($column =~ /datetime/);
274 ( $column =~ /datetime/ ) ? @$filters[0]
275 : ( $column =~ /category/ ) ? @$filters[2]
276 : ( $column =~ /itemtype/ ) ? @$filters[3]
277 : ( $column =~ /^branch/ ) ? @$filters[4]
278 : ( $column =~ /ccode/ ) ? @$filters[5]
279 : ( $column =~ /location/ ) ? @$filters[6]
280 : ( $column =~ /sort1/ ) ? @$filters[9]
281 : ( $column =~ /sort1/ ) ? @$filters[10]
282 : ( $column =~ /homebranch/) ? @$filters[11]
283 : ( $column =~ /holdingbranch/) ? @$filters[12]
284 : ( $column =~ /borrowers.branchcode/ ) ? @$filters[13]
285 : ( $column_attribute_type ) ? $attribute_filters->{$column_attribute_type}
288 if ( $column =~ /ccode/ or $column =~ /location/ or $column =~ /homebranch/ or $column =~ /holdingbranch/ ) {
289 $colsource = 'items';
294 if ( $line =~ /datetime/ ) {
296 # by Day, Month, Year or Hour (1,2,3,4 respectively)
298 ( $dsp == 1 ) ? " dayname($line)"
299 : ( $dsp == 2 ) ? "monthname($line)"
300 : ( $dsp == 3 ) ? " Year($line)"
301 : ( $dsp == 4 ) ? "extract(hour from $line)"
302 : 'date_format(`datetime`,"%Y-%m-%d")'; # Probably should be left alone or passed through Koha::Dates
307 ( $linefield =~ /dayname/ ) ? "weekday($line)"
308 : ( $linefield =~ /^month/ ) ? " month($line)"
312 if($line_attribute_type) {
313 $strsth = "SELECT attribute FROM borrower_attributes WHERE code = '$line_attribute_type' ";
315 $strsth = "SELECT distinctrow $linefield FROM statistics ";
317 # get stats on items if ccode or location, otherwise borrowers.
319 ( $linesource eq 'items' )
320 ? " LEFT JOIN items ON (statistics.itemnumber = items.itemnumber) "
321 : " LEFT JOIN borrowers ON (statistics.borrowernumber = borrowers.borrowernumber) ";
322 $strsth .= " WHERE $line IS NOT NULL ";
323 $strsth .= " AND $line != '' " if $line ne "datetime";
326 if ( $line =~ /datetime/ ) {
327 if ( $linefilter[1] and ( $linefilter[0] ) ) {
328 $strsth .= " AND $line between ? AND ? ";
329 } elsif ( $linefilter[1] ) {
330 $strsth .= " AND $line <= ? ";
331 } elsif ( $linefilter[0] ) {
332 $strsth .= " AND $line >= ? ";
334 $strsth .= " AND type ='" . $type . "' " if $type;
335 $strsth .= " AND dayname(datetime) ='" . $daysel . "' " if $daysel;
336 $strsth .= " AND monthname(datetime) ='" . $monthsel . "' " if $monthsel;
337 } elsif ( $linefilter[0] ) {
338 $linefilter[0] =~ s/\*/%/g;
339 $strsth .= " AND $line LIKE ? ";
341 $strsth .= " group by $linefield order by $lineorder ";
342 $debug and warn $strsth;
343 push @loopfilter, { crit => 'SQL =', sql => 1, filter => $strsth };
344 my $sth = $dbh->prepare($strsth);
345 if ( (@linefilter) and ($linefilter[0]) and ($linefilter[1]) ) {
346 $sth->execute( $linefilter[0], $linefilter[1] . " 23:59:59" );
347 } elsif ( $linefilter[1] ) {
348 $sth->execute( $linefilter[1] . " 23:59:59" );
349 } elsif ( $linefilter[0] ) {
350 $sth->execute( $linefilter[0] );
355 my $itemtypes_map = { map { $_->{itemtype} => $_ } @{ $itemtypes } };
356 while ( my ($celvalue) = $sth->fetchrow ) {
357 my %cell = ( rowtitle => $celvalue, totalrow => 0 ); # we leave 'rowtitle' as hash key (used when filling the table), and add coltitle_display
358 $cell{rowtitle_display} =
359 ( $line =~ /ccode/ ) ? $ccodes->{$celvalue}
360 : ( $line =~ /location/ ) ? $locations->{$celvalue}
361 : ( $line =~ /itemtype/ ) ? $itemtypes_map->{$celvalue}->{translated_description}
362 : $celvalue; # default fallback
363 if ( $line =~ /sort1/ ) {
365 ( $celvalue eq $_->{authorised_value} ) or next;
366 $cell{rowtitle_display} = $_->{lib} and last;
368 } elsif ( $line =~ /sort2/ ) {
370 ( $celvalue eq $_->{authorised_value} ) or next;
371 $cell{rowtitle_display} = $_->{lib} and last;
373 } elsif ($line =~ /category/) {
374 foreach my $patron_category ( @patron_categories ) {
375 ($celvalue eq $patron_category->categorycode) or next;
376 $cell{rowtitle_display} = $patron_category->description and last;
379 push @loopline, \%cell;
385 if ( $column =~ /datetime/ ) {
387 #Display by Day, Month or Year (1,2,3 respectively)
389 ( $dsp == 1 ) ? " dayname($column)"
390 : ( $dsp == 2 ) ? "monthname($column)"
391 : ( $dsp == 3 ) ? " Year($column)"
392 : ( $dsp == 4 ) ? "extract(hour from $column)"
393 : 'date_format(`datetime`,"%Y-%m-%d")'; # Probably should be left alone or passed through Koha::Dates
398 ( $colfield =~ /dayname/ ) ? "weekday($column)"
399 : ( $colfield =~ /^month/ ) ? " month($column)"
402 if($column_attribute_type) {
403 $strsth2 = "SELECT attribute FROM borrower_attributes WHERE code = '$column_attribute_type' ";
405 $strsth2 = "SELECT distinctrow $colfield FROM statistics ";
407 # get stats on items if ccode or location, otherwise borrowers.
409 ( $colsource eq 'items' )
410 ? "LEFT JOIN items ON (statistics.itemnumber = items.itemnumber) "
411 : "LEFT JOIN borrowers ON (statistics.borrowernumber = borrowers.borrowernumber) ";
412 $strsth2 .= " WHERE $column IS NOT NULL";
413 $strsth2 .= " AND $column != '' " if $column ne "datetime";
416 if ( $column =~ /datetime/ ) {
417 if ( ( $colfilter[1] ) and ( $colfilter[0] ) ) {
418 $strsth2 .= " AND $column BETWEEN ? AND ? ";
419 } elsif ( $colfilter[1] ) {
420 $strsth2 .= " AND $column <= ? ";
421 } elsif ( $colfilter[0] ) {
422 $strsth2 .= " AND $column >= ? ";
424 $strsth2 .= " AND type ='". $type ."' " if $type;
425 $strsth2 .= " AND dayname(datetime) ='". $daysel ."' " if $daysel;
426 $strsth2 .= " AND monthname(datetime) ='". $monthsel ."' " if $monthsel;
427 } elsif ($colfilter[0]) {
428 $colfilter[0] =~ s/\*/%/g;
429 $strsth2 .= " AND $column LIKE ? " ;
432 $strsth2 .= " group by $colfield order by $colorder ";
433 $debug and warn $strsth2;
434 push @loopfilter, { crit => 'SQL =', sql => 1, filter => $strsth2 };
435 my $sth2 = $dbh->prepare($strsth2);
436 if ( (@colfilter) and ($colfilter[0]) and ($colfilter[1]) ) {
437 $sth2->execute( $colfilter[0], $colfilter[1] . " 23:59:59" );
438 } elsif ( $colfilter[1] ) {
439 $sth2->execute( $colfilter[1] . " 23:59:59" );
440 } elsif ( $colfilter[0] ) {
441 $sth2->execute( $colfilter[0] );
446 while ( my ($celvalue) = $sth2->fetchrow ) {
447 my %cell = ( coltitle => $celvalue ); # we leave 'coltitle' as hash key (used when filling the table), and add coltitle_display
448 $cell{coltitle_display} =
449 ( $column =~ /ccode/ ) ? $ccodes->{$celvalue}
450 : ( $column =~ /location/ ) ? $locations->{$celvalue}
451 : ( $column =~ /itemtype/ ) ? $itemtypes_map->{$celvalue}->{translated_description}
452 : $celvalue; # default fallback
453 if ( $column =~ /sort1/ ) {
455 ( $celvalue eq $_->{authorised_value} ) or next;
456 $cell{coltitle_display} = $_->{lib} and last;
458 } elsif ( $column =~ /sort2/ ) {
460 ( $celvalue eq $_->{authorised_value} ) or next;
461 $cell{coltitle_display} = $_->{lib} and last;
463 } elsif ($column =~ /category/) {
464 foreach my $patron_category ( @patron_categories ) {
465 ($celvalue eq $patron_category->categorycode) or next;
466 $cell{coltitle_display} = $patron_category->description and last;
469 push @loopcol, \%cell;
472 #Initialization of cell values.....
474 foreach my $row (@loopline) {
475 foreach my $col (@loopcol) {
476 $debug and warn " init table : $row->{rowtitle} ( $row->{rowtitle_display} ) / $col->{coltitle} ( $col->{coltitle_display} ) ";
477 table_set(\%table, $row->{rowtitle}, $col->{coltitle}, 0);
479 table_set(\%table, $row->{rowtitle}, 'totalrow', 0);
482 # preparing calculation
483 my $strcalc = "SELECT ";
484 if($line_attribute_type) {
485 $strcalc .= "TRIM(attribute_$line_attribute_type.attribute) AS line_attribute, ";
487 $strcalc .= "TRIM($linefield), ";
489 if($column_attribute_type) {
490 $strcalc .= "TRIM(attribute_$column_attribute_type.attribute) AS column_attribute, ";
492 $strcalc .= "TRIM($colfield), ";
495 ( $process == 1 ) ? " COUNT(*) "
496 : ( $process == 2 ) ? "(COUNT(DISTINCT borrowers.borrowernumber))"
497 : ( $process == 3 ) ? "(COUNT(DISTINCT statistics.itemnumber))"
498 : ( $process == 5 ) ? "(COUNT(DISTINCT items.biblionumber))"
500 if ( $process == 4 ) {
501 my $rqbookcount = $dbh->prepare("SELECT count(*) FROM items");
502 $rqbookcount->execute;
503 my ($bookcount) = $rqbookcount->fetchrow;
504 $strcalc .= "100*(COUNT(DISTINCT statistics.itemnumber))/ $bookcount ";
508 LEFT JOIN borrowers ON statistics.borrowernumber=borrowers.borrowernumber
510 foreach (keys %$attribute_filters) {
512 ($line_attribute_type and $line_attribute_type eq $_)
513 or $column_attribute_type and $column_attribute_type eq $_
514 or $attribute_filters->{$_}
516 $strcalc .= " LEFT JOIN borrower_attributes AS attribute_$_ ON (statistics.borrowernumber = attribute_$_.borrowernumber AND attribute_$_.code = '$_') ";
519 $strcalc .= "LEFT JOIN items ON statistics.itemnumber=items.itemnumber "
520 if ( $linefield =~ /^items\./
521 or $colfield =~ /^items\./
523 or ( $colsource eq 'items' ) || @$filters[5] || @$filters[6] || @$filters[7] || @$filters[8] || @$filters[9] || @$filters[10] || @$filters[11] || @$filters[12] || @$filters[13] );
525 $strcalc .= "WHERE 1=1 ";
526 @$filters = map { my $f = $_; defined($f) and $f =~ s/\*/%/g; $f } @$filters;
527 $strcalc .= " AND statistics.datetime >= '" . @$filters[0] . "'" if ( @$filters[0] );
528 $strcalc .= " AND statistics.datetime <= '" . @$filters[1] . " 23:59:59'" if ( @$filters[1] );
529 $strcalc .= " AND borrowers.categorycode LIKE '" . @$filters[2] . "'" if ( @$filters[2] );
530 $strcalc .= " AND statistics.itemtype LIKE '" . @$filters[3] . "'" if ( @$filters[3] );
531 $strcalc .= " AND statistics.branch LIKE '" . @$filters[4] . "'" if ( @$filters[4] );
532 $strcalc .= " AND items.ccode LIKE '" . @$filters[5] . "'" if ( @$filters[5] );
533 $strcalc .= " AND items.location LIKE '" . @$filters[6] . "'" if ( @$filters[6] );
534 $strcalc .= " AND items.itemcallnumber >='" . @$filters[7] . "'" if ( @$filters[7] );
535 $strcalc .= " AND items.itemcallnumber <'" . @$filters[8] . "'" if ( @$filters[8] );
536 $strcalc .= " AND borrowers.sort1 LIKE '" . @$filters[9] . "'" if ( @$filters[9] );
537 $strcalc .= " AND borrowers.sort2 LIKE '" . @$filters[10] . "'" if ( @$filters[10] );
538 $strcalc .= " AND items.homebranch LIKE '" . @$filters[11] . "'" if ( @$filters[11] );
539 $strcalc .= " AND items.holdingbranch LIKE '" . @$filters[12] . "'" if ( @$filters[12] );
540 $strcalc .= " AND borrowers.branchcode LIKE '" . @$filters[13] . "'" if ( @$filters[13] );
541 $strcalc .= " AND dayname(datetime) LIKE '" . $daysel . "'" if ($daysel);
542 $strcalc .= " AND monthname(datetime) LIKE '" . $monthsel . "'" if ($monthsel);
543 $strcalc .= " AND statistics.type LIKE '" . $type . "'" if ($type);
544 foreach (keys %$attribute_filters) {
545 if($attribute_filters->{$_}) {
546 $strcalc .= " AND attribute_$_.attribute LIKE '" . $attribute_filters->{$_} . "'";
550 $strcalc .= " GROUP BY ";
551 if($line_attribute_type) {
552 $strcalc .= " line_attribute, ";
554 $strcalc .= " $linefield, ";
556 if($column_attribute_type) {
557 $strcalc .= " column_attribute ";
559 $strcalc .= " $colfield ";
562 $strcalc .= " ORDER BY ";
563 if($line_attribute_type) {
564 $strcalc .= " line_attribute, ";
566 $strcalc .= " $lineorder, ";
568 if($column_attribute_type) {
569 $strcalc .= " column_attribute ";
571 $strcalc .= " $colorder ";
574 ($debug) and warn $strcalc;
575 my $dbcalc = $dbh->prepare($strcalc);
576 push @loopfilter, { crit => 'SQL =', sql => 1, filter => $strcalc };
578 my ( $emptycol, $emptyrow );
579 while ( my ( $row, $col, $value ) = $dbcalc->fetchrow ) {
580 ($debug) and warn "filling table $row / $col / $value ";
581 unless ( defined $col ) {
584 unless ( defined $row ) {
587 table_inc(\%table, $row, $col, $value);
588 table_inc(\%table, $row, 'totalrow', $value);
589 $grantotal += $value;
591 push @loopcol, { coltitle => "NULL", coltitle_display => 'NULL' } if ($emptycol);
592 push @loopline, { rowtitle => "NULL", rowtitle_display => 'NULL' } if ($emptyrow);
594 foreach my $row (@loopline) {
597 #@loopcol ensures the order for columns is common with column titles
598 # and the number matches the number of columns
599 foreach my $col (@loopcol) {
600 my $value = table_get(\%table, $row->{rowtitle}, $col->{coltitle});
601 push @loopcell, { value => $value };
604 { 'rowtitle_display' => $row->{rowtitle_display},
605 'rowtitle' => $row->{rowtitle},
606 'loopcell' => \@loopcell,
607 'totalrow' => table_get(\%table, $row->{rowtitle}, 'totalrow'),
610 for my $col (@loopcol) {
612 foreach my $row (@looprow) {
613 $total += table_get(\%table, $row->{rowtitle}, $col->{coltitle}) || 0;
614 $debug and warn "value added " . table_get(\%table, $row->{rowtitle}, $col->{coltitle}) . "for line " . $row->{rowtitle};
616 push @loopfooter, { 'totalcol' => $total };
619 # the header of the table
620 $globalline{loopfilter} = \@loopfilter;
622 # the core of the table
623 $globalline{looprow} = \@looprow;
624 $globalline{loopcol} = \@loopcol;
626 # # the foot (totals by borrower type)
627 $globalline{loopfooter} = \@loopfooter;
628 $globalline{total} = $grantotal;
629 $globalline{line} = $line_attribute_type ? $line_attribute_type : $line;
630 $globalline{column} = $column_attribute_type ? $column_attribute_type : $column;
631 return [ ( \%globalline ) ];
634 sub null_to_zzempty {
637 if (!defined($string) or $string eq '' or uc($string) eq 'NULL') {
645 my ($table, $row, $col, $val) = @_;
649 $table->{ null_to_zzempty($row) }->{ null_to_zzempty($col) } = $val;
653 my ($table, $row, $col) = @_;
657 return $table->{ null_to_zzempty($row) }->{ null_to_zzempty($col) };
661 my ($table, $row, $col, $inc) = @_;
665 $table->{ null_to_zzempty($row) }->{ null_to_zzempty($col) } += $inc;