BillLineStore.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System.Linq;
  2. using Comal.Classes;
  3. using InABox.Core;
  4. using System;
  5. namespace Comal.Stores
  6. {
  7. internal class BillLineStore : BaseStore<BillLine>
  8. {
  9. protected override void AfterSave(BillLine entity)
  10. {
  11. base.BeforeSave(entity);
  12. if (entity.OrderItem.HasOriginalValue(x => x.ID))
  13. {
  14. Filter<PurchaseOrderItem> filter = (entity.OrderItem.ID != Guid.Empty)
  15. ? Filter<PurchaseOrderItem>.Where(x => x.ID).IsEqualTo(entity.OrderItem.ID)
  16. : Filter<PurchaseOrderItem>.Where(x => x.ID).IsEqualTo(entity.OrderItem.GetOriginalValue(x => x.ID));
  17. var items = Provider.Query(
  18. filter,
  19. Columns.Required<PurchaseOrderItem>()
  20. .Add(x => x.ID)
  21. .Add(x => x.BillLine.ID))
  22. .ToArray<PurchaseOrderItem>();
  23. foreach (var item in items)
  24. item.BillLine.ID = entity.OrderItem.ID != Guid.Empty ? entity.ID : Guid.Empty;
  25. Provider.Save(items);
  26. }
  27. // Actually, we don't want to do this, because we will lose the ability to do a delta between
  28. // Order values and Bill values (to identify price creep)
  29. // A more useful idea would be to update linked product/stock costings when receiving a bill,
  30. // although we need to be careful about how we manage side effects for average costs etc..
  31. // var pitems = Provider.Query(
  32. // Filter<PurchaseOrderItem>.Where(x => x.ID).IsEqualTo(entity.OrderItem.ID),
  33. // new Columns<PurchaseOrderItem>(
  34. // x => x.ID,
  35. // x => x.ExTax,
  36. // x => x.TaxCode.ID,
  37. // x => x.TaxRate,
  38. // x => x.IncTax,
  39. // x => x.Balance,
  40. // x => x.ReceivedDate
  41. // )
  42. // ).Rows.Select(x => x.ToObject<PurchaseOrderItem>()).ToArray();
  43. // foreach (var pitem in pitems)
  44. // {
  45. // pitem.ExTax = entity.ExTax;
  46. // pitem.TaxCode.ID = entity.TaxCode.ID;
  47. // pitem.TaxRate = entity.TaxRate;
  48. // pitem.IncTax = entity.IncTax;
  49. // pitem.Balance = pitem.ReceivedDate.IsEmpty() ? pitem.IncTax : 0.00F;
  50. // }
  51. //
  52. // FindSubStore<PurchaseOrderItem>().Save(pitems.Where(x => x.IsChanged()), "Updated by Bill Modification");
  53. }
  54. }
  55. }