{% extends 'base.html.twig' %}
{% block title %}Balance Comptable OHADA
{% endblock %}
{% block body %}
<main id="main" class="main">
<h3>Balance après Inventaires</h3>
<div class="pagetitle">
<div class="header">
<div class=" d-flex justify-content-end">
<div class="btn-group">
<button type="button" class="btn btn-success btn-sm" id="printButton">Imprimé</button>
<button type="button" class="btn btn-success dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
<span class="visually-hidden">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu">
<li>
<a class="dropdown-item" id="printButton">Imprime</a>
</li>
<li><hr class="dropdown-divider"></li>
<li>
<a class="dropdown-item" href="{{ path('generate_pdf') }}">Enregistre en PDF</a>
</li>
</ul>
</div>
</div>
</div>
<!-- End Logo -->
<br>
<table class="table table table-bordered table-striped table-sm">
<thead>
<tr align='center'>
<th rowspan="2">Compte</th>
<th rowspan="2">Intitulé</th>
<th colspan="2">Solde d'ouverture</th>
<th colspan="2">Mouvements</th>
<th colspan="2">Solde de clôture</th>
</tr>
<tr>
<th>Débiteur</th>
<th>Créditeur</th>
<th>Débiteur</th>
<th>Créditeur</th>
<th>Débiteur</th>
<th>Créditeur</th>
</tr>
</thead>
<tbody>
{% set Debit = 0 %}
{% set Credit = 0 %}
{% set Solde = 0 %}
{% set SoldeTotCredit = 0 %}
{% set SoldeTotDebit = 0 %}
{% for compte in comptesComptables %}
<tr>
<td>{{ compte.code }}</td>
<td>{{ compte.libelle }}</td>
<td></td>
<td></td>
<td>{% set Debit = Debit + compte.montantDebit %}
{{ compte.montantDebit }}</td>
<td>{% set Credit = Credit + compte.montantCredit %}
{{ compte.montantCredit }}</td>
{% set Solde = compte.montantDebit - compte.montantCredit %}
{% if Solde < 0 %}
<td>0</td>
<td>
{% set SoldeTotCredit = SoldeTotCredit + Solde %}
{{Solde}}</td>
{% else %}
<td>
{% set SoldeTotDebit = SoldeTotDebit + Solde %}
{{Solde}}</td>
<td>0</td>
{% endif %}
</tr>
{% endfor %}
<tr class='table table-primary' align='center'>
<td colspan="2">TOTAL</td>
<td></td>
<td></td>
<td>{{ Debit }}</td>
<td>{{ Credit }}</td>
<td>{{ SoldeTotDebit }}</td>
<td>{{ SoldeTotCredit }}</td>
</tr>
</tbody>
</table>
<script>
document.getElementById("printButton").addEventListener("click", function () {
window.print();
});
</script>
{% endblock %}