Product.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. using System;
  2. using InABox.Core;
  3. using PRSClasses;
  4. namespace Comal.Classes
  5. {
  6. [UserTracking("Product Management")]
  7. public class Product : DimensionedEntity<ProductDimensions>, IPersistent, IRemotable, IIssues, ILicense<ProductManagementLicense>, IExportable, IImportable, IMergeable
  8. {
  9. [UniqueCodeEditor(Visible = Visible.Default, Editable = Editable.Enabled)]
  10. [EditorSequence(1)]
  11. public string Code { get; set; }
  12. [TextBoxEditor]
  13. [EditorSequence(2)]
  14. public string Name { get; set; }
  15. [EditorSequence(3)]
  16. public ProductStyleLink DefaultStyle { get; set; }
  17. [NullEditor]
  18. [Obsolete("Replaced with Dimensions", true)]
  19. // [DoubleEditor]
  20. // [EditorSequence(4)]
  21. public double UnitSize { get; set; }
  22. [NullEditor]
  23. [Obsolete("Replaced with Dimensions", false)]
  24. // [EditorSequence(5)]
  25. public ProductUOMLink Units { get; set; }
  26. [NullEditor]
  27. [Obsolete("Replaced with Dimensions", true)]
  28. // [DoubleEditor]
  29. // [EditorSequence(6)]
  30. // [Caption("Standard Weight")]
  31. public double Weight { get; set; }
  32. [EditorSequence(4)]
  33. [RequiredColumn]
  34. [DimensionsEditor(typeof(ProductDimensions))]
  35. public override ProductDimensions Dimensions { get; set; }
  36. [EditorSequence(7)]
  37. public ProductGroupLink Group { get; set; }
  38. [EditorSequence(8)]
  39. [DataModelTableName("Image")]
  40. public ImageDocumentLink Image { get; set; }
  41. [URLEditor]
  42. [EditorSequence(9)]
  43. public string URL { get; set; }
  44. [TimestampEditor]
  45. [EditorSequence(10)]
  46. public DateTime Expired { get; set; }
  47. [EnumLookupEditor(typeof(ProductPricingStrategy))]
  48. [EditorSequence("Pricing", 1)]
  49. public ProductPricingStrategy PricingStrategy { get; set; } = ProductPricingStrategy.Standard;
  50. [EditorSequence("Pricing", 2)]
  51. public SupplierProductLink Supplier { get; set; }
  52. [CheckBoxEditor]
  53. [EditorSequence("Pricing", 3)]
  54. public bool UseDefaultSupplierPricing { get; set; } = true;
  55. [CurrencyEditor(Visible = Visible.Optional)]
  56. [EditorSequence("Pricing", 4)]
  57. public double BaseCost { get; set; }
  58. [Aggregate(typeof(ProductComponentCost))]
  59. [CurrencyEditor(Visible = Visible.Optional)] //, Editable = Editable.Disabled)]
  60. [EditorSequence("Pricing", 5)]
  61. public double ComponentCost { get; set; }
  62. [CurrencyEditor(Visible = Visible.Optional, Editable = Editable.Disabled)]
  63. [EditorSequence("Pricing", 6)]
  64. public double NettCost { get; set; }
  65. [CurrencyEditor(Visible = Visible.Optional)]
  66. [EditorSequence("Pricing", 7)]
  67. [LoggableProperty]
  68. public double AverageCost { get; set; }
  69. [EditorSequence("Pricing", 8)]
  70. [RequiredColumn]
  71. public TaxCodeLink TaxCode { get; set; }
  72. [EditorSequence("Pricing", 9)]
  73. [RequiredColumn]
  74. public PurchaseGLCodeLink PurchaseGL { get; set; }
  75. [EditorSequence("Pricing", 10)]
  76. [RequiredColumn]
  77. public SalesGLCodeLink SellGL { get; set; }
  78. [EditorSequence("Pricing", 11)]
  79. [RequiredColumn]
  80. public CostCentreLink CostCentre { get; set; }
  81. [EditorSequence("Pricing", 12)]
  82. public CostSheetSectionLink CostSheetSection { get; set; }
  83. [ProductChargeEditor]
  84. [EditorSequence("Pricing", 13)]
  85. public ProductCharge Charge { get; set; }
  86. /// <summary>
  87. /// Flag to indicate whether stock movements are to be tracked for this item
  88. /// If set, no stock movements will be recorded, even if the Warehouse and/or default location are set
  89. /// </summary>
  90. [CheckBoxEditor]
  91. [EditorSequence("Warehousing", 1)]
  92. public bool NonStock { get; set; } = false;
  93. /// <summary>
  94. /// The Warehouse that this item resides in. DefaultLocation Lookups are limited to this Warehouse only, although
  95. /// actual stock holdings can be anywhere (imperfect systems)
  96. /// </summary>
  97. [EditorSequence("Warehousing", 2)]
  98. public StockWarehouseLink Warehouse { get; set; }
  99. [IntegerEditor]
  100. [EditorSequence("Warehousing", 3)]
  101. public int MinimumStockLevel { get; set; }
  102. /// <summary>
  103. /// (Optional) The Location to be used when Purchase Orders / Consignments are received.
  104. /// If blank, the item will be received into the default location for the Warehouse assign to the product
  105. /// If that is also blank, then no stock movement will be recorded when receiving the item
  106. /// </summary>
  107. [EditorSequence("Warehousing", 4)]
  108. public StockLocationLink DefaultLocation { get; set; }
  109. [Caption("Incoming QA")]
  110. [EditorSequence("Warehousing", 5)]
  111. public DigitalFormLink DigitalForm { get; set; }
  112. [Caption("Mfg Treatment?")]
  113. [EditorSequence("Warehousing", 6)]
  114. public bool IsManufacturingTreatment { get; set; }
  115. [NullEditor]
  116. public string Barcodes { get; set; }
  117. [Aggregate(typeof(ProductUnitAggregate))]
  118. [DoubleEditor(Editable = Editable.Hidden)]
  119. public double UnitQty { get; set; }
  120. [Aggregate(typeof(ProductRemnantAggregate))]
  121. [DoubleEditor(Editable = Editable.Hidden)]
  122. public double RemnantQty { get; set; }
  123. [Aggregate(typeof(OnOrderAggregate))]
  124. [DoubleEditor(Editable = Editable.Hidden)]
  125. public double OnOrder { get; set; }
  126. [Aggregate(typeof(TotalStockAggregate))]
  127. [DoubleEditor(Editable = Editable.Hidden)]
  128. public double TotalStock { get; set; }
  129. [Formula(typeof(ReservedStockFormula))]
  130. [DoubleEditor(Editable = Editable.Hidden)]
  131. public double ReservedStock { get; set; }
  132. [Aggregate(typeof(FreeStockAggregate))]
  133. [DoubleEditor(Editable = Editable.Hidden)]
  134. public double FreeStock { get; set; }
  135. [Aggregate(typeof(TotalRequiredAggregate))]
  136. [DoubleEditor(Editable = Editable.Hidden)]
  137. public double Required { get; set; }
  138. [Aggregate(typeof(ProductReceivedAggregate))]
  139. [DateTimeEditor(Editable = Editable.Hidden)]
  140. public DateTime LastReceived { get; set; }
  141. [Aggregate(typeof(ProductIssuedAggregate))]
  142. [DateTimeEditor(Editable = Editable.Hidden)]
  143. public DateTime LastIssued { get; set; }
  144. [NullEditor]
  145. public string Issues { get; set; }
  146. public override string ToString()
  147. {
  148. return string.Format("{0}: {1} ({2})", Code, Name, Dimensions.UnitSize);
  149. }
  150. public static double CalculateNettCost(ProductPricingStrategy strategy, double basecost, double componentcost)
  151. {
  152. if (strategy == ProductPricingStrategy.Kit)
  153. return basecost + componentcost;
  154. if (strategy == ProductPricingStrategy.Subcontractor)
  155. return basecost - componentcost;
  156. // Standard or Assembly
  157. return basecost;
  158. }
  159. }
  160. public class ProductFormLookups : ILookupDefinition<DigitalForm, Product>
  161. {
  162. public Filter<DigitalForm> DefineFilter(Product[] items)
  163. {
  164. // Get all FillableFormTypes where 2nd parameter is typeof(PurchaseOrder)
  165. return new Filter<DigitalForm>(x => x.Active).IsEqualTo(true).And(x => x.AppliesTo).IsEqualTo("PurchaseOrderItem");
  166. }
  167. Columns<Product> ILookupDefinition<DigitalForm, Product>.DefineFilterColumns()
  168. => new Columns<Product>();
  169. }
  170. }