|
@@ -7,10 +7,12 @@ using InABox.Wpf;
|
|
|
using InABox.WPF;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Collections.Immutable;
|
|
|
using System.Drawing;
|
|
|
using System.Linq;
|
|
|
using System.Linq.Expressions;
|
|
|
using System.Threading;
|
|
|
+using System.Threading.Tasks;
|
|
|
using System.Windows;
|
|
|
using System.Windows.Controls;
|
|
|
using System.Windows.Media;
|
|
@@ -24,9 +26,12 @@ public delegate void GridRefresh();
|
|
|
|
|
|
public class ReservationManagementItemGrid : DynamicDataGrid<JobRequisitionItem>
|
|
|
{
|
|
|
- private readonly ReservationManagementUserSettings _userSettings = new ReservationManagementUserSettings();
|
|
|
|
|
|
+ public ReservationManagementUserSettings UserSettings { get; private set; }
|
|
|
+
|
|
|
private Button ArchiveButton;
|
|
|
+ private Button CreatePickingList;
|
|
|
+ private Button CreateOrder;
|
|
|
|
|
|
public bool ShowColors { get; set; }
|
|
|
|
|
@@ -107,12 +112,13 @@ public class ReservationManagementItemGrid : DynamicDataGrid<JobRequisitionItem>
|
|
|
private DynamicActionColumn TreatmentRequiredColumn;
|
|
|
private DynamicActionColumn TreatmentOnOrderColumn;
|
|
|
private DynamicActionColumn AllocatedColumn;
|
|
|
+ private DynamicActionColumn PickRequestedColumn;
|
|
|
private DynamicActionColumn IssuedColumn;
|
|
|
|
|
|
public ReservationManagementItemGrid()
|
|
|
{
|
|
|
- _userSettings = new UserConfiguration<ReservationManagementUserSettings>().Load();
|
|
|
- FilterComponent.SetSettings(_userSettings.Filters, false);
|
|
|
+ UserSettings = new UserConfiguration<ReservationManagementUserSettings>().Load();
|
|
|
+ FilterComponent.SetSettings(UserSettings.Filters, false);
|
|
|
|
|
|
HiddenColumns.Add(x => x.ID);
|
|
|
|
|
@@ -122,6 +128,7 @@ public class ReservationManagementItemGrid : DynamicDataGrid<JobRequisitionItem>
|
|
|
HiddenColumns.Add(x => x.TreatmentOnOrder);
|
|
|
HiddenColumns.Add(x => x.TreatmentRequired);
|
|
|
HiddenColumns.Add(x => x.Allocated);
|
|
|
+ HiddenColumns.Add(x => x.PickRequested);
|
|
|
HiddenColumns.Add(x => x.Issued);
|
|
|
|
|
|
HiddenColumns.Add(x => x.Product.ID);
|
|
@@ -166,6 +173,7 @@ public class ReservationManagementItemGrid : DynamicDataGrid<JobRequisitionItem>
|
|
|
TreatmentRequiredColumn = AddDoubleColumn(x => x.TreatmentRequired, "Req.");
|
|
|
TreatmentOnOrderColumn = AddDoubleColumn(x => x.TreatmentOnOrder, "Ord.");
|
|
|
AllocatedColumn = AddDoubleColumn(x => x.Allocated, "Stk.");
|
|
|
+ PickRequestedColumn = AddDoubleColumn(x => x.PickRequested, "P/L.");
|
|
|
IssuedColumn = AddDoubleColumn(x => x.Issued, "Iss.");
|
|
|
|
|
|
if (Security.CanEdit<JobRequisitionItem>())
|
|
@@ -174,10 +182,187 @@ public class ReservationManagementItemGrid : DynamicDataGrid<JobRequisitionItem>
|
|
|
ColumnsTag = "JobRequisitionReview";
|
|
|
|
|
|
FilterComponent.OnFiltersSelected += GridOnFilterSelected;
|
|
|
+
|
|
|
+ CreateOrder = AddButton("Create Order", PRSDesktop.Resources.purchase.AsBitmapImage(), DoCreatePurchaseOrder);
|
|
|
+ CreateOrder.IsEnabled = false;
|
|
|
+
|
|
|
+ CreatePickingList = AddButton("Create Picking List", PRSDesktop.Resources.trolley.AsBitmapImage(), DoCreatePickingList);
|
|
|
+ CreatePickingList.IsEnabled = false;
|
|
|
|
|
|
ArchiveButton = AddButton("Archive", PRSDesktop.Resources.archive.AsBitmapImage(), ArchiveButton_Clicked);
|
|
|
ArchiveButton.IsEnabled = false;
|
|
|
}
|
|
|
+
|
|
|
+ #region CreatePurchaseOrder
|
|
|
+
|
|
|
+ private bool DoCreatePurchaseOrder(Button button, CoreRow[]? rows)
|
|
|
+ {
|
|
|
+ if (rows?.Any() != true)
|
|
|
+ return false;
|
|
|
+
|
|
|
+ MultiSelectDialog<Supplier> dlg = new MultiSelectDialog<Supplier>(
|
|
|
+ LookupFactory.DefineFilter<Supplier>(),
|
|
|
+ Columns.None<Supplier>()
|
|
|
+ .Add(x => x.ID)
|
|
|
+ .Add(x => x.Code)
|
|
|
+ .Add(x => x.Name),
|
|
|
+ false
|
|
|
+ );
|
|
|
+
|
|
|
+ var _po = new PurchaseOrder();
|
|
|
+ if (dlg.ShowDialog())
|
|
|
+ {
|
|
|
+ Progress.ShowModal("Creating Purchase Order", progress =>
|
|
|
+ {
|
|
|
+
|
|
|
+ _po.Description = "Created from Job Requisition Screen" + System.Environment.NewLine;
|
|
|
+ _po.RaisedBy.ID = App.EmployeeID;
|
|
|
+ _po.SupplierLink.ID = dlg.IDs().First();
|
|
|
+ Client.Save(_po, "Created From Requisition Screen");
|
|
|
+
|
|
|
+ progress.Report("Creating Order Items");
|
|
|
+ Dictionary<Guid,PurchaseOrderItem> _pois = new Dictionary<Guid,PurchaseOrderItem>();
|
|
|
+ foreach (CoreRow row in SelectedRows)
|
|
|
+ {
|
|
|
+ JobRequisitionItem _jri = row.ToObject<JobRequisitionItem>();
|
|
|
+ PurchaseOrderItem _poi = new PurchaseOrderItem();
|
|
|
+ _poi.PurchaseOrderLink.ID = _po.ID;
|
|
|
+ _poi.Product.ID = _jri.Product.ID;
|
|
|
+ _poi.Product.Code = _jri.Product.Code;
|
|
|
+ _poi.Product.Name = _jri.Product.Name;
|
|
|
+ _poi.Qty = _jri.Qty;
|
|
|
+ _poi.Dimensions.CopyFrom(_jri.Dimensions);
|
|
|
+ _poi.Dimensions.Value = _jri.Dimensions.Value;
|
|
|
+ _poi.Style.ID = _jri.Style.ID;
|
|
|
+ _poi.Style.Code = _jri.Style.Code;
|
|
|
+ _poi.Style.Description = _jri.Style.Description;
|
|
|
+ _poi.Job.ID = _jri.Job.ID;
|
|
|
+ _poi.Dimensions.UnitSize = _jri.Dimensions.UnitSize;
|
|
|
+ _poi.Description = _jri.Product.Name + " (" + _jri.Dimensions.ToString() + ")";
|
|
|
+ _pois[_jri.ID] = _poi;
|
|
|
+ }
|
|
|
+ Client.Save(_pois.Values, "Created From Requisition Screen");
|
|
|
+
|
|
|
+ List<JobRequisitionItemPurchaseOrderItem> _jripois = new();
|
|
|
+ foreach (var _poi in _pois)
|
|
|
+ {
|
|
|
+ var _jripoi = new JobRequisitionItemPurchaseOrderItem();
|
|
|
+ _jripoi.JobRequisitionItem.ID = _poi.Key;
|
|
|
+ _jripoi.PurchaseOrderItem.ID = _poi.Value.ID;
|
|
|
+ _jripois.Add(_jripoi);
|
|
|
+ }
|
|
|
+ Client.Save(_jripois, "Created From Requisition Screen");
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+ new SupplierPurchaseOrders().EditItems(new[] { _po });
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region CreatePickingList
|
|
|
+
|
|
|
+ private bool DoCreatePickingList(Button button, CoreRow[]? rows)
|
|
|
+ {
|
|
|
+ if (rows?.Any() != true)
|
|
|
+ return false;
|
|
|
+ if (rows.All(r =>
|
|
|
+ r.Get<JobRequisitionItem, double>(x => x.PickRequested)
|
|
|
+ .IsEffectivelyEqual(r.Get<JobRequisitionItem, double>(x => x.Qty))))
|
|
|
+ {
|
|
|
+ MessageWindow.ShowMessage("All Items have been picked!","Error");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ var _jris = rows.ToObjects<JobRequisitionItem>()
|
|
|
+ .GroupBy(x=>new Tuple<Guid,String,String>(x.Requisition.Job.ID, x.Requisition.Job.JobNumber, x.Requisition.Job.Name))
|
|
|
+ .ToArray();
|
|
|
+
|
|
|
+ List<Requisition> _pls = new List<Requisition>();
|
|
|
+
|
|
|
+ Progress.ShowModal("Creating Picking Lists", progress =>
|
|
|
+ {
|
|
|
+ Task<StockMovement[]> _movementquery = Task.Run(
|
|
|
+ () => Client.Query(
|
|
|
+ new Filter<StockMovement>(x => x.JobRequisitionItem.ID)
|
|
|
+ .InList(rows.Select(r => r.Get<JobRequisitionItem,Guid>(c=>c.ID)).ToArray())
|
|
|
+ ).ToObjects<StockMovement>()
|
|
|
+ .ToArray()
|
|
|
+ );
|
|
|
+
|
|
|
+ foreach (var _job in _jris)
|
|
|
+ {
|
|
|
+ var _pl = new Requisition();
|
|
|
+ _pl.JobLink.ID = _job.Key.Item1;
|
|
|
+ _pl.JobLink.JobNumber = _job.Key.Item2;
|
|
|
+ _pl.JobLink.Name = _job.Key.Item3;
|
|
|
+ _pl.RequestedBy.ID = App.EmployeeID;
|
|
|
+ _pl.Notes = new string[] { $"Items requested by {App.EmployeeName}" };
|
|
|
+ _pls.Add(_pl);
|
|
|
+ }
|
|
|
+ Client.Save(_pls, "Created from Reservation Management Screen");
|
|
|
+
|
|
|
+ progress.Report("Retrieving Allocations");
|
|
|
+ _movementquery.Wait();
|
|
|
+
|
|
|
+ progress.Report("Creating Picking List Items");
|
|
|
+ List<RequisitionItem> _plitems = new List<RequisitionItem>();
|
|
|
+ foreach (var _pl in _pls)
|
|
|
+ {
|
|
|
+ var _pljris = _jris.First(x => x.Key.Item1 == _pl.JobLink.ID);
|
|
|
+ foreach (var _pljri in _pljris)
|
|
|
+ {
|
|
|
+ double qtyrequired = _pljri.Qty;
|
|
|
+ var _locations = _movementquery.Result.Where(x => x.JobRequisitionItem.ID == _pljri.ID)
|
|
|
+ .GroupBy(x => x.Location.ID);
|
|
|
+ foreach (var _location in _locations)
|
|
|
+ {
|
|
|
+ if (!qtyrequired.IsEffectivelyEqual(0.0))
|
|
|
+ {
|
|
|
+ var _plitem = new RequisitionItem();
|
|
|
+ _plitem.RequisitionLink.CopyFrom(_pl);
|
|
|
+ _plitem.JobRequisitionItem.CopyFrom(_pljri);
|
|
|
+ _plitem.SourceJRI.CopyFrom(_pljri);
|
|
|
+ _plitem.Product.CopyFrom(_pljri.Product);
|
|
|
+ _plitem.Style.CopyFrom(_pljri.Style);
|
|
|
+ _plitem.Dimensions.CopyFrom(_pljri.Dimensions);
|
|
|
+ _plitem.Location.ID = _location.Key;
|
|
|
+ _plitem.Quantity = Math.Min(qtyrequired, _location.Sum(x => x.Units));
|
|
|
+ _plitem.ActualQuantity = _plitem.Quantity;
|
|
|
+ qtyrequired -= _plitem.Quantity;
|
|
|
+ _plitems.Add(_plitem);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!qtyrequired.IsEffectivelyEqual(0.0))
|
|
|
+ {
|
|
|
+ var _plitem = new RequisitionItem();
|
|
|
+ _plitem.RequisitionLink.CopyFrom(_pl);
|
|
|
+ _plitem.JobRequisitionItem.CopyFrom(_pljri);
|
|
|
+ _plitem.Product.CopyFrom(_pljri.Product);
|
|
|
+ _plitem.Style.CopyFrom(_pljri.Style);
|
|
|
+ _plitem.Dimensions.CopyFrom(_pljri.Dimensions);
|
|
|
+ _plitem.Quantity = qtyrequired;
|
|
|
+ _plitems.Add(_plitem);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Client.Save(_plitems,"Created from Reservation Management Screen");
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ MessageWindow.ShowMessage(
|
|
|
+ $"Created the following Picking Lists:\n- {string.Join("\n- ",_pls.Select(x=>$"{x.Number}: {x.JobLink.JobNumber} {x.JobLink.Name}"))}",
|
|
|
+ "Picking Lists Created");
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
|
|
|
private DynamicActionColumn AddDoubleColumn(Expression<Func<JobRequisitionItem, object>> property, string header)
|
|
|
{
|
|
@@ -238,10 +423,11 @@ public class ReservationManagementItemGrid : DynamicDataGrid<JobRequisitionItem>
|
|
|
protected override void SelectItems(CoreRow[]? rows)
|
|
|
{
|
|
|
base.SelectItems(rows);
|
|
|
-
|
|
|
if(rows?.Any() == true)
|
|
|
{
|
|
|
ArchiveButton.IsEnabled = true;
|
|
|
+ CreateOrder.IsEnabled = true;
|
|
|
+ CreatePickingList.IsEnabled = true;
|
|
|
}
|
|
|
}
|
|
|
|