bug 2278 - fix results pagination in auth_finder
[koha_fer] / reports / issues_stats.pl
index 8bce853..c75ccfd 100755 (executable)
@@ -27,6 +27,7 @@ use C4::Koha;
 use C4::Output;
 use C4::Circulation;
 use C4::Dates qw/format_date format_date_in_iso/;
+use C4::Members;
 use Date::Manip;
 
 =head1 NAME
@@ -39,6 +40,7 @@ plugin that shows a stats on borrowers
 
 =cut
 
+my $debug = 1;
 my $input = new CGI;
 my $do_it=$input->param('do_it');
 my $fullreportname = "reports/issues_stats.tmpl";
@@ -56,18 +58,31 @@ my $output = $input->param("output");
 my $basename = $input->param("basename");
 my $mime = $input->param("MIME");
 my $del = $input->param("sep");
-#warn "calcul : ".$calc;
 my ($template, $borrowernumber, $cookie)
     = get_template_and_user({template_name => $fullreportname,
                             query => $input,
                             type => "intranet",
                             authnotrequired => 0,
                             flagsrequired => {reports => 1},
-                            debug => 1,
+                            debug => 0,
                             });
 $template->param(do_it => $do_it,
         DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
                 );
+
+my $itemtypes = GetItemTypes();
+my $categoryloop = GetBorrowercategoryList;
+
+my $ccodes = GetKohaAuthorisedValues("items.ccode");
+my $locations = GetKohaAuthorisedValues("items.location");
+
+my $Bsort1 = GetAuthorisedValues("Bsort1");
+my $Bsort2 = GetAuthorisedValues("Bsort2");
+my ($hassort1,$hassort2);
+$hassort1=1 if $Bsort1;
+$hassort2=1 if $Bsort2;
+
+
 if ($do_it) {
 # Displaying results
     my $results = calculate($line, $column, $podsp, $type, $daysel, $monthsel, $calc, \@filters);
@@ -118,100 +133,36 @@ if ($do_it) {
     my @values;
     my %labels;
     my %select;
-    my $req;
-    $req = $dbh->prepare("select distinctrow categorycode,description from categories order by description");
-    $req->execute;
-    my @select;
-    push @select,"";
-    $select{""}="";
-    while (my ($value, $desc) =$req->fetchrow) {
-        push @select, $value;
-        $select{$value}=$desc;
-    }
-    my $CGIBorCat=CGI::scrolling_list( -name     => 'Filter',
-                            -id => 'borcat',
-                            -values   => \@select,
-                            -labels   => \%select,
-                            -size     => 1,
-                            -multiple => 0 );
-    
-    $req = $dbh->prepare( "select distinctrow itemtype,description from itemtypes order by description");
-    $req->execute;
-    undef @select;
-    undef %select;
-    push @select,"";
-    $select{""}="";
-    while (my ($value,$desc) =$req->fetchrow) {
-        push @select, $value;
-        $select{$value}=$desc;
-    }
-    my $CGIItemTypes=CGI::scrolling_list( -name     => 'Filter',
-                            -id => 'itemtype',
-                            -values   => \@select,
-                            -labels    => \%select,
-                            -size     => 1,
-                            -multiple => 0 );
+
+   # create itemtype arrayref for <select>.
+   my @itemtypeloop;
+    for my $itype ( keys(%$itemtypes)) {
+               push @itemtypeloop, { code => $itype , description => $itemtypes->{$itype}->{description} } ;
+       }
     
-    $req = $dbh->prepare("select distinctrow sort1 from borrowers where sort1 is not null order by sort1");
-    $req->execute;
-    undef @select;
-    push @select,"";
-    my $hassort1;
-    while (my ($value) =$req->fetchrow) {
-        $hassort1 =1 if ($value);
-        push @select, $value;
-    }
     my $branches=GetBranches();
-    my @select_branch;
-    my %select_branches;
-    push @select_branch,"";
-    $select_branches{""} = "";
-    foreach my $branch (keys %$branches) {
-        push @select_branch, $branch;
-        $select_branches{$branch} = $branches->{$branch}->{'branchname'};
-    }
-    my $CGIBranch=CGI::scrolling_list( -name     => 'Filter',
-                            -id => 'branch',
-                            -values   => \@select_branch,
-                            -labels   => \%select_branches,
-                            -size     => 1,
-                            -multiple => 0 );
-    
-    my $CGISort1=CGI::scrolling_list( -name     => 'Filter',
-                            -id => 'sort1',
-                            -values   => \@select,
-                            -size     => 1,
-                            -multiple => 0 );
-    
-    $req = $dbh->prepare("select distinctrow sort2 from borrowers where sort2 is not null order by sort2");
-    $req->execute;
-    undef @select;
-    push @select,"";
-    my $hassort2;
-    my $hglghtsort2;
-    while (my ($value) =$req->fetchrow) {
-        $hassort2 =1 if ($value);
-        $hglghtsort2= !($hassort1);
-        push @select, $value;
+       my @branchloop;
+    foreach (keys %$branches) {
+        my $thisbranch = ''; 
+        my %row = (branchcode => $_,
+            selected => ($thisbranch eq $_ ? 1 : 0),
+            code => $branches->{$_}->{'branchcode'},
+            description => $branches->{$_}->{'branchname'},
+        );
+        push @branchloop, \%row;
     }
-    my $CGISort2=CGI::scrolling_list( -name     => 'Filter',
-                            -id => 'sort2',
-                            -values   => \@select,
-                            -size     => 1,
-                            -multiple => 0 );
+
     # location list
-    $req = $dbh->prepare("select distinctrow location from items order by location");
-    $req->execute;
-    undef @select;
-    push @select,"";
-    while (my ($value) =$req->fetchrow) {
-        push @select, $value;
+    my @locations;
+    foreach (sort keys %$locations) {
+        push @locations, { code => $_, description => "$_ - " . $locations->{$_} };
     }
-    my $CGIlocation=CGI::scrolling_list( -name     => 'Filter',
-                            -id => 'location',
-                            -values   => \@select,
-                            -size     => 1,
-                            -multiple => 0 );
+    
+    my @ccodes;
+    foreach (keys %$ccodes) {
+        push @ccodes, { code => $_, description => $ccodes->{$_} };
+    }
+
     # various
     my @mime = ( C4::Context->preference("MIME") );
     
@@ -229,19 +180,19 @@ if ($do_it) {
                             -values   => \@dels,
                             -size     => 1,
                             -multiple => 0 );
-    
     $template->param(
-        CGIBorCat => $CGIBorCat,
-        CGIItemType => $CGIItemTypes,
-        CGIBranch => $CGIBranch,
-        hassort1=> $hassort1,
+        categoryloop => $categoryloop,
+               itemtypeloop => \@itemtypeloop,
+               hassort1=> $hassort1,
         hassort2=> $hassort2,
-        HlghtSort2 => $hglghtsort2,
-        CGISort1 => $CGISort1,
-        CGISort2 => $CGISort2,
+               Bsort1 => $Bsort1,
+               Bsort2 => $Bsort2,
         CGIextChoice => $CGIextChoice,
         CGIsepChoice => $CGIsepChoice,
-        CGILocation => $CGIlocation,
+        locationloop => \@locations,
+               ccodeloop => \@ccodes,
+        branchloop => \@branchloop,
         );
     output_html_with_http_headers $input, $cookie, $template->output;
 }
@@ -265,7 +216,7 @@ sub calculate {
 # Checking filters
 #
         my @loopfilter;
-        for (my $i=0;$i<=9;$i++) {
+        for (my $i=0;$i<=10;$i++) {
                 my %cell;
                 if ( @$filters[$i] ) {
                         if (($i==1) and (@$filters[$i-1])) {
@@ -279,15 +230,16 @@ sub calculate {
                         }
                         $cell{crit} .="Period From" if ($i==0);
                         $cell{crit} .="Period To" if ($i==1);
-                        $cell{crit} .="Borrower Cat=" if ($i==2);
-                        $cell{crit} .="Doc Type=" if ($i==3);
-                        $cell{crit} .="Branch=" if ($i==4);
-                        $cell{crit} .="Location=" if ($i==5);
-                        $cell{crit} .="Item callnumber>=" if ($i==6);
-                        $cell{crit} .="Item callnumber<" if ($i==7);
-                        $cell{crit} .="sort1=" if ($i==8);
-                        $cell{crit} .="sort2=" if ($i==9);
-
+                        $cell{crit} .="Patron Category=" if ($i==2);
+                        $cell{crit} .="Item Type=" if ($i==3);
+                        $cell{crit} .="Library=" if ($i==4);
+                        $cell{crit} .="Collection=" if ($i==5);
+                        $cell{crit} .="Location=" if ($i==6);
+                        $cell{crit} .="Item callnumber>=" if ($i==7);
+                        $cell{crit} .="Item callnumber<" if ($i==8);
+                        $cell{crit} .="sort1=" if ($i==9);
+                        $cell{crit} .="sort2=" if ($i==10);
+                                               # FIXME - no translation mechanism !
                         push @loopfilter, \%cell;
                 }
         }
@@ -298,19 +250,27 @@ sub calculate {
         
         
         my @linefilter;
-#      warn "filtres ".@filters[0];
-#      warn "filtres ".@filters[1];
-#      warn "filtres ".@filters[2];
-#      warn "filtres ".@filters[3];
-        
+      $debug and warn "filtres ". join "|", @filters;
+        my ($colsource, $linesource);
         $linefilter[0] = @$filters[0] if ($line =~ /datetime/ )  ;
         $linefilter[1] = @$filters[1] if ($line =~ /datetime/ )  ;
-        $linefilter[0] = @$filters[2] if ($line =~ /category/ )  ;
-        $linefilter[0] = @$filters[3] if ($line =~ /itemtype/ )  ;
+               if ($line =~ /category/ )  {
+               $linefilter[0] = @$filters[2] ;
+               }
+               if ($line =~ /itemtype/ ) {
+               $linefilter[0] = @$filters[3] ;
+               }
         $linefilter[0] = @$filters[4] if ($line =~ /branch/ )  ;
-        $linefilter[0] = @$filters[5] if ($line =~ /location/ ) ;
-        $linefilter[0] = @$filters[6] if ($line =~ /sort1/ ) ;
-        $linefilter[0] = @$filters[7] if ($line =~ /sort2/ ) ;
+               if ($line =~ /ccode/ ) {
+               $linefilter[0] = @$filters[5] ;
+                       $linesource = 'items';
+               }
+               if ($line =~ /location/ ) {
+               $linefilter[0] = @$filters[6] ;
+                       $linesource = 'items';
+               }
+        $linefilter[0] = @$filters[9] if ($line =~ /sort1/ ) ;
+        $linefilter[0] = @$filters[10] if ($line =~ /sort2/ ) ;
 
         my @colfilter ;
         $colfilter[0] = @$filters[0] if ($column =~ /datetime/) ;
@@ -318,9 +278,16 @@ sub calculate {
         $colfilter[0] = @$filters[2] if ($column =~ /category/) ;
         $colfilter[0] = @$filters[3] if ($column =~ /itemtype/) ;
         $colfilter[0] = @$filters[4] if ($column =~ /branch/ )  ;
-        $colfilter[0] = @$filters[5] if ($column =~ /location/  )  ;
-        $colfilter[0] = @$filters[6] if ($column =~ /sort1/  )  ;
-        $colfilter[0] = @$filters[7] if ($column =~ /sort2/  )  ;
+               if ($column =~ /ccode/ ) {
+               $colfilter[0] = @$filters[5] ;
+                       $colsource = 'items';
+               }
+               if ($column =~ /location/ ) {
+               $colfilter[0] = @$filters[6] ;
+                       $colsource = 'items';
+               }
+        $colfilter[0] = @$filters[9] if ($column =~ /sort1/  )  ;
+        $colfilter[0] = @$filters[10] if ($column =~ /sort2/  )  ;
 # 1st, loop rows.                             
         my $linefield;                               
         if (($line =~/datetime/) and ($dsp == 1)) {
@@ -328,7 +295,7 @@ sub calculate {
                 $linefield .="dayname($line)";  
         } elsif (($line=~/datetime/) and ($dsp == 2)) {
                 #Display by Month
-                $linefield .="monthname($line)";  
+                $linefield .="monthname($line) ";  
         } elsif (($line=~/datetime/) and ($dsp == 3)) {
                 #Display by Year
                 $linefield .="Year($line)";
@@ -343,7 +310,12 @@ sub calculate {
         $lineorder = $linefield if (not ($linefield =~ "^month") and not($linefield =~ /dayname/));
 
         my $strsth;
-        $strsth .= "select distinctrow $linefield from statistics, borrowers where (statistics.borrowernumber=borrowers.borrowernumber) and $line is not null ";
+        $strsth .= "select distinctrow $linefield from statistics, ";
+               # get stats on items if ccode or location, otherwise borrowers.
+               $strsth .= ($linesource eq 'items' ) ? 
+                                               "items where (statistics.itemnumber=items.itemnumber) " 
+                                               : " borrowers where (statistics.borrowernumber=borrowers.borrowernumber) ";
+               $strsth .= " and $line is not null ";
         
         if ($line=~/datetime/) {
                 if ($linefilter[1] and ($linefilter[0])){
@@ -362,11 +334,10 @@ sub calculate {
         }
         $strsth .=" group by $linefield";
         $strsth .=" order by $lineorder";
-#         warn "". $strsth;
-        
+        $debug and warn $strsth;
         my $sth = $dbh->prepare( $strsth );
         if (( @linefilter ) and ($linefilter[1])){
-                $sth->execute("'".$linefilter[0]."'","'".$linefilter[1]."'");
+                $sth->execute($linefilter[0],$linefilter[1]);
         } elsif ($linefilter[0]) {
                 $sth->execute($linefilter[0]);
         } else {
@@ -375,6 +346,30 @@ sub calculate {
         
         while ( my ($celvalue) = $sth->fetchrow) {
                 my %cell;
+                               if($line =~ /ccode/) {
+                                       $cell{rowtitle_display} = $ccodes->{$celvalue};
+                               } elsif($line=~/location/) {
+                                        $cell{rowtitle_display} = $locations->{$celvalue};
+                               } elsif($line=~/sort1/) {
+                                       for my $s (@$Bsort1) {
+                                               $cell{rowtitle_display} = $s->{lib} if ($celvalue eq $s->{authorised_value});
+                                       }
+                                       $cell{rowtitle_display} = $celvalue unless  $cell{rowtitle_display};
+                               } elsif($line=~/sort2/) {
+                                       for my $s (@$Bsort2) {
+                                               $cell{rowtitle_display} = $s->{lib} if ($celvalue eq $s->{authorised_value});
+                                       }
+                                       $cell{rowtitle_display} = $celvalue unless  $cell{rowtitle_display};
+                               } elsif($line=~/categorycode/) {
+                                       for my $s (@$categoryloop) { 
+                                               $cell{rowtitle_display} = $s->{description} if ($celvalue eq $s->{categorycode});
+                                       }
+                                       $cell{rowtitle_display} = $celvalue unless  $cell{rowtitle_display};
+                               } elsif($line=~/itemtype/) {
+                                       $cell{rowtitle_display} = $itemtypes->{$celvalue}->{description};
+                               } else {
+                               $cell{rowtitle_display} = $celvalue;
+                               }                                       
                 if ($celvalue) {
                         $cell{rowtitle} = $celvalue;
                 } else {
@@ -405,8 +400,13 @@ sub calculate {
         $colorder = "month($line)" if $colfield =~ "^month";
         $colorder = $colfield if (not ($colfield =~ "^month") and not($colfield =~ "^dayname"));
         
-        my $strsth2;
-        $strsth2 .= "select distinctrow $colfield from statistics, borrowers where (statistics.borrowernumber=borrowers.borrowernumber) and $column is not null ";
+        my $strsth2; 
+        $strsth2 .= "select distinctrow $colfield from statistics, ";
+               # get stats on items if ccode or location, otherwise borrowers.
+               $strsth2 .= ($colsource eq 'items' ) ? 
+                                               "items where (statistics.itemnumber=items.itemnumber) " 
+                                               : " borrowers where (statistics.borrowernumber=borrowers.borrowernumber) ";
+               $strsth2 .= " and $column is not null ";
         
         if ($column=~/datetime/){
                 if (($colfilter[1]) and ($colfilter[0])){
@@ -425,7 +425,6 @@ sub calculate {
         }
         $strsth2 .=" group by $colfield";
         $strsth2 .=" order by $colorder";
-#      warn "". $strsth2;
         
         my $sth2 = $dbh->prepare( $strsth2 );
         if (( @colfilter ) and ($colfilter[1])){
@@ -440,24 +439,45 @@ sub calculate {
         while (my ($celvalue) = $sth2->fetchrow) {
                 my %cell;
                 my %ft;
-#              warn "coltitle :".$celvalue;
-                $cell{coltitle} = $celvalue;
+                               if($column =~ /ccode/) {
+                                       $cell{coltitle_display} = $ccodes->{$celvalue};
+                               } elsif($column=~/location/) {
+                                        $cell{coltitle_display} = $locations->{$celvalue};
+                               } elsif($column=~/itemtype/) {
+                                       $cell{coltitle_display} = $itemtypes->{$celvalue}->{description};
+                               } elsif($column=~/sort1/) {
+                                       for my $s (@$Bsort1) {
+                                               $cell{coltitle_display} = $s->{lib} if ($celvalue eq $s->{authorised_value});
+                                       }
+                                       $cell{coltitle_display} = $celvalue unless  $cell{coltitle_display};
+                               } elsif($column=~/sort2/) {
+                                       for my $s (@$Bsort2) {
+                                               $cell{coltitle_display} = $s->{lib} if ($celvalue eq $s->{authorised_value});
+                                       }
+                                       $cell{coltitle_display} = $celvalue unless  $cell{coltitle_display};
+                               } elsif($column=~/category/) {
+                                       for my $s (@$categoryloop) {
+                                               $cell{coltitle_display} = $s->{description} if ($celvalue eq $s->{categorycode});
+                                       }
+                                       $cell{coltitle_display} = $celvalue unless  $cell{coltitle_display};
+                               } else {
+                               $cell{coltitle_display} = $celvalue;
+                               }                                       
+                       $cell{coltitle} = $celvalue;
+                               # we leave this as 'coltitle' since we use it as hash key when filling the table, and add a title_display key.
                 $ft{totalcol} = 0;
                 push @loopcol, \%cell;
         }
-#      warn "fin des titres colonnes";
 
         my $i=0;
         my @totalcol;
-        my $hilighted=-1;
         
         #Initialization of cell values.....
         my %table;
-#      warn "init table";
         foreach my $row ( @loopline ) {
                 foreach my $col ( @loopcol ) {
-#                      warn " init table : $row->{rowtitle} / $col->{coltitle} ";
-                        $table{$row->{rowtitle}}->{$col->{coltitle}}=0;
+                               $debug and warn " init table : $row->{rowtitle} ( $row->{rowtitle_display} ) / $col->{coltitle} ( $col->{coltitle_display} )  ";
+                                               $table{$row->{rowtitle}}->{$col->{coltitle}}=0;
                 }
                 $table{$row->{rowtitle}}->{totalrow}=0;
         }
@@ -481,7 +501,7 @@ sub calculate {
         }
         $strcalc .= "FROM statistics ";
         $strcalc .= "LEFT JOIN borrowers ON statistics.borrowernumber=borrowers.borrowernumber ";
-        $strcalc .= "LEFT JOIN items ON statistics.itemnumber=items.itemnumber " if @$filters[5] or @$filters[6];
+        $strcalc .= "LEFT JOIN items ON statistics.itemnumber=items.itemnumber " if ( ($colsource eq 'items') || @$filters[5] || @$filters[6] ||@$filters[7] || @$filters[8] );
         
         $strcalc .= "WHERE 1=1 ";
         @$filters[0]=~ s/\*/%/g if (@$filters[0]);
@@ -495,36 +515,42 @@ sub calculate {
         @$filters[4]=~ s/\*/%/g if (@$filters[4]);
         $strcalc .= " AND statistics.branch like '" . @$filters[4] ."'" if ( @$filters[4] );
         @$filters[5]=~ s/\*/%/g if (@$filters[5]);
-        $strcalc .= " AND items.location like '" . @$filters[5] ."'" if ( @$filters[5] );
+        $strcalc .= " AND items.ccode like '" . @$filters[5] ."'" if ( @$filters[5] );
         @$filters[6]=~ s/\*/%/g if (@$filters[6]);
-        $strcalc .= " AND items.itemcallnumber >='" . @$filters[6] ."'" if ( @$filters[6] );
+        $strcalc .= " AND items.location like '" . @$filters[6] ."'" if ( @$filters[6] );
         @$filters[7]=~ s/\*/%/g if (@$filters[7]);
-        $strcalc .= " AND items.itemcallnumber <'" . @$filters[7] ."'" if ( @$filters[7] );
+        $strcalc .= " AND items.itemcallnumber >='" . @$filters[7] ."'" if ( @$filters[7] );
         @$filters[8]=~ s/\*/%/g if (@$filters[8]);
-        $strcalc .= " AND borrowers.sort1 like '" . @$filters[8] ."'" if ( @$filters[8] );
+        $strcalc .= " AND items.itemcallnumber <'" . @$filters[8] ."'" if ( @$filters[8] );
         @$filters[9]=~ s/\*/%/g if (@$filters[9]);
-        $strcalc .= " AND borrowers.sort2 like '" . @$filters[9] ."'" if ( @$filters[9] );
+        $strcalc .= " AND borrowers.sort1 like '" . @$filters[9] ."'" if ( @$filters[9] );
+        @$filters[10]=~ s/\*/%/g if (@$filters[10]);
+        $strcalc .= " AND borrowers.sort2 like '" . @$filters[10] ."'" if ( @$filters[10] );
         $strcalc .= " AND dayname(datetime) like '" . $daysel ."'" if ( $daysel );
         $strcalc .= " AND monthname(datetime) like '" . $monthsel ."'" if ( $monthsel );
         $strcalc .= " AND statistics.type like '" . $type ."'" if ( $type );
         
         $strcalc .= " group by $linefield, $colfield order by $lineorder,$colorder";
-        warn "". $strcalc;
+        ($debug) and warn "". $strcalc;
         my $dbcalc = $dbh->prepare($strcalc);
         $dbcalc->execute;
-#      warn "filling table";
-        my $emptycol; 
+        my ($emptycol,$emptyrow); 
         while (my ($row, $col, $value) = $dbcalc->fetchrow) {
-#                 warn "filling table $row / $col / $value ";
-                $emptycol = 1 if ($col eq undef);
-                $col = "zzEMPTY" if ($col eq undef);
-                $row = "zzEMPTY" if ($row eq undef);
-                
+                ($debug) and warn "filling table $row / $col / $value ";
+                               if ($col eq undef) {
+                       $emptycol = 1; 
+                       $col = "zzEMPTY" ;
+                               }
+                               if ($row eq undef) {
+                                       $emptyrow = 1;
+                       $row = "zzEMPTY"; 
+                }
                 $table{$row}->{$col}+=$value;
                 $table{$row}->{totalrow}+=$value;
                 $grantotal += $value;
         }
-        push @loopcol,{coltitle => "NULL"} if ($emptycol);
+        push @loopcol,{coltitle => "NULL", coltitle_display => 'NULL'} if ($emptycol);
+        push @loopline,{rowtitle => "NULL", rowtitle_display => 'NULL'} if ($emptyrow);
 
         foreach my $row (@loopline) {
                 my @loopcell;
@@ -534,22 +560,18 @@ sub calculate {
                         my $value =$table{($row->{rowtitle} eq "NULL")?"zzEMPTY":$row->{rowtitle}}->{($col->{coltitle} eq "NULL")?"zzEMPTY":$col->{coltitle}};
                         push @loopcell, {value => $value  } ;
                 }
-                push @looprow,{ 'rowtitle' => ($row->{rowtitle} eq "NULL")?"zzEMPTY":$row->{rowtitle},
+                push @looprow, { 'rowtitle' => ($row->{rowtitle} eq "NULL")?"zzEMPTY":$row->{rowtitle},
+                                                               'rowtitle_display' => ($row->{rowtitle_display} eq "NULL")?"NULL":$row->{rowtitle_display},
                                 'loopcell' => \@loopcell,
-                                'hilighted' => ($hilighted >0),
                                 'totalrow' => $table{($row->{rowtitle} eq "NULL")?"zzEMPTY":$row->{rowtitle}}->{totalrow}
                                                 };
-                $hilighted = -$hilighted;
         }
-        
-#      warn "footer processing";
-        foreach my $col ( @loopcol ) {
+        for my $col ( @loopcol ) {
                 my $total=0;
                 foreach my $row ( @looprow ) {
                         $total += $table{($row->{rowtitle} eq "NULL")?"zzEMPTY":$row->{rowtitle}}->{($col->{coltitle} eq "NULL")?"zzEMPTY":$col->{coltitle}};
-#                      warn "value added ".$table{$row->{rowtitle}}->{$col->{coltitle}}. "for line ".$row->{rowtitle};
+                       $debug and warn "value added ".$table{$row->{rowtitle}}->{$col->{coltitle}}. "for line ".$row->{rowtitle};
                 }
-#              warn "summ for column ".$col->{coltitle}."  = ".$total;
                 push @loopfooter, {'totalcol' => $total};
         }