Hi Valterci,
First I want to say that you're problem made me discover a small bug when displaying data with both parameters "headergrp" and "serial". It will be fixed in TBS 3.2.0.
The bug is that when a group have exactly the correct number of cells for a serial row, then an extra empty is displayed just after.
I think I understand your problem. With your template, the column Total should always display the same value. This is because [var.fields] are not merged at the same time as the block. They are merged at the end, when you call $TBS->Show().
I can suggest a solution which should work but is not smart:
In function f_total(), save the different totals in a global array.
function f_total($Name,&$CurrRec,$RecNum) {
global $save_data, $tot_1, $tot_all;
if (!isset($save_data)) {
$save_data = '';
$tot_all = array();
}
if ($save_data!=$CurrRec['data']) {
if (isset($tot_1)) $tot_all[] = $tot_1;
$tot_1 = 0;
$save_data= $CurrRec['data'];
}
// Calculate totals
$tot_1 += $CurrRec['valor'];
// Save into the current record
$CurrRec['tot_1'] = $tot_1;
}
|
Then, instead of displaying [var.tot_1] in your template, you can display all items of $tot_all in sequence. This can be done only using another function I think:
[var.tot_all;onformat=f_seq;frm='000.000,00';block=td]
function f_seq($FieldName,&$CurrVal) {
global $tot_id, $tot_all;
if (!isset($tot_id)) $tot_id = 0;
$CurrVal = $tot_all[$tot_id];
$tot_id++;
}
|
This method should be arrange if it happens that you have several lines in a same group.