Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

64 lines
1.7KB

  1. <?php
  2. namespace common\logic\Producer\ProducerPriceRange\Repository;
  3. use common\helpers\Price;
  4. use common\logic\AbstractRepository;
  5. use common\logic\Producer\ProducerPriceRange\Model\ProducerPriceRange;
  6. class ProducerPriceRangeRepository extends AbstractRepository
  7. {
  8. protected ProducerPriceRangeRepositoryQuery $query;
  9. public function loadDependencies(): void
  10. {
  11. $this->loadQuery(ProducerPriceRangeRepositoryQuery::class);
  12. }
  13. /**
  14. * Retourne les options de base nécessaires à la fonction de recherche.
  15. */
  16. public function getDefaultOptionsSearch(): array
  17. {
  18. return [
  19. self::WITH => [],
  20. self::JOIN_WITH => [],
  21. self::ORDER_BY => 'range_begin ASC',
  22. self::ATTRIBUTE_ID_PRODUCER => ''
  23. ];
  24. }
  25. public function findOneProducerPriceRangeById(int $id)
  26. {
  27. return $this->createDefaultQuery()
  28. ->filterById($id)
  29. ->findOne();
  30. }
  31. public function queryProducerPriceRanges()
  32. {
  33. return $this->createDefaultQuery();
  34. }
  35. public function findProducerPriceRanges()
  36. {
  37. return $this->queryProducerPriceRanges()->find();
  38. }
  39. public function getAmountToBeBilledByTurnover(float $turnover = null, $format = false)
  40. {
  41. $amountToBeBilled = 0;
  42. $producerPriceRangeArray = $this->findProducerPriceRanges();
  43. foreach ($producerPriceRangeArray as $priceRange) {
  44. if ($turnover >= $priceRange->range_begin && $turnover < $priceRange->range_end) {
  45. $amountToBeBilled = $priceRange->price;
  46. }
  47. }
  48. if ($format) {
  49. return Price::format($amountToBeBilled, 0);
  50. } else {
  51. return $amountToBeBilled;
  52. }
  53. }
  54. }