InvoiceLine.cs 3.5 KB

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