Product.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. [DimensionsEditor(typeof(ProductDimensions))]
  34. public override ProductDimensions Dimensions { 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; }
  49. [EditorSequence("Pricing", 2)]
  50. public SupplierProductLink Supplier { get; set; }
  51. [CheckBoxEditor]
  52. [EditorSequence("Pricing", 3)]
  53. public bool UseDefaultSupplierPricing { get; set; }
  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. [CurrencyEditor(Visible = Visible.Optional, Editable = Editable.Disabled)]
  65. [EditorSequence("Pricing", 7)]
  66. [LoggableProperty]
  67. public double AverageCost { get; set; }
  68. [EditorSequence("Pricing", 8)]
  69. public TaxCodeLink TaxCode { get; set; }
  70. [EditorSequence("Pricing", 9)]
  71. public GLCodeLink PurchaseGL { get; set; }
  72. [EditorSequence("Pricing", 10)]
  73. public GLCodeLink SellGL { get; set; }
  74. [EditorSequence("Pricing", 11)]
  75. public CostCentreLink CostCentre { get; set; }
  76. [EditorSequence("Pricing", 12)]
  77. public CostSheetSectionLink CostSheetSection { get; set; }
  78. /// <summary>
  79. /// Flag to indicate whether stock movements are to be tracked for this item
  80. /// If set, no stock movements will be recorded, even if the Warehouse and/or default location are set
  81. /// </summary>
  82. [CheckBoxEditor]
  83. [EditorSequence("Warehousing", 1)]
  84. public bool NonStock { get; set; }
  85. /// <summary>
  86. /// The Warehouse that this item resides in. DefaultLocation Lookups are limited to this Warehouse only, although
  87. /// actual stock holdings can be anywhere (imperfect systems)
  88. /// </summary>
  89. [EditorSequence("Warehousing", 2)]
  90. public StockWarehouseLink Warehouse { get; set; }
  91. [IntegerEditor]
  92. [EditorSequence("Warehousing", 3)]
  93. public int MinimumStockLevel { get; set; }
  94. /// <summary>
  95. /// (Optional) The Location to be used when Purchase Orders / Consignments are received.
  96. /// If blank, the item will be received into the default location for the Warehouse assign to the product
  97. /// If that is also blank, then no stock movement will be recorded when receiving the item
  98. /// </summary>
  99. [EditorSequence("Warehousing", 4)]
  100. public StockLocationLink DefaultLocation { get; set; }
  101. [Caption("Incoming QA")]
  102. [EditorSequence("Warehousing", 5)]
  103. public DigitalFormLink DigitalForm { get; set; }
  104. [NullEditor]
  105. public string Barcodes { get; set; }
  106. [Aggregate(typeof(ProductUnitAggregate))]
  107. [DoubleEditor(Editable = Editable.Hidden)]
  108. public double UnitQty { get; set; }
  109. [Aggregate(typeof(ProductRemnantAggregate))]
  110. [DoubleEditor(Editable = Editable.Hidden)]
  111. public double RemnantQty { get; set; }
  112. [Aggregate(typeof(OnOrderAggregate))]
  113. [DoubleEditor(Editable = Editable.Hidden)]
  114. public double OnOrder { get; set; }
  115. [Aggregate(typeof(TotalStockAggregate))]
  116. [DoubleEditor(Editable = Editable.Hidden)]
  117. public double TotalStock { get; set; }
  118. [Formula(typeof(ReservedStockFormula))]
  119. [DoubleEditor(Editable = Editable.Hidden)]
  120. public double ReservedStock { get; set; }
  121. [Aggregate(typeof(FreeStockAggregate))]
  122. [DoubleEditor(Editable = Editable.Hidden)]
  123. public double FreeStock { get; set; }
  124. [Aggregate(typeof(TotalRequiredAggregate))]
  125. [DoubleEditor(Editable = Editable.Hidden)]
  126. public double Required { get; set; }
  127. [Aggregate(typeof(ProductReceivedAggregate))]
  128. [DateTimeEditor(Editable = Editable.Hidden)]
  129. public DateTime LastReceived { get; set; }
  130. [Aggregate(typeof(ProductIssuedAggregate))]
  131. [DateTimeEditor(Editable = Editable.Hidden)]
  132. public DateTime LastIssued { get; set; }
  133. [NullEditor]
  134. public string Issues { get; set; }
  135. public override string ToString()
  136. {
  137. return string.Format("{0}: {1} ({2})", Code, Name, Dimensions.UnitSize);
  138. }
  139. protected override void Init()
  140. {
  141. base.Init();
  142. Supplier = new SupplierProductLink();
  143. //UnitSize = 1.0F;
  144. Units = new ProductUOMLink();
  145. Group = new ProductGroupLink();
  146. CostCentre = new CostCentreLink();
  147. PurchaseGL = new GLCodeLink();
  148. SellGL = new GLCodeLink();
  149. CostSheetSection = new CostSheetSectionLink();
  150. PricingStrategy = ProductPricingStrategy.Standard;
  151. TaxCode = new TaxCodeLink(() => this);
  152. Image = new ImageDocumentLink();
  153. Warehouse = new StockWarehouseLink();
  154. DigitalForm = new DigitalFormLink();
  155. DefaultLocation = new StockLocationLink();
  156. DefaultStyle = new ProductStyleLink();
  157. NonStock = false;
  158. UseDefaultSupplierPricing = true;
  159. Dimensions = new ProductDimensions(() => this);
  160. }
  161. public static double CalculateNettCost(ProductPricingStrategy strategy, double basecost, double componentcost)
  162. {
  163. if (strategy == ProductPricingStrategy.Kit)
  164. return basecost + componentcost;
  165. if (strategy == ProductPricingStrategy.Subcontractor)
  166. return basecost - componentcost;
  167. // Standard or Assembly
  168. return basecost;
  169. }
  170. }
  171. public class ProductFormLookups : ILookupDefinition<DigitalForm, Product>
  172. {
  173. public Filter<DigitalForm> DefineFilter(Product[] items)
  174. {
  175. // Get all FillableFormTypes where 2nd parameter is typeof(PurchaseOrder)
  176. return new Filter<DigitalForm>(x => x.Active).IsEqualTo(true).And(x => x.AppliesTo).IsEqualTo("PurchaseOrderItem");
  177. }
  178. Columns<Product> ILookupDefinition<DigitalForm, Product>.DefineFilterColumns()
  179. => new Columns<Product>();
  180. }
  181. }