StockLocation.cs 3.5 KB

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