SupplierProduct.cs 4.0 KB

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