Product.cs 8.3 KB

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