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)";
$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 ";
}
# 2nd, loop cols.
- my $colfield;
+ my $colfield;
+ my $colorder;
if (($column =~/datetime/) and ($dsp == 1)) {
#Display by day
$colfield .="dayname($column)";
} 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 ";
$strsth2 .= " and $column LIKE ? " ;
}
$strsth2 .=" group by $colfield";
- $strsth2 .=" order by $colfield";
+ $strsth2 .=" order by $colorder";
# warn "". $strsth2;
my $sth2 = $dbh->prepare( $strsth2 );
$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;
$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);
}
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;
}