SupplierProduct.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. [CodeEditor(Editable = Editable.Enabled)]
  35. [EditorSequence(5)]
  36. public string SupplierCode { get; set; }
  37. [TextBoxEditor]
  38. [EditorSequence(6)]
  39. public string SupplierDescription { get; set; }
  40. [TextBoxEditor]
  41. [EditorSequence(7)]
  42. public string SupplierCategory { get; set; }
  43. [EditorSequence(8)]
  44. public JobLink Job { get; set; }
  45. [CurrencyEditor(Visible = Visible.Optional)]
  46. [EditorSequence(9)]
  47. public double ForeignCurrencyPrice { get; set; }
  48. [CurrencyEditor(Visible = Visible.Optional)]
  49. [EditorSequence(10)]
  50. public double TradePrice { get; set; }
  51. [DoubleEditor(Visible = Visible.Optional)]
  52. [EditorSequence(11)]
  53. public double Discount { get; set; }
  54. [CurrencyEditor(Visible = Visible.Optional, Editable = Editable.Disabled)]
  55. [EditorSequence(12)]
  56. public double CostPrice { get; set; }
  57. [EditorSequence(13)]
  58. public TaxCodeLink TaxCode { get; set; }
  59. [URLEditor]
  60. [EditorSequence(14)]
  61. public string URL { get; set; }
  62. [TimestampEditor]
  63. [EditorSequence(15)]
  64. public DateTime Expired { get; set; }
  65. static SupplierProduct()
  66. {
  67. LinkedProperties.Register<SupplierProduct, ProductLink, String>(x => x.Product, x => x.Code, x => x.SupplierCode);
  68. LinkedProperties.Register<SupplierProduct, ProductLink, String>(x => x.Product, x => x.Name, x => x.SupplierDescription);
  69. StockEntity.LinkStockDimensions<SupplierProduct>();
  70. }
  71. private static String STYLEGROUPID = CoreUtils.GetFullPropertyName<SupplierProduct, Guid>(x => x.StyleGroup.ID, ".");
  72. private static String STYLEID = CoreUtils.GetFullPropertyName<SupplierProduct, Guid>(x => x.Style.ID, ".");
  73. protected override void DoPropertyChanged(string name, object? before, object? after)
  74. {
  75. base.DoPropertyChanged(name, before, after);
  76. if (bChanging)
  77. return;
  78. bChanging = true;
  79. if (name.Equals(nameof(ForeignCurrencyPrice)) && SupplierLink.Currency.ID != Guid.Empty)
  80. {
  81. TradePrice = (double)after / (SupplierLink.Currency.ExchangeRate.IsEffectivelyEqual(0.0) ? 1.0 : SupplierLink.Currency.ExchangeRate);
  82. CostPrice = TradePrice * (100.0F - Discount) / 100.0F;
  83. }
  84. else if (name.Equals(nameof(TradePrice)))
  85. {
  86. if (SupplierLink.Currency.ID != Guid.Empty)
  87. ForeignCurrencyPrice = (double)after * SupplierLink.Currency.ExchangeRate;
  88. CostPrice = (double)after * (100.0F - Discount) / 100.0F;
  89. }
  90. else if (name.Equals(nameof(Discount)))
  91. CostPrice = TradePrice * (100.0F - (double)after) / 100.0F;
  92. //else if (name.Equals(name,nameof(CostPrice)))
  93. // TradePrice = Discount == 100.0F ? double.MaxValue : (double)after / ((100.0F - Discount) / 100.0F);
  94. else if (name.Equals(STYLEGROUPID))
  95. Style.CopyFrom(new ProductStyleLink());
  96. else if (name.Equals(STYLEID))
  97. StyleGroup.CopyFrom(new ProductStyleGroupLink());
  98. bChanging = false;
  99. }
  100. }
  101. }