<?php
namespace App\Controller\Admin;
use App\Entity\OvhService;
use App\Entity\OvhVoiceConsumption;
use App\Entity\PhoneCorrespandance;
use App\Repository\CompanyRepository;
use App\Repository\DepartmentsRepository;
use App\Repository\DevisRepository;
use App\Repository\FactureRepository;
use App\Repository\OpportunityRepository;
use App\Repository\OvhServiceRepository;
use App\Repository\OvhVoiceConsumptionRepository;
use App\Repository\RegionsRepository;
use App\Service\Odoo\OddoHistoricalTransactions;
use App\Service\Odoo\TransactionKeys;
use App\Service\Ovh\OvhStatistics;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
use Symfony\Component\Serializer\SerializerInterface;
class TableauBordController extends AbstractController
{
public $em;
private $ovhVoiceConsumptionRepository;
private $serializer;
public function __construct(
EntityManagerInterface $EntityManagerInterface,
OvhVoiceConsumptionRepository $ovhVoiceConsumptionRepository,
SerializerInterface $serializer
) {
$this->em = $EntityManagerInterface;
$this->ovhVoiceConsumptionRepository = $ovhVoiceConsumptionRepository;
$this->serializer = $serializer;
}
#[Route('/admin/cosmos', name: 'app_admin_tableau_bord', options: ["need_permession" => true, "action" => "Afficher", "order" => 3, "module" => "Cosmos", "method" => ["Afficher"]])]
public function index(): Response
{
return $this->render('tableau_bord/cosmos.html.twig', [
'controller_name' => 'TableauBordController',
]);
}
#[Route('/admin/boutique', name: 'app_admin_tableau_ecommerce', options: ["need_permession" => true, "action" => "Afficher", "order" => 4, "module" => "Semi-fermetures", "method" => ["Afficher"]])]
public function boutique(): Response
{
return $this->render('tableau_bord/e_commerce.html.twig', [
//'controller_name' => 'TableauBordController',
]);
}
#[Route('/admin/analytic', name: 'app_admin_tableau_analytic', options: ["need_permession" => true, "action" => "Afficher", "order" => 5, "module" => "Analytics", "method" => ["Afficher"]])]
public function analytic(): Response
{
return $this->render('tableau_bord/analytic.html.twig', [
'controller_name' => 'TableauBordController',
]);
}
#[Route('/admin/semrush', name: 'app_admin_tableau_semrush', options: ["need_permession" => true, "action" => "Afficher", "order" => 6, "module" => "Semrush", "method" => ["Afficher"]])]
public function semrush(): Response
{
return $this->render('tableau_bord/semrush.html.twig', [
'controller_name' => 'TableauBordController',
]);
}
#[Route('/admin/appels-ovh', name: 'app_admin_tableau_appels_ovh', options: ["need_permession" => true, "action" => "Afficher", "order" => 7, "module" => "Appels OVH", "method" => ["Afficher"]])]
public function appels_ovh(OvhServiceRepository $ovhServiceRepository, OvhStatistics $ovhStatistics): Response
{
$services = $ovhServiceRepository->findAll();
$correspendance_list = $this->em->getRepository(PhoneCorrespandance::class)->findAll();
//get all calls by global filter parms
$global_filter_params = [
"interval" => ["from" => (new DateTime())->format('Y-m-d'), "to" => ""],
];
// get response from service
$response = $ovhStatistics->total_appels_recieved_par_site($global_filter_params);
$sites = $response["sites"];
/**
* params used for info of first list table ovh
*/
$appels = [];
$count = 0;
if (!empty($response["sites"])) {
// get first list
$global_filter_params["correspandences"] = $response["sites"][array_key_first($response["sites"])];
$result = $this->ovhVoiceConsumptionRepository->getCallsRecieved($global_filter_params);
$appels_res = $result["list"];
// serialize the data
$appels_res = json_decode($this->serializer->serialize($appels_res, 'json', [AbstractNormalizer::IGNORED_ATTRIBUTES => ['ovhService'], DateTimeNormalizer::FORMAT_KEY => 'Y-m-d H:i:s']), true);
foreach ($appels_res as $appel)
// convert data
$appels[] = array_values($appel);
$count = $result["count"];
}
// get first appel in db and store it in $start_date
$first_appel = $this->ovhVoiceConsumptionRepository->findFirstAppel();
$start_date = (!empty($first_appel)) ? $first_appel->getDate()->format('d/m/Y') : "";
return $this->render('tableau_bord/appels-ovh.html.twig', [
"sites" => array_keys($sites),
"start_date" => $start_date,
"appels" => $appels,
"count" => $count,
"page_number" => ceil($count / 30),
"services_ovh" => $services,
"correspendance_list" => $correspendance_list,
"total_recieved" => $response["Entrant_Sortant"]["total_recieved"],
"total_missed" => $response["Entrant_Sortant"]["total_missed"],
'json_multiligne_appels' => $response["json_charts"]["json_multiligne_appels"],
'json_batton' => $response["json_charts"]["json_batton"],
'json_circle_chart_appel' => $response["json_charts"]["json_circle_chart_appel"],
'json_circle_chart_manque' => $response["json_charts"]["json_circle_chart_manque"],
'colors' => $response["colors"]
//'json_entrant_manquant' => $response["json_charts"]["json_entrant_manquant"],
]);
}
#[Route('/admin/tableau_bord/opportunities-list', name: 'app_admin_tableau_bord_opportunities')]
public function opportunities(OpportunityRepository $opportunityRepository): Response
{
$opportunities = $opportunityRepository->findBy([], ["create_date" => "DESC"],100,0);
return $this->render('tableau_bord/opportunity.html.twig', ["list" => $opportunities]);
}
#[Route('/admin/tableau_bord/devis-list', name: 'app_admin_tableau_bord_devis_list')]
public function devis_list(DevisRepository $devisRepository): Response
{
$devis = $devisRepository->findBy([], ["create_date" => "DESC"],100,0);
return $this->render('tableau_bord/devis-list.html.twig', ["list" => $devis]);
}
#[Route('/admin/tableau_bord/facture-list', name: 'app_admin_tableau_bord_facture_list')]
public function facture_list(FactureRepository $factureRepository): Response
{
$factures = $factureRepository->findBy([], ["create_date" => "DESC"],100,0);
return $this->render('tableau_bord/facture-list.html.twig', ["list" => $factures]);
}
#[Route('/admin/devis', name: 'app_admin_tableau_devis')]
public function devis(RegionsRepository $regionsRepository, CompanyRepository $companyRepository, OddoHistoricalTransactions $oddoHistoricalTransactions): Response
{
$key = TransactionKeys::$array_keys["synchronization"];
// find latest synchronized date
$latest = $oddoHistoricalTransactions->find_last_transaction($key);
// $devis_list = $devisRepository->findBy([], ["create_date"=>"DESC"]);
$regions = $regionsRepository->findBy([], ["name" => "ASC"]);
// forward request
$response = $this->forward(
'App\Controller\Api\TableauBord\ApiDevisController::getStatistiques',
["regions" => $regions]
);
$datas = [
"regions" => $regions,
"companies" => $companyRepository->findAllExcept("Semi Fermetures"),
"last_synchronize_datas" => !empty($latest) ? $latest->getDate()->format('Y-m-d H:i:s') : ""
];
$datas = array_merge($datas, json_decode($response->getContent(), true));
/**
* response params
* [{ ovhVoiceConsumption }] phones_na_devis
* [array] phones_to_devis_facture,
* [array] total_devis_villes_factures
*/
dump(
$datas["circle_devis_sites"],
$datas["circle_devis_sites_chiffre"],
$datas["devis_without_calls"],
$datas["devis_without_sites"],
$datas["expectations_devis"],
$datas["calls_before_devis"],
$datas["devis_regions"],
$datas["devis_departments"],
$datas["devis_villes"],
$datas["departements"],
$datas["list"],
$datas["count"]
);
return $this->render('tableau_bord/devis.html.twig', $datas);
}
}