BillLine.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. [EditorSequence(8)]
  42. public JobLink Job { get; set; }
  43. [NullEditor]
  44. public string PostedReference { get; set; }
  45. static BillLine()
  46. {
  47. LinkedProperties.Register<BillLine, PurchaseOrderItemLink, double>(x => x.OrderItem, x => x.ExTax,
  48. x => x.ExTax);
  49. LinkedProperties.Register<BillLine, PurchaseGLCodeLink, Guid>(x => x.OrderItem.PurchaseGL, x => x.ID,
  50. x => x.PurchaseGL.ID);
  51. LinkedProperties.Register<BillLine, CostCentreLink, Guid>(x => x.OrderItem.CostCentre, x => x.ID,
  52. x => x.CostCentre.ID);
  53. LinkedProperties.Register<BillLine, TaxCodeLink, Guid>(x => x.OrderItem.TaxCode, x => x.ID,
  54. x => x.TaxCode.ID);
  55. LinkedProperties.Register<BillLine, TaxCodeLink, String>(x => x.OrderItem.TaxCode, x => x.Code,
  56. x => x.TaxCode.Code);
  57. LinkedProperties.Register<BillLine, TaxCodeLink, String>(x => x.OrderItem.TaxCode, x => x.Description,
  58. x => x.TaxCode.Description);
  59. LinkedProperties.Register<BillLine, TaxCodeLink, double>(x => x.OrderItem.TaxCode, x => x.Rate,
  60. x => x.TaxCode.Rate);
  61. LinkedProperties.Register<BillLine, PurchaseOrderItemLink, double>(x => x.OrderItem, x => x.Tax,
  62. x => x.Tax);
  63. LinkedProperties.Register<BillLine, PurchaseOrderItemLink, double>(x => x.OrderItem, x => x.IncTax,
  64. x => x.IncTax);
  65. LinkedProperties.Register<BillLine, TaxCodeLink, double>(x => x.TaxCode, x => x.Rate, x => x.TaxRate);
  66. LinkedProperties.Register<BillLine, PurchaseGLCodeLink, Guid>(x => x.Product.PurchaseGL, x => x.ID, x => x.PurchaseGL.ID);
  67. LinkedProperties.Register<BillLine, CostCentreLink, Guid>(x => x.Product.CostCentre, x => x.ID, x => x.CostCentre.ID);
  68. LinkedProperties.Register<BillLine, TaxCodeLink, Guid>(x => x.Product.TaxCode, x => x.ID, x => x.TaxCode.ID);
  69. LinkedProperties.Register<BillLine, TaxCodeLink, string>(x => x.Product.TaxCode, x => x.Code, x => x.TaxCode.Code);
  70. LinkedProperties.Register<BillLine, TaxCodeLink, string>(x => x.Product.TaxCode, x => x.Description, x => x.TaxCode.Description);
  71. LinkedProperties.Register<BillLine, TaxCodeLink, double>(x => x.Product.TaxCode, x => x.Rate, x => x.TaxCode.Rate);
  72. }
  73. private static readonly Column<BillLine> OrderItemColumn = new Column<BillLine>(x => x.OrderItem.ID);
  74. private static readonly Column<BillLine> ProductColumn = new Column<BillLine>(x => x.Product.ID);
  75. private static readonly Column<BillLine> JobColumn = new Column<BillLine>(x => x.Job.ID);
  76. protected override void DoPropertyChanged(string name, object? before, object? after)
  77. {
  78. base.DoPropertyChanged(name, before, after);
  79. if (OrderItemColumn.IsEqualTo(name) && after is Guid orderItemID && orderItemID != Guid.Empty)
  80. {
  81. Product.ID = Guid.Empty;
  82. Product.Clear();
  83. Job.ID = Guid.Empty;
  84. Job.Clear();
  85. }
  86. else if((ProductColumn.IsEqualTo(name) && after is Guid productID && productID != Guid.Empty)
  87. || (JobColumn.IsEqualTo(name) && after is Guid jobID && jobID != Guid.Empty))
  88. {
  89. OrderItem.ID = Guid.Empty;
  90. OrderItem.Clear();
  91. }
  92. }
  93. }
  94. }