Tutorial - Invoice Advance
Advance formula usage
In our invoice we want to show total price of each item. Add new column with text widget and a tag. We can calculate total price inside report. Set formula to: item.quantity * item.price
Formula engine supports following operations:
- basic math operations
+ - * / ^
- parentheses to indicate grouping and order of operaions
( )
- string literals
"this is string"
- global functions
sin()
- data functions (when data source is JavaScript file)
data.myAsyncFunc()
- methods on data types
"this is string".substring(3, 6)
Sum all prices
Total price is not available in source data. We have to calculate it when generating report.
PantherPDF editor supports simple variable transformation inside GUI editor. For complex transformations, use transforms.
We have to create a variable to save our calculation. Drag-drop a SetVar widget. Variable named var
(can be changed) will be accesible inside this widget. Drag-drop a Repeat widget inside SetVar widget and set source data to data.items
. Drag-drop Update variable into Repeat. Select variable var and formula to var + item.price * item.quantity
. This will take previous value and add current item's price. Last think is to display total value. Drag-drop a Text widget into SetVar (after Repeat), add tag, and set it's source data to var
.
Transforms
Transforms can be used to filter, sort or in some other way transform source data. It is designed as a pipeline - result of first transform is an input to the next one. Common use case is to sort array. It supports complex custom transformations with JavaScript functions.
Output CSV
PantherPDF edtior can be used to output not only PDFs but also csv, html and json files. You can prepare data for ERP system, CNC machines ... Property target on Property panel controls output type. It can be overriden when sending API request.