cms.compte-insert.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. $banque = banque::getInitialCompte(core::getGet("add"));
  3. if($banque["import"] != "manuel"){
  4. alert::recError("Vous ne pouvez pas ajouter des lignes manuellement sur ce compte.");
  5. echo '<script>window.location.replace("/compte-' . core::getGet("add") . '.html");</script>';
  6. exit();
  7. }
  8. ?>
  9. <link rel="stylesheet" href="css/dragAndDrop.css">
  10. <header class="d-flex flex-column flex-md-row align-items-md-center p-3 bg-light ">
  11. <h2 class="bd-title" id="content">
  12. <span>Banque : Insérer une ligne dans l'épargne financière</span>
  13. </h2>
  14. </header>
  15. <?php
  16. echo core::filAriane(array(
  17. "current" => "Importer un CSV",
  18. "arbo" => array(
  19. "Comptes bancaires" => NULL,
  20. $banque["label"] => "/compte-4.html",
  21. "Insérer une ligne" => NULL)
  22. ));
  23. $lastLigne = banque::lastArrayRecord(4); // ID du compte épargne
  24. if($lastLigne["debit"] == "0.00" AND $lastLigne["credit"] == "0.00"){
  25. $montant = "0.00";
  26. $type = "Intial";
  27. } elseif($lastLigne["debit"] == "0.00"){
  28. $montant = $lastLigne["credit"];
  29. $type = "Crédit";
  30. } else {
  31. $montant = $lastLigne["debit"];
  32. $type = "Débit";
  33. }
  34. ?>
  35. <br />
  36. <form action="/submit.php" method="post" onsubmit="loading()">
  37. <input type="hidden" name="from" value="compte-insert">
  38. <input type="hidden" name="compte" value="<?php echo $banque["compte"] ?>">
  39. <table>
  40. <tr>
  41. <td>
  42. <div class="form-group">
  43. <label>Date</label>
  44. <input type="date" min="<?php echo $lastLigne["date"] ?>" max="<?php echo date("Y-m-d") ?>" class="form-control" value="" name="date" placeholder="" required>
  45. </div>
  46. </td>
  47. <td width="40%">
  48. <div class="form-group">
  49. <label>Label</label>
  50. <input type="text" class="form-control" value="" name="label" placeholder="" required>
  51. </div>
  52. </td>
  53. <td>
  54. <div class="form-group">
  55. <label>Montant</label>
  56. <input type="number" class="form-control" value="" name="montant" placeholder="" required>
  57. </div>
  58. </td>
  59. <td>
  60. <div class="form-group">
  61. <label>Type de la ligne</label>
  62. <select name="type" class="form-select" name="type" required>
  63. <option value=""></option>
  64. <option value="1"<?php if(isset($ligne["type"]) AND $ligne["type"] == 1){ echo " selected"; } ?>>Crédit</option>
  65. <option value="2"<?php if(isset($ligne["type"]) AND $ligne["type"] == 2){ echo " selected"; } ?>>Débit</option>
  66. </select>
  67. </div>
  68. </td>
  69. <td>
  70. <div class="form-group">
  71. <label>Solde</label>
  72. <input type="text" class="form-control" value="" name="solde" placeholder="" readonly>
  73. </div>
  74. </td>
  75. <td>
  76. <div class="form-group">
  77. <label></label>
  78. <?php button::confirm(
  79. array(
  80. "value" => "Insérer",
  81. "text" => "Vous allez insérer une ligne dans le compte ".$banque["label"].".<br />Assurez-vous que les informations sont correctes avant de valider.",
  82. "class" => "btn btn-primary",
  83. )
  84. ) ?>
  85. </div>
  86. </td>
  87. </tr>
  88. <tr>
  89. <td>
  90. <div class="form-group">
  91. <input type="text" class="form-control" value="<?php echo core::convertDate($lastLigne["date"], FALSE) ?>" disabled>
  92. </div>
  93. </td>
  94. <td>
  95. <div class="form-group">
  96. <input type="text" class="form-control" value="<?php echo $lastLigne["label"] ?>" disabled>
  97. </div>
  98. </td>
  99. <td>
  100. <div class="form-group">
  101. <input type="text" class="form-control" value="<?php echo $montant ?>" disabled>
  102. </div>
  103. </td>
  104. <td>
  105. <div class="form-group">
  106. <input type="text" class="form-control" value="<?php echo $type ?>" disabled>
  107. </div>
  108. </td>
  109. <td>
  110. <div class="form-group">
  111. <input type="text" class="form-control" value="<?php echo $lastLigne["solde"] ?>" disabled>
  112. </div>
  113. </td>
  114. <td><span style="color:grey">Dernière ligne</span></td>
  115. </tr>
  116. </table>
  117. </form>
  118. <script>
  119. document.addEventListener("DOMContentLoaded", function () {
  120. const montantInput = document.querySelector('input[name="montant"]');
  121. const typeSelect = document.querySelector('select[name="type"]');
  122. const soldeInput = document.querySelector('input[name="solde"]');
  123. // Valeur initiale du solde (à adapter dynamiquement si besoin)
  124. let soldePrecedent = parseFloat("<?php echo $lastLigne['solde'] ?? 0; ?>");
  125. function updateSolde() {
  126. const montant = parseFloat(montantInput.value);
  127. const type = typeSelect.value;
  128. if (!isNaN(montant) && type) {
  129. let nouveauSolde = soldePrecedent;
  130. if (type === "1") { // Crédit
  131. nouveauSolde += montant;
  132. } else if (type === "2") { // Débit
  133. nouveauSolde -= montant;
  134. }
  135. soldeInput.value = nouveauSolde.toFixed(2);
  136. } else {
  137. soldeInput.value = soldePrecedent.toFixed(2);
  138. }
  139. }
  140. montantInput.addEventListener("input", updateSolde);
  141. typeSelect.addEventListener("change", updateSolde);
  142. });
  143. </script>