SupplierProduct.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. using System;
  2. using InABox.Core;
  3. using PRSClasses;
  4. namespace Comal.Classes
  5. {
  6. [UserTracking(typeof(Product))]
  7. public class SupplierProduct : StockEntity, IPersistent, IRemotable, ILicense<ProductManagementLicense>, IExportable, IImportable, IManyToMany<Supplier, Product>, IJobMaterial
  8. {
  9. private bool bChanging;
  10. [RequiredColumn]
  11. [EditorSequence(0)]
  12. public SupplierLink SupplierLink { get; set; }
  13. [EntityRelationship(DeleteAction.SetNull)]
  14. [NullEditor]
  15. [Obsolete("Replaced with Product", true)]
  16. public ProductLink ProductLink
  17. {
  18. get { return Product; }
  19. set { Product = value; }
  20. }
  21. [EntityRelationship(DeleteAction.SetNull)]
  22. [EditorSequence(1)]
  23. public override ProductLink Product { get; set; }
  24. [EditorSequence(2)]
  25. [RequiredColumn]
  26. [DimensionsEditor(typeof(StockDimensions))]
  27. public override StockDimensions Dimensions { get; set; }
  28. [EntityRelationship(DeleteAction.SetNull)]
  29. [EditorSequence(3)]
  30. public ProductStyleGroupLink StyleGroup { get; set; }
  31. [EntityRelationship(DeleteAction.SetNull)]
  32. [EditorSequence(4)]
  33. public ProductStyleLink Style { get; set; }
  34. /// <summary>
  35. /// The product code as the supplier knows it.
  36. /// </summary>
  37. [Comment("Product code as the supplier knows it.")]
  38. [CodeEditor(Editable = Editable.Enabled)]
  39. [EditorSequence(5)]
  40. public string SupplierCode { get; set; }
  41. /// <summary>
  42. /// Product description as the supplier knows it.
  43. /// </summary>
  44. [Comment("Product description as the supplier knows it.")]
  45. [TextBoxEditor]
  46. [EditorSequence(6)]
  47. public string SupplierDescription { get; set; }
  48. [TextBoxEditor]
  49. [EditorSequence(7)]
  50. public string SupplierCategory { get; set; }
  51. [EditorSequence(8)]
  52. public JobLink Job { get; set; }
  53. [CurrencyEditor(Visible = Visible.Optional)]
  54. [EditorSequence(9)]
  55. public double ForeignCurrencyPrice { get; set; }
  56. [CurrencyEditor(Visible = Visible.Optional)]
  57. [EditorSequence(10)]
  58. public double TradePrice { get; set; }
  59. [DoubleEditor(Visible = Visible.Optional)]
  60. [EditorSequence(11)]
  61. public double Discount { get; set; }
  62. [CurrencyEditor(Visible = Visible.Optional, Editable = Editable.Disabled)]
  63. [EditorSequence(12)]
  64. public double CostPrice { get; set; }
  65. [EditorSequence(13)]
  66. public TaxCodeLink TaxCode { get; set; }
  67. [URLEditor]
  68. [EditorSequence(14)]
  69. public string URL { get; set; }
  70. [TimestampEditor]
  71. [EditorSequence(15)]
  72. public DateTime Expired { get; set; }
  73. static SupplierProduct()
  74. {
  75. LinkedProperties.Register<SupplierProduct, ProductLink, String>(x => x.Product, x => x.Code, x => x.SupplierCode);
  76. LinkedProperties.Register<SupplierProduct, ProductLink, String>(x => x.Product, x => x.Name, x => x.SupplierDescription);
  77. StockEntity.LinkStockDimensions<SupplierProduct>();
  78. }
  79. private static String STYLEGROUPID = CoreUtils.GetFullPropertyName<SupplierProduct, Guid>(x => x.StyleGroup.ID, ".");
  80. private static String STYLEID = CoreUtils.GetFullPropertyName<SupplierProduct, Guid>(x => x.Style.ID, ".");
  81. protected override void DoPropertyChanged(string name, object? before, object? after)
  82. {
  83. base.DoPropertyChanged(name, before, after);
  84. if (bChanging)
  85. return;
  86. bChanging = true;
  87. if (name.Equals(nameof(ForeignCurrencyPrice)) && SupplierLink.Currency.ID != Guid.Empty)
  88. {
  89. TradePrice = (double)after / (SupplierLink.Currency.ExchangeRate.IsEffectivelyEqual(0.0) ? 1.0 : SupplierLink.Currency.ExchangeRate);
  90. CostPrice = TradePrice * (100.0F - Discount) / 100.0F;
  91. }
  92. else if (name.Equals(nameof(TradePrice)))
  93. {
  94. if (SupplierLink.Currency.ID != Guid.Empty)
  95. ForeignCurrencyPrice = (double)after * SupplierLink.Currency.ExchangeRate;
  96. CostPrice = (double)after * (100.0F - Discount) / 100.0F;
  97. }
  98. else if (name.Equals(nameof(Discount)))
  99. CostPrice = TradePrice * (100.0F - (double)after) / 100.0F;
  100. //else if (name.Equals(name,nameof(CostPrice)))
  101. // TradePrice = Discount == 100.0F ? double.MaxValue : (double)after / ((100.0F - Discount) / 100.0F);
  102. else if (name.Equals(STYLEGROUPID))
  103. Style.CopyFrom(new ProductStyleLink());
  104. else if (name.Equals(STYLEID))
  105. StyleGroup.CopyFrom(new ProductStyleGroupLink());
  106. bChanging = false;
  107. }
  108. }
  109. }