Exemplo n.º 1
0
        public IEnumerable<Att_OvertimeModel> Post(Att_ComputeOvertimeModel model)
        {
            Att_WorkDayServices serviceWorkDay = new Att_WorkDayServices();
            var status = string.Empty;
            var lstWorkDay = serviceWorkDay.GetWorkDaysByInOut(model.DateFrom, model.DateTo);
            Cat_ShiftServices serviceShift = new Cat_ShiftServices();
            var lstShift = serviceShift.GetDataNotParam<Cat_ShiftEntity>(ConstantSql.hrm_cat_sp_get_Shift, UserLogin, ref status);

            //Cat_ShiftItemServices serviceShiftItem = new Cat_ShiftItemServices();
            //var lstShiftItem = serviceShiftItem.GetCatShiftItem();
            var lstShiftItem = new List<Cat_ShiftItemEntity>();
            Cat_DayOffServices servicesDayOff = new Cat_DayOffServices();
            var lstDayOff = servicesDayOff.GetAllUseEntity<Cat_DayOffEntity>(ref status).ToList();

            Cat_OvertimeTypeServices servicesOvertimeType = new Cat_OvertimeTypeServices();
            var lstOvertimeType = servicesOvertimeType.GetDataNotParam<Cat_OvertimeTypeEntity>(ConstantSql.hrm_cat_sp_get_OvertimeType, UserLogin, ref status);

            var Att_OvertimeInfoFillterAnalyze = new Att_OvertimeInfoFillterAnalyze()
            {
                isAllowGetAfterShift = model.isAllowGetAfterShift,
                isAllowGetBeforeShift = model.isAllowGetBeforeShift,
                isAllowGetInShift = model.isAllowGetInShift,
                isAllowGetOTOutterShift = model.isAllowGetOTOutterShift,
                isAllowGetTypeBaseOnActualDate = model.isAllowGetTypeBaseOnActualDate,
                isAllowGetTypeBaseOnBeginShift = model.isAllowGetTypeBaseOnBeginShift,
                isAllowGetTypeBaseOnEndShift = model.isAllowGetTypeBaseOnEndShift,
                MininumOvertimeHour = model.MininumOvertimeHour
            };

            var service = new Att_OvertimeServices();
            var result = service.AnalyzeOvertime(lstWorkDay, 
                                                lstShift, 
                                                lstShiftItem, 
                                                lstDayOff, 
                                                lstOvertimeType,
                                                Att_OvertimeInfoFillterAnalyze, UserLogin).ToList().Translate<Att_OvertimeModel>();
            return result;
        }
Exemplo n.º 2
0
        //[Test]
        public void NUnit_Overtime_Domain_AnalyzeOvertime()
        {
            #region listWorkDay
            List<Att_WorkDayEntity> listWorkDay = new List<Att_WorkDayEntity>();
            Att_WorkDayEntity _workDayEntity = new Att_WorkDayEntity()
            {
                ProfileID = 1,
                WorkDate = DateTime.Parse("01-09-14"),
                FirstInTime = DateTime.Parse("01-09-14 07:00:00"),
                LastOutTime = DateTime.Parse("02-09-14 07:00:00"),
                InTime1 = DateTime.Parse("01-09-14 07:00:00"),
                OutTime1 = DateTime.Parse("02-09-14 07:00:00"),
                ShiftID = 1,
                WorkDuration = (float)14.5
            };
            listWorkDay.Add(_workDayEntity); 
            #endregion

            #region listShift
            List<Cat_ShiftEntity> listShift = new List<Cat_ShiftEntity>();
            Cat_ShiftEntity _shiftEntity = new Cat_ShiftEntity()
            {
                Id = 1,
                ShiftName = "Ca Test",
                InTime = DateTime.Parse("01-09-14 07:00:00"),
                CoOut = 9.5,
                CoBreakIn = 4,
                CoBreakOut = 5.5,
                NightTimeStart = DateTime.Parse("01-09-14 21:00:00"),
                NightTimeEnd = DateTime.Parse("02-09-14 05:00:00")
            };
            listShift.Add(_shiftEntity); 
            #endregion

            #region listShiftItem
            List<Cat_ShiftItemEntity> listShiftItem = new List<Cat_ShiftItemEntity>();
            Cat_ShiftItemEntity _shiftItemEntity1 = new Cat_ShiftItemEntity()
            {
                ShiftItemName = "Giao Ca Sang",
                ShiftID = 1,
                CoFrom = 4,
                CoTo = 5.5
            };
            Cat_ShiftItemEntity _shiftItemEntity2 = new Cat_ShiftItemEntity()
            {
                ShiftItemName = "Giao Ca Toi",
                ShiftID = 1,
                CoFrom = 9.5,
                CoTo = 10
            };
            listShiftItem.Add(_shiftItemEntity1);
            listShiftItem.Add(_shiftItemEntity2);
            #endregion

            #region listDayOff
            List<Cat_DayOffEntity> listDayOff = new List<Cat_DayOffEntity>();
            Cat_DayOffEntity _DayOffEntity1 = new Cat_DayOffEntity()
            {
                DateOff = DateTime.Parse("02-09-14"),
            };
            listDayOff.Add(_DayOffEntity1);
            #endregion

            #region listOvertimeType
            List<Cat_OvertimeTypeEntity> listOvertimeType = new List<Cat_OvertimeTypeEntity>();
            Cat_OvertimeTypeEntity _OvertimeTypeEntity1 = new Cat_OvertimeTypeEntity()
            {
                OvertimeTypeName = "OT - 3.0",
                OvertimeTypeCode = "E_HOLIDAY",
                Rate = 3,
                TaxRate = 1,
            };
            Cat_OvertimeTypeEntity _OvertimeTypeEntity5 = new Cat_OvertimeTypeEntity()
            {
                OvertimeTypeName = "OT - 3.5",
                OvertimeTypeCode = "E_HOLIDAY_NIGHTSHIFT",
                Rate = 3.5,
                TaxRate = 1,
            };
            Cat_OvertimeTypeEntity _OvertimeTypeEntity2 = new Cat_OvertimeTypeEntity()
            {
                OvertimeTypeName = "OT - 2.0",
                OvertimeTypeCode = "E_WEEKEND",
                Rate = 1,
                TaxRate = 1,
            };

            Cat_OvertimeTypeEntity _OvertimeTypeEntity3 = new Cat_OvertimeTypeEntity()
            {
                OvertimeTypeName = "OT - 1.5",
                OvertimeTypeCode = "E_WORKDAY",
                Rate = 1.5,
                TaxRate = 1,
            };

            Cat_OvertimeTypeEntity _OvertimeTypeEntity4 = new Cat_OvertimeTypeEntity()
            {
                OvertimeTypeName = "OT - 2.0",
                OvertimeTypeCode = "E_WORKDAY_NIGHTSHIFT",
                Rate = 2,
                TaxRate = 1,
            };

            listOvertimeType.Add(_OvertimeTypeEntity1);
            listOvertimeType.Add(_OvertimeTypeEntity2);
            listOvertimeType.Add(_OvertimeTypeEntity3);
            listOvertimeType.Add(_OvertimeTypeEntity4);
            #endregion

            #region listOvertimeInfoFillterAnalyze
            Att_OvertimeInfoFillterAnalyze _OvertimeInfoFillterAnalyzeEntity = new Att_OvertimeInfoFillterAnalyze()
            {
                isAllowGetOTOutterShift               = true,
                isAllowGetBeforeShift                 = false,
                isAllowGetAfterShift                  = true,
                isAllowGetInShift                     = false,
                isAllowGetTypeBaseOnActualDate        = true,
                isAllowGetTypeBaseOnBeginShift        = true,
                isAllowGetTypeBaseOnEndShift          = false,
                isAllowGetNightShift = true,
                // cắt h qua đêm 12h khuya
                isBreakMiddleNight = true,
                MininumOvertimeHour                   = 0.5
            };
            #endregion

            Att_OvertimeServices service = new Att_OvertimeServices();
            List<Att_OvertimeEntity> listResult = service.AnalyzeOvertime(listWorkDay, listShift, listShiftItem, listDayOff, listOvertimeType, _OvertimeInfoFillterAnalyzeEntity);

        }
Exemplo n.º 3
0
        public DataTable LoadDataAnalyzeOvertime_DataLimit(string strOrgStructure, DateTime DateStart, DateTime DateEnd, List<Hre_ProfileEntity> lstProfile, List<string> lstTypeData, Att_OvertimeInfoFillterAnalyze _OvertimeInfoFillterAnalyzeEntity, string userLogin)
        {
            DataTable table = GetSchemaExportExcel();
            string status = string.Empty;

            DateStart = DateStart.Date;
            DateEnd = DateEnd.Date.AddDays(1).AddMilliseconds(-1);
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoAtt_WorkDay = new Att_WorkDayRepository(unitOfWork);
                var repoCat_Shift = new Cat_ShiftRepository(unitOfWork);
                var repoCat_ShiftItem = new Cat_ShiftItemRepository(unitOfWork);
                var repoCat_DayOff = new Cat_DayOffRepository(unitOfWork);
                var repoCat_OvertimeType = new Cat_OvertimeTypeRepository(unitOfWork);
                var repoCat_OrgStructure = new CustomBaseRepository<Cat_OrgStructure>(unitOfWork);
                var repoCat_OrgStructureType = new CustomBaseRepository<Cat_OrgStructureType>(unitOfWork);

                var orgTypes = repoCat_OrgStructureType.FindBy(s => s.IsDelete == null).ToList();
                var orgs = repoCat_OrgStructure.FindBy(s => s.IsDelete == null && s.Code != null).ToList();

                List<WorkdayCustom> lstWorkday = new List<WorkdayCustom>();
                List<Guid> lstProfileId = lstProfile.Select(s => s.ID).ToList();

                List<object> lst3ParamSE = new List<object>();
                lst3ParamSE.Add(strOrgStructure);
                lst3ParamSE.Add(DateStart);
                lst3ParamSE.Add(DateEnd);
                if (lstProfile.Count > 0 && strOrgStructure == null)
                {
                    var lstWD = repoAtt_WorkDay.FindBy(s => s.IsDelete == null && s.WorkDate >= DateStart && s.WorkDate <= DateEnd && lstProfileId.Contains(s.ProfileID)).ToList();
                    if (lstWD.Count > 0)
                    {
                        lstWorkday = lstWD.Translate<WorkdayCustom>();
                    }
                }
                else
                {
                    lstWorkday = GetData<WorkdayCustom>(lst3ParamSE, ConstantSql.hrm_att_getdata_Workday, userLogin, ref status).ToList();
                }
                //var lstWorkdayQuery = repoAtt_WorkDay.FindBy(m => m.IsDelete == null && m.WorkDate >= DateStart && m.WorkDate <= DateEnd);
                //if (lstProfileId.Count > 0)
                //{
                //    lstWorkdayQuery = lstWorkdayQuery.Where(m => lstProfileId.Contains(m.ProfileID));
                //}
                //lstWorkday = lstWorkdayQuery.ToList().Translate<Att_WorkdayEntity>();

                List<Cat_ShiftEntity> lstShift = repoCat_Shift
                    .FindBy(s => s.IsDelete == null)
                    .ToList()
                    .Translate<Cat_ShiftEntity>();
                List<Cat_ShiftItemEntity> lstShiftItem = repoCat_ShiftItem
                    .FindBy(s => s.IsDelete == null)
                    .ToList()
                    .Translate<Cat_ShiftItemEntity>();
                List<Cat_DayOffEntity> LstDayOff = repoCat_DayOff
                    .FindBy(m => m.IsDelete == null && m.DateOff >= DateStart && m.DateOff < DateEnd)
                    .ToList()
                    .Translate<Cat_DayOffEntity>();
                List<Cat_OvertimeTypeEntity> lstOvertimeType = repoCat_OvertimeType
                    .FindBy(s => s.IsDelete == null).ToList()
                    .Translate<Cat_OvertimeTypeEntity>();

                string E_CANCEL = OverTimeStatus.E_CANCEL.ToString();
                string E_REJECTED = OverTimeStatus.E_REJECTED.ToString();
                DateTime beforeDateStart = DateStart.Date.AddDays(-1);
                DateTime afterDateEnd = DateEnd.Date.AddDays(2).AddMinutes(-1);
                // string E_HOLIDAY_HLD = HolidayType.E_HOLIDAY_HLD.ToString();
                List<DateTime> lstHoliday = repoCat_DayOff
                    .FindBy(s => s.IsDelete == null)
                    .Select(m => m.DateOff).ToList<DateTime>();
                //lstWorkday = filterData_NonAllowOT_inGrade(lstWorkday);
                List<Att_OvertimeEntity> lstOvertimeCal = AnalyzeOvertime(lstWorkday, lstShift, lstShiftItem, LstDayOff, lstOvertimeType, _OvertimeInfoFillterAnalyzeEntity, userLogin);
                if (lstOvertimeCal.Count == 0)
                {
                    lstOvertimeCache = lstOvertimeCal;
                    return table;
                }
                OvertimePermitEntity overtimePermit = getOvertimePermit(userLogin);
                FilterNonOvertimeByGradeConfig(lstOvertimeCal);
                SetNonOT(lstOvertimeCal);
                SetStatusOvertimeOnWorkday(lstOvertimeCal);
                FilterOvertimeByMaxHourPerDay(lstOvertimeCal, overtimePermit, _OvertimeInfoFillterAnalyzeEntity.MaximumOvertimeHour);
                RoundOT(lstOvertimeCal, userLogin);
                FillterAllowOvertime(context, lstOvertimeCal, overtimePermit, lstWorkday);
                RoundOT(lstOvertimeCal, userLogin);
                lstOvertimeCal = lstOvertimeCal.Where(m => m.RegisterHours != null && m.RegisterHours > 0).ToList();
                SetStatusLeaveOnWorkday(lstOvertimeCal);//Set loại ngày nghỉ cho OT

                if (lstTypeData.Count > 0)
                {
                    Expression<Func<Att_OvertimeEntity, bool>> predicate = VnResource.Helper.Linq.PredicateBuilder.False<Att_OvertimeEntity>();
                    if (lstTypeData.Any(m => m == ComputeLeavedayType.E_DATA_LEAVE.ToString()))
                    {
                        Expression<Func<Att_OvertimeEntity, bool>> predicate1 = m => m.udLeaveTypeCode != null || m.udLeaveTypeCode2 != null;
                        predicate = predicate.Or(predicate1);
                        //lstOvertimeCal = lstOvertimeCal.Where(m => (m.udLeaveTypeCode == null || m.udLeaveTypeCode == string.Empty) && (m.udLeaveTypeCode2 == null || m.udLeaveTypeCode2 == string.Empty)).ToList();
                    }
                    if (lstTypeData.Any(m => m == ComputeLeavedayType.E_DATA_NON_LEAVE.ToString()))
                    {
                        Expression<Func<Att_OvertimeEntity, bool>> predicate2 = m => (m.udLeaveTypeCode == null || m.udLeaveTypeCode == string.Empty) && (m.udLeaveTypeCode2 == null || m.udLeaveTypeCode2 == string.Empty);
                        predicate = predicate.Or(predicate2);
                        //lstOvertimeCal = lstOvertimeCal.Where(m => m.udLeaveTypeCode != null || m.udLeaveTypeCode2 != null).ToList();
                    }
                    if (lstTypeData.Any(m => m == ComputeOvertimeType.E_DATA_OT.ToString()))
                    {
                        Expression<Func<Att_OvertimeEntity, bool>> predicate2 = m => m.udOvertimeStatus != null;
                        predicate = predicate.Or(predicate2);
                    }
                    if (lstTypeData.Any(m => m == ComputeOvertimeType.E_DATA_NON_OT.ToString()))
                    {
                        Expression<Func<Att_OvertimeEntity, bool>> predicate2 = m => m.udOvertimeStatus == null;
                        predicate = predicate.Or(predicate2);
                    }
                    lstOvertimeCal = lstOvertimeCal.AsQueryable().Where(predicate).ToList();
                }

                //lstOvertimeCal = lstOvertimeCal.OrderBy(m => m.WorkDate.Date).ThenBy(m => m.ProfileID).ToList();
                //lstOvertimeCache = lstOvertimeCal;
                //BindToGrid(lstOvertimeCache);
                lstOvertimeCal = lstOvertimeCal
                    .Where(m => m.udIsLimitHour == true || m.udIsLimitHourLv1 == true || m.udIsLimitHourLv2 == true)
                    .OrderBy(m => m.WorkDate.Date)
                    .ThenBy(m => m.ProfileID)
                    .ToList();

                //lstOvertimeCal.ForEach(s => s.IsValid = false);

                #region process return table

                foreach (var item in lstOvertimeCal)
                {
                    DataRow row = table.NewRow();
                    Guid? orgId = lstProfile.Where(s => s.ID == item.ProfileID).FirstOrDefault().OrgStructureID;
                    var org = orgs.FirstOrDefault(s => s.ID == orgId);
                    var orgBranch = LibraryService.GetNearestParent(orgId, OrgUnit.E_BRANCH, orgs, orgTypes);
                    var orgOrg = LibraryService.GetNearestParent(orgId, OrgUnit.E_DEPARTMENT, orgs, orgTypes);
                    var orgTeam = LibraryService.GetNearestParent(orgId, OrgUnit.E_TEAM, orgs, orgTypes);
                    var orgSection = LibraryService.GetNearestParent(orgId, OrgUnit.E_SECTION, orgs, orgTypes);
                    row[Att_OvertimeEntity.FieldNames.BranchCode] = orgBranch != null ? orgBranch.Code : string.Empty;
                    row[Att_OvertimeEntity.FieldNames.OrgStructureCode] = orgOrg != null ? orgOrg.Code : string.Empty;
                    row[Att_OvertimeEntity.FieldNames.TeamCode] = orgTeam != null ? orgTeam.Code : string.Empty;
                    row[Att_OvertimeEntity.FieldNames.SectionCode] = orgSection != null ? orgSection.Code : string.Empty;
                    row[Att_OvertimeEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty;
                    row[Att_OvertimeEntity.FieldNames.OrgName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                    row[Att_OvertimeEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
                    row[Att_OvertimeEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty;

                    row[Att_OvertimeEntity.FieldNames.WorkDate] = item.WorkDate;
                    row[Att_OvertimeEntity.FieldNames.InTime] = item.InTime;
                    row[Att_OvertimeEntity.FieldNames.OutTime] = item.OutTime;

                    if (item.udIsLimitHour == null || item.udIsLimitHour == false)
                    {
                        row[Att_OvertimeEntity.FieldNames.Valid] = "Level1";
                    }
                    else if (item.udIsLimitHourLv1 == null || item.udIsLimitHourLv1 == false)
                    {
                        row[Att_OvertimeEntity.FieldNames.Valid] = "Level2";
                    }
                    else if (item.udIsLimitHourLv2 == null || item.udIsLimitHourLv2 == false)
                    {
                        row[Att_OvertimeEntity.FieldNames.Valid] = "Level3";
                    }
                    else
                    {
                        row[Att_OvertimeEntity.FieldNames.Valid] = string.Empty;
                    }

                    if (item.OvertimeTypeID != Guid.Empty)
                    {
                        var OTType = lstOvertimeType.Where(s => s.ID == item.OvertimeTypeID).FirstOrDefault();
                        row[Att_OvertimeEntity.FieldNames.OvertimeTypeID] = item.OvertimeTypeID;
                        row[Att_OvertimeEntity.FieldNames.OvertimeTypeName] = OTType.OvertimeTypeName;

                        row[OTType.Code] = item.RegisterHours;
                        row[OTType.Code + "Confirm"] = item.ApproveHours ?? 0.0;
                    }
                    if (item.ShiftID != Guid.Empty)
                    {
                        var _shift = lstShift.Where(s => s.ID == item.ShiftID).FirstOrDefault();
                        row[Att_OvertimeEntity.FieldNames.ShiftID] = item.ShiftID;
                        row[Att_OvertimeEntity.FieldNames.ShiftName] = _shift.ShiftName;
                    }
                    if (item.ProfileID != Guid.Empty)
                    {
                        var temp = lstProfile.Where(s => s.ID == item.ProfileID).FirstOrDefault();
                        row[Att_OvertimeEntity.FieldNames.ProfileID] = item.ProfileID;
                        row[Att_OvertimeEntity.FieldNames.ProfileName] = temp.ProfileName;
                        row[Att_OvertimeEntity.FieldNames.CodeEmp] = temp.CodeEmp;
                        //row[Att_ReportDetailOvertimeEntity.FieldNames.OrgStructureName] = temp.OrgStructureName;
                    }
                    row[Att_OvertimeEntity.FieldNames.TotalRow] = lstOvertimeCal.Count;
                    row[Att_OvertimeEntity.FieldNames.DateExport] = DateTime.Now;
                    row[Att_OvertimeEntity.FieldNames.AnalyseHour] = item.AnalyseHour;
                    row[Att_OvertimeEntity.FieldNames.udHourByDate] = item.udHourByDate;
                    row[Att_OvertimeEntity.FieldNames.udHourByWeek] = item.udHourByWeek;
                    row[Att_OvertimeEntity.FieldNames.udHourByMonth] = item.udHourByMonth;
                    row[Att_OvertimeEntity.FieldNames.udHourByYear] = item.udHourByYear;
                    row[Att_OvertimeEntity.FieldNames.udLeaveTypeCode] = item.udLeaveTypeCode;
                    row[Att_OvertimeEntity.FieldNames.udOvertimeStatus] = item.udOvertimeStatus;
                    row[Att_OvertimeEntity.FieldNames.RegisterHours] = item.RegisterHours;
                    row[Att_OvertimeEntity.FieldNames.ApproveHours] = item.RegisterHours;
                    table.Rows.Add(row);
                }
                #endregion
                return table;

            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Hàm phân tích tăng ca
        /// </summary>
        /// <param name="lstWorkday">Ds Workday đã được lọc theo ngày tháng , nhân viên v.v</param>
        /// <param name="lstShift">Ds ca làm việc </param>
        /// <param name="lstShiftItem">Ds ca làm việc Item </param>
        /// <param name="lstDayOff">Ds ngày nghỉ của Cty đã được lọc theo thời gian</param>
        /// <param name="lstOvertimeType">Ds loại OT</param>
        /// <param name="OvertimeInfoFillterAnalyze">Các info để tính toán phân tích tăng ca </param>
        /// <returns></returns>
        public List<Att_OvertimeEntity> AnalyzeOvertime(List<WorkdayCustom> lstWorkday, List<Cat_ShiftEntity> lstShift, List<Cat_ShiftItemEntity> lstShiftItem, List<Cat_DayOffEntity> lstDayOff, List<Cat_OvertimeTypeEntity> lstOvertimeType, Att_OvertimeInfoFillterAnalyze OvertimeInfoFillterAnalyze, string userLogin)
        {
            string status = string.Empty;
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoAtt_Pregnancy = new CustomBaseRepository<Att_Pregnancy>(unitOfWork);

                string E_OVERTIME = ShiftItemType.E_OVERTIME.ToString();
                List<Att_OvertimeEntity> lstOvertimeInsert = new List<Att_OvertimeEntity>();
                #region 1 số thông tin loc dữ liệu

                bool isAllowGetOTOutterShift = OvertimeInfoFillterAnalyze.isAllowGetOTOutterShift;
                bool isAllowGetBeforeShift = OvertimeInfoFillterAnalyze.isAllowGetBeforeShift;
                bool isAllowGetAfterShift = OvertimeInfoFillterAnalyze.isAllowGetAfterShift;
                bool isAllowGetInShift = OvertimeInfoFillterAnalyze.isAllowGetInShift;

                if (isAllowGetBeforeShift == false && isAllowGetAfterShift == false && isAllowGetInShift == false)
                    return lstOvertimeInsert;

                bool isAllowGetTypeBaseOnActualDate = OvertimeInfoFillterAnalyze.isAllowGetTypeBaseOnActualDate;
                bool isAllowGetTypeBaseOnBeginShift = OvertimeInfoFillterAnalyze.isAllowGetTypeBaseOnBeginShift;
                bool isAllowGetTypeBaseOnEndShift = OvertimeInfoFillterAnalyze.isAllowGetTypeBaseOnEndShift;
                bool isAllowGetNightShift = OvertimeInfoFillterAnalyze.isAllowGetNightShift;
                bool isBreakMiddleNight = OvertimeInfoFillterAnalyze.isBreakMiddleNight;
                double MininumOvertimeHour = OvertimeInfoFillterAnalyze.MininumOvertimeHour;

                string HRM_ATT_OT_OTPERMIT_PRENATALDONTREGISTEROT = AppConfig.HRM_ATT_OT_ALLOWREGISTEROTWHENINMATERNITYREGIME.ToString();
                List<object> lstREGISTEROT = new List<object>();
                lstREGISTEROT.Add(HRM_ATT_OT_OTPERMIT_PRENATALDONTREGISTEROT);
                lstREGISTEROT.Add(null);
                lstREGISTEROT.Add(null);
                var configTREGISTEROT = GetData<Sys_AllSettingEntity>(lstREGISTEROT, ConstantSql.hrm_sys_sp_get_AllSetting, userLogin, ref status).FirstOrDefault();

                var lstPrenacy = new List<Att_Pregnancy>().Select(m => new { m.ProfileID, m.DateStart, m.DateEnd });
                if (configTREGISTEROT != null && configTREGISTEROT.Value1 == bool.TrueString && lstWorkday.Count > 0)
                {
                    DateTime DateMin = lstWorkday.Min(m => m.WorkDate);
                    DateTime DateMax = lstWorkday.Max(m => m.WorkDate);
                    List<Guid> lstProfileId = lstWorkday.Select(m => m.ProfileID).Distinct().ToList();
                    //lstPrenacy = repoAtt_Pregnancy
                    //    .FindBy(m => m.DateStart <= DateMax && m.DateEnd > DateMin && lstProfileId.Contains(m.ProfileID))
                    //    .Select(m => new { m.ProfileID, m.DateStart, m.DateEnd })
                    //    .ToList();
                    if (lstProfileId.Count < 2000)
                    {
                        lstPrenacy = repoAtt_Pregnancy
                            .FindBy(m => m.IsDelete == null && m.DateStart <= DateMax && m.DateEnd > DateMin && lstProfileId.Contains(m.ProfileID)).Select(m => new { m.ProfileID, m.DateStart, m.DateEnd }).ToList();
                    }
                    else
                    {
                        lstPrenacy = repoAtt_Pregnancy
                            .FindBy(m => m.IsDelete == null && m.DateStart <= DateMax && m.DateEnd > DateMin).Select(m => new { m.ProfileID, m.DateStart, m.DateEnd }).ToList();
                    }
                }

                #endregion
                foreach (var Workday in lstWorkday)
                {
                    Guid? ShiftID = Workday.ShiftApprove ?? Workday.ShiftID;
                    Cat_ShiftEntity ShiftByWorkday = lstShift.Where(m => m.ID == ShiftID).FirstOrDefault();
                    DateTime? In1 = Workday.InTime1;
                    DateTime? In2 = Workday.InTime2;
                    DateTime? In3 = Workday.InTime3;
                    DateTime? In4 = Workday.InTime4;
                    DateTime? Out1 = Workday.OutTime1;
                    DateTime? Out2 = Workday.OutTime2;
                    DateTime? Out3 = Workday.OutTime3;
                    DateTime? Out4 = Workday.OutTime4;

                    bool isNonShift = false;
                    DateTime Workdate = Workday.WorkDate;
                    //
                    if (Workday.Status == WorkdayType.E_DETECTED_SHIFT.ToString() || Workday.ShiftID == null || Workday.ShiftID == Guid.Empty)
                        isNonShift = true;

                    if (ShiftByWorkday == null)
                    {
                        continue;
                    }
                    Guid ProfileID = Workday.ProfileID;
                    if (configTREGISTEROT != null && configTREGISTEROT.Value1 == bool.TrueString &&
                        lstPrenacy.Any(m => m.ProfileID == ProfileID && m.DateStart <= Workdate && m.DateEnd > Workdate)) //Người Thai phụ Ko được Đk Tăng Ca
                    {
                        continue;
                    }

                    List<Cat_ShiftItemEntity> lstShiftItemByShift = lstShiftItem.Where(m => m.ShiftID == ShiftByWorkday.ID && m.ShiftItemType == E_OVERTIME).ToList();
                    if (lstShiftItemByShift.Count > 0 && isAllowGetOTOutterShift == false) //Tang ca theo cai gio quy dinh cua item trong ca
                    {
                        foreach (var ShiftItem in lstShiftItemByShift)
                        {
                            if (ShiftItem.CoFrom == null || ShiftItem.CoTo == null)
                                continue;
                            DateTime DateBeginAllowOT = Workday.WorkDate.AddHours(ShiftItem.CoFrom);
                            DateTime DateEndAllowOT = Workday.WorkDate.AddHours(ShiftItem.CoTo);
                            if (isNonShift)
                            {
                                DateBeginAllowOT = DateBeginAllowOT.Date;
                                DateEndAllowOT = DateBeginAllowOT.Date;
                            }
                            DateTime? BeginOT = null;
                            DateTime? EndOT = null;
                            #region cặp thứ 1
                            if (In1 != null && Out1 != null) // Tính cặp thứ 1
                            {
                                if (isHaveOverTimeInner(In1.Value, Out1.Value, DateBeginAllowOT, DateEndAllowOT, out BeginOT, out EndOT, ShiftByWorkday.InOutDynamic))
                                {
                                    if (BeginOT != null && EndOT != null) // Có OT // Bước tiếp theo là tách ra khỏi ca đêm
                                    {
                                        CreateOvertimeAnalyzeNightShift(
                                            lstDayOff, lstOvertimeType, lstOvertimeInsert,
                                            Workday, ShiftByWorkday,
                                            BeginOT, EndOT,
                                            isAllowGetNightShift, MininumOvertimeHour,
                                            isAllowGetTypeBaseOnActualDate, isAllowGetTypeBaseOnBeginShift,
                                            isAllowGetTypeBaseOnEndShift, isNonShift, false, userLogin);
                                    }
                                }
                            }
                            #endregion
                            #region cặp thứ 2
                            if (In2 != null && Out2 != null) // Tính cặp thứ 2
                            {
                                if (isHaveOverTimeInner(In2.Value, Out2.Value, DateBeginAllowOT, DateEndAllowOT, out BeginOT, out EndOT, ShiftByWorkday.InOutDynamic))
                                {
                                    if (BeginOT != null && EndOT != null) // Có OT // Bước tiếp theo là tách ra khỏi ca đêm
                                    {
                                        CreateOvertimeAnalyzeNightShift(
                                            lstDayOff, lstOvertimeType, lstOvertimeInsert,
                                            Workday, ShiftByWorkday,
                                            BeginOT, EndOT,
                                            isAllowGetNightShift, MininumOvertimeHour,
                                            isAllowGetTypeBaseOnActualDate, isAllowGetTypeBaseOnBeginShift,
                                            isAllowGetTypeBaseOnEndShift, isNonShift, false, userLogin);
                                    }
                                }
                            }
                            #endregion
                            #region cặp thứ 3
                            if (In3 != null && Out3 != null) // Tính cặp thứ 3
                            {
                                if (isHaveOverTimeInner(In3.Value, Out3.Value, DateBeginAllowOT, DateEndAllowOT, out BeginOT, out EndOT, ShiftByWorkday.InOutDynamic))
                                {
                                    if (BeginOT != null && EndOT != null) // Có OT // Bước tiếp theo là tách ra khỏi ca đêm
                                    {
                                        CreateOvertimeAnalyzeNightShift(
                                            lstDayOff, lstOvertimeType, lstOvertimeInsert, Workday, ShiftByWorkday,
                                            BeginOT, EndOT, isAllowGetNightShift,
                                            MininumOvertimeHour, isAllowGetTypeBaseOnActualDate,
                                            isAllowGetTypeBaseOnBeginShift, isAllowGetTypeBaseOnEndShift, isNonShift, false, userLogin);

                                    }
                                }
                            }
                            #endregion
                            #region cặp thứ 4
                            if (In4 != null && Out4 != null) // Tính cặp thứ 4
                            {
                                if (isHaveOverTimeInner(In4.Value, Out4.Value, DateBeginAllowOT, DateEndAllowOT, out BeginOT, out EndOT, ShiftByWorkday.InOutDynamic))
                                {
                                    if (BeginOT != null && EndOT != null) // Có OT // Bước tiếp theo là tách ra khỏi ca đêm
                                    {
                                        CreateOvertimeAnalyzeNightShift(
                                            lstDayOff, lstOvertimeType, lstOvertimeInsert,
                                            Workday, ShiftByWorkday,
                                            BeginOT, EndOT, isAllowGetNightShift, MininumOvertimeHour,
                                            isAllowGetTypeBaseOnActualDate, isAllowGetTypeBaseOnBeginShift,
                                            isAllowGetTypeBaseOnEndShift, isNonShift, false, userLogin);

                                    }
                                }
                            }
                            #endregion
                        }
                    }
                    else if (isAllowGetOTOutterShift) // Tang ca theo cai gio dau ca cuoi ca
                    {
                        DateTime BeginShift = Workday.WorkDate.Date.AddHours(ShiftByWorkday.InTime.Hour).AddMinutes(ShiftByWorkday.InTime.Minute);
                        DateTime EndShift = BeginShift.AddHours(ShiftByWorkday.CoOut);
                        if (isNonShift)
                        {
                            BeginShift = BeginShift.Date;
                            EndShift = BeginShift.Date;
                        }
                        #region Cặp thứ 1
                        if (In1 != null && Out1 != null)
                        {
                            DateTime? DateStartOT_Infirst;
                            DateTime? DateEndOT_InFirst;
                            DateTime? DateStartOT_InLast;
                            DateTime? DateEndOT_InLast;
                            DateTime? DateStartOT_InShift;
                            DateTime? DateEndOT_InShift;

                            if (isHaveOverTimeOutter(In1.Value, Out1.Value, BeginShift, EndShift, out DateStartOT_Infirst, out DateEndOT_InFirst, out DateStartOT_InLast, out DateEndOT_InLast, ShiftByWorkday.InOutDynamic))
                            {
                                //Có OT
                                #region cặp đầu ca
                                if (DateStartOT_Infirst != null && DateEndOT_InFirst != null && isAllowGetBeforeShift)
                                {
                                    CreateOvertimeAnalyzeNightShift(
                                        lstDayOff, lstOvertimeType, lstOvertimeInsert,
                                        Workday, ShiftByWorkday,
                                        DateStartOT_Infirst, DateEndOT_InFirst, isAllowGetNightShift, MininumOvertimeHour,
                                        isAllowGetTypeBaseOnActualDate, isAllowGetTypeBaseOnBeginShift, isAllowGetTypeBaseOnEndShift, isNonShift, false, userLogin);
                                }
                                #endregion

                                #region cặp cuối ca
                                if (DateStartOT_InLast != null && DateEndOT_InLast != null && isAllowGetAfterShift)
                                {
                                    CreateOvertimeAnalyzeNightShift(
                                        lstDayOff, lstOvertimeType, lstOvertimeInsert, Workday, ShiftByWorkday,
                                        DateStartOT_InLast, DateEndOT_InLast, isAllowGetNightShift, MininumOvertimeHour,
                                        isAllowGetTypeBaseOnActualDate, isAllowGetTypeBaseOnBeginShift, isAllowGetTypeBaseOnEndShift, isNonShift, false, userLogin);
                                }
                                #endregion


                            }
                            #region cặp trong ca
                            if (isAllowGetInShift)
                            {
                                if (In1 >= BeginShift)
                                {
                                    DateStartOT_InShift = In1;
                                }
                                else
                                {
                                    DateStartOT_InShift = BeginShift;
                                }

                                if (Out1 < EndShift)
                                {
                                    DateEndOT_InShift = Out1;
                                }
                                else
                                {
                                    DateEndOT_InShift = EndShift;
                                }
                                CreateOvertimeAnalyzeNightShift(
                                    lstDayOff, lstOvertimeType, lstOvertimeInsert, Workday, ShiftByWorkday, DateStartOT_InShift,
                                    DateEndOT_InShift, isAllowGetNightShift, MininumOvertimeHour, isAllowGetTypeBaseOnActualDate,
                                    isAllowGetTypeBaseOnBeginShift, isAllowGetTypeBaseOnEndShift, isNonShift, false, userLogin);
                            }
                            #endregion
                        }
                        #endregion
                        #region Cặp thứ 2
                        if (In2 != null && Out2 != null)
                        {
                            DateTime? DateStartOT_Infirst;
                            DateTime? DateEndOT_InFirst;
                            DateTime? DateStartOT_InLast;
                            DateTime? DateEndOT_InLast;
                            DateTime? DateStartOT_InShift;
                            DateTime? DateEndOT_InShift;

                            if (isHaveOverTimeOutter(In2.Value, Out2.Value, BeginShift, EndShift, out DateStartOT_Infirst, out DateEndOT_InFirst, out DateStartOT_InLast, out DateEndOT_InLast, ShiftByWorkday.InOutDynamic))
                            {
                                //Có OT
                                #region cặp đầu ca
                                if (DateStartOT_Infirst != null && DateEndOT_InFirst != null && isAllowGetBeforeShift)
                                {
                                    CreateOvertimeAnalyzeNightShift(
                                        lstDayOff, lstOvertimeType, lstOvertimeInsert,
                                        Workday, ShiftByWorkday, DateStartOT_Infirst, DateEndOT_InFirst,
                                        isAllowGetNightShift, MininumOvertimeHour, isAllowGetTypeBaseOnActualDate, isAllowGetTypeBaseOnBeginShift,
                                        isAllowGetTypeBaseOnEndShift, isNonShift, false, userLogin);
                                }
                                #endregion

                                #region cặp cuối ca
                                if (DateStartOT_InLast != null && DateEndOT_InLast != null && isAllowGetAfterShift)
                                {
                                    CreateOvertimeAnalyzeNightShift(
                                        lstDayOff, lstOvertimeType, lstOvertimeInsert,
                                        Workday, ShiftByWorkday, DateStartOT_InLast, DateEndOT_InLast,
                                        isAllowGetNightShift, MininumOvertimeHour, isAllowGetTypeBaseOnActualDate, isAllowGetTypeBaseOnBeginShift,
                                        isAllowGetTypeBaseOnEndShift, isNonShift, false, userLogin);
                                }
                                #endregion


                            }
                            #region cặp trong ca
                            if (isAllowGetInShift)
                            {
                                if (In2 >= BeginShift)
                                {
                                    DateStartOT_InShift = In2;
                                }
                                else
                                {
                                    DateStartOT_InShift = BeginShift;
                                }

                                if (Out2 < EndShift)
                                {
                                    DateEndOT_InShift = Out2;
                                }
                                else
                                {
                                    DateEndOT_InShift = EndShift;
                                }
                                CreateOvertimeAnalyzeNightShift(
                                    lstDayOff, lstOvertimeType, lstOvertimeInsert,
                                    Workday, ShiftByWorkday, DateStartOT_InShift, DateEndOT_InShift, isAllowGetNightShift, MininumOvertimeHour,
                                    isAllowGetTypeBaseOnActualDate, isAllowGetTypeBaseOnBeginShift, isAllowGetTypeBaseOnEndShift, isNonShift, false, userLogin);
                            }
                            #endregion
                        }
                        #endregion
                        #region Cặp thứ 3
                        if (In3 != null && Out3 != null)
                        {
                            DateTime? DateStartOT_Infirst;
                            DateTime? DateEndOT_InFirst;
                            DateTime? DateStartOT_InLast;
                            DateTime? DateEndOT_InLast;
                            DateTime? DateStartOT_InShift;
                            DateTime? DateEndOT_InShift;

                            if (isHaveOverTimeOutter(In3.Value, Out3.Value, BeginShift, EndShift, out DateStartOT_Infirst, out DateEndOT_InFirst, out DateStartOT_InLast, out DateEndOT_InLast, ShiftByWorkday.InOutDynamic))
                            {
                                //Có OT
                                #region cặp đầu ca
                                if (DateStartOT_Infirst != null && DateEndOT_InFirst != null && isAllowGetBeforeShift)
                                {
                                    CreateOvertimeAnalyzeNightShift(
                                        lstDayOff, lstOvertimeType, lstOvertimeInsert,
                                        Workday, ShiftByWorkday, DateStartOT_Infirst, DateEndOT_InFirst,
                                        isAllowGetNightShift, MininumOvertimeHour, isAllowGetTypeBaseOnActualDate,
                                        isAllowGetTypeBaseOnBeginShift, isAllowGetTypeBaseOnEndShift, isNonShift, false, userLogin);
                                }
                                #endregion

                                #region cặp cuối ca
                                if (DateStartOT_InLast != null && DateEndOT_InLast != null && isAllowGetAfterShift)
                                {
                                    CreateOvertimeAnalyzeNightShift(
                                        lstDayOff, lstOvertimeType, lstOvertimeInsert,
                                        Workday, ShiftByWorkday, DateStartOT_InLast, DateEndOT_InLast,
                                        isAllowGetNightShift, MininumOvertimeHour, isAllowGetTypeBaseOnActualDate,
                                        isAllowGetTypeBaseOnBeginShift, isAllowGetTypeBaseOnEndShift, isNonShift, false, userLogin);
                                }
                                #endregion


                            }
                            #region cặp trong ca
                            if (isAllowGetInShift)
                            {
                                if (In3 >= BeginShift)
                                {
                                    DateStartOT_InShift = In3;
                                }
                                else
                                {
                                    DateStartOT_InShift = BeginShift;
                                }

                                if (Out3 < EndShift)
                                {
                                    DateEndOT_InShift = Out3;
                                }
                                else
                                {
                                    DateEndOT_InShift = EndShift;
                                }
                                CreateOvertimeAnalyzeNightShift(
                                    lstDayOff, lstOvertimeType, lstOvertimeInsert, Workday, ShiftByWorkday,
                                    DateStartOT_InShift, DateEndOT_InShift, isAllowGetNightShift, MininumOvertimeHour,
                                    isAllowGetTypeBaseOnActualDate, isAllowGetTypeBaseOnBeginShift,
                                    isAllowGetTypeBaseOnEndShift, isNonShift, false, userLogin);
                            }
                            #endregion
                        }
                        #endregion
                        #region Cặp thứ 4
                        if (In4 != null && Out4 != null)
                        {
                            DateTime? DateStartOT_Infirst;
                            DateTime? DateEndOT_InFirst;
                            DateTime? DateStartOT_InLast;
                            DateTime? DateEndOT_InLast;
                            DateTime? DateStartOT_InShift;
                            DateTime? DateEndOT_InShift;

                            if (isHaveOverTimeOutter(In4.Value, Out4.Value, BeginShift, EndShift, out DateStartOT_Infirst, out DateEndOT_InFirst, out DateStartOT_InLast, out DateEndOT_InLast, ShiftByWorkday.InOutDynamic))
                            {
                                //Có OT
                                #region cặp đầu ca
                                if (DateStartOT_Infirst != null && DateEndOT_InFirst != null && isAllowGetBeforeShift)
                                {
                                    CreateOvertimeAnalyzeNightShift(
                                        lstDayOff, lstOvertimeType, lstOvertimeInsert,
                                        Workday, ShiftByWorkday, DateStartOT_Infirst, DateEndOT_InFirst,
                                        isAllowGetNightShift, MininumOvertimeHour, isAllowGetTypeBaseOnActualDate,
                                        isAllowGetTypeBaseOnBeginShift, isAllowGetTypeBaseOnEndShift, isNonShift, false, userLogin);
                                }
                                #endregion

                                #region cặp cuối ca
                                if (DateStartOT_InLast != null && DateEndOT_InLast != null && isAllowGetAfterShift)
                                {
                                    CreateOvertimeAnalyzeNightShift(
                                        lstDayOff, lstOvertimeType, lstOvertimeInsert,
                                        Workday, ShiftByWorkday, DateStartOT_InLast, DateEndOT_InLast,
                                        isAllowGetNightShift, MininumOvertimeHour, isAllowGetTypeBaseOnActualDate,
                                        isAllowGetTypeBaseOnBeginShift, isAllowGetTypeBaseOnEndShift, isNonShift, false, userLogin);
                                }
                                #endregion


                            }
                            #region cặp trong ca
                            if (isAllowGetInShift)
                            {
                                if (In4 >= BeginShift)
                                {
                                    DateStartOT_InShift = In4;
                                }
                                else
                                {
                                    DateStartOT_InShift = BeginShift;
                                }

                                if (Out4 < EndShift)
                                {
                                    DateEndOT_InShift = Out4;
                                }
                                else
                                {
                                    DateEndOT_InShift = EndShift;
                                }
                                CreateOvertimeAnalyzeNightShift(
                                    lstDayOff, lstOvertimeType, lstOvertimeInsert,
                                    Workday, ShiftByWorkday, DateStartOT_InShift, DateEndOT_InShift,
                                    isAllowGetNightShift, MininumOvertimeHour, isAllowGetTypeBaseOnActualDate,
                                    isAllowGetTypeBaseOnBeginShift, isAllowGetTypeBaseOnEndShift, isNonShift, false, userLogin);
                            }
                            #endregion
                        }
                        #endregion
                    }
                }
                return lstOvertimeInsert;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Hàm phân tích tăng ca
        /// </summary>
        /// <param name="lstWorkday">Ds Overtime đang đăng ký cần phân tích</param>
        /// <param name="lstShift">Ds ca làm việc </param>
        /// <param name="lstShiftItem">Ds ca làm việc Item </param>
        /// <param name="lstDayOff">Ds ngày nghỉ của Cty đã được lọc theo thời gian</param>
        /// <param name="lstOvertimeType">Ds loại OT</param>
        /// <param name="OvertimeInfoFillterAnalyze">Các info để tính toán phân tích tăng ca </param>
        /// <returns></returns>
        public List<Att_OvertimeEntity> StartAnalyzeOvertime(List<Att_OvertimeEntity> lstOvertime, List<Cat_ShiftEntity> lstShift, List<Cat_ShiftItemEntity> lstShiftItem,
           List<Cat_DayOffEntity> lstDayOff, List<Cat_OvertimeTypeEntity> lstOvertimeType, Att_OvertimeInfoFillterAnalyze OvertimeInfoFillterAnalyze, string userLogin)
        {
            List<WorkdayCustom> lstWorkday = new List<WorkdayCustom>();
            WorkdayCustom Workday = new WorkdayCustom();
            foreach (var item in lstOvertime)
            {
                if (item.ProfileID == null || item.ShiftID == null || item.WorkDate == null || item.RegisterHours == null)
                    continue;

                Workday.ProfileID = item.ProfileID;
                Workday.ShiftID = item.ShiftID;
                Workday.WorkDate = item.WorkDate.Date;
                Workday.InTime1 = item.WorkDate;
                Workday.OutTime1 = item.WorkDate.AddHours(item.RegisterHours);
                lstWorkday.Add(Workday);
            }
            var rs = AnalyzeOvertime(lstWorkday, lstShift, lstShiftItem, lstDayOff, lstOvertimeType, OvertimeInfoFillterAnalyze, userLogin);
            return rs;
        }