Lines 465-473
sub calculate {
Link Here
|
465 |
foreach my $row (@loopline) { |
465 |
foreach my $row (@loopline) { |
466 |
foreach my $col (@loopcol) { |
466 |
foreach my $col (@loopcol) { |
467 |
$debug and warn " init table : $row->{rowtitle} ( $row->{rowtitle_display} ) / $col->{coltitle} ( $col->{coltitle_display} ) "; |
467 |
$debug and warn " init table : $row->{rowtitle} ( $row->{rowtitle_display} ) / $col->{coltitle} ( $col->{coltitle_display} ) "; |
468 |
$table{ $row->{rowtitle} }->{ $col->{coltitle} } = 0; |
468 |
table_set(\%table, $row->{rowtitle}, $col->{coltitle}, 0); |
469 |
} |
469 |
} |
470 |
$table{ $row->{rowtitle} }->{totalrow} = 0; |
470 |
table_set(\%table, $row->{rowtitle}, 'totalrow', 0); |
471 |
} |
471 |
} |
472 |
|
472 |
|
473 |
# preparing calculation |
473 |
# preparing calculation |
Lines 571-584
sub calculate {
Link Here
|
571 |
($debug) and warn "filling table $row / $col / $value "; |
571 |
($debug) and warn "filling table $row / $col / $value "; |
572 |
unless ( defined $col ) { |
572 |
unless ( defined $col ) { |
573 |
$emptycol = 1; |
573 |
$emptycol = 1; |
574 |
$col = "zzEMPTY"; |
|
|
575 |
} |
574 |
} |
576 |
unless ( defined $row ) { |
575 |
unless ( defined $row ) { |
577 |
$emptyrow = 1; |
576 |
$emptyrow = 1; |
578 |
$row = "zzEMPTY"; |
|
|
579 |
} |
577 |
} |
580 |
$table{$row}->{$col} += $value; |
578 |
table_inc(\%table, $row, $col, $value); |
581 |
$table{$row}->{totalrow} += $value; |
579 |
table_inc(\%table, $row, 'totalrow', $value); |
582 |
$grantotal += $value; |
580 |
$grantotal += $value; |
583 |
} |
581 |
} |
584 |
push @loopcol, { coltitle => "NULL", coltitle_display => 'NULL' } if ($emptycol); |
582 |
push @loopcol, { coltitle => "NULL", coltitle_display => 'NULL' } if ($emptycol); |
Lines 590-596
sub calculate {
Link Here
|
590 |
#@loopcol ensures the order for columns is common with column titles |
588 |
#@loopcol ensures the order for columns is common with column titles |
591 |
# and the number matches the number of columns |
589 |
# and the number matches the number of columns |
592 |
foreach my $col (@loopcol) { |
590 |
foreach my $col (@loopcol) { |
593 |
my $value = $table{ null_to_zzempty( $row->{rowtitle} ) }->{ null_to_zzempty( $col->{coltitle} ) }; |
591 |
my $value = table_get(\%table, $row->{rowtitle}, $col->{coltitle}); |
594 |
push @loopcell, { value => $value }; |
592 |
push @loopcell, { value => $value }; |
595 |
} |
593 |
} |
596 |
my $rowtitle = ( $row->{rowtitle} eq "NULL" ) ? "zzEMPTY" : $row->{rowtitle}; |
594 |
my $rowtitle = ( $row->{rowtitle} eq "NULL" ) ? "zzEMPTY" : $row->{rowtitle}; |
Lines 598-611
sub calculate {
Link Here
|
598 |
{ 'rowtitle_display' => $row->{rowtitle_display}, |
596 |
{ 'rowtitle_display' => $row->{rowtitle_display}, |
599 |
'rowtitle' => $rowtitle, |
597 |
'rowtitle' => $rowtitle, |
600 |
'loopcell' => \@loopcell, |
598 |
'loopcell' => \@loopcell, |
601 |
'totalrow' => $table{$rowtitle}->{totalrow} |
599 |
'totalrow' => table_get(\%table, $rowtitle, 'totalrow'), |
602 |
}; |
600 |
}; |
603 |
} |
601 |
} |
604 |
for my $col (@loopcol) { |
602 |
for my $col (@loopcol) { |
605 |
my $total = 0; |
603 |
my $total = 0; |
606 |
foreach my $row (@looprow) { |
604 |
foreach my $row (@looprow) { |
607 |
$total += $table{ null_to_zzempty( $row->{rowtitle} ) }->{ null_to_zzempty( $col->{coltitle} ) }; |
605 |
$total += table_get(\%table, $row->{rowtitle}, $col->{coltitle}); |
608 |
$debug and warn "value added " . $table{ $row->{rowtitle} }->{ $col->{coltitle} } . "for line " . $row->{rowtitle}; |
606 |
$debug and warn "value added " . table_get(\%table, $row->{rowtitle}, $col->{coltitle}) . "for line " . $row->{rowtitle}; |
609 |
} |
607 |
} |
610 |
push @loopfooter, { 'totalcol' => $total }; |
608 |
push @loopfooter, { 'totalcol' => $total }; |
611 |
} |
609 |
} |
Lines 632-635
sub null_to_zzempty ($) {
Link Here
|
632 |
return $string; # else return the valid value |
630 |
return $string; # else return the valid value |
633 |
} |
631 |
} |
634 |
|
632 |
|
|
|
633 |
sub table_set { |
634 |
my ($table, $row, $col, $val) = @_; |
635 |
|
636 |
$table->{ null_to_zzempty(lc($row)) }->{ null_to_zzempty(lc($col)) } = $val; |
637 |
} |
638 |
|
639 |
sub table_get { |
640 |
my ($table, $row, $col) = @_; |
641 |
|
642 |
return $table->{ null_to_zzempty(lc($row)) }->{ null_to_zzempty(lc($col)) }; |
643 |
} |
644 |
|
645 |
sub table_inc { |
646 |
my ($table, $row, $col, $inc) = @_; |
647 |
|
648 |
$table->{ null_to_zzempty(lc($row)) }->{ null_to_zzempty(lc($col)) } += $inc; |
649 |
} |
650 |
|
635 |
1; |
651 |
1; |
636 |
- |
|
|