{% extends 'base.html.twig' %}
{% block title %}Facturation{% endblock %}
{% block body %}
<ol class="breadcrumb">
<li>
<i class="clip-grid-6"></i>
<a href="#">
Factures
</a>
</li>
<li class="active">
Liste
</li>
</ol>
<div class="page-header">
<h1>Gestion des factures</h1>
<button class="btn btn-success" data-toggle="modal" data-target="#generate">Génération facture</button>
<button class="btn btn-success" data-toggle="modal" data-target="#validate">Validation facture</button>
<button class="btn btn-success" data-toggle="modal" data-target="#send">Envoi facture</button>
<button class="btn btn-success" data-toggle="modal" data-target="#encaissement">Encaisser factures</button>
<button class="btn btn-success" data-toggle="modal" data-target="#sepa">SEPA</button>
<button class="btn btn-success" data-toggle="modal" data-target="#relance">Relance factures</button>
<button class="btn btn-success" data-toggle="modal" data-target="#lot">LOT FACTURES</button>
<button class="btn btn-success" data-toggle="modal" data-target="#easycollect">ENVOI FACTURE EASYCOLLCET</button>
<button id="btn-rendre-contencieux" class="btn btn-success">Passer les factures en contentieux</button>
</div>
<div class="row">
{{ form_start(formFilter) }}
<div class="col-md-12">
<div class="col-md-2">
{{ form_row(formFilter.company) }}
</div>
<div class="col-md-2">
{{ form_row(formFilter.site) }}
</div>
<div class="col-md-2">
{{ form_row(formFilter.statusSite) }}
</div>
</div>
<div class="col-md-12">
<div class="col-md-3">
{{ form_row(formFilter.numFacture) }}
</div>
<div class="col-md-2">
{{ form_row(formFilter.client) }}
</div>
<div class="col-md-3">
{{ form_row(formFilter.status) }}
</div>
</div>
<div class="col-md-2">
{{ form_row(formFilter.dateDebut) }}
</div>
<div class="col-md-2">
{{ form_row(formFilter.dateFin) }}
</div>
<div class="col-md-2" style="padding-top: 23px;">
<button type="submit" class="btn btn-success">Valider</button>
</div>
{{ form_end(formFilter) }}
</div>
<div class="row">
<div class="col-md-12">
<!-- start: BASIC TABLE PANEL -->
<div class="panel panel-default">
<div class="panel-heading">
Factures
<div class="panel-tools">
</div>
</div>
<div class="panel-body">
<table class="table table-hover" id="sample-table-1">
<thead>
<tr>
<th><input type="checkbox" id="select-all"></th>
<th data-sort-default>Numéro facture</th>
<th>Date</th>
<th>Nom du client</th>
<th>HT</th>
<th>TVA</th>
<th>Montant TTC</th>
<th>Solde</th>
<th>Statut facture</th>
<th>Type facture (FDRV / FFDP)</th>
<th>Mode de réglement</th>
<th>Site</th>
<th>N°</th>
<th></th>
</tr>
</thead>
<tbody>
{% for billing in billings %}
<tr>
<!-- Add Checkbox for each row -->
<td><input type="checkbox" class="billing-checkbox" data-id="{{ billing.id }}"></td>
<td>{{ billing.code }}</td>
<td>{{ billing.dateBilling|date('d/m/Y') }}</td>
<td>
{% if billing.client %}
<a href="{{ path('client_edit', {id: billing.client.id }) }}" target="_blank">
<b>{{ billing.client.lastname }} {{ billing.client.firstname }}</b>
</a>
{% endif %}
</td>
<td style="text-align: right">
{{ billing.ht|number_format(2, '.', ',') }}
</td>
<td style="text-align: right">
{{ (billing.ht * (20/100))|number_format(2, '.', ',') }}
</td>
<td style="text-align: right">
<b>{{ billing.ttc }}</b>
</td>
<td style="text-align: right"> {{ billing.solde|number_format(2, '.', ',') }}</td>
<td>
{% if billing.status == 'a_regle' %}
A régler
{% else %}
{{ billing.status|capitalize }}
{% endif %}
</td>
<td>{{ billing.modeFacturation }}</td>
<td>{% if billing.reglement %}{{ billing.reglement.mode }}{%endif%}</td>
<td> {% if billing.client %}
{% if billing.client.site %}
{% if billing.client.site.status == "closed" %}
<span style="color: red;">{{ billing.client.site.name }}</span>
{% else %}
{{ billing.client.site.name }}
{% endif %}
{%endif%}
{%endif%}</td>
<td>{% if billing.reglement %}
<a href="{{ path('reglement_edit', {'id': billing.reglement.id}) }}" {% if billing.reglement.status == 'Annulé' %} style="color:red;text-decoration:line-through;"{% endif %}>{{ billing.reglement.id }}</a>{% endif %}</td>
<td>
<a href="{{ path('billing_edit', {'id': billing.id}) }}">Edition</a>
</td>
</tr>
{% else %}
<tr>
<td colspan="4">Aucun enregistrement trouvé</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
<!-- end: BASIC TABLE PANEL -->
</div>
</div>
{% include 'billing/generate_popup.html.twig' %}
{% include 'billing/validate_popup.html.twig' %}
{% include 'billing/send_popup.html.twig' %}
{% include 'billing/encaissement.html.twig' %}
{% include 'billing/sepa.html.twig' %}
{% include 'billing/relance.html.twig' %}
{% include 'billing/lot.html.twig' %}
{% include 'billing/easycollect.html.twig' %}
<style>
.select2-container {
display: block;
}
</style>
{% endblock %}
{% block javascripts %}
{{ parent() }}
<script type="text/javascript">
$('#lot_site').select2( {width: '100%' });
$('#lot_client').select2( {width: '100%' });
$('#filter_status').select2( {width: '250px' });
$('#filter_site').select2({
width: '100%'
});
$('#generate_site').select2({
width: '100%'
});
$('#validate_site').select2({
width: '100%'
});
$('#send_site').select2({
width: '100%'
});
$('#relance_site').select2({
width: '100%'
});
$('#filter_dateDebut').flatpickr({
altInput: true,
'dateFormat' : 'Y-m-d',
"locale": "fr",
"altFormat": "d-m-Y",
});
$('#filter_dateFin').flatpickr({
altInput: true,
'dateFormat' : 'Y-m-d',
"locale": "fr",
"altFormat": "d-m-Y",
});
$('.flatpicker').flatpickr({
altInput: true,
'dateFormat' : 'Y-m-d',
"locale": "fr",
"altFormat": "d-m-Y",
});
$('#generate').on('shown.bs.modal', function () {
$('#generate_start').flatpickr({
altInput: true,
'dateFormat' : 'Y-m-d',
"locale": "fr",
"altFormat": "d-m-Y",
});
$('#generate_end').flatpickr({
altInput: true,
'dateFormat' : 'Y-m-d',
"locale": "fr",
"altFormat": "d-m-Y",
});
});
$('#send').on('shown.bs.modal', function () {
$('#send_start').flatpickr({
altInput: true,
'dateFormat' : 'Y-m-d',
"locale": "fr",
"altFormat": "d-m-Y",
});
$('#send_end').flatpickr({
altInput: true,
'dateFormat' : 'Y-m-d',
"locale": "fr",
"altFormat": "d-m-Y",
});
});
$('#easycollect').on('shown.bs.modal', function () {
$('#easy_collect_start').flatpickr({
altInput: true,
'dateFormat' : 'Y-m-d',
"locale": "fr",
"altFormat": "d-m-Y",
});
$('#easy_collect_end').flatpickr({
altInput: true,
'dateFormat' : 'Y-m-d',
"locale": "fr",
"altFormat": "d-m-Y",
});
});
$('#validate').on('shown.bs.modal', function () {
$('#validate_start').flatpickr({
altInput: true,
'dateFormat' : 'Y-m-d',
"locale": "fr",
"altFormat": "d-m-Y",
});
$('#validate_end').flatpickr({
altInput: true,
'dateFormat' : 'Y-m-d',
"locale": "fr",
"altFormat": "d-m-Y",
});
});
new Tablesort(document.getElementById('sample-table-1'));
$('.encaissement-checkbox').on('change', function (e) {
let total = 0;
$('.encaissement-checkbox').each(function (e) {
if($(this).is(":checked")){
total += parseFloat($(this).data('solde'));
}
});
total = Math.round(total * 100) / 100;
$('.total').html(total);
});
$('.encaissement-all').on('change', function (e) {
let total = 0;
var value = $(this).is(":checked");
$('.encaissement-checkbox').each(function (e) {
$('.encaissement-checkbox').prop('checked', value);
if($(this).is(":checked")){
total += parseFloat($(this).data('solde'));
}
});
if(value == true) {
total = Math.round(total * 100) / 100;
$('.total').html(total);
}
});
$('#relance_start').flatpickr({
altInput: true,
'dateFormat' : 'Y-m-d',
"locale": "fr",
"altFormat": "d-m-Y",
});
$('#relance_end').flatpickr({
altInput: true,
'dateFormat' : 'Y-m-d',
"locale": "fr",
"altFormat": "d-m-Y",
});
$('#validate_dateBilling').flatpickr({
altInput: true,
'dateFormat' : 'Y-m-d',
"locale": "fr",
"altFormat": "d-m-Y",
});
$('#select-all').click(function () {
$('.billing-checkbox').prop('checked', this.checked);
});
$('.billing-checkbox').change(function () {
if ($('.billing-checkbox:checked').length === $('.billing-checkbox').length) {
$('#select-all').prop('checked', true);
} else {
$('#select-all').prop('checked', false);
}
});
$('#sepa').on('shown.bs.modal', function () {
var flatpickrInstance = flatpickr('#payment-date', {
dateFormat: 'd-m-Y',
locale: 'fr'
});
var today = new Date();
flatpickrInstance.setDate(today);
});
$('#btn-rendre-contencieux').click(function () {
let selectedIds = [];
$('.billing-checkbox:checked').each(function () {
selectedIds.push($(this).data('id'));
});
if (selectedIds.length > 0) {
$.ajax({
url: '{{ path('app_billing_rendrecontencieux') }}',
method: 'POST',
data: {ids: selectedIds},
success: function (response) {
alert('Factures marquées comme contentieuses avec succès.');
location.reload();
},
error: function (xhr, status, error) {
alert('Erreur lors du traitement des factures.');
}
});
} else {
alert('Veuillez sélectionner au moins une facture.');
}
});
</script>
{% endblock %}