|
|
@@ -113,7 +113,7 @@ class ProducerRepository extends AbstractRepository |
|
|
|
public function getTurnoverLastMonth(Producer $producer, bool $format = false) |
|
|
|
{ |
|
|
|
$period = date('Y-m', strtotime('-1 month')); |
|
|
|
return $this->getTurnover($producer, $period, $format); |
|
|
|
return $this->getTurnover($producer, $period, false, $format); |
|
|
|
} |
|
|
|
|
|
|
|
public function getYearsWithTurnover(Producer $producer): array |
|
|
@@ -144,7 +144,7 @@ class ProducerRepository extends AbstractRepository |
|
|
|
/** |
|
|
|
* Retourne le CA du producteur pour un mois donné |
|
|
|
*/ |
|
|
|
public function getTurnover(Producer $producer, string $period = '', bool $format = false) |
|
|
|
public function getTurnover(Producer $producer, string $period = '', bool $withTax = false, bool $format = false) |
|
|
|
{ |
|
|
|
if (!$period) { |
|
|
|
$period = date('Y-m'); |
|
|
@@ -153,10 +153,10 @@ class ProducerRepository extends AbstractRepository |
|
|
|
$dateStart = date('Y-m-31', strtotime("-1 month", strtotime($period))); |
|
|
|
$dateEnd = date('Y-m-01', strtotime("+1 month", strtotime($period))); |
|
|
|
|
|
|
|
return $this->getTurnoverByDateStartEnd($producer, $dateStart, $dateEnd, $format); |
|
|
|
return $this->getTurnoverByDateStartEnd($producer, $dateStart, $dateEnd, $withTax, $format); |
|
|
|
} |
|
|
|
|
|
|
|
public function getTurnoverByWeek(Producer $producer, int $year, int $week, bool $format = false) |
|
|
|
public function getTurnoverByWeek(Producer $producer, int $year, int $week, bool $withTax = false, bool $format = false) |
|
|
|
{ |
|
|
|
$date = new \DateTime(); |
|
|
|
$date->setISODate($year, $week); |
|
|
@@ -164,22 +164,29 @@ class ProducerRepository extends AbstractRepository |
|
|
|
$date->modify('+6 days'); |
|
|
|
$dateEnd = $date->format('Y-m-d'); |
|
|
|
|
|
|
|
return $this->getTurnoverByDateStartEnd($producer, $dateStart, $dateEnd, $format); |
|
|
|
return $this->getTurnoverByDateStartEnd($producer, $dateStart, $dateEnd, $withTax, $format); |
|
|
|
} |
|
|
|
|
|
|
|
public function getTurnoverByDateStartEnd(Producer $producer, string $dateStart, string $dateEnd, bool $format = false) |
|
|
|
public function getTurnoverByDateStartEnd(Producer $producer, string $dateStart, string $dateEnd, bool $withTax = false, bool $format = false) |
|
|
|
{ |
|
|
|
$connection = \Yii::$app->getDb(); |
|
|
|
|
|
|
|
$selectSum = 'product_order.price * product_order.quantity'; |
|
|
|
if($withTax) { |
|
|
|
$selectSum .= ' * (tax_rate.value + 1)'; |
|
|
|
} |
|
|
|
|
|
|
|
$command = $connection->createCommand( |
|
|
|
' |
|
|
|
SELECT SUM(product_order.price * product_order.quantity) AS turnover |
|
|
|
FROM `order`, product_order, distribution |
|
|
|
SELECT SUM('.$selectSum.') AS turnover |
|
|
|
FROM `order`, product_order, distribution, tax_rate |
|
|
|
WHERE `order`.id = product_order.id_order |
|
|
|
AND `order`.date_delete IS NULL |
|
|
|
AND distribution.id_producer = :id_producer |
|
|
|
AND `order`.id_distribution = distribution.id |
|
|
|
AND distribution.date > :date_start |
|
|
|
AND distribution.date < :date_end', |
|
|
|
AND distribution.date < :date_end |
|
|
|
AND product_order.id_tax_rate = tax_rate.id', |
|
|
|
[ |
|
|
|
':date_start' => $dateStart, |
|
|
|
':date_end' => $dateEnd, |
|
|
@@ -216,7 +223,7 @@ class ProducerRepository extends AbstractRepository |
|
|
|
return $this->producerPriceRangeRepository->getAmountToBeBilledByTurnover($turnover, $format); |
|
|
|
} |
|
|
|
|
|
|
|
public function getDatasChartTurnoverStatistics(Producer $producer, int $year, string $displayBy = 'month') |
|
|
|
public function getDatasChartTurnoverStatistics(Producer $producer, int $year, string $displayBy = 'month', bool $withTax = false) |
|
|
|
{ |
|
|
|
$data = []; |
|
|
|
$dataLabels = []; |
|
|
@@ -236,7 +243,7 @@ class ProducerRepository extends AbstractRepository |
|
|
|
foreach ($period as $date) { |
|
|
|
$week = $date->format('W'); |
|
|
|
$dataLabels[] = $week; |
|
|
|
$turnover = $this->getTurnoverByWeek($producer, $year, $date->format('W')); |
|
|
|
$turnover = $this->getTurnoverByWeek($producer, $year, $date->format('W'), $withTax); |
|
|
|
$data[$week] = $turnover; |
|
|
|
} |
|
|
|
} |
|
|
@@ -244,7 +251,7 @@ class ProducerRepository extends AbstractRepository |
|
|
|
foreach ($period as $date) { |
|
|
|
$month = $date->format('m/Y'); |
|
|
|
$dataLabels[] = $month; |
|
|
|
$turnover = $this->getTurnover($producer, $date->format('Y-m')); |
|
|
|
$turnover = $this->getTurnover($producer, $date->format('Y-m'), $withTax); |
|
|
|
$data[$month] = $turnover; |
|
|
|
} |
|
|
|
} |