refactor: [daily-report] 엑셀 내보내기 화면 데이터 기반으로 리팩토링
- DailyReportService: exportData를 dailyAccounts() 재사용 구조로 변경 - DailyReportExport: 헤더 라벨 전월이월/당월입금/당월출금/잔액으로 수정 - 화면 합계와 엑셀 합계 일치하도록 개선 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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']).'원'],
|
||||
[],
|
||||
['구분', '거래처명', '계정과목', '입금액', '출금액', '적요'],
|
||||
];
|
||||
|
||||
@@ -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,
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user