StockLocation.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Linq.Expressions;
  5. using InABox.Core;
  6. namespace Comal.Classes
  7. {
  8. public class StockLocationHoldings : CoreAggregate<StockLocation, StockHolding, Guid>
  9. {
  10. public override Expression<Func<StockHolding, Guid>> Aggregate => x => x.Product.ID;
  11. public override Dictionary<Expression<Func<StockHolding, object>>, Expression<Func<StockLocation, object>>> Links =>
  12. new Dictionary<Expression<Func<StockHolding, object>>, Expression<Func<StockLocation, object>>>()
  13. {
  14. { StockHolding => StockHolding.Location.ID, StockLocation => StockLocation.ID },
  15. };
  16. public override AggregateCalculation Calculation => AggregateCalculation.Count;
  17. }
  18. public enum StockTakeStatus
  19. {
  20. None,
  21. InProgress
  22. }
  23. [UserTracking(typeof(StockMovement))]
  24. public class StockLocation : Entity, IRemotable, IPersistent, IStockLocation, ILicense<WarehouseLicense>, IExportable, IImportable
  25. {
  26. [UniqueCodeEditor(Visible = Visible.Default, Editable = Editable.Enabled)]
  27. [EditorSequence(1)]
  28. public string Code { get; set; }
  29. [TextBoxEditor]
  30. [EditorSequence(2)]
  31. public string Description { get; set; }
  32. [EntityRelationship(DeleteAction.SetNull)]
  33. [EditorSequence(3)]
  34. public StockWarehouseLink Warehouse { get; set; }
  35. private class StockAreaLookup : LookupDefinitionGenerator<StockArea, StockLocation>
  36. {
  37. public override Filter<StockArea> DefineFilter(StockLocation[] items)
  38. {
  39. var ids = items.Select(x => x.Warehouse.ID).Distinct().ToArray();
  40. if (ids.Length == 1)
  41. return new Filter<StockArea>(x => x.Warehouse.ID).IsEqualTo(ids[0]).And(x => x.Active).IsEqualTo(true);
  42. return new Filter<StockArea>(x => x.ID).IsEqualTo(CoreUtils.FullGuid);
  43. }
  44. public override Columns<StockLocation> DefineFilterColumns()
  45. => new Columns<StockLocation>(x => x.Warehouse.ID);
  46. }
  47. [LookupDefinition(typeof(StockAreaLookup))]
  48. [EntityRelationship(DeleteAction.SetNull)]
  49. [EditorSequence(4)]
  50. public StockAreaLink Area { get; set; }
  51. [EditorSequence(5)]
  52. public JobLink Job { get; set; }
  53. /// <summary>
  54. /// Is the location a "shelf" (ie permanent) or "pack" (ie transient)
  55. /// </summary>
  56. [EnumLookupEditor(typeof(StockLocationType))]
  57. [EditorSequence(6)]
  58. public StockLocationType Type { get; set; }
  59. /// <summary>
  60. /// Is the Stock Location Active?
  61. /// </summary>
  62. [EditorSequence(7)]
  63. public bool Active { get; set; }
  64. /// <summary>
  65. /// Mark this location as the default receival location for the warehouse
  66. /// </summary>
  67. [EditorSequence(8)]
  68. public bool Default { get; set; }
  69. /// <summary>
  70. /// Mark this location as a favourite which shows up in Timebench Transfer module for quick selection
  71. /// </summary>
  72. [EditorSequence(9)]
  73. public bool Favourite { get; set; } = false;
  74. [Aggregate(typeof(StockLocationHoldings))]
  75. [DoubleEditor(Editable = Editable.Hidden)]
  76. [EditorSequence(10)]
  77. public double Holdings { get; set; }
  78. [EnumLookupEditor(typeof(StockTakeStatus))]
  79. [EditorSequence(11)]
  80. public StockTakeStatus StocktakeStatus { get; set; }
  81. [DateEditor]
  82. [EditorSequence(12)]
  83. public DateTime LastStocktake { get; set; }
  84. }
  85. }