{% extends "base_frontoffice.html" %}

{% block content %}



<div class="container mt-4">
    <h4>Journal Caisse</h4>
    <div class="d-flex justify-content-between align-items-center">
        <div class="input-group mb-1">
          <span class="input-group-text bg-secondary text-light" id="basic-addon1">Caisse: </span>
              <select class="form-control "  name="client" onchange="selectCaisse(this)">
                <option value="{{caisse.id}}">{{caisse.name}}</option>
                {% for caisse in all_caisse %}
                  <option value="{{caisse.id}}" data-name="{{caisse.name}}" >{{caisse.name}}</option>
                {% endfor %}
              </select>
          </div>
          <div class="input-group mb-1">
            <ul class="list-group " >
            <li class="list-group-item d-flex justify-content-between">
              <span >SOLDE: </span>
              <strong class="money">{{caisse.solde_val_html}}</strong>
            </li>
            </ul>
        </div>
    </div>
        
    <div class="d-flex justify-content-between align-items-center">

    <input type="text " id="tableSearch" class="form-control  w-50" placeholder="Recherche ..." >

    </div>
    <!-- Article Table -->
    <div class="table-responsive mt-4">
        <table class="table table-sm align-items-center justify-content-center mb-0" id="commandeTable">
            <thead class="table-light">
                <tr>
                    <th>Date</th>
                    <th>Affectation</th>
                    <th>RECETTE</th>
                    <th>DEPENSE</th>
                    <th>SOLDE</th>
                    <th>REF</th>
                    
                </tr>
            </thead>
            <tbody>
                {% for journal in all_journal %}
                <tr data-id="{{journal.id}}">
                    <td>{{ journal.date_str }}</td>
                    <td>{{ journal.affectation }}</td>
                    <td class="money">{{ journal.entree }}</td>
                    <td class="money">{{ journal.sortie }}</td>
                    <td class="money">{{ journal.solde }}</td>
                    <td>{{ journal.ref }}</td>
                </tr>
              
                {% endfor %}
            </tbody>
        </table>
    </div>
</div>

<script>
document.getElementById("tableSearch").addEventListener("keyup", function () {
  const input = this.value.toLowerCase();
  const rows = document.querySelectorAll("#commandeTable tbody tr");

  rows.forEach(row => {
    const rowText = row.innerText.toLowerCase();
    row.style.display = rowText.includes(input) ? "" : "none";
  });
});
</script>
<script>
  window.onload=function(){
    var all_number =$(".money");
    for (let number of all_number){

      number.textContent=parseFloat(number.textContent).toLocaleString("fr-FR", {minimumFractionDigits:2});
    };

};


function selectCaisse(self){

    window.location.href="/journal/caisse?cid="+self.value;
}
</script>
{% endblock %}