123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- using System;
- using InABox.Core;
- namespace Comal.Classes
- {
- [UserTracking(typeof(Invoice))]
- public class InvoiceLine : Entity, IPersistent, IRemotable, ISequenceable, IOneToMany<Invoice>, ITaxable, ILicense<AccountsReceivableLicense>
- {
- [NullEditor]
- [EntityRelationship(DeleteAction.Cascade)]
- public InvoiceLink InvoiceLink { get; set; }
- [MemoEditor]
- [EditorSequence(1)]
- public string Description { get; set; }
- [EditorSequence(2)]
- [DoubleEditor]
- public double Quantity { get; set; } = 1.0F;
- [EditorSequence(3)]
- [CurrencyEditor]
- public double Amount { get; set; }
-
- [EditorSequence(4)]
- [DoubleEditor(Summary = Summary.Sum)]
- public double ExTax { get; set; }
- [EditorSequence(5)]
- public TaxCodeLink TaxCode { get; set; }
-
- [EditorSequence(6)]
- [DoubleEditor(Editable = Editable.Hidden)]
- public double TaxRate { get; set; }
-
- [EditorSequence(7)]
- [DoubleEditor(Editable = Editable.Hidden, Summary = Summary.Sum)]
- public double Tax { get; set; }
-
- [EditorSequence(8)]
- [DoubleEditor(Summary = Summary.Sum)]
- public double IncTax { get; set; }
-
- private class JobScopeLookup : LookupDefinitionGenerator<JobScope, InvoiceLine>
- {
- public override Filter<JobScope> DefineFilter(InvoiceLine[] items)
- {
- if (items == null)
- return new Filter<JobScope>(x => x.ID).IsEqualTo(CoreUtils.FullGuid);
- var jobid = CoreUtils.FullGuid;
- foreach (var item in items)
- {
- if (jobid == CoreUtils.FullGuid)
- jobid = item.InvoiceLink.JobLink.ID;
- if (item.InvoiceLink.JobLink.ID != jobid)
- return new Filter<JobScope>(x => x.ID).IsEqualTo(CoreUtils.FullGuid);
- }
- return new Filter<JobScope>(x => x.Job.ID).IsEqualTo(jobid).And(x => x.Status.Approved).IsEqualTo(true);
- }
-
- public override Columns<InvoiceLine> DefineFilterColumns()
- => new Columns<InvoiceLine>(x => x.InvoiceLink.JobLink.ID);
- }
- [LookupDefinition(typeof(JobScopeLookup))]
- [EditorSequence(9)]
- public JobScopeLink Scope { get; set; }
-
- [EditorSequence(10)]
- public CostCentreLink CostCentre { get; set; }
-
- [NullEditor]
- public long Sequence { get; set; }
- static InvoiceLine()
- {
- LinkedProperties.Register<InvoiceLine, TaxCodeLink, double>(x => x.TaxCode, x => x.Rate, x => x.TaxRate);
- }
- private enum Suppress
- {
- This
- }
-
- protected override void DoPropertyChanged(string name, object? before, object? after)
- {
- base.DoPropertyChanged(name, before, after);
-
- if (EventSuppressor.IsSet(Suppress.This))
- return;
-
- using (new EventSuppressor(Suppress.This))
- {
- if (String.Equals(name, nameof(Quantity)))
- ExTax = (double)after * Amount;
- else if (String.Equals(name, nameof(Amount)))
- ExTax = (double)after * Quantity;
- else if (String.Equals(name, nameof(ExTax)))
- Amount = (double)after / (Quantity == 0.0F ? 1.0F : Quantity);
-
- }
- }
- }
- }
|