« Back to History
mesr_denier_data_manage.php
|
20260721_154033.php
Initial Bulk Import
Copy Code
<?php /* /erp/mesr/mesr_denier_data_manage.php */ require_once __DIR__ . '/../modules/auth/page_acl.php'; $ctx = page_require_access('mesr_stock_entry'); require_once __DIR__ . '/../modules/activity/activity_logger.php'; $company_id = (int)$ctx['company_id']; $pdo = $ctx['pdo']; $user_id = (int)($ctx['user']['id'] ?? 0); $message = ""; /* -------------------- Save / Update Logic -------------------- */ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action_save'])) { $id = (int)($_POST['id'] ?? 0); $type = $_POST['type'] ?? ''; $value = trim($_POST['value'] ?? ''); if (!empty($type) && !empty($value)) { try { if ($id > 0) { // Update Existing $st = $pdo->prepare("UPDATE mesr_denier_data SET type = ?, value = ? WHERE id = ? AND company_id = ?"); $st->execute([$type, $value, $id, $company_id]); activity_log([ 'company_id' => $company_id, 'user_id' => $user_id, 'module' => 'mesr', 'action_name' => 'edit', 'entity_type' => 'mesr_denier_data', 'entity_id' => $id, 'remarks' => 'Updated MESR denier data' ]); $message = "Success: Entry updated successfully!"; } else { // Insert New $st = $pdo->prepare("INSERT INTO mesr_denier_data (company_id, type, value, created_at) VALUES (?, ?, ?, NOW())"); $st->execute([$company_id, $type, $value]); activity_log([ 'company_id' => $company_id, 'user_id' => $user_id, 'module' => 'mesr', 'action_name' => 'create', 'entity_type' => 'mesr_denier_data', 'entity_id' => (int)$pdo->lastInsertId(), 'remarks' => 'Created MESR denier data' ]); $message = "Success: New entry added!"; } } catch (Exception $e) { $message = "Error: " . $e->getMessage(); } } } /* -------------------- Delete Logic -------------------- */ if (isset($_GET['del_id'])) { $del_id = (int)$_GET['del_id']; $pdo->prepare("DELETE FROM mesr_denier_data WHERE id = ? AND company_id = ?")->execute([$del_id, $company_id]); activity_log([ 'company_id' => $company_id, 'user_id' => $user_id, 'module' => 'mesr', 'action_name' => 'delete', 'entity_type' => 'mesr_denier_data', 'entity_id' => $del_id, 'remarks' => 'Deleted MESR denier data' ]); header("Location: mesr_denier_data_manage.php?msg=Deleted"); exit; } // Fetch for Edit $edit_row = null; if (isset($_GET['edit_id'])) { $edit_id = (int)$_GET['edit_id']; $st = $pdo->prepare("SELECT * FROM mesr_denier_data WHERE id = ? AND company_id = ?"); $st->execute([$edit_id, $company_id]); $edit_row = $st->fetch(PDO::FETCH_ASSOC); } // Fetch All Data $rows = $pdo->query("SELECT * FROM mesr_denier_data WHERE company_id = $company_id ORDER BY type ASC, value ASC")->fetchAll(PDO::FETCH_ASSOC); require_once __DIR__ . '/../partials/header.php'; ?> <div class="app-container"> <div class="index-welcome"> <h2>Denier & Color Manager <span class="welcome-user">| Master Setup</span></h2> </div> <?php if($message || isset($_GET['msg'])): ?> <div class="alert" style="padding:15px; background:#d4edda; color:#155724; margin-bottom:20px; border-radius:4px; border:1px solid #c3e6cb;"> <?= htmlspecialchars($message ?: $_GET['msg']) ?> </div> <?php endif; ?> <div style="display: grid; grid-template-columns: 350px 1fr; gap: 20px; align-items: start;"> <div class="form-card" style="padding: 20px; background: #fff; border: 1px solid #ddd; border-radius: 8px;"> <h3 style="margin-top: 0; margin-bottom: 20px; border-bottom: 1px solid #eee; padding-bottom: 10px;"> <?= $edit_row ? 'Edit Entry' : 'Add New Entry' ?> </h3> <form method="POST"> <input type="hidden" name="action_save" value="1"> <input type="hidden" name="id" value="<?= $edit_row['id'] ?? 0 ?>"> <div class="form-group" style="margin-bottom: 15px;"> <label style="display: block; margin-bottom: 5px; font-weight: bold;">Type</label> <select name="type" class="form-control" required style="width: 100%; padding: 8px;"> <option value="denier" <?= ($edit_row['type'] ?? '') == 'denier' ? 'selected' : '' ?>>Denier</option> <option value="color" <?= ($edit_row['type'] ?? '') == 'color' ? 'selected' : '' ?>>Color</option> </select> </div> <div class="form-group" style="margin-bottom: 15px;"> <label style="display: block; margin-bottom: 5px; font-weight: bold;">Value</label> <input type="text" name="value" value="<?= htmlspecialchars($edit_row['value'] ?? '') ?>" class="form-control" placeholder="e.g. 136 or Gold" required style="width: 100%; padding: 8px;"> </div> <div style="display: flex; gap: 10px;"> <button type="submit" class="btn-primary" style="flex: 1; padding: 10px; background: #28a745; color: #fff; border: none; border-radius: 4px; cursor: pointer;"> <?= $edit_row ? 'Update' : 'Save Entry' ?> </button> <?php if($edit_row): ?> <a href="mesr_denier_data_manage.php" class="btn-secondary" style="flex: 1; text-align: center; padding: 10px; background: #6c757d; color: #fff; text-decoration: none; border-radius: 4px;">Cancel</a> <?php endif; ?> </div> </form> </div> <div class="form-card" style="padding: 20px; background: #fff; border: 1px solid #ddd; border-radius: 8px;"> <h3 style="margin-top: 0; margin-bottom: 20px; border-bottom: 1px solid #eee; padding-bottom: 10px;">Master Records</h3> <table class="table erp-table" style="width: 100%; border-collapse: collapse;"> <thead> <tr style="background: #f8f9fa; text-align: left;"> <th style="padding: 12px; border-bottom: 2px solid #dee2e6;">Type</th> <th style="padding: 12px; border-bottom: 2px solid #dee2e6;">Value</th> <th style="padding: 12px; border-bottom: 2px solid #dee2e6; width: 100px; text-align: center;">Actions</th> </tr> </thead> <tbody> <?php if(empty($rows)): ?> <tr><td colspan="3" style="padding: 20px; text-align: center; color: #999;">No records found.</td></tr> <?php endif; ?> <?php foreach($rows as $r): ?> <tr style="border-bottom: 1px solid #eee;"> <td style="padding: 10px; text-transform: capitalize;"> <span style="padding: 3px 8px; border-radius: 12px; font-size: 0.85em; background: <?= $r['type'] == 'denier' ? '#e7f3ff; color: #007bff;' : '#e6ffed; color: #28a745;' ?>"> <?= htmlspecialchars($r['type']) ?> </span> </td> <td style="padding: 10px; font-weight: 500;"><?= htmlspecialchars($r['value']) ?></td> <td style="padding: 10px; text-align: center;"> <a href="?edit_id=<?= $r['id'] ?>" style="color: #007bff; text-decoration: none; margin-right: 10px;" title="Edit">📝</a> <a href="?del_id=<?= $r['id'] ?>" onclick="return confirm('Delete this entry?')" style="color: #dc3545; text-decoration: none;" title="Delete">🗑️</a> </td> </tr> <?php endforeach; ?> </tbody> </table> </div> </div> </div> <?php require_once __DIR__ . '/../partials/footer.php'; ?>