using Ease.Core.Model; using System; using System.Collections.Generic; using System.Data; namespace HRM.BO { public class Objective : BasicBaseObject { #region Constructor public Objective() { this.Description = string.Empty; this.Title = string.Empty; this.Activities = string.Empty; this.MeasuresOfSuccess = string.Empty; this.Weightages = 0.0; this.ObjectiveDate = DateTime.Today; this.RagingDate = DateTime.Today; this.YEEmployeeComments = string.Empty; this.MYEmployeeComments = string.Empty; this.YELMComments = string.Empty; this.MYLMComments = string.Empty; this.LMRatingID = 0; this.MYLMAssessRating = EnumAssessment.None; this.MYAssessRating = EnumAssessment.None; this.ObjectiveStatus = EnumObjectiveStatus.No_Change; this.YEStatus = EnumObjectiveStatus.No_Change; this.MYStatus = EnumObjectiveStatus.No_Change; this.IsOldObjective = false; this.PriorityPercent = 0; this.ProgressStatus = 0.0; this.YESecondLMMark = 0; this.ObjectiveSettingRemarksLM = string.Empty; this.ObjectiveSettingRemarksLM2 = string.Empty; } #endregion #region Properties public int ObjectiveSetID { get; set; } public int GroupID { get; set; } public string Tier { get; set; } public int PMPYearID { get; set; } public int PayrollTypeID { get; set; } public string Title { get; set; } public string Description { get; set; } public string Activities { get; set; } public string MeasuresOfSuccess { get; set; } // target public string MeasuresOfSuccess2 { get; set; } // target public double Weightages { get; set; } // percentage public int EmployeeID { get; set; } public int EmployeeNodeID { get; set; } public DateTime ObjectiveDate { get; set; } public int LMID { get; set; } public int LMNodeID { get; set; } public int LMRatingID { get; set; } public double YEEmpMark { get; set; } public double YELMMark { get; set; } public double YESecondLMMark { get; set; } public double? YEAssessRating { get; set; } public double? YELMAssessRating { get; set; } public DateTime YEEmpMarkDate { get; set; } public DateTime YELMMarkDate { get; set; } public DateTime RagingDate { get; set; } public string MYEmployeeComments { get; set; } public string YEEmployeeComments { get; set; } public string MYLMComments { get; set; } public string YELMComments { get; set; } public string YESecondLMComments { get; set; } public EnumAssessment MYAssessRating { get; set; } public EnumAssessment MYLMAssessRating { get; set; } public string ObjComment { get; set; } public DateTime StartDate { get; set; } public DateTime EndDate { get; set; } public bool IsDraft { get; set; } public bool IsOldObjective { get; set; } public EnumObjectiveStatus ObjectiveStatus { get; set; } public EnumObjectiveStatus MYStatus { get; set; } public EnumObjectiveStatus YEStatus { get; set; } //#region Property DevelopmentPlans : DevelopmentPlan //private List _developmentPlans; //public List DevelopmentPlans //{ // get // { // if (_developmentPlans == null && !this.ID.IsUnassigned && this.ID.Integer > 0) // { // _developmentPlans = Service.GetDevelopmentPlans(this.ID); // } // return _developmentPlans; // } // set // { // _developmentPlans = value; // } //} //#endregion //#region Property LMObjectives : LMObjective //private List _lMObjectives; //public List LMObjectives //{ // get // { // if (_lMObjectives == null && !this.ID.IsUnassigned && this.ID.Integer > 0) // { // _lMObjectives = Service.GetLMObjectives(this.ID); // } // else if (_lMObjectives == null) // { // _lMObjectives = new List(); // } // return _lMObjectives; // } // set // { // _lMObjectives = value; // } //} //#endregion public List ObjectiveEmployees { get; set; } public List LMObjectives { get; set; } public List DevelopmentPlans { get; set; } //#region Property ObjectiveEmployeess : ObjectiveEmployees //private List _objectiveEmployees; //public List ObjectiveEmployees //{ // get // { // if (_objectiveEmployees == null && !this.ID.IsUnassigned && this.ID.Integer > 0) // { // _objectiveEmployees = Service.GetObjectiveEmployees(this.ID); // } // return _objectiveEmployees; // } // set // { // _objectiveEmployees = value; // } //} //#endregion public int ObjectiveType { get; set; } public double PriorityPercent { get; set; } public EnumObjectiveType KPIType { get; set; } public int MasterKpiId { get; set; } public double LMAchivementPercentage { get; set; } public double EmpAchivementPercentage { get; set; } public double EmpPARating { get; set; } public double LMPARating { get; set; } public string ObjSecondLMComment { get; set; } public string MYSecondLMComment { get; set; } public string ObjectiveSettingRemarksLM { get; set; } public string ObjectiveSettingRemarksLM2 { get; set; } public double ProgressStatus { get; set; } public List UnreadEmployeeMessage { get; set; } public List UnreadLMMessage { get; set; } public List Attachments { get; set; } /// /// Transient flag (not persisted on Objective itself). When true, Save/UpdateObjectiveStatus /// stage the change in ObjectiveHistory instead of applying it to this row immediately; /// the change only takes effect once the line manager approves it. /// public bool OutsideOfSettings { get; set; } #endregion #region Old //#region Function //#region Get All //public static List Get() //{ // return Objective.Service.Get(); //} //#endregion //#region Get By ID //public static Objective Get(int id) //{ // return Objective.Service.Get(id); //} //#endregion //#region Get By Employee ID //public static List GetByEmployeeID(int Empid, int PMPYID, bool IsDrafted) //{ // return Objective.Service.GetByEmployeeID(Empid, PMPYID, IsDrafted); //} //public static List GetLMObjs(int Empid, int PMPYID, int nLMID) //{ // return Objective.Service.GetLMObjs(Empid, PMPYID, nLMID); //} //public static List GetByEmployeeID(string sEmpids, int PMPYID, bool IsDrafted) //{ // return Objective.Service.GetByEmployeeID(sEmpids, PMPYID, IsDrafted); //} //public static List GetByPMPYearID(int id, string InEmpSQL) //{ // return Objective.Service.GetByPMPYearID(id, InEmpSQL); //} //public static List GetByStatus(EnumPMPStatus estatus, bool IsFinalized) //{ // return Objective.Service.GetByStatus(estatus, IsFinalized); //} //#endregion //#region Get Draft Objective //public static List GetObjectives(int id, int draft) //{ // return Objective.Service.GetObjectives(id, draft); //} //#endregion //#region Get By Line Manager ID //public static Objective GetByLMID(int id) //{ // return Objective.Service.GetByLMID(id); //} //#endregion //#region Get Line Manager Obj //public static Objective GetLineManager(int id) //{ // return Objective.Service.GetLineManager(id); //} //#endregion //#region Save //public static void Update(List objectives) //{ // //this.SetAuditTrailProperties(); // Objective.Service.Update(objectives); //} //public int Save() //{ // this.SetAuditTrailProperties(); // return Objective.Service.Save(this); //} //public static void Save(List items) //{ // foreach (Objective item in items) // { // item.SetAuditTrailProperties(); // } // Objective.Service.Save(items); //} //public static void SaveForUpload(List items) //{ // foreach (Objective item in items) // { // item.SetAuditTrailProperties(); // } // Objective.Service.SaveForUpload(items); //} //public static void SaveForSalesUpload(List items) //{ // foreach (Objective item in items) // { // item.SetAuditTrailProperties(); // } // Objective.Service.SaveForSalesUpload(items); //} ////public string Save2(List UpdateHistory) ////{ //// this.SetAuditTrailProperties(); //// return Objective.Service.Save2(this, UpdateHistory); ////} //#endregion //#region Delete //public void Delete() //{ // Objective.Service.Delete(this.ID); //} //public static void DeleteAllCompanyObj(int yearID) //{ // Objective.Service.DeleteAllCompanyObj(yearID); //} //#endregion //public static DataSet GetComObjAssignedEmpID(int PMPYearID) //{ // DataSet oDataSet = new DataSet(); // oDataSet = Objective.Service.GetComObjAssignedEmpID(PMPYearID); // return oDataSet; //} //public static DataSet GetEmpObjectiveData(int year) //{ // DataSet oDataSet = new DataSet(); // oDataSet = Objective.Service.GetEmpObjectiveData(year); // return oDataSet; //} //public static DataSet GetEmpFreezedObjectiveData() //{ // DataSet oDataSet = new DataSet(); // oDataSet = Objective.Service.GetEmpFreezedObjectiveData(); // return oDataSet; //} //public bool IsValid(out string errorMessage) //{ // errorMessage = string.Empty; // StringBuilder sb = new StringBuilder(); // bool isValid = true; // ValidationContext context = new ValidationContext(this); // var result = new List(); // isValid = isValid && Validator.TryValidateObject(this, context, result, true); // foreach (var item in result) // { // sb.Append(item.ErrorMessage + Environment.NewLine); // } // double availablePercent; // if(this.EmployeeID == null || this.EmployeeID.IsUnassigned) // { // isValid = isValid && false; // sb.Append("Please Select an Employee." + Environment.NewLine); // } // if (!IsValidPercent(out availablePercent)) // { // isValid = isValid && false; // sb.Append("Total percent cannot greater than assigned percent. Available percent= " + availablePercent+ "% " + Environment.NewLine); // } // errorMessage = sb.ToString().Trim(); // return isValid; //} //private bool IsValidPercent(out double availablePercent) //{ // bool sts = true; // availablePercent = 0; // if (this.PriorityPercent > 0 && this.PriorityPercent <= 100) // { // List _ObjectiveCategoryGrades = ObjectiveCategoryGrades.GetByPMPYear(this.PMPYearID); // Employee oEmp = Employee.Get(this.EmployeeID); // List _ObjectiveGrades = _ObjectiveCategoryGrades.Where(obj => obj.GradeID == oEmp.GradeID && obj.Percent > 0).ToList(); // ObjectiveCategoryGrades oObjectiveType = _ObjectiveGrades.FirstOrDefault(item => item.ObjectiveType == this.ObjectiveType); // double nValidPercent = 0; // if (oObjectiveType != null) // nValidPercent = oObjectiveType.Percent; // double nTotalPercent = Objective.GetByEmployeeID(this.EmployeeID, this.PMPYearID, false) // .Where(x => x.ObjectiveType == this.ObjectiveType) // .Sum(x => x.PriorityPercent); // availablePercent = nValidPercent - nTotalPercent; // if (nTotalPercent + this.PriorityPercent > nValidPercent) // { // //MessageBox.Show("Total percent cannot greater than assigned percent. Available percent= " + (nValidPercent - nTotalPercent).ToString(), "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); // sts = false; // } // } // return sts; //} //#endregion //#region Service Factory IObjective : IObjective //internal static IObjectiveService Service //{ // get { return Services.Factory.CreateService(typeof(IObjectiveService)); } //} //#endregion #endregion } #region IObjectiveService Service public interface IObjectiveService { Objective Get(int id); List GetByEmployeeID(int Empid, int PMPID); List GetByEmployeeID(int Empid, int PMPID, bool IsDrafted); List GetForValidation(int empId, int pmpYearId, int objectTypeId); List GetByEmployeeID(string Empids, int PMPID, bool IsDrafted); int Save(Objective item); void Save(List items); void Delete(int id); List GetDevelopmentPlans(int iD); List GetLMObjectives(int iD); List GetObjectiveEmployees(int iD); List GetByPMPYearID(int id, string InEmpSQL); List GetByPMPYear(int nPMPYearID, int nPayrollTypeID); void Update(List objectives); List GetLMObjs(int Empid, int PMPYID, int nLMID); DataSet GetComObjAssignedEmpID(int PMPYearID); void SaveForUpload(List items); void SaveForSalesUpload(List items); DataSet GetEmpObjectiveData(int year); DataSet GetEmpFreezedObjectiveData(); DataSet GetPmsDataEmployeeWise(int pmpYearId, string empIds); DataSet GetPmsLmGoalReport(int pmpYearId, int empId); DataSet GetPmsIndividualGoalData(int pmpYearId, int empId); void DeletebyObjectiveSetIDs(string objectiveSetID); void UpdateObjectiveStatus(Objective item); void UpdateObjectiveHistorySubmitStatus(ObjectiveSet item, bool isSubmitted); void RejectObjectiveHistory(ObjectiveSet item); DataTable GetObjectiveHistoryStatus(int objectiveSetId); DataTable GetObjectiveHistoryWeightage(int objectiveSetId); void DismissObjectiveHistory(int objectiveHistoryId); List GetObjectiveFromHistory(int objectiveSetId); DataTable GetObjectiveFromHistoryDT(int objectiveSetId); List GetObjectiveAttachments(int objectiveId); int InsertObjectiveAttachment(ObjectiveAttachment item); void DeleteObjectiveAttachmentByID(int id); ObjectiveAttachment GetObjectiveAttachmentFileData(int attachmentid); List GetObjectiveAttachmentsByHistoryID(int objectiveHistoryId); } #endregion #region EnumPMSStage public enum EnumPMSStage { KPISettingEmp = 1, KPISettingLM = 2, KPISettingSLM = 3, MidYearEmp = 4, MidYearLM = 5, YEndEmp = 6, YEndLM = 7, YESLM = 8 } #endregion #region ObjectiveAttachment public class ObjectiveAttachment : BasicBaseObject { public ObjectiveAttachment() { this.ObjectiveID = 0; this.FileName = string.Empty; this.EmployeeID = 0; this.FileData = null; this.UploadDate = DateTime.Today; this.PMSStage = EnumPMSStage.KPISettingEmp; this.ObjectiveHistoryID = null; } public int ObjectiveID { get; set; } public string FileName { get; set; } public int EmployeeID { get; set; } public byte[] FileData { get; set; } public string Filetype { get; set; } public DateTime UploadDate { get; set; } public EnumPMSStage PMSStage { get; set; } /// /// Set (ObjectiveID left at its default 0) while this attachment belongs to a KPI still /// staged in ObjectiveHistory (outside-of-settings add/edit awaiting LM decision). Cleared /// back to null and ObjectiveID populated once the LM approves the change; the row is deleted /// outright if the LM rejects it. See ObjectiveService.ApplyOutsideOfSettingsHistory / /// RejectObjectiveHistory. /// public int? ObjectiveHistoryID { get; set; } } #endregion }