<?php
    include "../db/headerApi.php";
    include "../db/connection_main.php";

    $json = file_get_contents('php://input');
    $data = json_decode($json);

    $newid = $data->ID;
    $sql = "UPDATE YTYCUSTOM.XX_YTY_INCOMING_OUTGOING_INSPECTION_SHIP_HD
               SET GATEOUT_BY = :GATEOUT_BY,
                   GATEOUT_DATE = SYSDATE
             WHERE ID = :SHIP_ID";
        
    $sqlarr = oci_parse($dbcon , $sql);
    oci_bind_by_name($sqlarr, ':GATEOUT_BY', $data->USERID);
    oci_bind_by_name($sqlarr, ':SHIP_ID', $newid);
    $r = oci_execute($sqlarr, OCI_NO_AUTO_COMMIT);

    if (!$r) {
        $e = oci_error($sqlarr);
        $errorMsg = json_encode($e['message']);
        goto finalStep;
    }

finalStep:
    $result = [];
    if ($errorMsg == "") {
        oci_commit($dbcon);
        $result[] = [
            "message" => "Success",
            "id" => $newid
        ];
    } else {
        oci_rollback($dbcon);
        $result[] = [
            "message" => $errorMsg,
            "id" => ""
        ];
    }
    print json_encode($result);
?>