Example #1
0
        public DataTable ComparePayroll(Guid[] _cutOffDurationIDs, Guid[] _elementIDs, string OrgOrderNumber, Guid? OrgTypeID, bool isCreateTemplate, string CompareType, string ShowDataType, Guid[] WorkingPlace, string UserLogin)
        {
            using (var context = new VnrHrmDataContext())
            {
                string status = string.Empty;
                DataTable table = GetSchemaComparePayroll(_cutOffDurationIDs, _elementIDs, CompareType, OrgOrderNumber, OrgTypeID, ShowDataType, UserLogin);
                var E_ORGSTRUCTURE = EnumDropDown.CompareType.E_ORGSTRUCTURE.ToString();
                var E_PROFILE = EnumDropDown.CompareType.E_PROFILE.ToString();
                var column = EnumDropDown.ShowDataType.E_COLUMN.ToString();
                var row = EnumDropDown.ShowDataType.E_ROW.ToString();

                if (isCreateTemplate)
                {
                    return table.ConfigTable();
                }
                #region Group Theo Nhân Viên
                if (CompareType == E_PROFILE || string.IsNullOrEmpty(CompareType))
                {
                    // Xử Lý Group Phòng Ban
                    var orgsService = new Cat_OrgStructureServices();
                    var lstObjOrgByOrderNumber = new List<object>();
                    lstObjOrgByOrderNumber.Add(OrgOrderNumber);
                    var lstOrgByOrderNumber = orgsService.GetData<Cat_OrgStructure>(lstObjOrgByOrderNumber, ConstantSql.hrm_cat_sp_get_OrgStructureByOrderNumber, UserLogin, ref status).Select(s => new { s.ID, s.OrgStructureTypeID, s.OrderNumber }).ToList();
                    if (OrgTypeID != null)
                    {
                        lstOrgByOrderNumber = lstOrgByOrderNumber.Where(s => s.OrgStructureTypeID.Value == OrgTypeID.Value).ToList();
                    }
                    var strOrderNumer = string.Empty;
                    var OrderNumber = string.Empty;
                    OrderNumber = null;
                    foreach (var OrgOrderNumer in lstOrgByOrderNumber)
                    {
                        strOrderNumer += OrgOrderNumer.OrderNumber + ",";
                    }
                    if (!string.IsNullOrEmpty(strOrderNumer))
                    {
                        OrderNumber = strOrderNumer.Substring(0, strOrderNumer.Length - 1);
                    }


                    var profileServices = new Hre_ProfileServices();
                    var lstObjProfile = new List<object>();
                    lstObjProfile.Add(OrderNumber);
                    lstObjProfile.Add(null);
                    lstObjProfile.Add(null);
                    var listProfile = profileServices.GetData<Hre_ProfileEntity>(lstObjProfile, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrg, UserLogin, ref status).ToList();

                    if (WorkingPlace != null)
                    {
                        listProfile = listProfile.Where(m => m.WorkPlaceID != null && WorkingPlace.Contains((Guid)m.WorkPlaceID)).ToList();
                    }

                    var attCutOffDurationServices = new Att_CutOffDurationServices();
                    var lstObjCutOff = new List<object>();
                    lstObjCutOff.Add(null);
                    lstObjCutOff.Add(1);
                    lstObjCutOff.Add(int.MaxValue - 1);
                    var lstCutOffDuration = attCutOffDurationServices.GetData<Att_CutOffDurationEntity>(lstObjCutOff, ConstantSql.hrm_att_sp_get_CutOffDurations, UserLogin, ref status).ToList();
                    lstCutOffDuration = lstCutOffDuration.Where(s => _cutOffDurationIDs.Contains(s.ID)).ToList();
                    var lstCutOffDurationID = lstCutOffDuration.Select(s => s.ID).ToList();

                    var elementServices = new Cat_ElementServices();
                    var lstObjElement = new List<object>();
                    lstObjElement.Add(null);
                    lstObjElement.Add(null);
                    lstObjElement.Add(null);
                    lstObjElement.Add(null);
                    lstObjElement.Add(null);
                    lstObjElement.Add(1);
                    lstObjElement.Add(int.MaxValue - 1);
                    var lstElement = elementServices.GetData<Cat_ElementEntity>(lstObjElement, ConstantSql.hrm_cat_sp_get_Element, UserLogin, ref status).ToList();
                    lstElement = lstElement.Where(s => _elementIDs.Contains(s.ID)).ToList();

                    var payrollTableServices = new Sal_PayrollTableServices();
                    var lstObjPayrollTable = new List<object>();
                    lstObjPayrollTable.Add(null);
                    lstObjPayrollTable.Add(null);
                    lstObjPayrollTable.Add(null);
                    lstObjPayrollTable.Add(null);
                    lstObjPayrollTable.Add(1);
                    lstObjPayrollTable.Add(int.MaxValue - 1);
                    var lstPayrollTable = payrollTableServices.GetData<Sal_PayrollTableEntity>(lstObjPayrollTable, ConstantSql.hrm_sal_sp_get_PayrollTable, UserLogin, ref status).ToList();

                    var payrollTableItemServices = new Sal_PayrollTableItemServices();
                    var lstObjPayrollTableItem = new List<object>();
                    lstObjPayrollTableItem.Add(null);
                    lstObjPayrollTableItem.Add(null);
                    lstObjPayrollTableItem.Add(null);
                    lstObjPayrollTableItem.Add(null);
                    lstObjPayrollTableItem.Add(null);
                    lstObjPayrollTableItem.Add(null);
                    lstObjPayrollTableItem.Add(null);
                    lstObjPayrollTableItem.Add(1);
                    lstObjPayrollTableItem.Add(int.MaxValue - 1);
                    var lstPayrollTableItem = payrollTableItemServices.GetData<Sal_PayrollTableItemEntity>(lstObjPayrollTableItem, ConstantSql.hrm_sal_sp_get_PayrollTableItem, UserLogin, ref status).ToList();

                    foreach (var profile in listProfile)
                    {
                        DataRow dr = table.NewRow();
                        dr[Sal_ComparePayrollEntity.FieldNames.CodeEmp] = profile != null ? profile.CodeEmp : string.Empty;
                        dr[Sal_ComparePayrollEntity.FieldNames.ProfileName] = profile != null ? profile.ProfileName : string.Empty;
                        dr[Sal_ComparePayrollEntity.FieldNames.OrgStructureName] = profile != null ? profile.OrgStructureName : string.Empty;
                        foreach (var element in lstElement)
                        {
                            foreach (var cutOff in lstCutOffDuration)
                            {
                                var lstPayrollTableByProfileID = lstPayrollTable.Where(s => s.ProfileID == profile.ID && cutOff.ID == s.CutOffDurationID.Value).ToList();
                                foreach (var payrollTable in lstPayrollTableByProfileID)
                                {
                                    var payrollTableItemData = lstPayrollTableItem.Where(s => s.PayrollTableID == payrollTable.ID).ToList();
                                    foreach (var payrollTableItem in payrollTableItemData)
                                    {
                                        var elementData = payrollTableItemData.Where(s => element.ElementCode == s.Code).FirstOrDefault();
                                        double value = 0;
                                        var elementName = element.ElementName + "_" + (lstCutOffDuration.IndexOf(cutOff) + 1).ToString();
                                        if (table.Columns.Contains(elementName))
                                        {
                                            if (elementData != null)
                                            {
                                                if (elementData.ValueType == typeof(Double).Name)
                                                {
                                                    Double.TryParse(elementData.Value, out value);
                                                }
                                            }
                                            dr[elementName] = value;
                                        }
                                    }
                                }
                            }
                        }
                        table.Rows.Add(dr);
                    }
                }
                #endregion


                #region Group Theo Phòng Ban
                if (CompareType == E_ORGSTRUCTURE)
                {
                    #region Show dữ liệu theo dạng cột
                    if (ShowDataType == column)
                    {
                        // Xử Lý Group Phòng Ban
                        var orgsService = new Cat_OrgStructureServices();
                        var lstallorgs = orgsService.GetDataNotParam<Cat_OrgStructure>(ConstantSql.hrm_cat_sp_get_AllOrg, UserLogin, ref status).ToList();
                        var lstObjOrgByOrderNumber = new List<object>();
                        lstObjOrgByOrderNumber.Add(OrgOrderNumber);
                        var lstOrgByOrderNumber = orgsService.GetData<Cat_OrgStructure>(lstObjOrgByOrderNumber, ConstantSql.hrm_cat_sp_get_OrgStructureByOrderNumber, UserLogin, ref status).Select(s => new { s.ID, s.OrgStructureTypeID, s.OrderNumber, s.OrgStructureName, s.Code }).ToList();
                        if (OrgTypeID != null)
                        {
                            lstOrgByOrderNumber = lstOrgByOrderNumber.Where(s => s.OrgStructureTypeID.Value == OrgTypeID.Value).ToList();
                        }

                        var profileServices = new Hre_ProfileServices();
                        var lstObjProfile = new List<object>();
                        lstObjProfile.AddRange(new object[18]);
                        lstObjProfile[16] = 1;
                        lstObjProfile[17] = int.MaxValue - 1;
                        var listProfile = profileServices.GetData<Hre_ProfileEntity>(lstObjProfile, ConstantSql.hrm_hr_sp_get_Profile, UserLogin, ref status).ToList();

                        if (WorkingPlace != null)
                        {
                            listProfile = listProfile.Where(m => m.WorkPlaceID != null && WorkingPlace.Contains((Guid)m.WorkPlaceID)).ToList();
                        }

                        var attCutOffDurationServices = new Att_CutOffDurationServices();
                        var lstObjCutOff = new List<object>();
                        lstObjCutOff.Add(null);
                        lstObjCutOff.Add(1);
                        lstObjCutOff.Add(int.MaxValue - 1);
                        var lstCutOffDuration = attCutOffDurationServices.GetData<Att_CutOffDurationEntity>(lstObjCutOff, ConstantSql.hrm_att_sp_get_CutOffDurations, UserLogin, ref status).ToList();
                        lstCutOffDuration = lstCutOffDuration.Where(s => _cutOffDurationIDs.Contains(s.ID)).ToList();
                        var lstCutOffDurationID = lstCutOffDuration.Select(s => s.ID).ToList();

                        var elementServices = new Cat_ElementServices();
                        var lstObjElement = new List<object>();
                        lstObjElement.Add(null);
                        lstObjElement.Add(null);
                        lstObjElement.Add(null);
                        lstObjElement.Add(null);
                        lstObjElement.Add(null);
                        lstObjElement.Add(1);
                        lstObjElement.Add(int.MaxValue - 1);
                        var lstElement = elementServices.GetData<Cat_ElementEntity>(lstObjElement, ConstantSql.hrm_cat_sp_get_Element, UserLogin, ref status).ToList();
                        lstElement = lstElement.Where(s => _elementIDs.Contains(s.ID)).ToList();

                        var payrollTableServices = new Sal_PayrollTableServices();
                        var lstObjPayrollTable = new List<object>();
                        lstObjPayrollTable.Add(null);
                        lstObjPayrollTable.Add(null);
                        lstObjPayrollTable.Add(null);
                        lstObjPayrollTable.Add(null);
                        lstObjPayrollTable.Add(1);
                        lstObjPayrollTable.Add(int.MaxValue - 1);
                        var lstPayrollTable = payrollTableServices.GetData<Sal_PayrollTableEntity>(lstObjPayrollTable, ConstantSql.hrm_sal_sp_get_PayrollTable, UserLogin, ref status).ToList();

                        var payrollTableItemServices = new Sal_PayrollTableItemServices();
                        var lstObjPayrollTableItem = new List<object>();
                        lstObjPayrollTableItem.Add(null);
                        lstObjPayrollTableItem.Add(null);
                        lstObjPayrollTableItem.Add(null);
                        lstObjPayrollTableItem.Add(null);
                        lstObjPayrollTableItem.Add(null);
                        lstObjPayrollTableItem.Add(null);
                        lstObjPayrollTableItem.Add(null);
                        lstObjPayrollTableItem.Add(1);
                        lstObjPayrollTableItem.Add(int.MaxValue - 1);
                        var lstPayrollTableItem = payrollTableItemServices.GetData<Sal_PayrollTableItemEntity>(lstObjPayrollTableItem, ConstantSql.hrm_sal_sp_get_PayrollTableItem, UserLogin, ref status).ToList();

                        foreach (var org in lstOrgByOrderNumber)
                        {
                            DataRow dr = table.NewRow();
                            double total = 0;
                            //xử lý đếm nhân viên của phòng ban con
                            orderNumber = string.Empty;
                            orderNumber += org.OrderNumber.ToString() + ",";
                            getChildOrgStructure(lstallorgs, org.ID);
                            // orderNumber += "," + org.OrderNumber.ToString();
                            if (orderNumber.IndexOf(',') > 0)
                                orderNumber = orderNumber.Substring(0, orderNumber.Length - 1);



                            var lstObjProfileByOrgOrderNumer = new List<object>();
                            lstObjProfileByOrgOrderNumer.Add(orderNumber);
                            lstObjProfileByOrgOrderNumer.Add(null);
                            lstObjProfileByOrgOrderNumer.Add(null);
                            var listProfileByOrderNumber = profileServices.GetData<Hre_ProfileEntity>(lstObjProfileByOrgOrderNumer, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrg, UserLogin, ref status).Select(s => s.ID).ToList();

                            dr[Sal_ComparePayrollEntity.FieldNames.OrgStructureCode] = org != null ? org.Code : string.Empty;
                            dr[Sal_ComparePayrollEntity.FieldNames.OrgStructureName] = org != null ? org.OrgStructureName : string.Empty;
                            dr[Sal_ComparePayrollEntity.FieldNames.GroupNumberProfile] = listProfile.Where(m => m.OrgStructureID == org.ID).Count();
                            var lstProfileByOrgID = listProfile.Where(s => listProfileByOrderNumber.Contains(s.ID)).ToList();

                            foreach (var profile in lstProfileByOrgID)
                            {

                                foreach (var element in lstElement)
                                {
                                    foreach (var cutOff in lstCutOffDuration)
                                    {
                                        var lstPayrollTableByProfileID = lstPayrollTable.Where(s => s.ProfileID == profile.ID && cutOff.ID == s.CutOffDurationID.Value).ToList();
                                        foreach (var payrollTable in lstPayrollTableByProfileID)
                                        {
                                            var payrollTableItemData = lstPayrollTableItem.Where(s => s.PayrollTableID == payrollTable.ID).ToList();
                                            foreach (var payrollTableItem in payrollTableItemData)
                                            {
                                                var elementData = payrollTableItemData.Where(s => element.ElementCode == s.Code).FirstOrDefault();
                                                double value = 0;
                                                var elementName = element.ElementName + "_" + (lstCutOffDuration.IndexOf(cutOff) + 1).ToString();
                                                if (table.Columns.Contains(elementName))
                                                {
                                                    if (elementData != null)
                                                    {
                                                        if (elementData.ValueType == typeof(Double).Name)
                                                        {
                                                            Double.TryParse(elementData.Value, out value);
                                                        }
                                                    }
                                                    total += value;
                                                    dr[elementName] = total;
                                                }

                                            }
                                        }
                                    }
                                }
                            }
                            table.Rows.Add(dr);
                        }
                    }
                    #endregion

                    #region Show dữ liệu theo dạng Dòng
                    if (ShowDataType == row)
                    {
                        // Xử Lý Group Phòng Ban
                        var orgsService = new Cat_OrgStructureServices();
                        var lstallorgs = orgsService.GetDataNotParam<Cat_OrgStructure>(ConstantSql.hrm_cat_sp_get_AllOrg, UserLogin, ref status).ToList();
                        var lstObjOrgByOrderNumber = new List<object>();
                        lstObjOrgByOrderNumber.Add(OrgOrderNumber);
                        var lstOrgByOrderNumber = orgsService.GetData<Cat_OrgStructure>(lstObjOrgByOrderNumber, ConstantSql.hrm_cat_sp_get_OrgStructureByOrderNumber, UserLogin, ref status).Select(s => new { s.ID, s.OrgStructureTypeID, s.OrderNumber, s.OrgStructureName, s.Code }).ToList();
                        if (OrgTypeID != null)
                        {
                            lstOrgByOrderNumber = lstOrgByOrderNumber.Where(s => s.OrgStructureTypeID.Value == OrgTypeID.Value).ToList();
                        }

                        var profileServices = new Hre_ProfileServices();
                        var lstObjProfile = new List<object>();
                        lstObjProfile.AddRange(new object[18]);
                        lstObjProfile[16] = 1;
                        lstObjProfile[17] = int.MaxValue - 1;
                        var listProfile = profileServices.GetData<Hre_ProfileEntity>(lstObjProfile, ConstantSql.hrm_hr_sp_get_Profile, UserLogin, ref status).ToList();

                        var attCutOffDurationServices = new Att_CutOffDurationServices();
                        var lstObjCutOff = new List<object>();
                        lstObjCutOff.Add(null);
                        lstObjCutOff.Add(1);
                        lstObjCutOff.Add(int.MaxValue - 1);
                        var lstCutOffDuration = attCutOffDurationServices.GetData<Att_CutOffDurationEntity>(lstObjCutOff, ConstantSql.hrm_att_sp_get_CutOffDurations, UserLogin, ref status).ToList();
                        lstCutOffDuration = lstCutOffDuration.Where(s => _cutOffDurationIDs.Contains(s.ID)).ToList();
                        var lstCutOffDurationID = lstCutOffDuration.Select(s => s.ID).ToList();

                        var elementServices = new Cat_ElementServices();
                        var lstObjElement = new List<object>();
                        lstObjElement.Add(null);
                        lstObjElement.Add(null);
                        lstObjElement.Add(null);
                        lstObjElement.Add(null);
                        lstObjElement.Add(null);
                        lstObjElement.Add(1);
                        lstObjElement.Add(int.MaxValue - 1);
                        var lstElement = elementServices.GetData<Cat_ElementEntity>(lstObjElement, ConstantSql.hrm_cat_sp_get_Element, UserLogin, ref status).ToList();
                        lstElement = lstElement.Where(s => _elementIDs.Contains(s.ID)).ToList();

                        var payrollTableServices = new Sal_PayrollTableServices();
                        var lstObjPayrollTable = new List<object>();
                        lstObjPayrollTable.Add(null);
                        lstObjPayrollTable.Add(null);
                        lstObjPayrollTable.Add(null);
                        lstObjPayrollTable.Add(null);
                        lstObjPayrollTable.Add(1);
                        lstObjPayrollTable.Add(int.MaxValue - 1);
                        var lstPayrollTable = payrollTableServices.GetData<Sal_PayrollTableEntity>(lstObjPayrollTable, ConstantSql.hrm_sal_sp_get_PayrollTable, UserLogin, ref status).ToList();

                        var payrollTableItemServices = new Sal_PayrollTableItemServices();
                        var lstObjPayrollTableItem = new List<object>();
                        lstObjPayrollTableItem.Add(null);
                        lstObjPayrollTableItem.Add(null);
                        lstObjPayrollTableItem.Add(null);
                        lstObjPayrollTableItem.Add(null);
                        lstObjPayrollTableItem.Add(null);
                        lstObjPayrollTableItem.Add(null);
                        lstObjPayrollTableItem.Add(null);
                        lstObjPayrollTableItem.Add(1);
                        lstObjPayrollTableItem.Add(int.MaxValue - 1);
                        var lstPayrollTableItem = payrollTableItemServices.GetData<Sal_PayrollTableItemEntity>(lstObjPayrollTableItem, ConstantSql.hrm_sal_sp_get_PayrollTableItem, UserLogin, ref status).ToList();

                        foreach (var org in lstOrgByOrderNumber)
                        {
                            DataRow dr = table.NewRow();

                            //xử lý đếm nhân viên của phòng ban con
                            orderNumber = string.Empty;
                            orderNumber += org.OrderNumber.ToString() + ",";
                            getChildOrgStructure(lstallorgs, org.ID);
                            // orderNumber += "," + org.OrderNumber.ToString();
                            if (orderNumber.IndexOf(',') > 0)
                                orderNumber = orderNumber.Substring(0, orderNumber.Length - 1);



                            var lstObjProfileByOrgOrderNumer = new List<object>();
                            lstObjProfileByOrgOrderNumer.Add(orderNumber);
                            lstObjProfileByOrgOrderNumer.Add(null);
                            lstObjProfileByOrgOrderNumer.Add(null);
                            var listProfileByOrderNumber = profileServices.GetData<Hre_ProfileEntity>(lstObjProfileByOrgOrderNumer, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrg, UserLogin, ref status).Select(s => s.ID).ToList();

                            dr[Sal_ComparePayrollEntity.FieldNames.OrgStructureCode] = org != null ? org.Code : string.Empty;
                            dr[Sal_ComparePayrollEntity.FieldNames.OrgStructureName] = org != null ? org.OrgStructureName : string.Empty;
                            dr[Sal_ComparePayrollEntity.FieldNames.GroupNumberProfile] = listProfile.Where(m => m.OrgStructureID == org.ID).Count();
                            table.Rows.Add(dr);
                            var lstProfileByOrgID = listProfile.Where(s => listProfileByOrderNumber.Contains(s.ID)).ToList();
                            var lstProfileID = lstProfileByOrgID.Select(s => s.ID).ToList();

                            foreach (var element in lstElement)
                            {
                                DataRow dr1 = table.NewRow();
                                double total = 0;
                                dr1[Sal_ComparePayrollEntity.FieldNames.ElementName] = element.ElementCode;
                                foreach (var cutOff in lstCutOffDuration)
                                {
                                    var lstPayrollTableByProfileID = lstPayrollTable.Where(s => lstProfileID.Contains(s.ProfileID) && cutOff.ID == s.CutOffDurationID.Value).ToList();
                                    foreach (var payrollTable in lstPayrollTableByProfileID)
                                    {
                                        var payrollTableItemData = lstPayrollTableItem.Where(s => s.PayrollTableID == payrollTable.ID && element.ElementCode == s.Code).ToList();
                                        foreach (var payrollTableItem in payrollTableItemData)
                                        {

                                            double value = 0;
                                            var elementName = element.ElementName + "_" + (lstCutOffDuration.IndexOf(cutOff) + 1).ToString();
                                            if (table.Columns.Contains(cutOff.CutOffDurationName))
                                            {

                                                if (payrollTableItem.ValueType == typeof(Double).Name)
                                                {
                                                    Double.TryParse(payrollTableItem.Value, out value);
                                                }

                                                total += value;
                                                dr1[cutOff.CutOffDurationName] = total;
                                            }

                                        }
                                    }
                                }
                                if (total > 0)
                                {
                                    table.Rows.Add(dr1);
                                }

                            }
                        }
                    }
                    #endregion

                }
                #endregion

                //Dictionary<string, Dictionary<string, object>> configs = new Dictionary<string, Dictionary<string, object>>();
                //Dictionary<string, object> config = new Dictionary<string, object>();
                //config.Add("locked", true);
                //configs.Add("CodeEmp", config);
                //configs.Add("ProfileName", config);
                //configs.Add("OrgStructureCode", config);
                //configs.Add("OrgStructureName", config);
                return table.ConfigTable(true);
            }
        }
Example #2
0
        public DataTable GetReportCostCentreByOrg(Guid[] _cutOffDurationIDs, Guid[] _elementIDs, string OrgOrderNumber, string UserLogin, bool isCreateTemplate)
        {
            using (var context = new VnrHrmDataContext())
            {
                string status = string.Empty;
                var baservice = new BaseService();
                DataTable table = GetSchemaRptCostCentreByOrg(_elementIDs, UserLogin);

                if (isCreateTemplate)
                {
                    return table.ConfigTable();
                }

                // Xử Lý Group Phòng Ban
                var orgsService = new Cat_OrgStructureServices();
                var lstObjOrgByOrderNumber = new List<object>();
                lstObjOrgByOrderNumber.Add(OrgOrderNumber);
                var lstOrgByOrderNumber = orgsService.GetData<Cat_OrgStructureEntity>(lstObjOrgByOrderNumber, ConstantSql.hrm_cat_sp_get_OrgStructureByOrderNumber, UserLogin, ref status).Select(s => new { s.ID, s.OrgStructureTypeID, s.OrderNumber, s.OrgStructureName, s.GroupCostCentreID, s.Code }).ToList();

                var strOrderNumer = string.Empty;
                var OrderNumber = string.Empty;
                OrderNumber = null;
                foreach (var OrgOrderNumer in lstOrgByOrderNumber)
                {
                    strOrderNumer += OrgOrderNumer.OrderNumber + ",";
                }
                if (!string.IsNullOrEmpty(strOrderNumer))
                {
                    OrderNumber = strOrderNumer.Substring(0, strOrderNumer.Length - 1);
                }

                var profileServices = new Hre_ProfileServices();
                var lstObjProfile = new List<object>();
                lstObjProfile.Add(OrderNumber);
                lstObjProfile.Add(null);
                lstObjProfile.Add(null);
                var listProfile = profileServices.GetData<Hre_ProfileEntity>(lstObjProfile, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrg, UserLogin, ref status).ToList();
                var lstProfileIDs = listProfile.Select(s => s.ID).ToList();


                List<object> lstObjCostCentreSal = new List<object>();
                lstObjCostCentreSal.AddRange(new object[4]);
                lstObjCostCentreSal[0] = null;
                lstObjCostCentreSal[1] = null;
                lstObjCostCentreSal[2] = 1;
                lstObjCostCentreSal[3] = int.MaxValue - 1;
                var lstSal_CostCentreSal = baservice.GetData<Sal_CostCentreSalEntity>(lstObjCostCentreSal, ConstantSql.hrm_sal_sp_getdata_CostCentreSal, UserLogin, ref status).ToList();

                var lstObjCostCentre = new List<object>();
                lstObjCostCentre.AddRange(new object[4]);
                lstObjCostCentre[0] = null;
                lstObjCostCentre[1] = null;
                lstObjCostCentre[2] = 1;
                lstObjCostCentre[3] = int.MaxValue - 1;
                var lstCostCentre = baservice.GetData<Cat_CostCentreEntity>(lstObjCostCentreSal, ConstantSql.hrm_cat_sp_get_CostCentre, UserLogin, ref status).ToList();
                var lstCostCentreIDs = lstCostCentre.Select(s => s.ID).ToList();

                var payrollTableServices = new Sal_PayrollTableServices();
                var lstObjPayrollTable = new List<object>();
                lstObjPayrollTable.Add(null);
                lstObjPayrollTable.Add(null);
                lstObjPayrollTable.Add(null);
                lstObjPayrollTable.Add(null);
                lstObjPayrollTable.Add(1);
                lstObjPayrollTable.Add(int.MaxValue - 1);
                var lstPayrollTable = payrollTableServices.GetData<Sal_PayrollTableEntity>(lstObjPayrollTable, ConstantSql.hrm_sal_sp_get_PayrollTable, UserLogin, ref status).ToList();

                var payrollTableItemServices = new Sal_PayrollTableItemServices();
                var lstObjPayrollTableItem = new List<object>();
                lstObjPayrollTableItem.Add(null);
                lstObjPayrollTableItem.Add(null);
                lstObjPayrollTableItem.Add(null);
                lstObjPayrollTableItem.Add(null);
                lstObjPayrollTableItem.Add(null);
                lstObjPayrollTableItem.Add(null);
                lstObjPayrollTableItem.Add(null);
                lstObjPayrollTableItem.Add(1);
                lstObjPayrollTableItem.Add(int.MaxValue - 1);
                var lstPayrollTableItem = payrollTableItemServices.GetData<Sal_PayrollTableItemEntity>(lstObjPayrollTableItem, ConstantSql.hrm_sal_sp_get_PayrollTableItem, UserLogin, ref status).ToList();

                var elementServices = new Cat_ElementServices();
                var lstObjElement = new List<object>();
                lstObjElement.Add(null);
                lstObjElement.Add(null);
                lstObjElement.Add(null);
                lstObjElement.Add(null);
                lstObjElement.Add(null);
                lstObjElement.Add(1);
                lstObjElement.Add(int.MaxValue - 1);
                var lstElement = elementServices.GetData<Cat_ElementEntity>(lstObjElement, ConstantSql.hrm_cat_sp_get_Element, UserLogin, ref status).ToList();
                lstElement = lstElement.Where(s => _elementIDs.Contains(s.ID)).ToList();
                foreach (var cost in lstCostCentre)
                {
                    //      var lstOrgByCostcentre = lstOrgByOrderNumber.Where(s => s.GroupCostCentreID.Value == cost.ID).ToList();
                    foreach (var org in lstOrgByOrderNumber)
                    {
                        DataRow dr = table.NewRow();
                        double? sumProfile = 0;
                        var lstProfileByOrg = listProfile.Where(s => s.OrgStructureID.Value == org.ID).ToList();
                        dr[Sal_ReportCostCentreByOrgEntity.FieldNames.CostCentreCode] = cost == null ? string.Empty : cost.Code;
                        dr[Sal_ReportCostCentreByOrgEntity.FieldNames.OrgStructureCode] = org == null ? string.Empty : org.Code;
                        dr[Sal_ReportCostCentreByOrgEntity.FieldNames.OrgStructureName] = org == null ? string.Empty : org.OrgStructureName;

                        foreach (var profile in lstProfileByOrg)
                        {
                            var lstPayrollTableByProfileID = lstPayrollTable.Where(s => profile.ID == s.ProfileID && s.CutOffDurationID.Value == _cutOffDurationIDs[0]).ToList();
                            foreach (var payrollTable in lstPayrollTableByProfileID)
                            {
                                var lstPayrollTableItemByTableID = lstPayrollTableItem.Where(s => s.PayrollTableID == payrollTable.ID).ToList();
                                foreach (var item in lstPayrollTableItemByTableID)
                                {
                                    var costcentreByProfile = lstSal_CostCentreSal.Where(s => s.CostCentreID.Value == cost.ID && payrollTable.ProfileID == s.ProfileID.Value && item.Code == s.ElementType).ToList();

                                    foreach (var costcentre in costcentreByProfile)
                                    {
                                        foreach (var element in lstElement)
                                        {
                                            Double value = 0;
                                            if (costcentre.ElementType == element.ElementCode)
                                            {
                                                if (table.Columns.Contains(element.ElementName))
                                                {
                                                    Double.TryParse(item.Value, out value);
                                                    sumProfile += value * costcentre.Rate;
                                                    dr[element.ElementName] = sumProfile;
                                                }
                                            }
                                        }
                                    }
                                }

                            }
                        }
                        table.Rows.Add(dr);
                    }
                }

                return table.ConfigTable(true);
            }
        }
Example #3
0
        /// <summary>
        /// BC bảng lương
        /// <param name="dateStartCutOffDuration">Ngày bắt đầu của kỳ lương</param>
        /// <param name="monthYear">Tháng</param>
        /// <param name="listOrgIDs">Ds phòng ban</param>
        /// <param name="listPrGroupIDs">Ds nhóm Lương</param>
        /// <param name="isIncludeQuitEmp">Bao gồm NV nghỉ việc</param>
        /// </sumary>  
        public DataTable RefreshData(DateTime dateStartCutOffDuration, DateTime dateEndCutOffDuration, DateTime monthYear, List<Hre_ProfileEntity> listProfile, Guid? gradePayrollID, Boolean isIncludeQuitEmp, string codeEmp, string orderNumber, string Transfer, Guid[] workingPlaceID, Guid[] costcenterIds, string UserLogin)
        {
            try
            {
                using (var context = new VnrHrmDataContext())
                {


                    #region " Load dữ liệu"
                    string status = string.Empty;
                    var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));

                    //kỳ lương (hiện tại mặc định đầu tháng -> cuối tháng)
                    DateTime from = new DateTime(monthYear.Year, monthYear.Month, 1);
                    DateTime to = new DateTime(monthYear.Year, monthYear.Month, DateTime.DaysInMonth(monthYear.Year, monthYear.Month));

                    //Ds tất cả phòng ban
                    var orgServices = new Cat_OrgStructureServices();
                    var lstObjOrg = new List<object>();
                    //  var reposOrgStructure = new CustomBaseRepository<Cat_OrgStructure>(unitOfWork);
                    var listOrgAll = orgServices.GetDataNotParam<Cat_OrgStructure>(ConstantSql.hrm_cat_sp_get_AllOrg, UserLogin, ref status).ToList();

                    var lstObjOrgNumber = new List<object>();
                    lstObjOrgNumber.Add(orderNumber);
                    var lstOrgID = orgServices.GetData<Cat_OrgStructureEntity>(lstObjOrgNumber, ConstantSql.hrm_cat_sp_get_OrgStructureByOrderNumber, UserLogin, ref status).Select(s => s.ID).ToList();


                    //Ds cửa Hàng
                    var shopServices = new Cat_ShopServices();
                    var lstObjShop = new List<object>();
                    lstObjShop.Add(null);
                    lstObjShop.Add(null);
                    lstObjShop.Add(null);
                    lstObjShop.Add(1);
                    lstObjShop.Add(int.MaxValue - 1);
                    var lstShop = shopServices.GetData<Cat_ShopEntity>(lstObjShop, ConstantSql.hrm_cat_sp_get_Shop, UserLogin, ref status).ToList();

                    //Ds tất cả loại PB
                    var orgTypeServices = new Cat_OrgStructureTypeServices();
                    var lstObjOrgType = new List<object>();
                    lstObjOrgType.Add(string.Empty);
                    lstObjOrgType.Add(string.Empty);
                    lstObjOrgType.Add(1);
                    lstObjOrgType.Add(int.MaxValue - 1);
                    var listOrgType = orgTypeServices.GetData<Cat_OrgStructureType>(lstObjOrgType, ConstantSql.hrm_cat_sp_get_OrgStructureType, UserLogin, ref status).ToList();

                    //Ds nhân viên
                    var reposProfile = new CustomBaseRepository<Hre_Profile>(unitOfWork);
                    var profileServices = new Hre_ProfileServices();
                    var lstObjProfile = new List<object>();
                    lstObjProfile.AddRange(new object[17]);
                    lstObjProfile[15] = 1;
                    lstObjProfile[16] = int.MaxValue - 1;

                    var lstModel = new List<object>();
                    lstModel.AddRange(new object[10]);
                    //lstModel[4] = CutOffDuration.DateStart;
                    //lstModel[5] = CutOffDuration.DateEnd;
                    lstModel[8] = 1;
                    lstModel[9] = Int32.MaxValue - 1;
                    List<Sal_HoldSalaryEntity> listHoldSalary = orgTypeServices.GetData<Sal_HoldSalaryEntity>(lstModel, ConstantSql.hrm_sal_sp_get_HoldSalary, UserLogin, ref status).Where(m => m.MonthSalary <= dateEndCutOffDuration && (m.MonthEndSalary == null || m.MonthEndSalary >= dateStartCutOffDuration)).ToList();
                    //bỏ những nhân viên đang bị hold lương
                    listProfile = listProfile.Where(m => !listHoldSalary.Any(t => t.ProfileID == m.ID)).ToList();

                    bool isGroup = profileServices.IsGroupByOrgProfileQuit();

                    //lọc theo nhóm lương
                    List<Guid> listProfileID = listProfile.Select(s => s.ID).Distinct().ToList();

                    //lọc nhân viên nghỉ việc
                    if (!isIncludeQuitEmp)
                    {
                        listProfile = listProfile.Where(pro => pro.DateQuit == null || pro.DateQuit > from).ToList();
                    }

                    if (workingPlaceID != null)
                    {
                        listProfile = listProfile.Where(pro => pro.WorkPlaceID != null && workingPlaceID.Contains(pro.WorkPlaceID.Value)).ToList();
                    }

                    if (costcenterIds != null)
                    {
                        listProfile = listProfile.Where(pro => pro.CostCentreID != null && costcenterIds.Contains(pro.CostCentreID.Value)).ToList();

                    }

                    //lọc theo tên nhân viên
                    if (!string.IsNullOrEmpty(codeEmp))
                    {
                        listProfile = listProfile.Where(s => s.CodeEmp != null && s.CodeEmp.Contains(codeEmp)).ToList();
                    }

                    //ds chế độ lương
                    var saleGradeServices = new Sal_GradeServices();
                    var lstObjSalGrade = new List<object>();
                    lstObjSalGrade.Add(string.Empty);
                    lstObjSalGrade.Add(string.Empty);
                    lstObjSalGrade.Add(string.Empty);
                    lstObjSalGrade.Add(string.Empty);
                    lstObjSalGrade.Add(string.Empty);
                    lstObjSalGrade.Add(1);
                    lstObjSalGrade.Add(int.MaxValue - 1);

                    var reposSalGrade = new CustomBaseRepository<Sal_Grade>(unitOfWork);
                    var lstGradeAll = reposSalGrade.FindBy(s => s.IsDelete != true).ToList();
                    //var lstGradeAll = GetData<Sal_GradeEntity>(lstObjSalGrade, ConstantSql.hrm_sal_sp_get_Sal_Grade, UserLogin,ref status);
                    //ds thông tin lương

                    var salInfoServices = new Sal_SalaryInformationServices();
                    var lstObjSalInfo = new List<object>();
                    lstObjSalInfo.Add(null);
                    lstObjSalInfo.Add(null);
                    lstObjSalInfo.Add(null);
                    lstObjSalInfo.Add(null);
                    lstObjSalInfo.Add(null);
                    lstObjSalInfo.Add(null);
                    lstObjSalInfo.Add(1);
                    lstObjSalInfo.Add(int.MaxValue - 1);

                    var salInfoServices1 = new Sal_SalaryInformationServices();
                    var lstProfileIDs = new List<Guid>();
                    var lstSalaryInformation = salInfoServices.GetData<Sal_SalaryInformationEntity>(lstObjSalInfo, ConstantSql.hrm_sal_sp_get_Sal_SalaryInformation, UserLogin, ref status).ToList();
                    if (Transfer == EnumDropDown.Transfer.E_TRANSFER.ToString())
                    {
                        lstSalaryInformation = lstSalaryInformation.Where(s => s.IsCash == true).ToList();
                        lstProfileIDs = lstSalaryInformation.Select(s => s.ProfileID).ToList();
                    }
                    if (Transfer == EnumDropDown.Transfer.E_CASH.ToString())
                    {
                        lstSalaryInformation = lstSalaryInformation.Where(s => s.IsCash == false).ToList();
                        lstProfileIDs = lstSalaryInformation.Select(s => s.ProfileID).ToList();
                    }
                    if (Transfer == EnumDropDown.Transfer.E_OTHER.ToString())
                    {
                        lstProfileIDs = lstSalaryInformation.Select(s => s.ProfileID).ToList();
                    }

                    //ds loại mã lương 
                    var salaryClassServices = new Cat_SalaryClassServices();
                    var lstObjSalaryClass = new List<object>();
                    lstObjSalaryClass.Add(null);
                    lstObjSalaryClass.Add(1);
                    lstObjSalaryClass.Add(int.MaxValue - 1);
                    var lstSalaryClass = salaryClassServices.GetData<Cat_SalaryClassEntity>(lstObjSalaryClass, ConstantSql.hrm_cat_sp_get_SalaryClass, UserLogin, ref status).ToList().Translate<Cat_SalaryClass>();

                    var revenueProfileServices = new Sal_RevenueForProfileServices();
                    var lstObjRevenueForProfile = new List<object>();
                    lstObjRevenueForProfile.Add(null);
                    lstObjRevenueForProfile.Add(1);
                    lstObjRevenueForProfile.Add(int.MaxValue - 1);
                    var lstRevenueForProfile = revenueProfileServices.GetData<Sal_RevenueForProfileEntity>(lstObjRevenueForProfile, ConstantSql.hrm_sal_sp_get_RevenueForProfile, UserLogin, ref status).ToList();

                    //Ds phần tử lương
                    var elementServices = new Cat_ElementServices();
                    var methodPayroll = MethodPayroll.E_NORMAL.ToString();
                    var lstObjElement = new List<object>();
                    lstObjElement.AddRange(new object[8]);
                    lstObjElement[6] = 1;
                    lstObjElement[7] = int.MaxValue - 1;
                    var reposPayrollElement = new CustomBaseRepository<Cat_Element>(unitOfWork);
                    var listPayrollElement = elementServices.GetData<Cat_ElementEntity>(lstObjElement, ConstantSql.hrm_cat_sp_get_ElementByMethod, UserLogin, ref status).Where(s => s.MethodPayroll == methodPayroll).ToList().Translate<Cat_Element>();

                    #region Chọn lấy  back up bảng lương - Tung.Ly 20150513
                    var salComputePayrollService = new Sal_ComputePayrollServices();
                    var lstSalPayrollTb = new List<Sal_PayrollTableEntity>();
                    var lstSalPayrollTbItem = new List<Sal_PayrollTableItemEntity>();

                    #region param store bang luong
                    var payrollTableServices = new Sal_PayrollTableServices();
                    var lstObjPayrollTable = new List<object>();
                    lstObjPayrollTable.Add(null);
                    lstObjPayrollTable.Add(null);
                    lstObjPayrollTable.Add(from);
                    lstObjPayrollTable.Add(to);
                    lstObjPayrollTable.Add(1);
                    lstObjPayrollTable.Add(int.MaxValue - 1);
                    #endregion

                    #region param store bảng lương chi tiết
                    var payrollTableItemServices = new Sal_PayrollTableItemServices();
                    var lstObjPayrollTableItem = new List<object>();
                    lstObjPayrollTableItem.Add(null);
                    lstObjPayrollTableItem.Add(null);
                    lstObjPayrollTableItem.Add(from);
                    lstObjPayrollTableItem.Add(to);
                    lstObjPayrollTableItem.Add(null);
                    lstObjPayrollTableItem.Add(null);
                    lstObjPayrollTableItem.Add(null);
                    lstObjPayrollTableItem.Add(1);
                    lstObjPayrollTableItem.Add(int.MaxValue - 1);
                    #endregion

                    //kiem ra co du lieu backup không theo kỳ lương
                    if (salComputePayrollService.CheckDataIsBackUp(TypeDataBKInScheduleTask.E_PAYROLL_BK.ToString(), dateStartCutOffDuration))
                    {
                        //Du liệu backup
                        #region ds bảng lương(backcup)
                        lstSalPayrollTb = payrollTableServices.GetData<Sal_PayrollTableEntity>(lstObjPayrollTable, ConstantSql.hrm_sal_sp_get_PayrollTableBK, UserLogin, ref status)
                            .Where(pr => pr.IsDelete == null && pr.MonthYear == monthYear && listProfileID.Contains(pr.ProfileID)).ToList();
                        List<Guid> listSalPayrollIDs = lstSalPayrollTb.Select(p => p.ID).ToList();
                        #endregion

                        #region   ds bảng lương chi tiết(backup)
                        lstSalPayrollTbItem = payrollTableItemServices.GetData<Sal_PayrollTableItemEntity>(lstObjPayrollTableItem, ConstantSql.hrm_sal_sp_get_PayrollTableItemBK, UserLogin, ref status)
                            .Where(it => it.IsDelete == null && listSalPayrollIDs.Contains(it.PayrollTableID)).ToList();
                        #endregion
                    }
                    else
                    {
                        #region ds bảng lương
                        //  var reposSalPayrollTb = new CustomBaseRepository<Sal_PayrollTable>(unitOfWork);
                        lstSalPayrollTb = payrollTableServices.GetData<Sal_PayrollTableEntity>(lstObjPayrollTable, ConstantSql.hrm_sal_sp_get_PayrollTable, UserLogin, ref status)
                            .Where(pr => pr.IsDelete == null && pr.MonthYear == monthYear && listProfileID.Contains(pr.ProfileID)).ToList();
                        List<Guid> listSalPayrollIDs = lstSalPayrollTb.Select(p => p.ID).ToList();
                        #endregion

                        #region   ds bảng lương chi tiết
                        //  var reposSalPayrollTbItem = new CustomBaseRepository<Sal_PayrollTableItem>(unitOfWork);
                        lstSalPayrollTbItem = payrollTableItemServices.GetData<Sal_PayrollTableItemEntity>(lstObjPayrollTableItem, ConstantSql.hrm_sal_sp_get_PayrollTableItem, UserLogin, ref status)
                            .Where(it => it.IsDelete == null && listSalPayrollIDs.Contains(it.PayrollTableID)).ToList();
                        #endregion
                    }
                    #endregion

                    //  var lstSalPayrollTbItem = reposSalPayrollTbItem.GetAll().Where(it => it.IsDelete == null && listSalPayrollIDs.Contains(it.PayrollTableID)).ToList();
                    //Tạo cột dữ liệu cho table
                    DataTable tblData = GetSchemaOverallPayroll();
                    #endregion
                    #region " Không có dữ liệu Sal_PayrollTable"
                    if (lstSalPayrollTb == null || lstSalPayrollTb.Count <= 0)
                    {
                        foreach (Hre_ProfileEntity profile in listProfile)
                        {
                            var lstRankByProfileId = lstShop.Where(s => s.ID == profile.ShopID).FirstOrDefault();
                            DataRow dr = tblData.NewRow();
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.MonthYear] = monthYear;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.CodeEmp] = profile.CodeEmp;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.CodeAttendance] = profile.CodeAttendance;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.ProfileName] = profile.ProfileName;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.LaborType] = profile.LaborType;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.OrgStructureName] = profile.OrgStructureName;

                            dr["ShopGroupName"] = lstRankByProfileId != null ? lstRankByProfileId.ShopGroupName : string.Empty;
                            dr["OrgStructureType"] = profile.E_COMPANY_CODE + "->" + profile.E_BRANCH_CODE + "->" + profile.E_UNIT_CODE + "->" + profile.E_DIVISION_CODE + "->" + profile.E_DEPARTMENT_CODE + "->" + profile.E_TEAM_CODE + "->" + profile.E_SECTION_CODE;

                            //Sal_BasicSalaryEntity BasicSalaryByProfile = listBasicSalary.SingleOrDefault(m => m.ProfileID == profile.ID);
                            //dr["SalaryRankName"] = BasicSalaryByProfile != null ? BasicSalaryByProfile.SalaryRankName : "";

                            //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.EmployeeType] = profile.Cat_EmployeeType != null ? profile.Cat_EmployeeType.EmployeeTypeName : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.EmployeeType] = profile.EmployeeTypeName;
                            //dr["CostCenterCodePayrollTable"] = profile.CostCentreNamePayrollTable;
                            //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.Supervisor] = profile.Supervisor != null ? profile.Supervisor : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.Supervisor] = profile.Supervisor;
                            //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.HighSupervisor] = profile.HighSupervisor != null ? profile.HighSupervisor : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.HighSupervisor] = profile.HighSupervisor;
                            //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.WorkPlace] = profile.Cat_WorkPlace != null ? profile.Cat_WorkPlace.WorkPlaceName : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.WorkPlace] = profile.WorkPlaceName;
                            //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.TaxCode] = profile.CodeTax != null ? profile.CodeTax : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.TaxCode] = profile.CodeTax;
                            //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.IDNo] = profile.IDNo != null ? profile.IDNo : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.IDNo] = profile.IDNo;
                            //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.CostCenter] = profile.Cat_CostCentre != null ? profile.Cat_CostCentre.CostCentreName : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.CostCenter] = profile.CostCentreName;
                            //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.CostCenterCode] = profile.Cat_CostCentre != null ? profile.Cat_CostCentre.Code : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.CostCenterCode] = profile.CostCentreCode;
                            //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.PositionName] = profile.Cat_Position != null ? profile.Cat_Position.PositionName : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.PositionName] = profile.PositionName;
                            //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.JobtitleName] = profile.Cat_JobTitle != null ? profile.Cat_JobTitle.JobTitleName : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.JobtitleName] = profile.JobTitleName;
                            //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.Email] = profile.Email != null ? profile.Email : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.Email] = profile.Email;
                            if (profile.DateHire != null)
                                dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.DateHire] = profile.DateHire.Value;
                            if (profile.DateQuit != null)
                                dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.DateQuit] = profile.DateQuit;
                            if (profile.DateEndProbation != null)
                                dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.DateEndProbation] = profile.DateEndProbation.Value;
                            //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.SocialInsNo] = profile.SocialInsNo != null ? profile.SocialInsNo : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.SocialInsNo] = profile.SocialInsNo;
                            //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.PayrollGroup] = profile.Cat_PayrollGroup != null ? profile.Cat_PayrollGroup.PayrollGroupName : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.PayrollGroup] = profile.PayrollGroupName;
                            dr["CostSource"] = profile.CostSourceName;
                            if (profile.SalaryClassID != null)
                            {
                                Cat_SalaryClass salClass = lstSalaryClass.Where(s => s.ID == profile.SalaryClassID.Value && s.IsDelete == null).FirstOrDefault();
                                if (salClass != null)
                                {
                                    dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.SalaryClassName] = salClass.SalaryClassName;
                                }
                            }
                            if (profile.OrgStructureID != null)
                            {
                                var orgName = GetParentOrg(listOrgAll, listOrgType, profile.OrgStructureID);
                                if (orgName.Count < 3)
                                {
                                    orgName.Insert(0, string.Empty);
                                    if (orgName.Count < 3)
                                    {
                                        orgName.Insert(0, string.Empty);
                                    }
                                }
                                dr[Hre_ReportHCSalesEntity.FieldNames.Channel] = orgName[2];
                                dr[Hre_ReportHCSalesEntity.FieldNames.Region] = orgName[1];
                                dr[Hre_ReportHCSalesEntity.FieldNames.Area] = orgName[0];



                            }

                            //   Hre_Contract hrcontract = lstHreContractAll.Where(hr => hr.ProfileID == profile.ID && hr.IsDelete == null).FirstOrDefault();
                            //if (hrcontract != null && hrcontract.RankRateID != null)
                            //{
                            //    Cat_SalaryRank salrank = lstSalaryRankAll.Where(rk => rk.ID == hrcontract.RankRateID.Value && rk.IsDelete == null).FirstOrDefault();
                            //    dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.SalaryRankName] = salrank != null ? salrank.SalaryRankName : string.Empty;
                            //}

                            #region Insurance, Bank
                            var salaryInformationList = lstSalaryInformation.Where(sal => sal.ProfileID == profile.ID).ToList();
                            if (salaryInformationList.Count > 0)
                            {
                                Sal_SalaryInformationEntity bankSalary = salaryInformationList[0];
                                string accountTemp = string.Empty;
                                string accountNo = string.Empty;
                                string accountNo2 = string.Empty;
                                string bankNameTemp = string.Empty;
                                string bankCode = string.Empty;

                                accountTemp = bankSalary.AccountNo == null ? string.Empty : bankSalary.AccountNo;
                                accountNo = bankSalary.AccountNo == null ? string.Empty : bankSalary.AccountNo;
                                accountNo2 = bankSalary.AccountNo2 == null ? string.Empty : bankSalary.AccountNo2;
                                bankNameTemp = bankSalary.BankName == null ? string.Empty : bankSalary.BankName;
                                bankCode = bankSalary.BankCode1 == null ? string.Empty : bankSalary.BankCode1;

                                if (!string.IsNullOrEmpty(accountTemp))
                                    dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.BankAccountNo] = accountTemp.Trim();
                                if (!string.IsNullOrEmpty(accountNo))
                                    dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.AccountNo] = accountNo.Trim();
                                if (!string.IsNullOrEmpty(accountNo2))
                                    dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.AccountNo2] = accountNo2.Trim();
                                if (!string.IsNullOrEmpty(bankCode))
                                    dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.BankCode] = bankCode.Trim();
                                if (!string.IsNullOrEmpty(bankNameTemp))
                                    dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.BankName] = bankNameTemp.Trim();
                            }
                            #endregion

                            tblData.Rows.Add(dr);
                        }
                    }
                    #endregion
                    #region " Có dữ liệu tính lương Sal_PayrollTable"
                    else
                    {
                        foreach (Sal_PayrollTableEntity payroll in lstSalPayrollTb)
                        {
                            if (Transfer != null)
                            {
                                listProfile = listProfile.Where(s => lstProfileIDs.Contains(s.ID)).ToList();
                            }
                            Hre_ProfileEntity profile = listProfile.Where(s => s.ID == payroll.ProfileID).FirstOrDefault();

                            if (profile == null)
                                continue;

                            var lstRevenueByProfileId = lstRevenueForProfile.Where(s => s.ProfileID == payroll.ProfileID).FirstOrDefault();
                            var lstRankByProfileId = lstShop.Where(s => s.ID == profile.ShopID).FirstOrDefault();
                            //var unusualByProfileId = lstUnusual.Where(s => s.ProfileID == profile.ID).FirstOrDefault();
                            List<Sal_PayrollTableItemEntity> listItem = lstSalPayrollTbItem.Where(pi => pi.PayrollTableID == payroll.ID).ToList();

                            DataRow dr = tblData.NewRow();
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.ID] = payroll.ID;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.MonthYear] = monthYear;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.CodeEmp] = profile.CodeEmp;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.CodeAttendance] = profile.CodeAttendance;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.OrgStructureName] = profile.OrgStructureName;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.ProfileName] = profile.ProfileName;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.IsPaid] = payroll.IsPaid == null ? false : payroll.IsPaid.Value;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.LaborType] = profile.LaborType;
                            dr["OrgStructureType"] = profile.E_COMPANY_CODE + "->" + profile.E_BRANCH_CODE + "->" + profile.E_UNIT_CODE + "->" + profile.E_DIVISION_CODE + "->" + profile.E_DEPARTMENT_CODE + "->" + profile.E_TEAM_CODE + "->" + profile.E_SECTION_CODE;
                            dr["ShopGroupName"] = lstRankByProfileId != null ? lstRankByProfileId.ShopGroupName : string.Empty;

                            //Sal_BasicSalaryEntity BasicSalaryByProfile = listBasicSalary.SingleOrDefault(m => m.ProfileID == profile.ID);
                            //dr["SalaryRankName"] = BasicSalaryByProfile != null ? BasicSalaryByProfile.SalaryRankName : "";

                            //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.EmployeeType] = profile.Cat_EmployeeType != null ? profile.Cat_EmployeeType.EmployeeTypeName : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.EmployeeType] = profile.EmployeeTypeName;
                            //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.Supervisor] = profile.Supervisor != null ? profile.Supervisor : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.Supervisor] = profile.Supervisor;
                            //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.HighSupervisor] = profile.HighSupervisor != null ? profile.HighSupervisor : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.HighSupervisor] = profile.HighSupervisor;
                            //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.WorkPlace] = profile.Cat_WorkPlace != null ? profile.Cat_WorkPlace.WorkPlaceName : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.WorkPlace] = profile.WorkPlaceName;
                            //  dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.WorkingPlace] = profile.WorkingPlace != null ? profile.WorkingPlace : string.Empty;
                            //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.TaxCode] = profile.CodeTax != null ? profile.CodeTax : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.TaxCode] = profile.CodeTax;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.IDNo] = profile.IDNo;
                            //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.IDNo] = profile.IDNo != null ? profile.IDNo : string.Empty;
                            dr["CostCenterCodePayrollTable"] = payroll.CostCentreNamePayrollTable;

                            //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.CostCenter] = profile.Cat_CostCentre != null ? profile.Cat_CostCentre.CostCentreName : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.CostCenter] = profile.CostCentreName;
                            //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.CostCenterCode] = profile.Cat_CostCentre != null ? profile.Cat_CostCentre.Code : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.CostCenterCode] = profile.CostCentreCode;
                            //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.PositionName] = profile.Cat_Position != null ? profile.Cat_Position.PositionName : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.PositionName] = profile.PositionName;
                            //dr["PositionCode"] = profile.Cat_Position != null ? profile.Cat_Position.Code : string.Empty;
                            dr["PositionCode"] = profile.PositionCode;

                            //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.JobtitleName] = profile.Cat_JobTitle != null ? profile.Cat_JobTitle.JobTitleName : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.JobtitleName] = profile.JobTitleName;
                            //dr["JobtitleCode"] = profile.Cat_JobTitle != null ? profile.Cat_JobTitle.Code : string.Empty;
                            dr["JobtitleCode"] = profile.JobTitleCode;
                            dr["CostSource"] = profile.CostSourceName;
                            //dr["Rank"] = lstRankByProfileId != null ? lstRankByProfileId.Rank : string.Empty;
                            //dr["Target"] = lstRevenueByProfileId != null ? lstRevenueByProfileId.Target : 0;
                            //dr["Actual"] = lstRevenueByProfileId != null ? lstRevenueByProfileId.Actual : 0;

                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.Email] = profile.Email != null ? profile.Email : string.Empty;
                            if (profile.DateHire != null)
                                dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.DateHire] = profile.DateHire.Value;
                            if (profile.DateQuit != null)
                                dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.DateQuit] = profile.DateQuit;
                            if (profile.DateEndProbation != null)
                                dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.DateEndProbation] = profile.DateEndProbation.Value;

                            //if (unusualByProfileId != null)
                            //{
                            //    if (unusualByProfileId.MonthStart != null)
                            //    {
                            //        dr["MonthStart"] = unusualByProfileId.MonthStart;
                            //    }
                            //}
                            //if (unusualByProfileId != null)
                            //{
                            //    if (unusualByProfileId.MonthEnd != null)
                            //    {
                            //        dr["MonthEnd"] = unusualByProfileId.MonthEnd;
                            //    }
                            //}
                            //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.SocialInsNo] = profile.SocialInsNo != null ? profile.SocialInsNo : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.SocialInsNo] = profile.SocialInsNo;
                            //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.PayrollGroup] = profile.Cat_PayrollGroup != null ? profile.Cat_PayrollGroup.PayrollGroupName : string.Empty;
                            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.PayrollGroup] = profile.PayrollGroupName;
                            if (profile.OrgStructureID != null)
                            {
                                var orgName = new List<string>();
                                var orgCode = new List<string>();
                                if (isGroup)
                                {

                                    var orgEntity = listOrgAll.Where(s => s.ID == profile.OrgStructureID).FirstOrDefault();
                                    if (orgEntity != null)
                                    {
                                        orgName = GetParentOrgNameForShiseido(listOrgAll, listOrgType, profile.OrgStructureID);
                                        if (orgName.Count < 5)
                                        {
                                            orgName.Insert(0, string.Empty);
                                            if (orgName.Count < 5)
                                            {
                                                orgName.Insert(0, string.Empty);
                                            }
                                            if (orgName.Count < 5)
                                            {
                                                orgName.Insert(0, string.Empty);
                                            }
                                            if (orgName.Count < 5)
                                            {
                                                orgName.Insert(0, string.Empty);
                                            }
                                            if (orgName.Count < 5)
                                            {
                                                orgName.Insert(0, string.Empty);
                                            }

                                        }

                                        orgCode = GetParentOrgCodeForShiseido(listOrgAll, listOrgType, profile.OrgStructureID);
                                        if (orgCode.Count < 5)
                                        {
                                            orgCode.Insert(0, string.Empty);
                                            if (orgCode.Count < 5)
                                            {
                                                orgCode.Insert(0, string.Empty);
                                            }
                                            if (orgCode.Count < 5)
                                            {
                                                orgCode.Insert(0, string.Empty);
                                            }
                                            if (orgCode.Count < 5)
                                            {
                                                orgCode.Insert(0, string.Empty);
                                            }
                                            if (orgCode.Count < 5)
                                            {
                                                orgCode.Insert(0, string.Empty);
                                            }
                                        }

                                    }
                                    dr["Công Ty"] = orgName[4];
                                    dr["Chi Nhánh"] = orgName[3];
                                    dr[Hre_ReportHCSalesEntity.FieldNames.Channel] = orgName[2];
                                    dr[Hre_ReportHCSalesEntity.FieldNames.Region] = orgName[1];
                                    dr[Hre_ReportHCSalesEntity.FieldNames.Area] = orgName[0];


                                    dr["Mã Công Ty"] = orgCode[4];
                                    dr["Mã Chi Nhánh"] = orgCode[3];
                                    dr["Mã Channel"] = orgCode[2];
                                    dr["Mã Region"] = orgCode[1];
                                    dr["Mã Area"] = orgCode[0];
                                }





                                //var orgBranch = LibraryService.GetNearestParent(profile.OrgStructureID, OrgUnit.E_BRANCH, listOrgAll, listOrgType);
                                //var orgOrg = LibraryService.GetNearestParent(profile.OrgStructureID, OrgUnit.E_DEPARTMENT, listOrgAll, listOrgType);
                                //var orgTeam = LibraryService.GetNearestParent(profile.OrgStructureID, OrgUnit.E_TEAM, listOrgAll, listOrgType);
                                //var orgSection = LibraryService.GetNearestParent(profile.OrgStructureID, OrgUnit.E_SECTION, listOrgAll, listOrgType);
                                //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.BranchCode] = orgBranch != null ? orgBranch.Code : string.Empty;
                                //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.DepartmentCode] = orgOrg != null ? orgOrg.Code : string.Empty;
                                //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.TeamCode] = orgTeam != null ? orgTeam.Code : string.Empty;
                                //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.SectionCode] = orgSection != null ? orgSection.Code : string.Empty;
                                //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty;
                                //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.DepartmentName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                                //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
                                //dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty;
                            }



                            //     Hre_Contract hrcontract = lstHreContractAll.Where(hr => hr.ProfileID == profile.ID && hr.IsDelete == null).FirstOrDefault();

                            if (profile.SalaryClassID != null)
                            {
                                Cat_SalaryClass salClass = lstSalaryClass.Where(s => s.ID == profile.SalaryClassID.Value && s.IsDelete == null).FirstOrDefault();
                                if (salClass != null)
                                {
                                    dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.SalaryClassName] = salClass.SalaryClassName;
                                }
                            }

                            //if (hrcontract != null && hrcontract.RankRateID != null)
                            //{
                            //    if (profile.SalaryClassID != null)
                            //    {
                            //        Cat_SalaryRank salrank = lstSalaryRankAll.Where(rk => rk.SalaryClassID == profile.SalaryClassID.Value && hrcontract.RankRateID == rk.ID && rk.IsDelete == null).FirstOrDefault();
                            //        if (salrank != null)
                            //            dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.SalaryRankName] = salrank.SalaryRankName;
                            //    }

                            //}

                            #region Insurance, Bank
                            var salaryInformationList = lstSalaryInformation.Where(sal => sal.ProfileID == profile.ID).ToList();


                            if (salaryInformationList.Count > 0)
                            {
                                Sal_SalaryInformationEntity bankSalary = salaryInformationList[0];
                                string accountTemp = string.Empty;
                                string accountNo = string.Empty;
                                string accountNo2 = string.Empty;
                                string bankNameTemp = string.Empty;
                                string bankCode = string.Empty;

                                accountTemp = bankSalary.AccountNo == null ? string.Empty : bankSalary.AccountNo;
                                accountNo = bankSalary.AccountNo == null ? string.Empty : bankSalary.AccountNo;
                                accountNo2 = bankSalary.AccountNo2 == null ? string.Empty : bankSalary.AccountNo2;
                                bankNameTemp = bankSalary.BankName == null ? string.Empty : bankSalary.BankName;
                                bankCode = bankSalary.BankCode1 == null ? string.Empty : bankSalary.BankCode1;

                                if (!string.IsNullOrEmpty(accountTemp))
                                    dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.BankAccountNo] = accountTemp.Trim();
                                if (!string.IsNullOrEmpty(accountNo))
                                    dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.AccountNo] = accountNo.Trim();
                                if (!string.IsNullOrEmpty(accountNo2))
                                    dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.AccountNo2] = accountNo2.Trim();
                                if (!string.IsNullOrEmpty(bankCode))
                                    dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.BankCode] = bankCode.Trim();
                                if (!string.IsNullOrEmpty(bankNameTemp))
                                    dr[Sal_ReportBasicSalaryMonthlyEntity.FieldNames.BankName] = bankNameTemp.Trim();
                            }
                            #endregion

                            #region sal grade
                            Sal_Grade grade = new Sal_Grade();
                            if (gradePayrollID != null)
                            {
                                grade = lstGradeAll.Where(gr => gr.IsDelete == null && gr.ProfileID == profile.ID && gradePayrollID.Value == gr.GradePayrollID
                                                                    && gr.MonthStart < to).OrderByDescending(gr => gr.MonthStart).FirstOrDefault();
                            }
                            else
                            {
                                grade = lstGradeAll.Where(gr => gr.IsDelete == null && gr.ProfileID == profile.ID
                                                                       && gr.MonthStart < to).OrderByDescending(gr => gr.MonthStart).FirstOrDefault();
                            }


                            if (grade != null)
                            {
                                Cat_GradePayroll gradepayroll = grade.Cat_GradePayroll;
                                if (gradepayroll != null && gradepayroll.IsFormulaSalary == true)
                                {
                                    try
                                    {
                                        var lstSalPrItem = lstSalPayrollTbItem.Where(sal => sal.PayrollTableID == payroll.ID).ToList();
                                        var lstelement = listPayrollElement.Where(pr => pr.GradePayrollID == gradepayroll.ID).ToList();
                                        if (lstelement != null && lstelement.Count > 0)
                                        {
                                            foreach (Cat_Element payrollElement in lstelement)
                                            {
                                                if (payrollElement != null && !String.IsNullOrEmpty(payrollElement.ElementCode))
                                                {
                                                    if (payrollElement.Type == "Nvarchar")
                                                    {
                                                        //Add phần tử vào cột dữ liệu nếu chưa có
                                                        if (!tblData.Columns.Contains(payrollElement.ElementCode))
                                                        {
                                                            tblData.Columns.Add(payrollElement.ElementCode);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        //Add phần tử vào cột dữ liệu nếu chưa có
                                                        if (!tblData.Columns.Contains(payrollElement.ElementCode))
                                                        {
                                                            tblData.Columns.Add(payrollElement.ElementCode, typeof(Double));
                                                        }
                                                    }



                                                    //Lấy value của phần tử 
                                                    if (tblData.Columns.Contains(payrollElement.ElementCode))
                                                    {
                                                        Sal_PayrollTableItemEntity item = lstSalPrItem.Where(it => it.Code == payrollElement.ElementCode).FirstOrDefault();
                                                        Double value = 0;
                                                        if (item != null)
                                                        {
                                                            if (item.ValueType == typeof(Double).Name)
                                                            {
                                                                Double.TryParse(item.Value, out value);
                                                                dr[payrollElement.ElementCode] = value;
                                                            }
                                                            if (item.ValueType == EnumDropDown.DataType.Nvarchar.ToString())
                                                            {
                                                                dr[payrollElement.ElementCode] = item.Value;
                                                            }
                                                        }

                                                    }
                                                }
                                            }
                                        }
                                    }
                                    catch { }
                                }
                                tblData.Rows.Add(dr);
                            }
                            #endregion


                        }
                    }
                    #endregion
                    var configs = new Dictionary<string, Dictionary<string, object>>();
                    var config = new Dictionary<string, object>();
                    config.Add("hidden", true);
                    configs.Add("ID", config);
                    return tblData.ConfigTable(configs, true);
                }
            }
            catch (Exception ex)
            {
                return new DataTable();
            }
        }