|
@@ -19,20 +19,10 @@ namespace PRSDesktop;
|
|
|
|
|
|
public class FactoryPackGrid : DynamicDataGrid<StockHolding>
|
|
|
{
|
|
|
- public Guid AreaID { get; set; }
|
|
|
+ public StockArea? Area { get; set; }
|
|
|
|
|
|
public ManufacturingPacket? CurrentPacket { get; set; }
|
|
|
-
|
|
|
- public String AreaDescription
|
|
|
- {
|
|
|
- get => _holding.HeaderText;
|
|
|
- set
|
|
|
- {
|
|
|
- _holding.HeaderText = value;
|
|
|
- Refresh(true,false);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
private readonly Dictionary<Guid, byte[]> _images = new();
|
|
|
|
|
|
private readonly DynamicActionColumn _holding;
|
|
@@ -87,16 +77,21 @@ public class FactoryPackGrid : DynamicDataGrid<StockHolding>
|
|
|
{
|
|
|
Task<CoreTable> imagetask = Task.Run(() =>
|
|
|
{
|
|
|
+ if (Area == null)
|
|
|
+ return new Client<Document>().Query(new Filter<Document>().None());
|
|
|
+
|
|
|
return new Client<Document>().Query(
|
|
|
new Filter<Document>(x => x.ID)
|
|
|
- .InQuery(new Filter<StockHolding>(x => x.Location.Area.ID).IsEqualTo(AreaID),
|
|
|
+ .InQuery(new Filter<StockHolding>(x => x.Location.Area.ID).IsEqualTo(Area.ID),
|
|
|
x => x.Product.Image.ID),
|
|
|
new Columns<Document>(x => x.ID).Add(x => x.Data)
|
|
|
);
|
|
|
});
|
|
|
-
|
|
|
- criteria.Add(new Filter<StockHolding>(x => x.Location.Area.ID).IsEqualTo(AreaID));
|
|
|
-
|
|
|
+
|
|
|
+ criteria.Add(Area == null
|
|
|
+ ? new Filter<StockHolding>().None()
|
|
|
+ : new Filter<StockHolding>(x => x.Location.Area.ID).IsEqualTo(Area.ID));
|
|
|
+
|
|
|
base.Reload(criteria, columns, ref sort, (o,e) =>
|
|
|
{
|
|
|
if (o != null)
|
|
@@ -224,6 +219,27 @@ public class FactoryPackGrid : DynamicDataGrid<StockHolding>
|
|
|
|
|
|
return grid;
|
|
|
}
|
|
|
+
|
|
|
+ private class FactoryFloorReturn : BaseObject
|
|
|
+ {
|
|
|
+
|
|
|
+ [EditorSequence(1)]
|
|
|
+ public ProductLink Product { get; set; }
|
|
|
+
|
|
|
+ [EditorSequence(2)]
|
|
|
+ public ProductStyleLink Style { get; set; }
|
|
|
+
|
|
|
+ [EditorSequence(3)]
|
|
|
+ [DimensionsEditor(typeof(StockDimensions), AllowEditingUnit = false)]
|
|
|
+ public StockDimensions Dimensions { get; set;}
|
|
|
+
|
|
|
+ [EditorSequence(4)]
|
|
|
+ public double Qty { get; set; }
|
|
|
+
|
|
|
+ [EditorSequence(5)]
|
|
|
+ public JobLink Job { get; set; }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
private class FactoryFloorIssue : BaseObject
|
|
|
{
|
|
@@ -258,7 +274,114 @@ public class FactoryPackGrid : DynamicDataGrid<StockHolding>
|
|
|
[EditorSequence(2)]
|
|
|
public double Qty { get; set; }
|
|
|
}
|
|
|
+
|
|
|
+ public void ReplaceStock()
|
|
|
+ {
|
|
|
+ var holdingrow = SelectedRows.FirstOrDefault();
|
|
|
+ var receive = holdingrow == null
|
|
|
+ ? new StockMovement()
|
|
|
+ : holdingrow.ToObject<StockHolding>().CreateMovement();
|
|
|
+
|
|
|
+ receive.Type = StockMovementType.Receive;
|
|
|
+ receive.Date = DateTime.Now;
|
|
|
+ receive.Employee.ID = App.EmployeeID;
|
|
|
+ receive.Notes = "Returned from Manufacturing";
|
|
|
+ receive.Received = 1.0F;
|
|
|
+
|
|
|
+ var smg = new DynamicDataGrid<StockMovement>();
|
|
|
+ smg.OnCustomiseEditor += StockMovementCustomiseEditor;
|
|
|
+ smg.OnValidate += StockMovementValidate;
|
|
|
+ smg.OnEditorValueChanged += StockMovementValueChanged;
|
|
|
+ if (smg.EditItems(new StockMovement[] { receive }))
|
|
|
+ {
|
|
|
+ receive.Batch.ID = CheckStockMovementBatch();
|
|
|
+ new Client<StockMovement>().Save(receive,"Issued Stock to Factory Floor");
|
|
|
+ Refresh(false,true);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private Dictionary<string, object?> StockMovementValueChanged(IDynamicEditorForm form, string name, object value)
|
|
|
+ {
|
|
|
+ var result = new Dictionary<string, object?>();
|
|
|
+ if (name.Equals("Location.Job.ID"))
|
|
|
+ {
|
|
|
+ var editor = form.FindEditor("Job.ID");
|
|
|
+ if (!value.Equals(Guid.Empty))
|
|
|
+ result = DynamicGridUtils.UpdateEditorValue(form.Items, "Job.ID", value);
|
|
|
+ else
|
|
|
+ foreach (StockMovement item in form.Items)
|
|
|
+ result = DynamicGridUtils.UpdateEditorValue(new[] { item }, "Job.ID",
|
|
|
+ item.Job.HasOriginalValue("ID") ? item.Job.GetOriginalValue(x => x.ID) : item.Job.ID);
|
|
|
+ editor.IsEnabled = value.Equals(Guid.Empty);
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
+ private void StockMovementValidate(object sender, StockMovement[] items, List<string> errors)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (items.Any(x => x.Product.ID == Guid.Empty))
|
|
|
+ errors.Add("Product may not be blank");
|
|
|
+ if (items.Any(x => x.Location.ID == Guid.Empty))
|
|
|
+ errors.Add("Location may not be blank");
|
|
|
+ if (items.Any(x => x is { Received: 0, Issued: 0 }))
|
|
|
+ errors.Add("Quantity may not be zero");
|
|
|
+ }
|
|
|
+
|
|
|
+ private void StockMovementCustomiseEditor(IDynamicEditorForm sender, StockMovement[]? items, DynamicGridColumn column, BaseEditor editor)
|
|
|
+ {
|
|
|
+ if (column.ColumnName.Equals(CoreUtils.GetFullPropertyName<StockMovement,double>(x=>x.Cost,".")))
|
|
|
+ editor.Editable = Editable.Hidden;
|
|
|
+ else if (column.ColumnName.Equals(CoreUtils.GetFullPropertyName<StockMovement,DateTime>(x=>x.Date,".")))
|
|
|
+ editor.Editable = Editable.Hidden;
|
|
|
+ else if (column.ColumnName.Equals(CoreUtils.GetFullPropertyName<StockMovement,double>(x=>x.Issued,".")))
|
|
|
+ editor.Editable = Editable.Hidden;
|
|
|
+ else if (column.ColumnName.Equals(CoreUtils.GetFullPropertyName<StockMovement,Guid>(x=>x.Employee.ID,".")))
|
|
|
+ editor.Editable = Editable.Hidden;
|
|
|
+ else if (column.ColumnName.Equals(CoreUtils.GetFullPropertyName<StockMovement,String>(x=>x.Notes,".")))
|
|
|
+ editor.Editable = Editable.Hidden;
|
|
|
+ else if (column.ColumnName.Equals(CoreUtils.GetFullPropertyName<StockMovement,Guid>(x=>x.Location.ID,".")))
|
|
|
+ editor.EditorSequence = 1;
|
|
|
+ else if (column.ColumnName.Equals(CoreUtils.GetFullPropertyName<StockMovement,Guid>(x=>x.Product.ID,".")))
|
|
|
+ editor.EditorSequence = 2;
|
|
|
+ else if (column.ColumnName.Equals(CoreUtils.GetFullPropertyName<StockMovement,Guid>(x=>x.Style.ID,".")))
|
|
|
+ editor.EditorSequence = 3;
|
|
|
+ else if (column.ColumnName.Equals(CoreUtils.GetFullPropertyName<StockMovement,Guid>(x=>x.Job.ID,".")))
|
|
|
+ editor.EditorSequence = 4;
|
|
|
+ else if (column.ColumnName.Equals(CoreUtils.GetFullPropertyName<StockMovement,StockDimensions>(x=>x.Dimensions,".")))
|
|
|
+ editor.EditorSequence = 5;
|
|
|
+ else if (column.ColumnName.Equals(CoreUtils.GetFullPropertyName<StockMovement, double>(x => x.Received, ".")))
|
|
|
+ {
|
|
|
+ editor.EditorSequence = 6;
|
|
|
+ editor.Caption = "Quantity";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Guid CheckStockMovementBatch()
|
|
|
+ {
|
|
|
+ var _settings = new LocalConfiguration<FactoryFloorLocalSettings>().Load();
|
|
|
+ if (_settings.CurrentBatchDate != DateTime.Today)
|
|
|
+ {
|
|
|
+ StockMovementBatch batch = new StockMovementBatch
|
|
|
+ {
|
|
|
+ Type = StockMovementBatchType.Issue,
|
|
|
+ TimeStamp = DateTime.Now,
|
|
|
+ Notes = "Manufacturing Consumption"
|
|
|
+ };
|
|
|
+ batch.Employee.ID = App.EmployeeID;
|
|
|
+ new Client<StockMovementBatch>().Save(batch,"Created on Factory Floor Screen");
|
|
|
+ _settings.CurrentBatchDate = DateTime.Today;
|
|
|
+ _settings.CurrentBatchID = batch.ID;
|
|
|
+ new LocalConfiguration<FactoryFloorLocalSettings>().Save(_settings);
|
|
|
+ }
|
|
|
+
|
|
|
+ return _settings.CurrentBatchID;
|
|
|
+ }
|
|
|
+
|
|
|
private void UseStock(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
|
|
@@ -298,21 +421,7 @@ public class FactoryPackGrid : DynamicDataGrid<StockHolding>
|
|
|
if (!ffg.EditItems([ffi]))
|
|
|
return;
|
|
|
|
|
|
- var _settings = new LocalConfiguration<FactoryFloorLocalSettings>().Load();
|
|
|
- if (_settings.CurrentBatchDate != DateTime.Today)
|
|
|
- {
|
|
|
- StockMovementBatch batch = new StockMovementBatch
|
|
|
- {
|
|
|
- Type = StockMovementBatchType.Issue,
|
|
|
- TimeStamp = DateTime.Now,
|
|
|
- Notes = "Manufacturing Consumption"
|
|
|
- };
|
|
|
- batch.Employee.ID = App.EmployeeID;
|
|
|
- new Client<StockMovementBatch>().Save(batch,"Created on Factory Floor Screen");
|
|
|
- _settings.CurrentBatchDate = DateTime.Today;
|
|
|
- _settings.CurrentBatchID = batch.ID;
|
|
|
- new LocalConfiguration<FactoryFloorLocalSettings>().Save(_settings);
|
|
|
- }
|
|
|
+ var batchid = CheckStockMovementBatch();
|
|
|
|
|
|
List<StockMovement> updates = new();
|
|
|
Guid transactionid = Guid.NewGuid();
|
|
@@ -322,7 +431,7 @@ public class FactoryPackGrid : DynamicDataGrid<StockHolding>
|
|
|
|
|
|
var transferout = holding.CreateMovement();
|
|
|
transferout.JobRequisitionItem.ID = ffi.RequisitionID;
|
|
|
- transferout.Batch.ID = _settings.CurrentBatchID;
|
|
|
+ transferout.Batch.ID = batchid;
|
|
|
transferout.Type = StockMovementType.TransferOut;
|
|
|
transferout.Issued = ffi.Qty;
|
|
|
transferout.Transaction = transactionid;
|
|
@@ -333,7 +442,7 @@ public class FactoryPackGrid : DynamicDataGrid<StockHolding>
|
|
|
|
|
|
var transferin = holding.CreateMovement();
|
|
|
transferin.JobRequisitionItem.ID = ffi.RequisitionID;
|
|
|
- transferin.Batch.ID = _settings.CurrentBatchID;
|
|
|
+ transferin.Batch.ID = batchid;
|
|
|
transferin.Type = StockMovementType.TransferIn;
|
|
|
transferin.Received = ffi.Qty;
|
|
|
transferin.Job.ID = CurrentPacket.SetoutLink.JobLink.ID;
|
|
@@ -348,7 +457,7 @@ public class FactoryPackGrid : DynamicDataGrid<StockHolding>
|
|
|
|
|
|
var issue = holding.CreateMovement();
|
|
|
issue.JobRequisitionItem.ID = ffi.RequisitionID;
|
|
|
- issue.Batch.ID = _settings.CurrentBatchID;
|
|
|
+ issue.Batch.ID = batchid;
|
|
|
issue.Type = StockMovementType.Issue;
|
|
|
issue.Issued = ffi.Qty;
|
|
|
issue.Job.ID = CurrentPacket.SetoutLink.JobLink.ID;
|
|
@@ -362,7 +471,7 @@ public class FactoryPackGrid : DynamicDataGrid<StockHolding>
|
|
|
new Client<StockMovement>().Save(updates,"Issued Stock to Factory Floor", (_,_) => { });
|
|
|
if (issue.JobRequisitionItem.ID == Guid.Empty)
|
|
|
UpdateRow<StockHolding, double>(holdingrow, x=>x.Available, holding.Available - ffi.Qty,false);
|
|
|
- UpdateRow<StockHolding,double>(holdingrow, x => x.Units, holding.Units - ffi.Qty,true);
|
|
|
+ UpdateRow<StockHolding,double>(holdingrow, x => x.Units, holding.Units - ffi.Qty);
|
|
|
|
|
|
}
|
|
|
}
|