StockMovementBatchStore.cs 993 B

12345678910111213141516171819202122232425262728293031
  1. using Comal.Classes;
  2. using Comal.Stores;
  3. using InABox.Core;
  4. using System.Collections.Generic;
  5. using System.Text;
  6. using System;
  7. namespace PRSStores;
  8. public class StockMovementBatchStore : BaseStore<StockMovementBatch>
  9. {
  10. protected override void BeforeDelete(StockMovementBatch entity)
  11. {
  12. base.BeforeDelete(entity);
  13. UpdateStockHoldings(entity);
  14. }
  15. private void UpdateStockHoldings(StockMovementBatch entity)
  16. {
  17. var movements = Provider.Query(
  18. new Filter<StockMovement>(x => x.Batch.ID).IsEqualTo(entity.ID),
  19. Columns.None<StockMovement>().Add(x => x.ID));
  20. foreach(var row in movements.Rows)
  21. {
  22. // We need to do this in before delete, because aotherwise we wont have the data
  23. // that we need to pull to properly update the stockholdings
  24. StockHoldingStore.UpdateStockHolding(this, row.Get<StockMovement, Guid>(x => x.ID), StockHoldingStore.Action.Decrease);
  25. }
  26. }
  27. }