prepare("SELECT id FROM transit_vehicles WHERE id=? AND org_id=? LIMIT 1"); $chk->execute([$vehicleId, $transit_org_id]); if (!$chk->fetch()) jsonError('Vehicle not found or access denied', 404); $plate = filterRequest('plate'); if ($plate) { $plate = strtoupper($plate); $dup = $transit_con->prepare("SELECT id FROM transit_vehicles WHERE plate=? AND id<>? LIMIT 1"); $dup->execute([$plate, $vehicleId]); if ($dup->fetch()) jsonError('Vehicle plate already registered', 409); } $vType = filterRequest('vehicle_type'); if ($vType && !in_array($vType, ['bus','minibus','van','other'])) $vType = null; $transit_con->prepare( "UPDATE transit_vehicles SET plate=COALESCE(?, plate), make=COALESCE(?, make), model=COALESCE(?, model), year=COALESCE(?, year), color=COALESCE(?, color), capacity=COALESCE(?, capacity), vehicle_type=COALESCE(?, vehicle_type), notes=COALESCE(?, notes) WHERE id=?" )->execute([ $plate, filterRequest('make'), filterRequest('model'), filterRequest('year', 'int'), filterRequest('color'), filterRequest('capacity', 'int'), $vType, filterRequest('notes'), $vehicleId, ]); jsonSuccess(['vehicle_id' => $vehicleId], 'Vehicle updated');