Esempio n. 1
0
        private static void GetAllowanceInsuranceByFomular(double salInsurance, DateTime monthCheck, List<Hre_HDTJob> hreHDTJobs, Att_CutOffDuration cutOffDuration, Hre_ProfileEntity profile, Cat_GradePayroll gradePayroll, out Hre_HDTJob hreHdtJobProfile, out FormulaHelper.FormulaHelperModel result, List<Cat_UnusualAllowanceCfg> lstUnusualAllowanceCfg, List<Sal_UnusualAllowance> lstUnusualAllowance, List<Cat_Element> listElementFormulaInDB, double hdt4Amount, double hdt5Amount)
        {
            string fomular = (new InsuranceServices()).FomularReplace(gradePayroll.FormulaSalaryIns, listElementFormulaInDB);

            List<ElementFormula> listElementFormula = new List<ElementFormula>();
            hreHdtJobProfile = hreHDTJobs.Where(m => m.ProfileID == profile.ID && m.Status == HDTJobStatus.E_APPROVE.ToString()).OrderBy(m => m.DateFrom).FirstOrDefault();

            #region Công Loại IV
            var listHDTJob_Type4 = hreHDTJobs.Where(m => m.Status == HDTJobStatus.E_APPROVE.ToString() && m.Type == EnumDropDown.HDTJobType.E_TYPE4.ToString() && m.ProfileID == profile.ID).OrderBy(m => m.DateFrom).ToList();
            double TotalDayHDTJob4 = 0;
            if (listHDTJob_Type4 != null && listHDTJob_Type4.Count > 0)
            {
                TotalDayHDTJob4 = profile.NumdayHDTJobTypeIV ?? 0;
            }

            //Số ngày công làm HDT Job Loại 4 (tháng N)
            var item = new ElementFormula();
            item = new ElementFormula(PayrollElement.ATT_WORKDAY_HDTJOB_4.ToString(), TotalDayHDTJob4, 0);
            listElementFormula.Add(item);
            #endregion

            #region Công Loại V
            var listHDTJob_Type5 = hreHDTJobs.Where(m => m.Status == HDTJobStatus.E_APPROVE.ToString() && m.Type == EnumDropDown.HDTJobType.E_TYPE5.ToString() && m.ProfileID == profile.ID).OrderBy(m => m.DateFrom).ToList();
            double TotalDayHDTJob5 = 0;
            if (listHDTJob_Type5 != null && listHDTJob_Type5.Count > 0)
            {
                TotalDayHDTJob5 = profile.NumdayHDTJobTypeV ?? 0;
            }

            #region set hre_hdtjob có có ngày làm hdtjob lớn hơn
            if (TotalDayHDTJob4 >= TotalDayHDTJob5)
            {
                hreHdtJobProfile = listHDTJob_Type4.FirstOrDefault();
            }
            else
            {
                hreHdtJobProfile = listHDTJob_Type5.FirstOrDefault();
            }
            #endregion

            //Số ngày công làm HDT Job Loại 5 (tháng N)
            item = new ElementFormula(PayrollElement.ATT_WORKDAY_HDTJOB_5.ToString(), TotalDayHDTJob5, 0);
            listElementFormula.Add(item);
            #endregion


            gradePayroll.FormulaSalaryIns = fomular;
            if (hreHdtJobProfile != null)
            {
                if (hreHdtJobProfile.DateFrom.HasValue)
                {
                    item = new ElementFormula(PayrollElement.HR_START_DATE_HDTJOB.ToString(), hreHdtJobProfile.DateFrom.Value, 0);
                    listElementFormula.Add(item);
                }
                if (hreHdtJobProfile.DateTo.HasValue)
                {
                    item = new ElementFormula(PayrollElement.HR_END_DATE_HDTJOB.ToString(), hreHdtJobProfile.DateTo.Value, 0);
                    listElementFormula.Add(item);
                }
                if (hreHdtJobProfile.DateTo.HasValue)
                {
                    item = new ElementFormula(PayrollElement.ATT_CUTOFFDURATION_MONTH.ToString(), monthCheck, 0);
                    listElementFormula.Add(item);
                }
            }
            if (gradePayroll.FormulaSalaryIns.Contains(PayrollElement.INS_SALARY_INSURANCE_ROOT.ToString()))
            {
                item = new ElementFormula(PayrollElement.INS_SALARY_INSURANCE_ROOT.ToString(), salInsurance, 0);
                listElementFormula.Add(item);
            }

            if (gradePayroll.FormulaSalaryIns.Contains(InsuranceElement.INS_JOBNAME_NUMDAYNONHDTJOB.ToString()))
            {
                item = new ElementFormula(InsuranceElement.INS_JOBNAME_NUMDAYNONHDTJOB.ToString(), profile.NumdayNonHDTJob, 0);
                listElementFormula.Add(item);
            }

            if (gradePayroll.FormulaSalaryIns.Contains(InsuranceElement.INS_HDT4_TIMELINE.ToString()))
            {
                item = new ElementFormula(InsuranceElement.INS_HDT4_TIMELINE.ToString(), hdt4Amount, 0);
                listElementFormula.Add(item);
            }
            if (gradePayroll.FormulaSalaryIns.Contains(InsuranceElement.INS_HDT5_TIMELINE.ToString()))
            {
                item = new ElementFormula(InsuranceElement.INS_HDT5_TIMELINE.ToString(), hdt5Amount, 0);
                listElementFormula.Add(item);
            }

            foreach (var Allowance in lstUnusualAllowanceCfg)
            {
                var unusualAllowance = lstUnusualAllowance.FirstOrDefault(m => m.ProfileID == profile.ID && m.UnusualEDTypeID == Allowance.ID);
                if (gradePayroll.FormulaSalaryIns.Contains(Allowance.Code) && unusualAllowance != null)
                {
                    item = new ElementFormula(Allowance.Code, unusualAllowance.Amount, 0);
                    listElementFormula.Add(item);
                }
            }

            //tinh tien HDTJob

            result = FormulaHelper.ParseFormula(fomular.Replace("[", "").Replace("]", ""), listElementFormula.Distinct().ToList());
        }
Esempio n. 2
0
        /// <summary>      
        /// Tinh Thang tham gia bao hiem.
        /// </summary>
        /// <param name="rProfile"></param>
        /// <param name="MonthYear"></param>
        /// <returns></returns>
        public static DateTime GetMonthJoinInsurance(Hre_Profile pro, DateTime monthYear)
        {

            List<String> lstContractCodeSI = new List<String>();
            List<Sal_Grade> lstgrade = pro.Sal_Grade.Where(gr => gr.IsDelete == null || gr.IsDelete == false).ToList();
            List<Hre_Contract> lstContract = pro.Hre_Contract.Where(gr => gr.IsDelete == null || gr.IsDelete == false).ToList();

            if (pro.DateHire == null)
            {
                return DateTime.MinValue;
            }
            DateTime _dateHire = pro.DateHire.Value;
            if (_dateHire.Day > PeriodInsuranceDayCurrentMonthDefault)
                _dateHire = new DateTime(_dateHire.AddMonths(1).Year
                                        , _dateHire.AddMonths(1).Month
                                        , PeriodInsuranceDayCurrentMonthDefault);
            else
                _dateHire = new DateTime(_dateHire.Year
                                        , _dateHire.Month
                                        , PeriodInsuranceDayCurrentMonthDefault);

            DateTime monthJoinIns = new DateTime();
            if (pro.SocialInsDateReg.HasValue)
                monthJoinIns = pro.SocialInsDateReg.Value;
            else if (pro.DateEndProbation.HasValue)
                monthJoinIns = pro.DateEndProbation.Value;
            else
                monthJoinIns = _dateHire;

            for (DateTime _dx = _dateHire; _dx < monthYear;
                _dx = new DateTime(_dx.AddMonths(1).Year,
                                   _dx.AddMonths(1).Month,
                                   PeriodInsuranceDayCurrentMonthDefault)
                )
            {
                DateTime dateMaxGrade = DateTime.MinValue;
                Cat_GradePayroll gradeCfg = new Cat_GradePayroll();
                lstgrade = lstgrade.OrderBy(gra => gra.udMonthOfEffect).ToList();
                if (lstgrade.Count > 0)
                {
                    //Truong hop ngay hieu luc cua grade dau tien lon hon ngay vao lam
                    if (lstgrade[0].udMonthOfEffect.HasValue && lstgrade[0].udMonthOfEffect.Value > _dx)
                    {
                        //<RedundancyByResharper> //No Redundancy Trung.LE
                        dateMaxGrade = lstgrade[0].udMonthOfEffect.Value;
                        //</RedundancyByResharper>

                        gradeCfg = lstgrade[0].Cat_GradePayroll;
                    }
                    else
                    {
                        foreach (Sal_Grade gr in lstgrade)
                        {
                            if (gr.udMonthOfEffect > dateMaxGrade && gr.udMonthOfEffect <= _dx)
                            {
                                dateMaxGrade = gr.udMonthOfEffect.Value;
                                gradeCfg = gr.Cat_GradePayroll;
                            }
                        }
                    }
                }

                if (!String.IsNullOrEmpty(gradeCfg.SIContract))
                {
                    lstContractCodeSI.AddRange(gradeCfg.SIContract.Split(new char[1] { ',' }));
                    if (lstContract.Exists(ctr => ctr.DateStart <= _dx
                                      && (ctr.DateEnd == null || ctr.DateEnd > _dx)
                                      && lstContractCodeSI.Contains(ctr.Cat_ContractType.Code)))
                    {
                        monthJoinIns = _dx;
                        break;
                    }
                }
            }

            return monthJoinIns;

        }
Esempio n. 3
0
        /// <summary> Lấy JobName theo cong thức bên chế độ lương </summary>
        /// <param name="hdtJobMoney"></param>
        /// <param name="cat_SalaryClasses"></param>
        /// <param name="hdtJobGroups"></param>
        /// <param name="hreHdtJobProfile"></param>
        /// <param name="profile"></param>
        /// <param name="orgStructures"></param>
        /// <param name="orgTypes"></param>
        /// <param name="jobTitleName"></param>
        /// <param name="gradePayroll"></param>
        /// <param name="result"></param>
        /// <param name="listElementFormulaInDB"></param>
        private static void GetJobNameByFomular(double hdtJobMoney, List<Cat_SalaryClass> cat_SalaryClasses, List<Cat_HDTJobGroup> hdtJobGroups, Hre_HDTJob hreHdtJobProfile, Hre_ProfileEntity profile, List<Cat_OrgStructure> orgStructures, List<Cat_OrgStructureType> orgTypes, string jobTitleName, Cat_GradePayroll gradePayroll, out FormulaHelper.FormulaHelperModel result, List<Cat_Element> listElementFormulaInDB, out string hdtJobGroupCode)
        {
            /*
            *  Goal(Lấy JobName theo cong thức bên chế độ lương)
            *  Steps :
            *      Step1  :  Lấy giá trị của các phần tử 
            *      Step2  :  Thiết lập các phần tử (INS_JOBNAME_HDTJOBMONEY,INS_JOBNAME_NAMEOFRANK,INS_JOBNAME_HDTGROUPNAME,INS_JOBNAME_ORGSTRUCTURENAME,INS_JOBNAME_JOBTITLE)
            *      Step3  :  ParseFormula cho cot FormulaJobNameIns trong ds chế độ lương
            *      Step4  :  Note: rieng phần tử INS_JOBNAME_JOBTITLE  (nếu khac honda sẽ chỉ su dụng phần tử này)
            */

            var listElementFormula = new List<ElementFormula>();
            var item = new ElementFormula();

            #region Lấy giá trị của các phần tử
            var hdtGroupName = string.Empty;
            var nameOfRank = string.Empty;
            var orgName = string.Empty;

            #region Name of rank
            var salaryClass = cat_SalaryClasses.Where(p => profile != null && profile.SalaryClassID.HasValue && p.ID == profile.SalaryClassID).FirstOrDefault();
            if (salaryClass != null)
            {
                nameOfRank = salaryClass.AbilityTitleVNI + " ";
            }
            #endregion

            #region HdtJobGroup
            var hdtJobGroup = hdtJobGroups.Where(p => hreHdtJobProfile != null && p.ID == hreHdtJobProfile.HDTJobGroupID).FirstOrDefault();
            hdtJobGroupCode = string.Empty;
            if (hdtJobGroup != null)
            {
                hdtGroupName = hdtJobGroup.HDTJobGroupName;
                hdtJobGroupCode = hdtJobGroup.Code;
            }
            #endregion

            #region OrgStructure Name (tên tiếng Việt)
            var org = LibraryService.GetNearestParent(profile.OrgStructureID, OrgUnit.E_DEPARTMENT, orgStructures, orgTypes);

            if (org != null)
            {
                orgName = org.OrgStructureNameEN;
            }
            #endregion

            #endregion

            #region Thiết lập phần tử lấy jobName
            //lấy jobName
            string fomular = (new InsuranceServices()).FomularReplace(gradePayroll.FormulaJobNameIns, listElementFormulaInDB);
            gradePayroll.FormulaJobNameIns = fomular;
            if (gradePayroll.FormulaJobNameIns != null)
            {
                if (gradePayroll.FormulaJobNameIns.Contains(InsuranceElement.INS_JOBNAME_HDTJOBMONEY.ToString()))
                {
                    item = new ElementFormula(InsuranceElement.INS_JOBNAME_HDTJOBMONEY.ToString(), hdtJobMoney, 0);
                    listElementFormula.Add(item);
                }
                if (gradePayroll.FormulaJobNameIns.Contains(InsuranceElement.INS_JOBNAME_NAMEOFRANK.ToString()))
                {
                    item = new ElementFormula(InsuranceElement.INS_JOBNAME_NAMEOFRANK.ToString(), nameOfRank, 0);
                    listElementFormula.Add(item);
                }
                if (gradePayroll.FormulaJobNameIns.Contains(InsuranceElement.INS_JOBNAME_HDTGROUPNAME.ToString()))
                {
                    item = new ElementFormula(InsuranceElement.INS_JOBNAME_HDTGROUPNAME.ToString(), hdtGroupName, 0);
                    listElementFormula.Add(item);
                }
                if (gradePayroll.FormulaJobNameIns.Contains(InsuranceElement.INS_JOBNAME_ORGSTRUCTURENAME.ToString()))
                {
                    item = new ElementFormula(InsuranceElement.INS_JOBNAME_ORGSTRUCTURENAME.ToString(), orgName, 0);
                    listElementFormula.Add(item);
                }
                if (gradePayroll.FormulaJobNameIns.Contains(InsuranceElement.INS_JOBNAME_JOBTITLE.ToString()))
                {
                    item = new ElementFormula(InsuranceElement.INS_JOBNAME_JOBTITLE.ToString(), jobTitleName, 0);
                    listElementFormula.Add(item);
                }

                result = FormulaHelper.ParseFormula(fomular.Replace("[", "").Replace("]", ""), listElementFormula.Distinct().ToList());
            }
            else
            {
                result = new FormulaHelper.FormulaHelperModel();
                result.Value = string.Empty;
            }
            #endregion
        }