ForeignCurrencyStore.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using Comal.Classes;
  2. using Comal.Stores;
  3. using InABox.Clients;
  4. using InABox.Core;
  5. namespace PRSStores;
  6. public class ForeignCurrencyStore : BaseStore<ForeignCurrency>
  7. {
  8. protected override void AfterSave(ForeignCurrency entity)
  9. {
  10. base.AfterSave(entity);
  11. var queue = Provider.Query(
  12. new Filter<SupplierProduct>(x => x.SupplierLink.Currency.ID).IsEqualTo(entity.ID),
  13. Columns.None<SupplierProduct>()
  14. .Add(x => x.ID)
  15. .Add(x=>x.SupplierLink.Currency.ID)
  16. .Add(x => x.SupplierLink.Currency.ExchangeRate)
  17. .Add(x => x.TaxCode.ID)
  18. .Add(x => x.ForeignCurrencyPrice)
  19. .Add(x => x.TradePrice)
  20. .Add(x => x.Discount)
  21. .Add(x => x.CostPrice)
  22. ).ToObjects<SupplierProduct>().ToQueue();
  23. while (queue.Any())
  24. {
  25. var products = queue.Dequeue(100).ToArray();
  26. foreach (var product in products)
  27. {
  28. var price = product.ForeignCurrencyPrice;
  29. if (price.IsEffectivelyEqual(0.0))
  30. price = product.TradePrice * product.SupplierLink.Currency.ExchangeRate;
  31. product.ForeignCurrencyPrice = 0.0;
  32. product.CommitChanges();
  33. product.ForeignCurrencyPrice = price;
  34. }
  35. Provider.Save(products.Where(x=>x.IsChanged()));
  36. }
  37. }
  38. }