|
@@ -27,9 +27,7 @@ public class StockHoldingGrid : DynamicDataGrid<StockHolding>
|
|
|
}
|
|
|
private MovementAction _action;
|
|
|
private StockHolding? _holding;
|
|
|
-
|
|
|
|
|
|
-
|
|
|
private Button IssueButton;
|
|
|
|
|
|
private Button ReceiveButton;
|
|
@@ -42,6 +40,8 @@ public class StockHoldingGrid : DynamicDataGrid<StockHolding>
|
|
|
|
|
|
private Button RecalculateButton;
|
|
|
|
|
|
+ private Button AdjustValueButton;
|
|
|
+
|
|
|
public StockHoldingGrid() : base()
|
|
|
{
|
|
|
ColumnsTag = "StockHolding";
|
|
@@ -66,6 +66,10 @@ public class StockHoldingGrid : DynamicDataGrid<StockHolding>
|
|
|
TransferButton.Margin = new Thickness(20, TransferButton.Margin.Top, TransferButton.Margin.Right, TransferButton.Margin.Bottom);
|
|
|
TransferButton.IsEnabled = false;
|
|
|
|
|
|
+ AdjustValueButton = AddButton("Adjust Value", PRSDesktop.Resources.receipt.AsBitmapImage(), AdjustValues,
|
|
|
+ DynamicGridButtonPosition.Right);
|
|
|
+ AdjustValueButton.Margin = new Thickness(AdjustValueButton.Margin.Left, AdjustValueButton.Margin.Top, 10, AdjustValueButton.Margin.Bottom);
|
|
|
+
|
|
|
RecalculateButton = AddButton("Recalculate", PRSDesktop.Resources.service.AsBitmapImage(), RecalculateHoldings,
|
|
|
DynamicGridButtonPosition.Right);
|
|
|
|
|
@@ -101,6 +105,46 @@ public class StockHoldingGrid : DynamicDataGrid<StockHolding>
|
|
|
ActionColumns.Add(new DynamicMenuColumn(BuildMenu) { Position = DynamicActionColumnPosition.End });
|
|
|
}
|
|
|
|
|
|
+ private bool AdjustValues(Button arg1, CoreRow[] rows)
|
|
|
+ {
|
|
|
+ if (rows?.Any() != true)
|
|
|
+ return false;
|
|
|
+
|
|
|
+ double _newvalue = 0.0;
|
|
|
+ if (DoubleEdit.Execute("New Average Value", 0, double.MaxValue, ref _newvalue))
|
|
|
+ {
|
|
|
+ Progress.ShowModal("Creating Batch", progress =>
|
|
|
+ {
|
|
|
+ StockMovementBatch _batch = new StockMovementBatch()
|
|
|
+ {
|
|
|
+ Type = StockMovementBatchType.Transfer,
|
|
|
+ Employee = new EmployeeLink() { ID = App.EmployeeID },
|
|
|
+ Notes = "Stock Value Adjustment"
|
|
|
+ };
|
|
|
+ Client.Save(_batch,"Stock value adjusted from holding grid");
|
|
|
+
|
|
|
+ progress.Report("Creating Movements");
|
|
|
+ List<StockMovement> _updates = new List<StockMovement>();
|
|
|
+ foreach (var _row in rows)
|
|
|
+ {
|
|
|
+ var _holding = _row.ToObject<StockHolding>();
|
|
|
+ _holding.AverageValue = _newvalue;
|
|
|
+ _holding.Value = _newvalue * _holding.Units;
|
|
|
+ Client.Save(_holding,"Stock value adjusted from holding grid");
|
|
|
+ _updates.AddRange(_holding.AdjustValue(_newvalue, _batch));
|
|
|
+ }
|
|
|
+
|
|
|
+ progress.Report("Saving Movements");
|
|
|
+ Client.Save(_updates,"Stock value adjusted from holding grid");
|
|
|
+ });
|
|
|
+ MessageBox.Show("All Done");
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
private bool RecalculateHoldings(Button arg1, CoreRow[] arg2)
|
|
|
{
|
|
|
Dictionary<String, int> messages = new();
|
|
@@ -630,6 +674,12 @@ public class StockHoldingGrid : DynamicDataGrid<StockHolding>
|
|
|
ReceiveButton.IsEnabled = Location != null && Location.ID != Guid.Empty;
|
|
|
IssueButton.IsEnabled = Location != null && Location.ID != Guid.Empty && rows?.Any() == true;
|
|
|
TransferButton.IsEnabled = Location != null && Location.ID != Guid.Empty && rows?.Any() == true;
|
|
|
+ var _groups = rows?.GroupBy(x => new Tuple<Guid, double>(
|
|
|
+ x.Get<StockHolding, Guid>(c => c.Product.ID),
|
|
|
+ x.Get<StockHolding, double>(c => c.Dimensions.Value))
|
|
|
+ );
|
|
|
+ AdjustValueButton.IsEnabled = Location != null && Location.ID != Guid.Empty && _groups?.Count() == 1;
|
|
|
+ RecalculateButton.IsEnabled = Location != null && Location.ID != Guid.Empty;
|
|
|
}
|
|
|
|
|
|
private DynamicDataGrid<StockMovement> CheckStockMovementGrid(MovementAction action, StockHolding holding)
|