Bläddra i källkod

Possibilité d'ajouter une ligne dans le compte épargne

stany.ferer 5 månader sedan
förälder
incheckning
5e311bfd5e

+ 12 - 0
core/class/banque.class.php

@@ -3,6 +3,18 @@
 class banque
 {
 
+    public static function lastArrayRecord(int $_id)
+    {
+        db::query("SELECT "
+            . "* "
+            . "FROM " . DB_T_BANQUE_LIGNES . " "
+            . "WHERE " . DB_T_BANQUE_LIGNES . ".id_compte = :id "
+            . "ORDER BY creer DESC "
+            . "LIMIT 1");
+            db::bind(':id', $_id);
+            return db::single();
+    }
+    
     public static function lastRecord(int $_id)
     {
         db::query("SELECT "

+ 50 - 0
core/submit/cms.compte-insert.php

@@ -0,0 +1,50 @@
+<?php
+
+if (core::ifPost("from") AND core::getPost("from") == "compte-insert") {
+
+    $data = array(
+        "date" => core::getPost("date"),
+        "label" => core::getPost("label"),
+        "montant" => core::getPost("montant"),
+        "type" => core::getPost("type"),
+        "solde" => core::getPost("solde")
+    );
+
+    if (empty($data["date"]) || empty($data["label"]) || empty($data["montant"]) || empty($data["type"])) {
+        alert::recError("Tous les champs sont obligatoires.");
+        header("Location: /?p=compte-insert");
+        exit();
+    }
+
+    // Backup
+    (backup::create()) ? alert::recSuccess("Backup des données OK") : alert::recError("Backup des données KO");
+
+    $data["md5"] = md5($data["date"] . $data["label"] . $data["montant"] . $data["type"] . $data["solde"]);
+    $data["debit"] = ($data["type"] == 2) ? $data["montant"] : "0.00";
+    $data["credit"] = ($data["type"] == 1) ? $data["montant"] : "0.00";
+    
+    $type = ($data["type"] == 2) ? "Débit" : "Crédit";
+
+    banque::recordLigne($data, 4);
+    
+    $log = "Ligne ajoutée : " . $data["label"] . " - " . $type . " de " . $data["montant"] . " €";
+    
+    historique::recRef("/compte-4.html");
+    historique::add(array(
+        "idType" => historique::getIdRef("ACTION"),
+        "idUser" => session::getId(),
+        "idPage" => historique::getIdRef("/compte-4.html"),
+        "log" => $log
+    ));
+    historique::recordAlert("SUCCESS");
+    alert::recSuccess($log);
+
+    json::create("banque-lignes-4");
+
+    header("Location: /compte-4.html");
+    exit();
+} else {
+    header('HTTP/1.0 401 Unauthorized');
+    exit();
+}
+

+ 148 - 0
core/views/pages/cms.compte-insert.php

@@ -0,0 +1,148 @@
+<link rel="stylesheet" href="css/dragAndDrop.css">
+
+<header class="d-flex flex-column flex-md-row align-items-md-center p-3 bg-light ">
+    <h2 class="bd-title" id="content">
+        <span>Banque : Insérer une ligne dans l'épargne financière</span>
+    </h2>
+</header>
+<?php   
+        $banque = banque::getInitialCompte(4); // ID du compte épargne    
+
+        echo core::filAriane(array(
+            "current" => "Importer un CSV", 
+            "arbo" => array( 
+                "Comptes bancaires" => NULL,
+                $banque["label"] => "/compte-4.html",
+                "Insérer une ligne" => NULL)
+        )); 
+
+        $lastLigne = banque::lastArrayRecord(4); // ID du compte épargne
+        if($lastLigne["debit"] == "0.00" AND $lastLigne["credit"] == "0.00"){
+            $montant = "0.00"; 
+            $type = "Intial";
+        } elseif($lastLigne["debit"] == "0.00"){
+            $montant = $lastLigne["credit"];
+            $type = "Crédit";
+        } else {
+            $montant = $lastLigne["debit"]; 
+            $type = "Débit";
+        }
+?>
+<br />
+<form action="/submit.php" method="post" onsubmit="loading()">
+    <input type="hidden" name="from" value="compte-insert">
+    <input type="hidden" name="compte" value="<?php echo $banque["compte"] ?>">
+
+    <table>
+        <tr>
+            <td>
+                <div class="form-group">
+                    <label>Date</label>
+                    <input type="date" min="<?php echo $lastLigne["date"] ?>" max="<?php echo date("Y-m-d") ?>" class="form-control" value="" name="date" placeholder="" required>
+                </div>
+            </td>   
+            <td width="40%">
+                <div class="form-group">
+                    <label>Label</label>
+                    <input type="text" class="form-control" value="" name="label" placeholder="" required>
+                </div>
+            </td>
+            <td>
+                <div class="form-group">
+                    <label>Montant</label>
+                    <input type="number" class="form-control" value="" name="montant" placeholder="" required>
+                </div>
+            </td>
+            <td>
+                <div class="form-group">
+                    <label>Type de la ligne</label>
+                    <select name="type" class="form-select" name="type" required>
+                        <option value=""></option>
+                        <option value="1"<?php if(isset($ligne["type"]) AND $ligne["type"] == 1){ echo " selected"; } ?>>Crédit</option>
+                        <option value="2"<?php if(isset($ligne["type"]) AND $ligne["type"] == 2){ echo " selected"; } ?>>Débit</option>
+                    </select>       
+                </div>
+            </td>
+            <td>
+                <div class="form-group">
+                    <label>Solde</label>
+                    <input type="text" class="form-control" value="" name="solde" placeholder="" readonly>      
+                </div>
+            </td>
+            <td>
+                <div class="form-group">
+                    <label></label>
+                    <?php button::confirm(
+                        array(
+                            "value" => "Insérer",
+                            "text" => "Vous allez insérer une ligne dans le compte ".$banque["label"].".<br />Assurez-vous que les informations sont correctes avant de valider.",
+                            "class" => "btn btn-primary",
+                        )
+                    ) ?>
+                </div>
+            </td>
+        </tr>
+        <tr>
+            <td>
+                <div class="form-group">
+                    <input type="text" class="form-control" value="<?php echo core::convertDate($lastLigne["date"], FALSE) ?>" disabled>
+                </div>
+            </td>   
+            <td>
+                <div class="form-group">
+                    <input type="text" class="form-control" value="<?php echo $lastLigne["label"] ?>" disabled>
+                </div>
+            </td>
+            <td>
+                <div class="form-group">
+                    <input type="text" class="form-control" value="<?php echo $montant ?>" disabled>
+                </div>
+            </td>
+            <td>
+                <div class="form-group">
+                    <input type="text" class="form-control" value="<?php echo $type ?>" disabled>
+                </div>
+            </td>
+            <td>
+                <div class="form-group">
+                    <input type="text" class="form-control" value="<?php echo $lastLigne["solde"] ?>" disabled> 
+                </div>
+            </td>
+            <td><span style="color:grey">Dernière ligne</span></td>
+        </tr>
+    </table>
+</form>
+
+
+<script>
+document.addEventListener("DOMContentLoaded", function () {
+    const montantInput = document.querySelector('input[name="montant"]');
+    const typeSelect = document.querySelector('select[name="type"]');
+    const soldeInput = document.querySelector('input[name="solde"]');
+
+    // Valeur initiale du solde (à adapter dynamiquement si besoin)
+    let soldePrecedent = parseFloat("<?php echo $lastLigne['solde'] ?? 0; ?>");
+
+    function updateSolde() {
+        const montant = parseFloat(montantInput.value);
+        const type = typeSelect.value;
+
+        if (!isNaN(montant) && type) {
+            let nouveauSolde = soldePrecedent;
+
+            if (type === "1") { // Crédit
+                nouveauSolde += montant;
+            } else if (type === "2") { // Débit
+                nouveauSolde -= montant;
+            }
+
+            soldeInput.value = nouveauSolde.toFixed(2);
+        } else {
+            soldeInput.value = soldePrecedent.toFixed(2);
+        }
+    }
+
+    montantInput.addEventListener("input", updateSolde);
+    typeSelect.addEventListener("change", updateSolde);
+});
+</script>

+ 7 - 1
core/views/pages/cms.compte-upload.php

@@ -7,12 +7,18 @@
 </header>
 <?php   
         $banque = banque::getInitialCompte(core::getGet("add"));
+        
+        if(!empty($banque["compte"])){
+            $compte = " - N°". $banque["compte"];
+        } else {
+            $compte = "";
+        }       
 
         echo core::filAriane(array(
             "current" => "Importer un CSV", 
             "arbo" => array( 
                 "Comptes bancaires" => NULL,
-                $banque["label"] . " - N°".$banque["compte"] => "/compte-". core::getGet("add") .".html",
+                $banque["label"] . $compte => "/compte-". core::getGet("add") .".html",
                 "Importer un CSV" => NULL)
         )); 
 ?>

+ 7 - 2
core/views/pages/cms.compte.php

@@ -8,9 +8,14 @@ if (debug::isFile("debug")) {
     <h2 class="bd-title" id="content">
         <span>Etat des comptes</span>
     </h2>
-    <?php if (access::ifAccesss("compte-upload")) { ?>
+    <?php
+        if (access::ifAccesss("compte-upload")) { ?>
         <div class="fix-container-button-nav">
-            <a href="/?p=compte-upload&add=<?php echo core::getGet("id") ?>"><button type="submit" class="btn btn-outline-success btn-sm"><?php icon::getFont(["icon" => "bi bi-file-earmark-plus"]) ?> Charger un CSV</button></a>
+            <?php if(core::getGet("id") == 4){ ?>
+                <a href="/?p=compte-insert"><button type="submit" class="btn btn-outline-success btn-sm"><?php icon::getFont(["icon" => "bi bi-file-earmark-plus"]) ?> Ajouter une ligne</button></a>
+            <?php } else { ?>
+                <a href="/?p=compte-upload&add=<?php echo core::getGet("id") ?>"><button type="submit" class="btn btn-outline-success btn-sm"><?php icon::getFont(["icon" => "bi bi-file-earmark-plus"]) ?> Charger un CSV</button></a>
+            <?php } ?>
         </div>
     <?php } ?>
 </header>