From ac6aa2cfc46e87141f995ff4c8908649fbfd6cd1 Mon Sep 17 00:00:00 2001 From: VESSILLER <lvessiller@open-dsi.fr> Date: Tue, 2 Jun 2020 17:53:48 +0200 Subject: [PATCH] NEW liste des archives a traiter et traitees --- appinfo/routes.php | 1 - js/script.js | 28 ++- lib/Controller/PageController.php | 364 ++++++++++++--------------- lib/Db/DematpayslipArchiveMapper.php | 34 +++ templates/content/archive_list.php | 16 +- templates/navigation/index.php | 6 + 6 files changed, 219 insertions(+), 230 deletions(-) diff --git a/appinfo/routes.php b/appinfo/routes.php index e39ec25..265e384 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -18,7 +18,6 @@ return [ ['name' => 'page#agent_list', 'url' => '/agent_list', 'verb' => 'GET'], ['name' => 'page#agent_csv', 'url' => '/agent_csv', 'verb' => 'GET'], ['name' => 'page#archive_list', 'url' => '/archive_list', 'verb' => 'GET'], - ['name' => 'page#archive_list_action', 'url' => '/archive_list_action', 'verb' => 'POST'], ['name' => 'page#archive_action', 'url' => '/archive_action', 'verb' => 'POST'], ['name' => 'page#user_list', 'url' => '/user_list', 'verb' => ['GET', 'POST']], ] diff --git a/js/script.js b/js/script.js index 122977c..ef87b4e 100644 --- a/js/script.js +++ b/js/script.js @@ -93,17 +93,25 @@ jQuery(document).ready(function(){ 'style': 'multi', 'selector': 'input[name="archive_select[]"]' }, - 'dom': 'Bfrtip', + 'dom': 'Blfrtip', 'buttons': [ - { - 'id': 'btn_create', - 'text': 'Créer archive', - 'action': function() { - //jQuery('#archive_list').DataTable().rows().select(); - jQuery('#demmatpayslip_archive_action').val('create'); - jQuery('#demmatpayslip_archive_action_form').submit(); - } - }, + { + 'id': 'btn_create', + 'text': 'Créer archive', + 'action': function() { + //jQuery('#archive_list').DataTable().rows().select(); + jQuery('#demmatpayslip_archive_action').val('create'); + jQuery('#demmatpayslip_archive_action_form').submit(); + } + }, + { + 'id': 'btn_delete', + 'text': 'Ne pas archiver', + 'action': function() { + jQuery('#demmatpayslip_archive_action').val('delete'); + jQuery('#demmatpayslip_archive_action_form').submit(); + } + } // 'selectAll', // 'selectNone', ] diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 3133714..61dbeac 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -182,15 +182,21 @@ class PageController extends Controller { /** * Assign params for archive list * - * @return array Params for template + * @param int $archived [=-1] for all, 0 for not archived and 1 for archived + * @return array Params for template */ - private function _assignArchiveList() { + private function _assignArchiveList($archived) { + $paramList = array( + 'archived' => $archived + ); + // get archive list $dematpayslipArchiveMapper = new DematpayslipArchiveMapper(\OC::$server->getDatabaseConnection()); return array( - 'dematpayslipArchiveList' => $dematpayslipArchiveMapper->findAll(), - 'msgList' => $this->_msgList + 'dematpayslipArchiveList' => $dematpayslipArchiveMapper->findAllArchived($archived), + 'msgList' => $this->_msgList, + 'paramList' => $paramList ); } @@ -1316,7 +1322,7 @@ class PageController extends Controller { } // Phase - decoupage des pages du fichier PDF - if ($this->_process->getHasError()>0) $this->_processFailOnFirstError=true; + if ($this->_process->getHasError()>0) $this->_processFailOnFirstError = true; if ($this->_processFailOnFirstError===false || $this->_process->getHasError()<=0) { $this->_logCsvLine('## ' . $this->l->t('Début de découpage des pages du fichier PDF.') . ' ##', self::LOG_DEBUG); @@ -1444,7 +1450,9 @@ class PageController extends Controller { $this->_process->setProcessing(1); $this->_process->setPhase(2); $this->_process->setPhaseStartTime($phaseStartTime); - $this->_process->setPhaseStepNum(0); + if (!($retry > 0)) { + $this->_process->setPhaseStepNum(0); + } $this->_process->setMustTerminate(1); $this->_process->setHasError(0); $this->_process->setErrorCode(0); @@ -1662,25 +1670,59 @@ class PageController extends Controller { $this->_processErrorMsg(-1, $errorMsg, $phaseStep, $csvCheckLineNum); } - // TODO : check if file path not already archived (not have a pastell document Id) - // insert new file to archive + // check if file path not already archived (not have a pastell document Id) $pdfPayslipFile = Filesystem::getFileInfo($pdfPayslipFilePath); - $dematpayslipArchive = new DematpayslipArchive(); - $dematpayslipArchive->setIdFile($pdfPayslipFile->getId()); - $dematpayslipArchive->setIdUser(''); - $dematpayslipArchive->setFilePath($pdfPayslipFile->getPath()); - $dematpayslipArchive->setDematpayslipIdUser(0); - $dematpayslipArchive->setSiret($siret); - $dematpayslipArchive->setMatricule($matricule); - $dematpayslipArchive->setYear($year); - $dematpayslipArchive->setMonth($month); - $dematpayslipArchive->setLastname($lastname); - $dematpayslipArchive->setFirstname($firstname); - $dematpayslipArchive->setStartDate($startDate); - $dematpayslipArchive->setEndDate($endDate); - $dematpayslipArchive->setEditionDate($editionDate); - $dematpayslipArchive->setImportTime($phaseStartDateTime->getTimestamp()); - $dematpayslipArchiveMapper->insert($dematpayslipArchive); + $dematpayslipArchiveExistList = $dematpayslipArchiveMapper->findAllByFilePath($pdfPayslipFile->getPath()); + if (empty($dematpayslipArchiveExistList)) { + // insert new file to archive + $dematpayslipArchive = new DematpayslipArchive(); + $dematpayslipArchive->setIdFile($pdfPayslipFile->getId()); + $dematpayslipArchive->setIdUser(''); + $dematpayslipArchive->setFilePath($pdfPayslipFile->getPath()); + $dematpayslipArchive->setDematpayslipIdUser(0); + $dematpayslipArchive->setSiret($siret); + $dematpayslipArchive->setMatricule($matricule); + $dematpayslipArchive->setYear($year); + $dematpayslipArchive->setMonth($month); + $dematpayslipArchive->setLastname($lastname); + $dematpayslipArchive->setFirstname($firstname); + $dematpayslipArchive->setStartDate($startDate); + $dematpayslipArchive->setEndDate($endDate); + $dematpayslipArchive->setEditionDate($editionDate); + $dematpayslipArchive->setImportTime($phaseStartDateTime->getTimestamp()); + $dematpayslipArchiveMapper->insert($dematpayslipArchive); + } else { + if (count($dematpayslipArchiveExistList) > 1) { + $errorMsg = $this->l->t('Plusieurs bulletins de paie ayant pour chemin "' . $pdfPayslipFile->getPath() . '" existent déjà .'); + $this->_logCsvLine($errorMsg, self::LOG_ERROR, $siret, $matricule, $fullname, $zipCity, $startDate, $endDate, $email); + $this->_processErrorMsg(-1, $errorMsg, $phaseStep, $csvCheckLineNum); + } else { + // only one payslip was found + $dematpayslipArchiveExist = $dematpayslipArchiveExistList[0]; + + if (!empty($dematpayslipArchiveExist->getPastellIdDocument())) { + $errorMsg = $this->l->t('Ce bulletin de paie ayant pour chemin "' . $pdfPayslipFile->c() . '" est déjà en cours d\'archivage.'); + $this->_logCsvLine($errorMsg, self::LOG_ERROR, $siret, $matricule, $fullname, $zipCity, $startDate, $endDate, $email); + $this->_processErrorMsg(-1, $errorMsg, $phaseStep, $csvCheckLineNum); + } else { + // update file to archive + $dematpayslipArchiveExist->setIdFile($pdfPayslipFile->getId()); + $dematpayslipArchiveExist->setIdUser(''); + $dematpayslipArchiveExist->setDematpayslipIdUser(0); + $dematpayslipArchiveExist->setSiret($siret); + $dematpayslipArchiveExist->setMatricule($matricule); + $dematpayslipArchiveExist->setYear($year); + $dematpayslipArchiveExist->setMonth($month); + $dematpayslipArchiveExist->setLastname($lastname); + $dematpayslipArchiveExist->setFirstname($firstname); + $dematpayslipArchiveExist->setStartDate($startDate); + $dematpayslipArchiveExist->setEndDate($endDate); + $dematpayslipArchiveExist->setEditionDate($editionDate); + $dematpayslipArchiveExist->setImportTime($phaseStartDateTime->getTimestamp()); + $dematpayslipArchiveMapper->update($dematpayslipArchiveExist); + } + } + } $csvCheckLineNum++; continue; @@ -1837,25 +1879,59 @@ class PageController extends Controller { } } - // TODO : check if file path not already archived (not have a pastell document Id) - // insert new file to archive + // check if file path not already archived (not have a pastell document Id) $pdfPayslipFile = Filesystem::getFileInfo($pdfPayslipFilePath); - $dematpayslipArchive = new DematpayslipArchive(); - $dematpayslipArchive->setIdFile($pdfPayslipFile->getId()); - $dematpayslipArchive->setIdUser($dematpayslipUser->getUserId()); - $dematpayslipArchive->setFilePath($pdfPayslipFile->getPath()); - $dematpayslipArchive->setDematpayslipIdUser($dematpayslipUser->getId()); - $dematpayslipArchive->setSiret($siret); - $dematpayslipArchive->setMatricule($matricule); - $dematpayslipArchive->setYear($year); - $dematpayslipArchive->setMonth($month); - $dematpayslipArchive->setLastname($lastname); - $dematpayslipArchive->setFirstname($firstname); - $dematpayslipArchive->setStartDate($startDate); - $dematpayslipArchive->setEndDate($endDate); - $dematpayslipArchive->setEditionDate($editionDate); - $dematpayslipArchive->setImportTime($phaseStartDateTime->getTimestamp()); - $dematpayslipArchiveMapper->insert($dematpayslipArchive); + $dematpayslipArchiveExistList = $dematpayslipArchiveMapper->findAllByFilePath($pdfPayslipFile->getPath()); + if (empty($dematpayslipArchiveExistList)) { + // insert new file to archive + $dematpayslipArchive = new DematpayslipArchive(); + $dematpayslipArchive->setIdFile($pdfPayslipFile->getId()); + $dematpayslipArchive->setIdUser($dematpayslipUser->getUserId()); + $dematpayslipArchive->setFilePath($pdfPayslipFile->getPath()); + $dematpayslipArchive->setDematpayslipIdUser($dematpayslipUser->getId()); + $dematpayslipArchive->setSiret($siret); + $dematpayslipArchive->setMatricule($matricule); + $dematpayslipArchive->setYear($year); + $dematpayslipArchive->setMonth($month); + $dematpayslipArchive->setLastname($lastname); + $dematpayslipArchive->setFirstname($firstname); + $dematpayslipArchive->setStartDate($startDate); + $dematpayslipArchive->setEndDate($endDate); + $dematpayslipArchive->setEditionDate($editionDate); + $dematpayslipArchive->setImportTime($phaseStartDateTime->getTimestamp()); + $dematpayslipArchiveMapper->insert($dematpayslipArchive); + } else { + if (count($dematpayslipArchiveExistList) > 1) { + $errorMsg = $this->l->t('Plusieurs bulletins de paie ayant pour chemin "' . $pdfPayslipFile->getPath() . '" existent déjà .'); + $this->_logCsvLine($errorMsg, self::LOG_ERROR, $siret, $matricule, $fullname, $zipCity, $startDate, $endDate, $email); + $this->_processErrorMsg(-1, $errorMsg, $phaseStep, $csvCheckLineNum); + } else { + // only one payslip was found + $dematpayslipArchiveExist = $dematpayslipArchiveExistList[0]; + + if (!empty($dematpayslipArchiveExist->getPastellIdDocument())) { + $errorMsg = $this->l->t('Ce bulletin de paie ayant pour chemin "' . $pdfPayslipFile->getPath() . '" est déjà en cours d\'archivage.'); + $this->_logCsvLine($errorMsg, self::LOG_ERROR, $siret, $matricule, $fullname, $zipCity, $startDate, $endDate, $email); + $this->_processErrorMsg(-1, $errorMsg, $phaseStep, $csvCheckLineNum); + } else { + // update file to archive + $dematpayslipArchiveExist->setIdFile($pdfPayslipFile->getId()); + $dematpayslipArchiveExist->setIdUser($dematpayslipUser->getUserId()); + $dematpayslipArchiveExist->setDematpayslipIdUser($dematpayslipUser->getId()); + $dematpayslipArchiveExist->setSiret($siret); + $dematpayslipArchiveExist->setMatricule($matricule); + $dematpayslipArchiveExist->setYear($year); + $dematpayslipArchiveExist->setMonth($month); + $dematpayslipArchiveExist->setLastname($lastname); + $dematpayslipArchiveExist->setFirstname($firstname); + $dematpayslipArchiveExist->setStartDate($startDate); + $dematpayslipArchiveExist->setEndDate($endDate); + $dematpayslipArchiveExist->setEditionDate($editionDate); + $dematpayslipArchiveExist->setImportTime($phaseStartDateTime->getTimestamp()); + $dematpayslipArchiveMapper->update($dematpayslipArchiveExist); + } + } + } } else { $errorMsg = $this->l->t('L\'utilisateur "' . $userFindByEmailId . '" n\'a pas de dossier SIRET-MATRICULE associé [siret="' . $siret . '", matricule="' . $matricule . '", email="' . $email . '"].'); $this->_logCsvLine($errorMsg, self::LOG_ERROR, $siret, $matricule, $fullname, $zipCity, $startDate, $endDate, $email); @@ -2161,155 +2237,12 @@ class PageController extends Controller { if ($this->userId === $this->_dematpayslipConfigList['user_id']) { $this->_initDematFolders(); - return new TemplateResponse('dematpayslip', 'archive_list', $this->_assignArchiveList()); - } else { - return $this->shares(); - } - } - - /** - * Archive list generate - * - * @NoAdminRequired - * @NoCSRFRequired - * - * @return TemplateResponse - * @throws \OC\User\NoUserException - */ - public function archiveListAction() { - // verifier l'utilisateur - if ($this->userId === $this->_dematpayslipConfigList['user_id']) { - $this->_initDematFolders(); - - $action = filter_input(INPUT_POST, 'action', FILTER_SANITIZE_STRING); - -// if ($action == 'refresh') { -// // refresh new payslip files to archive -// $dematpayslipArchiveMapper = new DematpayslipArchiveMapper(\OC::$server->getDatabaseConnection()); -// -// // payslip list to archive -// $payslipDirPath = $this->_dematpayslipConfigList['payslip_dir']; -// $payslipFileList = $this->_findAllFiles($payslipDirPath); -// if (!empty($payslipFileList)) { -// foreach ($payslipFileList as $payslipFile) { -// $idFile = $payslipFile->getId(); -// $idUser = ''; -// $dematpayslipIdUser = 0; -// $siret = ''; -// $matricule = ''; -// $year = ''; -// $month = ''; -// $lastname = ''; -// $firstname = ''; -// $startDate = ''; -// $endDate = ''; -// -// // get file information (ex : files/Bulletins/SIRET-MATRICULE/YEAR/START-DATE_END-DATE.pdf) -// $pathArr = explode('files' . DIRECTORY_SEPARATOR, $payslipFile->getInternalPath()); -// if (count($pathArr) > 1) { -// $path = $pathArr[1]; -// $payslipDirArr = explode(DIRECTORY_SEPARATOR, $path); -// if (count($payslipDirArr) > 1) { -// $siretMatriculeArr = explode('-', $payslipDirArr[1]); -// if (count($siretMatriculeArr) > 1) { -// $siret = $siretMatriculeArr[0]; -// $matricule = $siretMatriculeArr[1]; -// -// $dematpayslipUserList = $this->_dematpayslipUserMapper->findAllBySiretAndMatricule($siret, $matricule); -// if (count($dematpayslipUserList) === 1) { -// $dematpayslipUser = $dematpayslipUserList[0]; -// $idUser = $dematpayslipUser->getUserId(); -// $dematpayslipIdUser = $dematpayslipUser->getId(); -// $lastname = $dematpayslipUser->getLastname(); -// $firstname = $dematpayslipUser->getFirstname(); -// -// if (empty($lastname) && empty($firstname)) { -// $agentUser = \OC::$server->getUserManager()->get($idUser); -// $agentDisplayNameArr = explode(' ', $agentUser->getDisplayName(), 2); -// if (count($agentDisplayNameArr) > 1) { -// $lastname = $agentDisplayNameArr[0]; -// $firstname = $agentDisplayNameArr[1]; -// } -// } -// } -// } -// } -// -// $payslipFileName = explode('.', $payslipFile->getName()); -// $payslipPeriodArr = explode('_', $payslipFileName[0]); -// if (count($payslipPeriodArr) > 1) { -// $startDate = $payslipPeriodArr[0]; -// $endDate = $payslipPeriodArr[1]; -// //setlocale(LC_TIME, 'fr_FR'); -// $startTime = strtotime($startDate); -// //$startDateTime = new \DateTime(); -// //$startDateTime->setTimezone(\OC::$server->getDateTimeZone()); -// //$startDateTime->setTimestamp($startTime); -// //$year = $startDateTime->format('Y'); -// //$month = strtolower($startDateTime->format('F')); -// $year = strftime('%Y', $startTime); -// $month = strtolower(strftime('%B', $startTime)); -// } -// } -// -// // check parameters -// if (!($idFile > 0)) { -// $this->_msgList['error'][] = $this->l->t('Le champ "Id de fichier" n\'a pas été retrouvé dans le fichier "' . $payslipFile->getInternalPath() . '".'); -// } -// if (!($dematpayslipIdUser > 0)) { -// $this->_msgList['error'][] = $this->l->t('Le champ "Id utilisateur" n\'a pas été retrouvé dans le fichier "' . $payslipFile->getInternalPath() . '".'); -// } -// if (empty($siret)) { -// $this->_msgList['error'][] = $this->l->t('Le champ "Siret" n\'a pas été retrouvé dans le fichier "' . $payslipFile->getInternalPath() . '".'); -// } -// if (empty($matricule)) { -// $this->_msgList['error'][] = $this->l->t('Le champ "Matricule" n\'a pas été retrouvé dans le fichier "' . $payslipFile->getInternalPath() . '".'); -// } -// if (empty($year)) { -// $this->_msgList['error'][] = $this->l->t('Le champ "Année" n\'a pas été retrouvé dans le fichier "' . $payslipFile->getInternalPath() . '".'); -// } -// if (empty($month)) { -// $this->_msgList['error'][] = $this->l->t('Le champ "Mois" n\'a pas été retrouvé dans le fichier "' . $payslipFile->getInternalPath() . '".'); -// } -// if (empty($lastname)) { -// $this->_msgList['error'][] = $this->l->t('Le champ "Nom" n\'a pas été retrouvé dans le fichier "' . $payslipFile->getInternalPath() . '".'); -// } -// if (empty($firstname)) { -// $this->_msgList['error'][] = $this->l->t('Le champ "Prénom" n\'a pas été retrouvé dans le fichier "' . $payslipFile->getInternalPath() . '".'); -// } -// if (empty($startDate)) { -// $this->_msgList['error'][] = $this->l->t('Le champ "Date de début" n\'a pas été retrouvé dans le fichier "' . $payslipFile->getInternalPath() . '".'); -// } -// if (empty($endDate)) { -// $this->_msgList['error'][] = $this->l->t('Le champ "Date de fin" n\'a pas été retrouvé dans le fichier "' . $payslipFile->getInternalPath() . '".'); -// } -// -// if (count($this->_msgList['error']) <= 0) { -// $dematpayslipArchiveList = $dematpayslipArchiveMapper->findAllByIdFile($idFile); -// if (empty($dematpayslipArchiveList)) { -// // insert new file to archive -// $dematpayslipArchive = new DematpayslipArchive(); -// $dematpayslipArchive->setIdFile($idFile); -// $dematpayslipArchive->setIdUser($idUser); -// $dematpayslipArchive->setDematpayslipIdUser($dematpayslipIdUser); -// $dematpayslipArchive->setSiret($siret); -// $dematpayslipArchive->setMatricule($matricule); -// $dematpayslipArchive->setYear($year); -// $dematpayslipArchive->setMonth($month); -// $dematpayslipArchive->setLastname($lastname); -// $dematpayslipArchive->setFirstname($firstname); -// $dematpayslipArchive->setStartDate($startDate); -// $dematpayslipArchive->setEndDate($endDate); -// $dematpayslipArchiveMapper->insert($dematpayslipArchive); -// } -// } else { -// break; -// } -// } -// } -// } + $archived = filter_input(INPUT_GET, 'archived', FILTER_SANITIZE_NUMBER_INT); + if ($archived === null) { + $archived = -1; + } - return new TemplateResponse('dematpayslip', 'archive_list', $this->_assignArchiveList()); + return new TemplateResponse('dematpayslip', 'archive_list', $this->_assignArchiveList($archived)); } else { return $this->shares(); } @@ -2329,14 +2262,18 @@ class PageController extends Controller { if ($this->userId === $this->_dematpayslipConfigList['user_id']) { $this->_initDematFolders(); - $action = filter_input(INPUT_POST, 'action', FILTER_SANITIZE_STRING); + $archived = filter_input(INPUT_POST, 'archived', FILTER_SANITIZE_NUMBER_INT); + if ($archived === null) { + $archived = -1; + } - if ($action == 'create') { - $archiveSelectIdList = filter_input(INPUT_POST, 'archive_select', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); + $action = filter_input(INPUT_POST, 'action', FILTER_SANITIZE_STRING); + $archiveSelectIdList = filter_input(INPUT_POST, 'archive_select', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); - if (!empty($archiveSelectIdList)) { - $dematpayslipArchiveMapper = new DematpayslipArchiveMapper(\OC::$server->getDatabaseConnection()); + if (!empty($archiveSelectIdList)) { + $dematpayslipArchiveMapper = new DematpayslipArchiveMapper(\OC::$server->getDatabaseConnection()); + if ($action == 'create') { foreach ($archiveSelectIdList as $archiveSelectId) { $dematpayslipArchive = $dematpayslipArchiveMapper->find(intval($archiveSelectId)); if (!empty($dematpayslipArchive)) { @@ -2349,9 +2286,9 @@ class PageController extends Controller { } // Pastell API config - $pastellConfigFlowId = $this->config->getAppValue($this->appName, 'pastell_config_flow' . $archiveFlowNum . '_id', ''); + $pastellConfigFlowId = $this->config->getAppValue($this->appName, 'pastell_config_flow' . $archiveFlowNum . '_id', ''); $pastellConfigFlowMapper = new PastellConfigFlowMapper(\OC::$server->getDatabaseConnection()); - $pastellConfigFlow = $pastellConfigFlowMapper->find($pastellConfigFlowId); + $pastellConfigFlow = $pastellConfigFlowMapper->find($pastellConfigFlowId); try { // Pastell API connection @@ -2386,10 +2323,10 @@ class PageController extends Controller { } if ($dematpayslipArchive->getPastellLastAction() == 'modification') { // send document file - $fileId = $dematpayslipArchive->getIdFile(); - $filePath = Filesystem::getPath($fileId); - $file = Filesystem::getFileInfo($filePath); - $fileName = $file->getName(); + $fileId = $dematpayslipArchive->getIdFile(); + $filePath = Filesystem::getPath($fileId); + $file = Filesystem::getFileInfo($filePath); + $fileName = $file->getName(); $fileContent = 'TEST'; //$fileContent = Filesystem::file_get_contents($filePath); $responseData = $pastellAPI->postEntityDocumentFile($pastellConfigFlow->getIdE(), $dematpayslipArchive->getPastellIdDocument(), 'document', 0, $fileName, $fileContent); @@ -2412,12 +2349,12 @@ class PageController extends Controller { if ($dematpayslipArchive->getPastellLastAction() == 'preparation-suppression-automatique') { // create "sae_config" JSON file and send it $saeConfigArr = array( - 'matricule' => $dematpayslipArchive->getMatricule(), - 'mois' => $dematpayslipArchive->getMonth(), - 'annee' => $dematpayslipArchive->getYear(), - 'nom' => $dematpayslipArchive->getLastname(), - 'prenom' => $dematpayslipArchive->getFirstname(), - 'date_edition' => $dematpayslipArchive->getEditionDate(), + 'matricule' => $dematpayslipArchive->getMatricule(), + 'mois' => $dematpayslipArchive->getMonth(), + 'annee' => $dematpayslipArchive->getYear(), + 'nom' => $dematpayslipArchive->getLastname(), + 'prenom' => $dematpayslipArchive->getFirstname(), + 'date_edition' => $dematpayslipArchive->getEditionDate(), 'periode_2_de_paie' => $dematpayslipArchive->getEndDate(), 'periode_1_de_paie' => $dematpayslipArchive->getStartDate(), ); @@ -2439,10 +2376,21 @@ class PageController extends Controller { } } } + } elseif ($action == 'delete') { + foreach ($archiveSelectIdList as $archiveSelectId) { + $dematpayslipArchive = $dematpayslipArchiveMapper->find(intval($archiveSelectId)); + if (!empty($dematpayslipArchive)) { + if (!empty($dematpayslipArchive->getPastellIdDocument())) { + $this->_msgList['error'][] = $this->l->t('Impossible de supprimer le bulletin de paie "' . $dematpayslipArchive->getFilePath() . '" en cours d\'archivage.');; + } else { + $dematpayslipArchiveMapper->delete($dematpayslipArchive); + } + } + } } } - return new TemplateResponse('dematpayslip', 'archive_list', $this->_assignArchiveList()); + return new TemplateResponse('dematpayslip', 'archive_list', $this->_assignArchiveList($archived)); } else { return $this->shares(); } diff --git a/lib/Db/DematpayslipArchiveMapper.php b/lib/Db/DematpayslipArchiveMapper.php index ced7f33..e050e09 100644 --- a/lib/Db/DematpayslipArchiveMapper.php +++ b/lib/Db/DematpayslipArchiveMapper.php @@ -34,6 +34,40 @@ class DematpayslipArchiveMapper extends QBMapper { return $this->findEntities($qb); } + public function findAllByFilePath(string $filePath) { + $qb = $this->db->getQueryBuilder(); + + $qb->select('*') + ->from($this->getTableName()) + ->where( + $qb->expr()->eq('file_path', $qb->createNamedParameter($filePath)) + ); + + return $this->findEntities($qb); + } + + public function findAllArchived(int $archived) { + $qb = $this->db->getQueryBuilder(); + + $qb->select('*'); + $qb->from($this->getTableName()); + $qb->where( + $qb->expr()->eq('disabled', $qb->createNamedParameter(0)) + ); + + if ($archived == 1) { + $qb->where( + $qb->expr()->isNotNull('pastell_id_document') + ); + } elseif ($archived == 0) { + $qb->where( + $qb->expr()->isNull('pastell_id_document') + ); + } + + return $this->findEntities($qb); + } + public function findAll() { $qb = $this->db->getQueryBuilder(); diff --git a/templates/content/archive_list.php b/templates/content/archive_list.php index cfe207b..12034d1 100644 --- a/templates/content/archive_list.php +++ b/templates/content/archive_list.php @@ -2,6 +2,7 @@ // assigned $dematpayslipArchiveList = (isset($_['dematpayslipArchiveList']) ? $_['dematpayslipArchiveList'] : array()); $msgList = (isset($_['msgList']) ? $_['msgList'] : array()); + $paramList = (isset($_['paramList']) ? $_['paramList'] : array()); // alert messages $htmlAlert = ''; @@ -48,18 +49,11 @@ <h2><?php p($l->t('Liste des archives')); ?> </h2> <br /> -<!-- <form action="--><?php //echo \OC\URLGenerator::linkToRoute('dematpayslip.page.archive_list_action'); ?><!--" name="demmatpayslip_archive_list_action_form" method="post">--> -<!-- <input type="hidden" name="requesttoken" value="--><?php //p($_['requesttoken']); ?><!--">--> -<!-- <input type="hidden" name="action" value="refresh" />--> -<!-- <div>--> -<!-- <button type="submit" class="btn btn-default">--><?php //p($l->t('Actualiser')); ?><!--</button>--> -<!-- </div>--> -<!-- </form>--> -<!-- <br />--> -<!-- <br />--> - <form action="<?php echo \OC\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" name="<?php print $paramName; ?>" value="<?php print $paramValue; ?>" /> + <?php } ?> <div class="table-responsive"> <table class="table table-bordered" id="archive_list"> <thead class="thead-dark"> @@ -82,7 +76,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><?php print $dematpayslipArchive->getFilePath(); ?></td> + <td><a href="<?php echo \OC\URLGenerator::linkToRoute('files.view.index', ['fileid' => $dematpayslipArchive->getIdFile()]); ?>" 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/navigation/index.php b/templates/navigation/index.php index de8c062..cd408ae 100644 --- a/templates/navigation/index.php +++ b/templates/navigation/index.php @@ -2,4 +2,10 @@ <li><a href="<?php echo \OC\URLGenerator::linkToRoute('dematpayslip.page.index'); ?>">Dématérialisation</a></li> <li><a href="<?php echo \OC\URLGenerator::linkToRoute('dematpayslip.page.agent_list'); ?>">Liste des agents</a></li> <li><a href="<?php echo \OC\URLGenerator::linkToRoute('dematpayslip.page.archive_list'); ?>">Liste des archives</a></li> + <li> + <ul> + <li><a href="<?php echo \OC\URLGenerator::linkToRoute('dematpayslip.page.archive_list', ['archived' => 0]); ?>">A traiter</a></li> + <li><a href="<?php echo \OC\URLGenerator::linkToRoute('dematpayslip.page.archive_list', ['archived' => 1]); ?>">Traitées</a></li> + </ul> + </li> </ul> -- GitLab