diff --git a/app/Exports/DailyReportExport.php b/app/Exports/DailyReportExport.php index f90c18b..3c7fcaa 100644 --- a/app/Exports/DailyReportExport.php +++ b/app/Exports/DailyReportExport.php @@ -32,10 +32,10 @@ public function headings(): array return [ ['일일 일보 - '.$this->report['date']], [], - ['전일 잔액', number_format($this->report['previous_balance']).'원'], - ['당일 입금액', number_format($this->report['daily_deposit']).'원'], - ['당일 출금액', number_format($this->report['daily_withdrawal']).'원'], - ['당일 잔액', number_format($this->report['current_balance']).'원'], + ['전월 이월', number_format($this->report['previous_balance']).'원'], + ['당월 입금', number_format($this->report['daily_deposit']).'원'], + ['당월 출금', number_format($this->report['daily_withdrawal']).'원'], + ['잔액', number_format($this->report['current_balance']).'원'], [], ['구분', '거래처명', '계정과목', '입금액', '출금액', '적요'], ]; diff --git a/app/Services/DailyReportService.php b/app/Services/DailyReportService.php index 8069ffc..188ea79 100644 --- a/app/Services/DailyReportService.php +++ b/app/Services/DailyReportService.php @@ -188,58 +188,48 @@ public function summary(array $params): array */ public function exportData(array $params): array { - $tenantId = $this->tenantId(); $date = isset($params['date']) ? Carbon::parse($params['date']) : Carbon::today(); $dateStr = $date->format('Y-m-d'); - $startOfDay = $date->copy()->startOfDay(); - $endOfDay = $date->copy()->endOfDay(); - // 전일 잔액 계산 (전일까지 입금 합계 - 전일까지 출금 합계) - $prevDeposits = Deposit::where('tenant_id', $tenantId) - ->where('deposit_date', '<', $startOfDay) - ->sum('amount'); - $prevWithdrawals = Withdrawal::where('tenant_id', $tenantId) - ->where('withdrawal_date', '<', $startOfDay) - ->sum('amount'); - $previousBalance = (float) ($prevDeposits - $prevWithdrawals); + // 화면과 동일한 계좌별 현황 데이터 재사용 + $dailyAccounts = $this->dailyAccounts($params); - // 당일 입금 - $dailyDeposits = Deposit::where('tenant_id', $tenantId) - ->whereBetween('deposit_date', [$startOfDay, $endOfDay]) - ->get(); - $dailyDepositTotal = (float) $dailyDeposits->sum('amount'); + // KRW 계좌 합산 (화면 합계와 동일) + $carryover = 0; + $totalIncome = 0; + $totalExpense = 0; + $totalBalance = 0; - // 당일 출금 - $dailyWithdrawals = Withdrawal::where('tenant_id', $tenantId) - ->whereBetween('withdrawal_date', [$startOfDay, $endOfDay]) - ->get(); - $dailyWithdrawalTotal = (float) $dailyWithdrawals->sum('amount'); - - $currentBalance = $previousBalance + $dailyDepositTotal - $dailyWithdrawalTotal; - - // 상세 내역 조합 $details = []; - foreach ($dailyDeposits as $d) { - $details[] = [ - 'type_label' => '입금', - 'client_name' => $d->client?->name ?? '-', - 'account_code' => $d->account_code ?? '-', - 'deposit_amount' => (float) $d->amount, - 'withdrawal_amount' => 0, - 'description' => $d->description ?? '', - ]; - } + foreach ($dailyAccounts as $account) { + $carryover += $account['carryover']; + $totalIncome += $account['income']; + $totalExpense += $account['expense']; + $totalBalance += $account['balance']; - foreach ($dailyWithdrawals as $w) { - $details[] = [ - 'type_label' => '출금', - 'client_name' => $w->client?->name ?? '-', - 'account_code' => $w->account_code ?? '-', - 'deposit_amount' => 0, - 'withdrawal_amount' => (float) $w->amount, - 'description' => $w->description ?? '', - ]; + // 계좌별 상세 내역 + if ($account['income'] > 0) { + $details[] = [ + 'type_label' => '입금', + 'client_name' => $account['category'], + 'account_code' => '-', + 'deposit_amount' => $account['income'], + 'withdrawal_amount' => 0, + 'description' => '', + ]; + } + + if ($account['expense'] > 0) { + $details[] = [ + 'type_label' => '출금', + 'client_name' => $account['category'], + 'account_code' => '-', + 'deposit_amount' => 0, + 'withdrawal_amount' => $account['expense'], + 'description' => '', + ]; + } } // 어음 및 외상매출채권 현황 @@ -247,10 +237,10 @@ public function exportData(array $params): array return [ 'date' => $dateStr, - 'previous_balance' => $previousBalance, - 'daily_deposit' => $dailyDepositTotal, - 'daily_withdrawal' => $dailyWithdrawalTotal, - 'current_balance' => $currentBalance, + 'previous_balance' => $carryover, + 'daily_deposit' => $totalIncome, + 'daily_withdrawal' => $totalExpense, + 'current_balance' => $totalBalance, 'details' => $details, 'note_receivables' => $noteReceivables, ];