Product.cs 7.7 KB

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