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