public async Task <IActionResult> CostCentralBugets(DataSourceRequest command,
                                                            CostCenterBugetListModel model)
        {
            model.ClientId = (int)_workContext.CurrentCustomer.ClientId;

            var(bugetcostListModel, totalCount) = await _financialManagementService.PrepareCostBugetListModel(model, command.Page, command.PageSize);

            var gridModel = new DataSourceResult
            {
                Data  = bugetcostListModel.ToList(),
                Total = totalCount
            };

            return(Json(gridModel));
        }
        public async Task <IActionResult> CostCentralBugets()
        {
            var model = new CostCenterBugetListModel();

            model.AvailableCostCenter.Add(new SelectListItem {
                Text = "All", Value = "0"
            });

            foreach (var item in (await _financialManagementService.GetCostBugetList((int)_workContext.CurrentCustomer.ClientId)))
            {
                model.AvailableCostCenter.Add(new SelectListItem {
                    Text = item.Exp1, Value = item.SName.Trim()
                });
            }

            return(View(model));
        }
        public async Task <(IEnumerable <CostCenterBugetModel> CBItemModel, int totalCount)> PrepareCostBugetListModel(CostCenterBugetListModel model, int pageIndex, int pageSize)
        {
            SqlParameter[] pr = new SqlParameter[]
            {
                new SqlParameter("@intClientID", model.ClientId)
            };

            var query = await _dbContext.Set <BudgetCostCenter2>().FromSqlRaw("exec BudgetCostCenter2 @intClientID", pr).ToListAsync();

            query = query.Where(b => b.SName != null && b.Exp1 != null).ToList();

            if (model.SearchByCostCenter != "0")
            {
                query = query.Where(b => b.SName.Contains(model.SearchByCostCenter)).ToList();
            }

            query = query.OrderBy(c => c.SName).ToList();

            var bugetcostListModel = new List <CostCenterBugetModel>();

            foreach (var item in query)
            {
                bugetcostListModel.Add(new CostCenterBugetModel
                {
                    Sid            = item.Sid,
                    CostCenterName = item.SName,
                    CostCenter     = item.ShipID,
                    GL             = item.S2GL1,
                    LastYear       = item.S2B2Past,
                    ThisYear       = item.S2B2Now,
                    NextYear       = item.S2B2Next
                });
            }

            int totalCount = bugetcostListModel.Count;
            int pageOffSet = (Convert.ToInt32(pageIndex) - 1) * 10;

            bugetcostListModel = bugetcostListModel.Skip(pageOffSet).Take(Convert.ToInt32(pageSize)).ToList();

            return(bugetcostListModel, totalCount);
        }