|
@@ -9,6 +9,8 @@ using InABox.Clients;
|
|
|
using InABox.Core;
|
|
|
using InABox.DynamicGrid;
|
|
|
using InABox.WPF;
|
|
|
+using PRSDesktop.Panels.PurchaseOrders;
|
|
|
+using Syncfusion.Windows.Tools.Controls;
|
|
|
|
|
|
namespace PRSDesktop;
|
|
|
|
|
@@ -164,27 +166,24 @@ public class SupplierPurchaseOrderItemOneToMany : DynamicOneToManyGrid<PurchaseO
|
|
|
if (row is null)
|
|
|
return;
|
|
|
|
|
|
- var qty = row.Get<PurchaseOrderItem, double>(x => x.Qty);
|
|
|
- var value = qty / 2;
|
|
|
- if(DoubleEdit.Execute("Enter quantity to split on:", 0.0, qty, ref value))
|
|
|
- {
|
|
|
- var poi = LoadItem(row);
|
|
|
-
|
|
|
- IList<PurchaseOrderItemAllocation> _allocations;
|
|
|
- if(poi.ID == Guid.Empty)
|
|
|
- {
|
|
|
- // If not saved yet, any allocations will be in the transient list.
|
|
|
- _allocations = Allocations.Where(x => x.Item1 == poi).Select(x => x.Item2).ToList();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- // Otherwise, they'll all be in the database.
|
|
|
- _allocations = Client.Query(
|
|
|
- new Filter<PurchaseOrderItemAllocation>(x => x.Item.ID).IsEqualTo(poi.ID),
|
|
|
- Columns.None<PurchaseOrderItemAllocation>().Add(x => x.Job.ID).Add(x => x.JobRequisitionItem.ID))
|
|
|
- .ToList<PurchaseOrderItemAllocation>();
|
|
|
- }
|
|
|
+ var grid = new SupplierPurchaseOrderItemSplitGrid();
|
|
|
+ var poi = LoadItem(row);
|
|
|
|
|
|
+ var _allocations = Allocations.Where(x => x.Item1 == poi).Select(x => x.Item2).ToList();
|
|
|
+ if(poi.ID != Guid.Empty)
|
|
|
+ {
|
|
|
+ // Otherwise, they'll all be in the database.
|
|
|
+ _allocations.AddRange(Client.Query(
|
|
|
+ new Filter<PurchaseOrderItemAllocation>(x => x.Item.ID).IsEqualTo(poi.ID)
|
|
|
+ .And(x => x.ID).NotInList(_allocations.ToArray(x => x.ID)),
|
|
|
+ Columns.None<PurchaseOrderItemAllocation>()
|
|
|
+ .Add(x => x.ID)
|
|
|
+ .Add(x => x.Job.ID).Add(x => x.JobRequisitionItem.ID).Add(x => x.Quantity).Add(x => x.Nominated))
|
|
|
+ .ToObjects<PurchaseOrderItemAllocation>());
|
|
|
+ }
|
|
|
+ var items = _allocations.ToList(SupplierPurchaseOrderItemSplit.FromAllocation);
|
|
|
+ if (SupplierPurchaseOrderItemSplitWindow.Execute(poi.Qty, items, out var value))
|
|
|
+ {
|
|
|
var newLine = CreateItem();
|
|
|
newLine.BillLine.ID = poi.BillLine.ID;
|
|
|
newLine.BillLine.Synchronise(poi.BillLine);
|
|
@@ -222,16 +221,26 @@ public class SupplierPurchaseOrderItemOneToMany : DynamicOneToManyGrid<PurchaseO
|
|
|
newLine.DueDate = poi.DueDate;
|
|
|
newLine.SupplierCode = poi.SupplierCode;
|
|
|
|
|
|
+ newLine.Qty = poi.Qty - value;
|
|
|
poi.Qty = value;
|
|
|
- newLine.Qty = qty - value;
|
|
|
|
|
|
- foreach(var allocation in _allocations)
|
|
|
+ foreach(var item in items)
|
|
|
{
|
|
|
+ var allocation = _allocations.FirstOrDefault(x => x.ID == item.AllocationID);
|
|
|
+ if (allocation is null) continue;
|
|
|
+
|
|
|
// Add to a list to be saved later.
|
|
|
- var jriPoi = new PurchaseOrderItemAllocation();
|
|
|
- jriPoi.Job.CopyFrom(allocation.Job);
|
|
|
- jriPoi.JobRequisitionItem.CopyFrom(allocation.JobRequisitionItem);
|
|
|
- Allocations.Add(new(newLine, jriPoi));
|
|
|
+ var newAllocation = new PurchaseOrderItemAllocation();
|
|
|
+ newAllocation.Job.CopyFrom(allocation.Job);
|
|
|
+ newAllocation.JobRequisitionItem.CopyFrom(allocation.JobRequisitionItem);
|
|
|
+ newAllocation.Nominated = allocation.Nominated;
|
|
|
+
|
|
|
+ newAllocation.Quantity = allocation.Quantity - item.SplitQuantity;
|
|
|
+ allocation.Quantity = item.SplitQuantity;
|
|
|
+
|
|
|
+ // Save both allocations.
|
|
|
+ Allocations.Add(new(poi, allocation));
|
|
|
+ Allocations.Add(new(newLine, newAllocation));
|
|
|
}
|
|
|
|
|
|
SaveItem(poi);
|