fix:카드별 사용금액 프로그래스바 바로빌 실거래 데이터 반영

- summary API에 cardUsages(카드번호별 사용금액) 응답 추가
- 카드 목록 프로그래스바가 바로빌 거래 합산 기준으로 표시
- 체크카드도 사용금액 있으면 금액 표시

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
김보곤
2026-02-11 10:31:06 +09:00
parent d78d431350
commit 5cb92c0fd7
2 changed files with 60 additions and 27 deletions

View File

@@ -228,8 +228,8 @@ public function summary(): JsonResponse
// 카드번호 목록
$cardNumbers = $activeCards->pluck('card_number')->toArray();
// 사용금액 계산
$billingUsage = $this->calculateBillingUsage(
// 사용금액 계산 (전체 + 카드별)
$usageResult = $this->calculateBillingUsage(
$tenantId,
$billingStart->format('Y-m-d'),
$billingEnd->format('Y-m-d'),
@@ -251,7 +251,8 @@ public function summary(): JsonResponse
'start' => $billingStart->format('Y-m-d'),
'end' => $billingEnd->format('Y-m-d'),
],
'billingUsage' => $billingUsage,
'billingUsage' => $usageResult['total'],
'cardUsages' => $usageResult['perCard'],
'prepaidAmount' => (int) $prepayment->amount,
'prepaidMemo' => $prepayment->memo ?? '',
],
@@ -328,13 +329,13 @@ private function getAdjustedPaymentDate(int $tenantId, int $year, int $month, in
/**
* 청구기간 사용금액 계산 (바로빌 카드거래 합산)
*/
private function calculateBillingUsage(int $tenantId, string $startDate, string $endDate, array $cardNumbers): int
private function calculateBillingUsage(int $tenantId, string $startDate, string $endDate, array $cardNumbers): array
{
// 카드번호 정규화 (하이픈 제거)
// 카드번호 정규화 (하이픈 제거) + 원본↔정규화 매핑
$normalizedNums = array_map(fn($num) => str_replace('-', '', $num), $cardNumbers);
if (empty($normalizedNums)) {
return 0;
return ['total' => 0, 'perCard' => []];
}
// use_date는 YYYYMMDD 형식
@@ -351,18 +352,24 @@ private function calculateBillingUsage(int $tenantId, string $startDate, string
->get();
$total = 0;
$perCard = [];
foreach ($transactions as $tx) {
if ($hiddenKeys->contains($tx->unique_key)) {
continue;
}
$amount = 0;
if ($tx->approval_type === '1') {
$total += (int) $tx->approval_amount; // 승인
$amount = (int) $tx->approval_amount;
} elseif ($tx->approval_type === '2') {
$total -= (int) $tx->approval_amount; // 취소
$amount = -(int) $tx->approval_amount;
}
$total += $amount;
$cardNum = $tx->card_num;
$perCard[$cardNum] = ($perCard[$cardNum] ?? 0) + $amount;
}
return $total;
return ['total' => $total, 'perCard' => (object) $perCard];
}
}