| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- namespace App\Http\Livewire;
- use Livewire\Component;
- class AbsenceReport extends Component
- {
- public $records;
- public function mount()
- {
- setlocale(LC_ALL, 'it_IT');
- }
- public function render()
- {
- setlocale(LC_ALL, 'it_IT');
- $this->records = [];
- $to = date("Y-m-d 23:59:59");
-
- $calendars = \App\Models\Calendar::where('from', '<=', $to)->orderBy('from')->get();
- foreach ($calendars as $calendar) {
- $presences = \App\Models\Presence::where('calendar_id', $calendar->id)->where('status', '<>', 99);
- $presences = $presences->pluck('member_id')->toArray();
- $presences_annullate = \App\Models\Presence::where('calendar_id', $calendar->id)->where('status', 99)->pluck('member_id')->toArray();
- $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);
- $courses = $courses->pluck('id')->toArray();
- $months = date("n", strtotime($calendar->from));
- // Elenco utenti iscritti al corso "padre"
- $members = \App\Models\MemberCourse::where('when', 'like', "%" . $d . "%")->where('when', 'like', '%"from":"' . $h . '"%')->where('months', 'like', '%"m":' . $months . ',%')->whereIn('course_id', $courses)->get();
- //$members = \App\Models\MemberCourse::where('when', 'like', "%" . $d . "%")->where('when', 'like', '%"from":"' . $h . '"%')->whereIn('member_id', $presences)->whereIn('course_id', $courses)->get();
- foreach ($members as $member) {
- $presence = \App\Models\Presence::where('member_id', $member->member->id)->where('calendar_id', $calendar->id)->first();
-
- if (!in_array($member->member->id, $presences))
- {
- if (!in_array($member->member->id, $presences_annullate))
- {
- if (array_key_exists($member->member->id, $this->records))
- {
- $this->records[$member->member->id]['total'] += 1;
- $this->records[$member->member->id]['date'] .= ", " . date("d/m/Y", strtotime($calendar->from));
- }
- else
- $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/Y", strtotime($calendar->from)));
- }
- }
- }
-
- }
- array_multisort(array_column($this->records, 'total'), SORT_DESC, $this->records);
- return view('livewire.absence_report');
- }
- }
|