public boolean calculateTaxTotal(){
  log.fine("");
  DB.executeUpdateEx("DELETE C_OrderTax WHERE C_Order_ID=" + getC_Order_ID(),get_TrxName());
  m_taxes=null;
  BigDecimal totalLines=Env.ZERO;
  ArrayList<Integer> taxList=new ArrayList<Integer>();
  MOrderLine[] lines=getLines();
  for (int i=0; i < lines.length; i++) {
    MOrderLine line=lines[i];
    Integer taxID=new Integer(line.getC_Tax_ID());
    if (!taxList.contains(taxID)) {
      MOrderTax oTax=MOrderTax.get(line,getPrecision(),false,get_TrxName());
      oTax.setIsTaxIncluded(isTaxIncluded());
      if (!oTax.calculateTaxFromLines())       return false;
      if (!oTax.save(get_TrxName()))       return false;
      taxList.add(taxID);
    }
    totalLines=totalLines.add(line.getLineNetAmt());
  }
  BigDecimal grandTotal=totalLines;
  MOrderTax[] taxes=getTaxes(true);
  for (int i=0; i < taxes.length; i++) {
    MOrderTax oTax=taxes[i];
    MTax tax=oTax.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(oTax.getTaxBaseAmt(),isTaxIncluded(),getPrecision());
        MOrderTax newOTax=new MOrderTax(getCtx(),0,get_TrxName());
        newOTax.setClientOrg(this);
        newOTax.setC_Order_ID(getC_Order_ID());
        newOTax.setC_Tax_ID(cTax.getC_Tax_ID());
        newOTax.setPrecision(getPrecision());
        newOTax.setIsTaxIncluded(isTaxIncluded());
        newOTax.setTaxBaseAmt(oTax.getTaxBaseAmt());
        newOTax.setTaxAmt(taxAmt);
        if (!newOTax.save(get_TrxName()))         return false;
        if (!isTaxIncluded())         grandTotal=grandTotal.add(taxAmt);
      }
      if (!oTax.delete(true,get_TrxName()))       return false;
      if (!oTax.save(get_TrxName()))       return false;
    }
 else {
      if (!isTaxIncluded())       grandTotal=grandTotal.add(oTax.getTaxAmt());
    }
  }
  setTotalLines(totalLines);
  setGrandTotal(grandTotal);
  return true;
}

public boolean calculateTaxTotal ( ) { log . fine ( "" ) ; DB . executeUpdateEx ( "DELETE C_OrderTax WHERE C_Order_ID=" + getC_Order_ID ( ) , get_TrxName ( ) ) ; m_taxes = null ; BigDecimal totalLines = Env . ZERO ; ArrayList < Integer > taxList = new ArrayList < Integer > ( ) ; MOrderLine [ ] lines = getLines ( ) ; for ( int i = 0 ; i < lines . length ; i ++ ) { MOrderLine line = lines [ i ] ; Integer taxID = new Integer ( line . getC_Tax_ID ( ) ) ; if ( ! taxList . contains ( taxID ) ) { MOrderTax oTax = MOrderTax . get ( line , getPrecision ( ) , false , get_TrxName ( ) ) ; oTax . setIsTaxIncluded ( isTaxIncluded ( ) ) ; if ( ! oTax . calculateTaxFromLines ( ) ) return false ; if ( ! oTax . save ( get_TrxName ( ) ) ) return false ; taxList . add ( taxID ) ; } totalLines = totalLines . add ( line . getLineNetAmt ( ) ) ; } BigDecimal grandTotal = totalLines ; MOrderTax [ ] taxes = getTaxes ( true ) ; for ( int i = 0 ; i < taxes . length ; i ++ ) { MOrderTax oTax = taxes [ i ] ; MTax tax = oTax . 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 ( oTax . getTaxBaseAmt ( ) , isTaxIncluded ( ) , getPrecision ( ) ) ; MOrderTax newOTax = new MOrderTax ( getCtx ( ) , 0 , get_TrxName ( ) ) ; newOTax . setClientOrg ( this ) ; newOTax . setC_Order_ID ( getC_Order_ID ( ) ) ; newOTax . setC_Tax_ID ( cTax . getC_Tax_ID ( ) ) ; newOTax . setPrecision ( getPrecision ( ) ) ; newOTax . setIsTaxIncluded ( isTaxIncluded ( ) ) ; newOTax . setTaxBaseAmt ( oTax . getTaxBaseAmt ( ) ) ; newOTax . setTaxAmt ( taxAmt ) ; if ( ! newOTax . save ( get_TrxName ( ) ) ) return false ; if ( ! isTaxIncluded ( ) ) grandTotal = grandTotal . add ( taxAmt ) ; } if ( ! oTax . delete ( true , get_TrxName ( ) ) ) return false ; if ( ! oTax . save ( get_TrxName ( ) ) ) return false ; } else { if ( ! isTaxIncluded ( ) ) grandTotal = grandTotal . add ( oTax . getTaxAmt ( ) ) ; } } setTotalLines ( totalLines ) ; setGrandTotal ( grandTotal ) ; return true ; }
calculate tax and total
