Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
97.44% |
38 / 39 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| Welcome | |
97.44% |
38 / 39 |
|
50.00% |
1 / 2 |
5 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| __invoke | |
97.37% |
37 / 38 |
|
0.00% |
0 / 1 |
4 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Controller; |
| 6 | |
| 7 | use App\Repository\StoreRepository; |
| 8 | use App\Repository\TransactionRepository; |
| 9 | use App\Service\ChartBuilderService; |
| 10 | use App\Service\TaxService; |
| 11 | use stdClass; |
| 12 | use Symfony\Component\HttpFoundation\Response; |
| 13 | use Symfony\Component\Routing\Attribute\Route; |
| 14 | |
| 15 | #[Route(path: '/', name: 'welcome', methods: ['GET'])] |
| 16 | class Welcome extends BaseController |
| 17 | { |
| 18 | public function __construct(private readonly StoreRepository $storeRepository, private readonly TransactionRepository $transactionRepository, private readonly TaxService $taxService, private readonly ChartBuilderService $chartBuilderService) {} |
| 19 | |
| 20 | public function __invoke(): Response |
| 21 | { |
| 22 | $user = $this->getUser(); |
| 23 | $balances = null; |
| 24 | $chartData = [ |
| 25 | 'headers' => [], |
| 26 | 'monthsDebt' => [], |
| 27 | 'balances' => [], |
| 28 | ]; |
| 29 | if ($user) { |
| 30 | foreach ($this->storeRepository->getActive() as $store) { |
| 31 | $balance = $this->transactionRepository->getSaldo($store); |
| 32 | $chartData['headers'][] = 'Local '.$store->getId(); |
| 33 | $valAlq = $this->taxService->addTax($store->getValAlq()); |
| 34 | |
| 35 | $chartData['monthsDebt'][] = $valAlq !== 0.0 |
| 36 | ? round(-$balance / $valAlq, 1) |
| 37 | : 0; |
| 38 | $chartData['balances'][] = -$balance; |
| 39 | |
| 40 | $s = new stdClass(); |
| 41 | $s->amount = $balance; |
| 42 | $s->store = $store; |
| 43 | |
| 44 | $balances[] = $s; |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | return $this->render( |
| 49 | 'default/index.html.twig', |
| 50 | [ |
| 51 | 'stores' => $user?->getStores(), |
| 52 | 'balances' => $balances, |
| 53 | 'chartBalances' => $this->chartBuilderService->getDashboardChart( |
| 54 | 'Saldo en $', |
| 55 | $chartData['headers'], |
| 56 | $chartData['balances'] |
| 57 | ), |
| 58 | 'chartMonthsDebt' => $this->chartBuilderService->getDashboardChart( |
| 59 | 'Meses de deuda', |
| 60 | $chartData['headers'], |
| 61 | $chartData['monthsDebt'] |
| 62 | ), |
| 63 | 'chargementRequired' => $this->transactionRepository->checkChargementRequired(), |
| 64 | ] |
| 65 | ); |
| 66 | } |
| 67 | } |