瀏覽代碼

[Administration] Statistiques > Chiffre d'affaires : vue semaine par semaine

feature/souke
Guillaume Bourgeois 11 月之前
父節點
當前提交
83dfb7e625
共有 3 個文件被更改,包括 61 次插入19 次删除
  1. +4
    -5
      backend/controllers/StatsController.php
  2. +14
    -1
      backend/views/stats/index.php
  3. +43
    -13
      common/logic/Producer/Producer/Repository/ProducerRepository.php

+ 4
- 5
backend/controllers/StatsController.php 查看文件

@@ -67,19 +67,18 @@ class StatsController extends BackendController
/**
* Affiche le CA réalisé par mois sur une année donnée
*/
public function actionIndex(int $year = null)
public function actionIndex(int $year = null, string $displayBy = 'month')
{
$producerModule = $this->getProducerModule();
$producerCurrent = $this->getProducerCurrent();

if(!$year) {
$year = date('Y');
}

$yearsWithTurnoverArray = $producerModule->getYearsWithTurnover($producerCurrent);
$dataChartTurnover = $producerModule->getDatasChartTurnoverStatistics($producerCurrent, $year);
$yearsWithTurnoverArray = $this->getProducerModule()->getRepository()->getYearsWithTurnover($producerCurrent);
$dataChartTurnover = $this->getProducerModule()->getRepository()->getDatasChartTurnoverStatistics($producerCurrent, $year, $displayBy);

return $this->render('index', [
'displayBy' => $displayBy,
'yearCurrent' => $year,
'dataLabels' => $dataChartTurnover['labels'],
'data' => $dataChartTurnover['data'],

+ 14
- 1
backend/views/stats/index.php 查看文件

@@ -44,13 +44,26 @@ $this->addBreadcrumb('Statistiques (chiffre d\'affaire)') ;

?>

Affichage :
<?php
echo Html::a('Mois',
['stats/index', 'year' => $yearCurrent, 'displayBy' => 'month'],
['class' => 'btn btn-xs '.(($displayBy == 'month') ? 'btn-primary' : 'btn-default')]).' ';
echo Html::a('Semaine',
['stats/index', 'year' => $yearCurrent, 'displayBy' => 'week'],
['class' => 'btn btn-xs '.(($displayBy == 'week') ? 'btn-primary' : 'btn-default')]).' ';

?>

<br><br>

<?php
foreach($yearsWithTurnoverArray as $year) {
$classBtn = 'btn-default';
if($yearCurrent == $year) {
$classBtn = 'btn-primary';
}
echo Html::a($year, ['stats/index', 'year' => $year], ['class' => 'btn '.$classBtn]).' ';
echo Html::a($year, ['stats/index', 'year' => $year, 'displayBy' => $displayBy], ['class' => 'btn '.$classBtn]).' ';
}
?>


+ 43
- 13
common/logic/Producer/Producer/Repository/ProducerRepository.php 查看文件

@@ -152,6 +152,25 @@ class ProducerRepository extends AbstractRepository
$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();
$command = $connection->createCommand(
'
@@ -160,11 +179,11 @@ class ProducerRepository extends AbstractRepository
WHERE `order`.id = product_order.id_order
AND distribution.id_producer = :id_producer
AND `order`.id_distribution = distribution.id
AND distribution.date > :date_begin
AND distribution.date > :date_start
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
]
);
@@ -198,9 +217,11 @@ class ProducerRepository extends AbstractRepository
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');
if($year == date('Y')) {
$end = new \DateTime('last day of this month');
@@ -208,16 +229,25 @@ class ProducerRepository extends AbstractRepository
else {
$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

Loading…
取消
儲存