private boolean createTaxCorrection(MAcctSchema as,Fact fact,DocLine_Allocation line,MAccount DiscountAccount,MAccount WriteOffAccoint,boolean isSOTrx){
  log.info(line.toString());
  BigDecimal discount=Env.ZERO;
  if (as.isTaxCorrectionDiscount())   discount=line.getDiscountAmt();
  BigDecimal writeOff=Env.ZERO;
  if (as.isTaxCorrectionWriteOff())   writeOff=line.getWriteOffAmt();
  Doc_AllocationTax tax=new Doc_AllocationTax(DiscountAccount,discount,WriteOffAccoint,writeOff,isSOTrx);
  String sql="SELECT * " + "FROM Fact_Acct " + "WHERE AD_Table_ID=318 AND Record_ID=?"+ " AND C_AcctSchema_ID=?"+ " AND Line_ID IS NULL";
  PreparedStatement pstmt=null;
  ResultSet rs=null;
  try {
    pstmt=DB.prepareStatement(sql,getTrxName());
    pstmt.setInt(1,line.getC_Invoice_ID());
    pstmt.setInt(2,as.getC_AcctSchema_ID());
    rs=pstmt.executeQuery();
    while (rs.next())     tax.addInvoiceFact(new MFactAcct(getCtx(),rs,fact.get_TrxName()));
  }
 catch (  Exception e) {
    log.log(Level.SEVERE,sql,e);
  }
 finally {
    DB.close(rs,pstmt);
    rs=null;
    pstmt=null;
  }
  if (tax.getLineCount() == 0) {
    log.warning("Invoice not posted yet - " + line);
    return false;
  }
  if (tax.getLineCount() < 2)   return true;
  return tax.createEntries(as,fact,line);
}

private boolean createTaxCorrection ( MAcctSchema as , Fact fact , DocLine_Allocation line , MAccount DiscountAccount , MAccount WriteOffAccoint , boolean isSOTrx ) { log . info ( line . toString ( ) ) ; BigDecimal discount = Env . ZERO ; if ( as . isTaxCorrectionDiscount ( ) ) discount = line . getDiscountAmt ( ) ; BigDecimal writeOff = Env . ZERO ; if ( as . isTaxCorrectionWriteOff ( ) ) writeOff = line . getWriteOffAmt ( ) ; Doc_AllocationTax tax = new Doc_AllocationTax ( DiscountAccount , discount , WriteOffAccoint , writeOff , isSOTrx ) ; String sql = "SELECT * " + "FROM Fact_Acct " + "WHERE AD_Table_ID=318 AND Record_ID=?" + " AND C_AcctSchema_ID=?" + " AND Line_ID IS NULL" ; PreparedStatement pstmt = null ; ResultSet rs = null ; try { pstmt = DB . prepareStatement ( sql , getTrxName ( ) ) ; pstmt . setInt ( 1 , line . getC_Invoice_ID ( ) ) ; pstmt . setInt ( 2 , as . getC_AcctSchema_ID ( ) ) ; rs = pstmt . executeQuery ( ) ; while ( rs . next ( ) ) tax . addInvoiceFact ( new MFactAcct ( getCtx ( ) , rs , fact . get_TrxName ( ) ) ) ; } catch ( Exception e ) { log . log ( Level . SEVERE , sql , e ) ; } finally { DB . close ( rs , pstmt ) ; rs = null ; pstmt = null ; } if ( tax . getLineCount ( ) == 0 ) { log . warning ( "Invoice not posted yet - " + line ) ; return false ; } if ( tax . getLineCount ( ) < 2 ) return true ; return tax . createEntries ( as , fact , line ) ; }
create tax correction . requirement : adjust the tax amount , if you did not receive the full amount of the invoice ( payment discount , write - off ) . applies to many countries with vat . example : invoice : net $ 100 + tax1 $ 15 + tax2 $ 5 = total $ 120 payment : $ 115 ( i . e . $ 5 underpayment ) tax adjustment = tax1 = 0 . 63 ( 15 / 120 * 5 ) tax2 = 0 . 21 ( 5 / 120 / 5 )
