You can add various totals field like item total, discount, tax, shipping, grand total etc dynamically using the addInvoiceTotal function. This function also helps you to auto calculate item sum or discount/tax amount as percentage or summation of fields. Similar to other fields, these can also be set in defaultData file as well as can be added dynamically. There are already few fields added in defaultData, You can overwrite that field or remove/reset that fields using reset function.
$xinvoice = new Xinvoice(); /** * Add invoice totals * @param string $totalId unique id for each totals * @param string $lableName Lable for the field * @param string $data data to be used to generate the field * @param string $operation Whether to use sum or percentage operation to generate field * @param string $param Parameter like how much percentage etc. * @param bool $negative Whether field will be negative or positive for further calculations. * return object Object of xinvoice */ $xinvoice->addInvoiceTotal("subtotal", "Sub Total: ", array("item_total")); $xinvoice->addInvoiceTotal("discount", "Discount @10%: ", array("item_total"),"%", 10, true); $xinvoice->addInvoiceTotal("tax", "Tax @10%: ", array("item_total", "discount"),"%", 10); $xinvoice->addInvoiceTotal("shipping", "Shipping: ", array(100)); $xinvoice->addInvoiceTotal("grandtotal", "Grand Total: ", array("item_total", "discount","tax","shipping"),"+");