I am designing a simple purchase requisition form which requires the following:
1. For each data entry row (only one row is shown below), multiply user inputs (Quantity * UnitPrice) and put into LineTotalTotal field
2. Check to see if Taxable radio button returns true value.
3. If value is true, calculate tax amount (Linetotal * .0825) = Tax and put in Tax Total field
4. Go to the next line and calculate next LineTotal, if the UnitPrice is taxable, calculate Tax and add it to the Tax Total
5. Add all LineTotals and put the result in the Subtotal field
6. Add Subtotal, Tax Total and Shipping (user input) and put result in Estimated Total field
Don't know which approach is the most efficient (or really how to set up a stack) do I need to create a variable?
Is it better to use numeric fields or decimal fields for calculating currency amounts?
Any help is appreciated.
If you check the help and search for "to perform calculations in a table" there is an example of using FormCalc for this.
For adding up the Tax Total field you would need an if statement to check if the item is marked Taxable and then add to the Tax Total or not.
Also, check out this sample from Niall, it might help:
You definitely want to use repeating fields/subforms so that you can use the Instance numbers (the number in square brackets you see in the hierarchy with repeated objects; , , , etc.) in the calculation.
How are you generating your extra rows currently?
With repeating table rows or subforms (table rows are a special subset of subforms) you can do things like:
subTotal = sum(Table1.Row1[*].Total) (in FormCalc) this would look for every instance of Row1 and sum the Total field (I think the syntax is correct, going off the top of my head).
I was planning to get the first row working properly and then just cloning the following rows (6 in all) and then giving unique identifiers to Qty., Unit Price, and Total. Seems very cumbersome, which is why I thought it might be a good idea to get advice regarding my intended direction first.
What would be slick is the ability to generate rows as needed (which is what I think you are hinting at with subforms) with a limit of no more than six instances.
I really appreciate your feedback and advice; as you might already have guessed my programming skills are mostly conceptual without much more.
Just make sure in the binding palette for the row you want to repeat you have the "Repeat Row for Each Data Item" box cheked. There you can also specify that the max number of rows is 6.
One of the tutorials that comes with LiveCycle is a purchase order with repeating rows, you might want to take a look at that.
Also take a look at another great sample by Niall on dealing with tables: