SupplierProduct.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using System;
  2. using InABox.Core;
  3. namespace Comal.Classes
  4. {
  5. [UserTracking(typeof(Product))]
  6. public class SupplierProduct : StockEntity, IPersistent, IRemotable, ILicense<ProductManagementLicense>, IExportable, IImportable, IManyToMany<Supplier, Product>
  7. {
  8. private bool bChanging;
  9. [EditorSequence(0)]
  10. public SupplierLink SupplierLink { get; set; }
  11. [EntityRelationship(DeleteAction.SetNull)]
  12. [NullEditor]
  13. [Obsolete("Replaced with Product", true)]
  14. public ProductLink ProductLink
  15. {
  16. get { return Product; }
  17. set { Product = value; }
  18. }
  19. [EntityRelationship(DeleteAction.SetNull)]
  20. [EditorSequence(1)]
  21. public override ProductLink Product { get; set; }
  22. [EditorSequence(2)]
  23. public JobLink Job { get; set; }
  24. [CodeEditor(Editable = Editable.Enabled)]
  25. [EditorSequence(3)]
  26. public string SupplierCode { get; set; }
  27. [TextBoxEditor]
  28. [EditorSequence(4)]
  29. public string SupplierDescription { get; set; }
  30. [EditorSequence(5)]
  31. [RequiredColumn]
  32. [DimensionsEditor(typeof(StockDimensions), AllowEditingUnit = false)]
  33. public override StockDimensions Dimensions { get; set; }
  34. [TextBoxEditor]
  35. [EditorSequence(6)]
  36. public string SupplierCategory { get; set; }
  37. [CurrencyEditor(Visible = Visible.Optional)]
  38. [EditorSequence(7)]
  39. public double TradePrice { get; set; }
  40. [DoubleEditor(Visible = Visible.Optional)]
  41. [EditorSequence(8)]
  42. public double Discount { get; set; }
  43. [CurrencyEditor(Visible = Visible.Optional)]
  44. [EditorSequence(9)]
  45. public double CostPrice { get; set; }
  46. [EditorSequence(10)]
  47. public TaxCodeLink TaxCode { get; set; }
  48. [URLEditor]
  49. [EditorSequence(11)]
  50. public string URL { get; set; }
  51. [TimestampEditor]
  52. [EditorSequence(12)]
  53. public DateTime Expired { get; set; }
  54. protected override void Init()
  55. {
  56. base.Init();
  57. SupplierLink = new SupplierLink(() => this);
  58. Job = new JobLink();
  59. TaxCode = new TaxCodeLink();
  60. }
  61. static SupplierProduct()
  62. {
  63. LinkedProperties.Register<SupplierProduct, ProductLink, String>(x => x.Product, x => x.Code, x => x.SupplierCode);
  64. LinkedProperties.Register<SupplierProduct, ProductLink, String>(x => x.Product, x => x.Name, x => x.SupplierDescription);
  65. StockEntity.LinkStockDimensions<SupplierProduct>();
  66. }
  67. protected override void DoPropertyChanged(string name, object before, object after)
  68. {
  69. base.DoPropertyChanged(name, before, after);
  70. if (bChanging)
  71. return;
  72. bChanging = true;
  73. if (name.Equals("TradePrice"))
  74. CostPrice = (double)after * (100.0F - Discount) / 100.0F;
  75. else if (name.Equals("Discount"))
  76. CostPrice = TradePrice * (100.0F - (double)after) / 100.0F;
  77. else if (name.Equals("CostPrice"))
  78. TradePrice = Discount == 100.0F ? double.MaxValue : (double)after / ((100.0F - Discount) / 100.0F);
  79. bChanging = false;
  80. }
  81. }
  82. }