src/Controller/DashboardController.php line 68

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Repository\GatewayLinkRepository;
  4. use App\Repository\TransactionRepository;
  5. use DateTime;
  6. use Exception;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Symfony\UX\Chartjs\Builder\ChartBuilderInterface;
  11. use Symfony\UX\Chartjs\Model\Chart;
  12. class DashboardController extends AbstractController
  13. {
  14.     private GatewayLinkRepository $GLRepository;
  15.     private TransactionRepository $transactionRepository;
  16.     public function __construct(GatewayLinkRepository $glRepositoryTransactionRepository $transactionRepository)
  17.     {
  18.         $this->GLRepository $glRepository;
  19.         $this->transactionRepository $transactionRepository;
  20.     }
  21.     #[Route('/'name'app_index')]
  22.     public function home(ChartBuilderInterface $chartBuilder): Response
  23.     {
  24.         if (!$this->getUser()) {
  25.             //return $this->redirectToRoute('app_login');
  26.             return $this->render('home.html.twig');
  27.         }
  28.         return $this->redirectToRoute('app_dashboard');
  29.     }
  30.     #[Route('/privacy'name'app_privacy')]
  31.     public function privacy(): Response
  32.     {
  33.         return $this->render('home/privacy.html.twig');
  34.     }
  35.     #[Route('/terms'name'app_terms')]
  36.     public function terms(): Response
  37.     {
  38.         return $this->render('home/terms.html.twig');
  39.     }
  40.     #[Route('/contact'name'app_contact')]
  41.     public function contact(): Response
  42.     {
  43.         return $this->render('home/contact.html.twig');
  44.     }
  45.     #[Route('/getit'name'app_getit')]
  46.     public function getit(): Response
  47.     {
  48.         return $this->render('home/getit.html.twig');
  49.     }
  50.     #[Route('/learn'name'app_learn')]
  51.     public function learn(): Response
  52.     {
  53.         return $this->render('home/getit.html.twig');
  54.     }
  55.     #[Route('/dashboard'name'app_dashboard')]
  56.     public function dashboard(ChartBuilderInterface $chartBuilder): Response
  57.     {
  58.         try {
  59.             $user $this->getUser();
  60.             $tdate = new DateTime();
  61.             $tdate $tdate->modify($user->getTimeZoneAdjustment());
  62.             $tdate = new DateTime($tdate->format($user->getCompletedStartDay()));
  63.             if ($user->getCompletedStart() == 'CQ'){
  64.                 $currentMonth intval($tdate->format('m'));
  65.                 if ($currentMonth <= 3){
  66.                     $tdate = new DateTime($tdate->format('Y') . '-1-1');
  67.                 }elseif  ($currentMonth <= 6){
  68.                     $tdate = new DateTime($tdate->format('Y') . '-4-1');
  69.                 }elseif  ($currentMonth <= 9){
  70.                     $tdate = new DateTime($tdate->format('Y') . '-7-1');
  71.                 }elseif  ($currentMonth <= 12){
  72.                     $tdate = new DateTime($tdate->format('Y') . '-10-1');
  73.                 }
  74.             }
  75.             $tdate $tdate->modify($user->getCompletedStartDayAdjustment());
  76.             $tdate $tdate->modify($user->getTimeZoneReAdjustment());
  77.             $edate = new DateTime();
  78.             $query $this->transactionRepository->createQueryBuilder('t')
  79.                 ->select('t','g')
  80.                 ->leftJoin('t.gateway_link''g')
  81.                 ->andWhere('t.user = :uid1')
  82.                 ->setParameter('uid1'$user->getId())
  83.                 ->andWhere('t.created_at >= :cdate')
  84.                 ->setParameter('cdate'$tdate->format('Y-m-d H:i:s'))
  85.                 ->andWhere('t.created_at < :edate')
  86.                 ->setParameter('edate'$edate->format('Y-m-d H:i:s'));
  87. //            $query->getQuery()
  88. //                ->getResult();
  89.             $ctotal 0.0;
  90.             foreach ($query as $row){
  91.                 $ctotal += 1.00//$row['transactiondata']['actions'][0]['amount'];
  92.             }
  93. //            if (!empty($newquery)){
  94. //                $tdate = $newquery[0]->getCreatedAt();
  95. //                $tdate = $tdate->modify($user->getTimeZoneAdjustment());
  96. ////                $tdate = new DateTime('' . $fdate->format('Y-m-d'));
  97. //                $edate = new DateTime($tdate->format('Y-m-d'));
  98. //                $fdate = new DateTime($tdate->format('Y-m-d'));
  99. //                $fdate = $fdate->modify($user->getTimeZoneReAdjustment());
  100. //                $edate = $edate->modify('+1 day');
  101. //                $edate = $edate->modify($user->getTimeZoneReAdjustment());
  102. //
  103. ////                $this->addFlash('msg_error', 't ' . $tdate->format('Y-m-d H:i:s' . '  e ' . $edate->format('Y-m-d')));
  104. //
  105. //                $query = $this->transactionRepository->createQueryBuilder('t')
  106. //                    ->andWhere('t.user = :uid1')
  107. //                    ->setParameter('uid1', $user->getId())
  108. //                    ->andWhere('t.created_at >= :cdate')
  109. //                    ->setParameter('cdate', $fdate->format('Y-m-d H:i:s'))
  110. //                    ->andWhere('t.created_at < :edate')
  111. //                    ->setParameter('edate', $edate->format('Y-m-d H:i:s'));
  112. //
  113. //                if (!empty($search)) {
  114. //                        $query->andWhere('t.transaction_data LIKE :search')
  115. //                            ->setParameter('search', "%$search%");
  116. //                }
  117. //
  118. //            }
  119. //            else
  120. //            {
  121. //                $tdate = new DateTime('now');
  122. //                $query = [];
  123. //            }
  124.             $dquery $this->transactionRepository->createQueryBuilder('t')
  125.                 ->andWhere('t.user = :uid')
  126.                 ->setParameter('uid'$user->getId())
  127.                 ->orderBy('t.id''DESC')
  128.                 ->distinct()
  129.                 ->getQuery()
  130.                 ->getResult();
  131.             $tdate $tdate->modify($user->getTimeZoneAdjustment());
  132.             $edate $edate->modify($user->getTimeZoneAdjustment());
  133.             return $this->render('dashboard/index.html.twig', [
  134.                 'master' => $this->getUser(),
  135.                 'checks' => 5,
  136.                 'credit_cards' => 47,
  137.                 'other' => 0,
  138.                 'chart_title' => 'Transaction Types the last 30 days',
  139.             ]);
  140.         } catch (Exception $e) {
  141.             $this->addFlash('msg_error'$e->getMessage());
  142.             return $this->redirectToRoute('app_integration_settings');
  143.         }
  144.     }
  145. }