src/Controller/Admin/TableauBordController.php line 74

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Admin;
  3. use App\Entity\OvhService;
  4. use App\Entity\OvhVoiceConsumption;
  5. use App\Entity\PhoneCorrespandance;
  6. use App\Repository\CompanyRepository;
  7. use App\Repository\DepartmentsRepository;
  8. use App\Repository\DevisRepository;
  9. use App\Repository\FactureRepository;
  10. use App\Repository\OpportunityRepository;
  11. use App\Repository\OvhServiceRepository;
  12. use App\Repository\OvhVoiceConsumptionRepository;
  13. use App\Repository\RegionsRepository;
  14. use App\Service\Odoo\OddoHistoricalTransactions;
  15. use App\Service\Odoo\TransactionKeys;
  16. use App\Service\Ovh\OvhStatistics;
  17. use DateTime;
  18. use Doctrine\ORM\EntityManagerInterface;
  19. use Symfony\Component\HttpFoundation\Response;
  20. use Symfony\Component\Routing\Annotation\Route;
  21. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  22. use Symfony\Component\HttpFoundation\Request;
  23. use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
  24. use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
  25. use Symfony\Component\Serializer\SerializerInterface;
  26. class TableauBordController extends AbstractController
  27. {
  28.     public $em;
  29.     private $ovhVoiceConsumptionRepository;
  30.     private  $serializer;
  31.     public function __construct(
  32.         EntityManagerInterface $EntityManagerInterface,
  33.         OvhVoiceConsumptionRepository $ovhVoiceConsumptionRepository,
  34.         SerializerInterface $serializer
  35.     ) {
  36.         $this->em = $EntityManagerInterface;
  37.         $this->ovhVoiceConsumptionRepository = $ovhVoiceConsumptionRepository;
  38.         $this->serializer = $serializer;
  39.     }
  40.     #[Route('/admin/cosmos', name: 'app_admin_tableau_bord', options: ["need_permession" => true, "action" => "Afficher", "order" => 3, "module" => "Cosmos", "method" => ["Afficher"]])]
  41.     public function index(): Response
  42.     {
  43.         return $this->render('tableau_bord/cosmos.html.twig', [
  44.             'controller_name' => 'TableauBordController',
  45.         ]);
  46.     }
  47.     #[Route('/admin/boutique', name: 'app_admin_tableau_ecommerce', options: ["need_permession" => true, "action" => "Afficher", "order" => 4, "module" => "Semi-fermetures", "method" => ["Afficher"]])]
  48.     public function boutique(): Response
  49.     {
  50.         return $this->render('tableau_bord/e_commerce.html.twig', [
  51.             //'controller_name' => 'TableauBordController',
  52.         ]);
  53.     }
  54.     #[Route('/admin/analytic', name: 'app_admin_tableau_analytic', options: ["need_permession" => true, "action" => "Afficher", "order" => 5, "module" => "Analytics", "method" => ["Afficher"]])]
  55.     public function analytic(): Response
  56.     {
  57.         return $this->render('tableau_bord/analytic.html.twig', [
  58.             'controller_name' => 'TableauBordController',
  59.         ]);
  60.     }
  61.     #[Route('/admin/semrush', name: 'app_admin_tableau_semrush', options: ["need_permession" => true, "action" => "Afficher", "order" => 6, "module" => "Semrush", "method" => ["Afficher"]])]
  62.     public function semrush(): Response
  63.     {
  64.         return $this->render('tableau_bord/semrush.html.twig', [
  65.             'controller_name' => 'TableauBordController',
  66.         ]);
  67.     }
  68.     #[Route('/admin/appels-ovh', name: 'app_admin_tableau_appels_ovh', options: ["need_permession" => true, "action" => "Afficher", "order" => 7, "module" => "Appels OVH", "method" => ["Afficher"]])]
  69.     public function appels_ovh(OvhServiceRepository $ovhServiceRepository, OvhStatistics $ovhStatistics): Response
  70.     {
  71.         $services = $ovhServiceRepository->findAll();
  72.         $correspendance_list = $this->em->getRepository(PhoneCorrespandance::class)->findAll();
  73.         //get all calls by global filter parms
  74.         $global_filter_params = [
  75.             "interval" => ["from" => (new DateTime())->format('Y-m-d'), "to" => ""],
  76.         ];
  77.         // get response from service
  78.         $response = $ovhStatistics->total_appels_recieved_par_site($global_filter_params);
  79.         $sites = $response["sites"];
  80.         /**
  81.          * params used for info of first list table ovh
  82.          */
  83.         $appels = [];
  84.         $count = 0;
  85.         if (!empty($response["sites"])) {
  86.             // get first list
  87.             $global_filter_params["correspandences"] = $response["sites"][array_key_first($response["sites"])];
  88.             $result = $this->ovhVoiceConsumptionRepository->getCallsRecieved($global_filter_params);
  89.             $appels_res = $result["list"];
  90.             // serialize the data
  91.             $appels_res = json_decode($this->serializer->serialize($appels_res, 'json', [AbstractNormalizer::IGNORED_ATTRIBUTES => ['ovhService'], DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s']), true);
  92.             foreach ($appels_res as $appel)
  93.                 // convert data
  94.                 $appels[] = array_values($appel);
  95.             $count = $result["count"];
  96.         }
  97.         // get first appel in db and store it in $start_date
  98.         $first_appel = $this->ovhVoiceConsumptionRepository->findFirstAppel();
  99.         $start_date = (!empty($first_appel)) ? $first_appel->getDate()->format('d/m/Y') : "";
  100.         return $this->render('tableau_bord/appels-ovh.html.twig', [
  101.             "sites" => array_keys($sites),
  102.             "start_date" => $start_date,
  103.             "appels" => $appels,
  104.             "count" => $count,
  105.             "page_number" => ceil($count / 30),
  106.             "services_ovh" => $services,
  107.             "correspendance_list" => $correspendance_list,
  108.             "total_recieved" => $response["Entrant_Sortant"]["total_recieved"],
  109.             "total_missed" => $response["Entrant_Sortant"]["total_missed"],
  110.             'json_multiligne_appels' => $response["json_charts"]["json_multiligne_appels"],
  111.             'json_batton' => $response["json_charts"]["json_batton"],
  112.             'json_circle_chart_appel' => $response["json_charts"]["json_circle_chart_appel"],
  113.             'json_circle_chart_manque' => $response["json_charts"]["json_circle_chart_manque"],
  114.             'colors' => $response["colors"]
  115.             //'json_entrant_manquant' => $response["json_charts"]["json_entrant_manquant"],
  116.         ]);
  117.     }
  118.     #[Route('/admin/tableau_bord/opportunities-list', name: 'app_admin_tableau_bord_opportunities')]
  119.     public function opportunities(OpportunityRepository $opportunityRepository): Response
  120.     {
  121.         $opportunities = $opportunityRepository->findBy([], ["create_date" => "DESC"],100,0);
  122.         return $this->render('tableau_bord/opportunity.html.twig', ["list" => $opportunities]);
  123.     }
  124.     #[Route('/admin/tableau_bord/devis-list', name: 'app_admin_tableau_bord_devis_list')]
  125.     public function devis_list(DevisRepository $devisRepository): Response
  126.     {
  127.         $devis = $devisRepository->findBy([], ["create_date" => "DESC"],100,0);
  128.         return $this->render('tableau_bord/devis-list.html.twig', ["list" => $devis]);
  129.     }
  130.     #[Route('/admin/tableau_bord/facture-list', name: 'app_admin_tableau_bord_facture_list')]
  131.     public function facture_list(FactureRepository $factureRepository): Response
  132.     {
  133.         $factures = $factureRepository->findBy([], ["create_date" => "DESC"],100,0);
  134.         return $this->render('tableau_bord/facture-list.html.twig', ["list" => $factures]);
  135.     }
  136.     #[Route('/admin/devis', name: 'app_admin_tableau_devis')]
  137.     public function devis(RegionsRepository $regionsRepository, CompanyRepository $companyRepository, OddoHistoricalTransactions $oddoHistoricalTransactions): Response
  138.     {
  139.         $key = TransactionKeys::$array_keys["synchronization"];
  140.         // find latest synchronized date
  141.         $latest = $oddoHistoricalTransactions->find_last_transaction($key);
  142.         // $devis_list = $devisRepository->findBy([], ["create_date"=>"DESC"]);
  143.         $regions = $regionsRepository->findBy([], ["name" => "ASC"]);
  144.         // forward request
  145.         $response = $this->forward(
  146.             'App\Controller\Api\TableauBord\ApiDevisController::getStatistiques',
  147.             ["regions" => $regions]
  148.         );
  149.         $datas = [
  150.             "regions" => $regions,
  151.             "companies" => $companyRepository->findAllExcept("Semi Fermetures"),
  152.             "last_synchronize_datas" => !empty($latest) ? $latest->getDate()->format('Y-m-d H:i:s') : ""
  153.         ];
  154.         $datas = array_merge($datas, json_decode($response->getContent(), true));
  155.         /**
  156.          * response params
  157.          * [{ ovhVoiceConsumption }] phones_na_devis
  158.          * [array] phones_to_devis_facture,
  159.          * [array] total_devis_villes_factures
  160.          */
  161.         dump(
  162.             $datas["circle_devis_sites"],
  163.             $datas["circle_devis_sites_chiffre"],
  164.             $datas["devis_without_calls"],
  165.             $datas["devis_without_sites"],
  166.             $datas["expectations_devis"],
  167.             $datas["calls_before_devis"],
  168.             $datas["devis_regions"],
  169.             $datas["devis_departments"],
  170.             $datas["devis_villes"],
  171.             $datas["departements"],
  172.             $datas["list"],
  173.             $datas["count"]
  174.         );
  175.         return $this->render('tableau_bord/devis.html.twig', $datas);
  176.     }
  177. }