« Back to History
vehicle_data_add.php
|
20260721_154033.php
Initial Bulk Import
Copy Code
<?php require_once __DIR__ . '/helpers/activity_helper.php'; /* ====================================================================== FILE: /erp/vehicle_data_add.php PURPOSE: Vehicle Master Entry ====================================================================== */ error_reporting(E_ALL); ini_set('display_errors', 1); /* ---------- AUTH + DB ---------- */ require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('vehicle_data_add'); $pdo = $ctx['pdo']; $COMPANY_ID = (int)$ctx['company_id']; $USER_ID = (int)$ctx['user']['id']; $u = $ctx['user']; function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); } /* ---------- SAVE ---------- */ $msg = $err = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $vehicle_no = trim($_POST['vehicle_no'] ?? ''); $vehicle_type = trim($_POST['vehicle_type'] ?? ''); $owner_name = trim($_POST['owner_name'] ?? ''); $mobile = trim($_POST['mobile'] ?? ''); /* ---- VALIDATION ---- */ if ($vehicle_no === '' || $vehicle_type === '' || $owner_name === '') { $err = 'Vehicle No, Type and Owner Name are required.'; } else { /* ---- DUPLICATE CHECK (COMPANY + VEHICLE NO) ---- */ $chk = $pdo->prepare(" SELECT id FROM vehicle_data WHERE company_id = ? AND vehicle_no = ? AND is_active = 1 LIMIT 1 "); $chk->execute([$COMPANY_ID, $vehicle_no]); if ($chk->fetch()) { $err = 'Vehicle already exists.'; } else { $pdo->prepare(" INSERT INTO vehicle_data ( company_id, vehicle_no, vehicle_type, owner_name, mobile, is_active, created_at, created_by ) VALUES (?,?,?,?,?,1, NOW(), ?) ")->execute([ $COMPANY_ID, $vehicle_no, $vehicle_type, $owner_name, $mobile ?: null, $USER_ID ]); activity_create('parcel', 'vehicle_data_add', 0, 'Vehicle added: ' . $vehicle_no . ', Type: ' . $vehicle_type . ', Owner: ' . $owner_name . ', Mobile: ' . $mobile); $msg = 'Vehicle added successfully.'; } } } /* ---------- HEADER ---------- */ $page_title = 'Vehicle Entry'; require_once __DIR__ . '/partials/header.php'; ?> <div class="container-fluid py-3"> <div class="row justify-content-center"> <div class="col-12 col-xl-10"> <div class="card shadow-sm border-0"> <div class="card-body p-4"> <div class="d-flex flex-wrap justify-content-between align-items-center gap-2 mb-4"> <div> <h2 class="h4 mb-1">Vehicle Entry</h2> <p class="text-muted mb-0">Add a new vehicle master record.</p> </div> </div> <?php if ($msg): ?> <div class="alert alert-success" role="alert"><?= h($msg) ?></div> <?php endif; ?> <?php if ($err): ?> <div class="alert alert-danger" role="alert"><?= h($err) ?></div> <?php endif; ?> <form method="post" autocomplete="off"> <div class="row g-3"> <div class="col-12 col-md-6 col-xl-3"> <label class="form-label">Vehicle No</label> <input type="text" name="vehicle_no" class="form-control" value="<?= h($_POST['vehicle_no'] ?? '') ?>" required> </div> <div class="col-12 col-md-6 col-xl-3"> <label class="form-label">Vehicle Type</label> <input type="text" name="vehicle_type" class="form-control" value="<?= h($_POST['vehicle_type'] ?? '') ?>" placeholder="Truck / Tempo / Pickup" required> </div> <div class="col-12 col-md-6 col-xl-3"> <label class="form-label">Owner Name</label> <input type="text" name="owner_name" class="form-control" value="<?= h($_POST['owner_name'] ?? '') ?>" required> </div> <div class="col-12 col-md-6 col-xl-3"> <label class="form-label">Mobile</label> <input type="text" name="mobile" class="form-control" value="<?= h($_POST['mobile'] ?? '') ?>" maxlength="15"> </div> <div class="col-12 d-flex justify-content-end pt-2"> <button type="submit" class="btn btn-primary px-4">Save</button> </div> </div> </form> </div> </div> </div> </div> </div> <?php require_once __DIR__ . '/partials/footer.php'; ?>