|
@@ -23,12 +23,13 @@ namespace PRSDesktop
|
|
|
private Button receive;
|
|
|
private Button assignLocation;
|
|
|
|
|
|
+ private List<Tuple<PurchaseOrderItem, JobRequisitionItemPurchaseOrderItem>> JobRequisitionItems = new();
|
|
|
+
|
|
|
public SupplierPurchaseOrderItemOneToMany() : base()
|
|
|
{
|
|
|
HiddenColumns.Add(x => x.ID);
|
|
|
|
|
|
HiddenColumns.Add(x => x.BillLine.ID);
|
|
|
- HiddenColumns.Add(x => x.BillLine.Deleted);
|
|
|
HiddenColumns.Add(x => x.Consignment.ID);
|
|
|
|
|
|
HiddenColumns.Add(x => x.Job.ID);
|
|
@@ -112,6 +113,30 @@ namespace PRSDesktop
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ protected override void OnAfterRefresh()
|
|
|
+ {
|
|
|
+ base.OnAfterRefresh();
|
|
|
+
|
|
|
+ JobRequisitionItems.RemoveAll(x => !Items.Contains(x.Item1));
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void AfterSave(object item)
|
|
|
+ {
|
|
|
+ base.AfterSave(item);
|
|
|
+
|
|
|
+ var toSave = new List<JobRequisitionItemPurchaseOrderItem>();
|
|
|
+ foreach (var poItem in Items)
|
|
|
+ {
|
|
|
+ var jriPois = JobRequisitionItems.Where(x => x.Item1 == poItem).Select(x => x.Item2);
|
|
|
+ foreach (var jriPoi in jriPois)
|
|
|
+ {
|
|
|
+ jriPoi.PurchaseOrderItem.ID = poItem.ID;
|
|
|
+ }
|
|
|
+ toSave.AddRange(jriPois);
|
|
|
+ }
|
|
|
+ Client.Save(toSave, "");
|
|
|
+ }
|
|
|
+
|
|
|
public override void Load(object item, Func<Type, CoreTable?>? PageDataHandler)
|
|
|
{
|
|
|
Reconfigure();
|
|
@@ -165,51 +190,76 @@ namespace PRSDesktop
|
|
|
{
|
|
|
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 first = LoadItem(row);
|
|
|
+ var poi = LoadItem(row);
|
|
|
+
|
|
|
+ IEnumerable<Guid> jobRequiItemIDs;
|
|
|
+ if(poi.ID == Guid.Empty)
|
|
|
+ {
|
|
|
+ // If not saved yet, we will have any jriPOIs in the transient list.
|
|
|
+ jobRequiItemIDs = JobRequisitionItems.Where(x => x.Item1 == poi).Select(x => x.Item2.JobRequisitionItem.ID).ToList();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // Otherwise, they'll all be in the database.
|
|
|
+ jobRequiItemIDs = Client.Query(
|
|
|
+ new Filter<JobRequisitionItemPurchaseOrderItem>(x => x.PurchaseOrderItem.ID).IsEqualTo(poi.ID),
|
|
|
+ new Columns<JobRequisitionItemPurchaseOrderItem>(x => x.JobRequisitionItem.ID))
|
|
|
+ .ExtractValues<JobRequisitionItemPurchaseOrderItem, Guid>(x => x.JobRequisitionItem.ID);
|
|
|
+ }
|
|
|
+
|
|
|
var newLine = new PurchaseOrderItem
|
|
|
{
|
|
|
};
|
|
|
- newLine.BillLine.ID = first.BillLine.ID;
|
|
|
- newLine.BillLine.Synchronise(first.BillLine);
|
|
|
- newLine.StockLocation.ID = first.StockLocation.ID;
|
|
|
- newLine.StockLocation.Synchronise(first.StockLocation);
|
|
|
- newLine.Consignment.ID = first.Consignment.ID;
|
|
|
- newLine.Consignment.Synchronise(first.Consignment);
|
|
|
- newLine.PurchaseGL.ID = first.PurchaseGL.ID;
|
|
|
- newLine.PurchaseGL.Synchronise(first.PurchaseGL);
|
|
|
- newLine.CostCentre.ID = first.CostCentre.ID;
|
|
|
- newLine.CostCentre.Synchronise(first.CostCentre);
|
|
|
- newLine.Product.ID = first.Product.ID;
|
|
|
- newLine.Product.Synchronise(first.Product);
|
|
|
- newLine.Style.ID = first.Style.ID;
|
|
|
- newLine.Style.Synchronise(first.Style);
|
|
|
- newLine.TaxCode.ID = first.TaxCode.ID;
|
|
|
- newLine.TaxCode.Synchronise(first.TaxCode);
|
|
|
- newLine.PurchaseOrderLink.ID = first.PurchaseOrderLink.ID;
|
|
|
- newLine.PurchaseOrderLink.Synchronise(first.PurchaseOrderLink);
|
|
|
- newLine.Job.ID = first.Job.ID;
|
|
|
- newLine.Job.Synchronise(first.Job);
|
|
|
- newLine.Dimensions.CopyFrom(first.Dimensions);
|
|
|
-
|
|
|
- newLine.Description = first.Description;
|
|
|
- newLine.TaxRate = first.TaxRate;
|
|
|
- newLine.ExTax = first.ExTax;
|
|
|
- newLine.Tax = first.Tax;
|
|
|
- newLine.IncTax = first.IncTax;
|
|
|
- newLine.Cost = first.Cost;
|
|
|
- newLine.Balance = first.Balance;
|
|
|
- newLine.PORevision = first.PORevision;
|
|
|
- newLine.DueDate = first.DueDate;
|
|
|
- newLine.SupplierCode = first.SupplierCode;
|
|
|
-
|
|
|
- first.Qty = value;
|
|
|
+ newLine.BillLine.ID = poi.BillLine.ID;
|
|
|
+ newLine.BillLine.Synchronise(poi.BillLine);
|
|
|
+ newLine.StockLocation.ID = poi.StockLocation.ID;
|
|
|
+ newLine.StockLocation.Synchronise(poi.StockLocation);
|
|
|
+ newLine.Consignment.ID = poi.Consignment.ID;
|
|
|
+ newLine.Consignment.Synchronise(poi.Consignment);
|
|
|
+ newLine.PurchaseGL.ID = poi.PurchaseGL.ID;
|
|
|
+ newLine.PurchaseGL.Synchronise(poi.PurchaseGL);
|
|
|
+ newLine.CostCentre.ID = poi.CostCentre.ID;
|
|
|
+ newLine.CostCentre.Synchronise(poi.CostCentre);
|
|
|
+ newLine.Product.ID = poi.Product.ID;
|
|
|
+ newLine.Product.Synchronise(poi.Product);
|
|
|
+ newLine.Style.ID = poi.Style.ID;
|
|
|
+ newLine.Style.Synchronise(poi.Style);
|
|
|
+ newLine.TaxCode.ID = poi.TaxCode.ID;
|
|
|
+ newLine.TaxCode.Synchronise(poi.TaxCode);
|
|
|
+ newLine.PurchaseOrderLink.ID = poi.PurchaseOrderLink.ID;
|
|
|
+ newLine.PurchaseOrderLink.Synchronise(poi.PurchaseOrderLink);
|
|
|
+ newLine.Job.ID = poi.Job.ID;
|
|
|
+ newLine.Job.Synchronise(poi.Job);
|
|
|
+ newLine.Dimensions.CopyFrom(poi.Dimensions);
|
|
|
+
|
|
|
+ newLine.Description = poi.Description;
|
|
|
+ newLine.TaxRate = poi.TaxRate;
|
|
|
+ newLine.ExTax = poi.ExTax;
|
|
|
+ newLine.Tax = poi.Tax;
|
|
|
+ newLine.IncTax = poi.IncTax;
|
|
|
+ newLine.Cost = poi.Cost;
|
|
|
+ newLine.Balance = poi.Balance;
|
|
|
+ newLine.PORevision = poi.PORevision;
|
|
|
+ newLine.DueDate = poi.DueDate;
|
|
|
+ newLine.SupplierCode = poi.SupplierCode;
|
|
|
+
|
|
|
+ poi.Qty = value;
|
|
|
newLine.Qty = qty - value;
|
|
|
|
|
|
- SaveItem(first);
|
|
|
+ foreach(var jriID in jobRequiItemIDs)
|
|
|
+ {
|
|
|
+ // Add to a list to be saved later.
|
|
|
+ var jriPoi = new JobRequisitionItemPurchaseOrderItem();
|
|
|
+ jriPoi.JobRequisitionItem.ID = jriID;
|
|
|
+ JobRequisitionItems.Add(new(newLine, jriPoi));
|
|
|
+ }
|
|
|
+
|
|
|
+ SaveItem(poi);
|
|
|
SaveItem(newLine);
|
|
|
Refresh(false, true);
|
|
|
DoChanged();
|