src/ApplicationBundle/Resources/views/modals/input_forms/generic_ai_report_modal.html.twig line 1

Open in your IDE?
  1. <div class="modal fade" id="GenericAiReportModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" style="z-index:9999;">
  2.     <div class="modal-dialog" role="document">
  3.         <div class="modal-content">
  4.             <div class="modal-header">
  5.                 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
  6.                 <h4 class="modal-title" id="GenericAiReportModalLabel">Report</h4>
  7.                 <div class="pull-right" style="margin-top:-4px;">
  8.                     <button type="button" class="btn btn-xs btn-default" onclick="aiReportExportCsv()" title="Export CSV">
  9.                         <i class="fa fa-file-text-o"></i> CSV
  10.                     </button>
  11.                     <button type="button" class="btn btn-xs btn-default" onclick="aiReportPrint()" title="Print / Save as PDF">
  12.                         <i class="fa fa-print"></i> Print / PDF
  13.                     </button>
  14.                 </div>
  15.             </div>
  16.             <div class="modal-body">
  17.                 <div class="row clearfix">
  18.                     <div class="col-md-12 " id="GenericAiReportModalBody">
  19.                     </div>
  20.                     <div class="col-md-12 " id="GenericAiReportChartBody">
  21.                         <canvas id="genericAiChart_bar"></canvas>
  22.                         <canvas id="genericAiChart_pi"></canvas>
  23.                         <canvas id="genericAiChart_line"></canvas>
  24.                     </div>
  25.                 </div>
  26. {#                <div class="row clearfix">#}
  27. {#                    <div class="col-md-12">#}
  28. {#                        <div class="btn-toolbar pull-right">#}
  29. {#                            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>#}
  30. {#                        </div>#}
  31. {#                    </div>#}
  32. {#                </div>#}
  33.                 {#</form>#}
  34.             </div>
  35.         </div>
  36.         {#<div class="modal-footer">#}
  37.         {#<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>#}
  38.         {#</div>#}
  39.     </div>
  40. </div>
  41. </div>
  42. <style type="text/css">
  43.     #GenericAiReportModal .modal-dialog { width: 80% !important; max-width: 1100px; }
  44.     #GenericAiReportModal .modal-header { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
  45.     #GenericAiReportModal .modal-header h4 { flex: 1; margin: 0; }
  46.     #GenericAiReportModal .modal-body { max-height: 70vh; overflow-y: auto; }
  47.     #GenericAiReportModalBody table { width: 100%; font-size: 12px; }
  48. </style>
  49. <script>
  50.     var genericAiChart ={
  51.         bar : null,
  52.         line : null,
  53.         pi : null,
  54.     }
  55.     // ── Report export helpers ─────────────────────────────────────────────────
  56.     function aiReportExportCsv() {
  57.         var $table = $('#GenericAiReportModalBody table');
  58.         if (!$table.length) { alert('No table data to export.'); return; }
  59.         var rows = [];
  60.         $table.find('tr').each(function () {
  61.             var row = [];
  62.             $(this).find('th, td').each(function () {
  63.                 var cell = $(this).text().trim().replace(/"/g, '""');
  64.                 row.push('"' + cell + '"');
  65.             });
  66.             if (row.length) rows.push(row.join(','));
  67.         });
  68.         var title = $('#GenericAiReportModalLabel').text().trim() || 'report';
  69.         var blob = new Blob([rows.join('\n')], {type: 'text/csv;charset=utf-8;'});
  70.         var url = URL.createObjectURL(blob);
  71.         var a = document.createElement('a');
  72.         a.href = url;
  73.         a.download = title.replace(/[^a-z0-9]/gi, '_').toLowerCase() + '.csv';
  74.         document.body.appendChild(a);
  75.         a.click();
  76.         document.body.removeChild(a);
  77.         URL.revokeObjectURL(url);
  78.     }
  79.     function aiReportPrint() {
  80.         var title = $('#GenericAiReportModalLabel').text().trim() || 'Report';
  81.         var bodyHtml = $('#GenericAiReportModalBody').html();
  82.         var win = window.open('', '_blank', 'width=960,height=720');
  83.         win.document.write('<!DOCTYPE html><html><head><meta charset="utf-8"><title>' + title + '</title><style>'
  84.             + 'body{font-family:Arial,sans-serif;font-size:12px;padding:24px;color:#222;}'
  85.             + 'h2{margin:0 0 14px;font-size:16px;}'
  86.             + 'table{border-collapse:collapse;width:100%;}'
  87.             + 'th,td{border:1px solid #ccc;padding:6px 10px;text-align:left;vertical-align:top;}'
  88.             + 'th{background:#f0f4f7;font-weight:bold;}'
  89.             + 'tr:nth-child(even){background:#fafafa;}'
  90.             + 'pre{white-space:pre-wrap;word-break:break-word;}'
  91.             + '@media print{body{padding:0;}@page{margin:15mm;}}'
  92.             + '</style></head><body>'
  93.             + '<h2>' + title + '</h2>'
  94.             + bodyHtml
  95.             + '<script>window.onload=function(){window.print();}<\/script>'
  96.             + '</body></html>');
  97.         win.document.close();
  98.     }
  99.     // ─────────────────────────────────────────────────────────────────────────
  100.     function generateGenericAiChart(data,type) {
  101.         type=type || 'bar';
  102.         data=data || {
  103.             labels : [],
  104.             x_title : "",
  105.             y_title : "",
  106.             datasets : [],
  107.         };
  108.         var ctx = document.getElementById('genericAiChart_'+type).getContext('2d');
  109.         var labels = data.labels||[];
  110.         if (genericAiChart[type]) {
  111.             genericAiChart[type].destroy();
  112.         }
  113.         genericAiChart[type] = new Chart(ctx, {
  114.             type: type,
  115.             data: {
  116.                 labels: labels,
  117.                 datasets: data.datasets
  118.             },
  119.             options: {
  120.                 responsive: true,
  121.                 maintainAspectRatio: false,
  122.                 scales: {
  123.                     x: {
  124.                         stacked: true,
  125.                         grid: {
  126.                             display: false
  127.                         },
  128.                         title: {
  129.                             display: true,
  130.                             text: data.x_title,
  131.                             font: {
  132.                                 weight: 'bold'
  133.                             }
  134.                         }
  135.                     },
  136.                     y: {
  137.                         beginAtZero: true,
  138.                         grid: {
  139.                             display: true
  140.                         },
  141.                         title: {
  142.                             display: true,
  143.                             text: data.y_title,
  144.                             font: {
  145.                                 weight: 'bold'
  146.                             }
  147.                         }
  148.                     },
  149.                 },
  150.                 plugins: {
  151.                     legend: {
  152.                         position: 'top',
  153.                         labels: {
  154.                             usePointStyle: false,
  155.                             boxWidth: 10
  156.                         }
  157.                     },
  158.                 }
  159.             }
  160.         });
  161.     }
  162. </script>