2025-12-18 15:31:59 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Api\V1;
|
|
|
|
|
|
|
|
|
|
use App\Helpers\ApiResponse;
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use App\Http\Requests\TaxInvoice\CancelTaxInvoiceRequest;
|
|
|
|
|
use App\Http\Requests\TaxInvoice\CreateTaxInvoiceRequest;
|
|
|
|
|
use App\Http\Requests\TaxInvoice\TaxInvoiceListRequest;
|
|
|
|
|
use App\Http\Requests\TaxInvoice\TaxInvoiceSummaryRequest;
|
|
|
|
|
use App\Http\Requests\TaxInvoice\UpdateTaxInvoiceRequest;
|
2026-01-19 20:53:36 +09:00
|
|
|
use App\Http\Requests\V1\TaxInvoice\BulkIssueRequest;
|
2026-03-08 10:32:20 +09:00
|
|
|
use App\Models\Tenants\JournalEntry;
|
|
|
|
|
use App\Services\JournalSyncService;
|
2025-12-18 15:31:59 +09:00
|
|
|
use App\Services\TaxInvoiceService;
|
2026-03-08 10:32:20 +09:00
|
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
|
use Illuminate\Http\Request;
|
2025-12-18 15:31:59 +09:00
|
|
|
|
|
|
|
|
class TaxInvoiceController extends Controller
|
|
|
|
|
{
|
|
|
|
|
public function __construct(
|
2026-03-08 10:32:20 +09:00
|
|
|
private TaxInvoiceService $taxInvoiceService,
|
|
|
|
|
private JournalSyncService $journalSyncService,
|
2025-12-18 15:31:59 +09:00
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 세금계산서 목록 조회
|
|
|
|
|
*/
|
|
|
|
|
public function index(TaxInvoiceListRequest $request)
|
|
|
|
|
{
|
2026-03-09 11:21:20 +09:00
|
|
|
return ApiResponse::handle(function () use ($request) {
|
|
|
|
|
return $this->taxInvoiceService->list($request->validated());
|
|
|
|
|
}, __('message.fetched'));
|
2025-12-18 15:31:59 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 세금계산서 상세 조회
|
|
|
|
|
*/
|
|
|
|
|
public function show(int $id)
|
|
|
|
|
{
|
2026-03-09 11:21:20 +09:00
|
|
|
return ApiResponse::handle(function () use ($id) {
|
|
|
|
|
return $this->taxInvoiceService->show($id);
|
|
|
|
|
}, __('message.fetched'));
|
2025-12-18 15:31:59 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 세금계산서 생성
|
|
|
|
|
*/
|
|
|
|
|
public function store(CreateTaxInvoiceRequest $request)
|
|
|
|
|
{
|
2026-03-09 11:21:20 +09:00
|
|
|
return ApiResponse::handle(function () use ($request) {
|
|
|
|
|
return $this->taxInvoiceService->create($request->validated());
|
|
|
|
|
}, __('message.created'));
|
2025-12-18 15:31:59 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 세금계산서 수정
|
|
|
|
|
*/
|
|
|
|
|
public function update(UpdateTaxInvoiceRequest $request, int $id)
|
|
|
|
|
{
|
2026-03-09 11:21:20 +09:00
|
|
|
return ApiResponse::handle(function () use ($request, $id) {
|
|
|
|
|
return $this->taxInvoiceService->update($id, $request->validated());
|
|
|
|
|
}, __('message.updated'));
|
2025-12-18 15:31:59 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 세금계산서 삭제
|
|
|
|
|
*/
|
|
|
|
|
public function destroy(int $id)
|
|
|
|
|
{
|
2026-03-09 11:21:20 +09:00
|
|
|
return ApiResponse::handle(function () use ($id) {
|
|
|
|
|
$this->taxInvoiceService->delete($id);
|
2026-02-23 10:17:37 +09:00
|
|
|
|
2026-03-09 11:21:20 +09:00
|
|
|
return null;
|
|
|
|
|
}, __('message.deleted'));
|
2025-12-18 15:31:59 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 세금계산서 발행
|
|
|
|
|
*/
|
|
|
|
|
public function issue(int $id)
|
|
|
|
|
{
|
2026-03-09 11:21:20 +09:00
|
|
|
return ApiResponse::handle(function () use ($id) {
|
|
|
|
|
return $this->taxInvoiceService->issue($id);
|
|
|
|
|
}, __('message.tax_invoice.issued'));
|
2025-12-18 15:31:59 +09:00
|
|
|
}
|
|
|
|
|
|
2026-01-19 20:53:36 +09:00
|
|
|
/**
|
|
|
|
|
* 세금계산서 일괄 발행
|
|
|
|
|
*/
|
|
|
|
|
public function bulkIssue(BulkIssueRequest $request)
|
|
|
|
|
{
|
2026-03-09 11:21:20 +09:00
|
|
|
return ApiResponse::handle(function () use ($request) {
|
|
|
|
|
return $this->taxInvoiceService->bulkIssue($request->getIds());
|
|
|
|
|
}, __('message.tax_invoice.bulk_issued'));
|
2026-01-19 20:53:36 +09:00
|
|
|
}
|
|
|
|
|
|
2025-12-18 15:31:59 +09:00
|
|
|
/**
|
|
|
|
|
* 세금계산서 취소
|
|
|
|
|
*/
|
|
|
|
|
public function cancel(CancelTaxInvoiceRequest $request, int $id)
|
|
|
|
|
{
|
2026-03-09 11:21:20 +09:00
|
|
|
return ApiResponse::handle(function () use ($request, $id) {
|
|
|
|
|
return $this->taxInvoiceService->cancel($id, $request->validated()['reason']);
|
|
|
|
|
}, __('message.tax_invoice.cancelled'));
|
2025-12-18 15:31:59 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 국세청 전송 상태 조회
|
|
|
|
|
*/
|
|
|
|
|
public function checkStatus(int $id)
|
|
|
|
|
{
|
2026-03-09 11:21:20 +09:00
|
|
|
return ApiResponse::handle(function () use ($id) {
|
|
|
|
|
return $this->taxInvoiceService->checkStatus($id);
|
|
|
|
|
}, __('message.fetched'));
|
2025-12-18 15:31:59 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 세금계산서 요약 통계
|
|
|
|
|
*/
|
|
|
|
|
public function summary(TaxInvoiceSummaryRequest $request)
|
|
|
|
|
{
|
2026-03-09 11:21:20 +09:00
|
|
|
return ApiResponse::handle(function () use ($request) {
|
|
|
|
|
return $this->taxInvoiceService->summary($request->validated());
|
|
|
|
|
}, __('message.fetched'));
|
2026-02-21 08:31:34 +09:00
|
|
|
}
|
2026-03-08 10:32:20 +09:00
|
|
|
|
|
|
|
|
// =========================================================================
|
|
|
|
|
// 분개 (Journal Entries)
|
|
|
|
|
// =========================================================================
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 세금계산서 분개 조회
|
|
|
|
|
*/
|
|
|
|
|
public function getJournalEntries(int $id): JsonResponse
|
|
|
|
|
{
|
|
|
|
|
return ApiResponse::handle(function () use ($id) {
|
|
|
|
|
$sourceKey = "tax_invoice_{$id}";
|
|
|
|
|
$data = $this->journalSyncService->getForSource(
|
|
|
|
|
JournalEntry::SOURCE_TAX_INVOICE,
|
|
|
|
|
$sourceKey
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return $data ?? ['rows' => []];
|
|
|
|
|
}, __('message.fetched'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 세금계산서 분개 저장/수정
|
|
|
|
|
*/
|
|
|
|
|
public function storeJournalEntries(Request $request, int $id): JsonResponse
|
|
|
|
|
{
|
|
|
|
|
return ApiResponse::handle(function () use ($request, $id) {
|
|
|
|
|
$validated = $request->validate([
|
|
|
|
|
'rows' => 'required|array|min:1',
|
|
|
|
|
'rows.*.side' => 'required|in:debit,credit',
|
|
|
|
|
'rows.*.account_subject' => 'required|string|max:20',
|
|
|
|
|
'rows.*.debit_amount' => 'required|integer|min:0',
|
|
|
|
|
'rows.*.credit_amount' => 'required|integer|min:0',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// 세금계산서 정보 조회 (entry_date용)
|
|
|
|
|
$taxInvoice = $this->taxInvoiceService->show($id);
|
|
|
|
|
|
|
|
|
|
$rows = array_map(fn ($row) => [
|
|
|
|
|
'side' => $row['side'],
|
|
|
|
|
'account_code' => $row['account_subject'],
|
|
|
|
|
'debit_amount' => $row['debit_amount'],
|
|
|
|
|
'credit_amount' => $row['credit_amount'],
|
|
|
|
|
], $validated['rows']);
|
|
|
|
|
|
|
|
|
|
$sourceKey = "tax_invoice_{$id}";
|
|
|
|
|
|
|
|
|
|
return $this->journalSyncService->saveForSource(
|
|
|
|
|
JournalEntry::SOURCE_TAX_INVOICE,
|
|
|
|
|
$sourceKey,
|
|
|
|
|
$taxInvoice->issue_date?->format('Y-m-d') ?? now()->format('Y-m-d'),
|
|
|
|
|
"세금계산서 분개 (#{$id})",
|
|
|
|
|
$rows,
|
|
|
|
|
);
|
|
|
|
|
}, __('message.created'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 세금계산서 분개 삭제
|
|
|
|
|
*/
|
|
|
|
|
public function deleteJournalEntries(int $id): JsonResponse
|
|
|
|
|
{
|
|
|
|
|
return ApiResponse::handle(function () use ($id) {
|
|
|
|
|
$sourceKey = "tax_invoice_{$id}";
|
|
|
|
|
|
|
|
|
|
return $this->journalSyncService->deleteForSource(
|
|
|
|
|
JournalEntry::SOURCE_TAX_INVOICE,
|
|
|
|
|
$sourceKey
|
|
|
|
|
);
|
|
|
|
|
}, __('message.deleted'));
|
|
|
|
|
}
|
2025-12-18 15:31:59 +09:00
|
|
|
}
|