Bladeren bron

[Administration] Statistiques > Chiffre d'affaire : affichage du CA en TTC et HT

feature/souke
Guillaume Bourgeois 9 maanden geleden
bovenliggende
commit
28720f0da6
3 gewijzigde bestanden met toevoegingen van 51 en 23 verwijderingen
  1. +6
    -1
      backend/controllers/StatsController.php
  2. +26
    -10
      backend/views/stats/index.php
  3. +19
    -12
      domain/Producer/Producer/ProducerRepository.php

+ 6
- 1
backend/controllers/StatsController.php Bestand weergeven

@@ -74,15 +74,20 @@ class StatsController extends BackendController
$year = date('Y');
}

$isVatNotApplicable = !$producerCurrent->taxRate->value;
$yearsWithTurnoverArray = $this->getProducerModule()->getRepository()->getYearsWithTurnover($producerCurrent);
$dataChartTurnover = $this->getProducerModule()->getRepository()->getDatasChartTurnoverStatistics($producerCurrent, $year, $displayBy);
$dataChartTurnoverWithTax = $this->getProducerModule()->getRepository()->getDatasChartTurnoverStatistics($producerCurrent, $year, $displayBy, true);


return $this->render('index', [
'isVatNotApplicable' => $isVatNotApplicable,
'displayBy' => $displayBy,
'yearCurrent' => $year,
'dataLabels' => $dataChartTurnover['labels'],
'data' => $dataChartTurnover['data'],
'yearsWithTurnoverArray' => $yearsWithTurnoverArray
'dataWithTax' => $dataChartTurnoverWithTax['data'],
'yearsWithTurnoverArray' => $yearsWithTurnoverArray,
]);
}


+ 26
- 10
backend/views/stats/index.php Bestand weergeven

@@ -65,6 +65,31 @@ foreach ($yearsWithTurnoverArray as $year) {
}
echo Html::a($year, ['stats/index', 'year' => $year, 'displayBy' => $displayBy], ['class' => 'btn ' . $classBtn]) . ' ';
}

if($isVatNotApplicable) {
$datasets = [
[
'label' => 'Recettes commandes',
'borderColor' => "#F39C12",
'data' => $data,
]
];
}
else {
$datasets = [
[
'label' => 'Recettes commandes (HT)',
'borderColor' => "#b4b4b4",
'data' => $data,
],
[
'label' => 'Recettes commandes (TTC)',
'borderColor' => "#F39C12",
'data' => $dataWithTax
]
];
}

?>

<?= ChartJs::widget([
@@ -84,16 +109,7 @@ foreach ($yearsWithTurnoverArray as $year) {
],
'data' => [
'labels' => $dataLabels,
'datasets' => [
[
'label' => 'Recettes commandes',
'backgroundColor' => "rgb(255,127,0,0.5)",
'borderColor' => "rgb(255,127,0,1)",
'pointBackgroundColor' => "rgb(255,127,0,1)",
'pointStrokeColor' => "#fff",
'data' => $data
]
]
'datasets' => $datasets
]
]);


+ 19
- 12
domain/Producer/Producer/ProducerRepository.php Bestand weergeven

@@ -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;
}
}

Laden…
Annuleren
Opslaan