<?php

$response = array();

require_once __DIR__ . '/catchexception.php';
require_once __DIR__ . '/db_config.php';

// $paraimeino = urldecode($_POST['paraimeino']);
$paraimeino ='f4f8ffbef470be87';

try {

    if ($paraimeino != "") {

        $paraquery = "SELECT
        coalesce(exchange_id,0) as exchange_id,
        coalesce(currency_short_name,'') as currency_short_name,
        coalesce(exchange_rate,0) as exchange_rate,
        coalesce(to_char(createddate,'YYYY-MM-DD HH24:MI:SS'),'') as createddate,
        coalesce(to_char(updateddate,'YYYY-MM-DD HH24:MI:SS'),'') as updateddate,
        coalesce(to_char(exchange_date,'YYYY-MM-DD'),'') as exchange_date,
        'Insert' as process
        FROM tblexchangerate
        ORDER BY exchange_id";

        $result = pg_query($con, $paraquery);

        if (!empty($result)) {

            if (pg_num_rows($result) > 0) {

                $response["Value"] = array();

                while ($row = pg_fetch_assoc($result)) {

                    $report = array();

                    $report["exchange_id"] = $row["exchange_id"];
                    $report["currency_short_name"] = $row["currency_short_name"];
                    $report["exchange_rate"] = $row["exchange_rate"];
                    $report["createddate"] = $row["createddate"];
                    $report["updateddate"] = $row["updateddate"];
                    $report["exchange_date"] = $row["exchange_date"];
                    $report["process"] = $row["process"];

                    array_push($response["Value"], $report);
                }

                $response["success"] = 1;

                echo json_encode($response, JSON_UNESCAPED_UNICODE);

            } else {

                $response["success"] = 0;
                $response["message"] = "No Exchange Rate Found";

                echo json_encode($response);
            }

        } else {

            $response["success"] = 0;
            $response["message"] = "No Exchange Rate Found";

            echo json_encode($response);
        }

    } else {

        // required field is missing
        $response["success"] = 0;
        $response["message"] = "Required field(s) is missing";

        echo json_encode($response, JSON_UNESCAPED_UNICODE);
    }

    mch_db_release($con);

} catch (Exception $e) {

    mch_db_release($con);

    echo 'Message: ' . $e->getMessage();
}
?>