Пример #1
0
        public List <Hre_CardHistoryEntity> GetCardCodeByProfile(List <Hre_CardHistoryEntity> listCardHistory,
                                                                 Hre_ProfileEntity profile, DateTime from, DateTime to)
        {
            List <Hre_CardHistoryEntity> lstCardCode = new List <Hre_CardHistoryEntity>();

            if (profile != null)
            {
                var listCardHistoryByProfile = listCardHistory.Where(his => his.ProfileID == profile.ID &&
                                                                     his.DateEffect <= to).OrderByDescending(his => his.DateEffect).ToList();

                //Chay tu ngay hieu luc lon nhat den ngay hieu luc nho nhat
                foreach (var card in listCardHistoryByProfile)
                {
                    if (card.DateEffect <= from)
                    {
                        lstCardCode.Add(card);
                        break;
                    }
                    else
                    {
                        lstCardCode.Add(card);
                    }
                }
            }

            return(lstCardCode);
        }
Пример #2
0
        public Hre_WorkHistoryModel Post([Bind] Hre_WorkHistoryModel model)
        {
            #region Validate
            BaseService BaseService   = new BaseService();
            string      status        = string.Empty;
            string      message       = string.Empty;
            var         checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData <Hre_WorkHistoryModel>(model, "Hre_WorkHistory", ref message);
            if (!checkValidate)
            {
                model.ActionStatus = message;
                return(model);
            }
            #endregion
            var WorkHistoryServices  = new Hre_WorkHistoryServices();
            var SalaryClassServices  = new Cat_SalaryClassServices();
            var OrgStructureServices = new Cat_OrgStructureServices();
            var JobTitleServices     = new Cat_JobTitleServices();
            var PositionServices     = new Cat_PositionServices();
            var WorkHistoryOld       = BaseService.GetData <Hre_WorkHistoryEntity>(Common.DotNetToOracle(model.ProfileID.ToString()), ConstantSql.hrm_hr_sp_get_WorkHistoryByProfileId, UserLogin, ref status).OrderByDescending(s => s.DateEffective).FirstOrDefault();
            if (WorkHistoryOld != null)
            {
                model.SalaryClassNameOld = WorkHistoryOld.SalaryClassName;
                model.JobTitleOld        = WorkHistoryOld.JobTitleName;
                model.PositionOld        = WorkHistoryOld.PositionName;
                model.OrgStructureOldID  = WorkHistoryOld.OrganizationStructureID;
                model.WorkLocationOld    = WorkHistoryOld.WorkLocation;
            }

            if (model.SalaryClassID != null)
            {
                var abilityTitleBySalaryClass = BaseService.GetData <Cat_AbilityTileEntity>(Common.DotNetToOracle(model.SalaryClassID.ToString()), ConstantSql.hrm_cat_sp_get_AbilityTileBySalaryClassId, UserLogin, ref status).FirstOrDefault();
                if (abilityTitleBySalaryClass != null)
                {
                    model.AbilityTileID = abilityTitleBySalaryClass.ID;
                }
            }
            // Son.Vo - 20140107 - Xử lý cập nhật ngược lại bảng profile
            if (model.Status == WorkHistoryStatus.E_APPROVED.ToString() && model.DateEffective != null && model.DateEffective <= DateTime.Now.Date)
            {
                Hre_ProfileServices profileServices = new Hre_ProfileServices();
                Hre_ProfileEntity   profile         = BaseService.GetData <Hre_ProfileEntity>(Common.DotNetToOracle(model.ProfileID.ToString()), ConstantSql.hrm_hr_sp_get_ProfileById, UserLogin, ref status).FirstOrDefault();
                if (profile != null)
                {
                    profile.OrgStructureID = model.OrganizationStructureID;
                    profile.JobTitleID     = model.JobTitleID;
                    profile.PositionID     = model.PositionID;
                    profile.DateOfEffect   = model.DateEffective;
                    profile.LaborType      = model.LaborType;
                    profile.CostCentreID   = model.CostCentreID;
                    profile.FormType       = model.FormType;
                    profile.EmpTypeID      = model.EmployeeTypeID;
                    profile.WorkingPlace   = model.WorkLocation;
                    profile.AbilityTileID  = model.AbilityTileID;
                    profileServices.Edit(profile);
                }
            }

            ActionService service = new ActionService(UserLogin);
            return(service.UpdateOrCreate <Hre_WorkHistoryEntity, Hre_WorkHistoryModel>(model));
        }
Пример #3
0
        public Hre_ProfileModel Post([Bind] Hre_ProfileModel model)
        {
            string status = string.Empty;

            if (model != null)
            {
                ActionService service     = new ActionService(UserLogin);
                BaseService   BaseService = new BaseService();

                if (!string.IsNullOrWhiteSpace(model.CodeAttendance))
                {
                    model.CodeAttendance = model.CodeAttendance.TrimAll();
                }

                #region Validate

                string message = string.Empty;

                var checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData <Hre_ProfileModel>(model, "Hre_Profile", ref message);
                if (!checkValidate)
                {
                    model.ActionStatus = message;
                    return(model);
                }
                if (model.DateOfEffectOld != null)
                {
                    checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData <Hre_ProfileModel>(model, "Hre_ProfileCheckDateOfEffect", ref message);
                    if (!checkValidate)
                    {
                        model.ActionStatus = message;
                        return(model);
                    }
                }
                #endregion

                #region Xử lý cập nhật AbilityTitle khi chọn rank

                if (model.SalaryClassID != null)
                {
                    var abilityTitleBySalaryClass = BaseService.GetData <Cat_AbilityTileEntity>(Common.DotNetToOracle(model.SalaryClassID.ToString()), ConstantSql.hrm_cat_sp_get_AbilityTileBySalaryClassId, UserLogin, ref status).FirstOrDefault();
                    if (abilityTitleBySalaryClass != null)
                    {
                        model.AbilityTileID = abilityTitleBySalaryClass.ID;
                    }
                }

                #endregion

                #region Xử Lý Lưu field DateOfBirth
                var dateOfBirth = string.Empty;
                if (model.DayOfBirth == 00 && model.MonthOfBirth == 00)
                {
                    model.ActionStatus = "ErrorDateOfBirth";
                    return(model);
                }
                if (model.DayOfBirth == null && model.MonthOfBirth == null && model.YearOfBirth == null)
                {
                    dateOfBirth = string.Empty;
                }
                else
                {
                    if (model.DayOfBirth == null)
                    {
                        model.DayOfBirth = DateTime.Now.Day;
                    }
                    if (model.MonthOfBirth == null)
                    {
                        model.MonthOfBirth = DateTime.Now.Month;
                    }
                    if (model.YearOfBirth == null)
                    {
                        model.ActionStatus = "ErrorDateOfBirth";
                        return(model);
                    }
                }


                if (model.DayOfBirth >= 0 || model.MonthOfBirth >= 0 || model.YearOfBirth >= 0)
                {
                    if (model.DayOfBirth == 30 && model.MonthOfBirth == 2)
                    {
                        model.ActionStatus = "ErrorDateOfBirth";
                        return(model);
                    }
                    if (model.DayOfBirth == 31 && model.MonthOfBirth == 2)
                    {
                        model.ActionStatus = "ErrorDateOfBirth";
                        return(model);
                    }
                    if (model.DayOfBirth > 31 || model.MonthOfBirth > 12)
                    {
                        model.ActionStatus = "ErrorDateOfBirth";
                        return(model);
                    }
                    dateOfBirth = model.MonthOfBirth + "/" + model.DayOfBirth + "/" + model.YearOfBirth;
                }

                model.DateOfBirth = string.IsNullOrEmpty(dateOfBirth) ? (DateTime?)null : DateTime.Parse(dateOfBirth);
                #endregion
                Hre_ProfileModel HreProfile = new Hre_ProfileModel();
                if (model.ID != Guid.Empty)
                {
                    HreProfile = GetById(model.ID);
                }
                if (HreProfile != null && (model.ID == HreProfile.ID) && model.ActionStatus != "1")
                {
                    string[] listFieldName = new[] { "JobTitleID", "PositionID", "EmpTypeID", "DateOfEffect", "CostCentreID", "OrgStructureID", "WorkPlaceID", "SupervisorID" };
                    foreach (var item in listFieldName)
                    {
                        var value1 = model.GetPropertyValue(item);
                        var value2 = HreProfile.GetPropertyValue(item);
                        if ((value1 != null && value2 != null) && (value1.ToString() != value2.ToString()))
                        {
                            model.SetPropertyValue(Constant.ActionStatus, NotificationType.Change.ToString());
                            return(model);
                        }
                    }
                    if (HreProfile.ProfileName != model.ProfileName)
                    {
                        if (model.ProfileName.Contains(' '))
                        {
                            model.FirstName  = model.ProfileName.Substring(model.ProfileName.LastIndexOf(' ') + 1);
                            model.NameFamily = model.ProfileName.Substring(0, model.ProfileName.LastIndexOf(' '));
                        }
                        else
                        {
                            model.FirstName = model.ProfileName;
                        }
                    }
                }
                if (model.ActionStatus == "1" || model.ActionStatus == "Success" || string.IsNullOrEmpty(model.ActionStatus))
                {
                    var serviceAddress = new Hre_AddressServices();
                    var serviceProfile = new Hre_ProfileServices();
                    var profileEntity  = new Hre_ProfileEntity();
                    if (model.ID != Guid.Empty)
                    {
                        profileEntity = serviceProfile.GetData <Hre_ProfileEntity>(Common.DotNetToOracle(model.ID.ToString()), ConstantSql.hrm_hr_sp_get_ProfileById, UserLogin, ref status).FirstOrDefault();
                    }

                    #region Xử lý lưu CardCode
                    Hre_CardHistoryServices cardservices        = new Hre_CardHistoryServices();
                    Hre_WorkHistoryServices workHistoryservices = new Hre_WorkHistoryServices();

                    if (profileEntity != null && model.CodeAttendance != null && model.DateApplyAttendanceCode != null && (model.CodeAttendance != profileEntity.CodeAttendance ||
                                                                                                                           model.DateApplyAttendanceCode != profileEntity.DateApplyAttendanceCode))
                    {
                        // Chỉ thay đổi mã chấm công
                        if (model.DateApplyAttendanceCode == profileEntity.DateApplyAttendanceCode && model.CodeAttendance != profileEntity.CodeAttendance)
                        {
                            Hre_CardHistoryEntity history = cardservices.GetData <Hre_CardHistoryEntity>(Common.DotNetToOracle(model.ID.ToString()), ConstantSql.hrm_hr_sp_get_CardHistoryByProfileId, UserLogin, ref status).OrderByDescending(s => s.DateEffect).FirstOrDefault();
                            if (history != null)
                            {
                                history.CardCode = model.CodeAttendance;
                                cardservices.Edit(history);
                            }
                            else
                            {
                                history            = new Hre_CardHistoryEntity();
                                history.ProfileID  = model.ID;
                                history.CardCode   = model.CodeAttendance;
                                history.DateEffect = model.DateApplyAttendanceCode;
                                cardservices.Add(history);
                            }
                        }
                        // Chỉ thay đổi Ngày áp dụng mã chấm công

                        else if (model.CodeAttendance == profileEntity.CodeAttendance && model.DateApplyAttendanceCode != profileEntity.DateApplyAttendanceCode)
                        {
                            if (model.DateApplyAttendanceCode < profileEntity.DateApplyAttendanceCode)
                            {
                                model.StatusVerify = "Invalid";
                                return(model);
                            }
                            Hre_CardHistoryEntity history = cardservices.GetData <Hre_CardHistoryEntity>(Common.DotNetToOracle(model.ID.ToString()), ConstantSql.hrm_hr_sp_get_CardHistoryByProfileId, UserLogin, ref status).OrderByDescending(s => s.DateEffect).FirstOrDefault();
                            if (history != null)
                            {
                                history.DateEffect = model.DateApplyAttendanceCode;
                                cardservices.Edit(history);
                            }
                            else
                            {
                                history            = new Hre_CardHistoryEntity();
                                history.ProfileID  = model.ID;
                                history.CardCode   = model.CodeAttendance;
                                history.DateEffect = model.DateApplyAttendanceCode;
                                cardservices.Add(history);
                            }
                        }
                    }
                    // Tạo mới NV hoặc thay đổi cả 2( mã chấm công + ngày hiệu lực)
                    Hre_CardHistoryEntity cardhistory = null;
                    if (model != null && model.ID == Guid.Empty || (model != null && profileEntity != null && model.CodeAttendance != profileEntity.CodeAttendance &&
                                                                    model.DateApplyAttendanceCode != profileEntity.DateApplyAttendanceCode))
                    {
                        cardhistory            = new Hre_CardHistoryEntity();
                        cardhistory.ProfileID  = model.ID;
                        cardhistory.CardCode   = model.CodeAttendance;
                        cardhistory.DateEffect = model.DateApplyAttendanceCode;
                    }
                    #endregion

                    #region Xử lý lưu quá trình công tác
                    Hre_WorkHistoryEntity workHistory = null;
                    if (model != null && (model.JobTitleID != profileEntity.JobTitleID || model.PositionID != profileEntity.PositionID || model.EmpTypeID != profileEntity.EmpTypeID ||
                                          (model.DateOfEffect != null && profileEntity.DateOfEffect != null &&
                                           model.DateOfEffect.Value.ToString() != profileEntity.DateOfEffect.Value.ToString()) ||
                                          model.CostCentreID != profileEntity.CostCentreID || model.SupervisorID != profileEntity.SupervisorID ||
                                          model.OrgStructureID != profileEntity.OrgStructureID || model.WorkPlaceID != profileEntity.WorkPlaceID))
                    {
                        workHistory = new Hre_WorkHistoryEntity();
                        var orgService       = new Cat_OrgStructureServices();
                        var jobtitleService  = new Cat_JobTitleServices();
                        var postitionService = new Cat_PositionServices();
                        var workPlaceService = new Cat_WorkPlaceServices();

                        workHistory.CostCentreID            = model.CostCentreID;
                        workHistory.OrganizationStructureID = model.OrgStructureID;
                        workHistory.PositionID    = model.PositionID;
                        workHistory.JobTitleID    = model.JobTitleID;
                        workHistory.SalaryClassID = model.SalaryClassID;
                        workHistory.CostSourceID  = model.CostSourceID;
                        workHistory.AbilityTileID = model.AbilityTileID;
                        if (profileEntity != null)
                        {
                            var orgStructureOld = new Cat_OrgStructureEntity();
                            if (profileEntity.OrgStructureID != null && profileEntity.OrgStructureID != Guid.Empty)
                            {
                                orgStructureOld = orgService.GetData <Cat_OrgStructureEntity>(profileEntity.OrgStructureID, ConstantSql.hrm_cat_sp_get_OrgStructureById, UserLogin, ref status).FirstOrDefault();
                            }
                            var jobtitleOld = new Cat_JobTitleEntity();
                            if (profileEntity.JobTitleID != null && profileEntity.JobTitleID != Guid.Empty)
                            {
                                jobtitleOld = jobtitleService.GetData <Cat_JobTitleEntity>(profileEntity.JobTitleID, ConstantSql.hrm_cat_sp_get_HDTJobTypeById, UserLogin, ref status).FirstOrDefault();
                            }
                            var postitionOld = new Cat_PositionEntity();
                            if (profileEntity.PositionID != null && profileEntity.PositionID != Guid.Empty)
                            {
                                postitionOld = postitionService.GetData <Cat_PositionEntity>(profileEntity.PositionID, ConstantSql.hrm_cat_sp_get_PositionById, UserLogin, ref status).FirstOrDefault();
                            }
                            var workPlace = new Cat_WorkPlaceEntity();
                            if (model.WorkPlaceID != null && model.WorkPlaceID != Guid.Empty)
                            {
                                workPlace = workPlaceService.GetData <Cat_WorkPlaceEntity>(model.WorkPlaceID, ConstantSql.hrm_cat_sp_get_WorkPlaceById, UserLogin, ref status).FirstOrDefault();
                            }
                            var workPlaceOld = new Cat_WorkPlaceEntity();
                            if (profileEntity.WorkPlaceID != null && profileEntity.WorkPlaceID != Guid.Empty)
                            {
                                workPlaceOld = workPlaceService.GetData <Cat_WorkPlaceEntity>(profileEntity.WorkPlaceID, ConstantSql.hrm_cat_sp_get_WorkPlaceById, UserLogin, ref status).FirstOrDefault();
                            }
                            workHistory.OrgOld          = orgStructureOld != null ? orgStructureOld.OrgStructureName : "";
                            workHistory.JobTitleOld     = jobtitleOld != null ? jobtitleOld.JobTitleName : "";
                            workHistory.PositionOld     = postitionOld != null ? postitionOld.PositionName : "";
                            workHistory.WorkLocation    = workPlace != null ? workPlace.WorkPlaceName : "";
                            workHistory.WorkLocationOld = workPlaceOld != null ? workPlaceOld.WorkPlaceName : "";
                        }
                        if (workHistory.ID == Guid.Empty)
                        {
                            if (model.DateOfEffect != null)
                            {
                                workHistory.DateEffective = model.DateOfEffect.Value;
                            }
                            else
                            {
                                workHistory.DateEffective = DateTime.Now;
                            }
                        }

                        if (model.DateQuit != null && (profileEntity == null || profileEntity.DateQuit != model.DateQuit))
                        {
                            workHistory.DateEffective = model.DateQuit.Value;
                        }
                    }

                    #region Ngày hiệu lực phải <= ngày hiện tại thì mới cập nhật lại quá trình công tác
                    if (model.DateOfEffect > DateTime.Now && profileEntity != null && profileEntity.DateOfEffect != null)
                    {
                        model.DateOfEffect     = profileEntity.DateOfEffect;
                        model.OrgStructureID   = profileEntity.OrgStructureID;
                        model.ShopID           = profileEntity.ShopID;
                        model.JobTitleID       = profileEntity.JobTitleID;
                        model.PositionID       = profileEntity.PositionID;
                        model.SupervisorID     = profileEntity.SupervisorID;
                        model.HighSupervisorID = profileEntity.HighSupervisorID;
                        model.IsHeadDept       = profileEntity.IsHeadDept;
                        model.EmpTypeID        = profileEntity.EmpTypeID;
                        model.LaborType        = profileEntity.LaborType;
                        model.SikillLevel      = profileEntity.SikillLevel;
                        model.PayrollGroupID   = profileEntity.PayrollGroupID;
                        model.SalaryClassID    = profileEntity.SalaryClassID;
                        model.CostCentreID     = profileEntity.CostCentreID;
                        model.LocationCode     = profileEntity.LocationCode;
                        model.WorkPlaceID      = profileEntity.WorkPlaceID;
                    }
                    #endregion

                    #endregion

                    var profileModel = service.UpdateOrCreate <Hre_ProfileEntity, Hre_ProfileModel>(model);

                    if (cardhistory != null && profileModel != null)
                    {
                        cardhistory.ProfileID = profileModel.ID;
                        cardservices.Add(cardhistory);
                    }

                    if (workHistory != null && profileModel != null)
                    {
                        workHistory.EmployeeTypeID = profileModel.EmpTypeID;
                        workHistory.ProfileID      = profileModel.ID;
                        workHistoryservices.Add(workHistory);
                    }
                }
            }

            //Xóa cache lưu lại của cây phòng ban
            HttpContext.Current.Cache.Remove("List_OrgStructureTreeView");
            HttpContext.Current.Cache.Remove("List_OrgStructureTreeViewSumProfile");

            return(model);
        }
Пример #4
0
        //[TestMethod]
        public void ExportData()
        {
            using (var context = new VnrHrmDataContext())
            {
                #region Cat_Export
                List <Cat_Export> listExport = new List <Cat_Export>();
                Cat_Export        _export    = new Cat_Export()
                {
                    Id               = 1,
                    ExportName       = "Test Export",
                    ExportCode       = "Test",
                    ScreenName       = "Test Screen",
                    ObjectName       = "Hre_Profile",
                    IsReadOnly       = true,
                    IsProtected      = true,
                    SheetIndex       = 1,
                    StartColumnIndex = 1,
                    StartRowIndex    = 2,
                    TemplateFile     = "Test Template File",
                    IsGroup          = true
                };
                listExport.Add(_export);
                #endregion

                #region Cat_ExportItem
                List <Cat_ExportItem> listExportItem     = new List <Cat_ExportItem>();
                Cat_ExportItem        _exportItemEntity1 = new Cat_ExportItem()
                {
                    ExportID   = 1,
                    DataField  = "ProfileName",
                    ExcelField = "B"
                };
                Cat_ExportItem _exportItemEntity2 = new Cat_ExportItem()
                {
                    ExportID   = 1,
                    DataField  = "CodeEmp",
                    ExcelField = "C"
                };
                Cat_ExportItem _exportItemEntity3 = new Cat_ExportItem()
                {
                    ExportID   = 1,
                    DataField  = "DateHire",
                    ExcelField = "D"
                };
                listExportItem.Add(_exportItemEntity1);
                listExportItem.Add(_exportItemEntity2);
                listExportItem.Add(_exportItemEntity3);
                #endregion

                context.Cat_ExportItem.Add(_exportItemEntity1);
                context.Cat_ExportItem.Add(_exportItemEntity2);
                context.Cat_ExportItem.Add(_exportItemEntity3);
                context.Cat_Export.Add(_export);
                context.SaveChanges();
            }

            string passwordwrite = "123";
            string passwordread  = "123";

            string filename     = "D:\\New Microsoft Excel Worksheet.xls";
            string templatePath = "D:\\Template";

            #region Datasource
            List <Hre_ProfileEntity> listdataProfile = new List <Hre_ProfileEntity>();
            Hre_ProfileEntity        _Profile1       = new Hre_ProfileEntity()
            {
                ProfileName = "Name1",
                CodeEmp     = "001",
                DateHire    = DateTime.Now
            };
            Hre_ProfileEntity _Profile2 = new Hre_ProfileEntity()
            {
                ProfileName = "Name2",
                CodeEmp     = "002",
                DateHire    = DateTime.Now
            };
            listdataProfile.Add(_Profile1);
            listdataProfile.Add(_Profile2);
            #endregion

            ExportService service = new ExportService();
            service.ExportByTemplate(1, filename, passwordwrite, passwordread, templatePath, null, listdataProfile);
            Process.Start(filename);
        }
Пример #5
0
        List <Cat_DayOff> GetListDayOffPerProfile(List <Att_LeaveDay> lstLeaveDayHoliday, Hre_ProfileEntity profile, List <Cat_DayOff> lstDayOff, string E_HOLIDAY_HLD)
        {
            //string strCat_DayOff = CachObjects.ListCat_DayOff;
            //if (Cache[strCat_DayOff] == null)
            //    SecurityService.CacheBaseCat_Holiday();

            List <Att_LeaveDay> lstLeaveDayHolidayTemp = lstLeaveDayHoliday.Where(att => att.ProfileID == profile.ID).ToList();
            List <Cat_DayOff>   lstDayOffPerProfile    = new List <Cat_DayOff>();

            // lstDayOffPerProfile = SecurityService.CacheBaseCat_Holiday();

            #region Clone danh sach ngay nghi

            foreach (Cat_DayOff dayoff in lstDayOff)
            {
                lstDayOffPerProfile.Add(new Cat_DayOff()
                {
                    ID      = dayoff.ID,
                    DateOff = dayoff.DateOff,
                    Type    = dayoff.Type//Ngày nghỉ ngày thành ngày nghỉ Holiday
                });
            }

            #endregion

            if (lstLeaveDayHolidayTemp.Count() > 0)
            {
                foreach (Att_LeaveDay att in lstLeaveDayHolidayTemp)
                {
                    for (DateTime idx = att.DateStart.Date; idx <= att.DateEnd.Date; idx = idx.AddDays(1))
                    {
                        List <Cat_DayOff> lstDayofftemp = lstDayOffPerProfile.Where(da => att.DateStart.Date >= da.DateOff.Date &&
                                                                                    att.DateEnd.Date <= da.DateOff.Date).ToList();
                        if (lstDayofftemp.Count() == 0)//Danh sách ngày nghỉ mỗi người chưa có ngày này --Trung.Le
                        {
                            lstDayOffPerProfile.Add(new Cat_DayOff()
                            {
                                DateOff = idx,
                                Type    = E_HOLIDAY_HLD//Ngày nghỉ ngày thành ngày nghỉ Holiday
                            });
                        }
                        else//Danh sách ngày nghỉ mỗi người đã có ngày này --Trung.Le
                        {
                            lstDayofftemp[0].Type = E_HOLIDAY_HLD;//Chỉnh ngày nghỉ ngày thành ngày nghỉ Holiday
                        }
                    }
                }
            }

            return(lstDayOffPerProfile);
        }
        private List <Att_AnnualDetail> AnalyzeAnnualSickPerProfile(Hre_ProfileEntity Profile, List <Cat_GradeAttendance> lstGradeCfg, List <Att_Grade> lstGrade,
                                                                    DateTime BeginYear, DateTime EndYear, List <Att_LeaveDay> lstLeaveSick, List <Att_AnnualDetail> lstAnnualDetailInDB, Att_AnnualLeave AnnualLeave,
                                                                    List <Att_Roster> lstRosterInYear, List <Att_RosterGroup> lstRosterGroup, List <Hre_WorkHistory> lstWorkHistory, List <Cat_DayOff> lstDayOff,
                                                                    bool IsFrom1To31, List <Cat_Shift> shifts)
        {
            List <Att_AnnualDetail> lstResult            = new List <Att_AnnualDetail>();
            double            leaveBeginYearToMonth      = 0;
            double            leaveBeginYearToMonth_Init = 0;
            string            E_ROSTERGROUP       = RosterType.E_ROSTERGROUP.ToString();
            List <Att_Roster> lstRoster_byProfile = lstRosterInYear.Where(m => m.ProfileID == Profile.ID && m.Type != E_ROSTERGROUP).ToList();
            List <Att_Roster> lstRosterTypeGroup  = lstRosterInYear.Where(m => m.ProfileID == Profile.ID && m.Type == E_ROSTERGROUP).ToList();

            for (DateTime Month = BeginYear; Month <= EndYear; Month = Month.AddMonths(1))
            {
                var gradeByProfileByTime = lstGrade.Where(m => m.ProfileID == Profile.ID && m.MonthStart <= Month).OrderByDescending(m => m.MonthStart).FirstOrDefault();
                if (gradeByProfileByTime == null)
                {
                    continue;
                }
                var GradeCfg = lstGradeCfg.Where(m => m.ID == gradeByProfileByTime.GradeAttendanceID).FirstOrDefault();
                if (GradeCfg == null)
                {
                    continue;
                }

                DateTime BeginMonth = Month;
                DateTime EndMonth   = BeginMonth.AddMonths(1).AddMinutes(-1);
                if (!IsFrom1To31)
                {
                    Att_AttendanceServices.GetRangeMaxMinGrade(new List <Cat_GradeAttendance>()
                    {
                        GradeCfg
                    }, Month, out BeginMonth, out EndMonth);
                }
                double Availale     = AnnualLeave == null ? 0 : AnnualLeave.InitSickValue;
                double LeaveInMonth = 0;
                List <Att_LeaveDay> lstSickInMonth = lstLeaveSick.Where(m => m.ProfileID == Profile.ID && m.DateStart <= EndMonth && m.DateEnd >= BeginMonth).ToList();

                var listRosterEntity = lstRoster_byProfile.Select(d => new Att_RosterEntity
                {
                    ID              = d.ID,
                    ProfileID       = d.ProfileID,
                    RosterGroupName = d.RosterGroupName,
                    Type            = d.Type,
                    Status          = d.Status,
                    DateEnd         = d.DateEnd,
                    DateStart       = d.DateStart,
                    MonShiftID      = d.MonShiftID,
                    TueShiftID      = d.TueShiftID,
                    WedShiftID      = d.WedShiftID,
                    ThuShiftID      = d.ThuShiftID,
                    FriShiftID      = d.FriShiftID,
                    SatShiftID      = d.SatShiftID,
                    SunShiftID      = d.SunShiftID,
                    MonShift2ID     = d.MonShiftID,
                    TueShift2ID     = d.TueShift2ID,
                    WedShift2ID     = d.WedShift2ID,
                    ThuShift2ID     = d.ThuShift2ID,
                    FriShift2ID     = d.FriShift2ID,
                    SatShift2ID     = d.SatShift2ID,
                    SunShift2ID     = d.SunShift2ID
                }).ToList();

                var listRosterGroupEntity = lstRosterGroup.Select(d => new Att_RosterGroupEntity
                {
                    ID              = d.ID,
                    DateEnd         = d.DateEnd,
                    DateStart       = d.DateStart,
                    MonShiftID      = d.MonShiftID,
                    TueShiftID      = d.TueShiftID,
                    WedShiftID      = d.WedShiftID,
                    ThuShiftID      = d.ThuShiftID,
                    FriShiftID      = d.FriShiftID,
                    SatShiftID      = d.SatShiftID,
                    SunShiftID      = d.SunShiftID,
                    RosterGroupName = d.RosterGroupName
                }).ToList();

                foreach (var item in lstSickInMonth)
                {
                    if (item.DateStart >= BeginMonth && item.DateEnd <= EndMonth)
                    {
                        //Chi cần lấy TotalDuration hoặc lấy giờ rồi lấy ca
                        if (item.DurationType == LeaveDayDurationType.E_FULLSHIFT.ToString())
                        {
                            LeaveInMonth += item.TotalDuration ?? 0;
                        }
                        else
                        {
                            //Lấy ra ca làm việc
                            DateTime DateBeginLeave = item.DateStart.Date;
                            DateTime DateEndLeave   = item.DateEnd.Date;

                            Dictionary <DateTime, Cat_Shift> dicShift = Att_AttendanceLib.GetDailyShifts(Profile != null ? Profile.ID : Guid.Empty, DateBeginLeave, DateEndLeave, listRosterEntity, listRosterGroupEntity, shifts);

                            if (dicShift != null && dicShift.ContainsKey(DateBeginLeave))
                            {
                                Cat_Shift shift = dicShift[DateBeginLeave];
                                if (shift != null)
                                {
                                    double HourWorkday = 8;
                                    if (shift.WorkHours != null && shift.WorkHours != 0)
                                    {
                                        HourWorkday = shift.WorkHours ?? 8;
                                    }
                                    LeaveInMonth += item.Duration / HourWorkday;
                                }
                            }
                        }
                    }
                    else
                    {
                        DateTime DateBegin = BeginMonth > item.DateStart ? BeginMonth : item.DateStart;
                        DateTime DateEnd   = EndMonth < item.DateEnd ? BeginMonth : item.DateEnd;
                        Dictionary <DateTime, Cat_Shift> dicShift = Att_AttendanceLib.GetDailyShifts(Profile != null ? Profile.ID : Guid.Empty, DateBegin, DateEnd, listRosterEntity, listRosterGroupEntity, shifts);
                        for (DateTime dateCheck = DateBegin; dateCheck <= DateEnd; dateCheck = dateCheck.AddDays(1))
                        {
                            if (Att_WorkDayHelper.IsWorkDay(dateCheck, GradeCfg, dicShift, lstDayOff) && !lstDayOff.Any(m => m.DateOff == dateCheck))
                            {
                                LeaveInMonth++;
                            }
                        }
                    }
                }
                Att_AnnualDetail AnnualDetail = lstAnnualDetailInDB.Where(m => m.ProfileID == Profile.ID && m.MonthYear == Month).FirstOrDefault();
                if (AnnualDetail == null)
                {
                    AnnualDetail = new Att_AnnualDetail();
                }
                if (Profile.DateQuit != null)
                {
                    DateTime MonthQuit = Profile.DateQuit.Value.Day >= 15 ? Profile.DateQuit.Value.AddMonths(1) : Profile.DateQuit.Value;
                    MonthQuit = new DateTime(MonthQuit.Year, MonthQuit.Month, 1);
                    if (Month >= MonthQuit)
                    {
                        AnnualDetail.IsDelete = true;
                    }
                }
                AnnualDetail.Available        = Availale;
                AnnualDetail.InitAvailable    = AnnualLeave == null ? 0 : AnnualLeave.InitSickValue;
                AnnualDetail.ProfileID        = Profile.ID;
                AnnualDetail.Year             = BeginYear.Year;
                AnnualDetail.MonthYear        = Month;
                AnnualDetail.MonthBeginInYear = MonthStartAnl; //todo: Phần tử này để trong cấu hình chung
                if (AnnualLeave != null && AnnualLeave.MonthResetAnlOfBeforeYear != null)
                {
                    AnnualDetail.MonthResetInitAvailable = AnnualLeave.MonthResetAnlOfBeforeYear.Value;//todo: MonthReset Này để trong chế độ lương
                }
                else
                {
                    AnnualDetail.MonthResetInitAvailable = 12;//todo: MonthReset Này để trong chế độ lương
                }
                AnnualDetail.MonthStartProfile = AnnualLeave == null ? 1 : AnnualLeave.MonthStart;
                if (AnnualDetail.MonthResetInitAvailable != null && AnnualDetail.MonthResetInitAvailable != 12 && AnnualDetail.Year != null)
                {
                    DateTime MonthReset = new DateTime(AnnualDetail.Year.Value, AnnualDetail.MonthResetInitAvailable.Value, 1);
                    AnnualDetail.IsHaveResetInitAvailable = true;
                    if (Month <= MonthReset) //Trong những tháng có
                    {
                        double delta = leaveBeginYearToMonth_Init + LeaveInMonth - AnnualDetail.InitAvailable.Value;
                        if (delta > 0)
                        {
                            AnnualDetail.TotalLeaveBefFromInitAvailable = leaveBeginYearToMonth_Init;
                            AnnualDetail.LeaveInMonthFromInitAvailable  = LeaveInMonth - delta;
                            AnnualDetail.LeaveInMonth   = delta;
                            AnnualDetail.TotalLeaveBef  = leaveBeginYearToMonth;
                            leaveBeginYearToMonth      += delta;
                            leaveBeginYearToMonth_Init += LeaveInMonth - delta;
                        }
                        else
                        {
                            AnnualDetail.TotalLeaveBefFromInitAvailable = leaveBeginYearToMonth_Init;
                            AnnualDetail.LeaveInMonthFromInitAvailable  = LeaveInMonth;
                            AnnualDetail.TotalLeaveBef  = leaveBeginYearToMonth;
                            AnnualDetail.LeaveInMonth   = 0;
                            leaveBeginYearToMonth_Init += LeaveInMonth;
                        }
                    }
                    else //sau những tháng kho có
                    {
                        AnnualDetail.InitAvailable = 0;
                        AnnualDetail.TotalLeaveBef = leaveBeginYearToMonth;
                        AnnualDetail.LeaveInMonth  = LeaveInMonth;
                        leaveBeginYearToMonth     += LeaveInMonth;
                    }
                }
                else //Bình thường
                {
                    AnnualDetail.IsHaveResetInitAvailable = false;
                    AnnualDetail.TotalLeaveBef            = leaveBeginYearToMonth;
                    AnnualDetail.LeaveInMonth             = LeaveInMonth;
                    leaveBeginYearToMonth += LeaveInMonth;
                }
                double remain = (AnnualDetail.Available ?? 0) + (AnnualDetail.InitAvailable ?? 0) - (AnnualDetail.TotalLeaveBefFromInitAvailable ?? 0) - (AnnualDetail.LeaveInMonthFromInitAvailable ?? 0) - (AnnualDetail.TotalLeaveBef ?? 0) - (AnnualDetail.LeaveInMonth ?? 0);
                AnnualDetail.Remain = remain;
                AnnualDetail.Type   = AnnualLeaveDetailType.E_SICK_LEAVE.ToString();
                lstResult.Add(AnnualDetail);
            }
            return(lstResult);
        }
Пример #7
0
        /// <summary>
        /// [Hieu.Van] Tồng hợp dữ liệu ăn
        /// </summary>
        /// <param name="request"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        //[HttpPost]
        public ActionResult GetLaundryRecordSummary([DataSourceRequest] DataSourceRequest request, Lau_LaundryRecordSearchModel model)
        {
            Lau_LaundryRecordServices LauService = new Lau_LaundryRecordServices();
            var baseService    = new BaseService();
            var Actionservices = new ActionService(UserLogin);

            #region xử lý dateStart - dateEnd
            DateTime dateStart = DateTime.Now;
            DateTime dateEnd   = DateTime.Now;
            if (model.DateFrom != null)
            {
                dateStart = model.DateFrom.Value;
            }
            if (model.DateTo != null)
            {
                dateEnd = model.DateTo.Value;
            }
            #endregion

            #region xử lý lấy lstProfileIds theo OrgStructureID
            List <Hre_ProfileEntity> lstProfileIDs = new List <Hre_ProfileEntity>();
            string        status = string.Empty;
            List <object> lstObj = new List <object>();
            lstObj.Add(model.OrgStructureID);
            lstObj.Add(null);
            lstObj.Add(null);
            List <Hre_ProfileEntity> _temp       = new List <Hre_ProfileEntity>();
            Hre_ProfileEntity        t           = new Hre_ProfileEntity();
            List <Hre_ProfileEntity> _profileIDs = new List <Hre_ProfileEntity>();
            var baseServices = new ActionService(UserLogin);
            if (model.ProfileIDs != null)
            {
                var lst = model.ProfileIDs.Split(',');
                foreach (var item in lst)
                {
                    t = new Hre_ProfileEntity();
                    Guid _Id = new Guid(item);
                    t.ID = _Id;
                    _temp.Add(t);
                }



                if (model.OrgStructureID != null)
                {
                    lstProfileIDs = Actionservices.GetData <Hre_ProfileEntity>(lstObj, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrg, ref status).ToList();
                    _profileIDs   = lstProfileIDs.Where(m => !_temp.Contains(m)).ToList();
                    lstProfileIDs.AddRange(_profileIDs);
                }
                else
                {
                    lstProfileIDs = _temp;
                }
            }
            else
            {
                lstProfileIDs = Actionservices.GetData <Hre_ProfileEntity>(lstObj, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrg, ref status).ToList();
            }
            #endregion

            // Hàm xử lý tổng hợp
            var result = LauService.GetLaundryRecordSummary(model.LineID, model.LockerID, model.MarkerID, dateStart, dateEnd, lstProfileIDs, UserLogin).ToList().Translate <Lau_LaundryRecordModel>();
            if (result != null)
            {
                var submit = ConstantDisplay.HRM_Enum_Submit.TranslateString();
                var auto   = ConstantDisplay.HRM_Enum_Auto.TranslateString();
                result.Where(s => s.Status == LaundryRecordStatus.E_SUBMIT.ToString()).Select(s => s.Status = submit).ToList();
                result.Where(s => s.Type == LaundryRecordType.E_AUTO.ToString()).Select(s => s.Type         = auto).ToList();
            }
            #region xử lý xuất áo cáo
            if (model.IsExport)
            {
                var fullPath = ExportService.Export(result, model.ValueFields.Split(','));
                return(Json(fullPath));
            }

            if (model.selectedIDs != null)
            {
                var         strSelect = model.selectedIDs.Split(',');
                List <Guid> lstSelect = new List <Guid>();
                foreach (var item in strSelect)
                {
                    lstSelect.Add(new Guid(item));
                }
                var resultSelect = result.Where(m => lstSelect.Contains(m.ID)).ToList();
                var fullPath     = ExportService.Export(resultSelect, model.ValueFields.Split(','));
                return(Json(fullPath));
            }
            #endregion

            request.Page = 1;
            var dataSourceResult = result.ToDataSourceResult(request);
            //dataSourceResult.Total = result.Count() <= 0 ? 0 : result.FirstOrDefault().TotalRow;
            return(Json(result.ToDataSourceResult(request)));
        }