{% extends "base_frontoffice.html" %}

{% block content %}



<div class="container mt-4">
    <div class="d-flex justify-content-between align-items-center">
        <h4>FOURNISSEUR</h4>
        {% if not fournisseur %}
        <button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addArticleModal" onclick="clear_form()">Ajouter un caisse</button>
        {% endif %}
    </div>

    <!-- Article Table -->
    <div class="table-responsive mt-4">
        <table class="table table-sm align-items-center justify-content-center mb-0">
            <thead class="table-light">
                <tr>
                    <th>NOM</th>
                    <th>ACHAT</th>
                    <th>REGLEMENT</th>
                    <th>SOLDE</th>
                    <th>ACTION</th>
                </tr>
            </thead>
            <tbody>
                {% if fournisseur %}
                <tr>
                    <td>{{ fournisseur.nom }}</td>
                    <td class="money ">{{ fournisseur.credit }}</td>
                    <td class="money ">{{ fournisseur.debit }}</td>
                    <td class="money ">{{ fournisseur.solde }}</td>
                    <td><span class="d-flex">
                        <a class="btn btn-outline-warning btn-sm" href="/balance/fournisseur?id={{fournisseur.id}}">BALANCE</a>
                    </span>
                    </td>

                </tr>
              
                {% endif %}
            </tbody>
        </table>
    </div>
</div>

<!-- Modal Form -->
<div class="modal fade" id="addArticleModal" tabindex="-1" aria-labelledby="addArticleModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-md">
        <div class="modal-content">
            <form method="POST" action="/add/fournisseur">
                <div class="modal-header">
                    <h5 class="modal-title" id="addArticleModalLabel">Ajouter un fournisseur</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Fermer"></button>
                </div>
                <div class="modal-body">
                    <div class="mb-3">
                        <label for="quantityInput" class="form-label">NOM</label>
                        <input type="text" class="form-control" name="name" autocomplete="off">
                      </div>
                </div>
                <div class="modal-footer">
                    <button type="submit" class="btn btn-warning" >ENREGISTRER</button>
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Annuler</button>
                    
                </div>
            </form>
        </div>
    </div>
</div>
<script>
  window.onload=function(){
    var all_number =$(".money");
    for (let number of all_number){

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

};
</script>
{% endblock %}