diff --git a/js/script.js b/js/script.js index 4a3141ff61384f9febc7b798f9cefbf34d20f5d2..caa4702c07b48c8db4d3db4a1c8ecd536e82bbea 100644 --- a/js/script.js +++ b/js/script.js @@ -52,10 +52,10 @@ jQuery(document).ready(function(){ }); jQuery(document).ready(function(){ - let paramArchived = parseInt(jQuery('#param_archived').val()); + let paramStepStatus = parseInt(jQuery('#param_step_status').val()); let buttons = []; - if (paramArchived === -1 || paramArchived === 0) { + if (paramStepStatus === 0) { buttons.push({ 'id': 'btn_create', 'text': 'Archiver', @@ -81,7 +81,17 @@ jQuery(document).ready(function(){ } }); } - if (paramArchived === -1 || paramArchived === 1) { + if (paramStepStatus === 1) { + buttons.push({ + 'id': 'btn_run_again', + 'text': 'Reprendre l\'archivage', + 'action': function() { + jQuery('#demmatpayslip_archive_action').val('run_again'); + jQuery('#demmatpayslip_archive_action_form').submit(); + } + }); + } + if (paramStepStatus === 1 || paramStepStatus === 2) { buttons.push({ 'id': 'btn_refresh_status', 'text': 'Actualiser les états', diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 549d42c57eccc145a57e3e41d2ef279638ea7cf3..af93bda499343d292a72a2d0dcdbcec82199fcbe 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -172,8 +172,8 @@ class PageController extends Controller { if (empty($dematpayslipArchiveExistList)) { $dematpayslipArchive = new DematpayslipArchive(); } elseif (count($dematpayslipArchiveExistList) === 1) { - if ($dematpayslipArchiveExistList[0]->isArchived()===true) { - $warningMsg = $this->l->t('Le bulletin de paie de l\'agent "' . $agentUser->getLastname() . ' ' . $agentUser->getFirstname() . '" pour la période du ' . $startDate . ' au ' . $endDate . ' est déjà archivée.'); + if (!empty($dematpayslipArchiveExistList[0]->getPastellIdDocument())) { + $warningMsg = $this->l->t('Le bulletin de paie de l\'agent "' . $agentUser->getLastname() . ' ' . $agentUser->getFirstname() . '" pour la période du ' . $startDate . ' au ' . $endDate . ' est déjà en cours d\'archivage.'); $this->_logCsvLine($warningMsg, self::LOG_WARNING, $agentUser, $startDate, $endDate); $this->_processWarningMsg($warningMsg); } else { @@ -214,45 +214,48 @@ class PageController extends Controller { // Pastell API connection $pastellAPI = new PastellAPI($pastellConfigFlow->getIdConfig()); - $canCreateArchive = false; + $canModifyArchive = false; if ($dematpayslipArchive->isArchived() === false) { - $canCreateArchive = true; + $canModifyArchive = true; } else { // get and modify document last action $responseData = $pastellAPI->getEntityDocument($pastellConfigFlow->getIdE(), $dematpayslipArchive->getPastellIdDocument()); - if (!empty($responseData['last_action']['action'])) { - $dematpayslipArchive->setPastellLastAction($responseData['last_action']['action']); + + $archiveLastAction = $responseData['last_action']['action']; + if (!empty($archiveLastAction)) { + $dematpayslipArchive->setPastellLastAction($archiveLastAction); $dematpayslipArchiveMapper->update($dematpayslipArchive); } } - if ($canCreateArchive === false) { + if ($canModifyArchive === false) { $this->_msgList['error'][] = $this->l->t('L\'archive "' . $dematpayslipArchive->getFilePath() . '" a déjà été créée.'); } else { - // create document - $nowDateTime = new \DateTime('now', \OC::$server->getDateTimeZone()->getTimeZone()); - $responseData = $pastellAPI->postEntityDocument($pastellConfigFlow->getIdE(), array( - 'type' => 'pdf-generique' - )); - $dematpayslipArchive->setPastellIdDocument($responseData['id_d']); - $dematpayslipArchive->setPastellLastAction($responseData['last_action']['action']); - $dematpayslipArchive->setStatus(DematpayslipArchive::STATUS_CREATED); - $dematpayslipArchive->setStatusTime($nowDateTime->getTimestamp()); - $dematpayslipArchiveMapper->update($dematpayslipArchive); - - if ($dematpayslipArchive->getPastellLastAction() == 'creation') { - // set document title + // 1. create document + if (empty($dematpayslipArchive->getPastellIdDocument())) { + $nowDateTime = new \DateTime('now', \OC::$server->getDateTimeZone()->getTimeZone()); + $responseData = $pastellAPI->postEntityDocument($pastellConfigFlow->getIdE(), array( + 'type' => 'pdf-generique' + )); + $dematpayslipArchive->setPastellIdDocument($responseData['id_d']); + $dematpayslipArchive->setPastellLastAction($responseData['last_action']['action']); + $dematpayslipArchive->setStatus(DematpayslipArchive::STATUS_CREATED); + $dematpayslipArchive->setStatusTime($nowDateTime->getTimestamp()); + $dematpayslipArchiveMapper->update($dematpayslipArchive); + } + // 2. set document title + if ($dematpayslipArchive->getStatus() == DematpayslipArchive::STATUS_CREATED) { $nowDateTime = new \DateTime('now', \OC::$server->getDateTimeZone()->getTimeZone()); $responseData = $pastellAPI->patchEntityDocument($pastellConfigFlow->getIdE(), $dematpayslipArchive->getPastellIdDocument(), array( - 'libelle' => $dematpayslipArchive->getId() . '_' . $dematpayslipArchive->getStartDate() . '_' . $dematpayslipArchive->getEndDate() + 'libelle' => $dematpayslipArchive->getId() . '_' . $dematpayslipArchive->getSiret() . '_' . $dematpayslipArchive->getMatricule() . '_' . $dematpayslipArchive->getStartDate() . '_' . $dematpayslipArchive->getEndDate() )); $dematpayslipArchive->setPastellLastAction($responseData['content']['last_action']['action']); $dematpayslipArchive->setStatus(DematpayslipArchive::STATUS_TITLED); $dematpayslipArchive->setStatusTime($nowDateTime->getTimestamp()); $dematpayslipArchiveMapper->update($dematpayslipArchive); } - if ($dematpayslipArchive->getPastellLastAction() == 'modification') { - // send document file + // 3. send document file + if ($dematpayslipArchive->getStatus() == DematpayslipArchive::STATUS_TITLED) { $nowDateTime = new \DateTime('now', \OC::$server->getDateTimeZone()->getTimeZone()); $fileId = $dematpayslipArchive->getIdFile(); $filePath = Filesystem::getPath($fileId); @@ -264,30 +267,27 @@ class PageController extends Controller { $dematpayslipArchive->setStatus(DematpayslipArchive::STATUS_FILE_SENT); $dematpayslipArchive->setStatusTime($nowDateTime->getTimestamp()); $dematpayslipArchiveMapper->update($dematpayslipArchive); - - // set orientation action on document + } + // 4. send to SAE + if ($dematpayslipArchive->getStatus() == DematpayslipArchive::STATUS_FILE_SENT) { $nowDateTime = new \DateTime('now', \OC::$server->getDateTimeZone()->getTimeZone()); - $responseData = $pastellAPI->postEntityDocumentAction($pastellConfigFlow->getIdE(), $dematpayslipArchive->getPastellIdDocument(), 'orientation'); - if ($responseData['result'] == true) { - // get and modify document last action - $responseData = $pastellAPI->getEntityDocument($pastellConfigFlow->getIdE(), $dematpayslipArchive->getPastellIdDocument()); - if (!empty($responseData['last_action']['action'])) { - $dematpayslipArchive->setPastellLastAction($responseData['last_action']['action']); - $dematpayslipArchive->setStatus(DematpayslipArchive::STATUS_ORIENTATION); - $dematpayslipArchive->setStatusTime($nowDateTime->getTimestamp()); - $dematpayslipArchiveMapper->update($dematpayslipArchive); - } - } + $responseData = $pastellAPI->patchEntityDocument($pastellConfigFlow->getIdE(), $dematpayslipArchive->getPastellIdDocument(), array( + 'envoi_sae' => true + )); + $dematpayslipArchive->setPastellLastAction($responseData['content']['last_action']['action']); + $dematpayslipArchive->setStatus(DematpayslipArchive::STATUS_SAE_SENT); + $dematpayslipArchive->setStatusTime($nowDateTime->getTimestamp()); + $dematpayslipArchiveMapper->update($dematpayslipArchive); } - if ($dematpayslipArchive->getPastellLastAction() == 'preparation-suppression-automatique') { - // create "sae_config" JSON file and send it + // 5. create JSON file and add meta-data on document + if ($dematpayslipArchive->getStatus() == DematpayslipArchive::STATUS_SAE_SENT) { $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(), ); @@ -295,19 +295,35 @@ class PageController extends Controller { $jsonFilePath = $this->_tmpDirUserPath . DIRECTORY_SEPARATOR . $jsonFileName; Filesystem::fopen($jsonFilePath, 'w+'); Filesystem::file_put_contents($jsonFilePath, json_encode($saeConfigArr)); - - // add meta-data on document $nowDateTime = new \DateTime('now', \OC::$server->getDateTimeZone()->getTimeZone()); $jsonFileContent = Filesystem::file_get_contents($jsonFilePath); - $responseData = $pastellAPI->postEntityDocumentFile($pastellConfigFlow->getIdE(), $dematpayslipArchive->getPastellIdDocument(), 'sae_config', 0, $jsonFileName, $jsonFileContent); + $responseData = $pastellAPI->postEntityDocumentExternalData($pastellConfigFlow->getIdE(), $dematpayslipArchive->getPastellIdDocument(), 'sae_config', array( + 'file_name' => $jsonFileName, + 'file_content' => $jsonFileContent + )); $dematpayslipArchive->setPastellLastAction($responseData['content']['last_action']['action']); $dematpayslipArchive->setStatus(DematpayslipArchive::STATUS_METADATA_SENT); $dematpayslipArchive->setStatusTime($nowDateTime->getTimestamp()); $dematpayslipArchiveMapper->update($dematpayslipArchive); } + // 6. set orientation action on document + if ($dematpayslipArchive->getStatus() == DematpayslipArchive::STATUS_METADATA_SENT) { + $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()); + if ($responseData['result'] == true) { + // get and modify document last action + $responseData = $pastellAPI->getEntityDocument($pastellConfigFlow->getIdE(), $dematpayslipArchive->getPastellIdDocument()); + if (!empty($responseData['last_action']['action'])) { + $dematpayslipArchive->setPastellLastAction($responseData['last_action']['action']); + } + } + $dematpayslipArchiveMapper->update($dematpayslipArchive); + } - if ($dematpayslipArchive->getStatus() < DematpayslipArchive::STATUS_METADATA_SENT) { - $this->_msgList['error'][] = $this->l->t('L\'archive "' . $dematpayslipArchive->getFilePath() . '" n\'a pas été correctement archivée [status=' . $dematpayslipArchive->getStatus() .'].'); + if ($dematpayslipArchive->getStatus() < DematpayslipArchive::STATUS_ORIENTATION) { + $this->_msgList['error'][] = $this->l->t('L\'archive "' . $dematpayslipArchive->getFilePath() . '" n\'a pas été correctement créée [status=' . $dematpayslipArchive->getStatus() .'].'); } else { $this->_msgList['success'][] = $this->l->t('L\'archive "' . $dematpayslipArchive->getFilePath() . '" a été créée.'); } @@ -396,20 +412,24 @@ class PageController extends Controller { /** * Assign params for archive list * - * @param int $archived [=-1] for all, 0 for not archived and 1 for archived - * @param int $refresh [=false] not to refresh list form API, else true + * @param int $stepStatus [=-1] for all (not deleted), 0 for step init, 1 for step in progress and 2 for step archived + * @param bool $refresh [=false] not to refresh list form API, else true * @return array Params for template */ - private function _assignArchiveList($archived = -1, $refresh = false) { + private function _assignArchiveList($stepStatus = -1, $refresh = false) { $paramList = array( - 'archived' => $archived + 'step_status' => $stepStatus ); // get archive list $dematpayslipArchiveMapper = new DematpayslipArchiveMapper(\OC::$server->getDatabaseConnection()); if ($refresh === true) { - $dematpayslipArchiveList = $dematpayslipArchiveMapper->findAllArchived($archived); + if ($stepStatus === -1) { + $dematpayslipArchiveList = $dematpayslipArchiveMapper->findAll(0); + } else { + $dematpayslipArchiveList = $dematpayslipArchiveMapper->findAllByStepStatus($stepStatus); + } if (!empty($dematpayslipArchiveList)) { foreach ($dematpayslipArchiveList as $dematpayslipArchive) { @@ -453,7 +473,12 @@ class PageController extends Controller { } } - $dematpayslipArchiveList = $dematpayslipArchiveMapper->findAllArchived($archived); + + if ($stepStatus === -1) { + $dematpayslipArchiveList = $dematpayslipArchiveMapper->findAll(0); + } else { + $dematpayslipArchiveList = $dematpayslipArchiveMapper->findAllByStepStatus($stepStatus); + } return array( 'dematpayslipArchiveList' => $dematpayslipArchiveList, @@ -2437,12 +2462,14 @@ class PageController extends Controller { if ($this->userId === $this->_dematpayslipConfigList['user_id']) { $this->_initDematFolders(); - $archived = filter_input(INPUT_GET, 'archived', FILTER_SANITIZE_NUMBER_INT); - if ($archived === null) { - $archived = -1; + $stepStatus = filter_input(INPUT_GET, 'step_status', FILTER_SANITIZE_NUMBER_INT); + if ($stepStatus === null) { + $stepStatus = -1; + } else { + $stepStatus = intval($stepStatus); } - return new TemplateResponse('dematpayslip', 'archive_list', $this->_assignArchiveList($archived)); + return new TemplateResponse('dematpayslip', 'archive_list', $this->_assignArchiveList($stepStatus)); } else { return $this->shares(); } @@ -2462,11 +2489,11 @@ class PageController extends Controller { if ($this->userId === $this->_dematpayslipConfigList['user_id']) { $this->_initDematFolders(); - $archived = filter_input(INPUT_POST, 'archived', FILTER_SANITIZE_NUMBER_INT); - if ($archived === null) { - $archived = -1; + $stepStatus = filter_input(INPUT_POST, 'step_status', FILTER_SANITIZE_NUMBER_INT); + if ($stepStatus === null) { + $stepStatus = -1; } else { - $archived = intval($archived); + $stepStatus = intval($stepStatus); } $refresh = false; @@ -2489,14 +2516,26 @@ class PageController extends Controller { } } elseif ($action == 'create_all') { $dematpayslipArchiveMapper = new DematpayslipArchiveMapper(\OC::$server->getDatabaseConnection()); - $dematpayslipArchiveList = $dematpayslipArchiveMapper->findAllArchived(0); + $dematpayslipArchiveList = $dematpayslipArchiveMapper->findAllByStepStatus(DematpayslipArchive::STEP_STATUS_INIT); foreach ($dematpayslipArchiveList as $dematpayslipArchive) { if (!empty($dematpayslipArchive)) { $this->_archiveProcess($dematpayslipArchiveMapper, $dematpayslipArchive); } } - } elseif ($action == 'delete') { + } elseif ($action == 'run_again') { + $dematpayslipArchiveMapper = new DematpayslipArchiveMapper(\OC::$server->getDatabaseConnection()); + + if (!empty($archiveSelectIdList)) { + foreach ($archiveSelectIdList as $archiveSelectId) { + $dematpayslipArchive = $dematpayslipArchiveMapper->find(intval($archiveSelectId)); + if (!empty($dematpayslipArchive)) { + $this->_archiveProcess($dematpayslipArchiveMapper, $dematpayslipArchive); + } + } + } + } + elseif ($action == 'delete') { $nowDateTime = new \DateTime('now', \OC::$server->getDateTimeZone()->getTimeZone()); $dematpayslipArchiveMapper = new DematpayslipArchiveMapper(\OC::$server->getDatabaseConnection()); @@ -2504,19 +2543,21 @@ class PageController extends Controller { foreach ($archiveSelectIdList as $archiveSelectId) { $dematpayslipArchive = $dematpayslipArchiveMapper->find(intval($archiveSelectId)); if (!empty($dematpayslipArchive)) { - if ($dematpayslipArchive->isArchived() === true) { - $this->_msgList['error'][] = $this->l->t('Impossible de supprimer le bulletin de paie "' . $dematpayslipArchive->getFilePath() . '" déjà archivé.');; + if (!empty($dematpayslipArchive->getPastellIdDocument())) { + $this->_msgList['error'][] = $this->l->t('Impossible de supprimer le bulletin de paie "' . $dematpayslipArchive->getFilePath() . '" déjà en cours d\'archivage.');; } else { $dematpayslipArchive->setStatus(DematpayslipArchive::STATUS_DELETED); $dematpayslipArchive->setStatusTime($nowDateTime->getTimestamp()); $dematpayslipArchiveMapper->update($dematpayslipArchive); } } + + if (count($this->_msgList['error']) > 0) break; } } } - return new TemplateResponse('dematpayslip', 'archive_list', $this->_assignArchiveList($archived, $refresh)); + return new TemplateResponse('dematpayslip', 'archive_list', $this->_assignArchiveList($stepStatus, $refresh)); } else { return $this->shares(); } @@ -2536,8 +2577,19 @@ class PageController extends Controller { if ($this->userId === $this->_dematpayslipConfigList['user_id']) { $this->_initDematFolders(); + $stepStatus = filter_input(INPUT_GET, 'step_status', FILTER_SANITIZE_NUMBER_INT); + if ($stepStatus === null) { + $stepStatus = -1; + } else { + $stepStatus = intval($stepStatus); + } + $dematpayslipArchiveMapper = new DematpayslipArchiveMapper(\OC::$server->getDatabaseConnection()); - $dematpayslipArchiveList = $dematpayslipArchiveMapper->findAllArchived(-1); + if ($stepStatus === -1) { + $dematpayslipArchiveList = $dematpayslipArchiveMapper->findAll(0); + } else { + $dematpayslipArchiveList = $dematpayslipArchiveMapper->findAllByStepStatus($stepStatus); + } if (!empty($dematpayslipArchiveList)) { $dateTimeNow = new \DateTime('now', \OC::$server->getDateTimeZone()->getTimeZone()); @@ -2608,7 +2660,7 @@ class PageController extends Controller { } } - return new TemplateResponse('dematpayslip', 'archive_list', $this->_assignArchiveList()); + return new TemplateResponse('dematpayslip', 'archive_list', $this->_assignArchiveList($stepStatus)); } else { return $this->shares(); } diff --git a/lib/Db/DematpayslipArchive.php b/lib/Db/DematpayslipArchive.php index a939e259097d5e8d4b60d574432ae47026411776..d023653c6303280dd458e8c69293e1c343e60a66 100644 --- a/lib/Db/DematpayslipArchive.php +++ b/lib/Db/DematpayslipArchive.php @@ -15,8 +15,16 @@ class DematpayslipArchive extends Entity implements JsonSerializable { const STATUS_CREATED = 1; const STATUS_TITLED = 2; const STATUS_FILE_SENT = 3; - const STATUS_ORIENTATION = 4; + const STATUS_SAE_SENT = 4; const STATUS_METADATA_SENT = 5; + const STATUS_ORIENTATION = 6; + + /** + * Const step status + */ + const STEP_STATUS_INIT = 0; + const STEP_STATUS_PROGRESS = 1; + const STEP_STATUS_ARCHIVED = 2; protected $idFile; protected $idUser; @@ -65,16 +73,82 @@ class DematpayslipArchive extends Entity implements JsonSerializable { ]; } + /** + * Get status list + * + * @param int $stepStatus Step status + * @return array Status list + */ + public static function getStepStatusListFrom($stepStatus) { + $stepStatusList = []; + + if ($stepStatus == self::STEP_STATUS_INIT) { + $stepStatusList[] = self::STATUS_INITIALIZED; + } else if ($stepStatus == self::STEP_STATUS_PROGRESS) { + $stepStatusList[] = self::STATUS_CREATED; + $stepStatusList[] = self::STATUS_TITLED; + $stepStatusList[] = self::STATUS_FILE_SENT; + $stepStatusList[] = self::STATUS_SAE_SENT; + $stepStatusList[] = self::STATUS_METADATA_SENT; + } else if ($stepStatus == self::STEP_STATUS_ARCHIVED) { + $stepStatusList[] = self::STATUS_ORIENTATION; + } + + return $stepStatusList; + } + + /** + * Show status label + * + * @return string Status label + */ + public function showStatusLabel() { + $pastellLastAction = $this->getPastellLastAction(); + + $statusLabelList = array( + self::STATUS_DELETED => 'Supprimé', + self::STATUS_INITIALIZED => 'Aucun', + self::STATUS_CREATED => 'Créé', + self::STATUS_TITLED => 'Titre ajouté', + self::STATUS_FILE_SENT => 'Fichier envoyé', + self::STATUS_SAE_SENT => 'Envoyé au SAE', + self::STATUS_METADATA_SENT => 'Méta-données transmises', + self::STATUS_ORIENTATION => 'Orienté', + ); + + $statusLabel = $statusLabelList[$this->getStatus()]; + if (!empty($pastellLastAction)) { + $statusLabel .= ' '; + if ($pastellLastAction == 'ar-recu-sae') { + $statusLabel .= '<span style="color: #777000;">'; + } else if ($pastellLastAction == 'accepter-sae') { + $statusLabel .= '<span style="color: #007700;">'; + } else if ($pastellLastAction == 'rejet-sae') { + $statusLabel .= '<span style="color: #770000;">'; + } else { + $statusLabel .= '<span>'; + } + $statusLabel .= '[' . $pastellLastAction . ']'; + $statusLabel .= '</span>'; + } + + return $statusLabel; + } + /** * Determine if it have already been archived (can't modify) * * @return bool */ public function isArchived() { + $isArchived = false; + if (!empty($this->getPastellIdDocument())) { - return true; - } else { - return false; + if (in_array($this->getStatus(), self::getStepStatusListFrom(self::STEP_STATUS_ARCHIVED))) { + $isArchived = true; + } } + + return $isArchived; } } diff --git a/lib/Db/DematpayslipArchiveMapper.php b/lib/Db/DematpayslipArchiveMapper.php index efe3c3f81183b37548b056e1d98c283d78e85f6f..d25b2d0efa7b4e7949b86a82a9900c4090b04d6a 100644 --- a/lib/Db/DematpayslipArchiveMapper.php +++ b/lib/Db/DematpayslipArchiveMapper.php @@ -4,6 +4,8 @@ namespace OCA\Dematpayslip\Db; use OCP\IDbConnection; use OCP\AppFramework\Db\QBMapper; +use OCP\DB\QueryBuilder\IQueryBuilder; + class DematpayslipArchiveMapper extends QBMapper { public function __construct(IDbConnection $db) { @@ -76,34 +78,53 @@ class DematpayslipArchiveMapper extends QBMapper { return $this->findEntities($qb); } - public function findAllArchived(int $archived) { + public function findAllNotDeleted() { $qb = $this->db->getQueryBuilder(); $qb->select('*'); $qb->from($this->getTableName()); - $qb->where( - $qb->expr()->gte('status', $qb->createNamedParameter(DematpayslipArchive::STATUS_INITIALIZED)) - ); - if ($archived == 1) { - $qb->andWhere( - $qb->expr()->isNotNull('pastell_id_document') + if (!empty($statusList)) { + $qb->where( + $qb->expr()->notIn('status', $qb->createNamedParameter([DematpayslipArchive::STATUS_DELETED], IQueryBuilder::PARAM_STR_ARRAY)) ); - } elseif ($archived == 0) { - $qb->andWhere( - $qb->expr()->isNull('pastell_id_document') + } + + return $this->findEntities($qb); + } + + public function findAllByStepStatus(int $stepStatus) { + $qb = $this->db->getQueryBuilder(); + + $qb->select('*'); + $qb->from($this->getTableName()); + + $statusList = DematpayslipArchive::getStepStatusListFrom($stepStatus); + if (!empty($statusList)) { + $qb->where( + $qb->expr()->in('status', $qb->createNamedParameter($statusList, IQueryBuilder::PARAM_STR_ARRAY)) ); } return $this->findEntities($qb); } - public function findAll() { + public function findAll($deleted = 0) { $qb = $this->db->getQueryBuilder(); $qb->select('*') ->from($this->getTableName()); + if ($deleted == 0) { + $qb->where( + $qb->expr()->notIn('status', $qb->createNamedParameter([DematpayslipArchive::STATUS_DELETED], IQueryBuilder::PARAM_STR_ARRAY)) + ); + } else if ($deleted > 0) { + $qb->where( + $qb->expr()->in('status', $qb->createNamedParameter([DematpayslipArchive::STATUS_DELETED], IQueryBuilder::PARAM_STR_ARRAY)) + ); + } + return $this->findEntities($qb); } } diff --git a/templates/content/archive_list.php b/templates/content/archive_list.php index b38bce75df3b3d900f16fcef338a53a9dd3c1446..6faad17f9860280ded98eb7a144c9038b8eb76b5 100644 --- a/templates/content/archive_list.php +++ b/templates/content/archive_list.php @@ -47,7 +47,7 @@ <?php if (!empty($htmlAlert)) { ?> <div id="dematpayslip_alert"><?php print $htmlAlert; ?></div> <?php } ?> - <h2><?php p($l->t('Liste des archives')); ?> <a href="<?php echo \OC\URLGenerator::linkToRoute('dematpayslip.page.archive_csv'); ?>" class="button" title="<?php p($l->t('Export CSV')); ?>"><?php p($l->t('CSV')); ?></a></h2> + <h2><?php p($l->t('Liste des archives')); ?> <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> <br /> <div> @@ -74,7 +74,7 @@ <th scope="col"><?php p($l->t('Fin')); ?></th> <th scope="col"><?php p($l->t('Edition')); ?></th> <th scope="col"><?php p($l->t('Archive')); ?></th> - <th scope="col"><?php p($l->t('Dernière action')); ?></th> + <th scope="col"><?php p($l->t('Etat')); ?></th> </tr> </thead> <?php if (!empty($dematpayslipArchiveList)) { ?> @@ -91,7 +91,7 @@ <td><?php print $dematpayslipArchive->getEndDate(); ?></td> <td><?php print $dematpayslipArchive->getEditionDate(); ?></td> <td><?php if (!empty($dematpayslipArchive->getPastellUrl())) { print $dematpayslipArchive->getPastellUrl(); } else { print $dematpayslipArchive->getPastellIdDocument(); } ?></td> - <td><?php print $dematpayslipArchive->getPastellLastAction(); ?></td> + <td><?php print $dematpayslipArchive->showStatusLabel(); ?></td> </tr> <?php } ?> </tbody> diff --git a/templates/navigation/index.php b/templates/navigation/index.php index cd408ae9bfefe56882735bebd324a8713fafb590..abb2bcd881d88d81ad21e51cc28ea42d8bf5ff07 100644 --- a/templates/navigation/index.php +++ b/templates/navigation/index.php @@ -1,11 +1,12 @@ <ul> <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><a href="<?php echo \OC\URLGenerator::linkToRoute('dematpayslip.page.archive_list'); ?>">Liste des bulletins</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> + <li><a href="<?php echo \OC\URLGenerator::linkToRoute('dematpayslip.page.archive_list', ['step_status' => \OCA\Dematpayslip\Db\DematpayslipArchive::STEP_STATUS_INIT]); ?>">A archiver</a></li> + <li><a href="<?php echo \OC\URLGenerator::linkToRoute('dematpayslip.page.archive_list', ['step_status' => \OCA\Dematpayslip\Db\DematpayslipArchive::STEP_STATUS_PROGRESS]); ?>">En cours</a></li> + <li><a href="<?php echo \OC\URLGenerator::linkToRoute('dematpayslip.page.archive_list', ['step_status' => \OCA\Dematpayslip\Db\DematpayslipArchive::STEP_STATUS_ARCHIVED]); ?>">Archivés</a></li> </ul> </li> </ul>