Browse Source

check aggiunta corsi

FabioFratini 7 months ago
parent
commit
fdc5c6fc41
2 changed files with 46 additions and 25 deletions
  1. 33 9
      app/Http/Livewire/Member.php
  2. 13 16
      resources/views/livewire/member.blade.php

+ 33 - 9
app/Http/Livewire/Member.php

@@ -40,12 +40,16 @@ class Member extends Component
         'city_id.required' => 'city_id',
         'city_id.required' => 'city_id',
         'gender' => 'gender'
         'gender' => 'gender'
     ];
     ];
-
     public function change($type)
     public function change($type)
     {
     {
         $this->type = $type;
         $this->type = $type;
-    }
 
 
+        if ($type === 'corsi' && $this->dataId > 0) {
+            $this->loadMemberCards();
+            $this->checkCourseAvailability();
+        }
+        $this->dispatchBrowserEvent('scroll-to-top');
+    }
     public function sortBy($field)
     public function sortBy($field)
     {
     {
         if ($this->sortField === $field) {
         if ($this->sortField === $field) {
@@ -1203,7 +1207,23 @@ class Member extends Component
         $this->addCard = true;
         $this->addCard = true;
         $this->updateCard = false;
         $this->updateCard = false;
     }
     }
+    private function checkCourseAvailability()
+    {
+        $this->active = $this->getActiveStatus();
 
 
+        $this->emit('course-availability-updated');
+    }
+
+    private function getActiveStatus()
+    {
+        if ($this->dataId > 0) {
+            $member = \App\Models\Member::find($this->dataId);
+            if ($member) {
+                return $member->getStatus();
+            }
+        }
+        return ["status" => 0, "date" => null];
+    }
     public function storeCard()
     public function storeCard()
     {
     {
 
 
@@ -1249,6 +1269,8 @@ class Member extends Component
             session()->flash('success, Tesserato creato');
             session()->flash('success, Tesserato creato');
             $this->resetCardFields();
             $this->resetCardFields();
             $this->addCard = false;
             $this->addCard = false;
+            $this->loadMemberCards();
+            $this->checkCourseAvailability();
         } catch (\Exception $ex) {
         } catch (\Exception $ex) {
             session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
             session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
         }
         }
@@ -1283,7 +1305,7 @@ class Member extends Component
         $this->validate(['card_card_id' => 'required']);
         $this->validate(['card_card_id' => 'required']);
 
 
         try {
         try {
-            \Illuminate\Support\Facades\Log::info('Starting card update', [
+            Log::info('Starting card update', [
                 'member_id' => $this->dataId,
                 'member_id' => $this->dataId,
                 'card_id' => $this->card_card_id,
                 'card_id' => $this->card_card_id,
                 'card_number' => $this->card_number
                 'card_number' => $this->card_number
@@ -1293,7 +1315,7 @@ class Member extends Component
             if ($this->card_date != '') {
             if ($this->card_date != '') {
                 $card = \App\Models\Card::findOrFail($this->card_card_id);
                 $card = \App\Models\Card::findOrFail($this->card_card_id);
 
 
-                \Illuminate\Support\Facades\Log::info('Card details', [
+                Log::info('Card details', [
                     'card_id' => $card->id,
                     'card_id' => $card->id,
                     'next_day_expire' => $card->next_day_expire,
                     'next_day_expire' => $card->next_day_expire,
                     'next_month_expire' => $card->next_month_expire,
                     'next_month_expire' => $card->next_month_expire,
@@ -1318,7 +1340,7 @@ class Member extends Component
                         $expire_date = $next_exp_obj->format('Y-m-d');
                         $expire_date = $next_exp_obj->format('Y-m-d');
                     }
                     }
 
 
-                    \Illuminate\Support\Facades\Log::info('Calculated expiration date (next_day_expire/next_month_expire rule)', [
+                    Log::info('Calculated expiration date (next_day_expire/next_month_expire rule)', [
                         'input_date' => $this->card_date,
                         'input_date' => $this->card_date,
                         'next_exp' => $next_exp,
                         'next_exp' => $next_exp,
                         'expire_date' => $expire_date,
                         'expire_date' => $expire_date,
@@ -1328,7 +1350,7 @@ class Member extends Component
                     if ($card->one_year_expire) {
                     if ($card->one_year_expire) {
                         $expire_date = date("Y-m-d", strtotime($this->card_date . ' + 1 years'));
                         $expire_date = date("Y-m-d", strtotime($this->card_date . ' + 1 years'));
 
 
-                        \Illuminate\Support\Facades\Log::info('Calculated expiration date (one_year_expire rule)', [
+                        Log::info('Calculated expiration date (one_year_expire rule)', [
                             'input_date' => $this->card_date,
                             'input_date' => $this->card_date,
                             'expire_date' => $expire_date
                             'expire_date' => $expire_date
                         ]);
                         ]);
@@ -1336,7 +1358,7 @@ class Member extends Component
                 }
                 }
             }
             }
 
 
-            \Illuminate\Support\Facades\Log::info('Updating member card', [
+            Log::info('Updating member card', [
                 'card_id' => $this->cardDataId,
                 'card_id' => $this->cardDataId,
                 'member_id' => $this->dataId,
                 'member_id' => $this->dataId,
                 'card_number' => $this->card_number,
                 'card_number' => $this->card_number,
@@ -1360,7 +1382,7 @@ class Member extends Component
 
 
             updateMemberData($this->dataId);
             updateMemberData($this->dataId);
 
 
-            \Illuminate\Support\Facades\Log::info('Card updated successfully', [
+            Log::info('Card updated successfully', [
                 'card_id' => $this->cardDataId,
                 'card_id' => $this->cardDataId,
                 'member_id' => $this->dataId
                 'member_id' => $this->dataId
             ]);
             ]);
@@ -1368,8 +1390,10 @@ class Member extends Component
             session()->flash('success', 'Tesserato aggiornato');
             session()->flash('success', 'Tesserato aggiornato');
             $this->resetCardFields();
             $this->resetCardFields();
             $this->updateCard = false;
             $this->updateCard = false;
+            $this->loadMemberCards();
+            $this->checkCourseAvailability();
         } catch (\Exception $ex) {
         } catch (\Exception $ex) {
-            \Illuminate\Support\Facades\Log::error('Error updating card', [
+            Log::error('Error updating card', [
                 'card_id' => $this->cardDataId,
                 'card_id' => $this->cardDataId,
                 'member_id' => $this->dataId,
                 'member_id' => $this->dataId,
                 'error_message' => $ex->getMessage(),
                 'error_message' => $ex->getMessage(),

+ 13 - 16
resources/views/livewire/member.blade.php

@@ -1130,10 +1130,14 @@
                                 @endif
                                 @endif
 
 
                                 @if($type == 'corsi')
                                 @if($type == 'corsi')
-
                                     @if($dataId > 0)
                                     @if($dataId > 0)
 
 
                                         @if(!$addCourse && !$updateCourse)
                                         @if(!$addCourse && !$updateCourse)
+                                            @if($active["status"] != 2)
+                                                <div class="alert alert-warning" role="alert">
+                                                    <strong>Attenzione:</strong> Per aggiungere corsi è necessario avere un tesseramento attivo.
+                                                </div>
+                                            @endif
                                             <table class="table tablesaw tableHead tablesaw-stack tabella--corsi" id="tablesaw-350-2" style="min-width:800px">
                                             <table class="table tablesaw tableHead tablesaw-stack tabella--corsi" id="tablesaw-350-2" style="min-width:800px">
                                                 <tbody id="checkall-target">
                                                 <tbody id="checkall-target">
                                                     @foreach($member_courses as $member_course)
                                                     @foreach($member_courses as $member_course)
@@ -1224,9 +1228,15 @@
 
 
                                                 </tbody>
                                                 </tbody>
                                             </table>
                                             </table>
-                                            <button class="btn--ui primary"wire:click.prevent="addCourse()" style="max-width:200px">Aggiungi</button>
+                                            @if($dataId > 0)
+                                                @if ($active["status"] == 2)
+                                                    <button class="btn--ui primary" wire:click.prevent="addCourse()" style="max-width:200px">Aggiungi</button>
+                                                @else
+                                                    <button class="btn--ui lightGrey" disabled style="max-width:200px">Aggiungi corso (non disponibile)</button>
+                                                    <small class="text-muted d-block mt-1">Completa prima il tesseramento per abilitare l'aggiunta di corsi</small>
+                                                @endif
+                                            @endif
                                         @else
                                         @else
-
                                             <div class="form--wrapper">
                                             <div class="form--wrapper">
                                                 <form class="form--utente">
                                                 <form class="form--utente">
                                                     @if(false)
                                                     @if(false)
@@ -1553,19 +1563,6 @@
                                                 </div>
                                                 </div>
                                             @endif
                                             @endif
                                         @endforeach
                                         @endforeach
-                                        <!--
-                                        <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>
                                     <div class="resume--tab_info tesseramento">
                                     <div class="resume--tab_info tesseramento">
                                         <h2 class="mb-3">Certificato</h2>
                                         <h2 class="mb-3">Certificato</h2>