6 Commits

11 changed files with 436 additions and 174 deletions

View File

@ -0,0 +1,26 @@
<?php
class Class_gestionFiche
{
private $pdo = null;
public function __construct(PdoGsb $pDO)
{
$this->pdo = $pDO->getPdoGsb();
}
public function getLesUtilisateurs(): array
{
$req = 'SELECT "uId", "uNom", "uPrenom" FROM utilisateur WHERE "uStatut"!=0 ORDER BY "uNom" ASC;';
$result = $this->pdo->prepare($req);
$result ->execute();
return $result->fetchAll();
}
public function utilisateur(string $idUtilisateur): array
{
$req = '';
}
}

View File

@ -12,30 +12,60 @@ class Class_newFiche
public function listFraisForfaitaires(): array public function listFraisForfaitaires(): array
{ {
$req = 'SELECT "fLibelle", round("fMontant", 2) AS "fMontant", "fId" FROM forfait'; $req = 'SELECT "fLibelle", NULL AS "lfQuantite", round("fMontant", 2) AS "fMontant", 0 AS "fTotal", "fId" FROM forfait';
$result = $this->pdo->prepare($req); $result = $this->pdo->prepare($req);
$result->execute(); $result->execute();
return $result->fetchAll(); return $result->fetchAll();
} }
public function listFraisHF():array public function listFraisForfaitForU(string $idUser, int $month): array
{ {
// $req = 'SELECT "fLibelle", "lfQuantite", ROUND("fMontant", 2) AS "fMontant", ROUND("lfQuantite" * "fMontant", 2) AS "fTotal", "fId"
FROM remboursement
INNER JOIN "ligne_forfait" ON "rVisiteur" = "lfVisiteur" AND "rMois" = "lfMois"
INNER JOIN "forfait" ON "fId" = "lfForfait"
WHERE "rVisiteur" = :idUser AND "rMois" = :monthF;';
$result = $this->pdo->prepare($req);
$result->bindParam('idUser', $idUser);
$result->bindParam('monthF', $month);
$result->execute();
return $result->fetchAll();
} }
public function endInter(string $id) public function listFraisHF(string $idVisiteur, int $month): array
{ {
$req = "UPDATE intervention $req = 'SELECT to_char("lhDate", \'YYYY-mm-dd\') AS "lhDate",
SET iHeureFin = NOW() "lhLibelle", ROUND("lhMontant",2) as "lhMontant",
WHERE iCis = :cis AND iId = :idInter AND iHeureFin IS NULL"; "lhJustificatif", "lhRefus"
FROM remboursement
inner join "ligne_hors_forfait" on "rVisiteur" = "lhVisiteur"
AND "rMois" = "lhMois"
WHERE "rVisiteur" = :idVisiteur AND "rMois" = :mois
ORDER BY "lhDate";';
$cis = explode('-', $id)[0]; $result = $this->pdo->prepare($req);
$idInter = explode('-', $id)[1]; $result->bindParam(':idVisiteur', $idVisiteur);
$result->bindParam(':mois', $month);
$result = PdoBD::$monPdo->prepare($req);
$result->bindParam(':cis', $cis);
$result->bindParam(':idInter', $idInter);
$result->execute(); $result->execute();
return $result->fetchAll();
}
public function getMontantValide(string $idVisiteur, int $month): float
{
$req = 'SELECT "rMontantValide"
FROM remboursement
WHERE "rVisiteur" = :idVisiteur AND "rMois" = :mois ;';
$result = $this->pdo->prepare($req);
$result->bindParam(':idVisiteur', $idVisiteur);
$result->bindParam(':mois', $month);
$result->execute();
return $result->fetchAll()[0]['rMontantValide'];
} }
} }

View File

@ -1,15 +1,9 @@
<?php <?php
session_start(); $_SESSION ["typeU"] = "comptable";
$_SESSION['typeU'] = 'comptable';
require_once(__DIR__ . '/../Class/class.gestionFiche.php');
$gestionFiche = new Class_gestionFiche($pdo);
include("../vues/v_gestionFiches.php"); $LesUtilisateurs = $gestionFiche->getLesUtilisateurs(); //RENVOIE LISTE USERS
include("vues/v_gestionFiches.php");
?>

View File

@ -2,6 +2,59 @@
require_once(__DIR__ . '/../Class/class.newFiche.php'); require_once(__DIR__ . '/../Class/class.newFiche.php');
$newFiche = new Class_newFiche($pdo); $newFiche = new Class_newFiche($pdo);
$typesFraisForfaitaires = $newFiche->listFraisForfaitaires();
$_SESSION['userId'] = 'b34';
$_SESSION['typeU'] = 'visiteur';
$date = '202011';
/**
* Gestion de la date selon la vue à afficher
*/
if (isset($_GET['currentList'])) {
//Date des req SQL et function
$date = date('Ym');
//Date du header
try {
//sudo timedatectl set-local-rtc 1
$format = new IntlDateFormatter(
'fr_FR',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'Europe/Paris',
IntlDateFormatter::GREGORIAN,
'MMMM Y'
);
$dateHeader = $format->format(time());
} catch (\Throwable $th) {
$dateHeader = date('F Y');
}
//Date du formulaire HF
$dateFormHFMin = date('Y-m-\01');
$dateFormHFMax = date("Y-m-t", mktime(0, 0, 0, date('m'), 1, date('Y'))); // retourne le dernier jour du mois (30 ou 31)
} elseif (isset($_GET['dateListing'])) {
$date = $_GET['dateListing'];
}
/**
* Liste des frais forfaitaires du mois et de l'user :: sinon afficher les libelle
*/
$listeFraisForfaitaire = $newFiche->listFraisForfaitForU($_SESSION['userId'], $date);
if (count($listeFraisForfaitaire) == 0) {
$listeFraisForfaitaire = $newFiche->listFraisForfaitaires();
}
/**
* Listes des frais HF
*/
$listeFraisHf = $newFiche->listFraisHF($_SESSION['userId'], $date);
/**
* TOTAL DE LA FICHE
*/
$totalFraisFiche = $newFiche->getMontantValide($_SESSION['userId'], $date);
include(__DIR__ . '/../vues/v_newFiche.php'); include(__DIR__ . '/../vues/v_newFiche.php');

View File

@ -1,10 +1,12 @@
stocker le nom d'utilisateur et le mot de passe dans la classe n'est pas une très bonne idée pour le code mis en production ... Une bonne solution consiste a stocker les paramètres de connexion à la base de données dans un fichier .ini et à en restreindre l'accès. Par exemple de cette façon: stocker le nom d'utilisateur et le mot de passe dans la classe n'est pas une très bonne idée pour le code mis en
production ... Une bonne solution consiste a stocker les paramètres de connexion à la base de données dans un fichier
.ini et à en restreindre l'accès. Par exemple de cette façon:
private static $serveur='mysql:host=localhost'; private static $serveur='mysql:host=localhost';
private static $bdd='dbname=gsb2021'; private static $bdd='dbname=gsb2021';
private static $user='root' ; private static $user='root' ;
private static $mdp='root' ; private static $mdp='root' ;
gsb.ini: gsb.ini:
[database] [database]
driver = mysql driver = mysql
@ -12,22 +14,23 @@ host = localhost
port = 3306 port = 3306
schema = gsb2021 schema = gsb2021
username = root username = root
password = root password = root
Database connection: Database connection:
<?php <?php
class MyPDO extends PDO class MyPDO extends PDO
{ {
public function __construct($file = 'gsb.ini') public function __construct($file = 'gsb.ini')
{ {
if (!$settings = parse_ini_file($file, TRUE)) throw new exception('acces impossible ' . $file . '.'); if (!$settings = parse_ini_file($file, TRUE))
throw new exception('acces impossible ' . $file . '.');
$dns = $settings['database']['driver'] . $dns = $settings['database']['driver'] .
':host=' . $settings['database']['host'] . ':host=' . $settings['database']['host'] .
((!empty($settings['database']['port'])) ? (';port=' . $settings['database']['port']) : '') . ((!empty($settings['database']['port'])) ? (';port=' . $settings['database']['port']) : '') .
';dbname=' . $settings['database']['schema']; ';dbname=' . $settings['database']['schema'];
parent::__construct($dns, $settings['database']['username'], $settings['database']['password']); parent::__construct($dns, $settings['database']['username'], $settings['database']['password']);
} }
} }

View File

@ -25,7 +25,7 @@
</a> </a>
</li> </li>
<li> <li>
<a href="index.php?direction=nouvelleFiche" class="nav-link px-0"> <span class="d-none d-sm-inline">Nouvelle Fiche</span> <a href="index.php?direction=nouvelleFiche&currentList" class="nav-link px-0"> <span class="d-none d-sm-inline">Fiche du mois</span>
</a> </a>
</li> </li>
</ul> </ul>

139
include/newFiche.js Normal file
View File

@ -0,0 +1,139 @@
$(document).ready(function () {
calcPrixTotalFrsF();
calcPrixTotalFrsHorsF();
updatePrixTotal();
/**
* Partie enregistrement frais F
*/
$('.frsFrt').on('change', function (e) {
console.log($(this).val())
val = $(this).val();
val = val.replace(',', '.')
if ($.isNumeric(val)) {
/**
* Calcul le prix de la ligne
*/
id = $(this).attr('id')
formTotal = $('#totalFrs-' + id)
mttFrs = $('#mttFrs-' + id).attr('data-price')
formTotal.html((val * mttFrs).toFixed(2) + ' €');
calcPrixTotalFrsF();
updatePrixTotal();
}
})
/**
* Enregistrement frais HF
*/
$('.validFraisHF').on('click', function () {
let date = $('#dateHf')
let libelle = $('#libelleHf')
let montant = $('#mttHf')
let canAdd = true;
if (date.val() == "") {
canAdd = false;
date.css("border-color", "red")
} else {
date.css("border-color", "var(--bs-border-color)")
}
if (libelle.val() == "") {
canAdd = false;
libelle.css("border-color", "red")
} else {
libelle.css("border-color", "var(--bs-border-color)")
}
if (montant.val() == "") {
canAdd = false;
montant.css("border-color", "red")
} else {
montant.css("border-color", "var(--bs-border-color)")
}
if (canAdd == true) {
var line = $('tr.fraisHF:first').clone();
lastId = $('tr.fraisHF').length
line.find('.btn').attr('id', 'frsSup-' + lastId)
var line = $('<tr id="fraisHf-' + lastId + '" class="fraisHF"></tr>');
var tdDate = $('<th scope="row" id="dateFrsHF"></th>');
tdDate.html(date.val());
var tdLibelle = $('<td id="LibelleFrsHF"></td>');
tdLibelle.html(libelle.val());
var tdMtt = $('<td id="MttFrsHF"></td>');
tdMtt.html(parseFloat(montant.val().replace(',', '.')).toFixed(2) + ' €');
var tdJust = $('<td></td>');
var btn = $('<td><button type="button" class="btn btn-outline-primary btnSuprFraisHf" id="frsSup-' + lastId + '">Supprimer</button></td>')
$(line).append(tdDate)
$(line).append(tdLibelle)
$(line).append(tdMtt)
$(line).append(tdJust)
$(line).append(btn)
line.insertBefore('.newFraisForm')
date.val('')
libelle.val('')
montant.val('')
}
calcPrixTotalFrsHorsF();
updatePrixTotal();
})
})
/**
* Supprimer fraisHf
*/
$(document).on('click', '.btnSuprFraisHf', function () {
id = $(this).attr('id').split('-')[1]
console.log(id)
$('#fraisHf-' + id).remove()
calcPrixTotalFrsHorsF();
updatePrixTotal();
})
/**
* Calcul prix total frais forfaitaires
*/
function calcPrixTotalFrsF() {
var prixTotal = 0;
$('td[id^="totalFrs-"]').each(function () {
prixTotal += parseFloat($(this).html().replace('€', ''))
})
$('.prixTotalFrsF').html('<strong>TOTAL :</strong> ' + prixTotal.toFixed(2) + ' €')
$('.prixTotalFrsF').attr('data-prix', prixTotal.toFixed(2))
}
/**
* Calcul prix total frais hors forfait
*/
function calcPrixTotalFrsHorsF() {
var prixTotal = 0;
$('td#MttFrsHF').each(function () {
prixTotal += parseFloat($(this).html().replace('€', ''))
})
$('#total-frais-HF').html('<strong>TOTAL :</strong> ' + prixTotal.toFixed(2) + ' €')
$('#total-frais-HF').attr('data-prix', prixTotal.toFixed(2))
}
/**
* Calcul prix total de la fiche
*/
function updatePrixTotal() {
var total = parseFloat($('#total-frais-HF').attr('data-prix'))
total += parseFloat($('.prixTotalFrsF').attr('data-prix'))
$('#total-fiche').html('<strong>TOTAL :</strong> ' + total.toFixed(2) + ' €')
}

View File

@ -37,6 +37,8 @@ if (!isset($_REQUEST['direction'])) {
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL"
crossorigin="anonymous"></script> crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.7.1.js"
integrity="sha256-eKhayi8LEQwp4NKxN+CfCh+3qOVUtJn3QNZ0TciWLP4=" crossorigin="anonymous"></script>
</head> </head>
<body> <body>

View File

@ -1,22 +0,0 @@
<!-- 03/05/2023 à 11H01 -->
<div id="contenu">
<h2>Identification utilisateur</h2>
<form method="POST" action="index.php?uc=connexion&action=valideConnexion">
<p>
<label for="nom">Login*</label>
<input id="login" type="text" name="login" size="30" maxlength="45">
</p>
<p>
<label for="mdp">Mot de passe*</label>
<input id="mdp" type="password" name="mdp" size="30" maxlength="45">
</p>
<input type="submit" value="Valider" name="valider">
<input type="reset" value="Annuler" name="annuler">
</p>
</form>
</div>

View File

@ -1,95 +1,76 @@
<?php <center>
var_dump($_SESSION['test']); <div class="col-3 mb-4">
?> <br>
<!DOCTYPE html> <?php
<html lang="en"> if ($_SESSION['typeU'] != 'comptable') {
echo '<h3>Gérer mes fiches de frais</h3>';
<head> } else {
<meta charset="UTF-8"> echo '<h3>Gérer les fiches de frais de :</h3>';
<meta name="viewport" content="width=device-width, initial-scale=1.0"> echo '<select class="form-select" name="selVisiteur" id="">';
<title>Page accueil</title> foreach ($LesUtilisateurs as $key => $value) {
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" $id = $value['uId'];
integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous"> $prenom = $value['uPrenom'];
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" $nom = $value['uNom'];
integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL"
crossorigin="anonymous"></script>
</head>
<body>
<div class="container-fluid">
<div class="row flex-nowrap">
<?php include('../include/menu.php') ?>
<div class="col py-3">
<center>
<div class="col-3 mb-4">
<h3>Gerer mes fiches de frais</h3>
<br>
<?php
if ($_SESSION['typeU'] == 'comptable') {
echo '<select class="form-select" name="selVisiteur" id="">
<option value="visiteur1">Visiteur 1</option></select>';
}
?>
</div>
</center>
<div class="col-11 d-flex mx-auto">
<table class="table table-striped">
<thead>
<tr>
<th scope="col">Mois</th>
<th scope="col">Total</th>
<th scope="col">Statut</th>
<th scope="col">Détails</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Novembre</th>
<td>351 €</td>
<td>en cours...</td>
<td><a href="#">voir</a></td>
</tr>
<tr>
<th scope="row">Octobre</th>
<td>1458 €</td>
<td>en cours...</td>
<td><a href="#">voir</a></td>
</tr>
<tr>
<th scope="row">Septembre</th>
<td>1112 €</td>
<td>classé</td>
<td><a href="#">voir</a></td>
</tr>
</tbody>
</table>
</div>
<div class="col-4 d-flex mx-auto">
<nav aria-label="...">
<ul class="pagination">
<li class="page-item disabled">
<a class="page-link">Previous</a>
</li>
<li class="page-item"><a class="page-link" href="#">1</a></li>
<li class="page-item active" aria-current="page">
<a class="page-link" href="#">2</a>
</li>
<li class="page-item"><a class="page-link" href="#">3</a></li>
<li class="page-item">
<a class="page-link" href="#">Next</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
echo '<option value="' . $id . '">' . $nom . " " . $prenom . "</option>";
}
echo '</select>';
}
?>
</div> </div>
</center>
</body> <div class="col-11 d-flex mx-auto">
<table class="table table-striped">
<thead>
<tr>
<th scope="col">Mois</th>
<th scope="col">Total</th>
<th scope="col">Statut</th>
<th scope="col">Détails</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Novembre</th>
<td>351 €</td>
<td>en cours...</td>
<td><a href="#">voir</a></td>
</tr>
<tr>
<th scope="row">Octobre</th>
<td>1458 €</td>
<td>en cours...</td>
<td><a href="#">voir</a></td>
</tr>
<tr>
<th scope="row">Septembre</th>
<td>1112 €</td>
<td>classé</td>
<td><a href="#">voir</a></td>
</tr>
</tbody>
</table>
</div>
</html> <!--
PAGINATION:// NE PAS TOUCHER
-->
<div class="col-4 d-flex mx-auto">
<nav aria-label="...">
<ul class="pagination">
<li class="page-item disabled">
<a class="page-link">Previous</a>
</li>
<li class="page-item"><a class="page-link" href="#">1</a></li>
<li class="page-item active" aria-current="page">
<a class="page-link" href="#">2</a>
</li>
<li class="page-item"><a class="page-link" href="#">3</a></li>
<li class="page-item">
<a class="page-link" href="#">Next</a>
</li>
</ul>
</nav>
</div>

View File

@ -1,7 +1,9 @@
<center> <center>
<h1>Nouvelle Fiche de frais</h1> <h1>Fiche de frais</h1>
<br> <br>
<p>Mois de Novembre 2023</p> <p>Mois de
<?= $dateHeader ?>
</p>
</center> </center>
<br> <br>
<!-- <!--
@ -20,23 +22,30 @@
</thead> </thead>
<tbody class="table-group-divider border-secondary-subtle"> <tbody class="table-group-divider border-secondary-subtle">
<?php <?php
foreach ($typesFraisForfaitaires as $key => $value): foreach ($listeFraisForfaitaire as $key => $value):
?> ?>
<tr> <tr>
<th scope="row"> <th scope="row">
<?= $value['fLibelle'] ?> <?= $value['fLibelle'] ?>
</th> </th>
<td><input type="text" name="fraisForfait-<?= $value['fId'] ?>" class="form-control"></td>
<td> <td>
<input type="text" name="fraisForfait-<?= $value['fId'] ?>" class="form-control frsFrt"
id="<?= $key ?>" value="<?= $value['lfQuantite'] ?>">
</td>
<td id="mttFrs-<?= $key ?>" data-price="<?= $value['fMontant'] ?>">
<?= $value['fMontant'] ?> € <?= $value['fMontant'] ?> €
</td> </td>
<td>0€</td> <td id="totalFrs-<?= $key ?>">
<?= $value['fTotal'] ?>€
</td>
</tr> </tr>
<?php <?php
endforeach; endforeach;
?> ?>
<tr>
<td colspan="3" class="border-0"></td>
<td class="prixTotalFrsF table-primary"></td>
</tr>
</tbody> </tbody>
</table> </table>
</div> </div>
@ -57,31 +66,78 @@
<th>Valider</th> <th>Valider</th>
</tr> </tr>
</thead> </thead>
<tbody class="table-group-divider border-secondary-subtle"> <tbody class="table-group-divider border-secondary-subtle fraisHFGroup">
<tr> <?php
<td scope="row">23/12/2023</td> foreach ($listeFraisHf as $key => $value):
<td>Salle de réunion</td> ?>
<td>130 €</td> <tr id="fraisHf-<?= $key ?>" class="fraisHF <?= $value['lhRefus'] == 1 ? 'table-danger' : '' ?>">
<td>facture.pdf</td> <th scope="row" id="dateFrsHF">
<td><button type="button" class="btn btn-outline-primary">Supprimer</button></td> <?= $value['lhDate'] ?>
</th>
<td id="LibelleFrsHF">
<?= $value['lhLibelle'] ?>
</td>
<td id="MttFrsHF">
<?= $value['lhMontant'] ?> €
</td>
<td>
<?= $value['lhJustificatif'] == 1 ? 'ok' : 'non fournis' ?>
</td>
<td>
<?php
if ($_SESSION['typeU'] === 'comptable') { ?>
<button type="button" class="btn btn-outline-primary btnRefuseFraisHf" id="frsSup-<?= $key ?>">
Refuser
</button>
<?php } elseif ($_SESSION['typeU'] === 'visiteur') { ?>
<button type="button" class="btn btn-outline-primary btnSuprFraisHf" id="frsSup-<?= $key ?>">
Supprimer
</button>
<?php } ?>
</td>
</tr>
<?php
endforeach;
?>
<!--
Formulaire d'ajout de frais HF
-->
<tr class="newFraisForm">
<td>
<!-- Date form -->
<input name="dateHf" class="form-control" id="dateHf" type="date" min="<?= $dateFormHFMin ?>"
max="<?= $dateFormHFMax ?>">
</td>
<td><input type="text" name="libelleHf" id="libelleHf" class="form-control"
placeholder="saisir un titre"></td>
<td><input type="text" name="mttHf" id="mttHf" class="form-control" placeholder="Saisir un Montant">
</td>
<td><input type="file" class="form-control"></td>
<td><button type="button" class="btn btn-outline-primary validFraisHF">Valider</button></td>
</tr> </tr>
<tr> <tr>
<td scope="row"><input class="form-control" type="date"></td> <td colspan="2" class="border-0"></td>
<td><input type="text" class="form-control" placeholder="saisir un titre"></td> <td class="table-primary" id="total-frais-HF">TOTAL: 0€</td> <!--COMPLETE HERE -->
<td><input type="text" class="form-control" placeholder="Saisir un Montant"></td>
<td><input type="file" class="form-control"></td>
<td><button type="button" class="btn btn-outline-primary">Valider</button></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
</div> </div>
<span class="border-3 border-bottom border-black col-10 mx-auto my-5 d-flex"></span> <!-- <span class="border-3 border-bottom border-black col-10 mx-auto my-5 d-flex"></span> -->
<!-- TOTAL -->
<div style="position:fixed; bottom:5px; right:5px; margin:0; padding:5px 3px;">
<button type="button" class="btn btn-primary" id="total-fiche">
<strong>TOTAL : </strong>
<?= $totalFraisFiche ?>
</button>
</div>
<!--
<h3 class="fw-bold offset-1">Commentaire (facultatif)</h3> <h3 class="fw-bold offset-1">Commentaire (facultatif)</h3>
<div class="col-8 d-flex mx-auto"> <div class="col-8 d-flex mx-auto">
<textarea name="commentaireFiche" id="commentaireFiche" class="form-control border-black"></textarea> <textarea name="commentaireFiche" id="commentaireFiche" class="form-control border-black"></textarea>
</div> </div>
-->
<div class="col-3 d-flex mx-auto my-5 justify-content-center"> <div class="col-3 d-flex mx-auto my-5 justify-content-center">
<button type="button" class="btn btn-outline-primary">Envoyer la Fiche</button> <button type="button" class="btn btn-outline-primary btn-lg">Envoyer la Fiche</button>
</div> </div>
<script src="../include/newFiche.js"></script>