using System; using System.Collections.Generic; using System.Linq; using System.Text; using Ease.Core; using System.Data; namespace HRM.BO { #region MonthlyWorkPlan public class MonthlyWorkPlan : AuditTrailBase { #region Constructor public MonthlyWorkPlan() { WorkDate = DateTime.MinValue; ShiftID = 0; HolidayID = 0; WorkPlanGroupID = 0; Type = EnumWorkPlanDayType.WorkingDay; } #endregion #region Properties #region ItemID private int? _employeeID; public int? EmployeeID { get { return _employeeID; } set { _employeeID = value; } } #endregion public int payrollTypeID { get; set; } public DateTime WorkDate { get; set; } public int ShiftID { get; set; } public int HolidayID { get; set; } public EnumWorkPlanDayType Type { get; set; } public int WorkPlanGroupID { get; set; } public int DaySerial { get; set; } public int NextDaySerial { get { if (this.WorkPlanGroup ==null) return 0; else if (this.WorkPlanGroup.Type == EnumWorkPlanGroup.Two_Days_Shift_1 || this.WorkPlanGroup.Type == EnumWorkPlanGroup.Two_Days_Shift_2) return DaySerial == 0 ? 0 : (DaySerial == 2 ? 1 : (DaySerial + 1)); else if (this.WorkPlanGroup.Type == EnumWorkPlanGroup.Three_Days_Shift_1 || this.WorkPlanGroup.Type == EnumWorkPlanGroup.Three_Days_Shift_2) return DaySerial == 0 ? 0 : (DaySerial == 3 ? 1 : (DaySerial + 1)); else return DaySerial == 0 ? 0 : (DaySerial == 7 ? 1 : (DaySerial + 1)); } } private Shift _shift; public Shift Shift { get { return _shift; } } private WorkPlanGroup _workPlanGroup; public WorkPlanGroup WorkPlanGroup { set { _workPlanGroup = value; } get { //if (_workPlanGroup == null && WorkPlanGroupID != null && !WorkPlanGroupID.IsUnassigned) //{ // _workPlanGroup = WorkPlanGroup.Get(WorkPlanGroupID); //} return _workPlanGroup; } } //#region Service Factory IMonthlyWorkPlanService : IMonthlyWorkPlanService //internal static IMonthlyWorkPlanService Service //{ // get { return Services.Factory.CreateService(typeof(IMonthlyWorkPlanService)); } //} //#endregion #endregion //#region Functions //public static ObjectsTemplate Get() //{ // #region Cache Header // ObjectsTemplate monthlyWorkPlans = _cache["Get"] as ObjectsTemplate; // if (monthlyWorkPlans != null) // return monthlyWorkPlans; // #endregion // try // { // monthlyWorkPlans = Service.Get(); // } // catch (ServiceException e) // { // throw new Exception(e.Message, e); // } // #region Cache Footer // _cache.Add(monthlyWorkPlans, "Get"); // #endregion // return monthlyWorkPlans; //} //public static ObjectsTemplate GetByPayrollTypeID(DateTime fromDate, DateTime toDate, int payrollTypeID) //{ // #region Cache Header // ObjectsTemplate monthlyWorkPlans = _cache["Get", fromDate, toDate] as ObjectsTemplate; // if (monthlyWorkPlans != null) // return monthlyWorkPlans; // #endregion // try // { // monthlyWorkPlans = Service.GetByPayrollTypeID(fromDate, toDate, payrollTypeID); // } // catch (ServiceException e) // { // throw new Exception(e.Message, e); // } // #region Cache Footer // _cache.Add(monthlyWorkPlans, "Get", fromDate, toDate); // #endregion // return monthlyWorkPlans; //} //public static MonthlyWorkPlan GetByEmpID(ID nEmpID, DateTime assDate, EnumWorkPlanGroup type) //{ // MonthlyWorkPlan oMonthlyWorkPlan = null; // #region Cache Header // oMonthlyWorkPlan = (MonthlyWorkPlan)_cache["GetByEmpID", nEmpID, assDate, type]; // if (oMonthlyWorkPlan != null) // return oMonthlyWorkPlan; // #endregion // oMonthlyWorkPlan = MonthlyWorkPlan.Service.GetByEmpID(nEmpID, assDate, type); // #region Cache Footer // _cache.Add(oMonthlyWorkPlan, "GetByEmpID", nEmpID, assDate, type); // #endregion // return oMonthlyWorkPlan; //} //public static ObjectsTemplate GetByDateAndPayrollType(DateTime attnDate, int payrollTypeID) //{ // #region Cache Header // ObjectsTemplate monthlyWorkPlans = _cache["Get", attnDate] as ObjectsTemplate; // if (monthlyWorkPlans != null) // return monthlyWorkPlans; // #endregion // try // { // monthlyWorkPlans = Service.GetByDateAndPayrollType(attnDate, payrollTypeID); // } // catch (ServiceException e) // { // throw new Exception(e.Message, e); // } // #region Cache Footer // _cache.Add(monthlyWorkPlans, "Get", attnDate); // #endregion // return monthlyWorkPlans; //} //public static MonthlyWorkPlan GetByEmpID(ID nEmpID, DateTime workDate) //{ // MonthlyWorkPlan oMonthlyWorkPlan = null; // #region Cache Header // oMonthlyWorkPlan = (MonthlyWorkPlan)_cache["GetByEmpID", nEmpID, workDate]; // if (oMonthlyWorkPlan != null) // return oMonthlyWorkPlan; // #endregion // oMonthlyWorkPlan = MonthlyWorkPlan.Service.GetByEmpID(nEmpID, workDate); // #region Cache Footer // _cache.Add(oMonthlyWorkPlan, "GetByEmpID", nEmpID, workDate); // #endregion // return oMonthlyWorkPlan; //} //public static ObjectsTemplate Get(DateTime fromDate, DateTime toDate) //{ // #region Cache Header // ObjectsTemplate monthlyWorkPlans = _cache["Get", fromDate, toDate] as ObjectsTemplate; // if (monthlyWorkPlans != null) // return monthlyWorkPlans; // #endregion // try // { // monthlyWorkPlans = Service.Get(fromDate, toDate); // } // catch (ServiceException e) // { // throw new Exception(e.Message, e); // } // #region Cache Footer // _cache.Add(monthlyWorkPlans, "Get", fromDate, toDate); // #endregion // return monthlyWorkPlans; //} //public static ObjectsTemplate GetMonthlyDataByEmp(DateTime fromDate, DateTime toDate, EnumWorkPlanGroup type, ID nEmpID, int workPlanGroupID) //{ // #region Cache Header // ObjectsTemplate monthlyWorkPlans = _cache["GetMonthlyDataByEmp", fromDate, toDate, type, nEmpID, workPlanGroupID] as ObjectsTemplate; // if (monthlyWorkPlans != null) // return monthlyWorkPlans; // #endregion // try // { // monthlyWorkPlans = Service.GetMonthlyDataByEmp(fromDate, toDate, type, nEmpID, workPlanGroupID); // } // catch (ServiceException e) // { // throw new Exception(e.Message, e); // } // #region Cache Footer // _cache.Add(monthlyWorkPlans, "GetMonthlyDataByEmp"); // #endregion // return monthlyWorkPlans; //} //public static ObjectsTemplate GetMonthlyDataByEmp(DateTime dAssDate, EnumWorkPlanGroup type, ID nEmpID) //{ // #region Cache Header // ObjectsTemplate monthlyWorkPlans = _cache["GetMonthlyDataByEmp", dAssDate, type, nEmpID] as ObjectsTemplate; // if (monthlyWorkPlans != null) // return monthlyWorkPlans; // #endregion // try // { // monthlyWorkPlans = Service.GetMonthlyDataByEmp(dAssDate, type, nEmpID); // } // catch (ServiceException e) // { // throw new Exception(e.Message, e); // } // #region Cache Footer // _cache.Add(monthlyWorkPlans, "GetMonthlyDataByEmp"); // #endregion // return monthlyWorkPlans; //} //public static ObjectsTemplate GetByDate(DateTime attnDate) //{ // try // { // return Service.GetByDate(attnDate); // } // catch (ServiceException e) // { // throw new Exception(e.Message, e); // } //} //public static ObjectsTemplate Get(DateTime attnMonth) //{ // try // { // return Service.Get(attnMonth); // } // catch (ServiceException e) // { // throw new Exception(e.Message, e); // } //} //public static ObjectsTemplate GetByDateAndGroupID(DateTime assignDate, ID groupID) //{ // #region Cache Header // ObjectsTemplate monthlyWorkPlans = _cache["GetByDateAndGroupID", assignDate, groupID] as ObjectsTemplate; // if (monthlyWorkPlans != null) // return monthlyWorkPlans; // #endregion // try // { // monthlyWorkPlans = Service.GetByDateAndGroupID(assignDate, groupID); // } // catch (ServiceException e) // { // throw new Exception(e.Message, e); // } // #region Cache Footer // _cache.Add(monthlyWorkPlans, "GetByDateAndGroupID"); // #endregion // return monthlyWorkPlans; //} //public static DateTime GetLastSavedWorkDate() //{ // return Service.GetLastSavedWorkDate(); //} //public void Save(ObjectsTemplate oMWPlans) //{ // foreach (MonthlyWorkPlan oMWPlan in oMWPlans) // { // oMWPlan.SetAuditTrailProperties(); // } // MonthlyWorkPlan.Service.Save(oMWPlans); //} //public void Delete(DateTime fromDate) //{ // MonthlyWorkPlan.Service.Delete(fromDate); //} //public void Delete(DateTime assignDate, string empIds) //{ // MonthlyWorkPlan.Service.Delete(assignDate, empIds); //} //public void Delete(DateTime dFromDate, DateTime dToDate) //{ // MonthlyWorkPlan.Service.Delete(dFromDate, dToDate); //} //public static bool IsExist(DateTime dAssDate, ID groupID) //{ // return MonthlyWorkPlan.Service.IsExist(dAssDate, groupID); //} //public static MonthlyWorkPlan GetPlanwithEmployee(DateTime EffectDate, ID employeeid, ObjectsTemplate plans, ObjectsTemplate MworkPlans, ObjectsTemplate temporaryShiftEmps) //{ // MonthlyWorkPlan dPlan = null; // if (temporaryShiftEmps == null) // { // EmployeeWorkPlanSetup workGroup = plans.FirstOrDefault(x => x.EmployeeID.Integer == employeeid.Integer); // if (workGroup != null) // { // dPlan = MworkPlans.FirstOrDefault(x => x.WorkPlanGroupID.Integer == workGroup.WorkPlanGroupID.Integer && x.WorkDate == EffectDate); // if (dPlan != null) // dPlan.EmployeeID = employeeid.Integer; // } // } // else // { // ActingResponsibilitySetup tempShift = temporaryShiftEmps.FirstOrDefault(x => x.EmployeeID.Integer == employeeid.Integer && x.GradeID == null); // if (tempShift != null) // { // dPlan = MworkPlans.FirstOrDefault(x => x.WorkPlanGroupID.Integer == tempShift.WorkPlanGroupID.Integer && x.WorkDate == EffectDate); // dPlan.EmployeeID = employeeid.Integer; // } // } // return dPlan; //} //#endregion } #endregion //#region IMonthlyWorkPlan Service public interface IMonthlyWorkPlanService { List Get(DateTime attnMonth, int payrollTypeID); List Get(DateTime fromDate, DateTime toDate, int payrollTypeID); List GetByDateAndGroupID(DateTime dAssDate, int groupID); List GetByDate(DateTime attnDate,int payrollTypeID); DateTime GetLastSavedWorkDate(int payrollTypeID); void Save(List oMonthlyWPlans); void UpdateShiftAndRoster(MonthlyWorkPlan mplan); void Delete(DateTime fromDate, DateTime toDate, int payrollTypeID); void DeleteOnward(DateTime fromMonth, int payrollTypeID); bool IsExist(DateTime dAssDate, int groupID); List RefreshMonthlyWorkplan(DateTime monthFromDate, DateTime monthToDate, int payrollTypeID); List updateWorkPlan(MonthlyWorkPlan mplan); //List GetMonthlyDataByEmp(DateTime fromDate, DateTime toDate, EnumWorkPlanGroup type, ID nEmpID, int workPlanGroupID); //List GetMonthlyDataByEmp(DateTime dAssDate, EnumWorkPlanGroup type, int nEmpID); //void Delete(DateTime assignDate, string empIds); //void Delete(DateTime fromDate, DateTime toDate); //MonthlyWorkPlan GetByEmpID(int nEmpID, DateTime assDate, EnumWorkPlanGroup type); //MonthlyWorkPlan GetByEmpID(int nEmpID, DateTime workDate); //List GetByDateAndPayrollType(DateTime attnDate, int payrollTypeID); //List GetByPayrollTypeID(DateTime fromDate, DateTime toDate, int payrollTypeID); } //#endregion }