|
|
|
|
|
|
|
|
$period = date('Y-m'); |
|
|
$period = date('Y-m'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$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); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function getTurnoverByWeek(Producer $producer, int $year, int $week, bool $format = false) |
|
|
|
|
|
{ |
|
|
|
|
|
$date = new \DateTime(); |
|
|
|
|
|
$date->setISODate($year, $week); |
|
|
|
|
|
$dateStart = $date->format('Y-m-d'); |
|
|
|
|
|
$date->modify('+6 days'); |
|
|
|
|
|
$dateEnd = $date->format('Y-m-d'); |
|
|
|
|
|
|
|
|
|
|
|
return $this->getTurnoverByDateStartEnd($producer, $dateStart, $dateEnd, $format); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function getTurnoverByDateStartEnd(Producer $producer, string $dateStart, string $dateEnd, bool $format = false) |
|
|
|
|
|
{ |
|
|
$connection = \Yii::$app->getDb(); |
|
|
$connection = \Yii::$app->getDb(); |
|
|
$command = $connection->createCommand( |
|
|
$command = $connection->createCommand( |
|
|
' |
|
|
' |
|
|
|
|
|
|
|
|
WHERE `order`.id = product_order.id_order |
|
|
WHERE `order`.id = product_order.id_order |
|
|
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_begin |
|
|
|
|
|
|
|
|
AND distribution.date > :date_start |
|
|
AND distribution.date < :date_end', |
|
|
AND distribution.date < :date_end', |
|
|
[ |
|
|
[ |
|
|
':date_begin' => date('Y-m-31', strtotime("-1 month", strtotime($period))), |
|
|
|
|
|
':date_end' => date('Y-m-01', strtotime("+1 month", strtotime($period))), |
|
|
|
|
|
|
|
|
':date_start' => $dateStart, |
|
|
|
|
|
':date_end' => $dateEnd, |
|
|
':id_producer' => $producer->id |
|
|
':id_producer' => $producer->id |
|
|
] |
|
|
] |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
return $this->producerPriceRangeRepository->getAmountToBeBilledByTurnover($turnover, $format); |
|
|
return $this->producerPriceRangeRepository->getAmountToBeBilledByTurnover($turnover, $format); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getDatasChartTurnoverStatistics(Producer $producer, int $year) |
|
|
|
|
|
|
|
|
public function getDatasChartTurnoverStatistics(Producer $producer, int $year, string $displayBy = 'month') |
|
|
{ |
|
|
{ |
|
|
$interval = new \DateInterval('P1M'); |
|
|
|
|
|
|
|
|
$data = []; |
|
|
|
|
|
$dataLabels = []; |
|
|
|
|
|
|
|
|
$start = new \DateTime($year.'-01-01'); |
|
|
$start = new \DateTime($year.'-01-01'); |
|
|
if($year == date('Y')) { |
|
|
if($year == date('Y')) { |
|
|
$end = new \DateTime('last day of this month'); |
|
|
$end = new \DateTime('last day of this month'); |
|
|
|
|
|
|
|
|
else { |
|
|
else { |
|
|
$end = new \DateTime($year.'-12-31'); |
|
|
$end = new \DateTime($year.'-12-31'); |
|
|
} |
|
|
} |
|
|
$period = new \DatePeriod($start, $interval, $end); |
|
|
|
|
|
|
|
|
|
|
|
$data = []; |
|
|
|
|
|
$dataLabels = []; |
|
|
|
|
|
|
|
|
$interval = new \DateInterval(($displayBy == 'week') ? 'P1W' : 'P1M'); |
|
|
|
|
|
$period = new \DatePeriod($start, $interval, $end); |
|
|
|
|
|
|
|
|
foreach ($period as $date) { |
|
|
|
|
|
$month = $date->format('m/Y'); |
|
|
|
|
|
$dataLabels[] = $month; |
|
|
|
|
|
$turnover = $this->getTurnover($producer, $date->format('Y-m')); |
|
|
|
|
|
$data[$month] = $turnover; |
|
|
|
|
|
|
|
|
if($displayBy == 'week') { |
|
|
|
|
|
foreach ($period as $date) { |
|
|
|
|
|
$week = $date->format('W'); |
|
|
|
|
|
$dataLabels[] = $week; |
|
|
|
|
|
$turnover = $this->getTurnoverByWeek($producer, $year, $date->format('W')); |
|
|
|
|
|
$data[$week] = $turnover; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
foreach ($period as $date) { |
|
|
|
|
|
$month = $date->format('m/Y'); |
|
|
|
|
|
$dataLabels[] = $month; |
|
|
|
|
|
$turnover = $this->getTurnover($producer, $date->format('Y-m')); |
|
|
|
|
|
$data[$month] = $turnover; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// création d'un tableau sans index car chart.js n'accepte pas les index |
|
|
// création d'un tableau sans index car chart.js n'accepte pas les index |