Working on fixing bug for acquisition bookfund modifying, work in progress
[koha.git] / reports / acquisitions_stats.pl
blob89551266264c5ac2a36e3d6c20b608cb4f80a2db
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::Date;
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 => get_date_format_string_for_DHTMLcalendar(),
74 if ($do_it) {
76 #warn
77 "line=$line, col=$column, pod=$podsp, rod=$rodsp, aod=$aodsp, calc=$calc, filters=@filters\n";
79 my $results =
80 calculate( $line, $column, $podsp, $rodsp, $aodsp, $calc, \@filters );
81 if ( $output eq "screen" ) {
82 $template->param( mainloop => $results );
83 output_html_with_http_headers $input, $cookie, $template->output;
84 exit(1);
86 else {
87 print $input->header(
88 -type => 'application/vnd.sun.xml.calc',
89 -encoding => 'utf-8',
90 -attachment => "$basename.csv",
91 -name => "$basename.csv"
93 my $cols = @$results[0]->{loopcol};
94 my $lines = @$results[0]->{looprow};
95 my $sep;
96 $sep = C4::Context->preference("delimiter");
97 print @$results[0]->{line} . "/" . @$results[0]->{column} . $sep;
98 foreach my $col (@$cols) {
99 print $col->{coltitle} . $sep;
101 print "Total\n";
102 foreach my $line (@$lines) {
103 my $x = $line->{loopcell};
104 print $line->{rowtitle} . $sep;
105 foreach my $cell (@$x) {
106 print $cell->{value} . $sep;
108 print $line->{totalrow};
109 print "\n";
111 print "TOTAL";
112 $cols = @$results[0]->{loopfooter};
113 foreach my $col (@$cols) {
114 print $sep. $col->{totalcol};
116 print $sep. @$results[0]->{total};
117 exit(1);
120 else {
121 my $dbh = C4::Context->dbh;
122 my @values;
123 my %labels;
124 my %select;
125 my $req;
126 $req =
127 $dbh->prepare(
128 "SELECT distinctrow id,name FROM aqbooksellers ORDER BY name");
129 $req->execute;
130 my @select;
131 push @select, "";
133 # $select{""}="";
134 while ( my ( $value, $desc ) = $req->fetchrow ) {
135 push @select, $desc;
137 # $select{$value}=$desc;
139 my $CGIBookSellers = CGI::scrolling_list(
140 -name => 'Filter',
141 -id => 'supplier',
142 -values => \@select,
144 # -labels => \%select,
145 -size => 1,
146 -multiple => 0
149 $req =
150 $dbh->prepare(
151 "SELECT DISTINCTROW itemtype,description FROM itemtypes ORDER BY description"
153 $req->execute;
154 undef @select;
155 undef %select;
156 push @select, "";
157 $select{""} = "";
158 while ( my ( $value, $desc ) = $req->fetchrow ) {
159 push @select, $value;
160 $select{$value} = $desc;
162 my $CGIItemTypes = CGI::scrolling_list(
163 -name => 'Filter',
164 -id => 'itemtypes',
165 -values => \@select,
166 -labels => \%select,
167 -size => 1,
168 -multiple => 0
171 $req =
172 $dbh->prepare(
173 "SELECT DISTINCTROW bookfundid,bookfundname FROM aqbookfund ORDER BY bookfundname"
175 $req->execute;
176 undef @select;
177 undef %select;
178 push @select, "";
179 $select{""} = "";
181 while ( my ( $value, $desc ) = $req->fetchrow ) {
182 push @select, $value;
183 $select{$value} = $desc;
185 my $CGIBudget = CGI::scrolling_list(
186 -name => 'Filter',
187 -id => 'budget',
188 -values => \@select,
189 -labels => \%select,
190 -size => 1,
191 -multiple => 0
194 $req =
195 $dbh->prepare(
196 "SELECT DISTINCTROW sort1 FROM aqorders WHERE sort1 IS NOT NULL ORDER BY sort1"
198 $req->execute;
199 undef @select;
200 push @select, "";
201 my $hassort1;
202 while ( my ($value) = $req->fetchrow ) {
203 $hassort1 = 1 if ($value);
204 push @select, $value;
206 my $CGISort1 = CGI::scrolling_list(
207 -name => 'Filter',
208 -id => 'sort1',
209 -values => \@select,
210 -size => 1,
211 -multiple => 0
214 $req =
215 $dbh->prepare(
216 "SELECT DISTINCTROW sort2 FROM aqorders WHERE sort2 IS NOT NULL ORDER BY sort2"
218 $req->execute;
219 undef @select;
220 push @select, "";
221 my $hassort2;
222 my $hglghtsort2;
224 while ( my ($value) = $req->fetchrow ) {
225 $hassort2 = 1 if ($value);
226 $hglghtsort2 = !($hassort1);
227 push @select, $value;
229 my $CGISort2 = CGI::scrolling_list(
230 -name => 'Filter',
231 -id => 'sort2',
232 -values => \@select,
233 -size => 1,
234 -multiple => 0
237 my @mime = ( C4::Context->preference("MIME") );
238 foreach my $mime (@mime) {
240 # warn "".$mime;
243 my $CGIextChoice = CGI::scrolling_list(
244 -name => 'MIME',
245 -id => 'MIME',
246 -values => \@mime,
247 -size => 1,
248 -multiple => 0
251 my @dels = ( C4::Context->preference("delimiter") );
252 my $CGIsepChoice = CGI::scrolling_list(
253 -name => 'sep',
254 -id => 'sep',
255 -values => \@dels,
256 -size => 1,
257 -multiple => 0
260 $template->param(
261 CGIBookSeller => $CGIBookSellers,
262 CGIItemType => $CGIItemTypes,
263 CGIBudget => $CGIBudget,
264 hassort1 => $hassort1,
265 hassort2 => $hassort2,
266 HlghtSort2 => $hglghtsort2,
267 CGISort1 => $CGISort1,
268 CGISort2 => $CGISort2,
269 CGIextChoice => $CGIextChoice,
270 CGIsepChoice => $CGIsepChoice
274 output_html_with_http_headers $input, $cookie, $template->output;
276 sub calculate {
277 my ( $line, $column, $podsp, $rodsp, $aodsp, $process, $filters ) = @_;
278 my @mainloop;
279 my @loopfooter;
280 my @loopcol;
281 my @loopline;
282 my @looprow;
283 my %globalline;
284 my $grantotal = 0;
286 # extract parameters
287 my $dbh = C4::Context->dbh;
289 # Filters
290 # Checking filters
292 my @loopfilter;
293 for ( my $i = 0 ; $i <= 8 ; $i++ ) {
294 my %cell;
295 if ( @$filters[$i] ) {
296 if ( ( ( $i == 1 ) or ( $i == 3 ) ) and ( @$filters[ $i - 1 ] ) ) {
297 $cell{err} = 1 if ( @$filters[$i] < @$filters[ $i - 1 ] );
299 # format the dates filters, otherwise just fill as is
300 if ($i>=4) {
301 $cell{filter} .= @$filters[$i];
302 } else {
303 $cell{filter} .= format_date(@$filters[$i]);
305 $cell{crit} .= "Placed On From" if ( $i == 0 );
306 $cell{crit} .= "Placed On To" if ( $i == 1 );
307 $cell{crit} .= "Received On From" if ( $i == 2 );
308 $cell{crit} .= "Received On To" if ( $i == 3 );
310 $cell{crit} .= "Acquired On From" if ( $i == 4 );
311 $cell{crit} .= "Acquired On To" if ( $i == 5 );
313 $cell{crit} .= "BookSeller" if ( $i == 6 );
314 $cell{crit} .= "Doc Type" if ( $i == 7 );
315 $cell{crit} .= "Budget" if ( $i == 8 );
316 $cell{crit} .= "Sort1" if ( $i == 9 );
317 $cell{crit} .= "Sort2" if ( $i == 10 );
318 push @loopfilter, \%cell;
322 my @linefilter;
324 # warn "filtres ".@filters[0];
325 # warn "filtres ".@filters[1];
326 # warn "filtres ".@filters[2];
327 # warn "filtres ".@filters[3];
329 $linefilter[0] = @$filters[0] if ( $line =~ /closedate/ );
330 $linefilter[1] = @$filters[1] if ( $line =~ /closedate/ );
331 $linefilter[0] = @$filters[2] if ( $line =~ /received/ );
332 $linefilter[1] = @$filters[3] if ( $line =~ /received/ );
334 $linefilter[0] = @$filters[4] if ( $line =~ /acquired/ );
335 $linefilter[1] = @$filters[5] if ( $line =~ /acquired/ );
337 $linefilter[0] = @$filters[6] if ( $line =~ /bookseller/ );
338 $linefilter[0] = @$filters[7] if ( $line =~ /itemtype/ );
339 $linefilter[0] = @$filters[8] if ( $line =~ /bookfund/ );
340 $linefilter[0] = @$filters[9] if ( $line =~ /sort1/ );
341 $linefilter[0] = @$filters[10] if ( $line =~ /sort2/ );
343 #warn "filtre lignes".$linefilter[0]." ".$linefilter[1];
345 my @colfilter;
346 $colfilter[0] = @$filters[0] if ( $column =~ /closedate/ );
347 $colfilter[1] = @$filters[1] if ( $column =~ /closedate/ );
348 $colfilter[0] = @$filters[2] if ( $column =~ /received/ );
349 $colfilter[1] = @$filters[3] if ( $column =~ /received/ );
351 $colfilter[0] = @$filters[4] if ( $column =~ /acquired/ );
352 $colfilter[1] = @$filters[5] if ( $column =~ /acquired/ );
354 $colfilter[0] = @$filters[6] if ( $column =~ /bookseller/ );
355 $colfilter[0] = @$filters[7] if ( $column =~ /itemtype/ );
356 $colfilter[0] = @$filters[8] if ( $column =~ /bookfund/ );
357 $colfilter[0] = @$filters[9] if ( $column =~ /sort1/ );
358 $colfilter[0] = @$filters[10] if ( $column =~ /sort2/ );
360 #warn "filtre col ".$colfilter[0]." ".$colfilter[1];
362 #warn "line=$line, podsp=$podsp, rodsp=$rodsp, aodsp=$aodsp\n";
364 # 1st, loop rows.
365 my $linefield;
366 if ( ( $line =~ /closedate/ ) and ( $podsp == 1 ) ) {
368 #Display by day
369 $linefield .= "dayname($line)";
371 elsif ( ( $line =~ /closedate/ ) and ( $podsp == 2 ) ) {
373 #Display by Month
374 $linefield .= "monthname($line)";
376 elsif ( ( $line =~ /closedate/ ) and ( $podsp == 3 ) ) {
378 #Display by Year
379 $linefield .= "Year($line)";
382 elsif ( ( $line =~ /received/ ) and ( $rodsp == 1 ) ) {
384 #Display by day
385 $linefield .= "dayname($line)";
387 elsif ( ( $line =~ /received/ ) and ( $rodsp == 2 ) ) {
389 #Display by Month
390 $linefield .= "monthname($line)";
392 elsif ( ( $line =~ /received/ ) and ( $rodsp == 3 ) ) {
394 #Display by Year
395 $linefield .= "Year($line)";
398 elsif ( ( $line =~ /acquired/ ) and ( $aodsp == 1 ) ) {
400 #Display by day
401 $linefield .= "dayname($line)";
403 elsif ( ( $line =~ /acquired/ ) and ( $aodsp == 2 ) ) {
405 #Display by Month
406 $linefield .= "monthname($line)";
408 elsif ( ( $line =~ /acquired/ ) and ( $aodsp == 3 ) ) {
410 #Display by Year
411 $linefield .= "Year($line)";
414 else {
415 $linefield .= $line;
418 my $strsth;
419 $strsth .=
420 "SELECT DISTINCTROW $linefield FROM (aqorders, aqbasket,aqorderbreakdown)
421 LEFT JOIN items ON (aqorders.biblioitemnumber= items.biblioitemnumber)
422 LEFT JOIN biblioitems ON (aqorders.biblioitemnumber= biblioitems.biblioitemnumber)
423 LEFT JOIN aqorderdelivery ON (aqorders.ordernumber =aqorderdelivery.ordernumber )
424 LEFT JOIN aqbooksellers ON (aqbasket.booksellerid=aqbooksellers.id) WHERE (aqorders.basketno=aqbasket.basketno)
425 AND (aqorderbreakdown.ordernumber=aqorders.ordernumber) AND $line IS NOT NULL ";
427 if (@linefilter) {
428 if ( $linefilter[1] ) {
429 if ( $linefilter[0] ) {
430 $strsth .= " AND $line BETWEEN ? AND ? ";
432 else {
433 $strsth .= " AND $line < ? ";
436 elsif (
437 ( $linefilter[0] )
438 and ( ( $line =~ /closedate/ )
439 or ( $line =~ /received/ )
440 or ( $line =~ /acquired/ ) )
443 $strsth .= " AND $line > ? ";
445 elsif ( $linefilter[0] ) {
446 $linefilter[0] =~ s/\*/%/g;
447 $strsth .= " AND $line LIKE ? ";
450 $strsth .= " GROUP BY $linefield";
451 $strsth .= " ORDER BY $linefield";
453 #warn "377:strsth= $strsth";
455 my $sth = $dbh->prepare($strsth);
456 if ( (@linefilter) and ( $linefilter[1] ) ) {
457 $sth->execute( "'" . $linefilter[0] . "'", "'" . $linefilter[1] . "'" );
459 elsif ( $linefilter[0] ) {
460 $sth->execute( $linefilter[0] );
462 else {
463 $sth->execute;
466 while ( my ($celvalue) = $sth->fetchrow ) {
467 my %cell;
468 if ($celvalue) {
469 $cell{rowtitle} = $celvalue;
471 # } else {
472 # $cell{rowtitle} = "";
474 $cell{totalrow} = 0;
475 push @loopline, \%cell;
478 #warn "column=$column, podsp=$podsp, rodsp=$rodsp, aodsp=$aodsp\n";
480 # 2nd, loop cols.
481 my $colfield;
482 if ( ( $column =~ /closedate/ ) and ( $podsp == 1 ) ) {
484 #Display by day
485 $colfield .= "dayname($column)";
487 elsif ( ( $column =~ /closedate/ ) and ( $podsp == 2 ) ) {
489 #Display by Month
490 $colfield .= "monthname($column)";
492 elsif ( ( $column =~ /closedate/ ) and ( $podsp == 3 ) ) {
494 #Display by Year
495 $colfield .= "Year($column)";
498 elsif ( ( $column =~ /deliverydate/ ) and ( $rodsp == 1 ) ) {
500 #Display by day
501 $colfield .= "dayname($column)";
503 elsif ( ( $column =~ /deliverydate/ ) and ( $rodsp == 2 ) ) {
505 #Display by Month
506 $colfield .= "monthname($column)";
508 elsif ( ( $column =~ /deliverydate/ ) and ( $rodsp == 3 ) ) {
510 #Display by Year
511 $colfield .= "Year($column)";
514 elsif ( ( $column =~ /dateaccessioned/ ) and ( $aodsp == 1 ) ) {
516 #Display by day
517 $colfield .= "dayname($column)";
519 elsif ( ( $column =~ /dateaccessioned/ ) and ( $aodsp == 2 ) ) {
521 #Display by Month
522 $colfield .= "monthname($column)";
524 elsif ( ( $column =~ /dateaccessioned/ ) and ( $aodsp == 3 ) ) {
526 #Display by Year
527 $colfield .= "Year($column)";
530 else {
531 $colfield .= $column;
534 my $strsth2;
535 $strsth2 .=
536 "SELECT distinctrow $colfield FROM (aqorders, aqbasket,aqorderbreakdown)
537 LEFT JOIN items ON (aqorders.biblioitemnumber= items.biblioitemnumber)
538 LEFT JOIN biblioitems ON (aqorders.biblioitemnumber= biblioitems.biblioitemnumber)
539 LEFT JOIN aqorderdelivery ON (aqorders.ordernumber =aqorderdelivery.ordernumber )
540 LEFT JOIN aqbooksellers ON (aqbasket.booksellerid=aqbooksellers.id)
541 WHERE (aqorders.basketno=aqbasket.basketno) AND (aqorderbreakdown.ordernumber=aqorders.ordernumber)
542 AND $column IS NOT NULL";
544 if (@colfilter) {
545 if ( $colfilter[1] ) {
546 if ( $colfilter[0] ) {
547 $strsth2 .= " AND $column BETWEEN ? AND ? ";
549 else {
550 $strsth2 .= " AND $column < ? ";
553 elsif (
554 ( $colfilter[0] )
555 and ( ( $column =~ /closedate/ )
556 or ( $line =~ /received/ )
557 or ( $line =~ /acquired/ ) )
560 $strsth2 .= " AND $column > ? ";
562 elsif ( $colfilter[0] ) {
563 $colfilter[0] =~ s/\*/%/g;
564 $strsth2 .= " AND $column LIKE ? ";
567 $strsth2 .= " GROUP BY $colfield";
568 $strsth2 .= " ORDER BY $colfield";
570 # warn "MASON:. $strsth2";
572 my $sth2 = $dbh->prepare($strsth2);
573 if ( (@colfilter) and ( $colfilter[1] ) ) {
575 # warn "from : ".$colfilter[0]." To :".$colfilter[1];
576 $sth2->execute( "'" . $colfilter[0] . "'", "'" . $colfilter[1] . "'" );
578 elsif ( $colfilter[0] ) {
579 $sth2->execute( $colfilter[0] );
581 else {
582 $sth2->execute;
585 while ( my ($celvalue) = $sth2->fetchrow ) {
586 my %cell;
587 if ($celvalue) {
589 # warn "coltitle :".$celvalue;
590 $cell{coltitle} = $celvalue;
592 push @loopcol, \%cell;
595 # warn "fin des titres colonnes";
597 my $i = 0;
598 my @totalcol;
599 my $hilighted = -1;
601 #Initialization of cell values.....
602 my %table;
604 # warn "init table";
605 foreach my $row (@loopline) {
606 foreach my $col (@loopcol) {
608 # warn " init table : $row->{rowtitle} / $col->{coltitle} ";
609 $table{ $row->{rowtitle} }->{ $col->{coltitle} } = 0;
611 $table{ $row->{rowtitle} }->{totalrow} = 0;
614 # preparing calculation
615 my $strcalc;
616 $strcalc .= "SELECT $linefield, $colfield, ";
617 $strcalc .= "SUM( aqorders.quantity ) " if ( $process == 1 );
618 $strcalc .= "SUM( aqorders.quantity * aqorders.listprice ) "
619 if ( $process == 2 );
620 $strcalc .= "FROM (aqorders, aqbasket,aqorderbreakdown)
621 LEFT JOIN items ON (aqorders.biblioitemnumber= items.biblioitemnumber)
622 LEFT JOIN biblioitems ON (aqorders.biblioitemnumber= biblioitems.biblioitemnumber)
623 LEFT JOIN aqorderdelivery ON (aqorders.ordernumber =aqorderdelivery.ordernumber )
624 LEFT JOIN aqbooksellers ON (aqbasket.booksellerid=aqbooksellers.id) WHERE (aqorders.basketno=aqbasket.basketno)
625 AND (aqorderbreakdown.ordernumber=aqorders.ordernumber) ";
627 @$filters[0] =~ s/\*/%/g if ( @$filters[0] );
628 $strcalc .= " AND aqbasket.closedate > '" . @$filters[0] . "'"
629 if ( @$filters[0] );
630 @$filters[1] =~ s/\*/%/g if ( @$filters[1] );
631 $strcalc .= " AND aqbasket.closedate < '" . @$filters[1] . "'"
632 if ( @$filters[1] );
633 @$filters[2] =~ s/\*/%/g if ( @$filters[2] );
634 $strcalc .= " AND aqorderdelivery.deliverydate > '" . @$filters[2] . "'"
635 if ( @$filters[2] );
636 @$filters[3] =~ s/\*/%/g if ( @$filters[3] );
637 $strcalc .= " AND aqorderdelivery.deliverydate < '" . @$filters[3] . "'"
638 if ( @$filters[3] );
639 @$filters[4] =~ s/\*/%/g if ( @$filters[4] );
640 $strcalc .= " AND aqbasket.closedate > '" . @$filters[4] . "'"
641 if ( @$filters[4] );
642 @$filters[5] =~ s/\*/%/g if ( @$filters[5] );
643 $strcalc .= " AND aqbasket.closedate < '" . @$filters[5] . "'"
644 if ( @$filters[5] );
645 @$filters[6] =~ s/\*/%/g if ( @$filters[6] );
646 $strcalc .= " AND aqbooksellers.name LIKE '" . @$filters[6] . "'"
647 if ( @$filters[6] );
648 @$filters[7] =~ s/\*/%/g if ( @$filters[7] );
649 $strcalc .= " AND biblioitems.itemtype LIKE '" . @$filters[7] . "'"
650 if ( @$filters[7] );
651 @$filters[8] =~ s/\*/%/g if ( @$filters[8] );
652 $strcalc .= " AND aqbookfund.bookfundid LIKE '" . @$filters[8] . "'"
653 if ( @$filters[8] );
654 @$filters[9] =~ s/\*/%/g if ( @$filters[9] );
655 $strcalc .= " AND aqorders.sort1 LIKE '" . @$filters[9] . "'"
656 if ( @$filters[9] );
657 @$filters[10] =~ s/\*/%/g if ( @$filters[10] );
658 $strcalc .= " AND aqorders.sort2 LIKE '" . @$filters[10] . "'"
659 if ( @$filters[10] );
660 $strcalc .= " GROUP BY $linefield, $colfield ORDER BY $linefield,$colfield";
662 # warn "/n/n". $strcalc;
663 my $dbcalc = $dbh->prepare($strcalc);
664 $dbcalc->execute;
666 # warn "filling table";
667 my $emptycol;
668 while ( my ( $row, $col, $value ) = $dbcalc->fetchrow ) {
670 # warn "filling table $row / $col / $value ";
671 $emptycol = 1 if ( $col eq undef );
672 $col = "zzEMPTY" if ( $col eq undef );
673 $row = "zzEMPTY" if ( $row eq undef );
675 $table{$row}->{$col} += $value;
676 $table{$row}->{totalrow} += $value;
677 $grantotal += $value;
680 push @loopcol, { coltitle => "NULL" } if ($emptycol);
682 foreach my $row ( sort keys %table ) {
683 my @loopcell;
685 #@loopcol ensures the order for columns is common with column titles
686 # and the number matches the number of columns
687 foreach my $col (@loopcol) {
688 my $value = $table{$row}->{
689 ( $col->{coltitle} eq "NULL" )
690 ? "zzEMPTY"
691 : $col->{coltitle}
693 push @loopcell, { value => $value };
695 push @looprow,
697 'rowtitle' => ( $row eq "zzEMPTY" ) ? "NULL" : $row,
698 'loopcell' => \@loopcell,
699 'hilighted' => ( $hilighted > 0 ),
700 'totalrow' => $table{$row}->{totalrow}
702 $hilighted = -$hilighted;
705 # warn "footer processing";
706 foreach my $col (@loopcol) {
707 my $total = 0;
708 foreach my $row (@looprow) {
709 $total += $table{
710 ( $row->{rowtitle} eq "NULL" ) ? "zzEMPTY"
711 : $row->{rowtitle}
712 }->{
713 ( $col->{coltitle} eq "NULL" ) ? "zzEMPTY"
714 : $col->{coltitle}
717 # warn "value added ".$table{$row->{rowtitle}}->{$col->{coltitle}}. "for line ".$row->{rowtitle};
720 # warn "summ for column ".$col->{coltitle}." = ".$total;
721 push @loopfooter, { 'totalcol' => $total };
724 # the header of the table
725 # $globalline{loopfilter}=\@loopfilter;
726 # the core of the table
727 $globalline{looprow} = \@looprow;
728 $globalline{loopcol} = \@loopcol;
730 # # the foot (totals by borrower type)
731 $globalline{loopfooter} = \@loopfooter;
732 $globalline{total} = $grantotal;
733 $globalline{line} = $line;
734 $globalline{column} = $column;
735 push @mainloop, \%globalline;
736 return \@mainloop;