Pārlūkot izejas kodu

refinement prima nota

FabioFratini 7 mēneši atpakaļ
vecāks
revīzija
7097b53242

+ 19 - 3
app/Http/Livewire/Record.php

@@ -39,6 +39,7 @@ class Record extends Component
     public $sendViaEmail = false;
     public $exportEmailAddress = '';
     public $exportEmailSubject = 'Prima Nota - Export';
+    private $causalAmounts = [];
 
     protected $rules = [
         'exportEmailAddress' => 'required_if:sendViaEmail,true|email',
@@ -513,6 +514,7 @@ class Record extends Component
     }
 
 
+
     public function render()
     {
         $month = 0;
@@ -520,6 +522,7 @@ class Record extends Component
 
         $this->records = array();
         $this->totals = array();
+        $this->causalAmounts = array();
 
         $exclude_from_records = \App\Models\Member::where('exclude_from_records', true)->pluck('id')->toArray();
 
@@ -575,6 +578,7 @@ class Record extends Component
 
         $groupedData = [];
         $causalsCount = [];
+        $causalsAmounts = [];
         $nominativi = [];
 
         foreach ($datas as $idx => $data) {
@@ -620,11 +624,19 @@ class Record extends Component
                         'notes' => []
                     ];
                     $causalsCount[$groupKey] = [];
+                    $causalsAmounts[$groupKey] = []; // Initialize causal amounts for this group
                     $nominativi[$groupKey] = $nominativo;
                 }
 
                 $groupedData[$groupKey]['amount'] += $amount;
                 $causalsCount[$groupKey][$causalCheck->getTree()] = true;
+
+                $causalName = $causalCheck->getTree();
+                if (!isset($causalsAmounts[$groupKey][$causalName])) {
+                    $causalsAmounts[$groupKey][$causalName] = 0;
+                }
+                $causalsAmounts[$groupKey][$causalName] += $amount;
+
                 if (!empty($data->note)) {
                     $groupedData[$groupKey]['notes'][] = $data->note;
                 }
@@ -640,7 +652,11 @@ class Record extends Component
             $causalDisplay = $group['type_label'];
 
             if (count($causalsInGroup) > 1) {
-                $detailDisplay = 'Varie|' . implode('|', $causalsInGroup);
+                $causalAmountsForJs = [];
+                foreach ($causalsInGroup as $causalName) {
+                    $causalAmountsForJs[] = $causalName . ':::' . formatPrice($causalsAmounts[$groupKey][$causalName]);
+                }
+                $detailDisplay = 'Varie|' . implode('|', $causalAmountsForJs);
             } else {
                 $detailDisplay = $causalsInGroup[0];
             }
@@ -1013,8 +1029,8 @@ class Record extends Component
 
         Log::info('exportWithData: Setting basic headers');
         $activeWorksheet->setCellValue('A1', "Data");
-        $activeWorksheet->setCellValue('B1', "Causale");
-        $activeWorksheet->setCellValue('C1', "Dettaglio");
+        $activeWorksheet->setCellValue('B1', "Tipologia");
+        $activeWorksheet->setCellValue('C1', "Causale");
         $activeWorksheet->setCellValue('D1', "Nominativo");
         $activeWorksheet->setCellValue('E1', "Stato");
 

+ 6 - 17
app/Jobs/ExportPrimaNota.php

@@ -192,8 +192,8 @@ class ExportPrimaNota implements ShouldQueue
 
         Log::info('Job createExcelFile: Setting basic headers');
         $activeWorksheet->setCellValue('A1', "Data");
-        $activeWorksheet->setCellValue('B1', "Causale");
-        $activeWorksheet->setCellValue('C1', "Dettaglio Causale");
+        $activeWorksheet->setCellValue('B1', "Tipologia");
+        $activeWorksheet->setCellValue('C1', "Causale");
         $activeWorksheet->setCellValue('D1', "Nominativo");
         $activeWorksheet->setCellValue('E1', "Stato");
 
@@ -694,18 +694,15 @@ class ExportPrimaNota implements ShouldQueue
         $activeWorksheet->fromArray([$totalsData], null, 'A' . $totalRow, true);
     }
 
-    // Apply styles more efficiently
     private function applyStylesEfficiently($activeWorksheet, $letters)
     {
         $maxCol = min(count($letters) - 1, count($this->payments) * 2 + 4);
         $lastCol = $letters[$maxCol];
-        $totalRows = count($this->exportData) + 4; // +4 for headers, spacing, and totals
+        $totalRows = count($this->exportData) + 4;
 
-        // Apply header styles
         $headerRange = 'A1:' . $lastCol . '2';
         $activeWorksheet->getStyle($headerRange)->getFont()->setBold(true);
 
-        // Apply header background
         $activeWorksheet->getStyle('A1:' . $lastCol . '1')
             ->getFill()
             ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)
@@ -714,7 +711,6 @@ class ExportPrimaNota implements ShouldQueue
         $activeWorksheet->getStyle('A1:' . $lastCol . '1')
             ->getFont()->getColor()->setARGB('FFFFFFFF');
 
-        // Apply totals row styles
         $totalsRange = 'A' . $totalRows . ':' . $lastCol . $totalRows;
         $activeWorksheet->getStyle($totalsRange)->getFont()->setBold(true);
         $activeWorksheet->getStyle($totalsRange)
@@ -723,7 +719,6 @@ class ExportPrimaNota implements ShouldQueue
             ->getStartColor()->setARGB('FFF0F0F0');
     }
 
-    // Set column dimensions efficiently
     private function setColumnDimensions($activeWorksheet, $letters)
     {
         $dimensions = [
@@ -738,8 +733,7 @@ class ExportPrimaNota implements ShouldQueue
             $activeWorksheet->getColumnDimension($col)->setWidth($width);
         }
 
-        // Set payment method column widths
-        for ($i = 5; $i < count($letters) && $i < 50; $i++) { // Limit to prevent excessive loops
+        for ($i = 5; $i < count($letters) && $i < 50; $i++) {
             $activeWorksheet->getColumnDimension($letters[$i])->setWidth(15);
         }
     }
@@ -781,15 +775,12 @@ class ExportPrimaNota implements ShouldQueue
         ]);
 
         try {
-            // Execute every 5 seconds to monitor progress
             $lastCheck = $startTime;
             $result = null;
 
-            // For non-blocking operations, we can't easily interrupt,
-            // but we can log progress
             register_tick_function(function () use ($startTime, $maxExecutionTime, $description, &$lastCheck) {
                 $currentTime = microtime(true);
-                if ($currentTime - $lastCheck >= 5) { // Log every 5 seconds
+                if ($currentTime - $lastCheck >= 5) {
                     $elapsed = $currentTime - $startTime;
                     $remaining = $maxExecutionTime > 0 ? $maxExecutionTime - $elapsed : 'unlimited';
 
@@ -842,7 +833,7 @@ class ExportPrimaNota implements ShouldQueue
 
         $maxExecutionTime = ini_get('max_execution_time');
         if ($maxExecutionTime <= 0) {
-            return false; // No limit set
+            return false;
         }
 
         $elapsed = microtime(true) - $startTime;
@@ -868,8 +859,6 @@ class ExportPrimaNota implements ShouldQueue
         return false;
     }
 
-    // SOLUTION 8: Log configuration and environment info at start
-
     public function logEnvironmentInfo()
     {
         Log::info('=== EXPORT ENVIRONMENT INFO ===', [

+ 80 - 21
resources/views/livewire/records.blade.php

@@ -227,20 +227,34 @@
         <div class="modal-dialog modal-lg">
             <div class="modal-content">
                 <div class="modal-header" style="background-color: #0C6197!important;">
-                    <h5 class="modal-title" id="causalsModalLabel">Dettaglio Causali</h5>
+                    <h5 class="modal-title" id="causalsModalLabel">
+                        <i class="me-2"></i>
+                        Dettaglio Causali
+                    </h5>
                     <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="CHIUDI"></button>
                 </div>
                 <div class="modal-body">
                     <div class="row">
                         <div class="col-12">
-                            <h6>Causali incluse:</h6>
-                            <ul id="causalsList" class="list-group list-group-flush">
-                            </ul>
+                            <div class="d-flex justify-content-between align-items-center mb-3">
+                                <h6 class="mb-0">
+                                    <i class="me-2 text-primary"></i>
+                                    Causali incluse:
+                                </h6>
+                            </div>
+                            <div class="border rounded" style="max-height: 400px; overflow-y: auto;">
+                                <ul id="causalsList" class="list-group list-group-flush mb-0">
+                                    <!-- Causals will be populated here by JavaScript -->
+                                </ul>
+                            </div>
                         </div>
                     </div>
                 </div>
                 <div class="modal-footer" style="background-color: #FFF!important;">
-                    <button type="button" class="btn--ui lightGrey me-2" data-bs-dismiss="modal">CHIUDI</button>
+                    <button type="button" class="btn--ui lightGrey me-2" data-bs-dismiss="modal">
+                        <i class="fas fa-times me-1"></i>
+                        CHIUDI
+                    </button>
                 </div>
             </div>
         </div>
@@ -695,6 +709,43 @@
             opacity: 0.7;
             cursor: not-allowed;
         }
+
+        .list-group-item {
+            border-left: none;
+            border-right: none;
+            border-top: 1px solid #dee2e6;
+            padding: 12px 15px;
+        }
+
+        .list-group-item:first-child {
+            border-top: none;
+        }
+
+        .list-group-item:last-child {
+            border-bottom: none;
+        }
+
+        /* Enhanced styles for the causal modal with amounts */
+        .list-group-item.d-flex {
+            display: flex !important;
+            justify-content: space-between !important;
+            align-items: center !important;
+        }
+
+        .list-group-item .badge {
+            font-size: 0.875rem;
+            font-weight: 600;
+        }
+
+        .list-group-item:hover {
+            background-color: rgba(12, 97, 151, 0.05);
+            transition: background-color 0.2s ease;
+        }
+
+        #causalsModal .modal-body {
+            padding: 1rem 0;
+        }
+
     </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>
@@ -846,12 +897,30 @@
 
                     causals.forEach(function(causal) {
                         if (causal.trim()) {
-                            $('#causalsList').append(
-                                '<li class="list-group-item">' +
-                                '<i class="fas fa-tags me-2" style="color: #0C6197;"></i>' +
-                                causal.trim() +
-                                '</li>'
-                            );
+                            if (causal.includes(':::')) {
+                                const parts = causal.split(':::');
+                                const causalName = parts[0].trim();
+                                const amount = parts[1].trim();
+
+                                $('#causalsList').append(
+                                    '<li class="list-group-item d-flex justify-content-between align-items-center">' +
+                                    '<div>' +
+                                    '<i class="fas fa-tags me-2" style="color: #0C6197;"></i>' +
+                                    causalName +
+                                    '</div>' +
+                                    '<span class="badge bg-primary rounded-pill" style="background-color: #0C6197 !important;">' +
+                                    amount +
+                                    '</span>' +
+                                    '</li>'
+                                );
+                            } else {
+                                $('#causalsList').append(
+                                    '<li class="list-group-item">' +
+                                    '<i class="fas fa-tags me-2" style="color: #0C6197;"></i>' +
+                                    causal.trim() +
+                                    '</li>'
+                                );
+                            }
                         }
                     });
 
@@ -862,17 +931,7 @@
                     });
                 }
             });
-
-            $('#causalsModal').on('show.bs.modal', function () {
-                closeSelect2Dropdowns();
-                $('body').addClass('modal-open');
-            });
-
-            $('#causalsModal').on('hidden.bs.modal', function () {
-                $('body').removeClass('modal-open');
-            });
         });
-
         Livewire.on('load-table', () => {
             load();
         });