get(); $expenses = Expense::whereDate('created_at', date('Y-m-d'))->get(); $laundries = Laundry::get(); $products = Product::get(); $transactionDiscount = Transaction::whereMonth('created_at', date('m'))->whereNotIn('discount', [0])->get(); $transactionChart = Transaction::get() ->groupBy([ fn($transaction) => Carbon::parse($transaction->getRawOriginal('created_at'))->format('Y'), fn($transaction) => Carbon::parse($transaction->getRawOriginal('created_at'))->format('M'), ]); $mutationChart = Mutation::whereYear('created_at', date('Y')) ->get() ->groupBy([ fn($mutation) => $mutation->type, fn($mutation) => Carbon::parse($mutation->getRawOriginal('created_at'))->format('M'), ]); $transactionOutletChart = Transaction::whereYear('created_at', date('Y')) ->whereMonth('created_at', date('m')) ->get() ->groupBy([ fn($transaction) => Carbon::parse($transaction->getRawOriginal('created_at'))->format('M'), fn($transaction) => $transaction->outlet->name, ]); $topTransactionChart = Transaction::get() ->groupBy('customer_number'); return inertia('home/Index', [ 'cardStatistics' => [ [ 'title' => __('words.transaction'), 'icon' => 'pi pi-shopping-cart', 'amount' => $transactions->count(), 'amountLabel' => __('words.today'), 'value' => (new TransactionService)->totalPriceGroupAsString($transactions), ], [ 'title' => __('words.expense'), 'icon' => 'pi pi-wallet', 'amount' => $expenses->count(), 'amountLabel' => __('words.today'), 'value' => (new ExpenseService)->totalPriceAsString($expenses), ], [ 'title' => __('words.discount_given'), 'icon' => 'pi pi-percentage', 'amount' => $transactionDiscount->count(), 'amountLabel' => __('words.this_month'), 'value' => (new TransactionService)->totalDiscountGivenGroupAsString($transactionDiscount), ], [ 'title' => __('words.laundry_type'), 'icon' => 'pi pi-table', 'amount' => $laundries->count(), 'amountLabel' => __('words.total'), ], [ 'title' => __('words.product_type'), 'icon' => 'pi pi-table', 'amount' => $products->count(), 'amountLabel' => __('words.total'), ], ], 'chartTransactionStatistics' => [ 'transaction' => [ 'title' => __('words.transaction_statistic'), 'description' => __('words.per_year') . ' ' . now()->subYear(1)->format('Y') . '-' . date('Y'), 'data' => (new TransactionService)->statisticData($transactionChart, -2), ], 'transactionMutation' => [ 'title' => __('words.mutation_statistic'), 'description' => __('words.per_year') . ' ' . date('Y'), 'data' => (new MutationService)->statisticData($mutationChart, -2), ], ], 'chartOutletStatistic' => [ 'title' => __('words.transaction_outlet_statistic'), 'description' => Carbon::parse(date('Y-m-d'))->translatedFormat('F, Y'), 'data' => (new TransactionService)->statisticData($transactionOutletChart)->first(), ], 'chartTopTransactionStatistic' => [ 'title' => __('words.top_customer'), 'description' => __('words.top_number_customer', ['number' => 5]), 'data' => (new TransactionService)->topTransaction($topTransactionChart), ], ]); } }