fix: [finance] 분리 카드거래 분개 매칭 누락 수정

- 분리 거래 source_key(uniqueKey|split:N) 패턴 매칭 추가
- 일반전표입력: 복수 분리 분개를 합산하여 1행으로 표시
- 계정별원장: 분리 키도 원본 카드 데이터로 매핑
This commit is contained in:
김보곤
2026-03-19 22:27:39 +09:00
parent 96e5435dc1
commit 140894ef9c
3 changed files with 98 additions and 15 deletions

View File

@@ -168,14 +168,18 @@ private function fetchCardTransactions(int $tenantId, Collection $lines): array
return [];
}
// source_key = "card_num|use_dt|approval_num|approval_amount"
// source_key = "card_num|use_dt|approval_num|approval_amount" 또는 "...|split:N"
$conditions = [];
$keyMap = []; // 원본 source_key → 파싱된 4-part key 매핑 (분리 키 포함)
foreach ($sourceKeys as $key) {
$parts = explode('|', $key);
$baseKey = explode('|split:', $key)[0];
$parts = explode('|', $baseKey);
if (count($parts) === 4) {
$conditions[] = $parts;
$conditions[$baseKey] = $parts;
$keyMap[$key] = $baseKey;
}
}
$conditions = array_values($conditions);
if (empty($conditions)) {
return [];
@@ -213,7 +217,7 @@ private function fetchCardTransactions(int $tenantId, Collection $lines): array
? (int) $tx->modified_tax
: (int) $tx->tax;
$map[$uniqueKey] = [
$txData = [
'card_num' => $tx->card_num,
'card_company_name' => $tx->card_company_name,
'merchant_name' => $tx->merchant_name,
@@ -223,6 +227,14 @@ private function fetchCardTransactions(int $tenantId, Collection $lines): array
'tax_amount' => $taxAmount,
'approval_amount' => (int) $tx->approval_amount,
];
$map[$uniqueKey] = $txData;
}
// 분리 키(uniqueKey|split:N)도 원본 카드 데이터로 매핑
foreach ($keyMap as $sourceKey => $baseKey) {
if ($sourceKey !== $baseKey && isset($map[$baseKey])) {
$map[$sourceKey] = $map[$baseKey];
}
}
return $map;