feat: enhance dashboard with marketplace summary and additional product statistics for improved analytics
This commit is contained in:
parent
ad73e8237c
commit
4a13297cb7
@ -50,6 +50,7 @@ public function index(): Response
|
||||
'cuttingByStatus' => $this->getCuttingByStatus(),
|
||||
'orderStats' => $this->getOrderStats(),
|
||||
'revenueSummary' => $this->getRevenueSummary(),
|
||||
'marketplaceSummary' => $this->getMarketplaceSummary(),
|
||||
'cashAccounts' => $this->getCashAccounts(),
|
||||
'monthlyCashFlow' => $this->getMonthlyCashFlow(),
|
||||
'monthlyExpenses' => $this->getMonthlyExpenses($startOfMonth, $endOfMonth),
|
||||
@ -89,7 +90,7 @@ private function getRawMaterialStock(): array
|
||||
private function getProductStock(): array
|
||||
{
|
||||
$data = ProductVariant::query()
|
||||
->selectRaw('SUM(stock) as total_stock, SUM(reject_stock) as total_reject')
|
||||
->selectRaw('SUM(stock) as total_stock, SUM(reject_stock) as total_reject, COUNT(*) as total_variants')
|
||||
->first();
|
||||
|
||||
$totalStock = (int) ($data->total_stock ?? 0);
|
||||
@ -100,10 +101,16 @@ private function getProductStock(): array
|
||||
->selectRaw('SUM(cutting_results.warehouse_stock * cuttings.cost_per_unit) as total_value')
|
||||
->value('total_value');
|
||||
|
||||
$totalProducts = \App\Models\Product::query()->count();
|
||||
$totalCategories = \App\Models\Category::query()->count();
|
||||
|
||||
return [
|
||||
'total_stock' => $totalStock,
|
||||
'total_reject' => (int) ($data->total_reject ?? 0),
|
||||
'total_value' => (int) ($totalValue ?? 0),
|
||||
'total_variants' => (int) ($data->total_variants ?? 0),
|
||||
'total_products' => $totalProducts,
|
||||
'total_categories' => $totalCategories,
|
||||
];
|
||||
}
|
||||
|
||||
@ -306,15 +313,44 @@ private function getRevenueSummary(): array
|
||||
->selectRaw('SUM(total_amount) as total_revenue, SUM(discount) as total_discount, SUM(shipping_cost) as total_shipping, COUNT(*) as total_orders, AVG(total_amount) as avg_order')
|
||||
->first();
|
||||
|
||||
$totalMarketplaceFees = Order::query()
|
||||
->where('status', OrderStatus::COMPLETED)
|
||||
->whereNotNull('marketplace_settings_snapshot')
|
||||
->get()
|
||||
->sum(fn ($order) => (int) ($order->marketplace_settings_snapshot['total_fee_amount'] ?? 0));
|
||||
|
||||
return [
|
||||
'total_revenue' => (int) ($data->total_revenue ?? 0),
|
||||
'total_discount' => (int) ($data->total_discount ?? 0),
|
||||
'total_marketplace_fees' => $totalMarketplaceFees,
|
||||
'total_potongan' => (int) ($data->total_discount ?? 0) + $totalMarketplaceFees,
|
||||
'total_shipping' => (int) ($data->total_shipping ?? 0),
|
||||
'total_orders' => (int) ($data->total_orders ?? 0),
|
||||
'avg_order' => (int) ($data->avg_order ?? 0),
|
||||
];
|
||||
}
|
||||
|
||||
private function getMarketplaceSummary(): array
|
||||
{
|
||||
$marketplaceOrders = Order::query()
|
||||
->where('status', OrderStatus::COMPLETED)
|
||||
->whereIn('channel', [OrderChannel::SHOPEE, OrderChannel::TIKTOK])
|
||||
->whereNotNull('marketplace_settings_snapshot')
|
||||
->get();
|
||||
|
||||
$totalRevenue = $marketplaceOrders->sum('total_amount');
|
||||
$totalFees = $marketplaceOrders->sum(fn ($order) => (int) ($order->marketplace_settings_snapshot['total_fee_amount'] ?? 0));
|
||||
$totalNet = $marketplaceOrders->sum(fn ($order) => (int) ($order->marketplace_settings_snapshot['net_amount'] ?? 0));
|
||||
$totalOrders = $marketplaceOrders->count();
|
||||
|
||||
return [
|
||||
'total_revenue' => (int) $totalRevenue,
|
||||
'total_fees' => (int) $totalFees,
|
||||
'total_net' => (int) $totalNet,
|
||||
'total_orders' => (int) $totalOrders,
|
||||
];
|
||||
}
|
||||
|
||||
private function getCashAccounts(): array
|
||||
{
|
||||
return CashAccount::query()
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user