Пример #1
0
        /// <summary>
        /// Get Discount Schema from Cache
        /// </summary>
        /// <param name="ctx">context</param>
        /// <param name="M_DiscountSchema_ID">id</param>
        /// <returns><MDiscountSchema/returns>
        public static MDiscountSchema Get(Ctx ctx, int M_DiscountSchema_ID)
        {
            int             key      = M_DiscountSchema_ID;
            MDiscountSchema retValue = (MDiscountSchema)s_cache[key];

            if (retValue != null)
            {
                return(retValue);
            }
            retValue = new MDiscountSchema(ctx, M_DiscountSchema_ID, null);
            if (retValue.Get_ID() != 0)
            {
                s_cache.Add(key, retValue);
            }
            return(retValue);
        }
Пример #2
0
        /// <summary>
        /// Calculate (Business Partner) Discount
        /// </summary>
        private void CalculateDiscount()
        {
            try
            {
                _discountSchema = false;
                if (_C_BPartner_ID == 0 || _M_Product_ID == 0)
                {
                    return;
                }

                int     M_DiscountSchema_ID = 0;
                Decimal?FlatDiscount        = null;
                String  sql = "SELECT COALESCE(p.M_DiscountSchema_ID,g.M_DiscountSchema_ID),"
                              + " COALESCE(p.PO_DiscountSchema_ID,g.PO_DiscountSchema_ID), p.FlatDiscount "
                              + "FROM C_BPartner p"
                              + " INNER JOIN C_BP_Group g ON (p.C_BP_Group_ID=g.C_BP_Group_ID) "
                              + "WHERE p.C_BPartner_ID=" + _C_BPartner_ID;
                DataTable   dt  = null;
                IDataReader idr = null;
                try
                {
                    idr = DataBase.DB.ExecuteReader(sql, null, null);
                    dt  = new DataTable();
                    dt.Load(idr);
                    idr.Close();
                    //if (dr.Read())
                    foreach (DataRow dr in dt.Rows)
                    {
                        M_DiscountSchema_ID = Utility.Util.GetValueOfInt(dr[_isSOTrx ? 0 : 1]);
                        if (dr[2] == DBNull.Value)
                        {
                            FlatDiscount = Env.ZERO;
                        }
                        else
                        {
                            FlatDiscount = Utility.Util.GetValueOfDecimal(dr[2]);//.getBigDecimal(3);
                        }
                        if (FlatDiscount == null)
                        {
                            FlatDiscount = Env.ZERO;
                        }
                    }
                }
                catch (Exception e)
                {
                    if (idr != null)
                    {
                        idr.Close();
                    }
                    log.Log(Level.SEVERE, sql, e);
                }
                finally
                {
                    dt = null;
                    if (idr != null)
                    {
                        idr.Close();
                    }
                }
                //	No Discount Schema
                if (M_DiscountSchema_ID == 0)
                {
                    return;
                }

                MDiscountSchema sd = MDiscountSchema.Get(Env.GetContext(), M_DiscountSchema_ID);        //	not correct
                if (sd.Get_ID() == 0)
                {
                    return;
                }
                //
                _discountSchema = true;
                _PriceStd       = sd.CalculatePrice(_qty, _PriceStd, _M_Product_ID, _M_Product_Category_ID, (decimal)FlatDiscount);
            }
            catch (Exception ex)
            {
                // MessageBox.Show("MProductPricing--CalculateDiscount");
                log.Severe(ex.ToString());
            }
        }