| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- using System;
- using System.Collections.ObjectModel;
- using System.Linq;
- using InABox.Core;
- using Xamarin.CommunityToolkit.ObjectModel;
- using Xamarin.Forms;
- namespace PRS.Mobile
- {
- public class StockLocationSelectionViewModel : BindableObject
- {
-
- public bool MultiSelect { get; set; }
-
- public bool DisplayStockTakeInfo { get; set; }
- public bool CurrentStockTakesOnly { get; set; } = false;
- public bool IncludeInactive { get; set; }
- public bool PullToRefresh
- {
- get => _pullToRefresh;
- set
- {
- if (value == _pullToRefresh) return;
- _pullToRefresh = value;
- OnPropertyChanged();
- }
- }
- public DateTime LastUpdated { get; set; }
- private StockWarehouseShell _warehouse;
- public StockWarehouseShell Warehouse
- {
- get => _warehouse;
- set
- {
- if (Equals(value, _warehouse)) return;
- _warehouse = value;
- Area = new StockAreaShell();
- }
- }
- private StockAreaShell _area;
-
- public StockAreaShell Area
- {
- get => _area;
- set
- {
- if (Equals(value, _area)) return;
- _area = value;
- ReloadLocations();
- }
- }
-
- public int SelectedPage { get; set; }
-
- public ObservableRangeCollection<StockLocationShell> Locations { get; private set; }
- public ObservableRangeCollection<StockLocationShell> Favourites { get; private set; }
-
- public ObservableCollection<StockLocationShell> Selected { get; private set; }
- public StockLocationSelectionViewModel()
- {
- _excludedLocations = new Guid[] { };
- _warehouse = new StockWarehouseShell();
- _area = new StockAreaShell();
-
- Selected = new ObservableCollection<StockLocationShell>();
- Selected.CollectionChanged += (sender, args) => ReloadLocations();
- //App.Data.StockLocations.Refresh(false);
-
- Favourites = new ObservableRangeCollection<StockLocationShell>(App.Data.StockLocations.Where(x => x.Favourite));
-
- Locations = new ObservableRangeCollection<StockLocationShell>(App.Data.StockLocations.ToArray());
-
- }
-
- private Guid[] _excludedLocations;
- public Guid[] ExcludedLocations
- {
- get => _excludedLocations;
- set
- {
- _excludedLocations = value;
- Favourites.ReplaceRange(App.Data.StockLocations.Where(x => x.Favourite && !ExcludedLocations.Contains(x.ID)));
- Locations.ReplaceRange(App.Data.StockLocations.Where(x => !ExcludedLocations.Contains(x.ID)));
- }
- }
- public bool AddVisible { get; set; }
- private string _searchText;
- private bool _pullToRefresh;
- public string SearchText
- {
- get => _searchText;
- set
- {
- if (value == _searchText) return;
- _searchText = value;
- ReloadLocations();
- OnPropertyChanged();
- }
- }
- public void RefreshData(bool force)
- {
- App.Data.StockLocations.Refresh(force);
- if (PullToRefresh)
- LastUpdated = App.Data.StockLocations.LastUpdated;
- ReloadLocations();
- }
-
- public void ReloadLocations()
- {
- var favourites = App.Data.StockLocations.Where(x =>
- Selected.All(s => s.ID != x.ID)
- && (IncludeInactive || x.Active)
- && x.Favourite
- && !ExcludedLocations.Contains(x.ID)
- );
- if (DisplayStockTakeInfo && CurrentStockTakesOnly)
- favourites = favourites.Where(x => !x.CurrentStocktake.IsEmpty());
- Favourites.ReplaceRange(favourites);
- var locations = App.Data.StockLocations.Where(x =>
- Selected.All(s => s.ID != x.ID)
- && (IncludeInactive || x.Active)
- && (_area.ID == Guid.Empty || x.AreaID == _area.ID)
- && (_warehouse.ID == Guid.Empty || x.WarehouseID == _warehouse.ID)
- && !ExcludedLocations.Contains(x.ID)
- && (String.IsNullOrWhiteSpace(_searchText)
- || x.Code.ToUpper().Contains(_searchText.ToUpper())
- || x.Description.ToUpper().Contains(_searchText.ToUpper())
- )
- );
- if (DisplayStockTakeInfo && CurrentStockTakesOnly)
- locations = locations.Where(x => !x.CurrentStocktake.IsEmpty());
-
- Locations.ReplaceRange(locations);
- }
- }
- }
|