<?php
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
ini_set ("display_errors", "0");
error_reporting(E_ALL);
require("../connect.php");

// receive your json object
$postvalue = json_decode(file_get_contents('php://input'));

// USER ACCESS
$stmtUserAccess = mysqli_query($conn, "SELECT DISTINCT username, employeecode, employeename, A.accessgroups, 
SUBSTRING_INDEX(`A`.`accessgroups`, ' - ', 1) AS `usertype`, SUBSTRING_INDEX(`A`.`accessgroups`, ' - ', -1) AS `userrole`, 
SUBSTRING_INDEX(SUBSTRING_INDEX(`A`.`accessgroups`, ' - ', 2), ' - ', -1 ) AS `userfunction`, modul, submodul, can_input, can_viewreport FROM
(SELECT field_12 AS username, field_643 AS employeecode, field_208 AS employeename, 
    (SELECT `name` FROM app_access_groups WHERE id = field_6)	AS accessgroups
FROM app_entity_1 WHERE field_643 = '".$postvalue->empcode."') A
LEFT JOIN
(SELECT accessgroups, modul, submodul, can_input, can_viewreport FROM
    (SELECT id, CONCAT(field_242,' - ', field_622,' - ', SUBSTRING_INDEX(field_649,' - ',-1)) accessgroups
    FROM app_entity_26 WHERE CONCAT(field_242,' - ', field_622,' - ', SUBSTRING_INDEX(field_649,' - ',-1)) = '".$postvalue->roletype."') t1
RIGHT JOIN
    (SELECT parent_item_id, 
        (SELECT `name` FROM app_global_lists_choices WHERE id = (SELECT `parent_id` FROM app_global_lists_choices WHERE id=field_969)) modul,
        (SELECT `name` FROM app_global_lists_choices WHERE id = field_969) submodul, field_970 AS can_input, field_972 AS can_viewreport
    FROM app_entity_64) t2
ON t2.parent_item_id = t1.id) B
ON B.accessgroups = A.accessgroups
ORDER BY username, employeecode, employeename, A.accessgroups, modul, submodul;");

$dataUserAccess = array();
while ($rowUserAccess = mysqli_fetch_assoc($stmtUserAccess)) {

    $nestedAccessData[] = array_map('utf8_encode', array("USERTYPE" => $rowUserAccess['usertype'], 
        "USERROLE" => $rowUserAccess['userrole'],
        "USERFUNCTION" => $rowUserAccess['userfunction'],
        "MENUMODULE" => $rowUserAccess['modul'], 
        "SUBMENU" => $rowUserAccess['submodul'], 
        "AUTHORIZED_INPUT" => $rowUserAccess['can_input'], 
        "AUTHORIZED_REPORT" => $rowUserAccess['can_viewreport']
    ));

    $dataUserAccess = array("NEWUSERACCESS" => $nestedAccessData);
}

// SITE MD
$stmtSiteMD = mysqli_query($conn, "SELECT id, parent_id, field_268 AS HOLDING, field_525 AS REGION, 
field_269 AS COMP_ID, field_270 AS SITE_ID, field_271 AS ESTATE, 
field_272 AS DIVCODE, field_523 AS DEPTCODE, field_524 AS SECTION, 
field_263 AS SITENAME, field_264 AS SITEDESC FROM app_entity_30;");

$dataSiteMD = array();
while ($rowSiteMD = mysqli_fetch_assoc($stmtSiteMD)) {

    $nestedSiteData[] = array_map('utf8_encode', array("SITEID" => $rowSiteMD['id'], 
        "PARENTSITEID" => $rowSiteMD['parent_id'], 
        "HOLDINGCODE" => $rowSiteMD['HOLDING'], 
        "REGIONCODE" => $rowSiteMD['REGION'], 
        "COMP_ID" => $rowSiteMD['COMP_ID'], 
        "SITE_ID" => $rowSiteMD['SITE_ID'], 
        "ESTATECODE" => $rowSiteMD['ESTATE'], 
        "DIVISIONCODE" => $rowSiteMD['DIVCODE'], 
        "DEPTCODE" => $rowSiteMD['DEPTCODE'], 
        "SECTIONCODE" => $rowSiteMD['SECTION'], 
        "SITENAME" => $rowSiteMD['SITENAME'],
        "SITEDESC" => $rowSiteMD['SITEDESC']
    ));

    $dataSiteMD = array("SITEMD" => $nestedSiteData);
}

// Data Employee
$stmtEmpMD = mysqli_query($conn, "SELECT emp.id AS EMPID, emp.field_303 AS HOLDING, emp.field_534 AS REGION, 
emp.field_304 AS COMP_ID, emp.field_305 AS SITE_ID, emp.field_306 AS ESTATE, emp.field_307 AS DIVCODE, 
emp.field_521 AS DEPARTMENT, emp.field_522 AS SECTIONCODE, emp.field_308 AS EMPCODE, emp.field_309 AS EMPNAME, 
lvl.field_398 AS POSITIONCODE, lvl.field_399 AS POSITIONNAME, emp.field_647 AS EMPFUNCTION, org.field_264 AS TEAMDESC FROM app_entity_31 emp 
INNER JOIN app_entity_36 lvl ON emp.field_310 = lvl.id INNER JOIN app_entity_30 org ON emp.parent_item_id = org.id
WHERE emp.field_307 = '".$postvalue->divcode."' AND emp.field_304 = '".$postvalue->compid."' 
AND emp.field_305 = '".$postvalue->siteid."' AND emp.field_306 = '".$postvalue->estatecode."' 
AND (emp.field_315 IS NULL OR emp.field_315 = 0)

UNION ALL

SELECT emp.id AS EMPID, emp.field_303 AS HOLDING, emp.field_534 AS REGION, 
emp.field_304 AS COMP_ID, emp.field_305 AS SITE_ID, emp.field_306 AS ESTATE, emp.field_307 AS DIVCODE, 
emp.field_521 AS DEPARTMENT, emp.field_522 AS SECTIONCODE, emp.field_308 AS EMPCODE, emp.field_309 AS EMPNAME, 
lvl.field_398 AS POSITIONCODE, lvl.field_399 AS POSITIONNAME, emp.field_647 AS EMPFUNCTION, org.field_264 AS TEAMDESC FROM app_entity_31 emp 
INNER JOIN app_entity_36 lvl ON emp.field_310 = lvl.id INNER JOIN app_entity_30 org ON emp.parent_item_id = org.id
WHERE emp.field_304 = '".$postvalue->compid."' AND emp.field_305 = '".$postvalue->siteid."' 
AND lvl.field_398 = 'DRV' AND (emp.field_315 IS NULL OR emp.field_315 = 0);");

$dataEmpMD = array();
while ($rowEmpMD = mysqli_fetch_assoc($stmtEmpMD)) {

    $nestedEmpData[] = array_map('utf8_encode', array("EMPID" => $rowEmpMD['EMPID'], 
        "HOLDINGCODE" => $rowEmpMD['HOLDING'], 
        "REGIONCODE" => $rowEmpMD['REGION'], 
        "COMP_ID" => $rowEmpMD['COMP_ID'], 
        "SITE_ID" => $rowEmpMD['SITE_ID'], 
        "ESTATECODE" => $rowEmpMD['ESTATE'], 
        "DIVCODE" => $rowEmpMD['DIVCODE'], 
        "DEPARTMENT" => $rowEmpMD['DEPARTMENT'], 
        "SEKSICODE" => $rowEmpMD['SECTIONCODE'], 
        "EMPCODE" => $rowEmpMD['EMPCODE'], 
        "EMPNAME" => $rowEmpMD['EMPNAME'],
        "POSITIONCODE" => $rowEmpMD['POSITIONCODE'], 
        "POSITIONNAME" => $rowEmpMD['POSITIONNAME'],
        "FUNCTION" => $rowEmpMD['EMPFUNCTION'],
        "TEAMDESC" => $rowEmpMD['TEAMDESC']
    ));

    $dataEmpMD = array("EMPLOYEEMD" => $nestedEmpData);
}

// Data Vehicle
$stmtVehicleMD = mysqli_query($conn, "SELECT vh.id AS VEHICLEID, vh.field_328 AS VEHICLECODE, ch.name AS VEHICLETYPE, 
vh.field_329 AS VEHICLEDESC, vh.field_331 AS PLATNO FROM app_entity_32 vh 
LEFT JOIN app_global_lists_choices ch ON ch.id = vh.field_327 
WHERE vh.field_323 = '".$postvalue->siteid."' OR vh.field_323 = 'ALL';");

$dataVehicleMD = array();
while ($rowVehicleMD = mysqli_fetch_assoc($stmtVehicleMD)) {

    $nestedVehicleData[] = array_map('utf8_encode', array("VHID" => $rowVehicleMD['VEHICLEID'], 
        "VHCODE" => $rowVehicleMD['VEHICLECODE'], 
        "VHTYPE" => $rowVehicleMD['VEHICLETYPE'], 
        "VHDESC" => $rowVehicleMD['VEHICLEDESC'], 
        "PLATNO" => $rowVehicleMD['PLATNO']
    ));

    $dataVehicleMD = array("VEHICLEMD" => $nestedVehicleData);
}

// Data Blok
$queryBlokData = "";
if ($postvalue->siteid == 'ALL') {
	$queryBlokData = "SELECT blk.id AS BLOKID, blk.field_406 AS COMP_ID, blk.field_407 AS SITE_ID, 
	blk.field_408 AS ESTATE, blk.field_409 AS DIVCODE, blk.field_414 AS BLOKCODE, FROM_UNIXTIME(blk.field_411, '%Y') AS PLANTYEAR, 
	blk.field_420 AS POKOKBLOK, blk.field_416 AS HEKTARBLOK, IFNULL(blk.field_424, 0) AS ACTUALBJR, 
	chtop.name AS TOPOGRAPHY, chcls.name AS KELASLAHAN, chppk.name AS BIBIT, chsec.name AS SEKSIPANEN FROM app_entity_34 blk
	INNER JOIN app_global_lists_choices chsec ON chsec.id = blk.field_1244 AND chsec.lists_id = 10
	LEFT JOIN app_global_lists_choices chtop ON chtop.id = blk.field_410 AND chtop.lists_id = 1
	LEFT JOIN app_global_lists_choices chcls ON chcls.id = blk.field_613 AND chcls.lists_id = 11
	LEFT JOIN app_global_lists_choices chppk ON chppk.id = blk.field_413 AND chppk.lists_id = 36;";
}
else if ($postvalue->siteid != 'ALL' && $postvalue->estatecode == 'ALL') {
    $queryBlokData = "SELECT blk.id AS BLOKID, blk.field_406 AS COMP_ID, blk.field_407 AS SITE_ID, 
	blk.field_408 AS ESTATE, blk.field_409 AS DIVCODE, blk.field_414 AS BLOKCODE, FROM_UNIXTIME(blk.field_411, '%Y') AS PLANTYEAR, 
	blk.field_420 AS POKOKBLOK, blk.field_416 AS HEKTARBLOK, IFNULL(blk.field_424, 0) AS ACTUALBJR, 
	chtop.name AS TOPOGRAPHY, chcls.name AS KELASLAHAN, chppk.name AS BIBIT, chsec.name AS SEKSIPANEN FROM app_entity_34 blk
	INNER JOIN app_global_lists_choices chsec ON chsec.id = blk.field_1244 AND chsec.lists_id = 10
	LEFT JOIN app_global_lists_choices chtop ON chtop.id = blk.field_410 AND chtop.lists_id = 1
	LEFT JOIN app_global_lists_choices chcls ON chcls.id = blk.field_613 AND chcls.lists_id = 11
	LEFT JOIN app_global_lists_choices chppk ON chppk.id = blk.field_413 AND chppk.lists_id = 36
    WHERE blk.field_406 = '".$postvalue->compid."' AND blk.field_407 = '".$postvalue->siteid."';";
}
else {
    $queryBlokData = "SELECT blk.id AS BLOKID, blk.field_406 AS COMP_ID, blk.field_407 AS SITE_ID, 
	blk.field_408 AS ESTATE, blk.field_409 AS DIVCODE, blk.field_414 AS BLOKCODE, FROM_UNIXTIME(blk.field_411, '%Y') AS PLANTYEAR, 
	blk.field_420 AS POKOKBLOK, blk.field_416 AS HEKTARBLOK, IFNULL(blk.field_424, 0) AS ACTUALBJR, 
	chtop.name AS TOPOGRAPHY, chcls.name AS KELASLAHAN, chppk.name AS BIBIT, chsec.name AS SEKSIPANEN FROM app_entity_34 blk
	INNER JOIN app_global_lists_choices chsec ON chsec.id = blk.field_1244 AND chsec.lists_id = 10
	LEFT JOIN app_global_lists_choices chtop ON chtop.id = blk.field_410 AND chtop.lists_id = 1
	LEFT JOIN app_global_lists_choices chcls ON chcls.id = blk.field_613 AND chcls.lists_id = 11
	LEFT JOIN app_global_lists_choices chppk ON chppk.id = blk.field_413 AND chppk.lists_id = 36
    WHERE blk.field_406 = '".$postvalue->compid."' AND blk.field_407 = '".$postvalue->siteid."' 
    AND blk.field_408 = '".$postvalue->estatecode."' AND blk.field_409 = '".$postvalue->divcode."';";
}

$stmtDataBlok = mysqli_query($conn, $queryBlokData);

$dataBlokMD = array();
while ($rowBlokMD = mysqli_fetch_assoc($stmtDataBlok)) {

    $nestedBlokData[] = array_map('utf8_encode', array("BLOKID" => $rowBlokMD['BLOKID'], 
        "COMP_ID" => $rowBlokMD['COMP_ID'], 
        "SITE_ID" => $rowBlokMD['SITE_ID'], 
        "ESTATECODE" => $rowBlokMD['ESTATE'], 
        "DIVCODE" => $rowBlokMD['DIVCODE'], 
        "BLOKCODE" => $rowBlokMD['BLOKCODE'], 
        "PLANTYEAR" => $rowBlokMD['PLANTYEAR'],          
        "POKOKBLOK" => $rowBlokMD['POKOKBLOK'], 
        "HEKTARBLOK" => $rowBlokMD['HEKTARBLOK'] != '' ? $rowBlokMD['HEKTARBLOK'] : "0", 
        "ACTUALBJR" => $rowBlokMD['ACTUALBJR'] != '' ? $rowBlokMD['ACTUALBJR'] : "0",
        "SEKSIPANEN" => $rowBlokMD['SEKSIPANEN'],
		"TOPOGRAPHY" => $rowBlokMD['TOPOGRAPHY'],
        "KELASLAHAN" => $rowBlokMD['KELASLAHAN'],
        "BIBIT" => $rowBlokMD['BIBIT']                               
    ));

    $dataBlokMD = array("BLOKMD" => $nestedBlokData);
}

// DATA TPH MANUAL MYSQLI
$stmtDataTPH = mysqli_query($conn, "SELECT id AS TPHID, parent_item_id AS BLOKID, field_562 AS COMP_ID, field_563 AS SITE_ID, 
field_564 AS ESTATE, field_565 AS DIVISION, field_566 AS BLOKCODE, field_569 AS TPHCODE, FROM_UNIXTIME(field_568, '%Y-%m-%d') AS PLANTYEAR, 
field_570 AS LUASHA, field_571 AS TOTALPOKOK, (SELECT `name` FROM app_global_lists_choices WHERE id = field_1904) AS POINTTYPE, 
field_576 AS LATITUDE, field_577 AS LONGITUDE FROM app_entity_43 WHERE field_565 = '".$postvalue->divcode."';");

$dataTPH = array();
while ($rowDataTPH = mysqli_fetch_assoc($stmtDataTPH)) {

    $nestedTPH[] = array_map('utf8_encode', array(
        "TPHID" => $rowDataTPH['TPHID'], 
        "BLOKID" => $rowDataTPH['BLOKID'], 
        "COMP_ID" => $rowDataTPH['COMP_ID'],
        "SITE_ID" => $rowDataTPH['SITE_ID'],
        "ESTATE" => $rowDataTPH['ESTATE'],
        "DIVISION" => $rowDataTPH['DIVISION'],
        "BLOKCODE" => $rowDataTPH['BLOKCODE'],
        "TPHCODE" => $rowDataTPH['TPHCODE'],
        "TAHUNTANAM" => $rowDataTPH['PLANTYEAR'],
        "LUASHEKTAR" => $rowDataTPH['LUASHA'],
        "TOTALPOKOK" => $rowDataTPH['TOTALPOKOK'],
        "POINTTYPE" => $rowDataTPH['POINTTYPE'],
        "LATITUDE" => $rowDataTPH['LATITUDE'],
        "LONGITUDE" => $rowDataTPH['LONGITUDE']
    ));

    $dataTPH = array("TPHMD" => $nestedTPH);
}

// Data Chart of Activity
$stmtDataCOA = mysqli_query($conn, "SELECT id AS COAID, 
field_1751 AS ACTCODE, field_1753 AS ACTGROUP, field_1750 AS ACTNAME,  
(SELECT `name` FROM app_global_lists_choices WHERE id = field_1746) AS FUNCNAME, 
(SELECT `name` FROM app_global_lists_choices WHERE id = field_1755) AS ACTUOM, 
(SELECT `name` FROM app_global_lists_choices WHERE id = field_1743) AS ACTLABEL FROM app_entity_84 
WHERE field_1742 = 'true' AND field_3026 = 'true';");

$dataCOA = array();
while ($rowDataCOA = mysqli_fetch_assoc($stmtDataCOA)) {

    $nestedCOA[] = array_map('utf8_encode', array(
        "COAID" => $rowDataCOA['COAID'], 
        "ACTCODE" => $rowDataCOA['ACTCODE'], 
        "ACTGROUP" => $rowDataCOA['ACTGROUP'],
        "ACTNAME" => $rowDataCOA['ACTNAME'],
        "FUNCNAME" => $rowDataCOA['FUNCNAME'],
        "ACTUOM" => $rowDataCOA['ACTUOM'],
        "ACTLABEL" => $rowDataCOA['ACTLABEL']
    ));

    $dataCOA = array("COAMD" => $nestedCOA);
}

// Data Material
$stmtDataMaterial = mysqli_query($conn, "SELECT id AS MATERIALID, field_2145 AS MATERIALCODE, field_2146 AS MATERIALNAME, 
(SELECT `name` FROM app_global_lists_choices WHERE id = field_2143) AS GOODSTYPE, 
(SELECT `name` FROM app_global_lists_choices WHERE id = field_2144) AS MATERIALCATEGORY, 
(SELECT `name` FROM app_global_lists_choices WHERE id = field_2149) AS UOM FROM app_entity_95 
WHERE field_2143 IN (452,454,455,456) AND field_2144 IN (276,277,275);");

$dataMaterial = array();
while ($rowDataMaterial = mysqli_fetch_assoc($stmtDataMaterial)) {

    $nestedCatalogueData[] = array(
        "MATERIALID" => utf8_encode($rowDataMaterial['MATERIALID']),
        "MATERIALCODE" => utf8_encode($rowDataMaterial['MATERIALCODE']),
        "MATERIALNAME" => utf8_encode($rowDataMaterial['MATERIALNAME']),
        "GOODSTYPE" => utf8_encode($rowDataMaterial['GOODSTYPE']),
        "MATERIALCATEGORY" => utf8_encode($rowDataMaterial['MATERIALCATEGORY']),
        "UOM" => utf8_encode($rowDataMaterial['UOM'])
    );

    $dataMaterial = array("MATERIALMD" => $nestedCatalogueData);
}

// Data Eksternal Company
$stmtDataExCo = mysqli_query($conn, "SELECT id AS SUPPLIERID, field_2120 AS SUPPLIERCODE, 
field_2121 AS SUPPLIERNAME, (SELECT `name` FROM app_global_lists_choices WHERE id = field_2127) AS SUPPLIERTYPE, 
(SELECT `name` FROM app_global_lists_choices WHERE id = field_2128) AS SUPPLIERSELL, 
(SELECT `name` FROM app_global_lists_choices WHERE id = field_2571) AS SUPPLIERINTER FROM app_entity_94;");

$dataEx = array();
while ($rowDataExCo = mysqli_fetch_assoc($stmtDataExCo)) {

	$nestedExternal[] = array_map('utf8_encode', array(
        "SUPPLIERID" => $rowDataExCo['SUPPLIERID'],
        "SUPPLIERCODE" => $rowDataExCo['SUPPLIERCODE'],
        "SUPPLIERNAME" => $rowDataExCo['SUPPLIERNAME'],
        "SUPPLIERTYPE" => $rowDataExCo['SUPPLIERTYPE'],
        "SUPPLIERSELL" => $rowDataExCo['SUPPLIERSELL'],
        "SUPPLIERINTER" => $rowDataExCo['SUPPLIERINTER']
    ));

    $dataEx = array("DATAEXCO" => $nestedExternal);

}
$stmtGlobalLists = mysqli_query($conn, "SELECT id AS OPTIONID, parent_id AS PARENTID, lists_id AS LISTID, 
name AS OPTIONNAME, 'from_global' AS TABLETYPE FROM app_global_lists_choices WHERE lists_id IN (7, 8, 24, 26, 29, 34, 35, 47)

UNION ALL

SELECT id AS OPTIONID, parent_id AS PARENTID, 
fields_id AS LISTID, name AS OPTIONNAME, 'from_fields' AS TABLETYPE FROM app_fields_choices WHERE fields_id IN (349);");

$dataGS = array();
while ($rowGlobalLists = mysqli_fetch_assoc($stmtGlobalLists)) {

    $nestedGlobalLists[] = array_map('utf8_encode', array(
        "OPTIONID" => $rowGlobalLists['OPTIONID'],
        "PARENTID" => $rowGlobalLists['PARENTID'],
        "LISTID" => $rowGlobalLists['LISTID'], 
        "OPTIONNAME" => $rowGlobalLists['OPTIONNAME'],
    	"TABLETYPE" => $rowGlobalLists['TABLETYPE']
    ));

    $dataGS = array("DATAGS" => $nestedGlobalLists);
}

$stmtGlobalVar = mysqli_query($conn, "SELECT id AS VARID, parent_id AS PARENTID, 
name AS VARNAME, value AS VARVALUE FROM app_global_vars WHERE parent_id IN (1, 27);");

$dataGlobalVar = array();
while ($rowGlobalVar = mysqli_fetch_assoc($stmtGlobalVar)) {

    $nestedGlobalVar[] = array_map('utf8_encode', array(
        "VARID" => $rowGlobalVar['VARID'],
        "PARENTID" => $rowGlobalVar['PARENTID'],
        "VARNAME" => $rowGlobalVar['VARNAME'], 
        "VARVALUE" => $rowGlobalVar['VARVALUE']
    ));

    $dataGlobalVar = array("DATAGLOBARVAR" => $nestedGlobalVar);
}

// Data Adjusment BJR
$stmtAdjustmentBJR = mysqli_query($conn, "SELECT field_1191 AS COMPANY, field_1192 AS SITE, 
field_1193 AS ESTATE, field_1194 AS DIVCODE, 
(SELECT field_414 FROM app_entity_34 WHERE id = field_1255) AS BLOKCODE, 
field_1252 AS PERIODT, field_1196 AS YIELDANGGARAN, field_1197 AS YIELDPOTENSI, 
field_1198 AS YIELDAKTUAL, field_1199 AS BJRANGGARAN, field_1200 AS BJRPOTENSI, 
field_1201 AS BJRAKTUAL, field_1247 AS JJGANGGARAN, field_1248 AS JJGPOTENSI, 
field_1249 AS JJGAKTUAL, FORMAT(field_1201/field_1199*100, 2) AS YIELDPERCENTANGGARAN, 
FORMAT(field_1201/field_1200*100, 2) AS YIELDPERCENTPOTENSI FROM app_entity_73;");

$dataAdjustmentBJR = array();	
while ($rowAdjustmentBJR = mysqli_fetch_assoc($stmtAdjustmentBJR)) {
	$nestedAdjustmentBJR[] = array_map('utf8_encode', array(
        "COMPANY" => $rowAdjustmentBJR['COMPANY'],
        "SITE" => $rowAdjustmentBJR['SITE'],
        "ESTATE" => $rowAdjustmentBJR['ESTATE'],
        "DIVCODE" => $rowAdjustmentBJR['DIVCODE'],
        "BLOKCODE" => $rowAdjustmentBJR['BLOKCODE'],
        "PERIODT" => $rowAdjustmentBJR['PERIODT'],
        "YIELDANGGARAN" => $rowAdjustmentBJR['YIELDANGGARAN'].' KG',
        "YIELDPOTENSI" => $rowAdjustmentBJR['YIELDPOTENSI'].' KG',
        "YIELDAKTUAL" => $rowAdjustmentBJR['YIELDAKTUAL'].' KG',
        "BJRANGGARAN" => $rowAdjustmentBJR['BJRANGGARAN'].' KG',
        "BJRPOTENSI" => $rowAdjustmentBJR['BJRPOTENSI'].' KG',
        "BJRAKTUAL" => $rowAdjustmentBJR['BJRAKTUAL'].' KG',
        "JJGANGGARAN" => $rowAdjustmentBJR['JJGANGGARAN'].' JJG',
        "JJGPOTENSI" => $rowAdjustmentBJR['JJGPOTENSI'].' JJG',
        "JJGAKTUAL" => $rowAdjustmentBJR['JJGAKTUAL'].' JJG',
        "YIELDPERCENTANGGARAN" => $rowAdjustmentBJR['YIELDPERCENTANGGARAN'].' %',
        "YIELDPERCENTPOTENSI" => $rowAdjustmentBJR['YIELDPERCENTPOTENSI'].' %'
    ));

    $dataAdjustmentBJR = array("DATABLOKDETAIL" => $nestedAdjustmentBJR);
}


// Convert all data to json, so the android can fetch the data
echo json_encode($dataUserAccess + $dataSiteMD + $dataEmpMD + $dataVehicleMD + 
$dataBlokMD + $dataTPH + $dataCOA + $dataMaterial + $dataEx + $dataGS + $dataGlobalVar + $dataAdjustmentBJR);

?>