123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Linq.Expressions;
- using InABox.Core;
- namespace Comal.Classes
- {
-
- public class StockLocationHoldings : CoreAggregate<StockLocation, StockHolding, Guid>
- {
- public override Expression<Func<StockHolding, Guid>> Aggregate => x => x.Product.ID;
-
- public override Dictionary<Expression<Func<StockHolding, object>>, Expression<Func<StockLocation, object>>> Links =>
- new Dictionary<Expression<Func<StockHolding, object>>, Expression<Func<StockLocation, object>>>()
- {
- { StockHolding => StockHolding.Location.ID, StockLocation => StockLocation.ID },
- };
-
- public override AggregateCalculation Calculation => AggregateCalculation.Count;
- }
- public enum StockTakeStatus
- {
- Inactive,
- InProgress
- }
- public enum StockTakeFrequency
- {
- Never,
- Daily,
- Weekly,
- Fortnightly,
- Monthly,
- Quarterly,
- TwiceYearly,
- Yearly
- }
-
- [UserTracking(typeof(StockMovement))]
- public class StockLocation : Entity, IRemotable, IPersistent, IStockLocation, ILicense<WarehouseLicense>, IExportable, IImportable
- {
-
-
- [UniqueCodeEditor(Visible = Visible.Default, Editable = Editable.Enabled)]
- [EditorSequence(1)]
- public string Code { get; set; }
- [TextBoxEditor]
- [EditorSequence(2)]
- public string Description { get; set; }
-
- [EntityRelationship(DeleteAction.SetNull)]
- [EditorSequence(3)]
- public StockWarehouseLink Warehouse { get; set; }
- private class StockAreaLookup : LookupDefinitionGenerator<StockArea, StockLocation>
- {
- public override Filter<StockArea> DefineFilter(StockLocation[] items)
- {
- var ids = items.Select(x => x.Warehouse.ID).Distinct().ToArray();
- if (ids.Length == 1)
- return new Filter<StockArea>(x => x.Warehouse.ID).IsEqualTo(ids[0]).And(x => x.Active).IsEqualTo(true);
- return new Filter<StockArea>(x => x.ID).IsEqualTo(CoreUtils.FullGuid);
- }
- public override Columns<StockLocation> DefineFilterColumns()
- => new Columns<StockLocation>(x => x.Warehouse.ID);
- }
- [LookupDefinition(typeof(StockAreaLookup))]
- [EntityRelationship(DeleteAction.SetNull)]
- [EditorSequence(4)]
- public StockAreaLink Area { get; set; }
-
-
- [EditorSequence(5)]
- public JobLink Job { get; set; }
- /// <summary>
- /// Is the location a "shelf" (ie permanent) or "pack" (ie transient)
- /// </summary>
- [EnumLookupEditor(typeof(StockLocationType))]
- [EditorSequence(6)]
- public StockLocationType Type { get; set; }
-
- /// <summary>
- /// Is the Stock Location Active?
- /// </summary>
- [EditorSequence(7)]
- public bool Active { get; set; }
- /// <summary>
- /// Mark this location as the default receival location for the warehouse
- /// </summary>
- [EditorSequence(8)]
- public bool Default { get; set; }
- /// <summary>
- /// Mark this location as a favourite which shows up in Timebench Transfer module for quick selection
- /// </summary>
- [EditorSequence(9)]
- public bool Favourite { get; set; } = false;
-
- [Aggregate(typeof(StockLocationHoldings))]
- [DoubleEditor(Editable = Editable.Hidden)]
- [EditorSequence(10)]
- public double Holdings { get; set; }
- [EnumLookupEditor(typeof(StockTakeStatus))]
- [EditorSequence(11)]
- public StockTakeStatus StocktakeStatus { get; set; } = StockTakeStatus.Inactive;
- [DateEditor]
- [EditorSequence(12)]
- public DateTime LastStocktake { get; set; } = DateTime.MinValue;
- [EnumLookupEditor(typeof(StockTakeFrequency))]
- [EditorSequence(13)]
- public StockTakeFrequency StocktakeFrequency { get; set; } = StockTakeFrequency.Never;
-
- [DateEditor(Editable = Editable.Disabled)]
- [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));
- }
- }
- }
|