BillLine.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using System;
  2. using InABox.Core;
  3. namespace Comal.Classes
  4. {
  5. public class BillLineLink : EntityLink<BillLine>
  6. {
  7. [NullEditor]
  8. public override Guid ID { get; set; }
  9. }
  10. [UserTracking(typeof(Bill))]
  11. public class BillLine : Entity, IPersistent, IRemotable, IOneToMany<Bill>, ITaxable, ILicense<AccountsPayableLicense>, IPostableFragment<Bill>
  12. {
  13. [EntityRelationship(DeleteAction.Cascade)]
  14. [NullEditor]
  15. public BillLink BillLink { get; set; }
  16. [EntityRelationship(DeleteAction.SetNull)]
  17. [EditorSequence(1)]
  18. public PurchaseOrderItemLink OrderItem { get; set; }
  19. [EditorSequence(2)]
  20. public ProductLink Product { get; set; }
  21. [MemoEditor]
  22. [EditorSequence(2)]
  23. public string Description { get; set; }
  24. [EditorSequence(3)]
  25. public PurchaseGLCodeLink PurchaseGL { get; set; }
  26. [EditorSequence(4)]
  27. public CostCentreLink CostCentre { get; set; }
  28. [CurrencyEditor(Summary = Summary.Sum)]
  29. [EditorSequence(5)]
  30. public double ExTax { get; set; }
  31. [RequiredColumn]
  32. [EditorSequence(6)]
  33. public TaxCodeLink TaxCode { get; set; }
  34. [DoubleEditor(Editable = Editable.Hidden)]
  35. public double TaxRate { get; set; }
  36. [CurrencyEditor(Summary = Summary.Sum)]
  37. public double Tax { get; set; }
  38. [CurrencyEditor(Summary = Summary.Sum)]
  39. [EditorSequence(7)]
  40. public double IncTax { get; set; }
  41. [NullEditor]
  42. public string PostedReference { get; set; }
  43. static BillLine()
  44. {
  45. LinkedProperties.Register<BillLine, PurchaseOrderItemLink, double>(x => x.OrderItem, x => x.ExTax,
  46. x => x.ExTax);
  47. LinkedProperties.Register<BillLine, PurchaseGLCodeLink, Guid>(x => x.OrderItem.PurchaseGL, x => x.ID,
  48. x => x.PurchaseGL.ID);
  49. LinkedProperties.Register<BillLine, CostCentreLink, Guid>(x => x.OrderItem.CostCentre, x => x.ID,
  50. x => x.CostCentre.ID);
  51. LinkedProperties.Register<BillLine, TaxCodeLink, Guid>(x => x.OrderItem.TaxCode, x => x.ID,
  52. x => x.TaxCode.ID);
  53. LinkedProperties.Register<BillLine, TaxCodeLink, String>(x => x.OrderItem.TaxCode, x => x.Code,
  54. x => x.TaxCode.Code);
  55. LinkedProperties.Register<BillLine, TaxCodeLink, String>(x => x.OrderItem.TaxCode, x => x.Description,
  56. x => x.TaxCode.Description);
  57. LinkedProperties.Register<BillLine, TaxCodeLink, double>(x => x.OrderItem.TaxCode, x => x.Rate,
  58. x => x.TaxCode.Rate);
  59. LinkedProperties.Register<BillLine, PurchaseOrderItemLink, double>(x => x.OrderItem, x => x.Tax,
  60. x => x.Tax);
  61. LinkedProperties.Register<BillLine, PurchaseOrderItemLink, double>(x => x.OrderItem, x => x.IncTax,
  62. x => x.IncTax);
  63. LinkedProperties.Register<BillLine, TaxCodeLink, double>(x => x.TaxCode, x => x.Rate, x => x.TaxRate);
  64. LinkedProperties.Register<BillLine, PurchaseGLCodeLink, Guid>(x => x.Product.PurchaseGL, x => x.ID, x => x.PurchaseGL.ID);
  65. LinkedProperties.Register<BillLine, CostCentreLink, Guid>(x => x.Product.CostCentre, x => x.ID, x => x.CostCentre.ID);
  66. LinkedProperties.Register<BillLine, TaxCodeLink, Guid>(x => x.Product.TaxCode, x => x.ID, x => x.TaxCode.ID);
  67. LinkedProperties.Register<BillLine, TaxCodeLink, string>(x => x.Product.TaxCode, x => x.Code, x => x.TaxCode.Code);
  68. LinkedProperties.Register<BillLine, TaxCodeLink, string>(x => x.Product.TaxCode, x => x.Description, x => x.TaxCode.Description);
  69. LinkedProperties.Register<BillLine, TaxCodeLink, double>(x => x.Product.TaxCode, x => x.Rate, x => x.TaxCode.Rate);
  70. }
  71. private static readonly Column<BillLine> OrderItemColumn = new Column<BillLine>(x => x.OrderItem.ID);
  72. private static readonly Column<BillLine> ProductColumn = new Column<BillLine>(x => x.Product.ID);
  73. protected override void DoPropertyChanged(string name, object? before, object? after)
  74. {
  75. base.DoPropertyChanged(name, before, after);
  76. if (OrderItemColumn.IsEqualTo(name) && after is Guid orderItemID && orderItemID != Guid.Empty)
  77. {
  78. Product.ID = Guid.Empty;
  79. Product.Clear();
  80. }
  81. else if(ProductColumn.IsEqualTo(name) && after is Guid productID && productID != Guid.Empty)
  82. {
  83. OrderItem.ID = Guid.Empty;
  84. OrderItem.Clear();
  85. }
  86. }
  87. }
  88. }