Commit 81f4b3cb authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

Amélioration de l'UI pour fluidifier le processus de soumission PCRU

FIX : Upload du marker de fin de transfert PCRU
parent c951ce1a
Loading
Loading
Loading
Loading
+5 −12
Original line number Diff line number Diff line
@@ -2779,17 +2779,6 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
        return $view;
    }

//    public function pcruAction()
//    {
//        if (!$this->getOscarConfigurationService()->getPcruEnabled()) {
//            throw new OscarException("Le module PCR n'est pas activé");
//        }
//        $activity = $this->getActivityFromRoute();
//        $this->getOscarUserContextService()->check(Privileges::ACTIVITY_PCRU, $activity);
//
//        die("NOT IMPLEMENTED");
//    }

    /**
     * Affiche la liste des activités soumises à un processus PCRU.
     *
@@ -2833,10 +2822,10 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
            $action = $this->params()->fromPost('action');
            if( $action == 'upload' ){
                $this->getProjectGrantService()->getPCRUService()->upload();
                $this->redirect()->toRoute('contract/pcru-list');
            }
        }


        return [
            'downloadable' => $this->getProjectGrantService()->getPCRUService()->hasDownload(),
            'uploadable' => !$this->getProjectGrantService()->getPCRUService()->hasUploadInProgress(),
@@ -2868,6 +2857,10 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
                case 'add-pool':
                    $this->getProjectGrantService()->getPCRUService()->addToPool($activity);
                    break;

                case 'download':
                    $this->getProjectGrantService()->getPCRUService()->downloadOne($activity);
                    break;
            }
            return $this->redirect()->toRoute('contract/pcru-infos', ['id' => $activity->getId() ]);
        }
+82 −6
Original line number Diff line number Diff line
@@ -139,6 +139,65 @@ class PCRUService implements UseLoggerService, UseOscarConfigurationService, Use
        return !file_exists($lockfile);
    }

    /**
     * Télécharge un aperçu des documents PCRU pour l'activité donnée.
     *
     * @param Activity $activity
     */
    public function downloadOne(Activity $activity): void
    {
        $num = $activity->getOscarNum();

        $ziptmp = "/tmp/pcru-preview-zip-$num-" . uniqid() . ".zip";
        $csvtmp = "/tmp/pcru-preview-csv-$num-" . uniqid() . ".zip";
        $pdftmp = "/tmp/pcru-preview-pdf-$num-" . uniqid() . ".zip";

        // Récupération des données
        $pcruInfos = $this->getPcruInfosActivity($activity);


        if (!$pcruInfos) {
            $factory = new ActivityPcruInfoFromActivityFactory($this->getOscarConfigurationService(), $this->getEntityManager());
            $pcruInfos = $factory->createNew($activity);
        }

        $csvFile = new PCRUCvsFile($this);
        $csvFile->addEntry($pcruInfos);
        $csvFile->writeContratsCsv($csvtmp);
        file_put_contents($pdftmp, $csvFile->getDocumentSignedFromPcruInfo($pcruInfos));

        // Création de l'archive
        $zip = new \ZipArchive();
        if ($zip->open($ziptmp, \ZipArchive::CREATE) !== TRUE) {
            throw new OscarException("Impossible de créer l'archive");
        }
        $zip->addFile($csvtmp, 'contrats.csv');
        $zip->addFile($pdftmp, $num . '.pdf');
        $zip->close();

        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename="oscar-pcru-preview-' . $num . '.zip"');
        header('Expires: 0');
        header('Cache-Control: must-revalidate');
        header('Pragma: public');
        readfile($ziptmp);

        unlink($csvtmp);
        unlink($pdftmp);
        unlink($ziptmp);
        exit;

    }

    /**
     * Ajoute une activité à la file d'attente du prochain envoi PCRU.
     *
     * @param $activityOrPcruInfos
     * @throws OscarException
     * @throws \Doctrine\ORM\ORMException
     * @throws \Doctrine\ORM\OptimisticLockException
     */
    public function addToPool($activityOrPcruInfos): void
    {
        if ($this->isPoolOpen()) {
@@ -455,6 +514,16 @@ class PCRUService implements UseLoggerService, UseOscarConfigurationService, Use
            fclose($handle);
        }

        $remotePath = 'pcru';
        $local_file = '/tmp/PCRU_MARKER.tmp';
        $remote_file = $remotePath . '/RETOUR-PCRU.OK';
        $pcruResponseFile = $remotePath . '/CONTRACT-PCRU.csv';

        // Fichier à déposer une fois le transfert terminé
        $marker_complete = 'DEPOT-PDF.OK';
        $marker_complete_tmp = '/tmp/' . $marker_complete;
        $marker_complete_remote = $remotePath . DIRECTORY_SEPARATOR . $marker_complete;


        $this->logPool("Connexion FTP...");
        $co = $this->ftpConnect();
@@ -462,15 +531,9 @@ class PCRUService implements UseLoggerService, UseOscarConfigurationService, Use
        // Mode PASSIVE
        ftp_pasv($co, true);

        $remotePath = 'pcru';
        $local_file = '/tmp/PCRU_MARKER.tmp';
        $remote_file = $remotePath . '/PCRU.OK';
        $pcruResponseFile = $remotePath . '/CONTRACT.PCRU.OK';

        // Ouverture du fichier pour écriture
        $handle = fopen($local_file, 'w');


        // On récupère les fichier FTP
        $remoteFiles = ftp_nlist($co, $remotePath);

@@ -530,7 +593,19 @@ class PCRUService implements UseLoggerService, UseOscarConfigurationService, Use

                fclose($stream);
            }

            // Ajout du fichier marker
            $this->logPool("Ajout du marqueur");
            file_put_contents($marker_complete_tmp, "");
            $marker = fopen($marker_complete_tmp, 'r');

            ftp_pasv($co, true);
            if (!ftp_fput($co, $marker_complete_remote, $marker, FTP_BINARY)) {
                $errors = error_get_last();
                $err = "Erreur FTP, impossible d'envoyer le $marker_complete" . $errors['message'];
                $this->logPool($err);
            }
            fclose($marker);

            ftp_close($co);

@@ -543,6 +618,7 @@ class PCRUService implements UseLoggerService, UseOscarConfigurationService, Use
            }

        }
    }

    /**
     * Génère les donnèes PCRU à partir de l'activité
+27 −11
Original line number Diff line number Diff line
@@ -153,9 +153,11 @@ class PCRUCvsFile
     * @return $this
     * @throws \Oscar\Exception\OscarException
     */
    public function writeContratsCsv()
    public function writeContratsCsv($dest=null)
    {
        if( $dest == null ){
            $dest = $this->pcruService->getOscarConfigurationService()->getPcruContratFile();
        }
        $handler = fopen($dest, 'w');
        fputcsv($handler, $this->getHeaders(), ';');
        foreach ($this->getData() as $data) {
@@ -164,6 +166,27 @@ class PCRUCvsFile
        return $this;
    }

    /**
     * Retourne le contenu du document (Contrat Signé) référencé dans les informations PCRU.
     *
     * @param ActivityPcruInfos $pcruInfos
     * @return string
     * @throws OscarException
     */
    public function getDocumentSignedFromPcruInfo(ActivityPcruInfos $pcruInfos) :string
    {
        /** @var ContractDocument $document */
        $document = $this->pcruService->getEntityManager()
            ->getRepository(ContractDocument::class)
            ->find($pcruInfos->getDocumentId());

        $docpath = $this->pcruService->getOscarConfigurationService()->getDocumentDropLocation()
            . DIRECTORY_SEPARATOR
            . $document->getPath();

        return file_get_contents($docpath);
    }

    /**
     * @return $this
     */
@@ -178,17 +201,10 @@ class PCRUCvsFile
            // traitement du document
            $filedest = $this->path . DIRECTORY_SEPARATOR . $info->getSignedFileName();

            /** @var ContractDocument $document */
            $document = $this->pcruService->getEntityManager()
                ->getRepository(ContractDocument::class)
                ->find($info->getDocumentId());

            $docpath = $this->pcruService->getOscarConfigurationService()->getDocumentDropLocation()
                . DIRECTORY_SEPARATOR
                . $document->getPath();
            $doccontent = $this->getDocumentSignedFromPcruInfo($info);

            $this->log("Ajout du document $docpath");
            file_put_contents($filedest, file_get_contents($docpath));
            $this->log("Ajout du document");
            file_put_contents($filedest, $doccontent);

            $returnedInfos[] = $info;
        }
+51 −18
Original line number Diff line number Diff line
@@ -6,6 +6,12 @@
        <h2><?= $activity ?></h2>
    </header>

    <?php
    $activable = false;
    $downloadable = false;
    $poolable = false;
    ?>

    <?php if(count($errors)): ?>
        <div class="alert alert-danger">
            <p><strong>Cette activité ne peut pas être envoyée à PCRU</strong>, certaines informations sont manquantes / erronées : </p>
@@ -18,31 +24,34 @@
    <?php endif; ?>

    <?php switch($status):
        case 'preview' : ?>
        case 'preview' : $downloadable = true; $activable = true; ?>
        <div class="alert alert-success">
        Toutes les informations requises semblent correctes. Vous pouvez déclencher l'envois des informations à PCRU.
        <form action="" method="post">
            <button type="submit" class="btn btn-success" name="action" value="activate-pcru">
                <i class="icon-paper-plane"></i>
                Activer l'envoi PCRU
            </button>
        </form>
            Toutes les informations requises semblent correctes. Vous pouvez <strong>activer PCRU</strong> pour cette activité.
        </div>
    <?php break;  ?>

    <?php case 'send_pending' : $downloadable = true; ?>
        <div class="alert alert-success">
            Les données ont été transférées vers PCRU, en attente d'un retour PCRU.
        </div>
    <?php break;  ?>

    <?php case 'send_pending' : ?>
    <?php case 'send_ready' : $poolable = true; $downloadable = true; ?>
        <div class="alert alert-success">
            Les données ont étaient transférées, en attente d'un retour PCRU.
            <?php if($poolopen): ?>
            Vous pouvez activer le transfert PCRU, elles seront envoyées lors du prochain transfert.
            <?php else: ?>
            Les données sont prêtes, un tranfert PCRU est déjà en attente de retour.
            <?php endif; ?>
        </div>
    <?php break;  ?>

    <?php case 'send_ready' : ?>
    <?php case 'file_wait' : $downloadable = true; ?>
        <div class="alert alert-success">
            Les données sont prêtes à être envoyées.
            <?php if($poolopen): ?>
            <form action="" method="post"><button name="action" value="add-pool">Ajouter au prochain envoi</button></form>
                Données en attentes, elles seront envoyées lors du prochain transfert.
            <?php else: ?>
            Vous devez attendre avoir de pouvoir envoyer les donnèes PCRU (un envoi a déjà été fait récamment et est en attente de traitement)
                Les données en attentes, un tranfert PCRU est déjà en attente de retour.
            <?php endif; ?>
        </div>
    <?php break;  ?>
@@ -62,6 +71,33 @@
            <i class="icon-pencil"></i>
            Modifier la fiche activité</a>
        <?php endif; ?>

        <?php if($activable): ?>
            <form action="" method="post" class="form-inline">
                <button type="submit" class="btn btn-success" name="action" value="activate-pcru">
                    <i class="icon-paper-plane"></i>
                    Activer PCRU
                </button>
            </form>
        <?php endif; ?>

        <?php if($poolable): ?>
            <form action="" method="post" class="form-inline">
                <button type="submit" class="btn btn-success" name="action" value="add-pool">
                    <i class="icon-paper-plane"></i>
                    Transferer vers PCRU
                </button>
            </form>
        <?php endif; ?>

        <?php if($downloadable): ?>
            <form action="" method="post" class="form-inline">
                <button type="submit" class="btn btn-default" name="action" value="download-pcru">
                    <i class="icon-download"></i>
                    Télécharger les documents PCRU (aperçu)
                </button>
            </form>
        <?php endif; ?>
    </nav>

    <?php if( !$documentPath ): ?>
@@ -70,6 +106,7 @@
    </div>
    <?php endif; ?>

    <h3>Aperçu des données PCRU</h3>
    <table class="table table-bordered card xs">
        <thead>
            <tr>
@@ -121,10 +158,6 @@

    </table>

    <nav>
        <button class="btn btn-info">Télécharger le fichier CSV (PCRU)</button>
    </nav>

    <?php /******************************* ANCIENNE VERSION
    <div id="app" style="visibility: hidden">
        <div class="">
+31 −16
Original line number Diff line number Diff line
@@ -5,9 +5,9 @@
    <!-- <div id="recherche"></div> -->
    <p class="alert alert-info">
        Les activités présentes dans cet écran sont soumises à un processus PCRU.<br>
        Pour activer le processus PCRU d'un activité, rendez-vous sur la fiche activité, puis dans l'encart PCRU, cliquez sur <strong>informations PCRU</strong>, une fois dans le récapitulatif des informations, cliquez sur <strong>Activer PCRU</strong>
        Pour activer le processus PCRU d'une activité, rendez-vous sur la fiche activité, puis dans l'encart PCRU, cliquez sur <strong>informations PCRU</strong>, une fois dans le récapitulatif des informations, cliquez sur <strong>Activer PCRU</strong>
    </p>
    <?php if(count($pcruInfos) == null): ?>
    <?php if(count($pcruInfos) == 0): ?>
    <div class="alert alert-warning">
        Aucun processus PCRU en cours
    </div>
@@ -17,14 +17,29 @@
        /** @var \Oscar\Entity\ActivityPcruInfos $pcruInfo */
        foreach ($pcruInfos as $pcruInfo): ?>
        <article class="card xs">
            <h3>
            <h4>
                <strong><?= $pcruInfo->getAcronyme() ?></strong>
                <em><?= $pcruInfo->getObjet() ?></em>
                <span class="cartouche">
                    <?= $pcruInfo->getStatus() ?>
                    <?= $pcruInfo->getStatusStr() ?>
                </span>
                <a href="<?= $this->url('contract/show', ['id' => $pcruInfo->getActivity()->getId()]) ?>">Voir la fiche activité</a>
                <?php switch($pcruInfo->getStatus()):
                    case 'file_wait': ?>
                    <span class="cartouche xs success">
                        <i class="icon-hourglass-3"></i>
                        En attente de transfert</span>
                <?php break; ?>

                <?php case 'send_pending': ?>
                    <span class="cartouche xs success">
                        <i class="icon-paper-plane"></i>
                        Transférée (en attente d'un retour)</span>
                <?php break; ?>

                <?php default: ?>
                    <pre><?php var_dump($pcruInfos); ?></pre>
                <?php break; ?>
                <?php endswitch; ?>
                <a href="<?= $this->url('contract/show', ['id' => $pcruInfo->getActivity()->getId()]) ?>">
                    <i class="icon-cube"></i>
                    Voir la fiche activité</a>
        </article>
        <?php endforeach; ?>
    </section>
@@ -32,27 +47,26 @@
    <nav>

        <?php if( $downloadable == true): ?>
            <a href="?a=download" class="btn btn-primary">
            <a href="?a=download" class="btn btn-default">
                <i class="icon-download"></i>
                Télécharger les fichiers pour PCRU
                Télécharger les fichiers PCRU en attente
            </a>
        <?php else: ?>
            <div class="alert alert-info">Il n'y a aucun documents PCRU en attente</div>
        <?php endif; ?>


        <?php if( $uploadable == true): ?>
        <form action="" method="post">
        <form action="" method="post" class="form-inline">
            <button value="upload" name="action" class="btn btn-primary">
                <i class="icon-upload"></i>
                Uploader les fichiers vers PCRU
                Transferer vers PCRU
            </button>
        </form>
        <?php else: ?>
            <div class="alert alert-info">Un processus PCRU est déjà en cours</div>
            <div class="alert alert-info">Un processus PCRU est déjà en cours (En attente d'un retour)</div>
        <?php endif; ?>

        <?php if( $hasready == true): ?>
        <form action="" method="post">
        <form action="" method="post" class="form-inline">
            <button value="activate" name="action" class="btn btn-primary">
                <i class="icon-upload"></i>
                Ajouter au prochain upload les infos prêtes
@@ -60,6 +74,7 @@
        </form>
        <?php endif; ?>


    </nav>