From 33ad29ea018b2b57f6ce6496e68bf0eb339a765c 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 08:45:11 +0900 Subject: [PATCH] =?UTF-8?q?feat:=EC=9D=BC=EC=9D=BC=EC=9E=90=EA=B8=88?= =?UTF-8?q?=EC=9D=BC=EB=B3=B4=20=EA=B8=B0=EA=B0=84=EB=B3=84=20=EB=B3=B4?= =?UTF-8?q?=EA=B3=A0=EC=84=9C=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?(=EB=B0=94=EB=A1=9C=EB=B9=8C=20=EA=B3=84=EC=A2=8C=EB=82=B4?= =?UTF-8?q?=EC=97=AD=20=EA=B8=B0=EB=B0=98)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Finance/DailyFundController.php | 114 +++ resources/views/finance/daily-fund.blade.php | 690 ++++++------------ routes/web.php | 1 + 3 files changed, 335 insertions(+), 470 deletions(-) diff --git a/app/Http/Controllers/Finance/DailyFundController.php b/app/Http/Controllers/Finance/DailyFundController.php index e6c47e53..aaad7b27 100644 --- a/app/Http/Controllers/Finance/DailyFundController.php +++ b/app/Http/Controllers/Finance/DailyFundController.php @@ -5,8 +5,10 @@ use App\Http\Controllers\Controller; use App\Models\Finance\DailyFundTransaction; use App\Models\Finance\DailyFundMemo; +use App\Models\Barobill\BankTransaction as BarobillBankTransaction; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use Illuminate\Support\Facades\DB; class DailyFundController extends Controller { @@ -157,4 +159,116 @@ public function saveMemo(Request $request): JsonResponse ], ]); } + + /** + * 기간별 자금일보 (바로빌 계좌 거래내역 기반) + */ + public function periodReport(Request $request): JsonResponse + { + $tenantId = session('selected_tenant_id', 1); + $startDate = $request->input('start_date', now()->subMonth()->format('Ymd')); + $endDate = $request->input('end_date', now()->format('Ymd')); + + // YYYYMMDD 형식으로 변환 + $startDateYmd = str_replace('-', '', $startDate); + $endDateYmd = str_replace('-', '', $endDate); + + // 기간 내 거래내역 조회 + $transactions = BarobillBankTransaction::where('tenant_id', $tenantId) + ->whereBetween('trans_date', [$startDateYmd, $endDateYmd]) + ->orderBy('trans_date', 'desc') + ->orderBy('trans_time', 'desc') + ->get(); + + // 일별로 그룹핑 + $dailyData = []; + $accountBalances = []; // 계좌별 최신 잔액 추적 + + foreach ($transactions as $tx) { + $date = $tx->trans_date; + $accountNum = $tx->bank_account_num; + + if (!isset($dailyData[$date])) { + $dailyData[$date] = [ + 'date' => $date, + 'dateFormatted' => $this->formatDateKorean($date), + 'accounts' => [], + 'deposits' => [], + 'withdrawals' => [], + 'totalDeposit' => 0, + 'totalWithdraw' => 0, + ]; + } + + // 계좌별 데이터 집계 + if (!isset($dailyData[$date]['accounts'][$accountNum])) { + $dailyData[$date]['accounts'][$accountNum] = [ + 'bankName' => $tx->bank_name, + 'accountNum' => $accountNum, + 'deposit' => 0, + 'withdraw' => 0, + 'balance' => $tx->balance, + ]; + } + + // 입출금 내역 추가 + if ($tx->deposit > 0) { + $dailyData[$date]['deposits'][] = [ + 'time' => $tx->trans_time, + 'bankName' => $tx->bank_name, + 'summary' => $tx->summary, + 'cast' => $tx->cast, + 'amount' => $tx->deposit, + 'balance' => $tx->balance, + ]; + $dailyData[$date]['accounts'][$accountNum]['deposit'] += $tx->deposit; + $dailyData[$date]['totalDeposit'] += $tx->deposit; + } + + if ($tx->withdraw > 0) { + $dailyData[$date]['withdrawals'][] = [ + 'time' => $tx->trans_time, + 'bankName' => $tx->bank_name, + 'summary' => $tx->summary, + 'cast' => $tx->cast, + 'amount' => $tx->withdraw, + 'balance' => $tx->balance, + ]; + $dailyData[$date]['accounts'][$accountNum]['withdraw'] += $tx->withdraw; + $dailyData[$date]['totalWithdraw'] += $tx->withdraw; + } + + // 해당 일자의 최신 잔액 업데이트 + $dailyData[$date]['accounts'][$accountNum]['balance'] = $tx->balance; + } + + // accounts를 배열로 변환 + foreach ($dailyData as $date => &$data) { + $data['accounts'] = array_values($data['accounts']); + } + + // 날짜 내림차순 정렬 (최신 일자가 위) + krsort($dailyData); + + return response()->json([ + 'success' => true, + 'data' => [ + 'startDate' => $startDate, + 'endDate' => $endDate, + 'dailyReports' => array_values($dailyData), + ], + ]); + } + + private function formatDateKorean(string $dateYmd): string + { + $year = substr($dateYmd, 0, 4); + $month = (int) substr($dateYmd, 4, 2); + $day = (int) substr($dateYmd, 6, 2); + + $date = \Carbon\Carbon::createFromFormat('Ymd', $dateYmd); + $dayOfWeek = ['일', '월', '화', '수', '목', '금', '토'][$date->dayOfWeek]; + + return "{$year}년 {$month}월 {$day}일 {$dayOfWeek}요일"; + } } diff --git a/resources/views/finance/daily-fund.blade.php b/resources/views/finance/daily-fund.blade.php index 085c31ff..46f83787 100644 --- a/resources/views/finance/daily-fund.blade.php +++ b/resources/views/finance/daily-fund.blade.php @@ -6,13 +6,8 @@ @endpush @@ -22,92 +17,29 @@ @endsection @push('scripts') - - - - - + + +