<?php
set_time_limit(300); // 300 detik (5 menit)
ini_set('max_execution_time', 300); // 5 menit
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once('includes/load.php');
$platform = 1;
$shopId = $_GET['shop_id'];
$sql = "SELECT access_token, shop_id, refresh_token, code FROM shop WHERE platform_id = $platform AND shop_id = $shopId";
$stmt = $db->prepare($sql);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        $shopId = $row['shop_id'];
        $accessToken = $row['access_token'];
        $refreshToken = $row['refresh_token'];
        $orderList = getShipmentListAll($accessToken, $refreshToken, $shopId);
        if ($orderList == null) {
            echo json_encode(["message" => "No shipment found"]);
            // continue;
        }
        $countOrder = count($orderList);
        $arrayPackingList = array();
        for ($i = 0; $i < $countOrder; $i++) {
            $queueItem['shop_id'] = $shopId;
            $queueItem['access_token'] = $accessToken;
            $queueItem['refresh_token'] = $refreshToken;
            $queueItem['order_sn'] = $orderList[$i];
            $queueItem['log_json'] = '{}';
            $queueItem['platform_id'] = $platform;
            $response = getDetailOrder(
                $accessToken,
                $refreshToken,
                $shopId,
                $orderList[$i]
            );
            echo "<pre>";
            var_dump($response);
            echo "</pre>";
        }
    }
    // echo json_encode(["message" => "Successfully"]);
} else {
    echo json_encode(["message" => "No access token found"]);
}
