예제 #1
0
        private IQueryable <InventoryDAO> OrFilter(IQueryable <InventoryDAO> query, InventoryFilter filter)
        {
            if (filter.OrFilter == null || filter.OrFilter.Count == 0)
            {
                return(query);
            }
            IQueryable <InventoryDAO> initQuery = query.Where(q => false);

            foreach (InventoryFilter InventoryFilter in filter.OrFilter)
            {
                IQueryable <InventoryDAO> queryable = query;
                if (InventoryFilter.Id != null)
                {
                    queryable = queryable.Where(q => q.Id, InventoryFilter.Id);
                }
                if (InventoryFilter.WarehouseId != null)
                {
                    queryable = queryable.Where(q => q.WarehouseId, InventoryFilter.WarehouseId);
                }
                if (InventoryFilter.ItemId != null)
                {
                    queryable = queryable.Where(q => q.ItemId, InventoryFilter.ItemId);
                }
                if (InventoryFilter.SaleStock != null)
                {
                    queryable = queryable.Where(q => q.SaleStock, InventoryFilter.SaleStock);
                }
                if (InventoryFilter.AccountingStock != null)
                {
                    queryable = queryable.Where(q => q.AccountingStock, InventoryFilter.AccountingStock);
                }
                initQuery = initQuery.Union(queryable);
            }
            return(initQuery);
        }
        public IEnumerable <HistoryModel> GetInventory(InventoryFilter filter)
        {
            IEnumerable <HistoryModel> inventory = null;

            switch (filter)
            {
            case InventoryFilter.All:
                inventory = _inventory;
                break;

            case InventoryFilter.Freezer:
                inventory = _inventory.Where(i => i.Storage == StorageType.Freezer);
                break;

            case InventoryFilter.Fridge:
                inventory = _inventory.Where(i => i.Storage == StorageType.Fridge);
                break;

            default:
                inventory = _inventory.Where(i => i.Storage != StorageType.Fridge && i.Storage != StorageType.Freezer);
                break;
            }

            return(inventory);
        }
예제 #3
0
        public async Task <int> Count(InventoryFilter filter)
        {
            IQueryable <InventoryDAO> Inventorys = DataContext.Inventory;

            Inventorys = DynamicFilter(Inventorys, filter);
            return(await Inventorys.CountAsync());
        }
예제 #4
0
 /// <summary>
 /// Adds a filter to the inventory view.  If active, the
 /// view will be regenerated.
 /// </summary>
 public void AddFilter(InventoryFilter filter)
 {
     _filters.Add(filter);
     if (Active)
     {
         Generate();
     }
 }
예제 #5
0
 /// <summary>
 /// Removes a filter from the inventory view.  If active, the
 /// view will be regenerated.
 /// </summary>
 public void RemoveFilter(InventoryFilter filter)
 {
     _filters.Remove(filter);
     if (Active)
     {
         Generate();
     }
 }
예제 #6
0
        public void ShowDetails()
        {
            InventoryFilter.Clear();
            var an = new DoubleAnimation(1, TimeSpan.FromSeconds(.3))
            {
                EasingFunction = R.MiscResources.QuadraticEase
            };

            an.Completed += (o, args) => DetailsBorder.IsHitTestVisible = true;
            DetailsBorder.BeginAnimation(OpacityProperty, an);
        }
예제 #7
0
 /// <summary>
 /// Apply an InventoryFilter to all the items in the InventorySpace.
 /// </summary>
 public void Apply(InventoryFilter filter, int index)
 {
     Debug.Assert(space != null, "Cannot filter null InventorySpace!");
     // For the first filter, fill the list from the InventorySpace.
     if (index == 0)
     {
         _items = filter.Filtered(space.items, _items);
     }
     else   // On subsequent filtering, just filter the already filtered items.
     {
         filter.Filter(_items);
     }
 }
예제 #8
0
        public async Task <List <InventoryDto> > GetByFilter(InventoryFilter inventoryFilter)
        {
            var queryAllInventories = _unitOfWork.InventortRepository
                                      .FindByCondition(i => i.TenantId == inventoryFilter.TenantId.Value);

            IQueryable <Inventory> queryInventory = queryAllInventories;

            if (inventoryFilter.InventoryType == InventoryType.StockMovement)
            {
                inventoryFilter.FromDate = inventoryFilter.FromDate ?? DateTime.Today;
                inventoryFilter.ToDate   = inventoryFilter.ToDate ?? DateTime.Today;
                queryInventory           = queryInventory.Where(i => i.CreatedDate >= inventoryFilter.FromDate &&
                                                                i.CreatedDate <= inventoryFilter.ToDate);
            }
            var inventories = await queryInventory.AsNoTracking()
                              .OrderByDescending(t => t.CreatedDate)
                              .ToListAsync();

            inventories = inventories.GroupBy(i => i.ProductId)
                          .Select(grp => grp.FirstOrDefault())
                          .ToList();
            var productIdList = inventories.Select(i => i.ProductId).ToList();
            var products      = await _unitOfWork.ProductRepository
                                .FindByCondition(p => productIdList.Contains(p.Id))
                                .Include(p => p.ProductType)
                                .Include(p => p.ProductManufacturer)
                                .Include(p => p.TaxCategory)
                                .Include(p => p.ProductCategories)
                                .ThenInclude(pc => pc.Category)
                                .Include(p => p.ProductStatus)
                                .AsNoTracking()
                                .ToListAsync();

            switch (inventoryFilter.InventoryType)
            {
            case InventoryType.Inventory:
                return(GenerateListForInventory(inventories, products));

            case InventoryType.StockMovement:
                var allInventories = await queryAllInventories.AsNoTracking().ToListAsync();

                return(GenerateListForStockMovement(inventories,
                                                    products,
                                                    allInventories,
                                                    inventoryFilter.FromDate.Value,
                                                    inventoryFilter.ToDate.Value));

            default:
                return(new List <InventoryDto>());
            }
        }
예제 #9
0
        public async Task <List <Inventory> > List(InventoryFilter filter)
        {
            if (filter == null)
            {
                return(new List <Inventory>());
            }
            IQueryable <InventoryDAO> InventoryDAOs = DataContext.Inventory.AsNoTracking();

            InventoryDAOs = DynamicFilter(InventoryDAOs, filter);
            InventoryDAOs = DynamicOrder(InventoryDAOs, filter);
            List <Inventory> Inventorys = await DynamicSelect(InventoryDAOs, filter);

            return(Inventorys);
        }
 public void Load()
 {
     if (File.Exists(string.Concat(Application.persistentDataPath, savePath)))
     {
         IFormatter      formatter    = new BinaryFormatter();
         Stream          stream       = new FileStream(string.Concat(Application.persistentDataPath, savePath), FileMode.Open, FileAccess.Read);
         InventoryFilter newContainer = (InventoryFilter)formatter.Deserialize(stream);
         for (int i = 0; i < Container.Items.Length; i++)
         {
             Container.Items[i].UpdateSlot(newContainer.Items[i].ID, newContainer.Items[i].item, newContainer.Items[i].amount);
         }
         stream.Close();
     }
 }
        /// <summary>
        /// TODO: Add more filters if needed
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        private Expression <Func <Inventory, bool> > Filter(InventoryFilter filter)
        {
            Expression <Func <Inventory, bool> > predicate = j => j.Name != null;

            if (filter == null)
            {
                return(predicate);
            }

            if (!string.IsNullOrWhiteSpace(filter.Name))
            {
                predicate = predicate.And(x => x.Name.Contains(filter.Name));
            }


            return(predicate);
        }
예제 #12
0
        private void FilterButton_Click(object sender, EventArgs e)
        {
            var filter = new InventoryFilter
            {
                ID                = FilterIDTextBox.Text.AsInt(),
                ComponentID       = (FilterComponentDropDown.SelectedValue.AsInt() == 0) ? null : FilterComponentDropDown.SelectedValue.AsInt(),
                EnteredFrom       = (FilterEnteredFromDatePicker.Format == DateTimePickerFormat.Custom) ? null : FilterEnteredFromDatePicker.Value.Date.AsDateTime(),
                EnteredTo         = (FilterEnteredToDatePicker.Format == DateTimePickerFormat.Custom) ? null : FilterEnteredToDatePicker.Value.Date.AsDateTime(),
                IsNotApprovedOnly = FilterIsNotApprovedOnlyCheckBox.Checked
            };

            using (var repository = new InventoryRepository())
            {
                InventoryGrid.DataSource = repository.GetInventories(filter);
            }

            InventoryGrid.ClearSelection();
        }
예제 #13
0
        public async Task <List <Item> > List(ItemFilter ItemFilter)
        {
            try
            {
                List <Item> Items = await UOW.ItemRepository.List(ItemFilter);

                var             Ids             = Items.Select(x => x.Id).ToList();
                InventoryFilter InventoryFilter = new InventoryFilter
                {
                    Skip   = 0,
                    Take   = int.MaxValue,
                    ItemId = new IdFilter {
                        In = Ids
                    },
                    Selects = InventorySelect.SaleStock | InventorySelect.Item
                };

                var inventories = await UOW.InventoryRepository.List(InventoryFilter);

                var list = inventories.GroupBy(x => x.ItemId).Select(x => new { ItemId = x.Key, SaleStock = x.Sum(s => s.SaleStock) }).ToList();

                foreach (var item in Items)
                {
                    item.SaleStock    = list.Where(i => i.ItemId == item.Id).Select(i => i.SaleStock).FirstOrDefault();
                    item.HasInventory = item.SaleStock > 0;
                }
                return(Items);
            }
            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    await Logging.CreateSystemLog(ex, nameof(ItemService));

                    throw new MessageException(ex);
                }
                else
                {
                    await Logging.CreateSystemLog(ex.InnerException, nameof(ItemService));

                    throw new MessageException(ex.InnerException);
                };
            }
        }
        public async Task <List <Inventory> > Search(InventoryFilter request)
        {
            var filter = Filter(request);

            IQueryable <Inventory> inventoryQuery = Selector.Get();

            if (!string.IsNullOrWhiteSpace(request.Name))
            {
                var lowerSearchPattern = request.Name.Trim().ToLower();

                inventoryQuery = inventoryQuery.Where(x =>
                                                      x.Name != null && x.Name.ToLower().Contains(lowerSearchPattern));
            }

            if (request.GetHighestQuantity)
            {
                var maxValue = inventoryQuery.Max(x => x.Quantity);
                inventoryQuery = inventoryQuery.Where(x => x.Quantity == maxValue);
            }

            if (request.GetLowestQuantity)
            {
                int minValue = inventoryQuery.Min(x => x.Quantity);
                inventoryQuery = inventoryQuery.Where(x => x.Quantity == minValue);
            }

            if (request.GetOldestItem)
            {
                var oldestDate = inventoryQuery.OrderBy(x => x.CreatedOn).First(); // this will give oldest date
                inventoryQuery = inventoryQuery.Where(x => x.CreatedOn == oldestDate.CreatedOn);
            }

            if (request.GetNewestItem)
            {
                var latestDate = inventoryQuery.OrderByDescending(x => x.CreatedOn).First(); // this will give latest date
                inventoryQuery = inventoryQuery.Where(x => x.CreatedOn == latestDate.CreatedOn);
            }

            return(await inventoryQuery.ToListAsync());
        }
예제 #15
0
        private async Task <List <Inventory> > DynamicSelect(IQueryable <InventoryDAO> query, InventoryFilter filter)
        {
            List <Inventory> Inventorys = await query.Select(q => new Inventory()
            {
                Id              = filter.Selects.Contains(InventorySelect.Id) ? q.Id : default(long),
                WarehouseId     = filter.Selects.Contains(InventorySelect.Warehouse) ? q.WarehouseId : default(long),
                ItemId          = filter.Selects.Contains(InventorySelect.Item) ? q.ItemId : default(long),
                SaleStock       = filter.Selects.Contains(InventorySelect.SaleStock) ? q.SaleStock : default(long),
                AccountingStock = filter.Selects.Contains(InventorySelect.AccountingStock) ? q.AccountingStock : default(long),
                UpdatedAt       = filter.Selects.Contains(InventorySelect.UpdatedAt) ? q.UpdatedAt : default(DateTime),
                Warehouse       = filter.Selects.Contains(InventorySelect.Warehouse) && q.Warehouse != null ? new Warehouse
                {
                    Id             = q.Warehouse.Id,
                    Code           = q.Warehouse.Code,
                    Name           = q.Warehouse.Name,
                    Address        = q.Warehouse.Address,
                    OrganizationId = q.Warehouse.OrganizationId,
                    DistrictId     = q.Warehouse.DistrictId,
                    ProvinceId     = q.Warehouse.ProvinceId,
                    WardId         = q.Warehouse.WardId,
                    StatusId       = q.Warehouse.StatusId,
                } : null,
                Item = filter.Selects.Contains(InventorySelect.Item) && q.Item != null ? new Item
                {
                    Id          = q.Item.Id,
                    Code        = q.Item.Code,
                    Name        = q.Item.Name,
                    ProductId   = q.Item.ProductId,
                    SalePrice   = q.Item.SalePrice,
                    RetailPrice = q.Item.RetailPrice,
                    ScanCode    = q.Item.ScanCode,
                } : null,
            }).ToListAsync();

            return(Inventorys);
        }
예제 #16
0
    private void Awake()
    {
        filter = GetComponent <InventoryFilter>();

        Set(size);
    }
        public async Task <IActionResult> Search([FromBody] InventoryFilter request)
        {
            var results = await _service.Search(request);

            return(Ok(results));
        }
예제 #18
0
 public IEnumerable <InventoryDTO> FindByFilter(InventoryFilter filter)
 {
     throw new NotImplementedException();
 }
        /* Fast filtering code which works off the data, rather than the visual elements.
         * Suboptimal due to potential desyncs with normal filter proceedure, but simply required for performance */
        public List <ListElementController_BASE_NotListView> Filter(List <ListElementController_BASE_NotListView> _items)
        {
            var items = Sort(_items);

            var iw = new Traverse(inventoryWidget);
            Func <string, bool> f = (n) => iw.Field(n).GetValue <bool>();
            var filter            = new InventoryFilter(false //this.filteringAll
                                                        , f("filteringWeapons")
                                                        , f("filterEnabledWeaponBallistic")
                                                        , f("filterEnabledWeaponEnergy")
                                                        , f("filterEnabledWeaponMissile")
                                                        , f("filterEnabledWeaponSmall")
                                                        , f("filteringEquipment")
                                                        , f("filterEnabledHeatsink")
                                                        , f("filterEnabledJumpjet")
                                                        , iw.Field("mechTonnage").GetValue <float>()
                                                        , f("filterEnabledUpgrade")
                                                        , false);

            InventoryDataObject_BASE tmpctl = new InventoryDataObject_InventoryWeapon();

            var current = items.Where(item => {
                tmpctl.weaponDef    = null;
                tmpctl.ammoBoxDef   = null;
                tmpctl.componentDef = null;
                var def             = item.componentDef;
                switch (def.ComponentType)
                {
                case ComponentType.Weapon:
                    tmpctl.weaponDef = def as WeaponDef;
                    break;

                case ComponentType.AmmunitionBox:
                    tmpctl.ammoBoxDef = def as AmmunitionBoxDef;
                    break;

                case ComponentType.HeatSink:
                case ComponentType.MechPart:
                case ComponentType.JumpJet:
                case ComponentType.Upgrade:
                    tmpctl.componentDef = def;
                    break;
                }
                Func <string> Summary = () =>
                {
                    var o    = "";
                    o       += "filteringWeapons? " + f("filteringWeapons") + "\n";
                    o       += "filterEnabledWeaponBallistic? " + f("filterEnabledWeaponBallistic") + "\n";
                    o       += "filterEnabledWeaponEnergy? " + f("filterEnabledWeaponEnergy") + "\n";
                    o       += "filterEnabledWeaponMissile? " + f("filterEnabledWeaponMissile") + "\n";
                    o       += "filterEnabledWeaponSmall? " + f("filterEnabledWeaponSmall") + "\n";
                    o       += "filteringEquipment? " + f("filteringEquipment") + "\n";
                    o       += "filterEnabledHeatsink? " + f("filterEnabledHeatsink") + "\n";
                    o       += "filterEnabledJumpjet? " + f("filterEnabledJumpjet") + "\n";
                    o       += "mechTonnage? " + iw.Field("mechTonnage").GetValue <float>() + "\n";
                    o       += "filterEnabledUpgrade? " + f("filterEnabledUpgrade") + "\n";
                    o       += $"weaponDef? {tmpctl.weaponDef}\n";
                    o       += $"ammoboxDef? {tmpctl.ammoBoxDef}\n";
                    o       += $"componentDef? {tmpctl.componentDef}\n";
                    o       += $"ComponentDefType? {tmpctl.componentDef?.ComponentType}\n";
                    o       += $"componentDefCSType? {tmpctl.componentDef?.GetType()?.FullName}\n";
                    var json = Trap(() => new Traverse(tmpctl.componentDef).Method("ToJSON").GetValue <string>());
                    o       += "JSON: " + json;
                    return(o);
                };

                var yes = Trap(() => filter.Execute(Enumerable.Repeat(tmpctl, 1)).Any()
                               , () => { LogError($"Filtering failed\n{Summary()}\n\n"); return(false); });
                if (!yes)
                {
                    LogDebug(string.Format("[Filter] Removing :id {0} :componentType {1} :quantity {2}", def.Description.Id, def.ComponentType, item.quantity));
                }
                return(yes);
            }).ToList();

            return(current);
        }
예제 #20
0
 public IEnumerable <InventoryDTO> FindByFilter([FromQuery] InventoryFilter filter)
 {
     return(_inventoryService.FindByFilter(filter));
 }
예제 #21
0
 private IQueryable <InventoryDAO> DynamicFilter(IQueryable <InventoryDAO> query, InventoryFilter filter)
 {
     if (filter == null)
     {
         return(query.Where(q => false));
     }
     query = query.Where(q => !q.DeletedAt.HasValue);
     if (filter.Id != null)
     {
         query = query.Where(q => q.Id, filter.Id);
     }
     if (filter.WarehouseId != null)
     {
         query = query.Where(q => q.WarehouseId, filter.WarehouseId);
     }
     if (filter.ItemId != null)
     {
         query = query.Where(q => q.ItemId, filter.ItemId);
     }
     if (filter.SaleStock != null)
     {
         query = query.Where(q => q.SaleStock, filter.SaleStock);
     }
     if (filter.AccountingStock != null)
     {
         query = query.Where(q => q.AccountingStock, filter.AccountingStock);
     }
     query = OrFilter(query, filter);
     return(query);
 }
예제 #22
0
        private IQueryable <InventoryDAO> DynamicOrder(IQueryable <InventoryDAO> query, InventoryFilter filter)
        {
            switch (filter.OrderType)
            {
            case OrderType.ASC:
                switch (filter.OrderBy)
                {
                case InventoryOrder.Id:
                    query = query.OrderBy(q => q.Id);
                    break;

                case InventoryOrder.Warehouse:
                    query = query.OrderBy(q => q.WarehouseId);
                    break;

                case InventoryOrder.Item:
                    query = query.OrderBy(q => q.ItemId);
                    break;

                case InventoryOrder.SaleStock:
                    query = query.OrderBy(q => q.SaleStock);
                    break;

                case InventoryOrder.AccountingStock:
                    query = query.OrderBy(q => q.AccountingStock);
                    break;
                }
                break;

            case OrderType.DESC:
                switch (filter.OrderBy)
                {
                case InventoryOrder.Id:
                    query = query.OrderByDescending(q => q.Id);
                    break;

                case InventoryOrder.Warehouse:
                    query = query.OrderByDescending(q => q.WarehouseId);
                    break;

                case InventoryOrder.Item:
                    query = query.OrderByDescending(q => q.ItemId);
                    break;

                case InventoryOrder.SaleStock:
                    query = query.OrderByDescending(q => q.SaleStock);
                    break;

                case InventoryOrder.AccountingStock:
                    query = query.OrderByDescending(q => q.AccountingStock);
                    break;
                }
                break;
            }
            query = query.Skip(filter.Skip).Take(filter.Take);
            return(query);
        }
        /* Fast filtering code which works off the data, rather than the visual elements.
         * Suboptimal due to potential desyncs with normal filter proceedure, but simply required for performance */
        public List <ListElementController_BASE_NotListView> Filter(List <ListElementController_BASE_NotListView> _items)
        {
            var items = Sort(_items);

            var filter = new InventoryFilter(allAllowed: false  //this.filteringAll
                                             , weaponsAllowed: inventoryWidget.filteringWeapons
                                             , weaponsBallisticAllowed: inventoryWidget.filterEnabledWeaponBallistic
                                             , weaponsEnergyAllowed: inventoryWidget.filterEnabledWeaponEnergy
                                             , weaponsMissileAllowed: inventoryWidget.filterEnabledWeaponMissile
                                             , weaponsPersonnelAllowed: inventoryWidget.filterEnabledWeaponSmall
                                             , gearAllowed: inventoryWidget.filteringEquipment
                                             , gearHeatSinksAllowed: inventoryWidget.filterEnabledHeatsink
                                             , gearJumpJetsAllowed: inventoryWidget.filterEnabledJumpjet
                                             , mechTonnageForJumpJets: inventoryWidget.mechTonnage
                                             , gearUpgradesAllowed: inventoryWidget.filterEnabledUpgrade
                                             , mechsAllowed: false
                                             , ammoAllowed: true);

            InventoryDataObject_BASE tmpctl = new InventoryDataObject_InventoryWeapon();

            var current = items.Where(item => {
                tmpctl.weaponDef    = null;
                tmpctl.ammoBoxDef   = null;
                tmpctl.componentDef = null;
                var def             = item.componentDef;
                switch (def.ComponentType)
                {
                case ComponentType.Weapon:
                    tmpctl.weaponDef = def as WeaponDef;
                    break;

                case ComponentType.AmmunitionBox:
                    tmpctl.ammoBoxDef = def as AmmunitionBoxDef;
                    break;

                case ComponentType.HeatSink:
                case ComponentType.MechPart:
                case ComponentType.JumpJet:
                case ComponentType.Upgrade:
                    tmpctl.componentDef = def;
                    break;
                }
                Func <string> Summary = () =>
                {
                    var o    = "";
                    o       += "filteringWeapons? " + inventoryWidget.filteringWeapons + "\n";
                    o       += "filterEnabledWeaponBallistic? " + inventoryWidget.filterEnabledWeaponBallistic + "\n";
                    o       += "filterEnabledWeaponEnergy? " + inventoryWidget.filterEnabledWeaponEnergy + "\n";
                    o       += "filterEnabledWeaponMissile? " + inventoryWidget.filterEnabledWeaponMissile + "\n";
                    o       += "filterEnabledWeaponSmall? " + inventoryWidget.filterEnabledWeaponSmall + "\n";
                    o       += "filteringEquipment? " + inventoryWidget.filteringEquipment + "\n";
                    o       += "filterEnabledHeatsink? " + inventoryWidget.filterEnabledHeatsink + "\n";
                    o       += "filterEnabledJumpjet? " + inventoryWidget.filterEnabledJumpjet + "\n";
                    o       += "mechTonnage? " + inventoryWidget.mechTonnage + "\n";
                    o       += "filterEnabledUpgrade? " + inventoryWidget.filterEnabledUpgrade + "\n";
                    o       += $"weaponDef? {tmpctl.weaponDef}\n";
                    o       += $"ammoboxDef? {tmpctl.ammoBoxDef}\n";
                    o       += $"componentDef? {tmpctl.componentDef}\n";
                    o       += $"ComponentDefType? {tmpctl.componentDef?.ComponentType}\n";
                    o       += $"componentDefCSType? {tmpctl.componentDef?.GetType()?.FullName}\n";
                    var json = Trap(() => tmpctl.componentDef.ToJSON());
                    o       += "JSON: " + json;
                    return(o);
                };

                var yes = Trap(() => filter.Execute(Enumerable.Repeat(tmpctl, 1)).Any()
                               , () => { LogError($"Filtering failed\n{Summary()}\n\n"); return(false); });
                if (!yes)
                {
                    LogDebug(string.Format("[Filter] Removing :id {0} :componentType {1} :quantity {2}", def.Description.Id, def.ComponentType, item.quantity));
                }
                return(yes);
            }).ToList();

            return(current);
        }
 public void Clear()
 {
     Container = new InventoryFilter();
 }