<?php
ini_set ("display_errors", "0");
error_reporting(E_ALL);

$paramsCtg = array(
	'key' => 'uq9gWhofzHpCbQZTaaCVyh6q6tiiwZfN9CfVbwGw',  
  	'username' => 'admin',
	'password' => 'terimakasih',
  	'action' => 'select',
  	'entity_id' => 95, //The ID of the entity from which records will be selected
  	'select_fields' => '2145, 2146, 2143, 2144, 2149, 2150, 2156, 2157', //ID fields, the values of which will be selected
	'filters' => array('2144'=> '280,281,513,541')
);
 						                                    
$ctg = curl_init('https://agri.digibizdev.online/api/rest.php');
curl_setopt($ctg, CURLOPT_HEADER, false);
curl_setopt($ctg, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ctg, CURLOPT_POST, 1);
curl_setopt($ctg, CURLOPT_POSTFIELDS, http_build_query($paramsCtg));
curl_setopt($ctg, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ctg, CURLOPT_TIMEOUT, 0);			
$resultCtg = curl_exec($ctg);
curl_close($ctg);

$resultCtg = json_decode($resultCtg, true);

$dataCatalogue = array();
for ($x = 0; $x < count($resultCtg['data']); $x++) {

	$nestedCatalogueData[] = array(
        "MATERIALID" => $resultCtg['data'][$x]['id'],
        "MATERIALCODE" => $resultCtg['data'][$x][2145],
        "MATERIALNAME" => $resultCtg['data'][$x][2146],
        "GOODSTYPE" => $resultCtg['data'][$x][2143],
        "MATERIALCATEGORY" => $resultCtg['data'][$x][2144],
        "UOM" => $resultCtg['data'][$x][2149]
    );

    $dataCatalogue = array("CATALOGUEMD" => $nestedCatalogueData);
}

echo json_encode($dataCatalogue, JSON_UNESCAPED_UNICODE);
?>