ferrari 3 месяцев назад
Родитель
Сommit
35bb144542

+ 110 - 22
app/Http/Livewire/RecordINOUT.php

@@ -1,6 +1,8 @@
 <?php
 
 namespace App\Http\Livewire;
+
+use Illuminate\Support\Carbon;
 use Livewire\Component;
 
 use PhpOffice\PhpSpreadsheet\Spreadsheet;
@@ -200,28 +202,62 @@ class RecordINOUT extends Component
 
                 $this->columns[] = $filter;
 
-                $f = $filter;
-                if ($m == 'x')
-                    $f = str_replace("x-", "", $filter);
+                list($m, $y) = explode("-", $filter);
+
+                // $f = $filter;
+                // if ($m == 'x')
+                //     $f = str_replace("x-", "", $filter);
 
                 //$dt = $y . "-0" . $m;
 
-                $records = \App\Models\Record::where('type', 'IN')
+                // $records = \App\Models\Record::where('type', 'IN')
+                //     ->join('records_rows', 'records.id', '=', 'records_rows.record_id')
+                //     ->whereNotIn('records_rows.causal_id', $this->excludeCausals)
+                //     ->where(function ($query)  {
+                //         $query->where('deleted', false)->orWhere('deleted', null);
+                //     })
+                //     ->where(function ($query)  {
+                //         $query->where('financial_movement', false)->orWhere('financial_movement', null);
+                //     })
+                //     ->whereNotIn('member_id', $exclude_from_records)
+                //     /*->where(function ($query) use ($f, $dt)  {
+                //         $query->where('records.date', 'like', '%' . $dt . '%')->orWhere('records_rows.when', 'like', '%' . $f . '%');
+                //     })*/
+                //     ->where('records_rows.when', 'like', '%"' . $f . '"%')
+                //     ->get();
+                // //$records = $records->orderBy('date', 'DESC')->get();
+
+                $recordsQuery = \App\Models\Record::where('type', 'IN')
                     ->join('records_rows', 'records.id', '=', 'records_rows.record_id')
                     ->whereNotIn('records_rows.causal_id', $this->excludeCausals)
-                    ->where(function ($query)  {
+                    ->where(function ($query) {
                         $query->where('deleted', false)->orWhere('deleted', null);
                     })
-                    ->where(function ($query)  {
+                    ->where(function ($query) {
                         $query->where('financial_movement', false)->orWhere('financial_movement', null);
                     })
-                    ->whereNotIn('member_id', $exclude_from_records)
-                    /*->where(function ($query) use ($f, $dt)  {
-                        $query->where('records.date', 'like', '%' . $dt . '%')->orWhere('records_rows.when', 'like', '%' . $f . '%');
-                    })*/
-                    ->where('records_rows.when', 'like', '%"' . $f . '"%')
-                    ->get();
-                //$records = $records->orderBy('date', 'DESC')->get();
+                    ->whereNotIn('member_id', $exclude_from_records);
+
+                if ($m === 'x') {
+                    // Anno fiscale da settembre $y a agosto $y+1
+                    $months = array_merge(range(9, 12), range(1, 8));
+                    $years = [
+                        9 => $y, 10 => $y, 11 => $y, 12 => $y,
+                        1 => $y+1, 2 => $y+1, 3 => $y+1, 4 => $y+1,
+                        5 => $y+1, 6 => $y+1, 7 => $y+1, 8 => $y+1
+                    ];
+
+                    $recordsQuery->where(function ($q) use ($months, $years) {
+                        foreach ($months as $month) {
+                            $year = $years[$month];
+                            $q->orWhereRaw("JSON_CONTAINS(`records_rows`.`when`, '{\"month\":\"{$month}\",\"year\":\"{$year}\"}')");
+                        }
+                    });
+
+                } else {
+                    $recordsQuery->whereRaw("JSON_CONTAINS(`records_rows`.`when`, '{\"month\":\"{$m}\",\"year\":\"{$y}\"}')");
+                }
+                $records = $recordsQuery->get();
 
                 foreach($records as $record)
                 {
@@ -242,18 +278,50 @@ class RecordINOUT extends Component
                     $this->updateParent("IN", $record->causal_id, $amount, $filter);
                 }
 
-                $records = \App\Models\Record::where('type', 'OUT')
+                // $records = \App\Models\Record::where('type', 'OUT')
+                //     ->join('records_rows', 'records.id', '=', 'records_rows.record_id')
+                //     ->whereNotIn('records_rows.causal_id', $this->excludeCausals)
+                //     ->where(function ($query)  {
+                //         $query->where('deleted', false)->orWhere('deleted', null);
+                //     })
+                //     ->where(function ($query)  {
+                //         $query->where('financial_movement', false)->orWhere('financial_movement', null);
+                //     })
+                //     ->whereNotIn('member_id', $exclude_from_records)
+                //     ->where('records_rows.when', 'like', '%"' . $f . '"%')->get();
+                //$records = $records->orderBy('date', 'DESC')->get();
+
+                $recordsQuery = \App\Models\Record::where('type', 'OUT')
                     ->join('records_rows', 'records.id', '=', 'records_rows.record_id')
                     ->whereNotIn('records_rows.causal_id', $this->excludeCausals)
-                    ->where(function ($query)  {
+                    ->where(function ($query) {
                         $query->where('deleted', false)->orWhere('deleted', null);
                     })
-                    ->where(function ($query)  {
+                    ->where(function ($query) {
                         $query->where('financial_movement', false)->orWhere('financial_movement', null);
                     })
-                    ->whereNotIn('member_id', $exclude_from_records)
-                    ->where('records_rows.when', 'like', '%"' . $f . '"%')->get();
-                //$records = $records->orderBy('date', 'DESC')->get();
+                    ->whereNotIn('member_id', $exclude_from_records);
+
+                if ($m === 'x') {
+                    // Anno fiscale da settembre $y a agosto $y+1
+                    $months = array_merge(range(9, 12), range(1, 8));
+                    $years = [
+                        9 => $y, 10 => $y, 11 => $y, 12 => $y,
+                        1 => $y+1, 2 => $y+1, 3 => $y+1, 4 => $y+1,
+                        5 => $y+1, 6 => $y+1, 7 => $y+1, 8 => $y+1
+                    ];
+
+                    $recordsQuery->where(function ($q) use ($months, $years) {
+                        foreach ($months as $month) {
+                            $year = $years[$month];
+                            $q->orWhereRaw("JSON_CONTAINS(`records_rows`.`when`, '{\"month\":\"{$month}\",\"year\":\"{$year}\"}')");
+                        }
+                    });
+
+                } else {
+                    $recordsQuery->whereRaw("JSON_CONTAINS(`records_rows`.`when`, '{\"month\":\"{$m}\",\"year\":\"{$y}\"}')");
+                }
+                $records = $recordsQuery->get();
 
                 foreach($records as $record)
                 {
@@ -272,7 +340,6 @@ class RecordINOUT extends Component
                         $this->records_out[$filter][$record->causal_id] = $amount;
                     $this->updateParent("OUT", $record->causal_id, $amount, $filter);
                 }
-
             }
         }
 
@@ -407,7 +474,12 @@ class RecordINOUT extends Component
                 $ret = '';
                 break;
         }
-        $ret .= $y;
+        if ($m == 'x') {
+            $nextY = $y+1;
+            $ret = "{$y}/{$nextY}";
+        } else {
+            $ret .= $y;
+        }
         return $ret;
     }
 
@@ -438,6 +510,7 @@ class RecordINOUT extends Component
     {
 
         $rows_in = array();
+        $rows_out = array();
 
         if ($this->filterCausalsIn != null && sizeof($this->filterCausalsIn) > 0)
         {
@@ -454,7 +527,22 @@ class RecordINOUT extends Component
             $rows_in = $this->rows_in;
         }
 
-        $path = $this->generateExcel($this->columns, $rows_in, $this->records_in, $this->rows_out, $this->records_out,false);
+        if ($this->filterCausalsOut != null && sizeof($this->filterCausalsOut) > 0)
+        {
+            foreach($this->rows_out as $r)
+            {
+                if (in_array($r["id"], $this->filterCausalsOut) || in_array($r["parent_id"], $this->filterCausalsOut) || in_array($r["first_parent_id"], $this->filterCausalsOut))
+                {
+                    $rows_out[] = $r;
+                }
+            }
+        }
+        else
+        {
+            $rows_out = $this->rows_out;
+        }
+
+        $path = $this->generateExcel($this->columns, $rows_in, $this->records_in, $rows_out, $this->records_out,false);
 
         return response()->download($path)->deleteFileAfterSend();
 

+ 8 - 0
public/css/style.css

@@ -16813,4 +16813,12 @@ body input[type=checkbox][name="annulla_lezione"]:checked {
 
 body div.dt-button-background {
   pointer-events: none;
+}
+
+select[multiple] {
+    max-height: 44px;
+}
+
+select[multiple] option {
+    display: none;
 }

+ 5 - 5
resources/views/livewire/records_in_out.blade.php

@@ -16,14 +16,14 @@
         <form action="" class=" d-flex align-items-center ">
 
             <select class="form-select form-select-lg me-1 " id="month" style="width:150px !important;">
-                <option value="x" {{$month == "x" ? 'selected' : ""}}>Anno completo</option>
+                <option value="x" {{$month == "x" ? 'selected' : ""}}>Stagione</option>
                 @foreach(getMonthList() as $mid => $mname)
                     <option value="{{$mid}}" {{$month == $mid ? 'selected' : ""}}>{{$mname}}</option>
                 @endforeach
             </select>
 
-            <select class="form-select " style="width:100px !important;" id="year">
-                @for($y=date("Y") + 5; $y>date("Y") - 2; $y--)
+            <select class="form-select " style="width:130px !important;" id="year">
+                @for($y=date("Y") + 5; $y>=date("Y") - 2; $y--)
                     <option value="{{$y}}" {{$y == date("Y") ? 'selected' : ''}}>{{$y}}</option>
                 @endfor
             </select>
@@ -75,7 +75,7 @@
                         Filtra per causale
                         </div>
                         <div class="col-md-12 m-1">
-                            <select name="search_causal_id[]" class="form-select filterCausalsIn filterCausals" multiple="multiple" wire:model="filterCausalsIn">
+                            <select name="search_causal_id[]" class="form-select filterCausalsIn filterCausals" multiple="multiple" wire:model="filterCausalsIn" wire:change='reset-collapse'>
                                 @foreach($causalsIn as $causal)
                                     <option value="{{$causal["id"]}}">{!!$causal["name"]!!}
                                 @endforeach
@@ -195,7 +195,7 @@
                             <label class="form-label">Filtra per causale</label>
                         </div>
                         <div class="col-md-12 m-1">
-                            <select name="search_causal_id_x[]" class="form-select filterCausalsOut filterCausals" multiple="multiple" wire:model="filterCausalsOut">
+                            <select name="search_causal_id_x[]" class="form-select filterCausalsOut filterCausals" multiple="multiple" wire:model="filterCausalsOut" wire:change='reset-collapse'>
                                 @foreach($causalsOut as $causal)
                                     <option value="{{$causal["id"]}}">{!!$causal["name"]!!}
                                 @endforeach