Product.cs 10 KB

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