/// <summary> /// Before Save /// </summary> /// <param name="newRecord">new</param> /// <returns>true</returns> protected override bool BeforeSave(bool newRecord) { if (GetLine() == 0) { SetLine(); } // Planned Amount - Currency Precision Decimal plannedAmt = Decimal.Multiply(GetPlannedQty(), GetPlannedPrice()); if (Env.Scale(plannedAmt) > GetCurPrecision()) { //plannedAmt.setScale(GetCurPrecision(), Decimal.ROUND_HALF_UP); Decimal.Round(plannedAmt, GetCurPrecision(), MidpointRounding.AwayFromZero); } SetPlannedAmt(plannedAmt); // Planned Margin if (Is_ValueChanged("M_Product_ID") || Is_ValueChanged("M_Product_Category_ID") || Is_ValueChanged("PlannedQty") || Is_ValueChanged("PlannedPrice")) { if (GetM_Product_ID() != 0) { Decimal marginEach = Decimal.Subtract(GetPlannedPrice(), GetLimitPrice()); SetPlannedMarginAmt(Decimal.Multiply(marginEach, GetPlannedQty())); } else if (GetM_Product_Category_ID() != 0) { MProductCategory category = MProductCategory.Get(GetCtx(), GetM_Product_Category_ID()); Decimal marginEach = category.GetPlannedMargin(); SetPlannedMarginAmt(Decimal.Multiply(marginEach, GetPlannedQty())); } } // Phase/Task if (Is_ValueChanged("C_ProjectTask_ID") && GetC_ProjectTask_ID() != 0) { MProjectTask pt = new MProjectTask(GetCtx(), GetC_ProjectTask_ID(), Get_TrxName()); if (pt == null || pt.Get_ID() == 0) { log.Warning("Project Task Not Found - ID=" + GetC_ProjectTask_ID()); return(false); } else { SetC_ProjectPhase_ID(pt.GetC_ProjectPhase_ID()); } } if (Is_ValueChanged("C_ProjectPhase_ID") && GetC_ProjectPhase_ID() != 0) { MProjectPhase pp = new MProjectPhase(GetCtx(), GetC_ProjectPhase_ID(), Get_TrxName()); if (pp == null || pp.Get_ID() == 0) { log.Warning("Project Phase Not Found - " + GetC_ProjectPhase_ID()); return(false); } else { SetC_Project_ID(pp.GetC_Project_ID()); } } return(true); }
/// <summary> /// Before Save /// </summary> /// <param name="newRecord">new</param> /// <returns>true</returns> protected override bool BeforeSave(bool newRecord) { if (GetLine() == 0) { SetLine(); } // Work done for Purchase Price and Mergin calculation if (Env.IsModuleInstalled("VA077_") && Get_ColumnIndex("VA077_PurchasePrice") >= 0 && Util.GetValueOfDecimal(Get_Value("VA077_PurchasePrice")).Equals(0)) { if (GetProject() != null && _parent.IsOpportunity() && Util.GetValueOfInt(_parent.Get_Value("PO_PriceList_ID")) > 0) { Set_Value("VA077_PurchasePrice", GetPurchasePrice()); // Calculate Purchase Amount Decimal purchaseAmt = Decimal.Multiply(GetPlannedQty(), Util.GetValueOfDecimal(Get_Value("VA077_PurchasePrice"))); if (Env.Scale(purchaseAmt) > GetCurPrecision()) { purchaseAmt = Decimal.Round(purchaseAmt, GetCurPrecision(), MidpointRounding.AwayFromZero); } Set_Value("VA077_PurchaseAmt", purchaseAmt); } // Calculate Margin Amount Decimal marginEach = Decimal.Subtract(GetPlannedPrice(), Util.GetValueOfDecimal(Get_Value("VA077_PurchasePrice"))); Set_Value("VA077_MarginAmt", Decimal.Multiply(marginEach, GetPlannedQty())); // Calculate Margin Percentage Decimal marginPer = 0; if (GetPlannedPrice() > 0) { marginPer = Decimal.Round(Decimal.Multiply(Decimal.Divide(marginEach, GetPlannedPrice()) , Env.ONEHUNDRED), GetCurPrecision(), MidpointRounding.AwayFromZero); } Set_Value("VA077_MarginPercent", marginPer); } // Planned Amount - Currency Precision Decimal plannedAmt = Decimal.Multiply(GetPlannedQty(), GetPlannedPrice()); if (Env.Scale(plannedAmt) > GetCurPrecision()) { //plannedAmt.setScale(GetCurPrecision(), Decimal.ROUND_HALF_UP); Decimal.Round(plannedAmt, GetCurPrecision(), MidpointRounding.AwayFromZero); } SetPlannedAmt(plannedAmt); // Planned Margin if (Is_ValueChanged("M_Product_ID") || Is_ValueChanged("M_Product_Category_ID") || Is_ValueChanged("PlannedQty") || Is_ValueChanged("PlannedPrice")) { if (GetM_Product_ID() != 0) { Decimal marginEach = Decimal.Subtract(GetPlannedPrice(), GetLimitPrice()); SetPlannedMarginAmt(Decimal.Multiply(marginEach, GetPlannedQty())); } else if (GetM_Product_Category_ID() != 0) { MProductCategory category = MProductCategory.Get(GetCtx(), GetM_Product_Category_ID()); Decimal marginEach = category.GetPlannedMargin(); SetPlannedMarginAmt(Decimal.Multiply(marginEach, GetPlannedQty())); } } // Phase/Task if (Is_ValueChanged("C_ProjectTask_ID") && GetC_ProjectTask_ID() != 0) { MProjectTask pt = new MProjectTask(GetCtx(), GetC_ProjectTask_ID(), Get_TrxName()); if (pt == null || pt.Get_ID() == 0) { log.Warning("Project Task Not Found - ID=" + GetC_ProjectTask_ID()); return(false); } else { SetC_ProjectPhase_ID(pt.GetC_ProjectPhase_ID()); } } if (Is_ValueChanged("C_ProjectPhase_ID") && GetC_ProjectPhase_ID() != 0) { MProjectPhase pp = new MProjectPhase(GetCtx(), GetC_ProjectPhase_ID(), Get_TrxName()); if (pp == null || pp.Get_ID() == 0) { log.Warning("Project Phase Not Found - " + GetC_ProjectPhase_ID()); return(false); } else { SetC_Project_ID(pp.GetC_Project_ID()); } } return(true); }
/// <summary> /// To copy task from other phase to new phase /// </summary> /// <param name="fromPhase">From Phase</param> /// <param name="toPhase">To Phase</param> /// <returns></returns> public int CopyTasksFrom(MProjectPhase fromPhase, MProjectPhase toPhase) { if (fromPhase == null) { return(0); } int count = 0; ValueNamePair pp = null; StringBuilder msg = new StringBuilder(); MProjectTask[] myTasks = GetTasks(); MProjectTask[] fromTasks = fromPhase.GetTasks(); int C_Task_ID = 0; bool exists = false; // Copy Project Tasks for (int i = 0; i < fromTasks.Length; i++) { // Check if Task already exists C_Task_ID = fromTasks[i].GetC_ProjectTask_ID(); exists = false; if (C_Task_ID == 0) { exists = false; } else { for (int ii = 0; ii < myTasks.Length; ii++) { if (myTasks[ii].GetC_ProjectTask_ID() == C_Task_ID) { exists = true; break; } } } // Phase exist if (exists) { log.Info("Task already exists here, ignored - " + fromTasks[i]); } else { MProjectTask toTask = new MProjectTask(GetCtx(), 0, Get_TrxName()); PO.CopyValues(fromTasks[i], toTask, GetAD_Client_ID(), GetAD_Org_ID()); toTask.SetC_ProjectPhase_ID(toPhase.GetC_ProjectPhase_ID()); if (toTask.Save()) { count++; count += CopyMTaskLinesFromProjectTask(fromTasks[i], toTask, toPhase.GetC_Project_ID()); } else { pp = VLogger.RetrieveError(); if (pp != null) { msg.Append(pp.GetName()); //if GetName is Empty then it will check GetValue if (string.IsNullOrEmpty(msg.ToString())) { msg.Append(Msg.GetMsg("", pp.GetValue())); } } if (string.IsNullOrEmpty(msg.ToString())) { msg.Append(Msg.GetMsg(GetCtx(), "VIS_LineNotSaved")); } else { msg.Append(Msg.GetMsg(GetCtx(), "VIS_LineNotSaved") + "," + msg.ToString()); } } } } if (fromTasks.Length != count) { log.Warning("Count difference - ProjectPhase=" + fromTasks.Length + " <> Saved=" + count); } return(count); }