feat: 보고서(Reports) API 구현
- 일일 일보 조회/엑셀 다운로드 API 추가 - 지출 예상 내역서 조회/엑셀 다운로드 API 추가 - ReportService: 전일/당일 잔액 계산, 월별 지출 예상 집계 - Laravel Excel을 이용한 엑셀 내보내기 구현 - Swagger 문서 작성 완료
This commit is contained in:
95
app/Exports/DailyReportExport.php
Normal file
95
app/Exports/DailyReportExport.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use Maatwebsite\Excel\Concerns\FromArray;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithStyles;
|
||||
use Maatwebsite\Excel\Concerns\WithTitle;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
|
||||
class DailyReportExport implements FromArray, ShouldAutoSize, WithHeadings, WithStyles, WithTitle
|
||||
{
|
||||
public function __construct(
|
||||
private readonly array $report
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 시트 제목
|
||||
*/
|
||||
public function title(): string
|
||||
{
|
||||
return '일일일보';
|
||||
}
|
||||
|
||||
/**
|
||||
* 헤더 정의
|
||||
*/
|
||||
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']).'원'],
|
||||
[],
|
||||
['구분', '거래처명', '계정과목', '입금액', '출금액', '적요'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 데이터 배열
|
||||
*/
|
||||
public function array(): array
|
||||
{
|
||||
$rows = [];
|
||||
|
||||
foreach ($this->report['details'] as $detail) {
|
||||
$rows[] = [
|
||||
$detail['type_label'],
|
||||
$detail['client_name'],
|
||||
$detail['account_code'],
|
||||
$detail['deposit_amount'] > 0 ? number_format($detail['deposit_amount']) : '',
|
||||
$detail['withdrawal_amount'] > 0 ? number_format($detail['withdrawal_amount']) : '',
|
||||
$detail['description'],
|
||||
];
|
||||
}
|
||||
|
||||
// 합계 행 추가
|
||||
$rows[] = [];
|
||||
$rows[] = [
|
||||
'합계',
|
||||
'',
|
||||
'',
|
||||
number_format($this->report['daily_deposit']),
|
||||
number_format($this->report['daily_withdrawal']),
|
||||
'',
|
||||
];
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* 스타일 정의
|
||||
*/
|
||||
public function styles(Worksheet $sheet): array
|
||||
{
|
||||
return [
|
||||
1 => ['font' => ['bold' => true, 'size' => 14]],
|
||||
3 => ['font' => ['bold' => true]],
|
||||
4 => ['font' => ['bold' => true]],
|
||||
5 => ['font' => ['bold' => true]],
|
||||
6 => ['font' => ['bold' => true]],
|
||||
8 => [
|
||||
'font' => ['bold' => true],
|
||||
'fill' => [
|
||||
'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
|
||||
'startColor' => ['rgb' => 'E0E0E0'],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
121
app/Exports/ExpenseEstimateExport.php
Normal file
121
app/Exports/ExpenseEstimateExport.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use Maatwebsite\Excel\Concerns\FromArray;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithStyles;
|
||||
use Maatwebsite\Excel\Concerns\WithTitle;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
|
||||
class ExpenseEstimateExport implements FromArray, ShouldAutoSize, WithHeadings, WithStyles, WithTitle
|
||||
{
|
||||
public function __construct(
|
||||
private readonly array $report
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 시트 제목
|
||||
*/
|
||||
public function title(): string
|
||||
{
|
||||
return '지출예상내역서';
|
||||
}
|
||||
|
||||
/**
|
||||
* 헤더 정의
|
||||
*/
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
['지출 예상 내역서 - '.$this->report['year_month']],
|
||||
[],
|
||||
['예상 지출 합계', number_format($this->report['total_estimate']).'원'],
|
||||
['계좌 잔액', number_format($this->report['account_balance']).'원'],
|
||||
['예상 잔액', number_format($this->report['expected_balance']).'원'],
|
||||
[],
|
||||
['예상 지급일', '품목', '지출금액', '거래처', '계좌'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 데이터 배열
|
||||
*/
|
||||
public function array(): array
|
||||
{
|
||||
$rows = [];
|
||||
|
||||
foreach ($this->report['items'] as $item) {
|
||||
$rows[] = [
|
||||
$item['expected_date'],
|
||||
$item['item_name'],
|
||||
number_format($item['amount']),
|
||||
$item['client_name'],
|
||||
$item['account_name'],
|
||||
];
|
||||
}
|
||||
|
||||
// 빈 줄 추가
|
||||
$rows[] = [];
|
||||
|
||||
// 월별 합계
|
||||
$rows[] = ['[월별 합계]', '', '', '', ''];
|
||||
|
||||
foreach ($this->report['monthly_summary']['by_month'] as $month) {
|
||||
$rows[] = [
|
||||
$month['month'].' 계',
|
||||
'',
|
||||
number_format($month['total']),
|
||||
'',
|
||||
'',
|
||||
];
|
||||
}
|
||||
|
||||
// 최종 합계
|
||||
$rows[] = [];
|
||||
$rows[] = [
|
||||
'지출 합계',
|
||||
'',
|
||||
number_format($this->report['monthly_summary']['total_expense']),
|
||||
'',
|
||||
'',
|
||||
];
|
||||
$rows[] = [
|
||||
'계좌 잔액',
|
||||
'',
|
||||
number_format($this->report['monthly_summary']['account_balance']),
|
||||
'',
|
||||
'',
|
||||
];
|
||||
$rows[] = [
|
||||
'최종 차액',
|
||||
'',
|
||||
number_format($this->report['monthly_summary']['final_difference']),
|
||||
'',
|
||||
'',
|
||||
];
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* 스타일 정의
|
||||
*/
|
||||
public function styles(Worksheet $sheet): array
|
||||
{
|
||||
return [
|
||||
1 => ['font' => ['bold' => true, 'size' => 14]],
|
||||
3 => ['font' => ['bold' => true]],
|
||||
4 => ['font' => ['bold' => true]],
|
||||
5 => ['font' => ['bold' => true]],
|
||||
7 => [
|
||||
'font' => ['bold' => true],
|
||||
'fill' => [
|
||||
'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
|
||||
'startColor' => ['rgb' => 'E0E0E0'],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user