|
|
@@ -39,6 +39,8 @@ public partial class ReservationManagementHoldingsGrid : INotifyPropertyChanged
|
|
|
|
|
|
public event HoldingsReviewRefresh? OnHoldingsReviewRefresh;
|
|
|
|
|
|
+ public StockDimensions? TargetDimensions { get; set; }
|
|
|
+
|
|
|
private JobRequisitionItem? item;
|
|
|
public JobRequisitionItem? Item
|
|
|
{
|
|
|
@@ -51,6 +53,7 @@ public partial class ReservationManagementHoldingsGrid : INotifyPropertyChanged
|
|
|
if(item?.ID != value?.ID)
|
|
|
{
|
|
|
item = value;
|
|
|
+ TargetDimensions = item?.Dimensions.Copy();
|
|
|
CalculateHoldings();
|
|
|
SetStyle();
|
|
|
SetProductName();
|
|
|
@@ -95,9 +98,28 @@ public partial class ReservationManagementHoldingsGrid : INotifyPropertyChanged
|
|
|
};
|
|
|
}
|
|
|
|
|
|
- private readonly ObservableCollection<ReservationManagementHoldingsModel<StockMovement>> greenList = new();
|
|
|
- private readonly ObservableCollection<ReservationManagementHoldingsModel<StockMovement>> yellowList = new();
|
|
|
- private readonly ObservableCollection<ReservationManagementHoldingsModel<StockMovement>> redList = new();
|
|
|
+ private class StockMovementModel
|
|
|
+ {
|
|
|
+ public StockMovement Movement { get; set; }
|
|
|
+
|
|
|
+ public StockDimensions ConvertedDimensions { get; private set; }
|
|
|
+
|
|
|
+ public double ConvertedUnits { get; private set; }
|
|
|
+
|
|
|
+ public double ConvertedCost { get; private set; }
|
|
|
+
|
|
|
+ public StockMovementModel(StockMovement movement)
|
|
|
+ {
|
|
|
+ Movement = movement;
|
|
|
+
|
|
|
+ ConvertedDimensions = movement.Dimensions.Copy();
|
|
|
+ (ConvertedUnits, ConvertedCost) = DimensionUtils.ConvertDimensions(ConvertedDimensions, movement.Units, movement.Cost, Client<ProductDimensionUnit>.Provider);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private readonly ObservableCollection<ReservationManagementHoldingsModel<StockMovementModel>> greenList = new();
|
|
|
+ private readonly ObservableCollection<ReservationManagementHoldingsModel<StockMovementModel>> yellowList = new();
|
|
|
+ private readonly ObservableCollection<ReservationManagementHoldingsModel<StockMovementModel>> redList = new();
|
|
|
private readonly ObservableCollection<ReservationManagementHoldingsModel<PurchaseOrderItem>> purchasedList = new();
|
|
|
|
|
|
private void DistributeItems<T>(Dictionary<Guid, List<T>>? items, Guid selectedStyleID, ReservationManagementHoldingsModel<T> model,
|
|
|
@@ -127,11 +149,22 @@ public partial class ReservationManagementHoldingsGrid : INotifyPropertyChanged
|
|
|
|
|
|
private void CalculateHoldings()
|
|
|
{
|
|
|
- if(item is not null)
|
|
|
+ if(item is not null && TargetDimensions is not null)
|
|
|
{
|
|
|
+ Filter<StockEntity> dimensionsFilter;
|
|
|
+ var hasConversion = DimensionUtils.HasConversion(TargetDimensions, Client<ProductDimensionUnit>.Provider);
|
|
|
+ if (hasConversion)
|
|
|
+ {
|
|
|
+ dimensionsFilter = Filter<StockEntity>.Where(x => x.Dimensions.Unit.ID).IsEqualTo(TargetDimensions.Unit.ID);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ dimensionsFilter = Filter<StockEntity>.Where(x => x.Dimensions).DimensionEquals(TargetDimensions);
|
|
|
+ }
|
|
|
+
|
|
|
var results = Client.Query(
|
|
|
Filter<StockMovement>.Where(x => x.Product.ID).IsEqualTo(item.Product.ID)
|
|
|
- .And(x => x.Dimensions).DimensionEquals(item.Dimensions)
|
|
|
+ .And(dimensionsFilter.Cast<StockMovement>())
|
|
|
.And(x => x.Location.ID).IsNotEqualTo(Guid.Empty),
|
|
|
Columns.None<StockMovement>().Add(
|
|
|
x => x.ID,
|
|
|
@@ -148,34 +181,21 @@ public partial class ReservationManagementHoldingsGrid : INotifyPropertyChanged
|
|
|
x => x.Cost)
|
|
|
.AddDimensionsColumns(x => x.Dimensions, Dimensions.ColumnsType.Data))
|
|
|
.ToObjects<StockMovement>();
|
|
|
- var stockMovements = new Dictionary<(Guid job, bool allocated), Dictionary<Guid, List<StockMovement>>>();
|
|
|
+ var stockMovements = new Dictionary<(Guid job, bool allocated), Dictionary<Guid, List<StockMovementModel>>>();
|
|
|
foreach(var mvt in results)
|
|
|
{
|
|
|
stockMovements.GetValueOrAdd((mvt.Job.ID, mvt.JobRequisitionItem.ID != Guid.Empty))
|
|
|
.GetValueOrAdd(mvt.Style.ID)
|
|
|
- .Add(mvt);
|
|
|
- }
|
|
|
-
|
|
|
- Filter<PurchaseOrderItem> dimensionsFilter;
|
|
|
- double jriDimensionsUnitValue;
|
|
|
- if (item.Dimensions.Unit.Conversion.IsNullOrWhiteSpace())
|
|
|
- {
|
|
|
- dimensionsFilter = Filter<PurchaseOrderItem>.Where(x => x.Dimensions).DimensionEquals(item.Dimensions);
|
|
|
- jriDimensionsUnitValue = 1;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- dimensionsFilter = Filter<PurchaseOrderItem>.Where(x => x.Dimensions.Unit.ID).IsEqualTo(item.Dimensions.Unit.ID);
|
|
|
- (jriDimensionsUnitValue, _) = DimensionUtils.ConvertDimensions(item.Dimensions.Copy(), 1, 0, Client<ProductDimensionUnit>.Provider);
|
|
|
+ .Add(new(mvt));
|
|
|
}
|
|
|
|
|
|
var orderItemsResult = Client.Query(
|
|
|
Filter<PurchaseOrderItem>.Where(x => x.Product.ID).IsEqualTo(item.Product.ID)
|
|
|
- .And(dimensionsFilter)
|
|
|
+ .And(dimensionsFilter.Cast<PurchaseOrderItem>())
|
|
|
.And(x => x.ReceivedDate).IsEqualTo(DateTime.MinValue),
|
|
|
Columns.None<PurchaseOrderItem>()
|
|
|
.Add(x => x.ID)
|
|
|
- .AddDimensionsColumns(x => x.Dimensions, Dimensions.ColumnsType.All)
|
|
|
+ .AddDimensionsColumns(x => x.Dimensions, Dimensions.ColumnsType.Data)
|
|
|
.Add(x => x.Dimensions.Unit.Conversion)
|
|
|
.Add(x => x.Style.ID)
|
|
|
.Add(x => x.Style.Description)
|
|
|
@@ -193,7 +213,7 @@ public partial class ReservationManagementHoldingsGrid : INotifyPropertyChanged
|
|
|
{
|
|
|
// We need the unallocated quantity to be in terms of the dimensions of the JRI.
|
|
|
var (qty, cost) = DimensionUtils.ConvertDimensions(orderItem.Dimensions, orderItem.Unallocated, orderItem.Cost, Client<ProductDimensionUnit>.Provider);
|
|
|
- orderItemQuantities[orderItem.ID] = qty / jriDimensionsUnitValue;
|
|
|
+ orderItemQuantities[orderItem.ID] = qty;
|
|
|
orderItem.Unallocated = qty;
|
|
|
}
|
|
|
else
|
|
|
@@ -214,11 +234,11 @@ public partial class ReservationManagementHoldingsGrid : INotifyPropertyChanged
|
|
|
|
|
|
if(!stockMovements.ContainsKey((item.Job.ID, false)))
|
|
|
{
|
|
|
- stockMovements.Add((item.Job.ID, false), new Dictionary<Guid, List<StockMovement>>());
|
|
|
+ stockMovements.Add((item.Job.ID, false), new Dictionary<Guid, List<StockMovementModel>>());
|
|
|
}
|
|
|
if (!stockMovements.ContainsKey((Guid.Empty, false)))
|
|
|
{
|
|
|
- stockMovements.Add((Guid.Empty, false), new Dictionary<Guid, List<StockMovement>>());
|
|
|
+ stockMovements.Add((Guid.Empty, false), new Dictionary<Guid, List<StockMovementModel>>());
|
|
|
}
|
|
|
|
|
|
greenList.Clear();
|
|
|
@@ -230,14 +250,14 @@ public partial class ReservationManagementHoldingsGrid : INotifyPropertyChanged
|
|
|
{
|
|
|
var job = jobs.GetValueOrDefault(key.job);
|
|
|
|
|
|
- ReservationManagementHoldingsModel<StockMovement> holding;
|
|
|
+ ReservationManagementHoldingsModel<StockMovementModel> holding;
|
|
|
if (key.allocated)
|
|
|
{
|
|
|
holding = new(key.job, job?.JobNumber ?? "", job?.Name ?? "")
|
|
|
{
|
|
|
AlreadyAllocated = true
|
|
|
};
|
|
|
- DistributeItems(movements, item.Style.ID, holding, x => x.Units);
|
|
|
+ DistributeItems(movements, item.Style.ID, holding, x => x.Movement.Units);
|
|
|
if (!holding.Empty)
|
|
|
{
|
|
|
redList.Add(holding);
|
|
|
@@ -246,19 +266,19 @@ public partial class ReservationManagementHoldingsGrid : INotifyPropertyChanged
|
|
|
else if (key.job == Guid.Empty)
|
|
|
{
|
|
|
holding = new(Guid.Empty, "Free Stock", "Free Stock");
|
|
|
- DistributeItems(movements, item.Style.ID, holding, x => x.Units);
|
|
|
+ DistributeItems(movements, item.Style.ID, holding, x => x.ConvertedUnits);
|
|
|
greenList.Add(holding);
|
|
|
}
|
|
|
else if(key.job == item.Job.ID)
|
|
|
{
|
|
|
holding = new(item.Job.ID, item.Job.JobNumber, item.Job.Name);
|
|
|
- DistributeItems(movements, item.Style.ID, holding, x => x.Units);
|
|
|
+ DistributeItems(movements, item.Style.ID, holding, x => x.ConvertedUnits);
|
|
|
greenList.Add(holding);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
holding = new(key.job, job?.JobNumber ?? "", job?.Name ?? "");
|
|
|
- DistributeItems(movements, item.Style.ID, holding, x => x.Units);
|
|
|
+ DistributeItems(movements, item.Style.ID, holding, x => x.ConvertedUnits);
|
|
|
if (!holding.Empty)
|
|
|
{
|
|
|
yellowList.Add(holding);
|
|
|
@@ -312,25 +332,6 @@ public partial class ReservationManagementHoldingsGrid : INotifyPropertyChanged
|
|
|
listViewPurchased.ItemsSource = purchasedList;
|
|
|
}
|
|
|
|
|
|
- //private void Take_RightClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
|
|
- //{
|
|
|
- // if (sender is not FrameworkElement element
|
|
|
- // || element.DataContext is not ReservationManagementHoldingsModel model
|
|
|
- // || element.Tag is not List<StockMovement> mvts) return;
|
|
|
-
|
|
|
- // if (model.AlreadyAllocated) return;
|
|
|
- // if (mvts == model.StockOfCurrentStyle && model.UnitsOfCurrentStyle > 0
|
|
|
- // || mvts == model.StockOfNoStyle && model.UnitsOfNoStyle > 0
|
|
|
- // || mvts == model.StockOfOtherStyles && model.UnitsOfOtherStyles > 0)
|
|
|
- // {
|
|
|
- // return;
|
|
|
- // }
|
|
|
-
|
|
|
- // var menu = new ContextMenu();
|
|
|
- // menu.AddItem("Take Anyway", null, () => LaunchStockSelectionPage(model, mvts));
|
|
|
- // menu.IsOpen = true;
|
|
|
- //}
|
|
|
-
|
|
|
private void Take_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
if (sender is not FrameworkElement element
|
|
|
@@ -344,8 +345,8 @@ public partial class ReservationManagementHoldingsGrid : INotifyPropertyChanged
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if(model is ReservationManagementHoldingsModel<StockMovement> movementModel
|
|
|
- && thisList is List<StockMovement> mvts)
|
|
|
+ if(model is ReservationManagementHoldingsModel<StockMovementModel> movementModel
|
|
|
+ && thisList is List<StockMovementModel> mvts)
|
|
|
{
|
|
|
LaunchStockSelectionPage(movementModel, mvts);
|
|
|
}
|
|
|
@@ -372,15 +373,16 @@ public partial class ReservationManagementHoldingsGrid : INotifyPropertyChanged
|
|
|
OnHoldingsReviewRefresh?.Invoke();
|
|
|
}
|
|
|
}
|
|
|
- private void LaunchStockSelectionPage(ReservationManagementHoldingsModel<StockMovement> model, List<StockMovement> mvts)
|
|
|
+ private void LaunchStockSelectionPage(ReservationManagementHoldingsModel<StockMovementModel> model, List<StockMovementModel> mvts)
|
|
|
{
|
|
|
- if (Item is null) return;
|
|
|
+ if (Item is null || TargetDimensions is null) return;
|
|
|
|
|
|
- var holdings = new Dictionary<(Guid locationID, Guid styleID, Guid requiItemID), StockHolding>();
|
|
|
+ var holdings = new Dictionary<(Guid locationID, Guid styleID, Guid requiItemID, StockDimensions dimensions), StockHolding>();
|
|
|
|
|
|
- foreach (var mvt in mvts)
|
|
|
+ foreach (var mvtModel in mvts)
|
|
|
{
|
|
|
- if(!holdings.TryGetValue(new(mvt.Location.ID, mvt.Style.ID, mvt.JobRequisitionItem.ID), out var holding))
|
|
|
+ var mvt = mvtModel.Movement;
|
|
|
+ if(!holdings.TryGetValue(new(mvt.Location.ID, mvt.Style.ID, mvt.JobRequisitionItem.ID, mvt.Dimensions), out var holding))
|
|
|
{
|
|
|
holding = new StockHolding();
|
|
|
|
|
|
@@ -388,7 +390,7 @@ public partial class ReservationManagementHoldingsGrid : INotifyPropertyChanged
|
|
|
holding.Style.CopyFrom(mvt.Style);
|
|
|
holding.Dimensions.CopyFrom(mvt.Dimensions);
|
|
|
|
|
|
- holdings.Add(new(mvt.Location.ID, mvt.Style.ID, mvt.JobRequisitionItem.ID), holding);
|
|
|
+ holdings.Add(new(mvt.Location.ID, mvt.Style.ID, mvt.JobRequisitionItem.ID, mvt.Dimensions), holding);
|
|
|
}
|
|
|
if (mvt.JobRequisitionItem.ID != Guid.Empty && model.AlreadyAllocated)
|
|
|
{
|
|
|
@@ -414,6 +416,7 @@ public partial class ReservationManagementHoldingsGrid : INotifyPropertyChanged
|
|
|
filteredHoldings,
|
|
|
Item,
|
|
|
new Job { ID = model.JobID, Name = model.JobName, JobNumber = model.JobNumber },
|
|
|
+ TargetDimensions,
|
|
|
model.AlreadyAllocated);
|
|
|
|
|
|
if (page.ShowDialog() == true)
|