|
@@ -3,6 +3,8 @@ using InABox.Clients;
|
|
|
using InABox.Core;
|
|
|
using InABox.DynamicGrid;
|
|
|
using InABox.WPF;
|
|
|
+using NPOI.OpenXmlFormats.Dml;
|
|
|
+using Syncfusion.Windows.Shared;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
@@ -26,7 +28,7 @@ namespace PRSDesktop
|
|
|
bool bIncludeArchived = false;
|
|
|
bool bViewCancelled = false;
|
|
|
public Guid JobID = Guid.Empty;
|
|
|
-
|
|
|
+ Dictionary<Guid, double> JobRequisReservedQty = new Dictionary<Guid, double>();
|
|
|
public JobRequisitionReviewGrid()
|
|
|
{
|
|
|
Options.AddRange(
|
|
@@ -71,12 +73,15 @@ namespace PRSDesktop
|
|
|
HiddenColumns.Add(x => x.Dimensions.Unit.Code);
|
|
|
HiddenColumns.Add(x => x.Dimensions.Unit.Description);
|
|
|
|
|
|
+ LoadStockMovements();
|
|
|
+ ActionColumns.Add(new DynamicTextColumn(CreateStatus));
|
|
|
+
|
|
|
if (Security.CanEdit<JobRequisitionItem>())
|
|
|
ActionColumns.Add(new DynamicMenuColumn(BuildMenu, EmptyReturnFunction));
|
|
|
if (Security.CanEdit<PurchaseOrder>())
|
|
|
AddButton("Create Purchase Order", null, CreatePurchaseOrder);
|
|
|
if (Security.CanEdit<PurchaseOrder>())
|
|
|
- AddButton("Create Treatment PO", null, CreateTreatmentPO);
|
|
|
+ AddButton("Create Treatment PO", null, CreateTreatmentPO);
|
|
|
|
|
|
AddButton("Include Archived", null, ViewArchived);
|
|
|
AddButton("Include Cancelled", null, ViewCancelled);
|
|
@@ -91,6 +96,85 @@ namespace PRSDesktop
|
|
|
empID = Guid.Parse(table.Rows.FirstOrDefault().Values[0].ToString());
|
|
|
empName = table.Rows.FirstOrDefault().Values[1].ToString();
|
|
|
}
|
|
|
+
|
|
|
+ //Migrate();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Migrate()
|
|
|
+ {
|
|
|
+ CoreTable table = new Client<JobRequisitionItem>().Query(null, new Columns<JobRequisitionItem>(x => x.ID, x => x.PurchaseOrderItem.PurchaseOrderLink.ID));
|
|
|
+ Dictionary<Guid, Guid> reqPOids = new Dictionary<Guid, Guid>();
|
|
|
+ List<JobRequisitionItem> affected = new List<JobRequisitionItem>();
|
|
|
+ foreach(CoreRow row in table.Rows)
|
|
|
+ {
|
|
|
+ var item = row.ToObject<JobRequisitionItem>();
|
|
|
+ if (item.PurchaseOrderItem.PurchaseOrderLink.ID != Guid.Empty)
|
|
|
+ {
|
|
|
+ reqPOids.Add(row.Get<JobRequisitionItem, Guid>(x => x.ID), item.PurchaseOrderItem.PurchaseOrderLink.ID);
|
|
|
+ affected.Add(row.ToObject<JobRequisitionItem>());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<JobRequisitionItem> list = new List<JobRequisitionItem>();
|
|
|
+ CoreTable POs = new Client<PurchaseOrder>().Query(new Filter<PurchaseOrder>(x => x.ID).InList(reqPOids.Values.ToArray()), new Columns<PurchaseOrder>(x => x.ID, x => x.Created));
|
|
|
+ foreach (CoreRow row in POs.Rows)
|
|
|
+ {
|
|
|
+ var items = affected.Where(x => x.PurchaseOrderItem.PurchaseOrderLink.ID == row.Get<PurchaseOrder, Guid>(x => x.ID));
|
|
|
+ foreach (var item in items)
|
|
|
+ {
|
|
|
+ item.Ordered = row.Get<PurchaseOrder, DateTime>(x => x.Created);
|
|
|
+ list.Add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ new Client<JobRequisitionItem>().Save(list, "Migrate");
|
|
|
+ }
|
|
|
+
|
|
|
+ private void LoadStockMovements()
|
|
|
+ {
|
|
|
+ CoreTable table = new Client<StockMovement>().Query(
|
|
|
+ new Filter<StockMovement>(x => x.JobRequisitionItem.ID).IsNotEqualTo(Guid.Empty),
|
|
|
+ new Columns<StockMovement>(
|
|
|
+ x => x.JobRequisitionItem.ID,
|
|
|
+ x => x.Received
|
|
|
+ )
|
|
|
+ );
|
|
|
+ foreach (CoreRow row in table.Rows)
|
|
|
+ {
|
|
|
+ var requiID = row.Get<StockMovement, Guid>(x => x.JobRequisitionItem.ID);
|
|
|
+ var qty = row.Get<StockMovement, double>(x => x.Received);
|
|
|
+ if (!JobRequisReservedQty.ContainsKey(requiID))
|
|
|
+ JobRequisReservedQty.Add(requiID, qty);
|
|
|
+ else
|
|
|
+ {
|
|
|
+ double newQty = JobRequisReservedQty[requiID] + qty;
|
|
|
+ JobRequisReservedQty.Remove(requiID);
|
|
|
+ JobRequisReservedQty.Add(requiID, newQty);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private string? CreateStatus(CoreRow? row)
|
|
|
+ {
|
|
|
+ Guid id = row.Get<JobRequisitionItem, Guid>(x => x.ID);
|
|
|
+
|
|
|
+ string status = "Not Checked";
|
|
|
+
|
|
|
+ if (row.Get<JobRequisitionItem, DateTime>(x => x.Cancelled) != DateTime.MinValue)
|
|
|
+ return "Cancelled";
|
|
|
+
|
|
|
+ if (row.Get<JobRequisitionItem, DateTime>(x => x.Archived) != DateTime.MinValue)
|
|
|
+ return "Archived";
|
|
|
+
|
|
|
+ if (row.Get<JobRequisitionItem, DateTime>(x => x.Ordered) != DateTime.MinValue && !JobRequisReservedQty.ContainsKey(id))
|
|
|
+ return "On Order";
|
|
|
+
|
|
|
+ if (row.Get<JobRequisitionItem, JobRequisitionItemStatus>(x => x.Status) == JobRequisitionItemStatus.OrderRequired)
|
|
|
+ return "Order Required";
|
|
|
+
|
|
|
+ if (JobRequisReservedQty.ContainsKey(id))
|
|
|
+ if (JobRequisReservedQty[id] == row.Get<JobRequisitionItem, double>(x => x.Qty))
|
|
|
+ return "Reserved";
|
|
|
+
|
|
|
+ return status;
|
|
|
}
|
|
|
|
|
|
protected override DynamicGridStyle GetRowStyle(CoreRow row, DynamicGridStyle style)
|
|
@@ -529,7 +613,7 @@ namespace PRSDesktop
|
|
|
|
|
|
if (JobID != Guid.Empty)
|
|
|
criteria.Add(new Filter<JobRequisitionItem>(x => x.Requisition.Job.ID).IsEqualTo(JobID));
|
|
|
-
|
|
|
+
|
|
|
|
|
|
sort = new SortOrder<JobRequisitionItem>(x => x.Requisition.Number, SortDirection.Descending);
|
|
|
base.Reload(criteria, columns, ref sort, action);
|