<?php
/* 	
 * Author   : Dhidhik / Tanggal : 26-11-2015	
 * note     : 
 * Revisi   : 
 */
//---------Untuk privellege Print and export excel ----------//
if (isset($group_user)) {
    if ($group_user->PrintPrivillage == 1) {
        $cek_autority_print = "";
    } else {
        $cek_autority_print = "disabled";
    }

    if ($group_user->ExcelPrivillage == 1) {
        $cek_autority_excel = "";
    } else {
        $cek_autority_excel = "disabled";
    }
    if ($group_user->EditPrivillage == 1) {
        $cek_autority_edit = "";
    } else {
        $cek_autority_edit = "disabled";
    }
} else {
    $cek_autority_print = "disabled";
    $cek_autority_excel = "disabled";
    $cek_autority_edit = "disabled";
}
//---------END Untuk privellege Print and export excel ----------//
?>
<!--<link rel="stylesheet" type="text/css" href="<?php echo base_url() ?>assets/custom/css/treetable/bootstrap.css">-->
<link rel="stylesheet" type="text/css" href="<?php echo base_url() ?>assets/custom/css/treetable/jquery.treegrid.css">
<script type="text/javascript" src="<?= base_url() ?>assets/custom/js/treetable/jquery.treegrid.bootstrap3.js"></script>
<script type="text/javascript" src="<?= base_url() ?>assets/custom/js/treetable/jquery.treegrid.js"></script>
<style type="text/css">

    .margin-left5persen{
        margin-left:5%; 
    }
    .margin-right5persen{
        margin-right:5%; 
    }
    @media print {
        .noPrint { display: none; visibility: hidden; }
        .displayPrint{
            display: inline-block;
            left: 0px;
            position: fixed;
            background-color: white;
            width: 82%;
        }
        .layout-panel-west{display: none; visibility: hidden; }
        table{
            width: 100%;
        }       
    }
    /* style sheet for "A4" printing */
    @media print and (width: 21cm) and (height: 29.7cm) {
        @page {
            margin: 3cm;
        }
    }

    /* style sheet for "letter" printing */
    @media print and (width: 8.5in) and (height: 11in) {
        @page {
            margin: 1in;
        }
    }

    /* A4 Landscape*/
    @page {
        size: A4 landscape;
    }
</style>
<div id="cc" class="easyui-layout" data-options="fit:true, border:false">
    <div id="west-panel" data-options="region:'west',split:true,border:true" class="noPrint" title="Filter" style="width:190px;background-color:#CCCCFF;padding:5px;">
        <form class="form-filter noPrint" method="post" name="formFilterDept" id="formFilterDept" >
            <table width="100%" cellpadding="0" cellspacing="0">
                <!-------copy company dari sini------------------------------------------------------------------------>
                <tr>
                    <td align="left" style="padding-bottom:8px;">
                        <b>by Company</b>
                    </td>
                </tr>
                <tr>
                    <td align="left">                        
                        <select name="cmb_company" id="cmb_company" 
                                class="easyui-combobox" 
                                style="width:174px;"
                                data-options="
                                value:'<?php echo $this->session->userdata('company'); ?>',
                                valueField:'CompanyCode',
                                textField:'CompanyName',
                                url:'<?php echo base_url(); ?>custom/get_data/company_find_master',
                                onSelect: function(rec){
                                var url = '<?php echo base_url(); ?>custom/get_data/branch_by_company_new/'+rec.CompanyCode;
                                $('#cmb_branch').combobox('reload', url);
                                $('#cmb_branch').combobox('setValue', '');
                                }
                                "
                                editable="true">
                        </select>
                    </td>
                </tr>
                <!---end COMPANY select--------------------------------------------------------------------- -->

                <!--ini separator-------------------------------------------->
                <tr><td colspan="2"><div class="tr-divider"></div></td></tr>
                <!--end-------------------------------------------------------->

                <!-------copy branch dari sini------------------------------------------------------------------------>
                <tr>
                    <td align="left" style="padding-bottom:8px;">
                        <b>by Branch/Depo</b>
                    </td>
                </tr>
                <tr>
                    <td align="left">
                        <select name="cmb_branch" id="cmb_branch" 
                                class="easyui-combobox" 
                                style="width:174px;"  
                                data-options="
                                value :'<?php echo $this->session->userdata('branch'); ?>',
                                valueField:'BranchCode', 
                                textField:'BranchName', 
                                url:'<?php echo base_url(); ?>custom/get_data/branch_by_company_new/<?php echo $this->session->userdata('company'); ?>'
                                " editable="true">
                        </select>
                    </td>
                </tr>
                <!------------end copy branch dari sini---------------------------------------------------------------->

                <!--ini separator-------------------------------------------->
                <tr><td colspan="2"><div class="tr-divider"></div></td></tr>
                <!--end-------------------------------------------------------->

                <!-------copy Invoice Receipt dari sini------------------------------------------------------------------------>
                <tr>
                    <td align="left" style="padding-bottom:8px;">
                        <b>by Departement</b>
                    </td>
                </tr>
                <tr>
                    <td align="left">
                        <input id="txt_departement" name="txt_departement" placeholder="< Departement Name >" style="margin:2px 0px 3px;width:100%;height:18px;border:1px solid #CCC;">
                    </td>
                </tr>
                <!------------end copy Invoice Receipt dari sini---------------------------------------------------------------->

                <!--ini separator-------------------------------------------->
                <tr><td colspan="2"><div class="tr-divider"></div></td></tr>
                <!--end-------------------------------------------------------->
                <!-------copy branch dari sini------------------------------------------------------------------------>
                <tr>
                    <td align="left" style="padding-bottom:8px;">
                        <b>Data in </b>
                    </td>
                </tr>
                <tr>
                    <td align="left">
                        <select name="cmb_collapse" id="cmb_collapse" 
                                class="easyui-combobox" 
                                style="width:174px;"  
                                editable="false">
                            <option value="collapseAll" selected > Collapse </option>
                            <option value="expandAll"> Expand </option>
                        </select>

                    </td>
                </tr>
                <!------------end copy branch dari sini---------------------------------------------------------------->

                <!--ini separator-------------------------------------------->
                <tr><td colspan="2"><div class="tr-divider"></div></td></tr>
                <!--end-------------------------------------------------------->

                <!----------------------------------ini by status---------------------------------------------------------->
                <!--<tr>
                    <td style="padding-bottom:8px;"><b>by Sold Status</b></td>
                </tr>
                <tr>
                    <td>
                        <input type="checkbox" name="chk_TransStatus" value="0" style="margin-left:0px;"  checked/> Inventories
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="checkbox" name="chk_TransStatus" value="1" style="margin-left:0px;" checked/> Sold
                    </td>
                </tr> -->
<!--                <tr>
                    <td>
                        <input type="checkbox" name="chk_TransStatus" value="2" style="margin-left:0px;"  /> -
                    </td>
                </tr>-->
                <!--<tr>
                    <td>
                        <input type="checkbox" name="chk_TransStatus" value="3" style="margin-left:0px;"  /> Return
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="checkbox" name="chk_TransStatus" value="4" style="margin-left:0px;"  /> Dispose
                    </td>
                </tr>
                -->

                <tr class="divTranstatus">
                    <td></td>
                </tr>
                <!------------------------------------------------------end by status-------------------------------------------------------------------------------------------->

                <!--copy dari sini untuk button reset dan search-->
                <tr>
                    <td height="38">
                        <div style="float:right;">
                            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-reload'" onClick="location.reload();" >Reset</a>
                            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onClick="searching_data_fixed_asset_list('', '');" >Search</a>
                        </div>
                    </td>
                </tr>
                <!--end copy dari sini untuk button reset dan search-------------------------->

            </table>
        </form>
    </div>

    <div data-options="region:'center',border:false,iconCls:'icon-ok'">
        <div style="padding:2px" id="form-header">
            <a href="#" class="easyui-linkbutton noPrint" data-options="plain:true,iconCls:'icon-print'" onClick="window.print_detail()" <?= $cek_autority_print ?>>Print</a>
            &nbsp;&nbsp;           
            <a href="#" class="easyui-linkbutton noPrint" data-options="plain:true,iconCls:'icon-excel'" onclick="actionExcel()" <?= $cek_autority_excel ?>>Export File </a>
            &nbsp;&nbsp;           
            <a href="#" class="easyui-linkbutton noPrint" data-options="plain:true,iconCls:'icon-reload'" onclick="location.reload();">Refresh</a>
        </div><br />
        <div id="databox" class="displayPrint"></div>	
    </div>

</div>

<script type="text/javascript">
    var shortingText = "";
    var rstTypeShorting = "ASC";
    var pre_url = base_url + 'report/index_fixed_asset/pre_ajax_reloadDataFixedAssetList';
    var url = base_url + 'report/index_fixed_asset/ajax_reloadDataFixedAssetList';
    var dataSend = {};
    var noTree = 1;
    var noUrutLevel1 = 1;
    var stringHTML = "";
    var pages = {limit: limitRowInPage(), pages: 1};
    var tempArSumm = [];
    var dataFooter = [];
    function variableDefault() {
        shortingText = "";
        rstTypeShorting = "ASC";
        dataSend = {};
        noTree = 1;
        noUrutLevel1 = 1;
        stringHTML = "";
        pages['pages'] = 1;
        tempArSumm = [];
        dataFooter = [];
    }

    function checkShorting(txtCheckShorting) {
        if (shortingText == txtCheckShorting) {
            rstTypeShorting == "DESC" ? rstTypeShorting = "ASC" : rstTypeShorting = "DESC";
        } else {
            rstTypeShorting = "ASC";
            shortingText = txtCheckShorting;
        }
        //alert("cek="+txtCheckShorting+"-"+rstTypeShorting);
        return rstTypeShorting;
    }
    function startLoad() {
        //========load tanggal=============//
        //$('#txt_DateFrom').datebox('enable', true);
        $('#txt_DateTo').datebox('enable', true);

//        if ($('#txt_DateFrom').datebox('getValue') == "" || $('#txt_DateFrom').datebox('getValue') == undefined) {
//            $('#txt_DateFrom').datebox('setValue', '<?= date('01-m-Y') ?>');
        //$('#txt_DateTo').datebox('setValue', 'today');
        //}
        //========END load tanggal=============//        

        var searchParameter = {};

        if ($('#cmb_company').length > 0) {
            searchParameter['cmb_company'] = $('#cmb_company').combobox('getValue');
        }
        if ($('#cmb_branch').length > 0) {
            searchParameter['cmb_branch'] = $('#cmb_branch').combobox('getValue');
        }

        if ($('#txt_DateTo').length > 0) {
            //searchParameter['txt_DateFrom'] = $('#txt_DateFrom').datebox('getValue');
            searchParameter['txt_DateTo'] = $('#txt_DateTo').datebox('getValue');
        }

        searchParameter['chk_TransStatus'] = new Array();
        $.each($('input[name="chk_TransStatus"]:checked'), function () {
            searchParameter['chk_TransStatus'].push($(this).val());
        });

        return searchParameter;
    }
    $(document).ready(function () {
        //============= transtatus ========================//
        var listTrans = [
            {"status": "all", "checked": ""},
            {"status": "inventories", "checked": "checked"},
            {"status": "sold", "checked": "checked"},
            {"status": "return", "checked": ""},
            {"status": "dispose", "checked": ""}
        ];//daftar Transtatus yang dipakai, value parameter nya liat di custom js
        toHTMLTranstatusReport("divTranstatus", listTrans);//untuk memanggil html Transtatus        
        //============= end transtatus ========================//

        startLoad();//Load awal
    });

    function searching_data_fixed_asset_list(txtTable, txtFieldShorting) {//(namaVariableTabelDiModel, namaField)
//        var url          = base_url + 'report/index_fixed_asset/ajax_reloadDataFixedAssetList';
        variableDefault();
        var getValue = startLoad();
        var typeShorting = checkShorting(txtFieldShorting);
        var dataIn = $('#cmb_collapse').combobox('getValue');

        dataSend = {
            pages: pages,
            predata: [],
            cmb_company: getValue['cmb_company'] == undefined ? "" : getValue['cmb_company'],
            cmb_branch: getValue['cmb_branch'] == undefined ? "" : getValue['cmb_branch'],
            txt_departement: document.formFilterDept.txt_departement.value,
            chk_TransStatus: getValue['chk_TransStatus'],
            txtTable: txtTable,
            txtField: txtFieldShorting,
            typeShorting: typeShorting,
            dataIn: dataIn
        };
        if ($('#cmb_branch').combobox('getValue') == undefined) {
            $('#cmb_branch').combobox('clear');
            var strAlert = strMessageAlert_report('branchIsEmpty');
            messageAlertBiasa('Warning', strAlert, 'error');
        }
        else if ($('#cmb_company').combobox('getValue') == undefined) {
            $('#cmb_company').combobox('clear');
            var strAlert = strMessageAlert_report('companyIsEmpty');
            messageAlertBiasa('Warning', strAlert, 'error');
        }
        else {
            modal_open('Progress Bar', 'dlg_loading');
            $.post(pre_url, dataSend).done(function (pre_result) {//preAjax
                //var stringHTML = "";   // untuk menyimpan yang akan ditampilkan ke layar
                var preResult = JSON.parse(pre_result);
                //Array Pre_result diambil code nya saja
                var dataTopHeader = {
                    CompanyName: preResult.company.CompanyName,
                    BranchName: preResult.company.BranchName == undefined || preResult.company.BranchName == "" ? "All Branch" : preResult.company.BranchName,
                    reportLabel: " Fixed Asset List ",
                    startdate: preResult.startdate,
                    enddate: preResult.enddate,
                    colspan: 9
                };
                stringHTML += tableHTMLTopHeaderReport(dataTopHeader);//topHeader   

                if (preResult.datas != 0) {//jika pre ajax data ada 
                    var pre_arData = [];
                    preResult.datas.forEach(function (pre_dtResults) {//untuk mempersiapkan pre Array utk search
                        var pre_code = pre_dtResults['code'];
                        pre_arData.push(pre_code);
                    });
                    dataSend['predata'] = pre_arData;//isi preArray dengan value baru

                    $.post(url, dataSend).done(function (result) {
                        var parseResult = JSON.parse(result);
                        var arTempDatas = [];

                        //=== JIKA DATA DITEMUKAN ========================================//
                        if (parseResult.datas != 0) {
                            arTempDatas = prepareReport(parseResult);
                            stringHTML += createReport(arTempDatas);
                            pages['pages'] = (pages['pages'] * 1) + 1;
                        }//=== END JIKA DATA DITEMUKAN ===================================//
                        else {
                            stringHTML += tableHTMLNotFound();
                        }
                        //console.log("arTempDatas="+JSON.stringify(arTempDatas));
                        $("#databox").html(stringHTML);
                        modal_close('dlg_loading');
                    }, 'json');
                } else {
                    stringHTML += tableHTMLNotFound();
                    $("#databox").html(stringHTML);
                    modal_close('dlg_loading');
                }
            }, 'json');
        }

        /*
        $.post(url, dataSend).done(function (result) {
            var parseResult = JSON.parse(result);
            //console.log("parseResult="+JSON.stringify(parseResult.datas));  
            var tempCode = "";
            var arTempDatas = [];   // temporer untuk menyimpan   
            var ArSummAll = [];   // untuk menyimpan nilai temporer 
            var tempArSumm = {"amount": 0, "paid": 0, "notYet": 0, "r1_30": 0, "r31_60": 0, "r61_90": 0, "r91_120": 0, "blh_120": 0};   //menyimpan array untuk tabel Summary
            var stringHTML = "";   // untuk menyimpan yang akan ditampilkan ke layar

            stringHTML += "<table border='0' cellspacing='0' cellpadding='3' width='96%' align='center' class='tree-2' style='margin-bottom:30px;'>"
                    + "<tr>"
                    + "<td colspan='10' class='s0 text-center'><span class='normal_bold span_block ' ><small>" + parseResult.company.CompanyName + "</small></span></td>"
                    + "</tr>"
                    + "<tr>"
                    + "<td colspan='10' class='s0 text-center'><span class='normal_bold span_block ' ><small>";
            parseResult.company.BranchName == undefined || parseResult.company.BranchName == "" ? stringHTML += "All Branch" : stringHTML += parseResult.company.BranchName;
            stringHTML += "</small></span></td>"
                    + "</tr>"
                    + "<tr>"
                    + "<td colspan='10' class='s1 text-center'><span class='normal_bold span_block ' ><small>Fixed Asset List</small></span></td>"
                    + "</tr>";
            //=== JIKA DATA DITEMUKAN ========================================//
            var testQindex = 0;
            if (parseResult.datas != 0) {
                // === LOOP PEMBACAAN DATA ===================================//
                parseResult.datas.forEach(function (dtResults) {
                    testQindex++;
                    if (tempCode == "") {//PEMBACAAN DATA PERTAMA KALI
                        tempCode = dtResults.BranchCode_ID;
                        var dataJSONLevel_1 = arJSONLevel_1(dtResults);
                        arTempDatas.push(dataJSONLevel_1);
                    }//END PEMBACAAN DATA PERTAMA KALI
                    else {//PEMBACAAN DATA UNTUK DATA BERIKUTNYA
                        var iL1 = cekArraySummary(arTempDatas, "BranchCode_ID", dtResults.BranchCode_ID);//mendapatkan index array level 1 (BranchCode_ID)
                        if (iL1 > -1) {
                            //console.log("arTempDatas="+JSON.stringify(arTempDatas));
                            var iL2 = cekArraySummary(arTempDatas[iL1]['data'], "DepartmentCode_PR", dtResults.DepartmentCode_PR);//index level 2()
                            if (iL2 > -1) {
                                var iL3 = cekArraySummary(arTempDatas[iL1]['data'][iL2]['data'], "ItemCode_ID", dtResults.ItemCode_ID);
                                if (iL3 > -1) {
                                    var iL4 = cekArraySummary(arTempDatas[iL1]['data'][iL2]['data'][iL3]['data'], "AssetCode_ID", dtResults.AssetCode_ID);
                                    if (iL4 > -1) {

                                    } else {
                                        arTempDatas[iL1]['data'][iL2]['JmlItemDept'] = (arTempDatas[iL1]['data'][iL2]['JmlItemDept'] * 1) + (dtResults.ItemQty_ID * 1);
                                        arTempDatas[iL1]['data'][iL2]['data'][iL3]['JmlItem'] = (arTempDatas[iL1]['data'][iL2]['data'][iL3]['JmlItem'] * 1) + (dtResults.ItemQty_ID * 1);
                                        var dtarJSONLevel_4 = arJSONLevel_4(dtResults);
                                        arTempDatas[iL1]['data'][iL2]['data'][iL3]['data'].push(dtarJSONLevel_4);
                                    }
                                } else {
                                    arTempDatas[iL1]['data'][iL2]['JmlItemDept'] = (arTempDatas[iL1]['data'][iL2]['JmlItemDept'] * 1) + (dtResults.ItemQty_ID * 1);
                                    var dtarJSONLevel_3 = arJSONLevel_3(dtResults);
                                    arTempDatas[iL1]['data'][iL2]['data'].push(dtarJSONLevel_3);
                                }
                            } else {
                                var dtarJSONLevel_2 = arJSONLevel_2(dtResults);
                                arTempDatas[iL1]['data'].push(dtarJSONLevel_2);
                            }
                        } else {
                            var dataJSONLevel_1 = arJSONLevel_1(dtResults);
                            arTempDatas.push(dataJSONLevel_1);
                        }
                    }//end PEMBACAAN DATA UNTUK DATA BERIKUTNYA

                    //console.log("dtResults.UsageDate_ID="+dtResults.UsageDate_ID+"; dtResults.DPStatus_IR="+dtResults.DPStatus_IR);
                });// === END LOOP PEMBACAAN DATA ============================/    
                //console.log("arTempDatas="+JSON.stringify(arTempDatas));

                //===CARA BARU================================================================================================================//                
                var noTree = 1;
                var noUrutLevel1 = 1;
                arTempDatas.forEach(function (arDataLevel1) {//MULAI LOOP  level 1 
                    stringHTML += tableHTMLHeader(arDataLevel1);
                    var noUrutLevel2 = 1;
                    arDataLevel1['data'].forEach(function (arDataLevel2) {//MULAI LOOP LEVEL 2
                        //noUrutLevel2==1?stringHTML+=tableHTMLHeader(arDataLevel2):null;//membuat tabel header LEVEL2
                        var parentLevel2 = noTree;
                        stringHTML += tableHTMLContentFirst(noTree, noUrutLevel2, arDataLevel2);//membuat tabel header LEVEL2
                        noTree++;

                        var noUrutLevel3 = 1;
                        arDataLevel2['data'].forEach(function (arDataLevel3) {//MULAI LOOP LEVEL 3 
                            var parentLevel3 = noTree;
                            stringHTML += tableHTMLContentOther(noTree, parentLevel2, noUrutLevel3, arDataLevel3);
                            noTree++;
                            var noUrutLevel4 = 1;
                            arDataLevel3['data'].forEach(function (arDataLevel4) {//MULAI LOOP LEVEL 4                                 
                                stringHTML += tableHTMLContentOtherDet(noTree, parentLevel3, noUrutLevel4, arDataLevel4);
                                noTree++;
                                noUrutLevel4++;
                            });//END MULAI LOOP LEVEL 4

                            noUrutLevel3++;
                        });//END MULAI LOOP LEVEL 3 
                        noUrutLevel2++;
                    });//END MULAI LOOP LEVEL 2                    
                    noUrutLevel1++;
                });//END MULAI LOOP INVOICE LEVEL 0 

                //===END CARA BARU================================================================================================================//
                //stringHTML+=tableHTMLFooterSummary(tempArSumm);//MEMBUAT FOOTER SUMARY 
                //tempArSumm      = {"amount":0,"paid":0,"notYet":0,"r1_30":0,"r31_60":0,"r61_90":0,"r91_120":0,"blh_120":0};
                stringHTML += "</table><script>"
                        + "$(document).ready(function () {"
                        + "    $('.tree-2').treegrid({"
                        + "        expanderExpandedClass: ' treegrid-expander-expanded ',"
                        + "        expanderCollapsedClass: 'treegrid-expander-collapsed'"
                        + "    });"
                        + "    $('.tree-2').treegrid('" + dataIn + "');"
                        + "});"
                        + "</script" + ">";
                stringHTML += stringLegend();
                //stringHTML+=summaryHTMLAll("ALL ITEM","left",ArSummAll);//MEMBUAT FOOTER SUMARY ALL
            }//=== END JIKA DATA DITEMUKAN ===================================//
            else {
                stringHTML += tableHTMLNotFound();
            }
            //console.log("arTempDatas="+JSON.stringify(arTempDatas));
            $("#databox").html(stringHTML);
            modal_close('dlg_loading');
        }, 'json');
        */
    }

    function print_detail() {
        //var opt_print   = $("input[type='radio'][name='opt_print']:checked").val();
        var data_print = $("#databox").html();
        Popup(data_print);

    }
    function Popup(data) {
        var mywindow = window.open('', 'print-container', 'height=528,width=700');
        //var css = '<link rel="stylesheet" href="<?php echo base_url() ?>assets/custom/css/print.css" type="text/css" />';
        var varCSS = "<style>table{width: 100%;"
                + "font-family: 'Times New Roman';"
                + "font-size: small;"
                + "}"
                + ".thead{border:1px solid #333333;} .margin-left5persen{margin-left:0px;} .margin-right5persen{margin-right:0px;}"
                + ".table-summary{width:auto;}</style>";
        mywindow.document.write('<html><head><title>Print Detail</title>');
        mywindow.document.write(varCSS);
        mywindow.document.write('</head><body >');
        mywindow.document.write(data);
        mywindow.document.write('</body></html>');

        mywindow.document.close(); // necessary for IE >= 10
        mywindow.focus(); // necessary for IE >= 10

        mywindow.print();
        mywindow.close();

        return true;
    }
    function actionExcel() {
        var htmls = "";
        var delRow = "";
        htmls = $('#databox').html();
        htmls = htmls.replace(/<table border='0' /gi, "<table border='1' ");
        htmls = htmls.replace(/<table border="0" /gi, "<table border='1' ");
        htmls = htmls.replace(/border='0'/gi, " ");
        htmls = htmls.replace(/'s0 text-center'/gi, "'s0 text-center' style='font-size:7;text-align: center;font-weight: bold;' ");
        htmls = htmls.replace(/'s1 text-center'/gi, "'s1 text-center' style='font-size:9;text-align: center;font-weight: bold;' ");
        htmls = htmls.replace(/'s2'/gi, "'s2' style='text-align: center;font-weight: bold;' ");
        htmls = htmls.replace(/id='tableHeader'/gi, " style='-webkit-print-color-adjust:exact;background-color:#d5d5d5;' ");
        htmls = htmls.replace(/<script/gi, " ");
        delRow = ">$(document).ready(function () {    $('.tree-2').treegrid({        expanderExpandedClass: ' treegrid-expander-expanded ',        expanderCollapsedClass: 'treegrid-expander-collapsed'    });    $('.tree-2').treegrid('";
        htmls = htmls.replace(delRow, " ");
        delRow = "collapseAll');});</";
        htmls = htmls.replace(delRow, " ");
        delRow = "expandAll');});</";
        htmls = htmls.replace(delRow, " ");
        htmls = htmls.replace(/script>/gi, " ");
        delRow = '';
        htmls = htmls.replace(/display: none;/gi, " ");

//        delRow="<tr>"
//            +"<td class='s5' align='right' colspan='10'><hr></td>"
//            +"</tr>";
//        htmls = htmls.replace(delRow, " ");
        //console.log("htmls = "+htmls);
        exportToExcel(htmls);
    }

    function prepareReport(parseResult) {
        var tempItemCode = "";
        var arTempDatas = [];
        // === LOOP PEMBACAAN DATA ===================================//
        parseResult.datas.forEach(function (dtResults) {
            if (tempItemCode == "") {//PEMBACAAN DATA PERTAMA KALI
                tempItemCode = dtResults.BranchCode_ID;
                var dataJSONLevel_1 = arJSONLevel_1(dtResults);
                arTempDatas.push(dataJSONLevel_1);
            }//END PEMBACAAN DATA PERTAMA KALI
            else {//PEMBACAAN DATA UNTUK DATA BERIKUTNYA
                var iL1 = cekArraySummary(arTempDatas, "BranchCode_ID", dtResults.BranchCode_ID);//mendapatkan index array level 1 (BranchCode_ID)
                if (iL1 > -1) {
                    //console.log("arTempDatas="+JSON.stringify(arTempDatas));
                    var iL2 = cekArraySummary(arTempDatas[iL1]['data'], "DepartmentCode_PR", dtResults.DepartmentCode_PR);//index level 2()
                    if (iL2 > -1) {
                        var iL3 = cekArraySummary(arTempDatas[iL1]['data'][iL2]['data'], "ItemCode_ID", dtResults.ItemCode_ID);
                        if (iL3 > -1) {
                            var iL4 = cekArraySummary(arTempDatas[iL1]['data'][iL2]['data'][iL3]['data'], "AssetCode_ID", dtResults.AssetCode_ID);
                            if (iL4 > -1) {

                            } else {
                                arTempDatas[iL1]['data'][iL2]['JmlItemDept'] = (arTempDatas[iL1]['data'][iL2]['JmlItemDept'] * 1) + (dtResults.ItemQty_ID * 1);
                                arTempDatas[iL1]['data'][iL2]['data'][iL3]['JmlItem'] = (arTempDatas[iL1]['data'][iL2]['data'][iL3]['JmlItem'] * 1) + (dtResults.ItemQty_ID * 1);
                                var dtarJSONLevel_4 = arJSONLevel_4(dtResults);
                                arTempDatas[iL1]['data'][iL2]['data'][iL3]['data'].push(dtarJSONLevel_4);
                            }
                        } else {
                            arTempDatas[iL1]['data'][iL2]['JmlItemDept'] = (arTempDatas[iL1]['data'][iL2]['JmlItemDept'] * 1) + (dtResults.ItemQty_ID * 1);
                            var dtarJSONLevel_3 = arJSONLevel_3(dtResults);
                            arTempDatas[iL1]['data'][iL2]['data'].push(dtarJSONLevel_3);
                        }
                    } else {
                        var dtarJSONLevel_2 = arJSONLevel_2(dtResults);
                        arTempDatas[iL1]['data'].push(dtarJSONLevel_2);
                    }
                } else {
                    var dataJSONLevel_1 = arJSONLevel_1(dtResults);
                    arTempDatas.push(dataJSONLevel_1);
                }
            }//end PEMBACAAN DATA UNTUK DATA BERIKUTNYA

            //console.log("dtResults.UsageDate_ID="+dtResults.UsageDate_ID+"; dtResults.DPStatus_IR="+dtResults.DPStatus_IR);
        });
        // === END LOOP PEMBACAAN DATA ============================/    
        return arTempDatas;
    }
    function createReport(arTempDatas) {
        var tempStringHtml = "";
        tempStringHtml += createRowReport(arTempDatas);
        tempStringHtml += tableHTMLBlankForNext();
        tempStringHtml += "</table><script>"
                + "$(document).ready(function () {"
                + "    $('.tree-2').treegrid({"
                + "        expanderExpandedClass: ' treegrid-expander-expanded ',"
                + "        expanderCollapsedClass: 'treegrid-expander-collapsed'"
                + "    });"
                + "    $('.tree-2').treegrid('" + dataSend['dataIn'] + "');"
                + "});"
                + "</script" + ">";

//        tempStringHtml += summaryHTMLAll(" ALL ITEM ", "left", tempArSumm['data']);
        tempStringHtml += stringLegend();
        return tempStringHtml;
    }
    function createRowReport(arTempDatas) {
        var tempStringHtml = "";
        //MULAI LOOP
//        if (dataFooter['footer'] == undefined || dataFooter['footer'] != 'yes') {dataFooter = {footer: "yes",TotalAmount: 0};}
        arTempDatas.forEach(function (arDataLevel1) {//MULAI LOOP  level 1 
            tempStringHtml += tableHTMLHeader(arDataLevel1);
            var noUrutLevel2 = 1;
            arDataLevel1['data'].forEach(function (arDataLevel2) {//MULAI LOOP LEVEL 2
                //noUrutLevel2==1?stringHTML+=tableHTMLHeader(arDataLevel2):null;//membuat tabel header LEVEL2
                var parentLevel2 = noTree;
                tempStringHtml += tableHTMLContentFirst(noTree, noUrutLevel2, arDataLevel2);//membuat tabel header LEVEL2
                noTree++;

                var noUrutLevel3 = 1;
                arDataLevel2['data'].forEach(function (arDataLevel3) {//MULAI LOOP LEVEL 3 
                    var parentLevel3 = noTree;
                    tempStringHtml += tableHTMLContentOther(noTree, parentLevel2, noUrutLevel3, arDataLevel3);
                    noTree++;
                    var noUrutLevel4 = 1;
                    arDataLevel3['data'].forEach(function (arDataLevel4) {//MULAI LOOP LEVEL 4                                 
                        tempStringHtml += tableHTMLContentOtherDet(noTree, parentLevel3, noUrutLevel4, arDataLevel4);
                        noTree++;
                        noUrutLevel4++;
                    });//END MULAI LOOP LEVEL 4

                    noUrutLevel3++;
                });//END MULAI LOOP LEVEL 3 
                noUrutLevel2++;
            });//END MULAI LOOP LEVEL 2                    
            noUrutLevel1++;
        });
        //END MULAI LOOP
//        tempStringHtml += tableHTMLFooterSummary(dataFooter);//MEMBUAT FOOTER SUMARY  
        return tempStringHtml;
    }
    function seeMore() {
        modal_open('Progress Bar', 'dlg_loading');
        $.post(pre_url, dataSend).done(function (pre_result) {//preAjax
            var preResult = JSON.parse(pre_result);
            if (preResult.datas != 0) {//jika pre ajax data ada                 
                //Array Pre_result diambil code nya saja
                var pre_arData = [];
                preResult.datas.forEach(function (pre_dtResults) {
                    var pre_code = pre_dtResults['code'];
                    pre_arData.push(pre_code);
                });
                dataSend['predata'] = pre_arData;//isi preArray dengan value baru
                //End Array Pre_result diambil code nya saja

                var prearTempDatas = [];
                var pre_stringHTML = "";
                $.post(url, dataSend).done(function (result) {//loadAjax
                    var parseResult = JSON.parse(result);
                    if (parseResult.datas != 0) {
                        //console.log("arTempDatas="+JSON.stringify(arTempDatas));
//                        $("#footerSumAll_hr").replaceWith("");
//                        $("#footerSumAll_row").replaceWith("");
                        prearTempDatas = prepareReport(parseResult);
                        pre_stringHTML += createRowReport(prearTempDatas);
                        pre_stringHTML += tableHTMLBlankForNext();

                        pages['pages'] = (pages['pages'] * 1) + 1;
                        $("#tr-see-more").replaceWith("");//clear row button 
                        $("#rowBlankForNext").replaceWith(pre_stringHTML);//mengganti row blank dengan ros data page baru                        
//                        $("#tableSumAll").replaceWith(summaryHTMLAll(" ALL DATA ", "left", tempArSumm['data']));
                        var htmlDataBox = $("#databox").html();//mengambil html pada div #databox yg data sudah baru
                        $("#databox").html(htmlDataBox);//mengisi kembali div #databox agar Tree-nya dapat work                      
                    } else {
                        $("#btn-see-more").prop("disabled", true);
                        $("#btn-see-more").val("Data Completed");
                    }
                    modal_close('dlg_loading');
                }, 'json');
            } else {
                $("#btn-see-more").prop("disabled", true);
                $("#btn-see-more").val("Data Completed");
                modal_close('dlg_loading');
            }
        }, 'json');
    }
    function tableHTMLNotFound() {
        var strHeader = "<tr><td colspan='10' class='s3' align='left'><b><u></u></b></td></tr>"
                + "<tr id='tableHeader'>"//baris heading table

                + "<td width='' class='s4'><span class='small_bold' >No</span></td>"
                + "<td width='' class='s4'><span class='small_bold'>Departement</span></td>"
                + "<td width='' class='s4'><span class='small_bold'>Code</span></td>"
                + "<td width='' class='s4'><span class='small_bold'>ItemDesc</span></td>"
                + "<td width='' class='s4'><span class='small_bold'>Unit</span></td>"
                + "<td width='' class='s4'><span class='small_bold'>Qty</span></td>"
                + "<td width='' class='s4'><span class='small_bold'>Estms.Life<br>(Month)</span></td>"
                + "<td width='' class='s4'><span class='small_bold'>Depct.<br>Rate(%)</span></td>"
                + "<td width='' class='s4' align='right'><span class='small_bold'>Sold<br>Status</span></td>"
                + "</tr><tr>"
                + "<td width='' class='s5 text-center' colspan='10' align='center'><span class='small_bold' >Data Not Found</span></td>"
                + "</tr></table>";
        return strHeader;
    }
    function tableHTMLHeaderLevel1(data) {
        var strHeader = "<tr><td colspan='10' class='s3' align='left' style='left:-5px;position:inherit;'><b>--" + data.BranchCode_ID + "</b></td></tr>";
        return strHeader;
    }
    function tableHTMLHeader(data) {
        var strHeader = "<tr><td colspan='10' class='s3' align='left'><a class='linkParentTab' href='#'onclick=\"parent.tab_edit('Branch Info','setup/branch_info', 'icon-edit', 'edit', '" + data.BranchCode_ID + "')\" <?= $cek_autority_edit ?>><u><b>" + data.BranchName_ID + " </b></u></a></td></tr>"
                + "<tr id='tableHeader'>"//baris heading table
                + "<td width='' class='s4'><span class='small_bold' >No</span></td>"
                + "<td width='' class='s4 linkParentTab' style='cursor:pointer;' onclick=\"searching_data_fixed_asset_list('am_department','DepartmentName');\"><span class='small_bold'>Departement</span></td>"
                + "<td width='' class='s4 linkParentTab' style='cursor:pointer;' onclick=\"searching_data_fixed_asset_list('at_purchaserequisition','DepartmentCode');\" ><span class='small_bold'>Code</span></td>"
                + "<td width='' class='s4 linkParentTab' style='cursor:pointer;' onclick=\"searching_data_fixed_asset_list('at_inventdetail','ItemDesc');\"><span class='small_bold'>ItemDesc</span></td>"
                + "<td width='' class='s4 linkParentTab' style='cursor:pointer;' onclick=\"searching_data_fixed_asset_list('am_item','ItemUnit');\"><span class='small_bold'>Unit</span></td>"
                + "<td width='' class='s4 linkParentTab' align='right' style='cursor:pointer;' onclick=\"searching_data_fixed_asset_list('at_inventdetail','ItemQty');\"><span class='small_bold'>Qty</span></td>"
                + "<td width='' class='s4 linkParentTab' align='right' style='cursor:pointer;' onclick=\"searching_data_fixed_asset_list('at_inventdetail','ItemAverage');\"><span class='small_bold'>Cost</span></td>"
                + "<td width='' class='s4 linkParentTab' align='right' style='cursor:pointer;' onclick=\"searching_data_fixed_asset_list('am_fixedassettype','EstimatedLife');\"><span class='small_bold'>Estms.Life<br>(Month)</span></td>"
                + "<td width='' class='s4 linkParentTab' align='right' style='cursor:pointer;' onclick=\"searching_data_fixed_asset_list('am_fixedassettype','DepriciateRate');\"><span class='small_bold'>Depct.<br>Rate(%)</span></td>"
                + "<td width='' class='s4 linkParentTab' align='right' style='cursor:pointer;' onclick=\"searching_data_fixed_asset_list('am_fixedassettype','DepMethodID');\"><span class='small_bold'>Sold<br>Status</span></td>"
                + "</tr>";
        return strHeader;
    }
    function tableHTMLContentFirst(noTree, noUrut, data) {
        var strContent = "<tr class='treegrid-" + noTree + "' style='-webkit-print-color-adjust:exact;background-color:#F4F4FF;font-weight: bold;'>"
                + "<td width='' class='s5'><span class='small_bold' >" + noUrut + "</span></td>"
                + "<td width='' class='s5'><span class='small_bold' >" + data.DepartmentName_PR + "</span></td>"//departement
                + "<td width='' class='s5'><span class='small_bold' ><a class='linkParentTab' href=\"#\" onclick=\"parent.tab_edit('Departments','list/departement', 'icon-edit', 'edit', '" + data.DepartmentCode_PR + "')\" <?= $cek_autority_edit ?>>" + data.DepartmentCode_PR + "</a></span></td>"
                + "<td width='' class='s5' align='right'><span class='small_bold'></span></td>"//item desc
                + "<td width='' class='s5' align='right'><span class='small_bold'></span></td>"//unit
                + "<td width='' class='s5' align='right'><span class='small_bold'>" + formatRp(data.JmlItemDept) + "</span></td>"//qty
                + "<td width='' class='s5' align='right'><span class='small_bold'></span></td>"//cost
                + "<td width='' class='s5' align='right'><span class='small_bold'></span></td>"//Estimasi
                + "<td width='' class='s5' align='right'><span class='small_bold'></span></td>"//DeptRate
                + "<td width='' class='s5' align='right'><span class='small_bold'></span></td>"//SoldStatus
                + "</tr>";
        return strContent;
    }
    function tableHTMLContentOther(noTree, noTreeParent, noUrut, data) {
        var strContent = "";
        strContent = "<tr  class='treegrid-" + noTree + " treegrid-parent-" + noTreeParent + "' style='-webkit-print-color-adjust:exact;background-color:#EAFFFB;font-weight: bold;'>"
                + "<td width='' class='s5'><span class='small_bold' >" + noUrut + "</span></td>"
                + "<td width='' class='s5'><span class='small_bold' ></span></td>"
                + "<td width='' class='s5'><span class='small_bold' ><a class='linkParentTab' href=\"#\" onclick=\"parent.tab_edit('Item Product','list/items', 'icon-edit', 'edit', '" + data.ItemCode_ID + "')\" <?= $cek_autority_edit ?>>" + data.ItemCode_ID + "</a></span></td>"
                + "<td width='' class='s5'><span class='small_bold'>" + data.ItemDesc_ID + "</span></td>"//item desc
                + "<td width='' class='s5' align='right'><span class='small_bold'></span></td>"//unit
                + "<td width='' class='s5' align='right'><span class='small_bold'>" + formatRp(data.JmlItem) + "</span></td>"//qty
                + "<td width='' class='s5' align='right'><span class='small_bold'></span></td>"//cost
                + "<td width='' class='s5' align='right'><span class='small_bold'></span></td>"//Estimasi
                + "<td width='' class='s5' align='right'><span class='small_bold'></span></td>"//DeptRate
                + "<td width='' class='s5' align='right'><span class='small_bold'></span></td>"//SoldStatus
                + "</tr>";
        return strContent;
    }
    function tableHTMLContentOtherDet(noTree, noTreeParent, noUrut, data) {
        var strContent = "";
        strContent = "<tr  class='treegrid-" + noTree + " treegrid-parent-" + noTreeParent + "' style='-webkit-print-color-adjust:exact;background-color:#e6ffcc;'>"
                + "<td width='' class='s5'><span class='small_bold' >" + noUrut + "</span></td>"
                + "<td width='' class='s5'><span class='small_bold' ></span></td>"//departement
                + "<td width='' class='s5'><span class='small_bold' ><a class='linkParentTab' href=\"#\" onclick=\"parent.tab_edit('Fixed Asset List','list/fixed_asset_list', 'icon-edit', 'edit', '" + data.IventDetailID_ID + "')\" <?= $cek_autority_edit ?>>" + data.AssetCode_ID + "</a></span></td>"
                + "<td width='' class='s5'><span class='small_bold'>" + data.ItemDesc_ID + "</span></td>"//item desc
                + "<td width='' class='s5'><span class='small_bold'>" + data.ItemUnit_ID + "</span></td>"//unit
                + "<td width='' class='s5' align='right'><span class='small_bold'>" + formatRp(data.ItemQty_ID) + "</span></td>"//qty
                + "<td width='' class='s5' align='right'><span class='small_bold'>" + formatRp(data.ItemAverage_ID) + "</span></td>"//qty
                + "<td width='' class='s5' align='right'><span class='small_bold'>" + data.EstimatedLife_ID + "</span></td>"//Estimasi 
                + "<td width='' class='s5' align='right'><span class='small_bold'>" + formatRp(data.DepriciateRate_ID) + "</span></td>"//DeptRate
                + "<td width='' class='s5' align='right'><span class='small_bold'>" + data.SoldStatus_ID + "&nbsp;</span></td>"//SoldStatus
                + "</tr>";
        return strContent;
    }
    function tableHTMLFooterSummary(data) {
        var strFooter = "<tr>"
                + "<td class='s5' align='right' colspan='10'><hr class='hrTableSummary' style='size:3px;'></td></tr>"
                + "<tr><td class='s5' align='right' colspan='3'><b>TOTAL : </b></td>"
                + "<td width='' class='s5' align='right'><span class='small_bold' ><b>" + formatRp(data.amount) + "</b></span></td>"
                + "<td width='' class='s5' align='right'><span class='small_bold' ><b>" + formatRp(data.paid) + "</b></span></td>"
                + "<td width='' class='s5' align='right'><span class='small_bold'><b>" + formatRp(data.notYet) + "</b></span></td>"
                + "<td width='' class='s5' align='right'><span class='small_bold'><b>" + formatRp(data.r1_30) + "</b></span></td>"
                + "<td width='' class='s5' align='right'><span class='small_bold'><b>" + formatRp(data.r31_60) + "</b></span></td>"
                + "<td width='' class='s5' align='right'><span class='small_bold'><b>" + formatRp(data.r61_90) + "</b></span></td>"
                + "<td width='' class='s5' align='right'><span class='small_bold'><b>" + formatRp(data.r91_120) + "</b></span></td>"
                + "<td width='' class='s5' align='right'><span class='small_bold'><b>" + formatRp(data.blh_120) + "</b></span></td>"
                + "</tr>";
        return strFooter;
    }
    function tableHTMLBlankForNext() {
        var strFooter = "<tr id='rowBlankForNext'>"
                + "<td class='s5' align='right' colspan='6'></td></tr>";
        strFooter += "<tr id='tr-see-more'><td colspan='5'><br><br><input id='btn-see-more' name='btn-see-more' type='button' onclick='seeMore()' value=' See More ' style='cursor:pointer;'></td></tr>";

        return strFooter;
    }
    function summaryHTMLAll(tempBranch, alignTo, datas) {
        //console.log('datas='+JSON.stringify(datas));
        var strHeader = "";
        datas.forEach(function (data) {
            strHeader = "<table align='" + alignTo + "' cellpadding='2' cellspacing='0' class='margin-" + alignTo + "5persen table-summary' style='margin-bottom:80px;'>"
                    + "<tr id='tableHeader'>"
                    + "<td width='' class='s4 text-center' colspan='10' align='center'><span class='small_bold' >Summary <u>" + tempBranch + " Currency " + data.CodeCurr + "</u></span></td>"
                    + "</tr>"
                    + "<tr id='tableHeader'>"
                    + "<td width='' class='s4 ' align='left' style='padding-left:6px; padding-right:6px;'><span class='small_bold' >No</span></td>"
                    + "<td width='' class='s4 ' align='left' style='padding-left:6px; padding-right:6px;'><span class='small_bold' >Vendor </span></td>"
                    + "<td width='' class='s4 ' align='right' style='padding-left:6px; padding-right:6px;'><span class='small_bold' >Amount</span></td>"
                    + "<td width='' class='s4 ' align='right' style='padding-left:6px; padding-right:6px;'><span class='small_bold' >Paid</span></td>"
                    + "<td width='' class='s4 ' align='right' style='padding-left:6px; padding-right:6px;'><span class='small_bold' >NotYet</span></td>"
                    + "<td width='' class='s4 ' align='right' style='padding-left:6px; padding-right:6px;'><span class='small_bold' >1-30</span></td>"
                    + "<td width='' class='s4 ' align='right' style='padding-left:6px; padding-right:6px;'><span class='small_bold' >31-60</span></td>"
                    + "<td width='' class='s4 ' align='right' style='padding-left:6px; padding-right:6px;'><span class='small_bold' >61-90</span></td>"
                    + "<td width='' class='s4 ' align='right' style='padding-left:6px; padding-right:6px;'><span class='small_bold' >90-120</span></td>"
                    + "<td width='' class='s4 ' align='right' style='padding-left:6px; padding-right:6px;'><span class='small_bold' >&GT;120</span></td>"
                    + "</tr>";
            var rowNo = 1;
            data['data'].forEach(function (datadet) {
                strHeader += "<tr>"
                        + "<td class='s5 text-left' style='padding-left:6px; padding-right:6px;'><b>" + rowNo + "</b></td>"
                        + "<td class='s5' align='left' style='padding-left:6px; padding-right:6px;'><b>" + datadet['Name'] + "</b></td>"
                        + "<td class='s5' align='right' style='padding-left:6px; padding-right:6px;'><b>" + formatRp(datadet['amount']) + "</b></td>"
                        + "<td class='s5' align='right' style='padding-left:6px; padding-right:6px;'><b>" + formatRp(datadet['paid']) + "</b></td>"
                        + "<td class='s5' align='right' style='padding-left:6px; padding-right:6px;'><b>" + formatRp(datadet['notYet']) + "</b></td>"
                        + "<td class='s5' align='right' style='padding-left:6px; padding-right:6px;'><b>" + formatRp(datadet['r1_30']) + "</b></td>"
                        + "<td class='s5' align='right' style='padding-left:6px; padding-right:6px;'><b>" + formatRp(datadet['r31_60']) + "</b></td>"
                        + "<td class='s5' align='right' style='padding-left:6px; padding-right:6px;'><b>" + formatRp(datadet['r61_90']) + "</b></td>"
                        + "<td class='s5' align='right' style='padding-left:6px; padding-right:6px;'><b>" + formatRp(datadet['r91_120']) + "</b></td>"
                        + "<td class='s5' align='right' style='padding-left:6px; padding-right:6px;'><b>" + formatRp(datadet['blh_120']) + "</b></td>"
                        + "</tr>";
                rowNo++;
            });
            strHeader += "</table>";
        });
        return strHeader;
    }

    function arJSONLevel_1(dtResults) {//isi array saat data adalah branch
        var tempData = {
            BranchCode_ID: dtResults.BranchCode_ID,
            BranchName_ID: dtResults.BranchName_ID,
            data: []
        };
        var ardt = arJSONLevel_2(dtResults);
        tempData['data'].push(ardt);
        return tempData;
    }
    function arJSONLevel_2(dtResults) {//isi array saat data adalah dept
        var tempData = {
            DepartmentCode_PR: dtResults.DepartmentCode_PR,
            DepartmentName_PR: dtResults.DepartmentName_PR,
            JmlItemDept: dtResults.ItemQty_ID,
            data: []
        };
        var ardt = arJSONLevel_3(dtResults);
        tempData['data'].push(ardt);
        return tempData;
    }
    function arJSONLevel_3(dtResults) {//isi data ItemCode_ID
        var tempData = {
            ItemCode_ID: dtResults.ItemCode_ID,
            ItemDesc_ID: dtResults.ItemDesc_ID,
            JmlItem: dtResults.ItemQty_ID,
            data: []
        };
        var ardt = arJSONLevel_4(dtResults);
        tempData['data'].push(ardt);
        return tempData;
    }
    function arJSONLevel_4(dtResults) {//isi data 
        var tempData = {
            BranchCode_ID: dtResults.BranchCode_ID,
            AssetCode_ID: dtResults.AssetCode_ID,
            Description_ID: dtResults.Description_ID,
            ItemCode_ID: dtResults.ItemCode_ID,
            ItemDesc_ID: dtResults.ItemDesc_ID,
            ItemQty_ID: dtResults.ItemQty_ID,
            ItemAverage_ID: dtResults.ItemAverage_ID,
            IventDetailID_ID: dtResults.IventDetailID_ID,
            ReceiptNumber_ID: dtResults.ReceiptNumber_ID,
            SoldStatus_ID: get_statusInvent(dtResults.SoldStatus_ID),
            TransStatus_PR: get_status(dtResults.TransStatus_PR),
            UsageDate_ID: dateSqlToIndo(dtResults.UsageDate_ID),
            ItemUnit_ID: dtResults.ItemUnit_ID,
            ItemCategoryName_ID: dtResults.ItemCategoryName_ID,
            EstimatedLife_ID: dtResults.EstimatedLife_ID,
            DepriciateRate_ID: dtResults.DepriciateRate_ID,
            DepMethodID_ID: get_depreciate_method(dtResults.DepMethodID_ID)
        };
        return tempData;
    }

    function stringLegend() {
        var strLgnd = {
            marginLeft: '2%',
            datas: [
                {boxColor: '#F4F4FF', strLabel: "Data Departement"},
                {boxColor: '#EAFFFB', strLabel: "Data Items"},
                {boxColor: '#e6ffcc', strLabel: "Data Asset"}
            ]
        };
        var rst = legendsTable(strLgnd);
        return rst;
    }

</script>
