DashboardController.php 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\Member;
  4. use App\Models\Mutation;
  5. use App\Models\TopUp;
  6. use App\Models\TypeMember;
  7. use App\Models\TypeVehicle;
  8. use App\Services\MutationService;
  9. use Carbon\Carbon;
  10. use Illuminate\Http\Request;
  11. class DashboardController extends Controller
  12. {
  13. /**
  14. * Handle the incoming request.
  15. *
  16. * @param \Illuminate\Http\Request $request
  17. * @return \Illuminate\Http\Response
  18. */
  19. public function __invoke(Request $request)
  20. {
  21. $member = Member::get();
  22. $typeMember = TypeMember::get();
  23. $typeVehicle = TypeVehicle::get();
  24. $mutation = Mutation::whereYear('created_at', date('Y'))
  25. ->get()
  26. ->groupBy([
  27. fn($mutation) => $mutation->type,
  28. fn($mutation) => Carbon::parse($mutation->getRawOriginal('created_at'))->format('M'),
  29. ]);
  30. $topUp = TopUp::get()->groupBy('member_id');
  31. return inertia('home/Index.vue', [
  32. 'cardStatistics' => [
  33. // [
  34. // 'title' => ...,
  35. // 'icon' => ...',
  36. // 'amount' => ...,
  37. // 'amountLabel' => ...,
  38. // 'value' => ...,
  39. // ],
  40. [
  41. 'title' => __('words.member'),
  42. 'icon' => 'pi pi-id-card',
  43. 'amount' => $member->count(),
  44. 'amountLabel' => __('words.total'),
  45. ],
  46. [
  47. 'title' => __('words.type_member'),
  48. 'icon' => 'pi pi-id-card',
  49. 'amount' => $typeMember->count(),
  50. 'amountLabel' => __('words.total'),
  51. ],
  52. [
  53. 'title' => __('words.type_vehicle'),
  54. 'icon' => 'pi pi-car',
  55. 'amount' => $typeVehicle->count(),
  56. 'amountLabel' => __('words.total'),
  57. ],
  58. ],
  59. 'barStatistics' => [
  60. [
  61. 'title' => __('words.mutation_statistic'),
  62. 'description' => __('words.per_year') . ' ' . date('Y'),
  63. 'data' => (new MutationService)->statistic($mutation),
  64. ],
  65. ],
  66. ]);
  67. }
  68. }