From fabf302e1f645b89a6be13edc3b707adf8db589f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B6=8C=ED=98=81=EC=84=B1?= Date: Fri, 23 Jan 2026 09:08:37 +0900 Subject: [PATCH] =?UTF-8?q?fix(API):=20=EB=8B=B9=EC=9B=94=20=EB=A7=A4?= =?UTF-8?q?=EC=9E=85=20=EC=83=81=EC=84=B8=20API=20=EC=9D=91=EB=8B=B5=20?= =?UTF-8?q?=ED=95=84=EB=93=9C=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - summary.current_month_total → current_month_amount 변경 - summary.previous_month_total → previous_month_amount 변경 - monthly_trend[].month → label 변경 ("2025-07" → "7월") - by_type[].label → type_label 변경 - by_type[].color 필드 추가 (차트 색상) - items[].date → purchase_date 변경 프론트엔드 transformer와 API 응답 구조 일치 Co-Authored-By: Claude --- app/Services/PurchaseService.php | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) 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, ],