diff --git a/app/Http/Controllers/Barobill/EcardController.php b/app/Http/Controllers/Barobill/EcardController.php index b4915ca5..7d064b74 100644 --- a/app/Http/Controllers/Barobill/EcardController.php +++ b/app/Http/Controllers/Barobill/EcardController.php @@ -1934,11 +1934,6 @@ public function storeJournal(Request $request): JsonResponse ]); } - // 동일 uniqueKey의 구버전 splits 자동 삭제 - CardTransactionSplit::where('tenant_id', $tenantId) - ->where('original_unique_key', $request->source_key) - ->delete(); - return $entry; }); diff --git a/resources/views/barobill/ecard/index.blade.php b/resources/views/barobill/ecard/index.blade.php index 85ffeca1..395cc2a6 100644 --- a/resources/views/barobill/ecard/index.blade.php +++ b/resources/views/barobill/ecard/index.blade.php @@ -703,6 +703,58 @@ className={`px-3 py-1.5 text-sm cursor-pointer ${index === highlightIndex ? 'bg- // 기본 분개 라인 const getDefaultLines = () => { + // splits 데이터가 있으면 분리 항목 기반으로 라인 생성 + const splits = log._splits || []; + if (splits.length > 0) { + const debitLines = []; + let totalDebitSum = 0; + + splits.forEach(split => { + const splitSupply = Math.round(parseFloat(split.split_supply_amount ?? split.supplyAmount ?? split.split_amount ?? split.amount ?? 0)); + const splitTax = Math.round(parseFloat(split.split_tax ?? split.tax ?? 0)); + const splitDeductionType = split.deduction_type || split.deductionType || 'non_deductible'; + const splitAccountCode = split.account_code || split.accountCode || '826'; + const splitAccountName = split.account_name || split.accountName || '잡비'; + + if (splitDeductionType === 'deductible') { + // 공제: 비용 계정 = 공급가액, 부가세대급금 = 세액 + debitLines.push({ + dc_type: 'debit', account_code: splitAccountCode, account_name: splitAccountName, + debit_amount: splitSupply, credit_amount: 0, + trading_partner_id: null, trading_partner_name: '', description: split.memo || '' + }); + totalDebitSum += splitSupply; + if (splitTax > 0) { + debitLines.push({ + dc_type: 'debit', account_code: '135', account_name: '부가세대급금', + debit_amount: splitTax, credit_amount: 0, + trading_partner_id: null, trading_partner_name: '', description: '' + }); + totalDebitSum += splitTax; + } + } else { + // 불공제: 비용 계정 = 공급가액 + 세액 + const combined = splitSupply + splitTax; + debitLines.push({ + dc_type: 'debit', account_code: splitAccountCode, account_name: splitAccountName, + debit_amount: combined, credit_amount: 0, + trading_partner_id: null, trading_partner_name: '', description: split.memo || '' + }); + totalDebitSum += combined; + } + }); + + // 대변: 미지급비용 = 전체 합계 + debitLines.push({ + dc_type: 'credit', account_code: '205', account_name: '미지급비용', + debit_amount: 0, credit_amount: totalDebitSum, + trading_partner_id: null, trading_partner_name: '', description: '' + }); + + return debitLines; + } + + // splits가 없으면 기존 로직 (원본 금액 기반) const expenseCode = log.accountCode || '826'; const expenseName = log.accountName || '잡비'; @@ -863,6 +915,16 @@ className={`px-3 py-1.5 text-sm cursor-pointer ${index === highlightIndex ? 'bg-
공급가액: {formatCurrency(supplyAmount)}
세액: {formatCurrency(taxAmount)}
+ {(log._splits || []).length > 0 && ( +
+ + 분리 데이터 기반 ({log._splits.length}건) + + {isEditMode && ( + 저장된 분개가 있어 참고용으로 표시됩니다 + )} +
+ )} {loadingJournal ? ( @@ -1515,7 +1577,7 @@ className="p-1.5 text-amber-500 hover:bg-amber-100 rounded-lg transition-colors" if (jInfo) { return (