diff --git a/Class/class.gestionFiche.php b/Class/class.gestionFiche.php index 8a085ad..0d16b70 100644 --- a/Class/class.gestionFiche.php +++ b/Class/class.gestionFiche.php @@ -3,7 +3,9 @@ class Class_gestionFiche { private $pdo = null; - public $NB_LIGNES_PAGINATION = 12; + public static $NB_LIGNES_PAGINATION = 12; + public static $NB_LIGNES_FICHEAVALIDER = 15; + public function __construct(PdoGsb $pDO) { @@ -19,40 +21,41 @@ class Class_gestionFiche return $result->fetchAll(); } - public function get_ListesFiches(string $idUtilisateur): array - { - $req = 'SELECT "rMois", "rEtat", "rNbJustificatifs", ROUND("rMontantValide", 2) as "rMontantValide", "eLibelle" - FROM remboursement - INNER JOIN etat ON etat."eId"=remboursement."rEtat" - WHERE "rVisiteur"= :userId - ORDER BY "rMois" DESC'; - - $result = $this->pdo->prepare($req); - $result->bindParam("userId", $idUtilisateur); - $result->execute(); - - return $result->fetchAll(); - } - public function dateComplete(string $date): string { return substr($date, 0, 4) . '-' . substr($date, 4); } - public function get_ficheAvalider(): array + public function get_ficheAvalider(int $nPage): array { - $req = 'SELECT "rMois", "rVisiteur", "rEtat", ROUND("rMontantValide", 2) as "rMontantValide", "eLibelle", "uNom", "uPrenom" + $decalage = ($nPage - 1) * $this::$NB_LIGNES_FICHEAVALIDER; + $req = 'SELECT "rMois", "rVisiteur", "rEtat", ROUND("rMontantValide", 2) + as "rMontantValide", "eLibelle", "uNom", "uPrenom" from remboursement INNER JOIN utilisateur ON utilisateur."uId"=remboursement."rVisiteur" INNER JOIN etat ON etat."eId"=remboursement."rEtat" where "rEtat"=\'CL\' - ORDER BY "rMois" ASC'; + ORDER BY "rMois" ASC + LIMIT :nbLignes offset :decalage;'; $result = $this->pdo->prepare($req); + $result->bindParam('nbLignes', $this::$NB_LIGNES_FICHEAVALIDER); + $result->bindParam('decalage', $decalage); $result->execute(); return $result->fetchAll(); } + public function get_nbFicheAvalider(): int + { + $req = 'SELECT COUNT(*) as "nbFicheAvalider" from remboursement + where "rEtat"=\'CL\''; + $result = $this->pdo->prepare($req); + $result->execute(); + $result = $result->fetch(); + + return (int) $result['nbFicheAvalider']; + } + public function get_nbRemboursement(string $idUtilisateur): int { $req = 'SELECT COUNT(*) as "nbRemboursement" from remboursement WHERE "rVisiteur"= :userId;'; @@ -64,14 +67,21 @@ class Class_gestionFiche return (int) $result['nbRemboursement']; } - public function get_nbPage(int $decalage): array + public function get_Page(int $nPage, string $idUtilisateur): array { - $req = 'SELECT * FROM remboursement ORDER BY "rDateModif" DESC LIMIT :nbLignes offset :decalage;'; + $decalage = ($nPage - 1) * $this::$NB_LIGNES_PAGINATION; + $req = 'SELECT "rMois", "rVisiteur", "rEtat", ROUND("rMontantValide", 2) + as "rMontantValide", "eLibelle" + FROM remboursement + INNER JOIN etat ON etat."eId"=remboursement."rEtat" + WHERE "rVisiteur"= :userId + ORDER BY "rDateModif" DESC LIMIT :nbLignes offset :decalage;'; $result = $this->pdo->prepare($req); - $result->bindParam('nbLigne', $this->NB_LIGNES_PAGINATION); + $result->bindParam('nbLignes', $this::$NB_LIGNES_PAGINATION); $result->bindParam('decalage', $decalage); + $result->bindParam('userId', $idUtilisateur); $result->execute(); return $result->fetchAll(PDO::FETCH_ASSOC); } -} \ No newline at end of file +} diff --git a/controleurs/c_ficheAvalider.php b/controleurs/c_ficheAvalider.php index dfc5c3c..b110367 100644 --- a/controleurs/c_ficheAvalider.php +++ b/controleurs/c_ficheAvalider.php @@ -16,7 +16,16 @@ if ($_SESSION["typeU"] == "comptable") { $userId = $_SESSION['uId']; } -$lesFiches = $gestionFiche->get_ficheAvalider(); +//Pagination +if(isset($_GET['page']) && !empty($_GET['page'])){ + $currentPage = (int) strip_tags($_GET['page']); +}else{ + $currentPage = 1; +} + +$pages = ceil($gestionFiche->get_nbFicheAvalider() / $gestionFiche::$NB_LIGNES_FICHEAVALIDER); + +$lesFiches = $gestionFiche->get_ficheAvalider($currentPage); include("vues/v_fichesAvalider.php"); \ No newline at end of file diff --git a/controleurs/c_gestionFiche.php b/controleurs/c_gestionFiche.php index b6924d4..e7c70ef 100644 --- a/controleurs/c_gestionFiche.php +++ b/controleurs/c_gestionFiche.php @@ -23,12 +23,9 @@ if(isset($_GET['page']) && !empty($_GET['page'])){ $currentPage = 1; } -$pages = ceil($gestionFiche->get_nbRemboursement($userId) / 12); - - - -$lesFiches = $gestionFiche->get_ListesFiches($userId); +$pages = ceil($gestionFiche->get_nbRemboursement($userId) / $gestionFiche::$NB_LIGNES_PAGINATION); +$lesFiches = $gestionFiche->get_Page($currentPage, $userId); include("vues/v_gestionFiches.php"); diff --git a/vues/v_fichesAvalider.php b/vues/v_fichesAvalider.php index 97afab7..69ba3d9 100644 --- a/vues/v_fichesAvalider.php +++ b/vues/v_fichesAvalider.php @@ -1,3 +1,7 @@ +