- feat: [barobill] 바로빌 카드/은행/홈택스 REST API 구현 - feat: [equipment] 설비관리 API 백엔드 구현 - feat: [payroll] 급여관리 계산 엔진 및 일괄 처리 API - feat: [QMS] 점검표 템플릿 관리 + 로트심사 개선 - feat: [생산/출하] 수주 단위 출하 자동생성 + 상태 흐름 개선 - feat: [receiving] 입고 성적서 파일 연결 - feat: [견적] 제어기 타입 체계 변경 - feat: [email] 테넌트 메일 설정 마이그레이션 및 모델 - feat: [pmis] 시공관리 테이블 마이그레이션 - feat: [R2] 파일 업로드 커맨드 + filesystems 설정 - feat: [배포] Jenkinsfile 롤백 기능 추가 - fix: [approval] SAM API 규칙 준수 코드 개선 - fix: [account-codes] 계정과목 중복 데이터 정리 - fix: [payroll] 일괄 생성 시 삭제된 사용자 건너뛰기 - fix: [db] codebridge DB 분리 후 깨진 FK 제약조건 제거 - refactor: [barobill] 바로빌 연동 코드 전면 개선
279 lines
9.8 KiB
PHP
279 lines
9.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\V1;
|
|
|
|
use App\Helpers\ApiResponse;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Tenants\JournalEntry;
|
|
use App\Services\HometaxInvoiceService;
|
|
use App\Services\JournalSyncService;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
/**
|
|
* 홈택스 세금계산서 API 컨트롤러 (React 연동용)
|
|
*
|
|
* MNG에서 동기화된 홈택스 세금계산서를 React에서 조회/관리
|
|
*/
|
|
class HometaxInvoiceController extends Controller
|
|
{
|
|
public function __construct(
|
|
protected HometaxInvoiceService $service,
|
|
protected JournalSyncService $journalSyncService,
|
|
) {}
|
|
|
|
/**
|
|
* 매출 세금계산서 목록
|
|
*/
|
|
public function sales(Request $request): JsonResponse
|
|
{
|
|
return ApiResponse::handle(function () use ($request) {
|
|
$params = $request->validate([
|
|
'start_date' => 'nullable|date',
|
|
'end_date' => 'nullable|date|after_or_equal:start_date',
|
|
'search' => 'nullable|string|max:100',
|
|
'per_page' => 'nullable|integer|min:1|max:100',
|
|
'page' => 'nullable|integer|min:1',
|
|
]);
|
|
|
|
return $this->service->sales($params);
|
|
}, __('message.fetched'));
|
|
}
|
|
|
|
/**
|
|
* 매입 세금계산서 목록
|
|
*/
|
|
public function purchases(Request $request): JsonResponse
|
|
{
|
|
return ApiResponse::handle(function () use ($request) {
|
|
$params = $request->validate([
|
|
'start_date' => 'nullable|date',
|
|
'end_date' => 'nullable|date|after_or_equal:start_date',
|
|
'search' => 'nullable|string|max:100',
|
|
'per_page' => 'nullable|integer|min:1|max:100',
|
|
'page' => 'nullable|integer|min:1',
|
|
]);
|
|
|
|
return $this->service->purchases($params);
|
|
}, __('message.fetched'));
|
|
}
|
|
|
|
/**
|
|
* 세금계산서 상세 조회
|
|
*/
|
|
public function show(int $id): JsonResponse
|
|
{
|
|
return ApiResponse::handle(function () use ($id) {
|
|
$invoice = $this->service->show($id);
|
|
if (! $invoice) {
|
|
throw new \Illuminate\Database\Eloquent\ModelNotFoundException;
|
|
}
|
|
|
|
return $invoice;
|
|
}, __('message.fetched'));
|
|
}
|
|
|
|
/**
|
|
* 요약 통계 (매출/매입 합계)
|
|
*/
|
|
public function summary(Request $request): JsonResponse
|
|
{
|
|
return ApiResponse::handle(function () use ($request) {
|
|
$params = $request->validate([
|
|
'start_date' => 'nullable|date',
|
|
'end_date' => 'nullable|date|after_or_equal:start_date',
|
|
]);
|
|
|
|
return $this->service->summary($params);
|
|
}, __('message.fetched'));
|
|
}
|
|
|
|
// =========================================================================
|
|
// 수동 입력 (Manual)
|
|
// =========================================================================
|
|
|
|
/**
|
|
* 수동 세금계산서 등록
|
|
*/
|
|
public function store(Request $request): JsonResponse
|
|
{
|
|
return ApiResponse::handle(function () use ($request) {
|
|
$validated = $request->validate([
|
|
'invoice_type' => 'required|in:sales,purchase',
|
|
'nts_confirm_num' => 'nullable|string|max:50',
|
|
'write_date' => 'required|date',
|
|
'issue_date' => 'nullable|date',
|
|
'invoicer_corp_num' => 'nullable|string|max:20',
|
|
'invoicer_corp_name' => 'nullable|string|max:200',
|
|
'invoicer_ceo_name' => 'nullable|string|max:100',
|
|
'invoicee_corp_num' => 'nullable|string|max:20',
|
|
'invoicee_corp_name' => 'nullable|string|max:200',
|
|
'invoicee_ceo_name' => 'nullable|string|max:100',
|
|
'supply_amount' => 'required|integer',
|
|
'tax_amount' => 'required|integer',
|
|
'total_amount' => 'required|integer',
|
|
'tax_type' => 'nullable|string|max:10',
|
|
'purpose_type' => 'nullable|string|max:10',
|
|
'issue_type' => 'nullable|string|max:10',
|
|
'item_name' => 'nullable|string|max:200',
|
|
'account_code' => 'nullable|string|max:20',
|
|
'account_name' => 'nullable|string|max:100',
|
|
'deduction_type' => 'nullable|string|max:20',
|
|
'remark1' => 'nullable|string|max:500',
|
|
]);
|
|
|
|
return $this->service->storeManual($validated);
|
|
}, __('message.created'));
|
|
}
|
|
|
|
/**
|
|
* 수동 세금계산서 수정
|
|
*/
|
|
public function update(Request $request, int $id): JsonResponse
|
|
{
|
|
return ApiResponse::handle(function () use ($request, $id) {
|
|
$validated = $request->validate([
|
|
'write_date' => 'nullable|date',
|
|
'issue_date' => 'nullable|date',
|
|
'invoicer_corp_num' => 'nullable|string|max:20',
|
|
'invoicer_corp_name' => 'nullable|string|max:200',
|
|
'invoicee_corp_num' => 'nullable|string|max:20',
|
|
'invoicee_corp_name' => 'nullable|string|max:200',
|
|
'supply_amount' => 'nullable|integer',
|
|
'tax_amount' => 'nullable|integer',
|
|
'total_amount' => 'nullable|integer',
|
|
'item_name' => 'nullable|string|max:200',
|
|
'account_code' => 'nullable|string|max:20',
|
|
'account_name' => 'nullable|string|max:100',
|
|
'deduction_type' => 'nullable|string|max:20',
|
|
'remark1' => 'nullable|string|max:500',
|
|
]);
|
|
|
|
return $this->service->updateManual($id, $validated);
|
|
}, __('message.updated'));
|
|
}
|
|
|
|
/**
|
|
* 수동 세금계산서 삭제
|
|
*/
|
|
public function destroy(int $id): JsonResponse
|
|
{
|
|
return ApiResponse::handle(function () use ($id) {
|
|
return $this->service->destroyManual($id);
|
|
}, __('message.deleted'));
|
|
}
|
|
|
|
// =========================================================================
|
|
// 분개 (자체 테이블: hometax_invoice_journals)
|
|
// =========================================================================
|
|
|
|
/**
|
|
* 분개 조회
|
|
*/
|
|
public function getJournals(int $id): JsonResponse
|
|
{
|
|
return ApiResponse::handle(function () use ($id) {
|
|
return $this->service->getJournals($id);
|
|
}, __('message.fetched'));
|
|
}
|
|
|
|
/**
|
|
* 분개 저장
|
|
*/
|
|
public function saveJournals(Request $request, int $id): JsonResponse
|
|
{
|
|
return ApiResponse::handle(function () use ($request, $id) {
|
|
$validated = $request->validate([
|
|
'items' => 'required|array|min:1',
|
|
'items.*.dc_type' => 'required|in:debit,credit',
|
|
'items.*.account_code' => 'required|string|max:20',
|
|
'items.*.account_name' => 'nullable|string|max:100',
|
|
'items.*.debit_amount' => 'required|integer|min:0',
|
|
'items.*.credit_amount' => 'required|integer|min:0',
|
|
'items.*.description' => 'nullable|string|max:500',
|
|
]);
|
|
|
|
return $this->service->saveJournals($id, $validated['items']);
|
|
}, __('message.created'));
|
|
}
|
|
|
|
/**
|
|
* 분개 삭제
|
|
*/
|
|
public function deleteJournals(int $id): JsonResponse
|
|
{
|
|
return ApiResponse::handle(function () use ($id) {
|
|
return $this->service->deleteJournals($id);
|
|
}, __('message.deleted'));
|
|
}
|
|
|
|
// =========================================================================
|
|
// 통합 분개 (JournalSyncService - CEO 대시보드 연동)
|
|
// =========================================================================
|
|
|
|
/**
|
|
* 통합 분개 조회
|
|
*/
|
|
public function getJournalEntries(int $id): JsonResponse
|
|
{
|
|
return ApiResponse::handle(function () use ($id) {
|
|
$sourceKey = "hometax_{$id}";
|
|
|
|
return $this->journalSyncService->getForSource(
|
|
JournalEntry::SOURCE_HOMETAX_INVOICE,
|
|
$sourceKey
|
|
) ?? ['items' => []];
|
|
}, __('message.fetched'));
|
|
}
|
|
|
|
/**
|
|
* 통합 분개 저장
|
|
*/
|
|
public function storeJournalEntries(Request $request, int $id): JsonResponse
|
|
{
|
|
return ApiResponse::handle(function () use ($request, $id) {
|
|
$validated = $request->validate([
|
|
'items' => 'required|array|min:1',
|
|
'items.*.side' => 'required|in:debit,credit',
|
|
'items.*.account_code' => 'required|string|max:20',
|
|
'items.*.account_name' => 'nullable|string|max:100',
|
|
'items.*.debit_amount' => 'required|integer|min:0',
|
|
'items.*.credit_amount' => 'required|integer|min:0',
|
|
'items.*.vendor_name' => 'nullable|string|max:200',
|
|
'items.*.memo' => 'nullable|string|max:500',
|
|
]);
|
|
|
|
$invoice = $this->service->show($id);
|
|
if (! $invoice) {
|
|
throw new \Illuminate\Database\Eloquent\ModelNotFoundException;
|
|
}
|
|
|
|
$entryDate = $invoice->write_date?->format('Y-m-d') ?? now()->format('Y-m-d');
|
|
$sourceKey = "hometax_{$id}";
|
|
|
|
return $this->journalSyncService->saveForSource(
|
|
JournalEntry::SOURCE_HOMETAX_INVOICE,
|
|
$sourceKey,
|
|
$entryDate,
|
|
"홈택스 세금계산서 분개 (#{$id})",
|
|
$validated['items'],
|
|
);
|
|
}, __('message.created'));
|
|
}
|
|
|
|
/**
|
|
* 통합 분개 삭제
|
|
*/
|
|
public function deleteJournalEntries(int $id): JsonResponse
|
|
{
|
|
return ApiResponse::handle(function () use ($id) {
|
|
$sourceKey = "hometax_{$id}";
|
|
|
|
return $this->journalSyncService->deleteForSource(
|
|
JournalEntry::SOURCE_HOMETAX_INVOICE,
|
|
$sourceKey
|
|
);
|
|
}, __('message.deleted'));
|
|
}
|
|
}
|