Product.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. using System;
  2. using System.Linq;
  3. using InABox.Core;
  4. using PRSClasses;
  5. namespace Comal.Classes
  6. {
  7. [UserTracking("Product Management")]
  8. public class Product : Entity, IPersistent, IRemotable, IIssues, ILicense<ProductManagementLicense>, IExportable, IImportable, IMergeable
  9. {
  10. [UniqueCodeEditor(Visible = Visible.Default, Editable = Editable.Enabled)]
  11. [EditorSequence(1)]
  12. public string Code { get; set; }
  13. [TextBoxEditor]
  14. [EditorSequence(2)]
  15. public string Name { get; set; }
  16. [MemoEditor]
  17. [EditorSequence(3)]
  18. public string Notes { get; set; }
  19. [EditorSequence(4)]
  20. public ProductDimensionUnitLink UnitOfMeasure { get; set; }
  21. private class ProductInstanceLookup : LookupDefinitionGenerator<ProductInstance, Product>
  22. {
  23. public override Filter<ProductInstance>? DefineFilter(Product[] items)
  24. {
  25. if (items.Length == 0)
  26. {
  27. return new Filter<ProductInstance>().None();
  28. }
  29. else
  30. {
  31. var filter = new Filters<ProductInstance>();
  32. foreach (var item in items)
  33. {
  34. filter.Add(new Filter<ProductInstance>(x => x.Product.ID).IsEqualTo(item.ID));
  35. }
  36. return filter.Combine();
  37. }
  38. }
  39. public override Columns<Product> DefineFilterColumns() => new Columns<Product>(x => x.ID);
  40. }
  41. [LookupDefinition(typeof(ProductInstanceLookup))]
  42. [EditorSequence(5)]
  43. [RequiredColumn]
  44. public ProductInstanceLink DefaultInstance { get; set; }
  45. [EditorSequence(6)]
  46. public ProductGroupLink Group { get; set; }
  47. [EditorSequence(7)]
  48. [DataModelTableName("Image")]
  49. public ImageDocumentLink Image { get; set; }
  50. [URLEditor]
  51. [EditorSequence(8)]
  52. public string URL { get; set; }
  53. [TimestampEditor]
  54. [EditorSequence(9)]
  55. public DateTime Expired { get; set; }
  56. [EnumLookupEditor(typeof(ProductPricingStrategy))]
  57. [EditorSequence("Pricing", 1)]
  58. public ProductPricingStrategy PricingStrategy { get; set; } = ProductPricingStrategy.Standard;
  59. private class SupplierProductLookup : LookupDefinitionGenerator<SupplierProduct, Product>
  60. {
  61. public override Filter<SupplierProduct> DefineFilter(Product[] items)
  62. {
  63. var id = items != null && items.Length == 1 ? items[0].ID : CoreUtils.FullGuid;
  64. return new Filter<SupplierProduct>(x => x.Product.ID).IsEqualTo(id);
  65. }
  66. public override Columns<Product> DefineFilterColumns()
  67. => new Columns<Product>(x => x.ID);
  68. }
  69. [LookupDefinition(typeof(SupplierProductLookup))]
  70. [EditorSequence("Pricing", 2)]
  71. public SupplierProductLink Supplier { get; set; }
  72. [CheckBoxEditor]
  73. [EditorSequence("Pricing", 3)]
  74. public bool UseDefaultSupplierPricing { get; set; } = true;
  75. [CurrencyEditor(Visible = Visible.Optional)]
  76. [EditorSequence("Pricing", 4)]
  77. public double BaseCost { get; set; }
  78. [Aggregate(typeof(ProductComponentCost))]
  79. [CurrencyEditor(Visible = Visible.Optional)] //, Editable = Editable.Disabled)]
  80. [EditorSequence("Pricing", 5)]
  81. public double ComponentCost { get; set; }
  82. [CurrencyEditor(Visible = Visible.Optional, Editable = Editable.Disabled)]
  83. [EditorSequence("Pricing", 6)]
  84. public double NettCost { get; set; }
  85. [Obsolete("Replaced with ProductInstance.AverageCost", true)]
  86. [CurrencyEditor(Visible = Visible.Optional)]
  87. [EditorSequence("Pricing", 7)]
  88. [LoggableProperty]
  89. public double AverageCost { get; set; }
  90. [EditorSequence("Pricing", 8)]
  91. [RequiredColumn]
  92. public TaxCodeLink TaxCode { get; set; }
  93. [EditorSequence("Pricing", 9)]
  94. [RequiredColumn]
  95. public PurchaseGLCodeLink PurchaseGL { get; set; }
  96. [EditorSequence("Pricing", 10)]
  97. [RequiredColumn]
  98. public SalesGLCodeLink SellGL { get; set; }
  99. [EditorSequence("Pricing", 11)]
  100. [RequiredColumn]
  101. public CostCentreLink CostCentre { get; set; }
  102. [EditorSequence("Pricing", 12)]
  103. public CostSheetSectionLink CostSheetSection { get; set; }
  104. [ProductChargeEditor]
  105. [EditorSequence("Pricing", 13)]
  106. public ProductCharge Charge { get; set; }
  107. /// <summary>
  108. /// Flag to indicate whether stock movements are to be tracked for this item
  109. /// If set, no stock movements will be recorded, even if the Warehouse and/or default location are set
  110. /// </summary>
  111. [CheckBoxEditor]
  112. [EditorSequence("Warehousing", 1)]
  113. public bool NonStock { get; set; } = false;
  114. /// <summary>
  115. /// The Warehouse that this item resides in. DefaultLocation Lookups are limited to this Warehouse only, although
  116. /// actual stock holdings can be anywhere (imperfect systems)
  117. /// </summary>
  118. [EditorSequence("Warehousing", 2)]
  119. public StockWarehouseLink Warehouse { get; set; }
  120. private class StockLocationLookup : LookupDefinitionGenerator<StockLocation, Product>
  121. {
  122. // If there are multiple items, they must be all in the same warehouse
  123. public override Filter<StockLocation> DefineFilter(Product[] items)
  124. {
  125. var warehouses = items.Select(x => x.Warehouse.ID).Distinct().ToArray();
  126. if (warehouses.Length == 1)
  127. return new Filter<StockLocation>(x => x.Active).IsEqualTo(true).And(x => x.Warehouse.ID).IsEqualTo(warehouses.First());
  128. return new Filter<StockLocation>(x => x.ID).IsEqualTo(CoreUtils.FullGuid);
  129. }
  130. public override Columns<Product> DefineFilterColumns()
  131. => new Columns<Product>(x => x.Warehouse.ID);
  132. }
  133. [LookupDefinition(typeof(StockLocationLookup))]
  134. /// <summary>
  135. /// (Optional) The Location to be used when Purchase Orders / Consignments are received.
  136. /// If blank, the item will be received into the default location for the Warehouse assign to the product
  137. /// If that is also blank, then no stock movement will be recorded when receiving the item
  138. /// </summary>
  139. [EditorSequence("Warehousing", 4)]
  140. public StockLocationLink DefaultLocation { get; set; }
  141. private class ProductFormLookups : LookupDefinitionGenerator<DigitalForm, Product>
  142. {
  143. public override Filter<DigitalForm> DefineFilter(Product[] items)
  144. {
  145. // Get all FillableFormTypes where 2nd parameter is typeof(PurchaseOrder)
  146. return new Filter<DigitalForm>(x => x.Active).IsEqualTo(true).And(x => x.AppliesTo).IsEqualTo("PurchaseOrderItem");
  147. }
  148. public override Columns<Product> DefineFilterColumns()
  149. => new Columns<Product>();
  150. }
  151. [Caption("Incoming QA")]
  152. [EditorSequence("Warehousing", 5)]
  153. public DigitalFormLink DigitalForm { get; set; }
  154. [Caption("Mfg Treatment?")]
  155. [EditorSequence("Warehousing", 6)]
  156. public bool IsManufacturingTreatment { get; set; }
  157. [NullEditor]
  158. public string Barcodes { get; set; }
  159. [Aggregate(typeof(ProductUnitAggregate))]
  160. [DoubleEditor(Editable = Editable.Hidden)]
  161. public double UnitQty { get; set; }
  162. [Aggregate(typeof(ProductRemnantAggregate))]
  163. [DoubleEditor(Editable = Editable.Hidden)]
  164. public double RemnantQty { get; set; }
  165. [Aggregate(typeof(OnOrderAggregate))]
  166. [DoubleEditor(Editable = Editable.Hidden)]
  167. public double OnOrder { get; set; }
  168. [Aggregate(typeof(TotalStockAggregate))]
  169. [DoubleEditor(Editable = Editable.Hidden)]
  170. public double TotalStock { get; set; }
  171. [Formula(typeof(ReservedStockFormula))]
  172. [DoubleEditor(Editable = Editable.Hidden)]
  173. public double ReservedStock { get; set; }
  174. [Aggregate(typeof(FreeStockAggregate))]
  175. [DoubleEditor(Editable = Editable.Hidden)]
  176. public double FreeStock { get; set; }
  177. [Aggregate(typeof(TotalRequiredAggregate))]
  178. [DoubleEditor(Editable = Editable.Hidden)]
  179. public double Required { get; set; }
  180. [Aggregate(typeof(ProductReceivedAggregate))]
  181. [DateTimeEditor(Editable = Editable.Hidden)]
  182. public DateTime LastReceived { get; set; }
  183. [Aggregate(typeof(ProductIssuedAggregate))]
  184. [DateTimeEditor(Editable = Editable.Hidden)]
  185. public DateTime LastIssued { get; set; }
  186. [Obsolete("Replaced with DefaultInstance.Style")]
  187. [NullEditor]
  188. public ProductStyleLink DefaultStyle { get; set; }
  189. [Obsolete("Replaced with DefaultInstance.MinimumStockLevel")]
  190. [NullEditor]
  191. public int MinimumStockLevel { get; set; }
  192. [Obsolete("Replaced with DefaultInstance.Dimensions")]
  193. [NullEditor]
  194. public ProductDimensions Dimensions { get; set; }
  195. [NullEditor]
  196. [Obsolete("Replaced with Dimensions", true)]
  197. // [DoubleEditor]
  198. // [EditorSequence(4)]
  199. public double UnitSize { get; set; }
  200. [NullEditor]
  201. [Obsolete("Replaced with Dimensions", false)]
  202. // [EditorSequence(5)]
  203. public ProductUOMLink Units { get; set; }
  204. [NullEditor]
  205. [Obsolete("Replaced with Dimensions", true)]
  206. // [DoubleEditor]
  207. // [EditorSequence(6)]
  208. // [Caption("Standard Weight")]
  209. public double Weight { get; set; }
  210. [NullEditor]
  211. public string Issues { get; set; }
  212. public override string ToString()
  213. {
  214. return string.Format("{0}: {1} ({2})", Code, Name, DefaultInstance.Dimensions.UnitSize);
  215. }
  216. public static double CalculateNettCost(ProductPricingStrategy strategy, double basecost, double componentcost)
  217. {
  218. if (strategy == ProductPricingStrategy.Kit)
  219. return basecost + componentcost;
  220. if (strategy == ProductPricingStrategy.Subcontractor)
  221. return basecost - componentcost;
  222. // Standard or Assembly
  223. return basecost;
  224. }
  225. }
  226. }