|
@@ -3,7 +3,9 @@ using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Windows;
|
|
|
+using System.Windows.Controls;
|
|
|
using Comal.Classes;
|
|
|
+using InABox.Clients;
|
|
|
using InABox.Core;
|
|
|
using InABox.DynamicGrid;
|
|
|
using InABox.WPF;
|
|
@@ -12,6 +14,8 @@ namespace PRSDesktop
|
|
|
{
|
|
|
public class JobBillOfMaterialsItemGrid : DynamicDataGrid<JobBillOfMaterialsItem>
|
|
|
{
|
|
|
+ Guid empID = Guid.Empty;
|
|
|
+ string empName = "";
|
|
|
public JobBillOfMaterialsItemGrid()
|
|
|
{
|
|
|
Options.AddRange(
|
|
@@ -45,15 +49,24 @@ namespace PRSDesktop
|
|
|
HiddenColumns.Add(x => x.Style.ID);
|
|
|
HiddenColumns.Add(x => x.Style.Code);
|
|
|
HiddenColumns.Add(x => x.Style.Description);
|
|
|
+ HiddenColumns.Add(x => x.BillOfMaterials.ID);
|
|
|
+ HiddenColumns.Add(x => x.Job.ID);
|
|
|
+ HiddenColumns.Add(x => x.PurchaseOrderItem.ID);
|
|
|
+ HiddenColumns.Add(x => x.PurchaseOrderItem.PurchaseOrderLink.PONumber);
|
|
|
+ HiddenColumns.Add(x => x.PurchaseOrderItem.ReceivedDate);
|
|
|
+ HiddenColumns.Add(x => x.PurchaseOrderItem.PONumber);
|
|
|
|
|
|
AddButton("Create Requi", null, CreateRequi);
|
|
|
- }
|
|
|
+ AddButton("Create PO", null, CreatePO);
|
|
|
+
|
|
|
+ GetEmpID();
|
|
|
+ }
|
|
|
|
|
|
private bool CreateRequi(System.Windows.Controls.Button btn, CoreRow[] rows)
|
|
|
{
|
|
|
if (!rows.Any())
|
|
|
{
|
|
|
- MessageBox.Show("Please select at least one row to add to Requi!");
|
|
|
+ MessageBox.Show("Please select at least one row to add to Requi");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -124,5 +137,161 @@ namespace PRSDesktop
|
|
|
base.Reload(criteria, columns, ref sort, action);
|
|
|
}
|
|
|
|
|
|
+ #region Create PO
|
|
|
+ private void GetEmpID()
|
|
|
+ {
|
|
|
+ CoreTable table = new Client<Employee>().Query(new Filter<Employee>(x => x.UserLink.UserID).IsEqualTo(ClientFactory.UserID), new Columns<Employee>(x => x.ID, x => x.Name));
|
|
|
+ if (table.Rows.Any())
|
|
|
+ {
|
|
|
+ empID = Guid.Parse(table.Rows.FirstOrDefault().Values[0].ToString());
|
|
|
+ empName = table.Rows.FirstOrDefault().Values[1].ToString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private bool CreatePO(System.Windows.Controls.Button btn, CoreRow[] rows)
|
|
|
+ {
|
|
|
+ if (!rows.Any())
|
|
|
+ {
|
|
|
+ MessageBox.Show("Please select at least one row to add to PO");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ PurchaseOrder purchaseOrder = new PurchaseOrder();
|
|
|
+ purchaseOrder.Notes = "Created from Job BOM Review Screen" + System.Environment.NewLine;
|
|
|
+ purchaseOrder.RaisedBy.ID = empID;
|
|
|
+ var page = new SupplierPurchaseOrders();
|
|
|
+ page.OnAfterSave += (form, items) =>
|
|
|
+ {
|
|
|
+ PurchaseOrderOnSave(form, items.Cast<PurchaseOrder>().ToArray());
|
|
|
+ MessageBox.Show("Success - New Purchase Order Created (" + purchaseOrder.PONumber + ")");
|
|
|
+ };
|
|
|
+ return page.EditItems(new[] { purchaseOrder }, LoadPurchaseOrderItems, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void PurchaseOrderOnSave(IDynamicEditorForm form, PurchaseOrder[] items)
|
|
|
+ {
|
|
|
+ Progress.Show("Working");
|
|
|
+
|
|
|
+ Guid POID = items[0].ID;
|
|
|
+
|
|
|
+ CoreTable table = new Client<PurchaseOrderItem>().Query(new Filter<PurchaseOrderItem>(x => x.PurchaseOrderLink.ID).IsEqualTo(POID),
|
|
|
+ new Columns<PurchaseOrderItem>(x => x.ID, x => x.Product.ID, x => x.Qty, x => x.Dimensions.UnitSize, x => x.DueDate, x => x.Job.ID));
|
|
|
+
|
|
|
+ if (table.Rows.Any())
|
|
|
+ {
|
|
|
+ var poItems = AddPOItems(table, new List<PurchaseOrderItem>());
|
|
|
+
|
|
|
+ var BOMItems = MatchBOMItems(poItems, new List<JobBillOfMaterialsItem>());
|
|
|
+
|
|
|
+ if (BOMItems.Count > 0)
|
|
|
+ SaveAndRefreshScreen(BOMItems);
|
|
|
+ }
|
|
|
+ Progress.Close();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void SaveAndRefreshScreen(List<JobBillOfMaterialsItem> bomItems)
|
|
|
+ {
|
|
|
+ new Client<JobBillOfMaterialsItem>().Save(bomItems, "Updated on Create Purchase Order from BOM Dashboard");
|
|
|
+ Dispatcher.BeginInvoke(() =>
|
|
|
+ {
|
|
|
+ Refresh(false, true);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<PurchaseOrderItem> AddPOItems(CoreTable table, List<PurchaseOrderItem> poItems)
|
|
|
+ {
|
|
|
+ foreach (CoreRow row in table.Rows)
|
|
|
+ {
|
|
|
+ PurchaseOrderItem poItem = row.ToObject<PurchaseOrderItem>();
|
|
|
+ poItems.Add(poItem);
|
|
|
+ }
|
|
|
+ return poItems;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<JobBillOfMaterialsItem> MatchBOMItems(List<PurchaseOrderItem> poItems, List<JobBillOfMaterialsItem> bomItems)
|
|
|
+ {
|
|
|
+ foreach (CoreRow row in SelectedRows)
|
|
|
+ {
|
|
|
+ JobBillOfMaterialsItem bomItem = row.ToObject<JobBillOfMaterialsItem>();
|
|
|
+ foreach (var item in poItems)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrWhiteSpace(bomItem.Dimensions.UnitSize))
|
|
|
+ bomItem.Dimensions.UnitSize = QueryUnitSize(bomItem.Product.ID);
|
|
|
+
|
|
|
+ if (string.IsNullOrWhiteSpace(item.Dimensions.UnitSize))
|
|
|
+ item.Dimensions.UnitSize = QueryUnitSize(item.Product.ID);
|
|
|
+
|
|
|
+ if (bomItem.Job.ID == Guid.Empty)
|
|
|
+ bomItem.Job.ID = QueryJobID(bomItem.BillOfMaterials.ID);
|
|
|
+
|
|
|
+ if (item.Job.ID == Guid.Empty)
|
|
|
+ item.Job.ID = QueryJobID(bomItem.BillOfMaterials.ID);
|
|
|
+
|
|
|
+ if (MatchBOMItemToPOItem(bomItem, item))
|
|
|
+ bomItems.Add(UpdateBOMItemWithPODetails(bomItem, item));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return bomItems;
|
|
|
+ }
|
|
|
+
|
|
|
+ private JobBillOfMaterialsItem UpdateBOMItemWithPODetails(JobBillOfMaterialsItem bomItem, PurchaseOrderItem item)
|
|
|
+ {
|
|
|
+ bomItem.PurchaseOrderItem.ID = item.ID;
|
|
|
+ bomItem.PurchaseOrderItem.DueDate = item.DueDate;
|
|
|
+ return bomItem;
|
|
|
+ }
|
|
|
+
|
|
|
+ private string QueryUnitSize(Guid productID)
|
|
|
+ {
|
|
|
+ CoreTable table = new Client<Product>().Query(new Filter<Product>(x => x.ID).IsEqualTo(productID),
|
|
|
+ new Columns<Product>(x => x.Dimensions.UnitSize));
|
|
|
+ return table.Rows.FirstOrDefault().Get<string>("Dimensions.UnitSize");
|
|
|
+ }
|
|
|
+
|
|
|
+ private Guid QueryJobID(Guid iD)
|
|
|
+ {
|
|
|
+ CoreTable table = new Client<JobBillOfMaterials>().Query(new Filter<JobBillOfMaterials>(x => x.ID).IsEqualTo(iD),
|
|
|
+ new Columns<JobBillOfMaterials>(x => x.Job.ID));
|
|
|
+ return table.Rows.FirstOrDefault().Get<JobBillOfMaterials, Guid>(x => x.Job.ID);
|
|
|
+ }
|
|
|
+
|
|
|
+ private bool MatchBOMItemToPOItem(JobBillOfMaterialsItem bomItem, PurchaseOrderItem item)
|
|
|
+ {
|
|
|
+ if (bomItem.Product.ID == item.Product.ID &&
|
|
|
+ bomItem.Dimensions.UnitSize == item.Dimensions.UnitSize &&
|
|
|
+ bomItem.Job.ID == item.Job.ID)
|
|
|
+ return true;
|
|
|
+ else
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ private CoreTable LoadPurchaseOrderItems(Type arg)
|
|
|
+ {
|
|
|
+ Progress.Show("Working");
|
|
|
+ var result = new CoreTable();
|
|
|
+ result.LoadColumns(typeof(PurchaseOrderItem));
|
|
|
+ List<PurchaseOrderItem> items = new List<PurchaseOrderItem>();
|
|
|
+ foreach (CoreRow row in SelectedRows)
|
|
|
+ {
|
|
|
+ JobBillOfMaterialsItem BOMItem = row.ToObject<JobBillOfMaterialsItem>();
|
|
|
+ PurchaseOrderItem POItem = new PurchaseOrderItem();
|
|
|
+ POItem.Product.ID = BOMItem.Product.ID;
|
|
|
+ POItem.Product.Code = BOMItem.Product.Code;
|
|
|
+ POItem.Product.Name = BOMItem.Product.Name;
|
|
|
+ POItem.Description = BOMItem.Product.Name;
|
|
|
+ POItem.Qty = BOMItem.Quantity;
|
|
|
+ POItem.Dimensions.CopyFrom(BOMItem.Dimensions);
|
|
|
+ POItem.Style.ID = BOMItem.Style.ID;
|
|
|
+ POItem.Style.Code = BOMItem.Style.Code;
|
|
|
+ POItem.Style.Description = BOMItem.Style.Description;
|
|
|
+ POItem.Job.ID = BOMItem.Job.ID;
|
|
|
+ POItem.Dimensions.UnitSize = BOMItem.Dimensions.UnitSize;
|
|
|
+ items.Add(POItem);
|
|
|
+ }
|
|
|
+ result.LoadRows(items);
|
|
|
+ Progress.Close();
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
}
|
|
|
}
|