<?php
    include "../db/headerApi.php";
    include "../db/connection_main.php";

    $json = file_get_contents('php://input');
    $data = json_decode($json);

    $sql = "SELECT DISTINCT a.p_size id, b.siz_nm text
             FROM apps.YTY_ITEM_MAPPING_SKUSIZEBRAND_V a, 
                  production.size_master b
            WHERE a.p_size = b.siz_main
              AND a.sku = :p_sku
         ORDER BY b.siz_nm";

    $sqlarr = oci_parse($dbcon , $sql);
    oci_bind_by_name($sqlarr, ':p_sku', $data->sku->ID);
    $r = oci_execute($sqlarr);
    $resMsg = "OK";

    if (!$r) {
         $e = oci_error($sqlarr);
         $resMsg = json_encode($e['message']);
    }
    oci_fetch_all($sqlarr, $rows_main, null, null, OCI_FETCHSTATEMENT_BY_ROW);

    $result[] = [
        "message" => $resMsg,
        "data" => $rows_main
    ];

    print json_encode($result);
?>