|
@@ -6,6 +6,7 @@ using InABox.Clients;
|
|
|
using InABox.Configuration;
|
|
|
using InABox.Core;
|
|
|
using InABox.DynamicGrid;
|
|
|
+using InABox.Wpf;
|
|
|
|
|
|
namespace PRSDesktop;
|
|
|
|
|
@@ -62,6 +63,7 @@ public class ProjectsGrid : DynamicDataGrid<Job>
|
|
|
HiddenColumns.Add(x => x.DefaultScope.ID);
|
|
|
|
|
|
ActionColumns.Add(new DynamicMapColumn<Job>(this, x => x.SiteAddress.Location));
|
|
|
+ //ActionColumns.Add(new DynamicMenuColumn(BuildMenu));
|
|
|
}
|
|
|
|
|
|
protected override void DoReconfigure(FluentList<DynamicGridOption> options)
|
|
@@ -74,6 +76,119 @@ public class ProjectsGrid : DynamicDataGrid<Job>
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ private void BuildMenu(DynamicMenuColumn column, CoreRow? row)
|
|
|
+ {
|
|
|
+ if (Security.IsAllowed<CanCancelAllJobRequisitions>())
|
|
|
+ {
|
|
|
+ column.AddItem("Cancel all active requisitions", null, CancelJobRequisitions_Click);
|
|
|
+ }
|
|
|
+ if (Security.IsAllowed<CanReleaseJobReserves>())
|
|
|
+ {
|
|
|
+ column.AddItem("Release Job Reserves", null, ReleaseJobReserves_Click);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void CancelJobRequisitions_Click(CoreRow? obj)
|
|
|
+ {
|
|
|
+ var job = obj?.ToObject<Job>();
|
|
|
+ if (job is null)
|
|
|
+ {
|
|
|
+ MessageWindow.ShowMessage("Please select a job.", "No job selected");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(MessageWindow.ShowYesNoCancel("Are you sure you wish to do this? This will cancel all requisitions for this job.", "Confirm") != MessageWindowResult.Yes)
|
|
|
+ {
|
|
|
+ MessageWindow.ShowMessage("No action taken.", "Process aborted");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ var requisitionItems = Client.Query(
|
|
|
+ new Filter<JobRequisitionItem>(x => x.Requisition.Job.ID).IsEqualTo(job.ID)
|
|
|
+ .And(x => x.Status).IsNotEqualTo(JobRequisitionItemStatus.Cancelled)
|
|
|
+ .And(x => x.Status).IsNotEqualTo(JobRequisitionItemStatus.Issued)
|
|
|
+ .And(x => x.Status).IsNotEqualTo(JobRequisitionItemStatus.Archived),
|
|
|
+ new Columns<JobRequisitionItem>(x => x.ID)
|
|
|
+ .Add(x => x.Cancelled))
|
|
|
+ .ToList<JobRequisitionItem>();
|
|
|
+ foreach(var jri in requisitionItems)
|
|
|
+ {
|
|
|
+ jri.Cancelled = DateTime.Now;
|
|
|
+ }
|
|
|
+ Client.Save(requisitionItems, "Cancelled all job requisitions for job");
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ReleaseJobReserves_Click(CoreRow? obj)
|
|
|
+ {
|
|
|
+ var job = obj?.ToObject<Job>();
|
|
|
+ if (job is null)
|
|
|
+ {
|
|
|
+ MessageWindow.ShowMessage("Please select a job.", "No job selected");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(MessageWindow.ShowYesNoCancel("Are you sure you wish to do this? This will release all reserves for this job.", "Confirm") != MessageWindowResult.Yes)
|
|
|
+ {
|
|
|
+ MessageWindow.ShowMessage("No action taken.", "Process aborted");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ var movements = Client.Query<StockMovement>(
|
|
|
+ new Filter<StockMovement>(x => x.Job.ID).IsEqualTo(job.ID),
|
|
|
+ new Columns<StockMovement>(x => x.Units)
|
|
|
+ .Add(x => x.Location.ID)
|
|
|
+ .Add(x => x.Product.ID)
|
|
|
+ .Add(x => x.Style.ID)
|
|
|
+ .AddDimensionsColumns(x => x.Dimensions)
|
|
|
+ .Add(x => x.Cost)
|
|
|
+ .Add(x => x.OrderItem.ID)
|
|
|
+ .Add(x => x.JobRequisitionItem.ID))
|
|
|
+ .ToObjects<StockMovement>()
|
|
|
+ .GroupBy(x => new
|
|
|
+ {
|
|
|
+ Location = x.Location.ID,
|
|
|
+ Product = x.Product.ID,
|
|
|
+ Style = x.Style.ID,
|
|
|
+ x.Dimensions,
|
|
|
+ x.Cost,
|
|
|
+ OrderItem = x.OrderItem.ID,
|
|
|
+ JobRequisitionItem = x.JobRequisitionItem.ID
|
|
|
+ })
|
|
|
+ .Select(x => new { x.Key, Units = x.Sum(x => x.Units) });
|
|
|
+
|
|
|
+ var toSave = new List<StockMovement>();
|
|
|
+ foreach(var group in movements)
|
|
|
+ {
|
|
|
+ var from = new StockMovement();
|
|
|
+ from.Location.ID = group.Key.Location;
|
|
|
+ from.Style.ID = group.Key.Style;
|
|
|
+ from.Product.ID = group.Key.Product;
|
|
|
+ from.Dimensions.CopyFrom(group.Key.Dimensions);
|
|
|
+
|
|
|
+ var to = from.CreateMovement();
|
|
|
+
|
|
|
+ from.Job.ID = job.ID;
|
|
|
+
|
|
|
+ from.Cost = group.Key.Cost;
|
|
|
+ to.Cost = group.Key.Cost;
|
|
|
+ from.OrderItem.ID = group.Key.OrderItem;
|
|
|
+ to.OrderItem.ID = group.Key.OrderItem;
|
|
|
+ from.JobRequisitionItem.ID = group.Key.JobRequisitionItem;
|
|
|
+ to.JobRequisitionItem.ID = group.Key.JobRequisitionItem;
|
|
|
+
|
|
|
+ from.Type = StockMovementType.TransferOut;
|
|
|
+ to.Type = StockMovementType.TransferIn;
|
|
|
+ to.Transaction = from.Transaction;
|
|
|
+
|
|
|
+ from.Units = -group.Units;
|
|
|
+ to.Units = group.Units;
|
|
|
+
|
|
|
+ toSave.Add(from);
|
|
|
+ toSave.Add(to);
|
|
|
+ }
|
|
|
+ Client.Save(toSave, "Released all job stock.");
|
|
|
+ }
|
|
|
+
|
|
|
public Guid StatusID
|
|
|
{
|
|
|
get => _statusid;
|