src/Controller/MainController.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Customer;
  4. use App\Entity\Service;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Doctrine\ORM\EntityRepository;
  8. class MainController extends AbstractController
  9. {
  10.     private function amount_service_invoiced_lastXmonths($months) {
  11.         $today date('Y-m-d');
  12.         $xmonths_ago date('Y-m-d',strtotime($today ' -' $months ' month'));
  13.         $em $this->getDoctrine()->getManager();
  14.         $sql 'select sum(invoicedamount) as sum from service where invoiced = 1 and invoiced_date >= "' $xmonths_ago '" and invoiced_date <= "' $today '"';
  15.         $sta $em->getConnection()->prepare($sql);
  16.         $sta->execute();
  17.         $res $sta->execute()->fetch();
  18.         return $res['sum'];
  19.     }
  20.     /**
  21.      * @Route("/", name="homepage")
  22.      */
  23.     public function homepage() {
  24.         $num_services $this->getDoctrine()->getRepository(Service::class)->count([]);
  25.         $num_services_started $this->getDoctrine()->getRepository(Service::class)->count(['status' => 1]);
  26.         $num_services_finished $this->getDoctrine()->getRepository(Service::class)->count(['status' => 2]);
  27.         $num_services_invoiced $this->getDoctrine()->getRepository(Service::class)->count(['invoiced' => true]);
  28.         $num_customers $this->getDoctrine()->getRepository(Customer::class)->count([]);
  29.         $amount_service_invoiced_last_month $this->amount_service_invoiced_lastXmonths(1);
  30.         $amount_service_invoiced_last_six_month $this->amount_service_invoiced_lastXmonths(6);;
  31.         return $this->render('main/dashboard.html.twig', [
  32.             'num_services_invoiced' => $num_services_invoiced,
  33.             'amount_service_invoiced_last_month' => $amount_service_invoiced_last_month,
  34.             'amount_service_invoiced_last_six_month' => $amount_service_invoiced_last_six_month,
  35.             'num_services' => $num_services,
  36.             'num_services_started' => $num_services_started,
  37.             'num_services_finished' => $num_services_finished,
  38.             'num_customers' => $num_customers,
  39.         ]);
  40.     }
  41.     public function getUserInfo() {
  42.         $user $this->getUser();
  43.         return $this->render('baseinfo.html.twig', [
  44.             'user' => $user,
  45.         ]);
  46.     }
  47. }