ソースを参照

Merge branch 'iao_team' of http://host.webmagistri.biz:3000/parisio/iao_team into iao_team_ferrari

ferrari 4 ヶ月 前
コミット
0f3788a284

+ 39 - 83
app/Http/Livewire/Member.php

@@ -298,6 +298,16 @@ class Member extends Component
         $this->image_old = '';
     }
 
+    public function updatedPresenceYearFilter()
+    {
+        $this->loadMemberPresences();   
+    }
+
+    public function updatedPresenceTitleFilter()
+    {
+        $this->loadMemberPresences();   
+    }
+
     public function updatedCourseName()
     {
         $this->course_course_id = null;
@@ -517,6 +527,7 @@ class Member extends Component
             $this->festivita[] = $pasquetta;  // Lunedì dell'Angelo
         }
 
+
     }
 
     public function updated()
@@ -632,87 +643,10 @@ class Member extends Component
 
 
         $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();
-            }
-
-            foreach ($this->records as $r) {
-                $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"];
-            }
-            /*
-            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');
-        }
-
+        
         $this->loadMemberCards();
         $this->loadMemberCourses();
-        $this->loadMemberPresences();
+        
         $this->loadMemberCategories();
         $this->loadMemberCertificates();
 
@@ -957,10 +891,12 @@ class Member extends Component
     {
         $course_ids = array();
         
-        $calendars = \App\Models\Calendar::whereNull('manual')->orderBy('from')->get();
+        //$calendars = \App\Models\Calendar::whereNull('manual')->orderBy('from')->get();
 
+        /*
         foreach($calendars as $calendar)
         {
+  
             $days = ['dom', 'lun', 'mar', 'mer', 'gio', 'ven', 'sab'];
             $dow = date('w', strtotime($calendar->from));
             $d = $days[$dow];
@@ -977,7 +913,9 @@ class Member extends Component
             //$course_ids = array_push($course_ids, $courses);
 
         }
-
+        */
+        $course_ids = \App\Models\MemberCourse::where('member_id', $this->dataId)->pluck('course_id')->toArray();
+        
         // Manuali (recuperi)
         $calendar_recuperi = \App\Models\Calendar::where('manual', 1)->pluck('name')->toArray();
         
@@ -1189,6 +1127,10 @@ class Member extends Component
                 $this->edit($member->id);
                 $this->emit('saved-and-continue', $this->type);
                 $this->dispatchBrowserEvent('scroll-to-top');
+                if ($this->birth_nation_id != null)
+                    $this->isBirthItaly = \App\Models\Nation::findOrFail($this->birth_nation_id)->first()->is_italy;// $this->nation_id;//$this->checkIsItaly();
+                if ($this->nation_id != null)
+                    $this->isItaly = \App\Models\Nation::findOrFail($this->nation_id)->first()->is_italy;// $this->nation_id;//$this->checkIsItaly();
             }
             $this->emit('setEdit', false);
         } catch (\Exception $ex) {
@@ -1281,6 +1223,14 @@ class Member extends Component
                 $this->update = true;
                 $this->add = false;
 
+                //$this->loadMemberCards();
+                //$this->loadMemberCourses();
+                //$this->loadMemberPresences();
+                //$this->loadMemberCategories();
+                //$this->loadMemberCertificates();
+
+                $this->loadMemberPresences();
+
                 $this->emit('setIds', $this->nation_id, $this->birth_nation_id);
 
                 $this->emit('load-select');
@@ -1445,11 +1395,17 @@ class Member extends Component
             updateMemberData($this->dataId);
             session()->flash('success', 'Tesserato aggiornato');
             if ($close) {
-                $this->resetFields();
-                $this->update = false;
+                $this->emit('saved-and-close');
+                //$this->resetFields();
+                //$this->update = false;
             } else {
+                
                 $this->emit('saved-and-continue', $this->type);
                 $this->dispatchBrowserEvent('scroll-to-top');
+                if ($this->birth_nation_id != null)
+                    $this->isBirthItaly = \App\Models\Nation::findOrFail($this->birth_nation_id)->first()->is_italy;// $this->nation_id;//$this->checkIsItaly();
+                if ($this->nation_id != null)
+                    $this->isItaly = \App\Models\Nation::findOrFail($this->nation_id)->first()->is_italy;// $this->nation_id;//$this->checkIsItaly();
             }
             $this->emit('setEdit', false);
         } catch (\Exception $ex) {

+ 20 - 11
app/Http/Livewire/Reports.php

@@ -518,11 +518,13 @@ class Reports extends Component
             ];
         }
 
-        $rates = \App\Models\Rate::whereHas('member_course', function ($query) use ($courseId) {
+        $member_courses = \App\Models\MemberCourse::where('course_id', $courseId)->get();
+
+        /*$rates = \App\Models\Rate::whereHas('member_course', function ($query) use ($courseId) {
             $query->where('course_id', $courseId);
-        })->with('member_course')->get();
+        })->with('member_course')->get();*/
 
-        if ($rates->isEmpty()) {
+        if ($member_courses->isEmpty()) {
             return [
                 'labels' => [],
                 'datasets' => [],
@@ -534,24 +536,31 @@ class Reports extends Component
 
         $hasData = false;
 
-        foreach ($rates as $rate) {
-            $totalPrice = (float)($rate->price ?? 0);
+        foreach ($member_courses as $member_course) {
+
+            $totalPrice = (float)($member_course->price ?? 0);
+            //$totalPrice = (float)($rate->price ?? 0);
+
+            if ($member_course->months) {
+                $monthsData = json_decode($member_course->months, true);
+
+                if (is_array($monthsData) && count($monthsData) > 0) 
+                {
+
 
-            if ($rate->months) {
-                $monthsData = json_decode($rate->months, true);
 
-                if (is_array($monthsData) && count($monthsData) > 0) {
-                    $pricePerMonth = $totalPrice / count($monthsData);
+                    $pricePerMonth = $totalPrice; //  / count($monthsData);
 
                     foreach ($monthsData as $month) {
-                        $monthNumber = (int)$month;
+                        $monthNumber = (int)$month["m"];
 
                         if (isset($monthlyData[$monthNumber])) {
                             $monthlyData[$monthNumber]['total'] += $pricePerMonth;
                             $monthlyData[$monthNumber]['participants']++;
                             $hasData = true;
 
-                            if (!is_null($rate->record_id) && $rate->record_id !== '') {
+                            //if (!is_null($rate->record_id) && $rate->record_id !== '') {
+                            if ($month["status"] == 1) {
                                 $monthlyData[$monthNumber]['earned'] += $pricePerMonth;
                             }
                         }

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

@@ -1214,7 +1214,7 @@
                                     @if($dataId > 0)
 
                                         @if(!$addCourse && !$updateCourse)
-                                            @if($active["status"] != 2 && $active["status"] != 1 )
+                                            @if(false && $active["status"] != 2 && $active["status"] != 1 )
                                                 <div class="alert alert-warning" role="alert">
                                                     <strong>Attenzione:</strong> Per aggiungere corsi è necessario avere un tesseramento.
                                                 </div>
@@ -1313,11 +1313,14 @@
                                                 </tbody>
                                             </table>
                                             @if($dataId > 0)
-                                                @if ($active["status"] == 2 || $active["status"] == 1)
-                                                    <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>
+                                                <button class="btn--ui primary" wire:click.prevent="addCourse()" style="max-width:200px">Aggiungi</button>
+                                                @if(false)
+                                                    @if ($active["status"] == 2 || $active["status"] == 1)
+                                                        <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
                                             @endif
                                         @else
@@ -2807,6 +2810,10 @@
             return false;
         }
 
+        Livewire.on('saved-and-close', (currentTab) => {
+            document.location.href = '/members';
+        });
+
         Livewire.on('saved-and-continue', (currentTab) => {
             const nextTab = getNextTab(currentTab);
             if (nextTab !== currentTab) {

+ 2 - 2
resources/views/livewire/reports.blade.php

@@ -105,7 +105,7 @@
             </div>
         </div>
 
-        {{-- @if(false) --}}
+        
         <div class="chart-row">
             <div class="chart-card modern-course-card">
                 <div class="chart-header">
@@ -149,7 +149,7 @@
                 </div>
             </div>
         </div>
-        {{-- @endif --}}
+        
     </div>
 
     <script>