groups -> licenses dalam format JSON. * * METHOD: GET * ENDPOINT: /api/myasset * AUTHENTICATION: Required (Bearer token atau session) * * RESPONSE SUCCESS (200): * ======================= * { * "success": true, * "data": { * "username": "dayansgi", * "fullName": "SGI Kutai", * "groups": [ * { * "userGroupID": "713", * "groupName": "Group Name", * "licenses": [ * { * "license": "BM 9613 RC", * "tid": "862292051351138" * } * ] * } * ] * }, * "statistics": {...}, * "processing_info": {...} * } * * BUSINESS LOGIC: * =============== * 1. Get user groups berdasarkan username dari session * 2. Untuk setiap group, get licenses yang valid (endTime > now) * 3. Filter licenses berdasarkan customerID range (MinNo - MaxNo) * 4. Return dalam format JSON clean tanpa HTML * 5. Set session variables untuk group mapping (optional) * * DATABASE TABLES: * ================ * - tbUserGroupMulti: User group relationships * - tbUserGroup: Group definitions dengan MinNo/MaxNo * - tbLicenseTran: License transactions dengan customerID dan endTime * * AUTHOR: Rodhi * DATE: 2026-01-19 * VERSION: 1.0 */ require_once __DIR__.'/../models/database.php'; require_once __DIR__.'/../helpers/session_helper.php'; require_once __DIR__.'/../auth/middleware.php'; if (!headers_sent()) { header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: GET, POST, OPTIONS'); header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Auth-Token'); header('Access-Control-Allow-Credentials: true'); header('Content-Type: application/json'); } // Set content type header('Content-Type: application/json'); // Handle CORS preflight if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { http_response_code(200); exit; } // Only allow GET method if ($_SERVER['REQUEST_METHOD'] !== 'GET') { http_response_code(405); echo json_encode([ 'error' => 'Method not allowed', 'allowed_methods' => ['GET'] ]); exit; } // Start performance monitoring $startTime = microtime(true); $startMemory = memory_get_usage(true); // Debug: Log API access // error_log("MyAsset API accessed"); // error_log("Request method: " . $_SERVER['REQUEST_METHOD']); try { // Require authentication $user = authRequired(); // Debug: Log authenticated user // error_log("MyAsset API - Authenticated user: " . $user); // Get database connection $pdo = Database::getConnection(); // Get user information from session data (dari login response) $fullName = $user; // Default to username // Try to get fullName from session or use username // Note: fullName biasanya sudah ada di login response // Initialize response data $responseData = array( 'username' => $user, 'fullName' => $fullName, 'groups' => array() ); // Debug: Log user groups query // error_log("MyAsset API - Getting user groups for: " . $user); // Step 1: Get user groups (berdasarkan original SQL) $sql1 = "SELECT tbUserGroupMulti.userGroupID, tbUserGroup.des FROM tbUserGroupMulti INNER JOIN tbUserGroup ON tbUserGroupMulti.userGroupID = tbUserGroup.userGroupID WHERE userName = ? ORDER BY tbUserGroup.des ASC"; $stmt1 = $pdo->prepare($sql1); $stmt1->execute([$user]); $userGroups = $stmt1->fetchAll(PDO::FETCH_ASSOC); // Debug: Log found groups // error_log("MyAsset API - Found " . count($userGroups) . " groups for user: " . $user); // Process each group foreach ($userGroups as $group) { $groupData = array( 'userGroupID' => $group['userGroupID'], 'groupName' => $group['des'], 'licenses' => array() ); // Add to HTML tree // $htmlTree .= '
' . htmlspecialchars($group['des']) . '';
// $htmlTree .= '
' . htmlspecialchars($license['license']);
// $htmlTree .= '';
// $htmlTree .= '