StockLocation.cs 3.8 KB

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