|
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Windows;
|
|
|
using System.Windows.Controls;
|
|
|
+using com.sun.tools.@internal.ws.processor.util;
|
|
|
using Comal.Classes;
|
|
|
using InABox.Clients;
|
|
|
using InABox.Core;
|
|
@@ -226,7 +227,7 @@ public class StockHoldingGrid : DynamicDataGrid<StockHolding>
|
|
|
{
|
|
|
base.DoReconfigure(options);
|
|
|
options.AddRows = false;
|
|
|
- options.EditRows = false;
|
|
|
+ options.EditRows = Security.CanEdit<StockHolding>();
|
|
|
options.DeleteRows = false;
|
|
|
options.RecordCount = true;
|
|
|
options.SelectColumns = true;
|
|
@@ -255,8 +256,8 @@ public class StockHoldingGrid : DynamicDataGrid<StockHolding>
|
|
|
|
|
|
column.AddItem("Relocate Items", null, r =>
|
|
|
{
|
|
|
- var requiitems = holding.LoadRequisitionItems(true).ToList();
|
|
|
- RelocateItems(holding, requiitems.ToArray());
|
|
|
+ var requiitems = holding.LoadRequisitionItems(true).ToArray();
|
|
|
+ RelocateItems(holding, requiitems);
|
|
|
});
|
|
|
|
|
|
if (holding.Dimensions.Unit.HasDimensions() && holding.Available.IsEffectivelyGreaterThan(0.0))
|
|
@@ -331,22 +332,19 @@ public class StockHoldingGrid : DynamicDataGrid<StockHolding>
|
|
|
Refresh(false, true);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- private class StockIssue : BaseObject
|
|
|
- {
|
|
|
- [EditorSequence(0)]
|
|
|
- public DateTime Date { get; set; } = DateTime.Now;
|
|
|
-
|
|
|
- [EditorSequence(1)]
|
|
|
- public JobLink Job { get; set; }
|
|
|
-
|
|
|
- [EditorSequence(2)]
|
|
|
- public double Qty { get; set; }
|
|
|
- }
|
|
|
|
|
|
private void RelocateItems(StockHolding holding, JobRequisitionItem[] requiitems)
|
|
|
{
|
|
|
- var win = new StockHoldingRelocationWindow(holding, requiitems);
|
|
|
+ var win = new StockHoldingRelocationWindow(holding, requiitems)
|
|
|
+ {
|
|
|
+ IsJobEditable = true,
|
|
|
+ Job = new Job
|
|
|
+ {
|
|
|
+ ID = holding.Job.ID,
|
|
|
+ JobNumber = holding.Job.JobNumber
|
|
|
+ },
|
|
|
+ ShowFrom = false
|
|
|
+ };
|
|
|
if (win.ShowDialog() == true)
|
|
|
{
|
|
|
var quantities = win.GetQuantities();
|
|
@@ -357,12 +355,7 @@ public class StockHoldingGrid : DynamicDataGrid<StockHolding>
|
|
|
{
|
|
|
if (!quantities.TryGetValue(requiitem.ID, out var qty)) continue;
|
|
|
|
|
|
- var mout = new StockMovement();
|
|
|
- mout.Location.ID = holding.Location.ID;
|
|
|
- mout.Product.ID = holding.Product.ID;
|
|
|
- mout.Style.ID = holding.Style.ID;
|
|
|
- mout.Dimensions.CopyFrom(holding.Dimensions);
|
|
|
- mout.Job.ID = holding.Job.ID;
|
|
|
+ var mout = holding.CreateMovement();
|
|
|
mout.Issued = Math.Min(requiitem.Qty, qty);
|
|
|
mout.Cost = holding.AverageValue;
|
|
|
mout.JobRequisitionItem.ID = requiitem.ID;
|
|
@@ -371,13 +364,12 @@ public class StockHoldingGrid : DynamicDataGrid<StockHolding>
|
|
|
mout.Employee.ID = App.EmployeeID;
|
|
|
mout.Notes = $"Moved to {target.Code} by {App.EmployeeName}";
|
|
|
updates.Add(mout);
|
|
|
-
|
|
|
- var min = new StockMovement();
|
|
|
+
|
|
|
+ var min = holding.CreateMovement();
|
|
|
+ min.Location.Clear();
|
|
|
min.Location.ID = target.ID;
|
|
|
- min.Product.ID = holding.Product.ID;
|
|
|
- min.Style.ID = holding.Style.ID;
|
|
|
- min.Dimensions.CopyFrom(holding.Dimensions);
|
|
|
- min.Job.ID = holding.Job.ID;
|
|
|
+ min.Job.CopyFrom(win.Job ?? new());
|
|
|
+
|
|
|
min.Received = mout.Issued;
|
|
|
min.Cost = holding.AverageValue;
|
|
|
min.JobRequisitionItem.ID = requiitem.ID;
|
|
@@ -479,38 +471,38 @@ public class StockHoldingGrid : DynamicDataGrid<StockHolding>
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- private IEnumerable<StockMovement> CreateIssue(StockHolding holding, StockIssue issueObj, Guid requiID)
|
|
|
+ private IEnumerable<StockMovement> CreateIssue(StockHolding holding, IJob? job, double qty, IJobRequisitionItem requi)
|
|
|
{
|
|
|
var issue = CreateMovementFromHolding(holding);
|
|
|
- issue.Job.ID = issueObj.Job.ID;
|
|
|
+ issue.Job.ID = job?.ID ?? Guid.Empty;
|
|
|
issue.Type = StockMovementType.Issue;
|
|
|
- issue.JobRequisitionItem.ID = requiID;
|
|
|
- issue.Issued = issueObj.Qty;
|
|
|
+ issue.JobRequisitionItem.ID = requi.ID;
|
|
|
+ issue.Issued = qty;
|
|
|
issue.Notes = $"Issued by {App.EmployeeName}";
|
|
|
- issue.Date = issueObj.Date;
|
|
|
+ issue.Date = DateTime.Now;
|
|
|
yield return issue;
|
|
|
|
|
|
if (holding.Job.ID != issue.Job.ID)
|
|
|
{
|
|
|
var xferout = CreateMovementFromHolding(holding);
|
|
|
xferout.Type = StockMovementType.TransferOut;
|
|
|
- xferout.JobRequisitionItem.ID = requiID;
|
|
|
- xferout.Issued = issueObj.Qty;
|
|
|
+ xferout.JobRequisitionItem.ID = requi.ID;
|
|
|
+ xferout.Issued = qty;
|
|
|
xferout.Transaction = issue.Transaction;
|
|
|
xferout.System = true;
|
|
|
xferout.Notes = $"Issued by {App.EmployeeName}";
|
|
|
- xferout.Date = issueObj.Date;
|
|
|
+ xferout.Date = issue.Date;
|
|
|
yield return xferout;
|
|
|
|
|
|
var xferin = CreateMovementFromHolding(holding);
|
|
|
xferin.Job.ID = issue.Job.ID;
|
|
|
xferin.Type = StockMovementType.TransferIn;
|
|
|
- xferin.JobRequisitionItem.ID = requiID;
|
|
|
- xferin.Received = issueObj.Qty;
|
|
|
+ xferin.JobRequisitionItem.ID = requi.ID;
|
|
|
+ xferin.Received = qty;
|
|
|
xferin.Transaction = issue.Transaction;
|
|
|
xferin.System = true;
|
|
|
xferin.Notes = $"Issued by {App.EmployeeName}";
|
|
|
- xferin.Date = issueObj.Date;
|
|
|
+ xferin.Date = issue.Date;
|
|
|
yield return xferin;
|
|
|
}
|
|
|
}
|
|
@@ -519,51 +511,30 @@ public class StockHoldingGrid : DynamicDataGrid<StockHolding>
|
|
|
{
|
|
|
var updates = new List<StockMovement>();
|
|
|
|
|
|
- if(requiitems.Length > 1 || requiitems.Any(x => x.ID != Guid.Empty))
|
|
|
+ var win = new StockHoldingRelocationWindow(holding, requiitems)
|
|
|
{
|
|
|
- var win = new StockHoldingRelocationWindow(holding, requiitems)
|
|
|
- {
|
|
|
- IsTargetEditable = false,
|
|
|
- IsJobEditable = true,
|
|
|
- Job = new Job
|
|
|
- {
|
|
|
- ID = holding.Job.ID,
|
|
|
- JobNumber = holding.Job.JobNumber
|
|
|
- },
|
|
|
- Title = "Issue Items"
|
|
|
- };
|
|
|
- if (win.ShowDialog() == true)
|
|
|
+ IsTargetEditable = false,
|
|
|
+ IsJobEditable = true,
|
|
|
+ Job = new Job
|
|
|
{
|
|
|
- var quantities = win.GetQuantities();
|
|
|
- var target = win.GetTargetLocation();
|
|
|
-
|
|
|
- foreach(var requi in requiitems)
|
|
|
- {
|
|
|
- if (!quantities.TryGetValue(requi.ID, out var qty) || qty <= 0) continue;
|
|
|
-
|
|
|
- var issue = new StockIssue();
|
|
|
- issue.Job.ID = win.Job.ID;
|
|
|
- issue.Qty = qty;
|
|
|
-
|
|
|
- updates.AddRange(CreateIssue(holding, issue, requi.ID));
|
|
|
- }
|
|
|
- SaveBatch(StockMovementBatchType.Issue, updates);
|
|
|
- DoChanged();
|
|
|
- Refresh(false,true);
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
+ ID = holding.Job.ID,
|
|
|
+ JobNumber = holding.Job.JobNumber
|
|
|
+ },
|
|
|
+ Title = "Issue Items"
|
|
|
+ };
|
|
|
+ if (win.ShowDialog() == true)
|
|
|
{
|
|
|
- var sjs = new StockIssue();
|
|
|
- sjs.Job.ID = holding.Job.ID;
|
|
|
- sjs.Qty = requiitems[0].Qty;
|
|
|
+ var quantities = win.GetQuantities();
|
|
|
|
|
|
- if (DynamicGridUtils.EditObject(sjs))
|
|
|
+ foreach(var requi in requiitems)
|
|
|
{
|
|
|
- var mvts = CreateIssue(holding, sjs, Guid.Empty);
|
|
|
- SaveBatch(StockMovementBatchType.Issue, mvts.ToArray());
|
|
|
- Refresh(false, true);
|
|
|
+ if (!quantities.TryGetValue(requi.ID, out var qty) || qty <= 0) continue;
|
|
|
+
|
|
|
+ updates.AddRange(CreateIssue(holding, win.Job, qty, requi));
|
|
|
}
|
|
|
+ SaveBatch(StockMovementBatchType.Issue, updates);
|
|
|
+ DoChanged();
|
|
|
+ Refresh(false,true);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -575,20 +546,22 @@ public class StockHoldingGrid : DynamicDataGrid<StockHolding>
|
|
|
var holding = rows.First().ToObject<StockHolding>();
|
|
|
var items = holding.LoadRequisitionItems(true).AsArray();
|
|
|
|
|
|
- DoTransfer(holding, items);
|
|
|
+ RelocateItems(holding, items);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- private void DoTransfer(StockHolding holding, JobRequisitionItem[] requiitems)
|
|
|
+ protected override void DoEdit()
|
|
|
{
|
|
|
- if (requiitems.Length > 1 || requiitems[0].Requisition.ID != Guid.Empty)
|
|
|
+ var holding = SelectedRows.FirstOrDefault()?.ToObject<StockHolding>();
|
|
|
+ if (holding is null) return;
|
|
|
+
|
|
|
+ var requiitems = holding.LoadRequisitionItems(true).AsArray();
|
|
|
+ if(requiitems.Length > 1)
|
|
|
{
|
|
|
- RelocateItems(holding, requiitems);
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
var movement = CreateMovementFromHolding(holding);
|
|
|
- movement.JobRequisitionItem.ID = requiitems[0].ID;
|
|
|
movement.Received = holding.Available;
|
|
|
movement.Type = StockMovementType.TransferIn;
|
|
|
|
|
@@ -606,7 +579,6 @@ public class StockHoldingGrid : DynamicDataGrid<StockHolding>
|
|
|
other.Issued = movement.Received;
|
|
|
other.Transaction = movement.Transaction;
|
|
|
other.Type = StockMovementType.TransferOut;
|
|
|
- other.JobRequisitionItem.ID = requiitems[0].ID;
|
|
|
|
|
|
var changes = new List<string>();
|
|
|
if (movement.Location.ID != other.Location.ID)
|