src/Controller/DashboardController.php line 33

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Repository\ChildsRepository;
  4. use App\Repository\UserRepository;
  5. use App\Repository\SessionsRepository;
  6. use Symfony\Component\Asset\Package;
  7. use Doctrine\ORM\EntityManagerInterface;
  8. use Symfony\Component\Security\Core\Security;
  9. use Symfony\Component\Asset\VersionStrategy\EmptyVersionStrategy;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. class DashboardController extends AbstractController
  15.     private $childsRepository;
  16.     private $userRepository
  17.     private $sessionsRepository
  18.     private $security;
  19.     public function __construct(ChildsRepository $childsRepositoryUserRepository $userRepositorySessionsRepository $sessionsRepositorySecurity $security)
  20.     {
  21.         $this->childsRepository $childsRepository;
  22.         $this->userRepository $userRepository
  23.         $this->sessionsRepository $sessionsRepository;
  24.         $this->security $security
  25.     }
  26.     #[Route('/dashboard')]
  27.     public function index(): Response
  28.     {
  29.         $current_user $this->security->getUser(); 
  30.         // Show only current stakeholder childs if user is stakeholder
  31.         $assigned_childs = array();
  32.         foreach ($current_user->getChilds() as $value) {
  33.             $assigned_childs[] = $value;
  34.         }
  35.         //if( !empty($assigned_childs) ){
  36.         if( isset($current_user->getRoles()[0]) && $current_user->getRoles()[0] == 'ROLE_STAKEHOLDER' ){
  37.             $childs $this->childsRepository->findByUser($current_user->getId());
  38.             $sessions $this->sessionsRepository->findByUser($current_user->getId()); 
  39.         }else{ 
  40.             $childs $this->childsRepository->findAll(); 
  41.             $sessions $this->sessionsRepository->findAll(); 
  42.         }
  43.         $users $this->userRepository->findByRoles('ROLE_STAKEHOLDER'); 
  44.         $sessions_accounting = array();
  45.         $sessions_accounting[] = $this->sessionsRepository->findByYear(date('Y')); 
  46.         $sessions_accounting[] = $this->sessionsRepository->findByYear(date('Y',strtotime("-1 year"))); 
  47.         $sessions_accounting[] = $this->sessionsRepository->findByYear(date('Y',strtotime("-2 year")));
  48.         return $this->render('dashboard.html.twig', ['childs' => $childs'users' => $users'sessions' => $sessions'sessions_accounting' => $sessions_accounting]);
  49.     }
  50.     #[Route('/accounting')]
  51.     public function accounting(): Response
  52.     {
  53.         $childs $this->childsRepository->findAll(); 
  54.         $users $this->userRepository->findByRoles('ROLE_STAKEHOLDER'); 
  55.         $sessions $this->sessionsRepository->findAll(); 
  56.  
  57.         $sessions_accounting_current $this->sessionsRepository->findByYear(date('Y')); 
  58.         return $this->render('accounting.html.twig', ['childs' => $childs'users' => $users'sessions' => $sessions'sessions_accounting_current' => $sessions_accounting_current]);
  59.     }
  60.     #[Route('/accounting/childreport'name'child_report_all')]
  61.     public function childReportAll(Request $request)
  62.     {
  63.         $rows = array(); 
  64.         $childs $this->childsRepository->findAll();
  65.         $filename 'childs-report-' date('d-m-Y') . '.csv';
  66.         if( !empty($childs) ){
  67.             $rows[] = implode(',', array('Session Date''Domaine''Intervenant''Cout''Contribution''Enfant'));
  68.             foreach( $childs as $child ){ 
  69.                 $childs_sessions $child->getSessions();
  70.         
  71.                 foreach ($childs_sessions as $session) {
  72.                     $total 0;
  73.                     $totalcontribution 0;
  74.                     $userdomains $session->getUser()->getUserdomains(); //Fetch all the userdomains of this session's user
  75.                     $contribution $session->getContribution(); //Fetch the contribution of this session
  76.                     if( !empty($userdomains) ){
  77.                         foreach($userdomains as $userdomain){
  78.                             // Check if the userdomains user and domain matches the sessions'
  79.                             if( $userdomain->getDomains()->getId() == $session->getDomain()->getId() && $userdomain->getUser()->getId() == $session->getUser()->getId() ){
  80.                                 // Add the domain fee in total
  81.                                 $total $total $userdomain->getFee();
  82.                             }
  83.                         }
  84.                     }
  85.                     if( !empty($contribution) ){
  86.                         // Add the session contribution in total contribution
  87.                         $totalcontribution $totalcontribution $contribution->getParentcontribution();
  88.                     }
  89.                     $data = array($session->getDate()->format('d-m-Y'), $session->getDomain()->getName(), $session->getUser()->getFirstname().' '.$session->getUser()->getLastname(), $total$totalcontribution$session->getChild()->getFirstname().' '.$session->getChild()->getLastname());
  90.                     $rows[] = implode(','$data);
  91.                 }
  92.             }
  93.         }
  94.         $content implode("\n"$rows); 
  95.         $response = new Response($content);
  96.         $response->headers->set('Content-Type''text/csv');
  97.         $response->headers->set('Content-Disposition''attachment; filename="' $filename '";');
  98.         return $response;
  99.     }
  100.     #[Route('/accounting/childreport/{id}'name'child_report')]
  101.     public function childReport($idRequest $request)
  102.     {
  103.         $rows = array();
  104.         if( !empty($id) ){
  105.             $child $this->childsRepository->find($id);
  106.             $filename $child->getFirstname() . ' ' $child->getLastname() . '-' date('d-m-Y') . '.csv';
  107.             $childs_sessions $child->getSessions(); // Fetch all sessions of this child
  108.             $rows[] = implode(',', array('Session Date''Domaine''Intervenant''Cout''Contribution'));
  109.             
  110.             foreach ($childs_sessions as $session) {
  111.                 $total 0;
  112.                 $totalcontribution 0;
  113.                 $userdomains $session->getUser()->getUserdomains(); //Fetch all the userdomains of this session's user
  114.                 $contribution $session->getContribution(); //Fetch the contribution of this session
  115.                 if( !empty($userdomains) ){
  116.                     foreach($userdomains as $userdomain){
  117.                         // Check if the userdomains user and domain matches the sessions'
  118.                         if( $userdomain->getDomains()->getId() == $session->getDomain()->getId() && $userdomain->getUser()->getId() == $session->getUser()->getId() ){
  119.                             // Add the domain fee in total
  120.                             $total $total $userdomain->getFee();
  121.                         }
  122.                     }
  123.                 }
  124.                 if( !empty($contribution) ){
  125.                     // Add the session contribution in total contribution
  126.                     $totalcontribution $totalcontribution $contribution->getParentcontribution();
  127.                 }
  128.                 $data = array($session->getDate()->format('d-m-Y'), $session->getDomain()->getName(), $session->getUser()->getFirstname().' '.$session->getUser()->getLastname(), $total$totalcontribution);
  129.                 $rows[] = implode(','$data);
  130.             }
  131.         }
  132.         $content implode("\n"$rows); 
  133.         $response = new Response($content);
  134.         $response->headers->set('Content-Type''text/csv');
  135.         $response->headers->set('Content-Disposition''attachment; filename="' $filename '";');
  136.         return $response;
  137.     }
  138.     #[Route('/accounting/stakeholderreport/{id}'name'stakeholder_report')]
  139.     public function stakeholderReport($idRequest $request)
  140.     {
  141.         $rows = array();
  142.         if( !empty($id) ){
  143.             $user $this->userRepository->find($id);
  144.             $filename $user->getFirstname() . ' ' $user->getLastname() . '-' date('d-m-Y') . '.csv';
  145.             $user_sessions $user->getSessions(); // Fetch all sessions of this child
  146.             $rows[] = implode(',', array('Seances Date''Domaine''Enfant''Cout'));
  147.             
  148.             foreach ($user_sessions as $session) {
  149.                 $total 0;
  150.                 $totalcontribution 0;
  151.                 $userdomains $session->getUser()->getUserdomains(); //Fetch all the userdomains of this session's user
  152.                 if( !empty($userdomains) ){
  153.                     foreach($userdomains as $userdomain){
  154.                         // Check if the userdomains user and domain matches the sessions'
  155.                         if( $userdomain->getDomains()->getId() == $session->getDomain()->getId() && $userdomain->getUser()->getId() == $session->getUser()->getId() ){
  156.                             // Add the domain fee in total
  157.                             $total $total $userdomain->getFee();
  158.                         }
  159.                     }
  160.                 } 
  161.                 $data = array($session->getDate()->format('d-m-Y'), $session->getDomain()->getName(), $session->getChild()->getFirstname().' '.$session->getChild()->getLastname(), $total);
  162.                 $rows[] = implode(','$data);
  163.             }
  164.         }
  165.         $content implode("\n"$rows); 
  166.         $response = new Response($content);
  167.         $response->headers->set('Content-Type''text/csv');
  168.         $response->headers->set('Content-Disposition''attachment; filename="' $filename '";');
  169.         return $response;
  170.     }
  171.     #[Route('/accounting/stakeholderreport'name'stakeholder_report_all')]
  172.     public function stakeholderReportAll(Request $request)
  173.     {
  174.         $rows = array();
  175.         $users $this->userRepository->findAll();
  176.         $filename 'stakeholders-report-' date('d-m-Y') . '.csv';
  177.         $rows[] = implode(',', array('Seances Date''Domaine''Enfant''Cout''Intervenant'));
  178.         if( !empty($users) ){
  179.             foreach( $users as $user ){
  180.                 $user_sessions $user->getSessions(); // Fetch all sessions of this user
  181.                 
  182.                 foreach ($user_sessions as $session) {
  183.                     $total 0;
  184.                     $totalcontribution 0;
  185.                     $userdomains $session->getUser()->getUserdomains(); //Fetch all the userdomains of this session's user
  186.                     if( !empty($userdomains) ){
  187.                         foreach($userdomains as $userdomain){
  188.                             // Check if the userdomains user and domain matches the sessions'
  189.                             if( $userdomain->getDomains()->getId() == $session->getDomain()->getId() && $userdomain->getUser()->getId() == $session->getUser()->getId() ){
  190.                                 // Add the domain fee in total
  191.                                 $total $total $userdomain->getFee();
  192.                             }
  193.                         }
  194.                     } 
  195.                     $data = array($session->getDate()->format('d-m-Y'), $session->getDomain()->getName(), $session->getChild()->getFirstname().' '.$session->getChild()->getLastname(), $total$session->getUser()->getFirstname().' '.$session->getUser()->getLastname());
  196.                     $rows[] = implode(','$data);
  197.                 }
  198.             }
  199.         }
  200.         $content implode("\n"$rows); 
  201.         $response = new Response($content);
  202.         $response->headers->set('Content-Type''text/csv');
  203.         $response->headers->set('Content-Disposition''attachment; filename="' $filename '";');
  204.         return $response;
  205.     }
  206.     #[Route('/accounting/sessionreport/'name'session_report')]
  207.     public function sessionReport(Request $request)
  208.     {
  209.         $rows = array(); 
  210.         $sessions $this->sessionsRepository->findAll();
  211.         $filename 'session-report-' date('d-m-Y') . '.csv';
  212.         //$user_sessions = $session->getUser()->getSessions(); // Fetch all sessions of this child
  213.         $rows[] = implode(',', array('Seances Date''Enfant''Stakeholder''Price'));
  214.         
  215.         foreach ($sessions as $session) {
  216.             $total 0;
  217.             $userdomains $session->getUser()->getUserdomains(); //Fetch all the userdomains of this session's user
  218.             if( !empty($userdomains) ){
  219.                 foreach($userdomains as $userdomain){
  220.                     // Check if the userdomains user and domain matches the sessions'
  221.                     if( $userdomain->getDomains()->getId() == $session->getDomain()->getId() && $userdomain->getUser()->getId() == $session->getUser()->getId() ){
  222.                         // Add the domain fee in total
  223.                         $total $total $userdomain->getFee();
  224.                     }
  225.                 }
  226.             } 
  227.             
  228.             $data = array($session->getDate()->format('d-m-Y'), $session->getChild()->getFirstname().' '.$session->getChild()->getLastname(), $session->getUser()->getFirstname().' '.$session->getUser()->getLastname(), $total);
  229.             $rows[] = implode(','$data);
  230.         } 
  231.         $content implode("\n"$rows); 
  232.         $response = new Response($content);
  233.         $response->headers->set('Content-Type''text/csv');
  234.         $response->headers->set('Content-Disposition''attachment; filename="' $filename '";');
  235.         return $response;
  236.     }
  237.     #[Route('/accounting/childexport'name'child_export')]
  238.     public function childExport(Request $request)
  239.     {
  240.         $rows = array(); 
  241.         $childs $this->childsRepository->findAll();
  242.         $filename 'childs-export-' date('d-m-Y') . '.csv';
  243.         if( !empty($childs) ){
  244.             $array array_map("utf8_decode", array('Date de naissance''Nom du père''Téléphone du père''Email du père''Nom de la mère''Téléphone du mère''Nom du médecin''Adresse du médecin''Téléphone du médecin''Email''Nom''Téléphone ''Sexe''Commentaire''Ville Née''Email du mère''Mères Adresse''Code postal''Ville''Status'));
  245.             $rows[] = implode(','$array);
  246.             foreach( $childs as $child ){                
  247.                     $data = array($child->getDob()->format('d-m-Y'), $child->getFathername(), $child->getFatherphone(), $child->getFatheremail(), $child->getMothername(), $child->getMotherphone(), $child->getDoctorname(), $child->getDoctorAddress(), $child->getDoctorPhone(), $child->getEmail(), $child->getFirstname(). ' ' .$child->getLastname(), $child->getPhone(), $child->getGender(), $child->getCommentaire(), $child->getCityborn(), $child->getMotheremail(), $child->getChildaddress(), $child->getChildzipcode(), $child->getChildcity(), $child->getStatus());
  248.                     $rows[] = implode(','$data); 
  249.             }
  250.         }
  251.         $content implode("\n"$rows); 
  252.         $response = new Response($content);
  253.         $response->headers->set('Content-Type''text/csv');
  254.         $response->headers->set('Content-Disposition''attachment; filename="' $filename '";');
  255.         return $response;
  256.     }
  257.     #[Route('/calendar'name'app_calendar')]
  258.     public function calendar(): Response
  259.     {
  260.         return $this->render('calendar.html.twig');
  261.     }
  262. }