| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- <?php
- $banque = banque::getInitialCompte(core::getGet("add"));
- if($banque["import"] != "manuel"){
- alert::recError("Vous ne pouvez pas ajouter des lignes manuellement sur ce compte.");
- echo '<script>window.location.replace("/compte-' . core::getGet("add") . '.html");</script>';
- exit();
- }
- ?>
- <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
- echo core::filAriane(array(
- "current" => "Importer un CSV",
- "arbo" => array(
- "Comptes bancaires" => NULL,
- $banque["label"] => "/compte-". core::getGet("add") .".html",
- "Insérer une ligne" => NULL)
- ));
- $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 = "Initial";
- } 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 core::getGet("add") ?>">
- <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>
|