InvoiceStore.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using System;
  2. using System.Linq;
  3. using Comal.Classes;
  4. using InABox.Core;
  5. namespace Comal.Stores
  6. {
  7. public class InvoiceStore : BaseStore<Invoice>
  8. {
  9. protected override void BeforeSave(Invoice entity)
  10. {
  11. base.BeforeSave(entity);
  12. // Get the Customer Details for this Invoice
  13. if (!entity.CustomerLink.IsValid() & entity.JobLink.IsValid())
  14. {
  15. var job = Provider.Query(
  16. new Filter<Job>(x => x.ID).IsEqualTo(entity.JobLink.ID),
  17. new Columns<Job>(x => x.Account.ID)
  18. .Add(x => x.Account.Deleted)
  19. .Add(x => x.Customer.ID))
  20. .Rows.FirstOrDefault()?.ToObject<Job>();
  21. if (job != null)
  22. {
  23. entity.CustomerLink.ID = job.Account.IsValid() ? job.Account.ID : job.Customer.ID;
  24. //var customer = Provider.Load(new Filter<Customer>(x => x.ID).IsEqualTo(entity.CustomerLink.ID)).FirstOrDefault();
  25. //entity.CustomerLink.Synchronise(customer);
  26. }
  27. }
  28. //UpdateAggregate<Customer>(entity, entity.CustomerLink, Sum<Customer>(x=>x.Balance, x=>x.Balance));
  29. }
  30. }
  31. }