<?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%; 
    }
    .displayPrint{
            display: inline-block;
            background-color: white;
            width: 100%;
        }
    @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 stringHTML      = "";
    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_reloadDataDepreciationList';
        var getValue     = startLoad();
        var typeShorting = checkShorting(txtFieldShorting);
        var dataIn       = $('#cmb_collapse').combobox('getValue');

        var dataSend = {
            cmb_company     : getValue['cmb_company'],
            cmb_branch      : getValue['cmb_branch'],
            txt_departement : document.formFilterDept.txt_departement.value,
            chk_TransStatus : getValue['chk_TransStatus'],
            txtTable        : txtTable,
            txtField        : txtFieldShorting,
            typeShorting    : typeShorting
        };
        
        modal_open('Progress Bar','dlg_loading');
        $.post(url, dataSend).done(function (result) {
            //alert("result="+result);
            //console.log("result="+result);
            //stringHTML = result;
            //console.log("result="+JSON.stringify(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      = {};   //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-left:2%; margin-bottom:30px;'>"
                    + "<tr>"
                    + "<td colspan='6' class='s0 text-center'><span class='normal_bold span_block ' ><small>" + parseResult.company.CompanyName + "</small></span></td>"
                    + "</tr>"
                    + "<tr>"
                    + "<td colspan='6' 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='6' class='s1 text-center'><span class='normal_bold span_block ' ><small>Depreciation 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'], "AssetCode_ID",dtResults.AssetCode_ID);//index level 2()
                            if(iL2>-1){
                                var iL3 = cekArraySummary(arTempDatas[iL1]['data'][iL2]['data'], "DateYear",dateYMToYear(dtResults.PeriodEnd_JV));
                                if(iL3>-1){
                                    var iL4 = cekArraySummary(arTempDatas[iL1]['data'][iL2]['data'][iL3]['data'], "PeriodEnd_JV",dateYMToString(dtResults.PeriodEnd_JV));
                                    if(iL4>-1){
                                        
                                    }else{
                                        arTempDatas[iL1]['data'][iL2]['data'][iL3]['SumYear']=(arTempDatas[iL1]['data'][iL2]['data'][iL3]['SumYear']*1) + (dtResults.JVchDebetSaldo_JV*1);
                                        var dtarJSONLevel_4 = arJSONLevel_4(dtResults);
                                        arTempDatas[iL1]['data'][iL2]['data'][iL3]['data'].push(dtarJSONLevel_4);
                                    }                                 
                                }else{
                                    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 
                            noUrutLevel3==1?stringHTML+=tableHTMLHeaderContentOther(noTree,parentLevel2):null; //bikin header level3
                            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,arDataLevel4);
                                noTree++;
                                noUrutLevel4++;
                            });//END MULAI LOOP LEVEL 4
                                
                            noUrutLevel3++;
                        });//END MULAI LOOP LEVEL 3 
                        noUrutLevel3>1?stringHTML+=tableHTMLFooterContentOther():null;//jika isi level 3 ditemukan maka buat footer level3
                        
                        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='6'><hr></td>"
//            +"</tr>";
//        htmls = htmls.replace(delRow, " ");
        //console.log("htmls = "+htmls);
        exportToExcel(htmls);
    }
    function tableHTMLNotFound(){
        var strHeader = "<tr><td colspan='6' class='s3' align='left'><b><u>_____</u></b></td></tr>"
                        +"<tr id='tableHeader'>"//baris heading table
                        + "<td width='' colspan='6' class='s4'><span class='small_bold' > </span></td>"
                        + "</tr><tr>"
                        + "<td width='' class='s5 text-center' colspan='6' align='center'><span class='small_bold' >Data Not Found</span></td>"
                        + "</tr></table>";
        return strHeader;
    }
    function tableHTMLHeaderLevel1(data){
        var strHeader = "<tr><td colspan='6' class='s3' align='left' style='left:-5px;position:inherit;'><b>--" + data.BranchCode_ID + "</b></td></tr>";
        return strHeader;
    }
    function tableHTMLHeader(data){
        var strHeader = "<tr id='tableHeader'><td colspan='6' class='s4' 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' style='cursor:pointer;' onclick=\"searching_data_fixed_asset_list('am_department','DepartmentName');\"><span class='small_bold'>Departement</span></td>"
//                        + "<td width='' class='s4' style='cursor:pointer;' onclick=\"searching_data_fixed_asset_list('at_purchaserequisition','DepartmentCode');\" ><span class='small_bold'>Code</span></td>"
//                        + "<td width='' class='s4' style='cursor:pointer;' onclick=\"searching_data_fixed_asset_list('at_inventdetail','ItemDesc');\"><span class='small_bold'>ItemDesc</span></td>"
//                        + "<td width='' class='s4' style='cursor:pointer;' onclick=\"searching_data_fixed_asset_list('am_item','ItemUnit');\"><span class='small_bold'>Unit</span></td>"
//                        + "<td width='' class='s4' 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' 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' 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' 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' 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 tableHTMLHeaderContentOther(noTree,noTreeParent){
        var strHeader = "<tr class='treegrid-"+noTree+" treegrid-parent-"+noTreeParent+"'><td colspan='6' style='-webkit-print-color-adjust:exact;background-color:#EAFFFB;font-weight: bold;'>"
            +"<table border='1'>"
            +"<tr> <td> Year </td> <td> Depreciation </td> </tr>"
        ;
        return strHeader;
    }
    function tableHTMLContentFirst(noTree,noUrut,data){
        var strContent = "<tr height='1'><td colspan='6'> </td></tr>"
        +"<tr class='treegrid-"+noTree+"' style='-webkit-print-color-adjust:exact;background-color:#F4F4FF;font-weight: bold;'>"
        + "<td width='80' class='s5' rowspan='5'><span class='small_bold' >" + noUrut + "</span></td>"
        + "<td width='100' class='s5'><span class='small_bold' >Asset Code</span></td>"
        + "<td width='' class='s5'><span class='small_bold' > : "+data.AssetCode_ID+"</span></td>"
        + "<td width='20' class='s5'><span class='small_bold' > </span></td>"
        + "<td width='100' class='s5'><span class='small_bold' >Estimated Life</span></td>"
        + "<td width='' class='s5'><span class='small_bold' > : "+data.EstimatedLife_ID+" months</span></td>"
        + "</tr>"
        +"<tr class='' style='-webkit-print-color-adjust:exact;background-color:#F4F4FF;font-weight: bold;'>"
        + "<td width='' class='s5'><span class='small_bold' >Asset Type Name</span></td>"
        + "<td width='' class='s5'><span class='small_bold' > : "+data.ItemCategoryName_ID+"</span></td>"
        + "<td width='20' class='s5'><span class='small_bold' > </span></td>"
        + "<td width='' class='s5'><span class='small_bold' >Drepreciation</span></td>"
        + "<td width='' class='s5'><span class='small_bold' > : "+data.DepMethodID_ID+"</span></td>"
        + "</tr>"
        +"<tr class='' style='-webkit-print-color-adjust:exact;background-color:#F4F4FF;font-weight: bold;'>"
        + "<td width='' class='s5'><span class='small_bold' >Asset Name</span></td>"
        + "<td width='' class='s5'><span class='small_bold' > : "+data.ItemDesc_ID+"</span></td>"
        + "<td width='20' class='s5'><span class='small_bold' > </span></td>"
        + "<td width='' class='s5'><span class='small_bold' >Asset Cost</span></td>"
        + "<td width='' class='s5'><span class='small_bold' > : "+formatRp(data.ItemPrice_ID)+"</span></td>"
        + "</tr>"
        +"<tr class='' style='-webkit-print-color-adjust:exact;background-color:#F4F4FF;font-weight: bold;'>"
        + "<td width='' class='s5'><span class='small_bold' >Purchase Date</span></td>"
        + "<td width='' class='s5'><span class='small_bold' > : "+data.ReceiptDate_ID+"</span></td>"
        + "<td width='20' class='s5'><span class='small_bold' > </span></td>"
        + "<td width='' class='s5'><span class='small_bold' >Annual</span></td>"
        + "<td width='' class='s5'><span class='small_bold' > : "+formatRp(data.ItemPrice_ID/data.EstimatedLife_ID*12)+"</span></td>"
        + "</tr>"
        +"<tr class='' style='-webkit-print-color-adjust:exact;background-color:#F4F4FF;font-weight: bold;border-bottom:1px #999 solid;'>"
        + "<td width='' class='s5'><span class='small_bold' >Usage Date</span></td>"
        + "<td width='' class='s5'><span class='small_bold' > : "+data.UsageDate+"</span></td>"
        + "<td width='20' class='s5'><span class='small_bold' > </span></td>"
        + "<td width='' class='s5'><span class='small_bold' >Monthly Life</span></td>"
        + "<td width='' class='s5'><span class='small_bold' > : "+formatRp(data.ItemPrice_ID/data.EstimatedLife_ID)+"</span></td>"
        + "</tr>"
        ;
        return strContent;
    }  
    function tableHTMLContentOther(noTree,data){
        var strContent="";
            strContent = "<tr class='treegrid-"+noTree+"  style='-webkit-print-color-adjust:exact;background-color:#EAFFFB;font-weight: bold;'>"
            + "<td width='' class='s5' align='right'><span class='small_bold'>"+data.DateYear+"</span></td>"//year
            + "<td width='' class='s5' align='right'><span class='small_bold'>"+formatRp(data.SumYear)+"</span></td>"//sumYear
            + "</tr>";
        return strContent;
    }      
    function tableHTMLContentOtherDet(noTree,noTreeParent,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'>"+data.PeriodEnd_JV+"</span></td>"//yeardate
            + "<td width='' class='s5' align='right'><span class='small_bold'>"+formatRp(data.JVchDebetSaldo_JV)+"</span></td>"//qty
            + "</tr>";
        return strContent;
    }  
    function tableHTMLFooterContentOther(){
        var strHeader = "</table></td></tr>";
        return strHeader;
    }
    function tableHTMLFooterSummary(data){
        var strFooter= "<tr>"
            + "<td class='s5' align='right' colspan='6'><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 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='6' 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 cekArraySummary(masterAr, cekName,cekValue){
        var checkIndexSumAll       = -1;
        var checkIndexArAll        = 0;
        masterAr.forEach(function (dtStatusAll) {//cek nilai status pada array statusAll ada ato tidak
            if (dtStatusAll[cekName] == cekValue) {
                checkIndexSumAll = checkIndexArAll;
                return checkIndexSumAll;
            }
            checkIndexArAll++;
        });
        return checkIndexSumAll;
    }
    
    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 
        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,
            ReceiptDate_ID      : dateSqlToIndo(dtResults.ReceiptDate_ID),
            SoldStatus_ID       : get_statusInvent(dtResults.SoldStatus_ID),
            TransStatus_PR      : get_status(dtResults.TransStatus_PR),
            UsageDate_ID        : dateSqlToIndo(dtResults.UsageDate_ID),
            
            ItemPrice_ID        : dtResults.ItemPrice_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),
            data:[]
        };        
        var ardt = arJSONLevel_3(dtResults);
        tempData['data'].push(ardt);
        return tempData;
    }   
    function arJSONLevel_3(dtResults){//isi data ItemCode_ID
        var tempData ={
            DateYear     : dateYMToYear(dtResults.PeriodEnd_JV),
            SumYear      : dtResults.JVchDebetSaldo_JV,
            data : []
        };        
        var ardt = arJSONLevel_4(dtResults);
        tempData['data'].push(ardt);
        return tempData;
    } 
    function arJSONLevel_4(dtResults){//isi data 
        var tempData ={
            JVchDate_JV         : dtResults.JVchDate_JV,
            JVchDebetSaldo_JV   : dtResults.JVchDebetSaldo_JV,
            PeriodEnd_JV        : dateYMToString(dtResults.PeriodEnd_JV)
        };        
        return tempData;
    }    
    
    function stringLegend(){
        var strLgnd = {
            marginLeft:'2%',
            datas :[
                {boxColor:'#F4F4FF',strLabel:"Data Aset"},
                {boxColor:'#EAFFFB',strLabel:"Data Depreciation/Year"},
                {boxColor:'#e6ffcc',strLabel:"Data Depreciation/MonthYear"},
            ]
        };
        var rst = legendsTable(strLgnd);
        return rst;
    }
    
</script>
