feat: [CEO 대시보드] 섹션별 API + 일일보고서 엑셀

- DashboardCeo 리스크 감지형 서비스 리팩토링
- 일일보고서 어음/외상매출채권 현황 섹션 추가
- 엑셀 내보내기 화면 데이터 기반 리팩토링
- 공정명 컬럼 및 근태 부서 조인 수정

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-07 02:59:05 +09:00
parent 1df34b2fa9
commit 95371fd841
6 changed files with 1050 additions and 8 deletions

View File

@@ -5,6 +5,9 @@
use App\Models\Tenants\BankAccount;
use App\Models\Tenants\Bill;
use App\Models\Tenants\Deposit;
use App\Models\Tenants\ExpectedExpense;
use App\Models\Tenants\Purchase;
use App\Models\Tenants\Sale;
use App\Models\Tenants\Withdrawal;
use Carbon\Carbon;
@@ -155,6 +158,11 @@ public function summary(array $params): array
: null;
$operatingStability = $this->getOperatingStability($operatingMonths);
// 기획서 D1.7 자금현황 카드용 필드
$receivableBalance = $this->calculateReceivableBalance($tenantId, $date);
$payableBalance = $this->calculatePayableBalance($tenantId);
$monthlyExpenseTotal = $this->calculateMonthlyExpenseTotal($tenantId, $date);
return [
'date' => $date->format('Y-m-d'),
'day_of_week' => $date->locale('ko')->dayName,
@@ -167,9 +175,138 @@ public function summary(array $params): array
'monthly_operating_expense' => $monthlyOperatingExpense,
'operating_months' => $operatingMonths,
'operating_stability' => $operatingStability,
// 자금현황 카드용
'receivable_balance' => $receivableBalance,
'payable_balance' => $payableBalance,
'monthly_expense_total' => $monthlyExpenseTotal,
];
}
/**
* 엑셀 내보내기용 데이터 조합
* DailyReportExport가 기대하는 구조로 변환
*/
public function exportData(array $params): array
{
$date = isset($params['date']) ? Carbon::parse($params['date']) : Carbon::today();
$dateStr = $date->format('Y-m-d');
// 화면과 동일한 계좌별 현황 데이터 재사용
$dailyAccounts = $this->dailyAccounts($params);
// KRW 계좌 합산 (화면 합계와 동일)
$carryover = 0;
$totalIncome = 0;
$totalExpense = 0;
$totalBalance = 0;
$details = [];
foreach ($dailyAccounts as $account) {
$carryover += $account['carryover'];
$totalIncome += $account['income'];
$totalExpense += $account['expense'];
$totalBalance += $account['balance'];
// 계좌별 상세 내역
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' => '',
];
}
}
// 어음 및 외상매출채권 현황
$noteReceivables = $this->noteReceivables($params);
return [
'date' => $dateStr,
'previous_balance' => $carryover,
'daily_deposit' => $totalIncome,
'daily_withdrawal' => $totalExpense,
'current_balance' => $totalBalance,
'details' => $details,
'note_receivables' => $noteReceivables,
];
}
/**
* 미수금 잔액 계산
* = 전체 매출 - 전체 입금 - 전체 수취어음 (기준일까지)
* ReceivablesService.getTotalCarryForwardBalance() 동일 로직
*/
private function calculateReceivableBalance(int $tenantId, Carbon $date): float
{
$endDate = $date->format('Y-m-d');
$totalSales = Sale::where('tenant_id', $tenantId)
->whereNotNull('client_id')
->where('sale_date', '<=', $endDate)
->sum('total_amount');
$totalDeposits = Deposit::where('tenant_id', $tenantId)
->whereNotNull('client_id')
->where('deposit_date', '<=', $endDate)
->sum('amount');
$totalBills = Bill::where('tenant_id', $tenantId)
->whereNotNull('client_id')
->where('bill_type', 'received')
->where('issue_date', '<=', $endDate)
->sum('amount');
return (float) ($totalSales - $totalDeposits - $totalBills);
}
/**
* 미지급금 잔액 계산
* = 미지급 상태(pending, partial, overdue)인 ExpectedExpense 합계
*/
private function calculatePayableBalance(int $tenantId): float
{
return (float) ExpectedExpense::where('tenant_id', $tenantId)
->whereIn('payment_status', ['pending', 'partial', 'overdue'])
->sum('amount');
}
/**
* 당월 예상 지출 합계 계산
* = 당월 매입(Purchase) + 당월 예상지출(ExpectedExpense)
*/
private function calculateMonthlyExpenseTotal(int $tenantId, Carbon $date): float
{
$startOfMonth = $date->copy()->startOfMonth()->format('Y-m-d');
$endOfMonth = $date->copy()->endOfMonth()->format('Y-m-d');
// 당월 매입 합계
$purchaseTotal = Purchase::where('tenant_id', $tenantId)
->whereBetween('purchase_date', [$startOfMonth, $endOfMonth])
->sum('total_amount');
// 당월 예상 지출 합계 (매입 외: 카드, 어음, 급여, 임대료 등)
$expectedExpenseTotal = ExpectedExpense::where('tenant_id', $tenantId)
->whereBetween('expected_payment_date', [$startOfMonth, $endOfMonth])
->sum('amount');
return (float) ($purchaseTotal + $expectedExpenseTotal);
}
/**
* 직전 3개월 평균 월 운영비 계산
*