feat(WEB): 회계/설정/카드 관리 페이지 대규모 기능 추가 및 리팩토링
- 일반전표입력, 상품권관리, 세금계산서 발행/조회 신규 페이지 추가 - 바로빌 연동 설정 페이지 추가 - 카드관리/계좌관리 리스트 UniversalListPage 공통 구조로 전환 - 카드거래조회/은행거래조회 리팩토링 (모달 분리, 액션 확장) - 계좌 상세 폼(AccountDetailForm) 신규 구현 - 카드 상세(CardDetail) 신규 구현 + CardNumberInput 적용 - DateRangeSelector, StatCards, IntegratedListTemplateV2 공통 컴포넌트 개선 - 레거시 파일 정리 (CardManagementUnified, cardConfig, _legacy 등) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,138 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import { useState, useCallback, useEffect } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { toast } from 'sonner';
|
||||
import { IntegratedDetailTemplate } from '@/components/templates/IntegratedDetailTemplate';
|
||||
import type { DetailMode } from '@/components/templates/IntegratedDetailTemplate/types';
|
||||
import { cardTransactionDetailConfig } from './cardTransactionDetailConfig';
|
||||
import type { CardTransaction } from './types';
|
||||
import {
|
||||
getCardTransactionById,
|
||||
createCardTransaction,
|
||||
updateCardTransaction,
|
||||
deleteCardTransaction,
|
||||
getCardList,
|
||||
} from './actions';
|
||||
import { useDevFill, generateCardTransactionData } from '@/components/dev';
|
||||
|
||||
// ===== Props =====
|
||||
interface CardTransactionDetailClientProps {
|
||||
transactionId?: string;
|
||||
initialMode?: DetailMode;
|
||||
}
|
||||
|
||||
export default function CardTransactionDetailClient({
|
||||
transactionId,
|
||||
initialMode = 'view',
|
||||
}: CardTransactionDetailClientProps) {
|
||||
const router = useRouter();
|
||||
const [mode, setMode] = useState<DetailMode>(initialMode);
|
||||
const [transaction, setTransaction] = useState<CardTransaction | null>(null);
|
||||
const [isLoading, setIsLoading] = useState(initialMode !== 'create');
|
||||
|
||||
// ===== DevFill: 자동 입력 기능 =====
|
||||
useDevFill('cardTransaction', useCallback(async () => {
|
||||
if (initialMode === 'create') {
|
||||
// 카드 목록 가져오기
|
||||
const cardResult = await getCardList();
|
||||
const cards = cardResult.success ? cardResult.data : undefined;
|
||||
|
||||
const mockData = generateCardTransactionData({ cards });
|
||||
setTransaction(mockData as unknown as CardTransaction);
|
||||
toast.success('카드 사용내역 데이터가 자동 입력되었습니다.');
|
||||
}
|
||||
}, [initialMode]));
|
||||
|
||||
// ===== 데이터 로드 =====
|
||||
useEffect(() => {
|
||||
const loadTransaction = async () => {
|
||||
if (transactionId && initialMode !== 'create') {
|
||||
setIsLoading(true);
|
||||
const result = await getCardTransactionById(transactionId);
|
||||
if (result.success && result.data) {
|
||||
setTransaction(result.data);
|
||||
} else {
|
||||
toast.error(result.error || '카드 사용내역을 불러오는데 실패했습니다.');
|
||||
}
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
loadTransaction();
|
||||
}, [transactionId, initialMode]);
|
||||
|
||||
// ===== 저장/등록 핸들러 =====
|
||||
const handleSubmit = useCallback(
|
||||
async (formData: Record<string, unknown>): Promise<{ success: boolean; error?: string }> => {
|
||||
const submitData = cardTransactionDetailConfig.transformSubmitData?.(formData) || formData;
|
||||
|
||||
if (!submitData.merchantName) {
|
||||
toast.error('가맹점명을 입력해주세요.');
|
||||
return { success: false, error: '가맹점명을 입력해주세요.' };
|
||||
}
|
||||
if (!submitData.amount || Number(submitData.amount) <= 0) {
|
||||
toast.error('사용금액을 입력해주세요.');
|
||||
return { success: false, error: '사용금액을 입력해주세요.' };
|
||||
}
|
||||
if (!submitData.usedAt) {
|
||||
toast.error('사용일시를 선택해주세요.');
|
||||
return { success: false, error: '사용일시를 선택해주세요.' };
|
||||
}
|
||||
|
||||
const result =
|
||||
mode === 'create'
|
||||
? await createCardTransaction(submitData as Parameters<typeof createCardTransaction>[0])
|
||||
: await updateCardTransaction(transactionId!, submitData as Parameters<typeof updateCardTransaction>[1]);
|
||||
|
||||
if (result.success) {
|
||||
toast.success(mode === 'create' ? '카드 사용내역이 등록되었습니다.' : '카드 사용내역이 수정되었습니다.');
|
||||
router.push('/ko/accounting/card-transactions');
|
||||
return { success: true };
|
||||
} else {
|
||||
toast.error(result.error || '저장에 실패했습니다.');
|
||||
return { success: false, error: result.error };
|
||||
}
|
||||
},
|
||||
[mode, transactionId, router]
|
||||
);
|
||||
|
||||
// ===== 삭제 핸들러 =====
|
||||
const handleDelete = useCallback(async (): Promise<{ success: boolean; error?: string }> => {
|
||||
if (!transactionId) return { success: false, error: 'ID가 없습니다.' };
|
||||
|
||||
const result = await deleteCardTransaction(transactionId);
|
||||
if (result.success) {
|
||||
toast.success('카드 사용내역이 삭제되었습니다.');
|
||||
router.push('/ko/accounting/card-transactions');
|
||||
return { success: true };
|
||||
} else {
|
||||
toast.error(result.error || '삭제에 실패했습니다.');
|
||||
return { success: false, error: result.error };
|
||||
}
|
||||
}, [transactionId, router]);
|
||||
|
||||
// ===== 모드 변경 핸들러 =====
|
||||
const handleModeChange = useCallback(
|
||||
(newMode: DetailMode) => {
|
||||
if (newMode === 'edit' && transactionId) {
|
||||
router.push(`/ko/accounting/card-transactions/${transactionId}?mode=edit`);
|
||||
} else {
|
||||
setMode(newMode);
|
||||
}
|
||||
},
|
||||
[transactionId, router]
|
||||
);
|
||||
|
||||
return (
|
||||
<IntegratedDetailTemplate
|
||||
config={cardTransactionDetailConfig as Parameters<typeof IntegratedDetailTemplate>[0]['config']}
|
||||
mode={mode}
|
||||
initialData={transaction as unknown as Record<string, unknown> | undefined}
|
||||
itemId={transactionId}
|
||||
isLoading={isLoading}
|
||||
onSubmit={handleSubmit}
|
||||
onDelete={handleDelete}
|
||||
onModeChange={handleModeChange}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,294 @@
|
||||
'use client';
|
||||
|
||||
import { useState, useCallback } from 'react';
|
||||
import { toast } from 'sonner';
|
||||
import { Loader2, Minus, Plus } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { FormField } from '@/components/molecules/FormField';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogFooter,
|
||||
} from '@/components/ui/dialog';
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/components/ui/select';
|
||||
import type { CardTransaction, JournalEntryItem } from './types';
|
||||
import { DEDUCTION_OPTIONS, ACCOUNT_SUBJECT_OPTIONS } from './types';
|
||||
import { saveJournalEntries } from './actions';
|
||||
|
||||
interface JournalEntryModalProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
transaction: CardTransaction | null;
|
||||
onSuccess: () => void;
|
||||
}
|
||||
|
||||
function createEmptyItem(transaction: CardTransaction | null): JournalEntryItem {
|
||||
return {
|
||||
supplyAmount: transaction?.supplyAmount || 0,
|
||||
taxAmount: transaction?.taxAmount || 0,
|
||||
totalAmount: transaction?.totalAmount || 0,
|
||||
accountSubject: '',
|
||||
deductionType: 'deductible',
|
||||
vendorName: '',
|
||||
description: '',
|
||||
memo: '',
|
||||
};
|
||||
}
|
||||
|
||||
export function JournalEntryModal({ open, onOpenChange, transaction, onSuccess }: JournalEntryModalProps) {
|
||||
const [items, setItems] = useState<JournalEntryItem[]>([]);
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
|
||||
// 모달 열릴 때 초기 항목 설정
|
||||
const handleOpenChange = useCallback((isOpen: boolean) => {
|
||||
if (isOpen && transaction) {
|
||||
setItems([createEmptyItem(transaction)]);
|
||||
}
|
||||
onOpenChange(isOpen);
|
||||
}, [transaction, onOpenChange]);
|
||||
|
||||
const updateItem = useCallback((index: number, key: keyof JournalEntryItem, value: string | number) => {
|
||||
setItems(prev => {
|
||||
const updated = [...prev];
|
||||
const item = { ...updated[index], [key]: value };
|
||||
// 합계금액 자동 계산
|
||||
if (key === 'supplyAmount' || key === 'taxAmount') {
|
||||
const supply = key === 'supplyAmount' ? (value as number) : item.supplyAmount;
|
||||
const tax = key === 'taxAmount' ? (value as number) : item.taxAmount;
|
||||
item.totalAmount = supply + tax;
|
||||
}
|
||||
updated[index] = item;
|
||||
return updated;
|
||||
});
|
||||
}, []);
|
||||
|
||||
const addItem = useCallback(() => {
|
||||
setItems(prev => [...prev, createEmptyItem(null)]);
|
||||
}, []);
|
||||
|
||||
const removeItem = useCallback((index: number) => {
|
||||
setItems(prev => prev.filter((_, i) => i !== index));
|
||||
}, []);
|
||||
|
||||
const journalTotal = items.reduce((sum, item) => sum + item.totalAmount, 0);
|
||||
|
||||
const handleSave = useCallback(async () => {
|
||||
if (!transaction) return;
|
||||
|
||||
const hasEmptyAccount = items.some(item => !item.accountSubject);
|
||||
if (hasEmptyAccount) {
|
||||
toast.error('모든 분개 항목에 계정과목을 선택해주세요.');
|
||||
return;
|
||||
}
|
||||
|
||||
setIsSubmitting(true);
|
||||
try {
|
||||
const result = await saveJournalEntries(transaction.id, items);
|
||||
if (result.success) {
|
||||
toast.success('분개가 저장되었습니다.');
|
||||
onOpenChange(false);
|
||||
onSuccess();
|
||||
} else {
|
||||
toast.error(result.error || '분개 저장에 실패했습니다.');
|
||||
}
|
||||
} catch {
|
||||
toast.error('분개 저장 중 오류가 발생했습니다.');
|
||||
} finally {
|
||||
setIsSubmitting(false);
|
||||
}
|
||||
}, [transaction, items, onOpenChange, onSuccess]);
|
||||
|
||||
if (!transaction) return null;
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={handleOpenChange}>
|
||||
<DialogContent className="sm:max-w-[600px] max-h-[90vh] overflow-y-auto">
|
||||
<DialogHeader>
|
||||
<DialogTitle>거래 분개</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="space-y-4 py-2">
|
||||
{/* 거래 정보 (읽기 전용 - FormField 대상 아님) */}
|
||||
<div className="border rounded-lg p-4 bg-muted/30 space-y-3">
|
||||
<h4 className="font-medium text-sm">거래 정보</h4>
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div>
|
||||
<Label className="text-xs text-muted-foreground">가맹점</Label>
|
||||
<p className="text-sm font-medium mt-0.5">{transaction.merchantName}</p>
|
||||
</div>
|
||||
<div>
|
||||
<Label className="text-xs text-muted-foreground">사용일시</Label>
|
||||
<p className="text-sm font-medium mt-0.5">{transaction.usedAt}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="grid grid-cols-3 gap-3">
|
||||
<div>
|
||||
<Label className="text-xs text-muted-foreground">공급가액</Label>
|
||||
<p className="text-sm font-medium mt-0.5">{transaction.supplyAmount.toLocaleString()}</p>
|
||||
</div>
|
||||
<div>
|
||||
<Label className="text-xs text-muted-foreground">세액</Label>
|
||||
<p className="text-sm font-medium mt-0.5">{transaction.taxAmount.toLocaleString()}</p>
|
||||
</div>
|
||||
<div>
|
||||
<Label className="text-xs text-muted-foreground">합계금액</Label>
|
||||
<p className="text-sm font-medium mt-0.5">{transaction.totalAmount.toLocaleString()}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 분개 항목 목록 */}
|
||||
{items.map((item, index) => (
|
||||
<div key={index} className="border rounded-lg p-4 space-y-3 relative">
|
||||
<div className="flex items-center justify-between">
|
||||
<h4 className="font-medium text-sm">분개 항목</h4>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-7 w-7"
|
||||
onClick={() => removeItem(index)}
|
||||
disabled={items.length <= 1}
|
||||
>
|
||||
<Minus className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* 공급가액 + 세액 + 합계금액 */}
|
||||
<div className="grid grid-cols-3 gap-3">
|
||||
<FormField
|
||||
type="number"
|
||||
label="공급가액"
|
||||
value={item.supplyAmount || ''}
|
||||
onChange={(v) => updateItem(index, 'supplyAmount', Number(v) || 0)}
|
||||
inputClassName="h-8 text-sm"
|
||||
/>
|
||||
<FormField
|
||||
type="number"
|
||||
label="세액"
|
||||
value={item.taxAmount || ''}
|
||||
onChange={(v) => updateItem(index, 'taxAmount', Number(v) || 0)}
|
||||
inputClassName="h-8 text-sm"
|
||||
/>
|
||||
{/* 합계금액 - readOnly (FormField 미지원, 커스텀 인터랙션 예외) */}
|
||||
<div>
|
||||
<Label className="text-xs">합계금액</Label>
|
||||
<Input
|
||||
type="number"
|
||||
value={item.totalAmount}
|
||||
readOnly
|
||||
className="mt-1 h-8 text-sm bg-muted/50"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 계정과목 + 공제 + 증빙/판매자상호 */}
|
||||
<div className="grid grid-cols-3 gap-3">
|
||||
{/* Select - FormField 예외 */}
|
||||
<div>
|
||||
<Label className="text-xs">계정과목</Label>
|
||||
<Select
|
||||
value={item.accountSubject || 'none'}
|
||||
onValueChange={(v) => updateItem(index, 'accountSubject', v === 'none' ? '' : v)}
|
||||
>
|
||||
<SelectTrigger className="mt-1 h-8 text-sm">
|
||||
<SelectValue placeholder="선택" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="none">선택</SelectItem>
|
||||
{ACCOUNT_SUBJECT_OPTIONS.filter(o => o.value !== '').map(opt => (
|
||||
<SelectItem key={opt.value} value={opt.value}>{opt.label}</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
{/* Select - FormField 예외 */}
|
||||
<div>
|
||||
<Label className="text-xs">공제</Label>
|
||||
<Select
|
||||
value={item.deductionType}
|
||||
onValueChange={(v) => updateItem(index, 'deductionType', v)}
|
||||
>
|
||||
<SelectTrigger className="mt-1 h-8 text-sm">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{DEDUCTION_OPTIONS.map(opt => (
|
||||
<SelectItem key={opt.value} value={opt.value}>{opt.label}</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<FormField
|
||||
label="증빙/판매자상호"
|
||||
value={item.vendorName}
|
||||
onChange={(v) => updateItem(index, 'vendorName', v)}
|
||||
placeholder="내용"
|
||||
inputClassName="h-8 text-sm"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 내역 + 메모 */}
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<FormField
|
||||
label="내역"
|
||||
value={item.description}
|
||||
onChange={(v) => updateItem(index, 'description', v)}
|
||||
placeholder="내역"
|
||||
inputClassName="h-8 text-sm"
|
||||
/>
|
||||
<FormField
|
||||
label="메모"
|
||||
value={item.memo}
|
||||
onChange={(v) => updateItem(index, 'memo', v)}
|
||||
inputClassName="h-8 text-sm"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
|
||||
{/* 분개 항목 추가 버튼 */}
|
||||
<Button
|
||||
variant="outline"
|
||||
className="w-full"
|
||||
onClick={addItem}
|
||||
>
|
||||
<Plus className="h-4 w-4 mr-2" />
|
||||
분개 항목 추가
|
||||
</Button>
|
||||
|
||||
{/* 분개 합계 */}
|
||||
<div className="bg-muted/50 rounded-lg p-3 flex items-center justify-between">
|
||||
<span className="text-sm font-medium">분개 합계</span>
|
||||
<span className="text-lg font-bold">{journalTotal.toLocaleString()}원</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<DialogFooter className="gap-3">
|
||||
<Button variant="outline" onClick={() => onOpenChange(false)} disabled={isSubmitting}>
|
||||
취소
|
||||
</Button>
|
||||
<Button onClick={handleSave} disabled={isSubmitting}>
|
||||
{isSubmitting ? (
|
||||
<>
|
||||
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
|
||||
저장 중...
|
||||
</>
|
||||
) : (
|
||||
'저장'
|
||||
)}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,322 @@
|
||||
'use client';
|
||||
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { toast } from 'sonner';
|
||||
import { Loader2 } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { FormField } from '@/components/molecules/FormField';
|
||||
import { DatePicker } from '@/components/ui/date-picker';
|
||||
import { TimePicker } from '@/components/ui/time-picker';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogFooter,
|
||||
} from '@/components/ui/dialog';
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/components/ui/select';
|
||||
import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group';
|
||||
import type { ManualInputFormData } from './types';
|
||||
import { DEDUCTION_OPTIONS, ACCOUNT_SUBJECT_OPTIONS } from './types';
|
||||
import { getCardList, createCardTransaction } from './actions';
|
||||
|
||||
interface ManualInputModalProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
onSuccess: () => void;
|
||||
}
|
||||
|
||||
const initialFormData: ManualInputFormData = {
|
||||
cardId: '',
|
||||
usedDate: new Date().toISOString().slice(0, 10),
|
||||
usedTime: '',
|
||||
approvalNumber: '',
|
||||
approvalType: 'approved',
|
||||
supplyAmount: 0,
|
||||
taxAmount: 0,
|
||||
merchantName: '',
|
||||
businessNumber: '',
|
||||
deductionType: 'deductible',
|
||||
accountSubject: '',
|
||||
vendorName: '',
|
||||
description: '',
|
||||
memo: '',
|
||||
};
|
||||
|
||||
export function ManualInputModal({ open, onOpenChange, onSuccess }: ManualInputModalProps) {
|
||||
const [formData, setFormData] = useState<ManualInputFormData>(initialFormData);
|
||||
const [cardOptions, setCardOptions] = useState<Array<{ id: number; name: string; cardNumber: string }>>([]);
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
const [isLoadingCards, setIsLoadingCards] = useState(false);
|
||||
|
||||
// 카드 목록 로드
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
setIsLoadingCards(true);
|
||||
getCardList()
|
||||
.then(result => {
|
||||
if (result.success) setCardOptions(result.data);
|
||||
})
|
||||
.finally(() => setIsLoadingCards(false));
|
||||
setFormData(initialFormData);
|
||||
}
|
||||
}, [open]);
|
||||
|
||||
const handleChange = useCallback((key: keyof ManualInputFormData, value: string | number) => {
|
||||
setFormData(prev => ({ ...prev, [key]: value }));
|
||||
}, []);
|
||||
|
||||
const totalAmount = formData.supplyAmount + formData.taxAmount;
|
||||
|
||||
const handleSubmit = useCallback(async () => {
|
||||
if (!formData.cardId) {
|
||||
toast.error('카드를 선택해주세요.');
|
||||
return;
|
||||
}
|
||||
if (!formData.usedDate) {
|
||||
toast.error('사용일을 입력해주세요.');
|
||||
return;
|
||||
}
|
||||
if (formData.supplyAmount <= 0 && formData.taxAmount <= 0) {
|
||||
toast.error('공급가액 또는 세액을 입력해주세요.');
|
||||
return;
|
||||
}
|
||||
|
||||
setIsSubmitting(true);
|
||||
try {
|
||||
const result = await createCardTransaction(formData);
|
||||
if (result.success) {
|
||||
toast.success('카드사용 내역이 등록되었습니다.');
|
||||
onOpenChange(false);
|
||||
onSuccess();
|
||||
} else {
|
||||
toast.error(result.error || '등록에 실패했습니다.');
|
||||
}
|
||||
} catch {
|
||||
toast.error('등록 중 오류가 발생했습니다.');
|
||||
} finally {
|
||||
setIsSubmitting(false);
|
||||
}
|
||||
}, [formData, onOpenChange, onSuccess]);
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="sm:max-w-[600px] max-h-[90vh] overflow-y-auto">
|
||||
<DialogHeader>
|
||||
<DialogTitle>카드사용 수기 입력</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="space-y-4 py-2">
|
||||
{/* 카드 선택 (동적 API Select - FormField 예외) */}
|
||||
<div>
|
||||
<Label className="text-sm font-medium">
|
||||
카드 선택 <span className="text-red-500">*</span>
|
||||
</Label>
|
||||
<Select
|
||||
value={formData.cardId}
|
||||
onValueChange={(v) => handleChange('cardId', v)}
|
||||
disabled={isLoadingCards}
|
||||
>
|
||||
<SelectTrigger className="mt-1">
|
||||
<SelectValue placeholder="카드를 선택하세요" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{cardOptions.map(card => (
|
||||
<SelectItem key={card.id} value={String(card.id)}>
|
||||
{card.cardNumber} {card.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{/* 사용일 + 사용시간 (공통 DatePicker/TimePicker) */}
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<Label className="text-sm font-medium">
|
||||
사용일 <span className="text-red-500">*</span>
|
||||
</Label>
|
||||
<DatePicker
|
||||
value={formData.usedDate}
|
||||
onChange={(v) => handleChange('usedDate', v)}
|
||||
placeholder="날짜 선택"
|
||||
className="mt-1"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label className="text-sm font-medium">사용시간</Label>
|
||||
<TimePicker
|
||||
value={formData.usedTime}
|
||||
onChange={(v) => handleChange('usedTime', v)}
|
||||
placeholder="시간 선택"
|
||||
showSeconds
|
||||
secondStep={1}
|
||||
minuteStep={1}
|
||||
className="mt-1"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 승인번호 + 승인유형 */}
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<FormField
|
||||
label="승인번호"
|
||||
value={formData.approvalNumber}
|
||||
onChange={(v) => handleChange('approvalNumber', v)}
|
||||
placeholder="승인번호"
|
||||
/>
|
||||
<div>
|
||||
<Label className="text-sm font-medium">
|
||||
승인유형 <span className="text-red-500">*</span>
|
||||
</Label>
|
||||
<RadioGroup
|
||||
value={formData.approvalType}
|
||||
onValueChange={(v) => handleChange('approvalType', v)}
|
||||
className="flex items-center gap-4 mt-2"
|
||||
>
|
||||
<div className="flex items-center space-x-2">
|
||||
<RadioGroupItem value="approved" id="approval-approved" />
|
||||
<Label htmlFor="approval-approved" className="text-sm">승인</Label>
|
||||
</div>
|
||||
<div className="flex items-center space-x-2">
|
||||
<RadioGroupItem value="cancelled" id="approval-cancelled" />
|
||||
<Label htmlFor="approval-cancelled" className="text-sm">취소</Label>
|
||||
</div>
|
||||
</RadioGroup>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 공급가액 + 세액 */}
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<FormField
|
||||
type="number"
|
||||
label="공급가액"
|
||||
required
|
||||
value={formData.supplyAmount || ''}
|
||||
onChange={(v) => handleChange('supplyAmount', Number(v) || 0)}
|
||||
placeholder="0"
|
||||
/>
|
||||
<FormField
|
||||
type="number"
|
||||
label="세액"
|
||||
required
|
||||
value={formData.taxAmount || ''}
|
||||
onChange={(v) => handleChange('taxAmount', Number(v) || 0)}
|
||||
placeholder="0"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 가맹점명 + 사업자번호 */}
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<FormField
|
||||
label="가맹점명"
|
||||
value={formData.merchantName}
|
||||
onChange={(v) => handleChange('merchantName', v)}
|
||||
placeholder="가맹점명"
|
||||
/>
|
||||
<FormField
|
||||
type="businessNumber"
|
||||
label="사업자번호"
|
||||
value={formData.businessNumber}
|
||||
onChange={(v) => handleChange('businessNumber', v)}
|
||||
placeholder="123-12-12345"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 공제여부 + 계정과목 (Select - FormField 예외) */}
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<Label className="text-sm font-medium">
|
||||
공제여부 <span className="text-red-500">*</span>
|
||||
</Label>
|
||||
<Select
|
||||
value={formData.deductionType}
|
||||
onValueChange={(v) => handleChange('deductionType', v)}
|
||||
>
|
||||
<SelectTrigger className="mt-1">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{DEDUCTION_OPTIONS.map(opt => (
|
||||
<SelectItem key={opt.value} value={opt.value}>{opt.label}</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div>
|
||||
<Label className="text-sm font-medium">계정과목</Label>
|
||||
<Select
|
||||
value={formData.accountSubject || 'none'}
|
||||
onValueChange={(v) => handleChange('accountSubject', v === 'none' ? '' : v)}
|
||||
>
|
||||
<SelectTrigger className="mt-1">
|
||||
<SelectValue placeholder="선택" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="none">선택</SelectItem>
|
||||
{ACCOUNT_SUBJECT_OPTIONS.filter(o => o.value !== '').map(opt => (
|
||||
<SelectItem key={opt.value} value={opt.value}>{opt.label}</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 증빙/판매자상호 + 내역 */}
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<FormField
|
||||
label="증빙/판매자상호"
|
||||
value={formData.vendorName}
|
||||
onChange={(v) => handleChange('vendorName', v)}
|
||||
placeholder="증빙/판매자상호"
|
||||
/>
|
||||
<FormField
|
||||
label="내역"
|
||||
value={formData.description}
|
||||
onChange={(v) => handleChange('description', v)}
|
||||
placeholder="내역"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 메모 */}
|
||||
<FormField
|
||||
type="textarea"
|
||||
label="메모"
|
||||
value={formData.memo}
|
||||
onChange={(v) => handleChange('memo', v)}
|
||||
rows={3}
|
||||
/>
|
||||
|
||||
{/* 합계 금액 */}
|
||||
<div className="bg-muted/50 rounded-lg p-3 flex items-center justify-between">
|
||||
<span className="text-sm font-medium">합계 금액 (공급가액 + 세액)</span>
|
||||
<span className="text-lg font-bold">{totalAmount.toLocaleString()}원</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<DialogFooter className="gap-3">
|
||||
<Button variant="outline" onClick={() => onOpenChange(false)} disabled={isSubmitting}>
|
||||
취소
|
||||
</Button>
|
||||
<Button onClick={handleSubmit} disabled={isSubmitting}>
|
||||
{isSubmitting ? (
|
||||
<>
|
||||
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
|
||||
등록 중...
|
||||
</>
|
||||
) : (
|
||||
'등록'
|
||||
)}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
import { executeServerAction, type ActionResult } from '@/lib/api/execute-server-action';
|
||||
import { executePaginatedAction } from '@/lib/api/execute-paginated-action';
|
||||
import { buildApiUrl } from '@/lib/api/query-params';
|
||||
import type { CardTransaction } from './types';
|
||||
import type { CardTransaction, ManualInputFormData, InlineEditData, JournalEntryItem } from './types';
|
||||
|
||||
// ===== API 응답 타입 =====
|
||||
interface CardTransactionApiItem {
|
||||
@@ -14,8 +14,17 @@ interface CardTransactionApiItem {
|
||||
used_at: string | null;
|
||||
merchant_name: string | null;
|
||||
amount: number | string;
|
||||
supply_amount?: number | string;
|
||||
tax_amount?: number | string;
|
||||
business_number?: string | null;
|
||||
account_code: string | null;
|
||||
description: string | null;
|
||||
deduction_type?: string | null;
|
||||
approval_number?: string | null;
|
||||
approval_type?: string | null;
|
||||
is_hidden?: boolean;
|
||||
is_manual?: boolean;
|
||||
vendor_name?: string | null;
|
||||
card: {
|
||||
id: number;
|
||||
card_company: string;
|
||||
@@ -43,26 +52,131 @@ function transformItem(item: CardTransactionApiItem): CardTransaction {
|
||||
const usedAtDate = new Date(usedAtRaw);
|
||||
const usedAt = item.used_at ? usedAtDate.toISOString().slice(0, 16).replace('T', ' ') : item.withdrawal_date;
|
||||
|
||||
const totalAmount = typeof item.amount === 'string' ? parseFloat(item.amount) : item.amount;
|
||||
const supplyAmount = item.supply_amount
|
||||
? (typeof item.supply_amount === 'string' ? parseFloat(item.supply_amount) : item.supply_amount)
|
||||
: totalAmount;
|
||||
const taxAmount = item.tax_amount
|
||||
? (typeof item.tax_amount === 'string' ? parseFloat(item.tax_amount) : item.tax_amount)
|
||||
: 0;
|
||||
|
||||
return {
|
||||
id: String(item.id),
|
||||
card: cardDisplay,
|
||||
cardCompany: card?.card_company || '-',
|
||||
card: card ? `****${card.card_number_last4}` : '-',
|
||||
cardName: card?.card_name || '-',
|
||||
user: card?.assigned_user?.name || '-',
|
||||
usedAt,
|
||||
merchantName: item.merchant_name || item.description || '-',
|
||||
amount: typeof item.amount === 'string' ? parseFloat(item.amount) : item.amount,
|
||||
merchantName: item.merchant_name || '-',
|
||||
businessNumber: item.business_number || '-',
|
||||
vendorName: item.vendor_name || '',
|
||||
supplyAmount,
|
||||
taxAmount,
|
||||
totalAmount: supplyAmount + taxAmount || totalAmount,
|
||||
deductionType: item.deduction_type || 'deductible',
|
||||
accountSubject: item.account_code || '',
|
||||
description: item.description || '',
|
||||
approvalNumber: item.approval_number || undefined,
|
||||
approvalType: item.approval_type || undefined,
|
||||
isHidden: !!item.is_hidden,
|
||||
hiddenAt: (item as unknown as { hidden_at?: string }).hidden_at,
|
||||
isManual: !!item.is_manual,
|
||||
memo: '',
|
||||
amount: totalAmount,
|
||||
usageType: item.usage_type || '',
|
||||
createdAt: item.created_at,
|
||||
updatedAt: item.updated_at,
|
||||
};
|
||||
}
|
||||
|
||||
// ===== Mock 데이터 (개발용) =====
|
||||
function generateMockData(): CardTransaction[] {
|
||||
const cards = [
|
||||
{ company: '신한', number: '****3456', name: '법인카드1' },
|
||||
{ company: 'KB국민', number: '****7890', name: '법인카드2' },
|
||||
{ company: '현대', number: '****1234', name: '복리후생카드' },
|
||||
];
|
||||
const merchants = [
|
||||
{ name: '스타벅스 강남점', biz: '123-45-67890', vendor: '스타벅스코리아' },
|
||||
{ name: 'GS25 역삼점', biz: '234-56-78901', vendor: 'GS리테일' },
|
||||
{ name: '쿠팡', biz: '345-67-89012', vendor: '쿠팡(주)' },
|
||||
{ name: '교보문고 광화문', biz: '456-78-90123', vendor: '교보문고' },
|
||||
{ name: '현대주유소', biz: '567-89-01234', vendor: '현대오일뱅크' },
|
||||
{ name: '삼성전자 서비스', biz: '678-90-12345', vendor: '삼성전자서비스(주)' },
|
||||
{ name: 'CJ대한통운', biz: '789-01-23456', vendor: 'CJ대한통운(주)' },
|
||||
{ name: '올리브영 선릉점', biz: '890-12-34567', vendor: 'CJ올리브영' },
|
||||
];
|
||||
const descriptions = ['사무용품 구매', '직원 식대', '택배비', '교통비', '복리후생비', '광고비', '소모품비', '통신비'];
|
||||
const accounts = ['', 'purchasePayment', 'expenses', 'rent', 'salary', 'insurance', 'utilities'];
|
||||
const now = new Date();
|
||||
|
||||
return Array.from({ length: 15 }, (_, i) => {
|
||||
const card = cards[i % cards.length];
|
||||
const merchant = merchants[i % merchants.length];
|
||||
const supply = Math.round((Math.random() * 500000 + 10000) / 100) * 100;
|
||||
const tax = Math.round(supply * 0.1);
|
||||
const d = new Date(now);
|
||||
d.setDate(d.getDate() - i);
|
||||
const dateStr = d.toISOString().slice(0, 10);
|
||||
const timeStr = `${String(9 + (i % 10)).padStart(2, '0')}:${String((i * 17) % 60).padStart(2, '0')}`;
|
||||
|
||||
return {
|
||||
id: String(1000 + i),
|
||||
cardCompany: card.company,
|
||||
card: card.number,
|
||||
cardName: card.name,
|
||||
user: '홍길동',
|
||||
usedAt: `${dateStr} ${timeStr}`,
|
||||
merchantName: merchant.name,
|
||||
businessNumber: merchant.biz,
|
||||
vendorName: merchant.vendor,
|
||||
supplyAmount: supply,
|
||||
taxAmount: tax,
|
||||
totalAmount: supply + tax,
|
||||
deductionType: i % 3 === 0 ? 'non_deductible' : 'deductible',
|
||||
accountSubject: accounts[i % accounts.length],
|
||||
description: descriptions[i % descriptions.length],
|
||||
isHidden: false,
|
||||
isManual: i % 5 === 0,
|
||||
memo: '',
|
||||
amount: supply + tax,
|
||||
usageType: '',
|
||||
createdAt: dateStr,
|
||||
updatedAt: dateStr,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function generateMockHiddenData(): CardTransaction[] {
|
||||
return [
|
||||
{
|
||||
id: '9001', cardCompany: '신한', card: '****3456', cardName: '법인카드1',
|
||||
user: '홍길동', usedAt: '2026-02-10 14:30', merchantName: '이마트 역삼점',
|
||||
businessNumber: '111-22-33333', vendorName: '이마트(주)',
|
||||
supplyAmount: 45000, taxAmount: 4500, totalAmount: 49500,
|
||||
deductionType: 'deductible', accountSubject: '', description: '사무용품',
|
||||
isHidden: true, hiddenAt: '2026-02-12 09:15', isManual: false, memo: '', amount: 49500, usageType: '',
|
||||
createdAt: '2026-02-10', updatedAt: '2026-02-10',
|
||||
},
|
||||
{
|
||||
id: '9002', cardCompany: 'KB국민', card: '****7890', cardName: '법인카드2',
|
||||
user: '홍길동', usedAt: '2026-02-08 11:15', merchantName: '다이소 강남점',
|
||||
businessNumber: '222-33-44444', vendorName: '아성다이소',
|
||||
supplyAmount: 12000, taxAmount: 1200, totalAmount: 13200,
|
||||
deductionType: 'non_deductible', accountSubject: '', description: '소모품',
|
||||
isHidden: true, hiddenAt: '2026-02-11 16:40', isManual: false, memo: '', amount: 13200, usageType: '',
|
||||
createdAt: '2026-02-08', updatedAt: '2026-02-08',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
// ===== 카드 거래 목록 조회 =====
|
||||
export async function getCardTransactionList(params?: {
|
||||
page?: number; perPage?: number; startDate?: string; endDate?: string;
|
||||
cardId?: number; search?: string; sortBy?: string; sortDir?: 'asc' | 'desc';
|
||||
isHidden?: boolean;
|
||||
}) {
|
||||
return executePaginatedAction<CardTransactionApiItem, CardTransaction>({
|
||||
const result = await executePaginatedAction<CardTransactionApiItem, CardTransaction>({
|
||||
url: buildApiUrl('/api/v1/card-transactions', {
|
||||
page: params?.page,
|
||||
per_page: params?.perPage,
|
||||
@@ -72,17 +186,29 @@ export async function getCardTransactionList(params?: {
|
||||
search: params?.search,
|
||||
sort_by: params?.sortBy,
|
||||
sort_dir: params?.sortDir,
|
||||
is_hidden: params?.isHidden,
|
||||
}),
|
||||
transform: transformItem,
|
||||
errorMessage: '카드 거래 조회에 실패했습니다.',
|
||||
});
|
||||
|
||||
// API 빈 응답 시 mock fallback (개발용)
|
||||
if (result.success && result.data.length === 0) {
|
||||
const mockData = generateMockData();
|
||||
return {
|
||||
...result,
|
||||
data: mockData,
|
||||
pagination: { currentPage: 1, lastPage: 1, perPage: 20, total: mockData.length },
|
||||
};
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// ===== 카드 거래 요약 통계 =====
|
||||
export async function getCardTransactionSummary(params?: {
|
||||
startDate?: string; endDate?: string;
|
||||
}): Promise<ActionResult<{ previousMonthTotal: number; currentMonthTotal: number; totalCount: number; totalAmount: number }>> {
|
||||
return executeServerAction({
|
||||
const result = await executeServerAction({
|
||||
url: buildApiUrl('/api/v1/card-transactions/summary', {
|
||||
start_date: params?.startDate,
|
||||
end_date: params?.endDate,
|
||||
@@ -95,6 +221,15 @@ export async function getCardTransactionSummary(params?: {
|
||||
}),
|
||||
errorMessage: '요약 조회에 실패했습니다.',
|
||||
});
|
||||
|
||||
// Mock fallback (개발용)
|
||||
if (!result.success || !result.data) {
|
||||
return {
|
||||
success: true,
|
||||
data: { previousMonthTotal: 8542300, currentMonthTotal: 10802897, totalCount: 15, totalAmount: 10802897 },
|
||||
};
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// ===== 카드 거래 단건 조회 =====
|
||||
@@ -106,19 +241,33 @@ export async function getCardTransactionById(id: string): Promise<ActionResult<C
|
||||
});
|
||||
}
|
||||
|
||||
// ===== 카드 거래 등록 =====
|
||||
export async function createCardTransaction(data: {
|
||||
cardId?: number; usedAt: string; merchantName: string; amount: number; memo?: string; usageType?: string;
|
||||
}): Promise<ActionResult<CardTransaction>> {
|
||||
// ===== 카드 거래 등록 (수기 입력) =====
|
||||
export async function createCardTransaction(data: ManualInputFormData): Promise<ActionResult<CardTransaction>> {
|
||||
const usedAt = data.usedTime
|
||||
? `${data.usedDate} ${data.usedTime}`
|
||||
: data.usedDate;
|
||||
|
||||
return executeServerAction({
|
||||
url: buildApiUrl('/api/v1/card-transactions'),
|
||||
method: 'POST',
|
||||
body: {
|
||||
card_id: data.cardId, used_at: data.usedAt, merchant_name: data.merchantName,
|
||||
amount: data.amount, description: data.memo,
|
||||
account_code: data.usageType === 'unset' ? null : data.usageType,
|
||||
card_id: data.cardId ? Number(data.cardId) : undefined,
|
||||
used_at: usedAt,
|
||||
merchant_name: data.merchantName,
|
||||
supply_amount: data.supplyAmount,
|
||||
tax_amount: data.taxAmount,
|
||||
amount: data.supplyAmount + data.taxAmount,
|
||||
business_number: data.businessNumber || undefined,
|
||||
deduction_type: data.deductionType,
|
||||
account_code: data.accountSubject || undefined,
|
||||
approval_number: data.approvalNumber || undefined,
|
||||
approval_type: data.approvalType,
|
||||
description: data.description || undefined,
|
||||
vendor_name: data.vendorName || undefined,
|
||||
memo: data.memo || undefined,
|
||||
is_manual: true,
|
||||
},
|
||||
transform: (data: CardTransactionApiItem) => transformItem(data),
|
||||
transform: (resp: CardTransactionApiItem) => transformItem(resp),
|
||||
errorMessage: '등록에 실패했습니다.',
|
||||
});
|
||||
}
|
||||
@@ -134,7 +283,7 @@ export async function updateCardTransaction(id: string, data: {
|
||||
used_at: data.usedAt, merchant_name: data.merchantName, amount: data.amount,
|
||||
description: data.memo, account_code: data.usageType === 'unset' ? null : data.usageType,
|
||||
},
|
||||
transform: (data: CardTransactionApiItem) => transformItem(data),
|
||||
transform: (resp: CardTransactionApiItem) => transformItem(resp),
|
||||
errorMessage: '수정에 실패했습니다.',
|
||||
});
|
||||
}
|
||||
@@ -177,3 +326,112 @@ export async function bulkUpdateAccountCode(ids: number[], accountCode: string):
|
||||
});
|
||||
return { success: result.success, updatedCount: result.data?.updatedCount, error: result.error };
|
||||
}
|
||||
|
||||
// ===== 인라인 편집 일괄 저장 =====
|
||||
export async function bulkSaveInlineEdits(
|
||||
edits: Record<string, InlineEditData>
|
||||
): Promise<ActionResult> {
|
||||
const items = Object.entries(edits).map(([id, data]) => ({
|
||||
id: Number(id),
|
||||
deduction_type: data.deductionType,
|
||||
account_code: data.accountSubject,
|
||||
description: data.description,
|
||||
}));
|
||||
|
||||
return executeServerAction({
|
||||
url: buildApiUrl('/api/v1/card-transactions/bulk-update'),
|
||||
method: 'PUT',
|
||||
body: { items },
|
||||
errorMessage: '일괄 저장에 실패했습니다.',
|
||||
});
|
||||
}
|
||||
|
||||
// ===== 거래 숨김 처리 =====
|
||||
export async function hideTransaction(id: string): Promise<ActionResult> {
|
||||
return executeServerAction({
|
||||
url: buildApiUrl(`/api/v1/card-transactions/${id}/hide`),
|
||||
method: 'PUT',
|
||||
errorMessage: '숨김 처리에 실패했습니다.',
|
||||
});
|
||||
}
|
||||
|
||||
// ===== 거래 숨김 해제 (복원) =====
|
||||
export async function unhideTransaction(id: string): Promise<ActionResult> {
|
||||
return executeServerAction({
|
||||
url: buildApiUrl(`/api/v1/card-transactions/${id}/unhide`),
|
||||
method: 'PUT',
|
||||
errorMessage: '복원에 실패했습니다.',
|
||||
});
|
||||
}
|
||||
|
||||
// ===== 숨김 처리된 거래 목록 =====
|
||||
export async function getHiddenTransactions(params?: {
|
||||
startDate?: string; endDate?: string;
|
||||
}) {
|
||||
const result = await executePaginatedAction<CardTransactionApiItem, CardTransaction>({
|
||||
url: buildApiUrl('/api/v1/card-transactions', {
|
||||
start_date: params?.startDate,
|
||||
end_date: params?.endDate,
|
||||
is_hidden: true,
|
||||
}),
|
||||
transform: transformItem,
|
||||
errorMessage: '숨김 거래 조회에 실패했습니다.',
|
||||
});
|
||||
|
||||
// Mock fallback (개발용)
|
||||
if (result.success && result.data.length === 0) {
|
||||
const mockHidden = generateMockHiddenData();
|
||||
return { ...result, data: mockHidden, pagination: { currentPage: 1, lastPage: 1, perPage: 20, total: mockHidden.length } };
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// ===== 분개 항목 저장 =====
|
||||
export async function saveJournalEntries(
|
||||
transactionId: string,
|
||||
items: JournalEntryItem[]
|
||||
): Promise<ActionResult> {
|
||||
return executeServerAction({
|
||||
url: buildApiUrl(`/api/v1/card-transactions/${transactionId}/journal-entries`),
|
||||
method: 'POST',
|
||||
body: {
|
||||
items: items.map(item => ({
|
||||
supply_amount: item.supplyAmount,
|
||||
tax_amount: item.taxAmount,
|
||||
account_code: item.accountSubject,
|
||||
deduction_type: item.deductionType,
|
||||
vendor_name: item.vendorName,
|
||||
description: item.description,
|
||||
memo: item.memo,
|
||||
})),
|
||||
},
|
||||
errorMessage: '분개 저장에 실패했습니다.',
|
||||
});
|
||||
}
|
||||
|
||||
// ===== 분개 항목 조회 =====
|
||||
export async function getJournalEntries(
|
||||
transactionId: string
|
||||
): Promise<ActionResult<JournalEntryItem[]>> {
|
||||
return executeServerAction({
|
||||
url: buildApiUrl(`/api/v1/card-transactions/${transactionId}/journal-entries`),
|
||||
transform: (data: { items?: Array<{
|
||||
id?: number; supply_amount: number; tax_amount: number;
|
||||
account_code: string; deduction_type: string; vendor_name: string;
|
||||
description: string; memo: string;
|
||||
}> }) => {
|
||||
return (data.items || []).map(item => ({
|
||||
id: item.id ? String(item.id) : undefined,
|
||||
supplyAmount: item.supply_amount,
|
||||
taxAmount: item.tax_amount,
|
||||
totalAmount: item.supply_amount + item.tax_amount,
|
||||
accountSubject: item.account_code || '',
|
||||
deductionType: item.deduction_type || 'deductible',
|
||||
vendorName: item.vendor_name || '',
|
||||
description: item.description || '',
|
||||
memo: item.memo || '',
|
||||
}));
|
||||
},
|
||||
errorMessage: '분개 조회에 실패했습니다.',
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,127 +0,0 @@
|
||||
import { CreditCard } from 'lucide-react';
|
||||
import type { DetailConfig, FieldDefinition } from '@/components/templates/IntegratedDetailTemplate/types';
|
||||
import type { CardTransaction } from './types';
|
||||
import { USAGE_TYPE_OPTIONS } from './types';
|
||||
import { getCardList } from './actions';
|
||||
|
||||
// ===== 필드 정의 =====
|
||||
const fields: FieldDefinition[] = [
|
||||
// 카드 선택 (create에서만 선택 가능)
|
||||
{
|
||||
key: 'cardId',
|
||||
label: '카드',
|
||||
type: 'select',
|
||||
required: true,
|
||||
placeholder: '카드를 선택해주세요',
|
||||
fetchOptions: async () => {
|
||||
const result = await getCardList();
|
||||
if (result.success) {
|
||||
return result.data.map((card) => ({
|
||||
value: String(card.id),
|
||||
label: `${card.name} (${card.cardNumber})`,
|
||||
}));
|
||||
}
|
||||
return [];
|
||||
},
|
||||
disabled: (mode) => mode === 'view',
|
||||
},
|
||||
// 사용일시
|
||||
{
|
||||
key: 'usedAt',
|
||||
label: '사용일시',
|
||||
type: 'datetime-local',
|
||||
required: true,
|
||||
placeholder: '사용일시를 선택해주세요',
|
||||
disabled: (mode) => mode === 'view',
|
||||
},
|
||||
// 가맹점명
|
||||
{
|
||||
key: 'merchantName',
|
||||
label: '가맹점명',
|
||||
type: 'text',
|
||||
required: true,
|
||||
placeholder: '가맹점명을 입력해주세요',
|
||||
disabled: (mode) => mode === 'view',
|
||||
},
|
||||
// 사용금액
|
||||
{
|
||||
key: 'amount',
|
||||
label: '사용금액',
|
||||
type: 'number',
|
||||
required: true,
|
||||
placeholder: '사용금액을 입력해주세요',
|
||||
disabled: (mode) => mode === 'view',
|
||||
},
|
||||
// 적요
|
||||
{
|
||||
key: 'memo',
|
||||
label: '적요',
|
||||
type: 'text',
|
||||
placeholder: '적요를 입력해주세요',
|
||||
gridSpan: 2,
|
||||
disabled: (mode) => mode === 'view',
|
||||
},
|
||||
// 사용유형
|
||||
{
|
||||
key: 'usageType',
|
||||
label: '사용유형',
|
||||
type: 'select',
|
||||
placeholder: '선택',
|
||||
options: USAGE_TYPE_OPTIONS.map((opt) => ({
|
||||
value: opt.value,
|
||||
label: opt.label,
|
||||
})),
|
||||
disabled: (mode) => mode === 'view',
|
||||
},
|
||||
];
|
||||
|
||||
// ===== Config 정의 =====
|
||||
export const cardTransactionDetailConfig: DetailConfig = {
|
||||
title: '카드 사용내역',
|
||||
description: '카드 사용 내역을 등록/수정합니다',
|
||||
icon: CreditCard,
|
||||
basePath: '/accounting/card-transactions',
|
||||
fields,
|
||||
gridColumns: 2,
|
||||
actions: {
|
||||
showBack: true,
|
||||
showDelete: true,
|
||||
showEdit: true,
|
||||
backLabel: '목록',
|
||||
deleteLabel: '삭제',
|
||||
editLabel: '수정',
|
||||
deleteConfirmMessage: {
|
||||
title: '카드 사용내역 삭제',
|
||||
description: '이 카드 사용내역을 삭제하시겠습니까? 삭제된 데이터는 복구할 수 없습니다.',
|
||||
},
|
||||
},
|
||||
transformInitialData: (data: Record<string, unknown>): Record<string, unknown> => {
|
||||
const record = data as unknown as CardTransaction;
|
||||
// DevFill에서 전달된 cardId 또는 기존 데이터의 cardId
|
||||
const inputCardId = (data as Record<string, unknown>).cardId;
|
||||
// usedAt을 datetime-local 형식으로 변환 (YYYY-MM-DDTHH:mm)
|
||||
let usedAtFormatted = '';
|
||||
if (record.usedAt) {
|
||||
// "2025-01-22 14:30" 형식을 "2025-01-22T14:30" 형식으로 변환
|
||||
usedAtFormatted = record.usedAt.replace(' ', 'T').slice(0, 16);
|
||||
}
|
||||
return {
|
||||
cardId: inputCardId ? String(inputCardId) : '', // create 모드에서 DevFill로 전달된 cardId 사용
|
||||
usedAt: usedAtFormatted,
|
||||
merchantName: record.merchantName || '',
|
||||
amount: record.amount || 0,
|
||||
memo: record.memo || '',
|
||||
usageType: record.usageType || 'unset',
|
||||
};
|
||||
},
|
||||
transformSubmitData: (formData: Record<string, unknown>) => {
|
||||
return {
|
||||
cardId: formData.cardId ? Number(formData.cardId) : undefined,
|
||||
usedAt: formData.usedAt as string,
|
||||
merchantName: formData.merchantName as string,
|
||||
amount: Number(formData.amount),
|
||||
memo: formData.memo as string,
|
||||
usageType: formData.usageType as string,
|
||||
};
|
||||
},
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,20 +1,83 @@
|
||||
// ===== 카드 내역 조회 타입 정의 =====
|
||||
// ===== 카드 사용내역 타입 정의 =====
|
||||
|
||||
// 카드 거래 레코드
|
||||
export interface CardTransaction {
|
||||
id: string;
|
||||
card: string; // 카드 (신한 1234 등)
|
||||
cardCompany: string; // 카드사 (신한, KB 등)
|
||||
card: string; // 카드번호 표시 (****1234 등)
|
||||
cardName: string; // 카드명 (법인카드1 등)
|
||||
user: string; // 사용자
|
||||
usedAt: string; // 사용일시
|
||||
merchantName: string; // 가맹점명
|
||||
amount: number; // 사용금액
|
||||
memo?: string; // 적요
|
||||
usageType: string; // 사용유형
|
||||
businessNumber: string; // 사업자번호
|
||||
vendorName: string; // 증빙/판매자상호
|
||||
supplyAmount: number; // 공급가액
|
||||
taxAmount: number; // 세액
|
||||
totalAmount: number; // 합계금액 (공급가액 + 세액)
|
||||
deductionType: string; // 공제여부 (deductible | non_deductible)
|
||||
accountSubject: string; // 계정과목
|
||||
description: string; // 내역
|
||||
approvalNumber?: string; // 승인번호
|
||||
approvalType?: string; // 승인유형 (approved | cancelled)
|
||||
isHidden: boolean; // 숨김 여부
|
||||
hiddenAt?: string; // 숨김일시
|
||||
isManual: boolean; // 수기 입력 여부
|
||||
memo?: string; // 메모
|
||||
// 하위 호환용 (기존 필드)
|
||||
amount: number; // 사용금액 (totalAmount과 동일)
|
||||
usageType: string; // 사용유형 (기존 호환)
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
// 분개 항목
|
||||
export interface JournalEntryItem {
|
||||
id?: string;
|
||||
supplyAmount: number; // 공급가액
|
||||
taxAmount: number; // 세액
|
||||
totalAmount: number; // 합계금액
|
||||
accountSubject: string; // 계정과목
|
||||
deductionType: string; // 공제여부
|
||||
vendorName: string; // 증빙/판매자상호
|
||||
description: string; // 내역
|
||||
memo: string; // 메모
|
||||
}
|
||||
|
||||
// 분개 데이터
|
||||
export interface JournalEntry {
|
||||
transactionId: string;
|
||||
items: JournalEntryItem[];
|
||||
totalAmount: number; // 분개 합계
|
||||
}
|
||||
|
||||
// 인라인 편집 데이터
|
||||
export interface InlineEditData {
|
||||
deductionType?: string;
|
||||
accountSubject?: string;
|
||||
vendorName?: string;
|
||||
description?: string;
|
||||
supplyAmount?: number;
|
||||
taxAmount?: number;
|
||||
}
|
||||
|
||||
// 수기 입력 폼 데이터
|
||||
export interface ManualInputFormData {
|
||||
cardId: string;
|
||||
usedDate: string; // yyyy-MM-dd
|
||||
usedTime: string; // HH:mm:ss
|
||||
approvalNumber: string;
|
||||
approvalType: 'approved' | 'cancelled';
|
||||
supplyAmount: number;
|
||||
taxAmount: number;
|
||||
merchantName: string;
|
||||
businessNumber: string;
|
||||
deductionType: string;
|
||||
accountSubject: string;
|
||||
vendorName: string; // 증빙/판매자상호
|
||||
description: string; // 내역
|
||||
memo: string;
|
||||
}
|
||||
|
||||
// 정렬 옵션
|
||||
export type SortOption = 'latest' | 'oldest' | 'amountHigh' | 'amountLow';
|
||||
|
||||
@@ -27,6 +90,12 @@ export const SORT_OPTIONS: { value: SortOption; label: string }[] = [
|
||||
{ value: 'amountLow', label: '금액낮은순' },
|
||||
];
|
||||
|
||||
// ===== 공제여부 옵션 =====
|
||||
export const DEDUCTION_OPTIONS = [
|
||||
{ value: 'deductible', label: '공제' },
|
||||
{ value: 'non_deductible', label: '불공제' },
|
||||
];
|
||||
|
||||
// ===== 사용유형 옵션 =====
|
||||
export const USAGE_TYPE_OPTIONS = [
|
||||
{ value: 'unset', label: '미설정' },
|
||||
@@ -49,9 +118,9 @@ export const USAGE_TYPE_OPTIONS = [
|
||||
{ value: 'miscellaneous', label: '잡비' },
|
||||
];
|
||||
|
||||
// ===== 계정과목명 옵션 (상단 셀렉트) =====
|
||||
// ===== 계정과목 옵션 =====
|
||||
export const ACCOUNT_SUBJECT_OPTIONS = [
|
||||
{ value: 'unset', label: '미설정' },
|
||||
{ value: '', label: '선택' },
|
||||
{ value: 'purchasePayment', label: '매입대금' },
|
||||
{ value: 'advance', label: '선급금' },
|
||||
{ value: 'suspense', label: '가지급금' },
|
||||
@@ -67,4 +136,14 @@ export const ACCOUNT_SUBJECT_OPTIONS = [
|
||||
{ value: 'utilities', label: '공과금' },
|
||||
{ value: 'expenses', label: '경비' },
|
||||
{ value: 'other', label: '기타' },
|
||||
];
|
||||
];
|
||||
|
||||
// ===== 월 프리셋 옵션 =====
|
||||
export const MONTH_PRESETS = [
|
||||
{ label: '이번달', value: 0 },
|
||||
{ label: '저번달', value: -1 },
|
||||
{ label: 'D-2달', value: -2 },
|
||||
{ label: 'D-3달', value: -3 },
|
||||
{ label: 'D-4달', value: -4 },
|
||||
{ label: 'D-5달', value: -5 },
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user