|
Hello,
I am working on an invoice related report, where I have the following table (simplified for example)
PriceId Amount ChargeCode LumpChargeCode
1 100 AAA null
2 50 SF AAA
3 20 BAF AAA
4 200 BBB null
The requirement is to add the amounts of those records that have LumpChargeCode value to those records that have the corresponding ChargeCode.
Example above: add records with PriceId 2 and 3 to record A's amount.
So in the report I'd need something like this:
1 170 AAA null
4 200 BBB null
Total: 370
So far I've tried to use Arrays which I populate with values of ChargeCode, LumpChargeCode and Amounts.
Afterwards, I have 2 nested for loops to iterate through the LumpChargeCodes and ChargeCodes and add the values where the two codes match.
This is for populating the arrays:
WhileReadingRecords;
NumberVar LumpedAmountSum;
Local StringVar Key := "" & {Price.LumpChargeCode};
Local StringVar ChC := "" & {Price.ChargeCode};
Local NumberVar Amt := {Price.InvAmount};
Local NumberVar LumpedAmt := {Price.InvAmount};
StringVar array Keys;
StringVar array ChCs;
NumberVar Array Amts;
NumberVar Array LumpedAmts;
redim preserve Keys [count(Keys)+1];
Keys[count(Keys)]:= Key;
redim preserve Amts[count(Keys)+1];
Amts[count(Keys)]:= Amt;
redim preserve LumpedAmts[count(LumpedAmts)+1];
LumpedAmts[count(LumpedAmts)]:= LumpedAmt;
redim preserve ChCs[count(ChCs)+1];
ChCs[count(ChCs)]:= ChC;
And this for adding the amounts:
evaluateafter({@ArrayDef});
//WhilePrintingRecords;
StringVar array Keys;
StringVar array ChCs;
NumberVar Array Amts;
NumberVar Array LumpedAmts;
StringVar Array TempArray;
NumberVar Array PriceItemCounters;
numbervar i := 1;
numbervar j;
for i:= i to count(Keys) do // 1x
(
for j:= i to count(ChCs) do
(
if Keys<>'' and Keys = ChCs[j] and not ({Price.PriceItemCounter} in PriceItemCounters)
then
(
LumpedAmts[j] := LumpedAmts[j] + Amts;
redim preserve TempArray[count(TempArray)+1];
redim preserve PriceItemCounters[count(PriceItemCounters)+1];
PriceItemCounters[count(PriceItemCounters)]:= {Price.PriceItemCounter};
)
);
);
This solution does not work correctly though, as it seems that some records are added multiple times (I guess something to do with evaluation times, whilereadingrecords and whileprintingrecords)...
The fields are displayed in the detail section of the report.
Any advice would be appreciated.
Edited by akrobet - 03 Dec 2012 at 1:36am
|
|
Wow, you have invested tons into this already. I would hate and try and dumb it down.
i would create 1 formula - group by this
if isnull(LumpChargeCode) then
ChargeCode
else
LumpChargeCode
----
i would create 1 running total
----- summarize amount
- type of summary - sum
---evaluate
for each record
---- Reset
on change of group
now in group footer
[GroupName] [Running Total]
----------
For Report Footer create another running total, or just do Insert a summary (if RT then reset = never)
Edited by comatt1 - 03 Dec 2012 at 3:55am
|