diff --git a/resources/views/finance/settlement/index.blade.php b/resources/views/finance/settlement/index.blade.php
index 3cf53929..bec312b3 100644
--- a/resources/views/finance/settlement/index.blade.php
+++ b/resources/views/finance/settlement/index.blade.php
@@ -12,22 +12,13 @@
@@ -205,42 +177,6 @@ function toggleSelectAll(checkbox) {
updateSelection();
}
- function openPaymentModal() {
- document.getElementById('payment-modal').classList.remove('hidden');
- }
-
- function closePaymentModal() {
- document.getElementById('payment-modal').classList.add('hidden');
- }
-
- function submitPayment() {
- const form = document.getElementById('payment-form');
- const formData = new FormData(form);
-
- fetch('{{ route("finance.sales-commissions.payment") }}', {
- method: 'POST',
- headers: {
- 'X-CSRF-TOKEN': '{{ csrf_token() }}',
- 'Accept': 'application/json',
- },
- body: formData
- })
- .then(response => response.json())
- .then(data => {
- if (data.success) {
- alert(data.message);
- closePaymentModal();
- location.reload();
- } else {
- alert(data.message || '오류가 발생했습니다.');
- }
- })
- .catch(error => {
- console.error('Error:', error);
- alert('오류가 발생했습니다.');
- });
- }
-
function openDetailModal(commissionId) {
fetch('{{ url("finance/sales-commissions") }}/' + commissionId + '/detail')
.then(response => response.text())
@@ -398,11 +334,109 @@ function formatCommissionInput(el) {
el.value = raw ? Number(raw).toLocaleString() : '';
}
- function onTenantSelect(managementId) {
- if (!managementId) return;
- htmx.ajax('GET', '{{ route("finance.sales-commissions.payment-form") }}?management_id=' + managementId, {
- target: '#payment-form-container'
- });
+ function exportCurrentTable() {
+ // 현재 활성 탭 감지
+ const activeTabEl = document.querySelector('[x-data]');
+ const activeTab = activeTabEl ? activeTabEl.__x.$data.activeTab : 'commission';
+
+ let table, filename;
+ const today = new Date().toISOString().slice(0, 10).replace(/-/g, '');
+
+ if (activeTab === 'commission') {
+ // 수당 관리 - 현재 보이는 서브탭 테이블
+ const subTab = activeTabEl.__x.$data.commissionSubTab;
+ if (subTab === 'manager') {
+ table = document.querySelector('#manager-table-container table');
+ filename = `매니저수당_${today}.csv`;
+ } else {
+ table = document.querySelector('#commission-table-container table');
+ filename = `영업파트너수당_${today}.csv`;
+ }
+ } else if (activeTab === 'customer') {
+ table = document.querySelector('#customer-content table');
+ filename = `고객사정산_${today}.csv`;
+ } else if (activeTab === 'subscription') {
+ table = document.querySelector('#subscription-content table');
+ filename = `구독관리_${today}.csv`;
+ }
+
+ if (!table) {
+ alert('내보낼 데이터가 없습니다.');
+ return;
+ }
+
+ // 테이블 → CSV 변환
+ const rows = [];
+ const thead = table.querySelector('thead');
+ const tbody = table.querySelector('tbody');
+
+ // 헤더 추출 (체크박스/액션 컬럼 제외)
+ if (thead) {
+ const headerRow = [];
+ thead.querySelectorAll('th').forEach(th => {
+ const text = th.textContent.trim();
+ // 체크박스(빈 헤더)와 액션 컬럼 제외
+ if (text && text !== '액션') {
+ headerRow.push(text);
+ }
+ });
+ rows.push(headerRow);
+ }
+
+ // 본문 추출
+ if (tbody) {
+ tbody.querySelectorAll('tr').forEach(tr => {
+ // 빈 메시지 행 제외
+ if (tr.querySelector('td[colspan]')) return;
+
+ const row = [];
+ tr.querySelectorAll('td').forEach(td => {
+ // 체크박스 셀 제외 (input[type=checkbox]만 있는 셀)
+ if (td.querySelector('input[type="checkbox"].commission-checkbox') || (td.querySelector('input[type="checkbox"]') && !td.textContent.trim())) return;
+ // 액션 버튼 셀 제외
+ if (td.querySelector('button[onclick*="openDetailModal"]')) return;
+
+ // input 값 우선, 없으면 텍스트
+ const dateInput = td.querySelector('input[type="date"]');
+ const textInput = td.querySelector('input[type="text"]');
+ let text;
+ if (dateInput) {
+ text = dateInput.value || '';
+ } else if (textInput) {
+ text = textInput.value || '';
+ } else {
+ text = td.textContent.replace(/\s+/g, ' ').trim();
+ }
+ row.push(text);
+ });
+
+ if (row.length > 0) {
+ rows.push(row);
+ }
+ });
+ }
+
+ if (rows.length <= 1) {
+ alert('내보낼 데이터가 없습니다.');
+ return;
+ }
+
+ // CSV 생성 (UTF-8 BOM 포함)
+ const BOM = '\uFEFF';
+ const csvContent = BOM + rows.map(row =>
+ row.map(cell => {
+ const escaped = String(cell).replace(/"/g, '""');
+ return `"${escaped}"`;
+ }).join(',')
+ ).join('\n');
+
+ // 다운로드
+ const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
+ const link = document.createElement('a');
+ link.href = URL.createObjectURL(blob);
+ link.download = filename;
+ link.click();
+ URL.revokeObjectURL(link.href);
}
document.addEventListener('DOMContentLoaded', function() {