ProductLookups.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using System;
  2. using System.Collections.Generic;
  3. using InABox.Core;
  4. namespace Comal.Classes
  5. {
  6. public class ProductLookups : EntityLookup<Product>,
  7. ILookupDefinition<Product, StockMovement>,
  8. ILookupDefinition<Product, EmployeeProduct>,
  9. ILookupDefinition<Product, StagingManufacturingPacketTreatment>,
  10. ILookupDefinition<Product, ManufacturingTreatment>,
  11. ILookupDefinition<Product, BillLine>
  12. {
  13. // EmployeeProduct records also require a Default Location to pull from
  14. public Filter<Product> DefineFilter(EmployeeProduct[] items)
  15. {
  16. return DefineFilter().And(x => x.NonStock).IsEqualTo(false).And(x => x.DefaultLocation).LinkValid();
  17. }
  18. Columns<EmployeeProduct> ILookupDefinition<Product, EmployeeProduct>.DefineFilterColumns()
  19. => new Columns<EmployeeProduct>();
  20. // You should not be able to create a stock movement for a non-stock item
  21. public Filter<Product> DefineFilter(StockMovement[] items)
  22. {
  23. return DefineFilter().And(x => x.NonStock).IsEqualTo(false);
  24. }
  25. Columns<StockMovement> ILookupDefinition<Product, StockMovement>.DefineFilterColumns()
  26. => new Columns<StockMovement>();
  27. // Filters for Manufacturing Treament Codes
  28. public Filter<Product> DefineFilter(StagingManufacturingPacketTreatment[] items)
  29. {
  30. return DefineFilter().And(x => x.IsManufacturingTreatment).IsEqualTo(true);
  31. }
  32. Columns<StagingManufacturingPacketTreatment> ILookupDefinition<Product, StagingManufacturingPacketTreatment>.DefineFilterColumns()
  33. => new Columns<StagingManufacturingPacketTreatment>();
  34. // Filters for Manufacturing Treament Codes
  35. public Filter<Product> DefineFilter(ManufacturingTreatment[] items)
  36. {
  37. return DefineFilter().And(x => x.IsManufacturingTreatment).IsEqualTo(true);
  38. }
  39. Columns<ManufacturingTreatment> ILookupDefinition<Product, ManufacturingTreatment>.DefineFilterColumns()
  40. => new Columns<ManufacturingTreatment>();
  41. public override Columns<Product> DefineColumns()
  42. {
  43. return new Columns<Product>(
  44. x => x.ID,
  45. x => x.Code,
  46. x => x.Name,
  47. x => x.TaxCode.ID,
  48. x => x.PurchaseGL.ID,
  49. x => x.NettCost,
  50. x => x.Dimensions.Unit.ID,
  51. x => x.Dimensions.Unit.Code,
  52. x => x.Dimensions.Unit.Description,
  53. x => x.Dimensions.Unit.HasLength,
  54. x => x.Dimensions.Unit.HasHeight,
  55. x => x.Dimensions.Unit.HasQuantity,
  56. x => x.Dimensions.Unit.HasWeight,
  57. x => x.Dimensions.Unit.HasWidth,
  58. x => x.Dimensions.Unit.Formula,
  59. x => x.Dimensions.Unit.Format,
  60. x => x.Dimensions.Height,
  61. x => x.Dimensions.Length,
  62. x => x.Dimensions.Quantity,
  63. x => x.Dimensions.Weight,
  64. x => x.Dimensions.Width,
  65. x => x.Dimensions.Value,
  66. x => x.Dimensions.UnitSize
  67. );
  68. }
  69. public override string FormatLookup(Dictionary<string, object?> values, IEnumerable<string> exclude)
  70. {
  71. return $"{values["Name"]}";
  72. }
  73. public override Filter<Product> DefineFilter()
  74. {
  75. return new Filter<Product>(x => x.Expired).IsEqualTo(DateTime.MinValue);
  76. }
  77. public override SortOrder<Product> DefineSortOrder()
  78. {
  79. return new SortOrder<Product>(x => x.Code);
  80. }
  81. public Filter<Product> DefineFilter(BillLine[] items)
  82. {
  83. return new Filter<Product>(x => x.NonStock);
  84. }
  85. public Columns<BillLine> DefineFilterColumns()
  86. {
  87. return new Columns<BillLine>();
  88. }
  89. }
  90. }