6 Commits

11 changed files with 380 additions and 81 deletions

View File

@ -18,4 +18,9 @@ class Class_gestionFiche
return $result->fetchAll();
}
public function utilisateur(string $idUtilisateur): array
{
$req = '';
}
}

View File

@ -10,28 +10,62 @@ class Class_newFiche
$this->pdo = $pDO->getPdoGsb();
}
public function listFraisForfaitaires(): array
{
$req = 'SELECT "fLibelle", "fMontant" 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->execute();
return $result->fetchAll();
}
public function endInter(string $id)
public function listFraisForfaitForU(string $idUser, int $month): array
{
$req = "UPDATE intervention
SET iHeureFin = NOW()
WHERE iCis = :cis AND iId = :idInter AND iHeureFin IS NULL";
$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;';
$cis = explode('-', $id)[0];
$idInter = explode('-', $id)[1];
$result = PdoBD::$monPdo->prepare($req);
$result->bindParam(':cis', $cis);
$result->bindParam(':idInter', $idInter);
$result = $this->pdo->prepare($req);
$result->bindParam('idUser', $idUser);
$result->bindParam('monthF', $month);
$result->execute();
return $result->fetchAll();
}
public function listFraisHF(string $idVisiteur, int $month): array
{
$req = 'SELECT to_char("lhDate", \'YYYY-mm-dd\') AS "lhDate",
"lhLibelle", ROUND("lhMontant",2) as "lhMontant",
"lhJustificatif", "lhRefus"
FROM remboursement
inner join "ligne_hors_forfait" on "rVisiteur" = "lhVisiteur"
AND "rMois" = "lhMois"
WHERE "rVisiteur" = :idVisiteur AND "rMois" = :mois
ORDER BY "lhDate";';
$result = $this->pdo->prepare($req);
$result->bindParam(':idVisiteur', $idVisiteur);
$result->bindParam(':mois', $month);
$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,9 +1,9 @@
<?php
$_SESSION ["typeU"] = "comptable";
require_once(__DIR__ . '/../Class/class.gestionFiche.php');
$gestionFiche = new Class_gestionFiche($pdo);
$LesUtilisateurs = $gestionFiche->getLesUtilisateurs(); //RENVOIE LISTE USERS
$_SESSION['typeU'] = 'comptable';
include("../vues/v_gestionFiches.php");
include("vues/v_gestionFiches.php");

View File

@ -2,8 +2,59 @@
require_once(__DIR__ . '/../Class/class.newFiche.php');
$newFiche = new Class_newFiche($pdo);
$liste = $newFiche->listFraisForfaitaires();
var_dump($liste);
$_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');

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 $bdd='dbname=gsb2021';
private static $user='root' ;
private static $mdp='root' ;
private static $bdd='dbname=gsb2021';
private static $user='root' ;
private static $mdp='root' ;
gsb.ini:
[database]
driver = mysql
@ -12,22 +14,23 @@ host = localhost
port = 3306
schema = gsb2021
username = root
password = root
password = root
Database connection:
<?php
class MyPDO extends PDO
{
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'] .
':host=' . $settings['database']['host'] .
((!empty($settings['database']['port'])) ? (';port=' . $settings['database']['port']) : '') .
';dbname=' . $settings['database']['schema'];
':host=' . $settings['database']['host'] .
((!empty($settings['database']['port'])) ? (';port=' . $settings['database']['port']) : '') .
';dbname=' . $settings['database']['schema'];
parent::__construct($dns, $settings['database']['username'], $settings['database']['password']);
}
}

View File

@ -21,11 +21,11 @@
</a>
<ul class="collapse show nav flex-column ms-1" id="submenu1" data-bs-parent="#menu">
<li class="w-100">
<a href="../controleurs/c_gestionFiche.php" class="nav-link px-0"> <span class="d-none d-sm-inline">Gérer ses fiches</span>
<a href="index.php?direction=gestionFiche" class="nav-link px-0"> <span class="d-none d-sm-inline">Gérer ses fiches</span>
</a>
</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>
</li>
</ul>
@ -44,7 +44,7 @@
</a>
<ul class="collapse show nav flex-column ms-1" id="submenu2" data-bs-parent="#menu">
<li class="w-100">
<a href="../controleurs/c_gestionFiche.php" class="nav-link px-0"> <span class="d-none d-sm-inline">A valider</span>
<a href="index.php?direction=gestionFiche" class="nav-link px-0"> <span class="d-none d-sm-inline">A valider</span>
</a>
</li>
<li>

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"
integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL"
crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.7.1.js"
integrity="sha256-eKhayi8LEQwp4NKxN+CfCh+3qOVUtJn3QNZ0TciWLP4=" crossorigin="anonymous"></script>
</head>
<body>
@ -53,7 +55,7 @@ if (!isset($_REQUEST['direction'])) {
break;
case 'gestionFiche':
include("controleurs/c_gestionFiche.php");
include(__DIR__ . "/controleurs/c_gestionFiche.php");
break;
case 'home':

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,11 +1,20 @@
<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>';
if ($_SESSION['typeU'] != 'comptable') {
echo '<h3>Gérer mes fiches de frais</h3>';
} else {
echo '<h3>Gérer les fiches de frais de :</h3>';
echo '<select class="form-select" name="selVisiteur" id="">';
foreach ($LesUtilisateurs as $key => $value) {
$id = $value['uId'];
$prenom = $value['uPrenom'];
$nom = $value['uNom'];
echo '<option value="' . $id . '">' . $nom . " " . $prenom . "</option>";
}
echo '</select>';
}
?>
</div>
@ -44,6 +53,10 @@
</tbody>
</table>
</div>
<!--
PAGINATION:// NE PAS TOUCHER
-->
<div class="col-4 d-flex mx-auto">
<nav aria-label="...">
<ul class="pagination">

View File

@ -1,9 +1,14 @@
<center>
<h1>Nouvelle Fiche de frais</h1>
<h1>Fiche de frais</h1>
<br>
<p>Mois de Novembre 2023</p>
<p>Mois de
<?= $dateHeader ?>
</p>
</center>
<br>
<!--
Liste des frais forfaitaires
-->
<h3 class="fw-bold offset-1">Frais forfaitaires</h3>
<div class="col-11 d-flex mx-auto my-3">
<table class="table table-striped-columns align-middle">
@ -16,17 +21,39 @@
</tr>
</thead>
<tbody class="table-group-divider border-secondary-subtle">
<?php
foreach ($listeFraisForfaitaire as $key => $value):
?>
<tr>
<th scope="row">
<?= $value['fLibelle'] ?>
</th>
<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'] ?> €
</td>
<td id="totalFrs-<?= $key ?>">
<?= $value['fTotal'] ?>€
</td>
</tr>
<?php
endforeach;
?>
<tr>
<th scope="row">Hotel</th>
<td><input type="text" class="form-control"></td>
<td>20 </td>
<td>400</td>
<td colspan="3" class="border-0"></td>
<td class="prixTotalFrsF table-primary"></td>
</tr>
</tbody>
</table>
</div>
<span class="border-3 border-bottom border-black col-10 mx-auto my-5 d-flex"></span>
<!--
Listes des frais Hors Forfaits
-->
<h3 class="fw-bold offset-1">Hors forfait</h3>
<div class="col-11 d-flex mx-auto my-3">
<table class="table table-striped-columns align-middle">
@ -39,31 +66,78 @@
<th>Valider</th>
</tr>
</thead>
<tbody class="table-group-divider border-secondary-subtle">
<tr>
<td scope="row">23/12/2023</td>
<td>Salle de réunion</td>
<td>130 </td>
<td>facture.pdf</td>
<td><button type="button" class="btn btn-outline-primary">Supprimer</button></td>
<tbody class="table-group-divider border-secondary-subtle fraisHFGroup">
<?php
foreach ($listeFraisHf as $key => $value):
?>
<tr id="fraisHf-<?= $key ?>" class="fraisHF <?= $value['lhRefus'] == 1 ? 'table-danger' : '' ?>">
<th scope="row" id="dateFrsHF">
<?= $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>
<td scope="row"><input class="form-control" type="date"></td>
<td><input type="text" class="form-control" placeholder="saisir un titre"></td>
<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>
<td colspan="2" class="border-0"></td>
<td class="table-primary" id="total-frais-HF">TOTAL: 0€</td> <!--COMPLETE HERE -->
</tr>
</tbody>
</table>
</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>
<div class="col-8 d-flex mx-auto">
<textarea name="commentaireFiche" id="commentaireFiche" class="form-control border-black"></textarea>
</div>
-->
<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>
</div>
<button type="button" class="btn btn-outline-primary btn-lg">Envoyer la Fiche</button>
</div>
<script src="../include/newFiche.js"></script>