258 lines
19 KiB
PHP
258 lines
19 KiB
PHP
@extends('layouts.app')
|
|
|
|
@section('title', '고객사별 정산')
|
|
|
|
@push('styles')
|
|
<style>
|
|
@media print { .no-print { display: none !important; } }
|
|
</style>
|
|
@endpush
|
|
|
|
@section('content')
|
|
<div id="customer-settlement-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 Building2 = createIcon('building-2');
|
|
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 Calendar = createIcon('calendar');
|
|
const CheckCircle = createIcon('check-circle');
|
|
const Clock = createIcon('clock');
|
|
|
|
function CustomerSettlementManagement() {
|
|
const [settlements, setSettlements] = useState([
|
|
{ id: 1, period: '2026-01', customer: '(주)제조산업', totalSales: 160000000, commission: 4800000, expense: 500000, netAmount: 154700000, status: 'pending', settledDate: '', memo: '' },
|
|
{ id: 2, period: '2026-01', customer: '(주)테크솔루션', totalSales: 6000000, commission: 300000, expense: 0, netAmount: 5700000, status: 'settled', settledDate: '2026-01-20', memo: '' },
|
|
{ id: 3, period: '2026-01', customer: '(주)디지털제조', totalSales: 80000000, commission: 2400000, expense: 200000, netAmount: 77400000, status: 'settled', settledDate: '2026-01-15', memo: '' },
|
|
{ id: 4, period: '2025-12', customer: '(주)AI산업', totalSales: 36000000, commission: 720000, expense: 100000, netAmount: 35180000, status: 'settled', settledDate: '2025-12-31', memo: '연간 계약' },
|
|
{ id: 5, period: '2025-12', customer: '(주)스마트팩토리', totalSales: 15000000, commission: 750000, expense: 0, netAmount: 14250000, status: 'settled', settledDate: '2025-12-28', memo: '' },
|
|
]);
|
|
|
|
const [searchTerm, setSearchTerm] = useState('');
|
|
const [filterStatus, setFilterStatus] = useState('all');
|
|
const [filterPeriod, setFilterPeriod] = useState('all');
|
|
|
|
const [showModal, setShowModal] = useState(false);
|
|
const [modalMode, setModalMode] = useState('add');
|
|
const [editingItem, setEditingItem] = useState(null);
|
|
|
|
const periods = [...new Set(settlements.map(s => s.period))].sort().reverse();
|
|
|
|
const initialFormState = {
|
|
period: new Date().toISOString().slice(0, 7),
|
|
customer: '',
|
|
totalSales: '',
|
|
commission: '',
|
|
expense: '',
|
|
netAmount: '',
|
|
status: 'pending',
|
|
settledDate: '',
|
|
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 filteredSettlements = settlements.filter(item => {
|
|
const matchesSearch = item.customer.toLowerCase().includes(searchTerm.toLowerCase());
|
|
const matchesStatus = filterStatus === 'all' || item.status === filterStatus;
|
|
const matchesPeriod = filterPeriod === 'all' || item.period === filterPeriod;
|
|
return matchesSearch && matchesStatus && matchesPeriod;
|
|
});
|
|
|
|
const totalSales = filteredSettlements.reduce((sum, item) => sum + item.totalSales, 0);
|
|
const totalCommission = filteredSettlements.reduce((sum, item) => sum + item.commission, 0);
|
|
const totalNet = filteredSettlements.reduce((sum, item) => sum + item.netAmount, 0);
|
|
const settledAmount = filteredSettlements.filter(i => i.status === 'settled').reduce((sum, item) => sum + item.netAmount, 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.totalSales) { alert('필수 항목을 입력해주세요.'); return; }
|
|
const totalSales = parseInt(formData.totalSales) || 0;
|
|
const commission = parseInt(formData.commission) || 0;
|
|
const expense = parseInt(formData.expense) || 0;
|
|
const netAmount = totalSales - commission - expense;
|
|
if (modalMode === 'add') {
|
|
setSettlements(prev => [{ id: Date.now(), ...formData, totalSales, commission, expense, netAmount }, ...prev]);
|
|
} else {
|
|
setSettlements(prev => prev.map(item => item.id === editingItem.id ? { ...item, ...formData, totalSales, commission, expense, netAmount } : item));
|
|
}
|
|
setShowModal(false); setEditingItem(null);
|
|
};
|
|
const handleDelete = (id) => { if (confirm('정말 삭제하시겠습니까?')) { setSettlements(prev => prev.filter(item => item.id !== id)); setShowModal(false); } };
|
|
|
|
const handleDownload = () => {
|
|
const rows = [['고객사별 정산'], [], ['정산월', '고객사', '매출액', '수수료', '비용', '정산금액', '상태', '정산일'],
|
|
...filteredSettlements.map(item => [item.period, item.customer, item.totalSales, item.commission, item.expense, item.netAmount, item.status === 'settled' ? '정산완료' : '정산대기', item.settledDate])];
|
|
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 = `고객사별정산_${filterPeriod || 'all'}.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-indigo-100 rounded-xl"><Building2 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">Customer Settlement</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><DollarSign className="w-5 h-5 text-gray-400" /></div>
|
|
<p className="text-2xl font-bold text-gray-900">{formatCurrency(totalSales)}원</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><Building2 className="w-5 h-5 text-indigo-500" /></div>
|
|
<p className="text-2xl font-bold text-indigo-600">{formatCurrency(totalNet)}원</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><CheckCircle className="w-5 h-5 text-emerald-500" /></div>
|
|
<p className="text-2xl font-bold text-emerald-600">{formatCurrency(settledAmount)}원</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></div>
|
|
<p className="text-2xl font-bold text-rose-600">{formatCurrency(totalCommission)}원</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-4 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" />
|
|
</div>
|
|
<select value={filterPeriod} onChange={(e) => setFilterPeriod(e.target.value)} className="px-3 py-2 border border-gray-300 rounded-lg"><option value="all">전체 기간</option>{periods.map(p => <option key={p} value={p}>{p}</option>)}</select>
|
|
<div className="flex gap-1">
|
|
{['all', 'settled', '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 === 'settled' ? '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 === 'settled' ? '완료' : '대기'}
|
|
</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-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-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>
|
|
<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">
|
|
{filteredSettlements.length === 0 ? (
|
|
<tr><td colSpan="8" className="px-6 py-12 text-center text-gray-400">데이터가 없습니다.</td></tr>
|
|
) : filteredSettlements.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.period}</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-right text-gray-900">{formatCurrency(item.totalSales)}원</td>
|
|
<td className="px-6 py-4 text-sm text-right text-rose-600">{formatCurrency(item.commission)}원</td>
|
|
<td className="px-6 py-4 text-sm text-right text-gray-600">{formatCurrency(item.expense)}원</td>
|
|
<td className="px-6 py-4 text-sm font-bold text-right text-indigo-600">{formatCurrency(item.netAmount)}원</td>
|
|
<td className="px-6 py-4 text-center">
|
|
<span className={`px-2 py-1 rounded-full text-xs font-medium ${item.status === 'settled' ? 'bg-emerald-100 text-emerald-700' : 'bg-amber-100 text-amber-700'}`}>
|
|
{item.status === 'settled' ? '정산완료' : '정산대기'}
|
|
</span>
|
|
{item.settledDate && <p className="text-xs text-gray-400 mt-1">{item.settledDate}</p>}
|
|
</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="month" value={formData.period} onChange={(e) => setFormData(prev => ({ ...prev, period: 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.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="settled">정산완료</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 className="grid grid-cols-3 gap-4">
|
|
<div><label className="block text-sm font-medium text-gray-700 mb-1">매출액 *</label><input type="text" value={formatInputCurrency(formData.totalSales)} onChange={(e) => setFormData(prev => ({ ...prev, totalSales: 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><input type="text" value={formatInputCurrency(formData.commission)} onChange={(e) => setFormData(prev => ({ ...prev, commission: 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><input type="text" value={formatInputCurrency(formData.expense)} onChange={(e) => setFormData(prev => ({ ...prev, expense: parseInputCurrency(e.target.value) }))} placeholder="0" 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><input type="date" value={formData.settledDate} onChange={(e) => setFormData(prev => ({ ...prev, settledDate: 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><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('customer-settlement-root');
|
|
if (rootElement) { ReactDOM.createRoot(rootElement).render(<CustomerSettlementManagement />); }
|
|
</script>
|
|
@endverbatim
|
|
@endpush
|