fix(API): 당월 매입 상세 API 응답 필드명 수정

- 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 <noreply@anthropic.com>
This commit is contained in:
2026-01-23 09:08:37 +09:00
parent 871db32e04
commit fabf302e1f

View File

@@ -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<array{month: string, amount: float}>,
* by_type: array<array{type: string, label: string, amount: float, ratio: float}>,
* items: array<array{id: int, date: string, vendor_name: string, amount: float, type: string, type_label: string}>
* monthly_trend: array<array{label: string, amount: float}>,
* by_type: array<array{type: string, type_label: string, amount: float, ratio: float, color: string}>,
* items: array<array{id: int, purchase_date: string, vendor_name: string, amount: float, type: string, type_label: string}>
* }
*/
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,
],