diff --git a/lib/BackgroundJob/IndexationProcess.php b/lib/BackgroundJob/IndexationProcess.php
index de768631eec9111c1851bbc24c40486b7d0c688a..9b232f48545dbf71a32d9391e24ab73bfa0a3914 100644
--- a/lib/BackgroundJob/IndexationProcess.php
+++ b/lib/BackgroundJob/IndexationProcess.php
@@ -270,9 +270,9 @@ class IndexationProcess extends TimedJob {
                 $this->_log('Indexation process : Begin');
 
                 // find process in indexation step
-                $processList = $this->_dematpayslipProcessMapper->findAll();
+                $processList = $this->_dematpayslipProcessMapper->findAllLast();
                 if (!empty($processList)) {
-                    $process = current($processList);
+                    $process = $processList[0];
                     if ($process->getPhase() == DematpayslipProcess::PHASE_ID_INDEXATION) {
                         $process->load($this->_appName, $this->_config, $this->_dbConnection, $this->_l10n, $this->_rootFolder, $this->_shareManager, $this->_userManager, $userId, $this->_dematpayslipProcessMapper, $this->_dematpayslipProcessSkipMapper, $this->_dematpayslipUserMapper, $this->_timeZone);
                         $result = $process->indexation($processMsgList);
diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php
index e5e3168ca286607a48e1cf3bf7600a367de56649..f497cc47a5f2deb93c80e12dac563a86a89db71f 100644
--- a/lib/Controller/PageController.php
+++ b/lib/Controller/PageController.php
@@ -248,7 +248,7 @@ class PageController extends Controller {
         $this->_dematpayslipUserMapper = $dematpayslipUserMapper;
 
         // create process if not exists
-        $processList = $this->_dematpayslipProcessMapper->findAll();
+        $processList = $this->_dematpayslipProcessMapper->findAllLast();
         if (empty($processList)) {
             $process = new DematpayslipProcess();
             $process->setProcessing(0);
@@ -266,6 +266,7 @@ class PageController extends Controller {
             $this->_dematpayslipProcessMapper->insert($process);
             $this->_dematpaylsipProcess = $process;
         } else {
+            // get last process
             $this->_dematpaylsipProcess = $processList[0];
         }
 
@@ -323,7 +324,7 @@ class PageController extends Controller {
      * @throws  Exception
      */
     public function upload() {
-        // verifier l'utilisateur
+        // check user
         if ($this->_userId === $this->_dematpayslipConfigList['user_id']) {
             $this->_dematpaylsipProcess->upload();
 
diff --git a/lib/Db/DematpayslipProcess.php b/lib/Db/DematpayslipProcess.php
index 61c72bab77511e08df8f1ac66307a25912ec355e..cad01911fe8af6b471f6e38b5b57d927cecfab91 100644
--- a/lib/Db/DematpayslipProcess.php
+++ b/lib/Db/DematpayslipProcess.php
@@ -392,7 +392,7 @@ class DematpayslipProcess extends Entity implements JsonSerializable {
      * Cancel process
      */
     private function _processCancel() {
-        if ($this->getMustTerminate()<=0) {
+        if ($this->getMustTerminate() <= 0) {
             // clean upload directory
             if (is_dir($this->_uploadDirFullPath)) {
                 self::_removeAllFilesDir($this->_uploadDirFullPath);
@@ -1111,7 +1111,7 @@ class DematpayslipProcess extends Entity implements JsonSerializable {
     public function check() {
         $this->_initDematUser();
         $this->_processCheck();
-        if ($this->getPhase() < self::PHASE_ID_CHECK) {
+        if ($this->getPhase() != self::PHASE_ID_CHECK) {
             $this->_msgList['error'][] = $this->_l10n->t('Opération impossible : phase en cours "' . self::_getPhaseName($this->getPhase()) . '".');
         }
 
@@ -1602,7 +1602,7 @@ class DematpayslipProcess extends Entity implements JsonSerializable {
         $this->_initDematUser();
 
         $this->_processCheck();
-        if ($this->getPhase() < self::PHASE_ID_PRE_INDEXATION) {
+        if ($this->getPhase() != self::PHASE_ID_PRE_INDEXATION) {
             $this->_msgList['error'][] = $this->_l10n->t('Opération impossible : phase en cours "' . self::_getPhaseName($this->getPhase()) . '".');
         }
 
@@ -1867,7 +1867,6 @@ class DematpayslipProcess extends Entity implements JsonSerializable {
                 if ($this->getHasError() <= 0) {
                     $successMsg = 'Opération "' . self::_getPhaseName($this->getPhase()) . '" terminée avec succès.';
                     $this->_msgList['success'][] = $successMsg;
-                    //$this->_processInit();
                 }
                 $this->setProcessing(0);
                 $this->setPhase(self::PHASE_ID_INDEXATION);
@@ -1889,8 +1888,18 @@ class DematpayslipProcess extends Entity implements JsonSerializable {
         try {
             $this->_initDematUser();
 
+            $retry = 0;
+            if ($this->getHasError() > 0) {
+                $retry = $this->getPhaseStepNum();
+            }
+            if ($retry > 0) {
+                $this->setHasError(0);
+                $this->setErrorCode(0);
+                $this->setErrorMsg('');
+            }
+
             $this->_processCheck();
-            if ($this->getPhase() < self::PHASE_ID_INDEXATION) {
+            if ($this->getPhase() != self::PHASE_ID_INDEXATION) {
                 $this->_msgList['error'][] = $this->_l10n->t('Opération impossible : phase en cours "' . self::_getPhaseName($this->getPhase()) . '".');
             }
 
@@ -1909,7 +1918,9 @@ class DematpayslipProcess extends Entity implements JsonSerializable {
                 $this->setProcessing(1);
                 $this->setPhase(self::PHASE_ID_INDEXATION);
                 $this->setPhaseStartTime($phaseStartTime);
-                $this->setPhaseStepNum(0);
+                if (!($retry > 0)) {
+                    $this->setPhaseStepNum(0);
+                }
                 $this->setMustTerminate(1);
                 $this->setHasError(0);
                 $this->setErrorCode(0);
@@ -1968,6 +1979,15 @@ class DematpayslipProcess extends Entity implements JsonSerializable {
                     $phaseStep = 'indexation';
                     $this->_logCsvLine($this->_l10n->t('Début de la phase "' . $phaseStep . '".'), self::LOG_DEBUG);
                     $csvCheckLineNum = 0;
+                    $retryCsvNumLine = 0;
+                    if ($retry > 0) {
+                        if ($this->getPhaseStep() == $phaseStep) {
+                            $this->setPhaseStep('');
+                        }
+                        $retryCsvNumLine = $this->getPhaseStepNum();
+                        $this->_logCsvLine($this->_l10n->t('Reprise à la ligne ' . ($retryCsvNumLine + 1) . ' du fichier CSV créé lors de la phase de vérification.'), self::LOG_DEBUG);
+                    }
+
                     if (empty($this->getPhaseStep())) {
                         $userFolder = $this->_rootFolder->getUserFolder($this->_userId);
 
@@ -2048,6 +2068,7 @@ class DematpayslipProcess extends Entity implements JsonSerializable {
                                         $pdfPayslipCheckFileName = basename($pdfPayslipCheckFilePath);
                                         $pdfCheckFileNames = explode('_', $pdfPayslipCheckFileName);
                                         $csvCheckLineNum = intval($pdfCheckFileNames[0]) - 1;
+                                        if ($csvCheckLineNum < $retryCsvNumLine)    continue; // already done
 
                                         $this->_logCsvLine($this->_l10n->t('Bulletin de l\'agent '), self::LOG_DEBUG, $agentUser, $startDate, $endDate);
 
@@ -2079,17 +2100,6 @@ class DematpayslipProcess extends Entity implements JsonSerializable {
                                         if (empty($agentUser->getEmail())) {
                                             $this->_logCsvLine('-- ' . $this->_l10n->t('Création du PDF non dématérialisé de l\'agent (aucun email) : ' . ($csvCheckLineNum + 1)) . ' --', self::LOG_DEBUG, $agentUser, $startDate, $endDate);
 
-                                            // add all agent pdf pages
-                                            //$pdfPayslipNoDemat = new \setasign\Fpdi\Fpdi();
-                                            //$this->_logCsvLine($this->_l10n->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->_l10n->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
                                             $payslipNoDematHorodateDirPath = $this->_payslipNoIndexDir . DIRECTORY_SEPARATOR . $phaseStartDateTime->format('Y-m-d_H-i-s');
                                             try {
@@ -2119,11 +2129,9 @@ class DematpayslipProcess extends Entity implements JsonSerializable {
 
                                             // create PDF payslip in no index folder
                                             $this->_logCsvLine($this->_l10n->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';
                                             try {
                                                 /** @var File $payslipNoDematPDFNode */
-                                                //$payslipNoDematPDFNode = $userFolder->get($payslipNoDematPDFPath);
                                                 $payslipNoDematPDFNode = $userFolder->get($pdfPayslipCheckFilePath);
                                                 $payslipNoDematPDFNode->move($userFolder->getPath() . DIRECTORY_SEPARATOR . $pdfPayslipFilePath);
                                                 $dematpayslipArchive->setIdFile($payslipNoDematPDFNode->getId());
@@ -2145,8 +2153,6 @@ class DematpayslipProcess extends Entity implements JsonSerializable {
                                                 $processMsgList['success'][] = $dematpayslipArchive;
                                                 $dematpayslipArchive->setStatus(DematpayslipArchive::STATUS_INDEXED);
                                                 $dematpayslipArchive->setStatusTime($phaseStartTime);
-                                                $dematpayslipArchive->setDematIdProcess(0);
-                                                $dematpayslipArchive->setFilePagesNum('');
                                                 // next operation for this file if asked
                                                 if ($operationAskArchive) {
                                                     $dematpayslipArchive->setOperationProgress(DematpayslipArchive::OPERATION_ARCHIVE);
@@ -2286,21 +2292,9 @@ class DematpayslipProcess extends Entity implements JsonSerializable {
                                                         }
                                                     }
                                                     $payslipNoDematPDFPath = $payslipNoDematHorodateAgentDirPath . DIRECTORY_SEPARATOR . $startDate . '_' . $endDate;
-                                                    //$pdfPayslipNoDemat = new \setasign\Fpdi\Fpdi();
-
-                                                    // add all agent pdf pages
-                                                    //$this->_logCsvLine($this->_l10n->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->_l10n->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->_l10n->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';
                                                     try {
                                                         //$payslipNoDematPDFNode = $userFolder->get($payslipNoDematPDFPath);
@@ -2333,8 +2327,6 @@ class DematpayslipProcess extends Entity implements JsonSerializable {
                                             $processMsgList['success'][] = $dematpayslipArchive;
                                             $dematpayslipArchive->setStatus(DematpayslipArchive::STATUS_INDEXED);
                                             $dematpayslipArchive->setStatusTime($phaseStartTime);
-                                            $dematpayslipArchive->setDematIdProcess(0);
-                                            $dematpayslipArchive->setFilePagesNum('');
                                             // next operation for this file if asked
                                             if ($operationAskArchive) {
                                                 $dematpayslipArchive->setOperationProgress(DematpayslipArchive::OPERATION_ARCHIVE);
@@ -2368,21 +2360,19 @@ class DematpayslipProcess extends Entity implements JsonSerializable {
                                         foreach ($skipArchiveList as $skipArchive) {
                                             $processMsgList['success'][] = $skipArchive;
                                             // remove payslip created in check directory
-                                            try {
-                                                $skipArchiveNode = $this->_rootFolder->get($skipArchive->getFilePath());
-                                                $skipArchiveNode->delete();
-                                            } catch (Exception $e) {
-                                                $errorMsg = $this->_l10n->t('Impossible de supprimer "' . $skipArchive->getFilePath() . '".');
-                                                $this->_logCsvLine($errorMsg, self::LOG_ERROR);
-                                                $this->_processErrorMsg(-1, $errorMsg, $phaseStep, $csvCheckLineNum);
-                                            }
+                                            //try {
+                                            //    $skipArchiveNode = $this->_rootFolder->get($skipArchive->getFilePath());
+                                            //    $skipArchiveNode->delete();
+                                            //} catch (Exception $e) {
+                                            //    $errorMsg = $this->_l10n->t('Impossible de supprimer "' . $skipArchive->getFilePath() . '".');
+                                            //    $this->_logCsvLine($errorMsg, self::LOG_ERROR);
+                                            //    $this->_processErrorMsg(-1, $errorMsg, $phaseStep, $csvCheckLineNum);
+                                            //}
 
                                             $skipArchive->setIdFile($payslipSkipPDFPathNode->getId());
                                             $skipArchive->setFilePath($payslipSkipPDFPathNode->getPath());
                                             $skipArchive->setStatus(DematpayslipArchive::STATUS_INDEXED);
                                             $skipArchive->setStatusTime($phaseStartTime);
-                                            $skipArchive->setDematIdProcess(0);
-                                            $skipArchive->setFilePagesNum('');
                                             $skipArchive->setOperationProgress(DematpayslipArchive::OPERATION_FINISHED); // no next operation
                                             $skipArchive->setError(0);
                                             $dematpayslipArchiveMapper->update($skipArchive);
@@ -2410,7 +2400,7 @@ class DematpayslipProcess extends Entity implements JsonSerializable {
 
                             // create report sub-directory
                             if ($phaseStepNum >= $retryPhaseStepNum) {
-                                $this->_logCsvLine($this->_l10n->t('Création du dossier de rapport.'), self::LOG_DEBUG);
+                                $this->_logCsvLine($this->_l10n->t('Création du dossier du rapport.'), self::LOG_DEBUG);
                                 try {
                                     $userFolder->get($reportSubDirPath);
                                 } catch (Exception $e) {
@@ -2503,16 +2493,13 @@ class DematpayslipProcess extends Entity implements JsonSerializable {
                         }
                     }
                 }
-
+                $successMsg = 'Opération "' . self::_getPhaseName($this->getPhase()) . '" terminée avec succès.';
                 if (!$this->hasError()) {
-                    $successMsg = 'Opération "' . self::_getPhaseName($this->getPhase()) . '" terminée avec succès.';
                     $this->_logCsvLine($this->_l10n->t($successMsg), self::LOG_SUCCESS);
-                    $this->_msgList['success'][] = $successMsg;
-                    $this->_processInit();
                 }
-
                 $this->_logCsvLine('## ' . $this->_l10n->t('Fin du processus d\'indexation.') . ' ##', self::LOG_DEBUG);
                 fclose($this->_logFile);
+
                 // rename log file
                 try {
                     $logFileNode = $userFolder->get($logFilePath);
@@ -2520,10 +2507,16 @@ class DematpayslipProcess extends Entity implements JsonSerializable {
                 } catch (Exception $e) {
                     $this->_msgList['error'][] = $this->_l10n->t('Impossible de déplacer le fichier de log "' . $userFolder->getPath() . DIRECTORY_SEPARATOR . $logFilePath . '.csv' . '" .');
                 }
+
                 $this->setProcessing(0);
                 $this->_dematpayslipProcessMapper->update($this);
-                // empty process skip lines
-                $this->_dematpayslipProcessSkipMapper->deleteAllByIdProcess($this->getId());
+                if (!$this->hasError()) {
+                    $this->_msgList['success'][] = $successMsg;
+                    // create new process for next time
+                    $createdProcess = new DematpayslipProcess();
+                    $createdProcess->_processInit();
+                    $this->_dematpayslipProcessMapper->insert($createdProcess);
+                }
             }
 
             if ($this->hasError()) {
@@ -2661,22 +2654,25 @@ class DematpayslipProcess extends Entity implements JsonSerializable {
             $dematpayslipArchiveMapper = new DematpayslipArchiveMapper($this->_dbConnection);
 
             if (!empty($archiveSelectIdList)) {
+                $processDoneIdList = array();
                 foreach ($archiveSelectIdList as $archiveSelectId) {
                     $dematpayslipArchive = $dematpayslipArchiveMapper->find(intval($archiveSelectId));
                     if (!empty($dematpayslipArchive)) {
                         // get operation progress and launch process
                         $operationProgress = $dematpayslipArchive->getOperationProgress();
-                        if ($operationProgress == DematpayslipArchive::OPERATION_INDEXATION) {
-                            $processList = $this->_dematpayslipProcessMapper->findAll();
+                        if (!in_array($dematpayslipArchive->getDematIdProcess(), $processDoneIdList) && $operationProgress == DematpayslipArchive::OPERATION_INDEXATION) {
+                            $processList = $this->_dematpayslipProcessMapper->findAllLast();
                             if (!empty($processList)) {
-                                $process = current($processList);
-                                if ($process->getPhase() == DematpayslipProcess::PHASE_ID_INDEXATION) {
+                                $process = $processList[0];
+                                if ($dematpayslipArchive->getDematIdProcess() == $process->getId() && $process->getPhase() == DematpayslipProcess::PHASE_ID_INDEXATION) {
                                     $processMsgList = array(
                                         'error'   => array(),
                                         'success' => array(),
                                     );
                                     $process->load($this->_appName, $this->_config, $this->_dbConnection, $this->_l10n, $this->_rootFolder, $this->_shareManager, $this->_userManager, $this->_userId, $this->_dematpayslipProcessMapper, $this->_dematpayslipProcessSkipMapper, $this->_dematpayslipUserMapper, $this->_timeZone);
                                     $process->indexation($processMsgList);
+
+                                    $processDoneIdList[] = $process->getId();
                                     $errorMsgList = $process->getMsgList('error');
                                     $successMsgList = $process->getMsgList('success');
                                     if (!empty($errorMsgList)) {
@@ -2727,22 +2723,25 @@ class DematpayslipProcess extends Entity implements JsonSerializable {
             $dematpayslipArchiveMapper = new DematpayslipArchiveMapper($this->_dbConnection);
 
             if (!empty($archiveSelectIdList)) {
+                $processDoneIdList = array();
                 foreach ($archiveSelectIdList as $archiveSelectId) {
                     $dematpayslipArchive = $dematpayslipArchiveMapper->find(intval($archiveSelectId));
                     if (!empty($dematpayslipArchive)) {
                         // get operation progress and launch process
                         $operationProgress = $dematpayslipArchive->getOperationProgress();
-                        if ($operationProgress == DematpayslipArchive::OPERATION_INDEXATION) {
-                            $processList = $this->_dematpayslipProcessMapper->findAll();
+                        if (!in_array($dematpayslipArchive->getDematIdProcess(), $processDoneIdList) && $operationProgress == DematpayslipArchive::OPERATION_INDEXATION) {
+                            $processList = $this->_dematpayslipProcessMapper->findAllLast();
                             if (!empty($processList)) {
-                                $process = current($processList);
-                                if ($process->getPhase() == DematpayslipProcess::PHASE_ID_INDEXATION) {
+                                $process = $processList[0];
+                                if ($dematpayslipArchive->getDematIdProcess() == $process->getId() && $process->getPhase() == DematpayslipProcess::PHASE_ID_INDEXATION) {
                                     $processMsgList = array(
                                         'error'   => array(),
                                         'success' => array(),
                                     );
                                     $process->load($this->_appName, $this->_config, $this->_dbConnection, $this->_l10n, $this->_rootFolder, $this->_shareManager, $this->_userManager, $this->_userId, $this->_dematpayslipProcessMapper, $this->_dematpayslipProcessSkipMapper, $this->_dematpayslipUserMapper, $this->_timeZone);
                                     $process->indexation($processMsgList);
+
+                                    $processDoneIdList[] = $process->getId();
                                     $errorMsgList = $process->getMsgList('error');
                                     $successMsgList = $process->getMsgList('success');
                                     if (!empty($errorMsgList)) {
diff --git a/lib/Db/DematpayslipProcessMapper.php b/lib/Db/DematpayslipProcessMapper.php
index 7db23d429617238b120c96b1d80a1f00d4e62386..c82f4e573ee0bc8ca9c25ef25edd967db53f34c3 100644
--- a/lib/Db/DematpayslipProcessMapper.php
+++ b/lib/Db/DematpayslipProcessMapper.php
@@ -30,4 +30,14 @@ class DematpayslipProcessMapper extends QBMapper {
 
         return $this->findEntities($qb);
     }
+
+    public function findAllLast() {
+        $qb = $this->db->getQueryBuilder();
+
+        $qb->select('*')
+            ->from($this->getTableName())
+            ->orderBy('id', 'DESC');
+
+        return $this->findEntities($qb);
+    }
 }