Browse Source

Maj gestion comptes & optimise history

stany.ferer 4 months ago
parent
commit
330a978d82

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

@@ -49,6 +49,36 @@ class banque
             }
     }
 
+    public static function delete(int $_id){
+        
+        db::query("DELETE FROM " . DB_T_BANQUE_COMPTES
+                . " WHERE id = :id");
+                db::bind(':id', $_id);
+        try {
+                db::execute();
+                alert::recSuccess("Le compte a été supprimé avec succès");
+                return TRUE;
+            } catch (Exception $ex) {
+                alert::recError("Erreur lors de la suppression du compte : " . $ex);
+                return FALSE;
+            }
+    }
+
+    public static function reset(int $_id){
+        
+        db::query("DELETE FROM " . DB_T_BANQUE_LIGNES
+                . " WHERE id_compte = :id");
+                db::bind(':id', $_id);
+        try {
+                db::execute();
+                alert::recSuccess("Les lignes du compte ont été vidées avec succès");
+                return TRUE;
+            } catch (Exception $ex) {
+                alert::recError("Erreur lors de la suppression des lignes du compte : " . $ex);
+                return FALSE;
+            }
+    }
+
     public static function add(){
         
         db::query("INSERT INTO " . DB_T_BANQUE_COMPTES . " (label, compte, commentaire, solde, solde_date, icon, import) VALUES (:label, :compte, :commentaire, :solde, :solde_date, :icon, :import)");
@@ -91,6 +121,15 @@ class banque
             $txtProtected = ($nbLines > 1) ? "Vous ne pouvez pas modifier ces données car cela entraînerait une désynchronisation des " . $nbLines . " lignes associées à ce compte. Pour se faire vous devez supprimer toutes les lignes associées à ce compte." : "Vous ne pouvez pas modifier ces données car cela entraînerait une désynchronisation de la ligne associée à ce compte. Pour se faire vous devez supprimer la ligne associée à ce compte.";
         }
 
+        echo "<div><div class=\"fix-container-button-nav\" style=\"margin:-20px 25px 0 0;\">";
+        if($protected == 1) { 
+            echo "<a href=\"/submit.php?from=compte-reset&id=" . $_array["id"] . "\" style=\"color: #dc3545; text-decoration:none;\" onclick=\"return confirm('Voulez-vous vider les lignes de ce compte bancaire ?')\"><button type=\"button\" class=\"btn btn-outline-danger btn-sm\"> Vider les lignes du compte</button></a>";
+        } else {
+            echo "<a href=\"/submit.php?from=compte-delete&id=" . $_array["id"] . "\" style=\"color: #dc3545; text-decoration:none;\" onclick=\"return confirm('Voulez-vous supprimer ce compte bancaire ?')\"><button type=\"button\" class=\"btn btn-outline-danger btn-sm\"> Supprimer ce compte</button></a>";
+        }
+        echo "<div></div></div></div>";        
+            
+        echo "<div style=\"margin-top:30px;\">";
         echo "<form method=\"post\" action=\"/submit.php\">";
         echo "<input type=\"hidden\" name=\"from\" value=\"parametres-compte-edit\">";
         echo "<input type=\"hidden\" name=\"id\" value=\"" . $_array["id"] . "\">";
@@ -129,6 +168,7 @@ class banque
         echo "<div class=\"form-group\"><label>Commentaire</label><input type=\"text\" class=\"form-control form-control-sm\" name=\"commentaire\" value=\"" . $_array["commentaire"] . "\"></div><br />";
         echo "<button class=\"btn btn-primary btn-lg\" style=\"width: 100%\" type=\"submit\">" . $txtSubmit . "</button>";
         echo "</form>";
+        echo "</div>";
     }
 
     public static function countLines(int|string $_id)

+ 24 - 0
core/submit/cms.compte-delete.php

@@ -0,0 +1,24 @@
+<?php
+
+if (core::ifGet("from") AND core::getGet("from") == "compte-delete") {
+
+    $banque = banque::getInitialCompte(core::getGet("id"));
+
+    banque::delete(core::getGet("id"));
+    json::delete("banque-lignes-" . core::getGet("id"));
+
+    historique::recRef("/parametres-comptes.html");
+    historique::add(array(
+        "idType" => historique::getIdRef("ACTION"),
+        "idUser" => session::getId(),
+        "idPage" => historique::getIdRef("/parametres-comptes.html"),
+        "log" => "Supression du compte en banque : " . $banque["label"] . " [" .core::getGet("id") . "]"
+    ));
+
+    header("Location: /parametres-comptes.html");
+    exit();
+} else {
+    header('HTTP/1.0 401 Unauthorized');
+    exit();
+}
+

+ 5 - 5
core/submit/cms.compte-insert.php

@@ -25,23 +25,23 @@ if (core::ifPost("from") AND core::getPost("from") == "compte-insert") {
     
     $type = ($data["type"] == 2) ? "Débit" : "Crédit";
 
-    banque::recordLigne($data, 4);
+    banque::recordLigne($data, core::getPost("compte"));
     
     $log = "Ligne ajoutée : " . $data["label"] . " - " . $type . " de " . $data["montant"] . " €";
     
-    historique::recRef("/compte-4.html");
+    historique::recRef("/compte-" . core::getPost("compte") . ".html");
     historique::add(array(
         "idType" => historique::getIdRef("ACTION"),
         "idUser" => session::getId(),
-        "idPage" => historique::getIdRef("/compte-4.html"),
+        "idPage" => historique::getIdRef("/compte-" . core::getPost("compte") . ".html"),
         "log" => $log
     ));
     historique::recordAlert("SUCCESS");
     alert::recSuccess($log);
 
-    json::create("banque-lignes-4");
+    json::create("banque-lignes-" . core::getPost("compte"));
 
-    header("Location: /compte-4.html");
+    header("Location: /compte-" . core::getPost("compte") . ".html");
     exit();
 } else {
     header('HTTP/1.0 401 Unauthorized');

+ 23 - 0
core/submit/cms.compte-reset.php

@@ -0,0 +1,23 @@
+<?php
+
+if (core::ifGet("from") AND core::getGet("from") == "compte-reset") {
+
+    $banque = banque::getInitialCompte(core::getGet("id"));
+
+    banque::reset(core::getGet("id"));
+    json::create("banque-lignes-" . core::getGet("id"));
+
+    historique::recRef("/parametres-comptes.html");
+    historique::add(array(
+        "idType" => historique::getIdRef("ACTION"),
+        "idUser" => session::getId(),
+        "idPage" => historique::getIdRef("/parametres-comptes.html"),
+        "log" => "Suppression des lignes du compte en banque : " . $banque["label"] . " [" .core::getGet("id") . "]"
+    ));
+
+    header("Location: /parametres-comptes.html#parametres-compte-" . core::getGet("id"));
+    exit();
+} else {
+    header('HTTP/1.0 401 Unauthorized');
+    exit();
+}

+ 5 - 3
core/submit/cms.document-delete.php

@@ -1,16 +1,18 @@
 <?php
 
 if(core::ifGet("id")) {
+    $document = document::get(core::getGet("id"));
+
     document::delete(core::getGet("id"));
     json::create("documents");
     json::create("documents-limited");
 
-    historique::recRef("/document-" . core::getGet("id").".html");
+    historique::recRef("/documents.html");
     historique::add(array(
         "idType" => historique::getIdRef("ACTION"),
         "idUser" => session::getId(),
-        "idPage" => historique::getIdRef("/document-" . core::getGet("id").".html"),
-        "log" => "Supression du document"
+        "idPage" => historique::getIdRef("/documents.html"),
+        "log" => "Supression du document : " . $document["titre"] . " [" .core::getGet("id") . "]"
     ));
 }
 

+ 18 - 0
core/submit/cms.parametres-compte-edit.php

@@ -4,11 +4,29 @@ if (core::ifPost("from")) {
 
     if(core::ifPost("id") AND core::getPost("id") != "add"){
         banque::update();
+
+        historique::recRef("/parametres-comptes.html");
+        historique::add(array(
+            "idType" => historique::getIdRef("ACTION"),
+            "idUser" => session::getId(),
+            "idPage" => historique::getIdRef("/parametres-comptes.html"),
+            "log" => "Mise à jour du compte : " . core::getPost("id")
+        ));
+        
         header("Location: /parametres-comptes.html#parametres-compte-". core::getPost("id"));
         exit();
     } else {
         $lastId = banque::add();
         json::create("banque-lignes-" . $lastId);
+
+        historique::recRef("/parametres-comptes.html");
+        historique::add(array(
+            "idType" => historique::getIdRef("ACTION"),
+            "idUser" => session::getId(),
+            "idPage" => historique::getIdRef("/parametres-comptes.html"),
+            "log" => "Création du compte : " . $lastId
+        ));
+
         header("Location: /parametres-comptes.html#parametres-compte-". $lastId);
         exit();
     }

+ 13 - 4
core/views/pages/cms.compte-insert.php

@@ -19,14 +19,23 @@
             "current" => "Importer un CSV", 
             "arbo" => array( 
                 "Comptes bancaires" => NULL,
-                $banque["label"] => "/compte-4.html",
+                $banque["label"] => "/compte-". core::getGet("add") .".html",
                 "Insérer une ligne" => NULL)
         )); 
 
-        $lastLigne = banque::lastArrayRecord(4); // ID du compte épargne
+        $lastLigne = banque::lastArrayRecord(core::getGet("add"));
+        if($lastLigne == FALSE){
+            unset($lastLigne);
+            $lastLigne["debit"] = "0.00";
+            $lastLigne["credit"] = "0.00";
+            $lastLigne["date"] = $banque["solde_date"];
+            $lastLigne["solde"] = $banque["solde"];
+            $lastLigne["label"] = "Solde d'ouverture";
+        }
+
         if($lastLigne["debit"] == "0.00" AND $lastLigne["credit"] == "0.00"){
             $montant = "0.00"; 
-            $type = "Intial";
+            $type = "Initial";
         } elseif($lastLigne["debit"] == "0.00"){
             $montant = $lastLigne["credit"];
             $type = "Crédit";
@@ -38,7 +47,7 @@
 <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"] ?>">
+    <input type="hidden" name="compte" value="<?php echo core::getGet("add") ?>">
 
     <table>
         <tr>