fix:부가세 카드매입 분개 이중계산 버그 수정

분개가 있는 카드거래의 unique_key가 금액 변경/수동입력으로
달라질 경우 매칭 실패하여 원본+분개 이중 집계되는 문제 수정.
금액을 제외한 부분키(card_num|use_dt|approval_num)로
보조 매칭하여 분개가 있으면 원본 금액을 사용하지 않도록 개선.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
김보곤
2026-02-09 15:05:39 +09:00
parent 625a6ccf69
commit 4c9daf3633

View File

@@ -98,13 +98,29 @@ public function index(Request $request): JsonResponse
$splitsByKey = CardTransactionSplit::getByDateRange($tenantId, $startDateYmd, $endDateYmd);
// 분개가 존재하는 거래의 부분키(금액 제외) 인덱스 생성
// 수동입력 등으로 금액이 달라져도 매칭되도록 함
$splitsByPartialKey = [];
foreach ($splitsByKey as $fullKey => $splits) {
$parts = explode('|', $fullKey);
if (count($parts) >= 3) {
$partialKey = $parts[0] . '|' . $parts[1] . '|' . $parts[2];
$splitsByPartialKey[$partialKey] = $splits;
}
}
foreach ($cardTransactions as $card) {
// 숨김 처리된 거래는 skip
if ($hiddenKeys->contains($card->unique_key)) {
continue;
}
// 분개 매칭: 정확한 키 → 부분키(금액 제외) 순으로 시도
$splits = $splitsByKey[$card->unique_key] ?? null;
if (!$splits) {
$cardPartialKey = $card->card_num . '|' . $card->use_dt . '|' . $card->approval_num;
$splits = $splitsByPartialKey[$cardPartialKey] ?? null;
}
if ($splits && count($splits) > 0) {
// 분개가 있으면: deductible 분개만 포함