<?php
/* 	
 * Author   : Dhidhik / Tanggal : 23-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="formFilterInv" id="formFilterInv" >
            <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-------------------------------------------------------->

                <!-----------------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>
                        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-------------------------------------------------------->

                <!-------copy Customer dari sini------------------------------------------------------------------------>
                <tr>
                    <td align="left" style="padding-bottom:8px;">
                        <b>by Customer</b>
                    </td>
                </tr>
                <tr>
                    <td align="left">
                        <input id="txt_cust" name="txt_cust" placeholder="< Customer Name >" style="margin:2px 0px 3px;width:100%;height:18px;border:1px solid #CCC;">
                    </td>
                </tr>
                <!------------end copy Customer 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---------------------------------------------------------------->

                <!--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_customer_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');
        }
        return searchParameter;
    }

    $(document).ready(function () {
        startLoad();//Load awal
        $('#txt_DateTo').datebox('setValue', 'today');
    });

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

        var dataSend = {
            cmb_company: getValue['cmb_company'] == undefined ? "" : getValue['cmb_company'],
            cmb_branch: getValue['cmb_branch'] == undefined ? "" : getValue['cmb_branch'],
            txt_cust: document.formFilterInv.txt_cust.value,
            txt_DateTo: getValue['txt_DateTo'],
            txtTable: txtTable,
            txtField: txtFieldShorting,
            typeShorting: typeShorting
        };
        if ($('#cmb_branch').combobox('getValue') == undefined) {
            $('#cmb_branch').combobox('clear');
            var strAlert = strMessageAlert_report('brachIsEmpty');
            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(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 = {balance: 0, tax: 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='5' class='s0 text-center'><span class='normal_bold span_block ' ><small>" + parseResult.company.CompanyName + "</small></span></td>"
                        + "</tr>"
                        + "<tr>"
                        + "<td colspan='100' 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='5' class='s1 text-center'><span class='normal_bold span_block ' ><small>Customer List</small></span></td>"
                        + "</tr>"
                        + "<tr><td colspan='5' class='s2 text-center'> As &nbsp;&nbsp; " + parseResult.enddate + "</td></tr>"
                        + "<tr>"
                        + "<td colspan='5' class='s1'>&nbsp;</td>"
                        + "</tr>";
                //=== JIKA DATA DITEMUKAN ========================================//
                var testQindex = 0;
                if (parseResult.datas != 0) {
                    // === LOOP PEMBACAAN DATA ===================================//
                    parseResult.datas.forEach(function (dtResults) {
                        testQindex++;
                        if (tempCode == "" && dtResults.totalTax !=undefined && dtResults.totalBalance !=undefined) {//PEMBACAAN DATA PERTAMA KALI
                            tempCode = dtResults.CurrencyCode;
                            var dataJSONLevel_1 = arJSONLevel_1(dtResults);
                            arTempDatas.push(dataJSONLevel_1);
                        }//END PEMBACAAN DATA PERTAMA KALI

                        else if (dtResults.totalTax !=undefined && dtResults.totalBalance !=undefined) {//PEMBACAAN DATA UNTUK DATA INVOICE
                            var iL1 = cekArraySummary(arTempDatas, "CurrencyCode", dtResults.CurrencyCode);//mendapatkan index array level 1 (currency)
                            if (iL1 > -1) {
                                //console.log("arTempDatas="+JSON.stringify(arTempDatas));
                                var iL2 = cekArraySummary(arTempDatas[iL1]['data'], "CustomerCode", dtResults.CustomerCode);//index level 2(noInvoice)
                                if (iL2 > -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 INVOICE

                    });// === 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  
                        if (noUrutLevel1 > 1) {
                            stringHTML += tableHTMLFooterSummary(tempArSumm);
                            tempArSumm = {"balance": 0, "tax": 0};
                        }
                        stringHTML += tableHTMLHeaderLevel1(arDataLevel1);

                        var noUrutLevel2 = 1;
                        arDataLevel1['data'].forEach(function (arDataLevel2) {//MULAI LOOP LEVEL 2
                            noUrutLevel2 == 1 ? stringHTML += tableHTMLHeader(arDataLevel2) : null;//membuat tabel header LEVEL2
                            noTree++;
                            ///====== SUMMARY =================================//
//                            tempArSumm["balance"] = (tempArSumm["balance"] * 1) + (arDataLevel2.OutStanding_IR * 1);
                            tempArSumm["balance"] = (tempArSumm["balance"] * 1) + (arDataLevel2.totalBalance * 1);
                            tempArSumm["tax"] = (tempArSumm["tax"] * 1) + (arDataLevel2.totalTax * 1);
                            //===============END SUMMARY =====================//
                            stringHTML += tableHTMLContentFirst(noTree, noUrutLevel2, arDataLevel2);
                            noTree++;

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

                    //===END CARA BARU================================================================================================================//
                    stringHTML += tableHTMLFooterSummary(tempArSumm);//MEMBUAT FOOTER SUMARY 
                    tempArSumm = {"balance": 0, "tax": 0};
                    stringHTML += "</table><script>"
                            + "$(document).ready(function () {"
                            + "    $('.tree-2').treegrid({"
                            + "        expanderExpandedClass: ' treegrid-expander-expanded ',"
                            + "        expanderCollapsedClass: 'treegrid-expander-collapsed'"
                            + "    });"
                            + "    $('.tree-2').treegrid('" + dataIn + "');"
                            + "});"
                            + "</script" + ">";
                    //stringHTML+=summaryHTMLAll("ALL ITEM","left",ArSummAll);//MEMBUAT FOOTER SUMARY ALL                
                    stringHTML += stringLegend();
                }//=== 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='5'><hr></td>"
//            +"</tr>";
//        htmls = htmls.replace(delRow, " ");
        //console.log("htmls = "+htmls);
        exportToExcel(htmls);
    }
    function tableHTMLNotFound() {
        var strHeader = "<tr><td colspan='5' 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='80' class='s4'><span class='small_bold'>Cust No</span></td>"
                + "<td width='' class='s4'><span class='small_bold'>Cust Name</span></td>"
                + "<td width='' class='s4'><span class='small_bold'>Balance</span></td>"
                + "<td width='' class='s4'><span class='small_bold'>Tax</span></td>"
                + "</tr><tr>"
                + "<td width='' class='s5 text-center' colspan='5' align='center'><span class='small_bold' >Data Not Found</span></td>"
                + "</tr></table>";
        return strHeader;
    }
    function tableHTMLHeaderLevel1(data) {
        var strHeader = "<tr><td colspan='5' class='s3' align='left' style='left:-5px;position:inherit;'>--" + data.CurrencyCode + "</td></tr>";
        return strHeader;
    }
    function tableHTMLHeader(data) {
        var strHeader = //"<tr><td colspan='5' class='s3' align='left'><a href='#'onclick=\"parent.tab_edit('Customers','list/customers', 'icon-edit', 'edit', '" + data.CustomerCode + "')\" <?= $cek_autority_edit ?>><u><b>" + data.CustomerName + " </b></u></a></td></tr>"
                "<tr id='tableHeader'>"//baris heading table
                + "<td width='' class='s4'><span class='small_bold' >No</span></td>"
                + "<td width='150' class='s4 linkParentTab' style='cursor:pointer;' onclick=\"searching_data_customer_list('at_invoicereceipt','CustomerCode');\"><span class='small_bold'>Cust No</span></td>"
                + "<td width='' class='s4 linkParentTab' style='cursor:pointer;' onclick=\"searching_data_customer_list('am_customer','CustomerName');\"><span class='small_bold'>Cust Name</span></td>"
                + "<td width='' class='s4 linkParentTab' align='right' style='cursor:pointer;' onclick=\"searching_data_customer_list('am_customer','OutStanding');\"><span class='small_bold'>Balance</span></td>"
                + "<td width='' class='s4 linkParentTab' align='right' style='cursor:pointer;' onclick=\"searching_data_customer_list('am_customer','OutStandingFiscal');\"><span class='small_bold'>Tax</span></td>"
                + "</tr>";
        return strHeader;
    }
    function tableHTMLContentFirst(noTree, noUrut, data) {
        console.log("data="+JSON.stringify(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' ><a class='linkParentTab' href=\"#\" onclick=\"parent.tab_edit('Customers','list/customers', 'icon-edit', 'edit', '" + data.CustomerCode + "')\" <?= $cek_autority_edit ?>>" + data.CustomerCode + "</a></span></td>"
                + "<td width='' class='s5'><span class='small_bold' ><a class='linkParentTab' href=\"#\" onclick=\"parent.tab_edit('Customers','list/customers', 'icon-edit', 'edit', '" + data.CustomerCode + "')\" <?= $cek_autority_edit ?>>" + data.CustomerName + "</a></span></td>"
                + "<td width='' class='s5' align='right'><span class='small_bold'>" + formatRp(data.totalBalance) + "</span></td>"//
                + "<td width='' class='s5' align='right'><span class='small_bold'>Rp. " + formatRp(data.totalTax) + "</span></td>"//
                + "</tr>";
        return strContent;
    }
    function tableHTMLFooterSummary(data){
        //console.log('datas='+JSON.stringify(data));
        var strFooter = "<tr>"
                + "<td class='s5' align='right' colspan='5'><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.balance) + "</b></span></td>"
                + "<td width='' class='s5' align='right'><span class='small_bold' ><b>Rp. " + formatRp(data.tax) + "</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='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' >Customer </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_LAMA(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 invoice sesuai jenis Currency
        var tempData = {
            CurrencyCode: dtResults.CurrencyCode,
            data: []
        };
        var ardt = arJSONLevel_2(dtResults);
        tempData['data'].push(ardt);
        return tempData;
    }
    function arJSONLevel_2(dtResults) {//isi array saat data adalah invoice sesuai jenis Currency
        var tempData = {
            totalTax        : dtResults.totalTax,
            totalBalance    : dtResults.totalBalance,
            CustomerCode    : dtResults.CustomerCode,
            CustomerName    : dtResults.CustomerName,
            CurrencyCode    : dtResults.CurrencyCode
        };
        return tempData;
    }

    function stringLegend() {
        var strLgnd = {
            marginLeft: '2%',
            datas: [
                {boxColor: '#F4F4FF !important', strLabel: "Data Customer"},
                {boxColor: '', strLabel: "'Cust No' : Nomor Customer."},
                {boxColor: '', strLabel: "'Cust Name' : Nama Customer."},
                {boxColor: '', strLabel: "'Balance' : Jumlah Nominal DP Customer yang belum dipakai."},
                {boxColor: '', strLabel: "'Tax' : Jumlah Nominal Pajak yang belum dibayar."}
            ]
        };
        var rst = legendsTable(strLgnd);
        return rst;
    }
</script>
