Adding Borrowers count feature.
authorhdl <hdl>
Wed, 20 Jul 2005 09:52:31 +0000 (09:52 +0000)
committerhdl <hdl>
Wed, 20 Jul 2005 09:52:31 +0000 (09:52 +0000)
Note : This COULD be reported in 2.2 branch.

koha-tmpl/intranet-tmpl/default/en/reports/issues_stats.tmpl
reports/issues_stats.pl

index 2501751..34e1103 100644 (file)
        <div id="bloc25">
                <h3 class="reports"> Cell value </h3>
                        <p><input type="radio" name="Cellvalue" value="1" checked> Count issues </p>
+                       <p><input type="radio" name="Cellvalue" value="2" > Count borrowers </p>
                        <p><input type="radio" name="Cellvalue" value="3"> Circulation rate </p>
        </div>
        <div id="bloc25">
index 56156e4..c7229e9 100755 (executable)
@@ -307,7 +307,7 @@ sub calculate {
        my $linefield;                               
        if (($line =~/datetime/) and ($dsp == 1)) {
                #Display by day
-               $linefield .="concat(weekday($line),' ',dayname($line))";  
+               $linefield .="dayname($line)";  
        } elsif (($line=~/datetime/) and ($dsp == 2)) {
                #Display by Month
                $linefield .="monthname($line)";  
@@ -320,7 +320,9 @@ sub calculate {
                $linefield .= $line;
        }  
        my $lineorder = $linefield;
-       $lineorder = "weekday($line)" if $lineorder =~ "^dayname";
+       $lineorder = "weekday($line)" if $linefield =~ /dayname/;
+       $lineorder = "month($line)" if $linefield =~ "^month";
+       $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 ";
@@ -365,7 +367,8 @@ sub calculate {
        }
 
 # 2nd, loop cols.
-       my $colfield;                               
+       my $colfield;
+       my $colorder;                               
        if (($column =~/datetime/) and ($dsp == 1)) {
                #Display by day
                $colfield .="dayname($column)";  
@@ -380,6 +383,9 @@ sub calculate {
        } else {
                $colfield .= $column;
        }  
+       $colorder = "weekday($line)" if $colfield =~ "^dayname";
+       $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 ";
@@ -400,7 +406,7 @@ sub calculate {
                $strsth2 .= " and $column LIKE ? " ;
        }
        $strsth2 .=" group by $colfield";
-       $strsth2 .=" order by $colfield";
+       $strsth2 .=" order by $colorder";
 #      warn "". $strsth2;
        
        my $sth2 = $dbh->prepare( $strsth2 );
@@ -443,6 +449,9 @@ sub calculate {
 
        $strcalc .= "SELECT $linefield, $colfield, ";
        $strcalc .= "COUNT( * ) " if ($process ==1);
+       if ($process ==2){
+               $strcalc .= "(COUNT(DISTINCT borrowers.borrowernumber))" ;
+       }
        if ($process ==3){
                my $rqbookcount = $dbh->prepare("SELECT count(*) FROM items");
                $rqbookcount->execute;
@@ -469,14 +478,14 @@ sub calculate {
        $strcalc .= " AND monthname(datetime) like '" . $monthsel ."'" if ( $monthsel );
        $strcalc .= " AND statistics.type like '" . $type ."'" if ( $type );
        
-       $strcalc .= " group by $linefield, $colfield order by $lineorder,$colfield";
+       $strcalc .= " group by $linefield, $colfield order by $lineorder,$colorder";
        warn "". $strcalc;
        my $dbcalc = $dbh->prepare($strcalc);
        $dbcalc->execute;
 #      warn "filling table";
        my $emptycol; 
        while (my ($row, $col, $value) = $dbcalc->fetchrow) {
-#              warn "filling table $row / $col / $value ";
+               warn "filling table $row / $col / $value ";
                $emptycol = 1 if ($col eq undef);
                $col = "zzEMPTY" if ($col eq undef);
                $row = "zzEMPTY" if ($row eq undef);
@@ -487,18 +496,18 @@ sub calculate {
        }
        push @loopcol,{coltitle => "NULL"} if ($emptycol);
 
-       foreach my $row ( sort keys %table ) {
+       foreach my $row (@loopline) {
                my @loopcell;
                #@loopcol ensures the order for columns is common with column titles
                # and the number matches the number of columns
                foreach my $col ( @loopcol ) {
-                       my $value =$table{$row}->{($col->{coltitle} eq "NULL")?"zzEMPTY":$col->{coltitle}};
+                       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 eq "zzEMPTY")?"NULL":$row,
+               push @looprow,{ 'rowtitle' => ($row->{rowtitle} eq "NULL")?"zzEMPTY":$row->{rowtitle},
                                                        'loopcell' => \@loopcell,
                                                        'hilighted' => ($hilighted >0),
-                                                       'totalrow' => $table{$row}->{totalrow}
+                                                       'totalrow' => $table{($row->{rowtitle} eq "NULL")?"zzEMPTY":$row->{rowtitle}}->{totalrow}
                                                };
                $hilighted = -$hilighted;
        }