<?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 stringHTML      = "";
    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)
        var url          = base_url + 'report/index_account_receivables/ajax_reloadDataDetailCustAgingRankingUnsettled';
        
        var typeShorting = checkShorting(txtFieldShorting);
        var dataIn       = $('#cmb_collapse').combobox('getValue');
        var dataSend = {
            companyCode     : "<?=$paramUrlCompanyCode;?>",
            customerCode    : "<?=$paramUrlCustCode;?>",
            txtTable        : txtTable,
            txtField        : txtFieldShorting,
            typeShorting    : typeShorting
        };
        
        modal_open('Progress Bar','dlg_loading');
        $.post(url, dataSend).done(function (result) {
            //alert("result="+result);
            //console.log("result="+result);
            //stringHTML = result;
            //console.log("result="+JSON.stringify(result)); 
            var parseResult = JSON.parse(result);
            //console.log("parseResult="+JSON.stringify(parseResult.datas));  
            var tempCode        = "";
            var arTempDatas     = [];   // temporer untuk menyimpan   
            var tempBranchCode  = "";   // untuk menyimpan nilai temporer 
            var tempArSumm      = {"amount":0,"paid":0,"texowing":0};   //menyimpan array untuk tabel Summary
            var arSumAll        = [];
            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='13' class='s0 text-center'><span class='normal_bold span_block ' ><small><?=$paramUrlCompany;?></small></span></td>"
                    + "</tr>"
                    + "<tr>"
                    + "<td colspan='13' class='s0 text-center'><span class='normal_bold span_block ' ><small><?=$paramUrlBranch;?></small></span></td>"
                    + "</tr>"
                    + "<tr>"
                    + "<td colspan='13' class='s1 text-center'><span class='normal_bold span_block ' ><small>Detail Customer Aging Ranking (Unsettled)</small></span></td>"
                    + "</tr>"
                    + "<tr>"
                    + "<td colspan='13' 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==""){//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'], "SRecDetailID",dtResults.SRecDetailID);
                            if(iL1>-1){
                                
                            }else{
                                if((dtResults.SRecDetailID!=null)&&(dtResults.SRecDetailID!="")&&(dtResults.SRecDetailID!=undefined)){                                    
                                    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 ============================/    
                //console.log("arTempDatas="+JSON.stringify(arTempDatas));
                
                //===CARA BARU================================================================================================================//                
                var noTree = 1;
                var noUrutLevel0 = 1;
                var totalOwingAll = 0;
                var currCust = "";
                arTempDatas.forEach(function (arDataLevel0) {//MULAI LOOP LEVEL 0                                 
                    if(noUrutLevel0==1){stringHTML+=tableHTMLHeader(arDataLevel0);}
                    var noTreeParentLevel0 = noTree;
                    stringHTML+=tableHTMLContentFirst(noTree,noUrutLevel0,arDataLevel0);
                    totalOwingAll =(totalOwingAll*1)+ ((arDataLevel0['SInvTotalAmount_SI']*1)-(arDataLevel0['TotalPaid']*1)-(arDataLevel0['TotalDiscount']*1));
                    currCust=arDataLevel0['CurrencySymbol_Cust'];
                    noTree++;
                    
                    var noUrutLevel1 = 1;
                    arDataLevel0['data'].forEach(function (arDataLevel1) {//MULAI LOOP LEVEL 1                                 
                        stringHTML+=tableHTMLContentOther(noTree,noTreeParentLevel0,noUrutLevel1,arDataLevel1);
                        noTree++;
                        noUrutLevel1++;
                    });
                    
                    noUrutLevel0++;
                });//END MULAI LOOP LEVEL 0
                
                //===END CARA BARU================================================================================================================//
                //stringHTML+=tableHTMLFooterSummary(tempTotalQtyInv,tempTotalQtyRet,tempTotalDisc,tempTotalAmount);//MEMBUAT FOOTER SUMARY 
                stringHTML+=tableHTMLFooterSummary(currCust,totalOwingAll);
                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",arSumAll);//MEMBUAT  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, " "); 

        //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 tableHTMLNotFound(){
        var strHeader = "<tr><td colspan='13' 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'>Total<br>Rounded</span></td>"
                        + "<td width='' class='s4' align='right'><span class='small_bold'>Total<br>Paid</span></td>"
                        + "<td width='' class='s4' align='right'><span class='small_bold'>Total<br>Disc</span></td>"
                        + "<td width='' class='s4' align='right'><span class='small_bold'>Total<br>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'>Status</span></td>"
                        + "</tr></table>";
        return strHeader;
    }    
    function tableHTMLHeader(data){
        var strHeader = //"<tr><td colspan='13' 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='13' 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'>Total<br>Rounded</span></td>"
                        + "<td width='' class='s4' align='right'><span class='small_bold'>Total<br>Paid</span></td>"
                        + "<td width='' class='s4' align='right'><span class='small_bold'>Total<br>Disc</span></td>"
                        + "<td width='' class='s4' align='right'><span class='small_bold'>Total<br>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'>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>"//Total<br>Rounded
        + "<td width='' class='s5' align='right'><span class='small_bold'>"+data.CurrencySymbol_Cust+""+formatRp(data.TotalPaid)+"</span></td>"//Total<br>Paid
        + "<td width='' class='s5' align='right'><span class='small_bold'>"+data.CurrencySymbol_Cust+""+formatRp(data.TotalDiscount)+"</span></td>"//Total<br>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>"//Total<br>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.AgeDueDate + "</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>"//Total<br>amount
            + "<td width='' class='s5' align='right'><span class='small_bold'>Rp."+formatRp(data.CurrencyRate_SR)+"</span></td>"//Currency Rate
            + "<td width='' class='s5' align='right'><span class='small_bold'>";(data.SRecCurrency_SRDet*1)>0?strContent+=data.CurrencySymbol_SR +""+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>"//Total<br>Rounded
            + "<td width='' class='s5' align='right'><span class='small_bold'>"+data.CurrencySymbol_Cust+""+formatRp(data.SRecAmount_SRDet)+"</span></td>"//Total<br>Paid
            + "<td width='' class='s5' align='right'><span class='small_bold'>"+data.CurrencySymbol_Cust +""+formatRp(data.SRecDiscount_SRDet)+"</span></td>"//Total<br>Discount
            + "<td width='' class='s5' align='right'><span class='small_bold'>"+data.CurrencySymbol_Cust+""+formatRp(data.SRecOwing_SRDet)+"</span></td>"//Total<br>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' align='right'><span class='small_bold' >"+data.TransStatus_SR+"</span></td>"//TransStatus_SI
            + "</tr>";
        return strContent;
    }  
    function tableHTMLFooterSummary(currCust,data){
        //console.log('datas='+JSON.stringify(data));
        var strFooter= "<tr>"
            + "<td class='s5' align='right' colspan='13'><hr class='hrTableSummary' style='size:3px;'></td></tr>"
            + "<tr><td class='s5' align='right' colspan='9'><b>TOTAL : </b></td>"
            + "<td width='' class='s5' align='right'><span class='small_bold' ><b>"+currCust+""+formatRp(data)+"</b></span></td>"
            + "</tr>";
        return strFooter;
    }      
    function cekArraySummary(masterAr, cekName,cekValue){
        var checkIndexSumAll       = -1;
        var checkIndexArAll        = 0;
        masterAr.forEach(function (dtStatusAll) {//cek nilai status pada array statusAll ada ato tidak
            if (dtStatusAll[cekName] == cekValue) {
                checkIndexSumAll = checkIndexArAll;
                return checkIndexSumAll;
            }
            checkIndexArAll++;
        });
        return checkIndexSumAll;
    }
    
    function arJSONLevel_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,
            SInvTotalAmount_SI  : dtResults.SInvTotalAmount_SI,
            CurrencySymbol_Cust : dtResults.CurrencySymbol_Cust,
            TransStatus_SI  : get_status(dtResults.TransStatus_SI),
            
            TotalRounded : 0,
            TotalDiscount : 0,
            TotalPaid : 0,
            data:[]
        };        
        if((dtResults.SRecDetailID!=null)&&(dtResults.SRecDetailID!="")&&(dtResults.SRecDetailID!=undefined)){
            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,
            CurrencySymbol_SR   : dtResults.CurrencySymbol_SR,
            SRecAmount_SRDet    : dtResults.SRecAmount_SRDet,
            SrecRounded_SRDet   : dtResults.SrecRounded_SRDet,
            SRecDiscount_SRDet  : dtResults.SRecDiscount_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"}
            ]
        };
        var rst = legendsTable(strLgnd);
        return rst;
    }
</script>
