Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

ProducerPriceRangeRepository.php 2.1KB

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