question: public boolean calculateTaxTotal ( ) { log . fine ( "" ) ; DB . executeUpdateEx ( "DELETE C_InvoiceTax WHERE C_Invoice_ID=" + getC_Invoice_ID ( ) , get_TrxName ( ) ) ; m_taxes = null ; BigDecimal totalLines = Env . ZERO ; ArrayList < Integer > taxList = new ArrayList < Integer > ( ) ; MInvoiceLine [ ] lines = getLines ( false ) ; for ( int i = 0 ; i < lines . length ; i ++ ) { MInvoiceLine line = lines [ i ] ; if ( ! taxList . contains ( line . getC_Tax_ID ( ) ) ) { MInvoiceTax iTax = MInvoiceTax . get ( line , getPrecision ( ) , false , get_TrxName ( ) ) ; if ( iTax != null ) { iTax . setIsTaxIncluded ( isTaxIncluded ( ) ) ; if ( ! iTax . calculateTaxFromLines ( ) ) return false ; iTax . saveEx ( ) ; taxList . add ( line . getC_Tax_ID ( ) ) ; } } totalLines = totalLines . add ( line . getLineNetAmt ( ) ) ; } BigDecimal grandTotal = totalLines ; MInvoiceTax [ ] taxes = getTaxes ( true ) ; for ( int i = 0 ; i < taxes . length ; i ++ ) { MInvoiceTax iTax = taxes [ i ] ; MTax tax = iTax . getTax ( ) ; if ( tax . isSummary ( ) ) { MTax [ ] cTaxes = tax . getChildTaxes ( false ) ; for ( int j = 0 ; j < cTaxes . length ; j ++ ) { MTax cTax = cTaxes [ j ] ; BigDecimal taxAmt = cTax . calculateTax ( iTax . getTaxBaseAmt ( ) , isTaxIncluded ( ) , getPrecision ( ) ) ; MInvoiceTax newITax = new MInvoiceTax ( getCtx ( ) , 0 , get_TrxName ( ) ) ; newITax . setClientOrg ( this ) ; newITax . setC_Invoice_ID ( getC_Invoice_ID ( ) ) ; newITax . setC_Tax_ID ( cTax . getC_Tax_ID ( ) ) ; newITax . setPrecision ( getPrecision ( ) ) ; newITax . setIsTaxIncluded ( isTaxIncluded ( ) ) ; newITax . setTaxBaseAmt ( iTax . getTaxBaseAmt ( ) ) ; newITax . setTaxAmt ( taxAmt ) ; newITax . saveEx ( get_TrxName ( ) ) ; if ( ! isTaxIncluded ( ) ) grandTotal = grandTotal . add ( taxAmt ) ; } iTax . deleteEx ( true , get_TrxName ( ) ) ; } else { if ( ! isTaxIncluded ( ) ) grandTotal = grandTotal . add ( iTax . getTaxAmt ( ) ) ; } } setTotalLines ( totalLines ) ; setGrandTotal ( grandTotal ) ; return true ; }
target:  Calculate Tax and Total