Bläddra i källkod

Add type facture

stany.ferer 1 år sedan
förälder
incheckning
db7618337e

+ 1 - 0
conf.inc.php

@@ -51,6 +51,7 @@ define("DB_T_DOCUMENTS", "documents");
 define("DB_T_DOCUMENT_FILES", "documents_files");
 define("DB_T_DOCUMENT_TAGS", "documents_tags");
 define("DB_T_TAGS", "tags");
+define("DB_T_CLIENTS", "clients");
 define("DB_T_JWT", "jwt");
 
 define("DB_T_ALERTES_EMAILS", "alertesEmails");

+ 38 - 0
core/class/clients.class.php

@@ -0,0 +1,38 @@
+<?php
+
+class clients
+{
+
+    public static function getAll() {
+        db::query("SELECT "
+            . "* "
+            . "FROM " . DB_T_CLIENTS);
+        return db::resultset();
+    }
+
+    public static function insert(string $_client) {
+        db::query("INSERT INTO " . DB_T_CLIENTS . " (label) VALUES (:label)");
+        db::bind(':label', $_client);
+
+        try {
+            db::execute();
+            return TRUE;
+        } catch (Exception $ex) {
+            return FALSE;
+        }
+    }
+
+    public static function maj(float $_id, string $_tag) {
+        db::query("UPDATE " . DB_T_CLIENTS . " SET label = :label WHERE id = :id; ");
+        db::bind(':label', $_tag);
+        db::bind(':id', $_id);
+
+        try {
+            db::execute();
+            return TRUE;
+        } catch (Exception $ex) {
+            return FALSE;
+        }
+    }
+
+}

+ 10 - 2
core/class/document.class.php

@@ -150,13 +150,14 @@ class document
         if(file::findM5($md5) == TRUE){
             alert::recError("Ce fichier a déjà été utilisé : " . $file["name"]);
         } else {
-            db::query("INSERT INTO " . DB_T_DOCUMENTS . " (id_type, titre, date, deadline, description, montant, id_user) VALUES (:id_type, :titre, :date, :deadline, :description, :montant, :id_user)");
+            db::query("INSERT INTO " . DB_T_DOCUMENTS . " (id_type, titre, date, deadline, description, montant, id_client, id_user) VALUES (:id_type, :titre, :date, :deadline, :description, :montant, :id_client, :id_user)");
             db::bind(':id_type', core::getPost("id_type"));
             db::bind(':titre', core::getPost("titre"));
             db::bind(':date', core::getPost("date"));
             db::bind(':deadline', core::getPost("deadline"));
             db::bind(':description', core::getPost("description"));
             db::bind(':montant', !empty(core::getPost("montant")) ? floatval(core::getPost("montant")) : 0.0);
+            db::bind(':id_client', core::getPost("id_client") == "" ? NULL : core::getPost("id_client"));
             db::bind(':id_user', session::getId());
             
             try {
@@ -265,7 +266,8 @@ class document
                     . "date = :date, "
                     . "deadline = :deadline, "
                     . "description = :description, "
-                    . "montant = :montant "
+                    . "montant = :montant, "
+                    . "id_client = :id_client "
                     . $sql
                     . "WHERE id = :id");
             
@@ -275,6 +277,7 @@ class document
             db::bind(':deadline', core::getPost("deadline"));
             db::bind(':description', core::getPost("description"));
             db::bind(':montant', core::getPost("montant"));
+            db::bind(':id_client', core::getPost("id_client") == "" ? NULL : core::getPost("id_client"));
             db::bind(':id', core::getPost("id"));
 
             if(core::ifPost("date_done") AND core::getPost("date_done") == TRUE){
@@ -340,6 +343,7 @@ class document
             . "" . DB_T_DOCUMENTS . ".deadline, "
             . "" . DB_T_DOCUMENTS . ".description, "
             . "" . DB_T_DOCUMENTS . ".montant, "
+            . "" . DB_T_DOCUMENTS . ".id_client, "
             . "" . DB_T_DOCUMENTS . ".id_user_done, "
             . "" . DB_T_DOCUMENTS . ".date_done, "
             . "CONCAT(" . DB_T_USER . ".prenom, ' ', " . DB_T_USER . ".nom) AS doneUser "
@@ -349,6 +353,10 @@ class document
         db::bind(':id', $_id);
         $document = db::single();
 
+        if(empty($document)){
+            $document = [];
+        }
+
         $document["tagsSupplier"] = self::getTags($_id, 2);
         $document["tagsUser"] = self::getTags($_id, 1);
 

+ 3 - 0
core/class/icon.class.php

@@ -88,6 +88,9 @@ class icon
             case 'tags':
                 return "bi bi-tags-fill";
                 break;
+            case 'clients':
+                return "bi bi-building-fill";
+                break;
             case 'maj':
                 return "bi bi-git";
                 break;

+ 15 - 0
core/javascript/cms.document.php

@@ -33,6 +33,12 @@
         });
 
         if (allFieldsFilled) {
+
+            const selectedType = $("#id_type").val();
+            if (selectedType !== "1") {
+                $("#id_client").val("");
+            }
+
             form.submit();
         }
     }
@@ -130,4 +136,13 @@
         });
     });
 <?php } ?>
+    $(document).ready(function() {
+        $("#id_type").change(function() {
+            if ($("#id_type").val() === "1") {
+                $("#client-section").show();
+            } else {
+                $("#client-section").hide();
+            }
+        });
+    });
 </script>

+ 22 - 0
core/submit/cms.client-add.php

@@ -0,0 +1,22 @@
+<?php
+
+if (core::ifPost("from")) {
+
+    clients::insert(core::getPost("client"));
+
+    alert::recSuccess("Ajout du client : ". core::getPost("client"));
+
+    historique::recRef("/clients.html");
+    historique::add(array(
+        "idType" => historique::getIdRef("ACTION"),
+        "idUser" => session::getId(),
+        "idPage" => historique::getIdRef("/clients.html"),
+        "log" => "Ajout du client : " . core::getPost("client")
+    ));
+
+    header("Location: /clients.html");
+    exit();
+} else {
+    header('HTTP/1.0 401 Unauthorized');
+    exit();
+}

+ 19 - 0
core/submit/cms.client-change.php

@@ -0,0 +1,19 @@
+<?php
+
+if (core::ifPost("from")) {
+
+    clients::maj(core::getPost("id"), core::getPost("value"));
+    json::create("documents");
+    json::create("documents-limited");
+
+    historique::recRef("/clients.html");
+    historique::add(array(
+        "idType" => historique::getIdRef("ACTION"),
+        "idUser" => session::getId(),
+        "idPage" => historique::getIdRef("/clients.html"),
+        "log" => "Modification du client : " . core::getPost("value")
+    ));
+} else {
+    header('HTTP/1.0 401 Unauthorized');
+    exit();
+}

+ 1 - 0
core/views/_cms.menu.php

@@ -81,6 +81,7 @@
             echo '<ul class="collapse ' . $_show . ' list-unstyled" id="col-admin" data-parent="#accordion">';
                 core::elementMenu("parametre-users", "/parametre-users.html", "Admin : Utilisateurs");
                 core::elementMenu("parametre-teams", "/parametre-teams.html", "Admin : Groupes & Droits");
+                core::elementMenu("clients", "/clients.html", "Admin : Clients");
                 core::elementMenu("tags", "/tags.html", "Admin : Tags");
                 core::elementMenu("historique", "/historique.html", "Admin : Historique");
                 core::elementMenu("parametres", "/parametres.html", "Admin : Paramètres");

+ 67 - 0
core/views/pages/cms.clients.php

@@ -0,0 +1,67 @@
+<header class="d-flex flex-column flex-md-row align-items-md-center p-3 bg-light ">
+    <h2 class="bd-title" id="content">
+        <span>Administration : Clients</span>
+    </h2>
+</header>
+<?php
+echo core::filAriane(array(
+    "current" => "Clients",
+    "arbo" => array(
+        "Administration" => NULL,
+        "Clients" => "/clients.html"
+    )
+));
+
+$allClients = clients::getAll();
+
+?>
+
+<table class="table">
+    <thead>
+        <tr>
+            <th scope="col">#</th>
+            <th scope="col">Clients</th>
+            <th scope="col"></th>
+        </tr>
+        <tr>
+            <form method="post" action="/submit.php">
+            <th scope="row"><input type="hidden" name="from" value="client-add"></th>
+            <td><input type="text" name="client" class="form-control form-control-sm" value=""></td>
+            <td><button type="submit" class="btn btn-success btn-sm">Ajouter</button></td>
+            </form>
+        </tr>
+    </thead>
+    <tbody>
+<?php 
+    foreach ($allClients as $value) {
+        echo "  <tr>
+                    <th scope=\"row\">" . $value["id"] . "</th>
+                    <td><input type=\"text\" class=\"form-control form-control-sm\" id=\"clients-".$value["id"]."\" value=\"" . $value["label"] . "\"></td>
+                    <td><button type=\"button\" class=\"btn btn-primary btn-sm\" onclick=\"majClients(".$value["id"].");\">Modifier</button></td>
+                </tr>";
+    }
+?>
+    </tbody>
+</table>
+
+<script>
+    function majClients(id){
+        $.ajax({
+            url: '/submit.php',
+            type: 'POST',
+            data: {
+                from: "client-change",
+                id: id,
+                value: $('#clients-'+id).val()
+            },
+            success: function(response) {
+                $("#printToastSuccessTxt").html("Le client vient d'être mis à jour");
+                $("#printToastSuccess").toast('show');
+            },
+            error: function(xhr, status, error) {
+                $("#printToastErrorTxt").html("Le client n'a pas été mis à jour");
+                $("#printToastError").toast('show');
+            }
+        });
+    }
+</script>

+ 62 - 25
core/views/pages/cms.document.php

@@ -14,7 +14,7 @@ if (core::getGet("id") == NULL) {
     $document = $datas["document"];
     $files = $datas["files"];
 
-    if (empty($document["id"]) OR access::ifLimitAccessException("salaire") AND isset($document["id_type"]) AND $document["id_type"] == 3) {
+    if (empty($document["id"]) or access::ifLimitAccessException("salaire") and isset($document["id_type"]) and $document["id_type"] == 3) {
         get::page("unknow");
         exit();
     }
@@ -56,7 +56,7 @@ echo core::filAriane(array(
     )
 ));
 
-if (isset($document["id"]) AND access::ifAccesss("add-document")) { 
+if (isset($document["id"]) and access::ifAccesss("add-document")) {
 ?>
     <div style="float:right; margin-top: -60px;">
         <a href="/submit.php?from=document-delete&id=<?php echo $document["id"] ?>" style="color: #dc3545; text-decoration:none;" onclick="return confirm('Voulez-vous supprimer ce document ?')"><button type="submit" class="btn btn-outline-danger btn-sm"><?php icon::getFont(["icon" => "bi-trash-fill"]) ?></i> Supprimer</button></a>
@@ -67,8 +67,8 @@ if (isset($document["id"]) AND access::ifAccesss("add-document")) {
 
 <link rel="stylesheet" href="css/dragAndDrop.css">
 <?php if (access::ifAccesss("add-document")) { ?>
-<form id="form-document" method="post" action="/submit.php" enctype="multipart/form-data" onsubmit="return(false);">
-<?php } ?>
+    <form id="form-document" method="post" action="/submit.php" enctype="multipart/form-data" onsubmit="return(false);">
+    <?php } ?>
     <div class="row">
         <div class="col">
             <input type="hidden" name="from" value="document">
@@ -79,17 +79,21 @@ if (isset($document["id"]) AND access::ifAccesss("add-document")) {
             <?php $_titre = (isset($document["titre"])) ? $document["titre"] : NULL; ?>
             <div class="form-group">
                 <label>Titre</label>
-                <input type="text" class="form-control" value="<?php core::printFormValue($_titre) ?>" name="titre" placeholder="" required <?php if (!access::ifAccesss("add-document")) { echo "readonly"; } ?>>
+                <input type="text" class="form-control" value="<?php core::printFormValue($_titre) ?>" name="titre" placeholder="" required <?php if (!access::ifAccesss("add-document")) {
+                                                                                                                                                echo "readonly";
+                                                                                                                                            } ?>>
             </div>
-
             <br />
+
             <?php
             $_type_document = (isset($document["id_type"])) ? $document["id_type"] : NULL;
             $_label_type_document = document::getTypes();
             ?>
             <div class="form-group">
                 <label>Type de document</label>
-                <select name="id_type" class="form-select" <?php if (!access::ifAccesss("add-document")) { echo "disabled"; } ?>>
+                <select id="id_type" name="id_type" class="form-select" <?php if (!access::ifAccesss("add-document")) {
+                                                                echo "disabled";
+                                                            } ?> required>
                     <option value=""></option>
                     <option value="1" <?php core::printFormSelectOption($_type_document, 1) ?>><?php echo $_label_type_document[1] ?></option>
                     <option value="2" <?php core::printFormSelectOption($_type_document, 2) ?>><?php echo $_label_type_document[2] ?></option>
@@ -101,45 +105,78 @@ if (isset($document["id"]) AND access::ifAccesss("add-document")) {
             </div>
             <br />
 
+            <?php
+            $_client = (isset($document["id_client"])) ? $document["id_client"] : NULL;
+            $_all_clients = clients::getAll();
+            ?>
+            <div class="form-group" id="client-section"<?php if($_type_document != 1){ echo 'style=" display: none;"'; } ?>>
+                <label>Facture(s) liée(s) à</label>
+                <select name="id_client" id="id_client" class="form-select" <?php if (!access::ifAccesss("add-client")) {
+                                                                    echo "disabled";
+                                                                } ?>>
+                    <option value=""></option>
+                    <?php
+                    foreach ($_all_clients as $client) {
+                        echo '<option value="' . $client["id"] . '"';
+                        echo $_client == $client["id"] ? " selected" : NULL;
+                        echo '>' . $client["label"] . '</option>';
+                    }
+                    ?>
+                </select>
+                <br />
+            </div>
+
             <?php $_montant = (isset($document["montant"])) ? $document["montant"] : NULL; ?>
             <div class="form-group">
                 <label>Montant associé</label>
-                <input type="text" class="form-control" value="<?php core::printFormValue($_montant) ?>" name="montant" placeholder="" onkeypress="return (event.charCode >= 48 && event.charCode <= 57) || event.charCode == 46 || event.charCode == 0 " <?php if (!access::ifAccesss("add-document")) { echo "readonly"; } ?>>
+                <input type="text" class="form-control" value="<?php core::printFormValue($_montant) ?>" name="montant" placeholder="" onkeypress="return (event.charCode >= 48 && event.charCode <= 57) || event.charCode == 46 || event.charCode == 0 " <?php if (!access::ifAccesss("add-document")) {
+                                                                                                                                                                                                                                                                echo "readonly";
+                                                                                                                                                                                                                                                            } ?>>
             </div>
             <br />
 
             <?php $_tagsSupplier = (isset($document["tagsSupplier"])) ? $document["tagsSupplier"] : NULL; ?>
             <div class="form-group">
                 <label>Tags associés</label>
-                <input type="text" value="<?php core::printFormValue($_tagsSupplier) ?>" name="tagsSupplier" id="tagsSupplier" <?php if (!access::ifAccesss("add-document")) { echo "class=\"form-control\" readonly"; } ?> />
+                <input type="text" value="<?php core::printFormValue($_tagsSupplier) ?>" name="tagsSupplier" id="tagsSupplier" <?php if (!access::ifAccesss("add-document")) {
+                                                                                                                                    echo "class=\"form-control\" readonly";
+                                                                                                                                } ?> />
             </div>
             <br />
 
             <?php $_date = (isset($document["date"])) ? $document["date"] : NULL; ?>
             <div class="form-group">
                 <label>Date associée à ce document</label>
-                <input type="date" class="form-control" name="date" value="<?php core::printFormValue($_date) ?>" placeholder="" required <?php if (!access::ifAccesss("add-document")) { echo "readonly"; } ?>>
+                <input type="date" class="form-control" name="date" value="<?php core::printFormValue($_date) ?>" placeholder="" required <?php if (!access::ifAccesss("add-document")) {
+                                                                                                                                                echo "readonly";
+                                                                                                                                            } ?>>
             </div>
             <br />
 
             <?php $_deadline = (isset($document["deadline"])) ? $document["deadline"] : NULL; ?>
             <div class="form-group">
                 <label>Date limite de traitement</label>
-                <input type="date" class="form-control" name="deadline" value="<?php core::printFormValue($_deadline) ?>" placeholder="" required <?php if (!access::ifAccesss("add-document")) { echo "readonly"; } ?>>
+                <input type="date" class="form-control" name="deadline" value="<?php core::printFormValue($_deadline) ?>" placeholder="" required <?php if (!access::ifAccesss("add-document")) {
+                                                                                                                                                        echo "readonly";
+                                                                                                                                                    } ?>>
             </div>
             <br />
 
             <?php $_description = (isset($document["description"])) ? $document["description"] : NULL; ?>
             <div class="form-group">
                 <label>Description et commentaires</label>
-                <textarea class="form-control" name="description" style="height:100%;" <?php if (!access::ifAccesss("add-document")) { echo "readonly"; } ?>><?php core::printFormValue($_description) ?></textarea>
+                <textarea class="form-control" name="description" style="height:100%;" <?php if (!access::ifAccesss("add-document")) {
+                                                                                            echo "readonly";
+                                                                                        } ?>><?php core::printFormValue($_description) ?></textarea>
             </div>
             <br />
 
             <?php $_tagsUser = (isset($document["tagsUser"])) ? $document["tagsUser"] : NULL; ?>
             <div class="form-group">
                 <label>Attribution</label>
-                <input type="text" value="<?php core::printFormValue($_tagsUser) ?>" name="tagsUser" id="tagsUser" <?php if (!access::ifAccesss("add-document")) { echo "class=\"form-control\" readonly"; } ?> />
+                <input type="text" value="<?php core::printFormValue($_tagsUser) ?>" name="tagsUser" id="tagsUser" <?php if (!access::ifAccesss("add-document")) {
+                                                                                                                        echo "class=\"form-control\" readonly";
+                                                                                                                    } ?> />
             </div>
             <br />
 
@@ -163,11 +200,11 @@ if (isset($document["id"]) AND access::ifAccesss("add-document")) {
                     document::printAttachement($files);
                     ?>
                     <?php if (access::ifAccesss("add-document")) { ?>
-                    <div class="file-drop-area">
-                        <span class="choose-file-button">Ajouter une pièce jointe</span>
-                        <span class="file-message">ou drag & drop</span>
-                        <input id="attachement-document" class="import-excel" name="attachement-document" type="file" onchange="dargAndDropAttachment()" accept="image/jpeg,image/png,application/pdf,text/xml,application/xml">
-                    </div>
+                        <div class="file-drop-area">
+                            <span class="choose-file-button">Ajouter une pièce jointe</span>
+                            <span class="file-message">ou drag & drop</span>
+                            <input id="attachement-document" class="import-excel" name="attachement-document" type="file" onchange="dargAndDropAttachment()" accept="image/jpeg,image/png,application/pdf,text/xml,application/xml">
+                        </div>
                     <?php } ?>
                 </div>
                 <br />
@@ -184,8 +221,8 @@ if (isset($document["id"]) AND access::ifAccesss("add-document")) {
                 <br />
             <?php } else {
                 $getMime = mime_content_type(file::download($files["principal"]["id"], DIR_DATAS_DOCS));
-                $heigh = ($getMime == "application/pdf" OR $getMime == "text/xml" OR $getMime == "application/xml") ? "height:110vh;" : NULL;
-                $marginTop = ($getMime == "text/xml" OR $getMime == "application/xml") ? "margin-top:4px;" : "margin-top:22px;";
+                $heigh = ($getMime == "application/pdf" or $getMime == "text/xml" or $getMime == "application/xml") ? "height:110vh;" : NULL;
+                $marginTop = ($getMime == "text/xml" or $getMime == "application/xml") ? "margin-top:4px;" : "margin-top:22px;";
                 echo '  <div style="' . $marginTop . '">
                         <embed src="/document.php?id=' . $files["principal"]["id"] . '" style="width:100%; margin-top:10px;' . $heigh . '" /></embed>
                     </div><br />
@@ -194,11 +231,11 @@ if (isset($document["id"]) AND access::ifAccesss("add-document")) {
             ?>
         </div>
     </div>
-<?php if (access::ifAccesss("add-document")) { ?>
-    <input class="btn btn-primary btn-lg" style="width: 100%;" type="button" value="<?php echo $submit ?>" onclick="validateAndSubmit()">
-</form>
+    <?php if (access::ifAccesss("add-document")) { ?>
+        <input class="btn btn-primary btn-lg" style="width: 100%;" type="button" value="<?php echo $submit ?>" onclick="validateAndSubmit()">
+    </form>
 
 <?php
-} 
+    }
     get::javascript("document");
-?>
+?>

+ 1 - 1
core/views/pages/cms.tags.php

@@ -29,7 +29,7 @@ $allTags = tags::getAll(2);
     foreach ($allTags as $value) {
         echo "  <tr>
                     <th scope=\"row\">" . $value["id"] . "</th>
-                    <td><input type=\"email\" class=\"form-control form-control-sm\" id=\"tags-".$value["id"]."\" value=\"" . $value["label"] . "\"></td>
+                    <td><input type=\"text\" class=\"form-control form-control-sm\" id=\"tags-".$value["id"]."\" value=\"" . $value["label"] . "\"></td>
                     <td><button type=\"button\" class=\"btn btn-primary btn-sm\" onclick=\"majTags(".$value["id"].");\">Modifier</button></td>
                 </tr>";
     }

+ 10 - 3
maj/sql/maj.sql

@@ -1,5 +1,12 @@
 
-INSERT INTO `access` (`id`, `label`, `show`, `add`, `access`, `noAccess`) VALUES (NULL, 'Médias (streaming)', '1', '1', 'medias', '');
+CREATE TABLE `clients` (
+    `id` int NOT NULL,
+    `label` tinytext COLLATE utf8mb4_general_ci NOT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
 
-INSERT INTO `type_access` (`id`, `id_type`, `id_access`, `exception`) VALUES ('4#18', '4', '18', NULL);
-INSERT INTO `type_access` (`id`, `id_type`, `id_access`, `exception`) VALUES ('5#18', '5', '18', NULL);
+ALTER TABLE `clients` CHANGE `id` `id` INT NOT NULL AUTO_INCREMENT, add PRIMARY KEY (`id`); 
+ALTER TABLE `documents` ADD `id_client` INT NULL AFTER `montant`; 
+ALTER TABLE `documents` ADD CONSTRAINT `id_client` FOREIGN KEY (`id_client`) REFERENCES `clients`(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION; 
+
+UPDATE `type_document` SET `label` = 'Facture' WHERE `type_document`.`id` = 1; 
+UPDATE `access` SET `access` = 'parametre*\r\nparametres\r\nadd-user\r\nmaj\r\ntag*\r\nclient*' WHERE `access`.`id` = 3;