<?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(currency_id,0) as currency_id,
        coalesce(currency_name,'') as currency_name,
        coalesce(currency_short_name,'') as currency_short_name,
        coalesce(tax_name,'') as tax_name,
        coalesce(tax_id,0) as tax_id,
        'Insert' as process
        FROM tblcurrency";

        $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["currency_id"] = $row["currency_id"];
                    $report["currency_name"] = $row["currency_name"];
                    $report["currency_short_name"] = $row["currency_short_name"];
                    $report["tax_name"] = $row["tax_name"];
                    $report["tax_id"] = $row["tax_id"];
                    $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 Currency Found";

                echo json_encode($response);
            }
        } else {

            $response["success"] = 0;
            $response["message"] = "No Currency 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();
}
?>