From e1372061e1a356be64e7791b453accdd7b649075 Mon Sep 17 00:00:00 2001 From: NAS-Admin Date: Sun, 8 Feb 2026 18:40:00 +0900 Subject: [PATCH] =?UTF-8?q?=EC=BF=BC=ED=83=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api.php | 83 +++++++++++++++++++++++++++++++++++++++++++++---- cards.php | 54 +++++++++++++++++--------------- departments.php | 42 ++++++++++++++++++++----- laptops.php | 65 ++++++++++++++++++++------------------ mfp.php | 54 +++++++++++++++++--------------- users.php | 28 +++++++++-------- 6 files changed, 219 insertions(+), 107 deletions(-) diff --git a/api.php b/api.php index b2e7bd4..343de55 100644 --- a/api.php +++ b/api.php @@ -60,34 +60,56 @@ try { case 'add_user': $data = json_decode(file_get_contents('php://input'), true); + $status = $data['status'] ?? 'active'; + $department_id = $data['department_id']; + + // Auto-relocate based on status + if ($status === 'on_leave' || $status === 'retired') { + $dept_name = ($status === 'on_leave') ? '휴직' : '퇴사'; + $target_dept = $db->query("SELECT id FROM departments WHERE name = '$dept_name'")->fetchColumn(); + if ($target_dept) + $department_id = $target_dept; + } + $stmt = $db->prepare("INSERT INTO users (emp_id, name, department_id, position, email, phone, mobile, accounting_type, status) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"); $stmt->execute([ $data['emp_id'], $data['name'], - $data['department_id'], + $department_id, $data['position'], $data['email'], $data['phone'] ?? '', $data['mobile'], $data['accounting_type'], - $data['status'] ?? 'active' + $status ]); echo json_encode(['success' => true]); break; case 'update_user': $data = json_decode(file_get_contents('php://input'), true); + $status = $data['status']; + $department_id = $data['department_id']; + + // Auto-relocate based on status + if ($status === 'on_leave' || $status === 'retired') { + $dept_name = ($status === 'on_leave') ? '휴직' : '퇴사'; + $target_dept = $db->query("SELECT id FROM departments WHERE name = '$dept_name'")->fetchColumn(); + if ($target_dept) + $department_id = $target_dept; + } + $stmt = $db->prepare("UPDATE users SET emp_id = ?, name = ?, department_id = ?, position = ?, email = ?, phone = ?, mobile = ?, accounting_type = ?, status = ? WHERE id = ?"); $stmt->execute([ $data['emp_id'], $data['name'], - $data['department_id'], + $department_id, $data['position'], $data['email'], $data['phone'] ?? '', $data['mobile'], $data['accounting_type'], - $data['status'], + $status, $data['id'] ]); echo json_encode(['success' => true]); @@ -352,8 +374,49 @@ try { case 'update_dept': $data = json_decode(file_get_contents('php://input'), true); - $stmt = $db->prepare("UPDATE departments SET name = ?, parent_id = ? WHERE id = ?"); - $stmt->execute([$data['name'], $data['parent_id'] ?: null, $data['id']]); + $new_name = $data['name']; + $parent_id = $data['parent_id'] ?: null; + $dept_id = $data['id']; + $merge_target_id = $data['merge_target_id'] ?? null; + + if ($merge_target_id) { + // Scenario: Merge members to an existing department with the same name + $db->prepare("UPDATE users SET department_id = ? WHERE department_id = ?")->execute([$merge_target_id, $dept_id]); + // Recursively move children? For now, we delete the source dept after merging members + $db->prepare("DELETE FROM departments WHERE id = ?")->execute([$dept_id]); + echo json_encode(['success' => true, 'merged' => true]); + } else { + // Check if a department with the same name exists under the same parent (excluding itself) + $check_stmt = $db->prepare("SELECT id FROM departments WHERE name = ? AND (parent_id <=> ?) AND id != ?"); + $check_stmt->execute([$new_name, $parent_id, $dept_id]); + $existing = $check_stmt->fetch(); + + if ($existing) { + echo json_encode(['success' => false, 'conflict' => true, 'existing_id' => $existing['id']]); + } else { + $stmt = $db->prepare("UPDATE departments SET name = ?, parent_id = ? WHERE id = ?"); + $stmt->execute([$new_name, $parent_id, $dept_id]); + echo json_encode(['success' => true]); + } + } + break; + + case 'delete_dept': + $dept_id = $_GET['id']; + // 1. Find the '미소속' department ID + $miso_id = $db->query("SELECT id FROM departments WHERE name = '미소속'")->fetchColumn(); + if (!$miso_id) { + // Fallback creation if not exists + $db->exec("INSERT INTO departments (name, level) VALUES ('미소속', 0)"); + $miso_id = $db->lastInsertId(); + } + + // 2. Move members to '미소속' + $db->prepare("UPDATE users SET department_id = ? WHERE department_id = ?")->execute([$miso_id, $dept_id]); + + // 3. Delete the department + $db->prepare("DELETE FROM departments WHERE id = ?")->execute([$dept_id]); + echo json_encode(['success' => true]); break; @@ -500,6 +563,14 @@ try { break; } + // Enhanced logic: if status is changed to leave/retired, override dept + if ($newStatus === 'on_leave' || $newStatus === 'retired') { + $dept_name = ($newStatus === 'on_leave') ? '휴직' : '퇴사'; + $target_dept = $db->query("SELECT id FROM departments WHERE name = '$dept_name'")->fetchColumn(); + if ($target_dept) + $newDeptId = $target_dept; + } + $sql = "UPDATE users SET "; $params = []; $updates = []; diff --git a/cards.php b/cards.php index ced6352..25f2348 100644 --- a/cards.php +++ b/cards.php @@ -37,34 +37,38 @@ 카드 등록 - +
-
-
- - 개 선택됨 -
-
-
- 일괄 변경: - - - + class="fixed bottom-10 left-10 z-[200] bg-slate-900 text-white px-6 py-4 rounded-3xl flex items-center gap-6 shadow-2xl border border-white/10 animate-in fade-in slide-in-from-left-4 duration-300"> +
+
+
+ Selected + 출입증 선택됨
- +
+
+ + + + +
diff --git a/departments.php b/departments.php index c6a72d9..2ac6cdf 100644 --- a/departments.php +++ b/departments.php @@ -86,7 +86,13 @@
-

+
+

+ +
@@ -205,28 +211,50 @@ this.showModal = true; }, - submitDept() { + submitDept(mergeTargetId = null) { const action = this.isEdit ? 'update_dept' : 'add_dept'; - // Calculate level based on parent - if (this.formData.parent_id) { + if (!mergeTargetId && this.formData.parent_id) { const parent = this.depts.find(d => d.id == this.formData.parent_id); - this.formData.level = this.getDeptLevel(parent.path) + 1; - } else { + this.formData.level = (parent ? this.getDeptLevel(parent.path) : 0) + 1; + } else if (!mergeTargetId) { this.formData.level = 0; } + const payload = { ...this.formData }; + if (mergeTargetId) payload.merge_target_id = mergeTargetId; + fetch(`api.php?action=${action}`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify(this.formData) + body: JSON.stringify(payload) }).then(res => res.json()).then(data => { if (data.success) { this.showModal = false; this.fetchDepts(); + if (data.merged) { + alert('부서원이 기존 부서로 이동되었으며, 해당 부서는 삭제되었습니다.'); + } + } else if (data.conflict) { + if (confirm(`동일한 위치에 '${this.formData.name}' 부서가 이미 존재합니다.\n부서 정보를 통합하여 부서원을 이동시키겠습니까?`)) { + this.submitDept(data.existing_id); + } } }); }, + deleteDept() { + if (confirm(`정말로 '${this.formData.name}' 부서를 제거하시겠습니까?\n이 명령을 수행하면 소속된 부서원들은 자동으로 '[한국경제인협회] - 미소속' 부서로 이동됩니다.\n이 작업은 되돌릴 수 없습니다.`)) { + fetch(`api.php?action=delete_dept&id=${this.formData.id}`) + .then(res => res.json()) + .then(data => { + if (data.success) { + this.showModal = false; + this.fetchDepts(); + } + }); + } + }, + viewMembers(dept) { this.selectedDept = dept; fetch(`api.php?action=get_dept_users&dept_id=${dept.id}`).then(res => res.json()).then(data => { diff --git a/laptops.php b/laptops.php index e8195eb..591be8f 100644 --- a/laptops.php +++ b/laptops.php @@ -52,40 +52,43 @@
- +
-
-
- - 개 선택됨 -
-
-
- 일괄 변경: - - - + class="fixed bottom-10 left-10 z-[200] bg-slate-900 text-white px-6 py-4 rounded-3xl flex items-center gap-6 shadow-2xl border border-white/10 animate-in fade-in slide-in-from-left-4 duration-300"> +
+
+
+ Selected + 자산 선택됨
- +
+
+ + + + +
diff --git a/mfp.php b/mfp.php index 80b8aa7..14f25ea 100644 --- a/mfp.php +++ b/mfp.php @@ -37,34 +37,38 @@ 계정 등록 - +
-
-
- - 개 선택됨 -
-
-
- 일괄 변경: - - - + class="fixed bottom-10 left-10 z-[200] bg-slate-900 text-white px-6 py-4 rounded-3xl flex items-center gap-6 shadow-2xl border border-white/10 animate-in fade-in slide-in-from-left-4 duration-300"> +
+
+
+ Selected + 계정 선택됨
- +
+
+ + + + +
diff --git a/users.php b/users.php index feb4fa3..0477dc7 100644 --- a/users.php +++ b/users.php @@ -98,36 +98,37 @@
- +
+ class="fixed bottom-10 left-10 z-[200] bg-slate-900 text-white px-6 py-4 rounded-3xl flex items-center gap-6 shadow-2xl border border-white/10 animate-in fade-in slide-in-from-left-4 duration-300">
- - 명 선택됨 +
+
+ Selected + 인원 선택됨 +
-
+
- 일괄 변경: - +
@@ -198,7 +199,8 @@
-
+