|
@@ -188,7 +188,7 @@ public partial class RequisitionItemEditor : INotifyPropertyChanged
|
|
|
|
|
|
#region Allocations
|
|
|
|
|
|
- private IEnumerable<StockSelectionItem> CreateStockSelectionItems(IEnumerable<IGrouping<Guid, StockMovement>> groups, Func<StockMovement,string> description)
|
|
|
+ private IEnumerable<StockSelectionItem> CreateStockSelectionItems(IEnumerable<IGrouping<Tuple<Guid,Guid>, StockMovement>> groups, Tuple<Guid,Guid,double>[] values, Func<StockMovement,string> description)
|
|
|
{
|
|
|
|
|
|
var _result = new List<StockSelectionItem>();
|
|
@@ -198,15 +198,20 @@ public partial class RequisitionItemEditor : INotifyPropertyChanged
|
|
|
if (!_units.IsEffectivelyEqual(0.0))
|
|
|
{
|
|
|
var _holding = new StockHolding();
|
|
|
- _holding.Location.ID = _group.Key;
|
|
|
+ _holding.Location.ID = _group.Key.Item1;
|
|
|
+ _holding.Job.ID = _group.Key.Item2;
|
|
|
_holding.Location.Synchronise(_group.FirstOrDefault()?.Location ?? new StockLocationLink());
|
|
|
_holding.Product.ID = Item.Product.ID;
|
|
|
_holding.Product.Synchronise(Item.Product);
|
|
|
_holding.Style.ID = Item.Style.ID;
|
|
|
_holding.Style.Synchronise(Item.Style);
|
|
|
+ _holding.Job.CopyFrom(_group.FirstOrDefault()?.Job ?? new JobLink());
|
|
|
_holding.Dimensions.CopyFrom(Item.Dimensions);
|
|
|
_holding.Location.Area.Code = description(_group.FirstOrDefault() ?? new StockMovement());
|
|
|
_holding.Units = _units;
|
|
|
+
|
|
|
+ _holding.AverageValue = values.FirstOrDefault(x=>x.Item1 == _group.Key.Item1 && x.Item2 == _group.Key.Item2)?.Item3 ?? 0.0;
|
|
|
+
|
|
|
var _jri = new JobRequisitionItem()
|
|
|
{
|
|
|
ID = _group.FirstOrDefault()?.JobRequisitionItem.ID ?? Guid.Empty
|
|
@@ -219,12 +224,13 @@ public partial class RequisitionItemEditor : INotifyPropertyChanged
|
|
|
|
|
|
private void LoadAllocations()
|
|
|
{
|
|
|
- var movements = Client.Query(
|
|
|
- new Filter<StockMovement>(x=>x.Product.ID).IsEqualTo(Item.Product.ID)
|
|
|
+ MultiQuery query = new MultiQuery();
|
|
|
+
|
|
|
+ query.Add(new Filter<StockMovement>(x=>x.Product.ID).IsEqualTo(Item.Product.ID)
|
|
|
.And(x=>x.Style.ID).IsEqualTo(Item.Style.ID)
|
|
|
.And(x=>x.Dimensions).DimensionEquals(Item.Dimensions)
|
|
|
.And(
|
|
|
- new Filter<StockMovement>(x => x.JobRequisitionItem.ID).IsEqualTo(Item.SourceJRI.ID)
|
|
|
+ new Filter<StockMovement>(x => x.JobRequisitionItem.ID).IsEqualTo(Item.JobRequisitionItem.ID)
|
|
|
.Or(new Filter<StockMovement>(x => x.Job.ID).IsEqualTo(Item.RequisitionLink.JobLink.ID)
|
|
|
.And(x => x.JobRequisitionItem.ID).IsEqualTo(Guid.Empty))
|
|
|
.Or(new Filter<StockMovement>(x => x.Job.ID).IsEqualTo(Guid.Empty)
|
|
@@ -241,15 +247,29 @@ public partial class RequisitionItemEditor : INotifyPropertyChanged
|
|
|
.Add(x=>x.JobRequisitionItem.Requisition.Number)
|
|
|
.Add(x=>x.JobRequisitionItem.Requisition.Description)
|
|
|
.Add(x => x.Units)
|
|
|
- ).Rows.Select(x=>x.ToObject<StockMovement>()).ToArray();
|
|
|
+ );
|
|
|
+
|
|
|
+ query.Add(new Filter<StockHolding>(x=>x.Product.ID).IsEqualTo(Item.Product.ID)
|
|
|
+ .And(x=>x.Style.ID).IsEqualTo(Item.Style.ID)
|
|
|
+ .And(x=>x.Dimensions).DimensionEquals(Item.Dimensions),
|
|
|
+ Columns.None<StockHolding>()
|
|
|
+ .Add(x => x.Location.ID)
|
|
|
+ .Add(x => x.Job.ID)
|
|
|
+ .Add(x => x.AverageValue)
|
|
|
+ );
|
|
|
+
|
|
|
+ query.Query();
|
|
|
+ var values = query.Get<StockHolding>().ToTuples<StockHolding,Guid,Guid,double>(x=>x.Location.ID, x=>x.Job.ID, x=>x.AverageValue).ToArray();
|
|
|
+ var movements = query.Get<StockMovement>().ToArray<StockMovement>();
|
|
|
|
|
|
List<StockSelectionItem> items = new();
|
|
|
|
|
|
- var allocations = movements.Where(x => x.JobRequisitionItem.ID == Item.SourceJRI.ID)
|
|
|
- .GroupBy(x => x.Location.ID);
|
|
|
+ var allocations = movements.Where(x => x.JobRequisitionItem.ID == Item.JobRequisitionItem.ID)
|
|
|
+ .GroupBy(x => new Tuple<Guid,Guid>(x.Location.ID,x.Job.ID));
|
|
|
items.AddRange(
|
|
|
CreateStockSelectionItems(
|
|
|
- allocations,
|
|
|
+ allocations,
|
|
|
+ values,
|
|
|
(m) => $"{m.Job.JobNumber}:{m.JobRequisitionItem.Requisition.Number} {m.JobRequisitionItem.Requisition.Description}"
|
|
|
)
|
|
|
);
|
|
@@ -258,19 +278,21 @@ public partial class RequisitionItemEditor : INotifyPropertyChanged
|
|
|
var reserves = movements.Where(x =>
|
|
|
x.JobRequisitionItem.ID != Guid.Empty && x.Job.ID == Item.RequisitionLink.JobLink.ID &&
|
|
|
x.JobRequisitionItem.ID == Guid.Empty)
|
|
|
- .GroupBy(x => x.Location.ID);
|
|
|
+ .GroupBy(x => new Tuple<Guid,Guid>(x.Location.ID, x.Job.ID));
|
|
|
items.AddRange(
|
|
|
CreateStockSelectionItems(
|
|
|
reserves,
|
|
|
+ values,
|
|
|
(m) => $"{m.Job.JobNumber} (Unallocated Stock)"
|
|
|
)
|
|
|
);
|
|
|
|
|
|
var freeitems = movements.Where(x => x.Job.ID == Guid.Empty && x.JobRequisitionItem.ID == Guid.Empty)
|
|
|
- .GroupBy(x => x.Location.ID);
|
|
|
+ .GroupBy(x => new Tuple<Guid,Guid>(x.Location.ID,x.Job.ID));
|
|
|
items.AddRange(
|
|
|
CreateStockSelectionItems(
|
|
|
- freeitems,
|
|
|
+ freeitems,
|
|
|
+ values,
|
|
|
(m) => $"General Stock"
|
|
|
)
|
|
|
);
|
|
@@ -331,15 +353,15 @@ public partial class RequisitionItemEditor : INotifyPropertyChanged
|
|
|
var newItem = newItems.Count == 0 ? Item : CopyRequisitionItem();
|
|
|
newItem.Location.CopyFrom(item.Holding.Location);
|
|
|
newItem.Cost = item.Holding.AverageValue;
|
|
|
- newItem.JobRequisitionItem.CopyFrom(item.JRI);
|
|
|
+ newItem.SourceJRI.CopyFrom(item.JRI);
|
|
|
newItem.JobLink.CopyFrom(item.Holding.Job);
|
|
|
|
|
|
// Automagically attach to Requisition if it seems appropriate
|
|
|
// ie selected from a JRI allocation, and current source jri is blank
|
|
|
- if (newItem.SourceJRI.ID == Guid.Empty
|
|
|
+ if (newItem.JobRequisitionItem.ID == Guid.Empty
|
|
|
&& newItem.RequisitionLink.JobLink.ID == item.Holding.Job.ID
|
|
|
&& item.JRI.ID != Guid.Empty)
|
|
|
- newItem.SourceJRI.ID = item.JRI.ID;
|
|
|
+ newItem.JobRequisitionItem.ID = item.JRI.ID;
|
|
|
|
|
|
newItem.Quantity = item.Issued;
|
|
|
newItem.ActualQuantity = item.Issued;
|
|
@@ -353,7 +375,7 @@ public partial class RequisitionItemEditor : INotifyPropertyChanged
|
|
|
{
|
|
|
var newItem = CopyRequisitionItem();
|
|
|
newItem.Location.CopyFrom(new StockLocationLink());
|
|
|
- newItem.JobRequisitionItem.CopyFrom(new JobRequisitionItemLink());
|
|
|
+ newItem.SourceJRI.CopyFrom(new JobRequisitionItemLink());
|
|
|
newItem.JobLink.CopyFrom(new JobLink());
|
|
|
newItem.Quantity = remainder;
|
|
|
newItem.Done = false;
|
|
@@ -473,7 +495,7 @@ public partial class RequisitionItemEditor : INotifyPropertyChanged
|
|
|
newItem.Description = Item.Description;
|
|
|
newItem.Image.CopyFrom(Item.Image);
|
|
|
newItem.RequisitionLink.ID = Item.RequisitionLink.ID;
|
|
|
- newItem.JobRequisitionItem.ID = item.ID;
|
|
|
+ newItem.JobRequisitionItem.CopyFrom(Item.JobRequisitionItem);
|
|
|
newItem.Product.CopyFrom(Item.Product);
|
|
|
newItem.Style.CopyFrom(Item.Style);
|
|
|
newItem.Location.CopyFrom(Item.Location);
|
|
@@ -481,10 +503,19 @@ public partial class RequisitionItemEditor : INotifyPropertyChanged
|
|
|
newItem.JobLink.CopyFrom(Item.JobLink);
|
|
|
newItem.EditType = RequisitionItemEditType.Normal;
|
|
|
}
|
|
|
- newItem.JobRequisitionItem.ID = item.ID;
|
|
|
+
|
|
|
+ // Automagically attach to Requisition if it seems appropriate
|
|
|
+ // ie selected from a JRI allocation, and current source jri is blank
|
|
|
+ if (newItem.JobRequisitionItem.ID == Guid.Empty
|
|
|
+ && newItem.RequisitionLink.JobLink.ID == StockHolding.Job.ID
|
|
|
+ && item.ID != Guid.Empty)
|
|
|
+ newItem.JobRequisitionItem.ID = item.ID;
|
|
|
+
|
|
|
+ newItem.SourceJRI.ID = item.ID;
|
|
|
newItem.Quantity = item.Taken;
|
|
|
newItem.ActualQuantity = item.Taken;
|
|
|
newItem.Cost = StockHolding.AverageValue;
|
|
|
+ newItem.Done = true;
|
|
|
remainder -= item.Taken;
|
|
|
|
|
|
newItems.Add(newItem);
|
|
@@ -497,8 +528,8 @@ public partial class RequisitionItemEditor : INotifyPropertyChanged
|
|
|
newItem.Description = Item.Description;
|
|
|
newItem.Image.CopyFrom(Item.Image);
|
|
|
newItem.RequisitionLink.ID = Item.RequisitionLink.ID;
|
|
|
-
|
|
|
- newItem.JobRequisitionItem.ID = Guid.Empty;
|
|
|
+ newItem.JobRequisitionItem.CopyFrom(Item.JobRequisitionItem);
|
|
|
+ newItem.SourceJRI.ID = Guid.Empty;
|
|
|
newItem.Product.CopyFrom(Item.Product);
|
|
|
newItem.Style.CopyFrom(Item.Style);
|
|
|
newItem.Dimensions.CopyFrom(Item.Dimensions, true);
|