{% extends 'base.html.twig' %}
{% block title %}Consulter entreprise{% endblock %}
{% block stylesheets %}
{{ parent() }}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
<style>
.pdl-details-container {
margin-bottom: 20px;
}
.pdl-select {
width: 100%;
padding: 8px;
border: 1px solid #ced4da;
border-radius: 4px;
margin-bottom: 15px;
}
.pdl-details-compact {
background: #f8f9fa;
border-radius: 4px;
padding: 10px;
margin-bottom: 15px;
}
.pdl-details-row {
display: flex;
flex-wrap: wrap;
gap: 20px;
margin-bottom: 5px;
}
.pdl-detail-item {
display: flex;
align-items: center;
}
.pdl-detail-label {
font-weight: bold;
margin-right: 8px;
color: #495057;
}
.pdl-detail-value {
color: #212529;
}
.pdl-actions {
margin-top: 10px;
display: flex;
gap: 10px;
}
.contracts-section {
margin-top: 20px;
border-top: 1px solid #dee2e6;
padding-top: 10px;
}
.related-contracts {
margin-top: 15px;
background: #fff;
border: 1px solid #dee2e6;
border-radius: 4px;
}
.related-contracts table {
width: 100%;
margin-bottom: 0;
}
.related-contracts th {
background: #f8f9fa;
padding: 8px;
border-bottom: 1px solid #dee2e6;
}
.related-contracts td {
padding: 8px;
border-bottom: 1px solid #dee2e6;
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
#pdl-details, #gas-pdl-details {
animation: fadeIn 0.5s ease-in-out;
}
.error-message {
color: #dc3545;
padding: 10px;
margin-top: 10px;
border-radius: 4px;
background-color: #f8d7da;
border: 1px solid #f5c6cb;
}
</style>
{% endblock %}
{% block body %}
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.12.1/css/jquery.dataTables.css">
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.12.1/js/jquery.dataTables.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
{{ include('_header.html.twig') }}
<a href="{{path('app_entreprise')}}" type="button" class="btn btn-lg btn-danger mt-2" id="backButton">Retour</a>
<a href="{{path('app_entreprise_edit',{'id':entreprise.id})}}" type="button" class="btn btn-lg btn-warning mt-2">Modifier</a>
<h1 class="h3 mb-3 font-weight-normal">Consultation d'une entreprise</h1>
<form>
<div class="form-group row">
<div class="col-sm-3">
<label for="RaisonSociale">Raison sociale</label>
<input type="texte" disabled class="form-control form-control-lg" id="RaisonSociale" value="{{entreprise.raison_sociale}}">
</div>
<div class="col-sm-3">
<label for="Siret">Siret</label>
<input type="texte" disabled class="form-control form-control-lg" id="Siret" value="{{entreprise.siret}}">
</div>
<div class="col-sm-3">
<label for="Naf">Naf</label>
<input type="texte" disabled class="form-control form-control-lg" id="Naf" value="{{entreprise.naf}}">
</div>
<div class="col-sm-3">
<label for="rcs">Rcs</label>
<input type="texte" disabled class="form-control form-control-lg" id="rcs" value="{{entreprise.rcs}}">
</div>
</div>
<div class="form-group row">
<div class="col-sm-3">
<label for="num_voie">N° voie</label>
<input type="texte" disabled class="form-control form-control-lg" id="num_voie" value="{{entreprise.num_voie}}">
</div>
<div class="col-sm-3">
<label for="Adresse">Adresse</label>
<input type="texte" disabled class="form-control form-control-lg" id="Adresse" value="{{entreprise.adresse}}">
</div>
<div class="col-sm-3">
<label for="code_postal">Code Postal</label>
<input type="texte" disabled class="form-control form-control-lg" id="code_postal" value="{{entreprise.code_postal}}">
</div>
<div class="col-sm-3">
<label for="commune">Commune</label>
<input type="texte" disabled class="form-control form-control-lg" id="commune" value="{{entreprise.commune}}">
</div>
</div>
<div class="form-group row">
<div class="col-sm-4">
<label for="Code_Insee">Code Insee</label>
<input type="texte" disabled class="form-control form-control-lg" id="Code_Insee" value="{{entreprise.code_insee}}">
</div>
<div class="col-sm-4">
<label for="Statut">Statut</label>
<input type="texte" disabled class="form-control form-control-lg" id="Statut" value="{{entreprise.statut}}">
</div>
<div class="col-sm-4">
<label for="Utilisateur">Utilisateurs</label>
<input type="texte" disabled class="form-control form-control-lg" id="Statut" value="{% if entreprise.utilisateur is not empty %}{% for username in entreprise.utilisateur %}{{ username }}, {% endfor %}{% else %}Aucun utilisateur{% endif %}">
</div>
</div>
</form>
<hr class="mt-2">
<div class="row">
<div class="col-2">
<div class="list-group" id="list-tab" role="tablist">
<a class="list-group-item list-group-item-action" id="list-notes-list" data-toggle="list" href="#list-notes" role="tab" aria-controls="notes"><span class="badge badge-primary bg-black badge-pill">{{notes|length}}</span> Notes</a>
<a class="list-group-item list-group-item-action" id="list-rappels-list" data-toggle="list" href="#list-rappels" role="tab" aria-controls="rappels"><span class="badge badge-primary bg-black badge-pill">{{rappels|length}}</span> Rappels</a>
<a class="list-group-item list-group-item-action" id="list-electric-meters-list" data-toggle="list" href="#list-electric-meters" role="tab" aria-controls="electric-meters"><span class="badge badge-primary bg-black badge-pill">{{electric_meters|length}}</span> Electric Meters</a>
<a class="list-group-item list-group-item-action" id="list-gas-meters-list" data-toggle="list" href="#list-gas-meters" role="tab" aria-controls="gas-meters"><span class="badge badge-primary bg-black badge-pill">{{gas_meters|length}}</span> Gas Meters</a>
<a class="list-group-item list-group-item-action" id="list-cspes-list" data-toggle="list" href="#list-cspes" role="tab" aria-controls="cspes"><span class="badge badge-primary bg-black badge-pill">{{cspes|length}}</span> CSPE</a>
<a class="list-group-item list-group-item-action" id="list-espace-clients-list" data-toggle="list" href="#list-espace-clients" role="tab" aria-controls="espace-clients"><span class="badge badge-primary bg-black badge-pill">{{espace_clients|length}}</span> Espaces Clients</a>
<a class="list-group-item list-group-item-action" id="list-contacts-list" data-toggle="list" href="#list-contacts" role="tab" aria-controls="contacts"><span class="badge badge-primary bg-black badge-pill">{{contacts|length}}</span> Contacts</a>
<a class="list-group-item list-group-item-action" id="list-contrats-list" data-toggle="list" href="#list-contrats" role="tab" aria-controls="contrats"><span class="badge badge-primary bg-black badge-pill">{{contrats|length}}</span> Contrats</a>
<a class="list-group-item list-group-item-action" id="panel-docs-list" data-toggle="list" href="#panel-docs" role="tab" aria-controls="documents">Génération document</a>
</div>
</div>
<div class="col-10">
<div class="tab-content" id="nav-tabContent">
<div class="tab-pane fade" id="list-notes" role="tabpanel" aria-labelledby="list-notes-list">
<div class="row mb-3">
<a type="button" href="{{path('app_note_add',{'id':entreprise.id})}}" class="btn btn-success">Ajouter une note</a>
</div>
<div id="notes-container">
{% for note in notes %}
<div class="card mb-3">
<div class="card-header d-flex justify-content-between align-items-center">
<span><strong>{{ note.user }}</strong> - {{ note.date_creation }}</span>
<div>
<a href="{{ note.edit_url }}" class="btn btn-sm btn-warning mb-1">Modifier</a>
<a href="{{ note.delete_url }}" class="btn btn-sm btn-danger ">Supprimer</a>
</div>
</div>
<div class="card-body">
<p class="card-text">{{ note.texte }}</p>
</div>
</div>
{% endfor %}
</div>
</div>
<div class="tab-pane fade" id="list-rappels" role="tabpanel" aria-labelledby="list-rappels-list">
<div class="row">
<a type="button" href="{{path('app_rappel_add',{'id':entreprise.id})}}" class="btn btn-success">Ajouter un rappel</a>
</div>
<table id="rappels" class="text-center table table-light table-bordered table-striped" style="width:100%">
<thead>
<tr class="bg-dark">
<th>Titre</th>
<th>Description</th>
<th>Echeance</th>
<th>Compléter</th>
<th>Action</th>
</tr>
</thead>
</table>
</div>
<div class="tab-pane fade" id="list-electric-meters" role="tabpanel" aria-labelledby="list-electric-meters-list">
<div class="row">
<a type="button" href="{{path('app_electric_meter_add',{'id':entreprise.id})}}" class="btn btn-success">Ajouter un Electric Meter</a>
</div>
<div class="pdl-details-container">
<h4>Point de Livraison</h4>
<select class="pdl-select" id="electric-pdl-select">
<option value="">Sélectionnez un PDL</option>
{% for meter in electric_meters %}
<option value="{{ meter.pdl }}" data-id="{{ meter.id }}">{{ meter.pdl }}</option>
{% endfor %}
</select>
<div id="pdl-details" class="pdl-details-compact">
Sélectionnez un PDL pour voir les détails
</div>
</div>
</div>
<div class="tab-pane fade" id="list-gas-meters" role="tabpanel" aria-labelledby="list-gas-meters-list">
<div class="row">
<a type="button" href="{{path('app_gas_meter_add',{'id':entreprise.id})}}" class="btn btn-success">Ajouter un Gas Meter</a>
</div>
<div class="pdl-details-container">
<h4>Point de Livraison</h4>
<select class="pdl-select" id="gas-pdl-select">
<option value="">Sélectionnez un PDL</option>
{% for meter in gas_meters %}
<option value="{{ meter.pdl }}" data-id="{{ meter.id }}">{{ meter.pdl }}</option>
{% endfor %}
</select>
<div id="gas-pdl-details" class="pdl-details-compact">
Sélectionnez un PDL pour voir les détails
</div>
</div>
</div>
<div class="tab-pane fade" id="list-cspes" role="tabpanel" aria-labelledby="list-cspes-list">
<div class="row">
<a type="button" href="{{path('app_cspe_add',{'id':entreprise.id})}}" class="btn btn-success">Ajouter une CSPE</a>
</div>
<table id="cspes" class="text-center table table-light table-bordered table-striped" style="width:100%">
<thead>
<tr class="bg-dark">
<th>Notes</th>
<th>Date</th>
<th>Valeur annuelle</th>
<th>Action</th>
</tr>
</thead>
</table>
</div>
<div class="tab-pane fade" id="list-espace-clients" role="tabpanel" aria-labelledby="list-espace-clients-list">
<div class="row">
<a type="button" href="{{path('app_espace_client_add',{'id':entreprise.id})}}" class="btn btn-success">Ajouter un Espace Client</a>
</div>
<table id="espace_clients" class="text-center table table-light table-bordered table-striped" style="width:100%">
<thead>
<tr class="bg-dark">
<th>Fournisseur</th>
<th>Login</th>
<th>Mdp</th>
<th>Lien</th>
<th>Action</th>
</tr>
</thead>
</table>
</div>
<div class="tab-pane fade" id="list-contacts" role="tabpanel" aria-labelledby="list-contacts-list">
<div class="row">
<a type="button" href="{{path('app_contact_add',{'id':entreprise.id})}}" class="btn btn-success">Ajouter un contact</a>
</div>
<table id="contacts" class="text-center table table-light table-bordered table-striped" style="width:100%">
<thead>
<tr class="bg-dark">
<th>Nom</th>
<th>Prénom</th>
<th>Civilite</th>
<th>Fonction</th>
<th>Téléphone</th>
<th>Mail</th>
<th>Mobile</th>
<th>Action</th>
</tr>
</thead>
<tbody>
{% for contact in contacts %}
<tr>
<td>{{ contact[0] }}</td>
<td>{{ contact[1] }}</td>
<td>{{ contact[2] }}</td>
<td>{{ contact[3] }}</td>
<td>{{ contact[4] }}</td>
<td>{{ contact[5] }}</td>
<td>{{ contact[6] }}</td>
<td>{{ contact[7]|raw }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div class="tab-pane fade" id="list-contrats" role="tabpanel" aria-labelledby="list-contrats-list">
<div class="row mb-3">
<a type="button" href="{{path('app_entreprise_new_contrat', {'id': entreprise.id})}}" class="btn btn-success">Ajouter un contrat</a>
</div>
<table id="contrats" class="text-center table table-light table-bordered table-striped" style="width:100%">
<thead>
<tr class="bg-dark">
<th>Type</th>
<th>Durée (mois)</th>
<th>Valeur</th>
<th>PDL</th>
<th>CAR</th>
<th>Prix moyen</th>
<th>Fournisseur</th>
<th>Date de début</th>
<th>Date de fin</th>
<th>Date signature</th>
<th>Action</th>
</tr>
</thead>
<tbody>
{% for contrat in contrats %}
<tr>
<td>
{% if contrat.pdl in electric_pdls|default([]) %}
Électricité
{% elseif contrat.pdl in gas_pdls|default([]) %}
Gaz
{% else %}
Non défini
{% endif %}
</td>
<td>{{ contrat.duree }}</td>
<td>{{ contrat.valeur }}</td>
<td>{{ contrat.pdl }}</td>
<td>{{ contrat.car }}</td>
<td>{{ contrat.prix_moyen }}</td>
<td>{{ contrat.fournisseur }}</td>
<td>{{ contrat.date_debut ? contrat.date_debut : 'N/A' }}</td>
<td>{{ contrat.date_fin ? contrat.date_fin : 'N/A' }}</td>
<td>{{ contrat.date_signature ? contrat.date_signature : 'N/A' }}</td>
<td>
<a href="{{ path('app_entreprise_edit_contrat', {'entrepriseId': entreprise.id, 'id': contrat.id}) }}" class="btn btn-sm btn-warning mb-1">Modifier</a>
<form method="post" action="{{ path('app_entreprise_delete_contrat', {'entrepriseId': entreprise.id, 'id': contrat.id}) }}" onsubmit="return confirmDelete(event);" style="display: inline-block;">
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ contrat.id) }}">
<button type="submit" class="btn btn-sm btn-danger">Supprimer</button>
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
{{ include('_footer.html.twig') }}
{% endblock %}
{% block javascripts %}
<script>
// Back button handler
document.getElementById('backButton').addEventListener('click', function(e) {
e.preventDefault();
window.location.href = this.getAttribute('href');
});
function confirmDelete(event) {
event.preventDefault();
if (confirm('Êtes-vous sûr de vouloir supprimer ce contrat ?')) {
event.target.submit();
}
}
function formatPDLDetails(details, meterType) {
console.log('Formatting details:', details); // Debug log
let html = '<div class="pdl-details-compact">';
// First row - PDL and dates
html += '<div class="pdl-details-row">';
if (details.PDL) {
html += `
<div class="pdl-detail-item">
<i class="fas fa-fingerprint mr-2"></i>
<span class="pdl-detail-label">PDL:</span>
<span class="pdl-detail-value">${details.PDL}</span>
</div>`;
}
/*if (details.dateDebut) {
html += `
<div class="pdl-detail-item">
<i class="fas fa-calendar-alt mr-2"></i>
<span class="pdl-detail-label">Date début:</span>
<span class="pdl-detail-value">${details.dateDebut}</span>
</div>`;
}
if (details.dateFin) {
html += `
<div class="pdl-detail-item">
<i class="fas fa-calendar-check mr-2"></i>
<span class="pdl-detail-label">Date fin:</span>
<span class="pdl-detail-value">${details.dateFin}</span>
</div>`;
}*/
html += '</div>';
// Second row - Address and supplier
html += '<div class="pdl-details-row">';
if (details.adresseCompteur) {
html += `
<div class="pdl-detail-item">
<i class="fas fa-map-marker-alt mr-2"></i>
<span class="pdl-detail-label">Adresse:</span>
<span class="pdl-detail-value">${details.adresseCompteur}</span>
</div>`;
}
/*if (details.fournisseur) {
html += `
<div class="pdl-detail-item">
<i class="fas fa-industry mr-2"></i>
<span class="pdl-detail-label">Fournisseur:</span>
<span class="pdl-detail-value">${details.fournisseur}</span>
</div>`;
}*/
html += '</div>';
// Third row - Technical details
html += '<div class="pdl-details-row">';
if (details.profil) {
html += `
<div class="pdl-detail-item">
<i class="fas fa-chart-bar mr-2"></i>
<span class="pdl-detail-label">Profil:</span>
<span class="pdl-detail-value">${details.profil}</span>
</div>`;
}
if (details.PS) {
html += `
<div class="pdl-detail-item">
<i class="fas fa-bolt mr-2"></i>
<span class="pdl-detail-label">PS:</span>
<span class="pdl-detail-value">${details.PS}</span>
</div>`;
}
if (details.CAR) {
html += `
<div class="pdl-detail-item">
<i class="fas fa-chart-line mr-2"></i>
<span class="pdl-detail-label">CAR:</span>
<span class="pdl-detail-value">${details.CAR}</span>
</div>`;
}
if (details.prix) {
html += `
<div class="pdl-detail-item">
<i class="fas fa-euro-sign mr-2"></i>
<span class="pdl-detail-label">Prix:</span>
<span class="pdl-detail-value">${formatValue('prix', details.prix)}</span>
</div>`;
}
html += '</div>';
// Add related contracts section
html += '<div class="contracts-section">';
html += '<h5>Contrats liés</h5>';
html += '<div class="related-contracts">';
html += '<table class="table">';
html += '<thead><tr>';
html += '<th>Date de début</th>';
html += '<th>Date de fin</th>';
html += '<th>Date signature</th>';
html += '<th>Fournisseur</th>';
html += '<th>Prix moyen</th>';
html += '</tr></thead>';
html += '<tbody>';
// Filter contracts for this PDL
const relatedContracts = window.contrats.filter(c => c.pdl === details.PDL);
if (relatedContracts.length > 0) {
relatedContracts.forEach(contract => {
html += '<tr>';
html += `<td>${contract.date_debut || ''}</td>`;
html += `<td>${contract.date_fin || ''}</td>`;
html += `<td>${contract.date_signature || ''}</td>`;
html += `<td>${contract.fournisseur || ''}</td>`;
html += `<td>${formatValue('prix', contract.prix_moyen)}</td>`;
html += '</tr>';
});
} else {
html += '<tr><td colspan="5" class="text-center">Aucun contrat lié</td></tr>';
}
html += '</tbody></table>';
html += '</div></div>';
// Actions with meter type and ID
const meterId = meterType === 'gas' ?
$('#gas-pdl-select option:selected').data('id') :
$('#electric-pdl-select option:selected').data('id');
html += `
<div class="pdl-actions">
<a href="{{ path('app_entreprise_new_contrat', {'id': entreprise.id}) }}?meterId=${meterId}&meterType=${meterType}" class="btn btn-sm btn-success">Nouveau contrat</a>
<button class="btn btn-sm btn-warning edit-pdl">Modifier</button>
<button class="btn btn-sm btn-danger delete-pdl">Supprimer</button>`;
// Add study generation buttons
if (meterType === 'electric') {
const studyUrlC5 = "{{ path('app_electric_meter_generate_study', {'pdl': '__PDL__', 'type': 'C5'}) }}".replace('__PDL__', details.PDL);
const studyUrlC4 = "{{ path('app_electric_meter_generate_study', {'pdl': '__PDL__', 'type': 'C4'}) }}".replace('__PDL__', details.PDL);
html += `
<a href="${studyUrlC5}" class="btn btn-sm btn-info">
Générer étude C5
</a>
<a href="${studyUrlC4}" class="btn btn-sm btn-info">
Générer étude C4/C3/C2
</a>`;
} else if (meterType === 'gas') {
const studyUrl = "{{ path('app_gas_meter_pre_etude_t2', {'pdl': '__PDL__'}) }}".replace('__PDL__', details.PDL);
html += `
<a href="${studyUrl}" class="btn btn-sm btn-info">
Générer étude T2
</a>`;
}
html += `</div>`;
html += '</div>';
return html;
}
function formatValue(key, value) {
if (key.toLowerCase().includes('prix') && !isNaN(value)) {
return new Intl.NumberFormat('fr-FR', { style: 'currency', currency: 'EUR' }).format(value);
}
if (typeof value === 'boolean') {
return value ? '<span class="text-success">Actif</span>' : '<span class="text-danger">Inactif</span>';
}
return value || '';
}
$(document).ready(function() {
// Store contracts data globally
window.contrats = {{ contrats|json_encode|raw }};
// Common DataTable configuration
const commonConfig = {
"language": {
"url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/French.json"
},
"pageLength": 10,
"destroy": true
};
// Handle automatic PDL selection when tabs are clicked
$('#list-electric-meters-list').on('click', function() {
const select = $('#electric-pdl-select');
if (select.find('option').length === 2) { // 2 because there's always a default empty option
select.val(select.find('option:last').val()).trigger('change');
}
});
$('#list-gas-meters-list').on('click', function() {
const select = $('#gas-pdl-select');
if (select.find('option').length === 2) { // 2 because there's always a default empty option
select.val(select.find('option:last').val()).trigger('change');
}
});
// Initialize tables that have data in tbody
$('#contacts, #contrats').each(function() {
if (!$.fn.DataTable.isDataTable(this)) {
$(this).DataTable({
...commonConfig,
"order": [[0, 'asc']]
});
}
});
// Initialize tables that need data from variables
const tableData = {
rappels: {{ rappels|json_encode|raw }},
cspes: {{ cspes|json_encode|raw }},
espace_clients: {{ espace_clients|json_encode|raw }}
};
Object.entries(tableData).forEach(([tableId, data]) => {
const table = $(`#${tableId}`);
if (!$.fn.DataTable.isDataTable(table)) {
table.DataTable({
...commonConfig,
data: data
});
}
});
// Electric Meters PDL selection
$('#electric-pdl-select').change(function() {
var pdl = $(this).val();
if (!pdl) {
$('#pdl-details').html('Sélectionnez un PDL pour voir les détails');
return;
}
$.ajax({
url: '{{ path('app_electric_meter_details', {'id': entreprise.id}) }}',
method: 'GET',
data: { pdl: pdl },
success: function(response) {
console.log('Electric meter response:', response);
$('#pdl-details').html(formatPDLDetails(response, 'electric'));
initializePDLActions('electric', $('#electric-pdl-select option:selected').data('id'));
},
error: function(xhr, status, error) {
console.error('Error details:', {
status: xhr.status,
statusText: xhr.statusText,
responseText: xhr.responseText
});
$('#pdl-details').html(`<div class="error-message">Erreur lors du chargement des détails: ${error}</div>`);
}
});
});
// Gas Meters PDL selection
$('#gas-pdl-select').change(function() {
var pdl = $(this).val();
if (!pdl) {
$('#gas-pdl-details').html('Sélectionnez un PDL pour voir les détails');
return;
}
$.ajax({
url: '{{ path('app_gas_meter_details', {'id': entreprise.id}) }}',
method: 'GET',
data: { pdl: pdl },
success: function(response) {
console.log('Gas meter response:', response);
$('#gas-pdl-details').html(formatPDLDetails(response, 'gas'));
initializePDLActions('gas', $('#gas-pdl-select option:selected').data('id'));
},
error: function(xhr, status, error) {
console.error('Error details:', {
status: xhr.status,
statusText: xhr.statusText,
responseText: xhr.responseText
});
$('#gas-pdl-details').html(`<div class="error-message">Erreur lors du chargement des détails: ${error}</div>`);
}
});
});
function initializePDLActions(type, id) {
// Handle edit PDL
$('.edit-pdl').click(function() {
var url = type === 'electric'
? '{{ path('app_electric_meter_edit', {'id': 'METER_ID'}) }}'
: '{{ path('app_gas_meter_edit', {'id': 'METER_ID'}) }}';
url = url.replace('METER_ID', id);
window.location.href = url;
});
// Handle delete PDL
$('.delete-pdl').click(function() {
if (confirm('Êtes-vous sûr de vouloir supprimer ce PDL ?')) {
var url = type === 'electric'
? '{{ path('app_electric_meter_suppr', {'id': 'METER_ID'}) }}'
: '{{ path('app_gas_meter_suppr', {'id': 'METER_ID'}) }}';
url = url.replace('METER_ID', id);
$.ajax({
url: url,
method: 'POST',
data: {
'_token': '{{ csrf_token('delete-meter') }}'
},
success: function() {
location.reload();
},
error: function(xhr, status, error) {
console.error('Error deleting meter:', error);
alert('Erreur lors de la suppression du compteur');
}
});
}
});
}
});
</script>
{% endblock %}