/// <summary>
        /// Get Tax Line for Order 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 MOrderTax Get(MOrderLine line, int precision, bool oldTax, Trx trxName)
        {
            MOrderTax retValue = null;

            if (line == null || line.GetC_Order_ID() == 0)
            {
                //s_log.fine("No Order");
                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)
                {
                    //s_log.fine("No Old Tax");
                    return(null);
                }
                C_Tax_ID = int.Parse(old.ToString());
            }
            if (C_Tax_ID == 0)
            {
                s_log.Fine("No Tax");
                return(null);
            }

            String  sql = "SELECT * FROM C_OrderTax WHERE C_Order_ID=" + line.GetC_Order_ID() + " AND C_Tax_ID=" + C_Tax_ID;
            DataSet ds  = null;

            try
            {
                ds = DataBase.DB.ExecuteDataset(sql, null, trxName);
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = ds.Tables[0].Rows[i];
                    retValue = new MOrderTax(line.GetCtx(), dr, trxName);
                }
                ds = null;
            }
            catch (Exception e)
            {
                s_log.Log(Level.SEVERE, sql, e);
            }

            // JID_1303: On Order tax calculate tax according to selected pricelist. If user delete lines and change pricelist, it should check IsTaxIncluded on selected Pricelist.
            bool isTaxIncluded = Util.GetValueOfString(DB.ExecuteScalar("SELECT IsTaxIncluded FROM M_PriceList WHERE M_PriceList_ID = (SELECT M_PriceList_ID FROM C_Order WHERE C_Order_ID = "
                                                                        + line.GetC_Order_ID() + ")", null, trxName)) == "Y";

            if (retValue != null)
            {
                retValue.SetPrecision(precision);
                retValue.Set_TrxName(trxName);

                retValue.SetIsTaxIncluded(isTaxIncluded);

                s_log.Fine("(old=" + oldTax + ") " + retValue);
                return(retValue);
            }

            //	Create New
            retValue = new MOrderTax(line.GetCtx(), 0, trxName);
            retValue.Set_TrxName(trxName);
            retValue.SetClientOrg(line);
            retValue.SetC_Order_ID(line.GetC_Order_ID());
            retValue.SetC_Tax_ID(line.GetC_Tax_ID());
            retValue.SetPrecision(precision);
            retValue.SetIsTaxIncluded(line.IsTaxIncluded());
            s_log.Fine("(new) " + retValue);
            return(retValue);
        }
Beispiel #2
0
        /// <summary>
        /// Get Tax Line for Order 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 MOrderTax Get(MOrderLine line, int precision, bool oldTax, Trx trxName)
        {
            MOrderTax retValue = null;

            if (line == null || line.GetC_Order_ID() == 0)
            {
                //s_log.fine("No Order");
                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)
                {
                    //s_log.fine("No Old Tax");
                    return(null);
                }
                C_Tax_ID = int.Parse(old.ToString());
            }
            if (C_Tax_ID == 0)
            {
                s_log.Fine("No Tax");
                return(null);
            }

            String  sql = "SELECT * FROM C_OrderTax WHERE C_Order_ID=" + line.GetC_Order_ID() + " AND C_Tax_ID=" + C_Tax_ID;
            DataSet ds  = null;

            try
            {
                ds = DataBase.DB.ExecuteDataset(sql, null, trxName);
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow dr = ds.Tables[0].Rows[i];
                    retValue = new MOrderTax(line.GetCtx(), dr, trxName);
                }
                ds = null;
            }
            catch (Exception e)
            {
                s_log.Log(Level.SEVERE, sql, e);
            }

            if (retValue != null)
            {
                retValue.SetPrecision(precision);
                retValue.Set_TrxName(trxName);
                s_log.Fine("(old=" + oldTax + ") " + retValue);
                return(retValue);
            }

            //	Create New
            retValue = new MOrderTax(line.GetCtx(), 0, trxName);
            retValue.Set_TrxName(trxName);
            retValue.SetClientOrg(line);
            retValue.SetC_Order_ID(line.GetC_Order_ID());
            retValue.SetC_Tax_ID(line.GetC_Tax_ID());
            retValue.SetPrecision(precision);
            retValue.SetIsTaxIncluded(line.IsTaxIncluded());
            s_log.Fine("(new) " + retValue);
            return(retValue);
        }
        /// <summary>
        /// Get Surcharge Tax Line for Order 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 MOrderTax GetSurcharge(MOrderLine line, int precision, bool oldTax, Trx trxName)
        {
            MOrderTax retValue = null;

            if (line == null || line.GetC_Order_ID() == 0)
            {
                //s_log.fine("No Order");
                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)
                {
                    //s_log.fine("No Old Tax");
                    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)
            {
                s_log.Fine("No Tax");
                return(null);
            }

            String  sql = "SELECT * FROM C_OrderTax WHERE C_Order_ID=" + line.GetC_Order_ID() + " AND C_Tax_ID=" + C_Tax_ID;
            DataSet ds  = null;

            try
            {
                ds = DataBase.DB.ExecuteDataset(sql, null, trxName);
                if (ds != null && ds.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        DataRow dr = ds.Tables[0].Rows[i];
                        retValue = new MOrderTax(line.GetCtx(), dr, trxName);
                    }
                    ds = null;
                }
            }
            catch (Exception e)
            {
                s_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_Order WHERE C_Order_ID = "
                                                                        + line.GetC_Order_ID() + ")", null, trxName)) == "Y";

            if (retValue != null)
            {
                retValue.SetPrecision(precision);
                retValue.SetIsTaxIncluded(isTaxIncluded);
                retValue.Set_TrxName(trxName);
                s_log.Fine("(old=" + oldTax + ") " + retValue);
                return(retValue);
            }

            //	Create New
            retValue = new MOrderTax(line.GetCtx(), 0, trxName);
            retValue.Set_TrxName(trxName);
            retValue.SetClientOrg(line);
            retValue.SetC_Order_ID(line.GetC_Order_ID());
            retValue.SetC_Tax_ID(C_Tax_ID);
            retValue.SetPrecision(precision);
            retValue.SetIsTaxIncluded(isTaxIncluded);
            s_log.Fine("(new) " + retValue);
            return(retValue);
        }