Esempio n. 1
0
        public async Task <IActionResult> InventoryControl(DataSourceRequest command,
                                                           InvetoryControlListModel model)
        {
            var(invControlListModel, totalCount) = await _invManagement.PrepareInventoryControlListModel(model, command.Page, command.PageSize);

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

            return(Json(gridModel));
        }
        public async Task <(IEnumerable <InventoryControlModel> inventoryitemModel, int totalCount)> PrepareInventoryControlListModel(InvetoryControlListModel model, int pageIndex, int pageSize)
        {
            var query = from i in _itemRepository.Table
                        join n in _inventoryRepository.Table on i.VitemId equals n.VitemId
                        join v in _vendorRepository.Table on i.VendorId equals v.VendorId
                        join s in _shipToRepository.Table on n.IlocationSid equals s.Sid
                        where n.ClientId == (int)_workContext.CurrentCustomer.ClientId && v.ClientId == (int)_workContext.CurrentCustomer.ClientId
                        select new InventoryControlModel
            {
                InvertID     = n.InventId,
                Category     = (n.Category ?? "unselected"),
                ReorderItem  = i.Vitem,
                VItemID      = i.VitemId,
                Description  = i.Vdescription,
                Unit         = i.Uom,
                Pkg          = i.Pkg,
                ReorderPrice = i.SellingPrice,
                OnHand       = n.IqtyStock1,
                DeptRequest  = (i.DeptResp ?? "0"),
                ReorderLevel = n.Reorder,
                GL           = (i.Gl ?? "unallocated")
            };

            //Searching
            if (!string.IsNullOrWhiteSpace(model.SearchByCriteria))
            {
                query = query.Where(c => c.ReorderItem.Trim().ToLower().Contains(model.SearchByCriteria.Trim().ToLower()) || c.Description.Trim().ToLower().Contains(model.SearchByCriteria.Trim().ToLower()));
            }

            //Sorting
            if (model.SortBy == 9)
            {
                query = query.OrderBy(c => c.Category);
            }

            if (model.SortBy == 2)
            {
                query = query.OrderBy(c => c.Description);
            }

            if (model.SortBy == 10)
            {
                query = query.OrderBy(c => c.ReorderItem);
            }

            if (model.SortBy == 4)
            {
                query = query.OrderBy(c => c.DeptRequest);
            }

            if (model.SortBy == 8)
            {
                query = query.OrderBy(c => c.OnHand);
            }

            if (model.SortBy == 7)
            {
                query = query.OrderBy(c => c.OnOrder);
            }

            if (model.SortBy == 1)
            {
                query = query.OrderBy(c => c.ReorderLevel);
            }

            var invControlListModel = query.ToList();
            int totalCount          = invControlListModel.Count;
            int pageOffSet          = (Convert.ToInt32(pageIndex) - 1) * 10;

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

            return(invControlListModel, totalCount);
        }