public void NUnit_AllowLimitOvertime_Domain_Add()
        {
            Att_AnnualLeaveDetailServices service = new Att_AnnualLeaveDetailServices();
            var result  = "";
            int countSC = 0;

            for (int i = 1; i <= 10; i++)
            {
                var model = new Att_AnnualLeaveDetail
                {
                    ProfileID = 3,
                    LeaveType = "a"
                };
                result = service.Add <Att_AnnualLeaveDetail>(model);
                NUnit.Framework.Assert.IsNull(result);
                if (result != "")
                {
                    countSC += 1;
                    Console.WriteLine("Process Success >>> Create >>> " + model.Id
                                      + " | " + model.LeaveType
                                      );
                }
            }
            Console.WriteLine("Total success record: " + countSC);
        }
Exemple #2
0
        public bool AddList(List <Att_AnnualLeaveDetailEntity> models)
        {
            bool isSuccess = false;
            var  leaveType = string.Empty;
            var  status    = string.Empty;
            var  year      = 2013;

            if (models != null && models.FirstOrDefault() != null && models.FirstOrDefault().Year != null)
            {
                year      = Convert.ToInt32(models.FirstOrDefault().Year);
                leaveType = models.FirstOrDefault().Type;
            }

            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repo       = new CustomBaseRepository <Att_AnnualLeaveDetail>(unitOfWork);
                try
                {
                    var annualLeaveDetails = GetAllUseEntity <Att_AnnualLeaveDetail>(ref status).Where(p => p.Type == leaveType && p.Year == year).ToList().AsQueryable();
                    foreach (var attAnnualLeaveDetail in models)
                    {
                        var addSuccess        = false;
                        var existAnnualDetail = annualLeaveDetails.Where(p => p.ProfileID == attAnnualLeaveDetail.ProfileID).FirstOrDefault();
                        if (existAnnualDetail != null)
                        {
                            existAnnualDetail.Month1  = attAnnualLeaveDetail.Month1;
                            existAnnualDetail.Month2  = attAnnualLeaveDetail.Month1;
                            existAnnualDetail.Month3  = attAnnualLeaveDetail.Month1;
                            existAnnualDetail.Month4  = attAnnualLeaveDetail.Month1;
                            existAnnualDetail.Month5  = attAnnualLeaveDetail.Month1;
                            existAnnualDetail.Month6  = attAnnualLeaveDetail.Month1;
                            existAnnualDetail.Month7  = attAnnualLeaveDetail.Month1;
                            existAnnualDetail.Month8  = attAnnualLeaveDetail.Month1;
                            existAnnualDetail.Month9  = attAnnualLeaveDetail.Month1;
                            existAnnualDetail.Month10 = attAnnualLeaveDetail.Month1;
                            existAnnualDetail.Month11 = attAnnualLeaveDetail.Month1;
                            existAnnualDetail.Month12 = attAnnualLeaveDetail.Month1;

                            repo.Edit(existAnnualDetail);
                        }
                        else
                        {
                            Att_AnnualLeaveDetail temp = new Att_AnnualLeaveDetail();
                            temp = attAnnualLeaveDetail.CopyData <Att_AnnualLeaveDetail>();
                            repo.Add(temp);
                        }
                    }
                    repo.SaveChanges();
                    return(true);
                }
                catch
                {
                    return(false);
                }
            }
        }
 public void NUnit_AllowLimitOvertime_Domain_GetById()
 {
     Att_AnnualLeaveDetailServices service = new Att_AnnualLeaveDetailServices();
     var model = new Att_AnnualLeaveDetail { Id = 5 };
     var result = service.GetById<Att_AnnualLeaveDetail>(model.Id, ref status);
     NUnit.Framework.Assert.IsNotNull(result);
     Console.Write("SearchResult: " + result.Id
         + " | " + result.ProfileID
         + " | " + result.LeaveType
         );
 }
        public void NUnit_AllowLimitOvertime_Domain_GetById()
        {
            Att_AnnualLeaveDetailServices service = new Att_AnnualLeaveDetailServices();
            var model = new Att_AnnualLeaveDetail {
                Id = 5
            };
            var result = service.GetById <Att_AnnualLeaveDetail>(model.Id, ref status);

            NUnit.Framework.Assert.IsNotNull(result);
            Console.Write("SearchResult: " + result.Id
                          + " | " + result.ProfileID
                          + " | " + result.LeaveType
                          );
        }
        public void NUnit_AllowLimitOvertime_Domain_Delete()
        {
            Att_AnnualLeaveDetailServices service = new Att_AnnualLeaveDetailServices();
            int rs    = 0;
            var model = new Att_AnnualLeaveDetail {
                Id = 4
            };
            var result = service.Delete <Att_AnnualLeaveDetail>(model.Id);

            NUnit.Framework.Assert.IsNull(result);
            if (result != "")
            {
                rs += 1;
                Console.WriteLine("Process Success >>> Delete >>> " + model.Id);
            }
        }
        public void NUnit_AllowLimitOvertime_Domain_Edit()
        {
            Att_AnnualLeaveDetailServices service = new Att_AnnualLeaveDetailServices();
            var model = new Att_AnnualLeaveDetail
            {
                Id        = 2,
                ProfileID = 3,
                LeaveType = "a"
            };
            var result = service.Edit <Att_AnnualLeaveDetail>(model);

            NUnit.Framework.Assert.IsNull(result);
            if (result != "")
            {
                Console.WriteLine("Process Success >>> Update >>> " + model.Id
                                  + " | " + model.ProfileID
                                  + " | " + model.LeaveType
                                  );
            }
        }
 public void NUnit_AllowLimitOvertime_Domain_Add()
 {
     Att_AnnualLeaveDetailServices service = new Att_AnnualLeaveDetailServices();
     var result = "";
     int countSC = 0;
     for (int i = 1; i <= 10; i++)
     {
         var model = new Att_AnnualLeaveDetail
         {
             ProfileID = 3,
             LeaveType = "a"
         };
         result = service.Add<Att_AnnualLeaveDetail>(model);
         NUnit.Framework.Assert.IsNull(result);
         if (result != "")
         {
             countSC += 1;
             Console.WriteLine("Process Success >>> Create >>> " + model.Id
                 + " | " + model.LeaveType
                 );
         }
     }
     Console.WriteLine("Total success record: " + countSC);
 }
        /// <summary>
        /// Button Tìm Kiếm Phép Bệnh
        /// </summary>
        /// <param name="Year"></param>
        /// <param name="orgStructure"></param>
        /// <param name="LstProfileStatus"></param>
        /// <returns></returns>
        public List <Att_AnnualLeaveDetailEntity> SearchAnnualSickLeaveDetail(int Year, string orgStructure, string LstProfileStatus, string UserLogin)
        {
            using (var context = new VnrHrmDataContext())
            {
                string status     = string.Empty;
                var    unitOfWork = (IUnitOfWork) new UnitOfWork(context);
                var    repoAtt_AnnualLeaveDetail = new CustomBaseRepository <Att_AnnualLeaveDetail>(unitOfWork);
                var    repoHre_Profile           = new CustomBaseRepository <Hre_Profile>(unitOfWork);
                var    repoHre_HDTJob            = new CustomBaseRepository <Hre_HDTJob>(unitOfWork);

                string E_SICK_LEAVE = AnnualLeaveDetailType.E_SICK_LEAVE.ToString();

                Att_AnnualLeaveDetail AnnualLeaveDetailTop = AnnualLeaveDetailTop = repoAtt_AnnualLeaveDetail
                                                                                    .FindBy(m => m.IsDelete == null && m.Type == E_SICK_LEAVE && m.Year == Year).FirstOrDefault();
                if (AnnualLeaveDetailTop == null)
                {
                    return(new List <Att_AnnualLeaveDetailEntity>());
                }
                DateTime beginyear = (AnnualLeaveDetailTop == null || AnnualLeaveDetailTop.MonthStart == null) ? new DateTime(Year, 1, 1) : AnnualLeaveDetailTop.MonthStart.Value;
                DateTime endYear   = beginyear.AddYears(1).AddMinutes(-1);

                List <object> lstObj = new List <object>();
                lstObj.Add(orgStructure);
                lstObj.Add(null);
                lstObj.Add(null);
                var lstProfileQuery = GetData <Hre_ProfileEntity>(lstObj, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrg, UserLogin, ref status).ToList();

                if (LstProfileStatus != null)
                {
                    if (LstProfileStatus == StatusEmpLeaveDetail.E_NEWEMPINYEAR.ToString())
                    {
                        lstProfileQuery = lstProfileQuery.Where(m => m.DateHire != null && m.DateHire >= beginyear && m.DateHire <= endYear).ToList();
                    }
                    if (LstProfileStatus == StatusEmpLeaveDetail.E_RESIGNEMPINYEAR.ToString())
                    {
                        lstProfileQuery = lstProfileQuery.Where(m => m.DateQuit != null && m.DateQuit >= beginyear && m.DateQuit <= endYear).ToList();
                    }
                    if (LstProfileStatus == StatusEmpLeaveDetail.E_EMPOFHDT4.ToString())
                    {
                        string      Job4           = HDTJobType.E_Four.ToString();
                        List <Guid> lstprofileHDT4 = repoHre_HDTJob
                                                     .FindBy(m => m.IsDelete == null && m.Type == Job4 && m.DateFrom <= endYear && m.DateTo >= beginyear && m.ProfileID != null)
                                                     .Select(m => m.ProfileID.Value).ToList <Guid>();
                        lstProfileQuery = lstProfileQuery.Where(m => lstprofileHDT4.Contains(m.ID)).ToList();
                    }
                    if (LstProfileStatus == StatusEmpLeaveDetail.E_EMPOFHDT5.ToString())
                    {
                        string      Job5           = HDTJobType.E_Five.ToString();
                        List <Guid> lstprofileHDT5 = repoHre_HDTJob
                                                     .FindBy(m => m.IsDelete == null && m.Type == Job5 && m.DateFrom <= endYear && m.DateTo >= beginyear && m.ProfileID != null)
                                                     .Select(m => m.ProfileID.Value).ToList <Guid>();
                        lstProfileQuery = lstProfileQuery.Where(m => lstprofileHDT5.Contains(m.ID)).ToList();
                    }
                }

                List <Guid> lstProfileID = lstProfileQuery.Select(m => m.ID).Distinct().ToList <Guid>();
                List <Att_AnnualLeaveDetailEntity> lstAnnDetail = repoAtt_AnnualLeaveDetail
                                                                  .FindBy(m => m.IsDelete == null && m.Type == E_SICK_LEAVE && m.Year == Year &&
                                                                          m.ProfileID != null && lstProfileID.Contains(m.ProfileID.Value)).ToList().Translate <Att_AnnualLeaveDetailEntity>();

                foreach (var ann in lstAnnDetail)
                {
                    var pro = lstProfileQuery.Where(s => s.ID == ann.ProfileID).FirstOrDefault();

                    ann.ProfileName      = pro.ProfileName ?? string.Empty;
                    ann.CodeEmp          = pro.CodeEmp ?? string.Empty;
                    ann.OrgStructureName = pro.OrgStructureName ?? string.Empty;
                    ann.DateHire         = pro.DateHire ?? null;
                }
                return(lstAnnDetail);
            }
        }
        /// <summary>
        /// Button Tính Phép Bệnh
        /// </summary>
        /// <param name="Year"></param>
        /// <param name="orgStructure"></param>
        /// <param name="LstProfileStatus"></param>
        /// <returns></returns>
        public bool ComputeAnnualSickLeaveDetail(int Year, string orgStructure, string LstProfileStatus, string UserLogin)
        {
            var result = false;

            using (var context = new VnrHrmDataContext())
            {
                string status     = string.Empty;
                var    unitOfWork = (IUnitOfWork) new UnitOfWork(context);
                var    repoAtt_AnnualLeaveDetail = new CustomBaseRepository <Att_AnnualLeaveDetail>(unitOfWork);
                var    repoHre_Profile           = new CustomBaseRepository <Hre_Profile>(unitOfWork);
                var    repoHre_HDTJob            = new CustomBaseRepository <Hre_HDTJob>(unitOfWork);
                var    repoCat_DayOff            = new CustomBaseRepository <Cat_DayOff>(unitOfWork);
                var    repoCat_LeaveDayType      = new CustomBaseRepository <Cat_LeaveDayType>(unitOfWork);
                var    repoAtt_LeaveDay          = new CustomBaseRepository <Att_LeaveDay>(unitOfWork);
                var    repoCat_JobTitle          = new CustomBaseRepository <Cat_JobTitle>(unitOfWork);


                #region FilterInfo
                string E_SICK_LEAVE = AnnualLeaveDetailType.E_SICK_LEAVE.ToString();

                Att_AnnualLeaveDetail AnnualLeaveDetailTop = repoAtt_AnnualLeaveDetail
                                                             .FindBy(m => m.IsDelete == null && m.Type == E_SICK_LEAVE && m.Year == Year).FirstOrDefault();

                DateTime beginyear = (AnnualLeaveDetailTop == null || AnnualLeaveDetailTop.MonthStart == null) ? new DateTime(Year, 1, 1) : AnnualLeaveDetailTop.MonthStart.Value;
                DateTime endYear   = beginyear.AddYears(1).AddMinutes(-1);

                List <object> lstObj = new List <object>();
                lstObj.Add(orgStructure);
                lstObj.Add(null);
                lstObj.Add(null);
                var lstProfileQuery = GetData <Hre_ProfileEntity>(lstObj, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrg, UserLogin, ref status).ToList();

                if (LstProfileStatus != null)
                {
                    if (LstProfileStatus == StatusEmpLeaveDetail.E_NEWEMPINYEAR.ToString())
                    {
                        lstProfileQuery = lstProfileQuery.Where(m => m.DateHire != null && m.DateHire >= beginyear && m.DateHire <= endYear).ToList();
                    }
                    if (LstProfileStatus == StatusEmpLeaveDetail.E_RESIGNEMPINYEAR.ToString())
                    {
                        lstProfileQuery = lstProfileQuery.Where(m => m.DateQuit != null && m.DateQuit >= beginyear && m.DateQuit <= endYear).ToList();
                    }
                    if (LstProfileStatus == StatusEmpLeaveDetail.E_EMPOFHDT4.ToString())
                    {
                        string      Job4           = HDTJobType.E_Four.ToString();
                        List <Guid> lstprofileHDT4 = repoHre_HDTJob
                                                     .FindBy(m => m.IsDelete == null && m.Type == Job4 && m.DateFrom <= endYear && m.DateTo >= beginyear && m.ProfileID != null)
                                                     .Select(m => m.ProfileID.Value).ToList <Guid>();
                        lstProfileQuery = lstProfileQuery.Where(m => lstprofileHDT4.Contains(m.ID)).ToList();
                    }
                    if (LstProfileStatus == StatusEmpLeaveDetail.E_EMPOFHDT5.ToString())
                    {
                        string      Job5           = HDTJobType.E_Five.ToString();
                        List <Guid> lstprofileHDT5 = repoHre_HDTJob
                                                     .FindBy(m => m.IsDelete == null && m.Type == Job5 && m.DateFrom <= endYear && m.DateTo >= beginyear && m.ProfileID != null)
                                                     .Select(m => m.ProfileID.Value).ToList <Guid>();
                        lstProfileQuery = lstProfileQuery.Where(m => lstprofileHDT5.Contains(m.ID)).ToList();
                    }
                }

                List <Guid> lstProfileID = lstProfileQuery.Select(m => m.ID).Distinct().ToList <Guid>();
                #endregion
                #region get Data
                //string E_STANDARD_WORKDAY = AppConfig.E_STANDARD_WORKDAY.ToString();
                //Sys_AppConfig appconfig = EntityService.CreateQueryable<Sys_AppConfig>(false, GuidContext, Guid.Empty, m => m.Info == E_STANDARD_WORKDAY).FirstOrDefault();
                //if (appconfig == null || string.IsNullOrEmpty(appconfig.Value76) || string.IsNullOrEmpty(appconfig.Value77))
                //{
                //    Common.MessageBoxs(Messages.Msg, Messages.PleaseConfigSickLeaveAtTotalConfig, MessageBox.Icon.WARNING, string.Empty);
                //    return;
                //}

                string        HRM_ATT_ANNUALSICKLEAVE_ = AppConfig.HRM_ATT_ANNUALSICKLEAVE_.ToString();
                List <object> lstO = new List <object>();
                lstO.Add(HRM_ATT_ANNUALSICKLEAVE_);
                lstO.Add(null);
                lstO.Add(null);
                var config = GetData <Sys_AllSettingEntity>(lstO, ConstantSql.hrm_sys_sp_get_AllSetting, UserLogin, ref status);

                var formular1 = config.Where(s => s.Name == AppConfig.HRM_ATT_ANNUALSICKLEAVE_FORMULARCONFIG.ToString()).FirstOrDefault();
                var formular2 = config.Where(s => s.Name == AppConfig.HRM_ATT_ANNUALSICKLEAVE_FORMULARCOMPUTE.ToString()).FirstOrDefault();

                if (config == null || string.IsNullOrEmpty(formular1.Value1) || string.IsNullOrEmpty(formular2.Value1))
                {
                    //Common.MessageBoxs(Messages.Msg, Messages.PleaseConfigAnnualLeaveAtTotalConfig, MessageBox.Icon.WARNING, string.Empty);
                    return(result);
                }

                string formularConfig  = formular1.Value1;
                string formularCompute = formular2.Value1;

                ParamGetConfigANL configAnl = new ParamGetConfigANL();
                (new Att_AttendanceServices()).GetConfigANL(formularConfig, out configAnl);

                int           MonthBegin             = 1;
                List <string> lstCodeLeaveTypeNonAnl = new List <string>();
                if (configAnl != null && configAnl.monthBeginYear != null)
                {
                    MonthBegin = configAnl.monthBeginYear;
                }
                if (configAnl != null && configAnl.lstCodeLeaveNonANL != null)
                {
                    lstCodeLeaveTypeNonAnl = configAnl.lstCodeLeaveNonANL;
                }
                DateTime BeginYear = new DateTime(Year, MonthBegin, 1);
                DateTime EndYear   = BeginYear.AddYears(1).AddMinutes(-1);

                string          E_APPROVED = LeaveDayStatus.E_APPROVED.ToString();
                List <DateTime> lstDayOff  = repoCat_DayOff
                                             .FindBy(m => m.IsDelete == null && m.DateOff > BeginYear && m.DateOff <= EndYear)
                                             .Select(m => m.DateOff).Distinct().ToList <DateTime>();
                List <Hre_ProfileEntity> lstprofile = lstProfileQuery
                                                      .Where(m => m.DateQuit == null || (m.DateQuit != null && m.DateQuit > BeginYear))
                                                      .ToList <Hre_ProfileEntity>();
                List <Guid> lstLeavedayTypeNonAnl = repoCat_LeaveDayType
                                                    .FindBy(m => m.IsDelete == null && lstCodeLeaveTypeNonAnl.Contains(m.Code)).Select(m => m.ID).ToList <Guid>();
                List <Att_LeaveDay> lstleavedayNonANl = repoAtt_LeaveDay
                                                        .FindBy(m => m.IsDelete == null && m.Status == E_APPROVED && lstLeavedayTypeNonAnl.Contains(m.LeaveDayTypeID) &&
                                                                lstProfileID.Contains(m.ProfileID)).ToList <Att_LeaveDay>();
                List <Att_LeaveDay> lstleavedayNonANlInYear = lstleavedayNonANl.Where(m => m.DateStart <= EndYear && m.DateEnd >= BeginYear).ToList <Att_LeaveDay>();
                List <Hre_HDTJob>   lstHDTJob = repoHre_HDTJob
                                                .FindBy(m => m.IsDelete == null && m.ProfileID != null && lstProfileID.Contains(m.ProfileID.Value)).ToList <Hre_HDTJob>();
                List <Cat_JobTitle> lstJobtitle = repoCat_JobTitle.FindBy(s => s.IsDelete == null).ToList();
                #endregion

                List <Att_AnnualLeaveDetail> lstAnnualDetail = new List <Att_AnnualLeaveDetail>();
                foreach (var item in lstprofile)
                {
                    List <Att_LeaveDay> lstLeavedayNonAnlByProfile       = lstleavedayNonANl.Where(m => m.ProfileID == item.ID).ToList();
                    List <Att_LeaveDay> lstLeavedayNonAnlByProfileInYear = lstleavedayNonANlInYear.Where(m => m.ProfileID == item.ID).ToList();
                    List <Hre_HDTJob>   lstHDTJobByProfile = lstHDTJob.Where(m => m.ProfileID == item.ID).ToList();
                    double AvailabelInYear = (new Att_AttendanceServices()).GetAnnualLeaveAvailableAllYear(Year, null, item.DateHire,
                                                                                                           item.DateEndProbation, item.DateQuit, formularConfig,
                                                                                                           formularCompute, lstLeavedayNonAnlByProfileInYear, lstJobtitle, lstDayOff, lstHDTJobByProfile, lstLeavedayNonAnlByProfile);
                    Att_AnnualLeaveDetail annualProfile = new Att_AnnualLeaveDetail();
                    annualProfile.ID         = Guid.NewGuid();
                    annualProfile.ProfileID  = item.ID;
                    annualProfile.MonthStart = BeginYear;
                    annualProfile.MonthEnd   = EndYear;
                    annualProfile.Year       = Year;
                    annualProfile.Type       = E_SICK_LEAVE;
                    annualProfile.Month1     = AvailabelInYear;
                    annualProfile.Month2     = AvailabelInYear;
                    annualProfile.Month3     = AvailabelInYear;
                    annualProfile.Month4     = AvailabelInYear;
                    annualProfile.Month5     = AvailabelInYear;
                    annualProfile.Month6     = AvailabelInYear;
                    annualProfile.Month7     = AvailabelInYear;
                    annualProfile.Month8     = AvailabelInYear;
                    annualProfile.Month9     = AvailabelInYear;
                    annualProfile.Month10    = AvailabelInYear;
                    annualProfile.Month11    = AvailabelInYear;
                    annualProfile.Month12    = AvailabelInYear;
                    lstAnnualDetail.Add(annualProfile);
                }

                DataErrorCode DataErr = DataErrorCode.Unknown;

                if (lstAnnualDetail.Count > 0)
                {
                    #region lấy dữ liệu dưới DB xóa đi
                    List <Guid> lstProfileID_InDB = lstAnnualDetail.Where(m => m.ProfileID != null).Select(m => m.ProfileID.Value).ToList();


                    List <Att_AnnualLeaveDetail> lstAnnualLeaveDetail_InDB = repoAtt_AnnualLeaveDetail
                                                                             .FindBy(m => m.IsDelete == null && m.Year == Year && m.Type == E_SICK_LEAVE && m.ProfileID != null && lstProfileID_InDB.Contains(m.ProfileID.Value)).ToList <Att_AnnualLeaveDetail>();
                    foreach (var item in lstAnnualLeaveDetail_InDB)
                    {
                        item.IsDelete = true;
                    }
                    #endregion

                    repoAtt_AnnualLeaveDetail.Add(lstAnnualDetail);
                    try
                    {
                        repoAtt_AnnualLeaveDetail.SaveChanges();
                    }
                    catch (Exception)
                    {
                        return(false);
                    }

                    //EntityService.AddEntity<Att_AnnualLeaveDetail>(GuidContext, lstAnnualDetail.ToArray());
                    //DataErr = EntityService.SubmitChanges(GuidContext, LoginUserID);

                    //if (DataErr == DataErrorCode.Success)
                    //{
                    //    Common.MessageBoxs(Messages.Msg, Messages.SaveSuccess, MessageBox.Icon.INFO, string.Empty);
                    //}
                    //else
                    //{
                    //    Common.MessageBoxs(Messages.Msg, Messages.SaveUnSuccess, MessageBox.Icon.INFO, string.Empty);
                    //}
                }
                //else
                //{
                //    Common.MessageBoxs(Messages.Msg, Messages.NoDataToCompute, MessageBox.Icon.WARNING, string.Empty);
                //}
                result = true;
            }
            return(result);
        }
Exemple #10
0
        public bool ComputeInsuranceLeaveDetail(int Year, string orgStructure, string LstProfileStatus, string UserLogin)
        {
            /*
             * -get leaveDetail : type , year
             *   - get List Profile :
             *      + Theo phong ban
             *      + Theo trạng thai StatusEmpleaveDetail
             *
             */

            var    result = false;
            string status = string.Empty;


            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoAtt_AnnualLeaveDetail = new CustomBaseRepository <Att_AnnualLeaveDetail>(unitOfWork);
                var repoHre_Profile           = new CustomBaseRepository <Hre_Profile>(unitOfWork);
                var repoHre_HDTJob            = new CustomBaseRepository <Hre_HDTJob>(unitOfWork);
                var repoSys_AppConfig         = new CustomBaseRepository <Sys_AppConfig>(unitOfWork);
                var repoCat_DayOff            = new CustomBaseRepository <Cat_DayOff>(unitOfWork);
                var repoCat_LeaveDayType      = new CustomBaseRepository <Cat_LeaveDayType>(unitOfWork);
                var repoAtt_LeaveDay          = new CustomBaseRepository <Att_LeaveDay>(unitOfWork);
                var repoCat_JobTitle          = new CustomBaseRepository <Cat_JobTitle>(unitOfWork);

                #region get Data
                string        HRM_ATT_ANNUALINSURANCELEAVE_ = AppConfig.HRM_ATT_ANNUALINSURANCELEAVE_.ToString();
                List <object> lstO = new List <object>();
                lstO.Add(HRM_ATT_ANNUALINSURANCELEAVE_);
                lstO.Add(null);
                lstO.Add(null);
                var config = GetData <Sys_AllSettingEntity>(lstO, ConstantSql.hrm_sys_sp_get_AllSetting, UserLogin, ref status);

                var formular1 = config.Where(s => s.Name == AppConfig.HRM_ATT_ANNUALINSURANCELEAVE_FORMULARCONFIG.ToString()).FirstOrDefault();
                var formular2 = config.Where(s => s.Name == AppConfig.HRM_ATT_ANNUALINSURANCELEAVE_FORMULARCOMPUTE.ToString()).FirstOrDefault();

                if (config == null || string.IsNullOrEmpty(formular1.Value1) || string.IsNullOrEmpty(formular2.Value1))
                {
                    //Common.MessageBoxs(Messages.Msg, Messages.PleaseConfigAnnualLeaveAtTotalConfig, MessageBox.Icon.WARNING, string.Empty);
                    return(result);
                }


                List <object> lstPro = new List <object>();
                lstPro.Add(orgStructure);
                lstPro.Add(null);
                lstPro.Add(null);
                var lstProfileQuery = GetData <Hre_ProfileEntity>(lstPro, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrg, UserLogin, ref status).ToList();

                string            formularConfig  = formular1.Value1;
                string            formularCompute = formular2.Value1;
                ParamGetConfigANL configAnl       = new ParamGetConfigANL();
                (new Att_AttendanceServices()).GetConfigANL(formularConfig, out configAnl);

                int           MonthBegin             = 1;
                List <string> lstCodeLeaveTypeNonAnl = new List <string>();
                if (configAnl != null && configAnl.monthBeginYear != null)
                {
                    MonthBegin = configAnl.monthBeginYear;
                }
                if (configAnl != null && configAnl.lstCodeLeaveNonANL != null)
                {
                    lstCodeLeaveTypeNonAnl = configAnl.lstCodeLeaveNonANL;
                }
                DateTime BeginYear = new DateTime(Year, MonthBegin, 1);
                DateTime EndYear   = BeginYear.AddYears(1).AddMinutes(-1);

                string          E_APPROVED = LeaveDayStatus.E_APPROVED.ToString();
                List <DateTime> lstDayOff  = repoCat_DayOff
                                             .FindBy(m => m.IsDelete == null && m.DateOff > BeginYear && m.DateOff <= EndYear)
                                             .Select(m => m.DateOff).Distinct().ToList <DateTime>();
                List <Hre_ProfileEntity> lstprofile = lstProfileQuery
                                                      .Where(m => m.DateQuit == null || (m.DateQuit != null && m.DateQuit > BeginYear)).ToList();
                List <Guid> lstProfileID          = lstprofile.Select(m => m.ID).ToList();
                List <Guid> lstLeavedayTypeNonAnl = repoCat_LeaveDayType
                                                    .FindBy(m => m.IsDelete == null && lstCodeLeaveTypeNonAnl.Contains(m.Code)).Select(m => m.ID).ToList <Guid>();
                List <Att_LeaveDay> lstleavedayNonANl = repoAtt_LeaveDay
                                                        .FindBy(m => m.IsDelete == null && m.Status == E_APPROVED && lstLeavedayTypeNonAnl.Contains(m.LeaveDayTypeID) && lstProfileID.Contains(m.ProfileID)).ToList <Att_LeaveDay>();
                List <Att_LeaveDay> lstleavedayNonANlInYear = lstleavedayNonANl.Where(m => m.DateStart <= EndYear && m.DateEnd >= BeginYear).ToList <Att_LeaveDay>();
                List <Hre_HDTJob>   lstHDTJob = repoHre_HDTJob
                                                .FindBy(m => m.IsDelete == null && m.ProfileID != null && lstProfileID.Contains(m.ProfileID.Value)).ToList <Hre_HDTJob>();
                List <Cat_JobTitle> lstJobtitle = repoCat_JobTitle.FindBy(s => s.IsDelete == null).ToList();
                string E_INSURANCE_LEAVE        = AnnualLeaveDetailType.E_INSURANCE_LEAVE.ToString();
                #endregion

                List <Att_AnnualLeaveDetail> lstInsDetail = new List <Att_AnnualLeaveDetail>();
                foreach (var item in lstprofile)
                {
                    List <Att_LeaveDay>   lstLeavedayNonAnlByProfile       = lstleavedayNonANl.Where(m => m.ProfileID == item.ID).ToList();
                    List <Att_LeaveDay>   lstLeavedayNonAnlByProfileInYear = lstleavedayNonANlInYear.Where(m => m.ProfileID == item.ID).ToList();
                    List <Hre_HDTJob>     lstHDTJobByProfile = lstHDTJob.Where(m => m.ProfileID == item.ID).ToList();
                    Att_AnnualLeaveDetail annualProfile      = new Att_AnnualLeaveDetail();
                    annualProfile.ID         = Guid.NewGuid();
                    annualProfile.ProfileID  = item.ID;
                    annualProfile.MonthStart = BeginYear;
                    annualProfile.MonthEnd   = EndYear;
                    annualProfile.Year       = Year;
                    annualProfile.Type       = E_INSURANCE_LEAVE;
                    for (DateTime Month = BeginYear; Month < EndYear; Month = Month.AddMonths(1))
                    {
                        double AvailabelInYear = (new Att_AttendanceServices()).GetAnnualLeaveAvailableAllYear(Year, Month.Month, item.DateHire,
                                                                                                               item.DateEndProbation, item.DateQuit, formularConfig,
                                                                                                               formularCompute, lstLeavedayNonAnlByProfileInYear, lstJobtitle, lstDayOff, lstHDTJobByProfile, lstLeavedayNonAnlByProfile);
                        if (Month.Month == 1)
                        {
                            annualProfile.Month1 = AvailabelInYear;
                        }
                        if (Month.Month == 2)
                        {
                            annualProfile.Month2 = AvailabelInYear;
                        }
                        if (Month.Month == 3)
                        {
                            annualProfile.Month3 = AvailabelInYear;
                        }
                        if (Month.Month == 4)
                        {
                            annualProfile.Month4 = AvailabelInYear;
                        }
                        if (Month.Month == 5)
                        {
                            annualProfile.Month5 = AvailabelInYear;
                        }
                        if (Month.Month == 6)
                        {
                            annualProfile.Month6 = AvailabelInYear;
                        }
                        if (Month.Month == 7)
                        {
                            annualProfile.Month7 = AvailabelInYear;
                        }
                        if (Month.Month == 8)
                        {
                            annualProfile.Month8 = AvailabelInYear;
                        }
                        if (Month.Month == 9)
                        {
                            annualProfile.Month9 = AvailabelInYear;
                        }
                        if (Month.Month == 10)
                        {
                            annualProfile.Month10 = AvailabelInYear;
                        }
                        if (Month.Month == 11)
                        {
                            annualProfile.Month11 = AvailabelInYear;
                        }
                        if (Month.Month == 12)
                        {
                            annualProfile.Month12 = AvailabelInYear;
                        }
                    }
                    lstInsDetail.Add(annualProfile);
                }

                DataErrorCode DataErr = DataErrorCode.Unknown;

                if (lstInsDetail.Count > 0)
                {
                    #region lấy dữ liệu dưới DB xóa đi
                    List <Guid> lstProfileID_InDB = lstInsDetail.Where(m => m.ProfileID != null).Select(m => m.ProfileID.Value).ToList();


                    List <Att_AnnualLeaveDetail> lstAnnualLeaveDetail_InDB = repoAtt_AnnualLeaveDetail
                                                                             .FindBy(m => m.IsDelete == null && m.Type == E_INSURANCE_LEAVE && m.Year == Year && m.ProfileID != null &&
                                                                                     lstProfileID_InDB.Contains(m.ProfileID.Value)).ToList();
                    foreach (var item in lstAnnualLeaveDetail_InDB)
                    {
                        item.IsDelete = true;
                    }
                    #endregion

                    repoAtt_AnnualLeaveDetail.Add(lstInsDetail);
                    try
                    {
                        repoAtt_AnnualLeaveDetail.SaveChanges();
                    }
                    catch (Exception)
                    {
                        return(false);
                    }

                    //EntityService.AddEntity<Att_AnnualLeaveDetail>(GuidContext, lstInsDetail.ToArray());
                    //DataErr = EntityService.SubmitChanges(GuidContext, LoginUserID);

                    //if (DataErr == DataErrorCode.Success)
                    //{
                    //    Common.MessageBoxs(Messages.Msg, Messages.SaveSuccess, MessageBox.Icon.INFO, string.Empty);
                    //}
                    //else
                    //{
                    //    Common.MessageBoxs(Messages.Msg, Messages.SaveUnSuccess, MessageBox.Icon.INFO, string.Empty);
                    //}
                }
                //else
                //{
                //    Common.MessageBoxs(Messages.Msg, Messages.NoDataToCompute, MessageBox.Icon.WARNING, string.Empty);
                //}
                result = true;
            }
            return(result);
        }
 public void NUnit_AllowLimitOvertime_Domain_Edit()
 {
     Att_AnnualLeaveDetailServices service = new Att_AnnualLeaveDetailServices();
     var model = new Att_AnnualLeaveDetail
     {
         Id = 2,
         ProfileID = 3,
         LeaveType = "a"
     };
     var result = service.Edit<Att_AnnualLeaveDetail>(model);
     NUnit.Framework.Assert.IsNull(result);
     if (result != "")
     {
         Console.WriteLine("Process Success >>> Update >>> " + model.Id
                 + " | " + model.ProfileID
                 + " | " + model.LeaveType
                 );
     }
 }
 public void NUnit_AllowLimitOvertime_Domain_Delete()
 {
     Att_AnnualLeaveDetailServices service = new Att_AnnualLeaveDetailServices();
     int rs = 0;
     var model = new Att_AnnualLeaveDetail { Id = 4 };
     var result = service.Delete<Att_AnnualLeaveDetail>(model.Id);
     NUnit.Framework.Assert.IsNull(result);
     if (result != "")
     {
         rs += 1;
         Console.WriteLine("Process Success >>> Delete >>> " + model.Id);
     }
 }