DashboardController.php 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\Expense;
  4. use App\Models\Laundry;
  5. use App\Models\Product;
  6. use App\Models\Transaction;
  7. use App\Services\ExpenseService;
  8. use App\Services\TransactionService;
  9. use Illuminate\Http\Request;
  10. use Inertia\Inertia;
  11. class DashboardController extends Controller
  12. {
  13. /**
  14. * Handle the incoming request.
  15. *
  16. * @param \Illuminate\Http\Request $request
  17. * @return \Inertia\Response
  18. */
  19. public function __invoke(Request $request)
  20. {
  21. $transactions = Transaction::filter(['startDate' => today()])->get();
  22. $expenses = Expense::filter(['startDate' => today()])->get();
  23. $laundries = Laundry::get();
  24. $products = Product::get();
  25. return inertia('home/Index', [
  26. 'cardStatistics' => [
  27. [
  28. 'label' => __('words.transaction'),
  29. 'icon' => 'pi pi-shopping-cart',
  30. 'amount' => $transactions->count(),
  31. 'amountLabel' => __('words.today'),
  32. 'value' => (new TransactionService)->totalPriceGroupAsString($transactions),
  33. ],
  34. [
  35. 'label' => __('words.expense'),
  36. 'icon' => 'pi pi-wallet',
  37. 'amount' => $expenses->count(),
  38. 'amountLabel' => __('words.today'),
  39. 'value' => (new ExpenseService)->totalPriceAsString($expenses),
  40. ],
  41. [
  42. 'label' => __('words.laundry_type'),
  43. 'icon' => 'pi pi-table',
  44. 'amountLabel' => __('words.total'),
  45. 'amount' => $laundries->count(),
  46. ],
  47. [
  48. 'label' => __('words.product_type'),
  49. 'icon' => 'pi pi-table',
  50. 'amountLabel' => __('words.total'),
  51. 'amount' => $products->count(),
  52. ],
  53. ],
  54. 'chartStatistics' => [
  55. [
  56. 'label' => __('words.transaction_statistic'),
  57. 'data' => $transactions->groupBy([])
  58. ],
  59. ],
  60. ]);
  61. }
  62. }