feat(overview): menambahkan card baru yaitu untuk belanja toko
This commit is contained in:
parent
fac455e7f1
commit
be9816fde2
@ -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'),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user