Commit 7ce9cd8a authored by Laurent Lécluse's avatar Laurent Lécluse
Browse files

Presque fini

parent f80da398
......@@ -2,6 +2,7 @@
namespace Application\Controller;
use Application\Entity\Db\Annee;
use Application\Entity\Db\Etape;
use Application\Entity\Db\Scenario;
use Application\Entity\Db\SeuilCharge;
......@@ -354,29 +355,40 @@ class ChargensController extends AbstractController
{
$form = $this->getFormChargensDifferentiel();
/*
$diff = [];
if ($this->getRequest()->isPost()) {
$post = array_merge_recursive(
$this->getRequest()->getPost()->toArray(),
$this->getRequest()->getFiles()->toArray()
);
$form->setData($post);
if ($form->isValid()) {
$data = $form->getData();
$pce = $this->getProviderChargens()->getExport();
$avant = $pce->fromCsv($data['avant']['tmp_name']);
$apres = $pce->fromCsv($data['apres']['tmp_name']);
$diff = $pce->diff($avant, $apres);
}
$diff = null;
if ($this->getRequest()->isPost()) {
$post = array_merge_recursive(
$this->getRequest()->getPost()->toArray(),
$this->getRequest()->getFiles()->toArray()
);
$form->setData($post);
if ($form->isValid()) {
$data = $form->getData();
$pce = $this->getProviderChargens()->getExport();
if ($data['avant'] == 'export' && isset($data['avant-fichier']['tmp_name'])) {
$avant = $pce->fromCsv($data['avant-fichier']['tmp_name']);
} else {
[$avantAnneeId, $avantScenarioId] = explode('-', $data['avant']);
$avantAnnee = $this->em()->find(Annee::class, $avantAnneeId);
$avantScenario = $this->em()->find(Scenario::class, $avantScenarioId);
$avant = $pce->fromBdd($avantAnnee, $avantScenario, $this->getServiceContext()->getStructure());
}
if ($data['apres'] == 'export' && isset($data['apres-fichier']['tmp_name'])) {
$apres = $pce->fromCsv($data['apres-fichier']['tmp_name']);
} else {
[$apresAnneeId, $apresScenarioId] = explode('-', $data['apres']);
$apresAnnee = $this->em()->find(Annee::class, $apresAnneeId);
$apresScenario = $this->em()->find(Scenario::class, $apresScenarioId);
$apres = $pce->fromBdd($apresAnnee, $apresScenario, $this->getServiceContext()->getStructure());
}
*/
$pce = $this->getProviderChargens()->getExport();
$avant = $pce->fromCsv(getcwd() . '/data/charges.csv');
$apres = $pce->fromCsv(getcwd() . '/data/charges2.csv');
$diff = $pce->diff($avant, $apres);
$diff = $pce->diff($avant, $apres);
}
}
return compact('form', 'diff');
}
......
......@@ -3,6 +3,7 @@
namespace Application\Form\Chargens;
use Application\Form\AbstractForm;
use Application\Service\Traits\ContextServiceAwareTrait;
/**
* Description of DifferentielForm
......@@ -11,6 +12,8 @@ use Application\Form\AbstractForm;
*/
class DifferentielForm extends AbstractForm
{
use ContextServiceAwareTrait;
public function init()
{
$this->setAttributes([
......@@ -21,9 +24,9 @@ class DifferentielForm extends AbstractForm
$this->add([
'type' => 'File',
'name' => 'avant',
'name' => 'avant-fichier',
'options' => [
'label' => "Premier export des charges",
],
'attributes' => [
'id' => 'fichier',
......@@ -34,9 +37,9 @@ class DifferentielForm extends AbstractForm
$this->add([
'type' => 'File',
'name' => 'apres',
'name' => 'apres-fichier',
'options' => [
'label' => "Export des charges le plus récent",
],
'attributes' => [
'id' => 'fichier',
......@@ -45,6 +48,30 @@ class DifferentielForm extends AbstractForm
],
]);
$this->add([
'name' => 'avant',
'options' => [
'label' => "Premier export des charges",
],
'attributes' => [
'class' => 'input-sm selectpicker',
'data-live-search' => 'true',
],
'type' => 'Select',
]);
$this->add([
'name' => 'apres',
'options' => [
'label' => "Export des charges le plus récent",
],
'attributes' => [
'class' => 'input-sm selectpicker',
'data-live-search' => 'true',
],
'type' => 'Select',
]);
$this->add([
'name' => 'submit',
'type' => 'Submit',
......@@ -53,6 +80,50 @@ class DifferentielForm extends AbstractForm
'class' => 'btn btn-primary btn-save',
],
]);
$scenarios = $this->getScenarioValues();
$this->get('avant')->setValueOptions($scenarios);
$this->get('apres')->setValueOptions($scenarios);
}
protected function getScenarioValues(): array
{
$scenarios = ['export' => ['label' => 'A partir d\'un fichier d\'export', 'options' => ['export' => 'Veuillez téléverser un fichier ci-dessous ou bien choisir un scénario']]];
$structure = $this->getServiceContext()->getStructure();
if ($structure) {
$where = 'WHERE s.structure_id IS NULL OR s.structure_id = :structure';
$params = ['structure' => $structure->getId()];
} else {
$where = '';
$params = [];
}
$sql = "
SELECT
DISTINCT c.annee_id, a.LIBELLE annee, s.id scenario_id, s.libelle scenario, s.type, s.structure_id
FROM
tbl_chargens c
JOIN scenario s ON s.id = c.scenario_id
JOIN annee a ON a.id = c.annee_id
$where
ORDER BY
annee_id, type DESC, scenario
";
$ss = $this->getServiceContext()->getEntityManager()->getConnection()->fetchAll($sql, $params);
foreach ($ss as $s) {
if (!isset($scenarios[(int)$s['ANNEE_ID']])) {
$scenarios[(int)$s['ANNEE_ID']] = [
'label' => $s['ANNEE'], 'options' => [],
];
}
$scenarios[(int)$s['ANNEE_ID']]['options'][$s['ANNEE_ID'] . '-' . $s['SCENARIO_ID']] = $s['SCENARIO'];
}
return $scenarios;
}
......
......@@ -13,6 +13,7 @@ use Application\Entity\Db\TypeHeures;
use Application\Service\Traits\ContextServiceAwareTrait;
use Application\Service\Traits\SourceServiceAwareTrait;
use Application\Service\Traits\TypeHeuresServiceAwareTrait;
use Application\Service\Traits\TypeInterventionServiceAwareTrait;
use BjyAuthorize\Service\Authorize;
use UnicaenTbl\Service\Traits\TableauBordServiceAwareTrait;
......@@ -24,6 +25,7 @@ class ChargensProvider
use StructureAwareTrait;
use TypeHeuresServiceAwareTrait;
use TableauBordServiceAwareTrait;
use TypeInterventionServiceAwareTrait;
/**
* @var Authorize
......
......@@ -75,7 +75,7 @@ class ExportProvider
'hetd' => (float)$d['HETD'],
];
if ($l['hetd'] === 120.00) $l['hetd'] = '120,00'; // Hack pour éviter un bug inxplicable
//if ($l['hetd'] === 120.00) $l['hetd'] = '120,00'; // Hack pour éviter un bug inxplicable
$data[$i] = $l;
}
......@@ -114,13 +114,13 @@ class ExportProvider
'seuil-ouverture' => (int)$d[16],
'seuil-dedoublement' => (int)$d[17],
'assiduite' => (float)$d[18],
'assiduite' => stringToFloat($d[18]),
'effectif-etape' => (int)$d[19],
'effectif-element' => (int)$d[20],
'heures-ens' => (float)$d[21],
'groupes' => (float)$d[22],
'heures' => (float)$d[23],
'hetd' => (float)$d[24],
'heures-ens' => stringToFloat($d[21]),
'groupes' => stringToFloat($d[22]),
'heures' => stringToFloat($d[23]),
'hetd' => stringToFloat($d[24]),
];
$data[] = $l;
}
......@@ -185,10 +185,15 @@ class ExportProvider
// structure ins
// etape ins
$typesIntervention = $this->chargens->getServiceTypeIntervention()->getList();
/* On formatte les donées d'avant */
foreach ($avant as $a) {
$spc = $a['structure-porteuse-code'];
$epc = $a['etape-porteuse-code'];
$ec = $a['element-code'];
$th = strtolower($a['type-heures']);
$ti = $a['type-intervention'];
if (!array_key_exists($spc, $diff)) {
$diff[$spc] = [
'libelle' => $a['structure-porteuse-libelle'],
......@@ -197,6 +202,7 @@ class ExportProvider
}
if (!array_key_exists($epc, $diff[$spc]['etapes'])) {
$diff[$spc]['etapes'][$epc] = [
'code' => $a['etape-porteuse-code'],
'libelle' => $a['etape-porteuse-libelle'],
'elements' => [],
];
......@@ -212,20 +218,34 @@ class ExportProvider
}
if (!isset($diff[$spc]['etapes'][$epc]['elements'][$ec]['avant'])) {
$diff[$spc]['etapes'][$epc]['elements'][$ec]['avant'] = [
'effectifs' => ['fi' => 0, 'fa' => 0, 'fc' => 0],
'ti' => [],
];
}
if (!isset($diff[$spc]['etapes'][$epc]['elements'][$ec]['avant']['ti'][$ti])) {
$diff[$spc]['etapes'][$epc]['elements'][$ec]['avant']['ti'][$ti] = [
'seuil-ouverture' => $a['seuil-ouverture'],
'seuil-dedoublement' => $a['seuil-dedoublement'],
'assiduite' => $a['assiduite'],
'effectifs-fi' => 0,
'effectifs-fa' => 0,
'effectifs-fc' => 0,
'heures-ens' => $a['heures-ens'],
'groupes' => 0,
'heures' => 0,
'hetd' => 0,
];
}
$diff[$spc]['etapes'][$epc]['elements'][$ec]['avant']['effectifs'][$th] += $a['effectif-element'];
$diff[$spc]['etapes'][$epc]['elements'][$ec]['avant']['ti'][$ti]['groupes'] += $a['groupes'];
$diff[$spc]['etapes'][$epc]['elements'][$ec]['avant']['ti'][$ti]['heures'] += $a['heures'];
$diff[$spc]['etapes'][$epc]['elements'][$ec]['avant']['ti'][$ti]['hetd'] += $a['hetd'];
}
/* On formatte les donées d'après */
foreach ($apres as $a) {
$spc = $a['structure-porteuse-code'];
$epc = $a['etape-porteuse-code'];
$ec = $a['element-code'];
$th = strtolower($a['type-heures']);
$ti = $a['type-intervention'];
if (!array_key_exists($spc, $diff)) {
$diff[$spc] = [
'libelle' => $a['structure-porteuse-libelle'],
......@@ -234,6 +254,7 @@ class ExportProvider
}
if (!array_key_exists($epc, $diff[$spc]['etapes'])) {
$diff[$spc]['etapes'][$epc] = [
'code' => $a['etape-porteuse-code'],
'libelle' => $a['etape-porteuse-libelle'],
'elements' => [],
];
......@@ -249,17 +270,95 @@ class ExportProvider
}
if (!isset($diff[$spc]['etapes'][$epc]['elements'][$ec]['apres'])) {
$diff[$spc]['etapes'][$epc]['elements'][$ec]['apres'] = [
'effectifs' => ['fi' => 0, 'fa' => 0, 'fc' => 0],
'ti' => [],
];
}
if (!isset($diff[$spc]['etapes'][$epc]['elements'][$ec]['apres']['ti'][$ti])) {
$diff[$spc]['etapes'][$epc]['elements'][$ec]['apres']['ti'][$ti] = [
'seuil-ouverture' => $a['seuil-ouverture'],
'seuil-dedoublement' => $a['seuil-dedoublement'],
'assiduite' => $a['assiduite'],
'effectifs-fi' => 0,
'effectifs-fa' => 0,
'effectifs-fc' => 0,
'heures-ens' => $a['heures-ens'],
'groupes' => 0,
'heures' => 0,
'hetd' => 0,
];
}
$diff[$spc]['etapes'][$epc]['elements'][$ec]['apres']['effectifs'][$th] += $a['effectif-element'];
$diff[$spc]['etapes'][$epc]['elements'][$ec]['apres']['ti'][$ti]['groupes'] += $a['groupes'];
$diff[$spc]['etapes'][$epc]['elements'][$ec]['apres']['ti'][$ti]['heures'] += $a['heures'];
$diff[$spc]['etapes'][$epc]['elements'][$ec]['apres']['ti'][$ti]['hetd'] += $a['hetd'];
}
// var_dump($avant, $apres);
/* On liste les différences */
foreach ($diff as $k1 => $d1) {
foreach ($d1['etapes'] as $k2 => $d2) {
foreach ($d2['elements'] as $ke => $d) {
$rd = [];
if (!array_key_exists('avant', $d)) {
$rd = 'new';
} elseif (!array_key_exists('apres', $d)) {
$rd = 'old';
} else {
$typeHeures = array_keys($d['avant']['effectifs']);
foreach ($typeHeures as $typeHeure) {
if ($d['avant']['effectifs'][$typeHeure] != $d['apres']['effectifs'][$typeHeure]) {
$rd['effectifs'][$typeHeure] = true;
}
}
foreach ($typesIntervention as $typeIntervention) {
$ti = $typeIntervention->getCode();
$hasAvant = isset($d['avant']['ti'][$ti]);
$hasApres = isset($d['apres']['ti'][$ti]);
if ($hasAvant && !$hasApres) {
$rd['ti'][$ti] = 'old';
} elseif (!$hasAvant && $hasApres) {
$rd['ti'][$ti] = 'new';
} elseif ($hasAvant && $hasApres) {
$rdti = [];
$keys = array_keys($d['avant']['ti'][$ti]);
foreach ($keys as $k) {
if ($d['avant']['ti'][$ti][$k] != $d['apres']['ti'][$ti][$k]) {
$rdti[$k] = true;
}
}
if (!empty($rdti)) {
$rd['ti'][$ti] = $rdti;
}
}
}
}
$diff[$k1]['etapes'][$k2]['elements'][$ke]['diff'] = $rd;
}
}
}
/* On retire tout ce qui est identique */
foreach ($diff as $k1 => $d1) {
foreach ($d1['etapes'] as $k2 => $d2) {
$hasDiff = false;
foreach ($d2['elements'] as $ke => $d) {
if (empty($d['diff'])) {
unset($diff[$k1]['etapes'][$k2]['elements'][$ke]);
}
// if ($ke != '1DUCUE6') { // TEST TEST TEST TEST TEST TEST TEST
// unset($diff[$k1]['etapes'][$k2]['elements'][$ke]);
// }
}
if (empty($diff[$k1]['etapes'][$k2]['elements'])) {
unset($diff[$k1]['etapes'][$k2]);
}
}
if (empty($diff[$k1]['etapes'])) {
unset($diff[$k1]);
}
}
return $diff;
}
......
......@@ -6,6 +6,8 @@
* @var $diff array
*/
use Application\Filter\StringFromFloat;
$title = "Différentiel entre deux exports des charges d'enseignement";
$uploader = $this->uploader();
......@@ -21,29 +23,137 @@ echo '<div class="row">';
echo '<div class="col-md-6">';
echo $this->formControlGroup($form->get('avant'));
echo $this->formControlGroup($form->get('avant-fichier'));
echo '</div>';
echo '<div class="col-md-6">';
echo $this->formControlGroup($form->get('apres'));
echo $this->formControlGroup($form->get('apres-fichier'));
echo '</div>';
echo '</div>';
echo $this->formSubmit($form->get('submit'));
echo $this->form()->closeTag();
if (!empty($diff)) {
?>
<script type="text/javascript">
$(function () {
$("[name='avant'").change(function () {
var value = $(this).val();
if (value == 'export') {
$("[name=avant-fichier").show();
} else {
$("[name=avant-fichier").hide();
}
});
$("[name='apres'").change(function () {
var value = $(this).val();
if (value == 'export') {
$("[name=apres-fichier").show();
} else {
$("[name=apres-fichier").hide();
}
});
$("[name='avant'").change();
$("[name='apres'").change();
});
</script>
<?php
$tks = [
'seuil-ouverture' => 'Seuil d\'ouverture',
'seuil-dedoublement' => 'Seuil de dédoublement',
'assiduite' => 'Assiduité',
'heures-ens' => 'Heures d\'enseignement',
'groupes' => 'Groupes',
'heures' => 'Heures',
'hetd' => 'HETD',
];
if (null === $diff) {
echo '<br /><div class="alert alert-warning">Veuillez choisir vos exports de charges d\'enseignement...</div>';
} elseif (empty($diff)) {
echo '<br /><div class="alert alert-info">Il n\'y a aucune différence entre les deux exports de charges</div>';
} else {
echo '<br /><div class="well">';
$first = true;
echo '<ul class="nav nav-tabs" role="tablist">';
foreach ($diff as $dk => $dc) {
echo '<li role="presentation"' . ($first ? ' class="active"' : '') . '><a href="#composante-' . $dk . '" aria-controls="home" role="tab" data-toggle="tab">' . $dc['libelle'] . '</a></li>';
$first = false;
}
echo '</ul>';
echo '<div class="tab-content">';
foreach ($diff as $dc) {
echo '<h2>' . $dc['libelle'] . '</h2>';
foreach ($diff as $dk => $dc) {
echo '<div role="tabpanel" class="tab-pane active" id="composante-' . $dk . '">';
echo '<br /><h2>' . $dc['libelle'] . '</h2>';
foreach ($dc['etapes'] as $de) {
echo '<h3>' . $de['libelle'] . '</h3>';
echo '<div class="panel panel-default">';
echo '<div class="panel-heading">';
echo '<h3 class="panel-title"><span class="label label-default">' . $de['code'] . '</span> ' . $de['libelle'] . '</h3>';
echo '</div>';
echo '<div class="panel-body">';
foreach ($de['elements'] as $ep) {
echo '<h4>' . $ep['libelle'] . ' (' . $ep['code'] . ')</h4>';
var_dump($ep);
$diff = $ep['diff'];
echo '<h4><span class="label label-default">' . $ep['code'] . '</span> ' . $ep['libelle'] . '</h4>';
echo '<div style="margin-left:2em;">';
if (is_array($diff)) {
echo '<table class="table table-bordered table-condensed table-extra-condensed table-hover">';
echo '<tr><th style="width:50%">Différentiel</th><th style="width:25%">Ancien</th><th style="width:25%">Nouveau</th></tr>';
if (isset($diff['effectifs'])) {
echo '<tr><th>Effectifs</th><td></td><td></td></tr>';
foreach ($diff['effectifs'] as $th => $null) {
echo '<tr><th style="padding-left:2em">' . strtoupper($th) . '</th>'
. '<td>' . StringFromFloat::run($ep['avant']['effectifs'][$th], false) . '</td>'
. '<td>' . StringFromFloat::run($ep['apres']['effectifs'][$th], false) . '</td>'
. '</tr>';
}
}
if (isset($diff['ti'])) {
foreach ($diff['ti'] as $ti => $tdata) {
if (is_array($tdata)) {
echo '<tr><th>' . $ti . '</th><td></td><td></td></tr>';
foreach ($tdata as $tk => $null) {
echo '<tr><th style="padding-left:2em">' . (isset($tks[$tk]) ? $tks[$tk] : $tk) . '</th>'
. '<td>' . StringFromFloat::run($ep['avant']['ti'][$ti][$tk], false) . '</td>'
. '<td>' . StringFromFloat::run($ep['apres']['ti'][$ti][$tk], false) . '</td>'
. '</tr>';
}
} else {
echo '<tr><th>' . $ti . '</th><td colspan="2">';
if ($tdata == 'new') {
echo '<span class="label label-info">Nouveau type d\'intervention</span>';
} elseif ($tdata == 'old') {
echo '<span class="label label-warning">Ancien type d\'intervention</span>';
}
echo '</td></tr>';
}
}
}
echo '</table>';
} else {
if ($diff == 'new') {
echo '<p class="alert alert-info">Pas de charges pour comparaison dans le premier export </p >';
} elseif ($diff == 'old') {
echo '<p class="alert alert-warning"> Pas de charges pour comparaison dans l\'export le plus récent </p >';
}
}
echo '</div > ';
}
echo '</div > ';
echo '</div > ';
}
echo '</div > ';
}
echo '</div > ';
echo '</div > ';
}
?>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment