<?php
namespace App\Controller\Admin;
use App\Service\PDF\MydReportCouveuse;
use CpChart\Chart\Pie;
use CpChart\Data;
use CpChart\Image;
use Doctrine\DBAL\Connection;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
/**
* @method \App\Entity\Utilisateur getUser()
*/
class DefaultController extends AbstractController
{
private Connection $db;
private EntityManagerInterface $em;
public function __construct(Connection $connection, EntityManagerInterface $manager)
{
$this->db = $connection;
$this->em = $manager;
}
public function indexAction(Request $request): Response
{
$activeStructure = $request->getSession()->get('activeStructure');
$userLevel = $request->getSession()->get('userLevel');
$htmlEffectifs = '';
$dateRef = new \DateTime();
if ($activeStructure->getNiveau() == 10) {
$queryCouveuses = "
SELECT count(*)
FROM couveuse
WHERE datecreation <= '" . $dateRef->format('d/m/Y') . "'
AND (datelabel is not null
AND datelabel <= '" . $dateRef->format('d/m/Y') . "')
";
$dbCouveuses = $this->db->fetchAssociative($queryCouveuses);
$queryTotal = "
SELECT count(*)
FROM couveuse
WHERE datecreation <= '" . $dateRef->format('d/m/Y') . "'
";
$dbTotal = $this->db->fetchAssociative($queryTotal);
$queryCouvBor = "
SELECT count(*)
FROM couveuse
WHERE datecreation <= '" . $dateRef->format('d/m/Y') . "'
AND boreal = true
";
$dbCouvBor = $this->db->fetchAssociative($queryCouvBor);
$queryAntenne = "
SELECT count(a.*)
FROM antenne a, structure s
WHERE a.idstructure = s.idstructure
AND s.idparent IN ( SELECT s.idstructure FROM structure s, couveuse c WHERE c.idstructure = s.idstructure AND c.datecreation <= '" . $dateRef->format('d/m/Y') . "' AND (c.datelabel is not null AND c.datelabel <= '" . $dateRef->format('d/m/Y') . "') )";
$dbAntenne = $this->db->fetchAssociative($queryAntenne);
$queryDept = "
SELECT COUNT(DISTINCT(substring( s.codepostal, 1, 2 )))
FROM couveuse c, structure s
WHERE c.idstructure = s.idstructure
AND datecreation <= '" . $dateRef->format('d/m/Y') . "'
AND (datelabel is not null
AND datelabel <= '" . $dateRef->format('d/m/Y') . "')
";
$dbDept = $this->db->fetchAssociative($queryDept);
$effectifsUCE = ["couveuses" => $dbCouveuses['count'], "total" => $dbTotal['count'], "boreal" => $dbCouvBor['count'], "antennes" => $dbAntenne['count'], "departements" => $dbDept['count']];
$htmlEffectifs = '
<table id="responsiveTable" class="table table-striped effectifs text-center">
<tr>
<th width="20%" class="candidats">Couveuses du Réseau</th>
<th width="20%" class="prospects">Couveuses labellisées</th>
<th width="20%" class="suivis">Couveuses Boréal</th>
<th width="20%" class="sortis">Antennes</th>
<th width="20%" class="candidats">Départements couverts</th>
</tr>
<tr>
<td width="20%" style="font-size:10px"><span style="font-size:12px">' . $effectifsUCE['total'] . '</span></td>
<td width="20%" style="font-size:10px"><span style="font-size:12px">' . $effectifsUCE['couveuses'] . '</span></td>
<td width="20%" style="font-size:10px"><span style="font-size:12px">' . $effectifsUCE['boreal'] . '</span></td>
<td width="20%" style="font-size:10px"><span style="font-size:12px">' . $effectifsUCE['antennes'] . '</span></td>
<td width="20%" style="font-size:10px"><span style="font-size:12px">' . $effectifsUCE['departements'] . '</span></td>
</tr>
</table>
';
}
if ($activeStructure->getNiveau() == 20) {
$qlistStructures = "SELECT idstructure FROM structure WHERE idparent = " . $activeStructure->getIdstructure();
$listStructures = $this->db->fetchAllAssociative($qlistStructures);
$listStructuresStr = '';
foreach ($listStructures as $struc) {
$listStructuresStr .= $struc['idstructure'] . ',';
}
$listStructuresStr .= $activeStructure->getIdstructure();
// CALCULS EFFECTIFS
$queryProspectOri = "
SELECT count(identrepreneur), SUM(chiffreaff), 0 as tmpetat
FROM entrepreneur
WHERE (dateprospect <= '" . $dateRef->format('d/m/Y') . "')
AND (datecandidat >= '" . $dateRef->format('d/m/Y') . "' OR datecandidat IS NULL)
AND (datecouve >= '" . $dateRef->format('d/m/Y') . "' OR datecouve IS NULL)
AND (datesortie >= '" . $dateRef->format('d/m/Y') . "' OR datesortie IS NULL)
AND idstructure IN (" . $listStructuresStr . ")
AND etat <> 4
";
$dbProspectOri = $this->db->fetchAllAssociative($queryProspectOri);
$queryCandiOri = "
SELECT count(identrepreneur), SUM(chiffreaff), 1 as tmpetat
FROM entrepreneur
WHERE (datecandidat <= '" . $dateRef->format('d/m/Y') . "')
AND (datecouve >= '" . $dateRef->format('d/m/Y') . "' OR datecouve IS NULL)
AND (datesortie >= '" . $dateRef->format('d/m/Y') . "' OR datesortie IS NULL)
AND idstructure IN (" . $listStructuresStr . ")
AND etat <> 4
";
$dbCandiOri = $this->db->fetchAllAssociative($queryCandiOri);
$queryCouveOri = "
SELECT count(identrepreneur), SUM(chiffreaff), 2 as tmpetat
FROM entrepreneur
WHERE(datecouve <= '" . $dateRef->format('d/m/Y') . "')
AND (datesortie >= '" . $dateRef->format('d/m/Y') . "' OR datesortie IS NULL)
AND idstructure IN (" . $listStructuresStr . ")
AND etat <> 4
";
$dbCouveOri = $this->db->fetchAllAssociative($queryCouveOri);
$querySortieOri = "
SELECT count(identrepreneur), SUM(chiffreaff), 3 as tmpetat
FROM entrepreneur
WHERE (datesortie <= '" . $dateRef->format('d/m/Y') . "')
AND idstructure IN (" . $listStructuresStr . ")
AND etat <> 4
";
$dbSortieOri = $this->db->fetchAllAssociative($querySortieOri);
$dbeffectifsOri = [$dbProspectOri[0], $dbCandiOri[0], $dbCouveOri[0], $dbSortieOri[0]];
$effectifsOri = [];
$totalEffectOri = 0;
foreach ($dbeffectifsOri as $eff) {
$totalEffectOri += $eff['count'];
$effectifsOri[$eff['tmpetat']] = $eff;
}
for ($i = 0; $i <= 3; $i++) {
if (!isset($effectifsOri[$i])) {
$effectifsOri[$i] = ["count" => 0, "per" => 0, "sum" => 0];
}
}
$htmlEffectifs .= '
<table id="responsiveTable" class="table table-striped effectifs text-center">
<tr>
<th class="prospects">Prospects</th>
<th class="candidats">Candidats</th>
<th class="suivis">Suivis</th>
<th class="sortis">Sortis</th>
</tr>
<tr>
<td>' . $effectifsOri[0]['count'] . '</td>
<td>' . $effectifsOri[1]['count'] . '</td>
<td>' . $effectifsOri[2]['count'] . '</td>
<td>' . $effectifsOri[3]['count'] . '</td>
</tr>
</table>
';
}
// Liste des années enregistrée
$queryYear = 'SELECT MIN(EXTRACT(YEAR FROM datecreation)) FROM couveuse WHERE idstructure=' . $activeStructure->getIdstructure();
$minYear = $this->db->fetchAssociative($queryYear);
$nowYear = date('Y');
$annees = [];
if ($minYear['min'] != '') {
for ($i = $minYear['min']; $i <= $nowYear; $i++) {
$annees[] = $i;
}
} else {
$annees[] = $nowYear;
}
// Date prospect la plus ancienne
$queryProspect = $this->db->fetchAssociative('SELECT MIN(dateprospect) FROM entrepreneur');
$minProspect = explode('-', $queryProspect['min']);
return $this->render('Admin/Default/index.html.twig', ['activeStructure' => $activeStructure, 'htmlEffectifs' => $htmlEffectifs, 'annees' => $annees, 'minProspect' => $minProspect]);
}
public function topNavAction(Request $request): Response
{
$activeStructure = $request->getSession()->get('activeStructure');
$user = $this->getUser();
$qb = $this->em->createQueryBuilder();
$qb->select('s')
->from(\App\Entity\UtilisateurStructure::class, 'us')
->from(\App\Entity\Structure::class, 's')
->where('s.idstructure = us.idstructure')
->andWhere("us.idutilisateur = " . $this->getUser()->getId())
->andWhere("s.niveau < 30")
->orderBy('s.niveau', 'ASC');
$structures = $qb->getQuery()->getResult();
$qb->select('us');
$droits = $qb->getQuery()->getResult();
$userLevel = '';
foreach ($structures as $struct) {
if ($struct->getIdstructure() == $activeStructure->getIdstructure()) {
$request->getSession()->set('activeStructure', $struct);
foreach ($droits as $droit) {
if ($droit->getIdstructure() == $struct) {
$userLevel = 'membre';
if ($droit->getIssuperv()) {
$userLevel = 'superv';
}
if ($droit->getIsadmin()) {
$userLevel = 'admin';
}
$factuLevel = $droit->getFactuAcces();
$factuAcces = $droit->getFactuLevel();
$request->getSession()->set('userLevel', $userLevel);
$request->getSession()->set('factuAcces', $factuAcces);
$request->getSession()->set('factuLevel', $factuLevel);
}
}
break;
}
}
$countStructures = $this->db->fetchAssociative('SELECT COUNT(*) FROM utilisateur_structure us, structure s WHERE us.idstructure = s.idstructure AND s.niveau < 30 AND us.idutilisateur = ' . $this->getUser()->getId());
// generation du lien vers la facturation
$secretLink = $this->generateUrl('factu_forcelog', [
'iduser' => $user->getId(),
'verifcode' => sha1($user->getId() . $user->getMail()),
'idstructure' => $activeStructure->getIdStructure()
]);
return $this->render('Admin/Default/topNav.html.twig', [
'activeStructure' => $activeStructure,
"countStructures" => $countStructures['count'],
"userLevel" => $userLevel,
"niveauStructure" => $activeStructure->getNiveau(),
'factuAcces' => $factuAcces ?? false,
'factuLevel' => $factuLevel ?? false,
'secretLink' => $secretLink
]);
}
public function listStructuresAction(Request $request): Response
{
$qb = $this->em->createQueryBuilder();
$qb->select('s')
->from(\App\Entity\UtilisateurStructure::class, 'us')
->from(\App\Entity\Structure::class, 's')
->where("us.idutilisateur = " . $this->getUser()->getId())
->andWhere('s.idstructure = us.idstructure')
->andWhere("s.niveau < 30")
->orderBy('s.niveau', 'ASC');
$structures = $qb->getQuery()->getResult();
return $this->render('Admin/Default/listStructures.html.twig', ['structures' => $structures]);
}
public function switchStructureAction(Request $request, $id)
{
$request->getSession()->remove('searchEntrepreneur');
$qb = $this->em->createQueryBuilder();
$qb->select('s')
->from(\App\Entity\UtilisateurStructure::class, 'us')
->from(\App\Entity\Structure::class, 's')
->where('s.idstructure = us.idstructure')
->andWhere("us.idutilisateur = " . $this->getUser()->getId())
->andWhere("s.niveau < 30")
->orderBy('s.niveau', 'ASC');
$structures = $qb->getQuery()->getResult();
$qb->select('us');
$droits = $qb->getQuery()->getResult();
$inStructure = false;
foreach ($structures as $struct) {
if ($struct->getIdstructure() == $id) {
$inStructure = true;
$request->getSession()->set('activeStructure', $struct);
foreach ($droits as $droit) {
if ($droit->getIdstructure() == $struct) {
$userLevel = 'membre';
if ($droit->getIssuperv()) {
$userLevel = 'superv';
}
if ($droit->getIsadmin()) {
$userLevel = 'admin';
}
$request->getSession()->set('userLevel', $userLevel);
}
}
break;
}
}
if (!$inStructure) {
throw new AccessDeniedHttpException();
}
return $this->redirectToRoute('admin_homepage');
}
public function genReportConsolideAction(Request $request): Response
{
$startReport = \DateTime::createFromFormat('d/m/Y', '01/01/' . date('Y'));
$endReport = \DateTime::createFromFormat('d/m/Y', '01/' . $request->get('monthStart') . '/' . date('Y'));
$endReport = date_add($endReport, date_interval_create_from_date_string('1 month'));
$endReport = date_sub($endReport, date_interval_create_from_date_string('1 day'));
$moinzunReport = \DateTime::createFromFormat('d/m/Y', $endReport->format('d/m/Y'));
$moinzunReport = date_sub($moinzunReport, date_interval_create_from_date_string('1 year'));
$rootUri = 'http://' . $_SERVER["HTTP_HOST"] . '/';
$tmpPath = $this->getParameter('kernel.project_dir') . '/public/tmp/';
$report = new MydReportCouveuse($startReport, $endReport, $rootUri, $tmpPath);
$report->initPDF();
$styles = '
<style>
span.h1 { font-size:20pt; margin:2cm; }
span.h2 { font-size:10pt; color:#808080; margin:0px; }
table.title { border-color:#404040; }
table.title td { border-color:#404040; background-color:#404040; color:#ffffff; font-weight:bold; padding:1cm; height:0.5cm; line-height:0.5cm; font-size:12px; }
table.effectifs th{ font-weight:bold; font-size:12px; }
table.effectifs td{ font-size:12px; }
span.small { font-size:10px }
.prospects{ color:#003770 }
.candidats{ color:#008bd2 }
.suivis{ color:#f088b6 }
.sortis{ color:#891e82 }
.gen{ color:#003770 }
.spe{ color:#891e82 }
.genspe{ color:#008bd2 }
.separator{ border-bottom:1px dashed #666666; height:0; line-height:0; }
</style>
';
$report->setStyles($styles);
$report->setEnteteUCE();
$report->addBr(8);
$report->addTitle('Le réseau des Couveuses d’Entreprises');
$queryCouveuses = "SELECT count(*) FROM couveuse WHERE datecreation <= '" . $endReport->format('d/m/Y') . "' AND (datelabel is not null AND datelabel <= '" . $endReport->format('d/m/Y') . "')";
$dbCouveuses = $this->db->fetchAssociative($queryCouveuses);
$queryTotal = "SELECT count(*) FROM couveuse WHERE datecreation <= '" . $endReport->format('d/m/Y') . "'";
$dbTotal = $this->db->fetchAssociative($queryTotal);
$queryCouvLab = "SELECT count(*) FROM couveuse WHERE datecreation <= '" . $endReport->format('d/m/Y') . "' AND (datelabel >= '" . $startReport->format('d/m/Y') . "' AND datelabel <= '" . $endReport->format('d/m/Y') . "')";
$dbCouvLab = $this->db->fetchAssociative($queryCouvLab);
$queryCouvBor = "SELECT count(*) FROM couveuse WHERE datecreation <= '" . $endReport->format('d/m/Y') . "' AND boreal = true";
$dbCouvBor = $this->db->fetchAssociative($queryCouvBor);
$queryAntenne = "
SELECT count(a.*)
FROM antenne a, structure s
WHERE a.idstructure = s.idstructure
AND s.idparent IN (
SELECT s.idstructure
FROM structure s, couveuse c
WHERE c.idstructure = s.idstructure
AND c.datecreation <= '" . $endReport->format('d/m/Y') . "'
AND (c.datelabel is not null AND c.datelabel <= '" . $endReport->format('d/m/Y') . "')
)
";
$dbAntenne = $this->db->fetchAssociative($queryAntenne);
$queryDept = "
SELECT COUNT(DISTINCT(substring( s.codepostal, 1, 2 )))
FROM couveuse c, structure s
WHERE c.idstructure = s.idstructure
AND datecreation <= '" . $endReport->format('d/m/Y') . "'
AND (datelabel is not null AND datelabel <= '" . $endReport->format('d/m/Y') . "')
";
$dbDept = $this->db->fetchAssociative($queryDept);
$effectifsUCE = [
"couveuses" => $dbCouveuses['count'],
"total" => $dbTotal['count'],
"boreal" => $dbCouvBor['count'],
"label" => $dbCouvLab['count'],
"antennes" => $dbAntenne['count'],
"departements" => $dbDept['count']
];
$report->drawEffectifsUCE($effectifsUCE);
$report->addBr(4);
$queryCouveusesAct = "
SELECT DISTINCT(typeactivite), count(idcouveuse)
FROM couveuse
WHERE datecreation <= '" . $endReport->format('d/m/Y') . "'
AND (datelabel is not null AND datelabel <= '" . $endReport->format('d/m/Y') . "')
GROUP BY typeactivite
";
$dbCouveusesAct = $this->db->fetchAllAssociative($queryCouveusesAct);
$qlistActivites = "SELECT * FROM activitecouveuse ORDER BY libelle";
$listActivites = $this->db->fetchAllAssociative($qlistActivites);
$arrAct = [];
foreach ($listActivites as $act) {
$foo = explode(' - ', $act['libelle']);
if (!isset($arrAct[$foo[0]])) {
$arrAct[$foo[0]] = ["ids" => [], "count" => 0];
}
$arrAct[$foo[0]]["ids"][] = ['id' => $act['idactivite'], 'lib' => (isset($foo[1])) ? $foo[1] : '', 'count' => 0];
}
foreach ($arrAct as $lib => $famille) {
foreach ($famille["ids"] as $id) {
foreach ($dbCouveusesAct as $k => $couvAct) {
if ($couvAct['typeactivite'] == $id['id']) {
$arrAct[$lib]['count'] += $couvAct['count'];
@$arrAct[$lib]['ids'][$k]['count'] += $couvAct['count']; // Notice: Undefined offset
}
}
}
}
$filename = 'rapportcons_act.png';
$libs = [];
$set = [];
foreach ($arrAct as $lib => $famille) {
$libs[] = $lib;
$set[] = $famille['count'];
}
$MyData = new Data();
$MyData->loadPalette($this->getParameter('kernel.project_dir') . "/uce.color", TRUE);
$MyData->addPoints($set, "ScoreA");
$MyData->addPoints($libs, "Labels");
$MyData->setAbscissa("Labels");
$myPicture = new Image(400, 340, $MyData);
$myPicture->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 12, "R" => 80, "G" => 80, "B" => 80]);
$PieChart = new Pie($myPicture, $MyData);
$PieChart->draw2DPie(200, 150, ["WriteValues" => PIE_VALUE_PERCENTAGE, "DataGapAngle" => 10, "DataGapRadius" => 6, "Border" => FALSE, "ValueR" => 0, "ValueG" => 0, "ValueB" => 0, "Radius" => 120]);
$myPicture->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 11, "R" => 80, "G" => 80, "B" => 80]);
$PieChart->drawPieLegend(10, 320, ["Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL]);
$myPicture->render($tmpPath . $filename);
$report->addBr(4);
$report->drawActivites($filename, $arrAct);
$report->pageBreak();
$report->setEnteteCouveuse('consolidation');
$report->addBr(4);
$report->addTitle('Actuellement dans les Couveuses');
// CALCULS EFFECTIFS
$queryProspect = "SELECT count(identrepreneur), SUM(chiffreaff), 0 as tmpetat FROM entrepreneur
WHERE (dateprospect >= '" . $startReport->format('d/m/Y') . "' AND dateprospect <= '" . $endReport->format('d/m/Y') . "')
AND (datecandidat >= '" . $endReport->format('d/m/Y') . "' OR datecandidat IS NULL)
AND (datecouve >= '" . $endReport->format('d/m/Y') . "' OR datecouve IS NULL)
AND (datesortie >= '" . $endReport->format('d/m/Y') . "' OR datesortie IS NULL)
AND etat <> 4";
$dbProspect = $this->db->fetchAllAssociative($queryProspect);
$queryProspectOri = "SELECT count(identrepreneur), SUM(chiffreaff), 0 as tmpetat FROM entrepreneur
WHERE (dateprospect <= '" . $endReport->format('d/m/Y') . "')
AND (datecandidat >= '" . $endReport->format('d/m/Y') . "' OR datecandidat IS NULL)
AND (datecouve >= '" . $endReport->format('d/m/Y') . "' OR datecouve IS NULL)
AND (datesortie >= '" . $endReport->format('d/m/Y') . "' OR datesortie IS NULL)
AND etat <> 4";
$dbProspectOri = $this->db->fetchAllAssociative($queryProspectOri);
$queryCandi = "SELECT count(identrepreneur), SUM(chiffreaff), 1 as tmpetat FROM entrepreneur
WHERE (datecandidat >= '" . $startReport->format('d/m/Y') . "' AND datecandidat <= '" . $endReport->format('d/m/Y') . "')
AND (datecouve >= '" . $endReport->format('d/m/Y') . "' OR datecouve IS NULL)
AND (datesortie >= '" . $endReport->format('d/m/Y') . "' OR datesortie IS NULL)
AND etat <> 4";
$dbCandi = $this->db->fetchAllAssociative($queryCandi);
$queryCandiOri = "SELECT count(identrepreneur), SUM(chiffreaff), 1 as tmpetat FROM entrepreneur
WHERE (datecandidat <= '" . $endReport->format('d/m/Y') . "')
AND (datecouve >= '" . $endReport->format('d/m/Y') . "' OR datecouve IS NULL)
AND (datesortie >= '" . $endReport->format('d/m/Y') . "' OR datesortie IS NULL)
AND etat <> 4";
$dbCandiOri = $this->db->fetchAllAssociative($queryCandiOri);
$queryCouve = "SELECT count(identrepreneur), SUM(chiffreaff), 2 as tmpetat FROM entrepreneur
WHERE (datecouve >= '" . $startReport->format('d/m/Y') . "' AND datecouve <= '" . $endReport->format('d/m/Y') . "')
AND (datesortie >= '" . $endReport->format('d/m/Y') . "' OR datesortie IS NULL)
AND etat <> 4";
$dbCouve = $this->db->fetchAllAssociative($queryCouve);
$queryCouveOri = "SELECT count(identrepreneur), SUM(chiffreaff), 2 as tmpetat FROM entrepreneur
WHERE(datecouve <= '" . $endReport->format('d/m/Y') . "')
AND (datesortie >= '" . $endReport->format('d/m/Y') . "' OR datesortie IS NULL)
AND etat <> 4";
$dbCouveOri = $this->db->fetchAllAssociative($queryCouveOri);
$querySortie = "SELECT count(identrepreneur), SUM(chiffreaff), 3 as tmpetat FROM entrepreneur
WHERE (datesortie >= '" . $startReport->format('d/m/Y') . "' AND datesortie <= '" . $endReport->format('d/m/Y') . "')
AND etat <> 4";
$dbSortie = $this->db->fetchAllAssociative($querySortie);
$querySortieOri = "SELECT count(identrepreneur), SUM(chiffreaff), 3 as tmpetat FROM entrepreneur
WHERE (datesortie <= '" . $endReport->format('d/m/Y') . "')
AND etat <> 4";
$dbSortieOri = $this->db->fetchAllAssociative($querySortieOri);
$dbeffectifs = [$dbProspect[0], $dbCandi[0], $dbCouve[0], $dbSortie[0]];
$dbeffectifsOri = [$dbProspectOri[0], $dbCandiOri[0], $dbCouveOri[0], $dbSortieOri[0]];
$effectifs = [];
$totalEffect = 0;
$totalCA = 0;
foreach ($dbeffectifs as $eff) {
$totalEffect += $eff['count'];
$effectifs[$eff['tmpetat']] = $eff;
}
foreach ($effectifs as $k => $eff) {
$effectifs[$k]['per'] = ($totalEffect != 0) ? $eff['count'] * 100 / $totalEffect : 0;
$effectifs[$k]['sum'] = ($effectifs[$k]['sum'] != '') ? $effectifs[$k]['sum'] : 0;
}
for ($i = 0; $i <= 3; $i++) {
if (!isset($effectifs[$i])) {
$effectifs[$i] = ["count" => 0, "per" => 0, "sum" => 0];
}
}
foreach ($dbeffectifs as $eff) {
$totalCA += $eff['sum'];
}
$effectifsOri = [];
$totalEffectOri = 0;
foreach ($dbeffectifsOri as $eff) {
$totalEffectOri += $eff['count'];
$effectifsOri[$eff['tmpetat']] = $eff;
}
foreach ($effectifs as $k => $eff) {
$effectifsOri[$k]['per'] = ($totalEffectOri != 0) ? $eff['count'] * 100 / $totalEffectOri : 0;
$effectifsOri[$k]['sum'] = ($effectifsOri[$k]['sum'] != '') ? $effectifsOri[$k]['sum'] : 0;
}
for ($i = 0; $i <= 3; $i++) {
if (!isset($effectifsOri[$i])) {
$effectifsOri[$i] = ["count" => 0, "per" => 0, "sum" => 0];
}
}
$report->drawEffectifs($effectifs, $effectifsOri);
$report->addBr();
$report->addLine('<div style="font-size:10px; color:#606060"><strong>Chiffre d’affaires généré</strong> : ' . number_format($totalCA, 2, ",", " ") . ' €</div>');
$report->addBr(4);
$report->addSeparator();
$report->addBr();
// Camemberts sortie
$querySorties = "SELECT DISTINCT(typesortie), count(identrepreneur) FROM entrepreneur
WHERE (datesortie <= '" . $endReport->format('d/m/Y') . "')
AND etat <> 4 GROUP BY typesortie";
$dbSorties = $this->db->fetchAllAssociative($querySorties);
$querySortiesM1 = "SELECT DISTINCT(typesortie), count(identrepreneur) FROM entrepreneur
WHERE (datesortie <= '" . $moinzunReport->format('d/m/Y') . "')
AND etat <> 4 GROUP BY typesortie";
$dbSortiesM1 = $this->db->fetchAllAssociative($querySortiesM1);
$qlistSorties = "SELECT * FROM typesortie ORDER by ordre, libelle";
$listSorties = $this->db->fetchAllAssociative($qlistSorties);
$repSorties = [];
$repSortiesM1 = [];
foreach ($listSorties as $sortie) {
$repSorties[$sortie['libelle']] = 0;
$repSortiesM1[$sortie['libelle']] = 0;
foreach ($dbSorties as $dbs) {
if ($dbs['typesortie'] == $sortie['idtypesortie']) {
$repSorties[$sortie['libelle']] += $dbs['count'];
}
}
foreach ($dbSortiesM1 as $dbsM1) {
if ($dbsM1['typesortie'] == $sortie['idtypesortie']) {
$repSortiesM1[$sortie['libelle']] += $dbsM1['count'];
}
}
}
$filename = 'rapportcons_sort.png';
$this->createDoublePie($filename, $repSortiesM1, $repSorties);
$report->addLine('<div style="font-size:12px; color:#606060; text-align:center"><strong>Types de sorties</strong></div>');
$report->addBr();
$report->addLine('
<table class="effectifs" cellspacing="0" cellpadding="1" border="0" width="100%" align="center">
<tr>
<th width="50%" class="prospects">' . $moinzunReport->format('m/Y') . '</th>
<th width="50%" class="sortis">' . $endReport->format('m/Y') . '</th>
</tr>
</table>
');
$report->addImage($filename);
$report->pageBreak();
$report->addTitle('Diversité des Entrepreneurs');
$report->addBr();
$report->addLine('<div style="font-size:12px; color:#606060; text-align:center"><strong>Femmes / Hommes</strong></div>');
$report->addBr();
$report->addLine('
<table class="effectifs" cellspacing="0" cellpadding="1" border="0" width="100%" align="center">
<tr>
<th width="50%" class="prospects">' . $moinzunReport->format('m/Y') . '</th>
<th width="50%" class="sortis">' . $endReport->format('m/Y') . '</th>
</tr>
</table>
');
// Camemberts civilité
$queryCiv = "SELECT DISTINCT(u.civilite), count(e.identrepreneur) FROM entrepreneur e, utilisateur u
WHERE e.idutilisateur = u.id AND (datecouve <= '" . $endReport->format('d/m/Y') . "')
AND etat <> 4 GROUP BY u.civilite";
$dbCiv = $this->db->fetchAllAssociative($queryCiv);
$queryCivM1 = "SELECT DISTINCT(u.civilite), count(e.identrepreneur) FROM entrepreneur e, utilisateur u
WHERE e.idutilisateur = u.id AND (datecouve <= '" . $moinzunReport->format('d/m/Y') . "')
AND etat <> 4 GROUP BY u.civilite";
$dbCivM1 = $this->db->fetchAllAssociative($queryCivM1);
$repCiv = ['Femmes' => 0, 'Hommes' => 0];
$repCivM1 = ['Femmes' => 0, 'Hommes' => 0];
foreach ($dbCiv as $dbs) {
if ($dbs['civilite'] == 'm') {
$repCiv['Hommes'] += $dbs['count'];
} else {
$repCiv['Femmes'] += $dbs['count'];
}
}
foreach ($dbCivM1 as $dbs) {
if ($dbs['civilite'] == 'm') {
$repCivM1['Hommes'] += $dbs['count'];
} else {
$repCivM1['Femmes'] += $dbs['count'];
}
}
$filename = 'rapportcons_civ.png';
$this->createDoublePie($filename, $repCivM1, $repCiv);
$report->addImage($filename);
$report->addBr();
$report->addSeparator();
$report->addBr();
$report->addLine('<div style="font-size:12px; color:#606060; text-align:center"><strong>Statut Social</strong></div>');
$report->addBr();
$report->addLine('
<table class="effectifs" cellspacing="0" cellpadding="1" border="0" width="100%" align="center">
<tr>
<th width="50%" class="prospects">' . $moinzunReport->format('m/Y') . '</th>
<th width="50%" class="sortis">' . $endReport->format('m/Y') . '</th>
</tr>
</table>
');
// Camemberts statut
$queryStatut = "SELECT DISTINCT(statutsocial), count(identrepreneur) FROM entrepreneur
WHERE (datecouve <= '" . $endReport->format('d/m/Y') . "')
AND etat <> 4 GROUP BY statutsocial";
$dbStatut = $this->db->fetchAllAssociative($queryStatut);
$queryStatutM1 = "SELECT DISTINCT(statutsocial), count(identrepreneur) FROM entrepreneur
WHERE (datecouve <= '" . $moinzunReport->format('d/m/Y') . "')
AND etat <> 4 GROUP BY statutsocial";
$dbStatutM1 = $this->db->fetchAllAssociative($queryStatutM1);
$qlistStatut = "SELECT * FROM statutsocial ORDER by ordre, libelle";
$listStatut = $this->db->fetchAllAssociative($qlistStatut);
$repStatut = [];
$repStatutM1 = [];
foreach ($listStatut as $statut) {
$repStatut[$statut['libelle']] = 0;
$repStatutM1[$statut['libelle']] = 0;
foreach ($dbStatut as $dbs) {
if ($dbs['statutsocial'] == $statut['idstatut']) {
$repStatut[$statut['libelle']] += $dbs['count'];
}
}
foreach ($dbStatutM1 as $dbsM1) {
if ($dbsM1['statutsocial'] == $statut['idstatut']) {
$repStatutM1[$statut['libelle']] += $dbsM1['count'];
}
}
}
$filename = 'rapportcons_statut.png';
$this->createDoublePie($filename, $repStatutM1, $repStatut);
$report->addImage($filename);
$report->pageBreak();
$report->addBr();
$report->addLine('<div style="font-size:12px; color:#606060; text-align:center"><strong>Bénéficiaires du RSA</strong></div>');
$report->addBr();
$report->addLine('
<table class="effectifs" cellspacing="0" cellpadding="1" border="0" width="100%" align="center">
<tr>
<th width="35%" align="right" class="prospects">' . $moinzunReport->format('m/Y') . '</th>
<th width="30%" align="left" class="sortis"></th>
<th width="35%" align="left" class="sortis">' . $endReport->format('m/Y') . '</th>
</tr>
</table>
');
// Camemberts rsa
$queryRSA = "SELECT DISTINCT(rsa), count(identrepreneur) FROM entrepreneur
WHERE (datecouve <= '" . $endReport->format('d/m/Y') . "')
AND etat <> 4 GROUP BY rsa";
$dbRSA = $this->db->fetchAllAssociative($queryRSA);
$queryRSAM1 = "SELECT DISTINCT(rsa), count(identrepreneur) FROM entrepreneur
WHERE (datecouve <= '" . $moinzunReport->format('d/m/Y') . "')
AND etat <> 4 GROUP BY rsa";
$dbRSAM1 = $this->db->fetchAllAssociative($queryRSAM1);
$repRSA = ['Bénéficiaire RSA' => 0, 'Non Bénéficiaire RSA' => 0];
$repRSAM1 = ['Bénéficiaire RSA' => 0, 'Non Bénéficiaire RSA' => 0];
foreach ($dbRSA as $dbs) {
if ($dbs['rsa'] == 't') {
$repRSA['Bénéficiaire RSA'] += $dbs['count'];
} else {
$repRSA['Non Bénéficiaire RSA'] += $dbs['count'];
}
}
foreach ($dbRSAM1 as $dbs) {
if ($dbs['rsa'] == 't') {
$repRSAM1['Bénéficiaire RSA'] += $dbs['count'];
} else {
$repRSAM1['Non Bénéficiaire RSA'] += $dbs['count'];
}
}
$filename = 'rapportcons_rsa.png';
$this->createDoublePie($filename, $repRSAM1, $repRSA);
$report->addImage($filename, '', true, '13cm');
$report->addBr();
$report->addSeparator();
$report->addBr();
$report->addLine('<div style="font-size:12px; color:#606060; text-align:center"><strong>Politique de la ville</strong></div>');
$report->addBr();
$report->addLine('
<table class="effectifs" cellspacing="0" cellpadding="1" border="0" width="100%" align="center">
<tr>
<th width="35%" align="right" class="prospects">' . $moinzunReport->format('m/Y') . '</th>
<th width="30%" align="left" class="sortis"></th>
<th width="35%" align="left" class="sortis">' . $endReport->format('m/Y') . '</th>
</tr>
</table>
');
// Camemberts politiqueville
$queryPol = "SELECT DISTINCT(politiqueville), count(identrepreneur) FROM entrepreneur
WHERE (datecouve <= '" . $endReport->format('d/m/Y') . "')
AND etat <> 4 GROUP BY politiqueville";
$dbPol = $this->db->fetchAllAssociative($queryPol);
$queryPolM1 = "SELECT DISTINCT(politiqueville), count(identrepreneur) FROM entrepreneur
WHERE (datecouve <= '" . $moinzunReport->format('d/m/Y') . "')
AND etat <> 4 GROUP BY politiqueville";
$dbPolM1 = $this->db->fetchAllAssociative($queryPolM1);
$repPol = ['Politique de la ville' => 0, 'Non Politique de la ville' => 0];
$repPolM1 = ['Politique de la ville' => 0, 'Non Politique de la ville' => 0];
foreach ($dbPol as $dbs) {
if ($dbs['politiqueville'] == 't') {
$repPol['Politique de la ville'] += $dbs['count'];
} else {
$repPol['Non Politique de la ville'] += $dbs['count'];
}
}
foreach ($dbPolM1 as $dbs) {
if ($dbs['politiqueville'] == 't') {
$repPolM1['Politique de la ville'] += $dbs['count'];
} else {
$repPolM1['Non Politique de la ville'] += $dbs['count'];
}
}
$filename = 'rapportcons_pol.png';
$this->createDoublePie($filename, $repPolM1, $repPol);
$report->addImage($filename, '', true, '13cm');
$report->addBr();
$report->addSeparator();
$report->addBr();
$report->addLine('<div style="font-size:12px; color:#606060; text-align:center"><strong>Travailleurs handicapés</strong></div>');
$report->addBr();
$report->addLine('
<table class="effectifs" cellspacing="0" cellpadding="1" border="0" width="100%" align="center">
<tr>
<th width="35%" align="right" class="prospects">' . $moinzunReport->format('m/Y') . '</th>
<th width="30%" align="left" class="sortis"></th>
<th width="35%" align="left" class="sortis">' . $endReport->format('m/Y') . '</th>
</tr>
</table>
');
// Camemberts handicap
$queryHand = "SELECT DISTINCT(handicap), count(identrepreneur) FROM entrepreneur
WHERE (datecouve <= '" . $endReport->format('d/m/Y') . "')
AND etat <> 4 GROUP BY handicap";
$dbHand = $this->db->fetchAllAssociative($queryHand);
$queryHandM1 = "SELECT DISTINCT(handicap), count(identrepreneur) FROM entrepreneur
WHERE (datecouve <= '" . $moinzunReport->format('d/m/Y') . "')
AND etat <> 4 GROUP BY handicap";
$dbHandM1 = $this->db->fetchAllAssociative($queryHandM1);
$repHand = ['Travailleurs handicapés' => 0, 'Non Travailleurs handicapés' => 0];
$repHandM1 = ['Travailleurs handicapés' => 0, 'Non Travailleurs handicapés' => 0];
foreach ($dbHand as $dbs) {
if ($dbs['handicap'] == 't') {
$repHand['Travailleurs handicapés'] += $dbs['count'];
} else {
$repHand['Non Travailleurs handicapés'] += $dbs['count'];
}
}
foreach ($dbHandM1 as $dbs) {
if ($dbs['handicap'] == 't') {
$repHandM1['Travailleurs handicapés'] += $dbs['count'];
} else {
$repHandM1['Non Travailleurs handicapés'] += $dbs['count'];
}
}
$filename = 'rapportcons_hand.png';
$this->createDoublePie($filename, $repHandM1, $repHand);
$report->addImage($filename, '', true, '13cm');
$report->pageBreak();
$report->addLine('<div style="font-size:12px; color:#606060; text-align:center"><strong>Age des entrepreneurs</strong></div>');
$report->addBr();
$report->addLine('
<table class="effectifs" cellspacing="0" cellpadding="1" border="0" width="100%" align="center">
<tr>
<th width="50%" class="prospects">' . $moinzunReport->format('m/Y') . '</th>
<th width="50%" class="sortis">' . $endReport->format('m/Y') . '</th>
</tr>
</table>
');
// Camemberts ages
$queryAge = "SELECT CASE
WHEN date_part('year',age(datenaissance)) < 26 THEN 1
WHEN date_part('year',age(datenaissance)) >= 26 AND date_part('year',age(datenaissance)) <= 31 THEN 2
WHEN date_part('year',age(datenaissance)) >= 32 AND date_part('year',age(datenaissance)) <= 45 THEN 3
ELSE 4
END AS tranche, count(identrepreneur) FROM entrepreneur WHERE (datecouve <= '" . $endReport->format('d/m/Y') . "') AND etat <> 4 GROUP BY tranche";
$dbAge = $this->db->fetchAllAssociative($queryAge);
$queryAgeM1 = "SELECT CASE
WHEN date_part('year',age(datenaissance)) < 26 THEN 1
WHEN date_part('year',age(datenaissance)) >= 26 AND date_part('year',age(datenaissance)) <= 31 THEN 2
WHEN date_part('year',age(datenaissance)) >= 32 AND date_part('year',age(datenaissance)) <= 45 THEN 3
ELSE 4
END AS tranche, count(identrepreneur) FROM entrepreneur WHERE (datecouve <= '" . $moinzunReport->format('d/m/Y') . "') AND etat <> 4 GROUP BY tranche";
$dbAgeM1 = $this->db->fetchAllAssociative($queryAgeM1);
$repAge = ["moins de 26 ans" => 0, "26 à 31ans" => 0, "31 à 45 ans" => 0, "plus de 45 ans" => 0];
$repAgeM1 = ["moins de 26 ans" => 0, "26 à 31ans" => 0, "31 à 45 ans" => 0, "plus de 45 ans" => 0];
foreach ($dbAge as $dbs) {
if ($dbs['tranche'] == 1) {
$repAge["moins de 26 ans"] += $dbs['count'];
}
if ($dbs['tranche'] == 2) {
$repAge["26 à 31ans"] += $dbs['count'];
}
if ($dbs['tranche'] == 3) {
$repAge["31 à 45 ans"] += $dbs['count'];
}
if ($dbs['tranche'] == 4) {
$repAge["plus de 45 ans"] += $dbs['count'];
}
}
foreach ($dbAgeM1 as $dbsM1) {
if ($dbsM1['tranche'] == 1) {
$repAgeM1["moins de 26 ans"] += $dbsM1['count'];
}
if ($dbsM1['tranche'] == 2) {
$repAgeM1["26 à 31ans"] += $dbsM1['count'];
}
if ($dbsM1['tranche'] == 3) {
$repAgeM1["31 à 45 ans"] += $dbsM1['count'];
}
if ($dbsM1['tranche'] == 4) {
$repAgeM1["plus de 45 ans"] += $dbsM1['count'];
}
}
$filename = 'rapportcons_age.png';
$this->createDoublePie($filename, $repAgeM1, $repAge);
$report->addImage($filename);
$report->addBr();
$report->addSeparator();
$report->addBr();
$report->addLine('<div style="font-size:12px; color:#606060; text-align:center"><strong>Niveaux de formation</strong></div>');
$report->addBr();
// Tableau formation
$queryFormation = "SELECT DISTINCT(formation), count(identrepreneur) FROM entrepreneur
WHERE (datecouve <= '" . $endReport->format('d/m/Y') . "')
AND etat <> 4 GROUP BY formation";
$dbFormation = $this->db->fetchAllAssociative($queryFormation);
$queryFormationM1 = "SELECT DISTINCT(formation), count(identrepreneur) FROM entrepreneur
WHERE (datecouve <= '" . $moinzunReport->format('d/m/Y') . "')
AND etat <> 4 GROUP BY formation";
$dbFormationM1 = $this->db->fetchAllAssociative($queryFormationM1);
$qlistFormation = "SELECT * FROM formation ORDER by ordre, libelle";
$listFormation = $this->db->fetchAllAssociative($qlistFormation);
$repFormation = [];
$totF = 0;
$repFormationM1 = [];
$totFM1 = 0;
foreach ($listFormation as $statut) {
$repFormation[$statut['libelle']] = 0;
$repFormationM1[$statut['libelle']] = 0;
foreach ($dbFormation as $dbs) {
if ($dbs['formation'] == $statut['idformation']) {
$repFormation[$statut['libelle']] += $dbs['count'];
$totF += $dbs['count'];
}
}
foreach ($dbFormationM1 as $dbsM1) {
if ($dbsM1['formation'] == $statut['idformation']) {
$repFormationM1[$statut['libelle']] += $dbsM1['count'];
$totFM1 += $dbsM1['count'];
}
}
}
foreach ($repFormation as $lib => $count) {
$perc = ($count == 0) ? 0 : $count * 100 / $totF;
$repFormation[$lib] = round($perc, 2);
}
foreach ($repFormationM1 as $lib => $count) {
$perc = ($count == 0) ? 0 : $count * 100 / $totFM1;
$repFormationM1[$lib] = round($perc, 2);
}
$report->drawDoubleTab($moinzunReport->format('m/Y'), $endReport->format('m/Y'), $repFormationM1, $repFormation);
$report->addBr();
$report->addBr();
$report->addSeparator();
$report->addBr();
$report->addLine('<div style="font-size:12px; color:#606060; text-align:center"><strong>5 codes NAF les plus utilisés</strong></div>');
$report->addBr();
// Tableau NAF
$queryNAF = "SELECT DISTINCT(codeape), count(identrepreneur), libelle_naf FROM entrepreneur
LEFT JOIN naf ON (naf.code_naf = entrepreneur.codeape)
WHERE (datecouve <= '" . $endReport->format('d/m/Y') . "')
AND etat <> 4 GROUP BY codeape, libelle_naf ORDER by count DESC LIMIT 5";
$dbNAF = $this->db->fetchAllAssociative($queryNAF);
$queryTot = "SELECT count(identrepreneur) FROM entrepreneur WHERE (datecouve <= '" . $endReport->format('d/m/Y') . "') AND etat <> 4";
$dbTot = $this->db->fetchAssociative($queryTot);
$queryNAFM1 = "SELECT DISTINCT(codeape), count(identrepreneur), libelle_naf FROM entrepreneur
LEFT JOIN naf ON (naf.code_naf = entrepreneur.codeape)
WHERE (datecouve <= '" . $moinzunReport->format('d/m/Y') . "')
AND etat <> 4 GROUP BY codeape, libelle_naf ORDER by count DESC LIMIT 5";
$dbNAFM1 = $this->db->fetchAllAssociative($queryNAFM1);
$queryTotM1 = "SELECT count(identrepreneur) FROM entrepreneur WHERE (datecouve <= '" . $moinzunReport->format('d/m/Y') . "') AND etat <> 4";
$dbTotM1 = $this->db->fetchAssociative($queryTotM1);
$repNAF = [];
$repNAFM1 = [];
foreach ($dbNAF as $dbs) {
if ($dbs['codeape'] != 0) {
$newLib = $dbs['codeape'] . ' - ' . $dbs['libelle_naf'];
} else {
$newLib = 'Indéfini';
}
if (!isset($repNAF[$newLib])) {
$repNAF[$newLib] = $dbs['count'];
}
}
foreach ($dbNAFM1 as $dbs) {
if ($dbs['codeape'] != 0) {
$newLib = $dbs['codeape'] . ' - ' . $dbs['libelle_naf'];
} else {
$newLib = 'Indéfini';
}
if (!isset($repNAFM1[$newLib])) {
$repNAFM1[$newLib] = $dbs['count'];
}
}
foreach ($repNAF as $lib => $count) {
$perc = ($count == 0) ? 0 : $count * 100 / $dbTot['count'];
$repNAF[$lib] = round($perc, 2);
}
foreach ($repNAFM1 as $lib => $count) {
$perc = ($count == 0) ? 0 : $count * 100 / $dbTotM1['count'];
$repNAFM1[$lib] = round($perc, 2);
}
$report->drawDoubleTab($moinzunReport->format('m/Y'), $endReport->format('m/Y'), $repNAFM1, $repNAF, true);
$report->pageBreak();
$report->addTitle('CAPE');
$report->addBr(4);
$report->addLine('<div style="font-size:12px; color:#606060; text-align:center"><strong>Nombre de CAPE signés pendant la période</strong></div>');
$report->addBr(2);
// Tableau CAPE
$queryCAPE = "SELECT count(*) FROM entrepreneur WHERE (debutcape <= '" . $endReport->format('d/m/Y') . "') AND etat <> 4";
$dbCAPE = $this->db->fetchAssociative($queryCAPE);
$queryCAPEM1 = "SELECT count(*) FROM entrepreneur WHERE (debutcape <= '" . $moinzunReport->format('d/m/Y') . "') AND etat <> 4";
$dbCAPEM1 = $this->db->fetchAssociative($queryCAPEM1);
$queryAvenant1 = "SELECT count(*) FROM entrepreneur WHERE (debutavcape1 <= '" . $endReport->format('d/m/Y') . "') AND etat <> 4";
$dbAvenant1 = $this->db->fetchAssociative($queryAvenant1);
$queryAvenant1M1 = "SELECT count(*) FROM entrepreneur WHERE (debutavcape1 <= '" . $moinzunReport->format('d/m/Y') . "') AND etat <> 4";
$dbAvenant1M1 = $this->db->fetchAssociative($queryAvenant1M1);
$queryAvenant2 = "SELECT count(*) FROM entrepreneur WHERE (debutavcape2 <= '" . $endReport->format('d/m/Y') . "') AND etat <> 4";
$dbAvenant2 = $this->db->fetchAssociative($queryAvenant2);
$queryAvenant2M1 = "SELECT count(*) FROM entrepreneur WHERE (debutavcape2 <= '" . $moinzunReport->format('d/m/Y') . "') AND etat <> 4";
$dbAvenant2M1 = $this->db->fetchAssociative($queryAvenant2M1);
if ($dbCAPE['count'] > $dbCAPEM1['count']) {
if ($dbCAPEM1['count'] > 0) {
$perc = ($dbCAPE['count'] * 100 / $dbCAPEM1['count']) - 100;
$libPerc = '(+' . round($perc, 2) . '%)';
} else {
$libPerc = '';
}
} elseif ($dbCAPE['count'] < $dbCAPEM1['count']) {
if ($dbCAPEM1['count'] > 0) {
$perc = ($dbCAPE['count'] * 100 / $dbCAPEM1['count']) - 100;
$libPerc = '(-' . round($perc, 2) . '%)';
} else {
$libPerc = '';
}
} else {
$libPerc = '(=)';
}
$dbCAPE['evol'] = $libPerc;
if ($dbAvenant1['count'] > $dbAvenant1M1['count']) {
if ($dbAvenant1M1['count'] > 0) {
$perc = ($dbAvenant1['count'] * 100 / $dbAvenant1M1['count']) - 100;
$libPerc = '(+' . round($perc, 2) . '%)';
} else {
$libPerc = '';
}
} elseif ($dbAvenant1['count'] < $dbAvenant1M1['count']) {
if ($dbAvenant1M1['count'] > 0) {
$perc = ($dbAvenant1['count'] * 100 / $dbAvenant1M1['count']) - 100;
$libPerc = '(-' . round($perc, 2) . '%)';
} else {
$libPerc = '';
}
} else {
$libPerc = '(=)';
}
$dbAvenant1['evol'] = $libPerc;
if ($dbAvenant2['count'] > $dbAvenant2M1['count']) {
if ($dbAvenant2M1['count'] > 0) {
$perc = ($dbAvenant2['count'] * 100 / $dbAvenant2M1['count']) - 100;
$libPerc = '(+' . round($perc, 2) . '%)';
} else {
$libPerc = '';
}
} elseif ($dbAvenant2['count'] < $dbAvenant2M1['count']) {
if ($dbAvenant2M1['count'] > 0) {
$perc = ($dbAvenant2['count'] * 100 / $dbAvenant2M1['count']) - 100;
$libPerc = '(-' . round($perc, 2) . '%)';
} else {
$libPerc = '';
}
} else {
$libPerc = '(=)';
}
$dbAvenant2['evol'] = $libPerc;
$tableContainerTop = '<table cellspacing="0" cellpadding="0" border="0" width="100%"><tr><td width="25%"></td><td width="50%">';
$tableTop = '<table class="effectifs" cellspacing="0" cellpadding="1" border="0" width="100%" align="center">';
$tableTitle = '
<tr>
<th width="50%" colspan="3" class="prospects">' . $moinzunReport->format('m/Y') . '</th>
<th width="50%" colspan="3" class="sortis">' . $endReport->format('m/Y') . '</th>
</tr>
';
$tableContent = ' <tr><td width="28%" align="left">Cape :</td>
<td width="20%" align="right">' . $dbCAPEM1['count'] . '</td>
<td width="2%" align="left" style="border-right:1px solid #808080"></td>';
$tableContent .= ' <td width="2%"></td>
<td width="28%" align="left"> Cape :</td>
<td width="20%" align="right">' . $dbCAPE['count'] . ' <span class="small">' . $dbCAPE['evol'] . '</span></td></tr>';
$tableContent .= ' <tr><td width="28%" align="left">Avenant 1 :</td>
<td width="20%" align="right">' . $dbAvenant1M1['count'] . '</td>
<td width="2%" align="left" style="border-right:1px solid #808080"></td>';
$tableContent .= ' <td width="2%"></td>
<td width="28%" align="left"> Avenant 1 :</td>
<td width="20%" align="right">' . $dbAvenant1['count'] . ' <span class="small">' . $dbAvenant1['evol'] . '</span></td></tr>';
$tableContent .= '';
$tableContent .= ' <tr><td width="28%" align="left">Avenant 2 :</td>
<td width="20%" align="right">' . $dbAvenant2M1['count'] . '</td>
<td width="2%" align="left" style="border-right:1px solid #808080"></td>';
$tableContent .= ' <td width="2%"></td>
<td width="28%" align="left"> Avenant 2 :</td>
<td width="20%" align="right">' . $dbAvenant2['count'] . ' <span class="small">' . $dbAvenant2['evol'] . '</span></td></tr>';
$tableBottom = '</table>';
$tableContainerBottom = '</td><td width="25%"></td></tr></table>';
$report->addLine($tableContainerTop . $tableTop . $tableTitle . $tableContent . $tableBottom . $tableContainerBottom);
$report->addBr(4);
$report->addSeparator();
$report->addBr(2);
$report->addLine('<div style="font-size:12px; color:#606060; text-align:center"><strong>Durée moyenne des CAPE et avenants</strong></div>');
$report->addBr(2);
// Tableau Durees CAPE
$queryCAPE = "SELECT debutcape, fincape FROM entrepreneur WHERE (debutcape <= '" . $endReport->format('d/m/Y') . "') AND etat <> 4";
$dbCAPE = $this->db->fetchAllAssociative($queryCAPE);
$queryCAPEM1 = "SELECT debutcape, fincape FROM entrepreneur WHERE (debutcape <= '" . $moinzunReport->format('d/m/Y') . "' AND fincape IS NOT NULL ) AND etat <> 4";
$dbCAPEM1 = $this->db->fetchAllAssociative($queryCAPEM1);
$queryAvenant1 = "SELECT debutavcape1, finavcape1 FROM entrepreneur WHERE (debutavcape1 <= '" . $endReport->format('d/m/Y') . "' AND finavcape1 IS NOT NULL ) AND etat <> 4";
$dbAvenant1 = $this->db->fetchAllAssociative($queryAvenant1);
$queryAvenant1M1 = "SELECT debutavcape1, finavcape1 FROM entrepreneur WHERE (debutavcape1 <= '" . $moinzunReport->format('d/m/Y') . "' AND finavcape1 IS NOT NULL ) AND etat <> 4";
$dbAvenant1M1 = $this->db->fetchAllAssociative($queryAvenant1M1);
$queryAvenant2 = "SELECT debutavcape2, finavcape2 FROM entrepreneur WHERE (debutavcape2 <= '" . $endReport->format('d/m/Y') . "' AND finavcape2 IS NOT NULL ) AND etat <> 4";
$dbAvenant2 = $this->db->fetchAllAssociative($queryAvenant2);
$queryAvenant2M1 = "SELECT debutavcape2, finavcape2 FROM entrepreneur WHERE (debutavcape2 <= '" . $moinzunReport->format('d/m/Y') . "' AND finavcape2 IS NOT NULL ) AND etat <> 4";
$dbAvenant2M1 = $this->db->fetchAllAssociative($queryAvenant2M1);
$totCAPE = 0;
foreach ($dbCAPE as $cape) {
$date1 = $cape['debutcape'];
$date2 = $cape['fincape'];
$ts1 = strtotime($date1);
$ts2 = strtotime($date2 . ' + 1 day');
$year1 = date('Y', $ts1);
$year2 = date('Y', $ts2);
$month1 = date('m', $ts1);
$month2 = date('m', $ts2);
$dureecape = (($year2 - $year1) * 12) + ($month2 - $month1);
$totCAPE += $dureecape;
}
$avgCAPE = $totCAPE / count($dbCAPE);
$totCAPEM1 = 0;
foreach ($dbCAPEM1 as $cape) {
$date1 = $cape['debutcape'];
$date2 = $cape['fincape'];
$ts1 = strtotime($date1);
$ts2 = strtotime($date2 . ' + 1 day');
$year1 = date('Y', $ts1);
$year2 = date('Y', $ts2);
$month1 = date('m', $ts1);
$month2 = date('m', $ts2);
$dureecape = (($year2 - $year1) * 12) + ($month2 - $month1);
$totCAPEM1 += $dureecape;
}
$avgCAPEM1 = $totCAPEM1 / count($dbCAPEM1);
$totAvenant1 = 0;
foreach ($dbAvenant1 as $avenant) {
$date1 = $avenant['debutavcape1'];
$date2 = $avenant['finavcape1'];
$ts1 = strtotime($date1);
$ts2 = strtotime($date2 . ' + 1 day');
$year1 = date('Y', $ts1);
$year2 = date('Y', $ts2);
$month1 = date('m', $ts1);
$month2 = date('m', $ts2);
$dureecape = (($year2 - $year1) * 12) + ($month2 - $month1);
$totAvenant1 += $dureecape;
}
$avgAvenant1 = $totAvenant1 / count($dbAvenant1);
$totAvenant1M1 = 0;
foreach ($dbAvenant1M1 as $avenant) {
$date1 = $avenant['debutavcape1'];
$date2 = $avenant['finavcape1'];
$ts1 = strtotime($date1);
$ts2 = strtotime($date2 . ' + 1 day');
$year1 = date('Y', $ts1);
$year2 = date('Y', $ts2);
$month1 = date('m', $ts1);
$month2 = date('m', $ts2);
$dureecape = (($year2 - $year1) * 12) + ($month2 - $month1);
$totAvenant1M1 += $dureecape;
}
$avgAvenant1M1 = $totAvenant1M1 / count($dbAvenant1M1);
$totAvenant2 = 0;
foreach ($dbAvenant2 as $avenant) {
$date1 = $avenant['debutavcape2'];
$date2 = $avenant['finavcape2'];
$ts1 = strtotime($date1);
$ts2 = strtotime($date2 . ' + 1 day');
$year1 = date('Y', $ts1);
$year2 = date('Y', $ts2);
$month1 = date('m', $ts1);
$month2 = date('m', $ts2);
$dureecape = (($year2 - $year1) * 12) + ($month2 - $month1);
$totAvenant2 += $dureecape;
}
$avgAvenant2 = $totAvenant2 / count($dbAvenant2);
$totAvenant2M1 = 0;
foreach ($dbAvenant2M1 as $avenant) {
$date1 = $avenant['debutavcape2'];
$date2 = $avenant['finavcape2'];
$ts1 = strtotime($date1);
$ts2 = strtotime($date2 . ' + 1 day');
$year1 = date('Y', $ts1);
$year2 = date('Y', $ts2);
$month1 = date('m', $ts1);
$month2 = date('m', $ts2);
$dureecape = (($year2 - $year1) * 12) + ($month2 - $month1);
$totAvenant2M1 += $dureecape;
}
$avgAvenant2M1 = $totAvenant2M1 / count($dbAvenant2M1);
$tableContainerTop = '<table cellspacing="0" cellpadding="0" border="0" width="100%"><tr><td width="25%"></td><td width="50%">';
$tableTop = '<table class="effectifs" cellspacing="0" cellpadding="1" border="0" width="100%" align="center">';
$tableTitle = '
<tr>
<th width="50%" colspan="3" class="prospects">' . $moinzunReport->format('m/Y') . '</th>
<th width="50%" colspan="3" class="sortis">' . $endReport->format('m/Y') . '</th>
</tr>
';
$tableContent = ' <tr><td width="28%" align="left">Cape :</td>
<td width="20%" align="right">' . round($avgCAPEM1, 2) . ' mois</td>
<td width="2%" align="left" style="border-right:1px solid #808080"></td>';
$tableContent .= ' <td width="2%"></td>
<td width="28%" align="left"> Cape :</td>
<td width="20%" align="right">' . round($avgCAPE, 2) . ' mois</td></tr>';
$tableContent .= ' <tr><td width="28%" align="left">Avenant 1 :</td>
<td width="20%" align="right">' . round($avgAvenant1M1, 2) . ' mois</td>
<td width="2%" align="left" style="border-right:1px solid #808080"></td>';
$tableContent .= ' <td width="2%"></td>
<td width="28%" align="left"> Avenant 1 :</td>
<td width="20%" align="right">' . round($avgAvenant1, 2) . ' mois</td></tr>';
$tableContent .= '';
$tableContent .= ' <tr><td width="28%" align="left">Avenant 2 :</td>
<td width="20%" align="right">' . round($avgAvenant2M1, 2) . ' mois</td>
<td width="2%" align="left" style="border-right:1px solid #808080"></td>';
$tableContent .= ' <td width="2%"></td>
<td width="28%" align="left"> Avenant 2 :</td>
<td width="20%" align="right">' . round($avgAvenant2, 2) . ' mois</td></tr>';
$tableBottom = '</table>';
$tableContainerBottom = '</td><td width="25%"></td></tr></table>';
$report->addLine($tableContainerTop . $tableTop . $tableTitle . $tableContent . $tableBottom . $tableContainerBottom);
// rapports couveuses
$qlistCouveuses = "SELECT c.idstructure FROM couveuse c, structure s WHERE c.idstructure = s.idstructure ORDER BY s.libelle";
$listCouveuses = $this->db->fetchAllAssociative($qlistCouveuses);
foreach ($listCouveuses as $couv) {
$report->pageBreak();
$report = $this->genReportCouveuse($couv['idstructure'], $startReport, $endReport, $report);
}
$report->output('rapport_consolide_' . $request->get('monthStart') . '_' . date('Y') . '.pdf', 'D');
exit();
}
public function genReportCouveuseAction(Request $request): Response
{
$activeStructure = $request->getSession()->get('activeStructure');
$startReport = \DateTime::createFromFormat('d/m/Y', '01/' . $request->get('monthStart') . '/' . $request->get('yearStart'));
$endReport = \DateTime::createFromFormat('d/m/Y', '01/' . $request->get('monthEnd') . '/' . $request->get('yearEnd'));
// on ajoute un mois puis on retire un jour à la date de fin pour bien couvrir le dernier mois
$endReport = date_add($endReport, date_interval_create_from_date_string('1 month'));
$endReport = date_sub($endReport, date_interval_create_from_date_string('1 day'));
$rootUri = 'http://' . $_SERVER["HTTP_HOST"] . '/';
$tmpPath = $this->getParameter('kernel.project_dir') . '/public/tmp/';
$report = new MydReportCouveuse($startReport, $endReport, $rootUri, $tmpPath);
$styles = '
<style>
span.h1 { font-size:20pt; margin:2cm; }
span.h2 { font-size:10pt; color:#808080; margin:0px; }
table.title { border-color:#404040; }
table.title td { border-color:#404040; background-color:#404040; color:#ffffff; font-weight:bold; padding:1cm; height:0.5cm; line-height:0.5cm; font-size:12px; }
table.effectifs th{ font-weight:bold; font-size:12px; }
table.effectifs td{ font-size:12px; }
span.small { font-size:10px }
.prospects{ color:#003770 }
.candidats{ color:#008bd2 }
.suivis{ color:#f088b6 }
.sortis{ color:#891e82 }
</style>';
$report->setStyles($styles);
$report = $this->genReportCouveuse($activeStructure->getIdstructure(), $startReport, $endReport, $report);
$report->output('rapport_' . strtolower($activeStructure->getLibelle()) . '_' . $startReport->format('m/Y') . '_' . $endReport->format('m/Y') . '.pdf', 'D');
exit();
}
private function genReportCouveuse($idstructure, $startReport, $endReport, $report)
{
$filelist = [];
$importDir = $this->getParameter('import_dir');
$couveuse = $this->db->fetchAssociative('SELECT * FROM structure s, couveuse c WHERE c.idstructure = s.idstructure AND s.idstructure = ' . $idstructure);
$logoDir = $importDir . '/logos/' . $couveuse['idstructure'] . '/';
$report->setCouveuse($couveuse, $logoDir);
$report->initPDF();
$logoDir = $importDir . '/logos/' . $couveuse['idstructure'] . '/';
$tmpPath = $this->getParameter('kernel.project_dir') . '/public/tmp/';
$qlistStructures = "SELECT idstructure FROM structure WHERE idparent = " . $idstructure;
$listStructures = $this->db->fetchAllAssociative($qlistStructures);
$listStructuresStr = '';
foreach ($listStructures as $struc) {
$listStructuresStr .= $struc['idstructure'] . ',';
}
$listStructuresStr .= $idstructure;
$qlistStatut = "SELECT * FROM statutsocial";
$listStatut = $this->db->fetchAllAssociative($qlistStatut);
// CALCULS EFFECTIFS
// Prospects
$queryProspect = "
SELECT count(identrepreneur), SUM(chiffreaff), 0 as tmpetat
FROM entrepreneur
WHERE idstructure IN (" . $listStructuresStr . ")
AND (dateprospect >= '" . $startReport->format('d/m/Y') . "' AND dateprospect <= '" . $endReport->format('d/m/Y') . "')
AND (datecandidat > '" . $endReport->format('d/m/Y') . "' OR datecandidat IS NULL)
AND (datecouve > '" . $endReport->format('d/m/Y') . "' OR datecouve IS NULL)
AND (datesortie > '" . $endReport->format('d/m/Y') . "' OR datesortie IS NULL)
AND etat <> 4
";
$dbProspect = $this->db->fetchAllAssociative($queryProspect);
// Prospects à l'origine
$queryProspectOri = "
SELECT count(identrepreneur), SUM(chiffreaff), 0 as tmpetat
FROM entrepreneur
WHERE idstructure IN (" . $listStructuresStr . ")
AND (dateprospect <= '" . $endReport->format('d/m/Y') . "')
AND (datecandidat > '" . $endReport->format('d/m/Y') . "' OR datecandidat IS NULL)
AND (datecouve > '" . $endReport->format('d/m/Y') . "' OR datecouve IS NULL)
AND (datesortie > '" . $endReport->format('d/m/Y') . "' OR datesortie IS NULL)
AND etat <> 4
";
$dbProspectOri = $this->db->fetchAllAssociative($queryProspectOri);
// Candidats
$queryCandi = "
SELECT count(identrepreneur), SUM(chiffreaff), 1 as tmpetat
FROM entrepreneur
WHERE idstructure IN (" . $listStructuresStr . ")
AND (datecandidat >= '" . $startReport->format('d/m/Y') . "' AND datecandidat <= '" . $endReport->format('d/m/Y') . "')
AND (datecouve > '" . $endReport->format('d/m/Y') . "' OR datecouve IS NULL)
AND (datesortie > '" . $endReport->format('d/m/Y') . "' OR datesortie IS NULL)
AND etat <> 4
";
$dbCandi = $this->db->fetchAllAssociative($queryCandi);
// Candidats à l'origine
$queryCandiOri = "
SELECT count(identrepreneur), SUM(chiffreaff), 1 as tmpetat
FROM entrepreneur
WHERE idstructure IN (" . $listStructuresStr . ")
AND (datecandidat <= '" . $endReport->format('d/m/Y') . "')
AND (datecouve > '" . $endReport->format('d/m/Y') . "' OR datecouve IS NULL)
AND (datesortie > '" . $endReport->format('d/m/Y') . "' OR datesortie IS NULL)
AND etat <> 4
";
$dbCandiOri = $this->db->fetchAllAssociative($queryCandiOri);
// Suivis
$queryCouve = "
SELECT count(identrepreneur), SUM(chiffreaff), 2 as tmpetat FROM entrepreneur
WHERE idstructure IN (" . $listStructuresStr . ")
AND (datecouve >= '" . $startReport->format('d/m/Y') . "' AND datecouve <= '" . $endReport->format('d/m/Y') . "')
AND (datesortie > '" . $endReport->format('d/m/Y') . "' OR datesortie IS NULL)
AND etat <> 4
";
$dbCouve = $this->db->fetchAllAssociative($queryCouve);
// Suivis à l'origine
$queryCouveOri = "
SELECT count(identrepreneur), SUM(chiffreaff), 2 as tmpetat FROM entrepreneur
WHERE idstructure IN (" . $listStructuresStr . ")
AND (datecouve <= '" . $endReport->format('d/m/Y') . "')
AND (datesortie > '" . $endReport->format('d/m/Y') . "' OR datesortie IS NULL)
AND etat <> 4
";
$dbCouveOri = $this->db->fetchAllAssociative($queryCouveOri);
// Sortis
$querySortie = "
SELECT count(identrepreneur), SUM(chiffreaff), 3 as tmpetat FROM entrepreneur
WHERE idstructure IN (" . $listStructuresStr . ")
AND (datesortie >= '" . $startReport->format('d/m/Y') . "' AND datesortie <= '" . $endReport->format('d/m/Y') . "')
AND etat <> 4
";
$dbSortie = $this->db->fetchAllAssociative($querySortie);
// Sortis à l'origine?.
$querySortieOri = "
SELECT count(identrepreneur), SUM(chiffreaff), 3 as tmpetat FROM entrepreneur
WHERE idstructure IN (" . $listStructuresStr . ")
AND (datesortie <= '" . $endReport->format('d/m/Y') . "')
AND etat <> 4
";
$dbSortieOri = $this->db->fetchAllAssociative($querySortieOri);
$dbeffectifs = [$dbProspect[0], $dbCandi[0], $dbCouve[0], $dbSortie[0]];
$dbeffectifsOri = [$dbProspectOri[0], $dbCandiOri[0], $dbCouveOri[0], $dbSortieOri[0]];
$effectifs = [];
$totalEffect = 0;
$totalCA = 0;
foreach ($dbeffectifs as $eff) {
$totalEffect += $eff['count'];
$effectifs[$eff['tmpetat']] = $eff;
}
foreach ($effectifs as $k => $eff) {
$effectifs[$k]['per'] = ($totalEffect != 0) ? $eff['count'] * 100 / $totalEffect : 0;
$effectifs[$k]['sum'] = ($effectifs[$k]['sum'] != '') ? $effectifs[$k]['sum'] : 0;
}
for ($i = 0; $i <= 3; $i++) {
if (!isset($effectifs[$i])) {
$effectifs[$i] = ["count" => 0, "per" => 0, "sum" => 0];
}
}
foreach ($dbeffectifs as $eff) {
$totalCA += $eff['sum'];
}
$effectifsOri = [];
$totalEffectOri = 0;
foreach ($dbeffectifsOri as $eff) {
$totalEffectOri += $eff['count'];
$effectifsOri[$eff['tmpetat']] = $eff;
}
foreach ($effectifs as $k => $eff) {
$effectifsOri[$k]['per'] = ($totalEffectOri != 0) ? $eff['count'] * 100 / $totalEffectOri : 0;
$effectifsOri[$k]['sum'] = ($effectifsOri[$k]['sum'] != '') ? $effectifsOri[$k]['sum'] : 0;
}
for ($i = 0; $i <= 3; $i++) {
if (!isset($effectifsOri[$i])) {
$effectifsOri[$i] = ["count" => 0, "per" => 0, "sum" => 0];
}
}
// REPARTITIONS
$queryHF = "
SELECT COUNT(civilite), civilite
FROM entrepreneur, utilisateur
WHERE idstructure IN (" . $listStructuresStr . ")
AND entrepreneur.idutilisateur = utilisateur.id
AND (
(dateprospect >= '" . $startReport->format('d/m/Y') . "' AND (dateprospect <= '" . $endReport->format('d/m/Y') . "' OR dateprospect IS NULL))
OR
(datecandidat >= '" . $startReport->format('d/m/Y') . "' AND (datecandidat <= '" . $endReport->format('d/m/Y') . "' OR datecandidat IS NULL))
OR
(datecouve >= '" . $startReport->format('d/m/Y') . "' AND (datecouve <= '" . $endReport->format('d/m/Y') . "' OR datecouve IS NULL))
OR
(datesortie >= '" . $startReport->format('d/m/Y') . "' AND (datesortie <= '" . $endReport->format('d/m/Y') . "' OR datesortie IS NULL))
)
AND etat <> 4
GROUP BY civilite
";
$dbHF = $this->db->fetchAllAssociative($queryHF);
$queryHFOri = "
SELECT COUNT(civilite), civilite
FROM entrepreneur, utilisateur
WHERE idstructure IN (" . $listStructuresStr . ")
AND entrepreneur.idutilisateur = utilisateur.id
AND (datesortie <= '" . $endReport->format('d/m/Y') . "' OR datesortie IS NULL)
AND etat <> 4
GROUP BY civilite
";
$dbHFOri = $this->db->fetchAllAssociative($queryHFOri);
$repHF = [];
$repHF['m'] = ['ori' => 0, 'act' => 0];
$repHF['mme'] = ['ori' => 0, 'act' => 0];
foreach ($dbHFOri as $arr) {
$repHF[$arr['civilite']] = ['ori' => $arr['count'], 'act' => 0];
}
foreach ($dbHF as $arr) {
if (!isset($repHF[$arr['civilite']])) {
$repHF[$arr['civilite']] = ['ori' => 0, 'act' => $arr['count']];
} else {
$repHF[$arr['civilite']]['act'] = $arr['count'];
}
}
$queryRSA = "
SELECT
COUNT(
CASE
WHEN rsa is null THEN 'non'
WHEN rsa = true THEN 'oui'
ELSE 'non'
END
), (
CASE
WHEN rsa is null THEN 'non'
WHEN rsa = true THEN 'oui'
ELSE 'non'
END
) AS rsa
FROM entrepreneur, utilisateur
WHERE idstructure IN (" . $listStructuresStr . ")
AND entrepreneur.idutilisateur = utilisateur.id
AND (
(dateprospect >= '" . $startReport->format('d/m/Y') . "' AND (dateprospect <= '" . $endReport->format('d/m/Y') . "' OR dateprospect IS NULL))
OR
(datecandidat >= '" . $startReport->format('d/m/Y') . "' AND (datecandidat <= '" . $endReport->format('d/m/Y') . "' OR datecandidat IS NULL))
OR
(datecouve >= '" . $startReport->format('d/m/Y') . "' AND (datecouve <= '" . $endReport->format('d/m/Y') . "' OR datecouve IS NULL))
OR
(datesortie >= '" . $startReport->format('d/m/Y') . "' AND (datesortie <= '" . $endReport->format('d/m/Y') . "' OR datesortie IS NULL))
)
AND etat <> 4
GROUP BY rsa
";
$dbRSA = $this->db->fetchAllAssociative($queryRSA);
$queryRSAOri = "
SELECT
COUNT(
CASE
WHEN rsa is null THEN 'non'
WHEN rsa = true THEN 'oui'
ELSE 'non'
END
), (
CASE
WHEN rsa is null THEN 'non'
WHEN rsa = true THEN 'oui'
ELSE 'non'
END
) AS rsa
FROM entrepreneur, utilisateur
WHERE idstructure IN (" . $listStructuresStr . ")
AND entrepreneur.idutilisateur = utilisateur.id
AND (datesortie <= '" . $endReport->format('d/m/Y') . "' OR datesortie IS NULL)
AND etat <> 4
GROUP BY rsa
";
$dbRSAOri = $this->db->fetchAllAssociative($queryRSAOri);
$repRSA = [];
$repRSA['oui'] = ['ori' => 0, 'act' => 0];
$repRSA['non'] = ['ori' => 0, 'act' => 0];
foreach ($dbRSAOri as $arr) {
$repRSA[$arr['rsa']] = ['ori' => $arr['count'], 'act' => 0];
}
foreach ($dbRSA as $arr) {
if (!isset($repRSA[$arr['rsa']])) {
$repRSA[$arr['rsa']] = ['ori' => 0, 'act' => $arr['count']];
} else {
$repRSA[$arr['rsa']]['act'] = $arr['count'];
}
}
$queryPol = "
SELECT
COUNT(
CASE
WHEN politiqueville is null THEN 'non'
WHEN politiqueville = true THEN 'oui'
ELSE 'non'
END
), (
CASE
WHEN politiqueville is null THEN 'non'
WHEN politiqueville = true THEN 'oui'
ELSE 'non'
END
) AS politiqueville
FROM entrepreneur, utilisateur
WHERE idstructure IN (" . $listStructuresStr . ")
AND entrepreneur.idutilisateur = utilisateur.id
AND (
(dateprospect >= '" . $startReport->format('d/m/Y') . "' AND (dateprospect <= '" . $endReport->format('d/m/Y') . "' OR dateprospect IS NULL))
OR
(datecandidat >= '" . $startReport->format('d/m/Y') . "' AND (datecandidat <= '" . $endReport->format('d/m/Y') . "' OR datecandidat IS NULL))
OR
(datecouve >= '" . $startReport->format('d/m/Y') . "' AND (datecouve <= '" . $endReport->format('d/m/Y') . "' OR datecouve IS NULL))
OR
(datesortie >= '" . $startReport->format('d/m/Y') . "' AND (datesortie <= '" . $endReport->format('d/m/Y') . "' OR datesortie IS NULL))
)
AND etat <> 4
GROUP BY politiqueville
";
$dbPol = $this->db->fetchAllAssociative($queryPol);
$queryPolOri = "
SELECT
COUNT(
CASE
WHEN politiqueville is null THEN 'non'
WHEN politiqueville = true THEN 'oui'
ELSE 'non'
END
), (
CASE
WHEN politiqueville is null THEN 'non'
WHEN politiqueville = true THEN 'oui'
ELSE 'non'
END
) AS politiqueville
FROM entrepreneur, utilisateur
WHERE idstructure IN (" . $listStructuresStr . ")
AND entrepreneur.idutilisateur = utilisateur.id
AND (datesortie <= '" . $endReport->format('d/m/Y') . "' OR datesortie IS NULL)
AND etat <> 4
GROUP BY politiqueville
";
$dbPolOri = $this->db->fetchAllAssociative($queryPolOri);
$repPol = [];
$repPol['oui'] = ['ori' => 0, 'act' => 0];
$repPol['non'] = ['ori' => 0, 'act' => 0];
foreach ($dbPolOri as $arr) {
$repPol[$arr['politiqueville']] = ['ori' => $arr['count'], 'act' => 0];
}
foreach ($dbPol as $arr) {
if (!isset($repPol[$arr['politiqueville']])) {
$repPol[$arr['politiqueville']] = ['ori' => 0, 'act' => $arr['count']];
} else {
$repPol[$arr['politiqueville']]['act'] = $arr['count'];
}
}
$queryStat = "
SELECT
COUNT(
CASE
WHEN statutsocial is null THEN 0
ELSE statutsocial
END
), (
CASE
WHEN statutsocial is null THEN 0
ELSE statutsocial
END
) AS statutsocial
FROM entrepreneur, utilisateur
WHERE idstructure IN (" . $listStructuresStr . ")
AND entrepreneur.idutilisateur = utilisateur.id
AND (
(dateprospect >= '" . $startReport->format('d/m/Y') . "' AND (dateprospect <= '" . $endReport->format('d/m/Y') . "' OR dateprospect IS NULL))
OR
(datecandidat >= '" . $startReport->format('d/m/Y') . "' AND (datecandidat <= '" . $endReport->format('d/m/Y') . "' OR datecandidat IS NULL))
OR
(datecouve >= '" . $startReport->format('d/m/Y') . "' AND (datecouve <= '" . $endReport->format('d/m/Y') . "' OR datecouve IS NULL))
OR
(datesortie >= '" . $startReport->format('d/m/Y') . "' AND (datesortie <= '" . $endReport->format('d/m/Y') . "' OR datesortie IS NULL))
)
AND etat <> 4
GROUP BY statutsocial
";
$dbStat = $this->db->fetchAllAssociative($queryStat);
$queryStatOri = "
SELECT
COUNT(
CASE
WHEN statutsocial is null THEN 0
ELSE statutsocial
END
), (
CASE
WHEN statutsocial is null THEN 0
ELSE statutsocial
END
) AS statutsocial
FROM entrepreneur, utilisateur
WHERE idstructure IN (" . $listStructuresStr . ")
AND entrepreneur.idutilisateur = utilisateur.id
AND (datesortie <= '" . $endReport->format('d/m/Y') . "' OR datesortie IS NULL)
AND etat <> 4
GROUP BY statutsocial
";
$dbStatOri = $this->db->fetchAllAssociative($queryStatOri);
$repStat = [];
foreach ($listStatut as $statut) {
$lib = $statut['libelle'];
$repStat[$lib] = ['ori' => 0, 'act' => 0];
}
foreach ($dbStatOri as $arr) {
if ($arr['statutsocial'] == 0) {
$lib = 'NC';
} else {
foreach ($listStatut as $statut) {
if ($arr['statutsocial'] == $statut['idstatut']) {
$lib = $statut['libelle'];
}
}
}
$repStat[$lib] = ['ori' => $arr['count'], 'act' => 0];
}
foreach ($dbStat as $arr) {
if ($arr['statutsocial'] == 0) {
$lib = 'NC';
} else {
foreach ($listStatut as $statut) {
if ($arr['statutsocial'] == $statut['idstatut']) {
$lib = $statut['libelle'];
}
}
}
if (!isset($repStat[$lib])) {
$repStat[$lib] = ['ori' => 0, 'act' => $arr['count']];
} else {
$repStat[$lib]['act'] = $arr['count'];
}
}
// CALCULS EVOLUTIONS (12 Derniers Mois, indépendant de la période fixée pour le rapport)
$completeEvol = [];
$completeCape = [];
// L'inversion des des dates de début et de fin est voulue car on remonte dans ls temps pour dessiner le graphique
$startEvol = clone $endReport;
$startEvol->modify('last day of this month');
$endEvol = clone $startReport;
$endEvol->modify('first day of this month');
$diff = $endEvol->diff($startEvol); //DateInterval entre les 2 dates
$interval = \DateInterval::createFromDateString('-1 month'); // -1 month DateInterval
$period = new \DatePeriod($startEvol, $interval, ($diff->m + ($diff->y * 12) + 1));
foreach ($period as $dt) {
$dt->modify('first day of next month');
$previousMonth = clone $dt;
$previousMonth->add($interval);
$queryEvol = "
SELECT *
FROM entrepreneur, utilisateur
WHERE idstructure IN (" . $listStructuresStr . ")
AND entrepreneur.idutilisateur = utilisateur.id
AND dateprospect < '" . $dt->format('d/m/Y') . "'
AND (datecandidat < '" . $dt->format('d/m/Y') . "' OR datecandidat IS NULL)
AND (datecouve < '" . $dt->format('d/m/Y') . "' OR datecouve IS NULL)
AND (datesortie >= '" . $previousMonth->format('d/m/Y') . "' OR datesortie IS NULL)
AND etat <> 4
";
$resEvol = $this->db->fetchAllAssociative($queryEvol);
$completeEvol[$previousMonth->format('m/Y')] = $resEvol;
$queryCape = "
SELECT
SUM(
CASE
WHEN (debutcape < '" . $dt->format('d/m/Y') . "' AND debutcape >= '" . $previousMonth->format('d/m/Y') . "') THEN 1
ELSE 0
END
) AS cape,
SUM(
CASE
WHEN (debutavcape1 < '" . $dt->format('d/m/Y') . "' AND debutavcape1 >= '" . $previousMonth->format('d/m/Y') . "') THEN 1
ELSE 0
END
) AS capeav1,
SUM(
CASE
WHEN (debutavcape2 < '" . $dt->format('d/m/Y') . "' AND debutavcape2 >= '" . $previousMonth->format('d/m/Y') . "') THEN 1
ELSE 0
END
) AS capeav2
FROM entrepreneur, utilisateur
WHERE entrepreneur.idutilisateur = utilisateur.id
AND etat <> 4
AND idstructure IN (" . $listStructuresStr . ")
AND (
(debutcape < '" . $dt->format('d/m/Y') . "' AND debutcape >= '" . $previousMonth->format('d/m/Y') . "')
OR
(debutavcape1 < '" . $dt->format('d/m/Y') . "' AND debutavcape1 >= '" . $previousMonth->format('d/m/Y') . "')
OR
(debutavcape2 < '" . $dt->format('d/m/Y') . "' AND debutavcape2 >= '" . $previousMonth->format('d/m/Y') . "')
)
";
$resCape = $this->db->fetchAllAssociative($queryCape);
$completeCape[$previousMonth->format('m/Y')] = $resCape;
}
$repCape = [];
foreach ($completeCape as $periode => $entr) {
if (!isset($repCape[$periode])) {
$repCape[$periode] = ['Cape' => 0, 'Avenant 1' => 0, 'Avenant 2' => 0];
}
foreach ($entr as $e) {
$repCape[$periode]["Cape"] += $e['cape'];
$repCape[$periode]["Avenant 1"] += $e['capeav1'];
$repCape[$periode]["Avenant 2"] += $e['capeav2'];
}
}
$repCape = array_reverse($repCape);
$report->setEnteteCouveuse();
$report->addBr(4);
$report->addTitle('Effectifs');
$report->drawEffectifs($effectifs, $effectifsOri);
$report->addLine('<p style="font-size:12px; color:#606060"><strong>Chiffre d’affaires généré</strong> : ' . number_format($totalCA, 2, ",", " ") . ' €</p>');
$report->addBr(6);
$report->addTitle('Répartition');
$report->addBr(4);
$report->drawEffectifsHF($repHF);
$report->addBr(4);
$report->drawEffectifsStatut($repStat);
$report->addBr(4);
$report->drawEffectifsRSA($repRSA);
$report->pageBreak();
$report->addBr(4);
$report->drawEffectifsPol($repPol);
// GRAPH Cape
$filename = 'rapportcouv' . $idstructure . '_cape.png';
$filelist[] = $filename;
$arrPeriodes = [];
$arrVals = [];
foreach ($repCape as $periode => $arr) {
$arrPeriodes[] = $periode;
foreach ($arr as $set => $val) {
$setName = $set;
$arrVals[$set][] = $val;
}
}
$MyData = new Data();
foreach ($arrVals as $set => $ar) {
$MyData->addPoints($ar, $set);
}
$MyData->loadPalette($this->getParameter('kernel.project_dir') . "/uce.color", TRUE);
$MyData->setSerieWeight("Probe 1", 2);
$MyData->setSerieTicks("Probe 2", 4);
$MyData->setAxisName(0, "CAPE");
$MyData->addPoints($arrPeriodes, "Labels");
$MyData->setSerieDescription("Labels", "Mois");
$MyData->setAbscissa("Labels");
$myPicture = new Image(700, 230, $MyData);
$myPicture->Antialias = FALSE;
$myPicture->drawRectangle(0, 0, 699, 229, ["R" => 255, "G" => 255, "B" => 255]);
$myPicture->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
$myPicture->setGraphArea(60, 20, 680, 190);
$scaleSettings = ["XMargin" => 10, "YMargin" => 10, "Floating" => TRUE, "GridR" => 200, "GridG" => 200, "GridB" => 200, "DrawSubTicks" => TRUE, "CycleBackground" => TRUE];
$myPicture->drawScale($scaleSettings);
$myPicture->Antialias = TRUE;
$myPicture->setShadow(TRUE, ["X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10]);
$myPicture->drawLineChart();
$myPicture->drawPlotChart(["DisplayValues" => TRUE, "PlotBorder" => TRUE, "BorderSize" => 2, "Surrounding" => -60, "BorderAlpha" => 80]);
$myPicture->drawLegend(540, 210, ["Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL]);
$myPicture->render($tmpPath . $filename);
$report->addBr(4);
$report->addImage($filename, 'Nombre de CAPE et Avenants', true, '15cm');
return $report;
}
private function createDoublePie($filename, $set1, $set2)
{
$tmpPath = $this->getParameter('kernel.project_dir') . '/public/tmp/';
$libs = [];
$set = [];
foreach ($set1 as $lib => $count) {
$libs[] = $lib;
$set[] = $count;
}
$MyData = new Data();
$MyData->loadPalette($this->getParameter('kernel.project_dir') . "/uce.color", TRUE);
$MyData->addPoints($set, "ScoreA");
$MyData->addPoints($libs, "Labels");
$MyData->setAbscissa("Labels");
$libs = [];
$set = [];
foreach ($set2 as $lib => $count) {
$libs[] = $lib;
$set[] = $count;
}
$MyData2 = new Data();
$MyData2->loadPalette($this->getParameter('kernel.project_dir') . "/uce.color", TRUE);
$MyData2->addPoints($set, "ScoreA");
$MyData2->addPoints($libs, "Labels");
$MyData2->setAbscissa("Labels");
$myPicture = new Image(800, 340, $MyData);
$myPicture->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 12, "R" => 80, "G" => 80, "B" => 80]);
$PieChart = new Pie($myPicture, $MyData);
$PieChart->draw2DPie(200, 150, ["WriteValues" => PIE_VALUE_PERCENTAGE, "DataGapAngle" => 10, "DataGapRadius" => 6, "Border" => FALSE, "ValueR" => 0, "ValueG" => 0, "ValueB" => 0, "Radius" => 120]);
$PieChart = new Pie($myPicture, $MyData2);
$PieChart->draw2DPie(600, 150, ["WriteValues" => PIE_VALUE_PERCENTAGE, "DataGapAngle" => 10, "DataGapRadius" => 6, "Border" => FALSE, "ValueR" => 0, "ValueG" => 0, "ValueB" => 0, "Radius" => 120]);
$myPicture->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 11, "R" => 80, "G" => 80, "B" => 80]);
$PieChart->drawPieLegend(150, 320, ["Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL]);
$myPicture->render($tmpPath . $filename);
}
public function calculEntrepreneursAction(Request $request): Response
{
$activeStructure = $request->getSession()->get('activeStructure');
$mois = $request->get('mois');
$annee = $request->get('annee');
$datemois = \DateTime::createFromFormat('d-m-Y', '01-' . $mois . '-' . $annee);
$plus1mois = \DateTime::createFromFormat('d-m-Y', '01-' . $mois . '-' . $annee);
$newdate = $plus1mois->add(new \DateInterval('P1M'));
// On récupère tous les entrepreneurs de la structure
$entrepreneurs = $this->db->fetchAllAssociative('SELECT u.id, e.debutcape, e.fincape, e.debutavcape1, e.finavcape1, e.debutavcape2, e.finavcape2, e.datesortie FROM entrepreneur e, structure s, utilisateur u WHERE s.idparent = ' . $activeStructure->getIdstructure() . ' AND s.idstructure=e.idstructure AND u.id=e.idutilisateur');
$idEntConcernees = [];
foreach ($entrepreneurs as $e) {
$datesortie = new \DateTime(date('d-m-Y', strtotime($e['datesortie'])));
if (!is_null($e['datesortie']) && $datesortie < $datemois) {
} else {
// On vérifie pour le cas des capes
if (!is_null($e['debutcape'])) {
$debutcape = new \DateTime(date('d-m-Y', strtotime($e['debutcape'])));
$fincape = new \DateTime(date('d-m-Y', strtotime($e['fincape'])));
// On vérifie que la date de fin de cape est bien < au mois sélèctionné
if ($fincape < $datemois) {
} else {
// On vérifie que la date de début est bien <= au mois sélectionné
if ($debutcape <= $datemois || $debutcape < $newdate) {
// On vérifie que la date de fin est >= au mois sélectionné (1er jour du mois suivant) et qu'aucune date de sortie ne soit renseignée
if (($fincape >= $newdate || is_null($fincape)) || ($fincape <= $newdate && $fincape > $datemois) && (is_null($e['datesortie']) || $datesortie < $newdate) && is_null($e['finavcape1']) && is_null($e['finavcape2'])) {
//On ajoute l'entrepreneur concerné
$idEntConcernees[] = $e['id'];
} elseif (($fincape >= $newdate || is_null($fincape)) || ($fincape <= $newdate && $fincape > $datemois) && !is_null($e['datesortie']) && is_null($e['finavcape1']) && is_null($e['finavcape2'])) {
// On vérifie que la date de sortie est bien > au mois sélectionné
if ($datesortie >= $newdate || ($datesortie <= $newdate && $datesortie > $datemois)) {
//On ajoute l'entrepreneur concerné
$idEntConcernees[] = $e['id'];
}
} elseif (!is_null($e['datesortie']) && $newdate < $datesortie && $datesortie < $newdate && is_null($e['finavcape1']) && is_null($e['finavcape2'])) {
//On ajoute l'entrepreneur concerné
if (!in_array($e['id'], $idEntConcernees)) {
$idEntConcernees[] = $e['id'];
}
}
}
}
}
// On vérifie pour le cas des avenant 1 capes
if (!is_null($e['debutavcape1'])) {
$debutav1cape = new \DateTime(date('d-m-Y', strtotime($e['debutavcape1'])));
$finav1cape = new \DateTime(date('d-m-Y', strtotime($e['finavcape1'])));
// On vérifie que la date de fin de cape est bien < au mois sélèctionné
if ($finav1cape < $datemois) {
} else {
// On vérifie que la date de début est bien <= au mois sélectionné
if ($debutav1cape <= $datemois || $debutav1cape < $newdate) {
// On vérifie que la date de fin est >= au mois sélectionné (1er jour du mois suivant) et qu'aucune date de sortie ne soit renseignée
if (($finav1cape >= $newdate || is_null($finav1cape)) && (is_null($e['datesortie']) || $datesortie < $newdate) && is_null($e['finavcape2'])) {
//On ajoute l'entrepreneur concerné
if (!in_array($e['id'], $idEntConcernees)) {
$idEntConcernees[] = $e['id'];
}
} elseif (($finav1cape >= $newdate || is_null($finav1cape)) && !is_null($e['datesortie']) && is_null($e['finavcape2'])) {
// On vérifie que la date de sortie est bien > au mois sélectionné
if ($datesortie >= $newdate) {
//On ajoute l'entrepreneur concerné
if (!in_array($e['id'], $idEntConcernees)) {
$idEntConcernees[] = $e['id'];
}
}
} elseif (!is_null($e['datesortie']) && $datemois < $datesortie && $datesortie < $newdate && is_null($e['finavcape2'])) {
//On ajoute l'entrepreneur concerné
if (!in_array($e['id'], $idEntConcernees)) {
$idEntConcernees[] = $e['id'];
}
}
}
}
}
// On vérifie pour le cas des avenant 2 capes
if (!is_null($e['debutavcape2'])) {
$debutav2cape = new \DateTime(date('d-m-Y', strtotime($e['debutavcape2'])));
$finav2cape = new \DateTime(date('d-m-Y', strtotime($e['finavcape2'])));
// On vérifie que la date de fin de cape est bien < au mois sélèctionné
if ($finav2cape < $datemois) {
} else {
// On vérifie que la date de début est bien <= au mois sélectionné
if ($debutav2cape <= $datemois || $debutav2cape < $newdate) {
// On vérifie que la date de fin est >= au mois sélectionné (1er jour du mois suivant) et qu'aucune date de sortie ne soit renseignée
if (($finav2cape >= $newdate || is_null($finav2cape)) && (is_null($e['datesortie']) || $datesortie < $newdate)) {
//On ajoute l'entrepreneur concerné
if (!in_array($e['id'], $idEntConcernees)) {
$idEntConcernees[] = $e['id'];
}
} elseif (($finav2cape >= $newdate || is_null($finav2cape)) && !is_null($e['datesortie'])) {
// On vérifie que la date de sortie est bien > au mois sélectionné
if ($datesortie >= $newdate) {
//On ajoute l'entrepreneur concerné
if (!in_array($e['id'], $idEntConcernees)) {
$idEntConcernees[] = $e['id'];
}
}
} elseif (!is_null($e['datesortie']) && $datemois < $datesortie && $datesortie < $newdate) {
//On ajoute l'entrepreneur concerné
if (!in_array($e['id'], $idEntConcernees)) {
$idEntConcernees[] = $e['id'];
}
}
}
}
}
}
}
return $this->json($idEntConcernees);
}
public function listEntrepreneursAction(Request $request): Response
{
$list = $request->get('list');
$queryEnt = 'SELECT u.nom, u.prenom, e.identrepreneur FROM entrepreneur e, utilisateur u
WHERE e.idutilisateur=u.id AND u.id IN (' . $list . ') ORDER BY u.nom, u.prenom';
$ent = $this->db->fetchAllAssociative($queryEnt);
$html = ' <div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4><i class="fa fa-graduation-cap"></i>Liste des entrepreneurs concernés</h4>
</div>';
$html .= '<div class="modal-body sidebar-inner scrollable-sidebar">';
$arrayIds = '';
foreach ($ent as $e) {
if ($arrayIds != '') {
$arrayIds .= ',' . $e['identrepreneur'];
} else {
$arrayIds .= $e['identrepreneur'];
}
$html .= '<div class="group group-1">';
$url = $this->generateUrl('admin_entrepreneur_edit', ['id' => $e['identrepreneur']]);
$html .= '<a href="' . $url . '" ><h4 style="padding-left:10px;">' . $e['nom'] . ' ' . $e['prenom'] . '</h4></a>';
$html .= '</div>';
}
$urlExport = $this->generateUrl('admin_entrepreneurs_export', ['ids' => $arrayIds]);
$html .= '<div class="padding-md clearfix text-center">';
$html .= '<a class="btn btn-info pull-right" style="padding:4px 7px;" data-placement="left" data-toggle="tooltip" data-original-title="Exporter les entrepreneurs" href="' . $urlExport . '">';
$html .= '<i class="fa fa-arrow-circle-o-down fa-2x"></i>';
$html .= '</a>';
$html .= '</div>';
$html .= '</div>';
$response = new Response();
$response->setContent($html);
$response->headers->set('Content-Type', 'text/plain');
return $response;
}
public function calculEntrepreneursFincapeAction(Request $request): Response
{
$activeStructure = $request->getSession()->get('activeStructure');
$nbmois = $request->get('nbmois');
$t = date('m-Y');
$datemois = \DateTime::createFromFormat('d-m-Y', '01-' . $t);
$plusNmois = \DateTime::createFromFormat('d-m-Y', '01-' . $t);
$moissuiv = $nbmois + 1;
$findate = $plusNmois->add(new \DateInterval('P' . $moissuiv . 'M'));
// On récupère tous les entrepreneurs de la structure
$entrepreneurs = $this->db->fetchAllAssociative('SELECT u.id, e.debutcape, e.fincape, e.debutavcape1, e.finavcape1, e.debutavcape2, e.finavcape2, e.datesortie FROM entrepreneur e, structure s, utilisateur u WHERE s.idparent = ' . $activeStructure->getIdstructure() . ' AND s.idstructure=e.idstructure AND u.id=e.idutilisateur ');
$idEntConcernees = [];
foreach ($entrepreneurs as $e) {
$datesortie = new \DateTime(date('d-m-Y', strtotime($e['datesortie'])));
if (!is_null($e['datesortie']) && $datesortie < $datemois) {
} else {
// On vérifie pour le cas des capes
if (!is_null($e['fincape']) && is_null($e['finavcape1']) && is_null($e['finavcape2'])) {
$fincape = new \DateTime(date('d-m-Y', strtotime($e['fincape'])));
if (!is_null($e['datesortie'])) {
if ($datemois <= $datesortie && $datesortie < $findate) {
//On ajoute l'entrepreneur concerné
if (!in_array($e['id'], $idEntConcernees)) {
$idEntConcernees[] = $e['id'];
}
}
} else {
// On vérifie que la date de fin est <= au nombre de mois sélectionné
if (($fincape < $findate && $fincape >= $datemois)) {
//On ajoute l'entrepreneur concerné
if (!in_array($e['id'], $idEntConcernees)) {
$idEntConcernees[] = $e['id'];
}
}
}
}
// On vérifie pour le cas des avenants 1 capes
if (!is_null($e['finavcape1']) && is_null($e['finavcape2'])) {
$finavcape1 = new \DateTime(date('d-m-Y', strtotime($e['finavcape1'])));
if (!is_null($e['datesortie'])) {
if ($datemois <= $datesortie && $datesortie < $findate) {
//On ajoute l'entrepreneur concerné
if (!in_array($e['id'], $idEntConcernees)) {
$idEntConcernees[] = $e['id'];
}
}
} else {
// On vérifie que la date de fin est <= au nombre de mois sélectionné
if (($finavcape1 < $findate && $finavcape1 >= $datemois)) {
//On ajoute l'entrepreneur concerné
if (!in_array($e['id'], $idEntConcernees)) {
$idEntConcernees[] = $e['id'];
}
}
}
}
// On vérifie pour le cas des avenants 2 capes
if (!is_null($e['finavcape2'])) {
$finavcape2 = new \DateTime(date('d-m-Y', strtotime($e['finavcape2'])));
if (!is_null($e['datesortie'])) {
if ($datemois <= $datesortie && $datesortie < $findate) {
//On ajoute l'entrepreneur concerné
if (!in_array($e['id'], $idEntConcernees)) {
$idEntConcernees[] = $e['id'];
}
}
} else {
// On vérifie que la date de fin est <= au nombre de mois sélectionné
if ($finavcape2 < $findate && $finavcape2 >= $datemois) {
//On ajoute l'entrepreneur concerné
if (!in_array($e['id'], $idEntConcernees)) {
$idEntConcernees[] = $e['id'];
}
}
}
}
}
}
return $this->json($idEntConcernees);
}
public function listEntrepreneursFincapeAction(Request $request): Response
{
$list = $request->get('list');
$queryEnt = 'SELECT u.nom, u.prenom, e.identrepreneur FROM entrepreneur e, utilisateur u
WHERE e.idutilisateur=u.id AND u.id IN (' . $list . ') ORDER BY u.nom, u.prenom';
$ent = $this->db->fetchAllAssociative($queryEnt);
$html = ' <div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4><i class="fa fa-graduation-cap"></i>Liste des entrepreneurs concernés</h4>
</div>';
$html .= '<div class="modal-body sidebar-inner scrollable-sidebar">';
$arrayIds = '';
foreach ($ent as $e) {
if ($arrayIds != '') {
$arrayIds .= ',' . $e['identrepreneur'];
} else {
$arrayIds .= $e['identrepreneur'];
}
$html .= '<div class="group group-1">';
$url = $this->generateUrl('admin_entrepreneur_edit', ['id' => $e['identrepreneur']]);
$html .= '<a href="' . $url . '" ><h4 style="padding-left:10px;">' . $e['nom'] . ' ' . $e['prenom'] . '</h4></a>';
$html .= '</div>';
}
$urlExport = $this->generateUrl('admin_entrepreneurs_export', ['ids' => $arrayIds]);
$html .= '<div class="padding-md clearfix text-center">';
$html .= '<a class="btn btn-info pull-right" style="padding:4px 7px;" data-placement="left" data-toggle="tooltip" data-original-title="Exporter les entrepreneurs" href="' . $urlExport . '">';
$html .= '<i class="fa fa-arrow-circle-o-down fa-2x"></i>';
$html .= '</a>';
$html .= '</div>';
$html .= '</div>';
$response = new Response();
$response->setContent($html);
$response->headers->set('Content-Type', 'text/plain');
return $response;
}
public function pageMentionsAction(Request $request): Response
{
return $this->render('Admin/Default/mentionsLegales.html.twig', []);
}
public function changePassFormAction(Request $request): Response
{
return $this->render('Admin/Default/changePassForm.html.twig', []);
}
public function changePassSaveAction(Request $request, UserPasswordHasherInterface $passwordHasher): Response
{
$utilisateur = $this->getUser();
$utilisateur->setSalt(md5(uniqid('', true)));
$password = $passwordHasher->hashPassword($utilisateur, $_REQUEST['newpass']);
$utilisateur->setPassword($password);
$this->em->persist($utilisateur);
$this->em->flush();
return $this->json('ok');
}
/**
* Permet de tester l'envoi d'un simple mail
*
* @param MailerInterface $mailer
* @return Response
*/
public function testMailAction(MailerInterface $mailer): Response
{
$debug = $this->getParameter('kernel.debug');
if ($debug) {
$to = 'mathieu@mapyourdream.com';
$messagemail = (new TemplatedEmail())
->to($to)
->subject("UCE : Test d'envoi de Mail")
->htmlTemplate('Admin/Mail/mailTest.html.twig');
$content = 'Send OK';
try {
$mailer->send($messagemail);
} catch (\Exception $e) {
$content = 'Send KO : ' . $e->getMessage();
}
$textResponse = new Response($content, 200);
$textResponse->headers->set('Content-Type', 'text/plain');
return $textResponse;
}
$textResponse = new Response('Vous n\'avez pas accès à cette page.', 403);
$textResponse->headers->set('Content-Type', 'text/plain');
return $textResponse;
}
}