Dashboard.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. <?php
  2. namespace App\Http\Livewire;
  3. use Livewire\Component;
  4. use Carbon\Carbon;
  5. use Illuminate\Support\Facades\Log;
  6. class Dashboard extends Component
  7. {
  8. // Existing properties
  9. public $totMembers = 0;
  10. public $totSuppliers = 0;
  11. public $totTodayIn = 0;
  12. public $totTodayOut = 0;
  13. public $dayName;
  14. public $in;
  15. public $out;
  16. public $members;
  17. // New properties for the enhanced dashboard
  18. public $activeUsers = 0;
  19. public $registeredUsers = 0;
  20. public $expiredCertificates = 0;
  21. public $suspendedSubscriptions = 0;
  22. public $activeUsersChange = 0;
  23. public $registeredUsersChange = 0;
  24. public $expiredCertificatesChange = 0;
  25. public $suspendedSubscriptionsChange = 0;
  26. public $toReceive = 0;
  27. public $toPay = 0;
  28. public $courses = [];
  29. public $fields = [];
  30. public $recentUsers = [];
  31. public $recentTransactions = [];
  32. public $coursesParticipation = [];
  33. public $notes = '';
  34. public $savedNotes = []; // Array to store saved notes
  35. public array $membersDatas = [];
  36. public array $recordDatas = [];
  37. public array $labels = [];
  38. public array $monthlyLabels = [];
  39. public array $monthlyIncomeData = [];
  40. public array $monthlyExpenseData = [];
  41. public function render()
  42. {
  43. Log::info('Dashboard render method called');
  44. return view('livewire.dashboard');
  45. }
  46. public function mount()
  47. {
  48. Log::info('Dashboard mount started');
  49. $startTime = microtime(true);
  50. $this->dayName = Carbon::now()->locale('it_IT')->dayName;
  51. Log::info('Day name set', ['day' => $this->dayName]);
  52. $this->loadBasicStats();
  53. $this->loadUserStats();
  54. $this->loadFinancialStats();
  55. $this->loadRecentData();
  56. $this->loadSavedNotes();
  57. $endTime = microtime(true);
  58. $executionTime = round(($endTime - $startTime) * 1000, 2);
  59. Log::info('Dashboard mount completed', [
  60. 'execution_time_ms' => $executionTime,
  61. 'active_users' => $this->activeUsers,
  62. 'courses_count' => count($this->courses),
  63. 'participation_count' => count($this->coursesParticipation)
  64. ]);
  65. }
  66. private function loadBasicStats()
  67. {
  68. Log::info('Loading basic stats');
  69. $startTime = microtime(true);
  70. try {
  71. $this->totMembers = \App\Models\Member::count();
  72. $this->totSuppliers = \App\Models\Supplier::count();
  73. Log::info('Basic counts loaded', [
  74. 'total_members' => $this->totMembers,
  75. 'total_suppliers' => $this->totSuppliers
  76. ]);
  77. // Calculate today's income and expenses
  78. $this->totTodayIn = 0;
  79. $todayRecordsIn = \App\Models\Record::where('type', 'IN')
  80. ->where('date', date("Y-m-d"))
  81. ->get();
  82. foreach($todayRecordsIn as $record) {
  83. foreach($record->rows as $row) {
  84. $this->totTodayIn += $row->amount;
  85. }
  86. }
  87. $this->totTodayOut = 0;
  88. $todayRecordsOut = \App\Models\Record::where('type', 'OUT')
  89. ->where('date', date("Y-m-d"))
  90. ->get();
  91. foreach($todayRecordsOut as $record) {
  92. foreach($record->rows as $row) {
  93. $this->totTodayOut += $row->amount;
  94. }
  95. }
  96. $endTime = microtime(true);
  97. Log::info('Basic stats loaded successfully', [
  98. 'today_income' => $this->totTodayIn,
  99. 'today_expenses' => $this->totTodayOut,
  100. 'execution_time_ms' => round(($endTime - $startTime) * 1000, 2)
  101. ]);
  102. } catch (\Exception $e) {
  103. Log::error('Error loading basic stats', [
  104. 'error' => $e->getMessage(),
  105. 'file' => $e->getFile(),
  106. 'line' => $e->getLine()
  107. ]);
  108. }
  109. }
  110. private function loadUserStats()
  111. {
  112. Log::info('Loading user stats');
  113. $startTime = microtime(true);
  114. try {
  115. $this->activeUsers = \App\Models\Member::where('is_archived', 0)->orWhere('is_archived', NULL)->count();
  116. $this->registeredUsers = \App\Models\Member::where('current_status', 2)->count();
  117. $this->suspendedSubscriptions = \App\Models\Member::where('current_status', 1)->count();
  118. Log::info('User counts loaded', [
  119. 'active_users' => $this->activeUsers,
  120. 'registered_users' => $this->registeredUsers,
  121. 'suspended_subscriptions' => $this->suspendedSubscriptions
  122. ]);
  123. $this->expiredCertificates = \App\Models\Member::whereHas('certificates', function($query) {
  124. $query->where('expire_date', '<', now());
  125. })->whereDoesntHave('certificates', function($query) {
  126. $query->where('expire_date', '>=', now());
  127. })->count();
  128. Log::info('Expired certificates count', ['expired_certificates' => $this->expiredCertificates]);
  129. // Calculate changes from last month
  130. $lastMonth = now()->subMonth();
  131. $endOfLastMonth = $lastMonth->copy()->endOfMonth();
  132. $lastMonthActiveUsers = \App\Models\Member::where('is_archived', false)
  133. ->where('created_at', '<=', $endOfLastMonth)
  134. ->count();
  135. $lastMonthRegisteredUsers = \App\Models\Member::where('current_status', 2)
  136. ->where('updated_at', '<=', $endOfLastMonth)
  137. ->count();
  138. $lastMonthSuspendedSubscriptions = \App\Models\Member::where('current_status', 1)
  139. ->where('updated_at', '<=', $endOfLastMonth)
  140. ->count();
  141. $lastMonthExpiredCertificates = \App\Models\Member::whereHas('certificates', function($query) use ($endOfLastMonth) {
  142. $query->where('expire_date', '<', $endOfLastMonth);
  143. })->whereDoesntHave('certificates', function($query) use ($endOfLastMonth) {
  144. $query->where('expire_date', '>=', $endOfLastMonth);
  145. })->count();
  146. $this->activeUsersChange = $this->activeUsers - $lastMonthActiveUsers;
  147. $this->registeredUsersChange = $this->registeredUsers - $lastMonthRegisteredUsers;
  148. $this->expiredCertificatesChange = $this->expiredCertificates - $lastMonthExpiredCertificates;
  149. $this->suspendedSubscriptionsChange = $this->suspendedSubscriptions - $lastMonthSuspendedSubscriptions;
  150. $endTime = microtime(true);
  151. Log::info('User stats loaded successfully', [
  152. 'changes' => [
  153. 'active_users' => $this->activeUsersChange,
  154. 'registered_users' => $this->registeredUsersChange,
  155. 'expired_certificates' => $this->expiredCertificatesChange,
  156. 'suspended_subscriptions' => $this->suspendedSubscriptionsChange
  157. ],
  158. 'execution_time_ms' => round(($endTime - $startTime) * 1000, 2)
  159. ]);
  160. } catch (\Exception $e) {
  161. Log::error('Error loading user stats', [
  162. 'error' => $e->getMessage(),
  163. 'file' => $e->getFile(),
  164. 'line' => $e->getLine()
  165. ]);
  166. }
  167. }
  168. private function loadFinancialStats()
  169. {
  170. Log::info('Loading financial stats');
  171. $startTime = microtime(true);
  172. try {
  173. $currentMonth = now()->format('Y-m');
  174. Log::info('Calculating financial stats for month', ['month' => $currentMonth]);
  175. $this->toReceive = \App\Models\Record::where('type', 'IN')
  176. ->whereRaw('DATE_FORMAT(date, "%Y-%m") = ?', [$currentMonth])
  177. ->where(function ($query) {
  178. $query->where('deleted', false)->orWhere('deleted', null);
  179. })
  180. ->sum('amount') ?? 0;
  181. $this->toPay = \App\Models\Record::where('type', 'OUT')
  182. ->whereRaw('DATE_FORMAT(date, "%Y-%m") = ?', [$currentMonth])
  183. ->where(function ($query) {
  184. $query->where('deleted', false)->orWhere('deleted', null);
  185. })
  186. ->sum('amount') ?? 0;
  187. $endTime = microtime(true);
  188. Log::info('Financial stats loaded successfully', [
  189. 'to_receive' => $this->toReceive,
  190. 'to_pay' => $this->toPay,
  191. 'execution_time_ms' => round(($endTime - $startTime) * 1000, 2)
  192. ]);
  193. } catch (\Exception $e) {
  194. Log::error('Error loading financial stats', [
  195. 'error' => $e->getMessage(),
  196. 'file' => $e->getFile(),
  197. 'line' => $e->getLine()
  198. ]);
  199. }
  200. }
  201. private function loadRecentData()
  202. {
  203. Log::info('Loading recent data');
  204. $startTime = microtime(true);
  205. try {
  206. // Load recent users
  207. $recentMembers = \App\Models\Member::where('is_archived', 0)
  208. ->orWhere('is_archived', NULL)
  209. ->orderBy('created_at', 'desc')
  210. ->limit(5)
  211. ->get();
  212. $this->recentUsers = $recentMembers->map(function($member) {
  213. return [
  214. 'surname' => strtoupper($member->last_name),
  215. 'name' => strtoupper($member->first_name),
  216. 'phone' => $member->phone ?? '',
  217. 'email' => $member->email ?? ''
  218. ];
  219. })->toArray();
  220. Log::info('Recent users loaded', ['count' => count($this->recentUsers)]);
  221. // Load recent transactions
  222. $recentRecords = \App\Models\Record::where('date', '>=', now()->subDays(30))
  223. ->with(['member', 'supplier'])
  224. ->orderBy('date', 'desc')
  225. ->orderBy('created_at', 'desc')
  226. ->limit(10)
  227. ->get();
  228. $this->recentTransactions = $recentRecords->map(function($record) {
  229. if ($record->type == 'IN') {
  230. $name = $record->member ?
  231. strtoupper($record->member->last_name) . ' ' . strtoupper($record->member->first_name) :
  232. 'MEMBRO SCONOSCIUTO';
  233. } else {
  234. $name = $record->supplier ?
  235. strtoupper($record->supplier->name) :
  236. 'FORNITORE SCONOSCIUTO';
  237. }
  238. $totalAmount = 0;
  239. foreach($record->rows as $row) {
  240. $totalAmount += $row->amount;
  241. }
  242. return [
  243. 'name' => $name,
  244. 'amount' => $totalAmount,
  245. 'type' => $record->type == 'IN' ? 'ENTRATA' : 'USCITA'
  246. ];
  247. })->toArray();
  248. Log::info('Recent transactions loaded', ['count' => count($this->recentTransactions)]);
  249. $this->loadCoursesData();
  250. $this->loadCoursesParticipation();
  251. $endTime = microtime(true);
  252. Log::info('Recent data loaded successfully', [
  253. 'execution_time_ms' => round(($endTime - $startTime) * 1000, 2)
  254. ]);
  255. } catch (\Exception $e) {
  256. Log::error('Error loading recent data', [
  257. 'error' => $e->getMessage(),
  258. 'file' => $e->getFile(),
  259. 'line' => $e->getLine()
  260. ]);
  261. }
  262. }
  263. private function loadCoursesData()
  264. {
  265. Log::info('Loading courses data');
  266. $startTime = microtime(true);
  267. try {
  268. $today = now()->format('N');
  269. $dayNames = [
  270. 1 => 'lun', 2 => 'mar', 3 => 'mer', 4 => 'gio',
  271. 5 => 'ven', 6 => 'sab', 7 => 'dom'
  272. ];
  273. $todayName = $dayNames[$today];
  274. Log::info('Searching courses for today', [
  275. 'today_number' => $today,
  276. 'today_name' => $todayName
  277. ]);
  278. // Try with status = 0 first (inactive), then status = 1 (active) as fallback
  279. $activeCourses = \App\Models\MemberCourse::with(['course', 'member'])
  280. ->whereIn('status', [0, 1]) // Include both statuses
  281. ->whereRaw('JSON_EXTRACT(`when`, "$[*].day") LIKE ?', ['%"' . $todayName . '"%'])
  282. ->get();
  283. Log::info('Raw query for courses', [
  284. 'today_name' => $todayName,
  285. 'query_like' => '%"' . $todayName . '"%',
  286. 'total_member_courses' => \App\Models\MemberCourse::count()
  287. ]);
  288. // Debug: let's also try a direct query to see what we get
  289. $allMemberCourses = \App\Models\MemberCourse::with(['course'])
  290. ->limit(10)
  291. ->get();
  292. Log::info('Sample member courses from database', [
  293. 'sample_courses' => $allMemberCourses->map(function($mc) {
  294. return [
  295. 'id' => $mc->id,
  296. 'course_id' => $mc->course_id,
  297. 'course_name' => $mc->course->name ?? 'No name',
  298. 'status' => $mc->status,
  299. 'when' => $mc->when
  300. ];
  301. })->toArray()
  302. ]);
  303. Log::info('Active courses found', [
  304. 'count' => $activeCourses->count(),
  305. 'courses_ids' => $activeCourses->pluck('id')->toArray()
  306. ]);
  307. $this->courses = $activeCourses->map(function($memberCourse) use ($todayName) {
  308. $whenData = json_decode($memberCourse->when, true);
  309. Log::debug('Processing course when data', [
  310. 'member_course_id' => $memberCourse->id,
  311. 'when_data' => $whenData,
  312. 'looking_for_day' => $todayName
  313. ]);
  314. $todaySchedule = null;
  315. if (is_array($whenData)) {
  316. foreach($whenData as $schedule) {
  317. if (isset($schedule['day']) && is_array($schedule['day']) && in_array($todayName, $schedule['day'])) {
  318. $todaySchedule = $schedule;
  319. Log::debug('Found matching schedule', [
  320. 'schedule' => $schedule,
  321. 'member_course_id' => $memberCourse->id
  322. ]);
  323. break;
  324. }
  325. }
  326. }
  327. if ($todaySchedule) {
  328. $days = implode('-', array_map('ucfirst', $todaySchedule['day']));
  329. return [
  330. 'time' => $todaySchedule['from'] . ' - ' . $todaySchedule['to'],
  331. 'course_name' => $memberCourse->course->name ?? 'Corso Sconosciuto',
  332. 'days' => $days,
  333. 'type' => $memberCourse->course->type ?? 'Standard'
  334. ];
  335. } else {
  336. Log::debug('No matching schedule found for today', [
  337. 'member_course_id' => $memberCourse->id,
  338. 'when_data' => $whenData
  339. ]);
  340. }
  341. return null;
  342. })->filter()->values()->toArray();
  343. $this->courses = array_slice($this->courses, 0, 5);
  344. $endTime = microtime(true);
  345. Log::info('Courses data loaded successfully', [
  346. 'final_courses_count' => count($this->courses),
  347. 'execution_time_ms' => round(($endTime - $startTime) * 1000, 2),
  348. 'courses' => $this->courses
  349. ]);
  350. } catch (\Exception $e) {
  351. Log::error('Error loading courses data', [
  352. 'error' => $e->getMessage(),
  353. 'file' => $e->getFile(),
  354. 'line' => $e->getLine()
  355. ]);
  356. $this->courses = [];
  357. }
  358. }
  359. private function loadCoursesParticipation()
  360. {
  361. Log::info('Loading courses participation');
  362. $startTime = microtime(true);
  363. try {
  364. // Conta le partecipazioni per corso (include tutti gli status)
  365. $courseStats = \App\Models\MemberCourse::with('course')
  366. ->whereIn('status', [0, 1]) // Include both statuses
  367. ->selectRaw('course_id, COUNT(*) as participants')
  368. ->groupBy('course_id')
  369. ->orderBy('participants', 'desc')
  370. ->limit(4)
  371. ->get();
  372. Log::info('Course participation stats', [
  373. 'courses_found' => $courseStats->count(),
  374. 'stats' => $courseStats->map(function($stat) {
  375. return [
  376. 'course_id' => $stat->course_id,
  377. 'course_name' => $stat->course->name ?? 'Unknown',
  378. 'participants' => $stat->participants
  379. ];
  380. })->toArray()
  381. ]);
  382. $totalParticipants = $courseStats->sum('participants');
  383. $this->coursesParticipation = $courseStats->map(function($stat) use ($totalParticipants) {
  384. $percentage = $totalParticipants > 0 ? ($stat->participants / $totalParticipants) * 100 : 0;
  385. $courseName = $stat->course->name ?? 'Corso Sconosciuto';
  386. // Assegna colori basati sul nome del corso
  387. $color = $this->getCourseColor($courseName);
  388. return [
  389. 'course_name' => $courseName,
  390. 'participants' => $stat->participants,
  391. 'percentage' => round($percentage, 1),
  392. 'color' => $color
  393. ];
  394. })->toArray();
  395. $endTime = microtime(true);
  396. Log::info('Courses participation loaded successfully', [
  397. 'total_participants' => $totalParticipants,
  398. 'participation_data' => $this->coursesParticipation,
  399. 'execution_time_ms' => round(($endTime - $startTime) * 1000, 2)
  400. ]);
  401. } catch (\Exception $e) {
  402. Log::error('Error loading courses participation', [
  403. 'error' => $e->getMessage(),
  404. 'file' => $e->getFile(),
  405. 'line' => $e->getLine()
  406. ]);
  407. $this->coursesParticipation = [];
  408. }
  409. }
  410. private function getCourseColor($courseName)
  411. {
  412. $courseName = strtolower($courseName);
  413. $color = 'default';
  414. if (strpos($courseName, 'padel') !== false) {
  415. $color = 'padel'; // #FFD700
  416. } elseif (strpos($courseName, 'tennis') !== false) {
  417. $color = 'tennis'; // #8B4CF7
  418. } elseif (strpos($courseName, 'pallavolo') !== false || strpos($courseName, 'volley') !== false) {
  419. $color = 'pallavolo'; // #FF6B35
  420. } elseif (strpos($courseName, 'yoga') !== false) {
  421. $color = 'yoga'; // #339E8E
  422. }
  423. Log::debug('Course color assigned', [
  424. 'course_name' => $courseName,
  425. 'assigned_color' => $color
  426. ]);
  427. return $color;
  428. }
  429. private function loadSavedNotes()
  430. {
  431. Log::info('Loading saved notes');
  432. try {
  433. // Load saved notes from session or database
  434. $this->savedNotes = session()->get('dashboard_notes', []);
  435. Log::info('Saved notes loaded', [
  436. 'notes_count' => count($this->savedNotes)
  437. ]);
  438. } catch (\Exception $e) {
  439. Log::error('Error loading saved notes', [
  440. 'error' => $e->getMessage()
  441. ]);
  442. $this->savedNotes = [];
  443. }
  444. }
  445. private function saveSavedNotes()
  446. {
  447. try {
  448. // Save notes to session (you can change this to save to database)
  449. session()->put('dashboard_notes', $this->savedNotes);
  450. Log::info('Notes saved to session', [
  451. 'notes_count' => count($this->savedNotes)
  452. ]);
  453. } catch (\Exception $e) {
  454. Log::error('Error saving notes', [
  455. 'error' => $e->getMessage()
  456. ]);
  457. }
  458. }
  459. public function saveNote()
  460. {
  461. Log::info('Save note called', ['note_text' => $this->notes]);
  462. try {
  463. if (trim($this->notes) !== '') {
  464. $newNote = [
  465. 'id' => uniqid(),
  466. 'text' => trim($this->notes),
  467. 'created_at' => now()->format('d/m/Y H:i'),
  468. 'completed' => false
  469. ];
  470. // Add note to the beginning of the array
  471. array_unshift($this->savedNotes, $newNote);
  472. // Save to session/database
  473. $this->saveSavedNotes();
  474. // Clear the input
  475. $this->notes = '';
  476. // Emit event for success message
  477. $this->dispatchBrowserEvent('note-saved');
  478. Log::info('Note saved successfully', [
  479. 'note_id' => $newNote['id'],
  480. 'total_notes' => count($this->savedNotes)
  481. ]);
  482. } else {
  483. Log::warning('Attempted to save empty note');
  484. }
  485. } catch (\Exception $e) {
  486. Log::error('Error saving note', [
  487. 'error' => $e->getMessage(),
  488. 'file' => $e->getFile(),
  489. 'line' => $e->getLine()
  490. ]);
  491. }
  492. }
  493. public function completeNote($noteId)
  494. {
  495. Log::info('Complete note called', ['note_id' => $noteId]);
  496. try {
  497. $initialCount = count($this->savedNotes);
  498. // Find and remove the note from savedNotes
  499. $this->savedNotes = array_filter($this->savedNotes, function($note) use ($noteId) {
  500. return $note['id'] !== $noteId;
  501. });
  502. // Reindex the array
  503. $this->savedNotes = array_values($this->savedNotes);
  504. $finalCount = count($this->savedNotes);
  505. if ($initialCount > $finalCount) {
  506. // Save to session/database
  507. $this->saveSavedNotes();
  508. // Emit event for success message
  509. $this->dispatchBrowserEvent('note-completed');
  510. Log::info('Note completed successfully', [
  511. 'note_id' => $noteId,
  512. 'remaining_notes' => $finalCount
  513. ]);
  514. } else {
  515. Log::warning('Note not found for completion', ['note_id' => $noteId]);
  516. }
  517. } catch (\Exception $e) {
  518. Log::error('Error completing note', [
  519. 'note_id' => $noteId,
  520. 'error' => $e->getMessage(),
  521. 'file' => $e->getFile(),
  522. 'line' => $e->getLine()
  523. ]);
  524. }
  525. }
  526. // Existing methods with logging
  527. public function addMember()
  528. {
  529. Log::info('Redirecting to add member');
  530. return redirect()->to('/members?new=1');
  531. }
  532. public function addSupplier()
  533. {
  534. Log::info('Redirecting to add supplier');
  535. return redirect()->to('/suppliers?new=1');
  536. }
  537. public function addIn()
  538. {
  539. Log::info('Redirecting to add income record');
  540. return redirect()->to('/in?new=1');
  541. }
  542. public function addOut()
  543. {
  544. Log::info('Redirecting to add expense record');
  545. return redirect()->to('/out?new=1');
  546. }
  547. // Existing methods (keeping original implementation)
  548. private function getLabels()
  549. {
  550. $labels = array();
  551. for($i = 6; $i >= 0; $i--) {
  552. $labels[] = date("d/M", strtotime('-' . $i . ' days'));
  553. }
  554. return $labels;
  555. }
  556. private function getRecordData($type)
  557. {
  558. $data = [];
  559. for($i = 6; $i >= 0; $i--) {
  560. $found = false;
  561. $records = $type == 'IN' ? $this->in : $this->out;
  562. foreach($records as $record) {
  563. if (date("Y-m-d", strtotime($record->date)) == date("Y-m-d", strtotime('-' . $i . ' days'))) {
  564. $data[] = $record->total;
  565. $found = true;
  566. break;
  567. }
  568. }
  569. if (!$found) {
  570. $data[] = 0;
  571. }
  572. }
  573. return $data;
  574. }
  575. private function getMemberData()
  576. {
  577. $data = [];
  578. for($i = 6; $i >= 0; $i--) {
  579. $found = false;
  580. foreach($this->members as $member) {
  581. if (date("Y-m-d", strtotime($member->created_at)) == date("Y-m-d", strtotime('-' . $i . ' days'))) {
  582. $data[] = $member->total;
  583. $found = true;
  584. break;
  585. }
  586. }
  587. if (!$found) {
  588. $data[] = 0;
  589. }
  590. }
  591. return $data;
  592. }
  593. }