|
|
|
|
|
|
|
|
public function getTurnoverLastMonth(Producer $producer, bool $format = false) |
|
|
public function getTurnoverLastMonth(Producer $producer, bool $format = false) |
|
|
{ |
|
|
{ |
|
|
$period = date('Y-m', strtotime('-1 month')); |
|
|
$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 |
|
|
public function getYearsWithTurnover(Producer $producer): array |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Retourne le CA du producteur pour un mois donné |
|
|
* 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) { |
|
|
if (!$period) { |
|
|
$period = date('Y-m'); |
|
|
$period = date('Y-m'); |
|
|
|
|
|
|
|
|
$dateStart = date('Y-m-31', strtotime("-1 month", strtotime($period))); |
|
|
$dateStart = date('Y-m-31', strtotime("-1 month", strtotime($period))); |
|
|
$dateEnd = date('Y-m-01', 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 = new \DateTime(); |
|
|
$date->setISODate($year, $week); |
|
|
$date->setISODate($year, $week); |
|
|
|
|
|
|
|
|
$date->modify('+6 days'); |
|
|
$date->modify('+6 days'); |
|
|
$dateEnd = $date->format('Y-m-d'); |
|
|
$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(); |
|
|
$connection = \Yii::$app->getDb(); |
|
|
|
|
|
|
|
|
|
|
|
$selectSum = 'product_order.price * product_order.quantity'; |
|
|
|
|
|
if($withTax) { |
|
|
|
|
|
$selectSum .= ' * (tax_rate.value + 1)'; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
$command = $connection->createCommand( |
|
|
$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 |
|
|
WHERE `order`.id = product_order.id_order |
|
|
AND `order`.date_delete IS NULL |
|
|
AND `order`.date_delete IS NULL |
|
|
AND distribution.id_producer = :id_producer |
|
|
AND distribution.id_producer = :id_producer |
|
|
AND `order`.id_distribution = distribution.id |
|
|
AND `order`.id_distribution = distribution.id |
|
|
AND distribution.date > :date_start |
|
|
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_start' => $dateStart, |
|
|
':date_end' => $dateEnd, |
|
|
':date_end' => $dateEnd, |
|
|
|
|
|
|
|
|
return $this->producerPriceRangeRepository->getAmountToBeBilledByTurnover($turnover, $format); |
|
|
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 = []; |
|
|
$data = []; |
|
|
$dataLabels = []; |
|
|
$dataLabels = []; |
|
|
|
|
|
|
|
|
foreach ($period as $date) { |
|
|
foreach ($period as $date) { |
|
|
$week = $date->format('W'); |
|
|
$week = $date->format('W'); |
|
|
$dataLabels[] = $week; |
|
|
$dataLabels[] = $week; |
|
|
$turnover = $this->getTurnoverByWeek($producer, $year, $date->format('W')); |
|
|
|
|
|
|
|
|
$turnover = $this->getTurnoverByWeek($producer, $year, $date->format('W'), $withTax); |
|
|
$data[$week] = $turnover; |
|
|
$data[$week] = $turnover; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
foreach ($period as $date) { |
|
|
foreach ($period as $date) { |
|
|
$month = $date->format('m/Y'); |
|
|
$month = $date->format('m/Y'); |
|
|
$dataLabels[] = $month; |
|
|
$dataLabels[] = $month; |
|
|
$turnover = $this->getTurnover($producer, $date->format('Y-m')); |
|
|
|
|
|
|
|
|
$turnover = $this->getTurnover($producer, $date->format('Y-m'), $withTax); |
|
|
$data[$month] = $turnover; |
|
|
$data[$month] = $turnover; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |