fix:일일자금일보 중복 제거 키에서 balance 제외
- 같은 거래가 잔액만 다르게 저장된 경우도 중복으로 인식하도록 수정 - save() upsert에서도 balance 제외하여 향후 중복 방지 - 기존 레코드 발견 시 balance도 갱신 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -928,18 +928,18 @@ public function save(Request $request): JsonResponse
|
||||
];
|
||||
|
||||
// Upsert: 있으면 업데이트, 없으면 생성
|
||||
// 금액 비교 시 정수로 캐스트하여 decimal 정밀도 차이로 인한 중복 방지
|
||||
// balance 제외: 같은 거래가 잔액만 다르게 저장되는 중복 방지
|
||||
$existing = BankTransaction::where('tenant_id', $tenantId)
|
||||
->where('bank_account_num', $data['bank_account_num'])
|
||||
->where('trans_dt', $transDt)
|
||||
->whereRaw('CAST(deposit AS SIGNED) = ?', [(int) $data['deposit']])
|
||||
->whereRaw('CAST(withdraw AS SIGNED) = ?', [(int) $data['withdraw']])
|
||||
->whereRaw('CAST(balance AS SIGNED) = ?', [(int) $data['balance']])
|
||||
->first();
|
||||
|
||||
if ($existing) {
|
||||
// 계정과목만 업데이트
|
||||
// 계정과목 + 잔액 업데이트
|
||||
$existing->update([
|
||||
'balance' => $data['balance'],
|
||||
'account_code' => $data['account_code'],
|
||||
'account_name' => $data['account_name'],
|
||||
]);
|
||||
|
||||
@@ -180,7 +180,7 @@ public function periodReport(Request $request): JsonResponse
|
||||
->orderBy('trans_date', 'desc')
|
||||
->orderBy('trans_time', 'desc')
|
||||
->get()
|
||||
->unique(fn($tx) => $tx->bank_account_num . '|' . $tx->trans_dt . '|' . (int)$tx->deposit . '|' . (int)$tx->withdraw . '|' . (int)$tx->balance)
|
||||
->unique(fn($tx) => $tx->bank_account_num . '|' . $tx->trans_dt . '|' . (int)$tx->deposit . '|' . (int)$tx->withdraw)
|
||||
->values();
|
||||
|
||||
// 오버라이드 데이터 병합 (수정된 적요/내용)
|
||||
|
||||
Reference in New Issue
Block a user