/** * Get Tax Line for Invoice Line * @param line invoice line * @param precision currency precision * @param oldTax if true old tax is returned * @param trxName transaction name * @return existing or new tax */ public static MInvoiceTax Get(MInvoiceLine line, int precision, Boolean oldTax, Trx trxName) { MInvoiceTax retValue = null; try { if (line == null || line.GetC_Invoice_ID() == 0 || line.IsDescription()) { return(null); } int C_Tax_ID = line.GetC_Tax_ID(); if (oldTax && line.Is_ValueChanged("C_Tax_ID")) { Object old = line.Get_ValueOld("C_Tax_ID"); if (old == null) { return(null); } C_Tax_ID = int.Parse(old.ToString()); } if (C_Tax_ID == 0) { _log.Warning("C_Tax_ID=0"); return(null); } String sql = "SELECT * FROM C_InvoiceTax WHERE C_Invoice_ID=" + line.GetC_Invoice_ID() + " AND C_Tax_ID=" + C_Tax_ID; try { DataSet ds = DataBase.DB.ExecuteDataset(sql, null, trxName); if (ds.Tables.Count > 0) { foreach (DataRow dr in ds.Tables[0].Rows) { retValue = new MInvoiceTax(line.GetCtx(), dr, trxName); } } } catch (Exception e) { _log.Log(Level.SEVERE, sql, e); } if (retValue != null) { retValue.Set_TrxName(trxName); retValue.SetPrecision(precision); _log.Fine("(old=" + oldTax + ") " + retValue); return(retValue); } // Create New retValue = new MInvoiceTax(line.GetCtx(), 0, trxName); retValue.Set_TrxName(trxName); retValue.SetClientOrg(line); retValue.SetC_Invoice_ID(line.GetC_Invoice_ID()); retValue.SetC_Tax_ID(line.GetC_Tax_ID()); retValue.SetPrecision(precision); retValue.SetIsTaxIncluded(line.IsTaxIncluded()); _log.Fine("(new) " + retValue); } catch { // MessageBox.Show("MInvoiceTax--Get"); } return(retValue); }
/// <summary> /// Get Surcharge Tax Line for Invoice Line /// </summary> /// <param name="line">line</param> /// <param name="precision">currenct precision</param> /// <param name="oldTax">get old tax</param> /// <param name="trxName">transaction</param> /// <returns>existing or new tax</returns> public static MInvoiceTax GetSurcharge(MInvoiceLine line, int precision, bool oldTax, Trx trxName) { MInvoiceTax retValue = null; try { if (line == null || line.GetC_Invoice_ID() == 0 || line.IsDescription()) { return(null); } int C_Tax_ID = line.GetC_Tax_ID(); if (oldTax && line.Is_ValueChanged("C_Tax_ID")) { Object old = line.Get_ValueOld("C_Tax_ID"); if (old == null) { return(null); } C_Tax_ID = int.Parse(old.ToString()); } // Get Surcharge Tax ID from Tax selected on Line C_Tax_ID = Util.GetValueOfInt(DB.ExecuteScalar("SELECT Surcharge_Tax_ID FROM C_Tax WHERE C_Tax_ID = " + C_Tax_ID, null, trxName)); if (C_Tax_ID == 0) { _log.Warning("C_Tax_ID=0"); return(null); } String sql = "SELECT * FROM C_InvoiceTax WHERE C_Invoice_ID=" + line.GetC_Invoice_ID() + " AND C_Tax_ID=" + C_Tax_ID; try { DataSet ds = DataBase.DB.ExecuteDataset(sql, null, trxName); if (ds.Tables.Count > 0) { foreach (DataRow dr in ds.Tables[0].Rows) { retValue = new MInvoiceTax(line.GetCtx(), dr, trxName); } } } catch (Exception e) { _log.Log(Level.SEVERE, sql, e); } // Get IsTaxincluded from selected PriceList on header bool isTaxIncluded = Util.GetValueOfString(DB.ExecuteScalar("SELECT IsTaxIncluded FROM M_PriceList WHERE M_PriceList_ID = (SELECT M_PriceList_ID FROM C_Invoice WHERE C_Invoice_ID = " + line.GetC_Invoice_ID() + ")", null, trxName)) == "Y"; if (retValue != null) { retValue.Set_TrxName(trxName); retValue.SetPrecision(precision); retValue.SetIsTaxIncluded(isTaxIncluded); _log.Fine("(old=" + oldTax + ") " + retValue); return(retValue); } // Create New retValue = new MInvoiceTax(line.GetCtx(), 0, trxName); retValue.Set_TrxName(trxName); retValue.SetClientOrg(line); retValue.SetC_Invoice_ID(line.GetC_Invoice_ID()); retValue.SetC_Tax_ID(C_Tax_ID); retValue.SetPrecision(precision); retValue.SetIsTaxIncluded(isTaxIncluded); _log.Fine("(new) " + retValue); } catch { // MessageBox.Show("MInvoiceTax--Get"); } return(retValue); }