Luca Parisio преди 1 година
родител
ревизия
94659947ca
променени са 5 файла, в които са добавени 327 реда и са изтрити 111 реда
  1. 84 77
      app/Http/Livewire/Member.php
  2. 1 1
      app/Http/Livewire/Record.php
  3. 1 1
      app/Http/Livewire/RecordINOUT.php
  4. 129 32
      resources/views/livewire/member.blade.php
  5. 112 0
      routes/web.php

+ 84 - 77
app/Http/Livewire/Member.php

@@ -372,96 +372,101 @@ class Member extends Component
     public function render()
     {
 
-        // $this->emit('destroy-data-table');
-
         $datas = [];
-        if (!$this->advanced)
-        {
-            /*if ($this->search != '')
-                $datas = \App\Models\Member::select('members.*') // , \DB::raw('SUM(records.id) As total'))
-                    ->where('first_name', 'LIKE', '%' . $this->search . '%')
-                    ->orWhere('last_name', 'LIKE', '%' . $this->search . '%')
-                    ->orWhere('email', 'LIKE', '%' . $this->search . '%');
-                $this->records = \App\Models\Member::where('first_name', 'LIKE', '%' . $this->search . '%')->orWhere('last_name', 'LIKE', '%' . $this->search . '%')->orWhere('email', 'LIKE', '%' . $this->search . '%')->get();
-            else*/
-                $this->records = \App\Models\Member::get();
-                //$datas = \App\Models\Member::select('members.*');
-        }
-        else
+        // $this->emit('destroy-data-table');
+        if (false)
         {
-            //$this->records = \App\Models\Member::where('id', '>', 0);
-            $datas = \App\Models\Member::select('members.*')->where('id', '>', 0);
-            if (sizeof($this->filterCard) > 0)
-            {
-                $card_ids = \App\Models\MemberCard::whereIn('card_id', $this->filterCard)->pluck('member_id');
-                //$this->records->whereIn('id', $card_ids);
-                $datas = $datas->whereIn('id', $card_ids);
-            }
-            if (sizeof($this->filterCategory) > 0)
-            {
-                $cats_ids = \App\Models\MemberCategory::whereIn('category_id', $this->filterCategory)->pluck('member_id');
-                //$this->records->whereIn('id', $cats_ids);
-                $datas = $datas->whereIn('id', $cats_ids);
-            }
-            $certs = [];
 
-            if ($this->filterCertNormal > 0)
-            {
-                $normal = \App\Models\MemberCertificate::where('type', 'N')->pluck('member_id');
-                //$this->records->whereIn('id', $normal);
-                $datas = $datas->whereIn('id', $normal);;
-            }
-            if ($this->filterCertAgonistic > 0)
-            {
-                $agonistic = \App\Models\MemberCertificate::where('type', 'A')->pluck('member_id');
-                //$this->records->whereIn('id', $agonistic);
-                $datas = $datas->whereIn('id', $agonistic);
-            }
-            if ($this->filterCertScaduto > 0)
+            if (!$this->advanced)
             {
-                $scaduto = \App\Models\MemberCertificate::where('expire_date', '<', date("Y-m-d"))->pluck('member_id');
-                //$this->records->whereIn('id', $scaduto);
-                $datas = $datas->whereIn('id', $scaduto);
+                /*if ($this->search != '')
+                    $datas = \App\Models\Member::select('members.*') // , \DB::raw('SUM(records.id) As total'))
+                        ->where('first_name', 'LIKE', '%' . $this->search . '%')
+                        ->orWhere('last_name', 'LIKE', '%' . $this->search . '%')
+                        ->orWhere('email', 'LIKE', '%' . $this->search . '%');
+                    $this->records = \App\Models\Member::where('first_name', 'LIKE', '%' . $this->search . '%')->orWhere('last_name', 'LIKE', '%' . $this->search . '%')->orWhere('email', 'LIKE', '%' . $this->search . '%')->get();
+                else*/
+                    $this->records = \App\Models\Member::select('id', 'first_name', 'last_name', 'phone')->get();
+                    //$datas = \App\Models\Member::select('members.*');
             }
-            if ($this->filterCertInScadenza > 0)
+            else
             {
-                $scaduto = \App\Models\MemberCertificate::whereBetween('expire_date', [date("Y-m-d"), date("Y-m-d", strtotime("+1 month"))])->pluck('member_id');
-                //$this->records->whereIn('id', $scaduto);
-                $datas = $datas->whereIn('id', $scaduto);
+                //$this->records = \App\Models\Member::where('id', '>', 0);
+                $datas = \App\Models\Member::select('members.*')->where('id', '>', 0);
+                if (sizeof($this->filterCard) > 0)
+                {
+                    $card_ids = \App\Models\MemberCard::whereIn('card_id', $this->filterCard)->pluck('member_id');
+                    //$this->records->whereIn('id', $card_ids);
+                    $datas = $datas->whereIn('id', $card_ids);
+                }
+                if (sizeof($this->filterCategory) > 0)
+                {
+                    $cats_ids = \App\Models\MemberCategory::whereIn('category_id', $this->filterCategory)->pluck('member_id');
+                    //$this->records->whereIn('id', $cats_ids);
+                    $datas = $datas->whereIn('id', $cats_ids);
+                }
+                $certs = [];
+
+                if ($this->filterCertNormal > 0)
+                {
+                    $normal = \App\Models\MemberCertificate::where('type', 'N')->pluck('member_id');
+                    //$this->records->whereIn('id', $normal);
+                    $datas = $datas->whereIn('id', $normal);;
+                }
+                if ($this->filterCertAgonistic > 0)
+                {
+                    $agonistic = \App\Models\MemberCertificate::where('type', 'A')->pluck('member_id');
+                    //$this->records->whereIn('id', $agonistic);
+                    $datas = $datas->whereIn('id', $agonistic);
+                }
+                if ($this->filterCertScaduto > 0)
+                {
+                    $scaduto = \App\Models\MemberCertificate::where('expire_date', '<', date("Y-m-d"))->pluck('member_id');
+                    //$this->records->whereIn('id', $scaduto);
+                    $datas = $datas->whereIn('id', $scaduto);
+                }
+                if ($this->filterCertInScadenza > 0)
+                {
+                    $scaduto = \App\Models\MemberCertificate::whereBetween('expire_date', [date("Y-m-d"), date("Y-m-d", strtotime("+1 month"))])->pluck('member_id');
+                    //$this->records->whereIn('id', $scaduto);
+                    $datas = $datas->whereIn('id', $scaduto);
+                }
+                if (sizeof($certs) > 0)
+                {
+                    $datas = $datas->whereIn('id', $certs);
+                    //$this->records->whereIn('id', $certs);
+                }
+                $this->records = $datas->get();
+
             }
-            if (sizeof($certs) > 0)
+
+            foreach($this->records as $r)
             {
-                $datas = $datas->whereIn('id', $certs);
-                //$this->records->whereIn('id', $certs);
+                $r->age = $r->getAge();
+                $active = $r->isActive();
+                $r->status = $active["status"];
+                $r->date = $active["date"];
+                $r->certificate = $r->hasCertificate()["date"];
+                $r->state = $r->getStatus()["status"];
             }
-            $this->records = $datas->get();
-
-        }
+            /*
+            if ($this->sortAsc)
+                $this->records = $this->records->sortBy($this->sortField);
+            else
+                $this->records = $this->records->sortByDesc($this->sortField);
+            */
 
-        /*
-        foreach($this->records as $r)
-        {
-            $r->age = $r->getAge();
-            $r->status = $r->isActive()["status"];
-            $r->certificate = $r->hasCertificate()["status"];
-            $r->state = $r->getStatus()["status"];
-        }
+            //$datas = $datas->get(); // ->orderBy($this->sortField, $this->sortAsc ? 'ASC' : 'DESC')->paginate(10);
 
-        if ($this->sortAsc)
-            $this->records = $this->records->sortBy($this->sortField);
-        else
-            $this->records = $this->records->sortByDesc($this->sortField);
-        */
+            //$this->records = $this->records->get();
+            $this->loadMemberCards();
+            $this->loadMemberCourses();
+            $this->loadMemberCategories();
+            $this->loadMemberCertificates();
 
-        //$datas = $datas->get(); // ->orderBy($this->sortField, $this->sortAsc ? 'ASC' : 'DESC')->paginate(10);
-
-        //$this->records = $this->records->get();
-        $this->loadMemberCards();
-        $this->loadMemberCourses();
-        $this->loadMemberCategories();
-        $this->loadMemberCertificates();
+            $this->emit('load-data-table');
+        }
 
-        $this->emit('load-data-table');
 
         return view('livewire.member', ['datas' => $datas]);
     }
@@ -1574,4 +1579,6 @@ class codicefiscale {
 
         return $codice;
     }
+
+
 }

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

@@ -517,7 +517,7 @@ class Record extends Component
             $activeWorksheet->getColumnDimension($l)->setWidth(20);
 
         $writer = new Xlsx($spreadsheet);
-        $writer->save($path = storage_path('export.xlsx'));
+        $writer->save($path = storage_path('prima_nota_' . date("YmdHis") . '.xlsx'));
 
         return response()->download($path)->deleteFileAfterSend();
 

+ 1 - 1
app/Http/Livewire/RecordINOUT.php

@@ -521,7 +521,7 @@ class RecordINOUT extends Component
             $activeWorksheet->getColumnDimension($l)->setWidth(20);
 
         $writer = new Xlsx($spreadsheet);
-        $writer->save($path = storage_path('export.xlsx'));
+        $writer->save($path = storage_path('entrate_uscite_' . date("YmdHis") . '.xlsx'));
 
         return $path;
 

+ 129 - 32
resources/views/livewire/member.blade.php

@@ -185,7 +185,7 @@
 
         @else
 
-        <div class="col-auto filterWrapper" id="filter--section" wire:ignore.self>
+        <div class="col-auto filterWrapper" id="filter--section" wire:ignore>
             <aside>
                 <header>
                     <h2>Filtra Utenti</h2>
@@ -200,7 +200,7 @@
                             <div class="col-12">
                                 @foreach(getCards() as $card)
                                     <div class="form-check form-check-inline  align-items-center">
-                                        <input class="form-check-input" type="checkbox" value="{{$card->id}}" wire:model="filterCard"  onclick="destroyDataTable()">
+                                        <input class="form-check-input chkCard" type="checkbox" value="{{$card->id}}">
                                         <label class="form-check-label ms-2" >{{$card->name}}</label>
                                     </div>
                                 @endforeach
@@ -215,21 +215,21 @@
                         <div class="filter--item_formElement row">
                             <div class="col-6">
                                 <div class="form-check form-check-inline  align-items-center">
-                                    <input class="form-check-input" type="checkbox"  wire:model="filterCertNormal" onclick="destroyDataTable()">
+                                    <input class="form-check-input chkCertificateNormal" type="checkbox">
                                     <label class="form-check-label ms-2" >Normale</label>
                                 </div>
                                 <div class="form-check form-check-inline  align-items-center">
-                                    <input class="form-check-input" type="checkbox"  wire:model="filterCertInScadenza" onclick="destroyDataTable()">
+                                    <input class="form-check-input chkCertificateScadenza" type="checkbox" >
                                     <label class="form-check-label ms-2" >In Scadenza</label>
                                 </div>
                             </div>
                             <div class="col-6">
                                 <div class="form-check form-check-inline  align-items-center">
-                                    <input class="form-check-input" type="checkbox"  wire:model="filterCertAgonistic" onclick="destroyDataTable()">
+                                    <input class="form-check-input chkCertificateAgonistico" type="checkbox" >
                                     <label class="form-check-label ms-2" >Agonistico</label>
                                 </div>
                                 <div class="form-check form-check-inline  align-items-center">
-                                    <input class="form-check-input" type="checkbox"  wire:model="filterCertScaduto"  onclick="destroyDataTable()">
+                                    <input class="form-check-input chkCertificateScaduti" type="checkbox" >
                                     <label class="form-check-label ms-2" >Scaduti</label>
                                 </div>
 
@@ -245,7 +245,7 @@
                             <div class="col-6">
                                 @foreach(getCategories() as $category)
                                     <div class="form-check form-check-inline  align-items-center">
-                                        <input class="form-check-input" type="checkbox"  value="{{$category->id}}" wire:model="filterCategory"  onclick="destroyDataTable()">
+                                        <input class="form-check-input chkCategory" type="checkbox"  value="{{$category->id}}" >
                                         <label class="form-check-label ms-2" >{{$category->name}}</label>
                                     </div>
                                 @endforeach
@@ -262,7 +262,8 @@
 
                 <footer>
                     <div class="filter--buttons d-flex align-items-center justify-content-between">
-                        <button class="btn--ui small dark disable"  wire:click.prevent="advancedSearchCancel()" onclick="destroyDataTable()">cancella</button><button class="btn--ui small white" onclick="destroyDataTable()" wire:click.prevent="advancedSearch()">filtra</button>
+                        <button class="btn--ui small dark disable"  wire:click.prevent="advancedSearchCancel()" onclick="destroyDataTable()">cancella</button>
+                        <button class="btn--ui small white" onclick="loadDataTable()">filtra</button>
                     </div>
                 </footer>
 
@@ -293,13 +294,13 @@
                 <button id="close-filter" onclick="pcsh2()"></button>
 
                 <section id="subheader" class="d-flex align-items-center justify-content-between">
-                    <form action="" class="group--action d-flex align-items-center">
+                    <!--<form action="" class="group--action d-flex align-items-center">
                     <select class="form-select form-select-lg me-1" aria-label=".form-select-lg example" wire:model="multipleAction">
                         <option selected>Azione multipla</option>
                         <option value="delete">Elimina</option>
                         </select>
                         <button type="submit" class="btn--ui" wire:click.prevent="executeMultipleAction()">applica</button>
-                    </form>
+                    </form>-->
 
                     @if(false)
                     <form action="" class="search--form d-flex align-items-center">
@@ -324,8 +325,6 @@
                         <thead>
                             <tr>
                                 <!--<th scope="col"><label><input class="table-check" type="checkbox" data-tablesaw-checkall=""></th>-->
-                                <th scope="col"><input class="table-check" type="checkbox" wire:model="checkedAll"  wire:click="checkUncheckAll()"></th>
-                                <th scope="col">#</th>
                                 <th scope="col">Codice</th>
                                 <th scope="col">Cognome</th>
                                 <th scope="col">Nome</th>
@@ -338,6 +337,7 @@
                             </tr>
                         </thead>
                         <tbody id="checkall-target">
+                            @if(false)
                             @foreach($records as $idx => $record)
                                 <tr>
                                     <td> <label><input class="table-check" type="checkbox" wire:model="multipleIds" value="{{$record->id}}"><span class="sr-only d-inline-block d-lg-none ms-2 mobile-row-selector"> Seleziona riga</span></label></td>
@@ -350,43 +350,35 @@
                                             <a href="tel:{{$record->phone}}">{{$record->phone}}</a>
                                         @endif
                                     </td>
-                                    <td>{{$record->getAge() > 0 ? $record->getAge() : ''}} </td>
-                                    @php
-                                    $member_status = $record->getStatus();
-                                    @endphp
+                                    <td>{{$record->age > 0 ? $record->age : ''}} </td>
+
                                     <td>
-                                        <span class="tablesaw-cell-content"><span class="badge tessera-badge {{$member_status["status"] > 0 ? ($member_status["status"] == 2 ? 'active' : 'suspended') : 'due'}}">{{$member_status["status"] > 0 ? ($member_status["status"] == 2 ? 'Tesserato' : 'Sospeso') : 'Non tesserato'}}</span></span>
+                                        <span class="tablesaw-cell-content"><span class="badge tessera-badge {{$record->state > 0 ? ($record->state == 2 ? 'active' : 'suspended') : 'due'}}">{{$record->state > 0 ? ($record->state == 2 ? 'Tesserato' : 'Sospeso') : 'Non tesserato'}}</span></span>
                                     </td>
-                                    @php
-                                    $isSubscribed = $record->isActive();
-                                    @endphp
                                     <td>
-                                        <span class="tablesaw-cell-content"><span class="badge tessera-badge {{$isSubscribed["status"] > 0 ? ($isSubscribed["status"] == 2 ? 'active' : 'suspended') : ''}}">{{$isSubscribed["status"] > 0 ? ($isSubscribed["status"] == 2 ? 'Attivo' : 'Sospesa') : ''}}</span></span>
+                                        <span class="tablesaw-cell-content"><span class="badge tessera-badge {{$record->status > 0 ? ($record->status == 2 ? 'active' : 'suspended') : ''}}">{{$record->status > 0 ? ($record->status == 2 ? 'Attivo' : 'Sospesa') : ''}}</span></span>
                                         <b class=" tablesaw-cell-label">Scadenza tessera</b>
                                         <span class="tablesaw-cell-content d-flex align-items-center">
-                                            {{$isSubscribed["status"] ? 'Scadenza : ' : ($isSubscribed["date"] != '' ? 'Scaduto : ' : '')}} {{$isSubscribed["date"] != '' ? date("d/m/Y", strtotime($isSubscribed["date"])) : ''}}
+                                            {{$record->status ? 'Scadenza : ' : ($record->date != '' ? 'Scaduto : ' : '')}} {{$record->date != '' ? date("d/m/Y", strtotime($record->date)) : ''}}
                                         </span>
                                     </td>
-                                    @php
-                                    $has_certificate = $record->hasCertificate();
-                                    @endphp
                                     <td>
-                                        @if($has_certificate["date"] != '')
+                                        @if($record->certificate != '')
                                             <b class=" tablesaw-cell-label">Scadenza certificato</b>
                                             <span class="tablesaw-cell-content d-flex align-items-center">
-                                                @if($has_certificate["date"] < date("Y-m-d"))
+                                                @if($record->certificate < date("Y-m-d"))
                                                     <i class="ico--ui check suspended me-2"></i>
                                                     Scaduto :
                                                 @endif
-                                                @if($has_certificate["date"] >= date("Y-m-d") && $has_certificate["date"] < date("Y-m-d", strtotime("+1 month")))
+                                                @if($record->certificate >= date("Y-m-d") && $record->certificate < date("Y-m-d", strtotime("+1 month")))
                                                     <i class="ico--ui check due me-2"></i>
                                                     In scadenza :
                                                 @endif
-                                                @if($has_certificate["date"] >= date("Y-m-d", strtotime("+1 month")))
+                                                @if($record->certificate >= date("Y-m-d", strtotime("+1 month")))
                                                     <i class="ico--ui check active me-2"></i>
                                                     Scadenza :
                                                 @endif
-                                                {{$has_certificate["date"] != '' ? date("d/m/Y", strtotime($has_certificate["date"])) : ''}}
+                                                {{$record->certificate != '' ? date("d/m/Y", strtotime($record->certificate)) : ''}}
                                             </span>
                                         @endif
                                     </td>
@@ -397,7 +389,7 @@
                                     </td>
                                 </tr>
                             @endforeach
-
+                            @endif
                         </tbody>
                     </table>
 
@@ -1525,6 +1517,17 @@
 @push('scripts')
     <script>
 
+        function editData(id)
+        {
+            @this.edit(id);
+        }
+
+        function deleteData(id)
+        {
+            if (confirm('Sei sicuro?'))
+                @this.delete(id);
+        }
+
         $(document).ready(function() {
             loadDataTable();
         } );
@@ -1550,10 +1553,104 @@
                 $('#tablesaw-350').DataTable().destroy();
             }
 
+            // Carico i filtri
+            var cards = "";
+            $('input:checkbox.chkCard').each(function () {
+                if (this.checked)
+                {
+                    if (cards != "") cards += ",";
+                    cards += $(this).val();
+                }
+            });
+
+            var categories = "";
+            $('input:checkbox.chkCategory').each(function () {
+                if (this.checked)
+                {
+                    if (categories != "") categories += ",";
+                    categories += $(this).val();
+                }
+            });
+
+            var chkCertificateNormal = $(".chkCertificateNormal").is(':checked') ? "1" : "";
+            var chkCertificateAgonistico = $(".chkCertificateAgonistico").is(':checked') ? "1" : "";
+            var chkCertificateScadenza = $(".chkCertificateScadenza").is(':checked') ? "1" : "";
+            var chkCertificateScaduti = $(".chkCertificateScaduti").is(':checked') ? "1" : "";
+
             $('#tablesaw-350').DataTable({
                 //destroy: true,
+                ajax: '/get_members?cards=' + cards + "&categories=" + categories + "&chkCertificateNormal=" + chkCertificateNormal + "&chkCertificateAgonistico=" + chkCertificateAgonistico + "&chkCertificateScadenza=" + chkCertificateScadenza + "&chkCertificateScaduti=" + chkCertificateScaduti,
+                columns: [
+                    { data: 'id' },
+                    { data: "first_name" },
+                    { data: "last_name"},
+                    { data: "phone"},
+                    { data: "age"},
+                    {
+                        data: "status",
+                        render: function (data){
+                            // Split class and text
+                            const d = data.split("|");
+                            var ret = '<span class="tablesaw-cell-content"><span class="badge tessera-badge ' + d[0] + '">' + d[1] + '</span></span>';
+                            return ret;
+                        }
+                    },
+                    {
+                        data: "state",
+                        render: function (data){
+                            // Split class and text
+                            const d = data.split("|");
+                            var ret = '<span class="tablesaw-cell-content"><span class="badge tessera-badge ' + d[0] + '">' + d[1] + '</span></span>';
+                            ret += '<b class=" tablesaw-cell-label">Scadenza tessera</b>';
+                            ret += '<span class="tablesaw-cell-content d-flex align-items-center">';
+                            d[2] + ' ' + d[3];
+                            ret += '</span>';
+                            return ret;
+                        }
+                    },
+                    {
+                        data: "certificate",
+                        render: function (data){
+                            // Split class and text
+                            var ret = '';
+                            if (data != "")
+                            {
+                                const d = data.split("|");
+
+                                ret += '<b class=" tablesaw-cell-label">Scadenza certificato</b>';
+                                ret += '<span class="tablesaw-cell-content d-flex align-items-center">';
+                                if (d[0] == "0")
+                                {
+                                    ret += '<i class="ico--ui check suspended me-2"></i>';
+                                    ret += 'Scaduto : ';
+                                }
+                                if (d[0] == "1")
+                                {
+                                    ret += '<i class="ico--ui check due me-2"></i>';
+                                    ret += 'In scadenza : ';
+                                }
+                                if (d[0] == "2")
+                                {
+                                    ret += '<i class="ico--ui check active me-2"></i>';
+                                    ret += 'Scadenza : ';
+                                }
+                                ret += d[1];
+                                ret += '</span>';
+                            }
+                            return ret;
+                        }
+                    },
+                    {
+                        data: "action",
+                        render: function (data){
+                            var ret = '<button type="button" class="btn btn-outline-primary btn-sm" onclick="editData(' + data + ')">Modifica</button>&nbsp;';
+                            ret += '<button type="button" class="btn btn-outline-danger btn-sm" onclick="deleteData(' + data + ')">Elimina</button>';
+                            return ret;
+                        }
+                    },
+                ],
                 fixedHeader: false,
-                order: [[3, 'asc'], [4, 'asc']],
+                order: [[1, 'asc'], [2, 'asc']],
                 thead: {
                 'th': {'background-color': 'blue'}
                 },

+ 112 - 0
routes/web.php

@@ -77,3 +77,115 @@ Route::get('/cities/{province_id}', function($province_id){
     }
     return array("results" => $data);
 });
+
+Route::get('/get_members', function(){
+
+    $datas = [];
+
+    // $datas = \App\Models\Member::select('members.*')->where('id', '>', 0);
+    $x = \App\Models\Member::select('id', 'first_name', 'last_name', 'phone')->where('id', '>', 0);
+    if ($_GET["cards"] != "")
+    {
+        $card_ids = \App\Models\MemberCard::whereIn('card_id', explode(",", $_GET["cards"]))->pluck('member_id');
+        $x = $x->whereIn('id', $card_ids);
+    }
+    if ($_GET["categories"] != "")
+    {
+        $cats_ids = \App\Models\MemberCategory::whereIn('category_id', explode(",", $_GET["categories"]))->pluck('member_id');
+        $x = $x->whereIn('id', $cats_ids);
+    }
+
+    $certs = [];
+
+    if ($_GET["chkCertificateNormal"] != "")
+    {
+        $normal = \App\Models\MemberCertificate::where('type', 'N')->pluck('member_id');
+        $x = $x->whereIn('id', $normal);;
+    }
+    if ($_GET["chkCertificateAgonistico"] != "")
+    {
+        $agonistic = \App\Models\MemberCertificate::where('type', 'A')->pluck('member_id');
+        $x = $x->whereIn('id', $agonistic);
+    }
+    if ($_GET["chkCertificateScaduti"] != "")
+    {
+        $scaduto = \App\Models\MemberCertificate::where('expire_date', '<', date("Y-m-d"))->pluck('member_id');
+        $x = $x->whereIn('id', $scaduto);
+    }
+    if ($_GET["chkCertificateScadenza"] != "")
+    {
+        $scadenza = \App\Models\MemberCertificate::whereBetween('expire_date', [date("Y-m-d"), date("Y-m-d", strtotime("+1 month"))])->pluck('member_id');
+        $x = $x->whereIn('id', $scadenza);
+    }
+    if (sizeof($certs) > 0)
+    {
+        $x = $x->whereIn('id', $certs);
+    }
+
+    $x = $x->get();
+
+
+    foreach($x as $idx => $r)
+    {
+        $status = $r->getStatus();
+        $status = $status["status"];
+
+        $class = $status > 0 ? ($status == 2 ? 'active' : 'suspended') : 'due';
+        $text = $status > 0 ? ($status == 2 ? 'Tesserato' : 'Sospeso') : 'Non tesserato';
+
+        $state = $r->isActive();
+        $x = $state["status"] > 0 ? ($state["status"] == 2 ? 'active' : 'suspended') : '';
+        $x .= "|";
+        $x .= $state["status"] > 0 ? ($state["status"] == 2 ? 'Attivo' : 'Sospesa') : '';
+        $x .= "|";
+        $x .= $state["status"] ? 'Scadenza : ' : ($state["date"] != '' ? 'Scaduto : ' : '');
+        $x .= "|";
+        $x .= $state["date"] != '' ? date("d/m/Y", strtotime($state["date"])) : '';
+
+        $has_certificate = $r->hasCertificate();
+        $y = '';
+        if($has_certificate["date"] != '')
+        {
+            if($has_certificate["date"] < date("Y-m-d"))
+                $y .= '0';
+
+            if($has_certificate["date"] >= date("Y-m-d") && $has_certificate["date"] < date("Y-m-d", strtotime("+1 month")))
+                $y .= '1';
+
+            if($has_certificate["date"] >= date("Y-m-d", strtotime("+1 month")))
+                $y .= '2';
+            $y .= '|';
+            $y .= $has_certificate["date"] != '' ? date("d/m/Y", strtotime($has_certificate["date"])) : '';
+        }
+
+        $datas[] = array(
+            'id' => $r->id,
+            'first_name' => $r->first_name,
+            'last_name' => $r->last_name,
+            'phone' => $r->phone,
+            'age' => $r->getAge(),
+            'status' => $class . "|" . $text,
+            'state' => $x,
+            'certificate' => $y,
+            'action' => $r->id
+        );
+        /*
+        $r->age = $r->getAge();
+        $active = $r->isActive();
+        $r->status = $active["status"];
+        $r->date = $active["date"] . "|" . $r->hasCertificate()["date"];
+        $r->state = $r->getStatus()["status"];
+        $r->action = '';*/
+    }
+    /*
+    if ($this->sortAsc)
+        $this->records = $this->records->sortBy($this->sortField);
+    else
+        $this->records = $this->records->sortByDesc($this->sortField);
+    */
+
+    // $datas = $x; // ->orderBy($this->sortField, $this->sortAsc ? 'ASC' : 'DESC')->paginate(10);
+    return json_encode(array("data" => $datas));
+
+
+});