|
@@ -21,82 +21,12 @@ using System.Windows.Shapes;
|
|
|
|
|
|
namespace PRSDesktop.Panels.Products.Locations;
|
|
|
|
|
|
-public class StockHoldingRelocationItem : INotifyPropertyChanged
|
|
|
-{
|
|
|
- public string ItemNumber { get; set; }
|
|
|
-
|
|
|
- public string Text { get; set; }
|
|
|
-
|
|
|
- public double Quantity { get; set; }
|
|
|
-
|
|
|
- private double _issued;
|
|
|
- public double Issued
|
|
|
- {
|
|
|
- get => _issued;
|
|
|
- set
|
|
|
- {
|
|
|
- _issued = value;
|
|
|
- OnPropertyChanged();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public double MaxValue { get; set; }
|
|
|
-
|
|
|
- private bool _editable = true;
|
|
|
- public bool Editable
|
|
|
- {
|
|
|
- get => _editable;
|
|
|
- set
|
|
|
- {
|
|
|
- _editable = value;
|
|
|
- OnPropertyChanged();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public Guid ID { get; set; }
|
|
|
-
|
|
|
- public JobRequisitionItem JRI { get; set; }
|
|
|
-
|
|
|
-
|
|
|
- public event PropertyChangedEventHandler? PropertyChanged;
|
|
|
-
|
|
|
- protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
|
|
|
- {
|
|
|
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
|
- }
|
|
|
-}
|
|
|
|
|
|
/// <summary>
|
|
|
/// Interaction logic for StockHoldingRelocationWindow.xaml
|
|
|
/// </summary>
|
|
|
public partial class StockHoldingRelocationWindow : Window, INotifyPropertyChanged
|
|
|
{
|
|
|
- public ObservableCollection<StockHoldingRelocationItem> Items { get; set; } = new();
|
|
|
-
|
|
|
- private double _totalQuantity;
|
|
|
- public double TotalQuantity
|
|
|
- {
|
|
|
- get => _totalQuantity;
|
|
|
- set
|
|
|
- {
|
|
|
- _totalQuantity = value;
|
|
|
- OnPropertyChanged();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- private double _totalIssued;
|
|
|
- public double TotalIssued
|
|
|
- {
|
|
|
- get => _totalIssued;
|
|
|
- set
|
|
|
- {
|
|
|
- _totalIssued = value;
|
|
|
- OnPropertyChanged();
|
|
|
- OnPropertyChanged(nameof(CanSave));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
public StockHolding From { get; private init; }
|
|
|
|
|
|
public bool ShowHeader => ShowFrom || IsTargetEditable || IsJobEditable;
|
|
@@ -149,10 +79,8 @@ public partial class StockHoldingRelocationWindow : Window, INotifyPropertyChang
|
|
|
OnPropertyChanged($"{nameof(Job)}.{nameof(Job.JobNumber)}");
|
|
|
OnPropertyChanged($"{nameof(Job)}.{nameof(Job.Name)}");
|
|
|
|
|
|
- SetObserving(false);
|
|
|
-
|
|
|
var jobID = value?.ID ?? Guid.Empty;
|
|
|
- foreach(var item in Items)
|
|
|
+ foreach(var item in Grid.Items)
|
|
|
{
|
|
|
if(item.JRI.ID != Guid.Empty && item.JRI.Job.ID != jobID)
|
|
|
{
|
|
@@ -164,8 +92,6 @@ public partial class StockHoldingRelocationWindow : Window, INotifyPropertyChang
|
|
|
item.Editable = true;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- SetObserving(true);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -184,7 +110,7 @@ public partial class StockHoldingRelocationWindow : Window, INotifyPropertyChang
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public bool CanSave => (!IsTargetEditable || To is not null) && TotalIssued > 0;
|
|
|
+ public bool CanSave => (!IsTargetEditable || To is not null) && Grid.TotalIssued > 0;
|
|
|
|
|
|
public StockHoldingRelocationWindow(StockHolding from, IEnumerable<JobRequisitionItem> items)
|
|
|
{
|
|
@@ -195,27 +121,18 @@ public partial class StockHoldingRelocationWindow : Window, INotifyPropertyChang
|
|
|
InitializeComponent();
|
|
|
|
|
|
SetRequisitionItems(items);
|
|
|
-
|
|
|
- Items.CollectionChanged += (o, e) => Recalculate();
|
|
|
}
|
|
|
|
|
|
- private bool _observing = false;
|
|
|
- public void SetObserving(bool observing)
|
|
|
+ private void Grid_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
|
|
{
|
|
|
- if(_observing != observing)
|
|
|
+ if(e.PropertyName == nameof(Grid.TotalIssued))
|
|
|
{
|
|
|
- _observing = observing;
|
|
|
- if (_observing)
|
|
|
- {
|
|
|
- Recalculate();
|
|
|
- }
|
|
|
+ OnPropertyChanged(nameof(CanSave));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void SetRequisitionItems(IEnumerable<JobRequisitionItem> items)
|
|
|
{
|
|
|
- SetObserving(false);
|
|
|
-
|
|
|
var rItems = items.AsIList();
|
|
|
|
|
|
var rIDs = rItems.Select(x => x.ID).Where(x => x != Guid.Empty).ToArray();
|
|
@@ -226,6 +143,7 @@ public partial class StockHoldingRelocationWindow : Window, INotifyPropertyChang
|
|
|
.ToObjects<StockMovement>().GroupBy(x => x.JobRequisitionItem.ID).ToDictionary(x => x.Key, x => x.Sum(x => x.Units));
|
|
|
|
|
|
var requidItems = new List<StockHoldingRelocationItem>();
|
|
|
+ var newItems = new List<StockHoldingRelocationItem>();
|
|
|
foreach(var item in rItems)
|
|
|
{
|
|
|
var qty = item.ID != Guid.Empty ? quantities.GetValueOrDefault(item.ID) : item.Qty;
|
|
@@ -243,14 +161,12 @@ public partial class StockHoldingRelocationWindow : Window, INotifyPropertyChang
|
|
|
Text = item.ID == Guid.Empty
|
|
|
? "Unrequisitioned Items"
|
|
|
: $"{item.Job.JobNumber}: {item.Requisition.Number} {item.Requisition.Description} ({qty})",
|
|
|
- ID = item.ID,
|
|
|
JRI = item
|
|
|
};
|
|
|
|
|
|
- newItem.PropertyChanged += (o, e) => Recalculate();
|
|
|
if(item.ID == Guid.Empty)
|
|
|
{
|
|
|
- Items.Add(newItem);
|
|
|
+ newItems.Add(newItem);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -262,29 +178,23 @@ public partial class StockHoldingRelocationWindow : Window, INotifyPropertyChang
|
|
|
foreach(var item in requidItems)
|
|
|
{
|
|
|
item.ItemNumber = $"{i}. ";
|
|
|
- Items.Add(item);
|
|
|
+ newItems.Add(item);
|
|
|
++i;
|
|
|
}
|
|
|
- SetObserving(true);
|
|
|
+
|
|
|
+ Grid.Items = newItems;
|
|
|
+ Grid.Refresh(true, true);
|
|
|
}
|
|
|
|
|
|
public Dictionary<Guid, double> GetQuantities()
|
|
|
{
|
|
|
- return Items.ToDictionary(x => x.ID, x => x.Issued);
|
|
|
+ return Grid.Items.ToDictionary(x => x.JRI.ID, x => x.Issued);
|
|
|
}
|
|
|
public StockLocation GetTargetLocation()
|
|
|
{
|
|
|
return To ?? new StockLocation();
|
|
|
}
|
|
|
|
|
|
- private void Recalculate()
|
|
|
- {
|
|
|
- if (!_observing) return;
|
|
|
-
|
|
|
- TotalQuantity = Items.Sum(x => x.Quantity);
|
|
|
- TotalIssued = Items.Sum(x => x.Issued);
|
|
|
- }
|
|
|
-
|
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
|
|
|
|
|
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
|
|
@@ -292,43 +202,6 @@ public partial class StockHoldingRelocationWindow : Window, INotifyPropertyChang
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
|
}
|
|
|
|
|
|
- #region Quantity Buttons
|
|
|
-
|
|
|
- private void Minus_Click(object sender, RoutedEventArgs e)
|
|
|
- {
|
|
|
- if (sender is not FrameworkElement element || element.Tag is not StockHoldingRelocationItem item) return;
|
|
|
-
|
|
|
- item.Issued = Math.Max(0, item.Issued - 1);
|
|
|
- }
|
|
|
-
|
|
|
- private void Plus_Click(object sender, RoutedEventArgs e)
|
|
|
- {
|
|
|
- if (sender is not FrameworkElement element || element.Tag is not StockHoldingRelocationItem item) return;
|
|
|
-
|
|
|
- if(item.ID == Guid.Empty)
|
|
|
- {
|
|
|
- item.Issued += 1;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- item.Issued = Math.Min(item.Issued + 1, item.Quantity);
|
|
|
- }
|
|
|
- }
|
|
|
- private void None_Click(object sender, RoutedEventArgs e)
|
|
|
- {
|
|
|
- if (sender is not FrameworkElement element || element.Tag is not StockHoldingRelocationItem item) return;
|
|
|
-
|
|
|
- item.Issued = 0;
|
|
|
- }
|
|
|
- private void All_Click(object sender, RoutedEventArgs e)
|
|
|
- {
|
|
|
- if (sender is not FrameworkElement element || element.Tag is not StockHoldingRelocationItem item) return;
|
|
|
-
|
|
|
- item.Issued = Math.Max(0, item.Quantity);
|
|
|
- }
|
|
|
-
|
|
|
- #endregion
|
|
|
-
|
|
|
#region Target Location
|
|
|
|
|
|
private bool DoLookupLocation(string? column, string? value)
|