This answer relates to:
Calculation with repeats
Firstly, let me define my Document Model. In all examples in this answer, I will be working with a document model with the following structure:
- Root (Group)
- Order (Group, repeatability = 10)
- UnitPrice (Field, Number, 2 decimal places)
- Amount (Field, Number, 0 decimal places)
- OrderComplete (Rule)
- TotalPrice (Field, Number, 2 decimal places)
- TotalPriceComputation (Rule)
- GrandTotalPrice (Field, Number, 2 decimal places)
- GrandTotalPriceComputation (Rule)
- AtLeastOneOrder (Rule)
- Order (Group, repeatability = 10)
As you can see, I’ve added two calculations to my Document Model, one to calculate the total price in each row of the repeat, TotalPriceComputation, and another to calculate the price of the whole order, GrandTotalPriceComputation.
It is not clear to me how you have modeled the computation in your Document Model. I can only tell you that for TotalPriceComputation, you need a precondition and for GrandTotalPriceComputation you do not. I modeled the computations as follows:
TotalPriceComputation
- Precondition
GroupFilled(RuleGroup)
- Computation
RoundAccounting([Amount]*[UnitPrice],2)
GrandTotalPriceComputation
- Precondition
- Computation
RoundAccounting(SumOfProducts(Order*/Amount,Order*/UnitPrice),2)
Please note, you need to use one of the language constructs for rounding when working with decimal places.
As you can see, the first rule has a simple precondition to check that a group has been specified before running the calculation. In other words, has the user click on the “Add” button on the repeat? If not, then do not run the calculation. The second rule has no precondition and will return 0,00€ if the Order is empty.