|
|
@@ -11,13 +11,140 @@ class banque
|
|
|
return db::resultset();
|
|
|
}
|
|
|
|
|
|
- public static function menu()
|
|
|
- {
|
|
|
+ public static function update(){
|
|
|
+
|
|
|
+ if(core::ifPost("solde")){
|
|
|
+ $sql = ", solde = :solde, solde_date = :solde_date, import = :import ";
|
|
|
+ } else {
|
|
|
+ $sql = "";
|
|
|
+ }
|
|
|
+
|
|
|
+ db::query("UPDATE " . DB_T_BANQUE_COMPTES . " SET "
|
|
|
+ . "label = :label, "
|
|
|
+ . "compte = :compte, "
|
|
|
+ . "commentaire = :commentaire, "
|
|
|
+ . "icon = :icon "
|
|
|
+ . $sql
|
|
|
+ . "WHERE id = :id");
|
|
|
+
|
|
|
+ db::bind(':label', core::getPost("label"));
|
|
|
+ db::bind(':compte', core::getPost("compte"));
|
|
|
+ db::bind(':commentaire', core::getPost("commentaire"));
|
|
|
+ db::bind(':icon', core::getPost("icon"));
|
|
|
+ db::bind(':id', core::getPost("id"));
|
|
|
+
|
|
|
+ if(!empty(core::getPost("solde"))){
|
|
|
+ db::bind(':solde', core::getPost("solde"));
|
|
|
+ db::bind(':solde_date', core::getPost("solde_date"));
|
|
|
+ db::bind(':import', core::getPost("import"));
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ db::execute();
|
|
|
+ alert::recSuccess("Compte mis à jour avec succès");
|
|
|
+ return TRUE;
|
|
|
+ } catch (Exception $ex) {
|
|
|
+ alert::recError("Erreur de mise à jour 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)");
|
|
|
+ db::bind(':label', core::getPost("label"));
|
|
|
+ db::bind(':compte', core::getPost("compte"));
|
|
|
+ db::bind(':commentaire', core::getPost("commentaire"));
|
|
|
+ db::bind(':solde', core::getPost("solde"));
|
|
|
+ db::bind(':solde_date', core::getPost("solde_date"));
|
|
|
+ db::bind(':icon', core::getPost("icon"));
|
|
|
+ db::bind(':import', core::getPost("import"));
|
|
|
+
|
|
|
+ try {
|
|
|
+ db::execute();
|
|
|
+ alert::recSuccess("Compte créé avec succès");
|
|
|
+ return db::lastInsertId();
|
|
|
+ } catch (Exception $ex) {
|
|
|
+ alert::recError("Erreur de création du Compte : " . $ex);
|
|
|
+ return FALSE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function menu(){
|
|
|
banque::getAll();
|
|
|
foreach (self::getAll() as $value) {
|
|
|
core::elementMenu("compte-" . $value["id"], "/compte-" . $value["id"] . ".html", $value["label"], NULL, $value["icon"]);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public static function printFormCompte(?array $_array = NULL) {
|
|
|
+ if($_array == NULL){
|
|
|
+ $_array = ["id" => "add", "label" => NULL, "compte" => NULL, "solde" => NULL, "solde_date" => NULL, "icon" => NULL, "commentaire" => NULL];
|
|
|
+ $txtSubmit = "Enregistrer un nouveau compte";
|
|
|
+ } else {
|
|
|
+ $txtSubmit = "Modifier ce compte";
|
|
|
+ }
|
|
|
+
|
|
|
+ $nbLines = self::countLines($_array["id"]);
|
|
|
+ $protected = ($_array["solde"] != NULL AND $nbLines > 0) ? 1 : 0;
|
|
|
+ if($protected == 1) {
|
|
|
+ $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 "<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"] . "\">";
|
|
|
+ echo "<div class=\"form-group\"><label>Nom du compte</label><input type=\"text\" class=\"form-control form-control-sm\" name=\"label\" value=\"" . $_array["label"] . "\" required></div><br />";
|
|
|
+ echo "<div class=\"form-group\"><label>Numéro de compte</label><input type=\"text\" class=\"form-control form-control-sm\" name=\"compte\" value=\"" . $_array["compte"] . "\"></div><br />";
|
|
|
+
|
|
|
+ if($protected == 1) {
|
|
|
+ echo "<fieldset class=\"border\" style=\"border-color: orange!important; padding: 15px;\">";
|
|
|
+ echo "<legend class=\"float-none w-auto\" style=\"font-size: 0.9rem; color: orange!important; padding: 0 5px;\">Protégé</legend>";
|
|
|
+ echo "<div class=\"alert alert-warning\" role=\"alert\">" . $txtProtected . "</div>";
|
|
|
+ }
|
|
|
+
|
|
|
+ echo "<div class=\"form-group\"><label>Solde initial</label><input type=\"number\" class=\"form-control form-control-sm\" name=\"solde\" value=\"" . $_array["solde"] . "\"";
|
|
|
+ echo ($protected == 1) ? " disabled" : " required";
|
|
|
+ echo "></div><br />";
|
|
|
+
|
|
|
+ echo "<div class=\"form-group\"><label>Date du solde initial</label><input type=\"date\" class=\"form-control form-control-sm\" name=\"solde_date\" value=\"" . $_array["solde_date"] . "\"";
|
|
|
+ echo ($protected == 1) ? " disabled" : " required";
|
|
|
+ echo "></div><br />";
|
|
|
+
|
|
|
+ echo "<div class=\"form-group\"><label>Mode d'importation des données</label><select name=\"import\" class=\"form-select\"";
|
|
|
+ echo ($protected == 1) ? " disabled" : " required";
|
|
|
+ echo ">";
|
|
|
+ echo "<option value=\"csv\"" . (($_array["import"] == "csv") ? " selected" : NULL) . ">Importer des données depuis le CSV de Crédit Mutuel</option>";
|
|
|
+ echo "<option value=\"manuel\"" . (($_array["import"] == "manuel") ? " selected" : NULL) . ">Ajouter des lignes manuellement</option>";
|
|
|
+ echo "</select></div><br />";
|
|
|
+
|
|
|
+ if($protected == 1) {
|
|
|
+ echo "</fieldset><br />";
|
|
|
+ }
|
|
|
+
|
|
|
+ echo "<div class=\"form-group\"><label>Icône</label><select name=\"icon\" class=\"form-select\">";
|
|
|
+ echo "<option value=\"courant\"" . (($_array["icon"] == "courant") ? " selected" : NULL) . ">Icône liée à un compte courant</option>";
|
|
|
+ echo "<option value=\"epargne\"" . (($_array["icon"] == "epargne") ? " selected" : NULL) . ">Icône liée à un compte d'épargne</option>";
|
|
|
+ echo "</select></div><br />";
|
|
|
+ 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>";
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function countLines(int|string $_id)
|
|
|
+ {
|
|
|
+ if($_id == "add"){
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ db::query("SELECT "
|
|
|
+ . "COUNT(id_compte) AS nb "
|
|
|
+ . "FROM " . DB_T_BANQUE_LIGNES . " "
|
|
|
+ . "WHERE " . DB_T_BANQUE_LIGNES . ".id_compte = :id");
|
|
|
+ db::bind(':id', $_id);
|
|
|
+ $nb = db::single()["nb"];
|
|
|
+ return (!empty($nb)) ? $nb : 0;
|
|
|
+ }
|
|
|
|
|
|
public static function lastArrayRecord(int $_id)
|
|
|
{
|
|
|
@@ -40,7 +167,8 @@ class banque
|
|
|
. "ORDER BY creer DESC "
|
|
|
. "LIMIT 1");
|
|
|
db::bind(':id', $_id);
|
|
|
- return db::single()["creer"];
|
|
|
+ $last = db::single();
|
|
|
+ return (!empty($last["creer"])) ? $last["creer"] : NULL;
|
|
|
}
|
|
|
|
|
|
public static function getInitial(int $_id)
|
|
|
@@ -49,6 +177,7 @@ class banque
|
|
|
$return = array(
|
|
|
"num" => 0,
|
|
|
"id" => 0,
|
|
|
+ "import" => $tmp["import"],
|
|
|
"date" => $tmp["solde_date"],
|
|
|
"label" => "SOLDE CREDITEUR AU " . core::convertDate($tmp["solde_date"], FALSE),
|
|
|
"debit" => 0,
|
|
|
@@ -260,7 +389,6 @@ class banque
|
|
|
}
|
|
|
|
|
|
public static function fileName(string $_compte){
|
|
|
- $n = explode(" ", $_compte);
|
|
|
- return $n[1].$n[2];
|
|
|
+ return str_replace(' ', '', $_compte);
|
|
|
}
|
|
|
}
|