From f6f3c4bc45d9da8efb292834fa7333c93faaefbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=B3=B4=EA=B3=A4?= Date: Wed, 4 Feb 2026 19:27:36 +0900 Subject: [PATCH] =?UTF-8?q?fix:=EC=B9=B4=EB=93=9C=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EB=82=B4=EC=97=AD=20=EA=B3=B5=EC=A0=9C/=EB=B6=88=EA=B3=B5?= =?UTF-8?q?=EC=A0=9C=20=ED=86=B5=EA=B3=84=EB=A5=BC=20=EC=A0=84=EC=B2=B4=20?= =?UTF-8?q?=ED=8E=98=EC=9D=B4=EC=A7=80=20=EA=B8=B0=EC=A4=80=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EA=B3=84=EC=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 백엔드에서 페이지네이션 전 전체 데이터로 공제/불공제/부가세 통계 산출 - parseTransactionLogs에 deductibleAmount/Count, nonDeductibleAmount/Count, totalTax 추가 - getAllCardsTransactions summary에 공제/불공제 통계 포함 - 프론트엔드에서 logs 기반 계산 제거, summary 데이터 사용 Co-Authored-By: Claude Opus 4.5 --- .../Controllers/Barobill/EcardController.php | 51 ++++++++++++++++++- .../views/barobill/ecard/index.blade.php | 24 ++------- 2 files changed, 54 insertions(+), 21 deletions(-) diff --git a/app/Http/Controllers/Barobill/EcardController.php b/app/Http/Controllers/Barobill/EcardController.php index e0c471e6..1a410f5f 100644 --- a/app/Http/Controllers/Barobill/EcardController.php +++ b/app/Http/Controllers/Barobill/EcardController.php @@ -427,6 +427,7 @@ private function getAllCardsTransactions(string $userId, string $startDate, stri $totalAmount = 0; $approvalCount = 0; $cancelCount = 0; + $totalTax = 0; foreach ($cardList as $card) { if (!is_object($card)) continue; @@ -484,6 +485,7 @@ private function getAllCardsTransactions(string $userId, string $startDate, stri $totalAmount += $parsed['summary']['totalAmount']; $approvalCount += $parsed['summary']['approvalCount']; $cancelCount += $parsed['summary']['cancelCount']; + $totalTax += $parsed['summary']['totalTax'] ?? 0; } } } @@ -493,6 +495,24 @@ private function getAllCardsTransactions(string $userId, string $startDate, stri return strcmp($b['useDt'] ?? '', $a['useDt'] ?? ''); }); + // 전체 데이터에서 공제/불공제 통계 계산 + $deductibleAmount = 0; + $deductibleCount = 0; + $nonDeductibleAmount = 0; + $nonDeductibleCount = 0; + + foreach ($allLogs as $log) { + $type = $log['deductionType'] ?? 'non_deductible'; + $amount = abs($log['approvalAmount'] ?? 0); + if ($type === 'deductible') { + $deductibleAmount += $amount; + $deductibleCount++; + } else { + $nonDeductibleAmount += $amount; + $nonDeductibleCount++; + } + } + // 페이지네이션 $totalCount = count($allLogs); $maxPageNum = (int)ceil($totalCount / $limit); @@ -513,7 +533,12 @@ private function getAllCardsTransactions(string $userId, string $startDate, stri 'totalAmount' => $totalAmount, 'count' => $totalCount, 'approvalCount' => $approvalCount, - 'cancelCount' => $cancelCount + 'cancelCount' => $cancelCount, + 'totalTax' => $totalTax, + 'deductibleAmount' => $deductibleAmount, + 'deductibleCount' => $deductibleCount, + 'nonDeductibleAmount' => $nonDeductibleAmount, + 'nonDeductibleCount' => $nonDeductibleCount, ] ] ]); @@ -528,6 +553,11 @@ private function parseTransactionLogs($resultData, $savedData = null): array $totalAmount = 0; $approvalCount = 0; $cancelCount = 0; + $totalTax = 0; + $deductibleAmount = 0; + $deductibleCount = 0; + $nonDeductibleAmount = 0; + $nonDeductibleCount = 0; $rawLogs = []; if (isset($resultData->CardLogList) && isset($resultData->CardLogList->CardApprovalLog)) { @@ -626,6 +656,18 @@ private function parseTransactionLogs($resultData, $savedData = null): array 'isSaved' => $savedItem !== null, ]; + // 공제/불공제 통계 집계 + $deductionType = $logItem['deductionType']; + $absAmount = abs($amount); + $totalTax += abs(floatval($log->Tax ?? 0)); + if ($deductionType === 'deductible') { + $deductibleAmount += $absAmount; + $deductibleCount++; + } else { + $nonDeductibleAmount += $absAmount; + $nonDeductibleCount++; + } + $logs[] = $logItem; } @@ -635,7 +677,12 @@ private function parseTransactionLogs($resultData, $savedData = null): array 'totalAmount' => $totalAmount, 'count' => count($logs), 'approvalCount' => $approvalCount, - 'cancelCount' => $cancelCount + 'cancelCount' => $cancelCount, + 'totalTax' => $totalTax, + 'deductibleAmount' => $deductibleAmount, + 'deductibleCount' => $deductibleCount, + 'nonDeductibleAmount' => $nonDeductibleAmount, + 'nonDeductibleCount' => $nonDeductibleCount, ] ]; } diff --git a/resources/views/barobill/ecard/index.blade.php b/resources/views/barobill/ecard/index.blade.php index 2ed0839d..8af81bb9 100644 --- a/resources/views/barobill/ecard/index.blade.php +++ b/resources/views/barobill/ecard/index.blade.php @@ -1244,20 +1244,6 @@ className="text-xs text-amber-600 hover:text-amber-700 underline" const formatCurrency = (val) => new Intl.NumberFormat('ko-KR').format(val || 0) + '원'; - // 공제/불공 통계 계산 - const deductionStats = logs.reduce((acc, log) => { - const type = log.deductionType || (log.merchantBizNum ? 'deductible' : 'non_deductible'); - const amount = Math.abs(log.approvalAmount || 0); - if (type === 'deductible') { - acc.deductibleAmount += amount; - acc.deductibleCount += 1; - } else { - acc.nonDeductibleAmount += amount; - acc.nonDeductibleCount += 1; - } - return acc; - }, { deductibleAmount: 0, deductibleCount: 0, nonDeductibleAmount: 0, nonDeductibleCount: 0 }); - return (
{/* Page Header */} @@ -1296,21 +1282,21 @@ className="text-xs text-amber-600 hover:text-amber-700 underline" /> } color="green" /> } color="red" /> sum + Math.abs(log.tax || 0), 0))} + value={formatCurrency(summary.totalTax)} subtext="조회기간 합계" icon={} color="stone"