Luca Parisio hai 1 mes
pai
achega
cf33f76303

+ 5 - 0
app/Http/Livewire/AbsenceReport.php

@@ -74,6 +74,11 @@ class AbsenceReport extends Component
                             $this->records[$member->member->id] = array("last_name" => $member->member->last_name, "first_name" => $member->member->first_name, "course" => $calendar->name, "total" => 1, "date" => date("d/m", strtotime($calendar->from)));
                     }
                 }
+                else
+                {
+                    if (array_key_exists($member->member->id, $this->records))
+                        unset($this->records[$member->member->id]);
+                }
             }
         }
 

+ 59 - 0
app/Http/Livewire/CalendarRemove.php

@@ -0,0 +1,59 @@
+<?php
+
+namespace App\Http\Livewire;
+
+use Livewire\Component;
+
+class CalendarRemove extends Component
+{
+    public $records;
+
+    public function render()
+    {
+        
+        $this->records = [];
+
+        $calendars = \App\Models\Calendar::orderBy('from')->get();
+        foreach($calendars as $calendar)
+        {
+            $days = ['dom', 'lun', 'mar', 'mer', 'gio', 'ven', 'sab'];
+            $dow = date('w', strtotime($calendar->from));
+            $d = $days[$dow];
+
+            $h = date('H:i', strtotime($calendar->from));
+
+            // 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();
+
+            $months = date("n", strtotime($calendar->from));
+
+            $members_count = \App\Models\MemberCourse::query()
+                        ->whereRaw("JSON_CONTAINS(`when`, JSON_OBJECT('day', JSON_ARRAY(?), 'from', ?), '$')", [$d, $h])
+                        ->whereRaw("JSON_CONTAINS(months, JSON_OBJECT('m', CAST(? AS UNSIGNED)), '$')", [$months])
+                        ->whereRaw("NOT JSON_CONTAINS(months, JSON_OBJECT('m', CAST(? AS UNSIGNED), 'status', 2), '$')", [$months])
+                        ->whereRaw("NOT JSON_CONTAINS(months, JSON_OBJECT('m', CAST(? AS UNSIGNED), 'status', '2'), '$')", [$months])
+                        ->whereIn('course_id', $courses)
+                        ->count();
+            
+            if ($members_count == 0)
+            {
+                $this->records[] = array('id' => $calendar->id, 'date' => date("d/m/Y", strtotime($calendar->from)), "name" => $calendar->name, "hour" => date("H:i", strtotime($calendar->from)));
+            }
+
+        }
+
+        return view('livewire.calendar_remove');
+    }
+
+    public function removeSelected($ids)
+    {
+
+        foreach($ids as $id)
+        {
+            \App\Models\Calendar::findOrFail($id)->delete();
+        }
+
+    }
+
+
+}

+ 6 - 0
resources/views/livewire/calendar.blade.php

@@ -30,6 +30,12 @@
                     Aggiungi lezione
                 </a>
             </div>
+            <div class="col-auto mt-2">
+                <a style="cursor:pointer" href="/calendar_remove">
+                    {{-- <i class="fa-solid fa-plus"></i> --}}
+                    Lezioni da eliminare
+                </a>
+            </div>
         </div>
         <br>
         <div id='calendar'></div>

+ 85 - 0
resources/views/livewire/calendar_remove.blade.php

@@ -0,0 +1,85 @@
+<div class="col card--ui" id="card--dashboard">
+
+    <a class="btn--ui lightGrey" href="/presence_reports"><i class="fa-solid fa-arrow-left"></i></a><br>
+
+    <header id="title--section" style="display:none !important" class="d-flex align-items-center justify-content-between">
+        <div class="title--section_name d-flex align-items-center justify-content-between">
+            <i class="ico--ui title_section utenti me-2"></i>
+            <h2 class="primary">Lezioni da rimuovere</h2>
+        </div>
+    </header>
+
+    <br>
+
+    <div class="row">
+        <div class="col-12 mb-3">
+            <h3 class="primary">Lezioni inserite senza nessun iscritto</h3>
+        </div>
+        <div class="col-12">
+            <table class="report-table">
+                <thead>
+                    <tr>
+                        <td></td>
+                        <td>Data</td>
+                        <td>Ora</td>
+                        <td>Corso</td>
+                        <td></td>
+                    </tr>
+                </thead>
+                <tbody>
+                    @foreach($records as $record)
+                    <tr>
+                        <td><input type="checkbox" value="{{$record["id"]}}" class="chk"></td>
+                        <td>{{$record["date"]}}</td>
+                        <td>{{$record["hour"]}}</td>
+                        <td>{{$record["name"]}}</td>
+                        <td><a href="/presences?calendarId={{$record["id"]}}" target="_blank">Visualizza</a></td>
+                    </tr>
+                    @endforeach
+                </tbody>
+                <span id="deleting" style="display:none">Eliminazione in corso...</span>
+                <input type="button" class="btDelete btn--ui" value="Elimina">
+            </table>
+        </div>
+    </div>
+</div>
+
+@push('css')
+<link href="/css/presence_report.css" rel="stylesheet" />
+@endpush
+
+@push('scripts')
+<link href="/css/datatables.css" rel="stylesheet" />
+<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
+@endpush
+
+@push('scripts')
+<script>
+    $(document).ready(function() {
+
+        var ids = [];
+
+        $('.chk').change(function() {
+            console.log($(this).val());
+            if(this.checked) 
+            {
+                ids.push($(this).val());
+            }
+            else
+            {
+                var index = ids.indexOf($(this).val());
+                if (index > -1) 
+                {
+                    ids.splice(index, 1);
+                }
+            }
+        }); 
+
+        $(".btDelete").click(function(){
+            $("#deleting").show();
+            @this.removeSelected(ids);      
+        });
+
+    });
+</script>
+@endpush

+ 1 - 0
routes/web.php

@@ -89,6 +89,7 @@ Route::group(['middleware' => 'auth'], function () {
     Route::get('/users', \App\Http\Livewire\User::class);
     Route::get('/profile', \App\Http\Livewire\Profile::class);
     Route::get('/calendar', \App\Http\Livewire\Calendar::class);
+    Route::get('/calendar_remove', \App\Http\Livewire\CalendarRemove::class);
     Route::get('/presences', \App\Http\Livewire\Presence::class);
     Route::get('/presence_reports', \App\Http\Livewire\PresenceReport::class);
     Route::get('/absence_reports', \App\Http\Livewire\AbsenceReport::class);