BIG COMMIT: minimal fix to authorities search
[koha.git] / reports / acquisitions_stats.pl
blobae093549132163bbac8ffcee71d1ea478d2a9e94
1 #!/usr/bin/perl
4 # Copyright 2000-2002 Katipo Communications
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
11 # version.
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA 02111-1307 USA
21 # test comment
23 use strict;
24 use C4::Auth;
25 use CGI;
26 use C4::Context;
28 use C4::Output;
29 use C4::Koha;
30 use C4::Circulation;
31 use C4::Dates qw/format_date format_date_in_iso/;
33 =head1 NAME
35 plugin that shows a stats on borrowers
37 =head1 DESCRIPTION
39 =over 2
41 =cut
43 my $input = new CGI;
44 my $do_it = $input->param('do_it');
45 my $fullreportname = "reports/acquisitions_stats.tmpl";
46 my $line = $input->param("Line");
47 my $column = $input->param("Column");
48 my @filters = $input->param("Filter");
49 $filters[0]=format_date_in_iso($filters[0]);
50 $filters[1]=format_date_in_iso($filters[1]);
51 $filters[2]=format_date_in_iso($filters[2]);
52 $filters[3]=format_date_in_iso($filters[3]);
53 my $podsp = $input->param("PlacedOnDisplay");
54 my $rodsp = $input->param("ReceivedOnDisplay");
55 my $aodsp = $input->param("AcquiredOnDisplay"); ##added by mason.
56 my $calc = $input->param("Cellvalue");
57 my $output = $input->param("output");
58 my $basename = $input->param("basename");
59 my $mime = $input->param("MIME");
60 my $del = $input->param("sep");
62 #warn "calcul : ".$calc;
63 my ($template, $borrowernumber, $cookie)
64 = get_template_and_user({template_name => $fullreportname,
65 query => $input,
66 type => "intranet",
67 authnotrequired => 0,
68 flagsrequired => {reports => 1},
69 debug => 1,
70 });
71 $template->param(do_it => $do_it,
72 DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
74 if ($do_it) {
75 # warn "line=$line, col=$column, pod=$podsp, rod=$rodsp, aod=$aodsp, calc=$calc, filters=@filters\n";
76 my $results =
77 calculate( $line, $column, $podsp, $rodsp, $aodsp, $calc, \@filters );
78 if ( $output eq "screen" ) {
79 $template->param( mainloop => $results );
80 output_html_with_http_headers $input, $cookie, $template->output;
82 else {
83 print $input->header(
84 -type => 'application/vnd.sun.xml.calc',
85 -encoding => 'utf-8',
86 -attachment => "$basename.csv",
87 -name => "$basename.csv"
89 my $cols = @$results[0]->{loopcol};
90 my $lines = @$results[0]->{looprow};
91 my $sep;
92 $sep = C4::Context->preference("delimiter");
93 print @$results[0]->{line} . "/" . @$results[0]->{column} . $sep;
94 foreach my $col (@$cols) {
95 print $col->{coltitle} . $sep;
97 print "Total\n";
98 foreach my $line (@$lines) {
99 my $x = $line->{loopcell};
100 print $line->{rowtitle} . $sep;
101 foreach my $cell (@$x) {
102 print $cell->{value} . $sep;
104 print $line->{totalrow};
105 print "\n";
107 print "TOTAL";
108 $cols = @$results[0]->{loopfooter};
109 foreach my $col (@$cols) {
110 print $sep. $col->{totalcol};
112 print $sep. @$results[0]->{total};
114 exit(1);
116 else {
117 my $dbh = C4::Context->dbh;
118 my @values;
119 my %labels;
120 my %select;
121 my $req;
122 $req = $dbh->prepare("SELECT distinctrow id,name FROM aqbooksellers ORDER BY name");
123 $req->execute;
124 my @select;
125 push @select, "";
127 # $select{""}="";
128 while ( my ( $value, $desc ) = $req->fetchrow ) {
129 push @select, $desc;
131 # $select{$value}=$desc;
133 my $CGIBookSellers = CGI::scrolling_list(
134 -name => 'Filter',
135 -id => 'supplier',
136 -values => \@select,
138 # -labels => \%select,
139 -size => 1,
140 -multiple => 0
143 $req =
144 $dbh->prepare(
145 "SELECT DISTINCTROW itemtype,description FROM itemtypes ORDER BY description"
147 $req->execute;
148 undef @select;
149 undef %select;
150 push @select, "";
151 $select{""} = "";
152 while ( my ( $value, $desc ) = $req->fetchrow ) {
153 push @select, $value;
154 $select{$value} = $desc;
156 my $CGIItemTypes = CGI::scrolling_list(
157 -name => 'Filter',
158 -id => 'itemtypes',
159 -values => \@select,
160 -labels => \%select,
161 -size => 1,
162 -multiple => 0
165 $req =
166 $dbh->prepare(
167 "SELECT DISTINCTROW bookfundid,bookfundname FROM aqbookfund ORDER BY bookfundname"
169 $req->execute;
170 undef @select;
171 undef %select;
172 push @select, "";
173 $select{""} = "";
175 while ( my ( $value, $desc ) = $req->fetchrow ) {
176 push @select, $value;
177 $select{$value} = $desc;
179 my $CGIBudget = CGI::scrolling_list(
180 -name => 'Filter',
181 -id => 'budget',
182 -values => \@select,
183 -labels => \%select,
184 -size => 1,
185 -multiple => 0
188 $req =
189 $dbh->prepare(
190 "SELECT DISTINCTROW sort1 FROM aqorders WHERE sort1 IS NOT NULL ORDER BY sort1"
192 $req->execute;
193 undef @select;
194 push @select, "";
195 my $hassort1;
196 while ( my ($value) = $req->fetchrow ) {
197 $hassort1 = 1 if ($value);
198 push @select, $value;
200 my $CGISort1 = CGI::scrolling_list(
201 -name => 'Filter',
202 -id => 'sort1',
203 -values => \@select,
204 -size => 1,
205 -multiple => 0
208 $req =
209 $dbh->prepare(
210 "SELECT DISTINCTROW sort2 FROM aqorders WHERE sort2 IS NOT NULL ORDER BY sort2"
212 $req->execute;
213 undef @select;
214 push @select, "";
215 my $hassort2;
216 my $hglghtsort2;
218 while ( my ($value) = $req->fetchrow ) {
219 $hassort2 = 1 if ($value);
220 $hglghtsort2 = !($hassort1);
221 push @select, $value;
223 my $CGISort2 = CGI::scrolling_list(
224 -name => 'Filter',
225 -id => 'sort2',
226 -values => \@select,
227 -size => 1,
228 -multiple => 0
231 my @mime = ( C4::Context->preference("MIME") );
232 foreach my $mime (@mime) {
233 # warn "".$mime;
236 my $CGIextChoice = CGI::scrolling_list(
237 -name => 'MIME',
238 -id => 'MIME',
239 -values => \@mime,
240 -size => 1,
241 -multiple => 0
244 my @dels = ( C4::Context->preference("delimiter") );
245 my $CGIsepChoice = CGI::scrolling_list(
246 -name => 'sep',
247 -id => 'sep',
248 -values => \@dels,
249 -size => 1,
250 -multiple => 0
253 $template->param(
254 CGIBookSeller => $CGIBookSellers,
255 CGIItemType => $CGIItemTypes,
256 CGIBudget => $CGIBudget,
257 hassort1 => $hassort1,
258 hassort2 => $hassort2,
259 HlghtSort2 => $hglghtsort2,
260 CGISort1 => $CGISort1,
261 CGISort2 => $CGISort2,
262 CGIextChoice => $CGIextChoice,
263 CGIsepChoice => $CGIsepChoice
267 output_html_with_http_headers $input, $cookie, $template->output;
269 sub calculate {
270 my ( $line, $column, $podsp, $rodsp, $aodsp, $process, $filters ) = @_;
271 my @mainloop;
272 my @loopfooter;
273 my @loopcol;
274 my @loopline;
275 my @looprow;
276 my %globalline;
277 my $grantotal = 0;
279 # extract parameters
280 my $dbh = C4::Context->dbh;
282 # Filters
283 # Checking filters
285 my @loopfilter;
286 for ( my $i = 0 ; $i <= 8 ; $i++ ) {
287 my %cell;
288 if ( @$filters[$i] ) {
289 if ( ( ( $i == 1 ) or ( $i == 3 ) ) and ( @$filters[ $i - 1 ] ) ) {
290 $cell{err} = 1 if ( @$filters[$i] < @$filters[ $i - 1 ] );
292 # format the dates filters, otherwise just fill as is
293 if ($i>=4) {
294 $cell{filter} .= @$filters[$i];
295 } else {
296 $cell{filter} .= format_date(@$filters[$i]);
298 $cell{crit} .= "Placed On From" if ( $i == 0 );
299 $cell{crit} .= "Placed On To" if ( $i == 1 );
300 $cell{crit} .= "Received On From" if ( $i == 2 );
301 $cell{crit} .= "Received On To" if ( $i == 3 );
303 $cell{crit} .= "Acquired On From" if ( $i == 4 );
304 $cell{crit} .= "Acquired On To" if ( $i == 5 );
306 $cell{crit} .= "BookSeller" if ( $i == 6 );
307 $cell{crit} .= "Doc Type" if ( $i == 7 );
308 $cell{crit} .= "Budget" if ( $i == 8 );
309 $cell{crit} .= "Sort1" if ( $i == 9 );
310 $cell{crit} .= "Sort2" if ( $i == 10 );
311 push @loopfilter, \%cell;
315 my @linefilter;
317 # warn "filtres ".@filters[0];
318 # warn "filtres ".@filters[1];
319 # warn "filtres ".@filters[2];
320 # warn "filtres ".@filters[3];
322 $linefilter[0] = @$filters[0] if ( $line =~ /closedate/ );
323 $linefilter[1] = @$filters[1] if ( $line =~ /closedate/ );
324 $linefilter[0] = @$filters[2] if ( $line =~ /received/ );
325 $linefilter[1] = @$filters[3] if ( $line =~ /received/ );
327 $linefilter[0] = @$filters[4] if ( $line =~ /acquired/ );
328 $linefilter[1] = @$filters[5] if ( $line =~ /acquired/ );
330 $linefilter[0] = @$filters[6] if ( $line =~ /bookseller/ );
331 $linefilter[0] = @$filters[7] if ( $line =~ /itemtype/ );
332 $linefilter[0] = @$filters[8] if ( $line =~ /bookfund/ );
333 $linefilter[0] = @$filters[9] if ( $line =~ /sort1/ );
334 $linefilter[0] = @$filters[10] if ( $line =~ /sort2/ );
336 #warn "filtre lignes".$linefilter[0]." ".$linefilter[1];
338 my @colfilter;
339 $colfilter[0] = @$filters[0] if ( $column =~ /closedate/ );
340 $colfilter[1] = @$filters[1] if ( $column =~ /closedate/ );
341 $colfilter[0] = @$filters[2] if ( $column =~ /received/ );
342 $colfilter[1] = @$filters[3] if ( $column =~ /received/ );
344 $colfilter[0] = @$filters[4] if ( $column =~ /acquired/ );
345 $colfilter[1] = @$filters[5] if ( $column =~ /acquired/ );
347 $colfilter[0] = @$filters[6] if ( $column =~ /bookseller/ );
348 $colfilter[0] = @$filters[7] if ( $column =~ /itemtype/ );
349 $colfilter[0] = @$filters[8] if ( $column =~ /bookfund/ );
350 $colfilter[0] = @$filters[9] if ( $column =~ /sort1/ );
351 $colfilter[0] = @$filters[10] if ( $column =~ /sort2/ );
353 #warn "filtre col ".$colfilter[0]." ".$colfilter[1];
355 #warn "line=$line, podsp=$podsp, rodsp=$rodsp, aodsp=$aodsp\n";
357 # 1st, loop rows.
358 my $linefield;
359 if ( ( $line =~ /closedate/ ) and ( $podsp == 1 ) ) {
361 #Display by day
362 $linefield .= "dayname($line)";
364 elsif ( ( $line =~ /closedate/ ) and ( $podsp == 2 ) ) {
366 #Display by Month
367 $linefield .= "monthname($line)";
369 elsif ( ( $line =~ /closedate/ ) and ( $podsp == 3 ) ) {
371 #Display by Year
372 $linefield .= "Year($line)";
375 elsif ( ( $line =~ /received/ ) and ( $rodsp == 1 ) ) {
377 #Display by day
378 $linefield .= "dayname($line)";
380 elsif ( ( $line =~ /received/ ) and ( $rodsp == 2 ) ) {
382 #Display by Month
383 $linefield .= "monthname($line)";
385 elsif ( ( $line =~ /received/ ) and ( $rodsp == 3 ) ) {
387 #Display by Year
388 $linefield .= "Year($line)";
391 elsif ( ( $line =~ /acquired/ ) and ( $aodsp == 1 ) ) {
393 #Display by day
394 $linefield .= "dayname($line)";
396 elsif ( ( $line =~ /acquired/ ) and ( $aodsp == 2 ) ) {
398 #Display by Month
399 $linefield .= "monthname($line)";
401 elsif ( ( $line =~ /acquired/ ) and ( $aodsp == 3 ) ) {
403 #Display by Year
404 $linefield .= "Year($line)";
407 else {
408 $linefield .= $line;
411 my $strsth;
412 $strsth .=
413 "SELECT DISTINCTROW $linefield FROM (aqorders, aqbasket,aqorderbreakdown)
414 LEFT JOIN items ON (aqorders.biblioitemnumber= items.biblioitemnumber)
415 LEFT JOIN biblioitems ON (aqorders.biblioitemnumber= biblioitems.biblioitemnumber)
416 LEFT JOIN aqorderdelivery ON (aqorders.ordernumber =aqorderdelivery.ordernumber )
417 LEFT JOIN aqbooksellers ON (aqbasket.booksellerid=aqbooksellers.id) WHERE (aqorders.basketno=aqbasket.basketno)
418 AND (aqorderbreakdown.ordernumber=aqorders.ordernumber) AND $line IS NOT NULL ";
420 if (@linefilter) {
421 if ( $linefilter[1] ) {
422 if ( $linefilter[0] ) {
423 $strsth .= " AND $line BETWEEN ? AND ? ";
425 else {
426 $strsth .= " AND $line < ? ";
429 elsif (
430 ( $linefilter[0] )
431 and ( ( $line =~ /closedate/ )
432 or ( $line =~ /received/ )
433 or ( $line =~ /acquired/ ) )
436 $strsth .= " AND $line > ? ";
438 elsif ( $linefilter[0] ) {
439 $linefilter[0] =~ s/\*/%/g;
440 $strsth .= " AND $line LIKE ? ";
443 $strsth .= " GROUP BY $linefield";
444 $strsth .= " ORDER BY $linefield";
446 #warn "377:strsth= $strsth";
448 my $sth = $dbh->prepare($strsth);
449 if ( (@linefilter) and ( $linefilter[1] ) ) {
450 $sth->execute( "'" . $linefilter[0] . "'", "'" . $linefilter[1] . "'" );
452 elsif ( $linefilter[0] ) {
453 $sth->execute( $linefilter[0] );
455 else {
456 $sth->execute;
459 while ( my ($celvalue) = $sth->fetchrow ) {
460 my %cell;
461 if ($celvalue) {
462 $cell{rowtitle} = $celvalue;
464 # } else {
465 # $cell{rowtitle} = "";
467 $cell{totalrow} = 0;
468 push @loopline, \%cell;
471 #warn "column=$column, podsp=$podsp, rodsp=$rodsp, aodsp=$aodsp\n";
473 # 2nd, loop cols.
474 my $colfield;
475 if ( ( $column =~ /closedate/ ) and ( $podsp == 1 ) ) {
477 #Display by day
478 $colfield .= "dayname($column)";
480 elsif ( ( $column =~ /closedate/ ) and ( $podsp == 2 ) ) {
482 #Display by Month
483 $colfield .= "monthname($column)";
485 elsif ( ( $column =~ /closedate/ ) and ( $podsp == 3 ) ) {
487 #Display by Year
488 $colfield .= "Year($column)";
491 elsif ( ( $column =~ /deliverydate/ ) and ( $rodsp == 1 ) ) {
493 #Display by day
494 $colfield .= "dayname($column)";
496 elsif ( ( $column =~ /deliverydate/ ) and ( $rodsp == 2 ) ) {
498 #Display by Month
499 $colfield .= "monthname($column)";
501 elsif ( ( $column =~ /deliverydate/ ) and ( $rodsp == 3 ) ) {
503 #Display by Year
504 $colfield .= "Year($column)";
507 elsif ( ( $column =~ /dateaccessioned/ ) and ( $aodsp == 1 ) ) {
509 #Display by day
510 $colfield .= "dayname($column)";
512 elsif ( ( $column =~ /dateaccessioned/ ) and ( $aodsp == 2 ) ) {
514 #Display by Month
515 $colfield .= "monthname($column)";
517 elsif ( ( $column =~ /dateaccessioned/ ) and ( $aodsp == 3 ) ) {
519 #Display by Year
520 $colfield .= "Year($column)";
523 else {
524 $colfield .= $column;
527 my $strsth2;
528 $strsth2 .=
529 "SELECT distinctrow $colfield FROM (aqorders, aqbasket,aqorderbreakdown)
530 LEFT JOIN items ON (aqorders.biblioitemnumber= items.biblioitemnumber)
531 LEFT JOIN biblioitems ON (aqorders.biblioitemnumber= biblioitems.biblioitemnumber)
532 LEFT JOIN aqorderdelivery ON (aqorders.ordernumber =aqorderdelivery.ordernumber )
533 LEFT JOIN aqbooksellers ON (aqbasket.booksellerid=aqbooksellers.id)
534 WHERE (aqorders.basketno=aqbasket.basketno) AND (aqorderbreakdown.ordernumber=aqorders.ordernumber)
535 AND $column IS NOT NULL";
537 if (@colfilter) {
538 if ( $colfilter[1] ) {
539 if ( $colfilter[0] ) {
540 $strsth2 .= " AND $column BETWEEN ? AND ? ";
542 else {
543 $strsth2 .= " AND $column < ? ";
546 elsif (
547 ( $colfilter[0] )
548 and ( ( $column =~ /closedate/ )
549 or ( $line =~ /received/ )
550 or ( $line =~ /acquired/ ) )
553 $strsth2 .= " AND $column > ? ";
555 elsif ( $colfilter[0] ) {
556 $colfilter[0] =~ s/\*/%/g;
557 $strsth2 .= " AND $column LIKE ? ";
560 $strsth2 .= " GROUP BY $colfield";
561 $strsth2 .= " ORDER BY $colfield";
563 # warn "MASON:. $strsth2";
565 my $sth2 = $dbh->prepare($strsth2);
566 if ( (@colfilter) and ( $colfilter[1] ) ) {
568 # warn "from : ".$colfilter[0]." To :".$colfilter[1];
569 $sth2->execute( "'" . $colfilter[0] . "'", "'" . $colfilter[1] . "'" );
571 elsif ( $colfilter[0] ) {
572 $sth2->execute( $colfilter[0] );
574 else {
575 $sth2->execute;
578 while ( my ($celvalue) = $sth2->fetchrow ) {
579 my %cell;
580 if ($celvalue) {
582 # warn "coltitle :".$celvalue;
583 $cell{coltitle} = $celvalue;
585 push @loopcol, \%cell;
588 # warn "fin des titres colonnes";
590 my $i = 0;
591 my @totalcol;
592 my $hilighted = -1;
594 #Initialization of cell values.....
595 my %table;
597 # warn "init table";
598 foreach my $row (@loopline) {
599 foreach my $col (@loopcol) {
601 # warn " init table : $row->{rowtitle} / $col->{coltitle} ";
602 $table{ $row->{rowtitle} }->{ $col->{coltitle} } = 0;
604 $table{ $row->{rowtitle} }->{totalrow} = 0;
607 # preparing calculation
608 my $strcalc;
609 $strcalc .= "SELECT $linefield, $colfield, ";
610 $strcalc .= "SUM( aqorders.quantity ) " if ( $process == 1 );
611 $strcalc .= "SUM( aqorders.quantity * aqorders.listprice ) "
612 if ( $process == 2 );
613 $strcalc .= "FROM (aqorders, aqbasket,aqorderbreakdown)
614 LEFT JOIN items ON (aqorders.biblioitemnumber= items.biblioitemnumber)
615 LEFT JOIN biblioitems ON (aqorders.biblioitemnumber= biblioitems.biblioitemnumber)
616 LEFT JOIN aqorderdelivery ON (aqorders.ordernumber =aqorderdelivery.ordernumber )
617 LEFT JOIN aqbooksellers ON (aqbasket.booksellerid=aqbooksellers.id) WHERE (aqorders.basketno=aqbasket.basketno)
618 AND (aqorderbreakdown.ordernumber=aqorders.ordernumber) ";
620 @$filters[0] =~ s/\*/%/g if ( @$filters[0] );
621 $strcalc .= " AND aqbasket.closedate > '" . @$filters[0] . "'"
622 if ( @$filters[0] );
623 @$filters[1] =~ s/\*/%/g if ( @$filters[1] );
624 $strcalc .= " AND aqbasket.closedate < '" . @$filters[1] . "'"
625 if ( @$filters[1] );
626 @$filters[2] =~ s/\*/%/g if ( @$filters[2] );
627 $strcalc .= " AND aqorderdelivery.deliverydate > '" . @$filters[2] . "'"
628 if ( @$filters[2] );
629 @$filters[3] =~ s/\*/%/g if ( @$filters[3] );
630 $strcalc .= " AND aqorderdelivery.deliverydate < '" . @$filters[3] . "'"
631 if ( @$filters[3] );
632 @$filters[4] =~ s/\*/%/g if ( @$filters[4] );
633 $strcalc .= " AND aqbasket.closedate > '" . @$filters[4] . "'"
634 if ( @$filters[4] );
635 @$filters[5] =~ s/\*/%/g if ( @$filters[5] );
636 $strcalc .= " AND aqbasket.closedate < '" . @$filters[5] . "'"
637 if ( @$filters[5] );
638 @$filters[6] =~ s/\*/%/g if ( @$filters[6] );
639 $strcalc .= " AND aqbooksellers.name LIKE '" . @$filters[6] . "'"
640 if ( @$filters[6] );
641 @$filters[7] =~ s/\*/%/g if ( @$filters[7] );
642 $strcalc .= " AND biblioitems.itemtype LIKE '" . @$filters[7] . "'"
643 if ( @$filters[7] );
644 @$filters[8] =~ s/\*/%/g if ( @$filters[8] );
645 $strcalc .= " AND aqbookfund.bookfundid LIKE '" . @$filters[8] . "'"
646 if ( @$filters[8] );
647 @$filters[9] =~ s/\*/%/g if ( @$filters[9] );
648 $strcalc .= " AND aqorders.sort1 LIKE '" . @$filters[9] . "'"
649 if ( @$filters[9] );
650 @$filters[10] =~ s/\*/%/g if ( @$filters[10] );
651 $strcalc .= " AND aqorders.sort2 LIKE '" . @$filters[10] . "'"
652 if ( @$filters[10] );
653 $strcalc .= " GROUP BY $linefield, $colfield ORDER BY $linefield,$colfield";
655 # warn "/n/n". $strcalc;
656 my $dbcalc = $dbh->prepare($strcalc);
657 $dbcalc->execute;
659 # warn "filling table";
660 my $emptycol;
661 while ( my ( $row, $col, $value ) = $dbcalc->fetchrow ) {
663 # warn "filling table $row / $col / $value ";
664 $emptycol = 1 if ( $col eq undef );
665 $col = "zzEMPTY" if ( $col eq undef );
666 $row = "zzEMPTY" if ( $row eq undef );
668 $table{$row}->{$col} += $value;
669 $table{$row}->{totalrow} += $value;
670 $grantotal += $value;
673 push @loopcol, { coltitle => "NULL" } if ($emptycol);
675 foreach my $row ( sort keys %table ) {
676 my @loopcell;
678 #@loopcol ensures the order for columns is common with column titles
679 # and the number matches the number of columns
680 foreach my $col (@loopcol) {
681 my $value = $table{$row}->{
682 ( $col->{coltitle} eq "NULL" )
683 ? "zzEMPTY"
684 : $col->{coltitle}
686 push @loopcell, { value => $value };
688 push @looprow,
690 'rowtitle' => ( $row eq "zzEMPTY" ) ? "NULL" : $row,
691 'loopcell' => \@loopcell,
692 'hilighted' => ( $hilighted > 0 ),
693 'totalrow' => $table{$row}->{totalrow}
695 $hilighted = -$hilighted;
698 # warn "footer processing";
699 foreach my $col (@loopcol) {
700 my $total = 0;
701 foreach my $row (@looprow) {
702 $total += $table{
703 ( $row->{rowtitle} eq "NULL" ) ? "zzEMPTY"
704 : $row->{rowtitle}
705 }->{
706 ( $col->{coltitle} eq "NULL" ) ? "zzEMPTY"
707 : $col->{coltitle}
710 # warn "value added ".$table{$row->{rowtitle}}->{$col->{coltitle}}. "for line ".$row->{rowtitle};
713 # warn "summ for column ".$col->{coltitle}." = ".$total;
714 push @loopfooter, { 'totalcol' => $total };
717 # the header of the table
718 # $globalline{loopfilter}=\@loopfilter;
719 # the core of the table
720 $globalline{looprow} = \@looprow;
721 $globalline{loopcol} = \@loopcol;
723 # # the foot (totals by borrower type)
724 $globalline{loopfooter} = \@loopfooter;
725 $globalline{total} = $grantotal;
726 $globalline{line} = $line;
727 $globalline{column} = $column;
728 push @mainloop, \%globalline;
729 return \@mainloop;