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,
82 flagsrequired => {reports => '*'},
85 our $sep = $input->param("sep") // ';';
86 $sep = "\t" if ($sep eq 'tabulation');
87 $template->param(do_it => $do_it,
90 our $itemtypes = Koha::ItemTypes->search_with_localization->unblessed;
92 our @patron_categories = Koha::Patron::Categories->search_limited({}, {order_by => ['description']});
94 our $locations = { map { ( $_->{authorised_value} => $_->{lib} ) } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => 'items.location' }, { order_by => ['description'] } ) };
95 our $ccodes = { map { ( $_->{authorised_value} => $_->{lib} ) } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => 'items.ccode' }, { order_by => ['description'] } ) };
97 our $Bsort1 = GetAuthorisedValues("Bsort1");
98 our $Bsort2 = GetAuthorisedValues("Bsort2");
99 my ($hassort1,$hassort2);
100 $hassort1=1 if $Bsort1;
101 $hassort2=1 if $Bsort2;
105 my $results = calculate( $line, $column, $podsp, $type, $daysel, $monthsel, $calc, \@filters, $attribute_filters);
106 if ( $output eq "screen" ) {
108 # Printing results to screen
109 $template->param( mainloop => $results );
110 output_html_with_http_headers $input, $cookie, $template->output;
113 # Printing to a csv file
114 print $input->header(
115 -type => 'application/vnd.sun.xml.calc',
116 -encoding => 'utf-8',
117 -attachment => "$basename.csv",
118 -filename => "$basename.csv"
120 my $cols = @$results[0]->{loopcol};
121 my $lines = @$results[0]->{looprow};
124 print @$results[0]->{line} . "/" . @$results[0]->{column} . $sep;
127 foreach my $col (@$cols) {
128 print $col->{coltitle} . $sep;
133 foreach my $line (@$lines) {
134 my $x = $line->{loopcell};
135 print $line->{rowtitle} . $sep;
136 print map { $_->{value} . $sep } @$x;
137 print $line->{totalrow}, "\n";
142 $cols = @$results[0]->{loopfooter};
143 print map {$sep.$_->{totalcol}} @$cols;
144 print $sep.@$results[0]->{total};
150 my $dbh = C4::Context->dbh;
157 foreach (sort keys %$locations) {
158 push @locations, { code => $_, description => "$_ - " . $locations->{$_} };
162 foreach (sort {$ccodes->{$a} cmp $ccodes->{$b}} keys %$ccodes) {
163 push @ccodes, { code => $_, description => $ccodes->{$_} };
166 my $CGIextChoice = ( 'CSV' ); # FIXME translation
167 my $CGIsepChoice=GetDelimiterChoices;
169 my $attribute_types = Koha::Patron::Attribute::Types->filter_by_branch_limitations;
170 my %attribute_types_by_class;
171 while ( my ( $attribute_type ) = $attribute_types->next ) {
172 $attribute_type = $attribute_type->unblessed;
173 if ($attribute_type->{authorised_value_category}) {
174 my $authorised_values = C4::Koha::GetAuthorisedValues(
175 $attribute_type->{authorised_value_category});
177 foreach my $authorised_value (@$authorised_values) {
178 push @{ $attribute_type->{authorised_values} }, $authorised_value;
181 push @{ $attribute_types_by_class{$attribute_type->{class}} }, $attribute_type;
185 categoryloop => \@patron_categories,
186 itemtypes => $itemtypes,
187 locationloop => \@locations,
188 ccodeloop => \@ccodes,
189 hassort1 => $hassort1,
190 hassort2 => $hassort2,
193 CGIextChoice => $CGIextChoice,
194 CGIsepChoice => $CGIsepChoice,
195 attribute_types_by_class => \%attribute_types_by_class,
197 output_html_with_http_headers $input, $cookie, $template->output;
200 my ( $line, $column, $dsp, $type, $daysel, $monthsel, $process, $filters, $attribute_filters ) = @_;
209 my $dbh = C4::Context->dbh;
211 my ($line_attribute_type, $column_attribute_type);
212 if($line =~ /^borrower_attributes\.(.*)/) {
213 $line_attribute_type = $1;
214 $line = "borrower_attributes.attribute";
216 if($column =~ /^borrower_attributes\.(.*)/) {
217 $column_attribute_type = $1;
218 $column = "borrower_attributes.attribute";
225 for ( my $i = 0 ; $i <= @$filters ; $i++ ) {
227 ( @$filters[$i] ) or next;
228 if ( ( $i == 1 ) and ( @$filters[ $i - 1 ] ) ) {
229 $cell{err} = 1 if ( @$filters[$i] < @$filters[ $i - 1 ] );
231 # format the dates filters, otherwise just fill as is
233 $cell{filter} = @$filters[$i];
235 $cell{filter} = eval { output_pref( { dt => dt_from_string( @$filters[$i] ), dateonly => 1 }); }
236 if ( @$filters[$i] );
240 push @loopfilter, \%cell;
242 foreach (keys %$attribute_filters) {
243 next unless $attribute_filters->{$_};
244 push @loopfilter, { crit => "$_ =", filter => $attribute_filters->{$_} };
246 push @loopfilter, { crit => "Event", filter => $type };
247 push @loopfilter, { crit => "Display by", filter => $dsp } if ($dsp);
248 push @loopfilter, { crit => "Select Day", filter => $daysel } if ($daysel);
249 push @loopfilter, { crit => "Select Month", filter => $monthsel } if ($monthsel);
252 $debug and warn "filtres " . join "|", @$filters;
253 my ( $colsource, $linesource ) = ('', '');
254 $linefilter[1] = @$filters[1] if ( $line =~ /datetime/ );
256 ( $line =~ /datetime/ ) ? @$filters[0]
257 : ( $line =~ /category/ ) ? @$filters[2]
258 : ( $line =~ /itemtype/ ) ? @$filters[3]
259 : ( $line =~ /^branch/ ) ? @$filters[4]
260 : ( $line =~ /ccode/ ) ? @$filters[5]
261 : ( $line =~ /location/ ) ? @$filters[6]
262 : ( $line =~ /sort1/ ) ? @$filters[9]
263 : ( $line =~ /sort2/ ) ? @$filters[10]
264 : ( $line =~ /homebranch/) ? @$filters[11]
265 : ( $line =~ /holdingbranch/) ? @$filters[12]
266 : ( $line =~ /borrowers.branchcode/ ) ? @$filters[13]
267 : ( $line_attribute_type ) ? $attribute_filters->{$line_attribute_type}
270 if ( $line =~ /ccode/ or $line =~ /location/ or $line =~ /homebranch/ or $line =~ /holdingbranch/ ) {
271 $linesource = 'items';
275 $colfilter[1] = @$filters[1] if ($column =~ /datetime/);
277 ( $column =~ /datetime/ ) ? @$filters[0]
278 : ( $column =~ /category/ ) ? @$filters[2]
279 : ( $column =~ /itemtype/ ) ? @$filters[3]
280 : ( $column =~ /^branch/ ) ? @$filters[4]
281 : ( $column =~ /ccode/ ) ? @$filters[5]
282 : ( $column =~ /location/ ) ? @$filters[6]
283 : ( $column =~ /sort1/ ) ? @$filters[9]
284 : ( $column =~ /sort1/ ) ? @$filters[10]
285 : ( $column =~ /homebranch/) ? @$filters[11]
286 : ( $column =~ /holdingbranch/) ? @$filters[12]
287 : ( $column =~ /borrowers.branchcode/ ) ? @$filters[13]
288 : ( $column_attribute_type ) ? $attribute_filters->{$column_attribute_type}
291 if ( $column =~ /ccode/ or $column =~ /location/ or $column =~ /homebranch/ or $column =~ /holdingbranch/ ) {
292 $colsource = 'items';
297 if ( $line =~ /datetime/ ) {
299 # by Day, Month, Year or Hour (1,2,3,4 respectively)
301 ( $dsp == 1 ) ? " dayname($line)"
302 : ( $dsp == 2 ) ? "monthname($line)"
303 : ( $dsp == 3 ) ? " Year($line)"
304 : ( $dsp == 4 ) ? "extract(hour from $line)"
305 : 'date_format(`datetime`,"%Y-%m-%d")'; # Probably should be left alone or passed through Koha::Dates
310 ( $linefield =~ /dayname/ ) ? "weekday($line)"
311 : ( $linefield =~ /^month/ ) ? " month($line)"
315 if($line_attribute_type) {
316 $strsth = "SELECT attribute FROM borrower_attributes WHERE code = '$line_attribute_type' ";
318 $strsth = "SELECT distinctrow $linefield FROM statistics ";
320 # get stats on items if ccode or location, otherwise borrowers.
322 ( $linesource eq 'items' )
323 ? " LEFT JOIN items ON (statistics.itemnumber = items.itemnumber) "
324 : " LEFT JOIN borrowers ON (statistics.borrowernumber = borrowers.borrowernumber) ";
325 $strsth .= " WHERE $line is not null AND $line != '' ";
328 if ( $line =~ /datetime/ ) {
329 if ( $linefilter[1] and ( $linefilter[0] ) ) {
330 $strsth .= " AND $line between ? AND ? ";
331 } elsif ( $linefilter[1] ) {
332 $strsth .= " AND $line <= ? ";
333 } elsif ( $linefilter[0] ) {
334 $strsth .= " AND $line >= ? ";
336 $strsth .= " AND type ='" . $type . "' " if $type;
337 $strsth .= " AND dayname(datetime) ='" . $daysel . "' " if $daysel;
338 $strsth .= " AND monthname(datetime) ='" . $monthsel . "' " if $monthsel;
339 } elsif ( $linefilter[0] ) {
340 $linefilter[0] =~ s/\*/%/g;
341 $strsth .= " AND $line LIKE ? ";
343 $strsth .= " group by $linefield order by $lineorder ";
344 $debug and warn $strsth;
345 push @loopfilter, { crit => 'SQL =', sql => 1, filter => $strsth };
346 my $sth = $dbh->prepare($strsth);
347 if ( (@linefilter) and ($linefilter[0]) and ($linefilter[1]) ) {
348 $sth->execute( $linefilter[0], $linefilter[1] . " 23:59:59" );
349 } elsif ( $linefilter[1] ) {
350 $sth->execute( $linefilter[1] . " 23:59:59" );
351 } elsif ( $linefilter[0] ) {
352 $sth->execute( $linefilter[0] );
357 my $itemtypes_map = { map { $_->{itemtype} => $_ } @{ $itemtypes } };
358 while ( my ($celvalue) = $sth->fetchrow ) {
359 my %cell = ( rowtitle => $celvalue, totalrow => 0 ); # we leave 'rowtitle' as hash key (used when filling the table), and add coltitle_display
360 $cell{rowtitle_display} =
361 ( $line =~ /ccode/ ) ? $ccodes->{$celvalue}
362 : ( $line =~ /location/ ) ? $locations->{$celvalue}
363 : ( $line =~ /itemtype/ ) ? $itemtypes_map->{$celvalue}->{translated_description}
364 : $celvalue; # default fallback
365 if ( $line =~ /sort1/ ) {
367 ( $celvalue eq $_->{authorised_value} ) or next;
368 $cell{rowtitle_display} = $_->{lib} and last;
370 } elsif ( $line =~ /sort2/ ) {
372 ( $celvalue eq $_->{authorised_value} ) or next;
373 $cell{rowtitle_display} = $_->{lib} and last;
375 } elsif ($line =~ /category/) {
376 foreach my $patron_category ( @patron_categories ) {
377 ($celvalue eq $patron_category->categorycode) or next;
378 $cell{rowtitle_display} = $patron_category->description and last;
381 push @loopline, \%cell;
387 if ( $column =~ /datetime/ ) {
389 #Display by Day, Month or Year (1,2,3 respectively)
391 ( $dsp == 1 ) ? " dayname($column)"
392 : ( $dsp == 2 ) ? "monthname($column)"
393 : ( $dsp == 3 ) ? " Year($column)"
394 : ( $dsp == 4 ) ? "extract(hour from $column)"
395 : 'date_format(`datetime`,"%Y-%m-%d")'; # Probably should be left alone or passed through Koha::Dates
400 ( $colfield =~ /dayname/ ) ? "weekday($column)"
401 : ( $colfield =~ /^month/ ) ? " month($column)"
404 if($column_attribute_type) {
405 $strsth2 = "SELECT attribute FROM borrower_attributes WHERE code = '$column_attribute_type' ";
407 $strsth2 = "SELECT distinctrow $colfield FROM statistics ";
409 # get stats on items if ccode or location, otherwise borrowers.
411 ( $colsource eq 'items' )
412 ? "LEFT JOIN items ON (statistics.itemnumber = items.itemnumber) "
413 : "LEFT JOIN borrowers ON (statistics.borrowernumber = borrowers.borrowernumber) ";
414 $strsth2 .= " WHERE $column IS NOT NULL AND $column != '' ";
417 if ( $column =~ /datetime/ ) {
418 if ( ( $colfilter[1] ) and ( $colfilter[0] ) ) {
419 $strsth2 .= " AND $column BETWEEN ? AND ? ";
420 } elsif ( $colfilter[1] ) {
421 $strsth2 .= " AND $column <= ? ";
422 } elsif ( $colfilter[0] ) {
423 $strsth2 .= " AND $column >= ? ";
425 $strsth2 .= " AND type ='". $type ."' " if $type;
426 $strsth2 .= " AND dayname(datetime) ='". $daysel ."' " if $daysel;
427 $strsth2 .= " AND monthname(datetime) ='". $monthsel ."' " if $monthsel;
428 } elsif ($colfilter[0]) {
429 $colfilter[0] =~ s/\*/%/g;
430 $strsth2 .= " AND $column LIKE ? " ;
433 $strsth2 .= " group by $colfield order by $colorder ";
434 $debug and warn $strsth2;
435 push @loopfilter, { crit => 'SQL =', sql => 1, filter => $strsth2 };
436 my $sth2 = $dbh->prepare($strsth2);
437 if ( (@colfilter) and ($colfilter[0]) and ($colfilter[1]) ) {
438 $sth2->execute( $colfilter[0], $colfilter[1] . " 23:59:59" );
439 } elsif ( $colfilter[1] ) {
440 $sth2->execute( $colfilter[1] . " 23:59:59" );
441 } elsif ( $colfilter[0] ) {
442 $sth2->execute( $colfilter[0] );
447 while ( my ($celvalue) = $sth2->fetchrow ) {
448 my %cell = ( coltitle => $celvalue ); # we leave 'coltitle' as hash key (used when filling the table), and add coltitle_display
449 $cell{coltitle_display} =
450 ( $column =~ /ccode/ ) ? $ccodes->{$celvalue}
451 : ( $column =~ /location/ ) ? $locations->{$celvalue}
452 : ( $column =~ /itemtype/ ) ? $itemtypes_map->{$celvalue}->{translated_description}
453 : $celvalue; # default fallback
454 if ( $column =~ /sort1/ ) {
456 ( $celvalue eq $_->{authorised_value} ) or next;
457 $cell{coltitle_display} = $_->{lib} and last;
459 } elsif ( $column =~ /sort2/ ) {
461 ( $celvalue eq $_->{authorised_value} ) or next;
462 $cell{coltitle_display} = $_->{lib} and last;
464 } elsif ($column =~ /category/) {
465 foreach my $patron_category ( @patron_categories ) {
466 ($celvalue eq $patron_category->categorycode) or next;
467 $cell{coltitle_display} = $patron_category->description and last;
470 push @loopcol, \%cell;
473 #Initialization of cell values.....
475 foreach my $row (@loopline) {
476 foreach my $col (@loopcol) {
477 $debug and warn " init table : $row->{rowtitle} ( $row->{rowtitle_display} ) / $col->{coltitle} ( $col->{coltitle_display} ) ";
478 table_set(\%table, $row->{rowtitle}, $col->{coltitle}, 0);
480 table_set(\%table, $row->{rowtitle}, 'totalrow', 0);
483 # preparing calculation
484 my $strcalc = "SELECT ";
485 if($line_attribute_type) {
486 $strcalc .= "TRIM(attribute_$line_attribute_type.attribute) AS line_attribute, ";
488 $strcalc .= "TRIM($linefield), ";
490 if($column_attribute_type) {
491 $strcalc .= "TRIM(attribute_$column_attribute_type.attribute) AS column_attribute, ";
493 $strcalc .= "TRIM($colfield), ";
496 ( $process == 1 ) ? " COUNT(*) "
497 : ( $process == 2 ) ? "(COUNT(DISTINCT borrowers.borrowernumber))"
498 : ( $process == 3 ) ? "(COUNT(DISTINCT statistics.itemnumber))"
499 : ( $process == 5 ) ? "(COUNT(DISTINCT items.biblionumber))"
501 if ( $process == 4 ) {
502 my $rqbookcount = $dbh->prepare("SELECT count(*) FROM items");
503 $rqbookcount->execute;
504 my ($bookcount) = $rqbookcount->fetchrow;
505 $strcalc .= "100*(COUNT(DISTINCT statistics.itemnumber))/ $bookcount ";
509 LEFT JOIN borrowers ON statistics.borrowernumber=borrowers.borrowernumber
511 foreach (keys %$attribute_filters) {
513 ($line_attribute_type and $line_attribute_type eq $_)
514 or $column_attribute_type and $column_attribute_type eq $_
515 or $attribute_filters->{$_}
517 $strcalc .= " LEFT JOIN borrower_attributes AS attribute_$_ ON (statistics.borrowernumber = attribute_$_.borrowernumber AND attribute_$_.code = '$_') ";
520 $strcalc .= "LEFT JOIN items ON statistics.itemnumber=items.itemnumber "
521 if ( $linefield =~ /^items\./
522 or $colfield =~ /^items\./
524 or ( $colsource eq 'items' ) || @$filters[5] || @$filters[6] || @$filters[7] || @$filters[8] || @$filters[9] || @$filters[10] || @$filters[11] || @$filters[12] || @$filters[13] );
526 $strcalc .= "WHERE 1=1 ";
527 @$filters = map { defined($_) and s/\*/%/g; $_ } @$filters;
528 $strcalc .= " AND statistics.datetime >= '" . @$filters[0] . "'" if ( @$filters[0] );
529 $strcalc .= " AND statistics.datetime <= '" . @$filters[1] . " 23:59:59'" if ( @$filters[1] );
530 $strcalc .= " AND borrowers.categorycode LIKE '" . @$filters[2] . "'" if ( @$filters[2] );
531 $strcalc .= " AND statistics.itemtype LIKE '" . @$filters[3] . "'" if ( @$filters[3] );
532 $strcalc .= " AND statistics.branch LIKE '" . @$filters[4] . "'" if ( @$filters[4] );
533 $strcalc .= " AND items.ccode LIKE '" . @$filters[5] . "'" if ( @$filters[5] );
534 $strcalc .= " AND items.location LIKE '" . @$filters[6] . "'" if ( @$filters[6] );
535 $strcalc .= " AND items.itemcallnumber >='" . @$filters[7] . "'" if ( @$filters[7] );
536 $strcalc .= " AND items.itemcallnumber <'" . @$filters[8] . "'" if ( @$filters[8] );
537 $strcalc .= " AND borrowers.sort1 LIKE '" . @$filters[9] . "'" if ( @$filters[9] );
538 $strcalc .= " AND borrowers.sort2 LIKE '" . @$filters[10] . "'" if ( @$filters[10] );
539 $strcalc .= " AND items.homebranch LIKE '" . @$filters[11] . "'" if ( @$filters[11] );
540 $strcalc .= " AND items.holdingbranch LIKE '" . @$filters[12] . "'" if ( @$filters[12] );
541 $strcalc .= " AND borrowers.branchcode LIKE '" . @$filters[13] . "'" if ( @$filters[13] );
542 $strcalc .= " AND dayname(datetime) LIKE '" . $daysel . "'" if ($daysel);
543 $strcalc .= " AND monthname(datetime) LIKE '" . $monthsel . "'" if ($monthsel);
544 $strcalc .= " AND statistics.type LIKE '" . $type . "'" if ($type);
545 foreach (keys %$attribute_filters) {
546 if($attribute_filters->{$_}) {
547 $strcalc .= " AND attribute_$_.attribute LIKE '" . $attribute_filters->{$_} . "'";
551 $strcalc .= " GROUP BY ";
552 if($line_attribute_type) {
553 $strcalc .= " line_attribute, ";
555 $strcalc .= " $linefield, ";
557 if($column_attribute_type) {
558 $strcalc .= " column_attribute ";
560 $strcalc .= " $colfield ";
563 $strcalc .= " ORDER BY ";
564 if($line_attribute_type) {
565 $strcalc .= " line_attribute, ";
567 $strcalc .= " $lineorder, ";
569 if($column_attribute_type) {
570 $strcalc .= " column_attribute ";
572 $strcalc .= " $colorder ";
575 ($debug) and warn $strcalc;
576 my $dbcalc = $dbh->prepare($strcalc);
577 push @loopfilter, { crit => 'SQL =', sql => 1, filter => $strcalc };
579 my ( $emptycol, $emptyrow );
580 while ( my ( $row, $col, $value ) = $dbcalc->fetchrow ) {
581 ($debug) and warn "filling table $row / $col / $value ";
582 unless ( defined $col ) {
585 unless ( defined $row ) {
588 table_inc(\%table, $row, $col, $value);
589 table_inc(\%table, $row, 'totalrow', $value);
590 $grantotal += $value;
592 push @loopcol, { coltitle => "NULL", coltitle_display => 'NULL' } if ($emptycol);
593 push @loopline, { rowtitle => "NULL", rowtitle_display => 'NULL' } if ($emptyrow);
595 foreach my $row (@loopline) {
598 #@loopcol ensures the order for columns is common with column titles
599 # and the number matches the number of columns
600 foreach my $col (@loopcol) {
601 my $value = table_get(\%table, $row->{rowtitle}, $col->{coltitle});
602 push @loopcell, { value => $value };
605 { 'rowtitle_display' => $row->{rowtitle_display},
606 'rowtitle' => $row->{rowtitle},
607 'loopcell' => \@loopcell,
608 'totalrow' => table_get(\%table, $row->{rowtitle}, 'totalrow'),
611 for my $col (@loopcol) {
613 foreach my $row (@looprow) {
614 $total += table_get(\%table, $row->{rowtitle}, $col->{coltitle}) || 0;
615 $debug and warn "value added " . table_get(\%table, $row->{rowtitle}, $col->{coltitle}) . "for line " . $row->{rowtitle};
617 push @loopfooter, { 'totalcol' => $total };
620 # the header of the table
621 $globalline{loopfilter} = \@loopfilter;
623 # the core of the table
624 $globalline{looprow} = \@looprow;
625 $globalline{loopcol} = \@loopcol;
627 # # the foot (totals by borrower type)
628 $globalline{loopfooter} = \@loopfooter;
629 $globalline{total} = $grantotal;
630 $globalline{line} = $line_attribute_type ? $line_attribute_type : $line;
631 $globalline{column} = $column_attribute_type ? $column_attribute_type : $column;
632 return [ ( \%globalline ) ];
635 sub null_to_zzempty {
638 if (!defined($string) or $string eq '' or uc($string) eq 'NULL') {
646 my ($table, $row, $col, $val) = @_;
650 $table->{ null_to_zzempty($row) }->{ null_to_zzempty($col) } = $val;
654 my ($table, $row, $col) = @_;
658 return $table->{ null_to_zzempty($row) }->{ null_to_zzempty($col) };
662 my ($table, $row, $col, $inc) = @_;
666 $table->{ null_to_zzempty($row) }->{ null_to_zzempty($col) } += $inc;