|
@@ -1,12 +1,125 @@
|
|
|
using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using System.Reactive.Linq;
|
|
|
+using System.Windows;
|
|
|
+using System.Windows.Controls;
|
|
|
using Comal.Classes;
|
|
|
+using InABox.Clients;
|
|
|
using InABox.Core;
|
|
|
using InABox.DynamicGrid;
|
|
|
+using InABox.WPF;
|
|
|
|
|
|
namespace PRSDesktop
|
|
|
{
|
|
|
internal class JobRequisitionItemGrid : DynamicDataGrid<JobRequisitionItem>
|
|
|
{
|
|
|
+ private Button CancelItemsButton;
|
|
|
+
|
|
|
+ public JobRequisitionItemGrid()
|
|
|
+ {
|
|
|
+ CancelItemsButton = AddButton("Cancel Items", PRSDesktop.Resources.disabled.AsBitmapImage(), CancelItems);
|
|
|
+ CancelItemsButton.Visibility = Security.CanEdit<JobRequisition>() && Security.CanEdit<JobRequisitionItem>()
|
|
|
+ ? System.Windows.Visibility.Visible
|
|
|
+ : System.Windows.Visibility.Hidden;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void SelectItems(CoreRow[]? rows)
|
|
|
+ {
|
|
|
+ base.SelectItems(rows);
|
|
|
+
|
|
|
+ CancelItemsButton.IsEnabled = rows is not null && rows.Length > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ private bool CancelItems(Button button, CoreRow[] rows)
|
|
|
+ {
|
|
|
+ if(rows.Length == 0)
|
|
|
+ {
|
|
|
+ MessageBox.Show("Please select at least one item to cancel.");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Reloading so I can ensure the correct columns without having to add hidden columns to JobRequisitionGrid.
|
|
|
+ var oldRequi = Client.Query(
|
|
|
+ new Filter<JobRequisition>(x => x.ID).IsEqualTo(Requisition.ID),
|
|
|
+ new Columns<JobRequisition>(x => x.Description)
|
|
|
+ .Add(x => x.DueDate))
|
|
|
+ .ToObjects<JobRequisition>()
|
|
|
+ .First();
|
|
|
+
|
|
|
+ var oldRequiItems = Client.Query(
|
|
|
+ new Filter<JobRequisitionItem>(x => x.ID).InList(rows.Select(x => x.Get<JobRequisitionItem, Guid>(x => x.ID)).ToArray()),
|
|
|
+ new Columns<JobRequisitionItem>(x => x.Qty)
|
|
|
+ .Add(x => x.Sequence)
|
|
|
+ .Add(x => x.Job.ID)
|
|
|
+ .Add(x => x.Product.ID)
|
|
|
+ .Add(x => x.Product.Code)
|
|
|
+ .Add(x => x.Style.ID)
|
|
|
+ .Add(x => x.Style.Code)
|
|
|
+ .Add(x => x.Style.Description)
|
|
|
+ .Add(x => x.Dimensions.Unit.ID)
|
|
|
+ .Add(x => x.Dimensions.Quantity)
|
|
|
+ .Add(x => x.Dimensions.Length)
|
|
|
+ .Add(x => x.Dimensions.Width)
|
|
|
+ .Add(x => x.Dimensions.Height)
|
|
|
+ .Add(x => x.Dimensions.Weight)
|
|
|
+ .Add(x => x.Dimensions.UnitSize)
|
|
|
+ .Add(x => x.Supplier.ID)
|
|
|
+ .Add(x => x.PurchaseOrderItem.ID));
|
|
|
+
|
|
|
+ var requisition = new JobRequisition
|
|
|
+ {
|
|
|
+ Description = $"Adjustment Requisition for {oldRequi.Description}",
|
|
|
+ DueDate = oldRequi.DueDate
|
|
|
+ };
|
|
|
+ requisition.Job.ID = Requisition.Job.ID;
|
|
|
+ requisition.Job.Synchronise(Requisition.Job);
|
|
|
+
|
|
|
+ var requiItems = new List<JobRequisitionItem>();
|
|
|
+ foreach(var oldItem in oldRequiItems.ToObjects<JobRequisitionItem>())
|
|
|
+ {
|
|
|
+ var newItem = new JobRequisitionItem
|
|
|
+ {
|
|
|
+ Notes = "Adjustment Requisition item",
|
|
|
+ Qty = -oldItem.Qty,
|
|
|
+ Sequence = oldItem.Sequence
|
|
|
+ };
|
|
|
+ newItem.Job.ID = requisition.Job.ID;
|
|
|
+ newItem.Job.Synchronise(requisition.Job);
|
|
|
+ newItem.Product.ID = oldItem.Product.ID;
|
|
|
+ newItem.Product.Synchronise(oldItem.Product);
|
|
|
+ newItem.Style.ID = oldItem.Style.ID;
|
|
|
+ newItem.Style.Synchronise(oldItem.Style);
|
|
|
+ newItem.Dimensions.CopyFrom(oldItem.Dimensions);
|
|
|
+ newItem.Supplier.ID = oldItem.Supplier.ID;
|
|
|
+ newItem.Supplier.Synchronise(oldItem.Supplier);
|
|
|
+ newItem.PurchaseOrderItem.ID = oldItem.PurchaseOrderItem.ID;
|
|
|
+ newItem.PurchaseOrderItem.Synchronise(oldItem.PurchaseOrderItem);
|
|
|
+ requiItems.Add(newItem);
|
|
|
+ }
|
|
|
+
|
|
|
+ var grid = DynamicGridUtils.CreateDynamicGrid(typeof(DynamicGrid<>), typeof(JobRequisition));
|
|
|
+ if (grid.EditItems(new JobRequisition[] { requisition }, t =>
|
|
|
+ {
|
|
|
+ if (t == typeof(JobRequisitionItem))
|
|
|
+ {
|
|
|
+ var table = new CoreTable();
|
|
|
+ table.LoadColumns(typeof(JobRequisitionItem));
|
|
|
+ table.LoadRows(requiItems);
|
|
|
+ return table;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }))
|
|
|
+ {
|
|
|
+ MessageBox.Show($"Created requisition {requisition.Number}");
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
protected override void DoReconfigure(FluentList<DynamicGridOption> options)
|
|
|
{
|
|
|
base.DoReconfigure(options);
|