} // toString /** * Before Save * @param newRecord new * @return true */ protected override Boolean BeforeSave(Boolean newRecord) { if (MEASURETYPE_Calculated.Equals(GetMeasureType()) && GetPA_MeasureCalc_ID() == 0) { log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "PA_MeasureCalc_ID")); return(false); } else if (MEASURETYPE_Ratio.Equals(GetMeasureType()) && GetPA_Ratio_ID() == 0) { log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "PA_Ratio_ID")); return(false); } else if (MEASURETYPE_UserDefined.Equals(GetMeasureType()) && (GetCalculationClass() == null || GetCalculationClass().Length == 0)) { log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "CalculationClass")); return(false); } else if (MEASURETYPE_Request.Equals(GetMeasureType()) && GetR_RequestType_ID() == 0) { log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "R_RequestType_ID")); return(false); } else if (MEASURETYPE_Project.Equals(GetMeasureType()) && GetC_ProjectType_ID() == 0) { log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "C_ProjectType_ID")); return(false); } return(true); } // beforeSave
} // afterSave /** * Update/save Goals * @return true if updated */ public Boolean UpdateGoals() { String mt = GetMeasureType(); try { if (MEASURETYPE_Manual.Equals(mt)) { return(UpdateManualGoals()); } else if (MEASURETYPE_Achievements.Equals(mt)) { return(UpdateAchievementGoals()); } else if (MEASURETYPE_Calculated.Equals(mt)) { return(UpdateCalculatedGoals()); } else if (MEASURETYPE_Ratio.Equals(mt)) { return(UpdateRatios()); } else if (MEASURETYPE_Request.Equals(mt)) { return(UpdateRequests()); } else if (MEASURETYPE_Project.Equals(mt)) { return(UpdateProjects()); } // Projects } catch (Exception e) { log.Log(Level.SEVERE, "MeasureType=" + mt, e); } return(false); } // updateGoals
/** * Update/save Goals with Calculation * @return true if updated */ private Boolean UpdateCalculatedGoals() { if (!MEASURETYPE_Calculated.Equals(GetMeasureType())) { return(false); } MGoal[] goals = MGoal.GetMeasureGoals(GetCtx(), GetPA_Measure_ID()); for (int i = 0; i < goals.Length; i++) { MGoal goal = goals[i]; // Find Role MRole role = null; if (goal.GetAD_Role_ID() != 0) { role = MRole.Get(GetCtx(), goal.GetAD_Role_ID()); } else if (goal.GetAD_User_ID() != 0) { MUser user = MUser.Get(GetCtx(), goal.GetAD_User_ID()); MRole[] roles = user.GetRoles(goal.GetAD_Org_ID()); if (roles.Length > 0) { role = roles[0]; } } if (role == null) { role = MRole.GetDefault(GetCtx(), false); // could result in wrong data } // MMeasureCalc mc = MMeasureCalc.Get(GetCtx(), GetPA_MeasureCalc_ID()); if (mc == null || mc.Get_ID() == 0 || mc.Get_ID() != GetPA_MeasureCalc_ID()) { log.Log(Level.SEVERE, "Not found PA_MeasureCalc_ID=" + GetPA_MeasureCalc_ID()); return(false); } Decimal?ManualActual = null; String sql = mc.GetSqlPI(goal.GetRestrictions(false), goal.GetMeasureScope(), GetMeasureDataType(), null, role); IDataReader idr = null; try // SQL statement could be wrong { idr = DataBase.DB.ExecuteReader(sql, null, null); if (idr.Read()) { ManualActual = Utility.Util.GetValueOfDecimal(idr[0]); } idr.Close(); } catch (Exception e) { if (idr != null) { idr.Close(); } log.Log(Level.SEVERE, sql, e); } // SQL may return no rows or null if (ManualActual == null) { ManualActual = Env.ZERO; log.Fine("No Value = " + sql); } goal.SetMeasureActual(ManualActual); goal.Save(); } return(true); }