Product.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. [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; }
  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. [IntegerEditor]
  100. [EditorSequence("Warehousing", 3)]
  101. public int MinimumStockLevel { get; set; }
  102. /// <summary>
  103. /// (Optional) The Location to be used when Purchase Orders / Consignments are received.
  104. /// If blank, the item will be received into the default location for the Warehouse assign to the product
  105. /// If that is also blank, then no stock movement will be recorded when receiving the item
  106. /// </summary>
  107. [EditorSequence("Warehousing", 4)]
  108. public StockLocationLink DefaultLocation { get; set; }
  109. [Caption("Incoming QA")]
  110. [EditorSequence("Warehousing", 5)]
  111. public DigitalFormLink DigitalForm { 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. [NullEditor]
  142. public string Issues { get; set; }
  143. public override string ToString()
  144. {
  145. return string.Format("{0}: {1} ({2})", Code, Name, Dimensions.UnitSize);
  146. }
  147. protected override void Init()
  148. {
  149. base.Init();
  150. Supplier = new SupplierProductLink();
  151. //UnitSize = 1.0F;
  152. Units = new ProductUOMLink();
  153. Group = new ProductGroupLink();
  154. CostCentre = new CostCentreLink(() => this);
  155. PurchaseGL = new PurchaseGLCodeLink(() => this);
  156. SellGL = new SalesGLCodeLink(() => this);
  157. CostSheetSection = new CostSheetSectionLink();
  158. PricingStrategy = ProductPricingStrategy.Standard;
  159. TaxCode = new TaxCodeLink(() => this);
  160. Image = new ImageDocumentLink();
  161. Warehouse = new StockWarehouseLink();
  162. DigitalForm = new DigitalFormLink();
  163. DefaultLocation = new StockLocationLink();
  164. DefaultStyle = new ProductStyleLink();
  165. NonStock = false;
  166. UseDefaultSupplierPricing = true;
  167. Dimensions = new ProductDimensions(() => this);
  168. Charge = new ProductCharge();
  169. }
  170. public static double CalculateNettCost(ProductPricingStrategy strategy, double basecost, double componentcost)
  171. {
  172. if (strategy == ProductPricingStrategy.Kit)
  173. return basecost + componentcost;
  174. if (strategy == ProductPricingStrategy.Subcontractor)
  175. return basecost - componentcost;
  176. // Standard or Assembly
  177. return basecost;
  178. }
  179. }
  180. public class ProductFormLookups : ILookupDefinition<DigitalForm, Product>
  181. {
  182. public Filter<DigitalForm> DefineFilter(Product[] items)
  183. {
  184. // Get all FillableFormTypes where 2nd parameter is typeof(PurchaseOrder)
  185. return new Filter<DigitalForm>(x => x.Active).IsEqualTo(true).And(x => x.AppliesTo).IsEqualTo("PurchaseOrderItem");
  186. }
  187. Columns<Product> ILookupDefinition<DigitalForm, Product>.DefineFilterColumns()
  188. => new Columns<Product>();
  189. }
  190. }