Browse Source

Added StockTakeFrequency and NextStocktake properties

frogsoftware 1 năm trước cách đây
mục cha
commit
01a15d346a
1 tập tin đã thay đổi với 53 bổ sung4 xóa
  1. 53 4
      prs.classes/Entities/Stock/StockLocation/StockLocation.cs

+ 53 - 4
prs.classes/Entities/Stock/StockLocation/StockLocation.cs

@@ -25,6 +25,19 @@ namespace Comal.Classes
         None,
         InProgress
     }
+
+    public enum StockTakeFrequency
+    {
+        Daily,
+        Weekly,
+        Fortnightly,
+        Monthly,
+        Quarterly,
+        TwiceYearly,
+        Yearly,
+        Never
+    }
+    
     [UserTracking(typeof(StockMovement))]
     public class StockLocation : Entity, IRemotable, IPersistent, IStockLocation, ILicense<WarehouseLicense>, IExportable, IImportable
     {
@@ -96,11 +109,47 @@ namespace Comal.Classes
 
         [EnumLookupEditor(typeof(StockTakeStatus))]
         [EditorSequence(11)]
-        public StockTakeStatus StocktakeStatus { get; set; }
+        public StockTakeStatus StocktakeStatus { get; set; } = StockTakeStatus.None;
+
+        [DateEditor] 
+        [EditorSequence(12)] 
+        public DateTime LastStocktake { get; set; } = DateTime.MinValue;
+
+        [EnumLookupEditor(typeof(StockTakeFrequency))]
+        [EditorSequence(13)]
+        public StockTakeFrequency StocktakeFrequency { get; set; } = StockTakeFrequency.Never;
         
-        [DateEditor]
-        [EditorSequence(12)]
-        public DateTime LastStocktake { get; set; }
+        [DateEditor] 
+        [EditorSequence(12)] 
+        public DateTime NextStocktake { get; set; } = DateTime.MaxValue;
+
 
+        private static DateTime CalculateNextStockTake(DateTime last, StockTakeFrequency frequency)
+        {
+            if (frequency == StockTakeFrequency.Never)
+                return DateTime.MaxValue;
+            if (last.IsEmpty())
+                return DateTime.Today;
+            return frequency switch
+            {
+                StockTakeFrequency.Daily => last.AddDays(1),
+                StockTakeFrequency.Weekly => last.AddDays(7),
+                StockTakeFrequency.Fortnightly => last.AddDays(14),
+                StockTakeFrequency.Monthly => last.AddMonths(1),
+                StockTakeFrequency.Quarterly => last.AddMonths(3),
+                StockTakeFrequency.TwiceYearly => last.AddMonths(6),
+                StockTakeFrequency.Yearly => last.AddYears(1),
+                _ => DateTime.MaxValue
+            };
+        }
+
+        protected override void DoPropertyChanged(string name, object? before, object? after)
+        {
+            base.DoPropertyChanged(name, before, after);
+            if (String.Equals(name, nameof(LastStocktake)))
+                NextStocktake = CalculateNextStockTake((DateTime)(after ?? DateTime.MinValue), StocktakeFrequency);
+            else if (String.Equals(name, nameof(StocktakeFrequency)))
+                NextStocktake = CalculateNextStockTake(LastStocktake, (StockTakeFrequency)(after ?? StockTakeFrequency.Never));
+        }
     }
 }