diff --git a/app/Services/PurchaseService.php b/app/Services/PurchaseService.php index 5918eb6..de0e9f9 100644 --- a/app/Services/PurchaseService.php +++ b/app/Services/PurchaseService.php @@ -311,9 +311,9 @@ public function bulkUpdateTaxReceived(array $ids, bool $taxInvoiceReceived): int * * @return array{ * summary: array{current_month_total: float, previous_month_total: float, change_rate: float, count: int}, - * monthly_trend: array, - * by_type: array, - * items: array + * monthly_trend: array, + * by_type: array, + * items: array * } */ public function dashboardDetail(): array @@ -360,7 +360,7 @@ public function dashboardDetail(): array ->sum('total_amount'); $monthlyTrend[] = [ - 'month' => $monthStart->format('Y-m'), + 'label' => $monthStart->format('n').'월', // "1월", "2월" 형식 'amount' => (float) $amount, ]; } @@ -376,13 +376,25 @@ public function dashboardDetail(): array $byType = []; $totalAmount = $byTypeRaw->sum('amount'); + // 유형별 색상 매핑 + $typeColors = [ + 'raw_material' => '#60A5FA', // 원자재 - 파랑 + 'sub_material' => '#34D399', // 부자재 - 초록 + 'packaging' => '#FBBF24', // 포장재 - 노랑 + 'consumable' => '#F87171', // 소모품 - 빨강 + 'unset' => '#9CA3AF', // 미설정 - 회색 + ]; + $colorIndex = 0; + $defaultColors = ['#60A5FA', '#34D399', '#FBBF24', '#F87171', '#A78BFA', '#F472B6']; + foreach ($byTypeRaw as $item) { $type = $item->purchase_type ?? 'unset'; $byType[] = [ 'type' => $type, - 'label' => Purchase::PURCHASE_TYPES[$type] ?? '미설정', + 'type_label' => Purchase::PURCHASE_TYPES[$type] ?? '미설정', 'amount' => (float) $item->amount, 'ratio' => $totalAmount > 0 ? round(($item->amount / $totalAmount) * 100, 1) : 0, + 'color' => $typeColors[$type] ?? $defaultColors[$colorIndex++ % count($defaultColors)], ]; } @@ -401,7 +413,7 @@ public function dashboardDetail(): array return [ 'id' => $purchase->id, - 'date' => $purchase->purchase_date->format('Y-m-d'), + 'purchase_date' => $purchase->purchase_date->format('Y-m-d'), 'vendor_name' => $purchase->client?->name ?? '-', 'amount' => (float) $purchase->total_amount, 'type' => $type, @@ -412,8 +424,8 @@ public function dashboardDetail(): array return [ 'summary' => [ - 'current_month_total' => (float) $currentMonthTotal, - 'previous_month_total' => (float) $previousMonthTotal, + 'current_month_amount' => (float) $currentMonthTotal, + 'previous_month_amount' => (float) $previousMonthTotal, 'change_rate' => $changeRate, 'count' => $currentMonthCount, ],