From 0f40ca673aa29c8cf0b64ec0fca19eea0b3ea6de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=B3=B4=EA=B3=A4?= Date: Fri, 6 Feb 2026 11:20:12 +0900 Subject: [PATCH] =?UTF-8?q?fix:=EC=88=98=EB=8F=99=EC=9E=85=EB=A0=A5=20?= =?UTF-8?q?=EA=B1=B4=20=EC=9E=94=EC=95=A1=EC=9D=84=20=EC=A7=81=EC=A0=84=20?= =?UTF-8?q?=EA=B1=B0=EB=9E=98=20=EA=B8=B0=EC=A4=80=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=9E=90=EB=8F=99=20=EC=9E=AC=EA=B3=84=EC=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - recalcManualBalances() 메서드 추가: 병합된 로그를 시간순으로 순회하며 수동입력 건의 잔액을 직전 거래 잔액 + 입금 - 출금으로 재계산 - 단일 계좌/전체 계좌/수동건만 있는 경우 모두 적용 - API 거래의 잔액은 그대로 유지 Co-Authored-By: Claude Opus 4.6 --- .../Barobill/EaccountController.php | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Barobill/EaccountController.php b/app/Http/Controllers/Barobill/EaccountController.php index 7b99059a..2585eb88 100644 --- a/app/Http/Controllers/Barobill/EaccountController.php +++ b/app/Http/Controllers/Barobill/EaccountController.php @@ -365,10 +365,11 @@ public function transactions(Request $request): JsonResponse if ($errorCode && in_array($errorCode, [-25005, -25001])) { // API 데이터 없어도 수동 건은 표시 $manualLogs = $this->convertManualToLogs($manualTransactions); + $recalcLogs = $this->recalcManualBalances($manualLogs['logs']); return response()->json([ 'success' => true, 'data' => [ - 'logs' => $manualLogs['logs'], + 'logs' => $recalcLogs, 'summary' => $manualLogs['summary'], 'pagination' => ['currentPage' => 1, 'maxPageNum' => 1] ] @@ -389,6 +390,9 @@ public function transactions(Request $request): JsonResponse return strcmp($dtB, $dtA); }); + // 수동입력 건 잔액 재계산 (직전 거래 기준) + $mergedLogs = $this->recalcManualBalances($mergedLogs); + // summary 합산 $mergedSummary = [ 'totalDeposit' => $logs['summary']['totalDeposit'] + $manualLogs['summary']['totalDeposit'], @@ -495,6 +499,9 @@ private function getAllAccountsTransactions(string $userId, string $startDate, s return strcmp($dateB, $dateA); }); + // 수동입력 건 잔액 재계산 (직전 거래 기준) + $allLogs = $this->recalcManualBalances($allLogs); + // 페이지네이션 $totalCount = count($allLogs); $maxPageNum = (int)ceil($totalCount / $limit); @@ -1262,6 +1269,34 @@ public function destroyManual(int $id): JsonResponse } } + /** + * 병합된 로그에서 수동입력 건의 잔액을 직전 거래 기준으로 재계산 + * 로그는 날짜 내림차순(DESC) 정렬 상태로 전달됨 + */ + private function recalcManualBalances(array $logs): array + { + if (empty($logs)) return $logs; + + // 시간순(ASC)으로 뒤집어서 순차 처리 + $logs = array_reverse($logs); + + $prevBalance = null; + foreach ($logs as &$log) { + if (!empty($log['isManual'])) { + $deposit = (float) ($log['deposit'] ?? 0); + $withdraw = (float) ($log['withdraw'] ?? 0); + $newBalance = ($prevBalance !== null ? $prevBalance : 0) + $deposit - $withdraw; + $log['balance'] = $newBalance; + $log['balanceFormatted'] = number_format($newBalance); + } + $prevBalance = (float) ($log['balance'] ?? 0); + } + unset($log); + + // 다시 내림차순(DESC)으로 복원 + return array_reverse($logs); + } + /** * 수동 입력 건을 API 로그 형식으로 변환 */