Hi,
I'm building a report of some votations, and I use an XLSX template. I have an outer block iterating over "votations", and an inner block iterating over "votes" (that are, the possible votes castable in a single votations).
Let us say that we have 2 votations, and in each one voters can choose among a bunch of possible votes, or can choose not to vote.
So I repeat the votations block for each votations, and inside each votation I present the number of votes cast bu the voters on the single votations. So far, it works..
this is the pseudo code
[votations;block=begin]
[votations.title]
[votes;block=begin;p1= [votations.id];aggregate=num_not_null:sum,num_null:sum,num:sum]
[votes.title;if [val]='';then 'Non votanti';else [val]] $ [votes.num_not_null;if [val]=0; then [votes.num_null]; else [val]] [votes;block=end]
Totale votanti $[votes.num_not_null:sum]
Totale non votanti $[votes.num_null:sum]
Totale generale $[votes.num:sum]
[votations;block=end]

Please imagine this in some Excel cells.. rows correspond to actual rows. The "$" sign, I've put it to clarify cell boundaries but it's not present in the template
For each possibile vote, my SQL query returns three numbers: num_null, num_not_null, and num.
At the end of the block I'd like to display the sum of all three counters for all the votes cast for a given votation.
This sort of works, that is, this is my outcome:
Votazione di Lista x CDA
Voto $ Voti Raccolti
Lista 3 $ 76
Lista 2 $ 250
Lista 1 $ 1826
Non votanti $ 434
Totale votanti $ 961
Totale non votanti $ 1625
Totale generale $ 2586
Votazione di lista x Collegio Sindaci
Voto $ Voti Raccolti
lista "Dei Buoni" $ 74
lista "I Belli" $ 887
Non votanti $ 1625
Totale votanti $ 961
Totale non votanti$$ 1625
Totale generale $ 2586

As you can see, the second totals (961,1625,2586) is correct with the above numbers, while the first is the same as the second, and is wrong.
I've debugged the Aggregate Plugin (easy) and in the AfterMerge function, the sums are stored correctly. This method is called twice (I've got 2 votations in my DB) and each time it stores the correct sums..
I suspect that OpenTBS itself will just ask for the sums at the end of the whole outer loop, and thus will get just the latest Aggregate calculations.
But, as per Aggregate manual, the sums MUST be placed outside of the relevant block, so I don't know what to do. I'll look at the TBS code but it's a bit convoluted for me.
Any suggestions, maybe I'm doing something wrong? I hope so..
Thanks
W