<?php
namespace App\Controller;
use App\Entity\Customer;
use App\Entity\Service;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Doctrine\ORM\EntityRepository;
class MainController extends AbstractController
{
private function amount_service_invoiced_lastXmonths($months) {
$today = date('Y-m-d');
$xmonths_ago = date('Y-m-d',strtotime($today . ' -' . $months . ' month'));
$em = $this->getDoctrine()->getManager();
$sql = 'select sum(invoicedamount) as sum from service where invoiced = 1 and invoiced_date >= "' . $xmonths_ago . '" and invoiced_date <= "' . $today . '"';
$sta = $em->getConnection()->prepare($sql);
$sta->execute();
$res = $sta->execute()->fetch();
return $res['sum'];
}
/**
* @Route("/", name="homepage")
*/
public function homepage() {
$num_services = $this->getDoctrine()->getRepository(Service::class)->count([]);
$num_services_started = $this->getDoctrine()->getRepository(Service::class)->count(['status' => 1]);
$num_services_finished = $this->getDoctrine()->getRepository(Service::class)->count(['status' => 2]);
$num_services_invoiced = $this->getDoctrine()->getRepository(Service::class)->count(['invoiced' => true]);
$num_customers = $this->getDoctrine()->getRepository(Customer::class)->count([]);
$amount_service_invoiced_last_month = $this->amount_service_invoiced_lastXmonths(1);
$amount_service_invoiced_last_six_month = $this->amount_service_invoiced_lastXmonths(6);;
return $this->render('main/dashboard.html.twig', [
'num_services_invoiced' => $num_services_invoiced,
'amount_service_invoiced_last_month' => $amount_service_invoiced_last_month,
'amount_service_invoiced_last_six_month' => $amount_service_invoiced_last_six_month,
'num_services' => $num_services,
'num_services_started' => $num_services_started,
'num_services_finished' => $num_services_finished,
'num_customers' => $num_customers,
]);
}
public function getUserInfo() {
$user = $this->getUser();
return $this->render('baseinfo.html.twig', [
'user' => $user,
]);
}
}