|
- <?php
-
- namespace common\logic\Producer\ProducerPriceRange;
-
- use common\helpers\Price;
- use common\logic\BaseService;
- use common\logic\RepositoryInterface;
-
- class ProducerPriceRangeRepository extends BaseService implements RepositoryInterface
- {
- /**
- * Retourne les options de base nécessaires à la fonction de recherche.
- *
- */
- public function defaultOptionsSearch(): array
- {
- return [
- 'with' => [],
- 'join_with' => [],
- 'orderby' => '',
- 'attribute_id_producer' => ''
- ];
- }
-
- public function query()
- {
- return ProducerPriceRange::find()->orderBy('range_begin ASC');
- }
-
- public function getAmountToBeBilledByTurnover(float $turnover, $format = false)
- {
- $amountToBeBilled = 0;
- $producerPriceRangeArray = ProducerPriceRange::find()->all();
- foreach ($producerPriceRangeArray as $priceRange) {
- if ($turnover >= $priceRange->range_begin && $turnover < $priceRange->range_end) {
- $amountToBeBilled = $priceRange->price;
- }
- }
-
- if ($format) {
- return Price::format($amountToBeBilled, 0);
- } else {
- return $amountToBeBilled;
- }
- }
- }
|