Bläddra i källkod

flusso archivio archiviazione

FabioFratini 7 månader sedan
förälder
incheckning
4b11472c64

+ 82 - 138
app/Http/Livewire/Member.php

@@ -147,6 +147,8 @@ class Member extends Component
     public $already_existing = false;
     private $fileService;
 
+    public $hasCertificate = false;
+
     protected $rules = [
         'first_name' => 'required',
         'last_name' => 'required',
@@ -369,19 +371,6 @@ class Member extends Component
 
             $this->course_subscriptions = \App\Models\CourseSubscription::select('*')->whereIn('id', $course_subscription_ids)->where('enabled', true)->get();
 
-            /*
-
-            if ($this->course_course_id > 0) {
-                $c = \App\Models\Course::findOrFail($this->course_course_id);
-                $this->course_price = formatPrice($c->price);
-                $this->course_subscription_price = formatPrice($c->subscription_price);
-                // Controllo se sono già iscritto la corso
-                $this->course_exist = \App\Models\MemberCourse::where('course_id', $this->course_course_id)->where('member_id', $this->dataId)->count() > 0;
-            } else {
-                $this->course_price = 0;
-                $this->course_subscription_price = 0;
-                $this->course_exist = false;
-            }*/
         } else {
             $this->course_price = 0;
             $this->course_subscription_price = 0;
@@ -552,13 +541,6 @@ class Member extends Component
 
         $this->getCategories(\App\Models\Category::select('id', 'name')->where('parent_id', null)->orderBy('name')->get(), 0);
 
-
-        // $this->getCourses(\App\Models\Course::select('id', 'name')->where('parent_id', null)->get(), 0);
-
-        /*$this->nations = \App\Models\Nation::select('id', 'name')->orderBy('name')->get();
-        $this->provinces = \App\Models\Province::where('nation_id', 1)->orderBy('name')->get();
-        $this->cities = \App\Models\City::where('province_id', 178)->orderBy('name')->orderBy('name')->get();*/
-
         $c = \App\Models\Causal::where('type', 'IN')->where('money', true)->first();
         if ($c)
             $this->causalId = $c->id;
@@ -567,9 +549,6 @@ class Member extends Component
             $this->showDetailF($_GET["member_detail"]);
             $this->refreshAfter = 1;
         }
-        /*$this->birthNations = \App\Models\Nation::select('id', 'name')->orderBy('name')->get();
-        $this->birthProvinces = \App\Models\Province::where('nation_id', 1)->orderBy('name')->get();
-        $this->birthCities = \App\Models\City::where('province_id', 178)->orderBy('name')->orderBy('name')->get();*/
     }
 
     public function boot(){
@@ -648,37 +627,6 @@ class Member extends Component
         } else
             $this->isBirthItaly = false;
     }
-
-    /*public function loadProvinces()
-    {
-        $n = \App\Models\Nation::findOrFail($this->nation_id);
-        $this->isItaly = $n->is_italy;
-        $this->provinces = \App\Models\Province::where('nation_id', $this->nation_id)->orderBy('name')->get();
-        $this->cities = array();
-        $this->selectId++;
-    }
-
-    public function loadCities()
-    {
-        $this->cities = \App\Models\City::where('province_id', $this->province_id)->orderBy('name')->orderBy('name')->get();
-        $this->selectId++;
-    }
-
-    public function loadBirthProvinces()
-    {
-        $n = \App\Models\Nation::findOrFail($this->birth_nation_id);
-        $this->isBirthItaly = $n->is_italy;
-        $this->birthProvinces = \App\Models\Province::where('nation_id', $this->birth_nation_id)->orderBy('name')->get();
-        $this->birthCities = array();
-        $this->selectId++;
-    }
-
-    public function loadBirthCities()
-    {
-        $this->birthCities = \App\Models\City::where('province_id', $this->birth_province_id)->get();
-        $this->selectId++;
-    }
-    */
     public function search()
     {
         if ($this->searchTxt != '') {
@@ -719,61 +667,43 @@ class Member extends Component
             if (!in_array($cN, $this->course_names))
                 $this->course_names[] = $cN;
         }
-        //$this->course_names = \App\Models\Course::orderBy('name')->groupBy('name')->pluck('name');
 
 
         $datas = [];
-        // $this->emit('destroy-data-table');
         if (false) {
 
             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::select('id', 'first_name', 'last_name', 'phone')->get();
-                //$datas = \App\Models\Member::select('members.*');
             } else {
-                //$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();
             }
@@ -786,16 +716,6 @@ class Member extends Component
                 $r->certificate = $r->hasCertificate()["date"];
                 $r->state = $r->getStatus()["status"];
             }
-            /*
-            if ($this->sortAsc)
-                $this->records = $this->records->sortBy($this->sortField);
-            else
-                $this->records = $this->records->sortByDesc($this->sortField);
-            */
-
-            //$datas = $datas->get(); // ->orderBy($this->sortField, $this->sortAsc ? 'ASC' : 'DESC')->paginate(10);
-
-            //$this->records = $this->records->get();
 
 
             $this->emit('load-data-table');
@@ -807,7 +727,6 @@ class Member extends Component
         $this->loadMemberCertificates();
 
         $this->courses = \App\Models\Course::select('id', 'name')->where('type', $this->course_course_type)->get();
-        // $this->course_subscriptions = \App\Models\CourseSubscription::select('*')->where('enabled', true)->get();
 
         return view('livewire.member', ['datas' => $datas]);
     }
@@ -851,25 +770,21 @@ class Member extends Component
     public function loadMemberCards()
     {
         $this->member_cards = \App\Models\MemberCard::where('member_id', $this->dataId)->get();
-        // return view('livewire.member');
     }
 
     public function loadMemberCourses()
     {
         $this->member_courses = \App\Models\MemberCourse::where('member_id', $this->dataId)->get();
-        // return view('livewire.member');
     }
 
     public function loadMemberCategories()
     {
         $this->member_categories = \App\Models\MemberCategory::where('member_id', $this->dataId)->get();
-        // return view('livewire.member');
     }
 
     public function loadMemberCertificates()
     {
         $this->member_certificates = \App\Models\MemberCertificate::where('member_id', $this->dataId)->orderBy('expire_date', 'DESC')->get();
-        // return view('livewire.member');
     }
 
     public function showDetailF($id)
@@ -1238,10 +1153,6 @@ class Member extends Component
                 $interval = $date1->diff($date2);
                 $this->age = $interval->y . " anni";
                 $this->under18 = $interval->y < 18;
-                //$this->provinces = \App\Models\Province::where('nation_id', $this->nation_id)->get();
-                //$this->cities = \App\Models\City::where('province_id', $this->province_id)->get();
-                //$this->birthProvinces = \App\Models\Province::where('nation_id', $this->birth_nation_id)->get();
-                //$this->birthCities = \App\Models\City::where('province_id', $this->birth_province_id)->get();
                 $this->update = true;
                 $this->add = false;
 
@@ -1592,7 +1503,7 @@ class Member extends Component
                 }
             }
 
-            \Illuminate\Support\Facades\Log::info('Updating member card', [
+            Log::info('Updating member card', [
                 'card_id' => $this->cardDataId,
                 'member_id' => $this->dataId,
                 'card_number' => $this->card_number,
@@ -1616,7 +1527,7 @@ class Member extends Component
 
             updateMemberData($this->dataId);
 
-            \Illuminate\Support\Facades\Log::info('Card updated successfully', [
+            Log::info('Card updated successfully', [
                 'card_id' => $this->cardDataId,
                 'member_id' => $this->dataId
             ]);
@@ -1625,7 +1536,7 @@ class Member extends Component
             $this->resetCardFields();
             $this->updateCard = false;
         } catch (\Exception $ex) {
-            \Illuminate\Support\Facades\Log::error('Error updating card', [
+            Log::error('Error updating card', [
                 'card_id' => $this->cardDataId,
                 'member_id' => $this->dataId,
                 'error_message' => $ex->getMessage(),
@@ -1657,19 +1568,6 @@ class Member extends Component
     public function addCourse()
     {
         $this->resetCourseFields();
-        /*if ($this->under18)
-        {
-            $this->course_months[] = array("m" => 9, "status" => "");
-            $this->course_months[] = array("m" => 10, "status" => "");
-            $this->course_months[] = array("m" => 11, "status" => "");
-            $this->course_months[] = array("m" => 12, "status" => "");
-            $this->course_months[] = array("m" => 1, "status" => "");
-            $this->course_months[] = array("m" => 2, "status" => "");
-            $this->course_months[] = array("m" => 3, "status" => "");
-            $this->course_months[] = array("m" => 4, "status" => "");
-            $this->course_months[] = array("m" => 5, "status" => "");
-            $this->course_months[] = array("m" => 6, "status" => "");
-        }*/
         $this->addCourse = true;
         $this->updateCourse = false;
         $this->emit('setEditCorso', true);
@@ -1725,24 +1623,6 @@ class Member extends Component
             $rate->status = 0;
             $rate->is_subscription = true;
             $rate->save();
-
-            // Se la data inizio pagamenti è "inizio corso" allora prendo quella come start date
-            /*if ($r->when_start == 'COURSE')
-                $start = $c->date_from;
-
-            //
-            $month_day = $r->month_day;
-            if ($month_day > 0)
-            {
-                if ($month_day >= 29)
-                    $start = date("Y-m-t", strtotime($start));
-                else
-                    $start = date('Y-m-d', strtotime('+' . ($month_day - 1) . ' days', strtotime('first day of ' . ((int)date('j', strtotime($start)) < $month_day ? 'this' : 'next' ) . ' month', strtotime($start))));
-            }
-
-            if ($r->months > 1)
-                $start = date('Y-m-' . ($month_day >= 29 ? 't' : 'd'), strtotime("+" . ($r->months - 1) . " months", strtotime($start)));
-            */
             $go = true;
             while ($go) {
 
@@ -2143,17 +2023,6 @@ class Member extends Component
         } else {
             $this->course_months[] = array("m" => $m, "status" => "");
         }
-
-        /*
-        if (in_array($m, $this->course_months))
-        {
-            $i = array_search($m, $this->course_months);
-            array_splice($this->course_months, $i, 1);
-        }
-        else
-        {
-            $this->course_months[] = $m;
-        }*/
     }
 
     public function newPayment($course)
@@ -2328,7 +2197,6 @@ class Member extends Component
                     }
                     if ($payed < $price)
                         $class = 'orange half';
-                    //$class .= $extraC;
                 }
             }
         }
@@ -2437,6 +2305,83 @@ class Member extends Component
         }
         return $ret;
     }
+    public function archive($id)
+    {
+        try {
+            $member = \App\Models\Member::findOrFail($id);
+
+            $originalFirstName = $member->first_name;
+            $originalLastName = $member->last_name;
+
+            $member->update([
+                'is_archived' => true,
+                'archived_date' => now(),
+
+                'first_name' => 'Nome Archiviato',
+                'last_name' => 'Cognome Archiviato',
+
+                'fiscal_code' => null,
+                'email' => null,
+                'phone' => null,
+                'phone2' => null,
+                'phone3' => null,
+                'address' => null,
+                'zip_code' => null,
+
+                'birth_place' => null,
+                'birth_date' => null,
+                'birth_city_id' => null,
+                'birth_province_id' => null,
+                'birth_nation_id' => null,
+
+                'nation_id' => null,
+                'province_id' => null,
+                'city_id' => null,
+
+                'document_type' => null,
+                'document_number' => null,
+                'document_from' => null,
+                'document_expire_date' => null,
+                'document_files' => null,
+
+                'father_name' => null,
+                'mother_name' => null,
+                'father_email' => null,
+                'mother_email' => null,
+                'father_phone' => null,
+                'mother_phone' => null,
+                'father_fiscal_code' => null,
+                'mother_fiscal_code' => null,
+                'father_doc_number' => null,
+                'father_doc_type' => null,
+                'mother_doc_number' => null,
+                'mother_doc_type' => null,
+                'father_document_files' => null,
+                'mother_document_files' => null,
+
+                'image' => null,
+
+                'gender' => null,
+                'status' => 'archived',
+
+                'enabled' => false
+            ]);
+
+            updateMemberData($id);
+
+            session()->flash('success', 'Membro archiviato con successo');
+
+            $this->emit('reload');
+
+        } catch (\Exception $e) {
+            session()->flash('error', 'Errore durante l\'archiviazione: ' . $e->getMessage());
+            Log::error('Archive member error', [
+                'member_id' => $id,
+                'error' => $e->getMessage(),
+                'trace' => $e->getTraceAsString()
+            ]);
+        }
+    }
 }
 
 class codicefiscale
@@ -2861,7 +2806,6 @@ class codicefiscale
         $codice .= $this->_calcolaCifraControllo($codice);
 
         if (strlen($codice) != 16) {
-            //$this->_setError(self::ERR_GENERIC);
             return 'ERROR';
         }
 

+ 3 - 1
app/Models/Member.php

@@ -53,7 +53,9 @@ class Member extends Model
         'current_status',
         'certificate',
         'certificate_date',
-        'to_complete'
+        'to_complete',
+        'is_archived',
+        'archived_date',
     ];
     public function nation()
     {

+ 2 - 2
app/helpers.php

@@ -63,7 +63,7 @@ function currencyToDouble($val)
 function getConfiguration($field)
 {
     $ret = "";
-    $conf = \App\Models\Configurration::first();
+    $conf = \App\Models\Configuration::first();
     if ($conf)
     {
         $ret = $conf[$field];
@@ -281,4 +281,4 @@ function sms_send($params, $backup = false)
 
     curl_close($c);
     return $content;
-}
+}

+ 32 - 0
database/migrations/2025_06_23_075223_is_archived_field_member_table.php

@@ -0,0 +1,32 @@
+<?php
+
+use App\Database\Migrations\TenantMigration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends TenantMigration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('members', function (Blueprint $table) {
+            $table->boolean('is_archived')->nullable();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('members', function (Blueprint $table) {
+            $table->dropColumn('is_archived');
+        });
+    }
+};

+ 32 - 0
database/migrations/2025_06_23_080139_archived_date_field_member_table.php

@@ -0,0 +1,32 @@
+<?php
+
+use App\Database\Migrations\TenantMigration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends TenantMigration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('members', function (Blueprint $table) {
+            $table->timestamp('archived_date')->nullable()->after('is_archived');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('members', function (Blueprint $table) {
+            $table->dropColumn('archived_date');
+        });
+    }
+};

+ 22 - 254
resources/views/livewire/member.blade.php

@@ -1110,47 +1110,6 @@
                                             </div>
 
                                         @endif
-                                        <!--
-
-                                    <button class="tab--btn w-100"><i class="ico--ui tessera me-2"></i><span class="btn_title">nessuna tessera registrata</span></button>
-
-                                    <div class="tessere--tab">
-                                        <div class="d-flex align-items-start">
-                                            <div class="nav flex-column nav-pills" id="v-pills-tab" role="tablist" aria-orientation="vertical">
-                                                <button class="nav-link active" id="v-pills-fit-tab" data-bs-toggle="pill" data-bs-target="#v-pills-fit" type="button" role="tab" aria-controls="v-pills-fit" aria-selected="true">Fit</button>
-                                                <button class="nav-link" id="v-pills-uisp-tab" data-bs-toggle="pill" data-bs-target="#v-pills-uisp" type="button" role="tab" aria-controls="v-pills-uisp" aria-selected="false">UISP</button>
-                                                <button class="nav-link" id="v-pills-mps-tab" data-bs-toggle="pill" data-bs-target="#v-pills-mps" type="button" role="tab" aria-controls="v-pills-mps" aria-selected="false" >MPS</button>
-                                                <button class="nav-link" id="v-pills-csi-tab" data-bs-toggle="pill" data-bs-target="#v-pills-csi" type="button" role="tab" aria-controls="v-pills-csi" aria-selected="false">CSI</button>
-                                                <button class="nav-link" id="v-pills-altro-tab" data-bs-toggle="pill" data-bs-target="#v-pills-altro" type="button" role="tab" aria-controls="v-pills-altro" aria-selected="false">Altro</button>
-                                            </div>
-                                            <div class="tab-content" id="v-pills-tabContent">
-                                                <div class="tab-pane fade show active" id="v-pills-fit" role="tabpanel" aria-labelledby="v-pills-fit-tab" tabindex="0">
-
-
-                                                <form class="form--tessere">
-                                                            <div class="mb-3">
-                                                                <label for="inputTessera" class="form-label">Numero Tessera</label>
-                                                                <input type="text" class="form-control" id="inputTessera">
-                                                            </div>
-                                                            <div class="mb-3">
-                                                                <label for="inputDate" class="form-label">Data di nascita</label>
-                                                                <div class="input-group mb-3">
-                                                                    <input id="inputDate" type="text" class="form-control" aria-label="Recipient's username" aria-describedby="button-addon2">
-                                                                    <button class="btn btn-outline-secondary" type="button" id="button-addon2">Date</button>
-                                                                </div>
-                                                            </div>
-                                                            <span class="scadenza-tessera">Scadenza: <strong>16 aprile 2024</strong></span>
-                                                            <button class="btn--ui_outline small mt-2"><i class="ico--ui tessera"></i>aggiungi tessera</button>
-                                                </form>
-
-                                            </div>
-                                                <div class="tab-pane fade" id="v-pills-uisp" role="tabpanel" aria-labelledby="v-pills-uisp-tab" tabindex="0">...</div>
-                                                <div class="tab-pane fade" id="v-pills-mps" role="tabpanel" aria-labelledby="v-pills-mps-tab" tabindex="0">...</div>
-                                                <div class="tab-pane fade" id="v-pills-csi" role="tabpanel" aria-labelledby="v-pills-csi-tab" tabindex="0">...</div>
-                                                <div class="tab-pane fade" id="v-pills-altro" role="tabpanel" aria-labelledby="v-pills-altro-tab" tabindex="0">...</div>
-                                            </div>
-                                            </div>
-                                    </div>-->
                                     @endif
 
                                 @endif
@@ -1697,19 +1656,6 @@
                                                 </div>
                                             @endif
                                         @endif
-                                        <!--
-                                        <div class="resume--wrapper d-flex align-items-start justify-content-between mb-2">
-                                            <div class="resume--info d-flex align-items-start">
-                                                <i class="ico--ui tessera me-2"></i>
-                                                <div class="title--tessera_added">
-                                                    <h4>Tennis/Corso Tennis/Adulti/Bisettimanale</h4>
-                                                    <span class="title-detail">Iscrizione: <span class="title-detail_date">12 marzo 2022</span></span></small>
-                                                </div>
-                                            </div>
-
-                                            <span class="badge tessera-badge active">attiva</span>
-                                        </div>-->
-
                                     </div>
                                     <div class="resume--tab_info gruppi">
                                         <h2 class="mb-3">Gruppi di appartenenza</h2>
@@ -1871,145 +1817,24 @@
             transition: all 0.3s ease-in-out;
             border: 2px solid #d3dce1;
         }
-        /* a.grey
-        {
-            display: flex;
-            margin-right:10px;
-            float:left;
-            height: 2.5rem !important;
-            width:50px;
-            align-items: center;
-            justify-content: center;
-            color: #006099;
-            background-color: #d3dce1 !important;
-            padding: 0 1.25rem;
-            font-size: 0.875rem;
-            font-family: greycliff-cf, sans-serif;
-            border-radius: 1.875rem !important;
-            -webkit-border-radius: 1.875rem !important;
-            -moz-border-radius: 1.875rem !important;
-            -webkit-transition: all 0.3s ease-in-out;
-            -moz-transition: all 0.3s ease-in-out;
-            -o-transition: all 0.3s ease-in-out;
-            transition: all 0.3s ease-in-out;
-            border: none;
-        }
-        a.blue
-        {
-            display: flex;
-            margin-right:10px;
-            float:left;
-            height: 2.5rem !important;
-            width:50px;
-            align-items: center;
-            justify-content: center;
-            color: #fff;
-            background-color: #006099 !important;
-            padding: 0 1.25rem;
-            font-size: 0.875rem;
-            font-family: greycliff-cf, sans-serif;
-            border-radius: 1.875rem !important;
-            -webkit-border-radius: 1.875rem !important;
-            -moz-border-radius: 1.875rem !important;
-            -webkit-transition: all 0.3s ease-in-out;
-            -moz-transition: all 0.3s ease-in-out;
-            -o-transition: all 0.3s ease-in-out;
-            transition: all 0.3s ease-in-out;
-            border: none;
-        }
-        a.yellow
-        {
-            display: flex;
-            margin-right:10px;
-            float:left;
-            height: 2.5rem !important;
-            width:50px;
-            align-items: center;
-            justify-content: center;
-            color: #fff;
-            background-color: #ffe238;
-            padding: 0 1.25rem;
-            font-size: 0.875rem;
-            font-family: greycliff-cf, sans-serif;
-            border-radius: 1.875rem !important;
-            -webkit-border-radius: 1.875rem !important;
-            -moz-border-radius: 1.875rem !important;
-            -webkit-transition: all 0.3s ease-in-out;
-            -moz-transition: all 0.3s ease-in-out;
-            -o-transition: all 0.3s ease-in-out;
-            transition: all 0.3s ease-in-out;
-            border: none;
-        }
-        a.orange
+        .btn--ui.lightGrey, .btn--ui.extraLightGrey
         {
-            display: flex;
-            margin-right:10px;
-            float:left;
-            height: 2.5rem !important;
-            width:50px;
-            align-items: center;
-            justify-content: center;
-            color: #fff;
-            background-color: #FF7E38;
-            padding: 0 1.25rem;
-            font-size: 0.875rem;
-            font-family: greycliff-cf, sans-serif;
-            border-radius: 1.875rem !important;
-            -webkit-border-radius: 1.875rem !important;
-            -moz-border-radius: 1.875rem !important;
-            -webkit-transition: all 0.3s ease-in-out;
-            -moz-transition: all 0.3s ease-in-out;
-            -o-transition: all 0.3s ease-in-out;
-            transition: all 0.3s ease-in-out;
-            border: none;
+            -webkit-border-radius: 0.5rem !important;
+            background-color:#ffffff !important;
+            border: 1px solid grey;
+            color: black;
+            font-weight:normal;
         }
-        a.green
+
+        .persistent-invalid
         {
-            display: flex;
-            margin-right:10px;
-            float:left;
-            height: 2.5rem !important;
-            width:50px;
-            align-items: center;
-            justify-content: center;
-            color: #fff;
-            background-color: green;
-            padding: 0 1.25rem;
-            font-size: 0.875rem;
-            font-family: greycliff-cf, sans-serif;
-            border-radius: 1.875rem !important;
-            -webkit-border-radius: 1.875rem !important;
-            -moz-border-radius: 1.875rem !important;
-            -webkit-transition: all 0.3s ease-in-out;
-            -moz-transition: all 0.3s ease-in-out;
-            -o-transition: all 0.3s ease-in-out;
-            transition: all 0.3s ease-in-out;
-            border: none;
+            border-color: #dc3545 !important;
+            padding-right: calc(1.5em + 0.75rem) !important;
+            background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' width='12' height='12' fill='none' stroke='%23dc3545'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath stroke-linejoin='round' d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='%23dc3545' stroke='none'/%3e%3c/svg%3e") !important;
+            background-repeat: no-repeat !important;
+            background-position: right calc(0.375em + 0.1875rem) center !important;
+            background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem) !important;
         }
- .btn--ui
-    {
-        -webkit-border-radius: 0.5rem !important;
-        background-color:#0C6197 !important;
-        font-weight:normal;
-    } */
-    .btn--ui.lightGrey, .btn--ui.extraLightGrey
-    {
-        -webkit-border-radius: 0.5rem !important;
-        background-color:#ffffff !important;
-        border: 1px solid grey;
-        color: black;
-        font-weight:normal;
-    }
-
-    .persistent-invalid
-    {
-        border-color: #dc3545 !important;
-        padding-right: calc(1.5em + 0.75rem) !important;
-        background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' width='12' height='12' fill='none' stroke='%23dc3545'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath stroke-linejoin='round' d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='%23dc3545' stroke='none'/%3e%3c/svg%3e") !important;
-        background-repeat: no-repeat !important;
-        background-position: right calc(0.375em + 0.1875rem) center !important;
-        background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem) !important;
-    }
     </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>
@@ -2026,55 +1851,9 @@
         }
         var nation_id = {{$nation_id > 0 ? $nation_id : 0}};
         var province_id = 0;
-
-        /*
-        $('.nationClass').select2({
-            // theme: 'bootstrap4',
-            ajax: {
-                url: '/nations',
-                dataType: 'json'
-            }
-        });
-
-        $('.nationClass').on('change', function (e) {
-            nation_id = $('.nationClass').select2("val");
-            @this.set('nation_id', nation_id);
-            @this.set('province_id', 0);
-            @this.set('city_id', 0);
-            @this.checkIsItaly();
-        });
-
-        $('.provinceClass').select2({
-            ajax: {
-                url: '/provinces/' + nation_id,
-                dataType: 'json'
-            }
-        });
-        $('.cityClass').select2({"language": {"noResults": function(){return "Nessun risultato";}}});*/
-
         var nation_birth_id = 0;
         var province_birth_id = 0;
 
-    /*
-        $('.nationBirthClass').select2({
-            // theme: 'bootstrap4',
-            ajax: {
-                url: '/nations',
-                dataType: 'json'
-            }
-        });
-
-        $('.nationBirthClass').on('change', function (e) {
-            nation_birth_id = $('.nationBirthClass').select2("val");
-            @this.set('birth_nation_id', nation_birth_id);
-            @this.set('birth_province_id', 0);
-            @this.set('birth_city_id', 0);
-            @this.checkIsBirthItaly();
-        });
-
-        $('.provinceBirthClass').select2({"language": {"noResults": function(){return "Nessun risultato";}}});
-        $('.cityBirthClass').select2({"language": {"noResults": function(){return "Nessun risultato";}}});*/
-
         Livewire.on('load-select', () => {
 
             loadCombo();
@@ -2299,6 +2078,11 @@
                 @this.delete(id);
         }
 
+        function archiveData(id)
+        {
+            if (confirm('Sei sicuro? Tutti i dati relativi a questo utente verranno archiviati e non saranno più visibili.'))
+                @this.archive(id);
+        }
 
         var isFilter = false;
         $(document).ready(function() {
@@ -2420,12 +2204,6 @@
             $('.filterCertificateType').val('-1').trigger('change');
             $('.filterCategories').val('-1').trigger('change');
 
-            /*
-            $(".chkCertificateNormal").prop( "checked", false );
-            $(".chkCertificateAgonistico").prop( "checked", false );
-            $(".chkCertificateScadenza").prop( "checked", false );
-            $(".chkCertificateScaduti").prop( "checked", false );
-            */
 
             $('input[name="txtFromYear"]').val('');
             $('input[name="txtToYear"]').val('');
@@ -2542,7 +2320,7 @@
                         data: "action",
                         render: function (data){
                             var ret = '<button type="button" class="btn" onclick="editData(' + data + ')" data-bs-toggle="popover"  data-bs-trigger="hover focus" data-bs-placement="bottom" data-bs-content="Modifica"><i class="fa-regular fa-pen-to-square"></i></button>&nbsp;';
-                            ret += '<button type="button" class="btn" onclick="deleteData(' + data + ')" data-bs-toggle="popover" data-bs-trigger="hover focus" data-bs-placement="bottom" data-bs-content="Elimina"><i class="fa-regular fa-trash-can"></i></button>';
+                            ret += '<button type="button" class="btn" onclick="archiveData(' + data + ')" data-bs-toggle="popover" data-bs-trigger="hover focus" data-bs-placement="bottom" data-bs-content="Archivia"><i class="fa-regular fa-folder-closed"></i></button>';
                             return ret;
                         }
                     },
@@ -2649,8 +2427,6 @@
             }
             console.log(errors);
 
-            //window.location.href = "#top";
-            //$("span").find(`[aria-controls='select2-birth_nation_id-container']`).css('border', 'solid 3px red');
         });
 
         Livewire.on('reload', (x) =>
@@ -2674,7 +2450,6 @@
             else
             {
                 document.body.scrollTop = document.documentElement.scrollTop = 0;
-                //window.location.href = "#top";
             }
         }
 
@@ -2727,15 +2502,11 @@
             window.location.href = "#top";
         });
 
-        /*$(window).on('popstate', function(event) {
-            document.location.href = '/members';
-        });*/
         $(function() {
             if (window.history && window.history.pushState) {
                 window.history.pushState('', null, './');
                 $(window).on('popstate', function() {
-                    // alert('Back button was pressed.');
-                    //document.location.href = '#';
+
                     document.location.href = '/members';
                 });
             }
@@ -2763,7 +2534,7 @@
         } else if (Array.isArray(fieldId) && fieldId.length > 0) {
             const firstFieldId = fieldId[0];
             element = document.getElementById(firstFieldId);
-            fieldId = firstFieldId; // Use the first fieldId for highlighting
+            fieldId = firstFieldId;
         }
 
         if (element) {
@@ -2795,9 +2566,6 @@
             // Stop preserving after user interaction
             element.addEventListener('input', () => {
                 clearInterval(intervalId);
-                // Optional: Remove the highlighting when user edits the field
-                // element.classList.remove('is-invalid');
-                // if (label) label.classList.remove('text-danger');
             });
 
         } else {

+ 44 - 58
routes/web.php

@@ -209,27 +209,31 @@ 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', 'birth_date', 'to_complete', 'current_status', 'certificate', 'certificate_date')->where('id', '>', 0);
+    // ALWAYS exclude archived members - this is the key change
+    $x = \App\Models\Member::select('id', 'first_name', 'last_name', 'phone', 'birth_date', 'to_complete', 'current_status', 'certificate', 'certificate_date')
+        ->where(function($query) {
+            $query->where('is_archived', false)
+                  ->orWhereNull('is_archived');
+        });
 
+    // All your existing filtering logic remains exactly the same
     if (isset($_GET["search"]["value"])) {
         $v = str_replace("'", "\'", stripcslashes($_GET["search"]["value"]));
         $x = $x->where(function ($query) use ($v) {
             $query->whereRaw("CONCAT(first_name, ' ', last_name) like '%" . $v . "%'")
                 ->orWhereRaw("CONCAT(last_name, ' ', first_name) like '%" . $v . "%'");
         });
-        //where('first_name', 'like', '%' . $_GET["search"]["value"] . '%');
     }
+
     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["filterCategories"] != "null") {
 
+    if ($_GET["filterCategories"] != "null") {
         $categories = [];
         $cats = explode(",", $_GET["filterCategories"]);
 
-        // Per ogni causale, se ha dei figli allora aggiungo le causali figlio
         foreach ($cats as $c) {
             $categories[] = $c;
             $childs = \App\Models\Category::where('parent_id', $c)->get();
@@ -245,18 +249,12 @@ Route::get('/get_members', function () {
         $cc = array();
         foreach ($categories as $c) {
             $m_ids = \App\Models\MemberCategory::where('category_id', $c)->pluck('member_id')->toArray();
-            /*if (sizeof($cc) > 0)
-                    $cc = array_intersect($cc, $m_ids);
-                else
-                    $cc = $m_ids;
-                */
             $cc = array_merge($cc, $m_ids);
         }
 
         $x = $x->whereIn('id', $cc);
-        //$cats_ids = \App\Models\MemberCategory::whereIn('category_id', explode(",", $_GET["filterCategories"]))->pluck('member_id');
-        //$x = $x->whereIn('id', $cats_ids);
     }
+
     if ($_GET["fromYear"] != "") {
         $x = $x->where('birth_date', '<', date("Y-m-d", strtotime("-" . $_GET["fromYear"] . " year", time())));
     }
@@ -273,9 +271,10 @@ Route::get('/get_members', function () {
     $ids = [];
 
     if ($_GET["filterCertificateType"] != "null") {
-        $types = \App\Models\MemberCertificate::where('type', $_GET["filterCertificateType"])->where('expire_date', '>', date("Y-m-d"))->pluck('member_id');
+        $types = \App\Models\MemberCertificate::where('type', $_GET["filterCertificateType"])
+            ->where('expire_date', '>', date("Y-m-d"))
+            ->pluck('member_id');
         $x = $x->whereIn('id', $types->toArray());
-        //$ids = array_merge($ids, $types->toArray());
     }
 
     if ($_GET["filterScadenza"] != "null") {
@@ -296,9 +295,6 @@ Route::get('/get_members', function () {
                     }
                 }
                 $scadIds = $expiredMemberIds;
-
-                Log::info("Expired certificates filter - member count: " . count($scadIds));
-                Log::info("Expired certificates member IDs: " . implode(", ", $scadIds));
             } else if ($filterValue == "2") {
                 $memberLatestCerts = DB::table('member_certificates')
                     ->select('member_id', DB::raw('MAX(expire_date) as latest_expire_date'))
@@ -317,7 +313,13 @@ Route::get('/get_members', function () {
                 }
                 $scadIds = $expiringMemberIds;
             } else if ($filterValue == "3") {
-                $scadIds = \App\Models\Member::whereNotIn('id', \App\Models\MemberCertificate::pluck('member_id'))->pluck('id')->toArray();
+                // Only non-archived members without certificates
+                $scadIds = \App\Models\Member::whereNotIn('id', \App\Models\MemberCertificate::pluck('member_id'))
+                    ->where(function($query) {
+                        $query->where('is_archived', false)
+                              ->orWhereNull('is_archived');
+                    })
+                    ->pluck('id')->toArray();
             } else if ($filterValue == "4") {
                 $memberLatestCerts = DB::table('member_certificates')
                     ->select('member_id', DB::raw('MAX(expire_date) as latest_expire_date'))
@@ -340,13 +342,17 @@ Route::get('/get_members', function () {
         }
 
         $allScadIds = array_unique($allScadIds);
-        Log::info("Total members after filterScadenza: " . count($allScadIds));
         $x = $x->whereIn('id', $allScadIds);
     }
 
     if ($_GET["filterStatus"] != "null") {
         $status = explode(",", $_GET["filterStatus"]);
-        $members = \App\Models\Member::all();
+        // Only get non-archived members for status filtering
+        $members = \App\Models\Member::where(function($query) {
+            $query->where('is_archived', false)
+                  ->orWhereNull('is_archived');
+        })->get();
+
         foreach ($status as $s) {
             foreach ($members as $m) {
                 $state = $m->getStatus();
@@ -367,6 +373,7 @@ Route::get('/get_members', function () {
 
     $x = $x->orderBy('to_complete', 'DESC');
 
+    // Rest of the ordering logic remains the same
     if (isset($_GET["order"])) {
         $column = '';
         if ($_GET["order"][0]["column"] == 0)
@@ -383,20 +390,24 @@ Route::get('/get_members', function () {
             $column = 'current_status';
         if ($_GET["order"][0]["column"] == 6)
             $column = 'certificate';
+
         if ($column != '') {
             $x = $x->orderBy($column, $_GET["order"][0]["dir"]);
             if ($column == 'certificate')
                 $x = $x->orderBy('certificate_date', $_GET["order"][0]["dir"]);
-        } else
+        } else {
             $x = $x->orderBy('last_name', 'ASC')->orderBy('first_name', 'ASC');
-    } else
+        }
+    } else {
         $x = $x->orderBy('last_name', 'ASC')->orderBy('first_name', 'ASC');
+    }
 
     if (isset($_GET["start"]))
         $x = $x->offset($_GET["start"])->limit($_GET["length"])->get();
     else
         $x = $x->get();
 
+    // Process results exactly as before
     $latestCertificates = [];
     foreach ($x as $member) {
         $latestCert = \App\Models\MemberCertificate::where('member_id', $member->id)
@@ -407,14 +418,9 @@ Route::get('/get_members', function () {
             $latestCertificates[$member->id] = $latestCert->expire_date;
         }
     }
-    Log::info($latestCertificates);
 
     foreach ($x as $idx => $r) {
-        // $status = $r->getStatus();
-        // $status = $status["status"];
-
         $status = $r->current_status;
-
         $class = $status > 0 ? ($status == 2 ? 'active' : 'due') : 'suspended';
         $text = $status > 0 ? ($status == 2 ? 'Tesserato' : 'Sospeso') : 'Non tesserato';
 
@@ -426,59 +432,39 @@ Route::get('/get_members', function () {
         $y = '';
 
         if (isset($latestCertificates[$r->id])) {
-            Log::info("Using latest certificate for member " . $r->id);
             $latest_date = $latestCertificates[$r->id];
-            $status = '';
+            $certStatus = '';
 
             if ($latest_date < date("Y-m-d")) {
-                $status = "0"; // Expired
+                $certStatus = "0";
             } else if ($latest_date <= date("Y-m-d", strtotime("+1 month"))) {
-                $status = "1"; // Expiring soon
+                $certStatus = "1";
             } else {
-                $status = "2"; // Valid
+                $certStatus = "2";
             }
 
-            $y = $status . "|" . date("d/m/Y", strtotime($latest_date));
+            $y = $certStatus . "|" . date("d/m/Y", strtotime($latest_date));
         } else if ($r->certificate_date != '') {
-            Log::info("Member " . $r->id . " not found in latest certificates array");
-
-            $status = '';
+            $certStatus = '';
 
             if ($r->certificate_date < date("Y-m-d")) {
-                $status = "0";
+                $certStatus = "0";
             } else if ($r->certificate_date >= date("Y-m-d") && $r->certificate_date <= date("Y-m-d", strtotime("+1 month"))) {
-                $status = "1";
+                $certStatus = "1";
             } else if ($r->certificate_date > date("Y-m-d", strtotime("+1 month"))) {
-                $status = "2";
+                $certStatus = "2";
             }
 
-            $y = $status . "|" . date("d/m/Y", strtotime($r->certificate_date));
+            $y = $certStatus . "|" . date("d/m/Y", strtotime($r->certificate_date));
         }
-        /*
-            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(
-            //'c' => $idx + 1,
-            //'id' => "ID" . str_pad($r->id, 5, "0", STR_PAD_LEFT),
             'last_name' => $r->last_name . "|" . $r->id,
             'first_name' => $r->first_name . "|" . $r->id,
             'phone' => $r->phone,
             'age' => $r->getAge(),
-            'year' => date("Y", strtotime($r->birth_date)),
+            'year' => $r->birth_date ? date("Y", strtotime($r->birth_date)) : 'N/A',
             'status' => $class . "|" . $text,
-            // 'state' => $x,
             'certificate' => $y,
             'action' => $r->id
         );