2
0

cms.compte-insert.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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-". core::getGet("add") .".html",
  21. "Insérer une ligne" => NULL)
  22. ));
  23. $lastLigne = banque::lastArrayRecord(core::getGet("add"));
  24. if($lastLigne == FALSE){
  25. unset($lastLigne);
  26. $lastLigne["debit"] = "0.00";
  27. $lastLigne["credit"] = "0.00";
  28. $lastLigne["date"] = $banque["solde_date"];
  29. $lastLigne["solde"] = $banque["solde"];
  30. $lastLigne["label"] = "Solde d'ouverture";
  31. }
  32. if($lastLigne["debit"] == "0.00" AND $lastLigne["credit"] == "0.00"){
  33. $montant = "0.00";
  34. $type = "Initial";
  35. } elseif($lastLigne["debit"] == "0.00"){
  36. $montant = $lastLigne["credit"];
  37. $type = "Crédit";
  38. } else {
  39. $montant = $lastLigne["debit"];
  40. $type = "Débit";
  41. }
  42. ?>
  43. <br />
  44. <form action="/submit.php" method="post" onsubmit="loading()">
  45. <input type="hidden" name="from" value="compte-insert">
  46. <input type="hidden" name="compte" value="<?php echo core::getGet("add") ?>">
  47. <table>
  48. <tr>
  49. <td>
  50. <div class="form-group">
  51. <label>Date</label>
  52. <input type="date" min="<?php echo $lastLigne["date"] ?>" max="<?php echo date("Y-m-d") ?>" class="form-control" value="" name="date" placeholder="" required>
  53. </div>
  54. </td>
  55. <td width="40%">
  56. <div class="form-group">
  57. <label>Label</label>
  58. <input type="text" class="form-control" value="" name="label" placeholder="" required>
  59. </div>
  60. </td>
  61. <td>
  62. <div class="form-group">
  63. <label>Montant</label>
  64. <input type="number" class="form-control" value="" name="montant" placeholder="" required>
  65. </div>
  66. </td>
  67. <td>
  68. <div class="form-group">
  69. <label>Type de la ligne</label>
  70. <select name="type" class="form-select" name="type" required>
  71. <option value=""></option>
  72. <option value="1"<?php if(isset($ligne["type"]) AND $ligne["type"] == 1){ echo " selected"; } ?>>Crédit</option>
  73. <option value="2"<?php if(isset($ligne["type"]) AND $ligne["type"] == 2){ echo " selected"; } ?>>Débit</option>
  74. </select>
  75. </div>
  76. </td>
  77. <td>
  78. <div class="form-group">
  79. <label>Solde</label>
  80. <input type="text" class="form-control" value="" name="solde" placeholder="" readonly>
  81. </div>
  82. </td>
  83. <td>
  84. <div class="form-group">
  85. <label></label>
  86. <?php button::confirm(
  87. array(
  88. "value" => "Insérer",
  89. "text" => "Vous allez insérer une ligne dans le compte ".$banque["label"].".<br />Assurez-vous que les informations sont correctes avant de valider.",
  90. "class" => "btn btn-primary",
  91. )
  92. ) ?>
  93. </div>
  94. </td>
  95. </tr>
  96. <tr>
  97. <td>
  98. <div class="form-group">
  99. <input type="text" class="form-control" value="<?php echo core::convertDate($lastLigne["date"], FALSE) ?>" disabled>
  100. </div>
  101. </td>
  102. <td>
  103. <div class="form-group">
  104. <input type="text" class="form-control" value="<?php echo $lastLigne["label"] ?>" disabled>
  105. </div>
  106. </td>
  107. <td>
  108. <div class="form-group">
  109. <input type="text" class="form-control" value="<?php echo $montant ?>" disabled>
  110. </div>
  111. </td>
  112. <td>
  113. <div class="form-group">
  114. <input type="text" class="form-control" value="<?php echo $type ?>" disabled>
  115. </div>
  116. </td>
  117. <td>
  118. <div class="form-group">
  119. <input type="text" class="form-control" value="<?php echo $lastLigne["solde"] ?>" disabled>
  120. </div>
  121. </td>
  122. <td><span style="color:grey">Dernière ligne</span></td>
  123. </tr>
  124. </table>
  125. </form>
  126. <script>
  127. document.addEventListener("DOMContentLoaded", function () {
  128. const montantInput = document.querySelector('input[name="montant"]');
  129. const typeSelect = document.querySelector('select[name="type"]');
  130. const soldeInput = document.querySelector('input[name="solde"]');
  131. // Valeur initiale du solde (à adapter dynamiquement si besoin)
  132. let soldePrecedent = parseFloat("<?php echo $lastLigne['solde'] ?? 0; ?>");
  133. function updateSolde() {
  134. const montant = parseFloat(montantInput.value);
  135. const type = typeSelect.value;
  136. if (!isNaN(montant) && type) {
  137. let nouveauSolde = soldePrecedent;
  138. if (type === "1") { // Crédit
  139. nouveauSolde += montant;
  140. } else if (type === "2") { // Débit
  141. nouveauSolde -= montant;
  142. }
  143. soldeInput.value = nouveauSolde.toFixed(2);
  144. } else {
  145. soldeInput.value = soldePrecedent.toFixed(2);
  146. }
  147. }
  148. montantInput.addEventListener("input", updateSolde);
  149. typeSelect.addEventListener("change", updateSolde);
  150. });
  151. </script>