feat:재무관리 4개 페이지 수정 (부가세/매출/미지급금)
- 부가세관리: 신고기간 1P/1C/2P/2C 형식, 세금구분(과세/영세/면세), 카드 공제분 매입 반영, 라벨 변경 - 매출관리: 작성일자/승인번호 라벨, 구분(과세/영세/면세) 추가 - 미지급금: 결제예정일/거래일자 라벨, 청구서번호 숨김, 매입세금계산서 발행여부 체크박스 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Finance\VatRecord;
|
||||
use App\Models\Finance\CardTransaction;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
@@ -17,8 +18,7 @@ public function index(Request $request): JsonResponse
|
||||
|
||||
if ($search = $request->input('search')) {
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('partner_name', 'like', "%{$search}%")
|
||||
->orWhere('invoice_no', 'like', "%{$search}%");
|
||||
$q->where('partner_name', 'like', "%{$search}%");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -32,6 +32,12 @@ public function index(Request $request): JsonResponse
|
||||
}
|
||||
}
|
||||
|
||||
if ($taxType = $request->input('tax_type')) {
|
||||
if ($taxType !== 'all') {
|
||||
$query->where('tax_type', $taxType);
|
||||
}
|
||||
}
|
||||
|
||||
if ($status = $request->input('status')) {
|
||||
if ($status !== 'all') {
|
||||
$query->where('status', $status);
|
||||
@@ -45,6 +51,7 @@ public function index(Request $request): JsonResponse
|
||||
'id' => $record->id,
|
||||
'period' => $record->period,
|
||||
'type' => $record->type,
|
||||
'taxType' => $record->tax_type ?? 'taxable',
|
||||
'partnerName' => $record->partner_name,
|
||||
'invoiceNo' => $record->invoice_no,
|
||||
'invoiceDate' => $record->invoice_date?->format('Y-m-d'),
|
||||
@@ -53,9 +60,53 @@ public function index(Request $request): JsonResponse
|
||||
'totalAmount' => $record->total_amount,
|
||||
'status' => $record->status,
|
||||
'memo' => $record->memo,
|
||||
'isCardTransaction' => false,
|
||||
];
|
||||
});
|
||||
|
||||
// 카드 공제분 매입 반영
|
||||
$cardRecords = collect();
|
||||
$cardPurchaseSupply = 0;
|
||||
$cardPurchaseVat = 0;
|
||||
|
||||
if ($period = $request->input('period')) {
|
||||
[$startDate, $endDate] = $this->periodToDateRange($period);
|
||||
|
||||
if ($startDate && $endDate) {
|
||||
$cardQuery = CardTransaction::forTenant($tenantId)
|
||||
->where('deduction_type', 'deductible')
|
||||
->whereBetween('transaction_date', [$startDate, $endDate]);
|
||||
|
||||
$cardTransactions = $cardQuery->orderBy('transaction_date', 'desc')->get();
|
||||
|
||||
$cardRecords = $cardTransactions->map(function ($card) use ($period) {
|
||||
$supply = (int) round($card->amount / 1.1);
|
||||
$vat = $card->amount - $supply;
|
||||
return [
|
||||
'id' => 'card_' . $card->id,
|
||||
'period' => $period,
|
||||
'type' => 'purchase',
|
||||
'taxType' => 'taxable',
|
||||
'partnerName' => $card->merchant,
|
||||
'invoiceNo' => $card->approval_no ?? '',
|
||||
'invoiceDate' => $card->transaction_date?->format('Y-m-d'),
|
||||
'supplyAmount' => $supply,
|
||||
'vatAmount' => $vat,
|
||||
'totalAmount' => $card->amount,
|
||||
'status' => 'filed',
|
||||
'memo' => $card->memo,
|
||||
'isCardTransaction' => true,
|
||||
];
|
||||
});
|
||||
|
||||
$cardPurchaseSupply = $cardRecords->sum('supplyAmount');
|
||||
$cardPurchaseVat = $cardRecords->sum('vatAmount');
|
||||
}
|
||||
}
|
||||
|
||||
// 통합 records
|
||||
$allRecords = $records->concat($cardRecords)->values();
|
||||
|
||||
// 해당 기간 통계
|
||||
$periodQuery = VatRecord::forTenant($tenantId);
|
||||
if ($period = $request->input('period')) {
|
||||
@@ -66,8 +117,10 @@ public function index(Request $request): JsonResponse
|
||||
$stats = [
|
||||
'salesSupply' => $periodRecords->where('type', 'sales')->sum('supply_amount'),
|
||||
'salesVat' => $periodRecords->where('type', 'sales')->sum('vat_amount'),
|
||||
'purchaseSupply' => $periodRecords->where('type', 'purchase')->sum('supply_amount'),
|
||||
'purchaseVat' => $periodRecords->where('type', 'purchase')->sum('vat_amount'),
|
||||
'purchaseSupply' => $periodRecords->where('type', 'purchase')->sum('supply_amount') + $cardPurchaseSupply,
|
||||
'purchaseVat' => $periodRecords->where('type', 'purchase')->sum('vat_amount') + $cardPurchaseVat,
|
||||
'cardPurchaseSupply' => $cardPurchaseSupply,
|
||||
'cardPurchaseVat' => $cardPurchaseVat,
|
||||
'total' => $periodRecords->count(),
|
||||
];
|
||||
|
||||
@@ -81,7 +134,7 @@ public function index(Request $request): JsonResponse
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $records,
|
||||
'data' => $allRecords,
|
||||
'stats' => $stats,
|
||||
'periods' => $periods,
|
||||
]);
|
||||
@@ -91,9 +144,9 @@ public function store(Request $request): JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
'partnerName' => 'required|string|max:100',
|
||||
'invoiceNo' => 'required|string|max:50',
|
||||
'period' => 'required|string|max:20',
|
||||
'type' => 'required|in:sales,purchase',
|
||||
'taxType' => 'nullable|in:taxable,zero_rated,exempt',
|
||||
'supplyAmount' => 'required|integer|min:0',
|
||||
]);
|
||||
|
||||
@@ -103,6 +156,7 @@ public function store(Request $request): JsonResponse
|
||||
'tenant_id' => $tenantId,
|
||||
'period' => $request->input('period'),
|
||||
'type' => $request->input('type', 'sales'),
|
||||
'tax_type' => $request->input('taxType', 'taxable'),
|
||||
'partner_name' => $request->input('partnerName'),
|
||||
'invoice_no' => $request->input('invoiceNo'),
|
||||
'invoice_date' => $request->input('invoiceDate'),
|
||||
@@ -127,15 +181,16 @@ public function update(Request $request, int $id): JsonResponse
|
||||
|
||||
$request->validate([
|
||||
'partnerName' => 'required|string|max:100',
|
||||
'invoiceNo' => 'required|string|max:50',
|
||||
'period' => 'required|string|max:20',
|
||||
'type' => 'required|in:sales,purchase',
|
||||
'taxType' => 'nullable|in:taxable,zero_rated,exempt',
|
||||
'supplyAmount' => 'required|integer|min:0',
|
||||
]);
|
||||
|
||||
$record->update([
|
||||
'period' => $request->input('period'),
|
||||
'type' => $request->input('type'),
|
||||
'tax_type' => $request->input('taxType', $record->tax_type),
|
||||
'partner_name' => $request->input('partnerName'),
|
||||
'invoice_no' => $request->input('invoiceNo'),
|
||||
'invoice_date' => $request->input('invoiceDate'),
|
||||
@@ -163,4 +218,31 @@ public function destroy(int $id): JsonResponse
|
||||
'message' => '세금계산서가 삭제되었습니다.',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 부가세 신고기간을 날짜 범위로 변환
|
||||
* YYYY-1P: 1기 예정 (0101~0331)
|
||||
* YYYY-1C: 1기 확정 (0401~0630)
|
||||
* YYYY-2P: 2기 예정 (0701~0930)
|
||||
* YYYY-2C: 2기 확정 (1001~1231)
|
||||
*/
|
||||
private function periodToDateRange(string $period): array
|
||||
{
|
||||
$parts = explode('-', $period);
|
||||
if (count($parts) !== 2) {
|
||||
return [null, null];
|
||||
}
|
||||
|
||||
$year = $parts[0];
|
||||
$code = $parts[1];
|
||||
|
||||
$ranges = [
|
||||
'1P' => ["{$year}-01-01", "{$year}-03-31"],
|
||||
'1C' => ["{$year}-04-01", "{$year}-06-30"],
|
||||
'2P' => ["{$year}-07-01", "{$year}-09-30"],
|
||||
'2C' => ["{$year}-10-01", "{$year}-12-31"],
|
||||
];
|
||||
|
||||
return $ranges[$code] ?? [null, null];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user