Files
sam-manage/resources/views/finance/refunds.blade.php

348 lines
25 KiB
PHP

@extends('layouts.app')
@section('title', '환불/해지 관리')
@push('styles')
<style>
@media print { .no-print { display: none !important; } }
</style>
@endpush
@section('content')
<div id="refunds-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;
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 RotateCcw = createIcon('rotate-ccw');
const Plus = createIcon('plus');
const Search = createIcon('search');
const Download = createIcon('download');
const X = createIcon('x');
const Edit = createIcon('edit');
const Trash2 = createIcon('trash-2');
const CheckCircle = createIcon('check-circle');
const Clock = createIcon('clock');
const XCircle = createIcon('x-circle');
const RefreshCw = createIcon('refresh-cw');
const PlayCircle = createIcon('play-circle');
function RefundsManagement() {
const [refunds, setRefunds] = useState([
{ id: 1, type: 'refund', customerName: '김철수', requestDate: '2026-01-18', productName: '프리미엄 구독', originalAmount: 99000, refundAmount: 49500, reason: '서비스 불만족', status: 'approved', processDate: '2026-01-19', note: '월정액 50% 환불' },
{ id: 2, type: 'cancel', customerName: '이영희', requestDate: '2026-01-17', productName: '엔터프라이즈 플랜', originalAmount: 500000, refundAmount: 300000, reason: '사업 종료', status: 'completed', processDate: '2026-01-18', note: '잔여 기간 환불' },
{ id: 3, type: 'refund', customerName: '박민수', requestDate: '2026-01-15', productName: '베이직 플랜', originalAmount: 29000, refundAmount: 29000, reason: '결제 오류', status: 'completed', processDate: '2026-01-16', note: '전액 환불' },
{ id: 4, type: 'cancel', customerName: '정수연', requestDate: '2026-01-20', productName: '프로 플랜', originalAmount: 199000, refundAmount: 0, reason: '경쟁사 이전', status: 'pending', processDate: '', note: '' },
{ id: 5, type: 'refund', customerName: '최지훈', requestDate: '2026-01-12', productName: '추가 스토리지', originalAmount: 50000, refundAmount: 0, reason: '중복 결제', status: 'rejected', processDate: '2026-01-14', note: '이미 사용한 서비스' },
]);
const [searchTerm, setSearchTerm] = useState('');
const [filterStatus, setFilterStatus] = useState('all');
const [filterType, setFilterType] = useState('all');
const [showModal, setShowModal] = useState(false);
const [modalMode, setModalMode] = useState('add');
const [editingItem, setEditingItem] = useState(null);
const [showProcessModal, setShowProcessModal] = useState(false);
const [processingItem, setProcessingItem] = useState(null);
const [processAction, setProcessAction] = useState('approved');
const [processRefundAmount, setProcessRefundAmount] = useState('');
const [processNote, setProcessNote] = useState('');
const types = ['refund', 'cancel'];
const reasons = ['서비스 불만족', '결제 오류', '사업 종료', '경쟁사 이전', '중복 결제', '기타'];
const initialFormState = {
type: 'refund',
customerName: '',
requestDate: new Date().toISOString().split('T')[0],
productName: '',
originalAmount: '',
refundAmount: 0,
reason: '서비스 불만족',
status: 'pending',
processDate: '',
note: ''
};
const [formData, setFormData] = useState(initialFormState);
const formatCurrency = (num) => num ? num.toLocaleString() : '0';
const formatInputCurrency = (value) => {
if (!value && value !== 0) return '';
const num = String(value).replace(/[^\d]/g, '');
return num ? Number(num).toLocaleString() : '';
};
const parseInputCurrency = (value) => String(value).replace(/[^\d]/g, '');
const filteredRefunds = refunds.filter(item => {
const matchesSearch = item.customerName.toLowerCase().includes(searchTerm.toLowerCase()) ||
item.productName.toLowerCase().includes(searchTerm.toLowerCase());
const matchesStatus = filterStatus === 'all' || item.status === filterStatus;
const matchesType = filterType === 'all' || item.type === filterType;
return matchesSearch && matchesStatus && matchesType;
});
const pendingCount = refunds.filter(i => i.status === 'pending').length;
const completedCount = refunds.filter(i => i.status === 'completed').length;
const rejectedCount = refunds.filter(i => i.status === 'rejected').length;
const totalRefunded = refunds.filter(i => i.status === 'completed' || i.status === 'approved').reduce((sum, item) => sum + item.refundAmount, 0);
const handleAdd = () => { setModalMode('add'); setFormData(initialFormState); setShowModal(true); };
const handleEdit = (item) => { setModalMode('edit'); setEditingItem(item); setFormData({ ...item }); setShowModal(true); };
const handleSave = () => {
if (!formData.customerName || !formData.productName || !formData.originalAmount) { alert('필수 항목을 입력해주세요.'); return; }
if (modalMode === 'add') {
setRefunds(prev => [{ id: Date.now(), ...formData, originalAmount: parseInt(formData.originalAmount) || 0, refundAmount: 0 }, ...prev]);
} else {
setRefunds(prev => prev.map(item => item.id === editingItem.id ? { ...item, ...formData, originalAmount: parseInt(formData.originalAmount) || 0, refundAmount: parseInt(formData.refundAmount) || 0 } : item));
}
setShowModal(false); setEditingItem(null);
};
const handleDelete = (id) => { if (confirm('정말 삭제하시겠습니까?')) { setRefunds(prev => prev.filter(item => item.id !== id)); setShowModal(false); } };
const handleProcess = (item) => {
setProcessingItem(item);
setProcessAction('approved');
setProcessRefundAmount(item.originalAmount.toString());
setProcessNote('');
setShowProcessModal(true);
};
const executeProcess = () => {
const refundAmt = parseInt(parseInputCurrency(processRefundAmount)) || 0;
setRefunds(prev => prev.map(item => {
if (item.id === processingItem.id) {
if (processAction === 'rejected') {
return { ...item, status: 'rejected', refundAmount: 0, processDate: new Date().toISOString().split('T')[0], note: processNote };
} else {
return { ...item, status: processAction, refundAmount: refundAmt, processDate: new Date().toISOString().split('T')[0], note: processNote };
}
}
return item;
}));
setShowProcessModal(false);
setProcessingItem(null);
};
const handleDownload = () => {
const rows = [['환불/해지 관리'], [], ['유형', '고객명', '요청일', '상품/서비스', '결제금액', '환불금액', '사유', '상태', '처리일'],
...filteredRefunds.map(item => [getTypeLabel(item.type), item.customerName, item.requestDate, item.productName, item.originalAmount, item.refundAmount, item.reason, getStatusLabel(item.status), item.processDate])];
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 = `환불해지관리_${new Date().toISOString().split('T')[0]}.csv`; link.click();
};
const getTypeLabel = (type) => {
const labels = { 'refund': '환불', 'cancel': '해지' };
return labels[type] || type;
};
const getStatusLabel = (status) => {
const labels = { 'pending': '대기', 'approved': '승인', 'completed': '완료', 'rejected': '거절' };
return labels[status] || status;
};
const getStatusStyle = (status) => {
const styles = {
'pending': 'bg-amber-100 text-amber-700',
'approved': 'bg-blue-100 text-blue-700',
'completed': 'bg-emerald-100 text-emerald-700',
'rejected': 'bg-red-100 text-red-700'
};
return styles[status] || 'bg-gray-100 text-gray-700';
};
const getTypeStyle = (type) => {
const styles = {
'refund': 'bg-pink-100 text-pink-700',
'cancel': 'bg-indigo-100 text-indigo-700'
};
return styles[type] || 'bg-gray-100 text-gray-700';
};
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 flex items-center justify-between">
<div className="flex items-center gap-4">
<div className="p-2 bg-pink-100 rounded-xl"><RotateCcw className="w-6 h-6 text-pink-600" /></div>
<div><h1 className="text-xl font-bold text-gray-900">환불/해지 관리</h1><p className="text-sm text-gray-500">Refunds & Cancellations</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"><Download className="w-4 h-4" /><span className="text-sm">Excel</span></button>
<button onClick={handleAdd} className="flex items-center gap-2 px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg"><Plus className="w-4 h-4" /><span className="text-sm font-medium">요청 등록</span></button>
</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-amber-200 p-6 bg-amber-50/30">
<div className="flex items-center justify-between mb-2"><span className="text-sm text-amber-700">처리 대기</span><Clock className="w-5 h-5 text-amber-500" /></div>
<p className="text-2xl font-bold text-amber-600">{pendingCount}</p>
</div>
<div className="bg-white rounded-xl border border-emerald-200 p-6 bg-emerald-50/30">
<div className="flex items-center justify-between mb-2"><span className="text-sm text-emerald-700">처리 완료</span><CheckCircle className="w-5 h-5 text-emerald-500" /></div>
<p className="text-2xl font-bold text-emerald-600">{completedCount}</p>
</div>
<div className="bg-white rounded-xl border border-red-200 p-6 bg-red-50/30">
<div className="flex items-center justify-between mb-2"><span className="text-sm text-red-700">거절</span><XCircle className="w-5 h-5 text-red-500" /></div>
<p className="text-2xl font-bold text-red-600">{rejectedCount}</p>
</div>
<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><RotateCcw className="w-5 h-5 text-gray-400" /></div>
<p className="text-2xl font-bold text-gray-900">{formatCurrency(totalRefunded)}</p>
</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-5 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-pink-500" />
</div>
<select value={filterType} onChange={(e) => setFilterType(e.target.value)} className="px-3 py-2 border border-gray-300 rounded-lg">
<option value="all">전체 유형</option>
<option value="refund">환불</option>
<option value="cancel">해지</option>
</select>
<div className="flex gap-1">
{['all', 'pending', 'approved', 'completed', 'rejected'].map(status => (
<button key={status} onClick={() => setFilterStatus(status)} className={`flex-1 px-2 py-2 rounded-lg text-xs font-medium ${filterStatus === status ? (status === 'completed' ? 'bg-green-600 text-white' : status === 'rejected' ? 'bg-red-600 text-white' : status === 'approved' ? 'bg-blue-600 text-white' : status === 'pending' ? 'bg-yellow-500 text-white' : 'bg-gray-800 text-white') : 'bg-gray-100 text-gray-700'}`}>
{status === 'all' ? '전체' : getStatusLabel(status)}
</button>
))}
</div>
<button onClick={() => { setSearchTerm(''); setFilterStatus('all'); setFilterType('all'); }} className="flex items-center justify-center gap-2 px-3 py-2 text-gray-600 hover:bg-gray-100 rounded-lg">
<RefreshCw className="w-4 h-4" /><span className="text-sm">초기화</span>
</button>
</div>
</div>
<div className="bg-white rounded-xl border border-gray-200 overflow-hidden">
<table className="w-full">
<thead className="bg-gray-50 border-b border-gray-200">
<tr>
<th className="px-6 py-3 text-left text-xs font-semibold text-gray-600">유형</th>
<th className="px-6 py-3 text-left text-xs font-semibold text-gray-600">고객명</th>
<th className="px-6 py-3 text-left text-xs font-semibold text-gray-600">상품/서비스</th>
<th className="px-6 py-3 text-left text-xs font-semibold text-gray-600">요청일</th>
<th className="px-6 py-3 text-left text-xs font-semibold text-gray-600">사유</th>
<th className="px-6 py-3 text-right text-xs font-semibold text-gray-600">결제금액</th>
<th className="px-6 py-3 text-right text-xs font-semibold text-gray-600">환불금액</th>
<th className="px-6 py-3 text-center text-xs font-semibold text-gray-600">상태</th>
</tr>
</thead>
<tbody className="divide-y divide-gray-100">
{filteredRefunds.length === 0 ? (
<tr><td colSpan="8" className="px-6 py-12 text-center text-gray-400">데이터가 없습니다.</td></tr>
) : filteredRefunds.map(item => (
<tr key={item.id} onClick={() => handleEdit(item)} className="hover:bg-gray-50 cursor-pointer">
<td className="px-6 py-4"><span className={`px-2 py-1 rounded text-xs font-medium ${getTypeStyle(item.type)}`}>{getTypeLabel(item.type)}</span></td>
<td className="px-6 py-4 text-sm font-medium text-gray-900">{item.customerName}</td>
<td className="px-6 py-4 text-sm text-gray-600">{item.productName}</td>
<td className="px-6 py-4 text-sm text-gray-600">{item.requestDate}</td>
<td className="px-6 py-4 text-sm text-gray-600">{item.reason}</td>
<td className="px-6 py-4 text-sm font-medium text-right text-gray-900">{formatCurrency(item.originalAmount)}</td>
<td className="px-6 py-4 text-sm font-bold text-right text-pink-600">{item.refundAmount ? formatCurrency(item.refundAmount) + '원' : '-'}</td>
<td className="px-6 py-4 text-center"><span className={`px-2 py-1 rounded-full text-xs font-medium ${getStatusStyle(item.status)}`}>{getStatusLabel(item.status)}</span></td>
</tr>
))}
</tbody>
</table>
</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)} 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.type} onChange={(e) => setFormData(prev => ({ ...prev, type: e.target.value }))} className="w-full px-3 py-2 border border-gray-300 rounded-lg"><option value="refund">환불</option><option value="cancel">해지</option></select></div>
<div><label className="block text-sm font-medium text-gray-700 mb-1">고객명 *</label><input type="text" value={formData.customerName} onChange={(e) => setFormData(prev => ({ ...prev, customerName: e.target.value }))} placeholder="고객명" className="w-full px-3 py-2 border border-gray-300 rounded-lg" /></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="text" value={formData.productName} onChange={(e) => setFormData(prev => ({ ...prev, productName: e.target.value }))} placeholder="상품/서비스명" className="w-full px-3 py-2 border border-gray-300 rounded-lg" /></div>
<div><label className="block text-sm font-medium text-gray-700 mb-1">요청일</label><input type="date" value={formData.requestDate} onChange={(e) => setFormData(prev => ({ ...prev, requestDate: e.target.value }))} className="w-full px-3 py-2 border border-gray-300 rounded-lg" /></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="text" value={formatInputCurrency(formData.originalAmount)} onChange={(e) => setFormData(prev => ({ ...prev, originalAmount: parseInputCurrency(e.target.value) }))} placeholder="0" className="w-full px-3 py-2 border border-gray-300 rounded-lg text-right" /></div>
<div><label className="block text-sm font-medium text-gray-700 mb-1">사유</label><select value={formData.reason} onChange={(e) => setFormData(prev => ({ ...prev, reason: e.target.value }))} className="w-full px-3 py-2 border border-gray-300 rounded-lg">{reasons.map(r => <option key={r} value={r}>{r}</option>)}</select></div>
</div>
{modalMode === 'edit' && (
<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.refundAmount)} onChange={(e) => setFormData(prev => ({ ...prev, refundAmount: parseInputCurrency(e.target.value) }))} placeholder="0" className="w-full px-3 py-2 border border-gray-300 rounded-lg text-right" /></div>
<div><label className="block text-sm font-medium text-gray-700 mb-1">상태</label><select value={formData.status} onChange={(e) => setFormData(prev => ({ ...prev, status: e.target.value }))} className="w-full px-3 py-2 border border-gray-300 rounded-lg"><option value="pending">대기</option><option value="approved">승인</option><option value="completed">완료</option><option value="rejected">거절</option></select></div>
</div>
)}
</div>
<div className="flex gap-3 mt-6">
{modalMode === 'edit' && <button onClick={() => handleDelete(editingItem.id)} className="px-4 py-2 bg-red-600 hover:bg-red-700 text-white rounded-lg">삭제</button>}
<button onClick={() => setShowModal(false)} className="flex-1 px-4 py-2 border border-gray-300 text-gray-700 rounded-lg hover:bg-gray-50">취소</button>
<button onClick={handleSave} className="flex-1 px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg">{modalMode === 'add' ? '등록' : '저장'}</button>
</div>
</div>
</div>
)}
{showProcessModal && processingItem && (
<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-md mx-4">
<div className="flex items-center justify-between mb-6">
<h3 className="text-lg font-bold text-gray-900">환불/해지 처리</h3>
<button onClick={() => setShowProcessModal(false)} className="p-1 hover:bg-gray-100 rounded-lg"><X className="w-5 h-5 text-gray-500" /></button>
</div>
<div className="bg-gray-50 rounded-lg p-4 mb-4">
<p className="font-medium text-gray-900">{processingItem.customerName} - {processingItem.productName}</p>
<p className="text-sm text-gray-500">{getTypeLabel(processingItem.type)} 요청 ({processingItem.requestDate})</p>
<div className="mt-3 text-sm">
<span>결제금액: {formatCurrency(processingItem.originalAmount)}</span>
</div>
</div>
<div className="space-y-4">
<div><label className="block text-sm font-medium text-gray-700 mb-1">처리 결정</label><select value={processAction} onChange={(e) => setProcessAction(e.target.value)} className="w-full px-3 py-2 border border-gray-300 rounded-lg"><option value="approved">승인</option><option value="completed">처리완료</option><option value="rejected">거절</option></select></div>
{processAction !== 'rejected' && (
<div><label className="block text-sm font-medium text-gray-700 mb-1">환불금액</label><input type="text" value={formatInputCurrency(processRefundAmount)} onChange={(e) => setProcessRefundAmount(parseInputCurrency(e.target.value))} placeholder="0" className="w-full px-3 py-2 border border-gray-300 rounded-lg text-right" /></div>
)}
<div><label className="block text-sm font-medium text-gray-700 mb-1">처리 메모</label><textarea value={processNote} onChange={(e) => setProcessNote(e.target.value)} rows="2" className="w-full px-3 py-2 border border-gray-300 rounded-lg"></textarea></div>
</div>
<div className="flex gap-3 mt-6">
<button onClick={() => setShowProcessModal(false)} className="flex-1 px-4 py-2 border border-gray-300 text-gray-700 rounded-lg hover:bg-gray-50">취소</button>
<button onClick={executeProcess} className={`flex-1 px-4 py-2 text-white rounded-lg ${processAction === 'rejected' ? 'bg-red-600 hover:bg-red-700' : 'bg-emerald-600 hover:bg-emerald-700'}`}>{processAction === 'rejected' ? '거절' : '처리'}</button>
</div>
</div>
</div>
)}
</div>
);
}
const rootElement = document.getElementById('refunds-root');
if (rootElement) { ReactDOM.createRoot(rootElement).render(<RefundsManagement />); }
</script>
@endverbatim
@endpush