Browse Source

prima nota - aggiunto filtro metodo di pagamento + fix filtro periodo

ferrari 1 month ago
parent
commit
0c72cec29c

+ 34 - 1
app/Http/Livewire/Record.php

@@ -30,6 +30,7 @@ class Record extends Component
     public $isExporting = false;
     public $selectedPeriod = 'OGGI';
     public $filterCausals = null;
+    public $filterPaymentMethods = null;
     public $filterMember = null;
     public $isFiltering = false;
     public array $recordDatas = [];
@@ -162,6 +163,11 @@ class Record extends Component
             Log::info('generateExportDataAndTotals: Causal filters applied', ['causal_count' => count($causals)]);
         }
 
+        if ($this->filterPaymentMethods != null && sizeof($this->filterPaymentMethods) > 0) {
+            $datas->whereIn('payment_method_id', $this->filterPaymentMethods);
+            Log::info('generateExportDataAndTotals: Payment method filters applied', ['payment_method_count' => count($this->filterPaymentMethods)]);
+        }
+
         if ($this->filterMember != null && $this->filterMember > 0) {
             $datas->where('member_id', $this->filterMember);
             Log::info('generateExportDataAndTotals: Member filter applied', ['member_id' => $this->filterMember]);
@@ -386,6 +392,9 @@ class Record extends Component
             }
             $datas->whereIn('causal_id', $causals);
         }
+        if ($this->filterPaymentMethods != null && sizeof($this->filterPaymentMethods) > 0) {
+            $datas->whereIn('payment_method_id', $this->filterPaymentMethods);
+        }
         if ($this->filterMember != null && $this->filterMember > 0) {
             $datas->where('member_id', $this->filterMember);
         }
@@ -427,6 +436,7 @@ class Record extends Component
         $this->showMonthPicker = false;
         $this->showDayPicker = false;
         $this->filterCausals = [];
+        $this->filterPaymentMethods = [];
         $this->filterMember = null;
 
         $today = date("Y-m-d");
@@ -625,6 +635,9 @@ class Record extends Component
             }
             $datas->whereIn('causal_id', $causals);
         }
+        if ($this->filterPaymentMethods != null && sizeof($this->filterPaymentMethods) > 0) {
+            $datas->whereIn('payment_method_id', $this->filterPaymentMethods);
+        }
         if ($this->filterMember != null && $this->filterMember > 0) {
             $datas->where('member_id', $this->filterMember);
         }
@@ -1063,6 +1076,10 @@ class Record extends Component
             $query->whereIn('causal_id', $causals);
         }
 
+        if ($this->filterPaymentMethods != null && sizeof($this->filterPaymentMethods) > 0) {
+            $query->whereIn('payment_method_id', $this->filterPaymentMethods);
+        }
+
         if ($this->filterMember != null && $this->filterMember > 0) {
             $query->where('member_id', $this->filterMember);
         }
@@ -1086,6 +1103,16 @@ class Record extends Component
         return implode(', ', $causals);
     }
 
+    private function getPaymentMethodsNames($paymentMethodIds)
+    {
+        if (!is_array($paymentMethodIds)) {
+            return null;
+        }
+
+        $payment_methods = \App\Models\PaymentMethod::whereIn('id', $paymentMethodIds)->pluck('name')->toArray();
+        return implode(', ', $payment_methods);
+    }
+
     public function updatedExportFromDate()
     {
         $this->updateEmailSubject();
@@ -1136,6 +1163,7 @@ class Record extends Component
             $filterDescriptions = [
                 'member' => $this->filterMember ? $this->getMemberName($this->filterMember) : null,
                 'causals' => $this->filterCausals ? $this->getCausalsNames($this->filterCausals) : null,
+                'payment_methods' => $this->filterPaymentMethods ? $this->getPaymentMethodsNames($this->filterPaymentMethods) : null,
             ];
 
             $paymentsArray = $this->payments->map(function ($payment) {
@@ -1587,7 +1615,12 @@ class Record extends Component
         return $email;
     }
 
-        public function updatedSelectedDay($value)
+    public function updatedSelectedPeriod($value) {
+        $this->setPeriodDates();
+        $this->applyFilters();
+    }
+
+    public function updatedSelectedDay($value)
     {
         if (!empty($value)) {
             $this->selectedPeriod = 'GIORNO_PERSONALIZZATO';

+ 6 - 1
app/Jobs/ExportPrimaNota.php

@@ -89,7 +89,8 @@ class ExportPrimaNota implements ShouldQueue
                 'subject' => $this->emailSubject,
                 'from_date' => $this->dateRange['from'],
                 'to_date' => $this->dateRange['to'],
-                //'total_records' => count($this->exportData),
+                // 'total_records' => count($this->exportData),
+                'total_records' => count($this->records) - 1,
                 'user_name' => $user ? $user->name : 'Utente',
                 'generated_at' => now()->format('d/m/Y H:i:s'),
                 'filters_applied' => $this->getFiltersDescription(),
@@ -874,6 +875,10 @@ class ExportPrimaNota implements ShouldQueue
             $descriptions[] = "Causali: " . (is_array($this->filters['causals']) ? implode(', ', $this->filters['causals']) : $this->filters['causals']);
         }
 
+        if (!empty($this->filters['payment_methods'])) {
+            $descriptions[] = "Metodi di pagamento: " . (is_array($this->filters['payment_methods']) ? implode(', ', $this->filters['payment_methods']) : $this->filters['payment_methods']);
+        }
+
         return empty($descriptions) ? 'Nessun filtro applicato' : implode(' | ', $descriptions);
     }
 

+ 55 - 3
resources/views/livewire/records.blade.php

@@ -19,7 +19,7 @@
                     @endforeach
                 </select>
             </div>
-            <div class="col-md-4">
+            <div class="col-md-3">
                 Causale
                 <select name="search_causal_id[]" class="form-select filterCausals me-2" multiple="multiple" wire:model="filterCausals">
                     @foreach($causals as $causal)
@@ -27,7 +27,15 @@
                     @endforeach
                 </select>
             </div>
-            <div class="col-md-3">
+            <div class="col-md-2">
+                Metodo di pagamento
+                <select name="search_payment_method[]" class="form-select filterPaymentMethods me-2" multiple="multiple" wire:model="filterPaymentMethods">
+                    @foreach($payments as $payment)
+                        <option value="{{$payment["id"]}}">{!!$payment["name"]!!}
+                    @endforeach
+                </select>
+            </div>
+            <div class="col-md-2">
                 Periodo
                 <div class="col-12 mb-3">
                     <select wire:model="selectedPeriod" class="form-select" @if($isFiltering) disabled @endif style="height: 43px!important;">
@@ -638,7 +646,7 @@
         }
 
         ::-webkit-scrollbar-thumb {
-            background: #e4e4e4;
+            background: #0c6197 !important;
             border-radius: 10px;
         }
 
@@ -1336,6 +1344,11 @@
                     $(this).select2('close');
                 }
             });
+            $('.filterPaymentMethods').each(function() {
+                if ($(this).hasClass('select2-hidden-accessible')) {
+                    $(this).select2('close');
+                }
+            });
             $('.filterMember').each(function() {
                 if ($(this).hasClass('select2-hidden-accessible')) {
                     $(this).select2('close');
@@ -1382,6 +1395,43 @@
                     }, 100);
                 });
 
+                $(document).on("keypress", $('.filterPaymentMethods'), function (e) {
+                    setTimeout(() => {
+                        $(".select2-results__option").each(function(){
+                            var txt = $(this).html();
+                            var count = (txt.match(/-/g) || []).length;
+                            $(this).addClass('paddingLeftSelect' + count);
+                        });
+                    }, 100);
+                });
+
+                if (!$('.filterPaymentMethods').hasClass('select2-hidden-accessible')) {
+                    $('.filterPaymentMethods').select2({
+                        "language": {"noResults": function(){return "Nessun risultato";}},
+                        "dropdownParent": $('body'),
+                        "width": "100%"
+                    });
+                }
+
+                $('.filterPaymentMethods').off('change.customHandler').on('change.customHandler', function (e) {
+                    var data = $('.filterPaymentMethods').select2("val");
+                    @this.set('filterPaymentMethods', data);
+                });
+
+                $('.filterPaymentMethods').off('select2:open.customHandler').on('select2:open.customHandler', function (e) {
+                    if ($('#causalsModal').hasClass('show')) {
+                        $('#causalsModal').modal('hide');
+                    }
+
+                    setTimeout(() => {
+                        $(".select2-results__option").each(function(){
+                            var txt = $(this).html();
+                            var count = (txt.match(/-/g) || []).length;
+                            $(this).addClass('paddingLeftSelect' + count);
+                        });
+                    }, 100);
+                });
+
                 if (!$('.filterMember').hasClass('select2-hidden-accessible')) {
                     $('.filterMember').select2({
                         "language": {"noResults": function(){return "Nessun risultato";}},
@@ -1519,6 +1569,7 @@
         Livewire.on('filters-reset', () => {
             $('.filterMember').val('').trigger('change');
             $('.filterCausals').val('').trigger('change');
+            $('.filterPaymentMethods').val('').trigger('change');
             load();
         });
 
@@ -1847,6 +1898,7 @@
         function resetFiltersWithMonthPicker() {
             $('.filterMember').val('').trigger('change');
             $('.filterCausals').val('').trigger('change');
+            $('.filterPaymentMethods').val('').trigger('change');
 
             if (typeof @this !== 'undefined') {
                 @this.call('resetFilters');