|
|
@@ -17,8 +17,6 @@ class Dashboard extends Component
|
|
|
public $in;
|
|
|
public $out;
|
|
|
public $members;
|
|
|
-
|
|
|
- // New properties for the enhanced dashboard
|
|
|
public $activeUsers = 0;
|
|
|
public $registeredUsers = 0;
|
|
|
public $expiredCertificates = 0;
|
|
|
@@ -37,8 +35,7 @@ class Dashboard extends Component
|
|
|
public $recentTransactions = [];
|
|
|
public $coursesParticipation = [];
|
|
|
public $notes = '';
|
|
|
- public $savedNotes = []; // Array to store saved notes
|
|
|
-
|
|
|
+ public $savedNotes = [];
|
|
|
public array $membersDatas = [];
|
|
|
public array $recordDatas = [];
|
|
|
public array $labels = [];
|
|
|
@@ -95,8 +92,8 @@ class Dashboard extends Component
|
|
|
->where('date', date("Y-m-d"))
|
|
|
->get();
|
|
|
|
|
|
- foreach($todayRecordsIn as $record) {
|
|
|
- foreach($record->rows as $row) {
|
|
|
+ foreach ($todayRecordsIn as $record) {
|
|
|
+ foreach ($record->rows as $row) {
|
|
|
$this->totTodayIn += $row->amount;
|
|
|
}
|
|
|
}
|
|
|
@@ -106,8 +103,8 @@ class Dashboard extends Component
|
|
|
->where('date', date("Y-m-d"))
|
|
|
->get();
|
|
|
|
|
|
- foreach($todayRecordsOut as $record) {
|
|
|
- foreach($record->rows as $row) {
|
|
|
+ foreach ($todayRecordsOut as $record) {
|
|
|
+ foreach ($record->rows as $row) {
|
|
|
$this->totTodayOut += $row->amount;
|
|
|
}
|
|
|
}
|
|
|
@@ -118,7 +115,6 @@ class Dashboard extends Component
|
|
|
'today_expenses' => $this->totTodayOut,
|
|
|
'execution_time_ms' => round(($endTime - $startTime) * 1000, 2)
|
|
|
]);
|
|
|
-
|
|
|
} catch (\Exception $e) {
|
|
|
Log::error('Error loading basic stats', [
|
|
|
'error' => $e->getMessage(),
|
|
|
@@ -144,9 +140,9 @@ class Dashboard extends Component
|
|
|
'suspended_subscriptions' => $this->suspendedSubscriptions
|
|
|
]);
|
|
|
|
|
|
- $this->expiredCertificates = \App\Models\Member::whereHas('certificates', function($query) {
|
|
|
+ $this->expiredCertificates = \App\Models\Member::whereHas('certificates', function ($query) {
|
|
|
$query->where('expire_date', '<', now());
|
|
|
- })->whereDoesntHave('certificates', function($query) {
|
|
|
+ })->whereDoesntHave('certificates', function ($query) {
|
|
|
$query->where('expire_date', '>=', now());
|
|
|
})->count();
|
|
|
|
|
|
@@ -165,9 +161,9 @@ class Dashboard extends Component
|
|
|
$lastMonthSuspendedSubscriptions = \App\Models\Member::where('current_status', 1)
|
|
|
->where('updated_at', '<=', $endOfLastMonth)
|
|
|
->count();
|
|
|
- $lastMonthExpiredCertificates = \App\Models\Member::whereHas('certificates', function($query) use ($endOfLastMonth) {
|
|
|
+ $lastMonthExpiredCertificates = \App\Models\Member::whereHas('certificates', function ($query) use ($endOfLastMonth) {
|
|
|
$query->where('expire_date', '<', $endOfLastMonth);
|
|
|
- })->whereDoesntHave('certificates', function($query) use ($endOfLastMonth) {
|
|
|
+ })->whereDoesntHave('certificates', function ($query) use ($endOfLastMonth) {
|
|
|
$query->where('expire_date', '>=', $endOfLastMonth);
|
|
|
})->count();
|
|
|
|
|
|
@@ -186,7 +182,6 @@ class Dashboard extends Component
|
|
|
],
|
|
|
'execution_time_ms' => round(($endTime - $startTime) * 1000, 2)
|
|
|
]);
|
|
|
-
|
|
|
} catch (\Exception $e) {
|
|
|
Log::error('Error loading user stats', [
|
|
|
'error' => $e->getMessage(),
|
|
|
@@ -225,7 +220,6 @@ class Dashboard extends Component
|
|
|
'to_pay' => $this->toPay,
|
|
|
'execution_time_ms' => round(($endTime - $startTime) * 1000, 2)
|
|
|
]);
|
|
|
-
|
|
|
} catch (\Exception $e) {
|
|
|
Log::error('Error loading financial stats', [
|
|
|
'error' => $e->getMessage(),
|
|
|
@@ -248,7 +242,7 @@ class Dashboard extends Component
|
|
|
->limit(5)
|
|
|
->get();
|
|
|
|
|
|
- $this->recentUsers = $recentMembers->map(function($member) {
|
|
|
+ $this->recentUsers = $recentMembers->map(function ($member) {
|
|
|
return [
|
|
|
'surname' => strtoupper($member->last_name),
|
|
|
'name' => strtoupper($member->first_name),
|
|
|
@@ -267,7 +261,7 @@ class Dashboard extends Component
|
|
|
->limit(10)
|
|
|
->get();
|
|
|
|
|
|
- $this->recentTransactions = $recentRecords->map(function($record) {
|
|
|
+ $this->recentTransactions = $recentRecords->map(function ($record) {
|
|
|
if ($record->type == 'IN') {
|
|
|
$name = $record->member ?
|
|
|
strtoupper($record->member->last_name) . ' ' . strtoupper($record->member->first_name) :
|
|
|
@@ -279,7 +273,7 @@ class Dashboard extends Component
|
|
|
}
|
|
|
|
|
|
$totalAmount = 0;
|
|
|
- foreach($record->rows as $row) {
|
|
|
+ foreach ($record->rows as $row) {
|
|
|
$totalAmount += $row->amount;
|
|
|
}
|
|
|
|
|
|
@@ -299,7 +293,6 @@ class Dashboard extends Component
|
|
|
Log::info('Recent data loaded successfully', [
|
|
|
'execution_time_ms' => round(($endTime - $startTime) * 1000, 2)
|
|
|
]);
|
|
|
-
|
|
|
} catch (\Exception $e) {
|
|
|
Log::error('Error loading recent data', [
|
|
|
'error' => $e->getMessage(),
|
|
|
@@ -317,8 +310,13 @@ class Dashboard extends Component
|
|
|
try {
|
|
|
$today = now()->format('N');
|
|
|
$dayNames = [
|
|
|
- 1 => 'lun', 2 => 'mar', 3 => 'mer', 4 => 'gio',
|
|
|
- 5 => 'ven', 6 => 'sab', 7 => 'dom'
|
|
|
+ 1 => 'lun',
|
|
|
+ 2 => 'mar',
|
|
|
+ 3 => 'mer',
|
|
|
+ 4 => 'gio',
|
|
|
+ 5 => 'ven',
|
|
|
+ 6 => 'sab',
|
|
|
+ 7 => 'dom'
|
|
|
];
|
|
|
$todayName = $dayNames[$today];
|
|
|
|
|
|
@@ -327,82 +325,57 @@ class Dashboard extends Component
|
|
|
'today_name' => $todayName
|
|
|
]);
|
|
|
|
|
|
- // Try with status = 0 first (inactive), then status = 1 (active) as fallback
|
|
|
- $activeCourses = \App\Models\MemberCourse::with(['course.level', 'course.frequency', 'member'])
|
|
|
- ->whereIn('status', [0, 1]) // Include both statuses
|
|
|
- ->whereRaw('JSON_EXTRACT(`when`, "$[*].day") LIKE ?', ['%"' . $todayName . '"%'])
|
|
|
+ $memberCourses = \App\Models\MemberCourse::with(['course.level', 'course.frequency', 'member'])
|
|
|
+ ->whereIn('status', [0, 1])
|
|
|
+ ->whereHas('course', function ($query) {
|
|
|
+ $query->whereNotNull('when');
|
|
|
+ })
|
|
|
->get();
|
|
|
|
|
|
- // Fallback: if JSON_EXTRACT doesn't work, get all and filter in PHP
|
|
|
- if ($activeCourses->isEmpty()) {
|
|
|
- Log::warning('JSON_EXTRACT query returned empty, trying PHP filtering');
|
|
|
-
|
|
|
- $allCourses = \App\Models\MemberCourse::with(['course.level', 'course.frequency', 'member'])
|
|
|
- ->whereIn('status', [0, 1])
|
|
|
- ->whereNotNull('when')
|
|
|
- ->get();
|
|
|
-
|
|
|
- $activeCourses = $allCourses->filter(function($memberCourse) use ($todayName) {
|
|
|
- try {
|
|
|
- $whenData = json_decode($memberCourse->when, true);
|
|
|
- if (is_array($whenData)) {
|
|
|
- foreach($whenData as $schedule) {
|
|
|
- if (isset($schedule['day']) && is_array($schedule['day']) && in_array($todayName, $schedule['day'])) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (\Exception $e) {
|
|
|
- Log::debug('Error parsing when data', [
|
|
|
- 'member_course_id' => $memberCourse->id,
|
|
|
- 'when' => $memberCourse->when,
|
|
|
- 'error' => $e->getMessage()
|
|
|
- ]);
|
|
|
- }
|
|
|
- return false;
|
|
|
- });
|
|
|
-
|
|
|
- Log::info('PHP filtering results', [
|
|
|
- 'total_courses_checked' => $allCourses->count(),
|
|
|
- 'matching_courses' => $activeCourses->count()
|
|
|
- ]);
|
|
|
- }
|
|
|
-
|
|
|
- Log::info('Raw query for courses', [
|
|
|
- 'today_name' => $todayName,
|
|
|
- 'query_like' => '%"' . $todayName . '"%',
|
|
|
- 'total_member_courses' => \App\Models\MemberCourse::count()
|
|
|
+ Log::info('Total member courses found', [
|
|
|
+ 'count' => $memberCourses->count()
|
|
|
]);
|
|
|
|
|
|
- // Debug: let's also try a direct query to see what we get
|
|
|
- $allMemberCourses = \App\Models\MemberCourse::with(['course.level', 'course.frequency'])
|
|
|
- ->limit(10)
|
|
|
- ->get();
|
|
|
+ $activeCourses = $memberCourses->filter(function ($memberCourse) use ($todayName) {
|
|
|
+ try {
|
|
|
+ $whenData = json_decode($memberCourse->course->when, true);
|
|
|
|
|
|
- Log::info('Sample member courses from database', [
|
|
|
- 'sample_courses' => $allMemberCourses->map(function($mc) {
|
|
|
- return [
|
|
|
- 'id' => $mc->id,
|
|
|
- 'course_id' => $mc->course_id,
|
|
|
- 'course_name' => $mc->course->name ?? 'No name',
|
|
|
- 'level_name' => is_object($mc->course->level) ? $mc->course->level->name : 'No level',
|
|
|
- 'frequency_name' => is_object($mc->course->frequency) ? $mc->course->frequency->name : 'No frequency',
|
|
|
- 'status' => $mc->status,
|
|
|
- 'when' => $mc->when
|
|
|
- ];
|
|
|
- })->toArray()
|
|
|
- ]);
|
|
|
+ if (!is_array($whenData)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- Log::info('Active courses found', [
|
|
|
+ foreach ($whenData as $schedule) {
|
|
|
+ if (
|
|
|
+ isset($schedule['day']) &&
|
|
|
+ is_array($schedule['day']) &&
|
|
|
+ in_array($todayName, $schedule['day'])
|
|
|
+ ) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Log::debug('Error parsing course schedule', [
|
|
|
+ 'member_course_id' => $memberCourse->id,
|
|
|
+ 'course_id' => $memberCourse->course->id,
|
|
|
+ 'when' => $memberCourse->course->when,
|
|
|
+ 'error' => $e->getMessage()
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ });
|
|
|
+
|
|
|
+ Log::info('Active courses found for today', [
|
|
|
'count' => $activeCourses->count(),
|
|
|
- 'courses_ids' => $activeCourses->pluck('id')->toArray()
|
|
|
+ 'course_ids' => $activeCourses->pluck('course.id')->toArray()
|
|
|
]);
|
|
|
|
|
|
- $this->courses = $activeCourses->map(function($memberCourse) use ($todayName) {
|
|
|
- $whenData = json_decode($memberCourse->when, true);
|
|
|
+ $this->courses = $activeCourses->map(function ($memberCourse) use ($todayName) {
|
|
|
+ $whenData = json_decode($memberCourse->course->when, true);
|
|
|
|
|
|
- Log::debug('Processing course when data', [
|
|
|
+ Log::debug('Processing course schedule', [
|
|
|
'member_course_id' => $memberCourse->id,
|
|
|
+ 'course_id' => $memberCourse->course->id,
|
|
|
+ 'course_name' => $memberCourse->course->name,
|
|
|
'when_data' => $whenData,
|
|
|
'looking_for_day' => $todayName
|
|
|
]);
|
|
|
@@ -410,78 +383,75 @@ class Dashboard extends Component
|
|
|
$todaySchedule = null;
|
|
|
|
|
|
if (is_array($whenData)) {
|
|
|
- foreach($whenData as $schedule) {
|
|
|
- if (isset($schedule['day']) && is_array($schedule['day']) && in_array($todayName, $schedule['day'])) {
|
|
|
+ foreach ($whenData as $schedule) {
|
|
|
+ if (
|
|
|
+ isset($schedule['day']) &&
|
|
|
+ is_array($schedule['day']) &&
|
|
|
+ in_array($todayName, $schedule['day'])
|
|
|
+ ) {
|
|
|
$todaySchedule = $schedule;
|
|
|
Log::debug('Found matching schedule', [
|
|
|
'schedule' => $schedule,
|
|
|
- 'member_course_id' => $memberCourse->id
|
|
|
+ 'course_id' => $memberCourse->course->id
|
|
|
]);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if ($todaySchedule) {
|
|
|
- $days = implode('-', array_map('ucfirst', $todaySchedule['day']));
|
|
|
-
|
|
|
- // Get course details
|
|
|
- $course = $memberCourse->course;
|
|
|
- $courseName = $course->name ?? 'Corso Sconosciuto';
|
|
|
- $levelName = is_object($course->level) ? $course->level->name : '';
|
|
|
- $frequencyName = is_object($course->frequency) ? $course->frequency->name : '';
|
|
|
- $typeName = $course->getFormattedTypeField() ?? '';
|
|
|
-
|
|
|
- // Build full course name similar to getCoursesForSelect
|
|
|
- $courseNameParts = [$courseName];
|
|
|
- if ($levelName) $courseNameParts[] = $levelName;
|
|
|
- if ($typeName) $courseNameParts[] = $typeName;
|
|
|
- if ($frequencyName) $courseNameParts[] = $frequencyName;
|
|
|
-
|
|
|
- $fullCourseName = implode(' - ', $courseNameParts);
|
|
|
-
|
|
|
- return [
|
|
|
- 'time' => $todaySchedule['from'] . ' - ' . $todaySchedule['to'],
|
|
|
- 'course_name' => $courseName,
|
|
|
- 'full_name' => $fullCourseName,
|
|
|
- 'level_name' => $levelName,
|
|
|
- 'type_name' => $typeName,
|
|
|
- 'frequency_name' => $frequencyName,
|
|
|
- 'days' => $days,
|
|
|
- 'type' => $course->type ?? 'Standard',
|
|
|
- 'from_time' => $todaySchedule['from'], // Add for sorting
|
|
|
- 'member_course_id' => $memberCourse->id
|
|
|
- ];
|
|
|
- } else {
|
|
|
+ if (!$todaySchedule) {
|
|
|
Log::debug('No matching schedule found for today', [
|
|
|
- 'member_course_id' => $memberCourse->id,
|
|
|
+ 'course_id' => $memberCourse->course->id,
|
|
|
'when_data' => $whenData
|
|
|
]);
|
|
|
+ return null;
|
|
|
}
|
|
|
- return null;
|
|
|
+
|
|
|
+ $days = implode('-', array_map('ucfirst', $todaySchedule['day']));
|
|
|
+ $course = $memberCourse->course;
|
|
|
+
|
|
|
+ $courseName = $course->name ?? 'Corso Sconosciuto';
|
|
|
+ $levelName = $course->level?->name ?? '';
|
|
|
+ $frequencyName = $course->frequency?->name ?? '';
|
|
|
+ $typeName = $course->getFormattedTypeField() ?? '';
|
|
|
+
|
|
|
+ $courseNameParts = [$courseName];
|
|
|
+ if ($levelName) $courseNameParts[] = $levelName;
|
|
|
+ if ($typeName) $courseNameParts[] = $typeName;
|
|
|
+ if ($frequencyName) $courseNameParts[] = $frequencyName;
|
|
|
+
|
|
|
+ $fullCourseName = implode(' - ', $courseNameParts);
|
|
|
+
|
|
|
+ return [
|
|
|
+ 'time' => $todaySchedule['from'] . ' - ' . $todaySchedule['to'],
|
|
|
+ 'course_name' => $courseName,
|
|
|
+ 'full_name' => $fullCourseName,
|
|
|
+ 'level_name' => $levelName,
|
|
|
+ 'type_name' => $typeName,
|
|
|
+ 'frequency_name' => $frequencyName,
|
|
|
+ 'days' => $days,
|
|
|
+ 'type' => $course->type ?? 'Standard',
|
|
|
+ 'from_time' => $todaySchedule['from'],
|
|
|
+ 'course_id' => $course->id,
|
|
|
+ 'member_course_id' => $memberCourse->id
|
|
|
+ ];
|
|
|
})->filter()->values();
|
|
|
|
|
|
- // Sort by start time (from_time)
|
|
|
- $sortedCourses = $this->courses->sortBy('from_time')->values();
|
|
|
+ $sortedCourses = $this->courses->sortBy('from_time')->take(5);
|
|
|
|
|
|
- // Log the sorted order before removing fields
|
|
|
Log::info('Courses sorted by time', [
|
|
|
- 'sorted_courses' => $sortedCourses->map(function($course) {
|
|
|
+ 'sorted_courses' => $sortedCourses->map(function ($course) {
|
|
|
return [
|
|
|
'time' => $course['time'],
|
|
|
'from_time' => $course['from_time'],
|
|
|
'course_name' => $course['course_name'],
|
|
|
- 'member_course_id' => $course['member_course_id']
|
|
|
+ 'course_id' => $course['course_id']
|
|
|
];
|
|
|
})->toArray()
|
|
|
]);
|
|
|
|
|
|
- // Limit to 5 courses
|
|
|
- $this->courses = $sortedCourses->take(5);
|
|
|
-
|
|
|
- // Remove from_time field from final output and convert to array
|
|
|
- $this->courses = $this->courses->map(function($course) {
|
|
|
- unset($course['from_time'], $course['member_course_id']);
|
|
|
+ $this->courses = $sortedCourses->map(function ($course) {
|
|
|
+ unset($course['from_time'], $course['member_course_id'], $course['course_id']);
|
|
|
return $course;
|
|
|
})->toArray();
|
|
|
|
|
|
@@ -491,7 +461,6 @@ class Dashboard extends Component
|
|
|
'execution_time_ms' => round(($endTime - $startTime) * 1000, 2),
|
|
|
'final_courses_display' => $this->courses
|
|
|
]);
|
|
|
-
|
|
|
} catch (\Exception $e) {
|
|
|
Log::error('Error loading courses data', [
|
|
|
'error' => $e->getMessage(),
|
|
|
@@ -519,7 +488,7 @@ class Dashboard extends Component
|
|
|
|
|
|
Log::info('Course participation stats', [
|
|
|
'courses_found' => $courseStats->count(),
|
|
|
- 'stats' => $courseStats->map(function($stat) {
|
|
|
+ 'stats' => $courseStats->map(function ($stat) {
|
|
|
$course = $stat->course;
|
|
|
$levelName = is_object($course->level) ? $course->level->name : '';
|
|
|
$frequencyName = is_object($course->frequency) ? $course->frequency->name : '';
|
|
|
@@ -536,7 +505,7 @@ class Dashboard extends Component
|
|
|
|
|
|
$totalParticipants = $courseStats->sum('participants');
|
|
|
|
|
|
- $this->coursesParticipation = $courseStats->map(function($stat) use ($totalParticipants) {
|
|
|
+ $this->coursesParticipation = $courseStats->map(function ($stat) use ($totalParticipants) {
|
|
|
$percentage = $totalParticipants > 0 ? ($stat->participants / $totalParticipants) * 100 : 0;
|
|
|
$course = $stat->course;
|
|
|
$courseName = $course->name ?? 'Corso Sconosciuto';
|
|
|
@@ -573,7 +542,6 @@ class Dashboard extends Component
|
|
|
'participation_data' => $this->coursesParticipation,
|
|
|
'execution_time_ms' => round(($endTime - $startTime) * 1000, 2)
|
|
|
]);
|
|
|
-
|
|
|
} catch (\Exception $e) {
|
|
|
Log::error('Error loading courses participation', [
|
|
|
'error' => $e->getMessage(),
|
|
|
@@ -586,24 +554,20 @@ class Dashboard extends Component
|
|
|
|
|
|
private function getCourseColor($courseName)
|
|
|
{
|
|
|
- // Array of different colors for courses
|
|
|
$colors = [
|
|
|
- 'padel', // #FFD700 - Gold
|
|
|
- 'tennis', // #8B4CF7 - Purple
|
|
|
- 'pallavolo', // #FF6B35 - Orange
|
|
|
- 'yoga', // #339E8E - Teal
|
|
|
- 'blue', // #0618BE - Blue
|
|
|
- 'pink', // #E91E63 - Pink
|
|
|
- 'green', // #4CAF50 - Green
|
|
|
- 'red', // #F44336 - Red
|
|
|
- 'indigo', // #3F51B5 - Indigo
|
|
|
- 'amber', // #FF9800 - Amber
|
|
|
- 'cyan', // #00BCD4 - Cyan
|
|
|
- 'lime' // #CDDC39 - Lime
|
|
|
+ 'padel',
|
|
|
+ 'tennis',
|
|
|
+ 'pallavolo',
|
|
|
+ 'yoga',
|
|
|
+ 'blue',
|
|
|
+ 'pink',
|
|
|
+ 'green',
|
|
|
+ 'red',
|
|
|
+ 'indigo',
|
|
|
+ 'amber',
|
|
|
+ 'cyan',
|
|
|
+ 'lime'
|
|
|
];
|
|
|
-
|
|
|
- // Use course_id or course name hash to consistently assign colors
|
|
|
- // This ensures the same course always gets the same color
|
|
|
$hash = crc32($courseName);
|
|
|
$colorIndex = abs($hash) % count($colors);
|
|
|
$assignedColor = $colors[$colorIndex];
|
|
|
@@ -623,13 +587,11 @@ class Dashboard extends Component
|
|
|
Log::info('Loading saved notes');
|
|
|
|
|
|
try {
|
|
|
- // Load saved notes from session or database
|
|
|
$this->savedNotes = session()->get('dashboard_notes', []);
|
|
|
|
|
|
Log::info('Saved notes loaded', [
|
|
|
'notes_count' => count($this->savedNotes)
|
|
|
]);
|
|
|
-
|
|
|
} catch (\Exception $e) {
|
|
|
Log::error('Error loading saved notes', [
|
|
|
'error' => $e->getMessage()
|
|
|
@@ -641,13 +603,11 @@ class Dashboard extends Component
|
|
|
private function saveSavedNotes()
|
|
|
{
|
|
|
try {
|
|
|
- // Save notes to session (you can change this to save to database)
|
|
|
session()->put('dashboard_notes', $this->savedNotes);
|
|
|
|
|
|
Log::info('Notes saved to session', [
|
|
|
'notes_count' => count($this->savedNotes)
|
|
|
]);
|
|
|
-
|
|
|
} catch (\Exception $e) {
|
|
|
Log::error('Error saving notes', [
|
|
|
'error' => $e->getMessage()
|
|
|
@@ -668,16 +628,12 @@ class Dashboard extends Component
|
|
|
'completed' => false
|
|
|
];
|
|
|
|
|
|
- // Add note to the beginning of the array
|
|
|
array_unshift($this->savedNotes, $newNote);
|
|
|
|
|
|
- // Save to session/database
|
|
|
$this->saveSavedNotes();
|
|
|
|
|
|
- // Clear the input
|
|
|
$this->notes = '';
|
|
|
|
|
|
- // Emit event for success message
|
|
|
$this->dispatchBrowserEvent('note-saved');
|
|
|
|
|
|
Log::info('Note saved successfully', [
|
|
|
@@ -687,7 +643,6 @@ class Dashboard extends Component
|
|
|
} else {
|
|
|
Log::warning('Attempted to save empty note');
|
|
|
}
|
|
|
-
|
|
|
} catch (\Exception $e) {
|
|
|
Log::error('Error saving note', [
|
|
|
'error' => $e->getMessage(),
|
|
|
@@ -704,21 +659,17 @@ class Dashboard extends Component
|
|
|
try {
|
|
|
$initialCount = count($this->savedNotes);
|
|
|
|
|
|
- // Find and remove the note from savedNotes
|
|
|
- $this->savedNotes = array_filter($this->savedNotes, function($note) use ($noteId) {
|
|
|
+ $this->savedNotes = array_filter($this->savedNotes, function ($note) use ($noteId) {
|
|
|
return $note['id'] !== $noteId;
|
|
|
});
|
|
|
|
|
|
- // Reindex the array
|
|
|
$this->savedNotes = array_values($this->savedNotes);
|
|
|
|
|
|
$finalCount = count($this->savedNotes);
|
|
|
|
|
|
if ($initialCount > $finalCount) {
|
|
|
- // Save to session/database
|
|
|
$this->saveSavedNotes();
|
|
|
|
|
|
- // Emit event for success message
|
|
|
$this->dispatchBrowserEvent('note-completed');
|
|
|
|
|
|
Log::info('Note completed successfully', [
|
|
|
@@ -728,7 +679,6 @@ class Dashboard extends Component
|
|
|
} else {
|
|
|
Log::warning('Note not found for completion', ['note_id' => $noteId]);
|
|
|
}
|
|
|
-
|
|
|
} catch (\Exception $e) {
|
|
|
Log::error('Error completing note', [
|
|
|
'note_id' => $noteId,
|
|
|
@@ -739,7 +689,6 @@ class Dashboard extends Component
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // Existing methods with logging
|
|
|
public function addMember()
|
|
|
{
|
|
|
Log::info('Redirecting to add member');
|
|
|
@@ -764,15 +713,19 @@ class Dashboard extends Component
|
|
|
return redirect()->to('/out?new=1');
|
|
|
}
|
|
|
|
|
|
- // Debug method - remove after testing
|
|
|
public function debugCourses()
|
|
|
{
|
|
|
Log::info('=== DEBUG COURSES CALLED ===');
|
|
|
|
|
|
$today = now()->format('N');
|
|
|
$dayNames = [
|
|
|
- 1 => 'lun', 2 => 'mar', 3 => 'mer', 4 => 'gio',
|
|
|
- 5 => 'ven', 6 => 'sab', 7 => 'dom'
|
|
|
+ 1 => 'lun',
|
|
|
+ 2 => 'mar',
|
|
|
+ 3 => 'mer',
|
|
|
+ 4 => 'gio',
|
|
|
+ 5 => 'ven',
|
|
|
+ 6 => 'sab',
|
|
|
+ 7 => 'dom'
|
|
|
];
|
|
|
$todayName = $dayNames[$today];
|
|
|
|
|
|
@@ -782,7 +735,7 @@ class Dashboard extends Component
|
|
|
Log::info('All courses debug', [
|
|
|
'total_courses' => $allCourses->count(),
|
|
|
'today_name' => $todayName,
|
|
|
- 'courses' => $allCourses->map(function($mc) {
|
|
|
+ 'courses' => $allCourses->map(function ($mc) {
|
|
|
return [
|
|
|
'id' => $mc->id,
|
|
|
'status' => $mc->status,
|
|
|
@@ -795,7 +748,6 @@ class Dashboard extends Component
|
|
|
$this->dispatchBrowserEvent('debug-completed');
|
|
|
}
|
|
|
|
|
|
- // Temporary method to activate courses for testing
|
|
|
public function activateTestCourses()
|
|
|
{
|
|
|
try {
|
|
|
@@ -804,24 +756,21 @@ class Dashboard extends Component
|
|
|
|
|
|
Log::info('Activated test courses', ['updated_count' => $updated]);
|
|
|
|
|
|
- // Reload the data
|
|
|
$this->loadCoursesData();
|
|
|
$this->loadCoursesParticipation();
|
|
|
|
|
|
$this->dispatchBrowserEvent('courses-activated', [
|
|
|
'message' => "Attivati $updated corsi per test"
|
|
|
]);
|
|
|
-
|
|
|
} catch (\Exception $e) {
|
|
|
Log::error('Error activating courses', ['error' => $e->getMessage()]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // Existing methods (keeping original implementation)
|
|
|
private function getLabels()
|
|
|
{
|
|
|
$labels = array();
|
|
|
- for($i = 6; $i >= 0; $i--) {
|
|
|
+ for ($i = 6; $i >= 0; $i--) {
|
|
|
$labels[] = date("d/M", strtotime('-' . $i . ' days'));
|
|
|
}
|
|
|
return $labels;
|
|
|
@@ -830,11 +779,11 @@ class Dashboard extends Component
|
|
|
private function getRecordData($type)
|
|
|
{
|
|
|
$data = [];
|
|
|
- for($i = 6; $i >= 0; $i--) {
|
|
|
+ for ($i = 6; $i >= 0; $i--) {
|
|
|
$found = false;
|
|
|
$records = $type == 'IN' ? $this->in : $this->out;
|
|
|
|
|
|
- foreach($records as $record) {
|
|
|
+ foreach ($records as $record) {
|
|
|
if (date("Y-m-d", strtotime($record->date)) == date("Y-m-d", strtotime('-' . $i . ' days'))) {
|
|
|
$data[] = $record->total;
|
|
|
$found = true;
|
|
|
@@ -851,9 +800,9 @@ class Dashboard extends Component
|
|
|
private function getMemberData()
|
|
|
{
|
|
|
$data = [];
|
|
|
- for($i = 6; $i >= 0; $i--) {
|
|
|
+ for ($i = 6; $i >= 0; $i--) {
|
|
|
$found = false;
|
|
|
- foreach($this->members as $member) {
|
|
|
+ foreach ($this->members as $member) {
|
|
|
if (date("Y-m-d", strtotime($member->created_at)) == date("Y-m-d", strtotime('-' . $i . ' days'))) {
|
|
|
$data[] = $member->total;
|
|
|
$found = true;
|