templates/entreprise/details.html.twig line 1

Open in your IDE?
  1. {% extends 'base.html.twig' %}
  2. {% block title %}Consulter entreprise{% endblock %}
  3. {% block stylesheets %}
  4.     {{ parent() }}
  5. {% endblock %}
  6. {% block body %}
  7. <div class="entreprise-layout">
  8.     <div class="entreprise-sidebar">
  9.         <h5>Informations</h5>
  10.         <p><strong>SIRET :</strong> {{ entreprise.siret }}</p>
  11.         <p><strong>NAF :</strong> {{ entreprise.naf }}</p>
  12.         <p><strong>RCS :</strong> {{ entreprise.rcs }}</p>
  13.         <p><strong>Adresse :</strong><br>{{ entreprise.num_voie }} {{ entreprise.adresse }}<br>{{ entreprise.code_postal }} {{ entreprise.commune }}</p>
  14.         <p><strong>Code INSEE :</strong> {{ entreprise.code_insee }}</p>
  15.         <p><strong>Statut :</strong> {{ entreprise.Statut }}</p>
  16.         <p><strong>Utilisateurs :</strong><br>
  17.             {% if entreprise.utilisateur is not empty %}
  18.                 {% for username in entreprise.utilisateur %}{{ username }}<br>{% endfor %}
  19.             {% else %}Aucun utilisateur{% endif %}
  20.         </p>
  21.     </div>
  22.     <div class="entreprise-content">
  23.         <div class="entreprise-header">
  24.             <h1>{{ entreprise.raison_sociale }}</h1>
  25.             <div class="d-flex gap-2">
  26.                 <a href="{{ path('app_entreprise') }}" class="btn btn-danger">Retour</a>
  27.                 <a href="{{ path('app_entreprise_edit', {'id': entreprise.id}) }}" class="btn btn-warning">Modifier</a>
  28.             </div>
  29.         </div>
  30.         <div class="entreprise-tabs list-group list-group-horizontal" id="list-tab" role="tablist">
  31.             <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">
  32.                 Notes
  33.                 <span class="badge badge-primary bg-black badge-pill">{{notes|length}}</span>
  34.             </a>
  35.             <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">
  36.                  Rappels
  37.                 <span class="badge badge-primary bg-black badge-pill">{{rappels|length}}</span> 
  38.             </a>
  39.             <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">
  40.                  Electric
  41.                 <span class="badge badge-primary bg-black badge-pill">{{electric_meters|length}}</span> 
  42.             </a>
  43.             <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">
  44.                  Gas
  45.                 <span class="badge badge-primary bg-black badge-pill">{{gas_meters|length}}</span>
  46.             </a>
  47.             <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">
  48.                  CSPE
  49.                 <span class="badge badge-primary bg-black badge-pill">{{cspes|length}}</span>
  50.             </a>
  51.             <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">
  52.                  Contacts
  53.                 <span class="badge badge-primary bg-black badge-pill">{{contacts|length}}</span>
  54.             </a>
  55.             <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">
  56.                  Contrats
  57.                 <span class="badge badge-primary bg-black badge-pill">{{contrats|length}}</span>
  58.             </a>
  59.             <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">
  60.                  Espaces Clients
  61.                 {# <span class="badge badge-primary bg-black badge-pill">{{espace_clients|length}}</span> #}
  62.             </a>
  63.             <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">
  64.                 Génération document
  65.             </a>
  66.         </div>
  67.         <div class="tab-content" id="nav-tabContent">
  68.             <div class="tab-pane fade show active" id="list-notes" role="tabpanel" aria-labelledby="list-notes-list">
  69.                 <div class="row mb-3">
  70.                     <a type="button" href="{{path('app_note_add',{'id':entreprise.id})}}" class="btn btn-success">Ajouter une note</a>
  71.                 </div>
  72.                 <div id="notes-container">
  73.                     {% for note in notes %}
  74.                         <div class="card mb-3">
  75.                             <div class="card-header d-flex justify-content-between align-items-center">
  76.                                 <span><strong>{{ note.user }}</strong> - {{ note.date_creation }}</span>
  77.                                 <div>
  78.                                     <a href="{{ note.edit_url }}" class="btn btn-sm btn-warning" title="Modifier">
  79.                                         <i class="fa-solid fa-pen"></i>
  80.                                     </a>
  81.                                     <a href="{{ note.delete_url }}" class="btn btn-sm btn-danger" title="Supprimer">
  82.                                         <i class="fa-solid fa-trash"></i>
  83.                                     </a>
  84.                                 </div>
  85.                             </div>
  86.                             <div class="card-body">
  87.                                 <p class="card-text note-text">{{ note.texte }}</p>
  88.                             </div>
  89.                         </div>
  90.                     {% endfor %}
  91.                 </div>
  92.             </div>
  93.             <div class="tab-pane fade" id="list-rappels" role="tabpanel" aria-labelledby="list-rappels-list">
  94.                 <div class="row">
  95.                     <a type="button" href="{{path('app_rappel_add',{'id':entreprise.id})}}" class="btn btn-success">Ajouter un rappel</a>
  96.                 </div>
  97.                 <table id="rappels" class="text-center table" style="width:100%">
  98.                     <thead>
  99.                         <tr class="">
  100.                             <th>Titre</th>
  101.                             <th>Description</th>
  102.                             <th>Echeance</th>
  103.                             <th>Compléter</th>
  104.                             <th>Action</th>
  105.                         </tr>
  106.                     </thead>
  107.                 </table>
  108.             </div>
  109.             <div class="tab-pane fade" id="list-electric-meters" role="tabpanel" aria-labelledby="list-electric-meters-list">
  110.                 <div class="row">
  111.                     <a type="button" href="{{path('app_electric_meter_add',{'id':entreprise.id})}}" class="btn btn-success">Ajouter un Electric Meter</a>
  112.                 </div>
  113.                 <div class="pdl-details-container">
  114.                     <h4>Point de Livraison</h4>
  115.                     <select class="pdl-select" id="electric-pdl-select">
  116.                         <option value="">Sélectionnez un PDL</option>
  117.                         {% for meter in electric_meters %}
  118.                             <option value="{{ meter.pdl }}" data-id="{{ meter.id }}">{{ meter.pdl }}</option>
  119.                         {% endfor %}
  120.                     </select>
  121.                     <div id="pdl-details" class="pdl-details-compact">
  122.                         Sélectionnez un PDL pour voir les détails
  123.                     </div>
  124.                 </div>
  125.             </div>
  126.             <div class="tab-pane fade" id="list-gas-meters" role="tabpanel" aria-labelledby="list-gas-meters-list">
  127.                 <div class="row">
  128.                     <a type="button" href="{{path('app_gas_meter_add',{'id':entreprise.id})}}" class="btn btn-success">Ajouter un Gas Meter</a>
  129.                 </div>
  130.                 <div class="pdl-details-container">
  131.                     <h4>Point de Livraison</h4>
  132.                     <select class="pdl-select" id="gas-pdl-select">
  133.                         <option value="">Sélectionnez un PDL</option>
  134.                         {% for meter in gas_meters %}
  135.                             <option value="{{ meter.pdl }}" data-id="{{ meter.id }}">{{ meter.pdl }}</option>
  136.                         {% endfor %}
  137.                     </select>
  138.                     <div id="gas-pdl-details" class="pdl-details-compact">
  139.                         Sélectionnez un PDL pour voir les détails
  140.                     </div>
  141.                 </div>
  142.             </div>
  143.             <div class="tab-pane fade" id="list-cspes" role="tabpanel" aria-labelledby="list-cspes-list">
  144.                 <div class="row">
  145.                     <a type="button" href="{{path('app_cspe_add',{'id':entreprise.id})}}" class="btn btn-success">Ajouter une CSPE</a>
  146.                 </div>
  147.                 <table id="cspes" class="text-center table" style="width:100%">
  148.                     <thead>
  149.                         <tr class="">
  150.                             <th>Notes</th>
  151.                             <th>Date</th>
  152.                             <th>Valeur annuelle</th>
  153.                             <th>Action</th>
  154.                         </tr>
  155.                     </thead>
  156.                 </table>
  157.             </div>
  158.             <div class="tab-pane fade" id="list-espace-clients" role="tabpanel" aria-labelledby="list-espace-clients-list">
  159.                 <div class="row">
  160.                     <a type="button" href="{{path('app_espace_client_add',{'id':entreprise.id})}}" class="btn btn-success">Ajouter un Espace Client</a>
  161.                 </div>
  162.                 <table id="espace_clients" class="text-center table" style="width:100%">
  163.                     <thead>
  164.                         <tr class="">
  165.                             <th>Fournisseur</th>
  166.                             <th>Login</th>
  167.                             <th>Mdp</th>
  168.                             <th>Lien</th>
  169.                             <th>Action</th>
  170.                         </tr>
  171.                     </thead>
  172.                 </table>
  173.             </div>
  174.             <div class="tab-pane fade" id="list-contacts" role="tabpanel" aria-labelledby="list-contacts-list">
  175.                 <div class="row">
  176.                     <a type="button" href="{{path('app_contact_add',{'id':entreprise.id})}}" class="btn btn-success">Ajouter un contact</a>
  177.                 </div>
  178.                 <table id="contacts" class="text-center table" style="width:100%">
  179.                     <thead>
  180.                         <tr class="">
  181.                             <th>Nom</th>
  182.                             <th>Prénom</th>
  183.                             <th>Civilite</th>
  184.                             <th>Fonction</th>
  185.                             <th>Téléphone</th>
  186.                             <th>Mail</th>
  187.                             <th>Mobile</th>
  188.                             <th>Action</th>
  189.                         </tr>
  190.                     </thead>
  191.                     <tbody>
  192.                         {% for contact in contacts %}
  193.                             <tr>
  194.                                 <td>{{ contact[0] }}</td>
  195.                                 <td>{{ contact[1] }}</td>
  196.                                 <td>{{ contact[2] }}</td>
  197.                                 <td>{{ contact[3] }}</td>
  198.                                 <td>{{ contact[4] }}</td>
  199.                                 <td>{{ contact[5] }}</td>
  200.                                 <td>{{ contact[6] }}</td>
  201.                                 <td>{{ contact[7]|raw }}</td>
  202.                             </tr>
  203.                         {% endfor %}
  204.                     </tbody>
  205.                 </table>
  206.             </div>
  207.             <div class="tab-pane fade" id="list-contrats" role="tabpanel" aria-labelledby="list-contrats-list">
  208.                 <div class="row mb-3">
  209.                     <a type="button" href="{{path('app_entreprise_new_contrat', {'id': entreprise.id})}}" class="btn btn-success">Ajouter un contrat</a>
  210.                 </div>
  211.                 <table id="contrats" class="text-center table" style="width:100%">
  212.                     <thead>
  213.                         <tr class="">
  214.                             <th>Type</th>
  215.                             <th>Durée (mois)</th>
  216.                             <th>Valeur</th>
  217.                             <th>PDL</th>
  218.                             <th>CAR</th>
  219.                             <th>Prix moyen</th>
  220.                             <th>Fournisseur</th>
  221.                             <th>Date de début</th>
  222.                             <th>Date de fin</th>
  223.                             <th>Date signature</th>
  224.                             <th>Action</th>
  225.                         </tr>
  226.                     </thead>
  227.                     <tbody>
  228.                     {% for contrat in contrats %}
  229.                         <tr>
  230.                             <td>
  231.                                 {% if contrat.pdl in electric_pdls|default([]) %}
  232.                                     Électricité
  233.                                 {% elseif contrat.pdl in gas_pdls|default([]) %}
  234.                                     Gaz
  235.                                 {% else %}
  236.                                     Non défini
  237.                                 {% endif %}
  238.                             </td>
  239.                             <td>{{ contrat.duree }}</td>
  240.                             <td>{{ contrat.valeur }}</td>
  241.                             <td>{{ contrat.pdl }}</td>
  242.                             <td>{{ contrat.car }}</td>
  243.                             <td>{{ contrat.prix_moyen }}</td>
  244.                             <td>{{ contrat.fournisseur }}</td>
  245.                             <td>{{ contrat.date_debut ? contrat.date_debut : 'N/A' }}</td>
  246.                             <td>{{ contrat.date_fin ? contrat.date_fin : 'N/A' }}</td>
  247.                             <td>{{ contrat.date_signature ? contrat.date_signature : 'N/A' }}</td>
  248.                             <td class="contrat-actions">
  249.                                 <a
  250.                                     href="{{ path('app_entreprise_edit_contrat', {'entrepriseId': entreprise.id, 'id': contrat.id}) }}"
  251.                                     class="btn btn-sm btn-warning"
  252.                                     title="Modifier"
  253.                                     aria-label="Modifier"
  254.                                 >
  255.                                     <i class="fa-solid fa-pen"></i>
  256.                                 </a>
  257.                                 <form
  258.                                     method="post"
  259.                                     action="{{ path('app_entreprise_delete_contrat', {'entrepriseId': entreprise.id, 'id': contrat.id}) }}"
  260.                                     onsubmit="return confirmDelete(event);"
  261.                                     class="d-inline-block"
  262.                                 >
  263.                                     <input type="hidden" name="_token" value="{{ csrf_token('delete' ~ contrat.id) }}">
  264.                                     <button
  265.                                         type="submit"
  266.                                         class="btn btn-sm btn-danger"
  267.                                         title="Supprimer"
  268.                                         aria-label="Supprimer"
  269.                                     >
  270.                                         <i class="fa-solid fa-trash"></i>
  271.                                     </button>
  272.                                 </form>
  273.                             </td>
  274.                         </tr>
  275.                     {% endfor %}
  276.                     </tbody>
  277.                 </table>
  278.             </div>
  279.         </div>        
  280.     </div>
  281. </div>
  282.     {{ include('_footer.html.twig') }}
  283. {% endblock %}
  284. {% block javascripts %}
  285.     {{ parent() }}
  286.     <script>
  287.         function confirmDelete(event) {
  288.             event.preventDefault();
  289.             if (confirm('Êtes-vous sûr de vouloir supprimer ce contrat ?')) {
  290.                 event.target.submit();
  291.             }
  292.         }
  293.         
  294.         function formatPDLDetails(details, meterType) {
  295.             console.log('Formatting details:', details); // Debug log
  296.             let html = '';
  297.             
  298.             // First row - PDL and dates
  299.             html += '<div class="pdl-details-row">';
  300.             if (details.PDL) {
  301.                 html += `
  302.                     <div class="pdl-detail-item">
  303.                         <i class="fas fa-fingerprint mr-2"></i>
  304.                         <span class="pdl-detail-label">PDL:</span>
  305.                         <span class="pdl-detail-value">${details.PDL}</span>
  306.                     </div>`;
  307.             }
  308.             html += '</div>';
  309.             
  310.             // Second row - Address and supplier
  311.             html += '<div class="pdl-details-row">';
  312.             if (details.adresseCompteur) {
  313.                 html += `
  314.                     <div class="pdl-detail-item">
  315.                         <i class="fas fa-map-marker-alt mr-2"></i>
  316.                         <span class="pdl-detail-label">Adresse:</span>
  317.                         <span class="pdl-detail-value">${details.adresseCompteur}</span>
  318.                     </div>`;
  319.             }
  320.             html += '</div>';
  321.             
  322.             // Third row - Technical details
  323.             html += '<div class="pdl-details-row">';
  324.             if (details.profil) {
  325.                 html += `
  326.                     <div class="pdl-detail-item">
  327.                         <i class="fas fa-chart-bar mr-2"></i>
  328.                         <span class="pdl-detail-label">Profil:</span>
  329.                         <span class="pdl-detail-value">${details.profil}</span>
  330.                     </div>`;
  331.             }
  332.             if (details.PS) {
  333.                 html += `
  334.                     <div class="pdl-detail-item">
  335.                         <i class="fas fa-bolt mr-2"></i>
  336.                         <span class="pdl-detail-label">PS:</span>
  337.                         <span class="pdl-detail-value">${details.PS}</span>
  338.                     </div>`;
  339.             }
  340.             if (details.CAR) {
  341.                 html += `
  342.                     <div class="pdl-detail-item">
  343.                         <i class="fas fa-chart-line mr-2"></i>
  344.                         <span class="pdl-detail-label">CAR:</span>
  345.                         <span class="pdl-detail-value">${details.CAR}</span>
  346.                     </div>`;
  347.             }
  348.             if (details.prix) {
  349.                 html += `
  350.                     <div class="pdl-detail-item">
  351.                         <i class="fas fa-euro-sign mr-2"></i>
  352.                         <span class="pdl-detail-label">Prix:</span>
  353.                         <span class="pdl-detail-value">${formatValue('prix', details.prix)}</span>
  354.                     </div>`;
  355.             }
  356.             html += '</div>';
  357.             // Add related contracts section
  358.             html += '<div class="contracts-section">';
  359.             html += '<h5>Contrats liés</h5>';
  360.             html += '<div class="related-contracts">';
  361.             html += '<table class="table">';
  362.             html += '<thead><tr>';
  363.             html += '<th>Date de début</th>';
  364.             html += '<th>Date de fin</th>';
  365.             html += '<th>Date signature</th>';
  366.             html += '<th>Fournisseur</th>';
  367.             html += '<th>Prix moyen</th>';
  368.             html += '</tr></thead>';
  369.             html += '<tbody>';
  370.             
  371.             // Filter contracts for this PDL
  372.             const relatedContracts = window.contrats.filter(c => c.pdl === details.PDL);
  373.             if (relatedContracts.length > 0) {
  374.                 relatedContracts.forEach(contract => {
  375.                     html += '<tr>';
  376.                     html += `<td>${contract.date_debut || ''}</td>`;
  377.                     html += `<td>${contract.date_fin || ''}</td>`;
  378.                     html += `<td>${contract.date_signature || ''}</td>`;
  379.                     html += `<td>${contract.fournisseur || ''}</td>`;
  380.                     html += `<td>${formatValue('prix', contract.prix_moyen)}</td>`;
  381.                     html += '</tr>';
  382.                 });
  383.             } else {
  384.                 html += '<tr><td colspan="5" class="text-center">Aucun contrat lié</td></tr>';
  385.             }
  386.             
  387.             html += '</tbody></table>';
  388.             html += '</div></div>';
  389.             
  390.             // Actions with meter type and ID
  391.             const meterId = meterType === 'gas' ? 
  392.                 $('#gas-pdl-select option:selected').data('id') : 
  393.                 $('#electric-pdl-select option:selected').data('id');
  394.             html += `
  395.                 <div class="pdl-actions">
  396.                     <a href="{{ path('app_entreprise_new_contrat', {'id': entreprise.id}) }}?meterId=${meterId}&meterType=${meterType}" class="btn btn-sm btn-success">Nouveau contrat</a>
  397.                     <button class="btn btn-sm btn-warning edit-pdl">Modifier</button>
  398.                     <button class="btn btn-sm btn-danger delete-pdl">Supprimer</button>`;
  399.             
  400.             // Add study generation buttons
  401.             if (meterType === 'electric') {
  402.                 const studyUrlC5 = "{{ path('app_electric_meter_generate_study', {'pdl': '__PDL__', 'type': 'C5'}) }}".replace('__PDL__', encodeURIComponent(details.PDL));
  403.                 const studyUrlC4 = "{{ path('app_electric_meter_generate_study', {'pdl': '__PDL__', 'type': 'C4'}) }}".replace('__PDL__', encodeURIComponent(details.PDL));
  404.                 const studyUrlC3 = "{{ path('app_electric_meter_generate_study', {'pdl': '__PDL__', 'type': 'C3'}) }}".replace('__PDL__', encodeURIComponent(details.PDL));
  405.                 
  406.                 html += `
  407.                     <a href="${studyUrlC5}" class="btn btn-sm btn-info">
  408.                         Générer étude C5
  409.                     </a>
  410.                     <a href="${studyUrlC4}" class="btn btn-sm btn-info">
  411.                         Générer étude C4
  412.                     </a>
  413.                     <a href="${studyUrlC3}" class="btn btn-sm btn-info">
  414.                         Générer étude C3 C2 C1
  415.                     </a>`;
  416.             } else if (meterType === 'gas') {
  417.                 const studyUrl = "{{ path('app_gas_meter_pre_etude_t2', {'pdl': '__PDL__'}) }}".replace('__PDL__', encodeURIComponent(details.PDL));
  418.                 html += `
  419.                     <a href="${studyUrl}" class="btn btn-sm btn-info">
  420.                         Générer étude Gaz
  421.                     </a>`;
  422.             }
  423.                         
  424.             html += '</div>';
  425.             return html;
  426.         }
  427.         function formatValue(key, value) {
  428.             if (key.toLowerCase().includes('prix') && !isNaN(value)) {
  429.                 return new Intl.NumberFormat('fr-FR', { style: 'currency', currency: 'EUR' }).format(value);
  430.             }
  431.             if (typeof value === 'boolean') {
  432.                 return value ? '<span class="text-success">Actif</span>' : '<span class="text-danger">Inactif</span>';
  433.             }
  434.             return value || '';
  435.         }
  436.         $(document).ready(function() {
  437.             // Store contracts data globally
  438.             window.contrats = {{ contrats|json_encode|raw }};
  439.             // Common DataTable configuration
  440.             const commonConfig = {
  441.                 "language": {
  442.                     "url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/French.json"
  443.                 },
  444.                 "pageLength": 10,
  445.                 "destroy": true
  446.             };
  447.             // Handle automatic PDL selection when tabs are clicked
  448.             $('#list-electric-meters-list').on('click', function() {
  449.                 const select = $('#electric-pdl-select');
  450.                 if (select.find('option').length === 2) { // 2 because there's always a default empty option
  451.                     select.val(select.find('option:last').val()).trigger('change');
  452.                 }
  453.             });
  454.             $('#list-gas-meters-list').on('click', function() {
  455.                 const select = $('#gas-pdl-select');
  456.                 if (select.find('option').length === 2) { // 2 because there's always a default empty option
  457.                     select.val(select.find('option:last').val()).trigger('change');
  458.                 }
  459.             });
  460.             // Initialize tables that have data in tbody
  461.             $('#contacts, #contrats').each(function() {
  462.                 if (!$.fn.DataTable.isDataTable(this)) {
  463.                     $(this).DataTable({
  464.                         ...commonConfig,
  465.                         "order": [[0, 'asc']]
  466.                     });
  467.                 }
  468.             });
  469.             // Initialize tables that need data from variables
  470.             const tableData = {
  471.                 rappels: {{ rappels|json_encode|raw }},
  472.                 cspes: {{ cspes|json_encode|raw }},
  473.                 espace_clients: {{ espace_clients|json_encode|raw }}
  474.             };
  475.             ['rappels', 'cspes', 'espace_clients'].forEach((tableId) => {
  476.                 const table = $('#' + tableId);
  477.                 if (table.length && !$.fn.DataTable.isDataTable(table[0])) {
  478.                     table.DataTable({
  479.                         ...commonConfig,
  480.                         data: tableData[tableId] || [],
  481.                         searching: true,
  482.                         paging: true,
  483.                         info: true
  484.                     });
  485.                 }
  486.             });
  487.             // Electric Meters PDL selection
  488.             $('#electric-pdl-select').change(function() {
  489.                 var pdl = $(this).val();
  490.                 console.log('CHANGE electric déclenché, pdl =', pdl);
  491.                 if (!pdl) {
  492.                     $('#pdl-details').html('Sélectionnez un PDL pour voir les détails');
  493.                     return;
  494.                 }
  495.                 
  496.                 $.ajax({
  497.                     url: '{{ path('app_electric_meter_details', {'id': entreprise.id}) }}',
  498.                     method: 'GET',
  499.                     data: { pdl: pdl },
  500.                     success: function(response) {
  501.                         console.log('Electric meter response:', response);
  502.                         $('#pdl-details').html(formatPDLDetails(response, 'electric'));
  503.                         initializePDLActions('electric', $('#electric-pdl-select option:selected').data('id'));
  504.                     },
  505.                     error: function(xhr, status, error) {
  506.                         console.error('Error details:', {
  507.                             status: xhr.status,
  508.                             statusText: xhr.statusText,
  509.                             responseText: xhr.responseText
  510.                         });
  511.                         $('#pdl-details').html(`<div class="error-message">Erreur lors du chargement des détails: ${error}</div>`);
  512.                     }
  513.                 });
  514.             });
  515.             // Gas Meters PDL selection
  516.             $('#gas-pdl-select').change(function() {
  517.                 var pdl = $(this).val();
  518.                 console.log('CHANGE gas déclenché, pdl =', pdl);
  519.                 
  520.                 if (!pdl) {
  521.                     $('#gas-pdl-details').html('Sélectionnez un PDL pour voir les détails');
  522.                     return;
  523.                 }
  524.                 
  525.                 $.ajax({
  526.                     url: '{{ path('app_gas_meter_details', {'id': entreprise.id}) }}',
  527.                     method: 'GET',
  528.                     data: { pdl: pdl },
  529.                     success: function(response) {
  530.                         console.log('Gas meter response:', response);
  531.                         $('#gas-pdl-details').html(formatPDLDetails(response, 'gas'));
  532.                         initializePDLActions('gas', $('#gas-pdl-select option:selected').data('id'));
  533.                     },
  534.                     error: function(xhr, status, error) {
  535.                         console.error('Error details:', {
  536.                             status: xhr.status,
  537.                             statusText: xhr.statusText,
  538.                             responseText: xhr.responseText
  539.                         });
  540.                         $('#gas-pdl-details').html(`<div class="error-message">Erreur lors du chargement des détails: ${error}</div>`);
  541.                     }
  542.                 });
  543.             });
  544.             function initializePDLActions(type, id) {
  545.                 // Handle edit PDL
  546.                 $('.edit-pdl').click(function() {
  547.                     var url = type === 'electric' 
  548.                         ? '{{ path('app_electric_meter_edit', {'id': 'METER_ID'}) }}'
  549.                         : '{{ path('app_gas_meter_edit', {'id': 'METER_ID'}) }}';
  550.                     url = url.replace('METER_ID', id);
  551.                     window.location.href = url;
  552.                 });
  553.                 // Handle delete PDL
  554.                 $('.delete-pdl').click(function() {
  555.                     if (confirm('Êtes-vous sûr de vouloir supprimer ce PDL ?')) {
  556.                         var url = type === 'electric' 
  557.                             ? '{{ path('app_electric_meter_suppr', {'id': 'METER_ID'}) }}'
  558.                             : '{{ path('app_gas_meter_suppr', {'id': 'METER_ID'}) }}';
  559.                         url = url.replace('METER_ID', id);
  560.                         
  561.                         $.ajax({
  562.                             url: url,
  563.                             method: 'POST',
  564.                             data: {
  565.                                 '_token': '{{ csrf_token('delete-meter') }}'
  566.                             },
  567.                             success: function() {
  568.                                 location.reload();
  569.                             },
  570.                             error: function(xhr, status, error) {
  571.                                 console.error('Error deleting meter:', error);
  572.                                 alert('Erreur lors de la suppression du compteur');
  573.                             }
  574.                         });
  575.                     }
  576.                 });
  577.             }
  578.             $('a[data-bs-toggle="list"]').on('shown.bs.tab', function () {
  579.                 $($.fn.dataTable.tables(true)).DataTable().columns.adjust();
  580.             });
  581.         });
  582.     </script>
  583. {% endblock %}