<?php
namespace App\Controller;
use DateTime;
use App\Entity\Log;
use App\Entity\Opco;
use App\Entity\Tuteur;
use App\Entity\LogOpco;
use App\Entity\Echeance;
use App\Entity\Apprenant;
use App\Utils\AjaxContent;
use App\Entity\StatutAccord;
use App\Entity\StatutEcheance;
use App\Entity\CentreFacturation;
use App\Entity\DossierFinancement;
use App\Utils\InfosAdvProGenerator;
use App\Entity\InscriptionFormation;
use App\Utils\InfosAdvPartGenerator;
use App\Form\ReportingInfosAdvProType;
use App\Form\ReportingInfosAdvPartType;
use App\Entity\StatutDossierFinancement;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class DefaultController extends AbstractController
{
/**
* @Route("/", name="homepage")
*/
public function indexAction(Request $request)
{
// $content = $this->renderView("homepage.html.twig");
$dateEche = new \DateTime();
$dateEche1 = new \DateTime();
$dateEche2 = new \DateTime();
// Sauvegarde
$save = $this->getUser()->getSettings('filters');
$listSave = array();
$tab = null;
if(isset($save['dashboard'])) {
$save = $save['dashboard'];
// Tableau des sauvegardes en format json
$tab = json_encode($save);
// Liste des sauvegardes de l'utilisateur
$listSave = array_keys($save);
}
$tabDefault = [];
$tabDefault = json_encode($tabDefault);
// ------------- PEDAGOGIE -------------
$listApprenants = $this->getDoctrine()->getRepository(Apprenant::class)->getApprenantsInactifs($this->getUser()->getId());
$nombreApprenants = sizeof($this->getDoctrine()->getRepository(Apprenant::class)->getApprenantsInactifs($this->getUser()->getId(), true));
// Recupere les inscriptions de l'apprenant
$listInscriptionFormation = array();
foreach($listApprenants as $apprenant) {
$parameters["apprenant"] = $apprenant;
$listInscriptionFormation[$apprenant->getId()] = $this->getDoctrine()->getRepository(InscriptionFormation::class)->sortListInscriptions($parameters);
}
// ------------- TUTORAT -------------
$listTuteurs = $this->getDoctrine()->getRepository(Tuteur::class)->getTuteursInactifs($this->getUser()->getId());
$nombreTuteurs = sizeof($listTuteurs);
// Dossier Financement sans accord
$listDossierFiSa = $this->getDoctrine()->getRepository(DossierFinancement::class)->getSansAccordDashboard();
$nombreDossierFiSa = sizeof($listDossierFiSa);
$actions = array();
$entity = array();
$opco = array();
$status = array();
$centreFacturation = array();
$keyword = "";
$page = 1;
if($this->getUser()->getRole()->getId() == 1){
$logOpco = $this->getDoctrine()->getRepository(LogOpco::class)->listLogsOpco($actions, $entity, $opco, $status, $centreFacturation, $keyword, null, $page);
}else{
$logOpco = $this->getDoctrine()->getRepository(LogOpco::class)->listLogsOpco($actions, $entity, $opco, $status, $centreFacturation, $keyword, $this->getUser(), $page);
}
if($this->getUser()->hasAccessTo("dashboard_adv")){
// ------------- ADV -------------
// PART
$partDossierEnCours = [];
$partDossierTermines = [];
$partAnomalieDossierMontant = [];
$partAnomalieDossierMontantEgal0 = [];
$partAnomalieDossierEcheanceEnRetard = [];
$partDossierEcheanceRefusee = [];
$partDossierEcheanceDepasseeSansFacture = [];
$partCaDuMois = 0;
$partCaEnAttente = 0;
$partCaEnRetard = 0;
// PRO
$proDossierEnCours = [];
$proDossierTermines = [];
$proDossierSansAccord = [];
$proDossierSansAccord2Mois = [];
$proCaDuMois = [];
$proCaEcheanceRetard = [];
$proCaEcheanceEnAttenteEncaissement = [];
$proCaSansAccord = [];
$proDossierEcheancePasseeSansFacture = [];
$proDossierPbMontantTotal = [];
$proDossierMontantTotal0 = [];
$proDossierEcheanceAttenteDepassee14 = [];
$proDossierEcheanceTransmiseDepassee30 = [];
foreach ($this->getDoctrine()->getRepository(DossierFinancement::class)->findExercice() as $dossier) {
// PART
if($dossier->getFinancement()->getId() == 1){
$montantRegle = 0;
$montantTotal = 0;
foreach ($dossier->getEcheances() as $echeance) {
if($echeance->getDate()->format("Y-m-d") >= date("2023-09-01")){
// Montant total des échéances
$montantTotal += $echeance->getMontant();
// Si échéance est validée ou en perte
if($echeance->getStatut()->getId() == 1 || $echeance->getStatut()->getId() == 7){
$montantRegle += $echeance->getMontant();
}
// Si échéance est en attente ou refusée
if($echeance->getStatut()->getId() == 3 || $echeance->getStatut()->getId() == 6){
$partDossierEnCours[] = $dossier;
}
// Si échéance en retard de facturation
if($echeance->getStatut()->getId() == 3 && $echeance->getDate()->modify("+5 jours")->format("Y-m-d") < date("Y-m-d")){
$partAnomalieDossierEcheanceEnRetard[] = $dossier;
}
// Si échéance dépassée sans facture
if($echeance->getDate()->format("Y-m-d") < date("Y-m-d") && $echeance->hasFacture() == false){
$partDossierEcheanceDepasseeSansFacture[] = $dossier;
$partCaEnRetard += $echeance->getMontant();
}
// Si échéance est refusée
if($echeance->getStatut()->getId() == 6){
$partDossierEcheanceRefusee[] = $dossier;
}
// CA du mois
if($echeance->hasFacture() && $echeance->getDate()->format("m/Y") == date("m/Y")){
$partCaDuMois += $echeance->getMontant();
}
// CA en attente
if($echeance->getDate()->format("Y-m-d") < date("Y-m-d") && ($echeance->getStatut()->getId() == 3 || $echeance->getStatut()->getId() == 6)){
$partCaEnAttente += $echeance->getMontant();
}
}
}
// Si montant du dossier est égal au montant réglé
if($dossier->getMontant() == $montantRegle){
$partDossierTermines[] = $dossier;
}
// Si montant du dossier est égal au montant réglé
if($dossier->getDateAdminDebut() >= "2023-09-01" && $dossier->getMontant() != $montantTotal){
$partAnomalieDossierMontant[] = $dossier;
}
// Si montant du dossier est égal au montant réglé
if($dossier->getMontant() == 0 || $montantTotal == 0){
$partAnomalieDossierMontantEgal0[] = $dossier;
}
}
// PRO
else{
$montantRegle = 0;
$montantTotal = 0;
$boolEcheancePasseeSansFacture = false;
$boolEcheanceAttenteDepassee14 = false;
$boolEcheanceTransmiseDepassee30 = false;
foreach ($dossier->getEcheances() as $echeance) {
// Montant total des échéances
$montantTotal += $echeance->getMontant();
// Si échéance est validée ou en perte
if($echeance->getStatut()->getId() == 1 || $echeance->getStatut()->getId() == 7){
$montantRegle += $echeance->getMontant();
}
if($echeance->getDate()->format("Y-m-d") >= date("2023-09-01")){
// Si échéance est en attente ou refusée
if($echeance->getStatut()->getId() == 3){
$proDossierEnCours[] = $dossier;
}
//
if($echeance->hasFacture() && $echeance->getDate()->format("m/Y") == date("m/Y")){
if(isset($proCaDuMois[$echeance->getDossierFinancement()->getFinancement()->getNom()][$echeance->getDossierFinancement()->getInscriptionFormation()->getCentreFacturation()->getNom()])){
$proCaDuMois[$echeance->getDossierFinancement()->getFinancement()->getNom()][$echeance->getDossierFinancement()->getInscriptionFormation()->getCentreFacturation()->getNom()] += $echeance->getMontant();
}else{
$proCaDuMois[$echeance->getDossierFinancement()->getFinancement()->getNom()][$echeance->getDossierFinancement()->getInscriptionFormation()->getCentreFacturation()->getNom()] = $echeance->getMontant();
}
}
// Si échéance en retard de facturation
if($echeance->getStatut()->getId() == 3 && $echeance->getDate()->format("Y-m-d") < date("Y-m-d")){
if(isset($proCaEcheanceRetard[$echeance->getDossierFinancement()->getFinancement()->getNom()][$echeance->getDossierFinancement()->getInscriptionFormation()->getCentreFacturation()->getNom()])){
$proCaEcheanceRetard[$echeance->getDossierFinancement()->getFinancement()->getNom()][$echeance->getDossierFinancement()->getInscriptionFormation()->getCentreFacturation()->getNom()] += $echeance->getMontant();
}else{
$proCaEcheanceRetard[$echeance->getDossierFinancement()->getFinancement()->getNom()][$echeance->getDossierFinancement()->getInscriptionFormation()->getCentreFacturation()->getNom()] = $echeance->getMontant();
}
}
// Si échéance en retard de facturation
if($echeance->getStatut()->getId() == 5){
if(isset($proCaEcheanceEnAttenteEncaissement[$echeance->getDossierFinancement()->getFinancement()->getNom()][$echeance->getDossierFinancement()->getInscriptionFormation()->getCentreFacturation()->getNom()])){
$proCaEcheanceEnAttenteEncaissement[$echeance->getDossierFinancement()->getFinancement()->getNom()][$echeance->getDossierFinancement()->getInscriptionFormation()->getCentreFacturation()->getNom()] += $echeance->getMontant();
}else{
$proCaEcheanceEnAttenteEncaissement[$echeance->getDossierFinancement()->getFinancement()->getNom()][$echeance->getDossierFinancement()->getInscriptionFormation()->getCentreFacturation()->getNom()] = $echeance->getMontant();
}
}
// Si échéance passée sans facture
if($echeance->hasFacture() == false && $echeance->getStatut()->getId() == 3 && $echeance->getDate()->format("Y-m-d") < date("Y-m-d") && $boolEcheancePasseeSansFacture == false){
if(isset($proDossierEcheancePasseeSansFacture[$echeance->getDossierFinancement()->getFinancement()->getNom()][$echeance->getDossierFinancement()->getInscriptionFormation()->getCentreFacturation()->getNom()])){
$proDossierEcheancePasseeSansFacture[$echeance->getDossierFinancement()->getFinancement()->getNom()][$echeance->getDossierFinancement()->getInscriptionFormation()->getCentreFacturation()->getNom()] += 1;
}else{
$proDossierEcheancePasseeSansFacture[$echeance->getDossierFinancement()->getFinancement()->getNom()][$echeance->getDossierFinancement()->getInscriptionFormation()->getCentreFacturation()->getNom()] = 1;
}
$boolEcheancePasseeSansFacture = true;
}
// Si échéance en attente dépassée de +14 jours
if($echeance->getStatut()->getId() == 3 && $echeance->getDate()->modify("+14 jours")->format("Y-m-d") < date("Y-m-d") && $boolEcheanceAttenteDepassee14 == false){
if(isset($proDossierEcheanceAttenteDepassee14[$echeance->getDossierFinancement()->getFinancement()->getNom()][$echeance->getDossierFinancement()->getInscriptionFormation()->getCentreFacturation()->getNom()])){
$proDossierEcheanceAttenteDepassee14[$echeance->getDossierFinancement()->getFinancement()->getNom()][$echeance->getDossierFinancement()->getInscriptionFormation()->getCentreFacturation()->getNom()] += 1;
}else{
$proDossierEcheanceAttenteDepassee14[$echeance->getDossierFinancement()->getFinancement()->getNom()][$echeance->getDossierFinancement()->getInscriptionFormation()->getCentreFacturation()->getNom()] = 1;
}
$boolEcheanceAttenteDepassee14 = true;
}
// Si échéance en attente dépassée de +14 jours
if($echeance->getStatut()->getId() == 5 && $echeance->getDate()->modify("+30 jours")->format("Y-m-d") < date("Y-m-d") && $boolEcheanceTransmiseDepassee30 == false){
if(isset($proDossierEcheanceTransmiseDepassee30[$echeance->getDossierFinancement()->getFinancement()->getNom()][$echeance->getDossierFinancement()->getInscriptionFormation()->getCentreFacturation()->getNom()])){
$proDossierEcheanceTransmiseDepassee30[$echeance->getDossierFinancement()->getFinancement()->getNom()][$echeance->getDossierFinancement()->getInscriptionFormation()->getCentreFacturation()->getNom()] += 1;
}else{
$proDossierEcheanceTransmiseDepassee30[$echeance->getDossierFinancement()->getFinancement()->getNom()][$echeance->getDossierFinancement()->getInscriptionFormation()->getCentreFacturation()->getNom()] = 1;
}
$boolEcheanceTransmiseDepassee30 = true;
}
}
}
// Si montant du dossier est égal au montant réglé
if($dossier->getMontant() == $montantRegle){
$proDossierTermines[] = $dossier;
}
// Si montant du dossier est pas égal au montant total
if($dossier->getMontant() != $montantTotal){
if(isset($proDossierPbMontantTotal[$dossier->getFinancement()->getNom()][$dossier->getInscriptionFormation()->getCentreFacturation()->getNom()])){
$proDossierPbMontantTotal[$dossier->getFinancement()->getNom()][$dossier->getInscriptionFormation()->getCentreFacturation()->getNom()] += 1;
}else{
$proDossierPbMontantTotal[$dossier->getFinancement()->getNom()][$dossier->getInscriptionFormation()->getCentreFacturation()->getNom()] = 1;
}
}
// Si montant du dossier est pas égal au montant total
if($montantTotal == 0 && ($dossier->getStatutAccord() == null or $dossier->getStatutAccord()->getId() == 1)){
if(isset($proDossierMontantTotal0[$dossier->getFinancement()->getNom()][$dossier->getInscriptionFormation()->getCentreFacturation()->getNom()])){
$proDossierMontantTotal0[$dossier->getFinancement()->getNom()][$dossier->getInscriptionFormation()->getCentreFacturation()->getNom()] += 1;
}else{
$proDossierMontantTotal0[$dossier->getFinancement()->getNom()][$dossier->getInscriptionFormation()->getCentreFacturation()->getNom()] = 1;
}
}
// Si montant du dossier est égal au montant réglé
if($dossier->getStatutAccord() != null && $dossier->getStatutAccord()->getId() == 3){
if(isset($proCaSansAccord[$dossier->getFinancement()->getNom()][$dossier->getInscriptionFormation()->getCentreFacturation()->getNom()])){
$proCaSansAccord[$dossier->getFinancement()->getNom()][$dossier->getInscriptionFormation()->getCentreFacturation()->getNom()] += $dossier->getmontant();
}else{
$proCaSansAccord[$dossier->getFinancement()->getNom()][$dossier->getInscriptionFormation()->getCentreFacturation()->getNom()] = $dossier->getmontant();
}
// Si créé depuis plus de 2 mois
if($dossier->getCreatedAt()->modify("+2 months")->format("Y-m-d") < date("Y-m-d")){
$proDossierSansAccord2Mois[] = $dossier;
$proDossierSansAccord[] = $dossier;
}else{
$proDossierSansAccord[] = $dossier;
}
}
}
}
$listCentreFacturation = $this->getDoctrine()->getRepository(CentreFacturation::class)->findBy(["hidden" => 0], []);
$content = $this->renderView("dashboard/dashboard.html.twig",[
"logsOpco" => $logOpco,
"opcos" => $this->getDoctrine()->getRepository(Opco::class)->findAll(),
"centreFacturations" => $this->getDoctrine()->getRepository(CentreFacturation::class)->findBy(["hidden" => 0], []),
"echeances" => $this->getDoctrine()->getRepository(Echeance::class)->findByRefAdmin($dateEche->format("Y-m-d"), $dateEche1->modify("+1days")->format("Y-m-d"), $dateEche2->modify("+2days")->format("Y-m-d"), $this->getDoctrine()->getRepository(StatutEcheance::class)->findOneBy(["id" => 3], []), $this->getUser()),
"echeancesTransmise" => $this->getDoctrine()->getRepository(Echeance::class)->findByRefAdminStatut($this->getDoctrine()->getRepository(StatutEcheance::class)->findOneBy(["id" => 5]), $this->getUser()),
"facture" => false,
"listSave" => $listSave,
"tab" => $tab,
"tabDefault" => $tabDefault,
"listApprenants" => $listApprenants,
"listInscriptionFormation" => $listInscriptionFormation,
"nombreApprenants" => $nombreApprenants,
"listTuteurs" => $listTuteurs,
"nombreTuteurs" => $nombreTuteurs,
"listDossierFiSa" => $listDossierFiSa,
"nombreDossierFiSa" => $nombreDossierFiSa,
"listCentreFacturation" => $listCentreFacturation,
// PART
"nombreDossiersEnCoursPart" => count(array_unique($partDossierEnCours)),
"nombreDossiersTerminesPart" => count(array_unique($partDossierTermines)),
"nombreDossierEcheanceRefuseePart" => count(array_unique($partDossierEcheanceRefusee)),
"nombreDossierEcheanceDepasseeSansFacturePart" => count(array_unique($partDossierEcheanceDepasseeSansFacture)),
"partAnomalieDossierMontant" => count(array_unique($partAnomalieDossierMontant)),
"partAnomalieDossierMontantEgal0" => count(array_unique($partAnomalieDossierMontantEgal0)),
"partAnomalieDossierEcheanceEnRetard" => count(array_unique($partAnomalieDossierEcheanceEnRetard)),
"partCaDuMois" => $partCaDuMois,
"partCaEnAttente" => $partCaEnAttente,
"partCaEnRetard" => $partCaEnRetard,
// PRO
"nombreDossiersEnCoursPro" => count(array_unique($proDossierEnCours)),
"nombreDossiersTerminesPro" => count(array_unique($proDossierTermines)),
"nombreDossiersSansAccordPro" => count(array_unique($proDossierSansAccord)),
"nombreDossiersSansAccord2MoisPro" => count(array_unique($proDossierSansAccord2Mois)),
"proCaDuMois" => $proCaDuMois,
"proCaEcheanceRetard" => $proCaEcheanceRetard,
"proCaEcheanceEnAttenteEncaissement" => $proCaEcheanceEnAttenteEncaissement,
"proCaSansAccord" => $proCaSansAccord,
"proDossierEcheancePasseeSansFacture" => $proDossierEcheancePasseeSansFacture,
"proDossierPbMontantTotal" => $proDossierPbMontantTotal,
"proDossierMontantTotal0" => $proDossierMontantTotal0,
"proDossierEcheanceAttenteDepassee14" => $proDossierEcheanceAttenteDepassee14,
"proDossierEcheanceTransmiseDepassee30" => $proDossierEcheanceTransmiseDepassee30
]);
}else{
$content = $this->renderView("dashboard/dashboard.html.twig",[
"logsOpco" => $logOpco,
"opcos" => $this->getDoctrine()->getRepository(Opco::class)->findAll(),
"centreFacturations" => $this->getDoctrine()->getRepository(CentreFacturation::class)->findBy(["hidden" => 0], []),
"echeances" => $this->getDoctrine()->getRepository(Echeance::class)->findByRefAdmin($dateEche->format("Y-m-d"), $dateEche1->modify("+1days")->format("Y-m-d"), $dateEche2->modify("+2days")->format("Y-m-d"), $this->getDoctrine()->getRepository(StatutEcheance::class)->findOneBy(["id" => 3], []), $this->getUser()),
"echeancesTransmise" => $this->getDoctrine()->getRepository(Echeance::class)->findByRefAdminStatut($this->getDoctrine()->getRepository(StatutEcheance::class)->findOneBy(["id" => 5]), $this->getUser()),
"facture" => false,
"listSave" => $listSave,
"tab" => $tab,
"tabDefault" => $tabDefault,
"listApprenants" => $listApprenants,
"listInscriptionFormation" => $listInscriptionFormation,
"nombreApprenants" => $nombreApprenants,
"listTuteurs" => $listTuteurs,
"nombreTuteurs" => $nombreTuteurs,
"listDossierFiSa" => $listDossierFiSa,
"nombreDossierFiSa" => $nombreDossierFiSa
]);
}
$response = new Response($content, 200);
$contentLength = strlen($content);
$response->headers->set("Content-Length", $contentLength);
$response->headers->set("Cache-Control", "no-cache");
return $response;
}
/**
* Liste des logs
* @Route("/list/logs/opco", name="list_log_opco")
*/
public function listLogOpco(Request $request)
{
$ajaxContent = new AjaxContent($request);
$formSorting = $ajaxContent->getForm("logOpco_sorting");
$actions = array();
$entity = array();
$opco = array();
$status = array();
$centreFacturation = array();
$dossierFinancement = array();
$keyword = "";
$page = null;
$date1 = null;
$date2 = null;
if(!empty($formSorting)) {
// Actions
if(isset($formSorting["keyword"])) {
$keyword = $formSorting["keyword"];
}
// Actions
if(isset($formSorting["action"])) {
$actions = $formSorting["action"];
}
// Actions
if(isset($formSorting["entity"])) {
$entity = $formSorting["entity"];
}
// Opco
if(isset($formSorting["opco"])) {
$opco = $formSorting["opco"];
}
// Opco
if(isset($formSorting["status"])) {
$status = $formSorting["status"];
}
// Centre facturation
if(isset($formSorting["centreFacturation"])) {
$centreFacturation = $formSorting["centreFacturation"];
}
// Date 1 - Début du créneau
if(isset($formSorting["date1"]) && $formSorting["date1"] !== "") {
$date1 = date_create_immutable_from_format("d/m/Y", $formSorting["date1"]);
}
// Date 2 - Début du créneau
if(isset($formSorting["date2"]) && $formSorting["date2"] !== "") {
$date2 = date_create_immutable_from_format("d/m/Y", $formSorting["date2"]);
}
// Page
if(isset($formSorting["page"])) {
$page = $formSorting["page"];
}
}else {
// Tri par defaut - Page 1
$page = 1;
}
if($this->getUser()->getRole()->getId() == 1){
$logsOpco = $this->getDoctrine()->getRepository(LogOpco::class)->listLogsOpco($actions, $entity, $opco, $status, $centreFacturation, $keyword, null, $page, $date1, $date2);
}else{
$logsOpco = $this->getDoctrine()->getRepository(LogOpco::class)->listLogsOpco($actions, $entity, $opco, $status, $centreFacturation, $keyword, $this->getUser(), $page, $date1, $date2);
}
$opcos = $this->getDoctrine()->getRepository(Opco::class)->findAll();
$centreFacturations = $this->getDoctrine()->getRepository(CentreFacturation::class)->findBy(["hidden" => 0], []);
// Render
return $this->render("dashboard/dashboard.html.twig", array(
"logsOpco" => $logsOpco,
"opcos" => $opcos,
"centreFacturations" => $centreFacturations,
"echeances" => "",
"echeancesTransmise" => "",
"facture" => false,
"listSave" => "",
"tab" => "",
"tabDefault" => "",
"listApprenants" => "",
"listInscriptionFormation" => "",
"listCentreFacturation" => "",
"nombreApprenants" => "",
"listTuteurs" => "",
"nombreTuteurs" => "",
"listDossierFiSa" => "",
"nombreDossierFiSa" => "",
// PART
"nombreDossiersEnCoursPart" => "",
"nombreDossiersTerminesPart" => "",
"nombreDossierEcheanceRefuseePart" => "",
"nombreDossierEcheanceDepasseeSansFacturePart" => "",
"partAnomalieDossierMontant" => "",
"partAnomalieDossierMontantEgal0" => "",
"partAnomalieDossierEcheanceEnRetard" => "",
"partCaDuMois" => "",
"partCaEnAttente" => "",
"partCaEnRetard" => "",
// PRO
"nombreDossiersEnCoursPro" => "",
"nombreDossiersTerminesPro" => "",
"nombreDossiersSansAccordPro" => "",
"nombreDossiersSansAccord2MoisPro" => "",
"proCaDuMois" => "",
"proCaEcheanceRetard" => "",
"proCaEcheanceEnAttenteEncaissement" => "",
"proDossierEcheancePasseeSansFacture" => "",
"proCaSansAccord" => "",
"proDossierPbMontantTotal" => "",
"proDossierMontantTotal0" => "",
"proDossierEcheanceAttenteDepassee14" => "",
"proDossierEcheanceTransmiseDepassee30" => "",
));
}
/**
* Liste des logs
* @Route("/reportin/infos-adv/part", name="reporting_infos_adv_part")
*/
public function reportingInfoAdvPart(Request $request, InfosAdvPartGenerator $documentGenerator){
$ajaxContent = new AjaxContent($request);
$additionalData = $ajaxContent->getAdditionalData();
if($ajaxContent->isMethodGet()) {
$form = $this->createForm(ReportingInfosAdvPartType::class, null, array(
"attr" => [
"class" => "ajax-submit",
"novalidate" => "novalidate",
"data-route" => $this->generateUrl("reporting_infos_adv_part"),
"data-id-container" => "#modal",
"data-container-type" => "modal-file-download",
]
));
// Render form
return $this->render("formulaire-reporting-infos-adv-part-modal.html.twig", [
"form" => $form->createView(),
"title" => "Créer un reporting des infos ADV des parts"
]);
}
else if($ajaxContent->isMethodPost()) {
$form = $this->createForm(ReportingInfosAdvPartType::class, null);
$form->submit($ajaxContent->getForm($form->getName()));
if($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$log = new Log(Log::ACTIONS["DOWNLOAD"], Log::ENTITIES["EXPORT_REPORTING"], null, null, null, $this->getUser());
$em->persist($log);
$em->flush();
$dossiers = $this->getDoctrine()->getRepository(DossierFinancement::class)->findExercice();
return $documentGenerator->exportDocument($dossiers);
}
}
else {
// ERROR - Mauvaise methode HTTP
return new Response("Method Not Allowed", 405);
}
}
/**
* Liste des logs
* @Route("/reportin/infos-adv/pro", name="reporting_infos_adv_pro")
*/
public function reportingInfoAdvPro(Request $request, InfosAdvProGenerator $documentGenerator){
$ajaxContent = new AjaxContent($request);
$additionalData = $ajaxContent->getAdditionalData();
if($ajaxContent->isMethodGet()) {
$form = $this->createForm(ReportingInfosAdvProType::class, null, array(
"attr" => [
"class" => "ajax-submit",
"novalidate" => "novalidate",
"data-route" => $this->generateUrl("reporting_infos_adv_pro"),
"data-id-container" => "#modal",
"data-container-type" => "modal-file-download",
]
));
// Render form
return $this->render("formulaire-reporting-infos-adv-pro-modal.html.twig", [
"form" => $form->createView(),
"title" => "Créer un reporting des infos ADV des pros"
]);
}
else if($ajaxContent->isMethodPost()) {
$form = $this->createForm(ReportingInfosAdvProType::class, null);
$form->submit($ajaxContent->getForm($form->getName()));
if($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$log = new Log(Log::ACTIONS["DOWNLOAD"], Log::ENTITIES["EXPORT_REPORTING"], null, null, null, $this->getUser());
$em->persist($log);
$em->flush();
$dossiers = $this->getDoctrine()->getRepository(DossierFinancement::class)->findExercice();
$listCentreFacturation = $this->getDoctrine()->getRepository(CentreFacturation::class)->findBy(["hidden" => 0], []);
return $documentGenerator->exportDocument($dossiers, $listCentreFacturation);
}
}
else {
// ERROR - Mauvaise methode HTTP
return new Response("Method Not Allowed", 405);
}
}
}