« Back to History
party_master.php
|
20260721_154032.php
Initial Bulk Import
Copy Code
<?php require_once __DIR__ . '/../modules/auth/page_acl.php'; // 'job_work_party_access' aapki ACL key ke hisab se badal sakte hain $ctx = page_require_access('job_work_party_access'); $company_id = (int)$ctx['company_id']; $pdo = $ctx['pdo']; $message = ""; // --- SAVE / UPDATE LOGIC --- if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action_save'])) { $party_id = !empty($_POST['party_id']) ? (int)$_POST['party_id'] : null; $party_name = trim($_POST['party_name']); $mobile = trim($_POST['mobile']); $location = trim($_POST['location']); $status = $_POST['status']; if (empty($party_name)) { $message = "Error: Party Name is required."; } else { try { $pdo->beginTransaction(); if ($party_id) { // UPDATE $stmt = $pdo->prepare("UPDATE job_work_party SET party_name = ?, mobile = ?, location = ?, status = ?, updated_at = NOW() WHERE id = ? AND company_id = ?"); $stmt->execute([$party_name, $mobile, $location, $status, $party_id, $company_id]); $message = "Success: Party updated successfully."; } else { // INSERT $stmt = $pdo->prepare("INSERT INTO job_work_party (company_id, party_name, mobile, location, status, created_at) VALUES (?, ?, ?, ?, ?, NOW())"); $stmt->execute([$company_id, $party_name, $mobile, $location, $status]); $message = "Success: Party added successfully."; } $pdo->commit(); } catch (Exception $e) { if ($pdo->inTransaction()) $pdo->rollBack(); $message = "Error: " . $e->getMessage(); } } } // --- FETCH DATA FOR EDIT --- $edit_data = ['id' => '', 'party_name' => '', 'mobile' => '', 'location' => '', 'status' => 'Active']; if (isset($_GET['edit'])) { $stmt = $pdo->prepare("SELECT * FROM job_work_party WHERE id = ? AND company_id = ?"); $stmt->execute([(int)$_GET['edit'], $company_id]); $res = $stmt->fetch(PDO::FETCH_ASSOC); if ($res) $edit_data = $res; } // --- FETCH LIST --- $parties = $pdo->prepare("SELECT * FROM job_work_party WHERE company_id = ? ORDER BY party_name ASC"); $parties->execute([$company_id]); $parties = $parties->fetchAll(PDO::FETCH_ASSOC); require_once __DIR__ . '/../partials/header.php'; ?> <div class="wrap container-fluid py-4"> <div class="d-flex justify-content-between align-items-center mb-4"> <div> <h2 class="fw-bold m-0 text-dark"> <i class="bi bi-person-lines-fill text-primary me-2"></i> Job Work Party Master </h2> <p class="text-muted small mb-0">Manage your service providers and job work parties</p> </div> <span class="badge bg-soft-primary text-primary border border-primary px-3 py-2 rounded-pill"> Configuration Mode </span> </div> <?php if($message): ?> <div class="alert alert-dismissible fade show shadow-sm border-0 border-start border-4 <?= strpos($message, 'Success') !== false ? 'alert-success border-success' : 'alert-danger border-danger' ?>" role="alert"> <i class="bi <?= strpos($message, 'Success') !== false ? 'bi-check-circle-fill' : 'bi-exclamation-triangle-fill' ?> me-2"></i> <?= htmlspecialchars($message) ?> <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> </div> <?php endif; ?> <div class="row g-4"> <div class="col-lg-4"> <div class="card shadow-sm border-0 h-100"> <div class="card-header bg-white py-3"> <h6 class="m-0 fw-bold text-muted text-uppercase small"> <?= $edit_data['id'] ? '<i class="bi bi-pencil-square"></i> Edit Party' : '<i class="bi bi-plus-circle"></i> Add New Party' ?> </h6> </div> <div class="card-body p-4"> <form method="POST" autocomplete="off"> <input type="hidden" name="action_save" value="1"> <input type="hidden" name="party_id" value="<?= (int)$edit_data['id'] ?>"> <div class="mb-3"> <label class="form-label small fw-bold">Party Name <span class="text-danger">*</span></label> <input type="text" name="party_name" class="form-control shadow-none" value="<?= htmlspecialchars($edit_data['party_name']) ?>" required> </div> <div class="mb-3"> <label class="form-label small fw-bold">Mobile Number</label> <div class="input-group"> <span class="input-group-text bg-light"><i class="bi bi-phone"></i></span> <input type="text" name="mobile" class="form-control shadow-none" maxlength="10" value="<?= htmlspecialchars($edit_data['mobile']) ?>" placeholder="10-digit mobile"> </div> </div> <div class="mb-3"> <label class="form-label small fw-bold">Location / Station</label> <div class="input-group"> <span class="input-group-text bg-light"><i class="bi bi-geo-alt"></i></span> <input type="text" name="location" class="form-control shadow-none" value="<?= htmlspecialchars($edit_data['location']) ?>" placeholder="e.g. Surat"> </div> </div> <div class="mb-4"> <label class="form-label small fw-bold">Status</label> <select name="status" class="form-select shadow-none"> <option value="Active" <?= $edit_data['status'] == 'Active' ? 'selected' : '' ?>>Active</option> <option value="Inactive" <?= $edit_data['status'] == 'Inactive' ? 'selected' : '' ?>>Inactive</option> </select> </div> <div class="d-grid gap-2"> <button type="submit" class="btn btn-primary fw-bold shadow-sm"> <i class="bi bi-save me-2"></i> <?= $edit_data['id'] ? 'Update Party Info' : 'Save Party' ?> </button> <?php if($edit_data['id']): ?> <a href="party_master.php" class="btn btn-light border text-muted">Cancel Editing</a> <?php endif; ?> </div> </form> </div> </div> </div> <div class="col-lg-8"> <div class="card shadow-sm border-0 h-100"> <div class="card-header bg-white py-3 d-flex justify-content-between align-items-center"> <h6 class="m-0 fw-bold text-muted text-uppercase small">Existing Parties</h6> <span class="badge bg-light text-dark border fw-normal"><?= count($parties) ?> Total</span> </div> <div class="card-body p-0"> <div class="table-responsive"> <table class="table table-hover align-middle mb-0"> <thead class="table-light"> <tr> <th class="ps-4">Party Name</th> <th>Location</th> <th>Mobile</th> <th>Status</th> <th class="text-end pe-4">Action</th> </tr> </thead> <tbody> <?php foreach($parties as $p): ?> <tr> <td class="ps-4 fw-bold text-dark"><?= htmlspecialchars($p['party_name']) ?></td> <td><span class="text-muted"><?= htmlspecialchars($p['location'] ?: '-') ?></span></td> <td><i class="bi bi-phone small me-1 opacity-50"></i><?= htmlspecialchars($p['mobile'] ?: '-') ?></td> <td> <?php if($p['status'] == 'Active'): ?> <span class="badge bg-success-soft text-success px-2 py-1">Active</span> <?php else: ?> <span class="badge bg-danger-soft text-danger px-2 py-1">Inactive</span> <?php endif; ?> </td> <td class="text-end pe-4"> <a href="?edit=<?= $p['id'] ?>" class="btn btn-outline-primary btn-sm px-3 rounded-pill"> <i class="bi bi-pencil me-1"></i> Edit </a> </td> </tr> <?php endforeach; ?> </tbody> </table> </div> </div> </div> </div> </div> </div> <style> /* Dashboard Styling */ .bg-soft-primary { background-color: #eef2ff; } .bg-success-soft { background-color: #e6fcf5; border: 1px solid #c3fae8; } .bg-danger-soft { background-color: #fff5f5; border: 1px solid #ffe3e3; } .table thead th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; font-weight: 700; color: #868e96; } .card { border-radius: 12px; } .form-control, .form-select { border-radius: 8px; padding: 0.6rem 0.8rem; } .form-control:focus { border-color: #4c6ef5; box-shadow: 0 0 0 0.25rem rgba(76, 110, 245, 0.1); } </style>