Product.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. using System;
  2. using InABox.Core;
  3. using PRSClasses;
  4. namespace Comal.Classes
  5. {
  6. [UserTracking("Product Management")]
  7. public class Product : Entity, 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 ProductDimensionUnitLink UnitOfMeasure { get; set; }
  17. [EditorSequence(3)]
  18. [RequiredColumn]
  19. public ProductInstanceLink DefaultInstance { get; set; }
  20. [NullEditor]
  21. [Obsolete("Replaced with Dimensions", true)]
  22. // [DoubleEditor]
  23. // [EditorSequence(4)]
  24. public double UnitSize { get; set; }
  25. [NullEditor]
  26. [Obsolete("Replaced with Dimensions", false)]
  27. // [EditorSequence(5)]
  28. public ProductUOMLink Units { get; set; }
  29. [NullEditor]
  30. [Obsolete("Replaced with Dimensions", true)]
  31. // [DoubleEditor]
  32. // [EditorSequence(6)]
  33. // [Caption("Standard Weight")]
  34. public double Weight { get; set; }
  35. [EditorSequence(7)]
  36. public ProductGroupLink Group { get; set; }
  37. [EditorSequence(8)]
  38. [DataModelTableName("Image")]
  39. public ImageDocumentLink Image { get; set; }
  40. [URLEditor]
  41. [EditorSequence(9)]
  42. public string URL { get; set; }
  43. [TimestampEditor]
  44. [EditorSequence(10)]
  45. public DateTime Expired { get; set; }
  46. [EnumLookupEditor(typeof(ProductPricingStrategy))]
  47. [EditorSequence("Pricing", 1)]
  48. public ProductPricingStrategy PricingStrategy { get; set; } = ProductPricingStrategy.Standard;
  49. [EditorSequence("Pricing", 2)]
  50. public SupplierProductLink Supplier { get; set; }
  51. [CheckBoxEditor]
  52. [EditorSequence("Pricing", 3)]
  53. public bool UseDefaultSupplierPricing { get; set; } = true;
  54. [CurrencyEditor(Visible = Visible.Optional)]
  55. [EditorSequence("Pricing", 4)]
  56. public double BaseCost { get; set; }
  57. [Aggregate(typeof(ProductComponentCost))]
  58. [CurrencyEditor(Visible = Visible.Optional)] //, Editable = Editable.Disabled)]
  59. [EditorSequence("Pricing", 5)]
  60. public double ComponentCost { get; set; }
  61. [CurrencyEditor(Visible = Visible.Optional, Editable = Editable.Disabled)]
  62. [EditorSequence("Pricing", 6)]
  63. public double NettCost { get; set; }
  64. [Obsolete("Replaced with ProductInstance.AverageCost", true)]
  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. /// <summary>
  100. /// (Optional) The Location to be used when Purchase Orders / Consignments are received.
  101. /// If blank, the item will be received into the default location for the Warehouse assign to the product
  102. /// If that is also blank, then no stock movement will be recorded when receiving the item
  103. /// </summary>
  104. [EditorSequence("Warehousing", 4)]
  105. public StockLocationLink DefaultLocation { get; set; }
  106. [Caption("Incoming QA")]
  107. [EditorSequence("Warehousing", 5)]
  108. public DigitalFormLink DigitalForm { get; set; }
  109. [Caption("Mfg Treatment?")]
  110. [EditorSequence("Warehousing", 6)]
  111. public bool IsManufacturingTreatment { get; set; }
  112. [NullEditor]
  113. public string Barcodes { get; set; }
  114. [Aggregate(typeof(ProductUnitAggregate))]
  115. [DoubleEditor(Editable = Editable.Hidden)]
  116. public double UnitQty { get; set; }
  117. [Aggregate(typeof(ProductRemnantAggregate))]
  118. [DoubleEditor(Editable = Editable.Hidden)]
  119. public double RemnantQty { get; set; }
  120. [Aggregate(typeof(OnOrderAggregate))]
  121. [DoubleEditor(Editable = Editable.Hidden)]
  122. public double OnOrder { get; set; }
  123. [Aggregate(typeof(TotalStockAggregate))]
  124. [DoubleEditor(Editable = Editable.Hidden)]
  125. public double TotalStock { get; set; }
  126. [Formula(typeof(ReservedStockFormula))]
  127. [DoubleEditor(Editable = Editable.Hidden)]
  128. public double ReservedStock { get; set; }
  129. [Aggregate(typeof(FreeStockAggregate))]
  130. [DoubleEditor(Editable = Editable.Hidden)]
  131. public double FreeStock { get; set; }
  132. [Aggregate(typeof(TotalRequiredAggregate))]
  133. [DoubleEditor(Editable = Editable.Hidden)]
  134. public double Required { get; set; }
  135. [Aggregate(typeof(ProductReceivedAggregate))]
  136. [DateTimeEditor(Editable = Editable.Hidden)]
  137. public DateTime LastReceived { get; set; }
  138. [Aggregate(typeof(ProductIssuedAggregate))]
  139. [DateTimeEditor(Editable = Editable.Hidden)]
  140. public DateTime LastIssued { get; set; }
  141. [Obsolete("Replaced with DefaultInstance.Style")]
  142. [NullEditor]
  143. public ProductStyleLink DefaultStyle { get; set; }
  144. [Obsolete("Replaced with DefaultInstance.MinimumStockLevel")]
  145. [NullEditor]
  146. public int MinimumStockLevel { get; set; }
  147. [Obsolete("Replaced with DefaultInstance.Dimensions")]
  148. [NullEditor]
  149. public ProductDimensions Dimensions { get; set; }
  150. [NullEditor]
  151. public string Issues { get; set; }
  152. public override string ToString()
  153. {
  154. return string.Format("{0}: {1} ({2})", Code, Name, DefaultInstance.Dimensions.UnitSize);
  155. }
  156. public static double CalculateNettCost(ProductPricingStrategy strategy, double basecost, double componentcost)
  157. {
  158. if (strategy == ProductPricingStrategy.Kit)
  159. return basecost + componentcost;
  160. if (strategy == ProductPricingStrategy.Subcontractor)
  161. return basecost - componentcost;
  162. // Standard or Assembly
  163. return basecost;
  164. }
  165. }
  166. public class ProductFormLookups : ILookupDefinition<DigitalForm, Product>
  167. {
  168. public Filter<DigitalForm> DefineFilter(Product[] items)
  169. {
  170. // Get all FillableFormTypes where 2nd parameter is typeof(PurchaseOrder)
  171. return new Filter<DigitalForm>(x => x.Active).IsEqualTo(true).And(x => x.AppliesTo).IsEqualTo("PurchaseOrderItem");
  172. }
  173. Columns<Product> ILookupDefinition<DigitalForm, Product>.DefineFilterColumns()
  174. => new Columns<Product>();
  175. }
  176. }