From aedbd12b659444f9bca1b51b5fd3c79ab6ddccd8 Mon Sep 17 00:00:00 2001
From: lvessiller <lvessiller@open-dsi.fr>
Date: Fri, 25 Sep 2020 17:57:42 +0200
Subject: [PATCH] NEW cases a cocher pour choisir entre l'indexation et
 archivage lors de l'execution finale de dematerialisation des bulletins de
 paie

---
 appinfo/info.xml                   |   2 +-
 css/style.css                      |  17 +-
 lib/Controller/PageController.php  | 499 +++++++++++++++++------------
 templates/content/archive_list.php |  10 +-
 templates/content/index.php        | 105 +++---
 5 files changed, 364 insertions(+), 269 deletions(-)

diff --git a/appinfo/info.xml b/appinfo/info.xml
index 4de0808..24c99ad 100644
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -5,7 +5,7 @@
     <name>Bulletins</name>
     <summary>Dématérialisation des bulletins de paie</summary>
     <description><![CDATA[Dématérialisation des bulletins de paie]]></description>
-    <version>2.0.0</version>
+    <version>2.0.1</version>
     <licence>agpl</licence>
     <author mail="support@open-dsi.fr" >Open-DSI</author>
     <namespace>Dematpayslip</namespace>
diff --git a/css/style.css b/css/style.css
index c9d28e1..428c8b2 100644
--- a/css/style.css
+++ b/css/style.css
@@ -2,10 +2,25 @@
 	margin: 20px;
 }
 
-legend.dematpayslip_legend {
+.dematpayslip_legend {
 	font-weight: bold;
 }
 
+#dematpayslip label span {
+	display: inline-block;
+	min-width: 250px;
+	padding: 8px 0;
+	vertical-align: middle;
+}
+
+#dematpayslip input {
+	vertical-align: middle;
+}
+
+#dematpayslip input[type="text"],
+#dematpayslip input[type="password"] {
+	width: 240px;
+}
 
 
 /*
diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php
index 9f1c65a..336621e 100644
--- a/lib/Controller/PageController.php
+++ b/lib/Controller/PageController.php
@@ -2,18 +2,19 @@
 namespace OCA\Dematpayslip\Controller;
 
 use OC\Files\Filesystem;
-use OCA\DAV\Db\Direct;
-use OCA\Gallery\Environment\NotFoundEnvException;
 use OCP\Files\NotFoundException;
 use OCP\IConfig;
 use OCP\IL10N;
 use OCP\IRequest;
 use OCP\AppFramework\Http\TemplateResponse;
-use OCP\AppFramework\Http\DataResponse;
-use OCP\AppFramework\Http\JSONResponse;
+//use OCP\AppFramework\Http\DataResponse;
+//use OCP\AppFramework\Http\JSONResponse;
 use OCP\AppFramework\Controller;
 
+use OC;
 use OC_App;
+use DateTime;
+use Exception;
 use OCP\Files\Folder;
 use OCA\Dematpayslip\Db\DematpayslipArchive;
 use OCA\Dematpayslip\Db\DematpayslipArchiveMapper;
@@ -24,13 +25,9 @@ use OCA\Dematpayslip\Db\DematpayslipProcessSkipMapper;
 use OCA\Dematpayslip\Db\DematpayslipUser;
 use OCA\Dematpayslip\Db\DematpayslipUserMapper;
 
-use OCA\Pastell\Db\PastellConfig;
-use OCA\Pastell\Db\PastellConfigMapper;
-use OCA\Pastell\Db\PastellConfigFlow;
 use OCA\Pastell\Db\PastellConfigFlowMapper;
 
 use OCA\Pastell\PastellAPI;
-use phpseclib\Crypt\Hash;
 
 class PageController extends Controller {
     const LOG_SUCCESS = 0;
@@ -38,7 +35,7 @@ class PageController extends Controller {
     const LOG_WARNING = 2;
     const LOG_ERROR   = 3;
 
-    const PROCESS_TIME_UNLOCK = 600; // seconds (max execution time)
+    const PROCESS_TIME_UNLOCK = 60; // seconds (max execution time)
 
     const PHASE_ID_UPLOAD = 0;
     const PHASE_ID_CHECK  = 1;
@@ -88,7 +85,7 @@ class PageController extends Controller {
     private $_csvEncodeTo = 'UTF-8';
 
     /**
-     * @var File handler Log file
+     * @var resource handler Log file
      */
     private $_logFile = null;
 
@@ -119,7 +116,7 @@ class PageController extends Controller {
     private $_process;
     private $_canCancelProcess = false;
 
-    /** @var Folder path */
+    /** @var string folder path */
     private $_uploadDirUserPath;
     private $_uploadDirFullPath;
     private $_checkDirUserPath;
@@ -163,7 +160,7 @@ class PageController extends Controller {
      * @param   string                      $endDate                        Period end date
      * @return  mixed|DematpayslipArchive|\OCP\AppFramework\Db\Entity|null
      *
-     * @throws \Exception
+     * @throws  Exception
      */
     private function _archiveCheckBeforeSave(DematpayslipArchiveMapper $dematpayslipArchiveMapper, DematpayslipUser $agentUser, $startDate, $endDate) {
         $dematpayslipArchive = null;
@@ -207,7 +204,7 @@ class PageController extends Controller {
 
         // Pastell API config
         $pastellConfigFlowId = $this->config->getAppValue($this->appName, 'pastell_config_f' . $archiveFlowNum . '_id', '');
-        $pastellConfigFlowMapper = new PastellConfigFlowMapper(\OC::$server->getDatabaseConnection());
+        $pastellConfigFlowMapper = new PastellConfigFlowMapper(OC::$server->getDatabaseConnection());
         $pastellConfigFlow = $pastellConfigFlowMapper->find($pastellConfigFlowId);
 
         try {
@@ -233,7 +230,7 @@ class PageController extends Controller {
             } else {
                 // 1. create document
                 if (empty($dematpayslipArchive->getPastellIdDocument())) {
-                    $nowDateTime = new \DateTime('now', \OC::$server->getDateTimeZone()->getTimeZone());
+                    $nowDateTime = new DateTime('now', OC::$server->getDateTimeZone()->getTimeZone());
                     $responseData = $pastellAPI->postEntityDocument($pastellConfigFlow->getIdE(), array(
                         'type' => 'pdf-generique'
                     ));
@@ -245,7 +242,7 @@ class PageController extends Controller {
                 }
                 // 2. set document title
                 if ($dematpayslipArchive->getStatus() == DematpayslipArchive::STATUS_CREATED) {
-                    $nowDateTime = new \DateTime('now', \OC::$server->getDateTimeZone()->getTimeZone());
+                    $nowDateTime = new DateTime('now', OC::$server->getDateTimeZone()->getTimeZone());
                     $responseData = $pastellAPI->patchEntityDocument($pastellConfigFlow->getIdE(), $dematpayslipArchive->getPastellIdDocument(), array(
                         'libelle' => $dematpayslipArchive->getId() . '_' . $dematpayslipArchive->getSiret() . '_' . $dematpayslipArchive->getMatricule() . '_' . $dematpayslipArchive->getStartDate() . '_' . $dematpayslipArchive->getEndDate()
                     ));
@@ -256,7 +253,7 @@ class PageController extends Controller {
                 }
                 // 3. send document file
                 if ($dematpayslipArchive->getStatus() == DematpayslipArchive::STATUS_TITLED) {
-                    $nowDateTime = new \DateTime('now', \OC::$server->getDateTimeZone()->getTimeZone());
+                    $nowDateTime = new DateTime('now', OC::$server->getDateTimeZone()->getTimeZone());
                     $fileId = $dematpayslipArchive->getIdFile();
                     $filePath = Filesystem::getPath($fileId);
                     $file = Filesystem::getFileInfo($filePath);
@@ -270,7 +267,7 @@ class PageController extends Controller {
                 }
                 // 4. send to SAE
                 if ($dematpayslipArchive->getStatus() == DematpayslipArchive::STATUS_FILE_SENT) {
-                    $nowDateTime = new \DateTime('now', \OC::$server->getDateTimeZone()->getTimeZone());
+                    $nowDateTime = new DateTime('now', OC::$server->getDateTimeZone()->getTimeZone());
                     $responseData = $pastellAPI->patchEntityDocument($pastellConfigFlow->getIdE(), $dematpayslipArchive->getPastellIdDocument(), array(
                         'envoi_sae' => true
                     ));
@@ -295,7 +292,7 @@ class PageController extends Controller {
                     $jsonFilePath = $this->_tmpDirUserPath . DIRECTORY_SEPARATOR . $jsonFileName;
                     Filesystem::fopen($jsonFilePath, 'w+');
                     Filesystem::file_put_contents($jsonFilePath, json_encode($saeConfigArr));
-                    $nowDateTime = new \DateTime('now', \OC::$server->getDateTimeZone()->getTimeZone());
+                    $nowDateTime = new DateTime('now', OC::$server->getDateTimeZone()->getTimeZone());
                     $jsonFileContent = Filesystem::file_get_contents($jsonFilePath);
                     $responseData = $pastellAPI->postEntityDocumentExternalData($pastellConfigFlow->getIdE(), $dematpayslipArchive->getPastellIdDocument(), 'sae_config', array(
                         'file_name'    => $jsonFileName,
@@ -308,7 +305,7 @@ class PageController extends Controller {
                 }
                 // 6. set orientation action on document
                 if ($dematpayslipArchive->getStatus() == DematpayslipArchive::STATUS_METADATA_SENT) {
-                    $nowDateTime = new \DateTime('now', \OC::$server->getDateTimeZone()->getTimeZone());
+                    $nowDateTime = new DateTime('now', OC::$server->getDateTimeZone()->getTimeZone());
                     $responseData = $pastellAPI->postEntityDocumentAction($pastellConfigFlow->getIdE(), $dematpayslipArchive->getPastellIdDocument(), 'orientation');
                     $dematpayslipArchive->setStatus(DematpayslipArchive::STATUS_ORIENTATION);
                     $dematpayslipArchive->setStatusTime($nowDateTime->getTimestamp());
@@ -328,7 +325,7 @@ class PageController extends Controller {
                     $this->_msgList['success'][] = $this->l->t('L\'archive "' . $dematpayslipArchive->getFilePath() . '" a été créée.');
                 }
             }
-        } catch (\Exception $e) {
+        } catch (Exception $e) {
             $this->_msgList['error'][] = $e->getMessage();
         }
     }
@@ -347,10 +344,10 @@ class PageController extends Controller {
      * @param   string                      $editionDate                Edition date
      * @param   int                         $importTime                 Import time
      *
-     * @throws  \Exception
+     * @throws  Exception
      */
     private function _archiveSaveForAgentAndPeriod(DematpayslipArchiveMapper $dematpayslipArchiveMapper, DematpayslipArchive $dematpayslipArchive, $archiveFilePath, DematpayslipUser $agentUser, $startDate, $endDate, $year, $month, $editionDate, $importTime) {
-        $nowDateTime = new \DateTime('now', \OC::$server->getDateTimeZone()->getTimeZone());
+        $nowDateTime = new DateTime('now', OC::$server->getDateTimeZone()->getTimeZone());
 
         $archiveFile         = Filesystem::getFileInfo($archiveFilePath);
         $archiveFileChecksum = Filesystem::hash('md5', $archiveFilePath);
@@ -382,6 +379,40 @@ class PageController extends Controller {
         }
     }
 
+    /**
+     * Save archive file for an agent and a period
+     *
+     * @param   string                      $pdfPayslipCheckFilePath    Pdf checked file path
+     * @param   DematpayslipArchiveMapper   $dematpayslipArchiveMapper  Archive table mapper
+     * @param   DematpayslipArchive         $dematpayslipArchive        Archive
+     * @param   string                      $archiveFilePath            Archive file path
+     * @param   DematpayslipUser            $agentUser                  Agent user
+     * @param   string                      $startDate                  Period start date
+     * @param   string                      $endDate                    Period end date
+     * @param   string                      $year                       Period year
+     * @param   string                      $month                      Period month
+     * @param   string                      $editionDate                Edition date
+     * @param   int                         $importTime                 Import time
+     * @return  int                         <0 if KO, >0 if OK
+     *
+     * @throws  Exception
+     */
+    private function _archiveSaveAndProcess($pdfPayslipCheckFilePath, DematpayslipArchiveMapper $dematpayslipArchiveMapper, DematpayslipArchive $dematpayslipArchive, $archiveFilePath, DematpayslipUser $agentUser, $startDate, $endDate, $year, $month, $editionDate, $importTime) {
+        if (!$archiveFilePath) {
+            $pdfPayslipCopyFileName = $agentUser->getSiret() . '-' . $agentUser->getMatricule() . '_' . $startDate . '-' . $endDate . '.pdf';
+            $pdfPayslipCopyFilePath = $this->_tmpDirUserPath . DIRECTORY_SEPARATOR . $pdfPayslipCopyFileName;
+            $fileCopied = Filesystem::copy($pdfPayslipCheckFilePath, $pdfPayslipCopyFilePath);
+            if (!$fileCopied) {
+                return -1;
+            }
+            $archiveFilePath = $pdfPayslipCopyFilePath;
+        }
+        $this->_archiveSaveForAgentAndPeriod($dematpayslipArchiveMapper, $dematpayslipArchive, $archiveFilePath, $agentUser, $startDate, $endDate, $year, $month, $editionDate, $importTime);
+        $this->_archiveProcess($dematpayslipArchiveMapper, $dematpayslipArchive);
+
+        return 1;
+    }
+
     /**
      * Assign params for template demat
      *
@@ -422,7 +453,7 @@ class PageController extends Controller {
         );
 
         // get archive list
-        $dematpayslipArchiveMapper = new DematpayslipArchiveMapper(\OC::$server->getDatabaseConnection());
+        $dematpayslipArchiveMapper = new DematpayslipArchiveMapper(OC::$server->getDatabaseConnection());
 
         if ($refresh === true) {
             if ($stepStatus === -1) {
@@ -447,7 +478,7 @@ class PageController extends Controller {
 
                     // Pastell API config
                     $pastellConfigFlowId = $this->config->getAppValue($this->appName, 'pastell_config_f' . $archiveFlowNum . '_id', '');
-                    $pastellConfigFlowMapper = new PastellConfigFlowMapper(\OC::$server->getDatabaseConnection());
+                    $pastellConfigFlowMapper = new PastellConfigFlowMapper(OC::$server->getDatabaseConnection());
                     $pastellConfigFlow = $pastellConfigFlowMapper->find($pastellConfigFlowId);
 
                     try {
@@ -460,7 +491,7 @@ class PageController extends Controller {
                             $dematpayslipArchive->setPastellLastAction($responseData['last_action']['action']);
                             $dematpayslipArchiveMapper->update($dematpayslipArchive);
                         }
-                    } catch (\Exception $e) {
+                    } catch (Exception $e) {
                         $this->_msgList['error'][] = $e->getMessage();
                     }
 
@@ -707,12 +738,12 @@ class PageController extends Controller {
      * @param   string                  $startDate      [=''] Start date
      * @param   string                  $endDate        [=''] End date
      *
-     * @throws  \Exception
+     * @throws  Exception
      */
     private function _logCsvLine($msg, $level = self::LOG_DEBUG, DematpayslipUser $agentUser = null, $startDate = '', $endDate = '') {
         if ($this->_logFile !== null) {
             if ($this->_logLevel <= $level || $level === self::LOG_SUCCESS) {
-                $dateTimeNow = new \DateTime('now', \OC::$server->getDateTimeZone()->getTimeZone());
+                $dateTimeNow = new DateTime('now', OC::$server->getDateTimeZone()->getTimeZone());
                 $logLevel = '';
                 switch ($level) {
                     case self::LOG_SUCCESS :
@@ -816,7 +847,7 @@ class PageController extends Controller {
     /**
      * Init application folders
      *
-     * @throws  \OC\User\NoUserException
+     * @throws  OC\User\NoUserException
      */
     private function _initDematFolders() {
         $appDataDirPath           = $this->_dematpayslipConfigList['app_data_dir']; // dematpayslip directory of user demat (upload, check, report, etc)
@@ -827,7 +858,7 @@ class PageController extends Controller {
         $this->_tmpDirUserPath    = $appDataDirPath . DIRECTORY_SEPARATOR . 'tmp';
 
         // recuperer le dossier de l'utilisateur Nextcloud
-        $user = \OC::$server->getUserManager()->get($this->userId);
+        $user = OC::$server->getUserManager()->get($this->userId);
         if (!$user) {
             $this->_msgList['error'][] = $this->l->t('Le dossier utilisateur "' . $this->userId . '" n\'existe pas.');
         }
@@ -878,7 +909,7 @@ class PageController extends Controller {
                 // dossier check
                 $isDir = Filesystem::is_dir($this->_checkDirUserPath);
                 if (!$isDir) {
-                    $dirCreated = \OC\Files\Filesystem::mkdir($this->_checkDirUserPath);
+                    $dirCreated = Filesystem::mkdir($this->_checkDirUserPath);
                     if (!$dirCreated) {
                         $this->_msgList['error'][] = $this->l->t('Impossible de créeer le dossier de l\'application "' . $this->_checkDirUserPath . '".');
                     }
@@ -926,7 +957,7 @@ class PageController extends Controller {
     /**
      * Init for demat user
      *
-     * @throws \OC\User\NoUserException
+     * @throws  OC\User\NoUserException
      */
     private function _initDematUser() {
         // init
@@ -963,9 +994,9 @@ class PageController extends Controller {
      * Load config
      */
     private function _loadConfig() {
-        $this->_dematpayslipConfigList['payslip_dir']  = \OC::$server->getConfig()->getAppValue($this->appName, 'payslip_dir', 'Bulletins'); // Bulletins
-        $this->_dematpayslipConfigList['user_id']      = \OC::$server->getConfig()->getAppValue($this->appName, 'user_id', 'demat');     // demat
-        $this->_dematpayslipConfigList['app_data_dir'] = \OC::$server->getConfig()->getAppValue($this->appName, 'app_data_dir', 'dematpayslip'); // dematpayslip directory of user demat (upload, check, report, etc)
+        $this->_dematpayslipConfigList['payslip_dir']  = OC::$server->getConfig()->getAppValue($this->appName, 'payslip_dir', 'Bulletins'); // Bulletins
+        $this->_dematpayslipConfigList['user_id']      = OC::$server->getConfig()->getAppValue($this->appName, 'user_id', 'demat');     // demat
+        $this->_dematpayslipConfigList['app_data_dir'] = OC::$server->getConfig()->getAppValue($this->appName, 'app_data_dir', 'dematpayslip'); // dematpayslip directory of user demat (upload, check, report, etc)
         if (empty($this->_dematpayslipConfigList['payslip_dir']) || empty($this->_dematpayslipConfigList['user_id'])) {
             $this->_msgList['error'][] = $this->l->t('Veuillez vérifier la configuration de cette application.');
         }
@@ -1068,8 +1099,9 @@ class PageController extends Controller {
      * Phase Upload
      * @NoAdminRequired
      *
-     * @return TemplateResponse
-     * @throws \OC\User\NoUserException
+     * @return  TemplateResponse
+     *
+     * @throws  OC\User\NoUserException
      */
     public function upload() {
         // verifier l'utilisateur
@@ -1078,7 +1110,7 @@ class PageController extends Controller {
 
             $this->_processCheck();
             if (count($this->_msgList['error'])<=0) {
-                $dateTimeNow = new \DateTime('now', \OC::$server->getDateTimeZone()->getTimeZone());
+                $dateTimeNow = new DateTime('now', OC::$server->getDateTimeZone()->getTimeZone());
 
                 $this->_process->setProcessing(1);
                 $this->_process->setPhase(0);
@@ -1212,7 +1244,7 @@ class PageController extends Controller {
      * @NoAdminRequired
      *
      * @return  TemplateResponse
-     * @throws  \OC\User\NoUserException
+     * @throws  OC\User\NoUserException
      * @throws  \setasign\Fpdi\PdfParser\CrossReference\CrossReferenceException
      * @throws  \setasign\Fpdi\PdfParser\Filter\FilterException
      * @throws  \setasign\Fpdi\PdfParser\PdfParserException
@@ -1230,7 +1262,7 @@ class PageController extends Controller {
 
             if (count($this->_msgList['error']) <= 0) {
                 $this->_processFailOnFirstError = false;
-                $dateTimeNow = new \DateTime('now', \OC::$server->getDateTimeZone()->getTimeZone());
+                $dateTimeNow = new DateTime('now', OC::$server->getDateTimeZone()->getTimeZone());
 
                 $this->_process->setProcessing(1);
                 $this->_process->setPhase(1);
@@ -1339,7 +1371,7 @@ class PageController extends Controller {
                                     //    $this->_dematpayslipProcessSkipMapper->insert($dematpayslipProcessSkip);
                                     //}
                                 } else {
-                                    $userManager = \OC::$server->getUserManager();
+                                    $userManager = OC::$server->getUserManager();
                                     $userFindByEmailList = $userManager->getByEmail($agentUser->getEmail());
 
                                     // /!\ remove all users not available (FIX for multiple users with SAML)
@@ -1705,14 +1737,14 @@ class PageController extends Controller {
      * @param   int                 $retry
      * @return  TemplateResponse
      *
-     * @throws NotFoundException
-     * @throws \OCP\Files\InvalidPathException
-     * @throws \OC\User\NoUserException
-     * @throws \setasign\Fpdi\PdfParser\CrossReference\CrossReferenceException
-     * @throws \setasign\Fpdi\PdfParser\Filter\FilterException
-     * @throws \setasign\Fpdi\PdfParser\PdfParserException
-     * @throws \setasign\Fpdi\PdfParser\Type\PdfTypeException
-     * @throws \setasign\Fpdi\PdfReader\PdfReaderException
+     * @throws  NotFoundException
+     * @throws  OC\User\NoUserException
+     * @throws  \OCP\Files\InvalidPathException
+     * @throws  \setasign\Fpdi\PdfParser\CrossReference\CrossReferenceException
+     * @throws  \setasign\Fpdi\PdfParser\Filter\FilterException
+     * @throws  \setasign\Fpdi\PdfParser\PdfParserException
+     * @throws  \setasign\Fpdi\PdfParser\Type\PdfTypeException
+     * @throws  \setasign\Fpdi\PdfReader\PdfReaderException
      */
     public function indexation(int $retry) {
         // verifier l'utilisateur
@@ -1730,8 +1762,16 @@ class PageController extends Controller {
                 $this->_msgList['error'][] = $this->l->t('Opération impossible : phase en cours "' . self::_getPhaseName($this->_process->getPhase()) . '".');
             }
 
+            $launchIndexation = filter_input(INPUT_POST, 'payslip_launch_indexation', FILTER_SANITIZE_NUMBER_INT);
+            $launchArchive    = filter_input(INPUT_POST, 'payslip_launch_archive', FILTER_SANITIZE_NUMBER_INT);
+            $launchIndexation = intval($launchIndexation);
+            $launchArchive    = intval($launchArchive);
+            if ($launchIndexation != 1 && $launchArchive != 1) {
+                $this->_msgList['error'][] = $this->l->t('Veuillez sélectionner au moins un élément entre "Indexation" et "Archivage".');
+            }
+
             if (count($this->_msgList['error']) <= 0) {
-                $phaseStartDateTime = new \DateTime('now', \OC::$server->getDateTimeZone()->getTimeZone());
+                $phaseStartDateTime = new DateTime('now', OC::$server->getDateTimeZone()->getTimeZone());
                 $phaseStartTime = $phaseStartDateTime->getTimestamp();
 
                 // log file
@@ -1760,7 +1800,7 @@ class PageController extends Controller {
                 $this->_logCsvLine($this->l->t('Récupération et montage du dossier de l\'utilisateur Nextcloud.'), self::LOG_DEBUG);
                 $userHomeFilesDirPath = '';
                 if ($this->_process->getHasError() <= 0) {
-                    $user = \OC::$server->getUserManager()->get($this->userId);
+                    $user = OC::$server->getUserManager()->get($this->userId);
                     if (!$user) {
                         $errorMsg = $this->l->t('Le dossier utilisateur "' . $this->userId . '" n\'existe pas.');
                         $this->_logCsvLine($errorMsg, self::LOG_ERROR);
@@ -1809,9 +1849,9 @@ class PageController extends Controller {
                         $this->_logCsvLine($this->l->t('Reprise à la ligne ' . ($retryCsvNumLine+1) . ' du fichier CSV créé lors de la phase de vérification.'), self::LOG_DEBUG);
                     }
                     if (empty($this->_process->getPhaseStep())) {
-                        $rootFolder   = \OC::$server->getRootFolder();
-                        $shareManager = \OC::$server->getShareManager();
-                        $userManager  = \OC::$server->getUserManager();
+                        $rootFolder   = OC::$server->getRootFolder();
+                        $shareManager = OC::$server->getShareManager();
+                        $userManager  = OC::$server->getUserManager();
                         $userFolder   = $rootFolder->getUserFolder($this->userId);
 
                         // recuperer tous les partages realises par cet utilisateur
@@ -1838,9 +1878,6 @@ class PageController extends Controller {
                             $this->_logCsvLine($this->l->t('Lecture du fichier PDF.'), self::LOG_DEBUG);
                             $pdfOriginFileFullPath = $this->_uploadDirFullPath . DIRECTORY_SEPARATOR . $this->_process->getPdfOrigin();
 
-                            // pdf payslip file path
-                            $pdfPayslipFilePath = '';
-
                             // creer le PDF des bulletins de paie a ne pas indexer (ne pas deposer dans le dossier partage de l'agent)
                             $pdfPayslipSkip = null;
                             $payslipSkipPDFPath = $this->_payslipNoIndexDir . DIRECTORY_SEPARATOR .  $phaseStartDateTime->format('Y-m-d_H-i-s') . '_skip';
@@ -1853,7 +1890,7 @@ class PageController extends Controller {
                             }
 
                             // payslip archive mapper
-                            $dematpayslipArchiveMapper = new DematpayslipArchiveMapper(\OC::$server->getDatabaseConnection());
+                            $dematpayslipArchiveMapper = new DematpayslipArchiveMapper(OC::$server->getDatabaseConnection());
 
                             $this->_logCsvLine($this->l->t('Lecture des lignes du fichier CSV créé lors de l\'étape de vérification.'), self::LOG_DEBUG);
                             while ($csvCheckLine = fgetcsv($csvCheckFile, $this->_csvLength, $this->_csvDelimiter, $this->_csvEnclosure)) {
@@ -1897,24 +1934,31 @@ class PageController extends Controller {
                                     $agentUser->setEmail($csvCheckLine[10]);
                                     $agentUser->setZipCity($csvCheckLine[4]);
 
+                                    // pdf check file path
+                                    $pdfPayslipCheckFileName = ($csvCheckLineNum + 1) . '_' . $agentUser->getMatricule() . '.pdf';
+                                    $pdfPayslipCheckFilePath = $this->_checkDirUserPath . DIRECTORY_SEPARATOR . $pdfPayslipCheckFileName;
+                                    $pdfPayslipFilePath = '';
+
                                     $this->_logCsvLine($this->l->t('Ligne CSV '), self::LOG_DEBUG, $agentUser, $startDate, $endDate);
 
                                     // process skip lines
                                     if (in_array($csvCheckLineNum, $dematpayslipProcessSkipLineIdList)) {
                                         $this->_logCsvLine('-- ' . $this->l->t('Saut de la ligne CSV : ' . ($csvCheckLineNum + 1)) . ' --', self::LOG_DEBUG, $agentUser, $startDate, $endDate);
 
-                                        // creer le PDF des bulletins de paie a ne pas indexer
-                                        if ($pdfPayslipSkip === null) {
-                                            $pdfPayslipSkip = new \setasign\Fpdi\Fpdi();
-                                        }
-                                        // ajout des pages des bulletins de paie de l'agent a ne pas indexer
-                                        $this->_logCsvLine($this->l->t('Ajout des pages PDF au bulletin de paie à ne pas indexer.'), self::LOG_DEBUG, $agentUser, $startDate, $endDate);
-                                        foreach ($pdfPageNumList as $pdfPageNum) {
-                                            $this->_logCsvLine($this->l->t('Ajout de la page ' . $pdfPageNum . '.'), self::LOG_DEBUG, $agentUser, $startDate, $endDate);
-                                            $pdfPayslipSkip->AddPage();
-                                            $pdfPayslipSkip->setSourceFile($pdfOriginFileFullPath);
-                                            $tplPayslipSkipId = $pdfPayslipSkip->importPage($pdfPageNum);
-                                            $pdfPayslipSkip->useTemplate($tplPayslipSkipId);
+                                        if ($launchIndexation == 1) {
+                                            // creer le PDF des bulletins de paie a ne pas indexer
+                                            if ($pdfPayslipSkip === null) {
+                                                $pdfPayslipSkip = new \setasign\Fpdi\Fpdi();
+                                            }
+                                            // ajout des pages des bulletins de paie de l'agent a ne pas indexer
+                                            $this->_logCsvLine($this->l->t('Ajout des pages PDF au bulletin de paie à ne pas indexer.'), self::LOG_DEBUG, $agentUser, $startDate, $endDate);
+                                            foreach ($pdfPageNumList as $pdfPageNum) {
+                                                $this->_logCsvLine($this->l->t('Ajout de la page ' . $pdfPageNum . '.'), self::LOG_DEBUG, $agentUser, $startDate, $endDate);
+                                                $pdfPayslipSkip->AddPage();
+                                                $pdfPayslipSkip->setSourceFile($pdfOriginFileFullPath);
+                                                $tplPayslipSkipId = $pdfPayslipSkip->importPage($pdfPageNum);
+                                                $pdfPayslipSkip->useTemplate($tplPayslipSkipId);
+                                            }
                                         }
 
                                         $csvCheckLineNum++;
@@ -1925,31 +1969,15 @@ class PageController extends Controller {
                                     if (empty($agentUser->getEmail())) {
                                         $this->_logCsvLine('-- ' . $this->l->t('Création du PDF non dématérialisé de l\'agent (aucun email) : ' . ($csvCheckLineNum + 1)) . ' --', self::LOG_DEBUG, $agentUser, $startDate, $endDate);
 
-                                        // check if not already archived
-                                        $dematpayslipArchive = $this->_archiveCheckBeforeSave($dematpayslipArchiveMapper, $agentUser, $startDate, $endDate);
-
-                                        if (!empty($dematpayslipArchive)) {
-                                            // create PDF payslip
-                                            $payslipNoDematHorodateDirPath = $this->_payslipNoIndexDir . DIRECTORY_SEPARATOR . $phaseStartDateTime->format('Y-m-d_H-i-s');
-                                            $isDir = Filesystem::is_dir($payslipNoDematHorodateDirPath);
-                                            if (!$isDir) {
-                                                $dirCreated = Filesystem::mkdir($payslipNoDematHorodateDirPath);
-                                                if (!$dirCreated) {
-                                                    $this->_msgList['error'][] = $this->l->t('Impossible de créeer le dossier "' . $payslipNoDematHorodateDirPath . '".');
-                                                }
-                                            }
-                                            $payslipNoDematHorodateAgentDirPath = $payslipNoDematHorodateDirPath . DIRECTORY_SEPARATOR . $agentUser->getSiret() . '-' . $agentUser->getMatricule();
-                                            $isDir = Filesystem::is_dir($payslipNoDematHorodateAgentDirPath);
-                                            if (!$isDir) {
-                                                $dirCreated = Filesystem::mkdir($payslipNoDematHorodateAgentDirPath);
-                                                if (!$dirCreated) {
-                                                    $this->_msgList['error'][] = $this->l->t('Impossible de créeer le dossier "' . $payslipNoDematHorodateAgentDirPath . '".');
-                                                }
-                                            }
-                                            $payslipNoDematPDFPath = $payslipNoDematHorodateAgentDirPath . DIRECTORY_SEPARATOR . $startDate . '_' . $endDate;
-                                            $pdfPayslipNoDemat = new \setasign\Fpdi\Fpdi();
+                                        // check if not already archived (return null if already archived with warning)
+                                        $dematpayslipArchive = null;
+                                        if ($launchArchive == 1) {
+                                            $dematpayslipArchive = $this->_archiveCheckBeforeSave($dematpayslipArchiveMapper, $agentUser, $startDate, $endDate);
+                                        }
 
+                                        if ($launchArchive != 1 || ($launchArchive==1 && !empty($dematpayslipArchive))) {
                                             // add all agent pdf pages
+                                            $pdfPayslipNoDemat = new \setasign\Fpdi\Fpdi();
                                             $this->_logCsvLine($this->l->t('Ajout des pages PDF au bulletin de paie à ne pas indexer.'), self::LOG_DEBUG, $agentUser, $startDate, $endDate);
                                             foreach ($pdfPageNumList as $pdfPageNum) {
                                                 $this->_logCsvLine($this->l->t('Ajout de la page ' . $pdfPageNum . '.'), self::LOG_DEBUG, $agentUser, $startDate, $endDate);
@@ -1959,19 +1987,51 @@ class PageController extends Controller {
                                                 $pdfPayslipNoDemat->useTemplate($pdfPayslipNoDematId);
                                             }
 
-                                            // create PDF payslip in no index folder
-                                            $this->_logCsvLine($this->l->t('Créer le PDF du bulletin de paie non dematérialisé.'), self::LOG_DEBUG);
-                                            $pdfPayslipNoDemat->Output('F', $userHomeFilesDirPath . DIRECTORY_SEPARATOR . $payslipNoDematPDFPath);
-                                            $pdfPayslipFilePath = $payslipNoDematPDFPath . '.pdf';
-                                            $renamed = Filesystem::rename($payslipNoDematPDFPath, $pdfPayslipFilePath);
-                                            if (!$renamed) {
-                                                $errorMsg = $this->l->t('Impossible de déplacer le PDF du bulletin de paie non dematérialisé "' . $payslipNoDematPDFPath . '".');
-                                                $this->_logCsvLine($errorMsg, self::LOG_ERROR);
-                                                $this->_processErrorMsg(-1, $errorMsg, $phaseStep, $csvCheckLineNum);
+                                            if ($launchIndexation == 1) {
+                                                // create PDF payslip
+                                                $payslipNoDematHorodateDirPath = $this->_payslipNoIndexDir . DIRECTORY_SEPARATOR . $phaseStartDateTime->format('Y-m-d_H-i-s');
+                                                $isDir = Filesystem::is_dir($payslipNoDematHorodateDirPath);
+                                                if (!$isDir) {
+                                                    $dirCreated = Filesystem::mkdir($payslipNoDematHorodateDirPath);
+                                                    if (!$dirCreated) {
+                                                        $errorMsg = $this->l->t('Impossible de créeer le dossier "' . $payslipNoDematHorodateDirPath . '".');
+                                                        $this->_logCsvLine($errorMsg, self::LOG_ERROR, $agentUser, $startDate, $endDate);
+                                                        $this->_processErrorMsg(-1, $errorMsg, $phaseStep, $csvCheckLineNum);
+                                                    }
+                                                }
+                                                $payslipNoDematHorodateAgentDirPath = $payslipNoDematHorodateDirPath . DIRECTORY_SEPARATOR . $agentUser->getSiret() . '-' . $agentUser->getMatricule();
+                                                $isDir = Filesystem::is_dir($payslipNoDematHorodateAgentDirPath);
+                                                if (!$isDir) {
+                                                    $dirCreated = Filesystem::mkdir($payslipNoDematHorodateAgentDirPath);
+                                                    if (!$dirCreated) {
+                                                        $errorMsg = $this->l->t('Impossible de créeer le dossier "' . $payslipNoDematHorodateAgentDirPath . '".');
+                                                        $this->_logCsvLine($errorMsg, self::LOG_ERROR, $agentUser, $startDate, $endDate);
+                                                        $this->_processErrorMsg(-1, $errorMsg, $phaseStep, $csvCheckLineNum);
+                                                    }
+                                                }
+                                                $payslipNoDematPDFPath = $payslipNoDematHorodateAgentDirPath . DIRECTORY_SEPARATOR . $startDate . '_' . $endDate;
+
+                                                // create PDF payslip in no index folder
+                                                $this->_logCsvLine($this->l->t('Créer le PDF du bulletin de paie non dematérialisé.'), self::LOG_DEBUG);
+                                                $pdfPayslipNoDemat->Output('F', $userHomeFilesDirPath . DIRECTORY_SEPARATOR . $payslipNoDematPDFPath);
+                                                $pdfPayslipFilePath = $payslipNoDematPDFPath . '.pdf';
+                                                $renamed = Filesystem::rename($payslipNoDematPDFPath, $pdfPayslipFilePath);
+                                                if (!$renamed) {
+                                                    $errorMsg = $this->l->t('Impossible de déplacer le PDF du bulletin de paie non dematérialisé "' . $payslipNoDematPDFPath . '".');
+                                                    $this->_logCsvLine($errorMsg, self::LOG_ERROR);
+                                                    $this->_processErrorMsg(-1, $errorMsg, $phaseStep, $csvCheckLineNum);
+                                                }
                                             }
 
-                                            // save archive
-                                            $this->_archiveSaveForAgentAndPeriod($dematpayslipArchiveMapper, $dematpayslipArchive, $pdfPayslipFilePath, $agentUser, $startDate, $endDate, $year, $month, $editionDate, $phaseStartDateTime->getTimestamp());
+                                            // save archive and process
+                                            if ($launchArchive == 1) {
+                                                $result = $this->_archiveSaveAndProcess($pdfPayslipCheckFilePath, $dematpayslipArchiveMapper, $dematpayslipArchive , $pdfPayslipFilePath, $agentUser, $startDate, $endDate, $year, $month, $editionDate, $phaseStartDateTime->getTimestamp());
+                                                if ($result < 0) {
+                                                    $errorMsg = $this->l->t('Impossible de créer le fichier temporaire du bulletin de paie "' . $pdfPayslipCheckFilePath . '".');
+                                                    $this->_logCsvLine($errorMsg, self::LOG_ERROR, $agentUser, $startDate, $endDate);
+                                                    $this->_processErrorMsg(-1, $errorMsg, $phaseStep, $csvCheckLineNum);
+                                                }
+                                            }
                                         }
 
                                         $csvCheckLineNum++;
@@ -2051,110 +2111,135 @@ class PageController extends Controller {
 
                                                 // si l'utilisateur n'a pas desactive la dematerialisation de son bulletin de paie
                                                 if ($dematpayslipUser->getDisabled() != 1) {
-                                                    // creer le partage du dossier "SIRET-MATRICULE"
-                                                    $payslipsMatriculeDirPathNode = $userFolder->get($payslipsMatriculeDirPath);
-
-                                                    // verifier si le dossier n'est pas deja partage
-                                                    if (!in_array($payslipsMatriculeDirPathNode->getId(), $payslipMatriculeShareNodeIdList)) {
-                                                        // partager le dossier MATRICULE en lecture seule avec l'utilisateur trouve a partir de son email
-                                                        $this->_logCsvLine($this->l->t('Partage du dossier SIRET-MATRICULE [' . $siretMatriculeDirName . '] en lecture seule.'), self::LOG_DEBUG, $agentUser, $startDate, $endDate);
-                                                        $payslipMatriculeShare = $shareManager->newShare();
-                                                        $payslipMatriculeShare->setNode($payslipsMatriculeDirPathNode);
-                                                        $payslipMatriculeShare->setShareType(\OC\Share\Share::SHARE_TYPE_USER);
-                                                        $payslipMatriculeShare->setSharedWith($userFindByEmailId);
-                                                        $payslipMatriculeShare->setPermissions(\OCP\Constants::PERMISSION_READ);
-                                                        $payslipMatriculeShare->setSharedBy($this->userId);
-                                                        $payslipMatriculeShare = $shareManager->createShare($payslipMatriculeShare);
-                                                    } else {
-                                                        $this->_logCsvLine($this->l->t('Dossier SIRET-MATRICULE [' . $siretMatriculeDirName . '] est déjà partagé.'), self::LOG_DEBUG, $agentUser, $startDate, $endDate);
-                                                    }
-
-                                                    // dossier "SIRET-MATRICULE/ANNEE"
-                                                    $this->_logCsvLine($this->l->t('Vérification de l\'existance du dossier de l\'annéee [' . $year . '].'), self::LOG_DEBUG, $agentUser, $startDate, $endDate);
                                                     $payslipsMatriculeYearDirPath = $payslipsMatriculeDirPath . DIRECTORY_SEPARATOR . $year;
-                                                    $isDir = Filesystem::is_dir($payslipsMatriculeYearDirPath);
-                                                    if (!$isDir) {
-                                                        $this->_logCsvLine($this->l->t('Création du dossier de l\'annéee [' . $year . '].'), self::LOG_DEBUG, $agentUser, $startDate, $endDate);
-                                                        $dirCreated = Filesystem::mkdir($payslipsMatriculeYearDirPath);
-                                                        if (!$dirCreated) {
-                                                            $errorMsg = $this->l->t('Impossible de créer le dossier "' . $payslipsMatriculeYearDirPath . '[siret="' . $agentUser->getSiret() . '", matricule="' . $agentUser->getMatricule() . '", année="' . $year . '"].');
-                                                            $this->_logCsvLine($errorMsg, self::LOG_ERROR, $agentUser, $startDate, $endDate);
-                                                            $this->_processErrorMsg(-1, $errorMsg, $phaseStep, $csvCheckLineNum);
+
+                                                    if ($launchIndexation == 1) {
+                                                        // creer le partage du dossier "SIRET-MATRICULE"
+                                                        $payslipsMatriculeDirPathNode = $userFolder->get($payslipsMatriculeDirPath);
+
+                                                        // verifier si le dossier n'est pas deja partage
+                                                        if (!in_array($payslipsMatriculeDirPathNode->getId(), $payslipMatriculeShareNodeIdList)) {
+                                                            // partager le dossier MATRICULE en lecture seule avec l'utilisateur trouve a partir de son email
+                                                            $this->_logCsvLine($this->l->t('Partage du dossier SIRET-MATRICULE [' . $siretMatriculeDirName . '] en lecture seule.'), self::LOG_DEBUG, $agentUser, $startDate, $endDate);
+                                                            $payslipMatriculeShare = $shareManager->newShare();
+                                                            $payslipMatriculeShare->setNode($payslipsMatriculeDirPathNode);
+                                                            $payslipMatriculeShare->setShareType(\OC\Share\Share::SHARE_TYPE_USER);
+                                                            $payslipMatriculeShare->setSharedWith($userFindByEmailId);
+                                                            $payslipMatriculeShare->setPermissions(\OCP\Constants::PERMISSION_READ);
+                                                            $payslipMatriculeShare->setSharedBy($this->userId);
+                                                            $payslipMatriculeShare = $shareManager->createShare($payslipMatriculeShare);
+                                                        } else {
+                                                            $this->_logCsvLine($this->l->t('Dossier SIRET-MATRICULE [' . $siretMatriculeDirName . '] est déjà partagé.'), self::LOG_DEBUG, $agentUser, $startDate, $endDate);
+                                                        }
+
+                                                        // dossier "SIRET-MATRICULE/ANNEE"
+                                                        $this->_logCsvLine($this->l->t('Vérification de l\'existance du dossier de l\'annéee [' . $year . '].'), self::LOG_DEBUG, $agentUser, $startDate, $endDate);
+                                                        $isDir = Filesystem::is_dir($payslipsMatriculeYearDirPath);
+                                                        if (!$isDir) {
+                                                            $this->_logCsvLine($this->l->t('Création du dossier de l\'annéee [' . $year . '].'), self::LOG_DEBUG, $agentUser, $startDate, $endDate);
+                                                            $dirCreated = Filesystem::mkdir($payslipsMatriculeYearDirPath);
+                                                            if (!$dirCreated) {
+                                                                $errorMsg = $this->l->t('Impossible de créer le dossier "' . $payslipsMatriculeYearDirPath . '[siret="' . $agentUser->getSiret() . '", matricule="' . $agentUser->getMatricule() . '", année="' . $year . '"].');
+                                                                $this->_logCsvLine($errorMsg, self::LOG_ERROR, $agentUser, $startDate, $endDate);
+                                                                $this->_processErrorMsg(-1, $errorMsg, $phaseStep, $csvCheckLineNum);
+                                                            }
                                                         }
                                                     }
 
                                                     if ($this->_process->getHasError() <= 0) {
-                                                        // check if not already archived
-                                                        $dematpayslipArchive = $this->_archiveCheckBeforeSave($dematpayslipArchiveMapper, $agentUser, $startDate, $endDate);
+                                                        // check if not already archived (return null if already archived with warning)
+                                                        $dematpayslipArchive = null;
+                                                        if ($launchArchive == 1) {
+                                                            $dematpayslipArchive = $this->_archiveCheckBeforeSave($dematpayslipArchiveMapper, $agentUser, $startDate, $endDate);
+                                                        }
 
-                                                        if (!empty($dematpayslipArchive)) {
-                                                            // deplacer le fichier PDF du bulletin de paie de l'agent dans "SIRET-MATRICULE/ANNEE/PERIODE.pdf"
-                                                            $pdfPayslipCheckFileName = ($csvCheckLineNum + 1) . '_' . $agentUser->getMatricule() . '.pdf';
-                                                            $pdfPayslipCheckFilePath = $this->_checkDirUserPath . DIRECTORY_SEPARATOR . $pdfPayslipCheckFileName;
-                                                            $pdfPayslipFilePath = $payslipsMatriculeYearDirPath . DIRECTORY_SEPARATOR . $period . '.pdf';
-                                                            $this->_logCsvLine($this->l->t('Déplacement du fichier PDF du bulletin de paie de la période [' . $period . '].'), self::LOG_DEBUG, $agentUser, $startDate, $endDate);
-                                                            $renamed = Filesystem::rename($pdfPayslipCheckFilePath, $pdfPayslipFilePath);
-                                                            if (!$renamed) {
-                                                                $errorMsg = $this->l->t('Impossible de déplacer le bulletin de paie "' . $pdfPayslipCheckFileName . '" dans le dossier "' . $pdfPayslipFilePath . '".');
-                                                                $this->_logCsvLine($errorMsg, self::LOG_ERROR, $agentUser, $startDate, $endDate);
-                                                                $this->_processErrorMsg(-1, $errorMsg, $phaseStep, $csvCheckLineNum);
+                                                        if ($launchArchive != 1 || ($launchArchive==1 && !empty($dematpayslipArchive))) {
+                                                            if ($launchIndexation == 1) {
+                                                                // deplacer le fichier PDF du bulletin de paie de l'agent dans "SIRET-MATRICULE/ANNEE/PERIODE.pdf"
+                                                                $pdfPayslipFilePath = $payslipsMatriculeYearDirPath . DIRECTORY_SEPARATOR . $period . '.pdf';
+                                                                $this->_logCsvLine($this->l->t('Déplacement du fichier PDF du bulletin de paie de la période [' . $period . '].'), self::LOG_DEBUG, $agentUser, $startDate, $endDate);
+                                                                $renamed = Filesystem::rename($pdfPayslipCheckFilePath, $pdfPayslipFilePath);
+                                                                if (!$renamed) {
+                                                                    $errorMsg = $this->l->t('Impossible de déplacer le bulletin de paie "' . $pdfPayslipCheckFileName . '" dans le dossier "' . $pdfPayslipFilePath . '".');
+                                                                    $this->_logCsvLine($errorMsg, self::LOG_ERROR, $agentUser, $startDate, $endDate);
+                                                                    $this->_processErrorMsg(-1, $errorMsg, $phaseStep, $csvCheckLineNum);
+                                                                }
                                                             }
 
-                                                            // save archive
-                                                            $this->_archiveSaveForAgentAndPeriod($dematpayslipArchiveMapper, $dematpayslipArchive, $pdfPayslipFilePath, $agentUser, $startDate, $endDate, $year, $month, $editionDate, $phaseStartDateTime->getTimestamp());
+                                                            // save archive and process
+                                                            if ($launchArchive == 1) {
+                                                                $result = $this->_archiveSaveAndProcess($pdfPayslipCheckFilePath, $dematpayslipArchiveMapper, $dematpayslipArchive , $pdfPayslipFilePath, $agentUser, $startDate, $endDate, $year, $month, $editionDate, $phaseStartDateTime->getTimestamp());
+                                                                if ($result < 0) {
+                                                                    $errorMsg = $this->l->t('Impossible de créer le fichier temporaire du bulletin de paie "' . $pdfPayslipCheckFilePath . '".');
+                                                                    $this->_logCsvLine($errorMsg, self::LOG_ERROR, $agentUser, $startDate, $endDate);
+                                                                    $this->_processErrorMsg(-1, $errorMsg, $phaseStep, $csvCheckLineNum);
+                                                                }
+                                                            }
                                                         }
                                                     }
                                                 } else {
                                                     // agent disabled payslip
                                                     $this->_logCsvLine($this->l->t('L\'utlisateur a désactivé la dématérialisation des fiches de paie [email=' . $agentUser->getEmail() . '].'), self::LOG_DEBUG, $agentUser, $startDate, $endDate);
 
-                                                    // check if not already archived
-                                                    $dematpayslipArchive = $this->_archiveCheckBeforeSave($dematpayslipArchiveMapper, $agentUser, $startDate, $endDate);
+                                                    // check if not already archived (return null if already archived with warning)
+                                                    $dematpayslipArchive = null;
+                                                    if ($launchArchive == 1) {
+                                                        $dematpayslipArchive = $this->_archiveCheckBeforeSave($dematpayslipArchiveMapper, $agentUser, $startDate, $endDate);
+                                                    }
 
-                                                    if (!empty($dematpayslipArchive)) {
-                                                        // create PDF payslip
-                                                        $payslipNoDematHorodateDirPath = $this->_payslipNoIndexDir . DIRECTORY_SEPARATOR . $phaseStartDateTime->format('Y-m-d_H-i-s');
-                                                        $isDir = Filesystem::is_dir($payslipNoDematHorodateDirPath);
-                                                        if (!$isDir) {
-                                                            $dirCreated = Filesystem::mkdir($payslipNoDematHorodateDirPath);
-                                                            if (!$dirCreated) {
-                                                                $this->_msgList['error'][] = $this->l->t('Impossible de créeer le dossier "' . $payslipNoDematHorodateDirPath . '".');
+                                                    if ($launchArchive != 1 || ($launchArchive == 1 && !empty($dematpayslipArchive))) {
+                                                        if ($launchIndexation == 1) {
+                                                            // create PDF payslip
+                                                            $payslipNoDematHorodateDirPath = $this->_payslipNoIndexDir . DIRECTORY_SEPARATOR . $phaseStartDateTime->format('Y-m-d_H-i-s');
+                                                            $isDir = Filesystem::is_dir($payslipNoDematHorodateDirPath);
+                                                            if (!$isDir) {
+                                                                $dirCreated = Filesystem::mkdir($payslipNoDematHorodateDirPath);
+                                                                if (!$dirCreated) {
+                                                                    $this->_msgList['error'][] = $this->l->t('Impossible de créeer le dossier "' . $payslipNoDematHorodateDirPath . '".');
+                                                                }
                                                             }
-                                                        }
-                                                        $payslipNoDematHorodateAgentDirPath = $payslipNoDematHorodateDirPath . DIRECTORY_SEPARATOR . $agentUser->getSiret() . '-' . $agentUser->getMatricule();
-                                                        $isDir = Filesystem::is_dir($payslipNoDematHorodateAgentDirPath);
-                                                        if (!$isDir) {
-                                                            $dirCreated = Filesystem::mkdir($payslipNoDematHorodateAgentDirPath);
-                                                            if (!$dirCreated) {
-                                                                $this->_msgList['error'][] = $this->l->t('Impossible de créeer le dossier "' . $payslipNoDematHorodateAgentDirPath . '".');
+                                                            $payslipNoDematHorodateAgentDirPath = $payslipNoDematHorodateDirPath . DIRECTORY_SEPARATOR . $agentUser->getSiret() . '-' . $agentUser->getMatricule();
+                                                            $isDir = Filesystem::is_dir($payslipNoDematHorodateAgentDirPath);
+                                                            if (!$isDir) {
+                                                                $dirCreated = Filesystem::mkdir($payslipNoDematHorodateAgentDirPath);
+                                                                if (!$dirCreated) {
+                                                                    $this->_msgList['error'][] = $this->l->t('Impossible de créeer le dossier "' . $payslipNoDematHorodateAgentDirPath . '".');
+                                                                }
+                                                            }
+                                                            $payslipNoDematPDFPath = $payslipNoDematHorodateAgentDirPath . DIRECTORY_SEPARATOR . $startDate . '_' . $endDate;
+                                                            $pdfPayslipNoDemat = new \setasign\Fpdi\Fpdi();
+
+                                                            // add all agent pdf pages
+                                                            $this->_logCsvLine($this->l->t('Ajout des pages PDF au bulletin de paie à ne pas indexer.'), self::LOG_DEBUG, $agentUser, $startDate, $endDate);
+                                                            foreach ($pdfPageNumList as $pdfPageNum) {
+                                                                $this->_logCsvLine($this->l->t('Ajout de la page ' . $pdfPageNum . '.'), self::LOG_DEBUG, $agentUser, $startDate, $endDate);
+                                                                $pdfPayslipNoDemat->AddPage();
+                                                                $pdfPayslipNoDemat->setSourceFile($pdfOriginFileFullPath);
+                                                                $pdfPayslipNoDematId = $pdfPayslipNoDemat->importPage($pdfPageNum);
+                                                                $pdfPayslipNoDemat->useTemplate($pdfPayslipNoDematId);
                                                             }
-                                                        }
-                                                        $payslipNoDematPDFPath = $payslipNoDematHorodateAgentDirPath . DIRECTORY_SEPARATOR . $startDate . '_' . $endDate;
-                                                        $pdfPayslipNoDemat = new \setasign\Fpdi\Fpdi();
-
-                                                        // add all agent pdf pages
-                                                        $this->_logCsvLine($this->l->t('Ajout des pages PDF au bulletin de paie à ne pas indexer.'), self::LOG_DEBUG, $agentUser, $startDate, $endDate);
-                                                        foreach ($pdfPageNumList as $pdfPageNum) {
-                                                            $this->_logCsvLine($this->l->t('Ajout de la page ' . $pdfPageNum . '.'), self::LOG_DEBUG, $agentUser, $startDate, $endDate);
-                                                            $pdfPayslipNoDemat->AddPage();
-                                                            $pdfPayslipNoDemat->setSourceFile($pdfOriginFileFullPath);
-                                                            $pdfPayslipNoDematId = $pdfPayslipNoDemat->importPage($pdfPageNum);
-                                                            $pdfPayslipNoDemat->useTemplate($pdfPayslipNoDematId);
-                                                        }
 
-                                                        // create PDF payslip in no index folder
-                                                        $this->_logCsvLine($this->l->t('Créer le PDF du bulletin de paie non dematérialisé.'), self::LOG_DEBUG);
-                                                        $pdfPayslipNoDemat->Output('F', $userHomeFilesDirPath . DIRECTORY_SEPARATOR . $payslipNoDematPDFPath);
-                                                        $pdfPayslipFilePath = $payslipNoDematPDFPath . '.pdf';
-                                                        $renamed = Filesystem::rename($payslipNoDematPDFPath, $pdfPayslipFilePath);
-                                                        if (!$renamed) {
-                                                            $errorMsg = $this->l->t('Impossible de déplacer le PDF du bulletin de paie non dematérialisé "' . $payslipNoDematPDFPath . '".');
-                                                            $this->_logCsvLine($errorMsg, self::LOG_ERROR);
-                                                            $this->_processErrorMsg(-1, $errorMsg, $phaseStep, $csvCheckLineNum);
+                                                            // create PDF payslip in no index folder
+                                                            $this->_logCsvLine($this->l->t('Créer le PDF du bulletin de paie non dematérialisé.'), self::LOG_DEBUG);
+                                                            $pdfPayslipNoDemat->Output('F', $userHomeFilesDirPath . DIRECTORY_SEPARATOR . $payslipNoDematPDFPath);
+                                                            $pdfPayslipFilePath = $payslipNoDematPDFPath . '.pdf';
+                                                            $renamed = Filesystem::rename($payslipNoDematPDFPath, $pdfPayslipFilePath);
+                                                            if (!$renamed) {
+                                                                $errorMsg = $this->l->t('Impossible de déplacer le PDF du bulletin de paie non dematérialisé "' . $payslipNoDematPDFPath . '".');
+                                                                $this->_logCsvLine($errorMsg, self::LOG_ERROR);
+                                                                $this->_processErrorMsg(-1, $errorMsg, $phaseStep, $csvCheckLineNum);
+                                                            }
                                                         }
 
-                                                        // save archive
-                                                        $this->_archiveSaveForAgentAndPeriod($dematpayslipArchiveMapper, $dematpayslipArchive, $pdfPayslipFilePath, $agentUser, $startDate, $endDate, $year, $month, $editionDate, $phaseStartDateTime->getTimestamp());
+                                                        // save archive and process
+                                                        if ($launchArchive == 1) {
+                                                            $result = $this->_archiveSaveAndProcess($pdfPayslipCheckFilePath, $dematpayslipArchiveMapper, $dematpayslipArchive , $pdfPayslipFilePath, $agentUser, $startDate, $endDate, $year, $month, $editionDate, $phaseStartDateTime->getTimestamp());
+                                                            if ($result < 0) {
+                                                                $errorMsg = $this->l->t('Impossible de créer le fichier temporaire du bulletin de paie "' . $pdfPayslipCheckFilePath . '".');
+                                                                $this->_logCsvLine($errorMsg, self::LOG_ERROR, $agentUser, $startDate, $endDate);
+                                                                $this->_processErrorMsg(-1, $errorMsg, $phaseStep, $csvCheckLineNum);
+                                                            }
+                                                        }
                                                     }
                                                 }
                                             } else {
@@ -2318,7 +2403,6 @@ class PageController extends Controller {
      * @NoCSRFRequired
      *
      * @return  TemplateResponse
-     * @throws  \OC\User\NoUserException
      */
     public function userList() {
         // verifier l'utilisateur
@@ -2329,7 +2413,7 @@ class PageController extends Controller {
             );
 
             if (!empty($userEmail)) {
-                $userManager = \OC::$server->getUserManager();
+                $userManager = OC::$server->getUserManager();
                 // /!\ remove all users not available (FIX for multiple users with SAML)
                 if (self::USER_REMOVE_UNKNOWN == 1) {
                     $this->_userList = self::_removeUnknownUser($userManager->getByEmail($userEmail));
@@ -2349,7 +2433,8 @@ class PageController extends Controller {
      * @NoCSRFRequired
      *
      * @return  TemplateResponse
-     * @throws  \OC\User\NoUserException
+     *
+     * @throws  OC\User\NoUserException
      */
     public function agentList() {
         // verifier l'utilisateur
@@ -2369,7 +2454,8 @@ class PageController extends Controller {
      * @NoCSRFRequired
      *
      * @return  TemplateResponse
-     * @throws  \OC\User\NoUserException
+     *
+     * @throws  OC\User\NoUserException
      */
     public function agentCsv() {
         // verifier l'utilisateur
@@ -2380,7 +2466,7 @@ class PageController extends Controller {
                 $dematpayslipUserList = $this->_dematpayslipUserMapper->findAll(array(array('disabled', 'desc'), array('siret'), array('matricule')));
 
                 if (!empty($dematpayslipUserList)) {
-                    $dateTimeNow = new \DateTime('now', \OC::$server->getDateTimeZone()->getTimeZone());
+                    $dateTimeNow = new DateTime('now', OC::$server->getDateTimeZone()->getTimeZone());
                     $csvFilePath = $this->_exportDirUserPath . DIRECTORY_SEPARATOR .  $dateTimeNow->format('Y-m-d_H-i-s') . '_agent';
                     $csvFile = Filesystem::fopen($csvFilePath, 'w+');
 
@@ -2408,7 +2494,7 @@ class PageController extends Controller {
 
                         if (count($this->_msgList['error']) <= 0) {
                             foreach ($dematpayslipUserList as $dematpayslipUser) {
-                                $agent = \OC::$server->getUserManager()->get($dematpayslipUser->getUserId());
+                                $agent = OC::$server->getUserManager()->get($dematpayslipUser->getUserId());
 
                                 $csvFields = array();
                                 //$csvFields[] = $dematpayslipUser->getUserId();
@@ -2455,7 +2541,8 @@ class PageController extends Controller {
      * @NoCSRFRequired
      *
      * @return  TemplateResponse
-     * @throws  \OC\User\NoUserException
+     *
+     * @throws  OC\User\NoUserException
      */
     public function archiveList() {
         // verifier l'utilisateur
@@ -2482,7 +2569,8 @@ class PageController extends Controller {
      * @NoCSRFRequired
      *
      * @return  TemplateResponse
-     * @throws  \OC\User\NoUserException
+     *
+     * @throws  OC\User\NoUserException
      */
     public function archiveAction() {
         // verifier l'utilisateur
@@ -2504,7 +2592,7 @@ class PageController extends Controller {
                 // refresh all archive status
                 $refresh = true;
             } elseif ($action == 'create') {
-                $dematpayslipArchiveMapper = new DematpayslipArchiveMapper(\OC::$server->getDatabaseConnection());
+                $dematpayslipArchiveMapper = new DematpayslipArchiveMapper(OC::$server->getDatabaseConnection());
 
                 if (!empty($archiveSelectIdList)) {
                     foreach ($archiveSelectIdList as $archiveSelectId) {
@@ -2515,7 +2603,7 @@ class PageController extends Controller {
                     }
                 }
             } elseif ($action == 'create_all') {
-                $dematpayslipArchiveMapper = new DematpayslipArchiveMapper(\OC::$server->getDatabaseConnection());
+                $dematpayslipArchiveMapper = new DematpayslipArchiveMapper(OC::$server->getDatabaseConnection());
                 $dematpayslipArchiveList = $dematpayslipArchiveMapper->findAllByStepStatus(DematpayslipArchive::STEP_STATUS_INIT);
 
                 foreach ($dematpayslipArchiveList as $dematpayslipArchive) {
@@ -2524,7 +2612,7 @@ class PageController extends Controller {
                     }
                 }
             } elseif ($action == 'run_again') {
-                $dematpayslipArchiveMapper = new DematpayslipArchiveMapper(\OC::$server->getDatabaseConnection());
+                $dematpayslipArchiveMapper = new DematpayslipArchiveMapper(OC::$server->getDatabaseConnection());
 
                 if (!empty($archiveSelectIdList)) {
                     foreach ($archiveSelectIdList as $archiveSelectId) {
@@ -2536,8 +2624,8 @@ class PageController extends Controller {
                 }
             }
             elseif ($action == 'delete') {
-                $nowDateTime = new \DateTime('now', \OC::$server->getDateTimeZone()->getTimeZone());
-                $dematpayslipArchiveMapper = new DematpayslipArchiveMapper(\OC::$server->getDatabaseConnection());
+                $nowDateTime = new DateTime('now', OC::$server->getDateTimeZone()->getTimeZone());
+                $dematpayslipArchiveMapper = new DematpayslipArchiveMapper(OC::$server->getDatabaseConnection());
 
                 if (!empty($archiveSelectIdList)) {
                     foreach ($archiveSelectIdList as $archiveSelectId) {
@@ -2569,8 +2657,9 @@ class PageController extends Controller {
      * @NoAdminRequired
      * @NoCSRFRequired
      *
-     * @return TemplateResponse
-     * @throws \Exception
+     * @return  TemplateResponse
+     *
+     * @throws  OC\User\NoUserException
      */
     public function archiveCsv() {
         // verifier l'utilisateur
@@ -2584,7 +2673,7 @@ class PageController extends Controller {
                 $stepStatus = intval($stepStatus);
             }
 
-            $dematpayslipArchiveMapper = new DematpayslipArchiveMapper(\OC::$server->getDatabaseConnection());
+            $dematpayslipArchiveMapper = new DematpayslipArchiveMapper(OC::$server->getDatabaseConnection());
             if ($stepStatus === -1) {
                 $dematpayslipArchiveList = $dematpayslipArchiveMapper->findAll(0);
             } else {
@@ -2592,7 +2681,7 @@ class PageController extends Controller {
             }
 
             if (!empty($dematpayslipArchiveList)) {
-                $dateTimeNow = new \DateTime('now', \OC::$server->getDateTimeZone()->getTimeZone());
+                $dateTimeNow = new DateTime('now', OC::$server->getDateTimeZone()->getTimeZone());
                 $csvFilePath = $this->_exportDirUserPath . DIRECTORY_SEPARATOR . $dateTimeNow->format('Y-m-d_H-i-s') . '_archive';
                 $csvFile = Filesystem::fopen($csvFilePath, 'w+');
 
@@ -2669,7 +2758,7 @@ class PageController extends Controller {
     /**
      * Liste des bulletins de paie
      *
-     * @return TemplateResponse
+     * @return  TemplateResponse
      */
     public function shares() {
         $this->_dematpayslipUserList = $this->_dematpayslipUserMapper->findAllByUserId($this->userId);
diff --git a/templates/content/archive_list.php b/templates/content/archive_list.php
index 6faad17..2d6ed08 100644
--- a/templates/content/archive_list.php
+++ b/templates/content/archive_list.php
@@ -5,6 +5,8 @@
     $msgList                 = (isset($_['msgList']) ? $_['msgList'] : array());
     $paramList               = (isset($_['paramList']) ? $_['paramList'] : array());
 
+    $urlGenerator = OC::$server->getURLGenerator();
+
     // alert messages
     $htmlAlert = '';
     if (!empty($msgList)) {
@@ -47,15 +49,15 @@
         <?php if (!empty($htmlAlert)) { ?>
             <div id="dematpayslip_alert"><?php print $htmlAlert; ?></div>
         <?php } ?>
-        <h2><?php p($l->t('Liste des archives')); ?> &nbsp;<a href="<?php echo \OC\URLGenerator::linkToRoute('dematpayslip.page.archive_csv', $paramList); ?>" class="button" title="<?php p($l->t('Export CSV')); ?>"><?php p($l->t('CSV')); ?></a></h2>
+        <h2><?php p($l->t('Liste des archives')); ?> &nbsp;<a href="<?php print $urlGenerator->linkToRoute('dematpayslip.page.archive_csv', $paramList); ?>" class="button" title="<?php p($l->t('Export CSV')); ?>"><?php p($l->t('CSV')); ?></a></h2>
         <br />
 
         <div>
-            <a href="<?php echo \OC\URLGenerator::linkToRoute('files.view.index', ['dir' => $exportDirUserPath]); ?>" class="button" target="_blank" title="<?php p($l->t('Accéder aux exports CSV')); ?>"><?php p($l->t('Accéder aux exports CSV')); ?></a>
+            <a href="<?php print $urlGenerator->linkToRoute('files.view.index', ['dir' => $exportDirUserPath]); ?>" class="button" target="_blank" title="<?php p($l->t('Accéder aux exports CSV')); ?>"><?php p($l->t('Accéder aux exports CSV')); ?></a>
         </div>
         <br />
 
-        <form action="<?php echo \OC\URLGenerator::linkToRoute('dematpayslip.page.archive_action'); ?>" id="demmatpayslip_archive_action_form" name="demmatpayslip_archive_action_form" method="post">
+        <form action="<?php print $urlGenerator->linkToRoute('dematpayslip.page.archive_action'); ?>" id="demmatpayslip_archive_action_form" name="demmatpayslip_archive_action_form" method="post">
             <input type="hidden" id="demmatpayslip_archive_action" name="action" value="" />
             <?php foreach ($paramList as $paramName => $paramValue) { ?>
                 <input type="hidden" id="<?php print 'param_' . $paramName; ?>" name="<?php print $paramName; ?>" value="<?php print $paramValue; ?>" />
@@ -82,7 +84,7 @@
                         <?php foreach ($dematpayslipArchiveList as $dematpayslipArchive) { ?>
                             <tr>
                                 <td><input type="checkbox" class="archive_select" id="archive_select_<?php print $dematpayslipArchive->getId(); ?>" name="archive_select[]" value="<?php print $dematpayslipArchive->getId(); ?>" style="cursor: pointer;" /></td>
-                                <td><a href="<?php echo \OC\URLGenerator::linkToRoute('files.view.index', ['fileid' => $dematpayslipArchive->getIdFile()]); ?>" target="_blank" title="<?php p($l->t('Voir')); ?>"><?php print $dematpayslipArchive->getFilePath(); ?></a></td>
+                                <td><a href="<?php print $urlGenerator->linkToRoute('files.view.index', ['fileid' => $dematpayslipArchive->getIdFile()]); ?>" target="_blank" title="<?php p($l->t('Voir')); ?>"><?php print $dematpayslipArchive->getFilePath(); ?></a></td>
                                 <td><?php print $dematpayslipArchive->getSiret(); ?></td>
                                 <td><?php print $dematpayslipArchive->getMatricule(); ?></td>
                                 <td><?php print $dematpayslipArchive->getLastname(); ?></td>
diff --git a/templates/content/index.php b/templates/content/index.php
index c888f05..94ffd6d 100644
--- a/templates/content/index.php
+++ b/templates/content/index.php
@@ -5,6 +5,8 @@
     $processArr       = (isset($_['processArr']) ? $_['processArr'] : array());
     $userArr          = (isset($_['userArr']) ? $_['userArr'] : array());
 
+    $urlGenerator = OC::$server->getURLGenerator();
+
     // alert messages
     $htmlAlert = '';
     if (!empty($msgList)) {
@@ -42,33 +44,25 @@
         }
     }
 ?>
-<div class="row" id="dematpayslip">
-    <div class="col-md-12 dematpayslip_block">
+<div id="dematpayslip">
+    <div class="dematpayslip_block">
         <h2><?php p($l->t('Dématérialisation des bulletins de paie')); ?></h2>
         <div id="dematpayslip_alert"><?php print $htmlAlert; ?></div>
 
-        <form action="<?php echo \OC\URLGenerator::linkToRoute('dematpayslip.page.upload'); ?>" name="dematpayslips_upload_form" enctype="multipart/form-data" method="POST" role="form">
-            <fieldset>
-                <legend class="dematpayslip_legend"><?php p($l->t('Upload des fichiers PDF et CSV')); ?></legend>
-                <input type="hidden" name="requesttoken" value="<?php p($_['requesttoken']); ?>">
-                <div class="form-group row">
-                    <label for="payslips_csv_file"><?php p($l->t('Fichier CSV')); ?></label> :
-                    <div class="col-md-6">
-                        <input type="file" name="payslips_csv_file" />
-                    </div>
-                </div>
-                <div class="form-group row">
-                    <label for="payslips_pdf_file"><?php p($l->t('Fichier PDF')); ?></label> :
-                    <div class="col-md-6">
-                        <input type="file" name="payslips_pdf_file" />
-                    </div>
-                </div>
-                <div class="form-group row">
-                    <div class="col-md-12">
-                        <button type="submit" class="btn btn-default"><?php p($l->t('Upload')); ?></button>
-                    </div>
-                </div>
-            </fieldset>
+        <form action="<?php print $urlGenerator->linkToRoute('dematpayslip.page.upload'); ?>" name="dematpayslips_upload_form" enctype="multipart/form-data" method="POST" role="form">
+            <div class="dematpayslip_legend"><?php p($l->t('Upload des fichiers PDF et CSV')); ?></div>
+            <input type="hidden" name="requesttoken" value="<?php p($_['requesttoken']); ?>">
+            <div>
+                <label for="payslips_csv_file"><?php p($l->t('Fichier CSV')); ?> : </label>
+                <div><input type="file" name="payslips_csv_file" /></div>
+            </div>
+            <div>
+                <label for="payslips_pdf_file"><?php p($l->t('Fichier PDF')); ?> : </label>
+                <div><input type="file" name="payslips_pdf_file" /></div>
+            </div>
+            <div>
+                <button type="submit" class="btn btn-default"><?php p($l->t('Upload')); ?></button>
+            </div>
         </form>
         <br />
         <br />
@@ -77,33 +71,27 @@
         if (!empty($processArr)) {
             if ($processArr['phase']>=1) {
                 ?>
-                <form action="<?php echo \OC\URLGenerator::linkToRoute('dematpayslip.page.check'); ?>" id="dematpayslips_check_form" name="dematpayslips_check_form" method="POST" role="form">
-                    <fieldset>
-                        <input type="hidden" name="requesttoken" value="<?php p($_['requesttoken']); ?>">
-                        <div class="form-group row">
-                            <div class="col-md-12">
-                                <label><?php p($l->t('Fichier CSV')); ?> : <?php echo $processArr['csvOrigin']; ?></label>
-                            </div>
-                        </div>
-                        <div class="form-group row">
-                            <div class="col-md-12">
-                                <label><?php p($l->t('Fichier PDF')); ?> : <?php echo $processArr['pdfOrigin']; ?></label>
-                            </div>
-                        </div>
-                        <div class="form-group row">
-                            <div class="col-md-12">
-                                <button type="submit" class="btn btn-default"><?php p($l->t('Vérifier')); ?></button>
-                                <?php
-                                    if ($canCancelProcess===true) {
-                                        ?>
-                                        <button type="button" id="dematpayslips_process_cancel_btn" class="btn btn-default" data-url="<?php echo \OC\URLGenerator::linkToRoute('dematpayslip.page.cancel'); ?>"><?php p($l->t('Abandonner')); ?></button>
-                                        <?php
-                                    }
+                <form action="<?php print $urlGenerator->linkToRoute('dematpayslip.page.check'); ?>" id="dematpayslips_check_form" name="dematpayslips_check_form" method="POST" role="form">
+                    <input type="hidden" name="requesttoken" value="<?php p($_['requesttoken']); ?>">
+                    <div>
+                        <label><?php p($l->t('Fichier CSV')); ?> : <?php echo $processArr['csvOrigin']; ?></label>
+                    </div>
+                    <div class="form-group row">
+                        <label><?php p($l->t('Fichier PDF')); ?> : <?php echo $processArr['pdfOrigin']; ?></label>
+                    </div>
+                    <div>
+                        <button type="submit" class="btn btn-default"><?php p($l->t('Vérifier')); ?></button>
+                        <?php
+                            if ($canCancelProcess===true) {
                                 ?>
-                            </div>
-                        </div>
-                    </fieldset>
+                                <button type="button" id="dematpayslips_process_cancel_btn" class="btn btn-default" data-url="<?php print $urlGenerator->linkToRoute('dematpayslip.page.cancel'); ?>"><?php p($l->t('Abandonner')); ?></button>
+                                <?php
+                            }
+                        ?>
+                    </div>
                 </form>
+                <br />
+                <br />
                 <?php
             }
 
@@ -113,15 +101,16 @@
                     $retry = 1;
                 }
                 ?>
-                <form action="<?php echo \OC\URLGenerator::linkToRoute('dematpayslip.page.indexation', array('retry' => $retry)); ?>" id="dematpayslips_indexation_form" name="dematpayslips_indexation_form" method="POST" role="form">
-                    <fieldset>
-                        <input type="hidden" name="requesttoken" value="<?php p($_['requesttoken']); ?>">
-                        <div class="form-group row">
-                            <div class="col-md-12">
-                                <button type="submit" class="btn btn-default"><?php p($l->t('Lancer')); ?></button>
-                            </div>
-                        </div>
-                    </fieldset>
+                <form action="<?php print $urlGenerator->linkToRoute('dematpayslip.page.indexation', array('retry' => $retry)); ?>" id="dematpayslips_indexation_form" name="dematpayslips_indexation_form" method="POST" role="form">
+                    <input type="hidden" name="requesttoken" value="<?php p($_['requesttoken']); ?>">
+                    <div>
+                        <input type="checkbox" id="payslip_launch_indexation" name="payslip_launch_indexation" value="1" checked="checked" /> <label for="payslip_launch_indexation"><?php p($l->t('Indexation')); ?></label>
+                        &nbsp;&nbsp;
+                        <input type="checkbox" id="payslip_launch_archive" name="payslip_launch_archive" value="1" checked="checked" /> <label for="payslip_launch_archive"><?php p($l->t('Archivage')); ?></label>
+                    </div>
+                    <div>
+                        <button type="submit" class="btn btn-default"><?php p($l->t('Lancer')); ?></button>
+                    </div>
                 </form>
                 <?php
             }
-- 
GitLab