From be9816fde21cdbdaa061d98b6333f27fb255d1a9 Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Thu, 13 Nov 2025 20:22:34 +0700 Subject: [PATCH] feat(overview): menambahkan card baru yaitu untuk belanja toko --- app/Livewire/Studio/Dashboard/Overview.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/Livewire/Studio/Dashboard/Overview.php b/app/Livewire/Studio/Dashboard/Overview.php index 9ba4fa0..8fc4ca2 100644 --- a/app/Livewire/Studio/Dashboard/Overview.php +++ b/app/Livewire/Studio/Dashboard/Overview.php @@ -6,6 +6,7 @@ use App\Models\Order; use App\Models\OrderItem; use App\Models\Perfume; +use App\Models\Purchase; use Illuminate\Support\Facades\DB; use Livewire\Attributes\Title; use Livewire\Component; @@ -85,6 +86,14 @@ protected function loadStats() ->yesterday() ->sum('amount'); + $todayPurchase = Purchase::when(! empty($outletIds), fn ($q) => $q->whereIn('outlet_id', $outletIds)) + ->today() + ->sum('total'); + + $yesterdayPurchase = Purchase::when(! empty($outletIds), fn ($q) => $q->whereIn('outlet_id', $outletIds)) + ->yesterday() + ->sum('total'); + $todayGrossProfit = $todayIncome - $todayCogs - $todayDiscount; $yesterdayGrossProfit = $yesterdayIncome - $yesterdayCogs - $yesterdayDiscount; @@ -179,7 +188,7 @@ protected function loadStats() 'trendUp' => $todayVoucher > $yesterdayVoucher, ], [ - 'title' => 'Pengeluaran', + 'title' => 'Beban Toko', 'value' => currency($todayExpense, 'Rp'), 'previous' => currency($yesterdayExpense, 'Rp'), 'trend' => $yesterdayExpense > 0 @@ -189,7 +198,16 @@ protected function loadStats() ], auth()->user()?->hasPermissionTo('view cogs') ? [ + 'title' => 'Belanja Barang', + 'value' => currency($todayPurchase, 'Rp'), + 'previous' => currency($yesterdayPurchase, 'Rp'), + 'trend' => $yesterdayPurchase > 0 + ? round((($todayPurchase - $yesterdayPurchase) / $yesterdayPurchase) * 100, 1).'%' + : '∞%', + 'trendUp' => $todayPurchase > $yesterdayPurchase, + ] : null, + auth()->user()?->hasPermissionTo('view cogs') ? [ 'title' => 'Laba Kotor', 'value' => currency($todayGrossProfit, 'Rp'), 'previous' => currency($yesterdayGrossProfit, 'Rp'),