Luca Parisio 5 miesięcy temu
rodzic
commit
830ab0e86f

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

@@ -44,7 +44,7 @@ class Calendar extends Component
         $this->course_frequencies = \App\Models\CourseFrequency::select('*')->where('enabled', true)->get();
         $this->courts = \App\Models\Court::select('*')->where('enabled', true)->get();
         $this->instructors = \App\Models\User::select('*')->where('level', 2)->where('enabled', true)->get();
-        $this->motivations = \App\Models\Motivation::select('*')->where('enabled', true)->get();
+        $this->motivations = \App\Models\Motivation::select('*')->where('enabled', true)->where('type', 'del')->get();
 
         if (isset($_GET["name_filter"]))
             $this->name_filter = $_GET["name_filter"];

+ 111 - 0
app/Http/Livewire/Member.php

@@ -149,6 +149,16 @@ class Member extends Component
     public $already_existing = false;
     public $tabOrder = ['dati', 'tesseramento', 'corsi', 'gruppi'];
 
+    public $presenceYears = [];
+    public $presenceTitle = [];
+    public $member_presences = [];
+
+    public $totals = 0;
+    public $presenze = 0;
+    public $assenze = 0;
+    public $annullate = 0;
+    public $recuperi = 0;
+
     protected $rules = [
         'first_name' => 'required',
         'last_name' => 'required',
@@ -694,6 +704,7 @@ class Member extends Component
 
         $this->loadMemberCards();
         $this->loadMemberCourses();
+        $this->loadMemberPresences();
         $this->loadMemberCategories();
         $this->loadMemberCertificates();
 
@@ -739,6 +750,106 @@ class Member extends Component
         // return view('livewire.member');
     }
 
+    public function loadMemberPresences()
+    {
+
+        $this->member_presences = [];
+
+        // Carico tutti i calendar_id delle presenza
+        $presences = \App\Models\Presence::where('member_id', $this->dataId)->where('status', '<>', 99)->pluck('calendar_id')->toArray();
+        $presences_annullate = \App\Models\Presence::where('member_id', $this->dataId)->where('status', 99)->pluck('calendar_id')->toArray();
+
+        $course_ids = array();
+        // Tutti i calendari
+        $calendars = \App\Models\Calendar::whereNull('manual')->orderBy('from')->get();
+
+        $this->totals = 0;
+        $this->presenze = 0;
+        $this->assenze = 0;
+        $this->annullate = 0;
+        $this->recuperi = 0;
+
+        foreach($calendars as $calendar)
+        {
+            $days = ['dom', 'lun', 'mar', 'mer', 'gio', 'ven', 'sab'];
+            $dow = date('w', strtotime($calendar->from));
+            $d = $days[$dow];
+
+            // Elenco corsi per tipologia in base al calendario
+            $courses = \App\Models\Course::where('name', $calendar->name)->where('date_from', '<=', $calendar->from)->where('date_to', '>=', $calendar->to)->pluck('id')->toArray();
+
+            // Elenco utenti iscritti al corso "padre"
+            if (\App\Models\MemberCourse::where('when', 'like', "%" . $d . "%")->whereIn('course_id', $courses)->where('member_id', $this->dataId)->first())
+            {
+                $status = '';
+                if (in_array($calendar->id, $presences))
+                {
+                    $status = "<span style=\"color:green\">Prezenza ordinaria</span>";
+                    $this->presenze += 1;
+                }
+                else
+                {
+                    if (in_array($calendar->id, $presences_annullate))
+                    {
+                        $status = "<span style=\"color:gray\">Annullata</span>";
+                        $this->annullate += 1;
+                    }
+                    else
+                    {
+                        if (date("Ymd") > date("Ymd", strtotime($calendar->from)))
+                        {
+                            $status = "<span style=\"color:red\">Assenza</span>";
+                            $this->assenze += 1;
+                        }
+                    }
+                }
+
+                if ($calendar->status == 99)
+                {
+                    $status = "<span style=\"color:gray\">Annullata</span>";
+                    $this->annullate += 1;
+                }
+                
+                $this->member_presences[] = array('calendar_id' => $calendar->id, 'from' => $calendar->from, 'to' => $calendar->to, 'status' => $status);//\App\Models\Presence::where('member_id', $this->dataId)->get();
+            }
+
+            //$courses = array(1);
+            foreach($courses as $c)
+            {
+                $course_ids[] = $c;    
+            }
+
+            //$course_ids = array_push($course_ids, $courses);
+
+        }
+
+        // Manuali (recuperi)
+        $calendar_recuperi = \App\Models\Calendar::where('manual', 1)->pluck('id')->toArray();
+        $presences_recuperi = \App\Models\Presence::whereIn('calendar_id', $calendar_recuperi)->where('member_id', $this->dataId)->get();
+        foreach($presences_recuperi as $p)
+        {
+            $this->member_presences[] = array('calendar_id' => $p->calendar->id, 'from' => $p->calendar->from, 'to' => $p->calendar->to, 'status' => '<span style=\"color:violet\">Recupero</span>');//\App\Models\Presence::where('member_id', $this->dataId)->get();
+            $this->recuperi += 1;
+        }
+
+        $sortVariable='from';
+        usort(
+            $this->member_presences, 
+            fn(array $a, array $b): int => $a[$sortVariable] <=> $b[$sortVariable]
+        );
+
+        //usort($this->member_presences, $this->cmp);
+        //usort($this->member_presences, function ($a, $b) { return $a['from'] > $b['from']; });
+        
+        $this->presenceYears = \App\Models\Course::whereIn('id', $course_ids)->orderBy('year')->groupBy('year')->pluck('year')->toArray();
+        $this->presenceTitle = \App\Models\Course::whereIn('id', $course_ids)->orderBy('name')->groupBy('name')->pluck('name')->toArray();
+
+        
+        // return view('livewire.member');
+    }
+
+    
+
     public function showDetailF($id)
     {
         if (!isset($_GET["from"]) && $this->from == '')

+ 36 - 0
public/css/extra.css

@@ -31,3 +31,39 @@ table.tableHead thead {
     background: #e4e4e4 !important;
     border-radius: 10px;
 }
+.box-presenze
+{
+    padding:10px; 
+    border:1px solid green;
+    margin: 10px; 
+    border-radius: 10px; 
+    text-align: center;
+    color:green;
+}
+.box-assenze
+{
+    padding:10px; 
+    border:1px solid red;
+    margin: 10px; 
+    border-radius: 10px; 
+    text-align: center;
+    color:red;
+}
+.box-recupero
+{
+    padding:10px; 
+    border:1px solid violet;
+    margin: 10px; 
+    border-radius: 10px; 
+    text-align: center;
+    color:violet;
+}
+.box-annullate
+{
+    padding:10px; 
+    border:1px solid gray;
+    margin: 10px; 
+    border-radius: 10px; 
+    text-align: center;
+    color:gray;
+}

+ 76 - 0
resources/views/livewire/member.blade.php

@@ -514,6 +514,7 @@
                                 <h4 style="cursor:pointer;{{$type == 'dati' ? 'border-bottom:2px solid #0C6197; color:#0C6197;' : ''}}" wire:click="change('dati')">Anagrafica</h4>
                                 <h4 style="cursor:pointer;{{$type == 'tesseramento' ? 'border-bottom:2px solid #0C6197; color:#0C6197;' : ''}}" wire:click="change('tesseramento')">Tesseramento</h4>
                                 <h4 style="cursor:pointer;{{$type == 'corsi' ? 'border-bottom:2px solid #0C6197; color:#0C6197;' : ''}}" wire:click="change('corsi')">Corsi</h4>
+                                <h4 style="cursor:pointer;{{$type == 'presenze' ? 'border-bottom:2px solid #0C6197; color:#0C6197;' : ''}}" wire:click="change('presenze')">Presenze</h4>
                                 <h4 style="cursor:pointer;{{$type == 'gruppi' ? 'border-bottom:2px solid #0C6197; color:#0C6197;' : ''}}" wire:click="change('gruppi')">Gruppi</h4>
                             </div>
 
@@ -1130,6 +1131,81 @@
 
                                 @endif
 
+                                @if($type == 'presenze')
+
+                                    <div class="form--wrapper">
+                                        <div class="row ">
+                                            <div class="col-md-6">
+                                                <select class="form-control">
+                                                    @foreach($presenceYears as $y)
+                                                        <option value="{{$y}}">{{$y}}</option>
+                                                    @endforeach
+                                                </select>
+                                            </div>
+                                            <div class="col-md-6">
+                                                <select class="form-control">
+                                                    @foreach($presenceTitle as $t)
+                                                        <option value="{{$t}}">{{$t}}</option>
+                                                    @endforeach
+                                                </select>
+                                            </div>
+                                        </div>
+                                        <div class="row ">
+                                            <div class="col-md-3">
+                                                <div class="box-presenze">
+                                                    Presenze<br>
+                                                    {{$presenze}}
+                                                </div>                                                
+                                            </div>
+                                            <div class="col-md-3">
+                                                <div class="box-assenze">
+                                                    Assenze<br>
+                                                    {{$assenze}}
+                                                </div>
+                                            </div>
+                                            <div class="col-md-3">
+                                                <div class="box-recupero">
+                                                    Recupero<br>
+                                                    {{$recuperi}}
+                                                </div>
+                                            </div>
+                                            <div class="col-md-3">
+                                                <div class="box-annullate">
+                                                    Annullate<br>
+                                                    {{$annullate}}
+                                                </div>
+                                            </div>
+                                        </div>
+                                        <div class="row ">
+                                            <div class="col-md-12">
+                                            </div>
+                                        </div>
+                                        <div class="row " style="height: 300px; overflow:auto; ">
+                                            <div class="col-md-12">
+                                                <table class="table tablesaw tableHead tablesaw-stack tabella--presenze" id="tablesaw-350-2" style="min-width:700px">
+                                                    <thead>
+                                                        <tr>
+                                                            <th>Data</th>
+                                                            <th>Orario</th>
+                                                            <th>Stato</th>
+                                                        </tr>                                                        
+                                                    </thead>
+                                                    <tbody>
+                                                        @foreach($member_presences as $mp)
+                                                            <tr>
+                                                                <td>{{date("d/m/Y", strtotime($mp["from"]))}}</td>
+                                                                <td>{{date("H:i", strtotime($mp["from"]))}} - {{date("H:i", strtotime($mp["to"]))}}</td>
+                                                                <td>{!!$mp["status"]!!}</td>
+                                                            </tr>
+                                                        @endforeach
+                                                    </tbody>
+                                                </table>
+                                            </div>
+                                        </div>
+                                    </div>
+
+                                @endif
+
                                 @if($type == 'corsi')
                                     @if($dataId > 0)