Product.cs 8.1 KB

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