|
@@ -10,6 +10,7 @@ using InABox.Clients;
|
|
|
using InABox.Core;
|
|
|
using InABox.DynamicGrid;
|
|
|
using InABox.WPF;
|
|
|
+using NPOI.SS.Formula.Functions;
|
|
|
using static InABox.DynamicGrid.DynamicMenuColumn;
|
|
|
|
|
|
namespace PRSDesktop
|
|
@@ -17,8 +18,8 @@ namespace PRSDesktop
|
|
|
public class SupplierPurchaseOrderItemOneToMany : DynamicOneToManyGrid<PurchaseOrder,PurchaseOrderItem>
|
|
|
{
|
|
|
private Button bill;
|
|
|
- private Button? consign;
|
|
|
- private Button? viewconsign;
|
|
|
+ private Button? createConsignment;
|
|
|
+ //private Button? viewconsign;
|
|
|
private Button receive;
|
|
|
private Button assignLocation;
|
|
|
|
|
@@ -66,11 +67,8 @@ namespace PRSDesktop
|
|
|
|
|
|
if (Security.IsAllowed<CanViewConsignmentModule>())
|
|
|
{
|
|
|
- consign = AddButton("Create Consignment", null, CreateConsignment);
|
|
|
- consign.IsEnabled = false;
|
|
|
-
|
|
|
- viewconsign = AddButton("View Consignment", null, ViewConsignment);
|
|
|
- viewconsign.Visibility = Visibility.Collapsed;
|
|
|
+ createConsignment = AddButton("Add to Consignment", null, AddToConsignment);
|
|
|
+ createConsignment.IsEnabled = false;
|
|
|
}
|
|
|
|
|
|
receive = AddButton("Receive Items", null, ReceiveItems);
|
|
@@ -96,7 +94,7 @@ namespace PRSDesktop
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public override void Load(object item, Func<Type, CoreTable>? PageDataHandler)
|
|
|
+ public override void Load(object item, Func<Type, CoreTable?>? PageDataHandler)
|
|
|
{
|
|
|
Reconfigure();
|
|
|
Refresh(true, false);
|
|
@@ -117,6 +115,12 @@ namespace PRSDesktop
|
|
|
private void BuildFormsMenu(DynamicMenuColumn column, CoreRow? row)
|
|
|
{
|
|
|
if (row == null) return;
|
|
|
+
|
|
|
+ if(row.Get<PurchaseOrderItem, Guid>(x => x.Consignment.ID) != Guid.Empty)
|
|
|
+ {
|
|
|
+ column.AddItem("View Consignment", null, ViewConsignment);
|
|
|
+ }
|
|
|
+
|
|
|
var formsItem = column.AddItem("Digital Forms", PRSDesktop.Resources.kanban, null);
|
|
|
DynamicGridUtils.PopulateFormMenu<PurchaseOrderItemForm, PurchaseOrderItem, PurchaseOrderItemLink>(
|
|
|
formsItem,
|
|
@@ -124,6 +128,19 @@ namespace PRSDesktop
|
|
|
row.ToObject<PurchaseOrderItem>);
|
|
|
}
|
|
|
|
|
|
+ private void ViewConsignment(CoreRow? row)
|
|
|
+ {
|
|
|
+ if (row is null) return;
|
|
|
+
|
|
|
+ var consignmentID = row.Get<PurchaseOrderItem, Guid>(x => x.Consignment.ID);
|
|
|
+ var consignments = new Client<Consignment>()
|
|
|
+ .Query(
|
|
|
+ new Filter<Consignment>(x => x.ID).IsEqualTo(consignmentID),
|
|
|
+ DynamicGridUtils.LoadEditorColumns(new Columns<Consignment>()))
|
|
|
+ .ToObjects<Consignment>().ToArray();
|
|
|
+ DynamicGridUtils.CreateDynamicGrid(typeof(DynamicDataGrid<>), typeof(Consignment)).EditItems(consignments);
|
|
|
+ }
|
|
|
+
|
|
|
private FrameworkElement? FormsToolTip(DynamicActionColumn arg1, CoreRow? arg2)
|
|
|
{
|
|
|
var text = arg2 == null || arg2.Get<PurchaseOrderItem, Guid>(x => x.Product.DigitalForm.ID) == Guid.Empty
|
|
@@ -149,7 +166,7 @@ namespace PRSDesktop
|
|
|
: PRSDesktop.Resources.quality.AsBitmapImage();
|
|
|
}
|
|
|
|
|
|
- private bool CreateConsignment(Button sender, CoreRow[] rows)
|
|
|
+ private bool AddToConsignment(Button sender, CoreRow[] rows)
|
|
|
{
|
|
|
if (!rows.Any())
|
|
|
{
|
|
@@ -157,32 +174,66 @@ namespace PRSDesktop
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- var consign = new Consignment();
|
|
|
- consign.Supplier.ID = rows.First().Get<PurchaseOrderItem, Guid>(x => x.PurchaseOrderLink.SupplierLink.ID);
|
|
|
- consign.Category.ID = rows.First().Get<PurchaseOrderItem, Guid>(x => x.PurchaseOrderLink.Category.ID);
|
|
|
- return new DynamicDataGrid<Consignment>().EditItems(new[] { consign }, LoadConsignmentLines, true);
|
|
|
- }
|
|
|
-
|
|
|
- private bool ViewConsignment(Button sender, CoreRow[] rows)
|
|
|
- {
|
|
|
- if (!rows.Any())
|
|
|
+ var poItems = LoadItems(rows);
|
|
|
+ if(poItems.Any(x => x.ID == Guid.Empty))
|
|
|
{
|
|
|
- MessageBox.Show("Please select a row first");
|
|
|
+ MessageBox.Show("Please save this purchase order first.");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- var consign = new Consignment();
|
|
|
- consign.Supplier.ID = rows.First().Get<PurchaseOrderItem, Guid>(x => x.PurchaseOrderLink.SupplierLink.ID);
|
|
|
- consign.Category.ID = rows.First().Get<PurchaseOrderItem, Guid>(x => x.PurchaseOrderLink.Category.ID);
|
|
|
- return new DynamicDataGrid<Consignment>().EditItems(new[] { consign }, LoadConsignmentLines, true);
|
|
|
+ var menu = new ContextMenu();
|
|
|
+ menu.AddItem("New Consignment", null, () =>
|
|
|
+ {
|
|
|
+ var consign = new Consignment();
|
|
|
+ consign.Supplier.ID = rows.First().Get<PurchaseOrderItem, Guid>(x => x.PurchaseOrderLink.SupplierLink.ID);
|
|
|
+ consign.Category.ID = rows.First().Get<PurchaseOrderItem, Guid>(x => x.PurchaseOrderLink.Category.ID);
|
|
|
+
|
|
|
+ if (new DynamicDataGrid<Consignment>().EditItems(new[] { consign }, LoadConsignmentLines, true))
|
|
|
+ {
|
|
|
+ foreach (var item in poItems)
|
|
|
+ {
|
|
|
+ item.Consignment.ID = consign.ID;
|
|
|
+ }
|
|
|
+ new Client<PurchaseOrderItem>().Save(poItems, "Added to new consignment");
|
|
|
+ Refresh(false, true);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ menu.AddItem("Existing Consignment", null, () =>
|
|
|
+ {
|
|
|
+ var popupList = new PopupList(typeof(Consignment), Guid.Empty, Array.Empty<string>());
|
|
|
+ popupList.OnDefineFilter += type =>
|
|
|
+ {
|
|
|
+ return new Filter<Consignment>(x => x.Closed).IsNotEqualTo(DateTime.MinValue)
|
|
|
+ .Or(x => x.ActualWarehouseArrival).IsNotEqualTo(DateTime.MinValue);
|
|
|
+ };
|
|
|
+ if (popupList.ShowDialog() == true)
|
|
|
+ {
|
|
|
+ foreach (var item in poItems)
|
|
|
+ {
|
|
|
+ item.Consignment.ID = popupList.ID;
|
|
|
+ }
|
|
|
+ new Client<PurchaseOrderItem>().Save(poItems, "Added to existing consignment");
|
|
|
+ Refresh(false, true);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ menu.IsOpen = true;
|
|
|
+
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
- private CoreTable LoadConsignmentLines(Type arg)
|
|
|
+ private CoreTable? LoadConsignmentLines(Type type)
|
|
|
{
|
|
|
- var result = new CoreTable();
|
|
|
- result.LoadColumns(typeof(PurchaseOrderItem));
|
|
|
- result.LoadRows(SelectedRows);
|
|
|
- return result;
|
|
|
+ if (type == typeof(PurchaseOrderItem))
|
|
|
+ {
|
|
|
+ var result = new CoreTable();
|
|
|
+ result.LoadColumns(typeof(PurchaseOrderItem));
|
|
|
+ result.LoadRows(SelectedRows);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private static bool EnterBill(Button sender, CoreRow[] rows)
|
|
@@ -306,22 +357,13 @@ namespace PRSDesktop
|
|
|
|
|
|
protected override void SelectItems(CoreRow[]? rows)
|
|
|
{
|
|
|
- if (consign != null && viewconsign != null)
|
|
|
+ if (createConsignment != null)
|
|
|
{
|
|
|
- consign.IsEnabled =
|
|
|
+ createConsignment.IsEnabled =
|
|
|
rows != null
|
|
|
&& !rows.Any(r => Entity.IsEntityLinkValid<PurchaseOrderItem, ConsignmentLink>(x => x.Consignment, r))
|
|
|
- && !rows.Any(r => r.Get<PurchaseOrderItem, DateTime>(c => c.ReceivedDate).IsEmpty() == false)
|
|
|
+ && !rows.Any(r => !r.Get<PurchaseOrderItem, DateTime>(c => c.ReceivedDate).IsEmpty())
|
|
|
&& !ReadOnly && Security.CanEdit<Consignment>();
|
|
|
-
|
|
|
- viewconsign.Visibility =
|
|
|
- rows == null
|
|
|
- || consign.IsEnabled
|
|
|
- || rows.Select(r =>r.Get<PurchaseOrderItem, Guid>(x => x.Consignment.ID)).Distinct().Count() != 1
|
|
|
- ? Visibility.Collapsed
|
|
|
- : Visibility.Visible;
|
|
|
-
|
|
|
- consign.Visibility = viewconsign.Visibility == Visibility.Visible ? Visibility.Collapsed : Visibility.Visible;
|
|
|
}
|
|
|
|
|
|
receive.IsEnabled =
|