Forráskód Böngészése

Added a comment for the Balance field of stock movement.
Added utility functions for creating stock movements from holdings and grouping stock movements into holdings.

Kenric Nugteren 1 éve
szülő
commit
712fa4ed3c

+ 42 - 0
prs.classes/Entities/Stock/StockHolding.cs

@@ -306,6 +306,48 @@ namespace Comal.Classes
 
     public static class StockHoldingExtensions
     {
+        public static StockMovement CreateMovement(this IStockHolding holding)
+        {
+            var movement = new StockMovement();
+            movement.Job.ID = holding.Job.ID;
+            movement.Job.Synchronise(holding.Job);
+            movement.Product.ID = holding.Product.ID;
+            movement.Product.Synchronise(holding.Product);
+            movement.Style.ID = holding.Style.ID;
+            movement.Style.Synchronise(holding.Style);
+            movement.Location.ID = holding.Location.ID;
+            movement.Location.Synchronise(holding.Location);
+            movement.Dimensions.CopyFrom(holding.Dimensions);
+            return movement;
+        }
+
+        public static IEnumerable<StockHolding> GroupMovements(IEnumerable<StockMovement> movements)
+        {
+            var grouped = new List<StockHolding>();
+
+            var toGroup = movements.AsList();
+            while (toGroup.Count > 0)
+            {
+                var first = toGroup.First();
+                var selected = toGroup.Where(x => x.IsEqualTo(first)).ToList();
+
+                var holding = grouped.FirstOrDefault(x => x.IsEqualTo(first));
+                if (holding == null)
+                {
+                    holding = new StockHolding();
+                    holding.Location.ID = first.Location.ID;
+                    holding.Product.ID = first.Product.ID;
+                    holding.Style.ID = first.Style.ID;
+                    holding.Job.ID = first.Job.ID;
+                    holding.Dimensions.CopyFrom(first.Dimensions);
+                }
+                holding.Recalculate(selected);
+
+                toGroup.RemoveAll(x => selected.Any(s => s.ID == x.ID));
+            }
+            return grouped;
+        }
+
         public static bool IsEqualTo(this IStockHolding h1, IStockHolding h2)
         {
             return h1.Product.ID == h2.Product.ID

+ 5 - 0
prs.classes/Entities/Stock/StockMovement.cs

@@ -79,6 +79,7 @@ namespace Comal.Classes
     public class StockMovement : StockEntity, IRemotable, IPersistent, IOneToMany<StockLocation>, IOneToMany<Product>, 
         ILicense<WarehouseLicense>, IStockHolding, IJobMaterial, IExportable, IImportable, IPostable
     {
+
         [DateTimeEditor]
         [EditorSequence(0)]
         public DateTime Date { get; set; }
@@ -111,6 +112,10 @@ namespace Comal.Classes
         [DoubleEditor(Summary = Summary.Sum)]
         [EditorSequence(5)]
         public double Issued { get; set; }
+
+        /// <summary>
+        /// This indicates the balance of the holding at the current point in time for a stock movement, populated for stock takes.
+        /// </summary>
         [DoubleEditor(Editable = Editable.Hidden)]
         [EditorSequence(6)]
         public double Balance { get; set; }