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"