private void GenerateMasterForecast(int M_Product_ID, decimal?totalQtyTeam, Decimal?totalQtyOpp, decimal?avgPrice) { sql = "select c_uom_id from m_product where m_product_id = " + M_Product_ID; MMasterForecastLine mfLine = new MMasterForecastLine(GetCtx(), 0, null); mfLine.SetAD_Client_ID(mf.GetAD_Client_ID()); mfLine.SetAD_Org_ID(mf.GetAD_Org_ID()); mfLine.SetM_Product_ID(M_Product_ID); mfLine.SetC_MasterForecast_ID(mf.GetC_MasterForecast_ID()); mfLine.SetForcastQty(totalQtyTeam); mfLine.SetOppQty(totalQtyOpp); Decimal?total = Decimal.Add(totalQtyOpp.Value, totalQtyTeam.Value); mfLine.SetTotalQty(total); mfLine.SetPrice(avgPrice); mfLine.SetC_UOM_ID(Util.GetValueOfInt(DB.ExecuteScalar(sql, null, null))); mfLine.SetProcessed(true); Decimal?planRevenue = Decimal.Round(Decimal.Multiply(avgPrice.Value, total.Value), 2, MidpointRounding.AwayFromZero); mfLine.SetPlannedRevenue(planRevenue); if (!mfLine.Save()) { log.SaveError("MasterForecastLineNotSaved", "MasterForecastLineNotSaved"); } }
/// <SUMmary> /// Create Master Forecast /// </SUMmary> /// <param name="M_Product_ID">Product </param> /// <param name="totalQtyTeam">Forecast Qty</param> /// <param name="totalQtyOpp">Opportunity Qty</param> /// <param name="avgPrice">Price</param> /// <param name="totalQtySO">Total </param> /// <returns>object</returns> private MMasterForecastLine GenerateMasterForecast(int M_Product_ID, int M_AttributeSetInstance, decimal?totalQtyTeam, Decimal?totalQtyOpp, decimal?avgPrice) { MMasterForecastLine mfLine = MMasterForecastLine.GetOrCreate(mf, M_Product_ID, M_AttributeSetInstance); Decimal? qty = mfLine.GetOppQty(); mfLine.SetC_MasterForecast_ID(mf.GetC_MasterForecast_ID()); if (totalQtyOpp > 0 && totalQtyTeam > 0) { mfLine.SetForcastQty(totalQtyTeam + mfLine.GetForcastQty()); mfLine.SetOppQty(totalQtyOpp); } else { mfLine.SetForcastQty(totalQtyTeam); mfLine.SetOppQty(totalQtyOpp + mfLine.GetOppQty()); } //Decimal? totalqty = Decimal.Add(mfLine.GetForcastQty(), mfLine.GetOppQty()); mfLine.SetTotalQty(mfLine.GetForcastQty() + mfLine.GetOppQty()); //calculate average price for opportunit case only if (totalQtyOpp > 0 && totalQtyTeam == 0) { avgPrice = ((mfLine.GetPrice() * qty) + (avgPrice * totalQtyOpp)) / mfLine.GetTotalQty(); avgPrice = Decimal.Round(avgPrice.Value, StdPrecision, MidpointRounding.AwayFromZero); mfLine.SetPrice(avgPrice); } //Team Forecast case else { mfLine.SetPrice(avgPrice); } Decimal?planRevenue = Decimal.Round(Decimal.Multiply(mfLine.GetPrice(), mfLine.GetTotalQty()), StdPrecision, MidpointRounding.AwayFromZero); mfLine.SetPlannedRevenue(planRevenue); return(mfLine); }
/// <SUMmary> /// Create Master Forecast /// </SUMmary> /// <param name="M_Product_ID">Product </param> /// <param name="totalQtyTeam">Forecast Qty</param> /// <param name="totalQtyOpp">Opportunity Qty</param> /// <param name="avgPrice">Price</param> /// <param name="totalQtySO">Total </param> /// <returns>odject</returns> private MMasterForecastLine GenerateMasterForecast(int M_Product_ID, int M_AttributeSetInstance, decimal?totalQtyTeam, Decimal?totalQtyOpp, decimal?avgPrice) { MMasterForecastLine mfLine = MMasterForecastLine.GetOrCreate(mf, M_Product_ID, M_AttributeSetInstance); mfLine.SetC_MasterForecast_ID(mf.GetC_MasterForecast_ID()); mfLine.SetForcastQty(totalQtyTeam); mfLine.SetOppQty(totalQtyOpp + mfLine.GetOppQty()); Decimal?total = Decimal.Add(totalQtyOpp.Value, totalQtyTeam.Value); mfLine.SetTotalQty(total + mfLine.GetTotalQty()); mfLine.SetPrice(avgPrice + mfLine.GetPrice()); Decimal?planRevenue = Decimal.Round(Decimal.Multiply(mfLine.GetPrice(), mfLine.GetTotalQty()), StdPrecision, MidpointRounding.AwayFromZero); mfLine.SetPlannedRevenue(planRevenue); return(mfLine); }