| 
					
				 | 
			
			
				@@ -0,0 +1,31 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+using Comal.Classes; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+using Comal.Stores; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+using InABox.Core; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+using System; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+using System.Collections.Generic; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+using System.Text; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+namespace PRSStores; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+public class StockMovementBatchStore : BaseStore<StockMovementBatch> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    protected override void BeforeDelete(StockMovementBatch entity) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        base.BeforeDelete(entity); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        UpdateStockHoldings(entity); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private void UpdateStockHoldings(StockMovementBatch entity) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        var movements = Provider.Query( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            new Filter<StockMovement>(x => x.Batch.ID).IsEqualTo(entity.ID), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            new Columns<StockMovement>(x => x.ID)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        foreach(var row in movements.Rows) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // We need to do this in before delete, because aotherwise we wont have the data 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // that we need to pull to properly update the stockholdings 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            StockHoldingStore.UpdateStockHolding(row.Get<StockMovement, Guid>(x => x.ID), StockHoldingStore.Action.Decrease); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 |