Esempio n. 1
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);
                }
            }
        }
Esempio n. 2
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;
        }