فهرست منبع

Treatment PO does average cost correctly

Kenric Nugteren 1 سال پیش
والد
کامیت
4829926d91

+ 4 - 4
prs.classes/Entities/Job/Materials/IJobMaterial.cs

@@ -7,13 +7,13 @@ namespace Comal.Classes
     public interface IJobMaterial
     {
         
-        JobLink Job { get; set; }
+        JobLink Job { get; }
         
-        ProductLink Product { get; set; }
+        ProductLink Product { get; }
 
-        ProductStyleLink Style { get; set; }
+        ProductStyleLink Style { get; }
 
-        StockDimensions Dimensions { get; set; }   
+        StockDimensions Dimensions { get; }   
         
     }
     

+ 1 - 1
prs.classes/Entities/Stock/StockHolding/IStockHolding.cs

@@ -4,7 +4,7 @@ namespace Comal.Classes
 {
     public interface IStockHolding : IJobMaterial
     {
-        StockLocationLink Location { get; set; }
+        StockLocationLink Location { get; }
     }
     
     

+ 45 - 1
prs.classes/Entities/Stock/StockHolding/StockHolding.cs

@@ -6,10 +6,11 @@ using InABox.Clients;
 using InABox.Core;
 using PRSClasses;
 
+
 namespace Comal.Classes
 {
+    using HoldingDictionary = Dictionary<(Guid product, Guid style, Guid location, Guid job, StockDimensions dimensions), StockHolding>;
 
-    
     public class StockHoldingLastStocktake : CoreAggregate<StockHolding, StockMovement, DateTime>
     {
         public override Expression<Func<StockMovement, DateTime>> Aggregate => x => x.Date;
@@ -308,6 +309,49 @@ namespace Comal.Classes
 
             return _result;
         }
+
+        public static HoldingDictionary LoadStockHoldings(IEnumerable<IStockHolding> mvts, Columns<StockHolding> columns, HoldingDictionary? holdings = null, IQueryProvider<StockHolding>? query = null)
+        {
+            query ??= Client<StockHolding>.Provider;
+
+            columns.Add(x => x.ID);
+            columns.Add(x => x.Product.ID);
+            columns.Add(x => x.Location.ID);
+            columns.Add(x => x.Style.ID);
+            columns.Add(x => x.Job.ID);
+            columns.AddDimensionsColumns(x => x.Dimensions, Dimensions.ColumnsType.Local);
+
+            if(holdings != null)
+            {
+                mvts = mvts.Where(mvt =>
+                {
+                    var key = (mvt.Product.ID, mvt.Style.ID, mvt.Location.ID, mvt.Job.ID, mvt.Dimensions);
+                    return !holdings.ContainsKey(key);
+                }).ToArray();
+            }
+            else
+            {
+                holdings = new HoldingDictionary();
+            }
+
+            var productIDs = mvts.Select(x => x.Product.ID).Distinct().ToArray();
+            var locationIDs = mvts.Select(x => x.Location.ID).Distinct().ToArray();
+            var styleIDs = mvts.Select(x => x.Style.ID).Distinct().ToArray();
+            var jobIDs = mvts.Select(x => x.Job.ID).Distinct().ToArray();
+
+            var newHoldings = query.Query(new Filter<StockHolding>(x => x.Product.ID).InList(productIDs)
+                    .And(x => x.Location.ID).InList(locationIDs)
+                    .And(x => x.Style.ID).InList(styleIDs)
+                    .And(x => x.Job.ID).InList(jobIDs),
+                    columns
+                ).ToObjects<StockHolding>();
+            foreach(var holding in newHoldings)
+            {
+                holdings[(holding.Product.ID, holding.Style.ID, holding.Location.ID, holding.Job.ID, holding.Dimensions)] = holding;
+            }
+
+            return holdings;
+        }
         
     //     public static IEnumerable<Tuple<Guid,double>> GetAllocations(this StockHolding holding, bool alwaysshowunallocated)
     //     {

+ 9 - 1
prs.desktop/Panels/Reservation Management/ReservationManagementPanel.xaml.cs

@@ -475,8 +475,10 @@ public partial class ReservationManagementPanel : UserControl, IPanel<JobRequisi
                 .Rows.FirstOrDefault()?.Get<Supplier, Guid>(x => x.DefaultLocation.ID) ?? Guid.Empty;
             if (locationID != Guid.Empty)
             {
-                var movements = new List<StockMovement>();
+                var holdings = StockHoldingExtensions.LoadStockHoldings(ResultItems.Select(x => x.Item),
+                    Columns.None<StockHolding>().Add(x => x.AverageValue));
 
+                var movements = new List<StockMovement>();
                 foreach(var item in ResultItems)
                 {
                     var tOut = new StockMovement();
@@ -506,6 +508,12 @@ public partial class ReservationManagementPanel : UserControl, IPanel<JobRequisi
                     tIn.JobRequisitionItem.CopyFrom(item.Item.JRI);
                     tIn.Notes = "Stock movement for treatment purchase order created from Reservation Management";
 
+                    if(holdings.TryGetValue((tOut.Product.ID, tOut.Style.ID, tOut.Location.ID, tOut.Job.ID, tOut.Dimensions), out var holding))
+                    {
+                        tOut.Cost = holding.AverageValue;
+                        tIn.Cost = holding.AverageValue;
+                    }
+
                     movements.Add(tOut);
                     movements.Add(tIn);
                 }

+ 1 - 1
prs.desktop/Panels/Reservation Management/Treatment PO/ReservationManagementTreatmentOrderGrid.cs

@@ -25,7 +25,7 @@ using Columns = InABox.Core.Columns;
 
 namespace PRSDesktop.Panels.ReservationManagement.TreatmentPO;
 
-public class ReservationManagementTreatmentPOItem : BaseObject
+public class ReservationManagementTreatmentPOItem : BaseObject, IStockHolding
 {
     public delegate void ChangedHandler(int idx, double quantity);
 

+ 10 - 41
prs.stores/StockHoldingStore.cs

@@ -43,47 +43,16 @@ public class StockHoldingStore : BaseStore<StockHolding>
 
     public static HoldingDictionary LoadStockHoldings(IStore store, StockMovement[] mvts, HoldingDictionary? holdings = null)
     {
-        if(holdings is not null)
-        {
-            mvts = mvts.Where(mvt =>
-            {
-                var key = (mvt.Product.ID, mvt.Style.ID, mvt.Location.ID, mvt.Job.ID, mvt.Dimensions);
-                return !holdings.ContainsKey(key);
-            }).ToArray();
-        }
-        else
-        {
-            holdings = new();
-        }
-
-        var productIDs = mvts.Select(x => x.Product.ID).Distinct().ToArray();
-        var locationIDs = mvts.Select(x => x.Location.ID).Distinct().ToArray();
-        var styleIDs = mvts.Select(x => x.Style.ID).Distinct().ToArray();
-        var jobIDs = mvts.Select(x => x.Job.ID).Distinct().ToArray();
-
-        var newHoldings = store.Provider.Query(new Filter<StockHolding>(x => x.Product.ID).InList(productIDs)
-                .And(x => x.Location.ID).InList(locationIDs)
-                .And(x => x.Style.ID).InList(styleIDs)
-                .And(x => x.Job.ID).InList(jobIDs),
-                Columns.None<StockHolding>().Add(x => x.ID)
-                    .Add(x => x.Units)
-                    .Add(x => x.Qty)
-                    .Add(x => x.Value)
-                    .Add(x => x.Available)
-                    .Add(x => x.Weight)
-                    .Add(x => x.AverageValue)
-                    .Add(x => x.Product.ID)
-                    .Add(x => x.Location.ID)
-                    .Add(x => x.Style.ID)
-                    .Add(x => x.Job.ID)
-                    .AddDimensionsColumns(x => x.Dimensions, Dimensions.ColumnsType.Local)
-            ).ToObjects<StockHolding>();
-        foreach(var holding in newHoldings)
-        {
-            holdings[(holding.Product.ID, holding.Style.ID, holding.Location.ID, holding.Job.ID, holding.Dimensions)] = holding;
-        }
-
-        return holdings;
+        return StockHoldingExtensions.LoadStockHoldings(
+            mvts,
+            Columns.None<StockHolding>()
+                .Add(x => x.Units)
+                .Add(x => x.Qty)
+                .Add(x => x.Value)
+                .Add(x => x.Available)
+                .Add(x => x.Weight)
+                .Add(x => x.AverageValue),
+            holdings, store.Provider.QueryProvider<StockHolding>());
     }
 
     public static void ModifyHoldings(StockMovement[] mvts, HoldingDictionary holdings, Action action)