Commit 124b49cc authored by Laurent Lécluse's avatar Laurent Lécluse
Browse files

Finalisation diff chargens

parent 4948956e
......@@ -355,6 +355,8 @@ class ChargensController extends AbstractController
{
$form = $this->getFormChargensDifferentiel();
$avantLibelle = null;
$apresLibelle = null;
$diff = null;
if ($this->getRequest()->isPost()) {
......@@ -368,29 +370,41 @@ class ChargensController extends AbstractController
$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());
try {
if ($data['avant'] == 'export' && isset($data['avant-fichier']['tmp_name'])) {
$avant = $pce->fromCsv($data['avant-fichier']['tmp_name']);
$avantLibelle = $data['avant-fichier']['name'];
} else {
[$avantAnneeId, $avantScenarioId] = explode('-', $data['avant']);
/** @var $avantAnnee Annee */
$avantAnnee = $this->em()->find(Annee::class, $avantAnneeId);
/** @var $avantScenario Scenario */
$avantScenario = $this->em()->find(Scenario::class, $avantScenarioId);
$avant = $pce->fromBdd($avantAnnee, $avantScenario, $this->getServiceContext()->getStructure());
$avantLibelle = $avantScenario->getLibelle() . ' ' . $avantAnnee->getLibelle();
}
if ($data['apres'] == 'export' && isset($data['apres-fichier']['tmp_name'])) {
$apres = $pce->fromCsv($data['apres-fichier']['tmp_name']);
$apresLibelle = $data['apres-fichier']['name'];
} else {
[$apresAnneeId, $apresScenarioId] = explode('-', $data['apres']);
/** @var $apresAnnee Annee */
$apresAnnee = $this->em()->find(Annee::class, $apresAnneeId);
/** @var $apresScenario Scenario */
$apresScenario = $this->em()->find(Scenario::class, $apresScenarioId);
$apres = $pce->fromBdd($apresAnnee, $apresScenario, $this->getServiceContext()->getStructure());
$apresLibelle = $apresScenario->getLibelle() . ' ' . $apresAnnee->getLibelle();
}
$diff = $pce->diff($avant, $apres);
} catch (\Exception $e) {
$this->flashMessenger()->addErrorMessage($e->getMessage());
}
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());
}
$diff = $pce->diff($avant, $apres);
}
}
return compact('form', 'diff');
return compact('form', 'diff', 'avantLibelle', 'apresLibelle');
}
......
......@@ -93,8 +93,17 @@ class ExportProvider
{
$data = [];
$row = 1;
if (!$filename) {
throw new \Exception('Fichier non fourni');
}
if (!file_exists($filename)) {
throw new \Exception('Fichier inexistant ou inaccessible');
}
if (($handle = fopen($filename, "r")) !== false) {
fgetcsv($handle, 9999, ";");
$head = fgetcsv($handle, 9999, ";");
if (!$this->checkGoodCSV($head)) {
throw new \Exception('Le fichier CSV fourni n\'est pas un export des charges d\'enseignement');
}
while (($d = fgetcsv($handle, 9999, ";")) !== false) {
$l = [
......@@ -137,6 +146,16 @@ class ExportProvider
protected function checkGoodCSV(array $data)
{
return
(isset($data[24]) && $data[24] === 'HETD')
&& (isset($data[22]) && $data[22] === 'Groupes')
&& (isset($data[1]) && $data[1] === 'Composante porteuse (code)');
}
public function toCsv(array $data): CsvModel
{
$csvModel = new CsvModel();
......@@ -215,9 +234,15 @@ class ExportProvider
$typeHeures = array_keys($d['avant']['effectifs']);
foreach ($typeHeures as $typeHeure) {
// if ($d['avant']['effectifs'][$typeHeure] != $d['apres']['effectifs'][$typeHeure]) {
$rd['effectifs'][$typeHeure] = true;
// }
$this->diff[$k1]['etapes'][$k2]['elements'][$ke]['avant']['effectifs'][$typeHeure] =
$d['avant']['effectifs'][$typeHeure] / count($d['avant']['ti']);
$this->diff[$k1]['etapes'][$k2]['elements'][$ke]['apres']['effectifs'][$typeHeure] =
$d['apres']['effectifs'][$typeHeure] / count($d['apres']['ti']);
if ($d['avant']['effectifs'][$typeHeure] != $d['apres']['effectifs'][$typeHeure]) {
$rd['effectifs'][$typeHeure] = true;
}
}
foreach ($typesIntervention as $typeIntervention) {
......@@ -234,9 +259,9 @@ class ExportProvider
$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 ($d['avant']['ti'][$ti][$k] != $d['apres']['ti'][$ti][$k]) {
$rdti[$k] = true;
}
}
if (!empty($rdti)) {
$rd['ti'][$ti] = $rdti;
......@@ -257,9 +282,9 @@ class ExportProvider
if (empty($d['diff'])) {
unset($this->diff[$k1]['etapes'][$k2]['elements'][$ke]);
}
if ($ke != 'M.AN-4B') { // TEST TEST TEST TEST TEST TEST TEST
unset($this->diff[$k1]['etapes'][$k2]['elements'][$ke]);
}
// if ($ke != 'act_3925') { // TEST TEST TEST TEST TEST TEST TEST
// unset($this->diff[$k1]['etapes'][$k2]['elements'][$ke]);
// }
}
if (empty($this->diff[$k1]['etapes'][$k2]['elements'])) {
unset($this->diff[$k1]['etapes'][$k2]);
......@@ -285,6 +310,14 @@ class ExportProvider
if (!array_key_exists($spc, $this->diff)) {
$this->diff[$spc] = [
'libelle' => $a['structure-porteuse-libelle'],
'avant' => [
'heures' => 0,
'hetd' => 0,
],
'apres' => [
'heures' => 0,
'hetd' => 0,
],
'etapes' => [],
];
}
......@@ -292,6 +325,14 @@ class ExportProvider
$this->diff[$spc]['etapes'][$epc] = [
'code' => $a['etape-porteuse-code'],
'libelle' => $a['etape-porteuse-libelle'],
'avant' => [
'heures' => 0,
'hetd' => 0,
],
'apres' => [
'heures' => 0,
'hetd' => 0,
],
'elements' => [],
];
}
......@@ -332,6 +373,12 @@ class ExportProvider
$this->diff[$spc]['etapes'][$epc]['elements'][$ec][$avap]['ti'][$ti]['groupes'] += $a['groupes'];
$this->diff[$spc]['etapes'][$epc]['elements'][$ec][$avap]['ti'][$ti]['heures'] += $a['heures'];
$this->diff[$spc]['etapes'][$epc]['elements'][$ec][$avap]['ti'][$ti]['hetd'] += $a['hetd'];
$this->diff[$spc][$avap]['heures'] += $a['heures'];
$this->diff[$spc][$avap]['hetd'] += $a['hetd'];
$this->diff[$spc]['etapes'][$epc][$avap]['heures'] += $a['heures'];
$this->diff[$spc]['etapes'][$epc][$avap]['hetd'] += $a['hetd'];
}
......
<?php
/**
* @var $this \Application\View\Renderer\PhpRenderer
* @var $form \Application\Form\Chargens\DifferentielForm
* @var $diff array
* @var $this \Application\View\Renderer\PhpRenderer
* @var $form \Application\Form\Chargens\DifferentielForm
* @var $diff array
* @var $avantLibelle string
* @var $apresLibelle string
*/
use Application\Filter\StringFromFloat;
......@@ -58,6 +60,19 @@ echo $this->form()->closeTag();
}
});
$(".diff-details-ep").click(function () {
var pb = $(this).parent().parent().parent();
var etapeElements = pb.find('.etape-elements');
if (etapeElements.is(':hidden')) {
etapeElements.show();
$(this).html('Masquer les éléments <span class="glyphicon glyphicon-arrow-up"></span>');
} else {
etapeElements.hide();
$(this).html('Afficher les éléments <span class="glyphicon glyphicon-arrow-down"></span>');
}
});
$("[name='avant'").change();
$("[name='apres'").change();
......@@ -76,7 +91,10 @@ $tks = [
'hetd' => 'HETD',
];
if (null === $diff) {
$error = (string)$this->messenger()->addCurrentMessagesFromFlashMessenger();
if ($error) {
echo '<br />' . $error;
} elseif (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>';
......@@ -94,19 +112,57 @@ if (null === $diff) {
foreach ($diff as $dk => $dc) {
echo '<div role="tabpanel" class="tab-pane active" id="composante-' . $dk . '">';
echo '<br /><h2>' . $dc['libelle'] . '</h2>';
echo '<table class="table table-bordered table-condensed" style="width:70%">'
. '<tr><th style="width:25%">Totaux Heures/HETD</th><th style="width:25%">' . $avantLibelle . '</th><th style="width:25%">' . $apresLibelle . '</th><th style="width:25%">Différence</th></tr>'
. '<tr>'
. '<th>Heures</th>'
. '<td>' . StringFromFloat::run($dc['avant']['heures'], false) . '</td>'
. '<td>' . StringFromFloat::run($dc['apres']['heures'], false) . '</td>'
. '<td>' . StringFromFloat::run($dc['apres']['heures'] - $dc['avant']['heures'], false) . '</td>'
. '</tr>'
. '<tr>'
. '<th>HETD</th>'
. '<td>' . StringFromFloat::run($dc['avant']['hetd'], false) . '</td>'
. '<td>' . StringFromFloat::run($dc['apres']['hetd'], false) . '</td>'
. '<td>' . StringFromFloat::run($dc['apres']['hetd'] - $dc['avant']['hetd'], false) . '</td>'
. '</tr>'
. '</table>';
foreach ($dc['etapes'] as $de) {
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">';
echo '<div class="row">';
echo '<div class="col-md-9">';
echo '<table class="table table-bordered table-condensed">'
. '<tr><th style="width:25%">Totaux Heures/HETD</th><th style="width:25%">' . $avantLibelle . '</th><th style="width:25%">' . $apresLibelle . '</th><th style="width:25%">Différence</th></tr>'
. '<tr>'
. '<th>Heures</th>'
. '<td>' . StringFromFloat::run($de['avant']['heures'], false) . '</td>'
. '<td>' . StringFromFloat::run($de['apres']['heures'], false) . '</td>'
. '<td>' . StringFromFloat::run($de['apres']['heures'] - $de['avant']['heures'], false) . '</td>'
. '</tr>'
. '<tr>'
. '<th>HETD</th>'
. '<td>' . StringFromFloat::run($de['avant']['hetd'], false) . '</td>'
. '<td>' . StringFromFloat::run($de['apres']['hetd'], false) . '</td>'
. '<td>' . StringFromFloat::run($de['apres']['hetd'] - $de['avant']['hetd'], false) . '</td>'
. '</tr>'
. '</table>';
echo '</div>';
echo '<div class="col-md-3">';
echo '<button class="btn btn-info diff-details-ep">Afficher les éléments <span class="glyphicon glyphicon-arrow-down"></span></button>';
echo '</div>';
echo '</div>';
echo '<div class="etape-elements" style="display:none">';
foreach ($de['elements'] as $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>';
echo '<tr><th style="width:50%">Différentiel</th><th style="width:25%">' . $avantLibelle . '</th><th style="width:25%">' . $apresLibelle . '</th></tr>';
if (isset($diff['effectifs'])) {
echo '<tr><th>Effectifs</th><td></td><td></td></tr>';
foreach ($diff['effectifs'] as $th => $null) {
......@@ -149,6 +205,7 @@ if (null === $diff) {
}
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