cms.compte-insert.php 5.7 KB

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