<?php
/* 	
 * Author   : Dhidhik / Tanggal : 29-12-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 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_custAgingRanking('', '');" >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()">Export File  <?= $cek_autority_excel; ?></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_account_receivables/pre_ajax_reloadDataDetailCustAgingRankingAll';
    var url = base_url + 'report/index_account_receivables/ajax_reloadDataDetailCustAgingRankingAll';
    var dataSend = {};
    var noTree = 1;
    var noUrutLevel0 = 1;
    var stringHTML = "";
    var pages = {limit: limitRowInPage(), pages: 1};
    var tempArSumm = [];
    function variableDefault() {
        shortingText = "";
        rstTypeShorting = "ASC";
        dataSend = {};
        noTree = 1;
        noUrutLevel0 = 1;
        stringHTML = "";
        pages['pages'] = 1;
        tempArSumm = [];
    }

    function checkShorting(txtCheckShorting) {
        if (shortingText == txtCheckShorting) {
            rstTypeShorting == "DESC" ? rstTypeShorting = "ASC" : rstTypeShorting = "DESC";
        } else {
            rstTypeShorting = "ASC";
            shortingText = txtCheckShorting;
        }
        //alert("cek="+txtCheckShorting+"-"+rstTypeShorting);
        return rstTypeShorting;
    }
    $(document).ready(function () {
        searching_data_custAgingRanking("", "");
    });

    function searching_data_custAgingRanking(txtTable, txtFieldShorting) {//(namaVariableTabelDiModel, namaField)
        variableDefault();
        var typeShorting = checkShorting(txtFieldShorting);
        var dataIn = $('#cmb_collapse').combobox('getValue');

        dataSend = {
            pages: pages,
            predata: [],
            cmb_company: "<?= $paramUrlCompanyCode; ?>",
            cmb_branch: "<?= $paramUrlBranch; ?>",
            customerCode: "<?= $paramUrlCustCode; ?>",
            txt_DateTo: "<?php echo date('d-m-Y');?>",
            txtTable: txtTable,
            txtField: txtFieldShorting,
            typeShorting: typeShorting,
            dataIn: dataIn
        };

        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.branch == undefined || preResult.branch == "" ? "All Branch" : preResult.branch,
                reportLabel: " Detail Customer Aging Ranking All (Settled & Unsettled) ",
                startdate: preResult.startdate,
                enddate: preResult.enddate,
                colspan: 14
            };
            stringHTML += tableHTMLTopHeaderReport(dataTopHeader);//topHeader   

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

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

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

    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, " ");


        //LEGENDS
        delRow = '<div style="margin-left:2%;';
        htmls = htmls.replace(delRow, '<table><tr><td> </td></tr><tr><td> </td></tr></table>  <table style="margin-left:2%;');//
        delRow = '<div style="-webkit-print-color-adjust:exact; color: #666;';
        htmls = htmls.replace(delRow, '<tr style="-webkit-print-color-adjust:exact; color: #666;');//
        delRow = 'Legends</div>';
        htmls = htmls.replace(delRow, '<td colspan="2">Legends</td></tr>');//
        delRow = '<div style="clear: both;"></div>';
        htmls = htmls.replace(delRow, '');//
        delRow = '<div style=" margin-bottom:2px;">';
        htmls = htmls.replace(delRow, '');//

        delRow = '<div style="-webkit-print-color-adjust:exact; width: 10px;height:10px;';
        htmls = htmls.replace(delRow, '<tr><td style="-webkit-print-color-adjust:exact; width: 10px;');//
        delRow = ' margin-right: 10px;">&nbsp;</div>';
        htmls = htmls.replace(delRow, ' margin-right: 10px;">&nbsp;</td>');//
        delRow = '<div style="float: left;">Data Invoice</div>';
        htmls = htmls.replace(delRow, '<td style="float: left;">Data Invoice</td></tr>');//

        delRow = '<div style="-webkit-print-color-adjust:exact; width: 10px;height:10px;';
        htmls = htmls.replace(delRow, '<tr><td style="-webkit-print-color-adjust:exact; width: 10px;');//
        delRow = ' margin-right: 10px;">&nbsp;</div>';
        htmls = htmls.replace(delRow, ' margin-right: 10px;">&nbsp;</td>');//
        delRow = '<div style="float: left;">Data Receipt</div>';
        htmls = htmls.replace(delRow, '<td style="float: left;">Data Receipt</td></tr><table>');//

        delRow = '<div style="clear: both;"></div></div></div>';
        htmls = htmls.replace(delRow, '');//

        //console.log("htmls="+htmls);

        exportToExcel(htmls);
    }

    function prepareReport(parseResult) {
        var tempCode = "";
        var arTempDatas = [];
        // === LOOP PEMBACAAN DATA ===================================//
        parseResult.datas.forEach(function (dtResults) {
            if (tempCode == "") {//PEMBACAAN DATA PERTAMA KALI
                tempCode = dtResults.SInvNumber;
                var dataJSONLevel_0 = arJSONLevel_0(dtResults);
                arTempDatas.push(dataJSONLevel_0);
            }//END PEMBACAAN DATA PERTAMA KALI
            else {
                var iL0 = cekArraySummary(arTempDatas, "SInvNumber", dtResults.SInvNumber);
                if (iL0 > -1) {
                    var iL1 = cekArraySummary(arTempDatas[iL0]['data'], "SrecNumber", dtResults.SrecNumber);
                    if (iL1 > -1) {
                        if ((dtResults.SRecDetailID != null) && (dtResults.SRecDetailID != "") && (dtResults.SRecDetailID != undefined) && (dtResults.PPnFiscalStatus == '0')) {
                            arTempDatas[iL0]['data'][iL1]['SRecAmount_SRDet'] = (arTempDatas[iL0]['data'][iL1]['SRecAmount_SRDet'] * 1) + (dtResults.SRecAmount_SRDet * 1);
                            arTempDatas[iL0]['data'][iL1]['SRecDiscount_SRDet'] = (arTempDatas[iL0]['data'][iL1]['SRecDiscount_SRDet'] * 1) + (dtResults.SRecDiscount_SRDet * 1);
                            arTempDatas[iL0]['data'][iL1]['SrecRounded_SRDet'] = (arTempDatas[iL0]['data'][iL1]['SrecRounded_SRDet'] * 1) + (dtResults.SrecRounded_SRDet * 1);
                            var haveDate = arTempDatas[iL0]['SRecDate'];
                            var LoopDate = dtResults.SRecDate;
                            if (+haveDate < +LoopDate) {
                                arTempDatas[iL0]['SRecDate'] = dtResults.SRecDate;
                                arTempDatas[iL0]['FinishDue'] = dtResults.FinishDue;
                            }
                            arTempDatas[iL0]['TotalRounded'] = (arTempDatas[iL0]['TotalRounded'] * 1) + (dtResults.SrecRounded_SRDet * 1);
                            arTempDatas[iL0]['TotalDiscount'] = (arTempDatas[iL0]['TotalDiscount'] * 1) + (dtResults.SRecDiscount_SRDet * 1);
                            arTempDatas[iL0]['TotalPaid'] = (arTempDatas[iL0]['TotalPaid'] * 1) + (dtResults.SRecAmount_SRDet * 1);
                        }
                    } else {
                        if ((dtResults.SRecDetailID != null) && (dtResults.SRecDetailID != "") && (dtResults.SRecDetailID != undefined) && (dtResults.PPnFiscalStatus == '0')) {
                            var haveDate = arTempDatas[iL0]['SRecDate'];
                            var LoopDate = dtResults.SRecDate;
                            if (+haveDate < +LoopDate) {
                                arTempDatas[iL0]['SRecDate'] = dtResults.SRecDate;
                                arTempDatas[iL0]['FinishDue'] = dtResults.FinishDue;
                            }
                            arTempDatas[iL0]['TotalRounded'] = (arTempDatas[iL0]['TotalRounded'] * 1) + (dtResults.SrecRounded_SRDet * 1);
                            arTempDatas[iL0]['TotalDiscount'] = (arTempDatas[iL0]['TotalDiscount'] * 1) + (dtResults.SRecDiscount_SRDet * 1);
                            arTempDatas[iL0]['TotalPaid'] = (arTempDatas[iL0]['TotalPaid'] * 1) + (dtResults.SRecAmount_SRDet * 1);
                            var dataJSONLevel_1 = arJSONLevel_1(dtResults);
                            arTempDatas[iL0]['data'].push(dataJSONLevel_1);
                        }
                    }
                } else {
                    var dataJSONLevel_0 = arJSONLevel_0(dtResults);
                    arTempDatas.push(dataJSONLevel_0);
                }
            }
            //console.log("dtResults.InvoiceType_IR="+dtResults.InvoiceType_IR+"; dtResults.DPStatus_IR="+dtResults.DPStatus_IR);
        });
        // === END LOOP PEMBACAAN DATA ============================/    
        return arTempDatas;
    }
    function createReport(arTempDatas) {
        var tempStringHtml = "";
        tempStringHtml += createRowReport(arTempDatas);
        tempStringHtml += tableHTMLBlankForNext();
        tempStringHtml += "</table><script>"
                + "$(document).ready(function () {"
                + "    $('.tree-2').treegrid({"
                + "        expanderExpandedClass: ' treegrid-expander-expanded ',"
                + "        expanderCollapsedClass: 'treegrid-expander-collapsed'"
                + "    });"
                + "    $('.tree-2').treegrid('" + dataSend['dataIn'] + "');"
                + "});"
                + "</script" + ">";

//        tempStringHtml += summaryHTMLAll(" ALL ITEM ", "left", tempArSumm);
        tempStringHtml += stringLegend();
        return tempStringHtml;
    }
    function createRowReport(arTempDatas) {
        var tempStringHtml = "";        
        if(tempArSumm['footer']==undefined ||tempArSumm['footer']!='yes'){            
            tempArSumm = {
                footer:"yes",
                totalOwingAll: 0,
                currCust: ""
            };
        }        
        //MULAI LOOP
        arTempDatas.forEach(function (arDataLevel0) {//MULAI LOOP LEVEL 0                                 
            if (noUrutLevel0 == 1 && pages['pages']<2) {
                tempStringHtml += tableHTMLHeader(arDataLevel0);
            }
            var noTreeParentLevel0 = noTree;
            tempStringHtml += tableHTMLContentFirst(noTree, noUrutLevel0, arDataLevel0);
            tempArSumm['totalOwingAll'] = (tempArSumm['totalOwingAll'] * 1) + ((arDataLevel0['SInvTotalAmount_SI'] * 1) - (arDataLevel0['TotalPaid'] * 1) - (arDataLevel0['TotalDiscount'] * 1));
            tempArSumm['currCust'] = arDataLevel0['CurrencySymbol_Cust'];
            noTree++;

            var noUrutLevel1 = 1;
            arDataLevel0['data'].forEach(function (arDataLevel1) {//MULAI LOOP LEVEL 1                                 
                tempStringHtml += tableHTMLContentOther(noTree, noTreeParentLevel0, noUrutLevel1, arDataLevel1);
                noTree++;
                noUrutLevel1++;
            });
            noUrutLevel0++;
        });
        //END MULAI LOOP
        tempStringHtml += tableHTMLFooterSummary(tempArSumm);//MEMBUAT FOOTER SUMARY 
        return tempStringHtml;
    }
    function seeMore() {
        modal_open('Progress Bar', 'dlg_loading');
        $.post(pre_url, dataSend).done(function (pre_result) {//preAjax
            var preResult = JSON.parse(pre_result);
//            dataSend['predata'] = preResult.datas;
            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) {
                        $("#footerSumAll_hr").replaceWith("");
                        $("#footerSumAll_row").replaceWith("");
                        prearTempDatas = prepareReport(parseResult);
                        pre_stringHTML += createRowReport(prearTempDatas);
                        pre_stringHTML += tableHTMLBlankForNext();

                        pages['pages'] = (pages['pages'] * 1) + 1;
                        $("#tr-see-more").replaceWith("");//clear row button 
                        $("#rowBlankForNext").replaceWith(pre_stringHTML);//mengganti row blank dengan ros data page baru
//                        $("#tableSumAll").replaceWith(summaryHTMLAll(" ALL ITEM ", "left", 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 {
                        $("#btn-see-more").prop("disabled", true);
                        $("#btn-see-more").val("Data Completed");
                    }
                    modal_close('dlg_loading');
                }, 'json');
            } else {
                $("#btn-see-more").prop("disabled", true);
                $("#btn-see-more").val("Data Completed");
                modal_close('dlg_loading');
            }
        }, 'json');
    }
    function tableHTMLNotFound() {
        var strHeader = "<tr><td colspan='14' class='s3' align='left'><b><u><?= $paramUrlCust; ?></u></b></td></tr>"
                + "<tr id='tableHeader'>"//baris heading table                        
                + "<td width='' class='s4'><span class='small_bold' >No</span></td>"
                + "<td width='' class='s4' align='right'><span class='small_bold'>Date</span></td>"
                + "<td width='' class='s4' align='right'><span class='small_bold'>NoTransaction</span></td>"
                + "<td width='' class='s4' align='right'><span class='small_bold'>Inv.Amount</span></td>"
                + "<td width='' class='s4' align='right'><span class='small_bold'>RatePaid</span></td>"
                + "<td width='' class='s4' align='right'><span class='small_bold'>Real Paid<br>NotCurr.Inv</span></td>"
                + "<td width='' class='s4' align='right'><span class='small_bold'>Rounded</span></td>"
                + "<td width='' class='s4' align='right'><span class='small_bold'>Paid</span></td>"
                + "<td width='' class='s4' align='right'><span class='small_bold'>Disc</span></td>"
                + "<td width='' class='s4' align='right'><span class='small_bold'>Owing</span></td>"
                + "<td width='' class='s4' align='right'><span class='small_bold'>NetDueIn</span></td>"
                + "<td width='' class='s4' align='right'><span class='small_bold'>DueDate</span></td>"
                + "<td width='' class='s4' align='right'><span class='small_bold'>AgeDue</span></td>"
                + "<td width='' class='s4' align='right'><span class='small_bold'>FinishDue</span></td>"
                //+ "<td width='' class='s4' align='right'><span class='small_bold'>Status</span></td>"
                + "</tr></table>";
        return strHeader;
    }
    function tableHTMLHeader(data) {
        var strHeader = //"<tr><td colspan='14' class='s3' align='left'><a href='#'onclick=\"parent.tab_edit('Vendors','list/vendors', 'icon-edit', 'edit', '" + data.VendorCode_PRet + "')\" <?= $cek_autority_edit ?>><u><b>" + data.VendorName_PRet + " </b></u></a></td></tr>"
                "<tr><td colspan='14' class='s3' align='left'><u class='linkParentTab' onclick=\"parent.tab_edit('Edit Customer','list/customers', 'icon-edit', 'edit', '<?= $paramUrlCustCode; ?>')\"><b> <?= $paramUrlCust; ?> </b></u></td></tr>"
                + "<tr id='tableHeader'>"//baris heading table
                + "<td width='' class='s4'><span class='small_bold' >No</span></td>"
                + "<td width='' class='s4'><span class='small_bold'>Date</span></td>"
                + "<td width='' class='s4 linkParentTab' onclick=\"searching_data_custAgingRanking('at_salesinvoice','SInvNumber');\"><span class='small_bold'>NoTransaction</span></td>"
                + "<td width='' class='s4' align='right'><span class='small_bold'>Inv.Amount</span></td>"
                + "<td width='' class='s4' align='right'><span class='small_bold'>RatePaid</span></td>"
                + "<td width='' class='s4' align='right'><span class='small_bold'>Real Paid<br>NotCurr.Inv</span></td>"
                + "<td width='' class='s4' align='right'><span class='small_bold'>Rounded</span></td>"
                + "<td width='' class='s4' align='right'><span class='small_bold'>Paid</span></td>"
                + "<td width='' class='s4' align='right'><span class='small_bold'>Disc</span></td>"
                + "<td width='' class='s4' align='right'><span class='small_bold'>Owing</span></td>"
                + "<td width='' class='s4' align='right'><span class='small_bold'>NetDueIn</span></td>"
                + "<td width='' class='s4' align='right'><span class='small_bold'>DueDate</span></td>"
                + "<td width='' class='s4' align='right'><span class='small_bold'>AgeDue</span></td>"
                + "<td width='' class='s4' align='right'><span class='small_bold'>FinishDue</span></td>"
                //+ "<td width='' class='s4' align='right'><span class='small_bold'>Status</span></td>"
                + "</tr>";
        return strHeader;
    }
    function tableHTMLContentFirst(noTree, noUrut, data) {
        var strContent = "<tr class='treegrid-" + noTree + "' style='-webkit-print-color-adjust:exact;background-color:#F4F4FF;font-weight: bold;'>"
                + "<td width='' class='s5'><span class='small_bold' >" + noUrut + "</span></td>"
                + "<td width='' class='s5'><span class='small_bold' >" + data.SInvDate + "</span></td>"
                + "<td width='' class='s5'><span class='small_bold' ><a class='linkParentTab' href=\"#\" onclick=\"parent.tab_edit('Edit Sales Invoice', 'list/sales_invoice', 'icon-edit', 'edit', '" + data.SInvNumber + "')\" <?= $cek_autority_edit ?>>" + data.SInvNumber + "</a></span></td>"
                + "<td width='' class='s5' align='right'><span class='small_bold'>" + data.CurrencySymbol_Cust + "" + formatRp(data.SInvTotalAmount_SI) + "</span></td>"//inv.Amount
                + "<td width='' class='s5' align='right'><span class='small_bold'></span></td>"//RatePaid
                + "<td width='' class='s5' align='right'><span class='small_bold'></span></td>"//Real Paid<br>NotCurr.Inv
                + "<td width='' class='s5' align='right'><span class='small_bold'>" + data.CurrencySymbol_Cust + "" + formatRp(data.TotalRounded) + "</span></td>"//Rounded
                + "<td width='' class='s5' align='right'><span class='small_bold'>" + data.CurrencySymbol_Cust + "" + formatRp(data.TotalPaid) + "</span></td>"//Paid
                + "<td width='' class='s5' align='right'><span class='small_bold'>" + data.CurrencySymbol_Cust + "" + formatRp(data.TotalDiscount) + "</span></td>"//Discount
                + "<td width='' class='s5' align='right'><span class='small_bold'>" + data.CurrencySymbol_Cust + "" + formatRp((data.SInvTotalAmount_SI * 1) - (data.TotalPaid * 1) - (data.TotalDiscount * 1)) + "</span></td>"//Owing
                + "<td width='' class='s5' align='right'><span class='small_bold'>" + data.NetDueIn + "</span></td>"//
                + "<td width='' class='s5' align='right'><span class='small_bold' >" + data.DueDate + "</span></td>"
                + "<td width='' class='s5' align='right'><span class='small_bold' >";
        data.TransStatus_SI_ori == 1 ? strContent += "" + data.AgeDueDate : strContent += "-";
        strContent += "</span></td>"
                + "<td width='' class='s5' align='right'><span class='small_bold' >";
        data.TransStatus_SI_ori == 2 ? strContent += "" + data.FinishDue : strContent += "-";
        strContent += "</span></td>"
                //+ "<td width='' class='s5' align='right'><span class='small_bold' >" + data.TransStatus_SI + "</span></td>"
                + "</tr>";
        return strContent;
    }
    function tableHTMLContentOther(noTree, noTreeParent, noUrut, data) {
        var strContent = "";
        strContent = "<tr  class='treegrid-" + noTree + " treegrid-parent-" + noTreeParent + "' style='-webkit-print-color-adjust:exact;background-color:#EAFFFB;'>"
                + "<td width='' class='s5'><span class='small_bold' >" + noUrut + "</span></td>"
                + "<td width='' class='s5'><span class='small_bold' >" + data.SRecDate + "</span></td>"
                + "<td width='' class='s5'><span class='small_bold' ><a class='linkParentTab' href=\"#\" onclick=\"parent.tab_edit('Sales Receipts','list/sales_receipt', 'icon-edit', 'edit', '" + data.SrecNumber + "')\" <?= $cek_autority_edit ?>>" + data.SrecNumber + "</a></span></td>"
                + "<td width='' class='s5' align='right'><span class='small_bold'></span></td>"//amount
                + "<td width='' class='s5' align='right'><span class='small_bold'>Rp." + formatRp(data.BankCurrRate_SR) + "</span></td>"//Currency Rate
                + "<td width='' class='s5' align='right'><span class='small_bold'>";
        (data.SRecCurrency_SRDet * 1) > 0 ? strContent += "Rp. " + formatRp(data.SRecCurrency_SRDet) : strContent += "-";
        strContent += "</span></td>"//Real Paid<br>NotCurr.Inv
                + "<td width='' class='s5' align='right'><span class='small_bold'>";
        (data.SRecCurrency_SRDet * 1) > 0 ? strContent += data.CurrencySymbol_Cust + "" + formatRp(data.SrecRounded_SRDet) : strContent += "-";
        strContent += "</span></td>"//Rounded
                + "<td width='' class='s5' align='right'><span class='small_bold'>" + data.CurrencySymbol_Cust + "" + formatRp(data.SRecAmount_SRDet) + "</span></td>"//Paid
                + "<td width='' class='s5' align='right'><span class='small_bold'>" + data.CurrencySymbol_Cust + "" + formatRp(data.SRecDiscount_SRDet) + "</span></td>"//Discount
                + "<td width='' class='s5' align='right'><span class='small_bold'></span></td>"//Owing
                + "<td width='' class='s5' width='50'><span class='small_bold' ></span></td>" //NetDueIn
                + "<td width='' class='s5' width='50'><span class='small_bold' ></span></td>" //DueDate
                + "<td width='' class='s5' width='50'><span class='small_bold' ></span></td>" //  AgeDueDate
                + "<td width='' class='s5' width='50'><span class='small_bold' ></span></td>" //  FinishDueDate
                //+ "<td width='' class='s5' align='right'><span class='small_bold' >"+data.TransStatus_SR+"</span></td>"//TransStatus_SI
                + "</tr>";
        return strContent;
    }
    function tableHTMLFooterSummary(data) {
        //console.log('datas='+JSON.stringify(data));
        var strFooter = "<tr id='footerSumAll_hr'>"
                + "<td class='s5' align='right' colspan='14'><hr class='hrTableSummary' style='size:3px;'></td></tr>"
                + "<tr id='footerSumAll_row'><td class='s5' align='right' colspan='9'><b>TOTAL : </b></td>"
                + "<td width='' class='s5' align='right'><span class='small_bold' ><b>" + data['currCust'] + "" + formatRp(data['totalOwingAll']) + "</b></span></td>"
                + "</tr>";
        return strFooter;
    }
    function tableHTMLBlankForNext() {
        var strFooter = "<tr id='rowBlankForNext'>"
                + "<td class='s5' align='right' colspan='10'></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) {//menentukan data invoice ataupun data dp
        var tempData = {
            SInvNumber: dtResults.SInvNumber,
            SInvDate: dateSqlToIndo(dtResults.SInvDate),
            DueDate: dtResults.DueDate,
            AgeDueDate: dtResults.AgeDueDate,
            NetDueIn: dtResults.NetDueIn,
            FinishDue: dtResults.FinishDue,
            SRecDate: dtResults.SRecDate,
            SInvTotalAmount_SI: dtResults.SInvTotalAmount_SI,
            CurrencySymbol_Cust: dtResults.CurrencySymbol_Cust,
            TransStatus_SI_ori: dtResults.TransStatus_SI,
            TransStatus_SI: get_status(dtResults.TransStatus_SI),
            TotalRounded: 0,
            TotalDiscount: 0,
            TotalPaid: 0,
            data: []
        };
        if ((dtResults.SRecDetailID != null) && (dtResults.SRecDetailID != "") && (dtResults.SRecDetailID != undefined) && (dtResults.PPnFiscalStatus == '0')) {
            tempData['TotalRounded'] = (tempData['TotalRounded'] * 1) + (dtResults.SrecRounded_SRDet * 1);
            tempData['TotalDiscount'] = (tempData['TotalDiscount'] * 1) + (dtResults.SRecDiscount_SRDet * 1);
            tempData['TotalPaid'] = (tempData['TotalPaid'] * 1) + (dtResults.SRecAmount_SRDet * 1);
            var dtLvl1 = arJSONLevel_1(dtResults);
            tempData['data'].push(dtLvl1);
        }
        return tempData;
    }
    function arJSONLevel_1(dtResults) {//isi array saat data adalah invoice sesuai jenis Currency
        var tempData = {
            SrecNumber: dtResults.SrecNumber,
            SRecDetailID: dtResults.SRecDetailID,
            SRecDate: dateSqlToIndo(dtResults.SRecDate),
            SInvTotalAmount_SR: dtResults.SInvTotalAmount_SR,
            CurrencyRate_SR: dtResults.CurrencyRate_SR,
            BankCurrRate_SR: dtResults.BankCurrRate_SR,
            CurrencySymbol_SR: dtResults.CurrencySymbol_SR,
            SRecAmount_SRDet: dtResults.SRecAmount_SRDet,
            SRecDiscount_SRDet: dtResults.SRecDiscount_SRDet,
            SrecRounded_SRDet: dtResults.SrecRounded_SRDet,
            SRecOwing_SRDet: dtResults.SRecOwing_SRDet,
            SRecCurrency_SRDet: dtResults.SRecCurrency_SRDet,
            CurrencySymbol_Cust: dtResults.CurrencySymbol_Cust,
            TransStatus_SR: get_status(dtResults.TransStatus_SR)
        };
        return tempData;
    }
    function stringLegend() {
        var strLgnd = {
            marginLeft: '2%',
            datas: [
                {boxColor: '#F4F4FF !important', strLabel: "Data Invoice"},
                {boxColor: '#EAFFFB !important', strLabel: "Data Receipt"},
                {boxColor: '', strLabel: "'Date' : Tanggal transaksi."},
                {boxColor: '', strLabel: "'No Transaction' : Nomor transaksi."},
                {boxColor: '', strLabel: "'Inv.Amount' : Jumlah nominal tagihan pada transaksi invoices(tidak termasuk Tax atau pajak)."},
                {boxColor: '', strLabel: "'Rate Paid' : Nilai tukar rupiah saat transaksi pembayaran invoices."},
                {boxColor: '', strLabel: "'Real Paid NotCurr.Inv' : Jumlah nominal pembayaran invoice dalam nominal Rupiah."},
                {boxColor: '', strLabel: "'Rounded' : Nominal pembulatan pembayaran invoices."},
                {boxColor: '', strLabel: "'Paid' : Jumlah nominal pembayaran invoices."},
                {boxColor: '', strLabel: "'Disc' : Jumlah nominal potongan tagihan pada saat pembayaran invoices."},
                {boxColor: '', strLabel: "'Owing' : Jumlah nominal tagihan(invoices) yang belum dibayar."},
                {boxColor: '', strLabel: "'NetDueIn' : Lama hari yang diberikan untuk melunasi tagihan(invoices)."},
                {boxColor: '', strLabel: "'DueDate' : Tanggal batas akhir yang diberikan untuk melunasi tagihan(invoices)."},
                {boxColor: '', strLabel: "'FinishDue' : Lama hari yang dibutuhkan Customer untuk melunasi tagihan(invoices)."}
            ]
        };
        var rst = legendsTable(strLgnd);
        return rst;
    }
</script>
