partie front et recup data (newFiche)
This commit is contained in:
		@@ -12,30 +12,46 @@ class Class_newFiche
 | 
			
		||||
 | 
			
		||||
    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->execute();
 | 
			
		||||
 | 
			
		||||
        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
 | 
			
		||||
			SET iHeureFin = NOW()
 | 
			
		||||
			WHERE iCis = :cis AND iId = :idInter AND iHeureFin IS NULL";
 | 
			
		||||
        $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";';
 | 
			
		||||
 | 
			
		||||
        $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(':idVisiteur', $idVisiteur);
 | 
			
		||||
        $result->bindParam(':mois', $month);
 | 
			
		||||
        $result->execute();
 | 
			
		||||
 | 
			
		||||
        return $result->fetchAll();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -2,6 +2,21 @@
 | 
			
		||||
require_once(__DIR__ . '/../Class/class.newFiche.php');
 | 
			
		||||
 | 
			
		||||
$newFiche = new Class_newFiche($pdo);
 | 
			
		||||
$typesFraisForfaitaires = $newFiche->listFraisForfaitaires();
 | 
			
		||||
 | 
			
		||||
$_SESSION['userId'] = 'b34';
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Liste des frais forfaitaires du mois et de l'user :: sinon afficher les libelle
 | 
			
		||||
 */
 | 
			
		||||
$listeFraisForfaitaire = $newFiche->listFraisForfaitForU($_SESSION['userId'], '202011');
 | 
			
		||||
if (count($listeFraisForfaitaire) == 0) {
 | 
			
		||||
    $listeFraisForfaitaire = $newFiche->listFraisForfaitaires();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Listes des frais HF
 | 
			
		||||
 */
 | 
			
		||||
$listeFraisHf = $newFiche->listFraisHF($_SESSION['userId'], '202011');
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
include(__DIR__ . '/../vues/v_newFiche.php');
 | 
			
		||||
 
 | 
			
		||||
@@ -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']);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -25,7 +25,7 @@
 | 
			
		||||
                        </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" class="nav-link px-0"> <span class="d-none d-sm-inline">Fiche du mois</span>
 | 
			
		||||
                        </a>
 | 
			
		||||
                    </li>
 | 
			
		||||
                </ul>
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										110
									
								
								include/newFiche.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										110
									
								
								include/newFiche.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,110 @@
 | 
			
		||||
$(document).ready(function () {
 | 
			
		||||
 | 
			
		||||
    calcPrixTotalFrsF();
 | 
			
		||||
    /**
 | 
			
		||||
     * 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();
 | 
			
		||||
        }
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 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("#dateFrsHF").html(date.val());
 | 
			
		||||
            line.find("#LibelleFrsHF").html(libelle.val());
 | 
			
		||||
            line.find("#MttFrsHF").html(parseFloat(montant.val()).toFixed(2) + ' €');
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
            line.find('.btn').attr('id', 'frsSup-' + lastId)
 | 
			
		||||
 | 
			
		||||
            var line = $('<tr id="fraisHf-' + lastId + '" class="fraisHF"></tr>');
 | 
			
		||||
            var tdDate = $('<td scope="row" id="dateFrsHF"></td>');
 | 
			
		||||
            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')
 | 
			
		||||
        }
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
* Supprimer fraisHf
 | 
			
		||||
*/
 | 
			
		||||
$(document).on('click', '.btnSuprFraisHf', function () {
 | 
			
		||||
    id = $(this).attr('id').split('-')[1]
 | 
			
		||||
    console.log(id)
 | 
			
		||||
 | 
			
		||||
    $('#fraisHf-' + id).remove()
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
* Calcul prix total
 | 
			
		||||
*/
 | 
			
		||||
function calcPrixTotalFrsF() {
 | 
			
		||||
 | 
			
		||||
    var prixTotal = 0;
 | 
			
		||||
    $('td[id^="totalFrs-"]').each(function () {
 | 
			
		||||
        prixTotal += parseFloat($(this).html().replace('€', ''))
 | 
			
		||||
    })
 | 
			
		||||
    $('.prixTotalFrsF').html('<strong>TOTAL :</strong> ' + prixTotal.toFixed(2) + ' €')
 | 
			
		||||
}
 | 
			
		||||
@@ -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>
 | 
			
		||||
 
 | 
			
		||||
@@ -20,23 +20,30 @@
 | 
			
		||||
        </thead>
 | 
			
		||||
        <tbody class="table-group-divider border-secondary-subtle">
 | 
			
		||||
            <?php
 | 
			
		||||
            foreach ($typesFraisForfaitaires as $key => $value):
 | 
			
		||||
            foreach ($listeFraisForfaitaire as $key => $value):
 | 
			
		||||
                ?>
 | 
			
		||||
                <tr>
 | 
			
		||||
                    <th scope="row">
 | 
			
		||||
                        <?= $value['fLibelle'] ?>
 | 
			
		||||
                    </th>
 | 
			
		||||
                    <td><input type="text" name="fraisForfait-<?= $value['fId'] ?>" class="form-control"></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'] ?> €
 | 
			
		||||
                    </td>
 | 
			
		||||
                    <td>0€</td>
 | 
			
		||||
                    <td id="totalFrs-<?= $key ?>">
 | 
			
		||||
                        <?= $value['fTotal'] ?>€
 | 
			
		||||
                    </td>
 | 
			
		||||
                </tr>
 | 
			
		||||
 | 
			
		||||
                <?php
 | 
			
		||||
            endforeach;
 | 
			
		||||
            ?>
 | 
			
		||||
 | 
			
		||||
            <tr>
 | 
			
		||||
                <td colspan="3" class="border-0"></td>
 | 
			
		||||
                <td class="prixTotalFrsF"></td>
 | 
			
		||||
            </tr>
 | 
			
		||||
        </tbody>
 | 
			
		||||
    </table>
 | 
			
		||||
</div>
 | 
			
		||||
@@ -57,20 +64,45 @@
 | 
			
		||||
                <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>
 | 
			
		||||
            </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>
 | 
			
		||||
        <tbody class="table-group-divider border-secondary-subtle fraisHFGroup">
 | 
			
		||||
            <?php
 | 
			
		||||
            foreach ($listeFraisHf as $key => $value):
 | 
			
		||||
                ?>
 | 
			
		||||
                <tr id="fraisHf-<?= $key ?>" class="fraisHF">
 | 
			
		||||
                    <td scope="row" id="dateFrsHF">
 | 
			
		||||
                        <?= $value['lhDate'] ?>
 | 
			
		||||
                    </td>
 | 
			
		||||
                    <td id="LibelleFrsHF">
 | 
			
		||||
                        <?= $value['lhLibelle'] ?>
 | 
			
		||||
                    </td>
 | 
			
		||||
                    <td id="MttFrsHF">
 | 
			
		||||
                        <?= $value['lhMontant'] ?> €
 | 
			
		||||
                    </td>
 | 
			
		||||
                    <td>
 | 
			
		||||
                        <?= $value['lhJustificatif'] == 1 ? 'ok' : 'non fournis' ?>
 | 
			
		||||
                    </td>
 | 
			
		||||
                    <td>
 | 
			
		||||
                        <button type="button" class="btn btn-outline-primary btnSuprFraisHf" id="frsSup-<?= $key ?>">
 | 
			
		||||
                            Supprimer
 | 
			
		||||
                        </button>
 | 
			
		||||
                    </td>
 | 
			
		||||
                </tr>
 | 
			
		||||
                <?php
 | 
			
		||||
            endforeach;
 | 
			
		||||
            ?>
 | 
			
		||||
            <!-- 
 | 
			
		||||
                Formulaire d'ajout de frais HF
 | 
			
		||||
             -->
 | 
			
		||||
            <tr class="newFraisForm">
 | 
			
		||||
                <td scope="row">
 | 
			
		||||
                    <input name="dateHf" class="form-control" id="dateHf" type="date" min="2020-11-01" max="2020-11-30">
 | 
			
		||||
                </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">Valider</button></td>
 | 
			
		||||
                <td><button type="button" class="btn btn-outline-primary validFraisHF">Valider</button></td>
 | 
			
		||||
            </tr>
 | 
			
		||||
        </tbody>
 | 
			
		||||
    </table>
 | 
			
		||||
@@ -84,4 +116,5 @@
 | 
			
		||||
</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>
 | 
			
		||||
</div>
 | 
			
		||||
<script src="../include/newFiche.js"></script>
 | 
			
		||||
		Reference in New Issue
	
	Block a user