diff --git a/add_disposal_columns.php b/add_disposal_columns.php new file mode 100644 index 0000000..39a247e --- /dev/null +++ b/add_disposal_columns.php @@ -0,0 +1,17 @@ +exec("ALTER TABLE laptop_assets ADD COLUMN disposal_recipient TEXT"); +} catch (Exception $e) { + echo "disposal_recipient already exists or error: " . $e->getMessage() . "\n"; +} + +try { + $db->exec("ALTER TABLE laptop_assets ADD COLUMN disposal_date TEXT"); +} catch (Exception $e) { + echo "disposal_date already exists or error: " . $e->getMessage() . "\n"; +} + +echo "Database updated successfully.\n"; +?> \ No newline at end of file diff --git a/api.php b/api.php index 2a8e438..ffc57a2 100644 --- a/api.php +++ b/api.php @@ -78,8 +78,9 @@ try { break; case 'get_dashboard_stats': // Laptops - $laptop_total = $db->query("SELECT COUNT(*) FROM laptop_assets")->fetchColumn(); + $laptop_total = $db->query("SELECT COUNT(*) FROM laptop_assets WHERE status != 'disposed'")->fetchColumn(); $laptop_assigned = $db->query("SELECT COUNT(*) FROM laptop_assets WHERE status = 'assigned'")->fetchColumn(); + $laptop_disposed = $db->query("SELECT COUNT(*) FROM laptop_assets WHERE status = 'disposed'")->fetchColumn(); // Cards $card_total = $db->query("SELECT COUNT(*) FROM access_cards")->fetchColumn(); @@ -94,7 +95,7 @@ try { $users_special = $db->query("SELECT COUNT(*) FROM users WHERE accounting_type = '특별회계'")->fetchColumn(); echo json_encode([ - 'laptops' => ['total' => (int) $laptop_total, 'assigned' => (int) $laptop_assigned], + 'laptops' => ['total' => (int) $laptop_total, 'assigned' => (int) $laptop_assigned, 'disposed' => (int) $laptop_disposed], 'cards' => ['total' => (int) $card_total, 'assigned' => (int) $card_assigned], 'mfp' => ['total' => (int) $mfp_total, 'active' => (int) $mfp_active], 'users' => ['general' => (int) $users_general, 'special' => (int) $users_special] @@ -439,17 +440,27 @@ ORDER BY path"; case 'add_laptop_asset': $data = json_decode(file_get_contents('php://input'), true); + $asset_tag = trim($data['asset_tag'] ?? ''); + + // Duplicate check + $check = $db->prepare("SELECT id FROM laptop_assets WHERE asset_tag = ?"); + $check->execute([$asset_tag]); + if ($check->fetch()) { + echo json_encode(['success' => false, 'error' => "이미 존재하는 자산번호({$asset_tag})입니다."]); + break; + } + $stmt = $db->prepare("INSERT INTO laptop_assets ( asset_tag, model_id, current_user_id, status, serial_number, purchase_date, ip_address, cpu, npu, hdd0_model, hdd0_capacity, hdd1_model, hdd1_capacity, ram, asset_status, assigned_user_name, fixed_ip, options, power_rating, manufacturer, vendor, product_name, remarks, -last_confirmed_date -) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); +last_confirmed_date, disposal_recipient, disposal_date, real_user, disposal_user_id +) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); $stmt->execute([ $data['asset_tag'], $data['model_id'], $data['current_user_id'] ?: null, - $data['current_user_id'] ? 'assigned' : 'stock', + $data['status'] ?: ($data['current_user_id'] ? 'assigned' : 'stock'), $data['serial_number'], $data['purchase_date'], $data['ip_address'] ?? null, @@ -469,7 +480,11 @@ last_confirmed_date $data['vendor'] ?? '', $data['product_name'] ?? '', $data['remarks'] ?? '', - $data['last_confirmed_date'] ?? null + $data['last_confirmed_date'] ?? null, + $data['disposal_recipient'] ?? null, + $data['disposal_date'] ?? null, + $data['real_user'] ?? null, + $data['disposal_user_id'] ?? null ]); $new_asset_id = $db->lastInsertId(); if ($data['assigned_user_name']) { @@ -497,17 +512,28 @@ last_confirmed_date $data['assigned_user_name'] = $u_stmt->fetchColumn() ?: ''; } + $asset_tag = trim($data['asset_tag'] ?? ''); + $asset_id = $data['id']; + + // Duplicate check (excluding current asset) + $check = $db->prepare("SELECT id FROM laptop_assets WHERE asset_tag = ? AND id != ?"); + $check->execute([$asset_tag, $asset_id]); + if ($check->fetch()) { + echo json_encode(['success' => false, 'error' => "이미 존재하는 자산번호({$asset_tag})입니다."]); + break; + } + $stmt = $db->prepare("UPDATE laptop_assets SET asset_tag = ?, model_id = ?, current_user_id = ?, status = ?, serial_number = ?, purchase_date = ?, ip_address = ?, cpu = ?, npu = ?, hdd0_model = ?, hdd0_capacity = ?, hdd1_model = ?, hdd1_capacity = ?, ram = ?, asset_status = ?, assigned_user_name = ?, fixed_ip = ?, options = ?, power_rating = ?, manufacturer = ?, vendor = ?, -product_name = ?, remarks = ?, last_confirmed_date = ? +product_name = ?, remarks = ?, last_confirmed_date = ?, disposal_recipient = ?, disposal_date = ?, real_user = ?, disposal_user_id = ? WHERE id = ?"); $stmt->execute([ $data['asset_tag'], $data['model_id'], $data['current_user_id'] ?: null, - $data['current_user_id'] ? 'assigned' : 'stock', + $data['status'] ?: ($data['current_user_id'] ? 'assigned' : 'stock'), $data['serial_number'], $data['purchase_date'], $data['ip_address'] ?? null, @@ -528,6 +554,10 @@ WHERE id = ?"); $data['product_name'] ?? '', $data['remarks'] ?? '', $data['last_confirmed_date'] ?? null, + $data['disposal_recipient'] ?? null, + $data['disposal_date'] ?? null, + $data['real_user'] ?? null, + $data['disposal_user_id'] ?? null, $data['id'] ]); @@ -642,10 +672,14 @@ LIMIT 1")->fetchColumn(); if ($newStatus) { $updates[] = "status = ?"; $params[] = $newStatus; - // 만약 상태를 'stock'(재고)으로 변경하는 경우 배정 정보도 초기화 + // 만약 상태를 'stock'(재고)으로 변경하는 경우 '업무용'으로 설정, 'disposed'(매각)인 경우 완전 초기화 if ($newStatus === 'stock') { + $updates[] = "current_user_id = NULL"; + $updates[] = "assigned_user_name = '업무용(TEMP_44666b)'"; + } elseif ($newStatus === 'disposed') { $updates[] = "current_user_id = NULL"; $updates[] = "assigned_user_name = NULL"; + $updates[] = "disposal_date = '" . date('Y-m-d') . "'"; } } if ($newModelId) { diff --git a/assets.db b/assets.db index cbf3bc4..ed6a68c 100644 Binary files a/assets.db and b/assets.db differ diff --git a/check_schema.php b/check_schema.php index c0dc51f..7a18594 100644 --- a/check_schema.php +++ b/check_schema.php @@ -1,11 +1,4 @@ query("PRAGMA table_info($table)"); - while ($row = $q->fetch()) { - print_r($row); - } -} -?> \ No newline at end of file +$db = new PDO('sqlite:d:\Docker\jasan\assets.db'); +$cols = $db->query("PRAGMA table_info(laptop_assets)")->fetchAll(PDO::FETCH_ASSOC); +echo json_encode($cols, JSON_PRETTY_PRINT); \ No newline at end of file diff --git a/general_rental.php b/general_rental.php index 2f948c6..0cde8fd 100644 --- a/general_rental.php +++ b/general_rental.php @@ -189,18 +189,57 @@
-
+
- +
+ + +
+ + + + +
+
+ + +
+
+
Search Results +
+
+
+ +
+

검색 결과가 없습니다.

+
+
+
@@ -276,6 +315,31 @@ rental_reason: '', items: [''] }, + userSearchQuery: '', + showUserDropdown: false, + + get filteredUsers() { + if (!this.userSearchQuery) return this.users.slice(0, 50); + const q = this.userSearchQuery.toLowerCase(); + return this.users.filter(u => + (u.name && u.name.toLowerCase().includes(q)) || + (u.emp_id && u.emp_id.toLowerCase().includes(q)) || + (u.dept_name && u.dept_name.toLowerCase().includes(q)) + ); + }, + + selectUser(user) { + this.formData.user_id = user.id; + this.userSearchQuery = `${user.name} (${user.emp_id})`; + this.showUserDropdown = false; + this.updateUserName(); + }, + + clearUser() { + this.formData.user_id = ''; + this.userSearchQuery = ''; + this.updateUserName(); + }, init() { this.fetchRentals(); @@ -315,6 +379,7 @@ rental_reason: '', items: [''] }; + this.userSearchQuery = ''; this.showAddModal = true; }, diff --git a/laptops.php b/laptops.php index f76a915..098e049 100644 --- a/laptops.php +++ b/laptops.php @@ -65,6 +65,40 @@
+ +
+
+ + + + +
+ +
+ Total: Items +
+
+
@@ -83,6 +117,7 @@ + + :class="isAssetTagDuplicate ? 'border-rose-500 ring-2 ring-rose-200' : 'border-slate-200'" + class="w-full px-4 py-3 bg-slate-50 border rounded-xl focus:ring-2 focus:ring-blue-500 outline-none transition-all font-bold"> +
- + +
+
+ + +
+
+
+ +
+ + +
+ + + +
+
+ +
+ +
+
+
+ + +
+
+ + +
@@ -273,46 +394,64 @@
-

Individual Asset Info -

+

Individual Asset Info

-
-
- -