DashboardController.php 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\Member;
  4. use App\Models\Mutation;
  5. use App\Models\TypeMember;
  6. use App\Models\TypeVehicle;
  7. use App\Models\User;
  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. $members = Member::get();
  22. $typeMembers = TypeMember::get();
  23. $typeVehicles = TypeVehicle::get();
  24. $users = User::get();
  25. $mutations = Mutation::whereYear('created_at', date('Y'))
  26. ->get()
  27. ->groupBy([
  28. fn($mutation) => $mutation->type,
  29. fn($mutation) => Carbon::parse($mutation->getRawOriginal('created_at'))->format('M')
  30. ]);
  31. return inertia('home/Index.vue', [
  32. 'cardStatistics' => [
  33. // [
  34. // 'title' => ...,
  35. // 'icon' => ...',
  36. // 'amount' => ...,
  37. // 'amountLabel' => ...,
  38. // 'value' => ...,
  39. // 'roleId' => [...,...]
  40. // ],
  41. [
  42. 'title' => __('words.member'),
  43. 'icon' => 'pi pi-id-card',
  44. 'amount' => $members->count(),
  45. 'amountLabel' => __('words.total'),
  46. 'roleId' => [3]
  47. ],
  48. [
  49. 'title' => __('words.type_member'),
  50. 'icon' => 'pi pi-id-card',
  51. 'amount' => $typeMembers->count(),
  52. 'amountLabel' => __('words.total'),
  53. 'roleId' => [2]
  54. ],
  55. [
  56. 'title' => __('words.type_vehicle'),
  57. 'icon' => 'pi pi-car',
  58. 'amount' => $typeVehicles->count(),
  59. 'amountLabel' => __('words.total'),
  60. 'roleId' => [3]
  61. ],
  62. [
  63. 'title' => __('words.user'),
  64. 'icon' => 'pi pi-user',
  65. 'amount' => $users->count(),
  66. 'amountLabel' => __('words.total'),
  67. 'roleId' => [1]
  68. ]
  69. ],
  70. 'barStatistics' => [
  71. // [
  72. // 'title' => ...,
  73. // 'description' => ...,
  74. // 'data' => ...,
  75. // 'roleId' => [..., ...],
  76. // ],
  77. [
  78. 'title' => __('words.mutation_statistic'),
  79. 'description' => __('words.per_year') . ' ' . date('Y'),
  80. 'data' => MutationService::statistic($mutations),
  81. 'roleId' => [2, 3]
  82. ]
  83. ]
  84. ]);
  85. }
  86. }