Ejemplo n.º 1
0
        public bool CheckIsExistFormula(List<ElementFormula> listElementFormula, Cat_ElementEntity formula, string StartsWith, string[] ArrayEndsWith)
        {
            //loại bỏ các khoản trắng và xuống dòng
            formula.Formula = formula.Formula.Replace("\n", "").Replace("\t", "").Trim();

            //Tách các phần tử từ công thức ra một array
            List<string> listFormulaItem = ParseFormulaToList(formula.Formula);
            foreach (var EndsWith in ArrayEndsWith)
            {
                if (listFormulaItem.Any(m => m.Replace("[", "").Replace("]", "").StartsWith(StartsWith) && m.Replace("[", "").Replace("]", "").EndsWith(EndsWith)))
                {
                    foreach (var i in listFormulaItem)
                    {
                        if (!listElementFormula.Any(m => m.VariableName == i.Replace("[", "").Replace("]", "")))
                        {
                            return true;
                        }
                    }
                    //if (!listElementFormula.Any(m => m.VariableName.StartsWith(StartsWith) && m.VariableName.EndsWith(EndsWith)))
                    //{
                    //    return true;
                    //}
                }
            }
            return false;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Kiểm tra xem phần tử có nằm trong công thức hay không
        /// </summary>
        /// <param name="formula"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool CheckIsExistFormula(List<ElementFormula> listElementFormula, Cat_ElementEntity formula, string[] value)
        {
            //loại bỏ các khoản trắng và xuống dòng
            formula.Formula = formula.Formula.Replace("\n", "").Replace("\t", "").Trim();

            //Tách các phần tử từ công thức ra một array
            List<string> listFormulaItem = ParseFormulaToList(formula.Formula);

            if (listFormulaItem.Any(m => value.Any(t => t == m.Replace("[", "").Replace("]", ""))))
            {
                if (value.Any(m => !listElementFormula.Any(t => t.VariableName == m.Replace("[", "").Replace("]", ""))))
                {
                    return true;
                }
            }
            return false;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Hàm Parse công thức ra phần tử và lưu vào list tổng 
        /// </summary>
        /// <param name="formula"></param>
        /// <param name="listElementFormula"></param>
        /// <param name="TotalData"></param>
        /// <param name="profileItem"></param>
        /// <param name="CutOffDuration"></param>
        /// <param name="listTmpDeduction"></param>
        /// <returns></returns>
        public List<ElementFormula> ParseFormula(Cat_ElementEntity formula, List<ElementFormula> listElementFormula, ComputePayrollDataModel TotalData, Hre_ProfileEntity profileItem, Att_CutOffDurationEntity CutOffDuration, Dictionary<Guid, ValueCount> listTmpDeduction)
        {
            string strFormula = formula.Formula.Replace("\n", "").Replace("\t", "").Trim();

            //Các phần tử tính lương tách ra từ 1 chuỗi công thức
            List<string> ListFormula = ParseFormulaToList(strFormula).Where(m => m.IndexOf('[') != -1 && m.IndexOf(']') != -1).ToList();

            //Các phần tử tính lương chưa có kết quả
            List<string> ListFormulaNotValue = ListFormula.Where(m => !listElementFormula.Any(t => t.VariableName == m.Replace("[", "").Replace("]", ""))).ToList();

            //có phần tử chưa được tính trước đó
            if (ListFormulaNotValue != null && ListFormulaNotValue.Count > 0)
            {
                foreach (string elementNotValue in ListFormulaNotValue)
                {

                    //kiểm tra phần tử đó là phần tử Enum hay là phần tử công thức
                    if (TotalData.listElement_All.Any(m => m.GradePayrollID != null && m.ElementCode == elementNotValue.Replace("[", "").Replace("]", "")))//là phần tử công thức
                    {
                        //var tt = TotalData.listElement_All.Where(m => m.ElementCode == elementNotValue.Replace("[", "").Replace("]", "")).FirstOrDefault();
                        listElementFormula = ParseFormula(TotalData.listElement_All.Where(m => m.ElementCode == elementNotValue.Replace("[", "").Replace("]", "")).FirstOrDefault(), listElementFormula, TotalData, profileItem, CutOffDuration, listTmpDeduction);
                    }
                    else//là phần tử enum
                    {
                        listElementFormula = GetStaticValues(TotalData, listElementFormula, profileItem, CutOffDuration, formula.ElementCode, listTmpDeduction);
                    }
                }
            }

            //Do mệnh đề if luôn trả về false nên xử lý riêng cho mệnh đề if ở đây
            //nguyên ngân là do dll CalcEngine, nhưng chưa tìm ra cách giải quyết
            if (formula.Formula.ToUpper().Contains("IF("))
            {
                string _formula = formula.Formula;
                foreach (var i in listElementFormula.Distinct().ToList())
                {
                    if (formula.Formula.Contains("[" + i.VariableName + "]"))
                    {
                        if (i.Value != null)
                        {
                            _formula = _formula.Replace("[" + i.VariableName + "]", i.Value.ToString());
                        }
                        else
                        {
                            i.Value = 0;
                            i.ErrorMessage = "Null";
                            _formula = _formula.Replace("[" + i.VariableName + "]", i.Value.ToString());
                        }
                    }
                }
                var result = FormulaHelper.ParseFormula(_formula.Replace("[", "").Replace("]", ""), listElementFormula.Distinct().ToList());
                listElementFormula.Add(new ElementFormula(formula.ElementCode, result.Value, 0, result.ErrorMessage));
            }
            else
            {
                var result = FormulaHelper.ParseFormula(formula.Formula.Replace("[", "").Replace("]", ""), listElementFormula.Distinct().ToList());
                listElementFormula.Add(new ElementFormula(formula.ElementCode, result.Value, 0, result.ErrorMessage));
            }
            return listElementFormula.Distinct().ToList();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Kiểm tra xem phần tử có nằm trong công thức hay không
        /// </summary>
        /// <param name="formula"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool CheckIsExistFormula(List<ElementFormula> listElementFormula, Cat_ElementEntity formula, string value)
        {
            //loại bỏ các khoản trắng và xuống dòng
            formula.Formula = formula.Formula.Replace("\n", "").Replace("\t", "").Trim();

            List<string> listFormulaItem = ParseFormulaToList(formula.Formula);

            if (listFormulaItem.Any(m => m.Replace("[", "").Replace("]", "") == value.ReplaceSpace()))
            {
                if (!listElementFormula.Any(m => m.VariableName.ReplaceSpace() == value.ReplaceSpace()))
                {
                    return true;
                }
            }
            return false;
        }
Ejemplo n.º 5
0
        public ActionResult CreateFirstElement()
        {
            #region GetData
            ActionService action = new ActionService(UserLogin);
            string status = string.Empty;
            List<object> listobject = new List<object>();
            listobject.AddRange(new object[4]);
            listobject[2] = 1;
            listobject[3] = Int32.MaxValue - 1;
            var listLeaveday = baseService.GetData<Cat_LeaveDayTypeEntity>(listobject, ConstantSql.hrm_cat_sp_get_LeaveDayType, UserLogin, ref status);

            listobject = new List<object>();
            listobject.AddRange(new object[5]);
            listobject[3] = 1;
            listobject[4] = Int32.MaxValue - 1;
            var listOvertimeType = baseService.GetData<Cat_OvertimeTypeEntity>(listobject, ConstantSql.hrm_cat_sp_get_OvertimeType, UserLogin, ref status);

            listobject = new List<object>();
            listobject.AddRange(new object[7]);
            listobject[5] = 1;
            listobject[6] = Int32.MaxValue - 1;
            var listElement = baseService.GetData<Cat_ElementEntity>(listobject, ConstantSql.hrm_cat_sp_get_Element, UserLogin, ref status);

            listobject = new List<object>();
            listobject.AddRange(new object[4]);
            listobject[2] = 1;
            listobject[3] = Int32.MaxValue - 1;
            var listGrade = baseService.GetData<Cat_GradePayrollMultiEntity>(listobject, ConstantSql.hrm_cat_sp_get_GradePayroll, UserLogin, ref status);

            listobject = new List<object>();
            listobject.AddRange(new object[4]);
            listobject[2] = 1;
            listobject[3] = Int32.MaxValue - 1;
            var listKPIBonus = baseService.GetData<Cat_KPIBonusEntity>(listobject, ConstantSql.hrm_cat_sp_get_KPIBonus, UserLogin, ref status);

            listobject = new List<object>();
            listobject.AddRange(new object[3]);
            listobject[1] = 1;
            listobject[2] = Int32.MaxValue - 1;
            var listSalesType = baseService.GetData<Eva_SalesTypeEntity>(listobject, ConstantSql.hrm_eva_sp_get_SalesType, UserLogin, ref status);

            //listobject = new List<object>();
            //listobject.AddRange(new object[5]);
            //listobject[3] = 1;
            //listobject[4] = Int32.MaxValue - 1;
            //var listTitle = baseService.GetData<Cat_JobTitleEntity>(listobject, ConstantSql.hrm_cat_sp_get_JobTitle, ref status);

            listobject = new List<object>();
            listobject.AddRange(new object[4]);
            listobject[2] = 1;
            listobject[3] = Int32.MaxValue - 1;
            var listPosition = baseService.GetData<Cat_PositionEntity>(listobject, ConstantSql.hrm_cat_sp_get_Position, UserLogin, ref status);

            List<Cat_RoleEntity> listCat_Role = new List<Cat_RoleEntity>();
            listobject = new List<object>();
            listobject.AddRange(new object[4]);
            listobject[2] = 1;
            listobject[3] = Int32.MaxValue - 1;
            listCat_Role = baseService.GetData<Cat_RoleEntity>(listobject, ConstantSql.hrm_cat_sp_get_Role, UserLogin, ref status).ToList();

            List<Cat_JobTypeEntity> listCat_JobType = new List<Cat_JobTypeEntity>();
            listobject = new List<object>();
            listobject.AddRange(new object[4]);
            listobject[2] = 1;
            listobject[3] = Int32.MaxValue - 1;
            listCat_JobType = baseService.GetData<Cat_JobTypeEntity>(listobject, ConstantSql.hrm_cat_sp_get_JobType, UserLogin, ref status).ToList();

            List<Cat_ShiftEntity> listCat_Shift = new List<Cat_ShiftEntity>();
            listobject = new List<object>();
            listobject.AddRange(new object[4]);
            listobject[2] = 1;
            listobject[3] = Int32.MaxValue - 1;
            listCat_Shift = baseService.GetData<Cat_ShiftEntity>(listobject, ConstantSql.hrm_cat_sp_get_Shift, UserLogin, ref status).ToList();

            listobject = new List<object>();
            listobject.AddRange(new object[4]);
            listobject[2] = 1;
            listobject[3] = Int32.MaxValue - 1;
            var listCurrency = baseService.GetData<Cat_CurrencyEntity>(listobject, ConstantSql.hrm_cat_sp_get_Currency, UserLogin, ref status);

            listobject = new List<object>();
            listobject.AddRange(new object[3]);
            listobject[1] = 1;
            listobject[2] = Int32.MaxValue - 1;
            var listPerformanceType = baseService.GetData<Cat_PerformanceTypeEntity>(listobject, ConstantSql.hrm_cat_sp_get_PerformanceType, UserLogin, ref status);
            #endregion

            List<Cat_ElementEntity> listModel = new List<Cat_ElementEntity>();

            #region Xóa hết các phần tử
            List<Cat_ElementEntity> _temp = listElement.Where(m => m.ElementType == CatElementType.Comission.ToString() || m.ElementType == CatElementType.Evaluation.ToString() || m.ElementType == CatElementType.Attendance.ToString() || m.ElementType == CatElementType.FLIGHT.ToString()).ToList();
            if (_temp != null && _temp.Count > 0)
            {
                foreach (var i in _temp)
                {
                    baseService.Delete<Cat_ElementEntity>(i.ID);
                    //listElement.Remove(i);
                }
            }
            #endregion

            #region Add các phần tử ngày nghỉ
            if (listLeaveday != null && listLeaveday.Count > 0)
            {
                foreach (var i in listLeaveday)
                {
                    if (!listElement.Any(m => m.ElementName == "ATT_LEAVE_" + i.Code + "_HOURS"))
                    {
                        Cat_ElementEntity item = new Cat_ElementEntity();
                        item.ElementCode = "ATT_LEAVE_" + i.Code + "_HOURS";
                        item.ElementName = "Tổng giờ nghỉ loại " + i.LeaveDayTypeName + " trong tháng";
                        item.Formula = "[ATT_LEAVE_" + i.Code + "_HOURS]";
                        item.Description = i.Notes;
                        item.ElementType = CatElementType.Attendance.ToString();
                        item.GradePayrollID = null;
                        item.MethodPayroll = MethodPayroll.E_NORMAL.ToString();
                        listModel.Add(item);
                    }
                    else
                    {
                        if (!listElement.Any(m => m.ElementName == "ATT_LEAVE_" + i.Code + "_HOURS" && m.GradePayrollID == null))
                        {
                            Cat_ElementEntity item = new Cat_ElementEntity();
                            item.ElementCode = "ATT_LEAVE_" + i.Code + "_HOURS";
                            item.ElementName = "Tổng giờ nghỉ loại " + i.LeaveDayTypeName + " trong tháng";
                            item.Formula = "[ATT_LEAVE_" + i.Code + "_HOURS]";
                            item.Description = i.Notes;
                            item.ElementType = CatElementType.Attendance.ToString();
                            item.GradePayrollID = null;
                            item.MethodPayroll = MethodPayroll.E_NORMAL.ToString();
                            listModel.Add(item);
                        }
                    }

                    //Số ngày nghỉ tháng N-1
                    if (!listElement.Any(m => m.ElementName == "ATT_LEAVE_" + i.Code + "_DAY_PREV"))
                    {
                        Cat_ElementEntity item = new Cat_ElementEntity();
                        item.ElementCode = "ATT_LEAVE_" + i.Code + "_DAY_PREV";
                        item.ElementName = "Tổng ngày nghỉ loại " + i.LeaveDayTypeName + " trong tháng N-1";
                        item.Formula = "[ATT_LEAVE_" + i.Code + "_DAY_PREV]";
                        item.Description = i.Notes;
                        item.ElementType = CatElementType.Attendance.ToString();
                        item.GradePayrollID = null;
                        item.MethodPayroll = MethodPayroll.E_NORMAL.ToString();
                        listModel.Add(item);
                    }
                    else
                    {
                        if (!listElement.Any(m => m.ElementName == "ATT_LEAVE_" + i.Code + "_DAY_PREV" && m.GradePayrollID == null))
                        {
                            Cat_ElementEntity item = new Cat_ElementEntity();
                            item.ElementCode = "ATT_LEAVE_" + i.Code + "_DAY_PREV";
                            item.ElementName = "Tổng ngày nghỉ loại " + i.LeaveDayTypeName + " trong tháng N-1";
                            item.Formula = "[ATT_LEAVE_" + i.Code + "_DAY_PREV]";
                            item.Description = i.Notes;
                            item.ElementType = CatElementType.Attendance.ToString();
                            item.GradePayrollID = null;
                            item.MethodPayroll = MethodPayroll.E_NORMAL.ToString();
                            listModel.Add(item);
                        }
                    }

                    //tổng số ngày nghỉ của từng loại theo năm
                    if (!listElement.Any(m => m.ElementName == "ATT_LEAVE_" + i.Code + "_DAY_INYEAR"))
                    {
                        Cat_ElementEntity item = new Cat_ElementEntity();
                        item.ElementCode = "ATT_LEAVE_" + i.Code + "_DAY_INYEAR";
                        item.ElementName = "Tổng ngày nghỉ loại " + i.LeaveDayTypeName + " trong năm";
                        item.Formula = "[ATT_LEAVE_" + i.Code + "_DAY_INYEAR]";
                        item.Description = i.Notes;
                        item.ElementType = CatElementType.Attendance.ToString();
                        item.GradePayrollID = null;
                        item.MethodPayroll = MethodPayroll.E_NORMAL.ToString();
                        listModel.Add(item);
                    }
                    else
                    {
                        if (!listElement.Any(m => m.ElementName == "ATT_LEAVE_" + i.Code + "_DAY_INYEAR" && m.GradePayrollID == null))
                        {
                            Cat_ElementEntity item = new Cat_ElementEntity();
                            item.ElementCode = "ATT_LEAVE_" + i.Code + "_DAY_INYEAR";
                            item.ElementName = "Tổng ngày nghỉ loại " + i.LeaveDayTypeName + " trong năm";
                            item.Formula = "[ATT_LEAVE_" + i.Code + "_DAY_INYEAR]";
                            item.Description = i.Notes;
                            item.ElementType = CatElementType.Attendance.ToString();
                            item.GradePayrollID = null;
                            item.MethodPayroll = MethodPayroll.E_NORMAL.ToString();
                            listModel.Add(item);
                        }
                    }
                }
            }
            #endregion

            #region Add các phần tử tiền tệ

            if (listCurrency != null)
            {
                foreach (var i in listCurrency)
                {
                    List<Cat_CurrencyEntity> listCurrencyRemoveCurrent = new List<Cat_CurrencyEntity>(listCurrency);
                    listCurrencyRemoveCurrent.Remove(i);
                    foreach (var j in listCurrencyRemoveCurrent)
                    {
                        //Giá mua
                        if (!listElement.Any(m => m.ElementName == i.Code + "_" + j.Code + "_BUYING"))
                        {
                            Cat_ElementEntity item = new Cat_ElementEntity();
                            item.ElementCode = i.Code + "_" + j.Code + "_BUYING";
                            item.ElementName = "Giá mua " + i.CurrencyName + "_" + j.CurrencyName;
                            item.Formula = "[" + i.Code + "_" + j.Code + "_BUYING]";
                            item.Description = i.Description;
                            item.ElementType = CatElementType.ExChangeRate.ToString();
                            item.GradePayrollID = null;
                            item.MethodPayroll = MethodPayroll.E_NORMAL.ToString();
                            listModel.Add(item);
                        }
                        else
                        {
                            if (!listElement.Any(m => m.ElementName == i.Code + "_" + j.Code + "_BUYING" && m.GradePayrollID == null))
                            {
                                Cat_ElementEntity item = new Cat_ElementEntity();
                                item.ElementCode = i.Code + "_" + j.Code + "_BUYING";
                                item.ElementName = "Giá mua " + i.CurrencyName + "_" + j.CurrencyName;
                                item.Formula = "[" + i.Code + "_" + j.Code + "_BUYING]";
                                item.Description = i.Description;
                                item.ElementType = CatElementType.ExChangeRate.ToString();
                                item.GradePayrollID = null;
                                item.MethodPayroll = MethodPayroll.E_NORMAL.ToString();
                                listModel.Add(item);
                            }
                        }

                        //Giá bán
                        if (!listElement.Any(m => m.ElementName == i.Code + "_" + j.Code + "_SELLING"))
                        {
                            Cat_ElementEntity item = new Cat_ElementEntity();
                            item.ElementCode = i.Code + "_" + j.Code + "_SELLING";
                            item.ElementName = "Giá bán " + i.CurrencyName + "_" + j.CurrencyName;
                            item.Formula = "[" + i.Code + "_" + j.Code + "_SELLING]";
                            item.Description = i.Description;
                            item.ElementType = CatElementType.ExChangeRate.ToString();
                            item.GradePayrollID = null;
                            item.MethodPayroll = MethodPayroll.E_NORMAL.ToString();
                            listModel.Add(item);
                        }
                        else
                        {
                            if (!listElement.Any(m => m.ElementName == i.Code + "_" + j.Code + "_SELLING" && m.GradePayrollID == null))
                            {
                                Cat_ElementEntity item = new Cat_ElementEntity();
                                item.ElementCode = i.Code + "_" + j.Code + "_SELLING";
                                item.ElementName = "Giá bán " + i.CurrencyName + "_" + j.CurrencyName;
                                item.Formula = "[" + i.Code + "_" + j.Code + "_SELLING]";
                                item.Description = i.Description;
                                item.ElementType = CatElementType.ExChangeRate.ToString();
                                item.GradePayrollID = null;
                                item.MethodPayroll = MethodPayroll.E_NORMAL.ToString();
                                listModel.Add(item);
                            }
                        }
                    }
                }
            }

            #endregion

            #region Add các phần tử là tăng ca
            if (listOvertimeType != null && listOvertimeType.Count > 0)
            {
                foreach (var i in listOvertimeType)
                {
                    #region Tăng ca tháng N
                    if (!listElement.Any(m => m.ElementName == "ATT_OVERTIME_" + i.Code + "_HOURS"))
                    {
                        Cat_ElementEntity item = new Cat_ElementEntity();
                        item.ElementCode = "ATT_OVERTIME_" + i.Code + "_HOURS";
                        item.ElementName = i.OvertimeTypeName;
                        item.Formula = "[ATT_OVERTIME_" + i.Code + "_HOURS]";
                        item.Description = i.Comment;
                        item.ElementType = CatElementType.Attendance.ToString();
                        item.GradePayrollID = null;
                        item.MethodPayroll = MethodPayroll.E_NORMAL.ToString();
                        listModel.Add(item);
                    }
                    else
                    {
                        if (!listElement.Any(m => m.ElementName == "ATT_OVERTIME_" + i.Code + "_HOURS" && m.GradePayrollID == null))
                        {
                            Cat_ElementEntity item = new Cat_ElementEntity();
                            item.ElementCode = "ATT_OVERTIME_" + i.Code + "_HOURS";
                            item.ElementName = i.OvertimeTypeName;
                            item.Formula = "[ATT_OVERTIME_" + i.Code + "_HOURS]";
                            item.Description = i.Comment;
                            item.ElementType = CatElementType.Attendance.ToString();
                            item.GradePayrollID = null;
                            item.MethodPayroll = MethodPayroll.E_NORMAL.ToString();
                            listModel.Add(item);

                        }
                    }
                    #endregion

                    #region Tăng ca tháng N-1
                    if (!listElement.Any(m => m.ElementName == "ATT_OVERTIME_" + i.Code + "_HOURS_PREV"))
                    {
                        Cat_ElementEntity item = new Cat_ElementEntity();
                        item.ElementCode = "ATT_OVERTIME_" + i.Code + "_HOURS_PREV";
                        item.ElementName = i.OvertimeTypeName + "Tháng N-1";
                        item.Formula = "[ATT_OVERTIME_" + i.Code + "_HOURS_PREV]";
                        item.Description = i.Comment;
                        item.ElementType = CatElementType.Attendance.ToString();
                        item.GradePayrollID = null;
                        item.MethodPayroll = MethodPayroll.E_NORMAL.ToString();
                        listModel.Add(item);
                    }
                    else
                    {
                        if (!listElement.Any(m => m.ElementName == "ATT_OVERTIME_" + i.Code + "_HOURS_PREV" && m.GradePayrollID == null))
                        {
                            Cat_ElementEntity item = new Cat_ElementEntity();
                            item.ElementCode = "ATT_OVERTIME_" + i.Code + "_HOURS_PREV";
                            item.ElementName = i.OvertimeTypeName + "Tháng N-1";
                            item.Formula = "[ATT_OVERTIME_" + i.Code + "_HOURS_PREV]";
                            item.Description = i.Comment;
                            item.ElementType = CatElementType.Attendance.ToString();
                            item.GradePayrollID = null;
                            item.MethodPayroll = MethodPayroll.E_NORMAL.ToString();
                            listModel.Add(item);
                        }
                    }
                    #endregion

                    #region Tăng ca tháng N khi có thay đổi lương
                    if (!listElement.Any(m => m.ElementName == "ATT_OVERTIME_" + i.Code + "_HOURS_AFTER"))
                    {
                        Cat_ElementEntity item = new Cat_ElementEntity();
                        item.ElementCode = "ATT_OVERTIME_" + i.Code + "_HOURS_AFTER";
                        item.ElementName = i.OvertimeTypeName + " sau khi thay đổi lương";
                        item.Formula = "[ATT_OVERTIME_" + i.Code + "_HOURS_AFTER]";
                        item.Description = i.Comment;
                        item.ElementType = CatElementType.Attendance.ToString();
                        item.GradePayrollID = null;
                        item.MethodPayroll = MethodPayroll.E_NORMAL.ToString();
                        listModel.Add(item);
                    }
                    else
                    {
                        if (!listElement.Any(m => m.ElementName == "ATT_OVERTIME_" + i.Code + "_HOURS_AFTER" && m.GradePayrollID == null))
                        {
                            Cat_ElementEntity item = new Cat_ElementEntity();
                            item.ElementCode = "ATT_OVERTIME_" + i.Code + "_HOURS_AFTER";
                            item.ElementName = i.OvertimeTypeName + " sau khi thay đổi lương";
                            item.Formula = "[ATT_OVERTIME_" + i.Code + "_HOURS_AFTER]";
                            item.Description = i.Comment;
                            item.ElementType = CatElementType.Attendance.ToString();
                            item.GradePayrollID = null;
                            item.MethodPayroll = MethodPayroll.E_NORMAL.ToString();
                            listModel.Add(item);
                        }
                    }
                    #endregion
                }
            }
            #endregion

            #region Add các phần tử là hoa hồng
            if (listKPIBonus != null && listKPIBonus.Count > 0)
            {
                foreach (var i in listKPIBonus)
                {
                    Cat_ElementEntity item = new Cat_ElementEntity();
                    item.ElementCode = CatElementType.Comission.ToString().ToUpper() + "_" + i.Code;
                    item.ElementName = i.KPIBonusName;
                    item.Formula = "[" + CatElementType.Comission.ToString().ToUpper() + "_" + i.Code + "]";
                    item.Description = i.Note;
                    item.ElementType = CatElementType.Comission.ToString();
                    item.GradePayrollID = null;
                    item.MethodPayroll = MethodPayroll.E_NORMAL.ToString();
                    listModel.Add(item);
                }
            }

            //các phần tử lương hoa hồng trong bảng cat_element
            List<Cat_ElementEntity> listElementByCommission = listElement.Where(m => m.MethodPayroll == MethodPayroll.E_COMMISSION_PAYMENT.ToString()).ToList();
            if (listElementByCommission.Count > 0)
            {
                foreach (var element in listElementByCommission)
                {
                    Cat_ElementEntity item = new Cat_ElementEntity();
                    item.ElementCode = "ELEMENT" + CatElementType.Comission.ToString().ToUpper() + "_" + element.ElementCode;
                    item.ElementName = element.ElementName;
                    item.Formula = "[ELEMENT" + CatElementType.Comission.ToString().ToUpper() + "_" + element.ElementCode + "]";
                    item.Description = element.Description;
                    item.ElementType = CatElementType.Comission.ToString();
                    item.GradePayrollID = null;
                    item.MethodPayroll = MethodPayroll.E_NORMAL.ToString();
                    listModel.Add(item);
                }
            }
            #endregion

            #region Add Các Phần Tử là số lượng chức vụ (position)
            if (listPosition != null && listPosition.Count > 0)
            {
                foreach (var i in listPosition)
                {
                    Cat_ElementEntity item = new Cat_ElementEntity();
                    item.ElementCode = CatElementType.Comission.ToString().ToUpper() + "_COUNTPOSITION_" + i.Code;
                    item.ElementName = i.PositionName;
                    item.Formula = "[" + CatElementType.Comission.ToString().ToUpper() + "_COUNTPOSITION_" + i.Code + "]";
                    item.Description = i.Description;
                    item.ElementType = CatElementType.Comission.ToString();
                    item.GradePayrollID = null;
                    item.MethodPayroll = MethodPayroll.E_NORMAL.ToString();
                    listModel.Add(item);
                }
            }
            #endregion

            #region Add các phần tử đánh giá
            if (listSalesType != null && listSalesType.Count > 0)
            {
                IList<string> List_EvaBonusType = Enum.GetValues(typeof(EvaBonusType))
                .Cast<EvaBonusType>()
                .Select(x => x.ToString())
                .ToList();
                foreach (var i in listSalesType)
                {
                    foreach (var j in List_EvaBonusType)
                    {
                        Cat_ElementEntity item = new Cat_ElementEntity();
                        item.ElementCode = CatElementType.Evaluation.ToString().ToUpper() + "_" + i.Code + "_" + j;
                        item.ElementName = i.SalesTypeName;
                        item.Formula = "[" + CatElementType.Evaluation.ToString().ToUpper() + "_" + i.Code + "_" + j + "]";
                        item.Description = i.Note;
                        item.ElementType = CatElementType.Evaluation.ToString();
                        item.GradePayrollID = null;
                        item.MethodPayroll = MethodPayroll.E_NORMAL.ToString();
                        listModel.Add(item);
                    }
                }
            }
            if (listPerformanceType != null && listPerformanceType.Count > 0)
            {
                foreach (var i in listPerformanceType)
                {
                    Cat_ElementEntity item = new Cat_ElementEntity();
                    item.ElementCode = CatElementType.Evaluation.ToString().ToUpper() + "_PERFORMANCETYPE_" + i.Code;
                    item.ElementName = i.PerformanceTypeName;
                    item.Formula = "[" + CatElementType.Evaluation.ToString().ToUpper() + "_PERFORMANCETYPE_" + i.Code + "]";
                    item.Description = i.Description;
                    item.ElementType = CatElementType.Evaluation.ToString();
                    item.GradePayrollID = null;
                    item.MethodPayroll = MethodPayroll.E_NORMAL.ToString();
                    listModel.Add(item);
                }
            }
            #endregion

            #region Vietject
            #region Các phần tử là Đơn Giá Công Việc

            if (listCat_Role != null && listCat_Role.Count > 0 && listCat_JobType != null && listCat_JobType.Count > 0)
            {
                for (int i = 0; i < listCat_Role.Count; i++)
                {
                    for (int j = 0; j < listCat_JobType.Count; j++)
                    {
                        //Số giờ bay
                        Cat_ElementEntity item = new Cat_ElementEntity();
                        item.ElementCode = CatElementType.FLIGHT.ToString() + "_" + listCat_Role[i].Code.ReplaceSpace() + "_" + listCat_JobType[j].Code.ReplaceSpace() + "_HOURS";
                        item.ElementName = "Số giờ bay " + listCat_Role[i].RoleName + " " + listCat_JobType[j].JobTypeName;
                        item.Formula = "[" + CatElementType.FLIGHT.ToString() + "_" + listCat_Role[i].Code.ReplaceSpace() + "_" + listCat_JobType[j].Code.ReplaceSpace() + "_HOURS]";
                        item.ElementType = CatElementType.FLIGHT.ToString();
                        item.GradePayrollID = null;
                        item.Description = "";
                        item.MethodPayroll = MethodPayroll.E_NORMAL.ToString();
                        listModel.Add(item);

                        //Số chặn bay
                        item = new Cat_ElementEntity();
                        item.ElementCode = CatElementType.FLIGHT.ToString() + "_" + listCat_Role[i].Code.ReplaceSpace() + "_" + listCat_JobType[j].Code.ReplaceSpace() + "_ROUTES";
                        item.ElementName = "Số chặn bay " + listCat_Role[i].RoleName + " " + listCat_JobType[j].JobTypeName;
                        item.Formula = "[" + CatElementType.FLIGHT.ToString() + "_" + listCat_Role[i].Code.ReplaceSpace() + "_" + listCat_JobType[j].Code.ReplaceSpace() + "_ROUTES]";
                        item.ElementType = CatElementType.FLIGHT.ToString();
                        item.GradePayrollID = null;
                        item.Description = "";
                        item.MethodPayroll = MethodPayroll.E_NORMAL.ToString();
                        listModel.Add(item);

                        //Số tiền
                        item = new Cat_ElementEntity();
                        item.ElementCode = CatElementType.FLIGHT.ToString() + "_" + listCat_Role[i].Code.ReplaceSpace() + "_" + listCat_JobType[j].Code.ReplaceSpace() + "_AMOUNT";
                        item.ElementName = "Tiền " + listCat_Role[i].RoleName + " " + listCat_JobType[j].JobTypeName;
                        item.Formula = "[" + CatElementType.FLIGHT.ToString() + "_" + listCat_Role[i].Code.ReplaceSpace() + "_" + listCat_JobType[j].Code.ReplaceSpace() + "_AMOUNT]";
                        item.ElementType = CatElementType.FLIGHT.ToString();
                        item.GradePayrollID = null;
                        item.Description = "";
                        item.MethodPayroll = MethodPayroll.E_NORMAL.ToString();
                        listModel.Add(item);
                    }
                }
            }
            #endregion

            #endregion

            #region Honda - tổng số ngày làm việc theo từng ca của nhân viên trong tháng

            if (listCat_Shift != null && listCat_Shift.Count > 0)
            {
                foreach (var i in listCat_Shift)
                {
                    Cat_ElementEntity item = new Cat_ElementEntity();
                    item.ElementCode = "ATT_SHIFT" + "_" + i.Code + "_" + "DAY";
                    item.ElementName = "Tổng số ngày làm việc của ca" + i.ShiftName;
                    item.Formula = "[" + "ATT_SHIFT" + "_" + i.Code + "_" + "DAY" + "]";
                    item.Description = string.Empty;
                    item.ElementType = CatElementType.Attendance.ToString();
                    item.GradePayrollID = null;
                    item.MethodPayroll = MethodPayroll.E_NORMAL.ToString();
                    listModel.Add(item);

                    item = new Cat_ElementEntity();
                    item.ElementCode = "ATT_SHIFT" + "_" + i.Code + "_" + "DAY_PREV";
                    item.ElementName = "Tổng số ngày làm việc của ca" + i.ShiftName + " Tháng N-1";
                    item.Formula = "[" + "ATT_SHIFT" + "_" + i.Code + "_" + "DAY_PREV" + "]";
                    item.Description = string.Empty;
                    item.ElementType = CatElementType.Attendance.ToString();
                    item.GradePayrollID = null;
                    item.MethodPayroll = MethodPayroll.E_NORMAL.ToString();
                    listModel.Add(item);

                    item = new Cat_ElementEntity();
                    item.ElementCode = "ATT_SHIFT" + "_" + i.Code + "_" + "HOURS";
                    item.ElementName = "Tổng số giờ làm việc của ca" + i.ShiftName + " Tháng N-1";
                    item.Formula = "[" + "ATT_SHIFT" + "_" + i.Code + "_" + "HOURS" + "]";
                    item.Description = string.Empty;
                    item.ElementType = CatElementType.Attendance.ToString();
                    item.GradePayrollID = null;
                    item.MethodPayroll = MethodPayroll.E_NORMAL.ToString();
                    listModel.Add(item);
                }
            }

            #endregion

        #endregion

            baseService.Add<Cat_ElementEntity>(listModel);

            return Json(true);
        }