コード例 #1
0
        /// <summary> Compute D02 và xuat bao cao D02 </summary>
        /// <param name="all"></param>
        /// <param name="increase"></param>
        /// <param name="descrease"></param>
        /// <param name="dtMonthYear"></param>
        /// <param name="orgIds"></param>
        /// <returns></returns>
        public List<Ins_InsuranceReportD02Entity> LoadData(bool? all, bool? increase, bool? descrease, DateTime? dtMonthYear, string orgIds, string searchNoteType, string searchStatus, string codeEmp, List<Guid> socialInsPlaceIDs, string userLogin)
        {
            var monthYear = dtMonthYear ?? DateTime.Now;
            DateTime dateFrom = monthYear.AddMonths(-1);
            dateFrom = new DateTime(dateFrom.Year, dateFrom.Month, InsuranceServices.PeriodInsuranceDayPreMonthDefault);
            DateTime dateTo = new DateTime(monthYear.Year, monthYear.Month, InsuranceServices.PeriodInsuranceDayCurrentMonthDefault);
            var status = string.Empty;
            var allCheck = all ?? false;
            var inCreaseCheck = increase ?? false;
            var descreaseCheck = descrease ?? false;

            DateTime dateFromNewHONDA = new DateTime(dateFrom.Year, dateFrom.Month, PeriodInsuranceDayPreMonth);//18
            DateTime dateToNewHONDA = new DateTime(dateTo.Year, dateTo.Month, PeriodInsuranceDayCurrentMonth);//17
            //
            int? sociaInsCountPro = 0;
            double? sociaInsTotalSalary = 0;
            int? healthInsCountPro = 0;
            double? healthInsTotalSalary = 0;
            int? unEmpInsCountPro = 0;
            double? unEmpInsTotalSalary = 0;
            double? maxSalary = long.MinValue + 1;
            double? minSalary = long.MaxValue - 1;
            //

            //lay ds Ins_ProfileInsuranceMonthly
            //List<object> listInsMonthlyObj = new List<object>();
            //listInsMonthlyObj.Add(orgs);
            //listInsMonthlyObj.Add(monthYear);
            //var profileInsMonthlys = GetData<Hre_ProfileEntity>(listInsMonthlyObj, ConstantSql.hrm_ins_sp_get_ProfileInsMonthly, ref status);
            Hashtable htbData = new Hashtable();
            var d02Reports = new List<Ins_InsuranceReportD02Entity>();
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var profileInsMonthly = new Ins_ProfileInsuranceMonthlyRepository(unitOfWork);
                var orgStructureRepo = new Cat_OrgStructureRepository(unitOfWork);
                var insInsuranceRecord = new Ins_InsuranceRecordRepository(unitOfWork);
                var hre_ContractRepo = new Hre_ContractRepository(unitOfWork);
                var cat_ContractTypeRepo = new Cat_ContractTypeRepository(unitOfWork);
                var att_LeaveDayRepo = new Att_LeavedayRepository(unitOfWork);

                #region Lấy DS Ins_ProfileInsuranceMonthly (lấy tất cả)
                var listInsMonthlyObj = new List<object> { orgIds, null, null, 1, int.MaxValue - 1 };
                if (Common.UseDataBaseName == DATABASETYPE.SQLSERVER.ToString())
                {
                    listInsMonthlyObj.Add("id");
                }
                var lstProfileInsuranceMonthlyInDb = GetData<Ins_ProfileInsuranceMonthlyEntity>(listInsMonthlyObj, ConstantSql.hrm_ins_sp_get_ProfileInsMonthly, userLogin, ref status);
                #endregion

                //get profiles trong Ins_ProfileInsuranceMonthly theo thang kiểm tra
                var lstProfile = lstProfileInsuranceMonthlyInDb.Where(s => (s.IsDelete == null || s.IsDelete.Value==false) && s.MonthYear.HasValue
                    && (s.MonthYear.Value.Year == dateFrom.Year || s.MonthYear.Value.Year == dateTo.Year)
                    && (s.MonthYear.Value.Month == dateFrom.Month || s.MonthYear.Value.Month == dateTo.Month)
                    && s.MonthYearEffect.HasValue && s.MonthYear == s.MonthYearEffect).ToList().Translate<Ins_ProfileInsuranceMonthly>();

                #region lay ins_ProfileInsuranceMonthly de tinh thai san 1 nam lien ke
                //Lấy Ds Ins_ProfileInsuranceMonthly 12 tháng trước so với tháng kiểm tra (de tinh thai san 1 nam lien ke)
                List<Ins_ProfileInsuranceMonthlyEntity> lstProfilePregnant = null;
                #endregion


                //var lstProfile = profileInsMonthly.FindBy(s => s.IsDelete == null && s.MonthYear.HasValue
                //    && (s.MonthYear.Value.Year == dateFrom.Year || s.MonthYear.Value.Year == dateTo.Year)
                //    && (s.MonthYear.Value.Month == dateFrom.Month || s.MonthYear.Value.Month == dateTo.Month)).ToList();

                //get InsuranceRecord (Chứng từ bảo hiểm)
                var lstInsuranceRecord = insInsuranceRecord.GetAll().Where(p => p.IsDelete == null).ToList();// lay tat ca chứng từ bảo hiểm (sau nay sửa lai sau)


                #region Lay ds Phong Ban
                var orgs = GetDataNotParam<Cat_OrgStructure>(ConstantSql.hrm_cat_sp_get_AllOrg, userLogin, ref status).ToList();
                List<Cat_OrgStructureEntity> orgStructures = orgs.Translate<Cat_OrgStructureEntity>();
                #endregion

                #region Lấy profile theo phong ban
                List<object> listObj = new List<object>();
                listObj.Add(orgIds);
                listObj.Add(string.Empty);
                listObj.Add(string.Empty);
                var profilebyOrgs = GetData<Hre_ProfileEntity>(listObj, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrg, userLogin, ref status);
                if (!string.IsNullOrEmpty(codeEmp))
                {
                    profilebyOrgs = profilebyOrgs.Where(p => p.CodeEmp == codeEmp).ToList();
                }
                else if (profilebyOrgs != null)
                {
                    profilebyOrgs = profilebyOrgs.Where(p => p.DateHire != null
                                && (p.DateQuit == null || p.DateQuit > dateFrom)
                                && p.DateHire <= monthYear).ToList();
                }


                var profileIds = profilebyOrgs.Select(p => p.ID).ToList();
                #endregion

                #region  lay ds hop dong đã ký so với tháng chọn (Loại HD có đóng BH)
                var contractTypeObjs = cat_ContractTypeRepo.FindBy(p => p.IsDelete == null).ToList();
                //Ds loại HĐ đóng BHXH
                var contractSocialTypeIDObjs = contractTypeObjs.Where(p => p.IsSocialInsurance.HasValue && p.IsSocialInsurance.Value).ToList();
                //Ds loại HĐ đóng BHTN
                var contractUnEmpTypeIDObjs = contractTypeObjs.Where(p => p.IsUnEmployInsurance.HasValue && p.IsUnEmployInsurance.Value).ToList();
                var contracts = new List<Hre_Contract>();
                var contractSocials = new List<Hre_Contract>();
                var contractUnEmps = new List<Hre_Contract>();
                if (contractSocialTypeIDObjs.Any())
                {
                    var contractSocialTypeIds = contractSocialTypeIDObjs.Select(p => p.ID).ToList();
                    var contractUnEmpTypeIds = contractUnEmpTypeIDObjs.Select(p => p.ID).ToList();
                    //Ds Hop Đồng của cac NV
                    contracts = hre_ContractRepo.FindBy(p => p.IsDelete == null && profileIds.Contains(p.ProfileID)).OrderBy(p => p.DateStart).ToList();
                    //Ds Hop đồng thuộc loại đóng BHXH
                    contractSocials = contracts.Where(p => contractSocialTypeIds.Contains(p.ContractTypeID)).OrderBy(p => p.DateStart).ToList();
                    //Ds Hop đồng thuộc loại đóng BHTN
                    contractUnEmps = contracts.Where(p => contractUnEmpTypeIds.Contains(p.ContractTypeID)).OrderBy(p => p.DateStart).ToList();
                }

                #endregion

                #region lấy Leaveday
                string E_APPROVED = LeaveDayStatus.E_APPROVED.ToString();
                string E_PREGNANCY_SUCKLE = InsuranceRecordType.E_PREGNANCY_SUCKLE.ToString();

                var lstLeaveday = att_LeaveDayRepo.FindBy(m => m.IsDelete == null && m.Status == E_APPROVED && m.DateStart <= dateTo && m.DateEnd >= dateFrom && m.Cat_LeaveDayType != null
                    && m.Cat_LeaveDayType.InsuranceType == E_PREGNANCY_SUCKLE && profileIds.Contains(m.ProfileID)).ToList();
                #endregion

                List<object> salInsuranceSalaryParams = new List<object>();
                salInsuranceSalaryParams.Add(null);
                salInsuranceSalaryParams.Add(null);
                salInsuranceSalaryParams.Add(orgIds);
                salInsuranceSalaryParams.Add(null);
                salInsuranceSalaryParams.Add(null);
                salInsuranceSalaryParams.Add(null);
                salInsuranceSalaryParams.Add(null);
                salInsuranceSalaryParams.Add(1);
                salInsuranceSalaryParams.Add(Int32.MaxValue - 1);
                var dateEnd = new DateTime(dateTo.Year, dateTo.Month, DateTime.DaysInMonth(dateTo.Year, dateTo.Month));
                var lstInsuranceSalaryByProfile = GetData<Sal_InsuranceSalary>(salInsuranceSalaryParams, ConstantSql.hrm_sal_sp_get_InsuranceSalary, userLogin, ref status)
                    .Where(p => p.DateEffect <= dateEnd && profileIds.Contains(p.ProfileID ?? Guid.Empty) && p.InsuranceAmount.HasValue).ToList();

                if (socialInsPlaceIDs != null)
                {
                    socialInsPlaceIDs = socialInsPlaceIDs.Where(p => p != null && p != Guid.Empty).ToList();
                    if (socialInsPlaceIDs != null && socialInsPlaceIDs.Any())
                    {
                        lstProfile = lstProfile.Where(p => socialInsPlaceIDs != null && socialInsPlaceIDs.Count > 0 && socialInsPlaceIDs.Contains(p.SocialInsPlaceID ?? Guid.Empty)).ToList();
                    }
                }



                foreach (var profile in profilebyOrgs)
                {
                    //lay các chung tu bao hiem cua nv
                    List<Ins_InsuranceRecord> lstInsRecordProfile = lstInsuranceRecord.Where(rec => rec.ProfileID == profile.ID).ToList();
                    var lstleavePregByProfile = lstLeaveday.Where(rec => rec.ProfileID == profile.ID).ToList();
                    var lstInsRecordPregByProfile = lstInsRecordProfile.Where(m => m.InsuranceType == E_PREGNANCY_SUCKLE).ToList();


                    var profileMonthlys = lstProfile.Where(p => p.ProfileID == profile.ID).OrderBy(p => p.MonthYear).ToList();



                    var inFirst = profileMonthlys.FirstOrDefault(p => p.MonthYear.HasValue && p.MonthYear.Value.Month == dateFrom.Month);
                    var inNow = profileMonthlys.LastOrDefault(p => p.MonthYear.HasValue && p.MonthYear.Value.Month == dateTo.Month);

                    if (inFirst == null)
                    {
                        inFirst = new Ins_ProfileInsuranceMonthly
                        {
                            IsHealthInsurance = false,
                            IsSocialInsurance = false,
                            IsUnEmpInsurance = false
                        };
                    }

                    if (inNow != null)
                    {
                        profile.JobName = inNow.JobName;
                        #region set Phu cap
                        if (inNow != null)
                        {
                            profile.Allowance1 = inNow.Allowance1;
                            profile.Allowance2 = inNow.Allowance2;
                            profile.Allowance3 = inNow.Allowance3;
                            profile.Allowance4 = inNow.Allowance4;
                        }
                        #endregion

                        #region Thống kê số lượng người đóng BHXH,BHYT,BHTN và tổng lương BHXH,BHTN,BHTN
                        if (inNow.IsSocialInsurance.HasValue && inNow.IsSocialInsurance.Value)
                        {
                            sociaInsCountPro++;
                            sociaInsTotalSalary += inNow.MoneySocialInsurance;
                        }
                        if (inNow.IsHealthInsurance.HasValue && inNow.IsHealthInsurance.Value)
                        {
                            healthInsCountPro++;
                            healthInsTotalSalary += inNow.MoneyHealthInsurance;
                        }
                        if (inNow.IsUnEmpInsurance.HasValue && inNow.IsUnEmpInsurance.Value)
                        {
                            unEmpInsCountPro++;
                            unEmpInsTotalSalary += inNow.MoneyUnEmpInsurance;
                        }
                        if (inNow.SalaryInsurance.HasValue && inNow.SalaryInsurance.Value > maxSalary)
                        {
                            maxSalary = inNow.SalaryInsurance.Value;
                        }
                        if (inNow.SalaryInsurance.HasValue && inNow.SalaryInsurance.Value < minSalary)
                        {
                            minSalary = inNow.SalaryInsurance.Value;
                        }
                        #endregion
                        
                        #region tang

                        if (IsIncreaseInsurance(inFirst, inNow) && (inCreaseCheck == true || allCheck == true))
                        {
                            String strPre = InsuranceRecordType.E_PREGNANCY_SUCKLE.ToString();
                            List<Ins_InsuranceRecord> lstInsPre = lstInsRecordProfile.Where(ins => ins.InsuranceType == strPre && ins.DateEnd > dateFrom && ins.DateEnd < dateTo).ToList();
                            String strSickLong = InsuranceRecordType.E_SICK_LONG.ToString();
                            String strSickShort = InsuranceRecordType.E_SICK_SHORT.ToString();
                            List<Ins_InsuranceRecord> lstInsSick = lstInsRecordProfile.Where(ins => ins.InsuranceType == strSickLong || ins.InsuranceType == strSickShort && ins.DayCount > 30
                                && ins.DateEnd > dateFrom && ins.DateEnd < dateTo).ToList();

                            #region Tăng LĐ
                            //lay ds hop dong cua NV
                            var contractProfile = contractSocials.Where(p => p.ProfileID == profile.ID).OrderBy(p => p.DateStart).FirstOrDefault();
                            Hre_Contract contract = null;
                            //lay hd moi nhat cua nv nằm trong khoảng 16-[N-1] đến 15-[N]
                            if (contractProfile != null && dateFromNewHONDA <= contractProfile.DateStart && contractProfile.DateStart <= dateToNewHONDA)
                            {
                                contract = contractProfile;
                            }

                            #region Tăng do Nghỉ 14 ngày đi làm lại

                            //Kiểm tra Tháng N-1 có ký HD ?    
                            //tang moi lao dong (Tháng N-1 ký HD nhưng chưa đóng BH do nghỉ hơn 14 ngày , Tháng N đóng bảo hiểm => thuoc loại tăng mới LĐ
                            if (inFirst.IsDecreaseWorkingDays.HasValue && inFirst.IsDecreaseWorkingDays.Value)
                            {
                                var contractDatefrom = new DateTime(dateFrom.Year, dateFrom.Month, 1);
                                var contractDateTo = contractDatefrom.AddMonths(1).AddDays(-1);
                                if (contractProfile != null && contractDatefrom <= contractProfile.DateStart && contractProfile.DateStart <= contractDateTo)
                                {
                                    //ký hợp đồng tháng trước
                                    SetHashtableData(htbData, profile, ref d02Reports, TypeInsuranceD02TS.E_TANG.ToString(), TypeInsuranceD02TS.E_TANG_LD.ToString(), inFirst.SalaryInsurance, inNow.SalaryInsurance, monthYear, orgStructures, "I.1");
                                }
                                else
                                {
                                    //tang do nghỉ 14 ngày đi làm lại
                                    SetHashtableData(htbData, profile, ref d02Reports, TypeInsuranceD02TS.E_TANG.ToString(), TypeInsuranceD02TS.E_TANG_LEAVE_14WORKINGDAYS.ToString(), inFirst.SalaryInsurance, inNow.SalaryInsurance, monthYear, orgStructures, "I.1");
                                }
                            }
                            #endregion

                            else if (contract != null)
                            {
                                //lay hd moi nhat cua nv nằm trong khoảng 16-[N-1] đến 15-[N]=>tăng lao động
                                SetHashtableData(htbData, profile, ref d02Reports, TypeInsuranceD02TS.E_TANG.ToString(), TypeInsuranceD02TS.E_TANG_LD.ToString(), inFirst.SalaryInsurance, inNow.SalaryInsurance, monthYear, orgStructures, "I.1");
                            }

                            #endregion

                            #region Tăng Thai Sản
                            else if (HasPregnant(dateTo.AddMonths(-1), lstleavePregByProfile, lstInsRecordPregByProfile))
                            {
                                SetHashtableData(htbData, profile, ref d02Reports, TypeInsuranceD02TS.E_TANG.ToString(), TypeInsuranceD02TS.E_TANG_TS.ToString(), inFirst.SalaryInsurance, inNow.SalaryInsurance, monthYear, orgStructures, "I.1");
                            }
                            #endregion

                            #region Tăng Bệnh
                            else if (lstInsSick.Count() > 0 /* && allCheck == false*/)
                            {
                                SetHashtableData(htbData, profile, ref d02Reports, TypeInsuranceD02TS.E_TANG.ToString(), TypeInsuranceD02TS.E_TANG_BENH.ToString(), inFirst.MoneySocialInsurance, inNow.MoneySocialInsurance, monthYear, orgStructures, "I.1");
                            }
                            #endregion

                            #region Honda - Tăng Đóng BHTN
                            else if ((!inFirst.IsUnEmpInsurance.HasValue || (inFirst.IsUnEmpInsurance.HasValue &&
                              !inFirst.IsUnEmpInsurance.Value))
                              && inNow.IsUnEmpInsurance.HasValue && inNow.IsUnEmpInsurance.Value)
                            {
                                var contractUnEmpProfile = contractUnEmps.Where(p => p.ProfileID == profile.ID).OrderBy(p => p.DateStart).FirstOrDefault();
                                if (contractUnEmpProfile != null && dateFrom <= contractUnEmpProfile.DateStart && contractUnEmpProfile.DateStart <= dateTo)
                                {
                                    SetHashtableData(htbData, profile, ref d02Reports, TypeInsuranceD02TS.E_TANG.ToString(), TypeInsuranceD02TS.E_TANG_BHTN.ToString(), inFirst.SalaryInsurance, inNow.SalaryInsurance, monthYear, orgStructures, "I.2");
                                }
                            }
                            #endregion

                            #region Tăng BHYT
                            else if ((!inFirst.IsHealthInsurance.HasValue || (inFirst.IsHealthInsurance.HasValue &&
                               !inFirst.IsHealthInsurance.Value))
                               && inNow.IsHealthInsurance.HasValue && inNow.IsHealthInsurance.Value)
                            {
                                SetHashtableData(htbData, profile, ref d02Reports, TypeInsuranceD02TS.E_TANG.ToString(), TypeInsuranceD02TS.E_TANG_BHYT.ToString(), inFirst.SalaryInsurance, inNow.SalaryInsurance, monthYear, orgStructures, "I.1");
                            }
                            #endregion

                        }
                        #endregion

                        #region giam
                        if (IsDecreaseInsurance(inFirst, inNow) && (descreaseCheck == true || allCheck == true))
                        {
                            String strPre = InsuranceRecordType.E_PREGNANCY_SUCKLE.ToString();
                            List<Ins_InsuranceRecord> lstInsPre = lstInsRecordProfile.Where(ins => ins.InsuranceType == strPre && ins.DateEnd > dateFrom && ins.DateStart < dateTo).ToList();
                            String strSickLong = InsuranceRecordType.E_SICK_LONG.ToString();
                            String strSickShort = InsuranceRecordType.E_SICK_SHORT.ToString();
                            List<Ins_InsuranceRecord> lstInsSick = lstInsRecordProfile.Where(ins => ins.InsuranceType == strSickLong && ins.InsuranceType == strSickShort
                                                                                                   && ins.DayCount > 30
                                                                                                   && ins.DateEnd > dateFrom && ins.DateEnd < dateTo).ToList();
                            if (inFirst.IsDecreaseWorkingDays == null)
                            {
                                inFirst.IsDecreaseWorkingDays = false;
                            }
                            if (inNow.IsDecreaseWorkingDays == null)
                            {
                                inNow.IsDecreaseWorkingDays = false;
                            }
                            #region giam

                            //neu NV nghỉ từ 16 tháng [N-1] đến 15 tháng N => Tạm Hoãn hoặc nghỉ luôn
                            if (profile.DateQuit.HasValue && dateFrom <= profile.DateQuit && profile.DateQuit <= dateTo)
                            {
                                #region Set trạng thái trả thẻ
                                var statusGiam_BHYT = string.Empty;
                                if (profile.ReceiveHealthIns.HasValue && profile.ReceiveHealthIns.Value)
                                {
                                    // Giam LD tra the 
                                    statusGiam_BHYT = TypeInsuranceD02TS.E_GIAM_LD_BHYT.ToString();
                                }
                                else if ((!profile.ReceiveHealthIns.HasValue || profile.ReceiveHealthIns == false))
                                {
                                    // Giảm Lao Động Không Trả Thẻ
                                    statusGiam_BHYT = TypeInsuranceD02TS.E_GIAM_LD_NOT_BHYT.ToString();
                                }
                                else
                                {
                                    // Giảm LĐ 
                                    statusGiam_BHYT = TypeInsuranceD02TS.E_GIAM_LD.ToString();
                                }
                                //HonDa
                                statusGiam_BHYT = TypeInsuranceD02TS.E_GIAM_LD_BHYT.ToString();
                                #endregion

                                if (profile.StopWorkType == EnumDropDown.StopWorkType.E_SUSPENSE.ToString())
                                {
                                    //tạm hoãn
                                    SetHashtableData(htbData, profile, ref d02Reports, TypeInsuranceD02TS.E_GIAM.ToString(), TypeInsuranceD02TS.E_GIAM_QUIT_SUSPENSE.ToString(), inFirst.SalaryInsurance, inNow.SalaryInsurance, monthYear, orgStructures, "II.1");
                                }
                                else if (!string.IsNullOrEmpty(statusGiam_BHYT))
                                {
                                    #region Nghỉ Việc Sau Khi Nghỉ Sinh Con
                                    if (HasPregnant(dateTo.AddMonths(-1), lstleavePregByProfile, lstInsRecordPregByProfile))
                                    {
                                        SetHashtableData(htbData, profile, ref d02Reports, TypeInsuranceD02TS.E_GIAM.ToString(), TypeInsuranceD02TS.E_GIAM_TS_QUIT.ToString(), inFirst.SalaryInsurance, inNow.SalaryInsurance, monthYear, orgStructures, "II.1");
                                    }
                                    else
                                    {
                                        SetHashtableData(htbData, profile, ref d02Reports, TypeInsuranceD02TS.E_GIAM.ToString(), statusGiam_BHYT, inFirst.SalaryInsurance, inNow.SalaryInsurance, monthYear, orgStructures, "II.1");
                                    }
                                    #endregion
                                }
                            }

                            #region Giam Thai San
                            else if (HasPregnant(dateTo, lstleavePregByProfile, lstInsRecordPregByProfile) 
                                && (!profile.DateQuit.HasValue || profile.DateQuit.Value > dateTo))
                            {
                                if (lstProfilePregnant == null)
                                {
                                    //chỉ lay 1 lần
                                    #region lay ins_ProfileInsuranceMonthly de tinh thai san 1 nam lien ke
                                    var dtPreDateCheck = dateFrom.AddYears(-1);
                                    //Lấy Ds Ins_ProfileInsuranceMonthly 12 tháng trước so với tháng kiểm tra (de tinh thai san 1 nam lien ke)
                                    lstProfilePregnant = lstProfileInsuranceMonthlyInDb.Where(s => s.MonthYear.HasValue
                                        && (dtPreDateCheck <= s.MonthYear.Value && s.MonthYear <= dateFrom)).ToList();
                                    #endregion
                                }

                                // Nhân viên đóng bảo hiểm đủ 6 tháng trong vòng 12 tháng liền kề
                                var insCount = lstProfilePregnant.Where(p => p.ProfileID == profile.ID && p.IsSocialInsurance.HasValue && p.IsSocialInsurance.Value).Count();
                                if (insCount >= 6)
                                {
                                    SetHashtableData(htbData, profile, ref d02Reports, TypeInsuranceD02TS.E_GIAM.ToString(), TypeInsuranceD02TS.E_GIAM_TS.ToString(), inFirst.SalaryInsurance, inNow.SalaryInsurance, monthYear, orgStructures, "II.1");
                                }
                                else
                                {
                                    SetHashtableData(htbData, profile, ref d02Reports, TypeInsuranceD02TS.E_GIAM.ToString(), TypeInsuranceD02TS.E_GIAM_LEAVE_14WORKINGDAYS.ToString(), inFirst.SalaryInsurance, inNow.SalaryInsurance, monthYear, orgStructures, "II.1");
                                }
                            }

                            #endregion

                            #region Giam benh
                            else if (lstInsSick.Count() > 0 /*&& allCheck == false*/)
                            {
                                SetHashtableData(htbData, profile, ref d02Reports, TypeInsuranceD02TS.E_GIAM.ToString(), TypeInsuranceD02TS.E_GIAM_BENH.ToString(), inFirst.SalaryInsurance, inNow.SalaryInsurance, monthYear, orgStructures, "II.1");
                            }
                            #endregion

                            #region giam do Nghỉ 14 ngày đi làm lại

                            // tháng N là false (hoac null) => Giảm do nghỉ >= 14 ngày                            
                            else if (inNow.IsDecreaseWorkingDays.HasValue && inNow.IsDecreaseWorkingDays.Value)
                            {
                                SetHashtableData(htbData, profile, ref d02Reports, TypeInsuranceD02TS.E_GIAM.ToString(), TypeInsuranceD02TS.E_GIAM_LEAVE_14WORKINGDAYS.ToString(), inFirst.SalaryInsurance, inNow.SalaryInsurance, monthYear, orgStructures, "II.1");
                            }
                            #endregion

                            #endregion
                        }//ket thuc giảm
                        #endregion

                        #region Thay doi luong

                        else if (inFirst != null && inFirst.SalaryInsurance != inNow.SalaryInsurance)
                        {
                            //-------Giam luong
                            if (inFirst != null && inFirst.SalaryInsurance > inNow.SalaryInsurance)
                            {
                                #region giảm lương và thay đổi chức danh nghề
                                if (inFirst.JobName != inNow.JobName)
                                {
                                    //giảm lương và thay đổi chức danh nghề
                                    SetHashtableData(htbData, profile, ref d02Reports, TypeInsuranceD02TS.E_GIAM_LUONG_CHANGEJOBNAME.ToString(), TypeInsuranceD02TS.E_GIAM_LUONG_CHANGEJOBNAME.ToString(), inFirst.SalaryInsurance, inNow.SalaryInsurance, monthYear, orgStructures, "IV.");
                                }
                                #endregion
                                #region Giảm Lương
                                else
                                {
                                    //giảm lương
                                    SetHashtableData(htbData, profile, ref d02Reports, TypeInsuranceD02TS.E_GIAM.ToString(), TypeInsuranceD02TS.E_GIAM_LUONG.ToString(), inFirst.SalaryInsurance, inNow.SalaryInsurance, monthYear, orgStructures, "IV.");
                                }
                                #endregion
                            }
                            //------------Tang luong-----------
                            else if (inFirst != null && inFirst.SalaryInsurance < inNow.SalaryInsurance)
                            {
                                #region tăng lương và thay đổi chức danh nghề
                                if (inFirst.JobName != inNow.JobName)
                                {
                                    //tăng lương và thay đổi chức danh nghề
                                    SetHashtableData(htbData, profile, ref d02Reports, TypeInsuranceD02TS.E_TANG_LUONG_CHANGEJOBNAME.ToString(), TypeInsuranceD02TS.E_TANG_LUONG_CHANGEJOBNAME.ToString(), inFirst.SalaryInsurance, inNow.SalaryInsurance, monthYear, orgStructures, "III.");
                                }
                                #endregion
                                #region tăng lương
                                else
                                {
                                    //tăng lương 
                                    SetHashtableData(htbData, profile, ref d02Reports, TypeInsuranceD02TS.E_TANG.ToString(), TypeInsuranceD02TS.E_TANG_LUONG.ToString(), inFirst.SalaryInsurance, inNow.SalaryInsurance, monthYear, orgStructures, "III.");
                                }
                                #endregion
                            }
                        }
                        #endregion

                        #region Thay đổi chức danh nghề (không đổi lương)
                        //Thay đổi chức danh nghề (không đổi lương)
                        if (inFirst != null && inNow != null && inFirst.SalaryInsurance == inNow.SalaryInsurance && inFirst.JobName != inNow.JobName)
                        {
                            SetHashtableData(htbData, profile, ref d02Reports, TypeInsuranceD02TS.E_CHANGEJOBNAME.ToString(), TypeInsuranceD02TS.E_CHANGEJOBNAME.ToString(), inFirst.SalaryInsurance, inNow.SalaryInsurance, monthYear, orgStructures, "V.");
                        }
                        #endregion

                        #region Trường Hợp đặc biệt (Honda)

                        #region Tháng N-1 nghỉ Thai Sản và tháng N nghỉ luon =>Nghỉ luôn sau thai sản
                        if (inFirst != null && inFirst.IsPregnant.HasValue && inFirst.IsPregnant.Value
                            && inNow != null && (inNow.IsPregnant == null || inNow.IsPregnant.Value == false)
                            && profile.DateQuit.HasValue && dateFrom <= profile.DateQuit && profile.DateQuit <= dateTo)                       
                        {
                            //>Nghỉ luôn sau thai sản
                            SetHashtableData(htbData, profile, ref d02Reports, TypeInsuranceD02TS.E_GIAM.ToString(), TypeInsuranceD02TS.E_GIAM_TS_QUIT.ToString(), inFirst.SalaryInsurance, inNow.SalaryInsurance, monthYear, orgStructures, "II.1");
                        }
                        #region Tháng N-1 nghỉ Thai Sản và tháng N nghỉ hơn 14 ngày => Nghỉ 14 ngày sau thai sản
                        else if (inNow != null && inNow.IsDecreaseWorkingDays.HasValue && inNow.IsDecreaseWorkingDays.Value
                            && HasPregnant(dateTo.AddMonths(-1), lstleavePregByProfile, lstInsRecordPregByProfile)
                            && (inNow.IsPregnant == null || inNow.IsPregnant.Value == false))
                        {
                            //Giảm do nghỉ hơn 14 ngày sau thai sản
                            SetHashtableData(htbData, profile, ref d02Reports, TypeInsuranceD02TS.E_GIAM.ToString(), TypeInsuranceD02TS.E_GIAM_PREGNANT_14WORKINGDAYS.ToString(), inFirst.SalaryInsurance, inNow.SalaryInsurance, monthYear, orgStructures, "II.1");
                        }
                        #endregion
                        #endregion

                        #region tháng N-1 giảm 14 ngày và tháng này nghỉ việc
                        if (profile != null && inFirst != null && inNow != null
                            && !HasPregnant(dateTo.AddMonths(-1), lstleavePregByProfile, lstInsRecordPregByProfile)
                            && inFirst.IsDecreaseWorkingDays.HasValue && inFirst.IsDecreaseWorkingDays.Value
                            && profile.DateQuit.HasValue && dateFrom <= profile.DateQuit && profile.DateQuit <= dateTo)
                        {
                            //Nghỉ việc mà trước đó nghỉ >=14 ngày
                            SetHashtableData(htbData, profile, ref d02Reports, TypeInsuranceD02TS.E_GIAM.ToString(), TypeInsuranceD02TS.E_GIAM_LEAVE_PREMONTH_14WORKINGDAYS.ToString(), inFirst.SalaryInsurance, inNow.SalaryInsurance, monthYear, orgStructures, "II.1");
                        }
                        #endregion

                      
                        
                        #region Nghiệp Vụ Chuyển Nơi Đóng BH (Honda)
                        if (inFirst != null && inNow != null 
                            && (inFirst.SocialInsPlaceID.HasValue && inFirst.SocialInsPlaceID.Value != Guid.Empty) 
                            && (inNow.SocialInsPlaceID.HasValue && inNow.SocialInsPlaceID.Value != Guid.Empty)
                            && (inFirst.SocialInsPlaceID.Value != inNow.SocialInsPlaceID.Value))
                        {
                            //thang truoc giam do chuyen noi dong bao hiem
                            profile.JobName = string.Copy(inFirst.JobName);
                            SetHashtableData(htbData, profile, ref d02Reports, TypeInsuranceD02TS.E_TANG.ToString(), TypeInsuranceD02TS.E_TANG_LD_CHANGE_INSPLACE.ToString(), inFirst.SalaryInsurance, inNow.SalaryInsurance, monthYear, orgStructures, "I.1");
                            //thang check tang do chuyen noi dong bao hiem
                            profile.JobName = string.Copy(inNow.JobName);
                            SetHashtableData(htbData, profile, ref d02Reports, TypeInsuranceD02TS.E_GIAM.ToString(), TypeInsuranceD02TS.E_GIAM_LD_CHANGE_INSPLACE.ToString(), inFirst.SalaryInsurance, inNow.SalaryInsurance, monthYear, orgStructures, "II.1");
                        }
                        #endregion

                        #endregion

                    }
                }//ket thuc foreach profile
            }

            //duyet hashtable => danh sach nv theo loai bao hiem (tangLd,tangBHXH,.....)
            var result = new List<Ins_InsuranceReportD02Entity>();
            var tang = TypeInsuranceD02TS.E_TANG.ToString();
            var giam = TypeInsuranceD02TS.E_GIAM.ToString();
            var tangLD = TypeInsuranceD02TS.E_GIAM_LD.ToString();
            foreach (DictionaryEntry entry in htbData)
            {
                var lst = new List<Ins_InsuranceReportD02Entity>();
                lst = (List<Ins_InsuranceReportD02Entity>)entry.Value;
                var d02Entity = lst.FirstOrDefault(p => p.OrderGroup != null);
                var orderGroup = string.Empty;
                if (d02Entity != null)
                {
                    orderGroup = d02Entity.OrderGroup;
                }

                var proName = entry.Key.ToString();
                if (!string.IsNullOrEmpty(proName))
                {
                    proName = GetDescription(proName);
                }
                var title = new Ins_InsuranceReportD02Entity()
                {
                    ProfileID = Guid.Empty,
                    ProfileName = proName,
                    OrderGroup = orderGroup,
                    CodeEmp = orderGroup,
                    BOLD = true.ToString()
                };

                lst.Insert(0, title);
                if (lst.Any(p => p.Status1 == tang) && !result.Any(p => p.Status == tangLD) && !result.Any(p => p.ProfileName == "Tăng"))
                {
                    lst.Insert(0, new Ins_InsuranceReportD02Entity { ProfileID = Guid.Empty, ProfileName = "Tăng", CodeEmp = "I", OrderGroup = "I" });
                }
                if (lst.Any(p => p.Status1 == giam) && !result.Any(p => p.ProfileName == "Giảm"))
                {
                    lst.Insert(0, new Ins_InsuranceReportD02Entity { ProfileID = Guid.Empty, ProfileName = "Giảm", CodeEmp = "II", OrderGroup = "II" });
                }
                //if (lst.Any(p => p.Status == TypeInsuranceD02TS.E_GIAM_LD.ToString()) && !result.Any(p => p.Status1 == giam) && !result.Any(p => p.ProfileName == "Giảm Lao Động"))
                //{
                //    lst.Insert(0, new Ins_InsuranceReportD02Entity { ProfileName = "Giảm Lao Động", CodeEmp = "II", OrderGroup = "II" });
                //}

                result.AddRange(lst);
            }

            result = result.OrderBy(p => p.OrderGroup).ToList();

            #region compute D02

            var periodIns = EnumDropDown.GetEnumDescription<PeriodInsurance>(PeriodInsurance.GETTEMP);
            var d02 = new Ins_ReportD02Entity
            {
                DateReport = DateTime.Now,
                SociaInsCountPro = sociaInsCountPro,
                SociaInsTotalSalary = sociaInsTotalSalary,
                HealthInsCountPro = healthInsCountPro,
                HealthInsTotalSalary = healthInsTotalSalary,
                UnEmpInsCountPro = unEmpInsCountPro,
                UnEmpInsTotalSalary = unEmpInsTotalSalary,
                MaxSalary = maxSalary,
                MinSalary = minSalary,
                Type = PeriodInsurance.GETTEMP.ToString()
            };
            //luu D02
            ComputeD02(result, d02, monthYear, dateFrom, dateTo, periodIns);
            #endregion

            return result;
        }
コード例 #2
0
        public List<Ins_InsuranceReportD03Entity> LoadDataD03(bool? all, bool? increase, bool? descrease, DateTime? dtMonthYear, string orgIds, string searchNoteType, string searchStatus, string codeEmp, List<Guid> workPlaceIDs, string userLogin)
        {

            var monthYear = dtMonthYear ?? DateTime.Now;
            DateTime dateFrom = monthYear.AddMonths(-1);
            dateFrom = new DateTime(dateFrom.Year, dateFrom.Month, InsuranceServices.PeriodInsuranceDayPreMonthDefault);
            DateTime dateTo = new DateTime(monthYear.Year, monthYear.Month, InsuranceServices.PeriodInsuranceDayCurrentMonthDefault);
            var status = string.Empty;
            var allCheck = all ?? false;
            var inCreaseCheck = increase ?? false;
            var descreaseCheck = descrease ?? false;


            //lay ds Ins_ProfileInsuranceMonthly
            //List<object> listInsMonthlyObj = new List<object>();
            //listInsMonthlyObj.Add(orgs);
            //listInsMonthlyObj.Add(monthYear);
            //var profileInsMonthlys = GetData<Hre_ProfileEntity>(listInsMonthlyObj, ConstantSql.hrm_ins_sp_get_ProfileInsMonthly, ref status);
            Hashtable htbData = new Hashtable();
            var d02Reports = new List<Ins_InsuranceReportD02Entity>();
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var profileInsMonthly = new Ins_ProfileInsuranceMonthlyRepository(unitOfWork);
                var orgStructureRepo = new Cat_OrgStructureRepository(unitOfWork);
                var insInsuranceRecord = new Ins_InsuranceRecordRepository(unitOfWork);
                var hre_ContractRepo = new Hre_ContractRepository(unitOfWork);
                var cat_ContractTypeRepo = new Cat_ContractTypeRepository(unitOfWork);
                var att_LeaveDayRepo = new Att_LeavedayRepository(unitOfWork);

                #region Lấy DS Ins_ProfileInsuranceMonthly (lấy tất cả)
                var listInsMonthlyObj = new List<object> { orgIds, null, null, 1, int.MaxValue - 1 };
                if (Common.UseDataBaseName == DATABASETYPE.SQLSERVER.ToString())
                {
                    listInsMonthlyObj.Add("id");
                }
                var lstProfileInsuranceMonthlyInDb = GetData<Ins_ProfileInsuranceMonthlyEntity>(listInsMonthlyObj, ConstantSql.hrm_ins_sp_get_ProfileInsMonthly, userLogin, ref status);
                #endregion

                //get profiles trong Ins_ProfileInsuranceMonthly theo thang kiểm tra
                var lstProfile = lstProfileInsuranceMonthlyInDb.Where(s => s.MonthYear.HasValue
                    && (s.MonthYear.Value.Year == dateFrom.Year || s.MonthYear.Value.Year == dateTo.Year)
                    && (s.MonthYear.Value.Month == dateFrom.Month || s.MonthYear.Value.Month == dateTo.Month))
                    .ToList().Translate<Ins_ProfileInsuranceMonthly>();

                #region lay ins_ProfileInsuranceMonthly de tinh thai san 1 nam lien ke
                var dtPreDateCheck = dateFrom.AddYears(-1);
                //Lấy Ds Ins_ProfileInsuranceMonthly 12 tháng trước so với tháng kiểm tra (de tinh thai san 1 nam lien ke)
                var lstProfilePregnant = lstProfileInsuranceMonthlyInDb.Where(s => s.MonthYear.HasValue
                    && (dtPreDateCheck <= s.MonthYear.Value && s.MonthYear <= dateFrom)).ToList();
                #endregion


                //var lstProfile = profileInsMonthly.FindBy(s => s.IsDelete == null && s.MonthYear.HasValue
                //    && (s.MonthYear.Value.Year == dateFrom.Year || s.MonthYear.Value.Year == dateTo.Year)
                //    && (s.MonthYear.Value.Month == dateFrom.Month || s.MonthYear.Value.Month == dateTo.Month)).ToList();

                //get InsuranceRecord (Chứng từ bảo hiểm)
                //var lstInsuranceRecord = insInsuranceRecord.GetAll().Where(p => p.IsDelete == null).ToList();// lay tat ca chứng từ bảo hiểm (sau nay sửa lai sau)


                #region Lay ds Phong Ban
                var orgs = GetDataNotParam<Cat_OrgStructure>(ConstantSql.hrm_cat_sp_get_AllOrg, userLogin, ref status).ToList();
                List<Cat_OrgStructureEntity> orgStructures = orgs.Translate<Cat_OrgStructureEntity>();
                // var orgs = orgStructureRepo.GetAll();
                //  var orgIds = orgs.Select(p => p.ID).ToList();
                #endregion

                #region Lấy profile theo phong ban
                List<object> listObj = new List<object>();
                listObj.Add(orgIds);
                listObj.Add(string.Empty);
                listObj.Add(string.Empty);
                var profilebyOrgs = GetData<Hre_ProfileEntity>(listObj, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrg, userLogin, ref status);
                if (profilebyOrgs != null)
                {
                    profilebyOrgs = profilebyOrgs.Where(p => p.DateHire != null
                                && (p.DateQuit == null || p.DateQuit > dateFrom)
                                && p.DateHire < monthYear).ToList();
                }
                if (!string.IsNullOrEmpty(codeEmp))
                {
                    profilebyOrgs = profilebyOrgs.Where(p => p.CodeEmp == codeEmp).ToList();
                }

                var profileIds = profilebyOrgs.Select(p => p.ID).ToList();
                #endregion

                #region  lay ds hop dong đã ký so với tháng chọn (Loại HD có đóng BH)
                //var contractTypeObjs = cat_ContractTypeRepo.FindBy(p => p.IsDelete == null).ToList();
                ////Ds loại HĐ đóng BHXH
                //var contractSocialTypeIDObjs = contractTypeObjs.Where(p => p.IsSocialInsurance.HasValue && p.IsSocialInsurance.Value).ToList();
                ////Ds loại HĐ đóng BHTN
                //var contractUnEmpTypeIDObjs = contractTypeObjs.Where(p => p.IsUnEmployInsurance.HasValue && p.IsUnEmployInsurance.Value).ToList();
                //var contracts = new List<Hre_Contract>();
                //var contractSocials = new List<Hre_Contract>();
                //var contractUnEmps = new List<Hre_Contract>();
                //if (contractSocialTypeIDObjs.Any())
                //{
                //    var contractSocialTypeIds = contractSocialTypeIDObjs.Select(p => p.ID).ToList();
                //    var contractUnEmpTypeIds = contractUnEmpTypeIDObjs.Select(p => p.ID).ToList();
                //    //Ds Hop Đồng của cac NV
                //    contracts = hre_ContractRepo.FindBy(p => p.IsDelete == null && profileIds.Contains(p.ProfileID)).OrderBy(p => p.DateStart).ToList();
                //    //Ds Hop đồng thuộc loại đóng BHXH
                //    contractSocials = contracts.Where(p => contractSocialTypeIds.Contains(p.ContractTypeID)).OrderBy(p => p.DateStart).ToList();
                //    //Ds Hop đồng thuộc loại đóng BHTN
                //    contractUnEmps = contracts.Where(p => contractUnEmpTypeIds.Contains(p.ContractTypeID)).OrderBy(p => p.DateStart).ToList();
                //}

                #endregion

                #region lấy Leaveday
                //string E_APPROVED = LeaveDayStatus.E_APPROVED.ToString();
                //string E_PREGNANCY_SUCKLE = InsuranceRecordType.E_PREGNANCY_SUCKLE.ToString();

                //var lstLeaveday = att_LeaveDayRepo.FindBy(m => m.IsDelete == null && m.Status == E_APPROVED && m.DateStart <= dateTo && m.DateEnd >= dateFrom && m.Cat_LeaveDayType != null
                //    && m.Cat_LeaveDayType.InsuranceType == E_PREGNANCY_SUCKLE && profileIds.Contains(m.ProfileID)).ToList();
                #endregion

                //List<object> salInsuranceSalaryParams = new List<object>();
                //salInsuranceSalaryParams.Add(null);
                //salInsuranceSalaryParams.Add(null);
                //salInsuranceSalaryParams.Add(orgIds);
                //salInsuranceSalaryParams.Add(null);
                //salInsuranceSalaryParams.Add(null);
                //salInsuranceSalaryParams.Add(null);
                //salInsuranceSalaryParams.Add(null);
                //salInsuranceSalaryParams.Add(1);
                //salInsuranceSalaryParams.Add(50000);
                //var lstInsuranceSalaryByProfile = GetData<Sal_InsuranceSalary>(salInsuranceSalaryParams, ConstantSql.hrm_sal_sp_get_InsuranceSalary, ref status)
                //    .Where(p => p.DateEffect <= dateTo && profileIds.Contains(p.ProfileID ?? Guid.Empty) && p.InsuranceAmount.HasValue).ToList();


                if (workPlaceIDs != null && workPlaceIDs.Any())
                {
                    workPlaceIDs = workPlaceIDs.Where(p => p != null && p != Guid.Empty).ToList();
                    if (workPlaceIDs.Any())
                    {
                        lstProfile = lstProfile.Where(p => workPlaceIDs != null && workPlaceIDs.Count > 0 && workPlaceIDs.Contains(p.WorkPlaceID ?? Guid.Empty)).ToList();
                    }
                }

                // workPlaceID = workPlaceID.Where(p => p != null).ToList();
                foreach (var profile in profilebyOrgs)
                {
                    //lay các chung tu bao hiem cua nv
                    //    List<Ins_InsuranceRecord> lstInsRecordProfile = lstInsuranceRecord.Where(rec => rec.ProfileID == profile.ID).ToList();
                    //    var lstleavePregByProfile = lstLeaveday.Where(rec => rec.ProfileID == profile.ID).ToList();
                    //   var lstInsRecordPregByProfile = lstInsRecordProfile.Where(m => m.InsuranceType == E_PREGNANCY_SUCKLE).ToList();


                    var profileMonthlys = lstProfile.Where(p => p.ProfileID == profile.ID).OrderBy(p => p.MonthYear).ToList();



                    var inFirst = profileMonthlys.FirstOrDefault(p => p.MonthYear.HasValue && p.MonthYear.Value.Month == dateFrom.Month);
                    var inNow = profileMonthlys.LastOrDefault(p => p.MonthYear.HasValue && p.MonthYear.Value.Month == dateTo.Month);

                    if (inFirst == null)
                    {
                        inFirst = new Ins_ProfileInsuranceMonthly
                        {
                            IsHealthInsurance = false,
                            IsSocialInsurance = false,
                            IsUnEmpInsurance = false
                        };
                    }

                    if (inNow != null)
                    {
                        profile.JobName = inNow.JobName;
                        #region set Phu cap
                        if (inNow != null)
                        {
                            profile.Allowance1 = inNow.Allowance1;
                            profile.Allowance2 = inNow.Allowance2;
                            profile.Allowance3 = inNow.Allowance3;
                            profile.Allowance4 = inNow.Allowance4;
                        }
                        #endregion

                        #region tang

                        if (IsIncreaseInsurance(inFirst, inNow) && (inCreaseCheck == true || allCheck == true))
                        {

                            #region Tăng BHYT
                            if ((!inFirst.IsHealthInsurance.HasValue || (inFirst.IsHealthInsurance.HasValue &&
                               !inFirst.IsHealthInsurance.Value))
                               && inNow.IsHealthInsurance.HasValue && inNow.IsHealthInsurance.Value)
                            {
                                SetHashtableData(htbData, profile, ref d02Reports, TypeInsuranceD02TS.E_TANG.ToString(), TypeInsuranceD02TS.E_TANG_BHYT.ToString(), inFirst.SalaryInsurance, inNow.SalaryInsurance, monthYear, orgStructures, "I");
                            }
                            #endregion

                        }
                        #endregion

                        #region giam
                        if (IsDecreaseInsurance(inFirst, inNow) && (descreaseCheck == true || allCheck == true))
                        {
                            #region giam
                            if ((inFirst.IsHealthInsurance.HasValue && inFirst.IsHealthInsurance.Value)
                            && !inNow.IsHealthInsurance.HasValue || (inNow.IsHealthInsurance.HasValue && !inNow.IsHealthInsurance.Value))
                            {
                                SetHashtableData(htbData, profile, ref d02Reports, TypeInsuranceD02TS.E_GIAM.ToString(), TypeInsuranceD02TS.E_GIAM_BHYT.ToString(), inFirst.SalaryInsurance, inNow.SalaryInsurance, monthYear, orgStructures, "II");
                            }
                            #endregion
                        }
                        #endregion

                    }
                }
            }

            //duyet hashtable => danh sach nv theo loai bao hiem (tangLd,tangBHXH,.....)
            var result = new List<Ins_InsuranceReportD02Entity>();
            var tang = TypeInsuranceD02TS.E_TANG.ToString();
            var giam = TypeInsuranceD02TS.E_GIAM.ToString();
            var tangLD = TypeInsuranceD02TS.E_GIAM_LD.ToString();
            foreach (DictionaryEntry entry in htbData)
            {
                var lst = new List<Ins_InsuranceReportD02Entity>();
                lst = (List<Ins_InsuranceReportD02Entity>)entry.Value;
                // lst = lst.OrderBy(p => p.STT).ToList();
                var d02Entity = lst.FirstOrDefault(p => p.OrderGroup != null);
                var orderGroup = string.Empty;
                if (d02Entity != null)
                {
                    orderGroup = d02Entity.OrderGroup;
                }

                var proName = entry.Key.ToString();
                if (!string.IsNullOrEmpty(proName))
                {
                    proName = GetDescription(proName);
                }
                var title = new Ins_InsuranceReportD02Entity()
                {
                    ProfileID = Guid.Empty,
                    ProfileName = proName,
                    OrderGroup = orderGroup,
                    CodeEmp = orderGroup,
                    BOLD = true.ToString()
                };

                lst.Insert(0, title);
                if (lst.Any(p => p.Status1 == tang) && !result.Any(p => p.Status == tangLD) && !result.Any(p => p.ProfileName == "Tăng"))
                {
                    lst.Insert(0, new Ins_InsuranceReportD02Entity { ProfileID = Guid.Empty, ProfileName = "Tăng", CodeEmp = "I", OrderGroup = "I" });
                }
                if (lst.Any(p => p.Status1 == giam) && !result.Any(p => p.ProfileName == "Giảm"))
                {
                    lst.Insert(0, new Ins_InsuranceReportD02Entity { ProfileID = Guid.Empty, ProfileName = "Giảm", CodeEmp = "II", OrderGroup = "II" });
                }
                //if (lst.Any(p => p.Status == TypeInsuranceD02TS.E_GIAM_LD.ToString()) && !result.Any(p => p.Status1 == giam) && !result.Any(p => p.ProfileName == "Giảm Lao Động"))
                //{
                //    lst.Insert(0, new Ins_InsuranceReportD02Entity { ProfileName = "Giảm Lao Động", CodeEmp = "II", OrderGroup = "II" });
                //}
                result.AddRange(lst);

            }

            result = result.Where(p => p.ProfileName != "Tăng Lao Động").ToList();
            result = result.Where(p => p.ProfileName != "Giảm BHYT").ToList();
            //var result = LoadData(all, increase, descrease, dtMonthYear, orgIds, searchNoteType, searchStatus, codeEmp, workPlaceIDs);
            //var E_TANG_BHYT = TypeInsuranceD02TS.E_TANG_BHYT.ToString();
            //var E_GIAM_BHYT = TypeInsuranceD02TS.E_GIAM_BHYT.ToString();
            //result = result.Where(p => p.Status == E_TANG_BHYT || p.Status == E_GIAM_BHYT).ToList();
            var listD03 = new List<Ins_InsuranceReportD03Entity>();
            foreach (var item in result)
            {
                var d03 = item.Copy<Ins_InsuranceReportD03Entity>();
                listD03.Add(d03);
            }
            return listD03.OrderBy(p => p.OrderGroup).ToList();
        }
コード例 #3
0
        /// <summary> Tìm kiếm bc D02TS (Hien tai chua dùng toi method này) </summary>
        /// <param name="all"></param>
        /// <param name="increase"></param>
        /// <param name="descrease"></param>
        /// <param name="dtMonthYear"></param>
        /// <param name="orgIds"></param>
        /// <returns></returns>
        public List<Ins_InsuranceReportD02Entity> SearchD02TS(bool? all, bool? increase, bool? descrease, DateTime? dtMonthYear, string orgIds, string searchNoteType, string searchStatus, string codeEmp, List<Guid> socialInsPlaceIDs, string userLogin)
        {
            var periodIns = EnumDropDown.GetEnumDescription<PeriodInsurance>(PeriodInsurance.GETTEMP);
            List<Ins_InsuranceReportD02Entity> lstInsuranceReportD02 = new List<Ins_InsuranceReportD02Entity>();
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoReportD02 = new Ins_ReportD02Repository(unitOfWork);
                var repoReportD02Item = new Ins_ReportD02ItemRepository(unitOfWork);
                var repoProfileInsMonthly = new Ins_ProfileInsuranceMonthlyRepository(unitOfWork);
                string status = string.Empty;
                var monthYear = dtMonthYear ?? DateTime.Now;
                DateTime dateFrom = monthYear.AddMonths(-1);
                dateFrom = new DateTime(dateFrom.Year, dateFrom.Month, InsuranceServices.PeriodInsuranceDayPreMonthDefault);
                DateTime dateTo = new DateTime(monthYear.Year, monthYear.Month, InsuranceServices.PeriodInsuranceDayCurrentMonthDefault);

                #region Lấy DS Ins_ProfileInsuranceMonthly (lấy tất cả)
                var listInsMonthlyObj = new List<object> { orgIds, monthYear, null, 1, int.MaxValue - 1 };
                if (Common.UseDataBaseName == DATABASETYPE.SQLSERVER.ToString())
                {
                    listInsMonthlyObj.Add("id");
                }
                var lstProfileInsuranceMonthlyInDb = GetData<Ins_ProfileInsuranceMonthlyEntity>(listInsMonthlyObj, ConstantSql.hrm_ins_sp_get_ProfileInsMonthly, userLogin, ref status);
                #endregion

                var lstProfileInsMonthly = lstProfileInsuranceMonthlyInDb.Where(s => s.MonthYear.HasValue
                   && (s.MonthYear.Value.Year == dateFrom.Year || s.MonthYear.Value.Year == dateTo.Year)
                   && (s.MonthYear.Value.Month == dateFrom.Month || s.MonthYear.Value.Month == dateTo.Month)).ToList();

                //tự sinh ra kỳ
                var cutOfDuration = "Kỳ " + periodIns + " - " + monthYear.ToString(ConstantFormat.HRM_Format_MonthYear);

                #region Get D02
                List<object> listD02Obj = new List<object>();
                listD02Obj.Add(null);
                listD02Obj.Add(dtMonthYear);
                listD02Obj.Add(cutOfDuration);
                var d02 = GetData<Ins_ReportD02>(listD02Obj, ConstantSql.hrm_ins_sp_get_D02, userLogin, ref status).FirstOrDefault();
                #endregion

                if (d02 != null)
                {
                    List<object> listD02ItemObj = new List<object>();
                    listD02ItemObj.Add(d02.ID);
                    listD02ItemObj.Add(codeEmp);
                    var d02Item = GetData<Ins_ReportD02ItemEntity>(listD02ItemObj, ConstantSql.hrm_ins_sp_get_D02ItemByD02ID, userLogin, ref status);

                    if (socialInsPlaceIDs != null && socialInsPlaceIDs.Any())
                    {
                        socialInsPlaceIDs = socialInsPlaceIDs.Where(p => p != null && p != Guid.Empty).ToList();
                        if (socialInsPlaceIDs.Any())
                        {
                            d02Item = d02Item.Where(p => socialInsPlaceIDs.Contains(p.SocialInsPlaceID ?? Guid.Empty)).ToList();
                        }
                    }


                    var monthYear1 = new DateTime(monthYear.Year, monthYear.Month, 1);
                    var isHonda = true;
                    foreach (var insReportD02Item in d02Item)
                    {
                        var profileMonthlys = lstProfileInsMonthly.Where(p => p.ProfileID == insReportD02Item.ProfileID && p.MonthYear == monthYear1).FirstOrDefault();
                        var d02Status = insReportD02Item.Status;
                        if (profileMonthlys != null)
                        {
                            #region Honda

                            if (isHonda)
                            {
                                if (insReportD02Item.Status == TypeInsuranceD02TS.E_TANG_TS.ToString() || insReportD02Item.Status == TypeInsuranceD02TS.E_TANG_LEAVE_14WORKINGDAYS.ToString()
                                    || insReportD02Item.Status == TypeInsuranceD02TS.E_TANG_BENH.ToString() || insReportD02Item.Status == TypeInsuranceD02TS.E_TANG_BHYT.ToString()
                                    || insReportD02Item.Status == TypeInsuranceD02TS.E_TANG_LEAVE_14WORKINGDAYS.ToString()
                                    || insReportD02Item.Status == TypeInsuranceD02TS.E_TANG_LD_CHANGE_INSPLACE.ToString())
                                {
                                    d02Status = TypeInsuranceD02TS.E_TANG_LD.ToString();
                                }
                                if (insReportD02Item.Status == TypeInsuranceD02TS.E_GIAM_TS_QUIT.ToString() || insReportD02Item.Status == TypeInsuranceD02TS.E_GIAM_TS.ToString()
                                    || insReportD02Item.Status == TypeInsuranceD02TS.E_GIAM_BENH.ToString() || insReportD02Item.Status == TypeInsuranceD02TS.E_GIAM_LD_BHYT.ToString()
                                    || insReportD02Item.Status == TypeInsuranceD02TS.E_GIAM_LD_NOT_BHYT.ToString()
                                    || insReportD02Item.Status == TypeInsuranceD02TS.E_GIAM_LEAVE_PREMONTH_14WORKINGDAYS.ToString()
                                    || insReportD02Item.Status == TypeInsuranceD02TS.E_GIAM_LEAVE_14WORKINGDAYS.ToString()
                                    || insReportD02Item.Status == TypeInsuranceD02TS.E_GIAM_QUIT_SUSPENSE.ToString()
                                    || insReportD02Item.Status == TypeInsuranceD02TS.E_GIAM_PREGNANT_14WORKINGDAYS.ToString()
                                    || insReportD02Item.Status == TypeInsuranceD02TS.E_GIAM_LD_CHANGE_INSPLACE.ToString())
                                {
                                    d02Status = TypeInsuranceD02TS.E_GIAM_LD.ToString();
                                }
                                if (insReportD02Item.Status == TypeInsuranceD02TS.E_GIAM_LUONG_CHANGEJOBNAME.ToString())
                                {
                                    d02Status = TypeInsuranceD02TS.E_GIAM_LUONG.ToString();
                                }

                                if (insReportD02Item.Status == TypeInsuranceD02TS.E_TANG_LUONG_CHANGEJOBNAME.ToString())
                                {
                                    d02Status = TypeInsuranceD02TS.E_TANG_LUONG.ToString();
                                }
                            }
                            #endregion

                            var insuranceReportD02 = new Ins_InsuranceReportD02Entity
                            {
                                Comment = insReportD02Item.Comment,
                                ProfileID = insReportD02Item.ProfileID,
                                Status = d02Status,
                                Status1 = insReportD02Item.Type,
                                STT = insReportD02Item.ItemOrder.HasValue ? insReportD02Item.ItemOrder.Value.ToString() : null,
                                ItemOrder = insReportD02Item.ItemOrder ?? 0,
                                RateBHXH = insReportD02Item.RateSocialIns,
                                RateBHYT = insReportD02Item.RateHealthIns,
                                RateBHTN = insReportD02Item.RateUnEmpIns,
                                NewBasicSalary = insReportD02Item.NewBasicSalary,
                                NotCardHealth = insReportD02Item.NotCardHealth.HasValue ? insReportD02Item.NotCardHealth.Value.ToString() : "false",
                                ProfileName = insReportD02Item.ProfileName,
                                CodeEmp = insReportD02Item.CodeEmp,
                                SocialInsNo = insReportD02Item.SocialInsNo,
                                JobName = insReportD02Item.JobName,
                                Allowance1 = profileMonthlys.Allowance1,
                                Allowance2 = profileMonthlys.Allowance2,
                                Allowance3 = profileMonthlys.Allowance3,
                                Allowance4 = profileMonthlys.Allowance4,
                                AllowanceAdditional = profileMonthlys.AllowanceAdditional,
                                FromMonth = insReportD02Item.MonthTo,
                                ToMonth = insReportD02Item.MonthTo,
                                PayBackID = insReportD02Item.PayBackID,
                                IsPayBack = insReportD02Item.IsPayBack
                            };
                            lstInsuranceReportD02.Add(insuranceReportD02);
                        }
                    }
                }
            }

            lstInsuranceReportD02 = lstInsuranceReportD02.OrderBy(p => p.Status).ToList();
            var tang = TypeInsuranceD02TS.E_TANG.ToString();
            var giam = TypeInsuranceD02TS.E_GIAM.ToString();
            List<Ins_InsuranceReportD02Entity> lst = new List<Ins_InsuranceReportD02Entity>();

            var statuses = new List<string> { 
                TypeInsuranceD02TS.E_TANG.ToString(), 
                TypeInsuranceD02TS.E_TANG_LD.ToString(), 
                TypeInsuranceD02TS.E_TANG_BHTN.ToString(), 
                 TypeInsuranceD02TS.E_GIAM.ToString(), 
                TypeInsuranceD02TS.E_GIAM_LD.ToString(), 
                TypeInsuranceD02TS.E_TANG_LUONG.ToString(), 
                TypeInsuranceD02TS.E_GIAM_LUONG.ToString(), 
                TypeInsuranceD02TS.E_Dieu_Chinh.ToString(),            
                TypeInsuranceD02TS.E_DieuChinhTang.ToString(),            
                TypeInsuranceD02TS.E_DieuChinhGiam.ToString(),            
            };
            foreach (var item in statuses)
            {
                var lstInsuranceByStatus = lstInsuranceReportD02.Where(p => p.Status == item).OrderBy(p => p.ItemOrder).ToList();

                if (lstInsuranceByStatus.Any())
                {
                    Ins_InsuranceReportD02Entity ins_InsuranceReportD02 = new Ins_InsuranceReportD02Entity
                    {
                        ProfileName = GetDescription(item),
                        CodeEmp = GetOrderStatus(item)
                    };

                    lstInsuranceByStatus = lstInsuranceByStatus.OrderBy(p => p.Comment).ToList();
                    int stt = 1;
                    foreach (var insuranceStatus in lstInsuranceByStatus)
                    {
                        insuranceStatus.STT = stt.ToString();
                        stt++;
                    }
                    lstInsuranceByStatus.Insert(0, ins_InsuranceReportD02);
                    lst.AddRange(lstInsuranceByStatus);
                }
                else
                {
                    Ins_InsuranceReportD02Entity ins_InsuranceReportItemD02 = new Ins_InsuranceReportD02Entity
                    {
                        ProfileName = GetDescription(item),
                        CodeEmp = GetOrderStatus(item)
                    };
                    lst.Add(ins_InsuranceReportItemD02);
                }
            }

            #region filter searchNoteType

            if (searchNoteType != "All")
            {
                var statusSearch = searchNoteType;
                searchNoteType = GetDescription(searchNoteType);
                if (statusSearch == TypeInsuranceD02TS.E_DieuChinhTang.ToString() ||
                    statusSearch == TypeInsuranceD02TS.E_DieuChinhGiam.ToString() ||
                    statusSearch == TypeInsuranceD02TS.E_Dieu_Chinh.ToString()
                    )
                {
                    lst = lst.Where(p => (p.Comment == null || p.Comment == "") || p.Status == statusSearch).ToList();
                }
                else
                {
                    lst = lst.Where(p => (p.Comment == null || p.Comment == "") || p.Comment == searchNoteType).ToList();
                }
            }
            else
                    {
                var lstSearch = new List<string>();
                if (searchStatus == TypeInsuranceD02TS.E_TANG.ToString())
                {
                    lstSearch = new List<string> {
                     GetDescription(TypeInsuranceD02TS.E_TANG_LD.ToString()),
                     GetDescription(TypeInsuranceD02TS.E_TANG_TS.ToString()),
                     //GetDescription(TypeInsuranceD02TS.E_TANG_BENH.ToString()),
                     //GetDescription(TypeInsuranceD02TS.E_TANG_BHYT.ToString()),
                     GetDescription(TypeInsuranceD02TS.E_TANG_BHTN.ToString()),
                     GetDescription(TypeInsuranceD02TS.E_TANG_LEAVE_14WORKINGDAYS.ToString() )                   
                    };
                }
                if (searchStatus == TypeInsuranceD02TS.E_GIAM.ToString())
                {
                    lstSearch = new List<string> {
                    GetDescription(TypeInsuranceD02TS.E_GIAM_LD_BHYT.ToString()),
                    GetDescription(TypeInsuranceD02TS.E_GIAM_QUIT_SUSPENSE.ToString()),
                    GetDescription(TypeInsuranceD02TS.E_GIAM_TS.ToString()),
                    GetDescription(TypeInsuranceD02TS.E_GIAM_LEAVE_14WORKINGDAYS.ToString()),
                    GetDescription(TypeInsuranceD02TS.E_GIAM_LEAVE_PREMONTH_14WORKINGDAYS.ToString()),                    
                    //GetDescription(TypeInsuranceD02TS.E_GIAM_BENH.ToString())
                    };
                }
                if (searchStatus == TypeInsuranceD02TS.E_GIAM_LUONG.ToString())
                {
                    lstSearch = new List<string> {
                     GetDescription( TypeInsuranceD02TS.E_GIAM_LUONG.ToString()),
                      GetDescription(TypeInsuranceD02TS.E_GIAM_LUONG_CHANGEJOBNAME.ToString())
                    };
                }
                if (searchStatus == TypeInsuranceD02TS.E_TANG_LUONG.ToString())
                {
                    lstSearch = new List<string> {
                     GetDescription(TypeInsuranceD02TS.E_TANG_LUONG.ToString()),
                     GetDescription(TypeInsuranceD02TS.E_TANG_LUONG_CHANGEJOBNAME.ToString())
                    };
                }
                if (searchStatus == TypeInsuranceD02TS.E_CHANGEJOBNAME.ToString())
                {
                    lstSearch = new List<string> { 
                         GetDescription(TypeInsuranceD02TS.E_CHANGEJOBNAME.ToString()),
                    };
                }
                if (searchStatus == TypeInsuranceD02TS.E_Dieu_Chinh.ToString())
                {
                    lstSearch = new List<string> { 
                         TypeInsuranceD02TS.E_Dieu_Chinh.ToString(),
                         GetDescription(TypeInsuranceD02TS.E_DieuChinhGiam.ToString()),
                         GetDescription(TypeInsuranceD02TS.E_DieuChinhTang.ToString()),
                    };
                }
                if (lstSearch.Any())
                {
                    lst = lst.Where(p => (p.Comment == null || p.Comment == "") || lstSearch.Contains(p.Comment)).ToList();
                }

            }

            #endregion

            return lst;
        }
コード例 #4
0
        /// <summary> set giá trị BC D02 </summary>
        /// <param name="profile"></param>
        /// <param name="status"></param>
        /// <param name="firstSal"></param>
        /// <param name="currentSal"></param>
        /// <param name="MonthYear"></param>
        /// <param name="orgStructures"></param>
        /// <param name="status1"></param>
        /// <param name="orderGroup">Số Thứ tự theo tăng , giảm (I,II,I.1)</param>
        /// <returns></returns>
        private Ins_InsuranceReportD02Entity SetReportD02(Hre_ProfileEntity profile, string status, double firstSal, double currentSal, DateTime MonthYear, List<Cat_OrgStructureEntity> orgStructures, string status1, string orderGroup)
        {
            var ins_d02 = new Ins_InsuranceReportD02Entity()
            {
                CodeEmp = profile.CodeEmp,
                Comment = GetDescription(status),
                ProfileName = profile.ProfileName,
                SocialInsNo = profile.SocialInsNo,
                OrderGroup = orderGroup,
                Status1 = status1,
                Status = status,
                JobTitle = profile.JobTitleName,
                Position = profile.PositionName,
                ProfileID = profile.ID,
                Gender = profile.Gender,
                DateOfBirth = profile.DateOfBirth.HasValue ? profile.DateOfBirth.Value.ToString(ConstantFormat.HRM_Format_DayMonthYear) : string.Empty,
                HireDate = profile.DateHire ?? DateTime.Now,
                EndProbationDate = profile.DateEndProbation ?? DateTime.Now,
                EndDate = profile.DateEnd ?? DateTime.Now,
                RateBHXH = RateSocial,
                RateBHYT = RateHealth,
                RateBHTN = RateUnEmp,
                WorkPlaceID = profile.WorkPlaceID,
                SocialInsPlaceID = profile.SocialInsPlaceID,
                Allowance1 = profile.Allowance1,
                Allowance2 = profile.Allowance2,
                Allowance3 = profile.Allowance3,
                Allowance4 = profile.Allowance4,
                AllowanceAdditional = profile.AllowanceAdditional,
                JobName = profile.JobName
            };

            if (string.IsNullOrEmpty(ins_d02.Position))
            {
                ins_d02.Position = ins_d02.JobTitle;
            }

            if (profile.OrgStructureID.HasValue)
            {
                ins_d02.CodeParentOrgLevel = GetCodeOrgStructure(orgStructures, profile.OrgStructureID ?? Guid.Empty);
            }

            if (status == TypeInsuranceD02TS.E_TANG_LUONG.ToString())
            {
                ins_d02.OldBasicSalary = firstSal;
                ins_d02.NewBasicSalary = currentSal;
            }
            else if (status == TypeInsuranceD02TS.E_TANG_LUONG_CHANGEJOBNAME.ToString())
            {
                ins_d02.OldBasicSalary = firstSal;
                ins_d02.NewBasicSalary = currentSal;
            }
            else if (status == TypeInsuranceD02TS.E_GIAM_LUONG.ToString()) //Ho tro masan xuat trang thai tru co luong ngay 12/08/2013
            {
                ins_d02.OldBasicSalary = firstSal;
                ins_d02.NewBasicSalary = currentSal;
            }
            else if (status == TypeInsuranceD02TS.E_GIAM_LUONG_CHANGEJOBNAME.ToString())
            {
                ins_d02.OldBasicSalary = firstSal;
                ins_d02.NewBasicSalary = currentSal;
            }
            else if (status == TypeInsuranceD02TS.E_GIAM_LEAVE_14WORKINGDAYS.ToString())
            {
                ins_d02.OldBasicSalary = firstSal;
                ins_d02.NewBasicSalary = firstSal;
            }
            else if (status == TypeInsuranceD02TS.E_TANG_LD.ToString() || status == TypeInsuranceD02TS.E_TANG_BENH.ToString() || status == TypeInsuranceD02TS.E_TANG_TS.ToString() || status == TypeInsuranceD02TS.E_TANG_LEAVE_14WORKINGDAYS.ToString())
            {
                ins_d02.OldBasicSalary = 0;
                ins_d02.NewBasicSalary = currentSal;
            }

            else if (status == TypeInsuranceD02TS.E_GIAM_BHYT.ToString() || status == TypeInsuranceD02TS.E_TANG_BHYT.ToString())
            {
                ins_d02.OldBasicSalary = firstSal;
                ins_d02.NewBasicSalary = currentSal;
                ins_d02.RateBHXH = 0;
                ins_d02.RateBHYT = RateHealth;
                ins_d02.RateBHTN = 0;
            }
            else if (status == TypeInsuranceD02TS.E_GIAM_BHTN.ToString() || status == TypeInsuranceD02TS.E_TANG_BHTN.ToString())
            {
                ins_d02.OldBasicSalary = firstSal;
                ins_d02.NewBasicSalary = currentSal;
                ins_d02.RateBHXH = 0;
                ins_d02.RateBHYT = 0;
                ins_d02.RateBHTN = RateUnEmp;
            }
            else if (status == TypeInsuranceD02TS.E_GIAM_LD.ToString() || status == TypeInsuranceD02TS.E_GIAM_LD_BHYT.ToString())
            {
                ins_d02.OldBasicSalary = firstSal;
                ins_d02.NewBasicSalary = firstSal;
            }
            else if (status == TypeInsuranceD02TS.E_GIAM_TS.ToString() || status == TypeInsuranceD02TS.E_GIAM_TS_QUIT.ToString())
            {
                ins_d02.OldBasicSalary = firstSal;
                ins_d02.NewBasicSalary = firstSal;
            }
            else if (status == TypeInsuranceD02TS.E_GIAM_LD_NOT_BHYT.ToString() || status == TypeInsuranceD02TS.E_GIAM_LD_BHYT.ToString()
                || status == TypeInsuranceD02TS.E_GIAM_LD_BHYT_KOKIPTHOI.ToString() || status == TypeInsuranceD02TS.E_GIAM_QUIT_SUSPENSE.ToString()) //Ho tro masan xuat trang thai tru co luong ngay 12/08/2013
            {
                ins_d02.OldBasicSalary = firstSal;
                ins_d02.NewBasicSalary = firstSal;
            }
            else if (status == TypeInsuranceD02TS.E_CHANGEJOBNAME.ToString())
            {
                ins_d02.OldBasicSalary = firstSal;
                ins_d02.NewBasicSalary = currentSal;
            }
            else if (status == TypeInsuranceD02TS.E_GIAM_LD.ToString() || status == TypeInsuranceD02TS.E_GIAM_LD_BHYT.ToString()
                || status == TypeInsuranceD02TS.E_GIAM_LD_BHYT_KOKIPTHOI.ToString() || status == TypeInsuranceD02TS.E_GIAM_LD_NOT_BHYT.ToString())
            {
                ins_d02.OldBasicSalary = firstSal;
                ins_d02.NewBasicSalary = firstSal;
            }

            ins_d02.MonthNow = new DateTime(MonthYear.Year, MonthYear.Month, 1);
            ins_d02.TitleMonthNow = "Số:..........Tháng " + MonthYear.Month + " Năm " + MonthYear.Year;
            ins_d02.FromMonth = new DateTime(MonthYear.AddMonths(-1).Year, MonthYear.AddMonths(-1).Month, 1);
            ins_d02.ToMonth = new DateTime(MonthYear.Year, MonthYear.Month, 1);
            ins_d02.Status = status;
            //dr["CodeParentOrgLevel"] = HRService.GetCodeInListOrgParent(pro.OrgStructureID ?? Guid.Empty, lstStrucAll, 1);

            return ins_d02;

        }