|
@@ -1,33 +1,179 @@
|
|
|
using System;
|
|
|
+using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Threading;
|
|
|
using System.Windows;
|
|
|
using System.Windows.Controls;
|
|
|
+using System.Windows.Media.Imaging;
|
|
|
using Comal.Classes;
|
|
|
using InABox.Clients;
|
|
|
using InABox.Core;
|
|
|
using InABox.DynamicGrid;
|
|
|
using InABox.Wpf;
|
|
|
using InABox.WPF;
|
|
|
+using Microsoft.Xaml.Behaviors.Core;
|
|
|
+using PRSDesktop.Panels.PurchaseOrders;
|
|
|
+using PurchaseOrder = MYOB.AccountRight.SDK.Contracts.Version2.Purchase.PurchaseOrder;
|
|
|
+using PurchaseOrderItemAllocation = Comal.Classes.PurchaseOrderItemAllocation;
|
|
|
|
|
|
namespace PRSDesktop;
|
|
|
|
|
|
public class ConsignmentItemGrid : DynamicDataGrid<PurchaseOrderItem>
|
|
|
{
|
|
|
private Button receiveall;
|
|
|
-
|
|
|
private Button receiveselected;
|
|
|
-
|
|
|
+ private Button allocateparcels;
|
|
|
+ public Guid ConsignmentID { get; set; } = CoreUtils.FullGuid;
|
|
|
+ public Guid ParcelID { get; set; } = Guid.Empty;
|
|
|
+ public bool Completed { get; set; }
|
|
|
+
|
|
|
+ public Func<CoreTable>? GetParcels { get; set; }
|
|
|
+
|
|
|
protected override void Init()
|
|
|
{
|
|
|
base.Init();
|
|
|
+ HiddenColumns.Add(x=>x.ConsignmentParcel.ID);
|
|
|
+ HiddenColumns.Add(x=>x.ConsignmentParcel.Description);
|
|
|
|
|
|
+ allocateparcels = AddButton("Parcels", null, ShowParcelMenu);
|
|
|
+ allocateparcels.IsEnabled = false;
|
|
|
+
|
|
|
receiveall = AddButton("Receive All", null, ReceiveAll);
|
|
|
receiveall.IsEnabled = false;
|
|
|
+
|
|
|
receiveselected = AddButton("Receive Selected", null, ReceiveSelected);
|
|
|
receiveselected.IsEnabled = false;
|
|
|
-
|
|
|
+
|
|
|
AddButton("Assign Location", null, SupplierPurchaseOrderItemOneToMany.AssignLocation);
|
|
|
+
|
|
|
+ ActionColumns.Add(
|
|
|
+ new DynamicMenuColumn(
|
|
|
+ DoBuildMenu,
|
|
|
+ row => row.Get<PurchaseOrderItem,DateTime>(x=>x.ReceivedDate).IsEmpty()
|
|
|
+ ? DynamicMenuStatus.Enabled
|
|
|
+ : DynamicMenuStatus.Disabled
|
|
|
+ )
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ private void DoBuildMenu(DynamicMenuColumn column, CoreRow? row)
|
|
|
+ {
|
|
|
+ if (row is null)
|
|
|
+ return;
|
|
|
+ column.AddItem("Split Line", PRSDesktop.Resources.split, SplitLine);
|
|
|
+ var parcels = GetParcels?.Invoke().ToArray<ConsignmentParcel>() ?? [];
|
|
|
+ if (parcels.Any())
|
|
|
+ {
|
|
|
+ column.AddSeparator();
|
|
|
+ foreach (var parcel in parcels.Where(x=>x.ID != Guid.Empty && x.ID != CoreUtils.FullGuid))
|
|
|
+ column.AddItem(parcel.Description, null, r => AllocateParcels([r], parcel));
|
|
|
+ if (row.Get<PurchaseOrderItem, Guid>(x => x.ConsignmentParcel.ID) != Guid.Empty)
|
|
|
+ {
|
|
|
+ column.AddSeparator();
|
|
|
+ column.AddItem("Clear Parcel", null, r => AllocateParcels([r], new ConsignmentParcel()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void SplitLine(CoreRow? row)
|
|
|
+ {
|
|
|
+ if (row is null || !row.Get<PurchaseOrderItem, DateTime>(x => x.ReceivedDate).IsEmpty())
|
|
|
+ return;
|
|
|
+
|
|
|
+ Guid itemid = row.Get<PurchaseOrderItem, Guid>(x => x.ID);
|
|
|
+ var query = new MultiQuery();
|
|
|
+ query.Add(
|
|
|
+ new Filter<PurchaseOrderItem>(x => x.ID).IsEqualTo(itemid),
|
|
|
+ Columns.Local<PurchaseOrderItem>()
|
|
|
+ );
|
|
|
+ query.Add(
|
|
|
+ new Filter<PurchaseOrderItemAllocation>(x => x.Item.ID),
|
|
|
+ Columns.Local<PurchaseOrderItemAllocation>()
|
|
|
+ );
|
|
|
+ query.Query();
|
|
|
+ var item = query.Get<PurchaseOrderItem>().ToObjects<PurchaseOrderItem>().FirstOrDefault() ?? new PurchaseOrderItem();
|
|
|
+ var allocations = query.Get<PurchaseOrderItemAllocation>().ToList<PurchaseOrderItemAllocation>();
|
|
|
+ var splits = allocations.ToList(SupplierPurchaseOrderItemSplit.FromAllocation);
|
|
|
+ if (SupplierPurchaseOrderItemSplitWindow.Execute(item.Qty, splits, out var value))
|
|
|
+ {
|
|
|
+ var newItem = item.Clone();
|
|
|
+ newItem.ID = Guid.Empty;
|
|
|
+ newItem.CommitChanges();
|
|
|
+ newItem.Qty = item.Qty - value;
|
|
|
+ item.Qty = value;
|
|
|
+
|
|
|
+ foreach(var split in splits)
|
|
|
+ {
|
|
|
+ var allocation = allocations.FirstOrDefault(x => x.ID == split.AllocationID);
|
|
|
+ if (allocation is null)
|
|
|
+ continue;
|
|
|
+
|
|
|
+ var newAllocation = new PurchaseOrderItemAllocation();
|
|
|
+ newAllocation.Job.CopyFrom(allocation.Job);
|
|
|
+ newAllocation.JobRequisitionItem.CopyFrom(allocation.JobRequisitionItem);
|
|
|
+ newAllocation.Quantity = allocation.Quantity - split.SplitQuantity;
|
|
|
+ allocations.Add(newAllocation);
|
|
|
+
|
|
|
+ allocation.Quantity = split.SplitQuantity;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ Progress.ShowModal("Saving items", progress =>
|
|
|
+ {
|
|
|
+ Client.Save([item,newItem],"Split Consignment Line");
|
|
|
+ Client.Save(allocations,"Split Consignment Line");
|
|
|
+ });
|
|
|
+
|
|
|
+ Refresh(false,true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private bool ShowParcelMenu(Button button, CoreRow[] rows)
|
|
|
+ {
|
|
|
+ var parcels = GetParcels?.Invoke()?.ToArray<ConsignmentParcel>() ?? [];
|
|
|
+ if (!parcels.Any())
|
|
|
+ return false;
|
|
|
+ ContextMenu menu = new ContextMenu();
|
|
|
+ if (rows.Any(r => r.Get<PurchaseOrderItem,Guid>(c => c.ConsignmentParcel.ID) != Guid.Empty))
|
|
|
+ {
|
|
|
+ menu.Items.Add(
|
|
|
+ new MenuItem()
|
|
|
+ {
|
|
|
+ Header = "Clear Allocation",
|
|
|
+ Command = new ActionCommand(() => AllocateParcels(rows, new ConsignmentParcel()))
|
|
|
+ });
|
|
|
+ menu.Items.Add(new Separator());
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach (var parcel in parcels.Where(p => p.ID != Guid.Empty && p.ID != CoreUtils.FullGuid))
|
|
|
+ menu.Items.Add(
|
|
|
+ new MenuItem()
|
|
|
+ {
|
|
|
+ Header = parcel.Description,
|
|
|
+ Command = new ActionCommand(() => AllocateParcels(rows, parcel))
|
|
|
+ }
|
|
|
+ );
|
|
|
+
|
|
|
+ menu.IsOpen = true;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void AllocateParcels(CoreRow[] rows, ConsignmentParcel parcel)
|
|
|
+ {
|
|
|
+ List<PurchaseOrderItem> updates = new();
|
|
|
+ foreach (var row in rows)
|
|
|
+ {
|
|
|
+ var update = row.ToObject<PurchaseOrderItem>();
|
|
|
+ update.ConsignmentParcel.CopyFrom(parcel);
|
|
|
+ updates.Add(update);
|
|
|
+
|
|
|
+ row.Set<PurchaseOrderItem,Guid>(x=>x.ConsignmentParcel.ID, parcel.ID);
|
|
|
+ row.Set<PurchaseOrderItem,string>(x=>x.ConsignmentParcel.Description, parcel.Description);
|
|
|
+ InvalidateRow(row);
|
|
|
+
|
|
|
+ }
|
|
|
+ Client.Save(updates,"Updated from Consignment Screen", (o,e) => { });
|
|
|
}
|
|
|
|
|
|
protected override void DoReconfigure(DynamicGridOptions options)
|
|
@@ -38,13 +184,14 @@ public class ConsignmentItemGrid : DynamicDataGrid<PurchaseOrderItem>
|
|
|
options.AddRows = true;
|
|
|
options.DeleteRows = true;
|
|
|
options.MultiSelect = true;
|
|
|
+ options.FilterRows = true;
|
|
|
+ options.HideDatabaseFilters = true;
|
|
|
}
|
|
|
-
|
|
|
- public Guid ConsignmentID { get; set; }
|
|
|
- public bool Completed { get; set; }
|
|
|
-
|
|
|
+
|
|
|
protected override void SelectItems(CoreRow[]? rows)
|
|
|
{
|
|
|
+ var parcels = GetParcels?.Invoke()?.ToArray<ConsignmentParcel>() ?? [];
|
|
|
+ allocateparcels.IsEnabled = parcels.Any() && rows != null && rows.Any(r => r.Get<PurchaseOrderItem, DateTime>(c => c.ReceivedDate).IsEmpty());
|
|
|
receiveselected.IsEnabled = rows != null && rows.Any(r => r.Get<PurchaseOrderItem, DateTime>(c => c.ReceivedDate).IsEmpty());
|
|
|
receiveall.IsEnabled = Data.Rows.Any(r => r.Get<PurchaseOrderItem, DateTime>(c => c.ReceivedDate).IsEmpty());
|
|
|
base.SelectItems(rows);
|
|
@@ -97,6 +244,8 @@ public class ConsignmentItemGrid : DynamicDataGrid<PurchaseOrderItem>
|
|
|
{
|
|
|
criteria.Add(new Filter<PurchaseOrderItem>(x => x.Consignment.ID).IsEqualTo(
|
|
|
ConsignmentID == Guid.Empty ? CoreUtils.FullGuid : ConsignmentID));
|
|
|
+ if (ParcelID != CoreUtils.FullGuid)
|
|
|
+ criteria.Add(new Filter<PurchaseOrderItem>(x=>x.ConsignmentParcel.ID).IsEqualTo(ParcelID));
|
|
|
base.Reload(criteria, columns, ref sort, token, action);
|
|
|
}
|
|
|
|
|
@@ -180,4 +329,5 @@ public class ConsignmentItemGrid : DynamicDataGrid<PurchaseOrderItem>
|
|
|
new Client<PurchaseOrderItem>().Save(items, "Removed from Consignment");
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|