SupplierProduct.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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>
  8. {
  9. private bool bChanging;
  10. [EditorSequence(0)]
  11. public SupplierLink SupplierLink { get; set; }
  12. [EntityRelationship(DeleteAction.SetNull)]
  13. [NullEditor]
  14. [Obsolete("Replaced with Product", true)]
  15. public ProductLink ProductLink
  16. {
  17. get { return Product; }
  18. set { Product = value; }
  19. }
  20. [EntityRelationship(DeleteAction.SetNull)]
  21. [EditorSequence(1)]
  22. public override ProductLink Product { get; set; }
  23. [EditorSequence(2)]
  24. public JobLink Job { get; set; }
  25. [CodeEditor(Editable = Editable.Enabled)]
  26. [EditorSequence(3)]
  27. public string SupplierCode { get; set; }
  28. [TextBoxEditor]
  29. [EditorSequence(4)]
  30. public string SupplierDescription { get; set; }
  31. [EditorSequence(5)]
  32. [RequiredColumn]
  33. [DimensionsEditor(typeof(StockDimensions), AllowEditingUnit = false)]
  34. public override StockDimensions Dimensions { get; set; }
  35. [TextBoxEditor]
  36. [EditorSequence(6)]
  37. public string SupplierCategory { get; set; }
  38. [CurrencyEditor(Visible = Visible.Optional)]
  39. [EditorSequence(7)]
  40. public double TradePrice { get; set; }
  41. [DoubleEditor(Visible = Visible.Optional)]
  42. [EditorSequence(8)]
  43. public double Discount { get; set; }
  44. [CurrencyEditor(Visible = Visible.Optional)]
  45. [EditorSequence(9)]
  46. public double CostPrice { get; set; }
  47. [EditorSequence(10)]
  48. public TaxCodeLink TaxCode { get; set; }
  49. [URLEditor]
  50. [EditorSequence(11)]
  51. public string URL { get; set; }
  52. [TimestampEditor]
  53. [EditorSequence(12)]
  54. public DateTime Expired { get; set; }
  55. protected override void Init()
  56. {
  57. base.Init();
  58. SupplierLink = new SupplierLink(() => this);
  59. Job = new JobLink();
  60. TaxCode = new TaxCodeLink();
  61. }
  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("TradePrice"))
  75. CostPrice = (double)after * (100.0F - Discount) / 100.0F;
  76. else if (name.Equals("Discount"))
  77. CostPrice = TradePrice * (100.0F - (double)after) / 100.0F;
  78. else if (name.Equals("CostPrice"))
  79. TradePrice = Discount == 100.0F ? double.MaxValue : (double)after / ((100.0F - Discount) / 100.0F);
  80. bChanging = false;
  81. }
  82. }
  83. }