Esempio n. 1
0
        public bool IsOverTimeNightShift(DateTime DateStart, DateTime DateEnd, Cat_ShiftEntity Shift, DateTime Workday,
           out DateTime? BeforeNightShiftStart, out DateTime? BeforeNightShiftEnd,
           out DateTime? NightShiftStart, out DateTime? NightShiftEnd,
           out DateTime? AfterNightShiftStart, out DateTime? AfterNightShiftEnd, bool isNonShift)
        {
            BeforeNightShiftStart = null;
            BeforeNightShiftEnd = null;
            NightShiftStart = null;
            NightShiftEnd = null;
            AfterNightShiftStart = null;
            AfterNightShiftEnd = null;

            bool IsOverTimeNightShift = false;
            //if (Shift == null || Shift.IsNightShift == null || Shift.IsNightShift == false || Shift.NightTimeStart == null || Shift.NightTimeEnd == null)
            if (Shift == null || Shift.NightTimeStart == null || Shift.NightTimeEnd == null)
            {
                return false;
            }
            DateTime NightS = Workday.Date.AddHours(Shift.NightTimeStart.Value.Hour).AddMinutes(Shift.NightTimeStart.Value.Minute);
            DateTime NightE = Workday.Date.AddHours(Shift.NightTimeEnd.Value.Hour).AddMinutes(Shift.NightTimeEnd.Value.Minute);
            if (isNonShift && Shift.CoStartOTNightWithOutShift != null && Shift.CoEndOTNightWithOutShift != null)
            {
                NightS = Workday.Date.Add(Shift.CoStartOTNightWithOutShift.Value.TimeOfDay);
                NightE = Workday.Date.Add(Shift.CoEndOTNightWithOutShift.Value.TimeOfDay);
            }
            if (NightE < NightS)
            {
                NightE = NightE.AddDays(1);
            }

            if (DateStart < NightE && DateEnd > NightS)
            {
                IsOverTimeNightShift = true;
                //Thời gian trước giờ ca đêm
                if (DateStart < NightS)
                {
                    BeforeNightShiftStart = DateStart;
                    BeforeNightShiftEnd = NightS;
                    //-----------------
                    NightShiftStart = NightS;
                }
                else
                {
                    NightShiftStart = DateStart;
                }

                //Thoi gian sau ca dem
                if (DateEnd > NightE)
                {
                    AfterNightShiftStart = NightE;
                    AfterNightShiftEnd = DateEnd;

                    NightShiftEnd = NightE;
                }
                else
                {
                    NightShiftEnd = DateEnd;
                }
            }

            if (IsOverTimeNightShift == false)
            { //Kiểm tra OT ca đêm vào đầu ca | Vd: OT lúc 5h ~ 7h sáng thì .. OT ca đêm là 5h~6h và Ot Ca ngày là 6h và 7h
                NightS = NightS.AddDays(-1);
                NightE = NightE.AddDays(-1);
                if (NightE < NightS)
                {
                    NightE = NightE.AddDays(1);
                }

                if (DateStart < NightE && DateEnd > NightS)
                {
                    IsOverTimeNightShift = true;
                    //Thời gian trước giờ ca đêm
                    if (DateStart < NightS)
                    {
                        BeforeNightShiftStart = DateStart;
                        BeforeNightShiftEnd = NightS;
                        //-----------------
                        NightShiftStart = NightS;
                    }
                    else
                    {
                        NightShiftStart = DateStart;
                    }

                    //Thoi gian sau ca dem
                    if (DateEnd > NightE)
                    {
                        AfterNightShiftStart = NightE;
                        AfterNightShiftEnd = DateEnd;

                        NightShiftEnd = NightE;
                    }
                    else
                    {
                        NightShiftEnd = DateEnd;
                    }
                }
            }


            return IsOverTimeNightShift;

        }
        //[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);

        }
Esempio n. 3
0
        /// <summary>
        /// hàm tạo ra OT với sự phân tích ra night shift và cắt giờ theo nightShift
        /// </summary>
        /// <param name="lstDayOff"></param>
        /// <param name="lstOvertimeType"></param>
        /// <param name="lstOvertimeInsert"></param>
        /// <param name="workday"></param>
        /// <param name="shiftByWorkday"></param>
        /// <param name="beginOT"></param>
        /// <param name="endOT"></param>
        private void CreateOvertimeAnalyzeNightShift(List<Cat_DayOffEntity> lstDayOff, List<Cat_OvertimeTypeEntity> lstOvertimeType, List<Att_OvertimeEntity> lstOvertimeInsert,
            WorkdayCustom Workday, Cat_ShiftEntity ShiftByWorkday, DateTime? BeginOT, DateTime? EndOT, bool isAllowGetNightShift, double MininumOvertimeHour
            , bool isAllowGetTypeBaseOnActualDate, bool isAllowGetTypeBaseOnBeginShift, bool isAllowGetTypeBaseOnEndShift, bool isNonShift, bool isBeforeShift, string userLogin)
        {
            DateTime? BeforeNightShiftStart = null;
            DateTime? BeforeNightShiftEnd = null;
            DateTime? NightShiftStart = null;
            DateTime? NightShiftEnd = null;
            DateTime? AfterNightShiftStart = null;
            DateTime? AfterNightShiftEnd = null;

            if ((EndOT.Value - BeginOT.Value).TotalHours < MininumOvertimeHour)
            {
                return;
            }

            DateTime DateChecking = Workday.WorkDate;
            DateTime ShiftBegin = DateChecking.Date.Add(ShiftByWorkday.InTime.TimeOfDay);
            DateTime ShiftEnd = ShiftBegin.AddHours(ShiftByWorkday.CoOut);


            DateTime ShiftStartBreak = DateChecking.Date.Add(ShiftByWorkday.InTime.TimeOfDay).AddHours(ShiftByWorkday.CoBreakIn);
            DateTime ShiftEndBreak = DateChecking.Date.Add(ShiftByWorkday.InTime.TimeOfDay).AddHours(ShiftByWorkday.CoBreakOut);


            if (isAllowGetNightShift && IsOverTimeNightShift(BeginOT.Value, EndOT.Value, ShiftByWorkday, Workday.WorkDate, out BeforeNightShiftStart, out BeforeNightShiftEnd, out NightShiftStart, out NightShiftEnd, out AfterNightShiftStart, out AfterNightShiftEnd, isNonShift))
            {
                //Có Đi Qua OT Đêm
                //Cặp trươc OT Đêm
                if (BeforeNightShiftStart != null && BeforeNightShiftEnd != null)
                {
                    double HourOT = 0;
                    //Logic Mantis:0029025
                    if (isNonShift)
                    {
                        HourOT = HourRoundDownNonShift(BeforeNightShiftStart, BeforeNightShiftEnd, ShiftBegin, ShiftEnd, ShiftStartBreak, ShiftEndBreak, userLogin);
                    }
                    else
                    {
                        if (BeforeNightShiftStart.Value < ShiftEndBreak && ShiftStartBreak < BeforeNightShiftEnd.Value) //co giao nhau
                        {
                            HourOT += (ShiftStartBreak - BeforeNightShiftStart.Value).TotalHours < 0 ? 0 : (ShiftStartBreak - BeforeNightShiftStart.Value).TotalHours;
                            HourOT += (BeforeNightShiftEnd.Value - ShiftEndBreak).TotalHours < 0 ? 0 : (BeforeNightShiftEnd.Value - ShiftEndBreak).TotalHours;
                        }
                        else
                        {
                            HourOT = (BeforeNightShiftEnd.Value - BeforeNightShiftStart.Value).TotalHours;
                        }
                    }
                    Guid? OvertimeTypeID = GetOvertimeType(DateChecking, lstDayOff, lstOvertimeType, false, isNonShift);
                    if (OvertimeTypeID != null)
                    {
                        Att_OvertimeEntity OTInsert = new Att_OvertimeEntity();
                        OTInsert.ID = Guid.NewGuid();
                        // OTInsert.WorkDate = BeginOT.Value;
                        OTInsert.WorkDate = BeforeNightShiftStart.Value;
                        OTInsert.WorkDateRoot = DateChecking;
                        OTInsert.RegisterHours = HourOT;
                        OTInsert.AnalyseHour = HourOT;

                        OTInsert.Status = OverTimeStatus.E_SUBMIT.ToString();
                        OTInsert.ProfileID = Workday.ProfileID;
                        OTInsert.OvertimeTypeID = OvertimeTypeID.Value;
                        //OTInsert.InTime = BeforeNightShiftStart.Value;
                        //OTInsert.OutTime = BeforeNightShiftEnd.Value;
                        OTInsert.InTime = Workday.InTime1;
                        OTInsert.OutTime = Workday.OutTime1;
                        OTInsert.ShiftID = Workday.ShiftApprove ?? Workday.ShiftID;
                        if (isNonShift)
                        {
                            OTInsert.udWorkdayNonShift = true;
                        }
                        if (isBeforeShift)
                        {
                            OTInsert.udTypeBeginOTWithShift = OverTimeBeginType.E_BEFORE_SHIFT.ToString();
                        }
                        else
                        {
                            OTInsert.udTypeBeginOTWithShift = OverTimeBeginType.E_AFTER_SHIFT.ToString();
                        }
                        lstOvertimeInsert.Add(OTInsert);
                    }
                }


                //Cặp sau OT Đêm
                if (AfterNightShiftStart != null && AfterNightShiftEnd != null)
                {
                    if (isAllowGetTypeBaseOnActualDate)
                    {
                        DateChecking = AfterNightShiftStart.Value.Date;
                    }
                    else if (isAllowGetTypeBaseOnEndShift)
                    {
                        DateChecking = AfterNightShiftEnd.Value.Date;

                    }

                    double HourOT = 0;
                    //Logic Mantis:0029025
                    if (isNonShift)
                    {
                        HourOT = HourRoundDownNonShift(AfterNightShiftStart, AfterNightShiftEnd, ShiftBegin, ShiftEnd, ShiftStartBreak, ShiftEndBreak, userLogin);
                    }
                    else
                    {
                        if (AfterNightShiftStart.Value < ShiftEndBreak && ShiftStartBreak < AfterNightShiftEnd.Value) //co giao nhau
                        {
                            HourOT += (ShiftStartBreak - AfterNightShiftStart.Value).TotalHours < 0 ? 0 : (ShiftStartBreak - AfterNightShiftStart.Value).TotalHours;
                            HourOT += (AfterNightShiftEnd.Value - ShiftEndBreak).TotalHours < 0 ? 0 : (AfterNightShiftEnd.Value - ShiftEndBreak).TotalHours;
                        }
                        else
                        {
                            HourOT = (AfterNightShiftEnd.Value - AfterNightShiftStart.Value).TotalHours;
                        }
                    }
                    Guid? OvertimeTypeID = GetOvertimeType(DateChecking, lstDayOff, lstOvertimeType, false, isNonShift);
                    if (OvertimeTypeID != null)
                    {
                        Att_OvertimeEntity OTInsert = new Att_OvertimeEntity();
                        OTInsert.ID = Guid.NewGuid();
                        //  OTInsert.WorkDate = BeginOT.Value;
                        OTInsert.WorkDate = AfterNightShiftStart.Value;
                        OTInsert.WorkDateRoot = DateChecking;
                        OTInsert.RegisterHours = HourOT;
                        OTInsert.AnalyseHour = HourOT;
                        OTInsert.Status = OverTimeStatus.E_SUBMIT.ToString();
                        OTInsert.ProfileID = Workday.ProfileID;
                        OTInsert.OvertimeTypeID = OvertimeTypeID.Value;
                        //OTInsert.InTime = AfterNightShiftStart.Value;
                        //OTInsert.OutTime = AfterNightShiftEnd.Value;
                        OTInsert.InTime = Workday.InTime1;
                        OTInsert.OutTime = Workday.OutTime1;
                        OTInsert.ShiftID = Workday.ShiftApprove ?? Workday.ShiftID;
                        if (isNonShift)
                        {
                            OTInsert.udWorkdayNonShift = true;
                        }
                        if (isBeforeShift)
                        {
                            OTInsert.udTypeBeginOTWithShift = OverTimeBeginType.E_BEFORE_SHIFT.ToString();
                        }
                        else
                        {
                            OTInsert.udTypeBeginOTWithShift = OverTimeBeginType.E_AFTER_SHIFT.ToString();
                        }
                        lstOvertimeInsert.Add(OTInsert);
                    }
                }

                //Cặp OT Đêm
                if (NightShiftStart != null && NightShiftEnd != null)
                {


                    if (isAllowGetTypeBaseOnActualDate)
                    {
                        DateChecking = NightShiftStart.Value.Date;
                    }
                    else if (isAllowGetTypeBaseOnEndShift)
                    {
                        DateChecking = NightShiftEnd.Value.Date;
                    }

                    double HourOT = 0;
                    //Logic Mantis:0029025
                    if (isNonShift)
                    {
                        HourOT = HourRoundDownNonShift(NightShiftStart, NightShiftEnd, ShiftBegin, ShiftEnd, ShiftStartBreak, ShiftEndBreak, userLogin);
                    }
                    else
                    {
                        if (NightShiftStart.Value < ShiftEndBreak && ShiftStartBreak < NightShiftEnd.Value) //co giao nhau
                        {
                            HourOT += (ShiftStartBreak - NightShiftStart.Value).TotalHours < 0 ? 0 : (ShiftStartBreak - NightShiftStart.Value).TotalHours;
                            HourOT += (NightShiftEnd.Value - ShiftEndBreak).TotalHours < 0 ? 0 : (NightShiftEnd.Value - ShiftEndBreak).TotalHours;
                        }
                        else
                        {
                            HourOT = (NightShiftEnd.Value - NightShiftStart.Value).TotalHours;
                        }
                    }
                    //double HourOT = (NightShiftEnd.Value - NightShiftStart.Value).TotalHours;
                    Guid? OvertimeTypeID = GetOvertimeType(DateChecking, lstDayOff, lstOvertimeType, true, isNonShift);
                    if (OvertimeTypeID != null)
                    {
                        Att_OvertimeEntity OTInsert = new Att_OvertimeEntity();
                        OTInsert.ID = Guid.NewGuid();
                        // OTInsert.WorkDate = BeginOT.Value;
                        OTInsert.WorkDate = NightShiftStart.Value;
                        OTInsert.WorkDateRoot = DateChecking;
                        OTInsert.RegisterHours = HourOT;
                        OTInsert.AnalyseHour = HourOT;
                        OTInsert.Status = OverTimeStatus.E_SUBMIT.ToString();
                        OTInsert.ProfileID = Workday.ProfileID;
                        OTInsert.OvertimeTypeID = OvertimeTypeID.Value;
                        //OTInsert.InTime = NightShiftStart.Value;
                        //OTInsert.OutTime = NightShiftEnd.Value;
                        OTInsert.InTime = Workday.InTime1;
                        OTInsert.OutTime = Workday.OutTime1;
                        OTInsert.ShiftID = Workday.ShiftApprove ?? Workday.ShiftID;
                        if (isNonShift)
                        {
                            OTInsert.udWorkdayNonShift = true;
                        }
                        if (isBeforeShift)
                        {
                            OTInsert.udTypeBeginOTWithShift = OverTimeBeginType.E_BEFORE_SHIFT.ToString();
                        }
                        else
                        {
                            OTInsert.udTypeBeginOTWithShift = OverTimeBeginType.E_AFTER_SHIFT.ToString();
                        }
                        lstOvertimeInsert.Add(OTInsert);
                    }
                }



            }
            else
            {
                //Không Đi Qua OT Ca Đêm
                double HourOT = 0;
                //Logic Mantis:0029025
                if (isNonShift)
                {
                    HourOT = HourRoundDownNonShift(BeginOT, EndOT, ShiftBegin, ShiftEnd, ShiftStartBreak, ShiftEndBreak, userLogin);
                }
                else
                {
                    if (BeginOT.Value < ShiftEndBreak && ShiftStartBreak < EndOT.Value) //co giao nhau
                    {
                        HourOT += (ShiftStartBreak - BeginOT.Value).TotalHours < 0 ? 0 : (ShiftStartBreak - BeginOT.Value).TotalHours;
                        HourOT += (EndOT.Value - ShiftEndBreak).TotalHours < 0 ? 0 : (EndOT.Value - ShiftEndBreak).TotalHours;
                    }
                    else
                    {
                        HourOT = (EndOT.Value - BeginOT.Value).TotalHours;
                    }
                }
                Guid? OvertimeTypeID = GetOvertimeType(DateChecking, lstDayOff, lstOvertimeType, false, isNonShift);

                if (OvertimeTypeID != null)
                {
                    Att_OvertimeEntity OTInsert = new Att_OvertimeEntity();
                    OTInsert.ID = Guid.NewGuid();
                    OTInsert.WorkDate = BeginOT.Value;
                    OTInsert.WorkDateRoot = DateChecking;
                    OTInsert.RegisterHours = HourOT;
                    OTInsert.AnalyseHour = HourOT;
                    OTInsert.Status = OverTimeStatus.E_SUBMIT.ToString();
                    OTInsert.ProfileID = Workday.ProfileID;
                    OTInsert.OvertimeTypeID = OvertimeTypeID.Value;
                    //OTInsert.InTime = BeginOT.Value;
                    //OTInsert.OutTime = EndOT.Value;
                    OTInsert.InTime = Workday.InTime1;
                    OTInsert.OutTime = Workday.OutTime1;
                    OTInsert.ShiftID = Workday.ShiftApprove ?? Workday.ShiftID;
                    if (isNonShift)
                    {
                        OTInsert.udWorkdayNonShift = true;
                    }
                    if (isBeforeShift)
                    {
                        OTInsert.udTypeBeginOTWithShift = OverTimeBeginType.E_BEFORE_SHIFT.ToString();
                    }
                    else
                    {
                        OTInsert.udTypeBeginOTWithShift = OverTimeBeginType.E_AFTER_SHIFT.ToString();
                    }
                    lstOvertimeInsert.Add(OTInsert);
                }
            }
        }