DashboardController.php 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 App\Services\TopUpService;
  10. use Carbon\Carbon;
  11. use Illuminate\Http\Request;
  12. class DashboardController extends Controller
  13. {
  14. /**
  15. * Handle the incoming request.
  16. *
  17. * @param \Illuminate\Http\Request $request
  18. * @return \Illuminate\Http\Response
  19. */
  20. public function __invoke(Request $request)
  21. {
  22. $member = Member::get();
  23. $typeMember = TypeMember::get();
  24. $typeVehicle = TypeVehicle::get();
  25. $mutation = 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. $topUp = TopUp::get()->groupBy('member_id');
  32. return inertia('home/Index.vue', [
  33. 'cardStatistics' => [
  34. // [
  35. // 'title' => ...,
  36. // 'icon' => ...',
  37. // 'amount' => ...,
  38. // 'amountLabel' => ...,
  39. // 'value' => ...,
  40. // ],
  41. [
  42. 'title' => __('words.member'),
  43. 'icon' => 'pi pi-id-card',
  44. 'amount' => $member->count(),
  45. 'amountLabel' => __('words.total'),
  46. ],
  47. [
  48. 'title' => __('words.type_member'),
  49. 'icon' => 'pi pi-id-card',
  50. 'amount' => $typeMember->count(),
  51. 'amountLabel' => __('words.total'),
  52. ],
  53. [
  54. 'title' => __('words.type_vehicle'),
  55. 'icon' => 'pi pi-car',
  56. 'amount' => $typeVehicle->count(),
  57. 'amountLabel' => __('words.total'),
  58. ],
  59. ],
  60. 'barStatistics' => [
  61. [
  62. 'title' => __('words.mutation_statistic'),
  63. 'description' => __('words.per_year') . ' ' . date('Y'),
  64. 'data' => (new MutationService)->statistic($mutation),
  65. ],
  66. ],
  67. 'barHorizontalStatistics' => [
  68. [
  69. 'title' => __('words.top_up_rank'),
  70. 'description' => __('words.top_up_number_rank', ['number' => 5]),
  71. 'data' => (new TopUpService)->topUpRank($topUp),
  72. ],
  73. ],
  74. ]);
  75. }
  76. }