Commit 1c8ebed5 authored by Laurent Lécluse's avatar Laurent Lécluse
Browse files

Finalisation de l'interface de test de la formule de calcul

parent 81b8518c
......@@ -49,6 +49,19 @@ return [
],
'may_terminate' => true,
],
'enregistrement' => [
'type' => 'Segment',
'options' => [
'route' => '/enregistrement[/:formuleTestIntervenant]',
'constraints' => [
'formuleTestIntervenant' => '[0-9]*',
],
'defaults' => [
'action' => 'test-enregistrement',
],
],
'may_terminate' => true,
],
'supprimer' => [
'type' => 'Segment',
'options' => [
......@@ -111,7 +124,7 @@ return [
PrivilegeController::class => [
[
'controller' => 'Application\Controller\Formule',
'action' => ['test', 'test-saisir', 'test-supprimer'],
'action' => ['test', 'test-saisir', 'test-enregistrement', 'test-supprimer'],
'privileges' => [Privileges::FORMULE_TESTS],
],
],
......@@ -132,9 +145,4 @@ return [
],
],
'form_elements' => [
'factories' => [
Form\FormuleTest\IntervenantForm::class => Form\FormuleTest\Factory\IntervenantFormFactory::class,
],
],
];
\ No newline at end of file
......@@ -3,9 +3,18 @@
namespace Application\Controller;
use Application\Entity\Db\Annee;
use Application\Entity\Db\EtatVolumeHoraire;
use Application\Entity\Db\Formule;
use Application\Entity\Db\FormuleTestIntervenant;
use Application\Form\FormuleTest\Traits\IntervenantFormAwareTrait;
use Application\Entity\Db\FormuleTestStructure;
use Application\Entity\Db\TypeIntervenant;
use Application\Entity\Db\TypeVolumeHoraire;
use Application\Service\Traits\ContextServiceAwareTrait;
use Application\Service\Traits\FormuleTestIntervenantServiceAwareTrait;
use Application\Service\Traits\ParametresServiceAwareTrait;
use UnicaenApp\View\Model\MessengerViewModel;
use Zend\View\Model\JsonModel;
/**
* Description of FormuleController
......@@ -15,7 +24,8 @@ use Application\Service\Traits\FormuleTestIntervenantServiceAwareTrait;
class FormuleController extends AbstractController
{
use FormuleTestIntervenantServiceAwareTrait;
use IntervenantFormAwareTrait;
use ContextServiceAwareTrait;
use ParametresServiceAwareTrait;
public function testAction()
{
......@@ -31,26 +41,28 @@ class FormuleController extends AbstractController
/* @var $formuleTestIntervenant FormuleTestIntervenant */
$formuleTestIntervenant = $this->getEvent()->getParam('formuleTestIntervenant');
$form = $this->getFormFormuleTestIntervenant();
$structures = $this->em()->createQuery("SELECT s FROM ".FormuleTestStructure::class." s ORDER BY s.libelle")->execute();
$formules = $this->em()->createQuery("SELECT f FROM ".Formule::class." f ORDER BY f.id")->execute();
$annees = $this->em()->createQuery("SELECT a FROM ".Annee::class." a WHERE a.id BETWEEN 2013 AND 2030 ORDER BY a.id")->execute();
$typesIntervenants = $this->em()->createQuery("SELECT ti FROM ".TypeIntervenant::class." ti ORDER BY ti.id")->execute();
$typesVh = $this->em()->createQuery("SELECT t FROM ".TypeVolumeHoraire::class." t ORDER BY t.id")->execute();
$etatsVh = $this->em()->createQuery("SELECT t FROM ".EtatVolumeHoraire::class." t ORDER BY t.id")->execute();
$annee = $this->getServiceContext()->getAnnee();
$formuleId = $this->getServiceParametres()->get('formule');
if (!$formuleTestIntervenant) {
$title = 'Ajout d\'un test de formule';
$formuleTestIntervenant = new FormuleTestIntervenant();
} else {
$title = 'Modification d\'un test de formule';
}
$form->bindRequestSave($formuleTestIntervenant, $this->getRequest(), function (FormuleTestIntervenant $fti) {
try {
$this->getServiceFormuleTestIntervenant()->save($fti);
$this->flashMessenger()->addSuccessMessage('Test de formule bien enregistré');
return $this->redirect()->toRoute('formule-calcul/test');
} catch (\Exception $e) {
$this->getServiceFormuleTestIntervenant()->calculer($formuleTestIntervenant);
}catch(\Exception $e){
$this->flashMessenger()->addErrorMessage($this->translate($e));
}
});
}
return compact('form', 'formuleTestIntervenant', 'title');
return compact('formuleTestIntervenant', 'title', 'annee', 'formuleId', 'structures', 'formules', 'annees', 'typesIntervenants', 'typesVh', 'etatsVh');
}
......@@ -58,7 +70,7 @@ class FormuleController extends AbstractController
public function testSupprimerAction()
{
/* @var $formuleTestIntervenant FormuleTestIntervenant */
$formuleTestIntervenant = $this->getEvent()->getParam('FormuleTestIntervenant');
$formuleTestIntervenant = $this->getEvent()->getParam('formuleTestIntervenant');
try {
$this->getServiceFormuleTestIntervenant()->delete($formuleTestIntervenant);
......@@ -72,6 +84,62 @@ class FormuleController extends AbstractController
public function testEnregistrementAction()
{
/* @var $formuleTestIntervenant FormuleTestIntervenant */
$formuleTestIntervenant = $this->getEvent()->getParam('formuleTestIntervenant');
if (!$formuleTestIntervenant){
$formuleTestIntervenant = new FormuleTestIntervenant();
}
$result = ['errors' => '', 'data' => []];
$data = json_decode($this->params()->fromPost('data'), true);
$formuleTestIntervenant->fromArray($data);
$passed = true;
if (!$formuleTestIntervenant->getLibelle()){
$result['errors'][] = 'Libellé manquant';
$passed = false;
}
if (!$formuleTestIntervenant->getFormule()){
$result['errors'][] = 'La formule à utiliser n\'est pas précisée';
$passed = false;
}
if (!$formuleTestIntervenant->getAnnee()){
$result['errors'][] = 'L\'année doit être renseignée';
$passed = false;
}
if (!$formuleTestIntervenant->getTypeIntervenant()){
$result['errors'][] = 'Le type d\'intervenant (permanent, vacataire) doit être renseigné';
$passed = false;
}
if (!$formuleTestIntervenant->getStructureTest()){
$result['errors'][] = 'La structure doit être renseignée';
$passed = false;
}
if (!$formuleTestIntervenant->getTypeVolumeHoraire()){
$result['errors'][] = 'Le type de volume horaire (prévu ou réalisé) doit être renseigné';
$passed = false;
}
if (!$formuleTestIntervenant->getEtatVolumeHoraire()){
$result['errors'][] = 'L\'état de volume horaire (saisi, validé, etc) doit être renseigné';
$passed = false;
}
if ($passed) {
$this->getServiceFormuleTestIntervenant()->save($formuleTestIntervenant);
try {
$this->getServiceFormuleTestIntervenant()->calculer($formuleTestIntervenant);
} catch (\Exception $e) {
$result['errors'] = $this->translate($e);
}
}
$result['data'] = $formuleTestIntervenant->toArray();
return new JsonModel($result);
}
public function calculerToutAction()
{
$this->em()->getConnection()->exec('BEGIN OSE_FORMULE.CALCULER_TOUT; END;');
......
......@@ -8,6 +8,7 @@ use Application\Entity\Db\Traits\FormuleAwareTrait;
use Application\Entity\Db\Traits\FormuleTestStructureAwareTrait;
use Application\Entity\Db\Traits\TypeIntervenantAwareTrait;
use Application\Entity\Db\Traits\TypeVolumeHoraireAwareTrait;
use Application\Hydrator\FormuleTestIntervenantHydrator;
class FormuleTestIntervenant
{
......@@ -113,9 +114,11 @@ class FormuleTestIntervenant
/**
* @param string $libelle
*/
public function setLibelle(string $libelle)
public function setLibelle(string $libelle): FormuleTestIntervenant
{
$this->libelle = $libelle;
return $this;
}
......@@ -133,9 +136,11 @@ class FormuleTestIntervenant
/**
* @param float $heuresDecharge
*/
public function setHeuresDecharge(float $heuresDecharge)
public function setHeuresDecharge(float $heuresDecharge): FormuleTestIntervenant
{
$this->heuresDecharge = $heuresDecharge;
return $this;
}
......@@ -153,9 +158,11 @@ class FormuleTestIntervenant
/**
* @param float $heuresServiceStatutaire
*/
public function setHeuresServiceStatutaire(float $heuresServiceStatutaire)
public function setHeuresServiceStatutaire(float $heuresServiceStatutaire): FormuleTestIntervenant
{
$this->heuresServiceStatutaire = $heuresServiceStatutaire;
return $this;
}
......@@ -173,9 +180,11 @@ class FormuleTestIntervenant
/**
* @param float $heuresServiceModifie
*/
public function setHeuresServiceModifie(float $heuresServiceModifie)
public function setHeuresServiceModifie(float $heuresServiceModifie): FormuleTestIntervenant
{
$this->heuresServiceModifie = $heuresServiceModifie;
return $this;
}
......@@ -183,7 +192,7 @@ class FormuleTestIntervenant
/**
* @return bool
*/
public function isDepassementServiceDuSansHC(): bool
public function getDepassementServiceDuSansHC(): bool
{
return $this->depassementServiceDuSansHC;
}
......@@ -193,9 +202,11 @@ class FormuleTestIntervenant
/**
* @param bool $depassementServiceDuSansHC
*/
public function setDepassementServiceDuSansHC(bool $depassementServiceDuSansHC)
public function setDepassementServiceDuSansHC(bool $depassementServiceDuSansHC): FormuleTestIntervenant
{
$this->depassementServiceDuSansHC = $depassementServiceDuSansHC;
return $this;
}
......@@ -213,9 +224,11 @@ class FormuleTestIntervenant
/**
* @param string $param1
*/
public function setParam1(string $param1)
public function setParam1(string $param1): FormuleTestIntervenant
{
$this->param1 = $param1;
return $this;
}
......@@ -233,9 +246,11 @@ class FormuleTestIntervenant
/**
* @param string $param2
*/
public function setParam2(string $param2)
public function setParam2(string $param2): FormuleTestIntervenant
{
$this->param2 = $param2;
return $this;
}
......@@ -253,9 +268,11 @@ class FormuleTestIntervenant
/**
* @param string $param3
*/
public function setParam3(string $param3)
public function setParam3(string $param3): FormuleTestIntervenant
{
$this->param3 = $param3;
return $this;
}
......@@ -273,9 +290,11 @@ class FormuleTestIntervenant
/**
* @param string $param4
*/
public function setParam4(string $param4)
public function setParam4(string $param4): FormuleTestIntervenant
{
$this->param4 = $param4;
return $this;
}
......@@ -293,9 +312,11 @@ class FormuleTestIntervenant
/**
* @param string $param5
*/
public function setParam5(string $param5)
public function setParam5(string $param5): FormuleTestIntervenant
{
$this->param5 = $param5;
return $this;
}
......@@ -313,9 +334,11 @@ class FormuleTestIntervenant
/**
* @param float $aServiceDu
*/
public function setAServiceDu(float $aServiceDu)
public function setAServiceDu(float $aServiceDu): FormuleTestIntervenant
{
$this->aServiceDu = $aServiceDu;
return $this;
}
......@@ -333,9 +356,11 @@ class FormuleTestIntervenant
/**
* @param float $cServiceDu
*/
public function setCServiceDu(float $cServiceDu)
public function setCServiceDu(float $cServiceDu): FormuleTestIntervenant
{
$this->cServiceDu = $cServiceDu;
return $this;
}
......@@ -357,7 +382,7 @@ class FormuleTestIntervenant
*
* @return Service
*/
public function addVolumeHoraireTest(FormuleTestVolumeHoraire $volumeHoraireTest)
public function addVolumeHoraireTest(FormuleTestVolumeHoraire $volumeHoraireTest): FormuleTestIntervenant
{
$this->volumeHoraireTest[] = $volumeHoraireTest;
......@@ -371,9 +396,23 @@ class FormuleTestIntervenant
*
* @param FormuleTestVolumeHoraire $volumeHoraireTest
*/
public function removeVolumeHoraireTest(FormuleTestVolumeHoraire $volumeHoraireTest)
public function removeVolumeHoraireTest(FormuleTestVolumeHoraire $volumeHoraireTest): FormuleTestIntervenant
{
$this->volumeHoraireTest->removeElement($volumeHoraireTest);
return $this;
}
/**
* @return FormuleTestIntervenant
*/
public function clearVolumeHoraireTest(): FormuleTestIntervenant
{
$this->volumeHoraireTest->clear();
return $this;
}
......@@ -390,6 +429,330 @@ class FormuleTestIntervenant
/**
* @return float
*/
public function getAServiceFi()
{
$sum = 0;
foreach ($this->getVolumeHoraireTest() as $vht) {
$sum += $vht->getAServiceFi();
}
return $sum;
}
/**
* @return float
*/
public function getAServiceFa()
{
$sum = 0;
foreach ($this->getVolumeHoraireTest() as $vht) {
$sum += $vht->getAServiceFa();
}
return $sum;
}
/**
* @return float
*/
public function getAServiceFc()
{
$sum = 0;
foreach ($this->getVolumeHoraireTest() as $vht) {
$sum += $vht->getAServiceFc();
}
return $sum;
}
/**
* @return float
*/
public function getAServiceReferentiel()
{
$sum = 0;
foreach ($this->getVolumeHoraireTest() as $vht) {
$sum += $vht->getAServiceReferentiel();
}
return $sum;
}
/**
* @return float
*/
public function getAHeuresComplFi()
{
$sum = 0;
foreach ($this->getVolumeHoraireTest() as $vht) {
$sum += $vht->getAHeuresComplFi();
}
return $sum;
}
/**
* @return float
*/
public function getAHeuresComplFa()
{
$sum = 0;
foreach ($this->getVolumeHoraireTest() as $vht) {
$sum += $vht->getAHeuresComplFa();
}
return $sum;
}
/**
* @return float
*/
public function getAHeuresComplFc()
{
$sum = 0;
foreach ($this->getVolumeHoraireTest() as $vht) {
$sum += $vht->getAHeuresComplFc();
}
return $sum;
}
/**
* @return float
*/
public function getAHeuresComplFcMajorees()
{
$sum = 0;
foreach ($this->getVolumeHoraireTest() as $vht) {
$sum += $vht->getAHeuresComplFcMajorees();
}
return $sum;
}
/**
* @return float
*/
public function getAHeuresComplReferentiel()
{
$sum = 0;
foreach ($this->getVolumeHoraireTest() as $vht) {
$sum += $vht->getAHeuresComplReferentiel();
}
return $sum;
}
/**
* @return float
*/
public function getCServiceFi()
{
$sum = 0;
foreach ($this->getVolumeHoraireTest() as $vht) {
$sum += $vht->getCServiceFi();
}
return $sum;
}
/**
* @return float
*/
public function getCServiceFa()
{
$sum = 0;
foreach ($this->getVolumeHoraireTest() as $vht) {
$sum += $vht->getCServiceFa();
}
return $sum;
}
/**
* @return float
*/
public function getCServiceFc()
{
$sum = 0;
foreach ($this->getVolumeHoraireTest() as $vht) {
$sum += $vht->getCServiceFc();
}
return $sum;
}
/**
* @return float
*/
public function getCServiceReferentiel()
{
$sum = 0;
foreach ($this->getVolumeHoraireTest() as $vht) {
$sum += $vht->getCServiceReferentiel();
}
return $sum;
}
/**
* @return float
*/
public function getCHeuresComplFi()
{
$sum = 0;
foreach ($this->getVolumeHoraireTest() as $vht) {
$sum += $vht->getCHeuresComplFi();
}
return $sum;
}
/**
* @return float
*/
public function getCHeuresComplFa()
{
$sum = 0;
foreach ($this->getVolumeHoraireTest() as