Commit 26ede631 authored by Antony Le Courtes's avatar Antony Le Courtes
Browse files

- Envoyer le contrat par email à l'intervenant.

parent 07495afa
Loading
Loading
Loading
Loading
+17 −5
Original line number Diff line number Diff line
@@ -93,6 +93,18 @@ return [
                            ],
                        ],
                    ],
                    'envoyer-mail'        => [
                        'type'    => 'Segment',
                        'options' => [
                            'route'       => '/:contrat/mail',
                            'constraints' => [
                                'contrat' => '[0-9]*',
                            ],
                            'defaults'    => [
                                'action' => 'envoyer-mail',
                            ],
                        ],
                    ],
                    'deposer-fichier'     => [
                        'type'    => 'Segment',
                        'options' => [
@@ -211,7 +223,7 @@ return [
                ],
                [
                    'controller' => 'Application\Controller\Contrat',
                    'action'     => ['exporter'],
                    'action'     => ['exporter', 'envoyer-mail'],
                    'privileges' => [Privileges::CONTRAT_CONTRAT_GENERATION, Privileges::CONTRAT_PROJET_GENERATION],
                    'assertion'  => Assertion\ContratAssertion::class,
                ],
+41 −10
Original line number Diff line number Diff line
@@ -326,12 +326,35 @@ class ContratController extends AbstractController



    public function envoyerMailAction()
    {
        $contrat = $this->getEvent()->getParam('contrat');

        if (!$this->isAllowed($contrat, ContratAssertion::PRIV_EXPORT)) {
            throw new UnAuthorizedException("Interdiction d'envoyer le contrat par email");
        }

        if (!empty($contrat->getIntervenant()->getEmail())) {
            $phpRenderer = $this->getServiceLocator()->get('view_manager')->getRenderer();
            $html        = $phpRenderer->render('application/contrat/mail/contrat', [
                'contrat' => $contrat,
            ]);
            $message     = $this->getServiceModeleContrat()->prepareMail($contrat, $html);
            $this->mail()->send($message);
        }

        return $this->getResponse();
    }



    /**
     * Dépôt du contrat signé.
     *
     * @return Response
     */
    public function deposerFichierAction()
    public
    function deposerFichierAction()
    {
        $contrat = $this->getEvent()->getParam('contrat');
        /* @var $contrat Contrat */
@@ -360,7 +383,8 @@ class ContratController extends AbstractController
     *
     * @return aarray
     */
    public function listerFichierAction()
    public
    function listerFichierAction()
    {
        $contrat = $this->getEvent()->getParam('contrat');
        /* @var $contrat Contrat */
@@ -381,7 +405,8 @@ class ContratController extends AbstractController
     *
     * @throws UnAuthorizedException
     */
    public function telechargerFichierAction()
    public
    function telechargerFichierAction()
    {
        $contrat = $this->getEvent()->getParam('contrat');
        /* @var $contrat Contrat */
@@ -403,7 +428,8 @@ class ContratController extends AbstractController
     * @return Response
     * @throws UnAuthorizedException
     */
    public function supprimerFichierAction()
    public
    function supprimerFichierAction()
    {
        $this->initFilters();

@@ -429,7 +455,8 @@ class ContratController extends AbstractController



    private function updateTableauxBord(Intervenant $intervenant)
    private
    function updateTableauxBord(Intervenant $intervenant)
    {
        $this->getServiceWorkflow()->calculerTableauxBord([
            'formule',
@@ -439,7 +466,8 @@ class ContratController extends AbstractController



    public function modelesListeAction()
    public
    function modelesListeAction()
    {
        $modeles = $this->getServiceModeleContrat()->getList();

@@ -448,7 +476,8 @@ class ContratController extends AbstractController



    public function modelesEditerAction()
    public
    function modelesEditerAction()
    {
        /* @var $modeleContrat ModeleContrat */
        $modeleContrat = $this->getEvent()->getParam('modeleContrat');
@@ -476,7 +505,8 @@ class ContratController extends AbstractController



    public function modelesSupprimerAction()
    public
    function modelesSupprimerAction()
    {
        /* @var $modeleContrat ModeleContrat */
        $modeleContrat = $this->getEvent()->getParam('modeleContrat');
@@ -493,7 +523,8 @@ class ContratController extends AbstractController



    public function modelesTelechargerAction()
    public
    function modelesTelechargerAction()
    {
        /* @var $modeleContrat ModeleContrat */
        $modeleContrat = $this->getEvent()->getParam('modeleContrat');
+56 −6
Original line number Diff line number Diff line
@@ -5,6 +5,10 @@ namespace Application\Service;
use Application\Entity\Db\Contrat;
use Application\Entity\Db\ModeleContrat;
use Unicaen\OpenDocument\Document;
use Zend\Mail\Message as MailMessage;
use Zend\Mime\Message;
use Zend\Mime\Mime;
use Zend\Mime\Part;

/**
 * Description of ModeleContratService
@@ -59,7 +63,7 @@ class ModeleContratService extends AbstractEntityService



    public function generer(Contrat $contrat)
    public function generer(Contrat $contrat, $download = true)
    {
        $fileName = sprintf(($contrat->estUnAvenant() ? 'avenant' : 'contrat') . "_%s_%s_%s.pdf",
            $contrat->getStructure()->getCode(),
@@ -92,7 +96,55 @@ class ModeleContratService extends AbstractEntityService
        $document->getPublisher()->setAutoBreak(true);
        $document->publish($this->generateData($modele, $contrat));
        $document->setPdfOutput(true);
        if ($download) {
            $document->download($fileName);
        } else {

            return $document;
        }
    }



    public function prepareMail(Contrat $contrat, String $htmlContent)
    {
        $fileName = sprintf(($contrat->estUnAvenant() ? 'avenant' : 'contrat') . "_%s_%s_%s.pdf",
            $contrat->getStructure()->getCode(),
            $contrat->getIntervenant()->getNomUsuel(),
            $contrat->getIntervenant()->getCode());

        $document = $this->generer($contrat, false);
        $content  = $document->saveToData();

        $subject          = "Contrat " . $contrat->getIntervenant()->getCivilite() . " " . $contrat->getIntervenant()->getNomUsuel();
        $emailIntervenant = $contrat->getIntervenant()->getEmail();

        $body = new Message();

        // Contenu HTML du mail
        $text          = new Part($htmlContent);
        $text->type    = Mime::TYPE_HTML;
        $text->charset = 'utf-8';
        $body->addPart($text);

        //Contrat en pièce jointe
        $attachment              = new Part($content);
        $attachment->type        = 'application/pdf';
        $attachment->disposition = Mime::DISPOSITION_ATTACHMENT;
        $attachment->encoding    = Mime::ENCODING_BASE64;
        $attachment->filename    = $fileName;
        $body->addPart($attachment);

        $message     = new MailMessage();
        $messageType = 'multipart/related';
        $message->setEncoding('UTF-8')
            ->setFrom(\AppConfig::get('mail', 'from'), "Application OSE")
            ->setSubject($subject)
            ->addTo($emailIntervenant)
            ->setBody($body)
            ->getHeaders()->get('content-type')->setType($messageType);

        return $message;
    }


@@ -221,6 +273,4 @@ class ModeleContratService extends AbstractEntityService
        return $this;
    }



}
 No newline at end of file
+4 −0
Original line number Diff line number Diff line
<p>Bonjour <?= $contrat->getIntervenant()->getCivilite()->getLibelleCourt() . " ". $contrat->getIntervenant()->getNomUsuel(); ?></p>

<p>Veuillez trouver en pièce jointe votre contrat à jour.</p>
<p>Cordialement.</p>
+28 −0
Original line number Diff line number Diff line
@@ -13,6 +13,10 @@ $validation = $contrat->getValidation();
$retourSigne = $contrat->getDateRetourSigne();
$uploader    = $this->uploader();

$urlEmail = $this->isAllowed($contrat, ContratAssertion::PRIV_EXPORT)
    ? $this->url('contrat/envoyer-mail', ['contrat' => $contrat->getId()])
    : null;

$urlExport = $this->isAllowed($contrat, ContratAssertion::PRIV_EXPORT)
    ? $this->url('contrat/exporter', ['contrat' => $contrat->getId()]) // oui car on peut le voir!!
    : null;
@@ -41,6 +45,8 @@ $urlSuppression = $this->isAllowed($contrat, Privileges::CONTRAT_SUPPRESSION)
    ? $this->url('contrat/supprimer', ['contrat' => $contrat->getId()])
    : null;

$disableEmail = (empty($contrat->getIntervenant()->getEmail()))?true:false;

if ($urlAjouter) {
    $uploader->setUrl($urlAjouter);
}
@@ -50,14 +56,36 @@ $panel = ($retourSigne !== null) ? 'success' : ($validation ? 'info' : 'default'
?>
<div class="contrat panel panel-<?= $panel ?>" id="contrat-<?= $contrat->getId() ?>">
    <div class="panel-heading panel-heading-h3">
        <?php if ($urlExport): ?>
            <span class="pull-right">
                <?php if($disableEmail): ?>
                    <a class="disabled btn btn-<?= $panel ?>" href="<?= $urlEmail ?>" title="L'intervenant du contrat n'a pas renseigné son email.">
                <?php endif; ?>
                <?php if(!$disableEmail): ?>
                    <a class="btn btn-<?= $panel ?> pop-ajax"
                       title="Envoyer le contrat par mail"
                       data-content="Souhaitez vous vraiment envoyer le contrat par email ?"
                       data-confirm="true"
                       data-confirm-button="Oui"
                       data-cancel-button="Non"
                       data-submit-reload="true"
                       href="<?= $urlEmail ?>">
                <?php endif; ?>
                <span class="glyphicon glyphicon-send"></span> Envoyer par mail
            </a>
            </span>
        <?php endif; ?>
        <!-- Lien de téléchargement du fichier -->
        <?php if ($urlExport): ?>

            <span class="pull-right">
            <a class="btn btn-<?= $panel ?>" href="<?= $urlExport ?>" title="Exporter le contrat/avenant au format PDF">
                <span class="glyphicon glyphicon-export"></span> Exporter en PDF
            </a>
            </span>
        <?php endif; ?>
        <!-- Lien de téléchargement du fichier -->

        <h3><?= $contrat->toString() ?> - <?= $contrat->getStructure() ?></h3>
    </div>