FabioFratini 11 mesiacov pred
rodič
commit
d32f9dfd13

+ 4 - 78
app/Http/Livewire/Report.php

@@ -1517,14 +1517,7 @@ class Report extends Component
             }
         }
 
-        $separatorPageCount = 0;
-        if ($hasPdfAttachments) {
-            $separatorPageCount = 1;
-            Log::info("Separator page count: {$separatorPageCount}");
-        }
-
-        $totalAttachmentPagesWithSeparator = $totalAttachmentPages + $separatorPageCount;
-        Log::info("Total attachment pages (including separator): {$totalAttachmentPagesWithSeparator}");
+        Log::info("Total attachment pages: {$totalAttachmentPages}");
 
         $data['total_pages'] = 0;
         $initialPdf = Pdf::loadView('pdf.verbale', array('data' => $data));
@@ -1532,9 +1525,9 @@ class Report extends Component
         $mainPageCount = $initialPdf->getDomPDF()->getCanvas()->get_page_count();
         Log::info("Main PDF has {$mainPageCount} pages");
 
-        $totalPages = $mainPageCount + $totalAttachmentPages + $separatorPageCount;
-        Log::info("Total pages breakdown: Main={$mainPageCount}, Attachments={$totalAttachmentPages}, Separator={$separatorPageCount}");
-        Log::info("Total pages (main + attachments + separator): {$totalPages}");
+        $totalPages = $mainPageCount + $totalAttachmentPages;
+        Log::info("Total pages breakdown: Main={$mainPageCount}, Attachments={$totalAttachmentPages}");
+        Log::info("Total pages (main + attachments): {$totalPages}");
 
         $data['total_pages'] = $totalPages;
         $pdf = Pdf::loadView('pdf.verbale', array('data' => $data));
@@ -1554,15 +1547,6 @@ class Report extends Component
 
                 $pdfFiles = [$tempMainPdf];
 
-                try {
-                    $separatorPath = $this->createSeparatorPage($tempDir, "DOCUMENTI ALLEGATI");
-                    if ($separatorPath) {
-                        $pdfFiles[] = $separatorPath;
-                    }
-                } catch (\Exception $e) {
-                    Log::warning("Failed to create separator page: " . $e->getMessage());
-                }
-
                 foreach ($pdfAttachments as $attachmentPath) {
                     if (file_exists($attachmentPath)) {
                         $pdfFiles[] = $attachmentPath;
@@ -1584,9 +1568,6 @@ class Report extends Component
 
                     @unlink($tempMainPdf);
                     @unlink($outputPath);
-                    if (isset($separatorPath)) {
-                        @unlink($separatorPath);
-                    }
 
                     return response($pdfContent)
                         ->header('Content-Type', 'application/pdf')
@@ -1594,9 +1575,6 @@ class Report extends Component
                 } else {
                     Log::warning("PDF merge failed, falling back to main PDF only");
                     @unlink($tempMainPdf);
-                    if (isset($separatorPath)) {
-                        @unlink($separatorPath);
-                    }
                     return $pdf->stream($pdfName);
                 }
             } catch (\Exception $e) {
@@ -1661,59 +1639,7 @@ class Report extends Component
         }
     }
 
-    private function createSeparatorPage($tempDir, $title)
-    {
-        try {
-            Log::info("Creating separator page with title: $title");
-            $separatorPath = $tempDir . '/separator_' . uniqid() . '.pdf';
-            Log::info("Separator path: $separatorPath");
-
-            $html = '
-            <!DOCTYPE html>
-            <html>
-            <head>
-                <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
-                <style>
-                    body {
-                        font-family: Helvetica, sans-serif;
-                        color: rgb(80, 80, 80);
-                        text-align: center;
-                    }
-                    .separator-title {
-                        margin-top: 300px;
-                        font-size: 24px;
-                        font-weight: bold;
-                        text-transform: uppercase;
-                    }
-                </style>
-            </head>
-            <body>
-                <div class="separator-title">' . $title . '</div>
-            </body>
-            </html>
-        ';
-
-            $separatorPdf = Pdf::loadHTML($html);
-
-            Log::info("Generating separator PDF");
-            $separatorContent = $separatorPdf->output();
-            $bytesWritten = file_put_contents($separatorPath, $separatorContent);
-
-            if ($bytesWritten === false) {
-                Log::error("Failed to write separator PDF to file");
-                return false;
-            }
-
-            Log::info("Separator PDF created successfully: $bytesWritten bytes written");
-            Log::info("Separator file exists: " . (file_exists($separatorPath) ? 'Yes' : 'No'));
 
-            return $separatorPath;
-        } catch (\Exception $e) {
-            Log::error("Failed to create separator page: " . $e->getMessage());
-            Log::error("Stack trace: " . $e->getTraceAsString());
-            return false;
-        }
-    }
     public function updated($property, $value)
     {
         if ($property === 'verificatosi_in_data' && !preg_match('/^\d{4}-\d{2}-\d{2}$/', $value)) {

+ 3 - 1
resources/views/components/verbale/allegati/index.blade.php

@@ -12,6 +12,8 @@
 @endphp
 
 @if($hasVisibleAllegati)
+    <div class="page-break"></div>
+
     <table width="100%">
         <tr>
             <td valign="top" align="center">
@@ -24,7 +26,7 @@
                     PEC: polizialocalefrascati@legalmail.it
                 </h3>
                 <img src="{{ public_path() }}/images/logo_pdf.png" width="250">
-                <h2>DOCUMENTAZIONE FOTOGRAFICA</h2>
+                <h2>DOCUMENTAZIONE FOTOGRAFICA E ALLEGATI</h2>
                 <h4>Protocollo n. {{ $protocollo->protocollo_num }} / {{ $protocollo->protocollo_anno }}</h4>
             </td>
         </tr>

+ 0 - 1
resources/views/pdf/verbale.blade.php

@@ -282,7 +282,6 @@
 
     <x-verbale.verbalizzanti.index :record="$data['record']" />
 
-    <div class="page-break"></div>
 
     <x-verbale.allegati.index :allegati="$data['allegati']" :protocollo="$data['record']" />