{% extends 'base.html.twig' %}
{% block title %}Consulter entreprise{% endblock %}
{% block stylesheets %}
{{ parent() }}
{% endblock %}
{% block body %}
<div class="entreprise-layout">
<div class="entreprise-sidebar">
<h5>Informations</h5>
<p><strong>SIRET :</strong> {{ entreprise.siret }}</p>
<p><strong>NAF :</strong> {{ entreprise.naf }}</p>
<p><strong>RCS :</strong> {{ entreprise.rcs }}</p>
<p><strong>Adresse :</strong><br>{{ entreprise.num_voie }} {{ entreprise.adresse }}<br>{{ entreprise.code_postal }} {{ entreprise.commune }}</p>
<p><strong>Code INSEE :</strong> {{ entreprise.code_insee }}</p>
<p><strong>Statut :</strong> {{ entreprise.Statut }}</p>
<p><strong>Utilisateurs :</strong><br>
{% if entreprise.utilisateur is not empty %}
{% for username in entreprise.utilisateur %}{{ username }}<br>{% endfor %}
{% else %}Aucun utilisateur{% endif %}
</p>
</div>
<div class="entreprise-content">
<div class="entreprise-header">
<h1>{{ entreprise.raison_sociale }}</h1>
<div class="d-flex gap-2">
<a href="{{ path('app_entreprise') }}" class="btn btn-danger">Retour</a>
<a href="{{ path('app_entreprise_edit', {'id': entreprise.id}) }}" class="btn btn-warning">Modifier</a>
</div>
</div>
<div class="entreprise-tabs list-group list-group-horizontal" id="list-tab" role="tablist">
<a class="list-group-item list-group-item-action active" id="list-notes-list" data-bs-toggle="list" href="#list-notes" role="tab" aria-controls="notes">
Notes
<span class="badge badge-primary bg-black badge-pill">{{notes|length}}</span>
</a>
<a class="list-group-item list-group-item-action" id="list-rappels-list" data-bs-toggle="list" href="#list-rappels" role="tab" aria-controls="rappels">
Rappels
<span class="badge badge-primary bg-black badge-pill">{{rappels|length}}</span>
</a>
<a class="list-group-item list-group-item-action" id="list-electric-meters-list" data-bs-toggle="list" href="#list-electric-meters" role="tab" aria-controls="electric-meters">
Electric
<span class="badge badge-primary bg-black badge-pill">{{electric_meters|length}}</span>
</a>
<a class="list-group-item list-group-item-action" id="list-gas-meters-list" data-bs-toggle="list" href="#list-gas-meters" role="tab" aria-controls="gas-meters">
Gas
<span class="badge badge-primary bg-black badge-pill">{{gas_meters|length}}</span>
</a>
<a class="list-group-item list-group-item-action" id="list-cspes-list" data-bs-toggle="list" href="#list-cspes" role="tab" aria-controls="cspes">
CSPE
<span class="badge badge-primary bg-black badge-pill">{{cspes|length}}</span>
</a>
<a class="list-group-item list-group-item-action" id="list-contacts-list" data-bs-toggle="list" href="#list-contacts" role="tab" aria-controls="contacts">
Contacts
<span class="badge badge-primary bg-black badge-pill">{{contacts|length}}</span>
</a>
<a class="list-group-item list-group-item-action" id="list-contrats-list" data-bs-toggle="list" href="#list-contrats" role="tab" aria-controls="contrats">
Contrats
<span class="badge badge-primary bg-black badge-pill">{{contrats|length}}</span>
</a>
<a class="list-group-item list-group-item-action" id="list-espace-clients-list" data-bs-toggle="list" href="#list-espace-clients" role="tab" aria-controls="espace-clients">
Espaces Clients
{# <span class="badge badge-primary bg-black badge-pill">{{espace_clients|length}}</span> #}
</a>
<a class="list-group-item list-group-item-action" id="panel-docs-list" data-bs-toggle="list" href="#panel-docs" role="tab" aria-controls="documents">
Génération document
</a>
</div>
<div class="tab-content" id="nav-tabContent">
<div class="tab-pane fade show active" 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" title="Modifier">
<i class="fa-solid fa-pen"></i>
</a>
<a href="{{ note.delete_url }}" class="btn btn-sm btn-danger" title="Supprimer">
<i class="fa-solid fa-trash"></i>
</a>
</div>
</div>
<div class="card-body">
<p class="card-text note-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" style="width:100%">
<thead>
<tr class="">
<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" style="width:100%">
<thead>
<tr class="">
<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" style="width:100%">
<thead>
<tr class="">
<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" style="width:100%">
<thead>
<tr class="">
<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" style="width:100%">
<thead>
<tr class="">
<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 class="contrat-actions">
<a
href="{{ path('app_entreprise_edit_contrat', {'entrepriseId': entreprise.id, 'id': contrat.id}) }}"
class="btn btn-sm btn-warning"
title="Modifier"
aria-label="Modifier"
>
<i class="fa-solid fa-pen"></i>
</a>
<form
method="post"
action="{{ path('app_entreprise_delete_contrat', {'entrepriseId': entreprise.id, 'id': contrat.id}) }}"
onsubmit="return confirmDelete(event);"
class="d-inline-block"
>
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ contrat.id) }}">
<button
type="submit"
class="btn btn-sm btn-danger"
title="Supprimer"
aria-label="Supprimer"
>
<i class="fa-solid fa-trash"></i>
</button>
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
{{ include('_footer.html.twig') }}
{% endblock %}
{% block javascripts %}
{{ parent() }}
<script>
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 = '';
// 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>`;
}
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>`;
}
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__', encodeURIComponent(details.PDL));
const studyUrlC4 = "{{ path('app_electric_meter_generate_study', {'pdl': '__PDL__', 'type': 'C4'}) }}".replace('__PDL__', encodeURIComponent(details.PDL));
const studyUrlC3 = "{{ path('app_electric_meter_generate_study', {'pdl': '__PDL__', 'type': 'C3'}) }}".replace('__PDL__', encodeURIComponent(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
</a>
<a href="${studyUrlC3}" class="btn btn-sm btn-info">
Générer étude C3 C2 C1
</a>`;
} else if (meterType === 'gas') {
const studyUrl = "{{ path('app_gas_meter_pre_etude_t2', {'pdl': '__PDL__'}) }}".replace('__PDL__', encodeURIComponent(details.PDL));
html += `
<a href="${studyUrl}" class="btn btn-sm btn-info">
Générer étude Gaz
</a>`;
}
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 }}
};
['rappels', 'cspes', 'espace_clients'].forEach((tableId) => {
const table = $('#' + tableId);
if (table.length && !$.fn.DataTable.isDataTable(table[0])) {
table.DataTable({
...commonConfig,
data: tableData[tableId] || [],
searching: true,
paging: true,
info: true
});
}
});
// Electric Meters PDL selection
$('#electric-pdl-select').change(function() {
var pdl = $(this).val();
console.log('CHANGE electric déclenché, pdl =', pdl);
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();
console.log('CHANGE gas déclenché, pdl =', pdl);
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');
}
});
}
});
}
$('a[data-bs-toggle="list"]').on('shown.bs.tab', function () {
$($.fn.dataTable.tables(true)).DataTable().columns.adjust();
});
});
</script>
{% endblock %}