Files
sam-manage/resources/views/finance/consulting-fee.blade.php

263 lines
20 KiB
PHP

@extends('layouts.app')
@section('title', '상담수수료')
@push('styles')
<style>
@media print { .no-print { display: none !important; } }
</style>
@endpush
@section('content')
<div id="consulting-fee-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 MessageCircle = createIcon('message-circle');
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 DollarSign = createIcon('dollar-sign');
const Users = createIcon('users');
function ConsultingFeeManagement() {
const [fees, setFees] = useState([
{ id: 1, date: '2026-01-21', consultant: '김상담', customer: '(주)제조산업', service: '기술 컨설팅', hours: 8, hourlyRate: 200000, amount: 1600000, status: 'pending', memo: 'MES 도입 상담' },
{ id: 2, date: '2026-01-18', consultant: '박컨설', customer: '(주)스마트팩토리', service: '프로세스 컨설팅', hours: 16, hourlyRate: 250000, amount: 4000000, status: 'paid', memo: '공정 개선' },
{ id: 3, date: '2026-01-15', consultant: '김상담', customer: '(주)디지털제조', service: '기술 컨설팅', hours: 4, hourlyRate: 200000, amount: 800000, status: 'paid', memo: 'ERP 연동 상담' },
{ id: 4, date: '2026-01-10', consultant: '이자문', customer: '(주)AI산업', service: '전략 컨설팅', hours: 24, hourlyRate: 300000, amount: 7200000, status: 'pending', memo: 'DX 전략 수립' },
{ id: 5, date: '2025-12-20', consultant: '박컨설', customer: '(주)테크솔루션', service: '프로세스 컨설팅', hours: 8, hourlyRate: 250000, amount: 2000000, status: 'paid', memo: '' },
]);
const [searchTerm, setSearchTerm] = useState('');
const [filterStatus, setFilterStatus] = useState('all');
const [filterConsultant, setFilterConsultant] = useState('all');
const [dateRange, setDateRange] = useState({
start: new Date(new Date().setMonth(new Date().getMonth() - 3)).toISOString().split('T')[0],
end: new Date().toISOString().split('T')[0]
});
const [showModal, setShowModal] = useState(false);
const [modalMode, setModalMode] = useState('add');
const [editingItem, setEditingItem] = useState(null);
const consultants = ['김상담', '박컨설', '이자문', '최전문'];
const services = ['기술 컨설팅', '프로세스 컨설팅', '전략 컨설팅', '교육/훈련', '기타'];
const initialFormState = {
date: new Date().toISOString().split('T')[0],
consultant: '김상담',
customer: '',
service: '기술 컨설팅',
hours: '',
hourlyRate: 200000,
amount: '',
status: 'pending',
memo: ''
};
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 filteredFees = fees.filter(item => {
const matchesSearch = item.customer.toLowerCase().includes(searchTerm.toLowerCase()) ||
item.consultant.toLowerCase().includes(searchTerm.toLowerCase());
const matchesStatus = filterStatus === 'all' || item.status === filterStatus;
const matchesConsultant = filterConsultant === 'all' || item.consultant === filterConsultant;
const matchesDate = item.date >= dateRange.start && item.date <= dateRange.end;
return matchesSearch && matchesStatus && matchesConsultant && matchesDate;
});
const totalAmount = filteredFees.reduce((sum, item) => sum + item.amount, 0);
const paidAmount = filteredFees.filter(i => i.status === 'paid').reduce((sum, item) => sum + item.amount, 0);
const pendingAmount = filteredFees.filter(i => i.status === 'pending').reduce((sum, item) => sum + item.amount, 0);
const totalHours = filteredFees.reduce((sum, item) => sum + item.hours, 0);
const handleAdd = () => { setModalMode('add'); setFormData(initialFormState); setShowModal(true); };
const handleEdit = (item) => { setModalMode('edit'); setEditingItem(item); setFormData({ ...item }); setShowModal(true); };
const handleSave = () => {
if (!formData.customer || !formData.hours) { alert('필수 항목을 입력해주세요.'); return; }
const hours = parseInt(formData.hours) || 0;
const hourlyRate = parseInt(formData.hourlyRate) || 0;
const amount = parseInt(formData.amount) || hours * hourlyRate;
if (modalMode === 'add') {
setFees(prev => [{ id: Date.now(), ...formData, hours, hourlyRate, amount }, ...prev]);
} else {
setFees(prev => prev.map(item => item.id === editingItem.id ? { ...item, ...formData, hours, hourlyRate, amount } : item));
}
setShowModal(false); setEditingItem(null);
};
const handleDelete = (id) => { if (confirm('정말 삭제하시겠습니까?')) { setFees(prev => prev.filter(item => item.id !== id)); setShowModal(false); } };
const handleDownload = () => {
const rows = [['상담수수료', `${dateRange.start} ~ ${dateRange.end}`], [], ['날짜', '컨설턴트', '고객사', '서비스', '시간', '시급', '금액', '상태'],
...filteredFees.map(item => [item.date, item.consultant, item.customer, item.service, item.hours, item.hourlyRate, item.amount, item.status === 'paid' ? '지급완료' : '지급예정'])];
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();
};
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-cyan-100 rounded-xl"><MessageCircle className="w-6 h-6 text-cyan-600" /></div>
<div><h1 className="text-xl font-bold text-gray-900">상담수수료</h1><p className="text-sm text-gray-500">Consulting Fee</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-gray-200 p-6">
<div className="flex items-center justify-between mb-2"><span className="text-sm text-gray-500"> 시간</span><Users className="w-5 h-5 text-gray-400" /></div>
<p className="text-2xl font-bold text-gray-900">{totalHours}시간</p>
</div>
<div className="bg-white rounded-xl border border-cyan-200 p-6 bg-cyan-50/30">
<div className="flex items-center justify-between mb-2"><span className="text-sm text-cyan-700"> 수수료</span><DollarSign className="w-5 h-5 text-cyan-500" /></div>
<p className="text-2xl font-bold text-cyan-600">{formatCurrency(totalAmount)}</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></div>
<p className="text-2xl font-bold text-emerald-600">{formatCurrency(paidAmount)}</p>
</div>
<div className="bg-white rounded-xl border border-amber-200 p-6">
<div className="flex items-center justify-between mb-2"><span className="text-sm text-amber-700">지급예정</span></div>
<p className="text-2xl font-bold text-amber-600">{formatCurrency(pendingAmount)}</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-cyan-500" />
</div>
<select value={filterConsultant} onChange={(e) => setFilterConsultant(e.target.value)} className="px-3 py-2 border border-gray-300 rounded-lg"><option value="all">전체 컨설턴트</option>{consultants.map(c => <option key={c} value={c}>{c}</option>)}</select>
<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 text-sm" />
<span>~</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 text-sm" />
</div>
<div className="flex gap-1">
{['all', 'paid', 'pending'].map(status => (
<button key={status} onClick={() => setFilterStatus(status)} className={`flex-1 px-3 py-2 rounded-lg text-sm font-medium ${filterStatus === status ? (status === 'paid' ? 'bg-green-600 text-white' : status === 'pending' ? 'bg-yellow-500 text-white' : 'bg-gray-800 text-white') : 'bg-gray-100 text-gray-700'}`}>
{status === 'all' ? '전체' : status === 'paid' ? '완료' : '예정'}
</button>
))}
</div>
</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-center 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>
<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">
{filteredFees.length === 0 ? (
<tr><td colSpan="8" className="px-6 py-12 text-center text-gray-400">데이터가 없습니다.</td></tr>
) : filteredFees.map(item => (
<tr key={item.id} className="hover:bg-gray-50 cursor-pointer" onClick={() => handleEdit(item)}>
<td className="px-6 py-4 text-sm text-gray-600">{item.date}</td>
<td className="px-6 py-4"><span className="px-2 py-1 bg-cyan-100 text-cyan-700 rounded text-xs font-medium">{item.consultant}</span></td>
<td className="px-6 py-4 text-sm font-medium text-gray-900">{item.customer}</td>
<td className="px-6 py-4 text-sm text-gray-600">{item.service}</td>
<td className="px-6 py-4 text-sm text-center text-gray-600">{item.hours}h</td>
<td className="px-6 py-4 text-sm font-bold text-right text-cyan-600">{formatCurrency(item.amount)}</td>
<td className="px-6 py-4 text-center"><span className={`px-2 py-1 rounded-full text-xs font-medium ${item.status === 'paid' ? 'bg-emerald-100 text-emerald-700' : 'bg-amber-100 text-amber-700'}`}>{item.status === 'paid' ? '지급완료' : '지급예정'}</span></td>
<td className="px-6 py-4 text-center" onClick={(e) => e.stopPropagation()}>
<button onClick={() => handleEdit(item)} className="p-1 text-gray-400 hover:text-blue-500"><Edit className="w-4 h-4" /></button>
<button onClick={() => handleDelete(item.id)} className="p-1 text-gray-400 hover:text-rose-500"><Trash2 className="w-4 h-4" /></button>
</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><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" /></div>
<div><label className="block text-sm font-medium text-gray-700 mb-1">컨설턴트</label><select value={formData.consultant} onChange={(e) => setFormData(prev => ({ ...prev, consultant: e.target.value }))} className="w-full px-3 py-2 border border-gray-300 rounded-lg">{consultants.map(c => <option key={c} value={c}>{c}</option>)}</select></div>
</div>
<div><label className="block text-sm font-medium text-gray-700 mb-1">고객사 *</label><input type="text" value={formData.customer} onChange={(e) => setFormData(prev => ({ ...prev, customer: 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><select value={formData.service} onChange={(e) => setFormData(prev => ({ ...prev, service: e.target.value }))} className="w-full px-3 py-2 border border-gray-300 rounded-lg">{services.map(s => <option key={s} value={s}>{s}</option>)}</select></div>
<div className="grid grid-cols-3 gap-4">
<div><label className="block text-sm font-medium text-gray-700 mb-1">시간 *</label><input type="number" value={formData.hours} onChange={(e) => setFormData(prev => ({ ...prev, hours: 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><input type="text" value={formatInputCurrency(formData.hourlyRate)} onChange={(e) => setFormData(prev => ({ ...prev, hourlyRate: parseInputCurrency(e.target.value) }))} 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><input type="text" value={formatInputCurrency(formData.amount)} onChange={(e) => setFormData(prev => ({ ...prev, amount: parseInputCurrency(e.target.value) }))} placeholder="자동계산" className="w-full px-3 py-2 border border-gray-300 rounded-lg text-right" /></div>
</div>
<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.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="paid">지급완료</option></select></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" /></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 flex items-center gap-2"><span>🗑️</span> 삭제</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>
)}
</div>
);
}
const rootElement = document.getElementById('consulting-fee-root');
if (rootElement) { ReactDOM.createRoot(rootElement).render(<ConsultingFeeManagement />); }
</script>
@endverbatim
@endpush