src/Controller/DashboardController.php line 20

  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Charge;
  4. use App\Entity\Payment;
  5. use App\Repository\EntrepriseRepository;
  6. use App\Repository\SubscriptionRepository;
  7. use App\Repository\UserEntrepriseRepository;
  8. use App\Repository\UserRepository;
  9. use Doctrine\ORM\EntityManagerInterface;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use Symfony\Component\Uid\Uuid;
  14. class DashboardController extends AbstractController
  15. {
  16.     #[Route('/admin'name'app_dashboard')]
  17.     public function index(
  18.         SubscriptionRepository $subscriptionRepository,
  19.         EntrepriseRepository $entrepriseRepository
  20.     ): Response {
  21. //        $users = $userRepository->findAll();
  22. //        foreach ($users as $user){
  23. //            $existing = $userEntrepriseRepository->findOneBy([
  24. //                'user'       => $user,
  25. //                'entreprise' => $user->getEntreprise(),
  26. //            ]);
  27. //            if (!$existing) {
  28. //                if($user->getEntreprise()) {
  29. //                    $link = new UserEntreprise();
  30. //                    $link->setUser($user);
  31. //                    $link->setEntreprise($user->getEntreprise());
  32. //                    $link->setRole('STAFF');
  33. //                    $link->setStatus(true);
  34. //                    $em->persist($link);
  35. //                    $em->flush();
  36. //                }
  37. //            }
  38. //        }
  39. //        $charge = $em->getRepository(Charge::class)->find(1812);
  40. ////        foreach ($charges as $charge){
  41. //            if (!$charge->getPayment()){
  42. //
  43. //                $payment = new Payment();
  44. //                $payment->setCode(Uuid::v4());
  45. //                $payment->setMarchand($charge->getMarchand());
  46. //                $payment->setLocation($charge->getLocation());
  47. //                $payment->setReference($charge->getMarchand()->getPseudo().'-'.uniqid());
  48. //                $payment->setMonth($charge->getMonth());
  49. //                $payment->setYear($charge->getYear());
  50. //                $payment->setPaid(false);
  51. //                $payment->setTotalAmount((float)$charge->getAmount());
  52. //                $payment->setSingleAmount((float)$charge->getAmount());
  53. //
  54. //                $charge->setPayment($payment);
  55. //
  56. //                $em->persist($payment);
  57. //                $em->flush();
  58. //            }
  59. //        }
  60.         $entreprises $entrepriseRepository->findBy(['admin' => $this->getUser()], ['id' => 'DESC']);
  61.         $activeEntreprises count($entrepriseRepository->findBy(['admin' => $this->getUser(), 'status' => true]));
  62.         $allEntrepriseCount count($entreprises);
  63.         $entreprise $entrepriseRepository->findOneBy(['admin' => $this->getUser()]);
  64.         $subscriptionCount count($subscriptionRepository->findBy(['entreprise' => $entreprise'paid' => true]));
  65.         return $this->render('dashboard/index.html.twig', [
  66.             'entreprises' => $entreprises,
  67.             'activeEntreprise' => $activeEntreprises,
  68.             'allEntrepriseCount' => $allEntrepriseCount,
  69.             'subscriptionCount' => $subscriptionCount
  70.         ]);
  71.     }
  72. }