I am currently working on a purchase order form in the Advanced Print Views option of my Purcahse Order workspace. It uses the BOM tab and the Grid Tab to list items to purchase. I had a few questions on how I could get the following acomplished:
1 - How to show the "Aggregation Title" from the Grid Tab (which is a total from that tab) on the print view.
2 - How to add the total floats from the BOM and the Grid Tab on the advanced print view.
3 - Lastly, how to multiply the total of both to a sales tax (5-13%) and show the total of everything as a grand total.
Thank you.
I am struggling with the same. Has this been responded to somewhere else?
Try this. You can google for Velocity Macro for more info. Note this is NOT javascript.
Note in the code below, Velocity likes {these} around variables, but it is not required. I have been careless in providing these.
There may be a better way to do this, but when I first added the Quantity column, I had something like this:
$sumQty = ${sumQty} + ${grid.QUANTITY.value}
My problem was that the value is treated as a string, so the "+" was joining the strings together.
The result of adding 2, 3 and 4, ... was "234".
The reason you can see in my example I multiple by 1 each time, is to force it to consider this as a number, and therefore to use numeric addition, rather than string concatenation.
If someone has a better way, please say.
Also note that when you google for Velocity Macros, there is use of MathTool, which is basically a java library that a developer can add into the Velocity context when the (APV) template and the data hashtables are merged.
This gives you more functionality in the templates.
I have not tried to use this, because I don't know if Autodesk have injected any extension libraries into the context or not. And, if they have, whether they would be there forever. So I did not use these in this example.
However, you can see that you can do some basic maths, but anything more than this would be perhaps a little challenging.
If Autodesk are watching, the extension mechanism is a great way to pass functionality into a template, you could provide us helpful methods like createLink(item), or $relatedItem = loadRelatedItem(${item.SOME_PICKLIST}), loadRelatedItemGrid(...) - you get the idea.
APV code:
<div class="grid">
<table border="1">
<tbody>
<tr>
<th class="header" colspan="5">${workspace.metadata.grid.title.value}</th>
</tr>
<tr>
<th style="border: 1px solid black;">${workspace.metadata.grid.fields.rowID.title}</th>
<th style="border: 1px solid black;">${workspace.metadata.grid.fields.FRUIT.title}</th>
<th style="border: 1px solid black;">${workspace.metadata.grid.fields.QUANTITY.title}</th>
<th style="border: 1px solid black;">${workspace.metadata.grid.fields.PRICE.title}</th>
<th style="border: 1px solid black;">Quantity X Price</th>
</tr>
<!-- #set( $grandTotal = 0 ) -->
<!-- #set( $sumQty = 0 ) -->
<!-- #set( $sumPrice = 0 ) -->
<!-- #set( $ct = 0 ) -->
<!-- #foreach( $grid in $item.grid.rows ) -->
<!-- #set( $subtotal = ${grid.PRICE.value} * ${grid.QUANTITY.value} ) -->
<!-- #set( $grandTotal = $grandTotal + $subtotal ) -->
<!-- #set( $sumQty = ${sumQty}*1 + ${grid.QUANTITY.value}*1 ) -->
<!-- #set( $sumPrice = $sumPrice*1 + ${grid.PRICE.value}*1 ) -->
<!-- #set( $ct = $ct + 1 ) -->
<tr>
<td style="border: 1px solid black; text-align: right">${grid.rowID.value}</td>
<td style="border: 1px solid black; text-align: left">${grid.FRUIT.value}</td>
<td style="border: 1px solid black; text-align: right">${grid.QUANTITY.value}</td>
<td style="border: 1px solid black; text-align: right">${grid.PRICE.value}</td>
<td style="border: 1px solid black; text-align: right">${subtotal}</td>
</tr>
<!-- #end --></tbody>
<!-- #set( $avgPrice = ${sumPrice} / $ct ) -->
<tr>
<th style="border: 1px solid black; text-align: right"> </th>
<th style="border: 1px solid black; text-align: right"> </th>
<th style="border: 1px solid black; text-align: right">Sum: ${sumQty}</th>
<th style="border: 1px solid black; text-align: right">Avg: ${avgPrice}</th>
<th style="border: 1px solid black; text-align: right">Grand Total: ${grandTotal}</th>
</tr>
</table>
</div>
Can't find what you're looking for? Ask the community or share your knowledge.