Переглянути джерело

uscite allegato modale e n fattura non commerciale

FabioFratini 7 місяців тому
батько
коміт
f29c084ebb

+ 14 - 1
app/Http/Livewire/RecordOUT.php

@@ -1825,8 +1825,21 @@ class RecordOUT extends Component
                 $row->formatted_amount = formatPrice($row->amount);
             }
 
-            if ($record->attachment) {
+            if ($record->attachment && !empty($record->attachment)) {
                 $record->attachment_url = $this->getAttachmentUrl($record->attachment);
+
+                $attachmentPath = $record->attachment;
+                if (strpos($attachmentPath, '/') !== false) {
+                    $record->attachment_filename = basename($attachmentPath);
+                } else {
+                    $record->attachment_filename = $attachmentPath;
+                }
+
+                Log::info("Allegato trovato: " . $record->attachment_url);
+            } else {
+                $record->attachment_url = null;
+                $record->attachment_filename = null;
+                Log::info("Nessun allegato presente");
             }
 
             Log::info("Emitting show-record-details event");

+ 255 - 5
resources/views/livewire/records_out.blade.php

@@ -220,12 +220,14 @@
                                 </div>
                             </div>
 
-                            <span class="title-form d-block w-100">N° Fattura</span>
-                            <div class="input-group mb-3">
-                                <div class="col-md-6">
-                                    <input class="form-control " type="text" placeholder="Numero fattura" wire:model="numero_fattura">
+                            @if($commercial == 1)
+                                <span class="title-form d-block w-100">N° Fattura</span>
+                                <div class="input-group mb-3">
+                                    <div class="col-md-6">
+                                        <input class="form-control " type="text" placeholder="Numero fattura" wire:model="numero_fattura">
+                                    </div>
                                 </div>
-                            </div>
+                            @endif
 
                             <div class="col-md-6">
                                 <span class="title-form d-block w-100">Data</span>
@@ -656,6 +658,26 @@
                                     <td><span id="recordPaymentStatus" class="badge"></span></td>
                                 </tr>
                             </table>
+                             <h6 class="primary mt-3">Allegato</h6>
+                            <div id="recordAttachmentSection">
+                                <div id="recordAttachmentPresent" style="display: none;">
+                                    <div class="d-flex align-items-center">
+                                        <i class="fa-solid fa-file-pdf me-2 text-danger"></i>
+                                        <div>
+                                            <a id="recordAttachmentLink" href="#" target="_blank" class="btn btn-sm btn-outline-primary">
+                                                <i class="fa-regular fa-eye me-1"></i>
+                                                <span id="recordAttachmentName">Visualizza allegato</span>
+                                            </a>
+                                        </div>
+                                    </div>
+                                </div>
+                                <div id="recordAttachmentMissing" style="display: none;">
+                                    <span class="text-muted">
+                                        <i class="fa-regular fa-file me-2"></i>
+                                        Nessun allegato presente
+                                    </span>
+                                </div>
+                            </div>
                         </div>
                     </div>
 
@@ -903,6 +925,107 @@
         .file-selected-info {
             animation: fileUploadSuccess 0.5s ease-out;
         }
+
+        #recordAttachmentSection {
+            min-height: 50px;
+        }
+
+        #recordAttachmentPresent {
+            background-color: #f8f9fa;
+            padding: 10px;
+            border-radius: 6px;
+            border-left: 4px solid #28a745;
+        }
+
+        #recordAttachmentMissing {
+            background-color: #f8f9fa;
+            padding: 10px;
+            border-radius: 6px;
+            border-left: 4px solid #6c757d;
+        }
+
+        #recordAttachmentLink {
+            text-decoration: none;
+            transition: all 0.2s ease;
+        }
+
+        #recordAttachmentLink:hover {
+            transform: translateY(-1px);
+            box-shadow: 0 2px 8px rgba(0,0,0,0.15);
+        }
+
+        /* Stili per i diversi tipi di file */
+        .fa-file-pdf {
+            color: #dc3545 !important;
+        }
+
+        .fa-file-code {
+            color: #17a2b8 !important;
+        }
+
+        .fa-file-image {
+            color: #28a745 !important;
+        }
+
+        .fa-file-word {
+            color: #007bff !important;
+        }
+
+        .fa-file-excel {
+            color: #28a745 !important;
+        }
+
+        .fa-file {
+            color: #6c757d !important;
+        }
+
+        /* Animazione per la transizione del campo numero fattura */
+        .numero-fattura-field {
+            transition: all 0.3s ease;
+            overflow: hidden;
+        }
+
+        .numero-fattura-field.hidden {
+            max-height: 0;
+            opacity: 0;
+            margin-bottom: 0 !important;
+        }
+
+        .numero-fattura-field.visible {
+            max-height: 100px;
+            opacity: 1;
+        }
+
+        /* Miglioramenti per i radio button */
+        .check--invoice .form-check-input:checked {
+            background-color: #0C6197;
+            border-color: #0C6197;
+        }
+
+        .check--invoice .form-check-label {
+            font-weight: 500;
+            transition: color 0.2s ease;
+        }
+
+        .check--invoice .form-check-input:checked + .form-check-label {
+            color: #0C6197;
+        }
+
+        /* Responsive per mobile */
+        @media (max-width: 768px) {
+            #recordAttachmentSection {
+                margin-top: 15px;
+            }
+
+            #recordAttachmentPresent,
+            #recordAttachmentMissing {
+                padding: 8px;
+            }
+
+            #recordAttachmentName {
+                font-size: 0.9em;
+            }
+        }
     </style>
     <script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
     <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
@@ -1887,5 +2010,132 @@
 
             setTimeout(() => clearInterval(pollInterval), 300000);
         }
+
+        function showRecordDetailsModal(record) {
+            const modalElement = document.getElementById('recordDetailsModal');
+            if (!modalElement) return;
+
+            try {
+                let recordDetailsModal = new bootstrap.Modal(modalElement);
+
+                document.getElementById('recordDate').textContent = record.formatted_date || 'N/A';
+                document.getElementById('recordPaymentDate').textContent = record.formatted_data_pagamento || 'N/A';
+                document.getElementById('recordSupplier').textContent = record.supplier_name || 'N/A';
+                document.getElementById('recordPaymentMethod').textContent = record.payment_method_name || 'N/A';
+                document.getElementById('recordTotalAmount').textContent = record.formatted_amount || 'N/A';
+
+                const paymentStatusElement = document.getElementById('recordPaymentStatus');
+                if (paymentStatusElement) {
+                    paymentStatusElement.textContent = record.payment_status || 'N/A';
+                    paymentStatusElement.className = 'badge ' + (record.is_paid ? 'bg-success' : 'bg-warning');
+                }
+
+                const attachmentPresentDiv = document.getElementById('recordAttachmentPresent');
+                const attachmentMissingDiv = document.getElementById('recordAttachmentMissing');
+                const attachmentLink = document.getElementById('recordAttachmentLink');
+                const attachmentName = document.getElementById('recordAttachmentName');
+
+                if (record.attachment && record.attachment_url) {
+                    attachmentPresentDiv.style.display = 'block';
+                    attachmentMissingDiv.style.display = 'none';
+
+                    // Configura il link per l'allegato
+                    attachmentLink.href = record.attachment_url;
+
+                    // Estrai il nome del file dal percorso
+                    let fileName = record.attachment;
+                    if (fileName.includes('/')) {
+                        fileName = fileName.split('/').pop();
+                    }
+                    if (fileName.includes('\\')) {
+                        fileName = fileName.split('\\').pop();
+                    }
+
+                    // Se il nome è troppo lungo, troncalo
+                    if (fileName.length > 30) {
+                        const extension = fileName.substring(fileName.lastIndexOf('.'));
+                        const baseName = fileName.substring(0, fileName.lastIndexOf('.'));
+                        fileName = baseName.substring(0, 25) + '...' + extension;
+                    }
+
+                    attachmentName.textContent = fileName;
+
+                    // Aggiorna l'icona in base al tipo di file
+                    const iconElement = attachmentPresentDiv.querySelector('i.fa-file-pdf');
+                    if (fileName.toLowerCase().includes('.pdf')) {
+                        iconElement.className = 'fa-solid fa-file-pdf me-2 text-danger';
+                    } else if (fileName.toLowerCase().includes('.xml')) {
+                        iconElement.className = 'fa-solid fa-file-code me-2 text-info';
+                    } else if (fileName.toLowerCase().match(/\.(jpg|jpeg|png|gif|webp)$/)) {
+                        iconElement.className = 'fa-solid fa-file-image me-2 text-success';
+                    } else if (fileName.toLowerCase().match(/\.(doc|docx)$/)) {
+                        iconElement.className = 'fa-solid fa-file-word me-2 text-primary';
+                    } else if (fileName.toLowerCase().match(/\.(xls|xlsx|csv)$/)) {
+                        iconElement.className = 'fa-solid fa-file-excel me-2 text-success';
+                    } else {
+                        iconElement.className = 'fa-solid fa-file me-2 text-secondary';
+                    }
+                } else {
+                    // Mostra la sezione senza allegato
+                    attachmentPresentDiv.style.display = 'none';
+                    attachmentMissingDiv.style.display = 'block';
+                }
+
+                // Popola le righe come prima
+                const rowsContainer = document.getElementById('recordRowsContainer');
+                if (rowsContainer) {
+                    rowsContainer.innerHTML = '';
+
+                    if (record.rows && record.rows.length > 0) {
+                        record.rows.forEach(function(row, index) {
+                            const tr = document.createElement('tr');
+
+                            tr.innerHTML = `
+                                <td>${index + 1}</td>
+                                <td>${row.note && row.note.trim() !== '' ? row.note : (row.causal_name || 'N/A')}</td>
+                                <td>${row.formatted_imponibile || 'N/A'}</td>
+                                <td>${row.aliquota_iva ? row.aliquota_iva + '%' : '-'}</td>
+                                <td>${row.formatted_imposta || 'N/A'}</td>
+                                <td class="fw-bold">${row.formatted_amount || 'N/A'}</td>
+                            `;
+
+                            rowsContainer.appendChild(tr);
+                        });
+                    } else {
+                        const tr = document.createElement('tr');
+                        tr.innerHTML = '<td colspan="6" class="text-center">Nessuna riga disponibile</td>';
+                        rowsContainer.appendChild(tr);
+                    }
+                }
+
+                recordDetailsModal.show();
+
+            } catch (error) {
+                console.error('Error displaying modal:', error);
+            }
+        }
+
+        // Aggiungere questo listener per gestire i cambi di stato del campo commercial
+        document.addEventListener('livewire:load', function() {
+            // Listener per il cambio del radio button commerciale/non commerciale
+            const commercialRadios = document.querySelectorAll('input[name="commercial"]');
+            commercialRadios.forEach(radio => {
+                radio.addEventListener('change', function() {
+                    console.log('Commercial value changed to:', this.value);
+                    // Il campo numero fattura sarà nascosto/mostrato automaticamente da Livewire
+                });
+            });
+        });
+
+        // Listener per gli aggiornamenti di Livewire
+        document.addEventListener('livewire:update', function() {
+            // Re-attach listeners dopo gli aggiornamenti di Livewire
+            const commercialRadios = document.querySelectorAll('input[name="commercial"]');
+            commercialRadios.forEach(radio => {
+                radio.addEventListener('change', function() {
+                    console.log('Commercial value changed to:', this.value);
+                });
+            });
+        });
     </script>
 @endpush