Syncing rangik enhancements to main.
[koha.git] / reports / acquisitions_stats.pl
1 #!/usr/bin/perl
2
3 # $Id$
4
5 # Copyright 2000-2002 Katipo Communications
6 #
7 # This file is part of Koha.
8 #
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
12 # version.
13 #
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License along with
19 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
20 # Suite 330, Boston, MA  02111-1307 USA
21
22 # test comment
23
24 use strict;
25 use C4::Auth;
26 use CGI;
27 use C4::Context;
28 use HTML::Template;
29 use C4::Search;
30 use C4::Output;
31 use C4::Koha;
32 use C4::Interface::CGI::Output;
33 use C4::Circulation::Circ2;
34
35 =head1 NAME
36
37 plugin that shows a stats on borrowers
38
39 =head1 DESCRIPTION
40
41
42 =over2
43
44 =cut
45
46 my $input = new CGI;
47 my $do_it=$input->param('do_it');
48 my $fullreportname = "reports/acquisitions_stats.tmpl";
49 my $line = $input->param("Line");
50 my $column = $input->param("Column");
51 my @filters = $input->param("Filter");
52 my $podsp = $input->param("PlacedOnDisplay");
53 my $rodsp = $input->param("ReceivedOnDisplay");
54 my $aodsp = $input->param("AcquiredOnDisplay"); ##added by mason.
55 my $calc = $input->param("Cellvalue");
56 my $output = $input->param("output");
57 my $basename = $input->param("basename");
58 my $mime = $input->param("MIME");
59 my $del = $input->param("sep");
60 #warn "calcul : ".$calc;
61 my ($template, $borrowernumber, $cookie)
62         = get_template_and_user({template_name => $fullreportname,
63                                 query => $input,
64                                 type => "intranet",
65                                 authnotrequired => 0,
66                                 flagsrequired => {editcatalogue => 1},
67                                 debug => 1,
68                                 });
69 $template->param(do_it => $do_it);
70 if ($do_it) {
71 warn "line=$line, col=$column, pod=$podsp, rod=$rodsp, aod=$aodsp, calc=$calc, filters=@filters\n";
72
73         my $results = calculate($line, $column, $podsp, $rodsp, $aodsp, $calc, \@filters);
74         if ($output eq "screen"){
75                 $template->param(mainloop => $results);
76                 output_html_with_http_headers $input, $cookie, $template->output;
77                 exit(1);
78         } else {
79                 print $input->header(-type => 'application/vnd.sun.xml.calc',
80                                                          -attachment=>"$basename.csv",
81                                                          -name=>"$basename.csv" );
82                 my $cols = @$results[0]->{loopcol};
83                 my $lines = @$results[0]->{looprow};
84                 my $sep;
85                 $sep =C4::Context->preference("delimiter");
86                 print @$results[0]->{line} ."/". @$results[0]->{column} .$sep;
87                 foreach my $col ( @$cols ) {
88                         print $col->{coltitle}.$sep;
89                 }
90                 print "Total\n";
91                 foreach my $line ( @$lines ) {
92                         my $x = $line->{loopcell};
93                         print $line->{rowtitle}.$sep;
94                         foreach my $cell (@$x) {
95                                 print $cell->{value}.$sep;
96                         }
97                         print $line->{totalrow};
98                         print "\n";
99                 }
100                 print "TOTAL";
101                 $cols = @$results[0]->{loopfooter};
102                 foreach my $col ( @$cols ) {
103                         print $sep.$col->{totalcol};
104                 }
105                 print $sep.@$results[0]->{total};
106                 exit(1);
107         }
108 } else {
109         my $dbh = C4::Context->dbh;
110         my @values;
111         my %labels;
112         my %select;
113         my $req;
114         $req = $dbh->prepare("SELECT distinctrow id,name FROM aqbooksellers ORDER BY name");
115         $req->execute;
116         my @select;
117         push @select,"";
118 #       $select{""}="";
119         while (my ($value, $desc) =$req->fetchrow) {
120                 push @select, $desc;
121 #               $select{$value}=$desc;
122         }
123         my $CGIBookSellers=CGI::scrolling_list( -name     => 'Filter',
124                                 -id => 'Filter',
125                                 -values   => \@select,
126 #                               -labels   => \%select,
127                                 -size     => 1,
128                                 -multiple => 0 );
129
130         $req = $dbh->prepare( "SELECT DISTINCTROW itemtype,description FROM itemtypes ORDER BY description");
131         $req->execute;
132         undef @select;
133         undef %select;
134         push @select,"";
135         $select{""}="";
136         while (my ($value,$desc) =$req->fetchrow) {
137                 push @select, $value;
138                 $select{$value}=$desc;
139         }
140         my $CGIItemTypes=CGI::scrolling_list( -name     => 'Filter',
141                                 -id => 'Filter',
142                                 -values   => \@select,
143                                 -labels    => \%select,
144                                 -size     => 1,
145                                 -multiple => 0 );
146
147         $req = $dbh->prepare( "SELECT DISTINCTROW bookfundid,bookfundname FROM aqbookfund ORDER BY bookfundname");
148         $req->execute;
149         undef @select;
150         undef %select;
151         push @select,"";
152         $select{""}="";
153         while (my ($value,$desc) =$req->fetchrow) {
154                 push @select, $value;
155                 $select{$value}=$desc;
156         }
157         my $CGIBudget=CGI::scrolling_list( -name     => 'Filter',
158                                 -id => 'Filter',
159                                 -values   => \@select,
160                                 -labels    => \%select,
161                                 -size     => 1,
162                                 -multiple => 0 );
163
164         $req = $dbh->prepare("SELECT DISTINCTROW sort1 FROM aqorders WHERE sort1 IS NOT NULL ORDER BY sort1");
165         $req->execute;
166         undef @select;
167         push @select,"";
168         my $hassort1;
169         while (my ($value) =$req->fetchrow) {
170                 $hassort1 =1 if ($value);
171                 push @select, $value;
172         }
173         my $CGISort1=CGI::scrolling_list( -name     => 'Filter',
174                                 -id => 'Filter',
175                                 -values   => \@select,
176                                 -size     => 1,
177                                 -multiple => 0 );
178
179         $req = $dbh->prepare("SELECT DISTINCTROW sort2 FROM aqorders WHERE sort2 IS NOT NULL ORDER BY sort2");
180         $req->execute;
181         undef @select;
182         push @select,"";
183         my $hassort2;
184         my $hglghtsort2;
185         while (my ($value) =$req->fetchrow) {
186                 $hassort2 =1 if ($value);
187                 $hglghtsort2= !($hassort1);
188                 push @select, $value;
189         }
190         my $CGISort2=CGI::scrolling_list( -name     => 'Filter',
191                                 -id => 'Filter',
192                                 -values   => \@select,
193                                 -size     => 1,
194                                 -multiple => 0 );
195
196         my @mime = ( C4::Context->preference("MIME") );
197         foreach my $mime (@mime){
198 #               warn "".$mime;
199         }
200
201         my $CGIextChoice=CGI::scrolling_list(
202                                 -name     => 'MIME',
203                                 -id       => 'MIME',
204                                 -values   => \@mime,
205                                 -size     => 1,
206                                 -multiple => 0 );
207
208         my @dels = ( C4::Context->preference("delimiter") );
209         my $CGIsepChoice=CGI::scrolling_list(
210                                 -name     => 'sep',
211                                 -id       => 'sep',
212                                 -values   => \@dels,
213                                 -size     => 1,
214                                 -multiple => 0 );
215
216         $template->param(
217                                         CGIBookSeller => $CGIBookSellers,
218                                         CGIItemType => $CGIItemTypes,
219                                         CGIBudget => $CGIBudget,
220                                         hassort1=> $hassort1,
221                                         hassort2=> $hassort2,
222                                         HlghtSort2 => $hglghtsort2,
223                                         CGISort1 => $CGISort1,
224                                         CGISort2 => $CGISort2,
225                                         CGIextChoice => $CGIextChoice,
226                                         CGIsepChoice => $CGIsepChoice
227                                         );
228
229 }
230 output_html_with_http_headers $input, $cookie, $template->output;
231
232
233
234 sub calculate {
235         my ($line, $column, $podsp, $rodsp, $aodsp, $process, $filters) = @_;
236         my @mainloop;
237         my @loopfooter;
238         my @loopcol;
239         my @loopline;
240         my @looprow;
241         my %globalline;
242         my $grantotal =0;
243 # extract parameters
244         my $dbh = C4::Context->dbh;
245
246 # Filters
247 # Checking filters
248 #
249         my @loopfilter;
250         for (my $i=0;$i<=8;$i++) {
251                 my %cell;
252                 if ( @$filters[$i] ) {
253                         if ((($i==1) or ($i==3)) and (@$filters[$i-1])) {
254                                 $cell{err} = 1 if (@$filters[$i]<@$filters[$i-1]) ;
255                         }
256                         $cell{filter} .= @$filters[$i];
257                         $cell{crit} .="Placed On From" if ($i==0);
258                         $cell{crit} .="Placed On To" if ($i==1);
259                         $cell{crit} .="Received On From" if ($i==2);
260                         $cell{crit} .="Received On To" if ($i==3);
261
262                         $cell{crit} .="Acquired On From" if ($i==4);
263                         $cell{crit} .="Acquired On To" if ($i==5);
264
265                         $cell{crit} .="BookSeller" if ($i==6);
266                         $cell{crit} .="Doc Type" if ($i==7);
267                         $cell{crit} .="Budget" if ($i==8);
268                         $cell{crit} .="Sort1" if ($i==9);
269                         $cell{crit} .="Sort2" if ($i==10);
270                         push @loopfilter, \%cell;
271                 }
272         }
273
274         my @linefilter;
275 #       warn "filtres ".@filters[0];
276 #       warn "filtres ".@filters[1];
277 #       warn "filtres ".@filters[2];
278 #       warn "filtres ".@filters[3];
279
280         $linefilter[0] = @$filters[0] if ($line =~ /closedate/ )  ;
281         $linefilter[1] = @$filters[1] if ($line =~ /closedate/ )  ;
282         $linefilter[0] = @$filters[2] if ($line =~ /received/ )  ;
283         $linefilter[1] = @$filters[3] if ($line =~ /received/ )  ;
284
285         $linefilter[0] = @$filters[4] if ($line =~ /acquired/ )  ;
286         $linefilter[1] = @$filters[5] if ($line =~ /acquired/ )  ;
287
288         $linefilter[0] = @$filters[6] if ($line =~ /bookseller/ )  ;
289         $linefilter[0] = @$filters[7] if ($line =~ /itemtype/ )  ;
290         $linefilter[0] = @$filters[8] if ($line =~ /bookfund/ )  ;
291         $linefilter[0] = @$filters[9] if ($line =~ /sort1/ )  ;
292         $linefilter[0] = @$filters[10] if ($line =~ /sort2/ ) ;
293 #warn "filtre lignes".$linefilter[0]." ".$linefilter[1];
294 #
295         my @colfilter ;
296         $colfilter[0] = @$filters[0] if ($column =~ /closedate/ ) ;
297         $colfilter[1] = @$filters[1] if ($column =~ /closedate/ ) ;
298         $colfilter[0] = @$filters[2] if ($column =~ /received/ )  ;
299         $colfilter[1] = @$filters[3] if ($column =~ /received/ )  ;
300
301         $colfilter[0] = @$filters[4] if ($column =~ /acquired/ )  ;
302         $colfilter[1] = @$filters[5] if ($column =~ /acquired/ )  ;
303
304         $colfilter[0] = @$filters[6] if ($column =~ /bookseller/ );
305         $colfilter[0] = @$filters[7] if ($column =~ /itemtype/ )  ;
306         $colfilter[0] = @$filters[8] if ($column =~ /bookfund/ )  ;
307         $colfilter[0] = @$filters[9] if ($column =~ /sort1/ )     ;
308         $colfilter[0] = @$filters[10] if ($column =~ /sort2/ )     ;
309 #warn "filtre col ".$colfilter[0]." ".$colfilter[1];
310
311 warn "line=$line, podsp=$podsp, rodsp=$rodsp, aodsp=$aodsp\n";
312
313 # 1st, loop rows.
314         my $linefield;
315         if (($line =~/closedate/) and ($podsp == 1)) {
316                 #Display by day
317                 $linefield .="dayname($line)";
318         } elsif (($line=~/closedate/) and ($podsp == 2)) {
319                 #Display by Month
320                 $linefield .="monthname($line)";
321         } elsif (($line=~/closedate/) and ($podsp == 3)) {
322                 #Display by Year
323                 $linefield .="Year($line)";
324
325         } elsif (($line =~/received/) and ($rodsp == 1)) {
326                 #Display by day
327                 $linefield .="dayname($line)";
328         } elsif (($line=~/received/) and ($rodsp == 2)) {
329                 #Display by Month
330                 $linefield .="monthname($line)";
331         } elsif (($line=~/received/) and ($rodsp == 3)) {
332                 #Display by Year
333                 $linefield .="Year($line)";
334
335         } elsif (($line =~/acquired/) and ($aodsp == 1)) {
336                 #Display by day
337                 $linefield .="dayname($line)";
338         } elsif (($line=~/acquired/) and ($aodsp == 2)) {
339                 #Display by Month
340                 $linefield .="monthname($line)";
341         } elsif (($line=~/acquired/) and ($aodsp == 3)) {
342                 #Display by Year
343                 $linefield .="Year($line)";
344
345
346         } else {
347                 $linefield .= $line;
348         }
349
350         my $strsth;
351         $strsth .= "SELECT DISTINCTROW $linefield FROM aqorders, aqbasket,aqorderbreakdown
352                 LEFT JOIN items ON (aqorders.biblioitemnumber= items.biblioitemnumber)
353                 LEFT JOIN biblioitems ON (aqorders.biblioitemnumber= biblioitems.biblioitemnumber)
354                 LEFT JOIN aqorderdelivery ON (aqorders.ordernumber =aqorderdelivery.ordernumber )
355                 LEFT JOIN aqbooksellers ON (aqbasket.booksellerid=aqbooksellers.id) WHERE (aqorders.basketno=aqbasket.basketno)
356                 AND (aqorderbreakdown.ordernumber=aqorders.ordernumber) AND $line IS NOT NULL ";
357
358         if ( @linefilter ) {
359                 if ($linefilter[1]){
360                         if ($linefilter[0]){
361                                 $strsth .= " AND $line BETWEEN ? AND ? " ;
362                         } else {
363                                 $strsth .= " AND $line < ? " ;
364                         }
365                 } elsif (($linefilter[0]) and (($line=~/closedate/) or ($line=~/received/) or ($line=~/acquired/))){
366                         $strsth .= " AND $line > ? " ;
367                 } elsif ($linefilter[0]) {
368                         $linefilter[0] =~ s/\*/%/g;
369                         $strsth .= " AND $line LIKE ? " ;
370                 }
371         }
372         $strsth .=" GROUP BY $linefield";
373         $strsth .=" ORDER BY $linefield";
374         warn "377:strsth= $strsth";
375
376         my $sth = $dbh->prepare( $strsth );
377         if (( @linefilter ) and ($linefilter[1])){
378                 $sth->execute("'".$linefilter[0]."'","'".$linefilter[1]."'");
379         } elsif ($linefilter[0]) {
380                 $sth->execute($linefilter[0]);
381         } else {
382                 $sth->execute;
383         }
384
385         while ( my ($celvalue) = $sth->fetchrow) {
386                 my %cell;
387                 if ($celvalue) {
388                         $cell{rowtitle} = $celvalue;
389 #               } else {
390 #                       $cell{rowtitle} = "";
391                 }
392                 $cell{totalrow} = 0;
393                 push @loopline, \%cell;
394         }
395
396 warn "column=$column, podsp=$podsp, rodsp=$rodsp, aodsp=$aodsp\n";
397 # 2nd, loop cols.
398         my $colfield;
399         if (($column =~/closedate/) and ($podsp == 1)) {
400                 #Display by day
401                 $colfield .="dayname($column)";
402         } elsif (($column=~/closedate/) and ($podsp == 2)) {
403                 #Display by Month
404                 $colfield .="monthname($column)";
405         } elsif (($column=~/closedate/) and ($podsp == 3)) {
406                 #Display by Year
407                 $colfield .="Year($column)";
408
409         } elsif (($column =~/deliverydate/) and ($rodsp == 1)) {
410                 #Display by day
411                 $colfield .="dayname($column)";
412         } elsif (($column=~/deliverydate/) and ($rodsp == 2)) {
413                 #Display by Month
414                 $colfield .="monthname($column)";
415         } elsif (($column=~/deliverydate/) and ($rodsp == 3)) {
416                 #Display by Year
417                 $colfield .="Year($column)";
418
419         } elsif (($column =~/dateaccessioned/) and ($aodsp == 1)) {
420                 #Display by day
421                 $colfield .="dayname($column)";
422         } elsif (($column=~/dateaccessioned/) and ($aodsp == 2)) {
423                 #Display by Month
424                 $colfield .="monthname($column)";
425         } elsif (($column=~/dateaccessioned/) and ($aodsp == 3)) {
426                 #Display by Year
427                 $colfield .="Year($column)";
428
429         } else {
430                 $colfield .= $column;
431         }
432
433         my $strsth2;
434         $strsth2 .= "SELECT distinctrow $colfield FROM aqorders, aqbasket,aqorderbreakdown
435                  LEFT JOIN items ON (aqorders.biblioitemnumber= items.biblioitemnumber)
436                  LEFT JOIN biblioitems ON (aqorders.biblioitemnumber= biblioitems.biblioitemnumber)
437                  LEFT JOIN aqorderdelivery ON (aqorders.ordernumber =aqorderdelivery.ordernumber )
438                  LEFT JOIN aqbooksellers ON (aqbasket.booksellerid=aqbooksellers.id)
439                  WHERE (aqorders.basketno=aqbasket.basketno) AND (aqorderbreakdown.ordernumber=aqorders.ordernumber)
440                  AND $column IS NOT NULL";
441
442         if ( @colfilter ) {
443                 if ($colfilter[1]){
444                         if ($colfilter[0]){
445                                 $strsth2 .= " AND $column BETWEEN  ? AND ? " ;
446                         } else {
447                                 $strsth2 .= " AND $column < ? " ;
448                         }
449                 } elsif (($colfilter[0]) and (($column=~/closedate/) or ($line=~/received/) or ($line=~/acquired/))){
450                         $strsth2 .= " AND $column > ? " ;
451                 } elsif ($colfilter[0]) {
452                         $colfilter[0] =~ s/\*/%/g;
453                         $strsth2 .= " AND $column LIKE ? " ;
454                 }
455         }
456         $strsth2 .=" GROUP BY $colfield";
457         $strsth2 .=" ORDER BY $colfield";
458 #        warn "MASON:. $strsth2";
459
460         my $sth2 = $dbh->prepare( $strsth2 );
461         if (( @colfilter ) and ($colfilter[1])){
462 #                warn "from : ".$colfilter[0]." To  :".$colfilter[1];
463                 $sth2->execute("'".$colfilter[0]."'","'".$colfilter[1]."'");
464         } elsif ($colfilter[0]) {
465                 $sth2->execute($colfilter[0]);
466         } else {
467                 $sth2->execute;
468         }
469
470         while (my ($celvalue) = $sth2->fetchrow) {
471                 my %cell;
472                 if ($celvalue){
473 #               warn "coltitle :".$celvalue;
474                         $cell{coltitle} = $celvalue;
475                 }
476                 push @loopcol, \%cell;
477         }
478 #       warn "fin des titres colonnes";
479
480         my $i=0;
481         my @totalcol;
482         my $hilighted=-1;
483
484         #Initialization of cell values.....
485         my %table;
486 #       warn "init table";
487         foreach my $row ( @loopline ) {
488                 foreach my $col ( @loopcol ) {
489 #                       warn " init table : $row->{rowtitle} / $col->{coltitle} ";
490                         $table{$row->{rowtitle}}->{$col->{coltitle}}=0;
491                 }
492                 $table{$row->{rowtitle}}->{totalrow}=0;
493         }
494
495 # preparing calculation
496         my $strcalc ;
497         $strcalc .= "SELECT $linefield, $colfield, ";
498         $strcalc .= "COUNT( aqorders.ordernumber ) " if ($process ==1);
499         $strcalc .= "SUM( aqorders.quantity * aqorders.listprice ) " if ($process ==2);
500         $strcalc .= "FROM aqorders, aqbasket,aqorderbreakdown
501                  LEFT JOIN items ON (aqorders.biblioitemnumber= items.biblioitemnumber)
502                  LEFT JOIN biblioitems ON (aqorders.biblioitemnumber= biblioitems.biblioitemnumber)
503                  LEFT JOIN aqorderdelivery ON (aqorders.ordernumber =aqorderdelivery.ordernumber )
504                  LEFT JOIN aqbooksellers ON (aqbasket.booksellerid=aqbooksellers.id) WHERE (aqorders.basketno=aqbasket.basketno)
505                       AND (aqorderbreakdown.ordernumber=aqorders.ordernumber) ";
506
507         @$filters[0]=~ s/\*/%/g if (@$filters[0]);
508         $strcalc .= " AND aqbasket.closedate > '" . @$filters[0] ."'" if ( @$filters[0] );
509         @$filters[1]=~ s/\*/%/g if (@$filters[1]);
510         $strcalc .= " AND aqbasket.closedate < '" . @$filters[1] ."'" if ( @$filters[1] );
511         @$filters[2]=~ s/\*/%/g if (@$filters[2]);
512         $strcalc .= " AND aqorderdelivery.deliverydate > '" . @$filters[2] ."'" if ( @$filters[2] );
513         @$filters[3]=~ s/\*/%/g if (@$filters[3]);
514         $strcalc .= " AND aqorderdelivery.deliverydate < '" . @$filters[3] ."'" if ( @$filters[3] );
515         @$filters[4]=~ s/\*/%/g if (@$filters[4]);
516         $strcalc .= " AND aqbasket.closedate > '" . @$filters[4] ."'" if ( @$filters[4] );
517         @$filters[5]=~ s/\*/%/g if (@$filters[5]);
518         $strcalc .= " AND aqbasket.closedate < '" . @$filters[5] ."'" if ( @$filters[5] );
519         @$filters[6]=~ s/\*/%/g if (@$filters[6]);
520         $strcalc .= " AND aqbooksellers.name LIKE '" . @$filters[6] ."'" if ( @$filters[6] );
521         @$filters[7]=~ s/\*/%/g if (@$filters[7]);
522         $strcalc .= " AND biblioitems.itemtype LIKE '" . @$filters[7] ."'" if ( @$filters[7] );
523         @$filters[8]=~ s/\*/%/g if (@$filters[8]);
524         $strcalc .= " AND aqbookfund.bookfundid LIKE '" . @$filters[8] ."'" if ( @$filters[8] );
525         @$filters[9]=~ s/\*/%/g if (@$filters[9]);
526         $strcalc .= " AND aqorders.sort1 LIKE '" . @$filters[9] ."'" if ( @$filters[9] );
527         @$filters[10]=~ s/\*/%/g if (@$filters[10]);
528         $strcalc .= " AND aqorders.sort2 LIKE '" . @$filters[10] ."'" if ( @$filters[10] );
529         $strcalc .= " GROUP BY $linefield, $colfield ORDER BY $linefield,$colfield";
530 #        warn "/n/n". $strcalc;
531         my $dbcalc = $dbh->prepare($strcalc);
532         $dbcalc->execute;
533
534 #       warn "filling table";
535         my $emptycol;
536         while (my ($row, $col, $value) = $dbcalc->fetchrow) {
537 #              warn "filling table $row / $col / $value ";
538                 $emptycol = 1 if ($col eq undef);
539                 $col = "zzEMPTY" if ($col eq undef);
540                 $row = "zzEMPTY" if ($row eq undef);
541
542                 $table{$row}->{$col}+=$value;
543                 $table{$row}->{totalrow}+=$value;
544                 $grantotal += $value;
545         }
546
547         push @loopcol,{coltitle => "NULL"} if ($emptycol);
548
549         foreach my $row ( sort keys %table ) {
550                 my @loopcell;
551                 #@loopcol ensures the order for columns is common with column titles
552                 # and the number matches the number of columns
553                 foreach my $col ( @loopcol ) {
554                         my $value =$table{$row}->{($col->{coltitle} eq "NULL")?"zzEMPTY":$col->{coltitle}};
555                         push @loopcell, {value => $value  } ;
556                 }
557                 push @looprow,{ 'rowtitle' => ($row eq "zzEMPTY")?"NULL":$row,
558                                                 'loopcell' => \@loopcell,
559                                                 'hilighted' => ($hilighted >0),
560                                                 'totalrow' => $table{$row}->{totalrow}
561                                         };
562                 $hilighted = -$hilighted;
563         }
564
565 #       warn "footer processing";
566         foreach my $col ( @loopcol ) {
567                 my $total=0;
568                 foreach my $row ( @looprow ) {
569                         $total += $table{($row->{rowtitle} eq "NULL")?"zzEMPTY":$row->{rowtitle}}->{($col->{coltitle} eq "NULL")?"zzEMPTY":$col->{coltitle}};
570 #                       warn "value added ".$table{$row->{rowtitle}}->{$col->{coltitle}}. "for line ".$row->{rowtitle};
571                 }
572 #               warn "summ for column ".$col->{coltitle}."  = ".$total;
573                 push @loopfooter, {'totalcol' => $total};
574         }
575
576
577         # the header of the table
578 #        $globalline{loopfilter}=\@loopfilter;
579         # the core of the table
580         $globalline{looprow} = \@looprow;
581         $globalline{loopcol} = \@loopcol;
582 #       # the foot (totals by borrower type)
583         $globalline{loopfooter} = \@loopfooter;
584         $globalline{total}= $grantotal;
585         $globalline{line} = $line;
586         $globalline{column} = $column;
587         push @mainloop,\%globalline;
588         return \@mainloop;
589 }
590
591 1;
592