852 lines
41 KiB
PHP
852 lines
41 KiB
PHP
@extends('layouts.app')
|
|
|
|
@section('title', '법인카드 거래내역')
|
|
|
|
@push('styles')
|
|
<style>
|
|
@media print {
|
|
.no-print { display: none !important; }
|
|
}
|
|
</style>
|
|
@endpush
|
|
|
|
@section('content')
|
|
<div id="card-transactions-root"></div>
|
|
@endsection
|
|
|
|
@push('scripts')
|
|
<script src="https://unpkg.com/react@18/umd/react.development.js?v={{ time() }}"></script>
|
|
<script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js?v={{ time() }}"></script>
|
|
<script src="https://unpkg.com/@babel/standalone/babel.min.js?v={{ time() }}"></script>
|
|
<script src="https://unpkg.com/lucide@latest?v={{ time() }}"></script>
|
|
@verbatim
|
|
<script type="text/babel">
|
|
const { useState, useRef, useEffect } = React;
|
|
|
|
// Lucide 아이콘 래핑
|
|
const createIcon = (name) => ({ className = "w-5 h-5", ...props }) => {
|
|
const ref = useRef(null);
|
|
useEffect(() => {
|
|
if (ref.current && lucide.icons[name]) {
|
|
ref.current.innerHTML = '';
|
|
const svg = lucide.createElement(lucide.icons[name]);
|
|
svg.setAttribute('class', className);
|
|
ref.current.appendChild(svg);
|
|
}
|
|
}, [className]);
|
|
return <span ref={ref} className="inline-flex items-center" {...props} />;
|
|
};
|
|
|
|
const CreditCard = createIcon('credit-card');
|
|
const Plus = createIcon('plus');
|
|
const Search = createIcon('search');
|
|
const Filter = createIcon('filter');
|
|
const Download = createIcon('download');
|
|
const Calendar = createIcon('calendar');
|
|
const X = createIcon('x');
|
|
const Edit = createIcon('edit');
|
|
const Trash2 = createIcon('trash-2');
|
|
const Receipt = createIcon('receipt');
|
|
const TrendingUp = createIcon('trending-up');
|
|
const TrendingDown = createIcon('trending-down');
|
|
const ShoppingBag = createIcon('shopping-bag');
|
|
const Coffee = createIcon('coffee');
|
|
const Car = createIcon('car');
|
|
const Utensils = createIcon('utensils');
|
|
const Building = createIcon('building');
|
|
const MoreHorizontal = createIcon('more-horizontal');
|
|
const ChevronLeft = createIcon('chevron-left');
|
|
const ChevronRight = createIcon('chevron-right');
|
|
|
|
function CardTransactionsManagement() {
|
|
// 카드 목록 (실제로는 API에서 가져옴)
|
|
const [cards] = useState([
|
|
{ id: 1, cardName: '업무용 법인카드', cardNumber: '9410-****-****-9012', holder: '김대표' },
|
|
{ id: 2, cardName: '마케팅 법인카드', cardNumber: '5412-****-****-1098', holder: '박마케팅' },
|
|
{ id: 3, cardName: '개발팀 체크카드', cardNumber: '4532-****-****-3333', holder: '이개발' },
|
|
]);
|
|
|
|
// 거래내역 데이터
|
|
const [transactions, setTransactions] = useState([
|
|
{
|
|
id: 1,
|
|
cardId: 1,
|
|
date: '2026-01-21',
|
|
time: '12:30',
|
|
merchant: '스타벅스 강남역점',
|
|
category: '식비',
|
|
amount: 15000,
|
|
approvalNo: '12345678',
|
|
status: 'approved',
|
|
memo: '팀 미팅'
|
|
},
|
|
{
|
|
id: 2,
|
|
cardId: 1,
|
|
date: '2026-01-21',
|
|
time: '14:20',
|
|
merchant: 'AWS Korea',
|
|
category: '운영비',
|
|
amount: 2500000,
|
|
approvalNo: '23456789',
|
|
status: 'approved',
|
|
memo: '1월 클라우드 비용'
|
|
},
|
|
{
|
|
id: 3,
|
|
cardId: 2,
|
|
date: '2026-01-21',
|
|
time: '10:15',
|
|
merchant: '네이버 광고',
|
|
category: '마케팅비',
|
|
amount: 500000,
|
|
approvalNo: '34567890',
|
|
status: 'approved',
|
|
memo: '검색광고 충전'
|
|
},
|
|
{
|
|
id: 4,
|
|
cardId: 1,
|
|
date: '2026-01-20',
|
|
time: '18:45',
|
|
merchant: '교보문고 광화문점',
|
|
category: '도서/교육',
|
|
amount: 89000,
|
|
approvalNo: '45678901',
|
|
status: 'approved',
|
|
memo: '개발 서적 구매'
|
|
},
|
|
{
|
|
id: 5,
|
|
cardId: 3,
|
|
date: '2026-01-20',
|
|
time: '16:30',
|
|
merchant: '쿠팡',
|
|
category: '사무용품',
|
|
amount: 156000,
|
|
approvalNo: '56789012',
|
|
status: 'approved',
|
|
memo: '모니터 거치대, 키보드'
|
|
},
|
|
{
|
|
id: 6,
|
|
cardId: 1,
|
|
date: '2026-01-19',
|
|
time: '19:20',
|
|
merchant: '한우명가',
|
|
category: '접대비',
|
|
amount: 450000,
|
|
approvalNo: '67890123',
|
|
status: 'approved',
|
|
memo: '고객사 미팅 식사'
|
|
},
|
|
{
|
|
id: 7,
|
|
cardId: 2,
|
|
date: '2026-01-19',
|
|
time: '11:00',
|
|
merchant: 'Google Ads',
|
|
category: '마케팅비',
|
|
amount: 800000,
|
|
approvalNo: '78901234',
|
|
status: 'approved',
|
|
memo: '디스플레이 광고'
|
|
},
|
|
{
|
|
id: 8,
|
|
cardId: 1,
|
|
date: '2026-01-18',
|
|
time: '09:30',
|
|
merchant: 'KTX 예매',
|
|
category: '교통비',
|
|
amount: 112000,
|
|
approvalNo: '89012345',
|
|
status: 'approved',
|
|
memo: '부산 출장'
|
|
},
|
|
{
|
|
id: 9,
|
|
cardId: 3,
|
|
date: '2026-01-18',
|
|
time: '15:00',
|
|
merchant: '다나와',
|
|
category: '장비구매',
|
|
amount: 1890000,
|
|
approvalNo: '90123456',
|
|
status: 'approved',
|
|
memo: '개발용 노트북 SSD 업그레이드'
|
|
},
|
|
{
|
|
id: 10,
|
|
cardId: 1,
|
|
date: '2026-01-17',
|
|
time: '13:00',
|
|
merchant: '취소-스타벅스',
|
|
category: '식비',
|
|
amount: -8500,
|
|
approvalNo: '01234567',
|
|
status: 'cancelled',
|
|
memo: '주문 취소'
|
|
}
|
|
]);
|
|
|
|
// 필터 상태
|
|
const [searchTerm, setSearchTerm] = useState('');
|
|
const [filterCard, setFilterCard] = useState('all');
|
|
const [filterCategory, setFilterCategory] = useState('all');
|
|
const [filterStatus, setFilterStatus] = useState('all');
|
|
const [dateRange, setDateRange] = useState({
|
|
start: new Date(new Date().setDate(new Date().getDate() - 30)).toISOString().split('T')[0],
|
|
end: new Date().toISOString().split('T')[0]
|
|
});
|
|
|
|
// 모달 상태
|
|
const [showModal, setShowModal] = useState(false);
|
|
const [modalMode, setModalMode] = useState('add');
|
|
const [editingTransaction, setEditingTransaction] = useState(null);
|
|
|
|
// 폼 초기값
|
|
const initialFormState = {
|
|
cardId: 1,
|
|
date: new Date().toISOString().split('T')[0],
|
|
time: '',
|
|
merchant: '',
|
|
category: '식비',
|
|
amount: '',
|
|
approvalNo: '',
|
|
status: 'approved',
|
|
memo: ''
|
|
};
|
|
const [formData, setFormData] = useState(initialFormState);
|
|
|
|
// 카테고리 목록
|
|
const categories = ['식비', '교통비', '운영비', '마케팅비', '사무용품', '도서/교육', '접대비', '장비구매', '기타'];
|
|
|
|
// 카테고리 아이콘
|
|
const getCategoryIcon = (category) => {
|
|
switch (category) {
|
|
case '식비': return <Utensils className="w-4 h-4" />;
|
|
case '교통비': return <Car className="w-4 h-4" />;
|
|
case '마케팅비': return <TrendingUp className="w-4 h-4" />;
|
|
case '접대비': return <Coffee className="w-4 h-4" />;
|
|
case '사무용품':
|
|
case '장비구매': return <ShoppingBag className="w-4 h-4" />;
|
|
case '운영비': return <Building className="w-4 h-4" />;
|
|
default: return <Receipt className="w-4 h-4" />;
|
|
}
|
|
};
|
|
|
|
// 카테고리 색상
|
|
const getCategoryColor = (category) => {
|
|
const colors = {
|
|
'식비': 'bg-orange-100 text-orange-700',
|
|
'교통비': 'bg-blue-100 text-blue-700',
|
|
'운영비': 'bg-purple-100 text-purple-700',
|
|
'마케팅비': 'bg-pink-100 text-pink-700',
|
|
'사무용품': 'bg-gray-100 text-gray-700',
|
|
'도서/교육': 'bg-emerald-100 text-emerald-700',
|
|
'접대비': 'bg-amber-100 text-amber-700',
|
|
'장비구매': 'bg-indigo-100 text-indigo-700',
|
|
'기타': 'bg-slate-100 text-slate-700'
|
|
};
|
|
return colors[category] || 'bg-gray-100 text-gray-700';
|
|
};
|
|
|
|
// 금액 포맷
|
|
const formatCurrency = (num) => {
|
|
if (!num) return '0';
|
|
return num.toLocaleString();
|
|
};
|
|
|
|
// 입력용 금액 포맷 (3자리 콤마)
|
|
const formatInputCurrency = (value) => {
|
|
if (!value && value !== 0) return '';
|
|
const num = String(value).replace(/[^\d-]/g, '');
|
|
if (!num) return '';
|
|
const isNegative = num.startsWith('-');
|
|
const absNum = num.replace('-', '');
|
|
if (!absNum) return isNegative ? '-' : '';
|
|
return (isNegative ? '-' : '') + Number(absNum).toLocaleString();
|
|
};
|
|
|
|
// 입력값에서 숫자만 추출
|
|
const parseInputCurrency = (value) => {
|
|
const num = String(value).replace(/[^\d-]/g, '');
|
|
return num;
|
|
};
|
|
|
|
// 필터링된 거래내역
|
|
const filteredTransactions = transactions.filter(tx => {
|
|
const matchesSearch = tx.merchant.toLowerCase().includes(searchTerm.toLowerCase()) ||
|
|
tx.memo.toLowerCase().includes(searchTerm.toLowerCase()) ||
|
|
tx.approvalNo.includes(searchTerm);
|
|
const matchesCard = filterCard === 'all' || tx.cardId === parseInt(filterCard);
|
|
const matchesCategory = filterCategory === 'all' || tx.category === filterCategory;
|
|
const matchesStatus = filterStatus === 'all' || tx.status === filterStatus;
|
|
const matchesDate = tx.date >= dateRange.start && tx.date <= dateRange.end;
|
|
return matchesSearch && matchesCard && matchesCategory && matchesStatus && matchesDate;
|
|
}).sort((a, b) => {
|
|
if (a.date !== b.date) return b.date.localeCompare(a.date);
|
|
return b.time.localeCompare(a.time);
|
|
});
|
|
|
|
// 통계 계산
|
|
const totalAmount = filteredTransactions.reduce((sum, tx) => sum + tx.amount, 0);
|
|
const approvedAmount = filteredTransactions.filter(tx => tx.status === 'approved').reduce((sum, tx) => sum + tx.amount, 0);
|
|
const cancelledAmount = filteredTransactions.filter(tx => tx.status === 'cancelled').reduce((sum, tx) => sum + Math.abs(tx.amount), 0);
|
|
|
|
// 카테고리별 합계
|
|
const categoryTotals = filteredTransactions
|
|
.filter(tx => tx.status === 'approved' && tx.amount > 0)
|
|
.reduce((acc, tx) => {
|
|
acc[tx.category] = (acc[tx.category] || 0) + tx.amount;
|
|
return acc;
|
|
}, {});
|
|
|
|
// 거래 추가 모달 열기
|
|
const handleAddTransaction = () => {
|
|
setModalMode('add');
|
|
setFormData(initialFormState);
|
|
setShowModal(true);
|
|
};
|
|
|
|
// 거래 수정 모달 열기
|
|
const handleEditTransaction = (transaction) => {
|
|
setModalMode('edit');
|
|
setEditingTransaction(transaction);
|
|
setFormData({
|
|
cardId: transaction.cardId,
|
|
date: transaction.date,
|
|
time: transaction.time,
|
|
merchant: transaction.merchant,
|
|
category: transaction.category,
|
|
amount: transaction.amount,
|
|
approvalNo: transaction.approvalNo,
|
|
status: transaction.status,
|
|
memo: transaction.memo
|
|
});
|
|
setShowModal(true);
|
|
};
|
|
|
|
// 저장
|
|
const handleSave = () => {
|
|
if (!formData.merchant || !formData.amount) {
|
|
alert('가맹점명과 금액을 입력해주세요.');
|
|
return;
|
|
}
|
|
|
|
if (modalMode === 'add') {
|
|
const newTransaction = {
|
|
id: Date.now(),
|
|
...formData,
|
|
cardId: parseInt(formData.cardId),
|
|
amount: parseInt(formData.amount) || 0,
|
|
time: formData.time || new Date().toTimeString().slice(0, 5)
|
|
};
|
|
setTransactions(prev => [newTransaction, ...prev]);
|
|
} else {
|
|
setTransactions(prev => prev.map(tx =>
|
|
tx.id === editingTransaction.id
|
|
? { ...tx, ...formData, cardId: parseInt(formData.cardId), amount: parseInt(formData.amount) || 0 }
|
|
: tx
|
|
));
|
|
}
|
|
|
|
setShowModal(false);
|
|
setEditingTransaction(null);
|
|
};
|
|
|
|
// 삭제
|
|
const handleDelete = (id) => {
|
|
if (confirm('정말 삭제하시겠습니까?')) {
|
|
setTransactions(prev => prev.filter(tx => tx.id !== id));
|
|
if (showModal) {
|
|
setShowModal(false);
|
|
setEditingTransaction(null);
|
|
}
|
|
}
|
|
};
|
|
|
|
// Excel 다운로드
|
|
const handleDownload = () => {
|
|
const rows = [
|
|
['법인카드 거래내역', `${dateRange.start} ~ ${dateRange.end}`],
|
|
[],
|
|
['날짜', '시간', '카드', '가맹점', '카테고리', '금액', '승인번호', '상태', '메모'],
|
|
...filteredTransactions.map(tx => [
|
|
tx.date,
|
|
tx.time,
|
|
cards.find(c => c.id === tx.cardId)?.cardName || '',
|
|
tx.merchant,
|
|
tx.category,
|
|
tx.amount,
|
|
tx.approvalNo,
|
|
tx.status === 'approved' ? '승인' : '취소',
|
|
tx.memo
|
|
]),
|
|
[],
|
|
['총 사용금액', '', '', '', '', totalAmount]
|
|
];
|
|
|
|
const csvContent = rows.map(row => row.join(',')).join('\n');
|
|
const blob = new Blob(['\uFEFF' + csvContent], { type: 'text/csv;charset=utf-8;' });
|
|
const link = document.createElement('a');
|
|
link.href = URL.createObjectURL(blob);
|
|
link.download = `법인카드거래내역_${dateRange.start}_${dateRange.end}.csv`;
|
|
link.click();
|
|
};
|
|
|
|
// 날짜 그룹화
|
|
const groupedTransactions = filteredTransactions.reduce((groups, tx) => {
|
|
const date = tx.date;
|
|
if (!groups[date]) groups[date] = [];
|
|
groups[date].push(tx);
|
|
return groups;
|
|
}, {});
|
|
|
|
// 날짜 포맷
|
|
const formatDateDisplay = (dateStr) => {
|
|
const date = new Date(dateStr);
|
|
const days = ['일', '월', '화', '수', '목', '금', '토'];
|
|
return `${date.getMonth() + 1}월 ${date.getDate()}일 (${days[date.getDay()]})`;
|
|
};
|
|
|
|
return (
|
|
<div className="bg-gray-50 min-h-screen">
|
|
{/* 헤더 */}
|
|
<header className="bg-white border-b border-gray-200 rounded-t-xl mb-6">
|
|
<div className="px-6 py-4">
|
|
<div className="flex items-center justify-between">
|
|
<div className="flex items-center gap-4">
|
|
<div className="p-2 bg-indigo-100 rounded-xl">
|
|
<Receipt className="w-6 h-6 text-indigo-600" />
|
|
</div>
|
|
<div>
|
|
<h1 className="text-xl font-bold text-gray-900">법인카드 거래내역</h1>
|
|
<p className="text-sm text-gray-500">Corporate Card Transactions</p>
|
|
</div>
|
|
</div>
|
|
<div className="flex items-center gap-3">
|
|
<button
|
|
onClick={handleDownload}
|
|
className="flex items-center gap-2 px-4 py-2 text-gray-700 hover:bg-gray-100 rounded-lg transition-colors"
|
|
>
|
|
<Download className="w-4 h-4" />
|
|
<span className="text-sm">Excel</span>
|
|
</button>
|
|
<button
|
|
onClick={handleAddTransaction}
|
|
className="flex items-center gap-2 px-4 py-2 bg-indigo-600 hover:bg-indigo-700 text-white rounded-lg transition-colors"
|
|
>
|
|
<Plus className="w-4 h-4" />
|
|
<span className="text-sm font-medium">거래 등록</span>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
|
|
{/* 요약 카드 */}
|
|
<div className="grid grid-cols-1 md:grid-cols-4 gap-4 mb-6">
|
|
<div className="bg-white rounded-xl border border-gray-200 p-6">
|
|
<div className="flex items-center justify-between mb-2">
|
|
<span className="text-sm text-gray-500">조회 건수</span>
|
|
<Receipt className="w-5 h-5 text-gray-400" />
|
|
</div>
|
|
<p className="text-2xl font-bold text-gray-900">{filteredTransactions.length}건</p>
|
|
<p className="text-xs text-gray-400 mt-1">승인 {filteredTransactions.filter(t => t.status === 'approved').length}건</p>
|
|
</div>
|
|
<div className="bg-white rounded-xl border border-indigo-200 p-6 bg-indigo-50/30">
|
|
<div className="flex items-center justify-between mb-2">
|
|
<span className="text-sm text-indigo-700">총 사용금액</span>
|
|
<CreditCard className="w-5 h-5 text-indigo-500" />
|
|
</div>
|
|
<p className="text-2xl font-bold text-indigo-600">{formatCurrency(totalAmount)}원</p>
|
|
<p className="text-xs text-indigo-500 mt-1">취소 제외</p>
|
|
</div>
|
|
<div className="bg-white rounded-xl border border-emerald-200 p-6">
|
|
<div className="flex items-center justify-between mb-2">
|
|
<span className="text-sm text-emerald-700">승인 금액</span>
|
|
<TrendingUp className="w-5 h-5 text-emerald-500" />
|
|
</div>
|
|
<p className="text-2xl font-bold text-emerald-600">{formatCurrency(approvedAmount)}원</p>
|
|
</div>
|
|
<div className="bg-white rounded-xl border border-rose-200 p-6">
|
|
<div className="flex items-center justify-between mb-2">
|
|
<span className="text-sm text-rose-700">취소 금액</span>
|
|
<TrendingDown className="w-5 h-5 text-rose-500" />
|
|
</div>
|
|
<p className="text-2xl font-bold text-rose-600">{formatCurrency(cancelledAmount)}원</p>
|
|
</div>
|
|
</div>
|
|
|
|
{/* 카테고리별 사용현황 */}
|
|
{Object.keys(categoryTotals).length > 0 && (
|
|
<div className="bg-white rounded-xl border border-gray-200 p-4 mb-6">
|
|
<h3 className="text-sm font-medium text-gray-700 mb-3">카테고리별 사용현황</h3>
|
|
<div className="flex flex-wrap gap-2">
|
|
{Object.entries(categoryTotals)
|
|
.sort((a, b) => b[1] - a[1])
|
|
.map(([cat, amount]) => (
|
|
<div key={cat} className={`flex items-center gap-2 px-3 py-2 rounded-lg ${getCategoryColor(cat)}`}>
|
|
{getCategoryIcon(cat)}
|
|
<span className="text-sm font-medium">{cat}</span>
|
|
<span className="text-sm">{formatCurrency(amount)}원</span>
|
|
</div>
|
|
))
|
|
}
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
{/* 필터 영역 */}
|
|
<div className="bg-white rounded-xl border border-gray-200 p-4 mb-6">
|
|
<div className="grid grid-cols-1 md:grid-cols-6 gap-4">
|
|
{/* 검색 */}
|
|
<div className="md:col-span-2 relative">
|
|
<Search className="w-5 h-5 text-gray-400 absolute left-3 top-1/2 -translate-y-1/2" />
|
|
<input
|
|
type="text"
|
|
placeholder="가맹점, 메모, 승인번호 검색..."
|
|
value={searchTerm}
|
|
onChange={(e) => setSearchTerm(e.target.value)}
|
|
className="w-full pl-10 pr-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500"
|
|
/>
|
|
</div>
|
|
|
|
{/* 카드 필터 */}
|
|
<div>
|
|
<select
|
|
value={filterCard}
|
|
onChange={(e) => setFilterCard(e.target.value)}
|
|
className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500"
|
|
>
|
|
<option value="all">전체 카드</option>
|
|
{cards.map(card => (
|
|
<option key={card.id} value={card.id}>{card.cardName}</option>
|
|
))}
|
|
</select>
|
|
</div>
|
|
|
|
{/* 카테고리 필터 */}
|
|
<div>
|
|
<select
|
|
value={filterCategory}
|
|
onChange={(e) => setFilterCategory(e.target.value)}
|
|
className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500"
|
|
>
|
|
<option value="all">전체 카테고리</option>
|
|
{categories.map(cat => (
|
|
<option key={cat} value={cat}>{cat}</option>
|
|
))}
|
|
</select>
|
|
</div>
|
|
|
|
{/* 기간 필터 */}
|
|
<div className="flex items-center gap-2">
|
|
<input
|
|
type="date"
|
|
value={dateRange.start}
|
|
onChange={(e) => setDateRange(prev => ({ ...prev, start: e.target.value }))}
|
|
className="flex-1 px-2 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 text-sm"
|
|
/>
|
|
<span className="text-gray-400">~</span>
|
|
<input
|
|
type="date"
|
|
value={dateRange.end}
|
|
onChange={(e) => setDateRange(prev => ({ ...prev, end: e.target.value }))}
|
|
className="flex-1 px-2 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 text-sm"
|
|
/>
|
|
</div>
|
|
|
|
{/* 상태 필터 버튼 */}
|
|
<div className="flex gap-1">
|
|
<button
|
|
onClick={() => setFilterStatus('all')}
|
|
className={`flex-1 px-3 py-2 rounded-lg text-sm font-medium transition-colors ${
|
|
filterStatus === 'all' ? 'bg-indigo-600 text-white' : 'bg-gray-100 text-gray-600 hover:bg-gray-200'
|
|
}`}
|
|
>
|
|
전체
|
|
</button>
|
|
<button
|
|
onClick={() => setFilterStatus('approved')}
|
|
className={`flex-1 px-3 py-2 rounded-lg text-sm font-medium transition-colors ${
|
|
filterStatus === 'approved' ? 'bg-emerald-600 text-white' : 'bg-gray-100 text-gray-600 hover:bg-gray-200'
|
|
}`}
|
|
>
|
|
승인
|
|
</button>
|
|
<button
|
|
onClick={() => setFilterStatus('cancelled')}
|
|
className={`flex-1 px-3 py-2 rounded-lg text-sm font-medium transition-colors ${
|
|
filterStatus === 'cancelled' ? 'bg-rose-600 text-white' : 'bg-gray-100 text-gray-600 hover:bg-gray-200'
|
|
}`}
|
|
>
|
|
취소
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{/* 거래 내역 목록 */}
|
|
<div className="space-y-4">
|
|
{Object.entries(groupedTransactions).length === 0 ? (
|
|
<div className="bg-white rounded-xl border border-gray-200 p-12 text-center">
|
|
<Receipt className="w-12 h-12 mx-auto mb-4 text-gray-300" />
|
|
<p className="text-gray-400">거래 내역이 없습니다.</p>
|
|
</div>
|
|
) : (
|
|
Object.entries(groupedTransactions).map(([date, txList]) => (
|
|
<div key={date} className="bg-white rounded-xl border border-gray-200 overflow-hidden">
|
|
<div className="px-6 py-3 bg-gray-50 border-b border-gray-200 flex items-center justify-between">
|
|
<div className="flex items-center gap-2">
|
|
<Calendar className="w-4 h-4 text-gray-400" />
|
|
<span className="font-medium text-gray-700">{formatDateDisplay(date)}</span>
|
|
</div>
|
|
<span className="text-sm text-gray-500">
|
|
{txList.length}건 / {formatCurrency(txList.reduce((s, t) => s + t.amount, 0))}원
|
|
</span>
|
|
</div>
|
|
<div className="divide-y divide-gray-100">
|
|
{txList.map(tx => (
|
|
<div
|
|
key={tx.id}
|
|
onClick={() => handleEditTransaction(tx)}
|
|
className="px-6 py-4 hover:bg-gray-50 cursor-pointer transition-colors"
|
|
>
|
|
<div className="flex items-center justify-between">
|
|
<div className="flex items-center gap-4">
|
|
<div className={`p-2 rounded-lg ${getCategoryColor(tx.category)}`}>
|
|
{getCategoryIcon(tx.category)}
|
|
</div>
|
|
<div>
|
|
<div className="flex items-center gap-2 mb-1">
|
|
<span className="font-medium text-gray-900">{tx.merchant}</span>
|
|
<span className={`px-2 py-0.5 rounded text-xs ${
|
|
tx.status === 'approved'
|
|
? 'bg-emerald-100 text-emerald-700'
|
|
: 'bg-rose-100 text-rose-700'
|
|
}`}>
|
|
{tx.status === 'approved' ? '승인' : '취소'}
|
|
</span>
|
|
</div>
|
|
<div className="flex items-center gap-3 text-sm text-gray-500">
|
|
<span>{tx.time}</span>
|
|
<span>{cards.find(c => c.id === tx.cardId)?.cardName}</span>
|
|
<span className={`px-1.5 py-0.5 rounded text-xs ${getCategoryColor(tx.category)}`}>
|
|
{tx.category}
|
|
</span>
|
|
{tx.memo && <span className="text-gray-400">| {tx.memo}</span>}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div className="flex items-center gap-4">
|
|
<div className="text-right">
|
|
<p className={`text-lg font-bold ${tx.amount < 0 ? 'text-rose-600' : 'text-gray-900'}`}>
|
|
{tx.amount < 0 ? '' : ''}{formatCurrency(tx.amount)}원
|
|
</p>
|
|
<p className="text-xs text-gray-400">승인번호: {tx.approvalNo}</p>
|
|
</div>
|
|
<div className="flex items-center gap-1">
|
|
<button
|
|
onClick={(e) => { e.stopPropagation(); handleEditTransaction(tx); }}
|
|
className="p-2 text-gray-400 hover:text-blue-500 hover:bg-blue-50 rounded-lg transition-colors"
|
|
>
|
|
<Edit className="w-4 h-4" />
|
|
</button>
|
|
<button
|
|
onClick={(e) => { e.stopPropagation(); handleDelete(tx.id); }}
|
|
className="p-2 text-gray-400 hover:text-rose-500 hover:bg-rose-50 rounded-lg transition-colors"
|
|
>
|
|
<Trash2 className="w-4 h-4" />
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
</div>
|
|
))
|
|
)}
|
|
</div>
|
|
|
|
{/* 등록/수정 모달 */}
|
|
{showModal && (
|
|
<div className="fixed inset-0 bg-black/50 flex items-center justify-center z-50">
|
|
<div className="bg-white rounded-xl p-6 w-full max-w-lg mx-4 max-h-[90vh] overflow-y-auto">
|
|
<div className="flex items-center justify-between mb-6">
|
|
<h3 className="text-lg font-bold text-gray-900">
|
|
{modalMode === 'add' ? '거래 등록' : '거래 수정'}
|
|
</h3>
|
|
<button
|
|
onClick={() => { setShowModal(false); setEditingTransaction(null); }}
|
|
className="p-1 hover:bg-gray-100 rounded-lg"
|
|
>
|
|
<X className="w-5 h-5 text-gray-500" />
|
|
</button>
|
|
</div>
|
|
|
|
<div className="space-y-4">
|
|
<div className="grid grid-cols-2 gap-4">
|
|
<div>
|
|
<label className="block text-sm font-medium text-gray-700 mb-1">카드 *</label>
|
|
<select
|
|
value={formData.cardId}
|
|
onChange={(e) => setFormData(prev => ({ ...prev, cardId: e.target.value }))}
|
|
className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500"
|
|
>
|
|
{cards.map(card => (
|
|
<option key={card.id} value={card.id}>{card.cardName}</option>
|
|
))}
|
|
</select>
|
|
</div>
|
|
<div>
|
|
<label className="block text-sm font-medium text-gray-700 mb-1">카테고리</label>
|
|
<select
|
|
value={formData.category}
|
|
onChange={(e) => setFormData(prev => ({ ...prev, category: e.target.value }))}
|
|
className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500"
|
|
>
|
|
{categories.map(cat => (
|
|
<option key={cat} value={cat}>{cat}</option>
|
|
))}
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="grid grid-cols-2 gap-4">
|
|
<div>
|
|
<label className="block text-sm font-medium text-gray-700 mb-1">날짜 *</label>
|
|
<input
|
|
type="date"
|
|
value={formData.date}
|
|
onChange={(e) => setFormData(prev => ({ ...prev, date: e.target.value }))}
|
|
className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500"
|
|
/>
|
|
</div>
|
|
<div>
|
|
<label className="block text-sm font-medium text-gray-700 mb-1">시간</label>
|
|
<input
|
|
type="time"
|
|
value={formData.time}
|
|
onChange={(e) => setFormData(prev => ({ ...prev, time: e.target.value }))}
|
|
className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500"
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<div>
|
|
<label className="block text-sm font-medium text-gray-700 mb-1">가맹점명 *</label>
|
|
<input
|
|
type="text"
|
|
value={formData.merchant}
|
|
onChange={(e) => setFormData(prev => ({ ...prev, merchant: e.target.value }))}
|
|
placeholder="가맹점명을 입력하세요"
|
|
className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500"
|
|
/>
|
|
</div>
|
|
|
|
<div className="grid grid-cols-2 gap-4">
|
|
<div>
|
|
<label className="block text-sm font-medium text-gray-700 mb-1">금액 *</label>
|
|
<input
|
|
type="text"
|
|
value={formatInputCurrency(formData.amount)}
|
|
onChange={(e) => setFormData(prev => ({ ...prev, amount: parseInputCurrency(e.target.value) }))}
|
|
placeholder="0"
|
|
className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 text-right"
|
|
/>
|
|
<p className="text-xs text-gray-400 mt-1">취소 시 음수(-) 입력</p>
|
|
</div>
|
|
<div>
|
|
<label className="block text-sm font-medium text-gray-700 mb-1">승인번호</label>
|
|
<input
|
|
type="text"
|
|
value={formData.approvalNo}
|
|
onChange={(e) => setFormData(prev => ({ ...prev, approvalNo: e.target.value }))}
|
|
placeholder="승인번호"
|
|
className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500"
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<div>
|
|
<label className="block text-sm font-medium text-gray-700 mb-1">상태</label>
|
|
<div className="flex gap-4">
|
|
<label className="flex items-center gap-2 cursor-pointer">
|
|
<input
|
|
type="radio"
|
|
name="status"
|
|
value="approved"
|
|
checked={formData.status === 'approved'}
|
|
onChange={(e) => setFormData(prev => ({ ...prev, status: e.target.value }))}
|
|
className="w-4 h-4 text-indigo-600"
|
|
/>
|
|
<span className="text-sm text-gray-700">승인</span>
|
|
</label>
|
|
<label className="flex items-center gap-2 cursor-pointer">
|
|
<input
|
|
type="radio"
|
|
name="status"
|
|
value="cancelled"
|
|
checked={formData.status === 'cancelled'}
|
|
onChange={(e) => setFormData(prev => ({ ...prev, status: e.target.value }))}
|
|
className="w-4 h-4 text-indigo-600"
|
|
/>
|
|
<span className="text-sm text-gray-700">취소</span>
|
|
</label>
|
|
</div>
|
|
</div>
|
|
|
|
<div>
|
|
<label className="block text-sm font-medium text-gray-700 mb-1">메모</label>
|
|
<input
|
|
type="text"
|
|
value={formData.memo}
|
|
onChange={(e) => setFormData(prev => ({ ...prev, memo: e.target.value }))}
|
|
placeholder="메모를 입력하세요"
|
|
className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500"
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="flex gap-3 mt-6">
|
|
{modalMode === 'edit' && (
|
|
<button
|
|
onClick={() => handleDelete(editingTransaction.id)}
|
|
className="px-4 py-2 bg-red-600 hover:bg-red-700 text-white rounded-lg flex items-center gap-2"
|
|
>
|
|
<span>🗑️</span> 삭제
|
|
</button>
|
|
)}
|
|
<button
|
|
onClick={() => { setShowModal(false); setEditingTransaction(null); }}
|
|
className="flex-1 px-4 py-2 border border-gray-300 text-gray-700 rounded-lg hover:bg-gray-50 flex items-center justify-center gap-2"
|
|
>
|
|
<span>✕</span> 취소
|
|
</button>
|
|
<button
|
|
onClick={handleSave}
|
|
className="flex-1 px-4 py-2 bg-indigo-600 hover:bg-indigo-700 text-white rounded-lg flex items-center justify-center gap-2"
|
|
>
|
|
<span>✓</span> {modalMode === 'add' ? '등록' : '저장'}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
// React 앱 마운트
|
|
const rootElement = document.getElementById('card-transactions-root');
|
|
if (rootElement) {
|
|
ReactDOM.createRoot(rootElement).render(<CardTransactionsManagement />);
|
|
}
|
|
</script>
|
|
@endverbatim
|
|
@endpush
|