<?php
/* 	
 * Author   : Dhidhik / Tanggal : 12-10-2015	
 * 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/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" >
            <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);
                                }
                                "editable="true"
                                >

                        </select>
                    </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'); ?>',
                                onSelect:function(rec){
                                    fncBranchSelected();
                                }
                                " editable="true" >
                        </select>
                        
                    </td>
                </tr>
                <!------------end-------------------------------------------------------------------------------->

                <!-------copy ibank To dari sini------------------------------------------------------------------------>
                <tr>
                    <td align="left" style="padding-bottom:8px;">
                        <b>By Bank :</b>
                    </td>
                </tr>
                <tr>
                    <td align="left">
                        <select name="cmb_bank" class="easyui-combogrid" 
                                id="cmb_bank"  
                                style="width:174px;"
                                data-options="
                                    panelWidth: 290,
                                    idField: 'AccountNumber',
                                    textField: 'BankCode',
                                    columns: [[
                                        {field:'AccountNumber',title:'Account Number',width:110, sortable: true},
                                        {field: 'BankCode', title: 'Bank Account', width: 190, sortable: true}
                                    ]],
                                    fitColumns: true
                                "
                                editable="true">
                        </select>
                    </td>
                </tr>
                <!------------end copy ibank To dari sini--------------------------------------------------------------------------- -->

                <!--ini separator-------------------------------------------->
                <tr><td colspan="2"><div class="tr-divider"></div></td></tr>
                <!--end-------------------------------------------------------->
                <!-----------------find by date------------------------------------------------------------------------>
                <tr>
                    <td style="padding-bottom:8px;">
                        <b>by Date</b>
                        <input type="checkbox" name="chk_ByDateNew" value="1" id="chk_ByDateNew" style="float:right;" checked disabled />
                    </td>
                </tr>
                <tr>
                    <td>
                        From
                        <span style="float:right;">
                            <input name="txt_DateFrom" id="txt_DateFrom" type="text" class="easyui-datebox " style="width:100px;height:22px;" editable="false" disabled />
                        </span>
                    </td>
                </tr>
                <tr>
                    <td>
                        To
                        <span style="float:right;">
                            <input name="txt_DateTo" id="txt_DateTo" type="text" class="easyui-datebox " style="width:100px;height:22px;" editable="false" disabled />
                        </span>
                    </td>
                </tr>
                <!----------------------------------------------end-------------------------------------------------------------->

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

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

                <!--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_bank_book('','');" >Search</a>
                        </div>
                    </td>
                </tr>
                <!--end-------------------------->
            </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()" <?=$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_cash_bank/pre_ajax_reloadDataBankBook';
    var url = base_url + 'report/index_cash_bank/ajax_reloadDataBankBook';
    var dataSend = {};
    var noTree = 1;    
    var noUrutLevel_1  = 1;
    var noUrutEndRow = 2;
    var stringHTML = "";
    var pages = {limit: limitRowInPage(), pages: 1};
    var tempArSumm = [];
    var SaldoOpening = 0;
    var SaldoEnding = 0;
    var startDateOpening = "";
    var endDateOpening = "",CurrencySymbol="",BankCode="";
    function variableDefault() {
        shortingText = "";
        rstTypeShorting = "ASC";
        dataSend = {};
        noTree = 1;
        noUrutLevel_1  = 1;
        noUrutEndRow = 2;
        stringHTML = "";
        pages['pages'] =1;
        pages['limit'] =limitRowInPage();
        tempArSumm = [];
        SaldoOpening = 0;
        SaldoEnding = 0;
        startDateOpening = 0;
        endDateOpening = 0;
        CurrencySymbol="";BankCode="";
    }

    function checkShorting(txtCheckShorting){
        if(shortingText==txtCheckShorting){
            rstTypeShorting=="DESC"?rstTypeShorting="ASC":rstTypeShorting="DESC";
        }else{
            rstTypeShorting = "ASC";
            shortingText    = txtCheckShorting;
        }
        return rstTypeShorting;
    }
    function fncBranchSelected(){
        var valCompCode     = $('#cmb_company').combobox('getValue');
        var valBranchCode   = $('#cmb_branch').combobox('getValue');
        $('#cmb_bank').combogrid({
            url: '<?php echo base_url(); ?><?php echo "report/index_cash_bank"; ?>/get_list_bank/'+valCompCode+'/'+valBranchCode,
            idField: 'AccountNumber',
            textField: 'BankCode',            
            panelWidth: 290,
            columns: [[
                {field:'AccountNumber',title:'Account Number',width:110, sortable: true},
                {field: 'BankCode', title: 'Bank Account', width: 190, sortable: true}
            ]],
            fitColumns: true,
            onLoadSuccess: function(data){
                var rows = data.rows;
                for(var i=0; i<1; i++){
                    var row = rows[i];
                    $(this).combogrid('setValue',row.AccountNumber);
                }
            }
        });
    }
    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 = {};
        /*
         disini hanya ada dua search, pakai company atau branch
         */

        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 ($('#cmb_bank').length > 0) {
            searchParameter['cmb_bank'] = $('#cmb_bank').combobox('getValue');
        }

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

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

        if ($('#cmb_paymentFrom').length > 0) {
            searchParameter['cmb_paymentFrom'] = $('#cmb_paymentFrom').datebox('getValue');
        }
        return searchParameter;
    }
    $(document).ready(function () {
        //============= transtatus ========================//
        var listTrans = [
            {"status": "all", "checked": ""},
            {"status": "dp", "checked": ""},
            {"status": "onprogress", "checked": ""},
            {"status": "finish", "checked": "checked"},
            {"status": "suspend", "checked": ""},
            {"status": "app_mgr", "checked": ""},
            {"status": "app_dir", "checked": ""},
            {"status": "app_dirmgr", "checked": ""},
            {"status": "app_limit", "checked": ""},
            {"status": "cancel_dir", "checked": ""}
        ];//daftar Transtatus yang dipakai, value parameter nya liat di custom js
        toHTMLTranstatusReport("divTranstatus", listTrans);//untuk memanggil html Transtatus        
        //============= end transtatus ========================//

        //Load Awal Data     
        fncBranchSelected();
        startLoad();
        /*===chk_ByDateNew jangan lupa ganti ============*/
        $('#chk_ByDateNew').click(function () {
            if ($(this).is(':checked')) {
                $('#txt_DateFrom').datebox('enable', true);
                $('#txt_DateTo').datebox('enable', true);
                $('#txt_DateFrom').datebox('setValue', '<?= date('01-m-Y') ?>');
                $('#txt_DateTo').datebox('setValue', 'today');
            }
            else {
                $('#txt_DateFrom').datebox('disable', true);
                $('#txt_DateTo').datebox('disable', true);
                $('#txt_DateFrom').datebox('setValue', '');
                $('#txt_DateTo').datebox('setValue', '');
            }

        });
        /*==================end=========================*/
    });
    
    function searching_data_bank_book(txtTable,txtFieldShorting){//(namaVariableTabelDiModel, namaField)
//        var url         = base_url + 'report/index_cash_bank/ajax_reloadDataPayment';    
        variableDefault();
        var getValue    = startLoad();
        var typeShorting= checkShorting(txtFieldShorting);
        var dataIn = "collapseAll";
        var dateNow = getDateNow_Eng();
        dataSend    = {
            pages: pages,
            predata: [],
            cmb_company: getValue['cmb_company'] == undefined ? "" : getValue['cmb_company'],
            cmb_branch: getValue['cmb_branch'] == undefined ? "" : getValue['cmb_branch'],
            cmb_bank: getValue['cmb_bank'] == undefined || getValue['cmb_bank']=="" ? "" : getValue['cmb_bank'],
            txt_DateFrom    : getValue['txt_DateFrom'],
            txt_DateTo      : getValue['txt_DateTo'],
            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 if ($('#cmb_bank').combobox('getValue') == undefined) {
            $('#cmb_bank').combobox('clear');
            var strAlert = strMessageAlert_report('bankIsEmpty');
            messageAlertBiasa('Warning', strAlert, 'error');
        }
        else if(strDateIndToEng(dataSend['txt_DateFrom'])>dateNow){
            var strAlert = strMessageAlert_report('dateFrom>now');
            messageAlertBiasa('Warning', strAlert, 'error');
        }
        else if(strDateIndToEng(dataSend['txt_DateTo'])>dateNow){
            var strAlert = strMessageAlert_report('dateTo>now');
            messageAlertBiasa('Warning', strAlert, 'error');
        }
        else if (strDateIndToEng(dataSend['txt_DateFrom']) > strDateIndToEng(dataSend['txt_DateTo'])) {
            var strAlert = strMessageAlert_report('dateFrom>dateTo');
            messageAlertBiasa('Warning', strAlert, 'error');
        } else {
            modal_open('Progress Bar', 'dlg_loading');
            $.post(pre_url, dataSend).done(function (pre_result) {//preAjax
                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: " Bank Book List ",
                    startdate: preResult.startdate,
                    enddate: preResult.enddate,
                    colspan: 7
                };
                stringHTML += tableHTMLTopHeaderReport(dataTopHeader);//topHeader   
                
                //====== value global ========================//
                SaldoOpening = preResult.nominalbalance;
                SaldoEnding = preResult.nominalbalance;
                startDateOpening = preResult.startdate;
                endDateOpening = preResult.enddate; 
                CurrencySymbol=preResult.CurrencySymbol; 
                BankCode=preResult.BankCode;
                //====== end value global ========================//
                
                var dataNotFound = {
                    "messagesWarning": preResult.messagesWarning
                    , "nominalbalance":preResult.nominalbalance
                    , "startdate" : preResult.startdate
                    , "enddate" : preResult.enddate
                };
                if (preResult.datas != 0 && preResult.messagesWarning=="") {//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(dataNotFound);
                        }
                        //console.log("arTempDatas="+JSON.stringify(arTempDatas));
                        $("#databox").html(stringHTML);
                        modal_close('dlg_loading');
                    }, 'json');
                } else {
                    stringHTML += tableHTMLNotFound(dataNotFound);
                    $("#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 = $("#list-print-container").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" />';
        mywindow.document.write('<html><head><title>Print Detail</title>');
        mywindow.document.write(css);
        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 = "";        
        htmls = stringHTML;
        htmls = htmls.replace(/<table/gi, "<table ><tr><td></td></tr><tr><td></td></tr></table><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='background-color:#d5d5d5;' "); 
        var delRow ="<tr>"
                +"<td class='s5' align='right' colspan='5'></td>"
                +"<td class='s5' align='right' colspan='2'><hr></td>"
            +"</tr>";
        htmls = htmls.replace(delRow, " ");

        delRow="<tr>"
            +"<td class='s5' align='right' colspan='8'><hr></td>"
            +"</tr>";
        htmls = htmls.replace(delRow, " ");
        exportToExcel(htmls);
    }
    function getDateNow_Eng(){
        var strDate = new Date();
        var day = strDate.getDate();
        var month = strDate.getMonth()+1;
        month.toString().length <2 ?month="0"+""+month:"";
        var year = strDate.getFullYear();
        var resultDate = year + "-" + month + "-" + day;
        return resultDate;
    }
    
    function prepareReport(parseResult) {
        var tempItemCode = "";
        var arTempDatas = [];
        // === LOOP PEMBACAAN DATA ===================================//
        
        parseResult.datas.forEach(function (dtResults) {
            if (tempItemCode == "") {//PEMBACAAN DATA PERTAMA KALI
                tempItemCode = dtResults.BankCode;
                var dataJSONLevel_0 = arJSONLevel_0(dtResults);
                arTempDatas.push(dataJSONLevel_0);
            }
            else {//PEMBACAAN DATA UNTUK DATA SETERUSNYA
                var indexLevel_0 = cekArraySummary(arTempDatas, "BankCode", dtResults.BankCode);//mendapatkan index array item
                if (indexLevel_0 > -1) {//jika item ditemukan data yg sama 
                    var dataJSONLevel_1 = arJSONLevel_1(dtResults);
                    arTempDatas[indexLevel_0]['data'].push(dataJSONLevel_1);
                    //console.log('indexSICode='+indexSICode);
                } else {
                    var dataJSONLevel_0 = arJSONLevel_0(dtResults);
                    arTempDatas.push(dataJSONLevel_0);
                }
            }//END PEMBACAAN DATA UNTUK DATA SETERUSNYA
        });
        // === 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 += stringLegend();
        return tempStringHtml;
    }
    function createRowReport(arTempDatas) {
        var tempStringHtml = "";
        //MULAI LOOP
        if(tempArSumm['footer']==undefined ||tempArSumm['footer']!='yes'){            
            tempArSumm = {
                footer:"yes",
                no: 2,
                enddate: endDateOpening,
                SaldoEnding: SaldoEnding
            };
        }
        
        arTempDatas.forEach(function (arDataLevel_0) {//MULAI LOOP UNTUK DAPAT NAMA CUSTOMER
            if(pages['pages'] <2){
                tempStringHtml += tableHTMLHeader(arDataLevel_0);                
                var ardatOpen = {"no":noUrutLevel_1 ,"startdate":startDateOpening,"SaldoOpening":SaldoOpening};
                tempStringHtml += tableHTMLSaldoOpening(noTree,ardatOpen);
                noTree++;
                noUrutLevel_1 ++;
            }

            arDataLevel_0['data'].forEach(function (arDataLevel_1) {//MULAI LOOP UNTUK DAPAT NAMA SALES INVOICE 
                tempArSumm['SaldoEnding'] = (tempArSumm['SaldoEnding'] * 1) + (arDataLevel_1['tempSaldoEnding'] * 1);
                arDataLevel_1['tempSaldoEnding']  = tempArSumm['SaldoEnding'];
                
                tempStringHtml += tableHTMLContentFirst(noTree, noUrutLevel_1 , arDataLevel_1);
                noTree++;
                noUrutLevel_1++;
                //===sumarry total=====================//
                tempArSumm['no'] = noUrutLevel_1;
                tempArSumm['enddate'] = arDataLevel_1.Journal_Date;
                //===end sumarry total================//
            });
        });
        //END MULAI LOOP        
//        $("#footerSumAll_hr").replaceWith("");
        $("#footerSumAll_row").replaceWith("");
        tempStringHtml += tableHTMLFooterSummary(noTree,tempArSumm);//MEMBUAT FOOTER SUMARY 
        noTree++;
        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
//                        $("#footerSumAll").replaceWith(tableHTMLFooterSummary(tempArSumm));
                        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 {
                        tempArSumm['enddate']=endDateOpening;
                        $("#footerSumAll_row").replaceWith(tableHTMLFooterSummary(noTree,tempArSumm));//MEMBUAT FOOTER SUMARY 
                        noTree++;                
                        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 

                        $("#btn-see-more").prop("disabled", true);
                        $("#btn-see-more").val("Data Completed");
                    }
                    modal_close('dlg_loading');
                }, 'json');
            } else {
                tempArSumm['enddate']=endDateOpening;
                $("#footerSumAll_row").replaceWith(tableHTMLFooterSummary(noTree,tempArSumm));//MEMBUAT FOOTER SUMARY 
                noTree++;                
                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 
                
                $("#btn-see-more").prop("disabled", true);
                $("#btn-see-more").val("Data Completed");
                modal_close('dlg_loading');
            }
        }, 'json');
    }
    function tableHTMLNotFound(data) {
        var dataLabel = "Data Not Found";
        data.messagesWarning!=""?dataLabel=data.messagesWarning:"";
        var strHeader = "<tr><td colspan='7' class='s3' align='left'><b><u>"+BankCode+"</u></b></td></tr>"
                + "<tr id='tableHeader'>"//baris heading table                
                + "<td width='' class='s4 text-left'><span class='small_bold' >No</span></td>"
                + "<td width='' class='s4 text-center'><span class='small_bold' >Date</span></td>"
                + "<td width='' class='s4 text-left'><span class='small_bold' >NoTransaction</span></td>"
                + "<td width='' class='s4 text-left'><span class='small_bold' >Description</span></td>"
                + "<td width='' class='s4 text-left'><span class='small_bold' >Debet</span></td>"
                + "<td width='' class='s4 text-left'><span class='small_bold' >Credit</span></td>"
                + "<td width='' class='s4 text-right' align='right'><span class='small_bold' >Saldo</span></td>"
                + "</tr>";
        if(data.messagesWarning!=""){
            strHeader+="<tr style='-webkit-print-color-adjust:exact;background-color:#F4F4FF;font-weight: bold;'>"
                + "<td width='' class='s5 text-center' colspan='7' align='center'><span class='small_bold' >"+dataLabel+"</span></td>"
                + "</tr></table>";
        }else{
            var ardatOpen = {"no":1,"startdate":data.startdate,"SaldoOpening":data.nominalbalance};
            var ardatEnd = {"no":2,"enddate":data.enddate,"SaldoEnding":data.nominalbalance};
            strHeader+=tableHTMLSaldoOpening("1",ardatOpen);
            strHeader+=tableHTMLFooterSummary("2",ardatEnd);
            strHeader+="</table>";
        }    
        return strHeader;
    }
    function tableHTMLSaldoOpening(noTree,data) {
        var str = "<tr class='s5 treegrid-" + noTree + "' style='-webkit-print-color-adjust:exact;background-color:#F4F4FF;font-weight: bold;'>"
                    +"<td class='s5' align=''>"+data['no']+"</td>"//no
                    +"<td class='s5' align=''>"+data['startdate']+"</td>"//date
                    +"<td class='s5' align=''></td>"//noTransaction
                    +"<td class='s5' align=''>Saldo Opening</td>"//desc
                    +"<td class='s5' align='right'><b></b></td>"//Debet
                    +"<td class='s5' align='right'><b></b></td>"//Credit
                    +"<td class='s5' align='right'><b>";
            data['SaldoOpening']<0?str+=" ("+CurrencySymbol+" "+formatRp(data['SaldoOpening'])+")":str+=CurrencySymbol+" "+formatRp(data['SaldoOpening']);
            str+="</b></td>"//Saldo
                +"</tr>";
        return str;
    }
    function tableHTMLHeader(data) {
        var strHeader="<tr><td colspan='7' class='s3' align='left'><b><u>"+BankCode+"</u></b></td></tr>" //baris nama branch
            +"<tr id='tableHeader'>"//baris heading table
                + "<td width='' class='s4 text-left'><span class='small_bold' >No</span></td>"
                + "<td width='' class='s4 text-center'><span class='small_bold' >Date</span></td>"
                + "<td width='' class='s4 text-left'><span class='small_bold' >NoTransaction</span></td>"
                + "<td width='' class='s4 text-left' style='width:400px;'><span class='small_bold' >Description</span></td>"
                + "<td width='' class='s4 text-right' align='right'><span class='small_bold' >Debet</span></td>"
                + "<td width='' class='s4 text-right' align='right'><span class='small_bold' >Credit</span></td>"
                + "<td width='' class='s4 text-right' align='right'><span class='small_bold' >Saldo</span></td>"
            +"</tr>";
        return strHeader;
    }
    function tableHTMLContentFirst(noTree, noUrut, data){
        var strContent = "<tr class='s5 treegrid-" + noTree + "' style='-webkit-print-color-adjust:exact;background-color:#F4F4FF;font-weight: bold;'>"
            +"<td width='' class='text-left'><span class='small_bold' >"+noUrut+"</span></td>"
            +"<td width='' class=' text-center'><span class='small_bold' >"+data.Journal_Date+"</span></td>"//date
            +"<td width='' class='text-left'><span class='small_bold' ><a class='linkParentTab' href=\"#\" onclick=\"trasanction_load('CPay', '"+data.Journal_Number+"');\" <?=$cek_autority_edit?>>"+data.Journal_Number+"</a></span></td>"
            +"<td width='' class=' text-left'><span class='small_bold' >"+data.Journal_Desc+"</span></td>"//desc
            +"<td width='' class=' text-right' align='right'><span class='small_bold' >"+CurrencySymbol+" "+formatRp(data.Saldo_Debet)+"</span></td>"//debet
            +"<td width='' class=' text-right' align='right'><span class='small_bold' >"+CurrencySymbol+" "+formatRp(data.Saldo_Credit)+"</span></td>"//credit
            +"<td width='' class=' text-right' align='right'><span class='small_bold' >"+CurrencySymbol+" "+formatRp(data.tempSaldoEnding)+"</span></td>"//saldo
        + "</tr>";
        return strContent;
    }
    function tableHTMLFooter() {
        var strFooter = "<tr>"
                + "<td class='s5' align='right' colspan='12'><hr class='hrTableSummary'></td></tr>";
        return strFooter;
    }
    function tableHTMLFooterSummary(noTree,data) {
        var strFooter = "<tr id='footerSumAll_row' class='s5 treegrid-" + noTree + "' style='-webkit-print-color-adjust:exact;background-color:#F4F4FF;font-weight: bold;'>"
                    +"<td class='s5' align=''>"+data['no']+"</td>"//no
                    +"<td class='s5' align=''>"+data['enddate']+"</td>"//date
                    +"<td class='s5' align=''></td>"//noTransaction
                    +"<td class='s5' align=''>Saldo Ending</td>"//desc
                    +"<td class='s5' align='right'><b></b></td>"//Debet
                    +"<td class='s5' align='right'><b></b></td>"//Credit
                    +"<td class='s5' align='right'><b>";
            data['SaldoEnding']<0?strFooter+=" ("+CurrencySymbol+" "+formatRp(data['SaldoEnding'])+")":strFooter+=CurrencySymbol+" "+formatRp(data['SaldoEnding']);
            strFooter+="</b></td>"//Saldo
                +"</tr>";
        return strFooter;
    }
    function tableHTMLBlankForNext() {
        var strFooter = "<tr id='rowBlankForNext'>"
                + "<td class='s5' align='right' colspan='8'></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 arJSONLevel_0(dtResults) {
        var tempData = {
            BankName:dtResults.BankName,
            BankCode:dtResults.BankCode,
            data:[]
        };
        var arData = arJSONLevel_1(dtResults);
        tempData['data'].push(arData);
        return tempData;
    }
    function arJSONLevel_1(dtResults) {
        var tempData = {
            Journal_Date: dateSqlToIndo(dtResults.Journal_Date),
            Journal_Desc: dtResults.Journal_Desc,
            Journal_Number:dtResults.Journal_Number,
            Saldo_Debet:dtResults.Saldo_Debet,
            Saldo_Credit:dtResults.Saldo_Credit,
            tempSaldoEnding: (dtResults.Saldo_Debet*1) - (dtResults.Saldo_Credit*1)
        };
        return tempData;
    }
    function stringLegend(){
        var strLgnd = {
            marginLeft:'2%',
            datas :[
                {boxColor:'#F4F4FF',strLabel:"Data Payment"},
                {boxColor:'',strLabel:"'Date' : Tanggal transaksi."},
                {boxColor:'',strLabel:"'NoTransaction' : Nomor transaksi."},
                {boxColor:'',strLabel:"'Description' : keterangan transaksi."},
                {boxColor:'',strLabel:"'Debet' : Debet."},
                {boxColor:'',strLabel:"'Credit' : Kredit."},
                {boxColor:'',strLabel:"'Saldo' : Nominal total transaksi."}
            ]
        };
        var rst = legendsTable(strLgnd);
        return rst;
    }
</script>