123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using InABox.Core;
- using InABox.Mobile;
- using Xamarin.Forms;
- using Xamarin.Forms.Xaml;
- namespace PRS.Mobile
- {
-
- public class SelectFromHoldingAllocation : BindableObject
- {
- private bool _selected;
- public bool Selected
- {
- get => _selected;
- set
- {
- if (value == _selected) return;
- _selected = value;
- OnPropertyChanged();
- OnPropertyChanged(nameof(SelectFromHoldingViewModel.HasAllocation));
- }
- }
-
- public Guid JobID { get; set; }
-
- public Guid JobRequisitionItemID { get; set; }
-
- public String Description { get; set; }
- public double Quantity { get; set; }
- }
-
- public class SelectFromHoldingViewModel : BindableObject
- {
-
- public RequisitionItemModel? RequisitionItems { get; set; }
-
- private StockHoldingShell? _holding;
- private bool bChanging;
- public StockHoldingShell? Holding
- {
- get => _holding;
- set
- {
- if (Equals(value, _holding)) return;
- _holding = value;
- Allocations.Clear();
- if (_holding != null)
- {
- foreach (var alloc in _holding.Allocations)
- {
-
- var picked = RequisitionItems?.Items.Where(x =>
- x.LocationID == _holding.LocationID
- && x.ProductID == _holding.ProductID
- && x.StyleID == _holding.StyleID
- && x.JobID == _holding.JobID
- && x.DimensionsLength.IsEffectivelyEqual(_holding.DimensionsLength)
- && x.DimensionsWidth.IsEffectivelyEqual(_holding.DimensionsWidth)
- && x.DimensionsHeight.IsEffectivelyEqual(_holding.DimensionsHeight)
- && x.DimensionsWeight .IsEffectivelyEqual(_holding.DimensionsWeight)
- && x.DimensionsQuantity.IsEffectivelyEqual(_holding.DimensionsQuantity)
- && x.ID == alloc.ID)
- .Sum(x => x.ActualQuantity) ?? 0.0;
-
- if (!alloc.Maximum.IsEffectivelyGreaterThan(picked))
- continue;
-
- var allocation = new SelectFromHoldingAllocation()
- { JobID = alloc.JobID, JobRequisitionItemID = alloc.ID, Description = alloc.Description, Quantity = alloc.Maximum - picked };
- allocation.PropertyChanged += (sender, args) =>
- {
- if (bChanging)
- return;
- if (args.PropertyName.Equals(nameof(SelectFromHoldingAllocation.Selected)))
- {
- bChanging = true;
- foreach (var a in Allocations)
- a.Selected = a == sender;
- bChanging = false;
- OnPropertyChanged(nameof(HasAllocation));
- }
- Quantity = Math.Max(0.0F,Math.Min(RequestedQuantity,(sender as SelectFromHoldingAllocation)?.Quantity ?? 0.0F));
- };
- Allocations.Add(allocation);
- }
- if (Allocations.Count == 1)
- Allocations.First().Selected = true;
- }
- OnPropertyChanged();
- }
- }
- public ObservableCollection<SelectFromHoldingAllocation> Allocations { get; private set; }
- public SelectFromHoldingViewModel()
- {
- Allocations = new ObservableCollection<SelectFromHoldingAllocation>();
- }
-
- public double RequestedQuantity { get; set; }
-
- public double Quantity { get; set; }
- public bool HasAllocation => Allocations.Any(x => x.Selected);
- public double GetMaximum()
- {
- var alloc = Allocations.FirstOrDefault(x => x.Selected);
- return alloc?.Quantity ?? 0.0F;
- }
- }
-
- [XamlCompilation(XamlCompilationOptions.Compile)]
- public partial class SelectFromHoldingView : ContentView
- {
- public event RequisitionItemScannerSaveEvent? OnSave;
- public event EventHandler? OnCancel;
- public SelectFromHoldingView(StockHoldingShell? holding, double requestedquantity, RequisitionItemModel? requisitionItems = null)
- {
- InitializeComponent();
- _viewModel.RequisitionItems = requisitionItems;
- _viewModel.Holding = holding;
- _viewModel.RequestedQuantity = requestedquantity;
- }
- private void Cancel_Click(object sender, MobileButtonClickEventArgs args)
- {
- OnCancel?.Invoke(this, EventArgs.Empty);
- }
- private void OK_Click(object sender, MobileButtonClickEventArgs args)
- {
- if (_viewModel.Holding == null)
- return;
- var alloc = _viewModel.Allocations.FirstOrDefault(x => x.Selected);
- if (alloc == null)
- return;
-
- OnSave?.Invoke(this, new RequisitionItemScannerSaveArgs(_viewModel.Holding, alloc.JobID, alloc.JobRequisitionItemID, _viewModel.Quantity));
- }
- private void TakeNone_Click(object sender, MobileButtonClickEventArgs args)
- {
- _viewModel.Quantity = 0.0F;
- }
- private void SubtractOne_Click(object sender, MobileButtonClickEventArgs args)
- {
- _viewModel.Quantity -= 1.0F;
- }
- private void AddOne_Click(object sender, MobileButtonClickEventArgs args)
- {
- _viewModel.Quantity = Math.Min(_viewModel.GetMaximum(), _viewModel.Quantity + 1.0F);
- }
- private void TakeAll_Click(object sender, MobileButtonClickEventArgs args)
- {
- _viewModel.Quantity = Math.Min(_viewModel.RequestedQuantity,_viewModel.GetMaximum());
- }
- }
- }
|