« Back to History
job_work_party_master.php
|
20260723_000646.php
Initial Domain Snapshot
Copy Code
<?php require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('job_work_party_master'); $pdo = $ctx['pdo']; $company_id = (int)$ctx['company_id']; require_once __DIR__ . '/partials/header.php'; require_once __DIR__ . '/helpers/activity_helper.php'; $msg = ''; $edit_id = isset($_GET['edit']) ? (int)$_GET['edit'] : 0; $editRow = [ 'id' => 0, 'party_name' => '', 'short_name' => '', 'mobile' => '', 'address' => '', 'is_active' => 1, ]; if ($edit_id > 0) { $editStmt = $pdo->prepare(" SELECT * FROM job_work_party_master WHERE id = :id AND company_id = :cid LIMIT 1 "); $editStmt->execute([':id' => $edit_id, ':cid' => $company_id]); $found = $editStmt->fetch(PDO::FETCH_ASSOC); if ($found) { $editRow = $found; } else { $edit_id = 0; } } /* ===== SAVE / UPDATE ===== */ if($_SERVER['REQUEST_METHOD']==='POST'){ $party_id = (int)($_POST['party_id'] ?? 0); $name = trim($_POST['party_name'] ?? ''); $short = trim($_POST['short_name'] ?? ''); $mobile = trim($_POST['mobile'] ?? ''); $address = trim($_POST['address'] ?? ''); $is_active = isset($_POST['is_active']) ? (int)$_POST['is_active'] : 1; $editRow = [ 'id' => $party_id, 'party_name' => $name, 'short_name' => $short, 'mobile' => $mobile, 'address' => $address, 'is_active' => $is_active ? 1 : 0, ]; if($name){ try{ if ($party_id > 0) { $stmt = $pdo->prepare(" UPDATE job_work_party_master SET party_name = :name, short_name = :short, mobile = :mobile, address = :address, is_active = :active WHERE id = :id AND company_id = :cid "); $stmt->execute([ ':cid'=>$company_id, ':id'=>$party_id, ':name'=>$name, ':short'=>$short, ':mobile'=>$mobile, ':address'=>$address, ':active'=>$is_active ? 1 : 0 ]); $msg = "Updated successfully"; $edit_id = 0; $editRow = ['id'=>0,'party_name'=>'','short_name'=>'','mobile'=>'','address'=>'','is_active'=>1]; // Activity Log log_activity([ 'activity_type' => 'master', 'module_name' => 'job_work_party_master', 'action_name' => 'update', 'activity_note' => "Updated Party: $name ($short)", 'reference_id' => $party_id, ]); } else { $stmt = $pdo->prepare(" INSERT INTO job_work_party_master (company_id, party_name, short_name, mobile, address, is_active) VALUES (:cid,:name,:short,:mobile,:address,:active) "); $stmt->execute([ ':cid'=>$company_id, ':name'=>$name, ':short'=>$short, ':mobile'=>$mobile, ':address'=>$address, ':active'=>$is_active ? 1 : 0 ]); $msg = "Saved successfully"; $editRow = ['id'=>0,'party_name'=>'','short_name'=>'','mobile'=>'','address'=>'','is_active'=>1]; // Activity Log $new_id = $pdo->lastInsertId(); log_activity([ 'activity_type' => 'master', 'module_name' => 'job_work_party_master', 'action_name' => 'create', 'activity_note' => "Created Party: $name ($short)", 'reference_id' => $new_id, ]); } }catch(PDOException $e){ if(($e->errorInfo[1] ?? 0) == 1062){ $msg = "Duplicate party name"; }else{ throw $e; } } } } /* ===== LIST ===== */ $stmt = $pdo->prepare(" SELECT * FROM job_work_party_master WHERE company_id = :cid ORDER BY id DESC "); $stmt->execute([':cid'=>$company_id]); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); ?> <div class="container mt-4"> <div class="card p-3"> <h4>Job Work Party Master</h4> <?php if($msg): ?> <div class="alert alert-info"><?= htmlspecialchars($msg) ?></div> <?php endif; ?> <form method="post" class="row g-3 mb-3"> <input type="hidden" name="party_id" value="<?= (int)$editRow['id'] ?>"> <div class="col-md-4"> <label>Party Name</label> <input type="text" name="party_name" class="form-control" value="<?= htmlspecialchars($editRow['party_name']) ?>" required> </div> <div class="col-md-2"> <label>Short Name</label> <input type="text" name="short_name" class="form-control" value="<?= htmlspecialchars($editRow['short_name']) ?>"> </div> <div class="col-md-2"> <label>Mobile</label> <input type="text" name="mobile" class="form-control" value="<?= htmlspecialchars($editRow['mobile']) ?>"> </div> <div class="col-md-2"> <label>Status</label> <select name="is_active" class="form-select"> <option value="1" <?= ((int)$editRow['is_active'] === 1) ? 'selected' : '' ?>>Active</option> <option value="0" <?= ((int)$editRow['is_active'] === 0) ? 'selected' : '' ?>>Inactive</option> </select> </div> <div class="col-md-2"> <label>Address</label> <input type="text" name="address" class="form-control" value="<?= htmlspecialchars($editRow['address']) ?>"> </div> <div class="col-md-12 d-flex gap-2"> <button class="btn btn-primary"><?= $edit_id > 0 ? 'Update Party' : 'Add Party' ?></button> <?php if($edit_id > 0): ?> <a href="job_work_party_master.php" class="btn btn-outline-secondary">Cancel</a> <?php endif; ?> </div> </form> <div class="table-responsive"> <table class="table table-bordered table-sm"> <thead> <tr> <th>ID</th> <th>Party Name</th> <th>Short</th> <th>Mobile</th> <th>Address</th> <th>Status</th> <th>Action</th> </tr> </thead> <tbody> <?php foreach($rows as $r): ?> <tr> <td><?= $r['id'] ?></td> <td><?= htmlspecialchars($r['party_name']) ?></td> <td><?= htmlspecialchars($r['short_name']) ?></td> <td><?= htmlspecialchars($r['mobile']) ?></td> <td><?= htmlspecialchars($r['address']) ?></td> <td><?= $r['is_active'] ? 'Active' : 'Inactive' ?></td> <td> <a href="?edit=<?= (int)$r['id'] ?>" class="btn btn-sm btn-outline-primary">Edit</a> </td> </tr> <?php endforeach; ?> </tbody> </table> </div> </div> </div> <?php require_once __DIR__ . '/partials/footer.php'; ?>