Lines 310-332
sub calculate {
Link Here
|
310 |
if($line_attribute_type) { |
310 |
if($line_attribute_type) { |
311 |
$strsth = "SELECT attribute FROM borrower_attributes WHERE code = '$line_attribute_type' "; |
311 |
$strsth = "SELECT attribute FROM borrower_attributes WHERE code = '$line_attribute_type' "; |
312 |
} else { |
312 |
} else { |
313 |
$strsth = "SELECT distinctrow $linefield FROM statistics, "; |
313 |
$strsth = "SELECT distinctrow $linefield FROM statistics "; |
314 |
|
314 |
|
315 |
# get stats on items if ccode or location, otherwise borrowers. |
315 |
# get stats on items if ccode or location, otherwise borrowers. |
316 |
$strsth .= |
316 |
$strsth .= |
317 |
( $linesource eq 'items' ) |
317 |
( $linesource eq 'items' ) |
318 |
? " items WHERE (statistics.itemnumber=items.itemnumber) " |
318 |
? " LEFT JOIN items ON (statistics.itemnumber = items.itemnumber) " |
319 |
: " borrowers WHERE (statistics.borrowernumber=borrowers.borrowernumber) "; |
319 |
: " LEFT JOIN borrowers ON (statistics.borrowernumber = borrowers.borrowernumber) "; |
320 |
} |
320 |
} |
321 |
$strsth .= " AND $line is not null "; |
321 |
$strsth .= " WHERE $line is not null "; |
322 |
|
322 |
|
323 |
if ( $line =~ /datetime/ ) { |
323 |
if ( $line =~ /datetime/ ) { |
324 |
if ( $linefilter[1] and ( $linefilter[0] ) ) { |
324 |
if ( $linefilter[1] and ( $linefilter[0] ) ) { |
325 |
$strsth .= " AND $line between ? AND ? "; |
325 |
$strsth .= " AND $line between ? AND ? "; |
326 |
} elsif ( $linefilter[1] ) { |
326 |
} elsif ( $linefilter[1] ) { |
327 |
$strsth .= " AND $line < ? "; |
327 |
$strsth .= " AND $line <= ? "; |
328 |
} elsif ( $linefilter[0] ) { |
328 |
} elsif ( $linefilter[0] ) { |
329 |
$strsth .= " AND $line > ? "; |
329 |
$strsth .= " AND $line >= ? "; |
330 |
} |
330 |
} |
331 |
$strsth .= " AND type ='" . $type . "' " if $type; |
331 |
$strsth .= " AND type ='" . $type . "' " if $type; |
332 |
$strsth .= " AND dayname(datetime) ='" . $daysel . "' " if $daysel; |
332 |
$strsth .= " AND dayname(datetime) ='" . $daysel . "' " if $daysel; |
Lines 339-346
sub calculate {
Link Here
|
339 |
$debug and warn $strsth; |
339 |
$debug and warn $strsth; |
340 |
push @loopfilter, { crit => 'SQL =', sql => 1, filter => $strsth }; |
340 |
push @loopfilter, { crit => 'SQL =', sql => 1, filter => $strsth }; |
341 |
my $sth = $dbh->prepare($strsth); |
341 |
my $sth = $dbh->prepare($strsth); |
342 |
if ( (@linefilter) and ( $linefilter[1] ) ) { |
342 |
if ( (@linefilter) and ($linefilter[0]) and ($linefilter[1]) ) { |
343 |
$sth->execute( $linefilter[0], $linefilter[1] ); |
343 |
$sth->execute( $linefilter[0], $linefilter[1] . " 23:59:59" ); |
|
|
344 |
} elsif ( $linefilter[1] ) { |
345 |
$sth->execute( $linefilter[1] . " 23:59:59" ); |
344 |
} elsif ( $linefilter[0] ) { |
346 |
} elsif ( $linefilter[0] ) { |
345 |
$sth->execute( $linefilter[0] ); |
347 |
$sth->execute( $linefilter[0] ); |
346 |
} else { |
348 |
} else { |
Lines 396-418
sub calculate {
Link Here
|
396 |
if($column_attribute_type) { |
398 |
if($column_attribute_type) { |
397 |
$strsth2 = "SELECT attribute FROM borrower_attributes WHERE code = '$column_attribute_type' "; |
399 |
$strsth2 = "SELECT attribute FROM borrower_attributes WHERE code = '$column_attribute_type' "; |
398 |
} else { |
400 |
} else { |
399 |
$strsth2 = "SELECT distinctrow $colfield FROM statistics, "; |
401 |
$strsth2 = "SELECT distinctrow $colfield FROM statistics "; |
400 |
|
402 |
|
401 |
# get stats on items if ccode or location, otherwise borrowers. |
403 |
# get stats on items if ccode or location, otherwise borrowers. |
402 |
$strsth2 .= |
404 |
$strsth2 .= |
403 |
( $colsource eq 'items' ) |
405 |
( $colsource eq 'items' ) |
404 |
? "items WHERE (statistics.itemnumber=items.itemnumber) " |
406 |
? "LEFT JOIN items ON (statistics.itemnumber = items.itemnumber) " |
405 |
: "borrowers WHERE (statistics.borrowernumber=borrowers.borrowernumber) "; |
407 |
: "LEFT JOIN borrowers ON (statistics.borrowernumber = borrowers.borrowernumber) "; |
406 |
} |
408 |
} |
407 |
$strsth2 .= " AND $column IS NOT NULL "; |
409 |
$strsth2 .= " WHERE $column IS NOT NULL "; |
408 |
|
410 |
|
409 |
if ( $column =~ /datetime/ ) { |
411 |
if ( $column =~ /datetime/ ) { |
410 |
if ( ( $colfilter[1] ) and ( $colfilter[0] ) ) { |
412 |
if ( ( $colfilter[1] ) and ( $colfilter[0] ) ) { |
411 |
$strsth2 .= " AND $column BETWEEN ? AND ? "; |
413 |
$strsth2 .= " AND $column BETWEEN ? AND ? "; |
412 |
} elsif ( $colfilter[1] ) { |
414 |
} elsif ( $colfilter[1] ) { |
413 |
$strsth2 .= " AND $column < ? "; |
415 |
$strsth2 .= " AND $column <= ? "; |
414 |
} elsif ( $colfilter[0] ) { |
416 |
} elsif ( $colfilter[0] ) { |
415 |
$strsth2 .= " AND $column > ? "; |
417 |
$strsth2 .= " AND $column >= ? "; |
416 |
} |
418 |
} |
417 |
$strsth2 .= " AND type ='". $type ."' " if $type; |
419 |
$strsth2 .= " AND type ='". $type ."' " if $type; |
418 |
$strsth2 .= " AND dayname(datetime) ='". $daysel ."' " if $daysel; |
420 |
$strsth2 .= " AND dayname(datetime) ='". $daysel ."' " if $daysel; |
Lines 426-433
sub calculate {
Link Here
|
426 |
$debug and warn $strsth2; |
428 |
$debug and warn $strsth2; |
427 |
push @loopfilter, { crit => 'SQL =', sql => 1, filter => $strsth2 }; |
429 |
push @loopfilter, { crit => 'SQL =', sql => 1, filter => $strsth2 }; |
428 |
my $sth2 = $dbh->prepare($strsth2); |
430 |
my $sth2 = $dbh->prepare($strsth2); |
429 |
if ( (@colfilter) and ( $colfilter[1] ) ) { |
431 |
if ( (@colfilter) and ($colfilter[0]) and ($colfilter[1]) ) { |
430 |
$sth2->execute( $colfilter[0], $colfilter[1] ); |
432 |
$sth2->execute( $colfilter[0], $colfilter[1] . " 23:59:59" ); |
|
|
433 |
} elsif ( $colfilter[1] ) { |
434 |
$sth2->execute( $colfilter[1] . " 23:59:59" ); |
431 |
} elsif ( $colfilter[0] ) { |
435 |
} elsif ( $colfilter[0] ) { |
432 |
$sth2->execute( $colfilter[0] ); |
436 |
$sth2->execute( $colfilter[0] ); |
433 |
} else { |
437 |
} else { |
Lines 591-602
sub calculate {
Link Here
|
591 |
my $value = table_get(\%table, $row->{rowtitle}, $col->{coltitle}); |
595 |
my $value = table_get(\%table, $row->{rowtitle}, $col->{coltitle}); |
592 |
push @loopcell, { value => $value }; |
596 |
push @loopcell, { value => $value }; |
593 |
} |
597 |
} |
594 |
my $rowtitle = ( $row->{rowtitle} eq "NULL" ) ? "zzEMPTY" : $row->{rowtitle}; |
|
|
595 |
push @looprow, |
598 |
push @looprow, |
596 |
{ 'rowtitle_display' => $row->{rowtitle_display}, |
599 |
{ 'rowtitle_display' => $row->{rowtitle_display}, |
597 |
'rowtitle' => $rowtitle, |
600 |
'rowtitle' => $row->{rowtitle}, |
598 |
'loopcell' => \@loopcell, |
601 |
'loopcell' => \@loopcell, |
599 |
'totalrow' => table_get(\%table, $rowtitle, 'totalrow'), |
602 |
'totalrow' => table_get(\%table, $row->{rowtitle}, 'totalrow'), |
600 |
}; |
603 |
}; |
601 |
} |
604 |
} |
602 |
for my $col (@loopcol) { |
605 |
for my $col (@loopcol) { |
Lines 623-633
sub calculate {
Link Here
|
623 |
return [ ( \%globalline ) ]; |
626 |
return [ ( \%globalline ) ]; |
624 |
} |
627 |
} |
625 |
|
628 |
|
626 |
sub null_to_zzempty ($) { |
629 |
sub null_to_zzempty { |
627 |
my $string = shift; |
630 |
my $string = shift; |
628 |
defined($string) or return 'zzEMPTY'; |
631 |
|
629 |
($string eq "NULL") and return 'zzEMPTY'; |
632 |
if (!defined($string) or $string eq '' or uc($string) eq 'NULL') { |
630 |
return $string; # else return the valid value |
633 |
return 'zzEMPTY'; |
|
|
634 |
} |
635 |
|
636 |
return $string; |
631 |
} |
637 |
} |
632 |
|
638 |
|
633 |
sub table_set { |
639 |
sub table_set { |
634 |
- |
|
|