コード例 #1
0
ファイル: Sal_HoldSalaryServices.cs プロジェクト: radtek/vnr
        public List <Sal_HoldSalaryEntity> ComputeHoldSalary(Guid?cutOffDurationID, Guid[] ProfileIDs, string orgStructureID, Guid TimeAnalyze, string userLoginName)
        {
            using (var context = new VnrHrmDataContext())
            {
                #region Get Data
                string status = string.Empty;
                List <Sal_HoldSalaryEntity> lstHoldSalaryEntity = new List <Sal_HoldSalaryEntity>();

                //ds kỳ công
                var cutOffServies = new Att_CutOffDurationServices();
                var lstObjCutOff  = new List <object>();
                lstObjCutOff.Add(null);
                lstObjCutOff.Add(1);
                lstObjCutOff.Add(int.MaxValue - 1);
                var lstCutOff = cutOffServies.GetData <Att_CutOffDurationEntity>(Common.DotNetToOracle(cutOffDurationID.Value.ToString()), ConstantSql.hrm_att_sp_get_CutOffDurationById, userLoginName, ref status).FirstOrDefault();

                //ds nv
                var           hrService = new Hre_ProfileServices();
                List <object> strOrgIDs = new List <object>();
                strOrgIDs.AddRange(new object[3]);
                strOrgIDs[0] = (object)orgStructureID;
                var lstProfile = hrService.GetData <Hre_ProfileEntity>(strOrgIDs, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrg, userLoginName, ref status);

                if (ProfileIDs != null)
                {
                    lstProfile = lstProfile.Where(s => ProfileIDs.Contains(s.ID)).ToList();
                }

                //ds ngày nghỉ
                var leaveDayServices = new Att_LeavedayServices();
                var lstObjLeaveDay   = new List <object>();
                lstObjLeaveDay.AddRange(new object[11]);
                lstObjLeaveDay[4]  = lstCutOff.DateStart;
                lstObjLeaveDay[5]  = lstCutOff.DateEnd;
                lstObjLeaveDay[9]  = 1;
                lstObjLeaveDay[10] = int.MaxValue - 1;
                var lstLeaveDay = leaveDayServices.GetData <Att_LeaveDayEntity>(lstObjLeaveDay, ConstantSql.hrm_att_sp_get_Leaveday, userLoginName, ref status);

                //ds loại ngày nghỉ
                var leavedayTypeServices = new Cat_LeaveDayTypeServices();
                var lstObjLeavedayType   = new List <object>();
                lstObjLeavedayType.Add(null);
                lstObjLeavedayType.Add(null);
                lstObjLeavedayType.Add(1);
                lstObjLeavedayType.Add(int.MaxValue - 1);
                var lstLeavedayType = leavedayTypeServices.GetData <Cat_LeaveDayTypeEntity>(lstObjLeavedayType, ConstantSql.hrm_cat_sp_get_LeaveDayType, userLoginName, ref status);

                lstObjLeavedayType = new List <object>();
                lstObjLeavedayType.Add(null);
                lstObjLeavedayType.Add(EnumDropDown.EntityType.E_CountAnalyzeHoldSalary.ToString());
                lstObjLeavedayType.Add(1);
                lstObjLeavedayType.Add(int.MaxValue - 1);
                var ListNameEntity = leavedayTypeServices.GetData <Cat_NameEntityEntity>(lstObjLeavedayType, ConstantSql.hrm_cat_sp_get_NameEntityByKPI, userLoginName, ref status);

                ////ds chế độ lương
                //var Sal_GradeServices = new Sal_GradeServices();
                //var lstObjSal_Grade = new List<object>();
                //lstObjSal_Grade.AddRange(new object[7]);
                //lstObjSal_Grade[3] = lstCutOff.DateStart;
                //lstObjSal_Grade[4] = lstCutOff.DateEnd;//sửa lại store lấy lên tất cả các grade mà ko có ngày kết thúc
                //lstObjSal_Grade[5] = 1;
                //lstObjSal_Grade[6] = int.MaxValue - 1;
                //var lstSal_Grade = Sal_GradeServices.GetData<Sal_GradeEntity>(lstObjSal_Grade, ConstantSql.hrm_sal_sp_get_Sal_Grade, ref status).ToList();

                Sys_AttOvertimePermitConfigServices Sys_Services = new Sys_AttOvertimePermitConfigServices();
                double DATECLOSE_SALARY = Sys_Services.GetConfigValue <double>(AppConfig.HRM_SAL_DATECLOSE_SALARY);

                foreach (var profile in lstProfile)
                {
                    Sal_HoldSalaryEntity entity = new Sal_HoldSalaryEntity();

                    entity.ProfileID        = profile.ID;
                    entity.CodeEmp          = profile.CodeEmp;
                    entity.ProfileName      = profile.ProfileName;
                    entity.CodeAttendance   = profile.CodeAttendance;
                    entity.EmployeeTypeName = profile.EmployeeTypeName;
                    entity.WorkPlaceName    = profile.WorkPlaceName;
                    entity.IDNo             = profile.IDNo;
                    entity.MonthSalary      = lstCutOff.MonthYear;
                    entity.TimeAnalyzeID    = TimeAnalyze;
                    entity.CatNameEntity    = ListNameEntity.FirstOrDefault(m => m.ID == TimeAnalyze) != null?ListNameEntity.FirstOrDefault(m => m.ID == TimeAnalyze).NameEntityName : "";

                    var lstLeavedayByProfileID = lstLeaveDay.Where(s => profile.ID == s.ProfileID).ToList();

                    #region NV Nghỉ việc trước ngày 18
                    if (profile.DateQuit != null)
                    {
                        if (profile.DateQuit.Value <= lstCutOff.DateEnd && profile.IsSettlement != true)
                        {
                            //if (profile.DateQuit.Value.Day <= 18)
                            //{
                            entity.Terminate = true;
                            lstHoldSalaryEntity.Add(entity);
                            continue;
                            //}
                        }
                    }
                    #endregion

                    #region kiểm tra nghỉ quá 12 ngày
                    if (lstLeavedayByProfileID.Count > 0)
                    {
                        var    lstLeavedayTypeBy12 = lstLeavedayType.Where(m => m.Code == "SP" || m.Code == "SC" || m.Code == "DSP" || m.Code == "DL" || m.Code == "M").ToList();
                        var    _tmp  = lstLeavedayByProfileID.Where(m => !lstLeavedayTypeBy12.Any(t => t.ID == m.LeaveDayTypeID)).ToList();
                        double count = 0;
                        foreach (var i in _tmp)
                        {
                            count += i.LeaveDays != null ? (double)i.LeaveDays : 0;
                        }
                        if (count >= 12)
                        {
                            entity.DayLeave = (int)count;
                            lstHoldSalaryEntity.Add(entity);
                            continue;
                        }
                    }
                    #endregion

                    #region trường hợp đăng ký thai sản trước ngày 18
                    if (lstLeavedayByProfileID.Count > 0)
                    {
                        var lstLeavedayTypeBy12 = lstLeavedayType.Where(m => m.Code == "M").ToList();
                        var _tmp = lstLeavedayByProfileID.FirstOrDefault(m => lstLeavedayTypeBy12.Any(t => t.ID == m.LeaveDayTypeID) && m.DateStart.Day < 18);
                        if (_tmp != null)
                        {
                            entity.IsLeaveM = true;
                            lstHoldSalaryEntity.Add(entity);
                            continue;
                        }
                    }
                    #endregion

                    #region Nghỉ liên tục 3 ngày
                    if (lstLeavedayByProfileID.Count > 0)
                    {
                        var lstLeavedayTypeBy3 = lstLeavedayType.Where(m => m.Code == "D").ToList();
                        //lấy ngày nghỉ theo loại ngày nghỉ D
                        var lstLeavedayByProfileID3 = lstLeavedayByProfileID.Where(m => lstLeavedayTypeBy3.Any(t => t.ID == m.LeaveDayTypeID)).ToList();

                        lstLeavedayByProfileID3 = lstLeavedayByProfileID3.Where(m => m.DateEnd.Day <= DATECLOSE_SALARY).ToList();
                        double count = 0;
                        //còn 1 bug đó là khi đăng ký 3 dòng  liền kế ngày nhau
                        foreach (var i in lstLeavedayByProfileID3)
                        {
                            count = i.LeaveDays != null ? (double)i.LeaveDays : 0;
                            if (count >= 3)
                            {
                                entity.IsLeaveContinuous = true;
                                break;
                            }
                        }
                        if (entity.IsLeaveContinuous != null && entity.IsLeaveContinuous == true)
                        {
                            lstHoldSalaryEntity.Add(entity);
                            continue;
                        }
                    }

                    #endregion
                }
                return(lstHoldSalaryEntity);

                #endregion
            }
        }
コード例 #2
0
        public Att_LeaveDayModel Post([Bind] Att_LeaveDayModel model)
        {
            string status  = "";
            string message = string.Empty;

            //truong hop edit 1 nhan vien
            if (model.ProfileID != Guid.Empty)
            {
                model.ProfileIds = model.ProfileID.ToString();
            }
            BaseService baseService   = new BaseService();
            List <Guid> lstProfileIDs = new List <Guid>();

            #region Xu ly lay lst nhan vien cuoi cung
            //xu ly chon nhan vien hay chon phong ban
            if (!string.IsNullOrEmpty(model.ProfileIds))
            {
                List <Guid> lstMulti = new List <Guid>();
                var         lst      = model.ProfileIds.Split(',');
                foreach (var item in lst)
                {
                    Guid _Id = new Guid(item);
                    lstMulti.Add(_Id);
                }
                lstProfileIDs = lstMulti;
            }
            else
            {
                if (model.strOrgStructureIDs == "")
                {
                    model.strOrgStructureIDs = null;
                }
                List <object> lstObj = new List <object>();
                lstObj.Add(model.strOrgStructureIDs);
                lstObj.Add(null);
                lstObj.Add(null);
                List <Hre_ProfileEntity> lstOrg = baseService.GetData <Hre_ProfileEntity>(lstObj, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrg, UserLogin, ref status).ToList();
                lstProfileIDs = lstOrg.Select(d => d.ID).ToList();
                //neu co loai tru
                if (!string.IsNullOrEmpty(model.ProfileIDsExclude) && lstProfileIDs.Count > 0)
                {
                    List <Guid> lstProfileIDsExclude = new List <Guid>();
                    var         lst = model.ProfileIDsExclude.Split(',');
                    foreach (var item in lst)
                    {
                        Guid _Id = new Guid(item);
                        lstProfileIDsExclude.Add(_Id);
                    }
                    lstProfileIDs = lstProfileIDs.Where(d => !lstProfileIDsExclude.Contains(d)).ToList();
                }
            }
            if (lstProfileIDs.Count() == 0)
            {
                message            = string.Format(ConstantMessages.FieldNotAllowNull.TranslateString(), ("ProfileID").TranslateString());
                model.ActionStatus = message;
                return(model);
            }
            #endregion
            if (model.HoursFrom != null)
            {
                model.DateStart = new DateTime(model.DateStart.Year, model.DateStart.Month, model.DateStart.Day, model.HoursFrom.Value.Hour, model.HoursFrom.Value.Minute, 0);
            }
            if (model.HoursTo != null)
            {
                model.DateEnd = new DateTime(model.DateStart.Year, model.DateStart.Month, model.DateStart.Day, model.HoursTo.Value.Hour, model.HoursTo.Value.Minute, 0);
            }
            #region Validate


            var checkValidate = true;
            if (model.IsPortal == true)
            {
                checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData <Att_LeaveDayModel>(model, "Att_LeaveDayPortal", ref message);
            }
            else
            {
                checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData <Att_LeaveDayModel>(model, "Att_LeaveDay", ref message);
            }
            if (!checkValidate)
            {
                model.ActionStatus = message;
                return(model);
            }
            if (model.LeaveDays == 0 && model.LeaveHours == 0)
            {
                model.ActionStatus = ConstantMessages.AccessDenied.TranslateString();
                return(model);
            }
            #endregion



            //TimeSpan ts = new TimeSpan(model.HoursFrom.Value.Hour, model.HoursFrom.Value.Minute, 0);
            //model.DateStart = model.DateStart + ts;


            if (model.DurationType != LeaveDayDurationType.E_FULLSHIFT.ToString())
            {
                if (model.HoursFrom.HasValue)
                {
                    model.DateStart = new DateTime(model.DateStart.Year, model.DateStart.Month, model.DateStart.Day, model.HoursFrom.Value.Hour, model.HoursFrom.Value.Minute, model.HoursFrom.Value.Second);
                }
                if (model.HoursTo.HasValue)
                {
                    model.DateEnd = new DateTime(model.DateEnd.Year, model.DateEnd.Month, model.DateEnd.Day, model.HoursTo.Value.Hour, model.HoursTo.Value.Minute, model.HoursTo.Value.Second);
                }

                if (model.DurationType == LeaveDayDurationType.E_FIRSTHALFSHIFT.ToString() || model.DurationType == LeaveDayDurationType.E_LASTHALFSHIFT.ToString())
                {
                    model.LeaveDays = 0.5;
                }
            }

            ActionService service   = new ActionService(UserLogin);
            List <object> lstobject = new List <object>();
            lstobject.AddRange(new object[11]);
            //lstobject[4] = DateTime.MinValue; //DateFrom
            //lstobject[5] = DateTime.MaxValue; //DateTo
            lstobject[9] = 1;
            //lstobject[10] = int.MaxValue;
            lstobject[10] = Int32.MaxValue - 1;

            string strMessages  = "";
            var    _catLeaveDay = new Att_LeavedayServices();
            List <Att_LeaveDayEntity> lstLeaveDayInDbUpdate = _catLeaveDay.GetData <Att_LeaveDayEntity>(lstobject, ConstantSql.hrm_att_sp_get_Leaveday, UserLogin, ref status);

            #region [Hien.Nguyen] - Kiểm tra trùng khi đăng kí cùng một ngày và cùng loại ngày nghỉ

            //if (lstLeaveDayInDbUpdate != null)
            //{
            //    if (model.ID == Guid.Empty)
            //    {
            //        if (lstLeaveDayInDbUpdate.Any(m => m.ProfileID == model.ProfileID && m.DateStart <= model.DateEnd && m.DateEnd >= model.DateStart && m.LeaveDayTypeID == model.LeaveDayTypeID))
            //        {
            //            model.SetPropertyValue(Constant.ActionStatus, NotificationType.Error + "," + strMessages + ConstantMessages.FieldDuplicate);
            //            return model;
            //        }
            //    }
            //    else
            //    {
            //        var leaveDay = _catLeaveDay.GetData<Att_LeaveDayEntity>(model.ID, ConstantSql.hrm_att_sp_get_LeaveDayById, ref status).FirstOrDefault();
            //        if (leaveDay != null)
            //        {
            //            if (leaveDay.LeaveDayTypeID != model.LeaveDayTypeID || leaveDay.DateStart != model.DateStart || leaveDay.DateEnd != model.DateEnd || leaveDay.ProfileID != model.ProfileID)
            //            {
            //                if (lstLeaveDayInDbUpdate.Any(m => m.ProfileID == model.ProfileID && m.DateStart <= model.DateEnd && m.DateEnd >= model.DateStart && m.LeaveDayTypeID == model.LeaveDayTypeID))
            //                {
            //                    model.SetPropertyValue(Constant.ActionStatus, NotificationType.Error + "," + strMessages + ConstantMessages.FieldDuplicate);
            //                    return model;
            //                }
            //            }
            //        }
            //    }
            //}

            #endregion

            #region Kiểm tra đăng ký trùng 1 ngày chỉ 1 loại ngày nghỉ nếu là Loại Toàn Ca, Còn lại thì 2 loại ngày nghỉ
            if (model.ID != Guid.Empty)//nếu là chỉnh sửa thì loại bỏ dòng đó ra khỏi list tổng
            {
                lstLeaveDayInDbUpdate = lstLeaveDayInDbUpdate.Where(m => m.ID != model.ID).ToList();
            }
            if (model.DurationType == LeaveDayDurationType.E_FULLSHIFT.ToString())//Toàn ca chỉ được dk 1 dòng
            {
                if (lstLeaveDayInDbUpdate.Any(m => lstProfileIDs.Contains(m.ProfileID) && m.DateStart <= model.DateEnd && m.DateEnd >= model.DateStart))
                {
                    //model.SetPropertyValue(Constant.ActionStatus, NotificationType.Error + "," + strMessages + ConstantMessages.FieldDuplicate);
                    model.SetPropertyValue(Constant.ActionStatus, NotificationType.Error + "," + string.Format(ConstantMessages.FieldDuplicate.TranslateString(), ConstantDisplay.HRM_Evaluation_Information.TranslateString()));
                    return(model);
                }
            }
            else//Ngược lại thì đk 2 dòng
            {
                if (lstLeaveDayInDbUpdate.Any(m => lstProfileIDs.Contains(m.ProfileID) && m.DateStart <= model.DateEnd && m.DateEnd >= model.DateStart && m.DurationType == LeaveDayDurationType.E_FULLSHIFT.ToString()))
                {
                    //  model.SetPropertyValue(Constant.ActionStatus, NotificationType.Error + "," + strMessages + ConstantMessages.FieldDuplicate);
                    model.SetPropertyValue(Constant.ActionStatus, NotificationType.Error + "," + string.Format(ConstantMessages.FieldDuplicate.TranslateString(), ConstantDisplay.HRM_Evaluation_Information.TranslateString()));
                    return(model);
                }
                else if (lstLeaveDayInDbUpdate.Where(m => lstProfileIDs.Contains(m.ProfileID) && m.DateStart <= model.DateEnd && m.DateEnd >= model.DateStart && m.DurationType != LeaveDayDurationType.E_FULLSHIFT.ToString()).Count() > 1)
                {
                    // model.SetPropertyValue(Constant.ActionStatus, NotificationType.Error + "," + strMessages + ConstantMessages.FieldDuplicate);
                    model.SetPropertyValue(Constant.ActionStatus, NotificationType.Error + "," + string.Format(ConstantMessages.FieldDuplicate.TranslateString(), ConstantDisplay.HRM_Evaluation_Information.TranslateString()));
                    return(model);
                }
            }


            #endregion

            #region Triet.Mai Kiểm tra vượt giới hạn cho 1 tháng
            //string[] ProfileArr = model.ProfileIds.Split(',');
            //List<Guid> lstProfileID = new List<Guid>();
            //foreach (var item in lstProfileIDs)
            //{
            //    Guid ProfileID = item;
            //    //Guid.TryParse(item, out ProfileID);
            //    if (ProfileID != Guid.Empty)
            //        lstProfileID.Add(ProfileID);
            //}
            var    LeaveDayEntity = model.CopyData <Att_LeaveDayEntity>();
            string Error          = (new Att_LeavedayServices()).ValidateOverDayInMonth(LeaveDayEntity, lstProfileIDs);
            if (Error != string.Empty)
            {
                model.SetPropertyValue(Constant.ActionStatus, Error);
                return(model);
            }
            #endregion

            List <Att_LeaveDayEntity>   lstSM     = new List <Att_LeaveDayEntity>();
            Att_ProcessApprovedServices smService = new Att_ProcessApprovedServices();

            if (!string.IsNullOrEmpty(model.ProfileIds))
            {
                //string[] arrProfileIds = model.ProfileIds.Split(',');
                strMessages = "";
                if (strMessages != "")
                {
                    // model.SetPropertyValue(Constant.ActionStatus, NotificationType.Error + "," + strMessages + ConstantMessages.FieldDuplicate);
                    model.SetPropertyValue(Constant.ActionStatus, NotificationType.Error + "," + string.Format(ConstantMessages.FieldDuplicate.TranslateString(), ConstantDisplay.HRM_Evaluation_Information.TranslateString()));
                    return(model);
                }
                else
                {
                    var leavedayTypeServices = new Cat_LeaveDayTypeServices();
                    var lstLeavedayType      = leavedayTypeServices.GetData <Cat_LeaveDayTypeEntity>(model.LeaveDayTypeID, ConstantSql.hrm_cat_sp_get_LeaveDayTypeById, UserLogin, ref status).FirstOrDefault();


                    if (lstProfileIDs.Count() == 1)
                    {
                        var guiId = lstProfileIDs[0];
                        Att_LeaveDayModel modelSave = model.CopyData <Att_LeaveDayModel>();
                        modelSave.ProfileID = guiId;
                        #region Kiểm tra Tổng Số Ngày Nghỉ
                        if (lstLeavedayType != null)
                        {
                            if (model.LeaveDays > lstLeavedayType.MaxPerTimes)
                            {
                                modelSave.ActionStatus = "ErrorTotalLeave";
                                return(modelSave);
                            }
                            if (model.LeaveDays > lstLeavedayType.MaxPerYear)
                            {
                                modelSave.ActionStatus = "ErrorTotalLeave";
                                return(modelSave);
                            }
                        }
                        #endregion

                        modelSave = service.UpdateOrCreate <Att_LeaveDayEntity, Att_LeaveDayModel>(modelSave);
                        if (modelSave.ActionStatus == NotificationType.Success.ToString())
                        {
                            lstSM.Add(modelSave.Copy <Att_LeaveDayEntity>());
                        }
                        smService.GetEmailToSend_LeaveDay(lstSM, UserLogin);
                        return(modelSave);
                    }

                    foreach (var ProfileId in lstProfileIDs)
                    {
                        var guiId = ProfileId;
                        Att_LeaveDayModel modelSave = model.CopyData <Att_LeaveDayModel>();
                        modelSave.ProfileID = guiId;

                        #region Kiểm tra Tổng Số Ngày Nghỉ
                        if (lstLeavedayType != null)
                        {
                            if (model.LeaveDays > lstLeavedayType.MaxPerTimes)
                            {
                                modelSave.ActionStatus = "ErrorTotalLeave";
                                return(modelSave);
                            }
                            if (model.LeaveDays > lstLeavedayType.MaxPerYear)
                            {
                                modelSave.ActionStatus = "ErrorTotalLeave";
                                return(modelSave);
                            }
                        }
                        #endregion

                        modelSave = service.UpdateOrCreate <Att_LeaveDayEntity, Att_LeaveDayModel>(modelSave);
                        if (modelSave.ActionStatus == NotificationType.Success.ToString())
                        {
                            lstSM.Add(modelSave.Copy <Att_LeaveDayEntity>());
                        }
                        else
                        {
                            smService.GetEmailToSend_LeaveDay(lstSM, UserLogin);
                            return(modelSave);
                        }
                    }
                }
                smService.GetEmailToSend_LeaveDay(lstSM, UserLogin);

                model.SetPropertyValue(Constant.ActionStatus, NotificationType.Success.ToString());
                return(model);
            }
            else
            {
                //Đã kiểm tra ở trên , nên không cần kt dưới này - [hien.nguyen]
                //if (lstLeaveDayInDbUpdate != null && lstLeaveDayInDbUpdate.Any(d => d.ID != model.ID && d.ProfileID == model.ProfileID && d.DateStart <= model.DateEnd && d.DateEnd >= model.DateStart))
                //{
                //    strMessages = lstLeaveDayInDbUpdate.Where(d => d.ProfileID == model.ProfileID).FirstOrDefault().ProfileName;
                //    model.SetPropertyValue(Constant.ActionStatus, NotificationType.Error + "," + strMessages + ConstantMessages.FieldDuplicate);
                //    return model;
                //}
                //else
                model = service.UpdateOrCreate <Att_LeaveDayEntity, Att_LeaveDayModel>(model);
                if (model.ActionStatus == NotificationType.Success.ToString())
                {
                    lstSM.Add(model.Copy <Att_LeaveDayEntity>());
                    smService.GetEmailToSend_LeaveDay(lstSM, UserLogin);
                }
                return(model);
            }
        }