Skip to content
Snippets Groups Projects
Commit 560f717e authored by gauthierb's avatar gauthierb
Browse files

Ajout saisie de la date de retour signé (possibilité de la modifier/vider).

parent e30d6b49
No related branches found
No related tags found
No related merge requests found
......@@ -80,6 +80,18 @@ return array(
),
),
),
'saisir-retour' => array(
'type' => 'Segment',
'options' => array(
'route' => '/:contrat/saisir-retour',
'constraints' => array(
'contrat' => '[0-9]*',
),
'defaults' => array(
'action' => 'saisir-retour',
),
),
),
'exporter' => array(
'type' => 'Segment',
'options' => array(
......@@ -125,7 +137,7 @@ return array(
'BjyAuthorize\Guard\Controller' => array(
array(
'controller' => 'Application\Controller\Contrat',
'action' => array('creer', 'valider', 'devalider'),
'action' => array('creer', 'valider', 'devalider', 'saisir-retour'),
'roles' => array(ComposanteRole::ROLE_ID),
),
array(
......
......@@ -16,6 +16,7 @@ use UnicaenApp\Exporter\Pdf;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Application\Form\Intervenant\ContratValidation;
use Application\Form\Intervenant\ContratRetour;
use Application\Entity\Db\Contrat;
/**
......@@ -35,11 +36,6 @@ class ContratController extends AbstractActionController implements ContextProvi
*/
private $contrat;
/**
* @var ViewModel
*/
private $view;
/**
*
* @return array
......@@ -257,13 +253,14 @@ class ContratController extends AbstractActionController implements ContextProvi
$this->contrat = $this->context()->mandatory()->contratFromRoute();
$this->intervenant = $this->contrat->getIntervenant();
$form = $this->getFormValidationContrat()->setContrat($this->contrat)->init();
$title = "Validation " . lcfirst($this->contrat->toString(true, true)) . " <small>$this->intervenant</small>";
$contratToString = $this->contrat->toString(true);
$title = "Validation $contratToString <small>$this->intervenant</small>";
$process = $this->getProcessContrat();
$messages = [];
$rule = new \Application\Rule\Intervenant\PeutValiderContratRule($this->intervenant, $this->contrat);
if (!$rule->execute()) {
throw new \Common\Exception\MessageException("Impossible de valider le contrat/avenant.", null, new \Exception($rule->getMessage()));
throw new \Common\Exception\MessageException("Impossible de valider $contratToString.", null, new \Exception($rule->getMessage()));
}
$this->em()->getFilters()->enable('historique');
......@@ -349,11 +346,54 @@ class ContratController extends AbstractActionController implements ContextProvi
return $viewModel;
}
private function getView()
/**
* Saisie de la date de retour du contrat/avenant signé par l'intervenant.
*
* @return \Zend\View\Model\ViewModel
* @throws Common\Exception\MessageException
*/
public function saisirRetourAction()
{
if (null === $this->view) {
$this->view = new ViewModel();
$role = $this->getContextProvider()->getSelectedIdentityRole();
$this->structure = $role->getStructure();
$this->contrat = $this->context()->mandatory()->contratFromRoute();
$this->intervenant = $this->contrat->getIntervenant();
$form = $this->getFormRetourContrat()->setContrat($this->contrat)->init();
$contratToString = $this->contrat->toString(true, true);
$title = "Retour $contratToString signé <small>$this->intervenant</small>";
$process = $this->getProcessContrat();
$messages = [];
$rule = new \Application\Rule\Intervenant\PeutSaisirRetourContratRule($this->intervenant, $this->contrat);
if (!$rule->execute()) {
throw new \Common\Exception\MessageException(
"Impossible de saisir la date de retour $contratToString.",
null,
new \Exception($rule->getMessage()));
}
$form ->bind($this->contrat)
->setAttribute('action', $this->url()->fromRoute(null, array(), array(), true));
if ($this->getRequest()->isPost()) {
$data = $this->getRequest()->getPost();
$form->setData($data);
if ($form->isValid()) {
$this->em()->flush();
$this->flashMessenger()->addSuccessMessage(
"Saisie du retour $contratToString signé enregistrée avec succès.");
}
}
$this->view = new \Zend\View\Model\ViewModel(array(
'role' => $role,
'intervenant' => $this->intervenant,
'form' => $form,
'title' => $title,
'messages' => $messages,
));
return $this->view;
}
......@@ -455,6 +495,23 @@ class ContratController extends AbstractActionController implements ContextProvi
$exp->export($fileName, Pdf::DESTINATION_BROWSER_FORCE_DL);
}
/**
* @var ViewModel
*/
private $view;
/**
*
* @return ViewModel
*/
private function getView()
{
if (null === $this->view) {
$this->view = new ViewModel();
}
return $this->view;
}
private $formValider;
/**
......@@ -469,6 +526,20 @@ class ContratController extends AbstractActionController implements ContextProvi
return $this->formValider;
}
private $formRetour;
/**
* @return ContratRetour
*/
protected function getFormRetourContrat()
{
if (null === $this->formRetour) {
$this->formRetour = new ContratRetour();
}
return $this->formRetour;
}
private $intervenant;
/**
......
<?php
namespace Application\Form\Intervenant;
use Zend\Form\Element\Csrf;
use Zend\Form\Form;
use Zend\InputFilter\InputFilterProviderInterface;
use Zend\Stdlib\Hydrator\ClassMethods;
/**
* Formulaire de saisie de la date de retour du contrat/avenant signé.
*
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/
class ContratRetour extends Form implements InputFilterProviderInterface
{
use \Application\Traits\ContratAwareTrait;
public function init()
{
$this->setHydrator(new ClassMethods(false));
$this->setAttribute('method', 'POST');
$contratToString = lcfirst($this->getContrat()->toString(true));
$this->add(array(
'name' => 'dateRetourSigne',
'type' => 'UnicaenApp\Form\Element\Date',
'options' => array(
'label' => "Date de retour $contratToString signé",
),
'attributes' => array(
),
));
$this->add(new Csrf('security'));
$this->add(array(
'name' => 'submit',
'type' => 'Submit',
'attributes' => array(
'value' => "Enregistrer",
),
));
$this->getHydrator()->addStrategy('dateRetourSigne', new \UnicaenApp\Hydrator\Strategy\DateStrategy($this->get('dateRetourSigne')));
return $this;
}
/**
* Should return an array specification compatible with
* {@link Zend\InputFilter\Factory::createInputFilter()}.
*
* @return array
*/
public function getInputFilterSpecification()
{
return array(
'valide' => array(
'required' => false,
),
);
}
}
\ No newline at end of file
<?php
namespace Application\Rule\Intervenant;
use Application\Entity\Db\Intervenant;
use Application\Entity\Db\Contrat;
/**
* Description of PeutSaisirRetourContratRule
*
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/
class PeutSaisirRetourContratRule extends IntervenantRule
{
use \Application\Service\Initializer\ContratServiceAwareTrait;
private $contrat;
public function __construct(Intervenant $intervenant, Contrat $contrat)
{
parent::__construct($intervenant);
$this->contrat = $contrat;
}
public function execute()
{
$contratToString = $this->contrat->toString(true);
if (!($validation = $this->contrat->getValidation())) {
$this->setMessage("$contratToString n'est pas encore validé.");
return false;
}
return true;
}
public function isRelevant()
{
return $this->getIntervenant()->getStatut()->estVacataire();
}
}
\ No newline at end of file
......@@ -5,7 +5,12 @@ $role = $this->role;
?>
<style>
th.structure, td.structure { max-width: 100px; }
th.structure, td.structure { width: 100px; }
th.retour, td.retour { width: 75px; }
</style>
<style>
.ui-datepicker{z-index:1151 !important; }
</style>
<?php if ($contrats): ?>
......@@ -14,7 +19,7 @@ $role = $this->role;
<tr>
<th class="structure">Composante d'enseignement</th>
<th>Contrat ou avenant</th>
<th>Retour<br />signé</th>
<th class="retour">Retour<br />signé</th>
</tr>
</thead>
<tbody>
......@@ -25,6 +30,7 @@ $role = $this->role;
$urlExport = $this->url('contrat/exporter', array('contrat' => $contrat->getId()));
$urlValidation = $this->url('contrat/valider', array('contrat' => $contrat->getId()));
$urlDevalidation = $this->url('contrat/devalider', array('contrat' => $contrat->getId()));
$urlSaisieRetour = $this->url('contrat/saisir-retour', array('contrat' => $contrat->getId()));
?>
<td class="structure"><?php echo $contrat->getStructure() ?></td>
<td>
......@@ -41,7 +47,7 @@ $role = $this->role;
<?php echo $this->messenger()->setMessage((string)$this->validationDl($validation), 'success') ?>
<?php if ($role instanceof Application\Acl\ComposanteDbRole && $contrat->estUnAvenant()): ?>
<a href="<?php echo $urlDevalidation ?>" class="btn btn-primary ajax-modal"
data-event="event-validation-suppr">Suppimer la validation <?php echo $contrat->toString(true, true) ?></a>
data-event="event-validation-suppr">Supprimer la validation <?php echo $contrat->toString(true, true) ?></a>
<?php endif; ?>
<?php else: ?>
<?php if ($role instanceof Application\Acl\ComposanteDbRole): ?>
......@@ -57,7 +63,14 @@ $role = $this->role;
'services' => $this->services[$contrat->getId()])) ?>
</p>
</td>
<td><?php echo ($d = $contrat->getDateRetourSigne()) ? $d->format(Common\Constants::DATETIME_FORMAT) : null ?></td>
<td class="retour">
<?php echo ($d = $contrat->getDateRetourSigne()) ? $d->format(Common\Constants::DATE_FORMAT) : null ?>
<?php if ($role instanceof Application\Acl\ComposanteDbRole && $contrat->getValidation()): ?>
<a href="<?php echo $urlSaisieRetour ?>" class="btn btn-primary ajax-modal"
data-event="event-saisie-retour-suppr"
title="Cliquez pour saisir la date de retour <?php echo $contrat->toString(true, true) ?> signé">Saisir</a>
<?php endif ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
......@@ -68,7 +81,7 @@ $role = $this->role;
<script>
$("body").on("event-contrat-validation event-validation-suppr", function(event, data) {
$("body").on("event-contrat-validation event-validation-suppr event-saisie-retour-suppr", function(event, data) {
event.div.modal('hide'); // ferme la fenêtre modale
window.location.reload();
});
......
<h2 class="page-header"><?php echo $title ?></h2>
<?php echo $this->messenger(true)->addMessages($messages) ?>
<?php $form->prepare(); ?>
<?php echo $this->form()->openTag($form); ?>
<div class="row">
<div class="col-md-8">
<?php
echo $this->formControlGroup($form->get('dateRetourSigne'));
echo $this->formHidden($form->get('security'));
?>
</div>
</div>
<hr />
<?php echo $this->formSubmit($form->get('submit')->setAttribute('class', 'btn btn-primary')); ?>
<?php echo $this->form()->closeTag();
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment