fix:카드 사용내역 공제/불공제 통계를 전체 페이지 기준으로 계산
- 백엔드에서 페이지네이션 전 전체 데이터로 공제/불공제/부가세 통계 산출 - parseTransactionLogs에 deductibleAmount/Count, nonDeductibleAmount/Count, totalTax 추가 - getAllCardsTransactions summary에 공제/불공제 통계 포함 - 프론트엔드에서 logs 기반 계산 제거, summary 데이터 사용 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user