InvoiceLine.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using System;
  2. using InABox.Core;
  3. namespace Comal.Classes
  4. {
  5. [UserTracking(typeof(Invoice))]
  6. public class InvoiceLine : Entity, IPersistent, IRemotable, ISequenceable, IOneToMany<Invoice>, ITaxable, ILicense<AccountsReceivableLicense>
  7. {
  8. [NullEditor]
  9. [EntityRelationship(DeleteAction.Cascade)]
  10. public InvoiceLink Invoice { get; set; }
  11. [Obsolete("Replaced by Invoice")]
  12. public InvoiceLink InvoiceLink
  13. {
  14. get => Invoice;
  15. set { }
  16. }
  17. [MemoEditor]
  18. [EditorSequence(1)]
  19. public string Description { get; set; }
  20. [EditorSequence(2)]
  21. [DoubleEditor]
  22. public double Quantity { get; set; } = 1.0F;
  23. [EditorSequence(3)]
  24. [CurrencyEditor]
  25. public double Amount { get; set; }
  26. [EditorSequence(4)]
  27. [DoubleEditor(Summary = Summary.Sum)]
  28. public double ExTax { get; set; }
  29. [EditorSequence(5)]
  30. public TaxCodeLink TaxCode { get; set; }
  31. [EditorSequence(6)]
  32. [DoubleEditor(Editable = Editable.Hidden)]
  33. public double TaxRate { get; set; }
  34. [EditorSequence(7)]
  35. [DoubleEditor(Editable = Editable.Hidden, Summary = Summary.Sum)]
  36. public double Tax { get; set; }
  37. [EditorSequence(8)]
  38. [DoubleEditor(Summary = Summary.Sum)]
  39. public double IncTax { get; set; }
  40. private class JobScopeLookup : LookupDefinitionGenerator<JobScope, InvoiceLine>
  41. {
  42. public override Filter<JobScope> DefineFilter(InvoiceLine[] items)
  43. {
  44. if (items == null)
  45. return Filter<JobScope>.Where(x => x.ID).IsEqualTo(CoreUtils.FullGuid);
  46. var jobid = CoreUtils.FullGuid;
  47. foreach (var item in items)
  48. {
  49. if (jobid == CoreUtils.FullGuid)
  50. jobid = item.Invoice.Job.ID;
  51. if (item.Invoice.Job.ID != jobid)
  52. return Filter<JobScope>.Where(x => x.ID).IsEqualTo(CoreUtils.FullGuid);
  53. }
  54. return Filter<JobScope>.Where(x => x.Job.ID).IsEqualTo(jobid).And(x => x.Status.Approved).IsEqualTo(true);
  55. }
  56. public override Columns<InvoiceLine> DefineFilterColumns()
  57. => Columns.None<InvoiceLine>().Add(x => x.Invoice.Job.ID);
  58. }
  59. [LookupDefinition(typeof(JobScopeLookup))]
  60. [EditorSequence(9)]
  61. public JobScopeLink Scope { get; set; }
  62. [EditorSequence(10)]
  63. public CostCentreLink CostCentre { get; set; }
  64. [EditorSequence(11)]
  65. public SalesGLCodeLink SellGL { get; set; }
  66. [NullEditor]
  67. public long Sequence { get; set; }
  68. static InvoiceLine()
  69. {
  70. LinkedProperties.Register<InvoiceLine, TaxCodeLink, double>(x => x.TaxCode, x => x.Rate, x => x.TaxRate);
  71. }
  72. private enum Suppress
  73. {
  74. This
  75. }
  76. protected override void DoPropertyChanged(string name, object? before, object? after)
  77. {
  78. base.DoPropertyChanged(name, before, after);
  79. if (EventSuppressor.IsSet(Suppress.This))
  80. return;
  81. using (new EventSuppressor(Suppress.This))
  82. {
  83. if (String.Equals(name, nameof(Quantity)))
  84. ExTax = (double)after * Amount;
  85. else if (String.Equals(name, nameof(Amount)))
  86. ExTax = (double)after * Quantity;
  87. else if (String.Equals(name, nameof(ExTax)))
  88. Amount = (double)after / (Quantity == 0.0F ? 1.0F : Quantity);
  89. }
  90. }
  91. }
  92. }