Esempio n. 1
0
 public void NUnit_Domain_GetByIdCatShift()
 {
     string status = string.Empty;
     Cat_ShiftServices service = new Cat_ShiftServices();
     var Shift = new Cat_Shift { Id = 2 };
     var result = service.GetById<Cat_ShiftEntity>(Shift.Id, ref status) as Cat_ShiftEntity;
     NUnit.Framework.Assert.IsNotNull(result);
     Console.Write("SearchResult: " + result.Id + " | " + result.ShiftName + " | " + result.ShiftCode + " | " + result.InTime + " | " + result.CoOut + " | " + result.CoBreakIn + " | " + result.CoBreakOut);
 }
Esempio n. 2
0
        public void NUnit_Domain_GetByIdCatShift()
        {
            string            status  = string.Empty;
            Cat_ShiftServices service = new Cat_ShiftServices();
            var Shift = new Cat_Shift {
                Id = 2
            };
            var result = service.GetById <Cat_ShiftEntity>(Shift.Id, ref status) as Cat_ShiftEntity;

            NUnit.Framework.Assert.IsNotNull(result);
            Console.Write("SearchResult: " + result.Id + " | " + result.ShiftName + " | " + result.ShiftCode + " | " + result.InTime + " | " + result.CoOut + " | " + result.CoBreakIn + " | " + result.CoBreakOut);
        }
Esempio n. 3
0
 public void NUnit_Domain_UpdateCatShift()
 {
     Cat_ShiftServices service = new Cat_ShiftServices();
     var Shift = new Cat_Shift
     {
         Id = 12,
         ShiftName = "ABCDomain12",
         ShiftCode = "BC-12",
     };
     string result = service.Edit(Shift);
     if (result != string.Empty)
     {
         Console.WriteLine("==>>> Result After Update:  " + Shift.Id + " | " + Shift.ShiftName + " | " + Shift.ShiftCode + " | " + Shift.InTime + " | " + Shift.CoOut + " | " + Shift.CoBreakIn + " | " + Shift.CoBreakOut);
     }
 }
Esempio n. 4
0
        public void NUnit_Domain_UpdateCatShift()
        {
            Cat_ShiftServices service = new Cat_ShiftServices();
            var Shift = new Cat_Shift
            {
                Id        = 12,
                ShiftName = "ABCDomain12",
                ShiftCode = "BC-12",
            };
            string result = service.Edit(Shift);

            if (result != string.Empty)
            {
                Console.WriteLine("==>>> Result After Update:  " + Shift.Id + " | " + Shift.ShiftName + " | " + Shift.ShiftCode + " | " + Shift.InTime + " | " + Shift.CoOut + " | " + Shift.CoBreakIn + " | " + Shift.CoBreakOut);
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Thêm mới một record
 /// </summary>
 /// <param name="cat"></param>
 /// <returns></returns>
 public bool Add(Cat_Shift cat)
 {
     using (var context = new VnrAttendanceDataContext())
     {
         IUnitOfWork unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
         Cat_ShiftRepository repo = new Cat_ShiftRepository(unitOfWork);
         try
         {
             repo.Add(cat);
             repo.SaveChanges();
             return true;
         }
         catch
         {
             return false;
         }
     }
 }
Esempio n. 6
0
 /// <summary>
 /// Edit một record
 /// </summary>
 /// <param name="cat"></param>
 /// <returns></returns>
 public bool Edit(Cat_Shift cat)
 {
     using (var context = new VnrAttendanceDataContext())
     {
         IUnitOfWork         unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
         Cat_ShiftRepository repo       = new Cat_ShiftRepository(unitOfWork);
         try
         {
             repo.Edit(cat);
             repo.SaveChanges();
             return(true);
         }
         catch
         {
             return(false);
         }
     }
 }
Esempio n. 7
0
        public void NUnit_Domain_DeleteCatShift()
        {
            Cat_ShiftServices service = new Cat_ShiftServices();
            string result = string.Empty;
            int rs = 0;
            for (int i = 1; i <= 10; i++)
            {
                var Shift = new Cat_Shift { Id = i };
                result = service.Delete<Cat_ShiftEntity>(Shift.Id);
                if (result != string.Empty)
                {
                    rs += 1;
                    Console.WriteLine("Process Success >>> Delete >>> " + i);
                }
            }
            Console.WriteLine("Total success record: " + rs);

            //NUnit.Framework.Assert.IsTrue(result);
        }
Esempio n. 8
0
 public void NUnit_Domain_AddCatShift()
 {
     Cat_ShiftServices service = new Cat_ShiftServices();
     string result = string.Empty;
     int rs = 0;
     for (int i = 0; i < 10; i++)
     {
         var Shift = new Cat_Shift
         {
             ShiftName = "NUnit Domain ShiftName " + i,
             ShiftCode = "NUnit-Code-" + i,
         };
         result = service.Add(Shift);
         if (result != string.Empty)
         {
             rs += 1;
             Console.WriteLine("Process Success >>> Create >>> " + Shift.Id + " | " + Shift.ShiftName + " | " + Shift.ShiftCode + " | " + Shift.InTime + " | " + Shift.CoOut + " | " + Shift.CoBreakIn + " | " + Shift.CoBreakOut);
         }
     }
     Console.WriteLine("Total success record: " + rs);
 }
Esempio n. 9
0
        public void NUnit_Domain_DeleteEternityCatShift()
        {
            Cat_ShiftServices service = new Cat_ShiftServices();
            string            result  = string.Empty;
            int rs = 0;

            for (int i = 1; i <= 10; i++)
            {
                var Shift = new Cat_Shift {
                    Id = i
                };
                result = service.Delete <Cat_ShiftEntity>(Shift.Id);
                if (result != string.Empty)
                {
                    rs += 1;
                    Console.Write(" Process Success >>> DeleteEternity >>> " + i);
                }
            }
            Console.WriteLine("Total success record: " + rs);
            //NUnit.Framework.Assert.IsTrue(result);
        }
Esempio n. 10
0
        public void NUnit_Domain_AddCatShift()
        {
            Cat_ShiftServices service = new Cat_ShiftServices();
            string            result  = string.Empty;
            int rs = 0;

            for (int i = 0; i < 10; i++)
            {
                var Shift = new Cat_Shift
                {
                    ShiftName = "NUnit Domain ShiftName " + i,
                    ShiftCode = "NUnit-Code-" + i,
                };
                result = service.Add(Shift);
                if (result != string.Empty)
                {
                    rs += 1;
                    Console.WriteLine("Process Success >>> Create >>> " + Shift.Id + " | " + Shift.ShiftName + " | " + Shift.ShiftCode + " | " + Shift.InTime + " | " + Shift.CoOut + " | " + Shift.CoBreakIn + " | " + Shift.CoBreakOut);
                }
            }
            Console.WriteLine("Total success record: " + rs);
        }
Esempio n. 11
0
 public void NUnit_WorkDay_Domain_SummaryInOut()
 {
     #region listShift
     using (var contextCategory = new VnrHrmDataContext())
     {
         List <Cat_Shift> listShift = new List <Cat_Shift>();
         Cat_Shift        _shift    = new Cat_Shift()
         {
             Id         = 1,
             ShiftName  = "Ca Test",
             InTime     = DateTime.Parse("01-09-14 08:00:00"),
             CoOut      = 9,
             CoBreakIn  = 4,
             CoBreakOut = 5,
         };
         listShift.Add(_shift);
         contextCategory.Cat_Shift.Add(_shift);
         contextCategory.SaveChanges();
     }
     #endregion
     #region listRoster
     using (var contextAtt = new VnrHrmDataContext())
     {
         List <Att_Roster> listRoster = new List <Att_Roster>();
         Att_Roster        _roster    = new Att_Roster()
         {
             ProfileID       = 1,
             RosterGroupName = "Nhom 1",
             Type            = "E_DEFAULT",
             Status          = "",
             DateEnd         = DateTime.Parse("01-03-2014"),
             DateStart       = DateTime.Parse("01-02-2014"),
             MonShiftID      = 1,
             TueShiftID      = 1,
             WedShiftID      = 1,
             ThuShiftID      = 1,
             FriShiftID      = 1,
             SatShiftID      = 1,
             SunShiftID      = 1
         };
         listRoster.Add(_roster);
         contextAtt.Att_Roster.Add(_roster);
         contextAtt.SaveChanges();
         #endregion
         #region listTamScanLog
         List <Att_TAMScanLog> listTamScanLog = new List <Att_TAMScanLog>();
         Att_TAMScanLog        _tamScanLog1   = new Att_TAMScanLog()
         {
             CardCode = "123",
             TimeLog  = DateTime.Parse("01-02-2014 08:00:00"),
             SrcType  = "E_IN",
             Type     = ""
         };
         Att_TAMScanLog _tamScanLog2 = new Att_TAMScanLog()
         {
             CardCode = "123",
             TimeLog  = DateTime.Parse("01-02-2014 17:00:00"),
             SrcType  = "E_OUT",
             Type     = ""
         };
         Att_TAMScanLog _tamScanLog3 = new Att_TAMScanLog()
         {
             CardCode = "123",
             TimeLog  = DateTime.Parse("02-02-2014 08:00:00"),
             SrcType  = "E_IN",
             Type     = ""
         };
         Att_TAMScanLog _tamScanLog4 = new Att_TAMScanLog()
         {
             CardCode = "123",
             TimeLog  = DateTime.Parse("02-02-2014 17:00:00"),
             SrcType  = "E_OUT",
             Type     = ""
         };
         listTamScanLog.Add(_tamScanLog1);
         listTamScanLog.Add(_tamScanLog2);
         listTamScanLog.Add(_tamScanLog3);
         listTamScanLog.Add(_tamScanLog4);
         contextAtt.Att_TAMScanLog.Add(_tamScanLog1);
         contextAtt.Att_TAMScanLog.Add(_tamScanLog2);
         contextAtt.Att_TAMScanLog.Add(_tamScanLog3);
         contextAtt.Att_TAMScanLog.Add(_tamScanLog4);
         contextAtt.SaveChanges();
     }
     #endregion
     # region CardHistory
     using (var contextHr = new VnrHrmDataContext())
        private List <Att_AnnualDetail> AnalyzeAnnualSickPerProfile(Hre_ProfileEntity Profile, List <Cat_GradeAttendance> lstGradeCfg, List <Att_Grade> lstGrade,
                                                                    DateTime BeginYear, DateTime EndYear, List <Att_LeaveDay> lstLeaveSick, List <Att_AnnualDetail> lstAnnualDetailInDB, Att_AnnualLeave AnnualLeave,
                                                                    List <Att_Roster> lstRosterInYear, List <Att_RosterGroup> lstRosterGroup, List <Hre_WorkHistory> lstWorkHistory, List <Cat_DayOff> lstDayOff,
                                                                    bool IsFrom1To31, List <Cat_Shift> shifts)
        {
            List <Att_AnnualDetail> lstResult            = new List <Att_AnnualDetail>();
            double            leaveBeginYearToMonth      = 0;
            double            leaveBeginYearToMonth_Init = 0;
            string            E_ROSTERGROUP       = RosterType.E_ROSTERGROUP.ToString();
            List <Att_Roster> lstRoster_byProfile = lstRosterInYear.Where(m => m.ProfileID == Profile.ID && m.Type != E_ROSTERGROUP).ToList();
            List <Att_Roster> lstRosterTypeGroup  = lstRosterInYear.Where(m => m.ProfileID == Profile.ID && m.Type == E_ROSTERGROUP).ToList();

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

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

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

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

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

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

                            if (dicShift != null && dicShift.ContainsKey(DateBeginLeave))
                            {
                                Cat_Shift shift = dicShift[DateBeginLeave];
                                if (shift != null)
                                {
                                    double HourWorkday = 8;
                                    if (shift.WorkHours != null && shift.WorkHours != 0)
                                    {
                                        HourWorkday = shift.WorkHours ?? 8;
                                    }
                                    LeaveInMonth += item.Duration / HourWorkday;
                                }
                            }
                        }
                    }
                    else
                    {
                        DateTime DateBegin = BeginMonth > item.DateStart ? BeginMonth : item.DateStart;
                        DateTime DateEnd   = EndMonth < item.DateEnd ? BeginMonth : item.DateEnd;
                        Dictionary <DateTime, Cat_Shift> dicShift = Att_AttendanceLib.GetDailyShifts(Profile != null ? Profile.ID : Guid.Empty, DateBegin, DateEnd, listRosterEntity, listRosterGroupEntity, shifts);
                        for (DateTime dateCheck = DateBegin; dateCheck <= DateEnd; dateCheck = dateCheck.AddDays(1))
                        {
                            if (Att_WorkDayHelper.IsWorkDay(dateCheck, GradeCfg, dicShift, lstDayOff) && !lstDayOff.Any(m => m.DateOff == dateCheck))
                            {
                                LeaveInMonth++;
                            }
                        }
                    }
                }
                Att_AnnualDetail AnnualDetail = lstAnnualDetailInDB.Where(m => m.ProfileID == Profile.ID && m.MonthYear == Month).FirstOrDefault();
                if (AnnualDetail == null)
                {
                    AnnualDetail = new Att_AnnualDetail();
                }
                if (Profile.DateQuit != null)
                {
                    DateTime MonthQuit = Profile.DateQuit.Value.Day >= 15 ? Profile.DateQuit.Value.AddMonths(1) : Profile.DateQuit.Value;
                    MonthQuit = new DateTime(MonthQuit.Year, MonthQuit.Month, 1);
                    if (Month >= MonthQuit)
                    {
                        AnnualDetail.IsDelete = true;
                    }
                }
                AnnualDetail.Available        = Availale;
                AnnualDetail.InitAvailable    = AnnualLeave == null ? 0 : AnnualLeave.InitSickValue;
                AnnualDetail.ProfileID        = Profile.ID;
                AnnualDetail.Year             = BeginYear.Year;
                AnnualDetail.MonthYear        = Month;
                AnnualDetail.MonthBeginInYear = MonthStartAnl; //todo: Phần tử này để trong cấu hình chung
                if (AnnualLeave != null && AnnualLeave.MonthResetAnlOfBeforeYear != null)
                {
                    AnnualDetail.MonthResetInitAvailable = AnnualLeave.MonthResetAnlOfBeforeYear.Value;//todo: MonthReset Này để trong chế độ lương
                }
                else
                {
                    AnnualDetail.MonthResetInitAvailable = 12;//todo: MonthReset Này để trong chế độ lương
                }
                AnnualDetail.MonthStartProfile = AnnualLeave == null ? 1 : AnnualLeave.MonthStart;
                if (AnnualDetail.MonthResetInitAvailable != null && AnnualDetail.MonthResetInitAvailable != 12 && AnnualDetail.Year != null)
                {
                    DateTime MonthReset = new DateTime(AnnualDetail.Year.Value, AnnualDetail.MonthResetInitAvailable.Value, 1);
                    AnnualDetail.IsHaveResetInitAvailable = true;
                    if (Month <= MonthReset) //Trong những tháng có
                    {
                        double delta = leaveBeginYearToMonth_Init + LeaveInMonth - AnnualDetail.InitAvailable.Value;
                        if (delta > 0)
                        {
                            AnnualDetail.TotalLeaveBefFromInitAvailable = leaveBeginYearToMonth_Init;
                            AnnualDetail.LeaveInMonthFromInitAvailable  = LeaveInMonth - delta;
                            AnnualDetail.LeaveInMonth   = delta;
                            AnnualDetail.TotalLeaveBef  = leaveBeginYearToMonth;
                            leaveBeginYearToMonth      += delta;
                            leaveBeginYearToMonth_Init += LeaveInMonth - delta;
                        }
                        else
                        {
                            AnnualDetail.TotalLeaveBefFromInitAvailable = leaveBeginYearToMonth_Init;
                            AnnualDetail.LeaveInMonthFromInitAvailable  = LeaveInMonth;
                            AnnualDetail.TotalLeaveBef  = leaveBeginYearToMonth;
                            AnnualDetail.LeaveInMonth   = 0;
                            leaveBeginYearToMonth_Init += LeaveInMonth;
                        }
                    }
                    else //sau những tháng kho có
                    {
                        AnnualDetail.InitAvailable = 0;
                        AnnualDetail.TotalLeaveBef = leaveBeginYearToMonth;
                        AnnualDetail.LeaveInMonth  = LeaveInMonth;
                        leaveBeginYearToMonth     += LeaveInMonth;
                    }
                }
                else //Bình thường
                {
                    AnnualDetail.IsHaveResetInitAvailable = false;
                    AnnualDetail.TotalLeaveBef            = leaveBeginYearToMonth;
                    AnnualDetail.LeaveInMonth             = LeaveInMonth;
                    leaveBeginYearToMonth += LeaveInMonth;
                }
                double remain = (AnnualDetail.Available ?? 0) + (AnnualDetail.InitAvailable ?? 0) - (AnnualDetail.TotalLeaveBefFromInitAvailable ?? 0) - (AnnualDetail.LeaveInMonthFromInitAvailable ?? 0) - (AnnualDetail.TotalLeaveBef ?? 0) - (AnnualDetail.LeaveInMonth ?? 0);
                AnnualDetail.Remain = remain;
                AnnualDetail.Type   = AnnualLeaveDetailType.E_SICK_LEAVE.ToString();
                lstResult.Add(AnnualDetail);
            }
            return(lstResult);
        }
Esempio n. 13
0
        private Att_RptExceptionDataEntity SetExceptionData(Att_InOut InOut, Hre_Profile profile, Cat_Shift shift, DateTime idx, string userExport)
        {
            Att_RptExceptionDataEntity exceptionData = new Att_RptExceptionDataEntity();

            exceptionData.ID      = Guid.NewGuid();
            exceptionData.InOutID = InOut == null ? Guid.Empty : InOut.ID;
            //exceptionData.EntityType = ClassNames.Att_InOut;
            exceptionData.EntityType  = "Att_InOut";
            exceptionData.CodeEmp     = profile.CodeEmp;
            exceptionData.ShiftID     = shift == null ? Guid.Empty : shift.ID;
            exceptionData.ProfileID   = profile.ID;
            exceptionData.ProfileName = profile.ProfileName;
            exceptionData.UserExport  = userExport;
            exceptionData.DateExport  = DateTime.Today;

            //exceptionData.Position = profile.Cat_Position == null ? string.Empty : profile.Cat_Position.PositionName;

            //string[] strDepartment = GradeCfgDAO.getLinkDepartment(ListCacheOrgStructure, profile.Cat_OrgStructure, true);
            //exceptionData.Department = strDepartment[1];

            exceptionData.Date = idx;
            return(exceptionData);
        }
Esempio n. 14
0
        public void NUnit_WorkDay_Domain_SummaryInOut()
        {
            #region listShift
            using (var contextCategory = new VnrHrmDataContext())
            {
                List<Cat_Shift> listShift = new List<Cat_Shift>();
                Cat_Shift _shift = new Cat_Shift()
                {
                    Id = 1,
                    ShiftName = "Ca Test",
                    InTime = DateTime.Parse("01-09-14 08:00:00"),
                    CoOut = 9,
                    CoBreakIn = 4,
                    CoBreakOut = 5,
                };
                listShift.Add(_shift);
                contextCategory.Cat_Shift.Add(_shift);
                contextCategory.SaveChanges();
            }
            #endregion
            #region listRoster
            using (var contextAtt = new VnrHrmDataContext())
            {
                List<Att_Roster> listRoster = new List<Att_Roster>();
                Att_Roster _roster = new Att_Roster()
                {
                    ProfileID = 1,
                    RosterGroupName = "Nhom 1",
                    Type = "E_DEFAULT",
                    Status = "",
                    DateEnd = DateTime.Parse("01-03-2014"),
                    DateStart = DateTime.Parse("01-02-2014"),
                    MonShiftID = 1,
                    TueShiftID = 1,
                    WedShiftID = 1,
                    ThuShiftID = 1,
                    FriShiftID = 1,
                    SatShiftID = 1,
                    SunShiftID = 1
                };
                listRoster.Add(_roster);
                contextAtt.Att_Roster.Add(_roster);
                contextAtt.SaveChanges();
                #endregion
                #region listTamScanLog
                List<Att_TAMScanLog> listTamScanLog = new List<Att_TAMScanLog>();
                Att_TAMScanLog _tamScanLog1 = new Att_TAMScanLog()
                {
                    CardCode = "123",
                    TimeLog = DateTime.Parse("01-02-2014 08:00:00"),
                    SrcType = "E_IN",
                    Type = ""
                };
                Att_TAMScanLog _tamScanLog2 = new Att_TAMScanLog()
                {
                    CardCode = "123",
                    TimeLog = DateTime.Parse("01-02-2014 17:00:00"),
                    SrcType = "E_OUT",
                    Type = ""
                };
                Att_TAMScanLog _tamScanLog3 = new Att_TAMScanLog()
                {
                    CardCode = "123",
                    TimeLog = DateTime.Parse("02-02-2014 08:00:00"),
                    SrcType = "E_IN",
                    Type = ""
                };
                Att_TAMScanLog _tamScanLog4 = new Att_TAMScanLog()
                {
                    CardCode = "123",
                    TimeLog = DateTime.Parse("02-02-2014 17:00:00"),
                    SrcType = "E_OUT",
                    Type = ""
                };
                listTamScanLog.Add(_tamScanLog1);
                listTamScanLog.Add(_tamScanLog2);
                listTamScanLog.Add(_tamScanLog3);
                listTamScanLog.Add(_tamScanLog4);
                contextAtt.Att_TAMScanLog.Add(_tamScanLog1);
                contextAtt.Att_TAMScanLog.Add(_tamScanLog2);
                contextAtt.Att_TAMScanLog.Add(_tamScanLog3);
                contextAtt.Att_TAMScanLog.Add(_tamScanLog4);
                contextAtt.SaveChanges();
            }
            #endregion
            # region CardHistory
            using (var contextHr = new VnrHrmDataContext())
            {
                List<Hre_CardHistory> listcardhistory = new List<Hre_CardHistory>();
                Hre_CardHistory cardhistory = new Hre_CardHistory()
                {
                    ProfileID = 1,
                    CardCode = "123",
                    DateEffect = DateTime.Parse("01-01-2014")
                };
                listcardhistory.Add(cardhistory);
                contextHr.Hre_CardHistory.Add(cardhistory);
                contextHr.SaveChanges();
            }
            #endregion
            DateTime dateFrom = DateTime.Parse("01-02-2014");
            DateTime dateTo = DateTime.Parse("01-03-2014");

            List<int> listSelectedProfileID = new List<int>(){1,2};

            Att_WorkDayServices service = new Att_WorkDayServices();
            //List<Att_WorkDayEntity> ListInOut = service.SummaryInOut(dateFrom, dateTo, listSelectedProfileID);
        }
Esempio n. 15
0
        private static WorkDay CreateWorkDay(Hre_Profile profile, List <Att_Workday> listInOutByWorkDate, Cat_OrgStructure orgLine,
                                             Cat_Shift shift, List <Cat_ShiftItem> listShiftItem, Att_Pregnancy pregnancyByWorkDay, Cat_GradeAttendance graCfgPro, string userLogin)
        {
            WorkDay result = null;

            listInOutByWorkDate = listInOutByWorkDate.Where(d => d.InTime1 != null &&
                                                            d.OutTime1 != null).OrderBy(d => d.WorkDate).ThenBy(d => d.InTime1).ToList();

            if (listInOutByWorkDate != null && listInOutByWorkDate.Count() > 0)
            {
                #region Khởi tạo

                result              = new WorkDay();
                result.Cat_Shift    = shift;
                result.WorkDuration = 0D;

                result.WorkDate = listInOutByWorkDate.Select(d => d.WorkDate).FirstOrDefault(); //ngày làm việc
                DateTime timeShiftStart = result.WorkDate.Date.Add(shift.InTime.TimeOfDay);     //thời gian bắt đầu của ca làm việc
                DateTime timeShiftEnd   = timeShiftStart.AddHours(shift.CoOut);                 ////thời gian kết thúc của ca làm việc (date + time)
                double   totalTimeShift = timeShiftEnd.Subtract(timeShiftStart).TotalHours;

                //LamLe - 20121017 - Lay gio lam viec trong grade hay trong Shift
                double workingStandardHour = graCfgPro.GetWorkHouPerDay(result.WorkDate);
                //if (shift != null && graCfgPro != null && graCfgPro.WorkHoursType == GradeHoursType.E_SHIFT_HOURS.ToString())
                if (shift != null && graCfgPro != null)
                {
                    workingStandardHour = shift.WorkHours != null ? shift.WorkHours.Value : 0D;
                }

                listShiftItem = listShiftItem.Where(sh => sh.ShiftItemType == ShiftItemType.E_SHIFTBREAK.ToString()).OrderBy(p => p.CoFrom).ToList();
                Guid?         lineID        = orgLine != null ? orgLine.ID : profile.OrgStructureID;//LamLe - 20121030 - Xu ly truong hop co Line org trong Roster
                Cat_ShiftItem shiftItemFlex = listShiftItem.Where(p => p.OrgStructureID == lineID).FirstOrDefault();

                double realCoBreakStart = 0D;
                double realCoBreakEnd   = 0D;

                //Vinhtran: Kiểm tra có giờ nghỉ giữa ca làm việc hay không?
                if (shift.ShiftBreakType == ShiftBreakType.E_FLEXIBLE.ToString() && totalTimeShift > workingStandardHour &&
                    shiftItemFlex != null && shiftItemFlex.CoFrom > 0 && shiftItemFlex.CoTo > shiftItemFlex.CoFrom)
                {
                    if (!shift.IsBreakAsWork.HasValue || !shift.IsBreakAsWork.Value)
                    {
                        shift.udCoBreakStart = shiftItemFlex.CoFrom;
                        shift.udCoBreakEnd   = shiftItemFlex.CoTo;
                    }

                    realCoBreakStart = shiftItemFlex.CoFrom;
                    realCoBreakEnd   = shiftItemFlex.CoTo;
                }
                else if (shift.CoBreakIn > 0 && shift.CoBreakOut > shift.CoBreakIn)
                {
                    if (!shift.IsBreakAsWork.HasValue || !shift.IsBreakAsWork.Value)
                    {
                        shift.udCoBreakStart = shift.CoBreakIn;
                        shift.udCoBreakEnd   = shift.CoBreakOut;
                    }

                    realCoBreakStart = shift.CoBreakIn;
                    realCoBreakEnd   = shift.CoBreakOut;
                }

                if (realCoBreakEnd > realCoBreakStart)
                {
                    totalTimeShift -= realCoBreakEnd - realCoBreakStart;
                }

                //Thời gian bắt đầu và kết thúc nghỉ giữa ca - dùng cho tính toán
                DateTime timeShiftBreakIn  = timeShiftStart.AddHours(shift.udCoBreakStart);
                DateTime timeShiftBreakOut = timeShiftStart.AddHours(shift.udCoBreakEnd);

                //Khoảng thời gian của nửa ca đầu
                DateTime firstHalfShiftStart = timeShiftStart;
                DateTime firstHalfShiftEnd   = timeShiftEnd;

                //Khoảng thời gian của nửa ca sau
                DateTime lastHalfShiftStart = timeShiftStart;
                DateTime lastHalfShiftEnd   = timeShiftEnd;

                if (shift.udCoBreakEnd > shift.udCoBreakStart &&
                    shift.udCoBreakStart > 0)
                {
                    firstHalfShiftStart = timeShiftStart;
                    firstHalfShiftEnd   = timeShiftBreakIn;

                    lastHalfShiftStart = timeShiftBreakOut;
                    lastHalfShiftEnd   = timeShiftEnd;
                }

                if (timeShiftBreakIn > timeShiftStart && listInOutByWorkDate.Count() > 1)
                {
                    //Lần quẹt thẻ vào đầu tiên và lần quẹt thẻ ra cuối cùng của nửa ca đâu
                    if (listInOutByWorkDate.Any(d => d.InTime1 < timeShiftBreakIn))
                    {
                        result.FirstInTime  = listInOutByWorkDate.Where(d => d.InTime1 < timeShiftBreakIn).OrderBy(d => d.WorkDate).ThenBy(d => d.InTime1).Select(d => d.InTime1.Value).FirstOrDefault();
                        result.FirstOutTime = listInOutByWorkDate.Where(d => d.InTime1 < timeShiftBreakIn).OrderBy(d => d.WorkDate).ThenBy(d => d.OutTime1).Select(d => d.OutTime1.Value).LastOrDefault();
                    }
                    else
                    {
                        result.FirstInTime  = listInOutByWorkDate.OrderBy(d => d.WorkDate).ThenBy(d => d.InTime1).Select(d => d.InTime1.Value).FirstOrDefault();
                        result.FirstOutTime = listInOutByWorkDate.OrderBy(d => d.WorkDate).ThenBy(d => d.OutTime1).Select(d => d.OutTime1.Value).FirstOrDefault();
                    }

                    //Lần quẹt thẻ vào đầu tiên và lần quẹt thẻ ra cuối cùng của nửa ca sau
                    if (listInOutByWorkDate.Any(d => d.OutTime1 > timeShiftBreakOut))
                    {
                        result.LastInTime  = listInOutByWorkDate.Where(d => d.OutTime1 > timeShiftBreakOut).OrderBy(d => d.WorkDate).ThenBy(d => d.InTime1).Select(d => d.InTime1.Value).FirstOrDefault();
                        result.LastOutTime = listInOutByWorkDate.Where(d => d.OutTime1 > timeShiftBreakOut).OrderBy(d => d.WorkDate).ThenBy(d => d.OutTime1).Select(d => d.OutTime1.Value).LastOrDefault();
                    }
                    else
                    {
                        result.LastInTime  = listInOutByWorkDate.OrderBy(d => d.WorkDate).ThenBy(d => d.InTime1).Select(d => d.InTime1.Value).LastOrDefault();
                        result.LastOutTime = listInOutByWorkDate.OrderBy(d => d.WorkDate).ThenBy(d => d.OutTime1).Select(d => d.OutTime1.Value).LastOrDefault();
                    }
                }
                else
                {
                    //Lần quẹt thẻ vào đầu tiên và lần quẹt thẻ ra cuối cùng của nửa ca đâu
                    result.FirstInTime  = listInOutByWorkDate.OrderBy(d => d.WorkDate).ThenBy(d => d.InTime1).Select(d => d.InTime1.Value).FirstOrDefault();
                    result.FirstOutTime = listInOutByWorkDate.OrderBy(d => d.WorkDate).ThenBy(d => d.OutTime1).Select(d => d.OutTime1.Value).LastOrDefault();

                    //Lần quẹt thẻ vào đầu tiên và lần quẹt thẻ ra cuối cùng của nửa ca sau
                    result.LastInTime  = listInOutByWorkDate.OrderBy(d => d.WorkDate).ThenBy(d => d.InTime1).Select(d => d.InTime1.Value).FirstOrDefault();
                    result.LastOutTime = listInOutByWorkDate.OrderBy(d => d.WorkDate).ThenBy(d => d.OutTime1).Select(d => d.OutTime1.Value).LastOrDefault();
                }

                DateTime nightTimeStart = result.WorkDate.Date.AddHours(21);
                DateTime nightTimeEnd   = result.WorkDate.Date.AddDays(1).AddHours(5);

                double nightDuration = 0D;
                double firstDuration = 0D;
                double lastDuration  = 0D;

                if (shift.IsNightShift)
                {
                    if (shift.NightTimeStart == null || shift.NightTimeEnd == null)
                    {
                        string appConfigName = AppConfig.HRM_ATT_OT_.ToString();
                        double startHour     = 21D;
                        double endHour       = 5D;

                        List <object> lstParamSys = new List <object>();
                        lstParamSys.Add(appConfigName);
                        lstParamSys.Add(null);
                        lstParamSys.Add(null);
                        string      status       = string.Empty;
                        BaseService baseService  = new BaseService();
                        var         lstAppConfig = baseService.GetData <Sys_AllSetting>(lstParamSys, ConstantSql.hrm_sys_sp_get_AllSetting, userLogin, ref status);

                        Sys_AllSetting appConfig13 = lstAppConfig.Where(s => s.IsDelete == null && s.Name == AppConfig.HRM_ATT_OT_NIGHTSHIFTFROM.ToString()).FirstOrDefault();
                        Sys_AllSetting appConfig14 = lstAppConfig.Where(s => s.IsDelete == null && s.Name == AppConfig.HRM_ATT_OT_NIGHTSHIFTTO.ToString()).FirstOrDefault();
                        //Sys_AppConfig appConfig = EntityService.Instance.GetEntityList<Sys_AppConfig>(false,
                        //    EntityService.Instance.GuidMainContext, Guid.Empty, d => d.Info == appConfigName).FirstOrDefault();

                        if (lstAppConfig != null && appConfig13 != null && appConfig14 != null)
                        {
                            double.TryParse(appConfig13.Value1, out startHour);
                            double.TryParse(appConfig14.Value1, out endHour);
                        }

                        nightTimeStart = shift.NightTimeStart == null?result.WorkDate.Date.AddHours(startHour) : result.WorkDate.Date.Add(shift.NightTimeStart.Value.TimeOfDay);

                        nightTimeEnd = shift.NightTimeEnd == null?result.WorkDate.Date.AddHours(endHour) : result.WorkDate.Date.Add(shift.NightTimeEnd.Value.TimeOfDay);
                    }
                    else
                    {
                        nightTimeStart = result.WorkDate.Date.Add(shift.NightTimeStart.Value.TimeOfDay);
                        nightTimeEnd   = result.WorkDate.Date.Add(shift.NightTimeEnd.Value.TimeOfDay);
                    }

                    nightTimeEnd = nightTimeStart > nightTimeEnd?nightTimeEnd.AddDays(1) : nightTimeEnd;
                }

                #endregion

                foreach (Att_Workday objInOut in listInOutByWorkDate)
                {
                    if (objInOut.InTime1.HasValue && objInOut.OutTime1.HasValue)
                    {
                        #region Tính work duration

                        DateTime inTime  = objInOut.InTime1.Value;
                        DateTime outTime = objInOut.OutTime1.Value;

                        firstDuration += GetIntersectAmountMinutes(inTime, outTime, firstHalfShiftStart, firstHalfShiftEnd);

                        if (timeShiftBreakIn > timeShiftStart)
                        {
                            //Nếu có giờ nghỉ giữa ca
                            lastDuration += GetIntersectAmountMinutes(inTime, outTime, lastHalfShiftStart, lastHalfShiftEnd);
                        }

                        #endregion

                        #region Tính night shift

                        if (shift.IsNightShift)
                        {
                            if (pregnancyByWorkDay != null)
                            {
                                if ((pregnancyByWorkDay.TypePregnancyEarly == PregnancyLeaveEarlyType.E_FIRST.ToString() ||
                                     pregnancyByWorkDay.TypePregnancyEarly == PregnancyLeaveEarlyType.E_FIRST_OUT_BEARK.ToString()) &&
                                    Common.IsOverlap(inTime, outTime, nightTimeStart, nightTimeEnd))
                                {
                                    nightTimeStart = nightTimeStart.AddHours(1);
                                }
                                else if ((pregnancyByWorkDay.TypePregnancyEarly == PregnancyLeaveEarlyType.E_LAST.ToString() ||
                                          pregnancyByWorkDay.TypePregnancyEarly == PregnancyLeaveEarlyType.E_LAST_IN_BEARK.ToString()) &&
                                         Common.IsOverlap(inTime, outTime, nightTimeStart, nightTimeEnd))
                                {
                                    nightTimeEnd = nightTimeEnd.AddHours(-1);
                                }
                            }

                            //Truong hop nghi giua ca nam trong khoang bat dau ca dem
                            if (nightTimeStart >= timeShiftBreakIn && nightTimeStart <= timeShiftBreakOut)
                            {
                                nightDuration += GetIntersectAmountMinutes(inTime, outTime, timeShiftBreakOut, nightTimeEnd);
                            }
                            else if (nightTimeEnd >= timeShiftBreakIn && nightTimeEnd <= timeShiftBreakOut)
                            {
                                nightDuration += GetIntersectAmountMinutes(inTime, outTime, nightTimeStart, timeShiftBreakIn);
                            }
                            else if (nightTimeEnd > timeShiftBreakOut && nightTimeStart < timeShiftBreakIn)
                            {
                                nightDuration += GetIntersectAmountMinutes(inTime, outTime, nightTimeStart, timeShiftBreakIn);
                                nightDuration += GetIntersectAmountMinutes(inTime, outTime, timeShiftBreakOut, nightTimeEnd);
                            }
                            else
                            {
                                nightDuration += GetIntersectAmountMinutes(inTime, outTime, nightTimeStart, nightTimeEnd);
                            }
                        }

                        #endregion
                    }
                }

                if (shift.ReduceNightShift != null && shift.ReduceNightShift >= 0)
                {
                    Int32 reduceNightMinutes = Convert.ToInt32(shift.ReduceNightShift.Value * 60);
                    nightDuration = nightDuration > reduceNightMinutes ? reduceNightMinutes : nightDuration;
                }

                nightDuration = nightDuration > 0 ? nightDuration / 60 : 0D;
                firstDuration = firstDuration > 0 ? firstDuration / 60 : 0D;
                lastDuration  = lastDuration > 0 ? lastDuration / 60 : 0D;

                //Vinhtran: Tổng thời gian làm việc - tính theo giờ
                result.WorkDuration       = firstDuration + lastDuration;
                result.NightShiftDuration = nightDuration;
                result.FirstDuration      = firstDuration;
                result.LastDuration       = lastDuration;

                if (result.WorkDuration > workingStandardHour)
                {
                    result.WorkDuration = workingStandardHour;
                }
                if (result.NightShiftDuration > workingStandardHour)
                {
                    result.NightShiftDuration = workingStandardHour;
                }

                if (shift.IsDoubleShift.Get_Boolean())
                {
                    //Vinh.Tran: Xử lý trường hợp ca ghép
                    totalTimeShift = shift.WorkHours.Get_Double();
                }

                //Vinhtran: Tổng thời gian bị đi trễ hoặc về sớm - tính theo giờ
                result.LateEarlyDuration = totalTimeShift - result.WorkDuration;

                #region Tính trễ sớm

                //Có đi trễ hoặc về sớm
                if (result.LateEarlyDuration > 0)
                {
                    if (timeShiftBreakIn > timeShiftStart)
                    {
                        if (result.FirstInTime > firstHalfShiftStart && result.FirstInTime < firstHalfShiftEnd)
                        {
                            //thời gian đi trễ nửa ca đầu
                            result.FirstLateDuration = result.FirstInTime.Value.Subtract(firstHalfShiftStart).TotalHours;
                        }

                        if (result.LastInTime > lastHalfShiftStart)
                        {
                            //thời gian đi trễ nửa ca sau
                            result.LastLateDuration = result.LastInTime.Value.Subtract(lastHalfShiftStart).TotalHours;
                        }

                        result.FirstEarlyDuration = firstHalfShiftEnd.Subtract(firstHalfShiftStart).TotalHours - firstDuration - result.FirstLateDuration;
                        result.LastEarlyDuration  = lastHalfShiftEnd.Subtract(lastHalfShiftStart).TotalHours - lastDuration - result.LastLateDuration;

                        result.LateDuration  = result.FirstLateDuration + result.LastLateDuration;
                        result.EarlyDuration = result.FirstEarlyDuration + result.LastEarlyDuration;
                    }
                    else
                    {
                        if (result.FirstInTime > timeShiftStart)
                        {
                            //thời gian đi trễ nửa ca đầu
                            result.LateDuration      = result.FirstInTime.Value.Subtract(timeShiftStart).TotalHours;
                            result.FirstLateDuration = result.LateDuration;
                            result.LastLateDuration  = 0;
                        }

                        result.EarlyDuration      = timeShiftEnd.Subtract(timeShiftStart).TotalHours - result.WorkDuration - result.LateDuration;
                        result.FirstEarlyDuration = result.EarlyDuration;
                        result.LastEarlyDuration  = 0;
                    }

                    if (pregnancyByWorkDay != null)
                    {
                        //Thời gian làm việc lớn nhất có thể xảy ra
                        double maxWorkDuration = totalTimeShift - result.LateEarlyDuration + 1;
                        maxWorkDuration += shift.IsDoubleShift.Get_Boolean() ? 1 : 0;//Ca ghép thì thêm 1 giờ
                        maxWorkDuration  = maxWorkDuration > totalTimeShift ? totalTimeShift : maxWorkDuration;

                        if (pregnancyByWorkDay.TypePregnancyEarly == PregnancyLeaveEarlyType.E_FIRST.ToString())
                        {
                            //Chỉ được đi trễ 1 giờ đầu của nửa ca trước, không được về sớm trong nữa ca đầu.
                            result.WorkDuration     += result.FirstLateDuration <= 1 ? result.FirstLateDuration : 1;
                            result.FirstLateDuration = result.FirstLateDuration <= 1 ? 0 : result.FirstLateDuration - 1;

                            if (shift.IsDoubleShift.Get_Boolean())
                            {
                                result.WorkDuration    += result.LastLateDuration <= 1 ? result.LastLateDuration : 1;
                                result.LastLateDuration = result.LastLateDuration <= 1 ? 0 : result.LastLateDuration - 1;
                                result.LateDuration     = result.LateDuration <= 2 ? 0 : result.LateDuration - 2;
                            }
                            else
                            {
                                result.LateDuration = result.LateDuration <= 1 ? 0 : result.LateDuration - 1;
                            }

                            result.WorkDuration = result.WorkDuration > maxWorkDuration ? maxWorkDuration : result.WorkDuration;
                        }
                        else if (pregnancyByWorkDay.TypePregnancyEarly == PregnancyLeaveEarlyType.E_FIRST_OUT_BEARK.ToString())
                        {
                            //Được đi trễ hoặc về sớm 1 giờ bất kỳ của nửa ca trước, nếu là ca ghép thì được 1 tiếng trễ sớm ở mỗi ca (tổng là 2 tiếng)
                            double firstLatetEarly = timeShiftBreakIn > timeShiftStart ? result.FirstLateDuration + result.FirstEarlyDuration : result.LateDuration + result.EarlyDuration;
                            double lastLatetEarly  = (shift.IsDoubleShift.Get_Boolean() && timeShiftBreakIn > timeShiftStart) ? result.LastLateDuration + result.LastEarlyDuration : 0;
                            double totalLatetEarly = firstLatetEarly + lastLatetEarly;

                            if (shift.IsDoubleShift.Get_Boolean())
                            {
                                result.WorkDuration += totalLatetEarly <= 2 ? totalLatetEarly : 2;
                                result.LateDuration  = result.LateDuration <= 2 ? 0 : result.LateDuration - 2;
                            }
                            else
                            {
                                result.WorkDuration += totalLatetEarly <= 1 ? totalLatetEarly : 1;
                                result.LateDuration  = result.LateDuration <= 1 ? 0 : result.LateDuration - 1;
                            }

                            if (timeShiftBreakIn > timeShiftStart)
                            {
                                result.FirstLateDuration  = result.FirstLateDuration <= 1 ? 0 : result.FirstLateDuration - 1;
                                result.FirstEarlyDuration = firstLatetEarly - result.FirstLateDuration;

                                if (shift.IsDoubleShift.Get_Boolean())
                                {
                                    result.LastLateDuration  = result.LastLateDuration <= 1 ? 0 : result.LastLateDuration - 1;
                                    result.LastEarlyDuration = lastLatetEarly - result.LastLateDuration;
                                }
                            }

                            result.EarlyDuration = totalLatetEarly - result.LateDuration;
                        }
                        else if (pregnancyByWorkDay.TypePregnancyEarly == PregnancyLeaveEarlyType.E_LAST_IN_BEARK.ToString())
                        {
                            //Được đi trễ hoặc về sớm 1 giờ bất kỳ của nửa ca sau, nếu là ca ghép thì được 1 tiếng trễ sớm ở mỗi ca (tổng là 2 tiếng)
                            double lastLatetEarly  = timeShiftBreakIn > timeShiftStart ? result.LastLateDuration + result.LastEarlyDuration : result.LateDuration + result.EarlyDuration;
                            double firstLatetEarly = (shift.IsDoubleShift.Get_Boolean() && timeShiftBreakIn > timeShiftStart) ? result.FirstLateDuration + result.FirstEarlyDuration : 0;
                            double totalLatetEarly = firstLatetEarly + lastLatetEarly;

                            if (shift.IsDoubleShift.Get_Boolean())
                            {
                                result.WorkDuration += totalLatetEarly <= 2 ? totalLatetEarly : 2;
                                result.LateDuration  = result.LateDuration <= 2 ? 0 : result.LateDuration - 2;
                            }
                            else
                            {
                                result.WorkDuration += totalLatetEarly <= 1 ? totalLatetEarly : 1;
                                result.LateDuration  = result.LateDuration <= 1 ? 0 : result.LateDuration - 1;
                            }

                            if (timeShiftBreakIn > timeShiftStart)
                            {
                                result.LastLateDuration  = result.LastLateDuration <= 1 ? 0 : result.LastLateDuration - 1;
                                result.LastEarlyDuration = lastLatetEarly - result.LastLateDuration;

                                if (shift.IsDoubleShift.Get_Boolean())
                                {
                                    result.FirstLateDuration  = result.FirstLateDuration <= 1 ? 0 : result.FirstLateDuration - 1;
                                    result.FirstEarlyDuration = firstLatetEarly - result.FirstLateDuration;
                                }
                            }

                            result.EarlyDuration = totalLatetEarly - result.LateDuration;
                        }
                        else if (pregnancyByWorkDay.TypePregnancyEarly == PregnancyLeaveEarlyType.E_LAST.ToString())
                        {
                            //Chỉ được về sớm 1 giờ cuối của nửa ca trước, không được đi trễ trong nữa ca sau.
                            if (timeShiftBreakIn > timeShiftStart)
                            {
                                result.WorkDuration     += result.LastEarlyDuration <= 1 ? result.LastEarlyDuration : 1;
                                result.LastEarlyDuration = result.LastEarlyDuration <= 1 ? 0 : result.LastEarlyDuration - 1;

                                if (shift.IsDoubleShift.Get_Boolean())
                                {
                                    result.WorkDuration      += result.FirstEarlyDuration <= 1 ? result.FirstEarlyDuration : 1;
                                    result.FirstEarlyDuration = result.FirstEarlyDuration <= 1 ? 0 : result.FirstEarlyDuration - 1;
                                }
                            }
                            else
                            {
                                if (shift.IsDoubleShift.Get_Boolean())
                                {
                                    result.WorkDuration += result.EarlyDuration <= 2 ? result.EarlyDuration : 2;
                                }
                                else
                                {
                                    result.WorkDuration += result.EarlyDuration <= 1 ? result.EarlyDuration : 1;
                                }
                            }

                            if (shift.IsDoubleShift.Get_Boolean())
                            {
                                result.EarlyDuration = result.EarlyDuration <= 2 ? 0 : result.EarlyDuration - 2;
                            }
                            else
                            {
                                result.EarlyDuration = result.EarlyDuration <= 1 ? 0 : result.EarlyDuration - 1;
                            }

                            result.WorkDuration = result.WorkDuration > maxWorkDuration ? maxWorkDuration : result.WorkDuration;
                        }
                    }
                }

                #endregion

                //Vinhtran: Tổng thời gian bị đi trễ hoặc về sớm - tính theo phút
                result.LateDuration       = result.LateDuration > 0 ? result.LateDuration * 60 : 0D;
                result.EarlyDuration      = result.EarlyDuration > 0 ? result.EarlyDuration * 60 : 0D;
                result.FirstLateDuration  = result.FirstLateDuration > 0 ? result.FirstLateDuration * 60 : 0D;
                result.FirstEarlyDuration = result.FirstEarlyDuration > 0 ? result.FirstEarlyDuration * 60 : 0D;
                result.LastLateDuration   = result.LastLateDuration > 0 ? result.LastLateDuration * 60 : 0D;
                result.LastEarlyDuration  = result.LastEarlyDuration > 0 ? result.LastEarlyDuration * 60 : 0D;
                result.LateEarlyDuration  = result.LateEarlyDuration > 0 ? result.LateEarlyDuration * 60 : 0D;

                //Vinhtran: Tổng thời gian (h) làm ca đêm lớn nhất có thể => làm tròn trễ sớm
                result.MaxNightDuration = nightTimeEnd.Subtract(nightTimeStart).TotalHours;

                //Thời gian bắt đầu và kết thúc nghỉ giữa ca - giá trị thực tế
                result.ShiftBreakInTime  = timeShiftStart.AddHours(realCoBreakStart);
                result.ShiftBreakOutTime = timeShiftStart.AddHours(realCoBreakEnd);

                //Khoản thời gian làm việc của ca
                result.ShiftInTime  = timeShiftStart;
                result.ShiftOutTime = timeShiftEnd;

                if (shift != null && shift.IsNotApplyWorkHoursReal != null && shift.IsNotApplyWorkHoursReal.Value == true)
                {
                    result.WorkDuration = workingStandardHour - Math.Abs(result.LateDuration / 60) - Math.Abs(result.EarlyDuration / 60);
                }
            }

            return(result);
        }
Esempio n. 16
0
        /// <summary>
        /// Edit comment Trung.le 20120529
        /// Them thuoc tinh Khong cat Overtime qua ngày E_STANDARD_WORKDAY - Value37 Trung.le 20120529
        /// </summary>
        /// <param name="overtime"></param>
        /// <param name="lstDayOff"></param>
        /// <param name="_LstPregnancy"></param>
        /// <param name="GuidContext"></param>
        /// <param name="_userId"></param>
        /// <param name="isByShift">Lấy theo ca làm việc của từng người</param>
        /// <returns></returns>
        public List <Att_OvertimeEntity> AnalysisOvertime(Att_OvertimeEntity overtime, List <Cat_DayOff> lstDayOff,
                                                          List <Att_Pregnancy> _LstPregnancy, bool isByShift, bool isAllowCutBreakHour, string UserLogin)
        {
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork    = (IUnitOfWork)(new UnitOfWork(context));
                var repoCat_Shift = new CustomBaseRepository <Cat_Shift>(unitOfWork);

                Cat_Shift ShiftOfOT = repoCat_Shift.FindBy(s => s.ID == overtime.ShiftID).FirstOrDefault();


                string status = string.Empty;

                Att_OvertimeEntity baseOT = null;
                if (overtime != null)
                {
                    //overtime.SerialCode = overtime.Workdate.ToString("ddMMyyyy");
                }

                List <Att_OvertimeEntity> listOvertimeInsert = new List <Att_OvertimeEntity>();
                Hre_Profile profile = new Hre_Profile();
                profile.ID = overtime.ProfileID;
                DateTime _workDate    = overtime.WorkDate;
                DateTime dateWorkDate = _workDate;

                string        key      = "HRM_ATT_OT";
                List <object> lstSysOT = new List <object>();
                lstSysOT.Add(key);
                lstSysOT.Add(null);
                lstSysOT.Add(null);
                var config = GetData <Sys_AllSettingEntity>(lstSysOT, ConstantSql.hrm_sys_sp_get_AllSetting, UserLogin, ref status);
                if (config == null)
                {
                    return(listOvertimeInsert);
                }
                var  NoCutOvertimePassDay   = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_NOCUTOVERTIMEPASSDAY.ToString()).FirstOrDefault();
                var  ByPeriodOfTime         = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_BYPERIODOFTIME.ToString()).FirstOrDefault();
                var  nightShiftFrom         = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_NIGHTSHIFTFROM.ToString()).FirstOrDefault();
                var  nightShiftTo           = config.Where(s => s.Name == AppConfig.HRM_ATT_OT_NIGHTSHIFTTO.ToString()).FirstOrDefault();
                bool isNocutOvertimePassDay = Convert.ToBoolean(NoCutOvertimePassDay.Value1);//Không cắt Overtime qua ngày


                List <Hre_Profile> lstProfile = new List <Hre_Profile>()
                {
                    profile
                };
                List <Guid>            lstProfileIDs      = lstProfile.Select(m => m.ID).ToList();
                List <Att_Roster>      lstRosterTypeGroup = new List <Att_Roster>();
                List <Att_RosterGroup> lstRosterGroup     = new List <Att_RosterGroup>();
                Att_RosterServices.GetRosterGroup(lstProfileIDs, _workDate.Date, _workDate.Date, out lstRosterTypeGroup, out lstRosterGroup);

                string registryCode  = "OT_" + overtime.CodeEmp + "_" + overtime.WorkDate.ToString("ddMMyyyyHHmmss");
                double basicHours    = overtime.RegisterHours;
                double durationHours = overtime.RegisterHours;
                //overtime.BasicHours = basicHours;
                //overtime.RegisterCode = registryCode;
                bool                isWorkDay       = true;
                DateTime            dateWorkDateEnd = dateWorkDate.AddHours(durationHours);
                Att_Grade           grade           = Att_GradeServices.GetGrade(profile, _workDate.Date);
                Cat_GradeAttendance gradeCfg        = grade == null ? null : grade.Cat_GradeAttendance;
                if (gradeCfg == null)
                {
                    return(listOvertimeInsert);
                }
                Hashtable htable = null;
                htable    = Att_RosterServices.GetRosterTable(false, profile, _workDate.Date, _workDate.Date, lstRosterGroup, lstRosterTypeGroup);
                isWorkDay = Att_AttendanceServices.IsWorkDay(gradeCfg, htable, lstDayOff, _workDate.Date);
                if (isByShift)//Lấy theo ca làm việc của từng người
                {
                    #region Lấy theo ca làm việc của từng người

                    Cat_Shift ship = Att_AttendanceServices.GetShift(gradeCfg, htable, _workDate.Date);
                    if (ship != null)
                    {
                        if (isWorkDay)
                        {
                            if (overtime.DurationType == EnumDropDown.OvertimeDurationType.E_OT_LATE.ToString() && ship != null)
                            {
                                DateTime timeOut = ship.InTime.AddHours(ship.CoOut);
                                dateWorkDate    = _workDate.Date.AddHours(timeOut.Hour).AddMinutes(timeOut.Minute);
                                dateWorkDateEnd = dateWorkDate.AddHours(durationHours);
                            }
                            else if (overtime.DurationType == EnumDropDown.OvertimeDurationType.E_OT_EARLY.ToString() && ship != null)
                            {
                                DateTime timeIn = ship.InTime;
                                dateWorkDate    = _workDate.Date.AddHours(timeIn.Hour).AddMinutes(timeIn.Minute);
                                dateWorkDateEnd = dateWorkDate;
                                dateWorkDate    = dateWorkDate.AddHours(-durationHours);
                            }
                        }
                        else
                        {
                            DateTime timeIn = ship.InTime;
                            dateWorkDate = _workDate.Date.AddHours(timeIn.Hour).AddMinutes(timeIn.Minute);
                        }
                    }
                    else
                    {
                        dateWorkDate    = dateWorkDate.Date;
                        dateWorkDateEnd = dateWorkDate.AddHours(durationHours);
                    }
                    ShiftOfOT = ship;


                    htable    = Att_RosterServices.GetRosterTable(false, profile, dateWorkDate, dateWorkDate.AddHours(durationHours), lstRosterGroup, lstRosterTypeGroup);
                    isWorkDay = Att_AttendanceServices.IsWorkDay(gradeCfg, htable, lstDayOff, dateWorkDate.AddHours(durationHours));

                    #endregion
                }

                //Kiem tra xem co trong thoi gian nghi thai san khong?
                if (isWorkDay && overtime.DurationType == EnumDropDown.OvertimeDurationType.E_OT_LATE.ToString() &&
                    _LstPregnancy != null && _LstPregnancy.Exists(pc => pc.ProfileID == profile.ID && pc.DateEnd >= dateWorkDate && pc.DateStart <= dateWorkDateEnd))
                {
                    dateWorkDate    = dateWorkDate.AddHours(-1);
                    dateWorkDateEnd = dateWorkDate.AddHours(durationHours);
                }
                overtime.WorkDate = dateWorkDate;



                string strHoursNightFrom = string.Empty;
                string strHoursNightTo   = string.Empty;


                if (!Att_AttendanceServices.IsNightShiftByConfig(ByPeriodOfTime) && ShiftOfOT != null &&
                    ShiftOfOT.NightTimeStart != null &&
                    ShiftOfOT.NightTimeEnd != null)
                {
                    strHoursNightFrom = ShiftOfOT.NightTimeStart.Value.ToString("HH:mm:ss");
                    strHoursNightTo   = ShiftOfOT.NightTimeEnd.Value.ToString("HH:mm:ss");
                }
                else
                {
                    strHoursNightFrom = string.IsNullOrEmpty(nightShiftFrom.Value1) == true ? "21:00:00" : nightShiftFrom.Value1 + ":00";
                    strHoursNightTo   = string.IsNullOrEmpty(nightShiftTo.Value1) == true ? "05:00:00" : nightShiftTo.Value1 + ":00";
                }

                DateTime dateNightFrom = Common.ConvertStringToDateTime(dateWorkDate.Date.ToString("MM/dd/yyyy") + " " + strHoursNightFrom, CultureInfo.CurrentCulture.DateTimeFormat.LongDatePattern);
                DateTime dateNightTo   = Common.ConvertStringToDateTime(dateWorkDate.Date.AddDays(1).ToString("MM/dd/yyyy") + " " + strHoursNightTo, CultureInfo.CurrentCulture.DateTimeFormat.LongDatePattern);


                OvertimeInfo overtimeInfo = new OvertimeInfo(true);
                overtimeInfo.DateFrom   = dateWorkDate;
                overtimeInfo.TotalHours = overtime.RegisterHours;

                overtimeInfo.DayShiftPoints = new DateTime[] { dateNightTo };

                if (isNocutOvertimePassDay)
                {
                    overtimeInfo.NightShiftPoints = new DateTime[] { dateNightFrom };
                }
                else
                {
                    //truong hop cat khi qua ngay hom sau
                    overtimeInfo.NightShiftPoints = new DateTime[] { dateNightFrom, dateNightFrom.Date };
                }

                if (ShiftOfOT != null && isAllowCutBreakHour)
                {
                    Cat_Shift shift      = ShiftOfOT;
                    DateTime  coBreakOut = shift.InTime.AddHours(shift.CoBreakIn);

                    if (shift.CoBreakOut - shift.CoBreakIn > 0)
                    {
                        overtimeInfo.BreaktPoints.Add(coBreakOut, shift.CoBreakOut - shift.CoBreakIn);
                    }
                }
                Hre_Profile temp = new Hre_Profile();
                temp.ID = overtime.ProfileID;

                overtimeInfo.Hre_Profile = temp;
                overtimeInfo.ListDayOff  = lstDayOff;

                listOvertimeInsert = AnalysisOvertime(overtime, overtimeInfo);



                return(listOvertimeInsert);
            }
        }
Esempio n. 17
0
        /// <summary>
        /// Hàm tính toán Phép năm dành cho từng nhân viên
        /// </summary>
        /// <param name="Profile">Nhân Viên</param>
        /// <param name="lstGradeCfg">Ds Chế Độ lương</param>
        /// <param name="lstGrade">Ds Grade của Nhân viên</param>
        /// <param name="BeginYear">Ngày bắt đầu của năm</param>
        /// <param name="EndYear">Ngày Kết Thúc Của Năm</param>
        /// <param name="lstLeaveAnl">Ds nghỉ phép năm</param>
        /// <param name="lstAnnualDetailInDB">Ds AnnualDetail trong DB</param>
        /// <param name="AnnualLeave">AnnualLeave</param>
        /// <param name="lstRosterInYear">Ds Roster</param>
        /// <param name="lstRosterGroup">Ds RosterGroup</param>
        /// <param name="lstWorkHistory">Ds WorkingHistory</param>
        /// <param name="lstDayOff">Ds Ngày Nghỉ Lễ </param>
        /// <returns></returns>
        private List <Att_AnnualDetail> AnalyzeAnnualDetailPerProfile(Hre_ProfileMultiField Profile, List <Cat_GradeAttendance>
                                                                      lstGradeCfg, List <Att_Grade> lstGrade, DateTime BeginYear, DateTime EndYear, List <Att_LeaveDayInfo> lstLeaveAnl,
                                                                      List <Att_AnnualDetail> lstAnnualDetailInDB, Att_AnnualLeave AnnualLeave, List <Att_RosterInfo> lstRosterInYearIn,
                                                                      List <Att_RosterGroup> lstRosterGroup, List <Cat_DayOff> lstDayOff,
                                                                      bool IsFrom1To31, Cat_Position Position, List <Sys_AllSetting> lstAllSetting, List <Hre_HDTJob> lstHDTJob, out List <Att_AnnualDetail> AnalyzeAnnualDetailPerProfile_Update, string userLogin)
        {
            AnalyzeAnnualDetailPerProfile_Update = new List <Att_AnnualDetail>();
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork     = (IUnitOfWork)(new UnitOfWork(context));
                var repoAtt_Roster = new CustomBaseRepository <Att_Roster>(unitOfWork);
                var repoCat_Shift  = new Cat_ShiftRepository(unitOfWork);
                var shifts         = repoCat_Shift.FindBy(s => s.IsDelete == null).ToList();

                var lstRosterID     = lstRosterInYearIn.Select(s => s.ID).ToList();
                var lstRosterInYear = repoAtt_Roster.FindBy(s => lstRosterID.Contains(s.ID)).ToList();

                List <Att_AnnualDetail> lstResult            = new List <Att_AnnualDetail>();
                double            leaveBeginYearToMonth      = 0;
                double            leaveBeginYearToMonth_Init = 0;
                string            E_ROSTERGROUP       = RosterType.E_ROSTERGROUP.ToString();
                List <Att_Roster> lstRoster_byProfile = lstRosterInYear.Where(m => m.ProfileID == Profile.ID && m.Type != E_ROSTERGROUP).ToList();
                List <Att_Roster> lstRosterTypeGroup  = lstRosterInYear.Where(m => m.ProfileID == Profile.ID && m.Type == E_ROSTERGROUP).ToList();

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

                    DateTime BeginMonth = Month;
                    DateTime EndMonth   = BeginMonth.AddMonths(1).AddMinutes(-1);
                    if (!IsFrom1To31)
                    {
                        Att_AttendanceServices.GetRangeMaxMinGrade(new List <Cat_GradeAttendance>()
                        {
                            GradeCfg
                        }, Month, out BeginMonth, out EndMonth);
                    }

                    int    AnnualLeaveMonthStart   = AnnualLeave != null ? AnnualLeave.MonthStart : 1;
                    double AnnualLeaveInitAnlValue = AnnualLeave != null ? AnnualLeave.InitAnlValue : 0;

                    double Availale = Att_AttendanceLib.GetAnnualLeaveReceive(BeginYear.Year, Month, GradeCfg, Profile.DateHire,
                                                                              Profile.DateEndProbation, Profile.DateQuit, AnnualLeaveMonthStart, AnnualLeaveInitAnlValue, Position, Profile,
                                                                              lstLeaveAnl, lstAllSetting, lstHDTJob, lstDayOff.Select(m => m.DateOff).ToList(), lstLeaveAnl, userLogin);
                    double LeaveInMonth = 0;
                    List <Att_LeaveDayInfo> lstAnlInMonth = lstLeaveAnl.Where(m => m.ProfileID == Profile.ID && m.DateStart <= EndMonth && m.DateEnd >= BeginMonth).ToList();
                    foreach (var item in lstAnlInMonth)
                    {
                        var listRosterEntity = lstRoster_byProfile.Select(d => new Att_RosterEntity
                        {
                            ID              = d.ID,
                            ProfileID       = d.ProfileID,
                            RosterGroupName = d.RosterGroupName,
                            Type            = d.Type,
                            Status          = d.Status,
                            DateEnd         = d.DateEnd,
                            DateStart       = d.DateStart,
                            MonShiftID      = d.MonShiftID,
                            TueShiftID      = d.TueShiftID,
                            WedShiftID      = d.WedShiftID,
                            ThuShiftID      = d.ThuShiftID,
                            FriShiftID      = d.FriShiftID,
                            SatShiftID      = d.SatShiftID,
                            SunShiftID      = d.SunShiftID,
                            MonShift2ID     = d.MonShiftID,
                            TueShift2ID     = d.TueShift2ID,
                            WedShift2ID     = d.WedShift2ID,
                            ThuShift2ID     = d.ThuShift2ID,
                            FriShift2ID     = d.FriShift2ID,
                            SatShift2ID     = d.SatShift2ID,
                            SunShift2ID     = d.SunShift2ID
                        }).ToList();

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

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

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

                                if (dicShift != null && dicShift.ContainsKey(DateBeginLeave))
                                {
                                    Cat_Shift shift = dicShift[DateBeginLeave];
                                    if (shift != null)
                                    {
                                        double HourWorkday = shift.udStandardWorkHours > 0 ? shift.udStandardWorkHours : 8.0;

                                        LeaveInMonth += item.LeaveHours.Value / HourWorkday;
                                    }
                                }
                            }
                        }
                        else
                        {
                            DateTime DateBegin = BeginMonth > item.DateStart ? BeginMonth : item.DateStart;
                            DateTime DateEnd   = EndMonth < item.DateEnd ? BeginMonth : item.DateEnd;
                            Dictionary <DateTime, Cat_Shift> dicShift = Att_AttendanceLib.GetDailyShifts(Profile != null ? Profile.ID : Guid.Empty, DateBegin, DateEnd, listRosterEntity, listRosterGroupEntity, shifts);
                            for (DateTime dateCheck = DateBegin; dateCheck <= DateEnd; dateCheck = dateCheck.AddDays(1))
                            {
                                if (Att_WorkDayHelper.IsWorkDay(dateCheck, GradeCfg, dicShift, lstDayOff) && !lstDayOff.Any(m => m.DateOff == dateCheck))
                                {
                                    LeaveInMonth++;
                                }
                            }
                        }
                    }
                    Att_AnnualDetail AnnualDetail = lstAnnualDetailInDB.Where(m => m.ProfileID == Profile.ID && m.MonthYear == Month).FirstOrDefault();
                    bool             isNew        = false;
                    if (AnnualDetail == null)
                    {
                        isNew        = true;
                        AnnualDetail = new Att_AnnualDetail();
                    }
                    else
                    {
                        AnalyzeAnnualDetailPerProfile_Update.Add(AnnualDetail);
                    }


                    if (Profile.DateQuit != null)
                    {
                        DateTime MonthQuit = Profile.DateQuit.Value.Day >= 15 ? Profile.DateQuit.Value.AddMonths(1) : Profile.DateQuit.Value;
                        MonthQuit = new DateTime(MonthQuit.Year, MonthQuit.Month, 1);
                        if (Month >= MonthQuit)
                        {
                            AnnualDetail.IsDelete = true;
                        }
                    }
                    AnnualDetail.Available     = Availale;
                    AnnualDetail.InitAvailable = AnnualLeave == null ? 0 : AnnualLeave.InitAnlValue;
                    AnnualDetail.ProfileID     = Profile.ID;
                    //AnnualDetail.Hre_Profile = Profile.CopyData<Hre_Profile>();
                    AnnualDetail.Year             = BeginYear.Year;
                    AnnualDetail.MonthYear        = Month;
                    AnnualDetail.MonthBeginInYear = MonthStartAnl; //todo: Phần tử này để trong cấu hình chung
                    if (AnnualLeave != null && AnnualLeave.MonthResetAnlOfBeforeYear != null)
                    {
                        AnnualDetail.MonthResetInitAvailable = AnnualLeave.MonthResetAnlOfBeforeYear.Value;//todo: MonthReset Này để trong chế độ lương
                    }
                    else
                    {
                        AnnualDetail.MonthResetInitAvailable = 12;//todo: MonthReset Này để trong chế độ lương
                    }
                    AnnualDetail.MonthStartProfile = AnnualLeave == null ? 1 : AnnualLeave.MonthStart;
                    if (AnnualDetail.MonthResetInitAvailable != null && AnnualDetail.MonthResetInitAvailable != 12 && AnnualDetail.Year != null)
                    {
                        DateTime MonthReset = new DateTime(AnnualDetail.Year.Value, AnnualDetail.MonthResetInitAvailable.Value, 1);
                        AnnualDetail.IsHaveResetInitAvailable = true;
                        if (Month <= MonthReset) //Trong những tháng có
                        {
                            double delta = leaveBeginYearToMonth_Init + LeaveInMonth - AnnualDetail.InitAvailable.Value;
                            if (delta > 0)
                            {
                                AnnualDetail.TotalLeaveBefFromInitAvailable = leaveBeginYearToMonth_Init;
                                AnnualDetail.LeaveInMonthFromInitAvailable  = LeaveInMonth - delta;
                                AnnualDetail.LeaveInMonth   = delta;
                                AnnualDetail.TotalLeaveBef  = leaveBeginYearToMonth;
                                leaveBeginYearToMonth      += delta;
                                leaveBeginYearToMonth_Init += LeaveInMonth - delta;
                            }
                            else
                            {
                                AnnualDetail.TotalLeaveBefFromInitAvailable = leaveBeginYearToMonth_Init;
                                AnnualDetail.LeaveInMonthFromInitAvailable  = LeaveInMonth;
                                AnnualDetail.TotalLeaveBef  = leaveBeginYearToMonth;
                                AnnualDetail.LeaveInMonth   = 0;
                                leaveBeginYearToMonth_Init += LeaveInMonth;
                            }
                        }
                        else //sau những tháng kho có
                        {
                            AnnualDetail.InitAvailable = 0;
                            AnnualDetail.TotalLeaveBef = leaveBeginYearToMonth;
                            AnnualDetail.LeaveInMonth  = LeaveInMonth;
                            leaveBeginYearToMonth     += LeaveInMonth;
                        }
                    }
                    else //Bình thường
                    {
                        AnnualDetail.IsHaveResetInitAvailable = false;
                        AnnualDetail.TotalLeaveBef            = leaveBeginYearToMonth;
                        AnnualDetail.LeaveInMonth             = LeaveInMonth;
                        leaveBeginYearToMonth += LeaveInMonth;
                    }
                    double remain = (AnnualDetail.Available ?? 0) + (AnnualDetail.InitAvailable ?? 0) - (AnnualDetail.TotalLeaveBefFromInitAvailable ?? 0) - (AnnualDetail.LeaveInMonthFromInitAvailable ?? 0) - (AnnualDetail.TotalLeaveBef ?? 0) - (AnnualDetail.LeaveInMonth ?? 0);
                    AnnualDetail.Remain = remain;
                    AnnualDetail.Type   = AnnualLeaveDetailType.E_ANNUAL_LEAVE.ToString();
                    if (isNew)
                    {
                        lstResult.Add(AnnualDetail);
                    }
                }
                return(lstResult);
            }
        }