« Back to History
saree_cut_types_manage.php
|
20260722_120325.php
Initial Domain Snapshot
Copy Code
<?php error_reporting(E_ALL); ini_set('display_errors', 1); require_once __DIR__ . '/modules/auth/page_acl.php'; // Yahan module name 'cutting_entry' hi rakha hai ya aap 'master_manage' kar sakte hain $ctx = page_require_access('cutting_entry'); require_once __DIR__ . '/helpers/activity_helper.php'; $pdo = $ctx['pdo']; $company_id = (int)$ctx['company_id']; $msg = ''; $error = ''; /* ===== 1. INSERT LOGIC ===== */ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'save') { try { $cut_name = trim($_POST['cut_name']); if ($cut_name === '') throw new Exception("Cut Name (Meters) is required"); $pdo->beginTransaction(); $ins = $pdo->prepare("INSERT INTO saree_cut_types (company_id, cut_name, is_active, created_at) VALUES (:cid, :name, 1, NOW())"); $ins->execute([ ':cid' => $company_id, ':name' => $cut_name ]); $new_id = $pdo->lastInsertId(); $pdo->commit(); // Activity Log log_activity([ 'activity_type' => 'master', 'module_name' => 'saree_cut_types', 'action_name' => 'create', 'activity_note' => "New Cut Type Added: $cut_name Mtrs", 'reference_id' => $new_id, ]); header("Location: saree_cut_types_manage.php?success=1"); exit; } catch (Exception $e) { if ($pdo->inTransaction()) $pdo->rollBack(); $error = $e->getMessage(); } } /* ===== 2. DELETE (TOGGLE STATUS) LOGIC ===== */ if (isset($_GET['delete_id'])) { try { $del_id = (int)$_GET['delete_id']; $pdo->prepare("UPDATE saree_cut_types SET is_active = 0 WHERE id = :id AND company_id = :cid") ->execute([':id' => $del_id, ':cid' => $company_id]); log_activity([ 'activity_type' => 'master', 'module_name' => 'saree_cut_types', 'action_name' => 'delete', 'activity_note' => "Cut Type ID $del_id marked as inactive", 'reference_id' => $del_id, ]); header("Location: saree_cut_types_manage.php?msg=Deleted Successfully"); exit; } catch (Exception $e) { $error = $e->getMessage(); } } if (isset($_GET['success'])) $msg = "New Cut Type Added Successfully!"; if (isset($_GET['msg'])) $msg = $_GET['msg']; /* ===== 3. FETCH DATA ===== */ $stmt = $pdo->prepare("SELECT * FROM saree_cut_types WHERE company_id = :cid AND is_active = 1 ORDER BY id DESC"); $stmt->execute([':cid' => $company_id]); $cut_types = $stmt->fetchAll(PDO::FETCH_ASSOC); require_once __DIR__ . '/partials/header.php'; ?> <div class="container mt-4"> <div class="row"> <div class="col-md-4"> <div class="card shadow-sm border-0 mb-4"> <div class="card-body"> <h5 class="card-title text-primary fw-bold mb-3">Add New Cut Type</h5> <form method="post" autocomplete="off"> <input type="hidden" name="action" value="save"> <div class="mb-3"> <label class="form-label">Cut Name (e.g. 5.25, 6.10)</label> <input type="text" name="cut_name" class="form-control" placeholder="Enter meters" required> </div> <button type="submit" class="btn btn-primary w-100 fw-bold">SAVE CUT TYPE</button> </form> </div> </div> </div> <div class="col-md-8"> <div class="card shadow-sm border-0"> <div class="card-body"> <h5 class="card-title text-dark fw-bold mb-3">Saree Cut Types List</h5> <?php if($msg): ?> <div class="alert alert-success p-2 small fw-bold"><?= $msg ?></div> <?php endif; ?> <?php if($error): ?> <div class="alert alert-danger p-2 small"><?= htmlspecialchars($error) ?></div> <?php endif; ?> <div class="table-responsive"> <table class="table table-hover table-bordered align-middle"> <thead class="table-light"> <tr> <th width="10%">ID</th> <th>Cut Name (Mtrs)</th> <th>Created At</th> <th width="15%" class="text-center">Action</th> </tr> </thead> <tbody> <?php if(empty($cut_types)): ?> <tr><td colspan="4" class="text-center text-muted">No active cut types found.</td></tr> <?php endif; ?> <?php foreach($cut_types as $row): ?> <tr> <td><?= $row['id'] ?></td> <td class="fw-bold text-primary"><?= htmlspecialchars($row['cut_name']) ?></td> <td class="small"><?= date('d-M-Y H:i', strtotime($row['created_at'])) ?></td> <td class="text-center"> <a href="?delete_id=<?= $row['id'] ?>" class="btn btn-outline-danger btn-sm" onclick="return confirm('Are you sure you want to delete this?')"> Delete </a> </td> </tr> <?php endforeach; ?> </tbody> </table> </div> </div> </div> </div> </div> </div> <?php require_once __DIR__ . '/partials/footer.php'; ?>