<?php
/**
 * Created by PhpStorm.
 * User: aziz
 * Date: 8/16/2018
 * Time: 8:51 PM
 */
$segment_uri_array = $this->uri->segment_array();
$segmenUri = implode("/", $segment_uri_array);
$segmenUriEnc = implode("_", $segment_uri_array);

$btnNavigasi = "";
switch ($mode) {
    case "viewStatus":
    case "viewHistory":
    case "viewSettlement":
    case "viewHistoryOld":
        //region btnNavigasi
        $uri_1 = $segment_uri_array['1'];
        $uri_2 = $segment_uri_array['2'];
        $uri_3 = $segment_uri_array['3'];
        $date1 = isset($_GET['date1']) ? "?date1=" . $_GET['date1'] : "";
        $date2 = isset($_GET['date2']) ? "&date2=" . $_GET['date2'] : "";
        $metodes = array(
            "viewHistory" => "Data Baru",
            "viewHistoryOld" => "Data Lama",
        );
        $navigasies[base_url() . $uri_1 . "/viewHistory/" . $uri_3] = "Baru";
        $navigasies[base_url() . $uri_1 . "/viewHistoryOld/" . $uri_3] = "Lama";

        $btnNavigasi = "";
        // foreach($navigasies as $navLink => $navLabel){
        foreach ($metodes as $navMetode => $navLabel) {
            $navLink = base_url() . $uri_1 . "/$navMetode/" . $uri_3 . $date1 . $date2;
            $btnDisabled = $navMetode == $uri_2 ? "disabled" : "";
            $btnNavigasi .= "<button type='button' class='btn btn-info' $btnDisabled onclick=\"location.href='$navLink';\"><i class='fa fa-history'>&nbsp; $navLabel</i></button> ";
        }
        if (isset($_GET['date1'])) {
            $date1_f = formatField("fulldate", $_GET['date1']);
            $date2_f = formatField("fulldate", $_GET['date2']);
            $dateRange = $date1_f . " - " . $date2_f;
        }
        else {
            $dateRange = "";
        }
        // $subTitle = "<h4 class='no-padding no-margin text-capitalise'>".$subTitle . " $dateRange </h4>";
        $subTitle = $subTitle . " $dateRange";
        // $filters['date1'] = "2019-10-9";
        //endregion
        break;
}
//region seraching entry
$acturi = base_url() . $segmenUri;
$getSearch = isset($_GET['search']) ? $_GET['search'] : "";
$searching = "<form method='get' action='$acturi' class='margin-top-10'>";
$searching .= "<div class='input-group input-group-sm'>";
$searching .= "<input type='text' name='search' value='$getSearch' onclick=\"this.select();\" class='form-control' placeholder='Search by customer or PIC name'>";
// $searching .= "<input type='hidden' name=''>";
$searching .= "<span class='input-group-btn'>
                          <button type='submit' class='btn btn-info'><i class='fa fa-search'></i></button>
                        </span>";
$searching .= "</div>";
$searching .= "</form>";
//endregion
$btnNavigasi .= $searching;

switch ($mode) {
    case "viewHistory":
        $contens = "";
        $custom_button = "";

        if (isset($customButton)) {
            if (sizeof($customButton) > 0) {
                foreach ($customButton as $ky => $preg) {
                    foreach ($preg as $k => $mbuh) {
                        $$k = $preg[$k];
                    }
                    $custom_button .= "{text:'$label',action:function(e,dt,node,config){window.open('" . base_url() . $target . $customButtonTarget . "','download');}},";
                    // $custom_button .= "{text:'$label',action:function(e,dt,node,config){window.open('".base_url().$target.$uri_4."?date1=$date1&date2=$date2','download');}},";
                }
            }
        }

        $cf_button = $this->config->item('button');
        $segment_total = $this->uri->total_segments();
        $segment_page = $segment_total;
        $arrayHistoryCanceleds = isset($arrayHistoryCanceled) ? $arrayHistoryCanceled : array();

        $content = "";
        if (isset($stepLabels) && sizeof($stepLabels) > 0) {
            $content .= ("<ul class='nav nav-tabs'>");

            foreach ($stepLabels as $step => $label) {
                $color = $steps[$step]['target'] == $currentState ? "#454549" : "#999999";
                $borderColor = $steps[$step]['target'] == $currentState ? "#cccccc" : "#ffffff";
                $bgColor = $steps[$step]['target'] == $currentState ? "#ffffff" : "#f0f0f0";
                $content .= ("<li class='nav-item'>");
                $content .= "<a class='nav-link btn' style='background:$bgColor;color:$color;border-width:1px 1px 0px 1px; border-color:$borderColor; border-style: solid;' onclick =\"location.href='" . $stepLinks[$step] . "';\">";
                if ($steps[$step]['target'] == $currentState) {
                    $content .= "<span class='fa fa-adjust'></span> ";
                }
                $content .= "$label</a>";
                $content .= ("</li>");
            }
            $content .= ("</ul class='pager'>");
        }


        $content .= ("<div class=\"box-body\">");
        if (sizeof($arrayHistory) > 0) {
//            $content .= ("<form name='fSelect'>");
            $content .= "<div class='table-responsive table_history_$segmenUriEnc'>";
            $content .= "<table id='table_history_$segmenUriEnc' class='table display no-padding'>";

            //region thead
            $content .= ("<thead>");
            $content .= ("<tr bgcolor='#f0f0f0'>");

            foreach ($arrayHistoryLabels as $key => $label) {
                // arrPrint($label);
                $content .= ("<th class='text-uppercase text-muted text-center'>");
                if (is_array($label)) {
                    $content .= ($label['label']);
                }
                else {
                    $content .= ($label);
                }
                $content .= ("</th>");
            }


            $content .= ("</tr>");
            $content .= ("</thead>");

            //endregion head

            //region tbody
            $content .= ("<tbody>");
            $rowCtr = 0;
            foreach ($arrayHistory as $ii => $row) {

                $rslt_style = "";
                $cancel = false;
                if (isset($history_canceled[$ii]) && (sizeof($history_canceled[$ii]) > 0)) {
                    foreach ($history_canceled[$ii] as $hist_cancel) {
                        if ($rslt_style == "") {
                            $rslt_style = $hist_cancel;
                        }
                        else {
                            $rslt_style = $rslt_style . $hist_cancel;
                        }
                    }
                    $cancel = true;
                }
                if (isset($history_keterangan[$ii]) && (sizeof($history_keterangan[$ii]) > 0)) {
                    if ($cancel == false) {

                        foreach ($history_keterangan[$ii] as $hist_keterangan) {

                            if ($rslt_style == "") {
                                $rslt_style = $hist_keterangan;
                            }
                            else {
                                $rslt_style = $rslt_style . $hist_keterangan;
                            }
                        }
                    }
                }

                $rowCtr++;
                $content .= ("<tr id='tr$rowCtr' style='$rslt_style'>");
                foreach ($arrayHistoryLabels as $key => $label) {
                    $content .= ("<td>");
                    $content .= ($row[$key]);
                    $content .= ("</td>");
                }
                $content .= ("</tr>");
            }
            $content .= ("</tbody>");
            //endregion tbody

            //region tfoot
//            $content .= ("<tfoot>");
//            $content .= "<tr class='tfooter bg-grey-1'>";
//            foreach ($arrayHistoryLabels as $key => $label) {
//                $content .= ("<th>");
//                if (isset($arrayHistorySumField) && isset($arrayHistorySumField[$key])) {
////                    $content .= formatField($key, $arrayHistorySumField[$key]);
//                    $content .= "";
//                }
//                else {
//                    $content .= "";
//                }
//                $content .= ("</th>");
//            }
//            $content .= "</tr>";
//            $content .= ("</tfoot>");
            //endregion tfoot
            $content .= "</table class='table table-bordered'>";
            $content .= "</div class='table-responsive'>";
//            $content .= ("</form>");

        }
        else {
            $content .= "no history found.<br>";
            $content .= "to go back to index, you can click BACK button<br>";
        }
        $content .= "</div>";

        $content .= "<script>
                    $(document).ready( function(){
                        var table = $('#table_history_$segmenUriEnc').DataTable({
                            dom: 'lBfrtip',
                            fixedHeader: true,
                            lengthMenu: [ [10, 20, 50, 100, -1], [10, 20, 50, 100, 'All'] ],
                            pageLength: -1,
                            stateSave: true,
                            processing: true,
                            searchDelay: 1500,
                            search: {
                                smart: false
                            },
                            buttons: [
                                        { extend: 'print', footer: true },
                                        {
                                            text: 'Download Excel',
                                            action: function (e, dt, node, config) {
                                                fnExcelReport('table_history_$segmenUriEnc');
                                            }
                                        },
                                        $custom_button
                                    ],



//                            footerCallback: function ( row, data, start, end, display ) {
//                                        var api = this.api(), data;
//
//                                        // Remove the formatting to get integer data for summation
//                                        var intVal = function ( i ) {
//                                            return typeof i === 'string' ?
//                                                i.replace(/[$,]/g, '')*1 :
//                                                typeof i === 'number' ?
//                                                    i : 0;
//                                        };
//                                        var arrayFooter = $('#table_history_$segmenUriEnc>tfoot>tr>th');
//                                        var dpageTotal = [];
//                                        jQuery.each(arrayFooter, function(i,d){
//                                            var id_n_index = parseFloat(i);
//                                            dpageTotal[id_n_index] = 0;
//                                            jQuery.each( $(api.column(id_n_index, { page: 'current'}).data() ), function(ii, obj){
//                                                var pos = obj.indexOf('<');
//                                                var hr = obj.indexOf('<hr>');
//                                                if(pos!==-1&&hr==-1&&id_n_index>0){
//                                                    dpageTotal[id_n_index] += intVal( $(obj).html() );
//                                                }
//                                                else{
//                                                }
//                                            });
//                                            if( !isNaN(dpageTotal[id_n_index]) && dpageTotal[id_n_index] >= 0 ){
//                                                $( api.column(id_n_index).footer() ).html(
//                                                    \"<div class='text-right text-primary text-bold'>\"+addCommas(dpageTotal[id_n_index])+\"</div>\"
//                                                );
//                                            }
//                                        });
//                                    }
                                });

                                //new $.fn.dataTable.FixedHeader( table );
                                $('.table-responsive.table_history_$segmenUriEnc').floatingScroll();
                                $('.table-responsive.table_history_$segmenUriEnc').scroll(function() {
                                    setTimeout(function () {
                                        $('#table_history_$segmenUriEnc').DataTable().fixedHeader.adjust();
                                    }, 100);
                            });
                            });
                    </script>";


        if (is_array($addLink)) {
            $addLinkStr = "<a href='" . $addLink['link'] . "' class='btn btn-success'>" . $addLink['label'] . "</a>";
        }
        else {
            $addLinkStr = "";
        }

        $p = New Layout("$title", "$subTitle", MODUL_TEMPLATE_PATH . "/template/history.html");
        $str_group = isset($_GET['gr']) ? "?gr=" . $_GET['gr'] : "";

        $p->addTags(array(
            "jenisTr" => $jenisTr . $str_group,
            "trName" => $trName,
            "navigasi" => $btnNavigasi,
            "menu_left" => callMenuLeft(),
            "float_menu_atas" => callFloatMenu('atas'),
            "float_menu_bawah" => callFloatMenu(),
            "menu_taskbar" => callMenuTaskbar(),
            "btn_back" => callBackNav(),
            "content" => $content,
            "profile_name" => $this->session->login['nama'],
            "add_link" => $addLinkStr,
            "date1" => $filters['date1'],
            "date2" => $filters['date2'],
            "date_min" => isset($filters['dates']['start']) ? $filters['dates']['start'] : "",
            "date_max" => isset($filters['dates']['end']) ? $filters['dates']['end'] : "",
            "url" => $thisPage,
            "newTrTarget" => isset($addLink['link']) ? $addLink['link'] . $str_group : "javascript:void(0)",
            "newTrDisp" => isset($addLink['link']) ? "inline-table" : "none",
            "getSearch" => strlen($getSearch) > 0 ? "&search=" . $getSearch : "",
        ));

        $p->render();
        break;
    case "viewHistory_old":
        $contens = "";
        $custom_button = "";
        // $uri_4 = $segment_uri_array['4'];
        // $date1 = isset($_GET['date1']) ? $_GET['date1'] : "";
        // $date2 = isset($_GET['date2']) ? $_GET['date2'] : "";
// arrPrint($customButton);
        if (isset($customButton)) {
            if (sizeof($customButton) > 0) {
                foreach ($customButton as $ky => $preg) {
                    foreach ($preg as $k => $mbuh) {
                        $$k = $preg[$k];
                    }
                    $custom_button .= "{text:'$label',action:function(e,dt,node,config){window.open('" . base_url() . $target . $customButtonTarget . "','download');}},";
                    // $custom_button .= "{text:'$label',action:function(e,dt,node,config){window.open('".base_url().$target.$uri_4."?date1=$date1&date2=$date2','download');}},";
                }
            }
        }
// cekLime($custom_button . " $target");
        $cf_button = $this->config->item('button');
        $segment_uri_array = $this->uri->segment_array();
        $segment_total = $this->uri->total_segments();
        $segment_page = $segment_total;
        $arrayHistoryCanceleds = isset($arrayHistoryCanceled) ? $arrayHistoryCanceled : array();

        $content = "";
        if (isset($stepLabels) && sizeof($stepLabels) > 0) {
            $content .= ("<ul class='nav nav-tabs'>");

            foreach ($stepLabels as $step => $label) {
                //                $btnClass = $steps[$step]['target'] == $currentState ? "btn-success" : "btn-default";
                $color = $steps[$step]['target'] == $currentState ? "#454549" : "#999999";
                $borderColor = $steps[$step]['target'] == $currentState ? "#cccccc" : "#ffffff";
                $bgColor = $steps[$step]['target'] == $currentState ? "#ffffff" : "#f0f0f0";
                $content .= ("<li class='nav-item'>");
                $content .= "<a class='nav-link btn' style='background:$bgColor;color:$color;border-width:1px 1px 0px 1px; border-color:$borderColor; border-style: solid;' onclick =\"location.href='" . $stepLinks[$step] . "?date1=" . $filters['date1'] . "&date2=" . $filters['date2'] . "';\">";
                if ($steps[$step]['target'] == $currentState) {
                    $content .= "<span class='fa fa-adjust'></span> ";
                }
                $content .= "$label</a>";
                $content .= ("</li>");
            }
            $content .= ("</ul class='pager'>");
        }


        $content .= ("<div class=\"box-body\">");
        if (sizeof($arrayHistory) > 0) {
            $content .= ("<form name='fSelect'>");
            $content .= ("<div class='table-responsive'>");
            $content .= "<table class='table hover datatables table-condensed table-bordered no-padding'>";

            //region thead
            $content .= ("<thead>");
            $content .= ("<tr bgcolor='#f0f0f0'>");

            foreach ($arrayHistoryLabels as $key => $label) {
                // arrPrint($label);
                $content .= ("<th class='text-uppercase text-muted text-center'>");
                if (is_array($label)) {
                    $content .= ($label['label']);
                }
                else {
                    $content .= ($label);
                }
                $content .= ("</th>");
            }
            // $content .= ("<th class='text-uppercase text-muted text-center'>");
            // $content .= ("</th>");

            $content .= ("</tr>");
            $content .= ("</thead>");

            //endregion head

            //region tbody
            $content .= ("<tbody>");
            $rowCtr = 0;
            foreach ($arrayHistory as $row) {
                $rowCtr++;
                $content .= ("<tr id='tr$rowCtr'>");
                foreach ($arrayHistoryLabels as $key => $label) {

                    $content .= ("<td>");
                    $content .= (isset($row[$key]) ? $row[$key] : "");
                    $content .= ("</td>");

                }
                $content .= ("</tr>");
            }
            $content .= ("</tbody>");
            //endregion tbody

            //region tfoot
//            $content .= ("<tfoot>");
//            $content .= "<tr class='tfooter bg-grey-1'>";
//            foreach ($arrayHistoryLabels as $key => $label) {
//                $content .= ("<th>");
//                if (isset($arrayHistorySumField) && sizeof($arrayHistorySumField) > 0) {
//                    if (isset($arrayHistorySumField[$key])) {
//                        $content .= $arrayHistorySumField[$key];
//                    }
//                    else {
//                        $content .= "-";
//                    }
//                }
//                else {
//                    $content .= "-";
//                }
//                $content .= ("</th>");
//            }
//            $content .= "</tr>";
//            $content .= ("</tfoot>");
            //endregion tfoot

            $content .= ("</table class='table table-bordered'>");
            $content .= ("</div class='table-responsive'>");
            $content .= ("</form>");

        }
        else {
//            $content .= ("no history found.<br>");
//            $content .= ("to go back to index, you can click BACK button<br>");
            $msg = "no history found.<br>to go back to index, you can click BACK button<br>";
            $content .= tplNoData($msg);
        }
        $content .= ("</div>");

        $content .= "<script>
                    $(document).ready( function(){

                        var table = $('table.datatables').dataTable({
                            dom: 'lBfrtip',
                            fixedHeader: true,
                            lengthMenu: [ [10, 20, 50, 100, -1], [10, 20, 50, 100, 'All'] ],
                            pageLength: -1,
                            buttons: [
                                        { extend: 'print', footer: true },
                                        { 
                                            extend: 'csv',
                                            text: 'CSV',
                                            footer: true 
                                        },
                                          $custom_button
                                    ],
//                            buttons: [
//                                        'copy', 'csv', 'excel', 'pdf', 'print'
//                                    ],
//                            buttons: [
//                                        {
//                                            extend: 'colvisGroup',
//                                            text: 'Office info',
//                                            show: [ 1, 2 ],
//                                            hide: [ 3, 4, 5 ]
//                                        },
//                                        {
//                                            extend: 'colvisGroup',
//                                            text: 'HR info',
//                                            show: [ 3, 4, 5 ],
//                                            hide: [ 1, 2 ]
//                                        },
//                                        {
//                                            extend: 'colvisGroup',
//                                            text: 'Show all',
//                                            show: ':hidden'
//                                        }
//                                    ]
                            footerCallback: function ( row, data, start, end, display ) {
                                        var api = this.api(), data;

                                        // Remove the formatting to get integer data for summation
                                        var intVal = function ( i ) {
                                            return typeof i === 'string' ?
                                                i.replace(/[$,]/g, '')*1 :
                                                typeof i === 'number' ?
                                                    i : 0;
                                        };

                                        var arrayFooter = $('tfoot>tr>th');
                                        var dpageTotal = [];
                                        jQuery.each(arrayFooter, function(i,d){
                                            var id_n_index = parseFloat(i);
                                            dpageTotal[id_n_index] = 0;
                                            jQuery.each( $(api.column(id_n_index, { page: 'current'}).data() ), function(ii, obj){
                                                dpageTotal[id_n_index] += intVal( $(obj).html() );
//                                                console.log( $('span', obj).html() );
//                                                console.log( obj );
//                                                console.error( $(obj).html() );
                                            });
//                                            console.log('dpageTotal[id_n_index]: ' + ' ' + id_n_index + ' '  +  dpageTotal[id_n_index] );


                                        if( !isNaN(dpageTotal[id_n_index]) && dpageTotal[id_n_index] > 0 ){
                                            $( api.column(id_n_index).footer() ).html(
                                                \"<div class='text-right text-primary text-bold'>\"+addCommas(dpageTotal[id_n_index])+\"</div>\"
                                            );
                                        }


                                        });

// Total over all pages
//                                        var total2=0;
//                                        jQuery.each( $(api.column(2).data()), function(i, obj){
//                                            total2 += intVal( $('span', obj).html() );
//                                        });
//
//                                        var total3=0;
//                                        jQuery.each( $(api.column(3).data()), function(i, obj){
//                                            total3 += intVal( $('span', obj).html() );
//                                        });
//
//                                        var total4=0;
//                                        jQuery.each( $(api.column(4).data()), function(i, obj){
//                                            total4 += intVal( $('span', obj).html() );
//                                        });
//
//                                        var total5=0;
//                                        jQuery.each( $(api.column(5).data()), function(i, obj){
//                                            total5 += intVal( $('span', obj).html() );
//                                        });


                                        // Total over this page
//                                        pageTotal2 = api
//                                            .column( 2, { page: 'current'} )
//                                            .data()
//                                            .reduce( function (a, b) {
//                                                return intVal(a) + intVal(b);
//                                            }, 0 );

//                                        var pageTotal2=0;
//                                        jQuery.each( $(api.column(2, { page: 'current'}).data()), function(i, obj){
//                                            pageTotal2 += intVal( $('span', obj).html() );
//                                        });
//
//                                        var pageTotal3=0;
//                                        jQuery.each( $(api.column(3, { page: 'current'}).data()), function(i, obj){
//                                            pageTotal3 += intVal( $('span', obj).html() );
//                                        });
//
//                                        var pageTotal4=0;
//                                        jQuery.each( $(api.column(4, { page: 'current'}).data()), function(i, obj){
//                                            pageTotal4 += intVal( $('span', obj).html() );
//                                        });
//
//                                        var pageTotal5=0;
//                                        jQuery.each( $(api.column(5, { page: 'current'}).data()), function(i, obj){
//                                            pageTotal5 += intVal( $('span', obj).html() );
//                                        });

                                        // Update footer
//                                        $( api.column( 2 ).footer() ).html(
//                                            \"<div class='text-right text-primary text-bold'>\"+addCommas(pageTotal2)+\"</div>\"
//                                            + \"<div class='text-right'>\"+addCommas(total2)+\"</div>\"
//                                        );

//                                        $( api.column( 3 ).footer() ).html(
//                                            \"<div class='text-right text-success text-bold'>\"+addCommas(pageTotal3)+\"</div>\"
//                                            + \"<div class='text-right'>\"+addCommas(total3)+\"</div>\"
//                                        );

//                                        $( api.column( 4 ).footer() ).html(
//                                            \"<div class='text-right text-success text-bold'>\"+addCommas(pageTotal4)+\"</div>\"
//                                            + \"<div class='text-right'>\"+addCommas(total4)+\"</div>\"
//                                        );

//                                        $( api.column( 5 ).footer() ).html(
//                                            \"<div class='text-right text-danger text-bold'>\"+addCommas(pageTotal5)+\"</div>\"
//                                            + \"<div class='text-right'>\"+addCommas(total5)+\"</div>\"
//                                        );

                                    }
                                });

                            });

                            $('.table-responsive').floatingScroll();
                    </script>";


        if (is_array($addLink)) {
            $addLinkStr = "<a href='" . $addLink['link'] . "' class='btn btn-success'>" . $addLink['label'] . "</a>";
        }
        else {
            $addLinkStr = "";
        }

        $p = New Layout("$title", "$subTitle", MODUL_TEMPLATE_PATH . "template/history.html");
        $p->addTags(array(
            "jenisTr" => $jenisTr,
            "trName" => $trName,
            "navigasi" => $btnNavigasi,
            "menu_left" => callMenuLeft(),
            //                                "trans_menu" => callTransMenu(),
            "float_menu_atas" => callFloatMenu('atas'),
            "float_menu_bawah" => callFloatMenu(),
            "menu_taskbar" => callMenuTaskbar(),
            "btn_back" => callBackNav(),
            "content" => $content,
            "profile_name" => $this->session->login['nama'],
            "add_link" => $addLinkStr,
            "date1" => $filters['date1'],
            "date2" => $filters['date2'],
            "date_min" => isset($filters['dates']['start']) ? $filters['dates']['start'] : "",
            "date_max" => isset($filters['dates']['end']) ? $filters['dates']['end'] : "",
            "url" => $thisPage,
            "newTrTarget" => isset($addLink['link']) ? $addLink['link'] : "JavaScript:void(0)",
            "newTrDisp" => isset($addLink['link']) ? "inline-table" : "none",
        ));

        $p->render();
        break;
    case "showData":

        $contens = "";
        $custom_button = "";
        // cekBiru();
        // $uri_4 = $segment_uri_array['4'];
        // $date1 = isset($_GET['date1']) ? $_GET['date1'] : "";
        // $date2 = isset($_GET['date2']) ? $_GET['date2'] : "";
        // arrPrint($customButton);
        if (isset($customButton)) {
            if (sizeof($customButton) > 0) {
                foreach ($customButton as $ky => $preg) {
                    foreach ($preg as $k => $mbuh) {
                        $$k = $preg[$k];
                    }
                    $custom_button .= "{text:'$label',action:function(e,dt,node,config){window.open('" . base_url() . $target . $customButtonTarget . "','download');}},";
                    // $custom_button .= "{text:'$label',action:function(e,dt,node,config){window.open('".base_url().$target.$uri_4."?date1=$date1&date2=$date2','download');}},";
                }
            }
        }
        // cekLime($custom_button . " $target");
        $cf_button = $this->config->item('button');
        $segment_total = $this->uri->total_segments();
        $segment_page = $segment_total;
        $arrayHistoryCanceleds = isset($arrayHistoryCanceled) ? $arrayHistoryCanceled : array();

        $content = "";
//        $content .= "<div class='box box-info'>";
//        $content .= "<div class='box-header'>";
//        $content .= "<h4><span cclass=\"glyphicon glyphicon-flash\"></span> HISTORY TRANSACTIONS</h4>";
//        $content .= "</div class='box box-header'>";
        if (isset($stepLabels) && sizeof($stepLabels) > 0) {
            $content .= ("<ul class='nav nav-tabs'>");

            foreach ($stepLabels as $step => $label) {
                //                $btnClass = $steps[$step]['target'] == $currentState ? "btn-success" : "btn-default";
                $color = $steps[$step]['target'] == $currentState ? "#454549" : "#999999";
                $borderColor = $steps[$step]['target'] == $currentState ? "#cccccc" : "#ffffff";
                $bgColor = $steps[$step]['target'] == $currentState ? "#ffffff" : "#f0f0f0";

                $linkStep = $stepLinks[$step];
                $content .= ("<li class='nav-item'>");

                // $content .= "<a class='nav-link btn' style='background:$bgColor;color:$color;border-width:1px 1px 0px 1px; border-color:$borderColor; border-style: solid;' onclick =\"location.href='" . $stepLinks[$step] . "?date1=" . $filters['date1'] . "&date2=" . $filters['date2'] . "';\">";
                // $content .= "<a class='nav-link btn' style='background:$bgColor;color:$color;border-width:1px 1px 0px 1px; border-color:$borderColor; border-style: solid;' onclick =\"location.href='" . $stepLinks[$step] . "';\">";
                $content .= "<a class='nav-link btn' style='background:$bgColor;color:$color;border-width:1px 1px 0px 1px; border-color:$borderColor; border-style: solid;' onclick =\"$('#historyList').load('$linkStep');\">";
                if ($steps[$step]['target'] == $currentState) {
                    $content .= "<span class='fa fa-adjust'></span> ";
                }
                $content .= "$label</a>";
                $content .= ("</li>");
            }
            $content .= ("</ul class='pager'>");
        }


        $content .= ("<div class=\"box-body\">");
        if (sizeof($arrayHistory) > 0) {
            $content .= ("<form name='fSelect'>");
            $content .= ("<div class='table-responsive'>");
            $content .= "<table id='history_penjualan' class='table dataTable table-condensed compact display nowrap table-bordered no-padding'>";

            //region thead
            $content .= ("<thead>");
            $content .= ("<tr bgcolor='#f0f0f0'>");

            foreach ($arrayHistoryLabels as $key => $label) {
                // arrPrint($label);
                $content .= ("<th class='text-uppercase text-muted text-center'>");
                if (is_array($label)) {
                    $content .= ($label['label']);
                }
                else {
                    $content .= ($label);
                }
                $content .= ("</th>");
            }
            // $content .= ("<th class='text-uppercase text-muted text-center'>");
            // $content .= ("</th>");

            $content .= ("</tr>");
            $content .= ("</thead>");

            //endregion head

            //region tbody
            $content .= ("<tbody>");
            $rowCtr = 0;
            foreach ($arrayHistory as $ii => $row) {

                $rslt_style = "";
                if (isset($history_canceled[$ii]) && (sizeof($history_canceled[$ii]) > 0)) {
                    //                    arrPrintWebs($history_canceled[$ii]);
                    foreach ($history_canceled[$ii] as $hist_cancel) {
                        if ($rslt_style == "") {
                            $rslt_style = $hist_cancel;
                        }
                        else {
                            $rslt_style = $rslt_style . $hist_cancel;
                        }
                    }
                }
                //cekHere($rslt_style);
                $rowCtr++;
                $content .= ("<tr id='tr$rowCtr' style='$rslt_style'>");
                foreach ($arrayHistoryLabels as $key => $label) {
                    $content .= ("<td>");
                    $content .= ($row[$key]);
                    $content .= ("</td>");
                }
                $content .= ("</tr>");
            }
            $content .= ("</tbody>");
            //endregion tbody

            //region tfoot
//            $content .= ("<tfoot>");
//            $content .= "<tr class='tfooter bg-grey-1'>";
//            foreach ($arrayHistoryLabels as $key => $label) {
//                $content .= ("<th>");
//                if (isset($arrayHistorySumField) && isset($arrayHistorySumField[$key])) {
//                    $content .= formatField($key, $arrayHistorySumField[$key]);
//                }
//                else {
//                    $content .= "--";
//                }
//                $content .= ("</th>");
//            }
//            $content .= "</tr>";
//            $content .= ("</tfoot>");
            //endregion tfoot

            $content .= ("</table class='table table-bordered'>");
            $content .= ("</div class='table-responsive'>");
            $content .= ("</form>");
        }
        else {
//            $content .= ("no history found.<br>");
//            $content .= ("to go back to index, you can click BACK button<br>");
            $msg = "no history found.<br>to go back to index, you can click BACK button<br>";
            $content .= tplNoData($msg);
        }
        $content .= ("</div>");
        $content .= ("</div>");

        $content .= "<script>
                    $(document).ready( function(){
                        var tablesss = $('#history_penjualan').dataTable({
                                            dom: 'lBfrtip',
                                            lengthMenu: [ [15, 20, 50, 100, -1], [15, 20, 50, 100, 'All'] ],
                                            pageLength: 15,
                                            order: [[0, 'desc']],
                                            buttons: [
                                                'copy', 'csv', 'excel', 'pdf', 'print'
                                            ],
                                        });
                    });
                    </script>";

        echo $content;

        break;

    case "viewStatus":
        $contens = "";
        $custom_button = "";
        $cf_button = $this->config->item('button');
        $segment_total = $this->uri->total_segments();
        $segment_page = $segment_total;
        $arrayHistoryCanceleds = isset($arrayHistoryCanceled) ? $arrayHistoryCanceled : array();

        $stepLabels = array();

        $content = "";
        if (isset($stepLabels) && sizeof($stepLabels) > 0) {
            $content .= ("<ul class='nav nav-tabs'>");

            foreach ($stepLabels as $step => $label) {
                $color = $steps[$step]['target'] == $currentState ? "#454549" : "#999999";
                $borderColor = $steps[$step]['target'] == $currentState ? "#cccccc" : "#ffffff";
                $bgColor = $steps[$step]['target'] == $currentState ? "#ffffff" : "#f0f0f0";
                $content .= ("<li class='nav-item'>");
                $content .= "<a class='nav-link btn' style='background:$bgColor;color:$color;border-width:1px 1px 0px 1px; border-color:$borderColor; border-style: solid;' onclick =\"location.href='" . $stepLinks[$step] . "?date1=" . $filters['date1'] . "&date2=" . $filters['date2'] . "';\">";
                if ($steps[$step]['target'] == $currentState) {
                    $content .= "<span class='fa fa-adjust'></span> ";
                }
                $content .= "$label</a>";
                $content .= ("</li>");
            }
            $content .= ("</ul class='pager'>");
        }


        $content .= ("<div class=\"box-body\">");
        if (sizeof($arrayHistory) > 0) {
            $content .= ("<form name='fSelect'>");
            $content .= ("<div class='table-responsive'>");
            $content .= "<table class='table hover datatables table-condensed table-bordered no-padding'>";
            $content .= ("<thead>");
            $content .= ("<tr bgcolor='#f0f0f0'>");
//            $content .= ("<th class='text-muted'>");
//            $content .= "no.";
//            $content .= ("</th>");
            foreach ($arrayHistoryLabels as $key => $label) {
                $content .= ("<th class='text-muted'>");
                $content .= ($label);
                $content .= ("</th>");
            }
            $content .= ("</tr>");
            $content .= ("</thead>");

            $content .= ("<tbody>");
            $rowCtr = 0;
            foreach ($arrayHistory as $trID => $row) {
                $canceled = "";
                if (in_array($trID, $arrayHistoryCanceleds)) {
                    $canceled = "background-color:#E6E6FA;";
                }

                $rowCtr++;
                $content .= ("<tr id='tr$rowCtr' style='$canceled'>");

//                $content .= ("<td>");
//                $content .= ($rowCtr);
//                $content .= ("</td>");
                foreach ($arrayHistoryLabels as $key => $label) {
                    $content .= ("<td data-order='" . preg_replace('/[^A-Za-z0-9\-]/', '', $row[$key]) . "'>");
                    $content .= ($row[$key]);
                    $content .= ("</td>");
                }
                $content .= ("</tr>");

            }
            $content .= ("</tbody>");

            $content .= ("</table class='table table-bordered'>");
            $content .= ("</div class='table-responsive'>");
            $content .= ("</form>");

        }
        else {
            $content .= ("no history found.<br>");
            $content .= ("to go back to index, you can click BACK button<br>");
        }
        $content .= ("</div>");


        $content .= "\n<script>
                    $(document).ready( function(){

                        var table = $('table.datatables').dataTable({
                            dom: 'lBfrtip',
                            fixedHeader: true,
                            lengthMenu: [ [10, 20, 50, 100, -1], [10, 20, 50, 100, 'All'] ],
                            pageLength: -1,
                            buttons: [
                                        { extend: 'print', footer: true },
                                          $custom_button
                                    ],
//                            buttons: [
//                                        'copy', 'csv', 'excel', 'pdf', 'print'
//                                    ],
//                            buttons: [
//                                        {
//                                            extend: 'colvisGroup',
//                                            text: 'Office info',
//                                            show: [ 1, 2 ],
//                                            hide: [ 3, 4, 5 ]
//                                        },
//                                        {
//                                            extend: 'colvisGroup',
//                                            text: 'HR info',
//                                            show: [ 3, 4, 5 ],
//                                            hide: [ 1, 2 ]
//                                        },
//                                        {
//                                            extend: 'colvisGroup',
//                                            text: 'Show all',
//                                            show: ':hidden'
//                                        }
//                                    ]
                            footerCallback: function ( row, data, start, end, display ) {
                                        var api = this.api(), data;

                                        // Remove the formatting to get integer data for summation
                                        var intVal = function ( i ) {
                                            return typeof i === 'string' ?
                                                i.replace(/[$,]/g, '')*1 :
                                                typeof i === 'number' ?
                                                    i : 0;
                                        };

                                        var arrayFooter = $('tfoot>tr>th');
                                        var dpageTotal = [];
                                        jQuery.each(arrayFooter, function(i,d){
                                            var id_n_index = parseFloat(i);
                                            dpageTotal[id_n_index] = 0;
                                            jQuery.each( $(api.column(id_n_index, { page: 'current'}).data() ), function(ii, obj){
                                                dpageTotal[id_n_index] += intVal( $(obj).html() );
//                                                console.log( $('span', obj).html() );
//                                                console.log( obj );
//                                                console.error( $(obj).html() );
                                            });
//                                            console.log('dpageTotal[id_n_index]: ' + ' ' + id_n_index + ' '  +  dpageTotal[id_n_index] );


                                        if( !isNaN(dpageTotal[id_n_index]) && dpageTotal[id_n_index] > 0 ){
                                            $( api.column(id_n_index).footer() ).html(
                                                \"<div class='text-right text-primary text-bold'>\"+addCommas(dpageTotal[id_n_index])+\"</div>\"
                                            );
                                        }


                                        });

// Total over all pages
//                                        var total2=0;
//                                        jQuery.each( $(api.column(2).data()), function(i, obj){
//                                            total2 += intVal( $('span', obj).html() );
//                                        });
//
//                                        var total3=0;
//                                        jQuery.each( $(api.column(3).data()), function(i, obj){
//                                            total3 += intVal( $('span', obj).html() );
//                                        });
//
//                                        var total4=0;
//                                        jQuery.each( $(api.column(4).data()), function(i, obj){
//                                            total4 += intVal( $('span', obj).html() );
//                                        });
//
//                                        var total5=0;
//                                        jQuery.each( $(api.column(5).data()), function(i, obj){
//                                            total5 += intVal( $('span', obj).html() );
//                                        });


                                        // Total over this page
//                                        pageTotal2 = api
//                                            .column( 2, { page: 'current'} )
//                                            .data()
//                                            .reduce( function (a, b) {
//                                                return intVal(a) + intVal(b);
//                                            }, 0 );

//                                        var pageTotal2=0;
//                                        jQuery.each( $(api.column(2, { page: 'current'}).data()), function(i, obj){
//                                            pageTotal2 += intVal( $('span', obj).html() );
//                                        });
//
//                                        var pageTotal3=0;
//                                        jQuery.each( $(api.column(3, { page: 'current'}).data()), function(i, obj){
//                                            pageTotal3 += intVal( $('span', obj).html() );
//                                        });
//
//                                        var pageTotal4=0;
//                                        jQuery.each( $(api.column(4, { page: 'current'}).data()), function(i, obj){
//                                            pageTotal4 += intVal( $('span', obj).html() );
//                                        });
//
//                                        var pageTotal5=0;
//                                        jQuery.each( $(api.column(5, { page: 'current'}).data()), function(i, obj){
//                                            pageTotal5 += intVal( $('span', obj).html() );
//                                        });

                                        // Update footer
//                                        $( api.column( 2 ).footer() ).html(
//                                            \"<div class='text-right text-primary text-bold'>\"+addCommas(pageTotal2)+\"</div>\"
//                                            + \"<div class='text-right'>\"+addCommas(total2)+\"</div>\"
//                                        );

//                                        $( api.column( 3 ).footer() ).html(
//                                            \"<div class='text-right text-success text-bold'>\"+addCommas(pageTotal3)+\"</div>\"
//                                            + \"<div class='text-right'>\"+addCommas(total3)+\"</div>\"
//                                        );

//                                        $( api.column( 4 ).footer() ).html(
//                                            \"<div class='text-right text-success text-bold'>\"+addCommas(pageTotal4)+\"</div>\"
//                                            + \"<div class='text-right'>\"+addCommas(total4)+\"</div>\"
//                                        );

//                                        $( api.column( 5 ).footer() ).html(
//                                            \"<div class='text-right text-danger text-bold'>\"+addCommas(pageTotal5)+\"</div>\"
//                                            + \"<div class='text-right'>\"+addCommas(total5)+\"</div>\"
//                                        );

                                    }
                                });

                            });

                            $('.table-responsive').floatingScroll();
                    </script>";


        if (is_array($addLink)) {
            $addLinkStr = "<a href='" . $addLink['link'] . "' class='btn btn-success'>" . $addLink['label'] . "</a>";
        }
        else {
            $addLinkStr = "";
        }

        $p = New Layout("$title", "$subTitle", "application/template/history.html");
        $p->addTags(array(
            "jenisTr" => $jenisTr,
            "trName" => $trName,
            "navigasi" => $btnNavigasi,
            "menu_left" => callMenuLeft(),
            //                                "trans_menu" => callTransMenu(),
            "float_menu_atas" => callFloatMenu('atas'),
            "float_menu_bawah" => callFloatMenu(),
            "menu_taskbar" => callMenuTaskbar(),
            "btn_back" => callBackNav(),
            "content" => $content,
            "profile_name" => $this->session->login['nama'],
            "add_link" => $addLinkStr,
            "date1" => $filters['date1'],
            "date2" => $filters['date2'],
            "date_min" => $filters['dates']['start'],
            "date_max" => $filters['dates']['end'],
            "url" => $thisPage,
            "newTrTarget" => isset($addLink['link']) ? $addLink['link'] : "JavaScript:void(0)",
            "newTrDisp" => isset($addLink['link']) ? "inline-table" : "none",
        ));

        $p->render();
        break;

    case "viewHistoryOld":
        $contens = "";
        $custom_button = "";
        if (isset($customButton)) {
            if (sizeof($customButton) > 0) {
                // arrPrint($customButton);
                foreach ($customButton as $ky => $preg) {
                    foreach ($preg as $k => $mbuh) {
                        $$k = $preg[$k];
                    }
                    $custom_button .= "{text:'$label',action:function(e,dt,node,config){window.open('" . base_url() . $target . $customButtonTarget . "','download');}},";
                    // $custom_button .= "{text:'$label',action:function(e,dt,node,config){window.open('".base_url().$target.$uri_4."?date1=$date1&date2=$date2','download');}},";
                }
            }
        }
        $cf_button = $this->config->item('button');
        $segment_uri_array = $this->uri->segment_array();
        $segment_total = $this->uri->total_segments();
        $segment_page = $segment_total;

        $content = "";
        if (isset($stepLabels) && sizeof($stepLabels) > 0) {
            $content .= ("<ul class='nav nav-tabs'>");

            foreach ($stepLabels as $step => $label) {
                //                $btnClass = $steps[$step]['target'] == $currentState ? "btn-success" : "btn-default";
                $color = $steps[$step]['target'] == $currentState ? "#454549" : "#999999";
                $borderColor = $steps[$step]['target'] == $currentState ? "#cccccc" : "#ffffff";
                $bgColor = $steps[$step]['target'] == $currentState ? "#ffffff" : "#f0f0f0";
                $content .= ("<li class='nav-item'>");
                $content .= "<a class='nav-link btn' style='background:$bgColor;color:$color;border-width:1px 1px 0px 1px; border-color:$borderColor; border-style: solid;' onclick =\"location.href='" . $stepLinks[$step] . "?date1=" . $filters['date1'] . "&date2=" . $filters['date2'] . "';\">";
                if ($steps[$step]['target'] == $currentState) {
                    $content .= "<span class='fa fa-adjust'></span> ";
                }
                $content .= "$label</a>";
                $content .= ("</li>");
            }
            $content .= ("</ul class='pager'>");
        }


        $content .= ("<div class=\"box-body\">");
        if (sizeof($arrayHistory) > 0) {
            $content .= ("<form name='fSelect'>");
            $content .= ("<div class='table-responsive'>");
            $content .= "<table class='table table-condensed table-bordered no-padding table-hover datatables'>";

            $content .= ("<thead>");
            $content .= ("<tr bgcolor='#f0f0f0'>");
            $content .= "<th class='text-muted text-center'>No</th>";
            foreach ($arrayHistoryLabels as $key => $label) {
                $content .= ("<th class='text-muted text-center'>");
                $content .= ($label);
                $content .= ("</th>");
            }
            $content .= ("</tr>");
            $content .= ("</thead>");


            $rowCtr = 0;
            foreach ($arrayHistory as $row) {
                $rowCtr++;

                $content .= ("<tr id='tr$rowCtr'>");
                $content .= ("<td class='text-right'>");
                $content .= $rowCtr;
                $content .= ("</td>");
                foreach ($arrayHistoryLabels as $key => $label) {
                    $content .= ("<td>");
                    $content .= ($row[$key]);
                    $content .= ("</td>");
                }
                $content .= ("</tr>");


            }


            $content .= ("</table class='table table-bordered'>");
            $content .= ("</div class='table-responsive'>");
            $content .= ("</form>");

        }
        else {
            $content .= ("no history found.<br>");
            $content .= ("to go back to index, you can click BACK button<br>");
        }
        $content .= ("</div>");

        $content .= "<script>
                    $(document).ready( function(){

                        var table = $('table.datatables').dataTable({
                            dom: 'lBfrtip',
                            fixedHeader: true,
                            lengthMenu: [ [10, 20, 50, 100, -1], [10, 20, 50, 100, 'All'] ],
                            pageLength: -1,
                            buttons: [
                                        { extend: 'print', footer: true },
                                          $custom_button
                                    ],
//                            buttons: [
//                                        'copy', 'csv', 'excel', 'pdf', 'print'
//                                    ],
//                            buttons: [
//                                        {
//                                            extend: 'colvisGroup',
//                                            text: 'Office info',
//                                            show: [ 1, 2 ],
//                                            hide: [ 3, 4, 5 ]
//                                        },
//                                        {
//                                            extend: 'colvisGroup',
//                                            text: 'HR info',
//                                            show: [ 3, 4, 5 ],
//                                            hide: [ 1, 2 ]
//                                        },
//                                        {
//                                            extend: 'colvisGroup',
//                                            text: 'Show all',
//                                            show: ':hidden'
//                                        }
//                                    ]
                            footerCallback: function ( row, data, start, end, display ) {
                                        var api = this.api(), data;

                                        // Remove the formatting to get integer data for summation
                                        var intVal = function ( i ) {
                                            return typeof i === 'string' ?
                                                i.replace(/[$,]/g, '')*1 :
                                                typeof i === 'number' ?
                                                    i : 0;
                                        };

                                        var arrayFooter = $('tfoot>tr>th');
                                        var dpageTotal = [];
                                        jQuery.each(arrayFooter, function(i,d){
                                            var id_n_index = parseFloat(i);
                                            dpageTotal[id_n_index] = 0;
                                            jQuery.each( $(api.column(id_n_index, { page: 'current'}).data() ), function(ii, obj){
                                                dpageTotal[id_n_index] += intVal( $(obj).html() );
//                                                console.log( $('span', obj).html() );
//                                                console.log( obj );
//                                                console.error( $(obj).html() );
                                            });
                                            console.log('dpageTotal[id_n_index]: ' + ' ' + id_n_index + ' '  +  dpageTotal[id_n_index] );


                                        if( !isNaN(dpageTotal[id_n_index]) && dpageTotal[id_n_index] > 0 ){
                                            $( api.column(id_n_index).footer() ).html(
                                                \"<div class='text-right text-primary text-bold'>\"+addCommas(dpageTotal[id_n_index])+\"</div>\"
                                            );
                                        }


                                        });

// Total over all pages
//                                        var total2=0;
//                                        jQuery.each( $(api.column(2).data()), function(i, obj){
//                                            total2 += intVal( $('span', obj).html() );
//                                        });
//
//                                        var total3=0;
//                                        jQuery.each( $(api.column(3).data()), function(i, obj){
//                                            total3 += intVal( $('span', obj).html() );
//                                        });
//
//                                        var total4=0;
//                                        jQuery.each( $(api.column(4).data()), function(i, obj){
//                                            total4 += intVal( $('span', obj).html() );
//                                        });
//
//                                        var total5=0;
//                                        jQuery.each( $(api.column(5).data()), function(i, obj){
//                                            total5 += intVal( $('span', obj).html() );
//                                        });


                                        // Total over this page
//                                        pageTotal2 = api
//                                            .column( 2, { page: 'current'} )
//                                            .data()
//                                            .reduce( function (a, b) {
//                                                return intVal(a) + intVal(b);
//                                            }, 0 );

//                                        var pageTotal2=0;
//                                        jQuery.each( $(api.column(2, { page: 'current'}).data()), function(i, obj){
//                                            pageTotal2 += intVal( $('span', obj).html() );
//                                        });
//
//                                        var pageTotal3=0;
//                                        jQuery.each( $(api.column(3, { page: 'current'}).data()), function(i, obj){
//                                            pageTotal3 += intVal( $('span', obj).html() );
//                                        });
//
//                                        var pageTotal4=0;
//                                        jQuery.each( $(api.column(4, { page: 'current'}).data()), function(i, obj){
//                                            pageTotal4 += intVal( $('span', obj).html() );
//                                        });
//
//                                        var pageTotal5=0;
//                                        jQuery.each( $(api.column(5, { page: 'current'}).data()), function(i, obj){
//                                            pageTotal5 += intVal( $('span', obj).html() );
//                                        });

                                        // Update footer
//                                        $( api.column( 2 ).footer() ).html(
//                                            \"<div class='text-right text-primary text-bold'>\"+addCommas(pageTotal2)+\"</div>\"
//                                            + \"<div class='text-right'>\"+addCommas(total2)+\"</div>\"
//                                        );

//                                        $( api.column( 3 ).footer() ).html(
//                                            \"<div class='text-right text-success text-bold'>\"+addCommas(pageTotal3)+\"</div>\"
//                                            + \"<div class='text-right'>\"+addCommas(total3)+\"</div>\"
//                                        );

//                                        $( api.column( 4 ).footer() ).html(
//                                            \"<div class='text-right text-success text-bold'>\"+addCommas(pageTotal4)+\"</div>\"
//                                            + \"<div class='text-right'>\"+addCommas(total4)+\"</div>\"
//                                        );

//                                        $( api.column( 5 ).footer() ).html(
//                                            \"<div class='text-right text-danger text-bold'>\"+addCommas(pageTotal5)+\"</div>\"
//                                            + \"<div class='text-right'>\"+addCommas(total5)+\"</div>\"
//                                        );

                                    }
                                });

                            });

                            $('.table-responsive').floatingScroll();
                    </script>";

        if (is_array($addLink)) {
            $addLinkStr = "<a href='" . $addLink['link'] . "' class='btn btn-success'>" . $addLink['label'] . "</a>";
        }
        else {
            $addLinkStr = "";
        }

        $p = New Layout("$title", "$subTitle", "application/template/history.html");
        $p->addTags(array(
            "jenisTr" => $jenisTr,
            "trName" => $trName,
            "navigasi" => $btnNavigasi,
            "menu_left" => callMenuLeft(),
            //                                "trans_menu" => callTransMenu(),
            "float_menu_atas" => callFloatMenu('atas'),
            "float_menu_bawah" => callFloatMenu(),
            "menu_taskbar" => callMenuTaskbar(),
            "btn_back" => callBackNav(),
            "content" => $content,
            "profile_name" => $this->session->login['nama'],
            "add_link" => $addLinkStr,
            "date1" => $filters['date1'],
            "date2" => $filters['date2'],
            "date_min" => $filters['dates']['start'],
            "date_max" => $filters['dates']['end'],
            "url" => $thisPage,
            "newTrTarget" => isset($addLink['link']) ? $addLink['link'] : "JavaScript:void(0)",
            "newTrDisp" => isset($addLink['link']) ? "inline-table" : "none",
        ));

        $p->render();
        break;
    case "viewMyActs":
        //$myId = my_id();
        //$myCabangId = my_cabang_id();
        $contens = "";
        //        $contens .= "<script type=\"text/javascript\">
        //        var table;
        //                        $(document).ready(function() {
        //                        table = $('#table').DataTable({
        ////                        'processing': true,
        ////                        'serverSide': true,
        //                        'pageLength': 50,
        //                   });
        //
        //                        });
        //                        </script>";
        $cf_button = $this->config->item('button');
        $segment_uri_array = $this->uri->segment_array();
        $segment_total = $this->uri->total_segments();
        $segment_page = $segment_total;


        $content = "";
        if (isset($stepLabels) && sizeof($stepLabels) > 0) {
            $content .= ("<ul class='nav nav-tabs'>");

            foreach ($stepLabels as $step => $label) {
                //                $btnClass = $steps[$step]['target'] == $currentState ? "btn-success" : "btn-default";
                $color = $steps[$step]['target'] == $currentState ? "#454549" : "#999999";
                $borderColor = $steps[$step]['target'] == $currentState ? "#cccccc" : "#ffffff";
                $bgColor = $steps[$step]['target'] == $currentState ? "#ffffff" : "#f0f0f0";
                $content .= ("<li class='nav-item'>");
                $content .= "<a class='nav-link btn' style='background:$bgColor;color:$color;border-width:1px 1px 0px 1px; border-color:$borderColor; border-style: solid;' onclick =\"location.href='" . $stepLinks[$step] . "?date1=" . $filters['date1'] . "&date2=" . $filters['date2'] . "';\">";
                if ($steps[$step]['target'] == $currentState) {
                    $content .= "<span class='fa fa-adjust'></span> ";
                }
                $content .= "$label</a>";
                $content .= ("</li>");
            }
            $content .= ("</ul class='pager'>");
        }


        $content .= ("<div class=\"box-body\">");
        if (sizeof($arrayHistory) > 0) {
            $content .= ("<form name='fSelect'>");
            $content .= ("<div class='table-responsive'>");
            $content .= "<h3 class='text-muted'>$trName details</h3>";
            $content .= "<table class='table table-condensed table-bordered no-padding'>";
            $content .= ("<tr bgcolor='#f0f0f0'>");
            foreach ($arrayHistoryLabels as $key => $label) {
                $content .= ("<th class='text-muted'>");
                $content .= ($label);
                $content .= ("</th>");
            }
            $content .= ("</tr>");


            $rowCtr = 0;
            foreach ($arrayHistory as $row) {
                $rowCtr++;
                $content .= ("<tr id='tr$rowCtr'>");
                foreach ($arrayHistoryLabels as $key => $label) {
                    $content .= ("<td>");
                    $content .= ($row[$key]);
                    $content .= ("</td>");
                }
                $content .= ("</tr>");

            }


            $content .= ("</table class='table table-bordered'>");
            $content .= ("</div class='table-responsive'>");
            $content .= ("</form>");

        }
        else {
            $msg = ("you did not make any <strong>$trName</strong> activity at selected date(s).<br>");
            $msg .= ("you may try to select other date(s) or you can click <strong>BACK</strong> button to go to previous page<br>");
            $content .= tplNoData($msg);
        }
        $content .= ("</div>");

        //        if (sizeof($availFilters) > 0 && sizeof($arrayHistory) > 0) {
        //            $content .= ("<div class=\"box-body\">");
        //            $content .= "<h3 class='text-muted'>resume</h3>";
        //            $content .= ("<div class=\"row\">");
        //
        //            foreach ($availFilters as $fName => $fLabel) {
        //                if (isset($names[$fName]) && sizeof($names[$fName]) > 0) {
        //                    $content .= ("<div class=\"col-md-4\">");
        //                    $content .= "<h4>$fLabel</h4>";
        //
        //
        //                    $content .= "<table class='table table-condensed table-bordered no-padding'>";
        //                    $content .= "<tr bgcolor='#f0f0f0'>";
        //
        //                    $content .= "<td>$fLabel</td>";
        //                    $content .= "<td class='text-right'>(unit)</td>";
        //                    $content .= "<td class='text-right'>IDR</td>";
        //
        //                    $content .= "</tr>";
        //                    foreach ($names[$fName] as $oID => $oName) {
        //
        //                        $content .= "<tr>";
        //
        //                        $content .= "<td>$oName</td>";
        //                        $content .= "<td class='text-right'>" . number_format($recaps[$fName][$oID]['qty']) . "</td>";
        //                        $content .= "<td class='text-right'>" . number_format($recaps[$fName][$oID]['value']) . "</td>";
        //
        //                        $content .= "</tr>";
        //                    }
        //                    $content .= "</table>";
        //                    $content .= ("</div class=\"col-md-4\">");
        //                }
        //            }
        //            $content .= ("</div class=\"row\">");
        //            $content .= ("</div class=\"box-body\">");
        //        }

        if (is_array($addLink)) {
            $addLinkStr = "<a href='" . $addLink['link'] . "' class='btn btn-success'>" . $addLink['label'] . "</a>";
        }
        else {
            $addLinkStr = "";
        }

        $p = New Layout("$title", "$subTitle", MODUL_TEMPLATE_PATH . "template/history.html");
        $p->addTags(array(
            "jenisTr" => $jenisTr,
            "trName" => $trName,
            "navigasi" => $btnNavigasi,
            "menu_left" => callMenuLeft(),
            //                                "trans_menu" => callTransMenu(),
            "float_menu_atas" => callFloatMenu('atas'),
            "float_menu_bawah" => callFloatMenu(),
            "menu_taskbar" => callMenuTaskbar(),
            "btn_back" => callBackNav(),
            "content" => $content,
            "profile_name" => $this->session->login['nama'],
            "add_link" => $addLinkStr,
            "date1" => $filters['date1'],
            "date2" => $filters['date2'],
            "date_min" => isset($filters['dates']['start']) ? $filters['dates']['start'] : "",
            "date_max" => isset($filters['dates']['end']) ? $filters['dates']['end'] : "",
            "url" => $thisPage,
            "newTrTarget" => isset($addLink['link']) ? $addLink['link'] : "JavaScript:void(0)",
            "newTrDisp" => isset($addLink['link']) ? "inline-table" : "none",
        ));

        $p->render();
        break;

    case "viewIncomplete":

//arrPrint($stepLinks);
//arrPrint($stepLabels);
        $content = "";
        if (isset($stepLabels) && sizeof($stepLabels) > 0) {
            $content .= ("<ul class='nav nav-tabs'>");
            foreach ($stepLabels as $step => $label) {
                //                $btnClass = $step == $currentState ? "btn-success" : "btn-default";
//                $color = $step == $currentState ? "#454549" : "#999999";
//                $borderColor = $step == $currentState ? "#cccccc" : "#ffffff";
//                $bgColor = $step == $currentState ? "#ffffff" : "#f0f0f0";
//cekHitam(":: $step == $checkState ::");
                $color = ((string)$step == (string)$checkState) ? "#454549" : "#999999";
                $borderColor = ((string)$step == (string)$checkState) ? "#cccccc" : "#ffffff";
                $bgColor = ((string)$step == (string)$checkState) ? "#ffffff" : "#f0f0f0";

                $content .= ("<li class='nav-item'>");
                $content .= "<a class='btn ' style='background:$bgColor;color:$color;border-width:1px 1px 0px 1px; border-color:$borderColor; border-style: solid;' 
                    onclick =\"location.href='" . $stepLinks[$step] . "';\">";
                $content .= "$label</a>";
                $content .= ("</li>");
            }
            $content .= ("</ul class='pager'>");
        }


        $content .= ("<div class=\"box-body\">");
        if (sizeof($arrayOnProgress) > 0) {
            $content .= ("<form name='fSelect'>");
            $content .= ("<div class='table-responsive'>");
            $content .= "<table class='table table-condensed table-bordered no-padding'>";
            $content .= ("<tr bgcolor='#f0f0f0'>");
            foreach ($arrayProgressLabels as $key => $label) {
                $content .= ("<th class='text-muted'>");
                $content .= ($label);
                $content .= ("</th>");
            }
            $content .= ("</tr>");


            $rowCtr = 0;
            foreach ($arrayOnProgress as $row) {
                $rowCtr++;
                $content .= ("<tr id='tr$rowCtr'>");
                foreach ($arrayProgressLabels as $key => $label) {
                    $content .= ("<td>");
                    $content .= ($row[$key]);
                    $content .= ("</td>");
                }
                $content .= ("</tr>");

            }
            if ($allowJoin) {
                //                echo "allow join";
                $content .= ("<tr id='tr$rowCtr'>");

                $content .= ("<td colspan='" . sizeof($arrayProgressLabels) . "'>");
                $content .= ("<a class='btn btn-warning btn-block' href='#' onclick=\"

var items = document.forms['fSelect'].elements['oID[]'];
console.log('items-length='+items.length);

var strIDs='';
for (var i=0; i<=items.length; i++) {
    console.log('iterasi checkbox ke '+i);
    if(items[i].checked){
        console.log(items[i].value);
        strIDs+=items[i].value+'-';
    }
}
console.log('strIDs='+strIDs);
if(strIDs.length>0){top.document.getElementById('result').src='$followupBase'+strIDs+'/$_nextStepNum/$_currentStepNum';}else{alert('please select at least one entry')}


\">$actionLabel from selected items</a>");
                $content .= ("</td>");
                $content .= ("</tr>");
            }

            $content .= ("</table class='table table-bordered'>");
            $content .= ("</div class='table-responsive'>");
            $content .= ("</form>");

        }
        else {
            $msg = ("no item to followup.<br>");
            $msg .= ("you can try to select another status tab<br>");
            $content .= tplNoData($msg);
        }
        $content .= ("</div>");
//arrPrint($addLink);
        if (is_array($addLink)) {
            $addLinkStr = "<a href='" . $addLink['link'] . "' class='btn btn-success'>" . $addLink['label'] . "</a>";
        }
        else {
            $addLinkStr = "";
        }


        $p = New Layout("$title", "$subTitle", "application/template/history.html");
        $p->addTags(array(
            "jenisTr" => $jenisTr,
            "trName" => $trName,
            "navigasi" => $btnNavigasi,
            "menu_left" => callMenuLeft(),
            //                                "trans_menu" => callTransMenu(),
            "float_menu_atas" => callFloatMenu('atas'),
            "float_menu_bawah" => callFloatMenu(),
            "menu_taskbar" => callMenuTaskbar(),
            "btn_back" => callBackNav(),
            "content" => $content,
            "profile_name" => $this->session->login['nama'],
            "add_link" => $addLinkStr,
            "date1" => $filters['date1'],
            "date2" => $filters['date2'],
            "date_min" => $filters['dates']['start'],
            "date_max" => $filters['dates']['end'],
            "url" => $thisPage,
            "newTrTarget" => isset($addLink['link']) ? $addLink['link'] : "JavaScript:void(0)",
            "newTrDisp" => isset($addLink['link']) ? "inline-table" : "none",
        ));

        $p->render();
        break;

    case "viewMySettlementOLD":


        $cf_button = $this->config->item('button');
        $segment_uri_array = $this->uri->segment_array();
        $segment_total = $this->uri->total_segments();
        $segment_page = $segment_total;
        $c_myItems = (isset($myItems) && sizeof($myItems) > 0) ? sizeof($myItems) : 0;

        $content = "";
        if (isset($stepLabels) && sizeof($stepLabels) > 0) {
            $content .= ("<ul class='nav nav-tabs'>");

            foreach ($stepLabels as $step => $label) {
                //                $btnClass = $steps[$step]['target'] == $currentState ? "btn-success" : "btn-default";
                $color = $steps[$step]['target'] == $currentState ? "#454549" : "#999999";
                $borderColor = $steps[$step]['target'] == $currentState ? "#cccccc" : "#ffffff";
                $bgColor = $steps[$step]['target'] == $currentState ? "#ffffff" : "#f0f0f0";
                $content .= ("<li class='nav-item'>");
                $content .= "<a class='nav-link btn' style='background:$bgColor;color:$color;border-width:1px 1px 0px 1px; border-color:$borderColor; border-style: solid;' onclick =\"location.href='" . $stepLinks[$step] . "?date1=" . $filters['date1'] . "&date2=" . $filters['date2'] . "';\">";
                if ($steps[$step]['target'] == $currentState) {
                    $content .= "<span class='fa fa-adjust'></span> ";
                }
                $content .= "$label</a>";
                $content .= ("</li>");
            }
            $content .= ("</ul class='pager'>");
        }


        $content .= ("<div class='panel-body'>");

        $content .= "<h3 class='text-muted text-center' style='border:2px #cccccc dashed;'>resume of activities</h3><br>";


        $content .= ("<div class='row'>");
        if (isset($trans_mine) && sizeof($trans_mine) > 0) {
//            $content .= ("<div class='panel panel-default'>");

            $content .= ("<div class='col-md-6'>");
            $content .= "<h3 class='text-blue'>resume of my activities</h3>";

            $content .= "<table class='table table-condensed table-bordered'>";
            $content .= ("<tr bgcolor='#f0f0f0'>");
            $content .= "<td class='text-muted' align='right'>no.</td>";
            foreach ($transLabels as $key => $label) {
                $content .= "<td class='text-muted'>";
                $content .= $label;
                $content .= "</td>";
            }
            $content .= ("</tr>");
            $tCtr = 0;
            foreach ($trans_mine as $tSpec) {
                $tCtr++;
                $content .= "<tr>";
                $content .= "<td class='text-muted' align='right'>$tCtr.</td>";
                foreach ($transLabels as $key => $label) {
                    $content .= "<td>";
                    $content .= formatField($key, $tSpec[$key]);
                    $content .= "</td>";
                }
                $content .= "</tr>";
            }
            $content .= "</table class='table table-condensed'>";
            $content .= ("</div class='col-md-8'>");
//            $content .= ("</div class='panel panel-default'>");


            //
            if (sizeof($trans_followers) > 0) {

                $content .= ("<div class='col-md-6'>");
                $content .= "<h3 class='text-blue'>resume of related activities</h3>";

                $content .= "<table class='table table-condensed table-bordered'>";
                $content .= ("<tr bgcolor='#f0f0f0'>");
                $content .= "<td class='text-muted' align='right'>no.</td>";
                foreach ($transLabels as $key => $label) {
                    $content .= "<td class='text-muted'>";
                    $content .= $label;
                    $content .= "</td>";
                }
                $content .= ("</tr>");
                $tCtr = 0;
                foreach ($trans_followers as $tSpec) {
                    $tCtr++;
                    $content .= "<tr>";
                    $content .= "<td class='text-muted' align='right'>$tCtr.</td>";
                    foreach ($transLabels as $key => $label) {
                        $content .= "<td>";
                        $content .= formatField($key, $tSpec[$key]);
                        $content .= "</td>";
                    }
                    $content .= "</tr>";
                }
                $content .= "</table class='table table-condensed'>";

                $content .= ("</div class='col-md-8'>");


            }


        }
        $content .= ("</div class='row'>");
        $content .= ("</div class='panel-body'>");


        $content .= ("<div class='panel-body'>");
        $content .= ("<div class='row'>");

        $content .= ("<div class='col-md-6'>");
        $content .= ("<h3 class='text-blue'><a title='click to show/hide entries' data-toggle='tooltip' data-placement='top'  href='JavaScript:void(0)' onclick=\"
        if(document.getElementById('actHistory').style.display=='none'){document.getElementById('actHistory').style.display='block'}else{document.getElementById('actHistory').style.display='none'}
\">my activities (" . $c_myItems . ")</a></h3>");
        if (isset($myItems) && sizeof($myItems) > 0) {
            $content .= ("<div id='actHistory' style='display:none;'>");
            $content .= ("<table class='table table-bordered table-condensed'>");
            $content .= ("<tr bgcolor='#f0f0f0'>");
            $content .= ("<td align='right' class='text-muted'>no.");
            $content .= ("</td>");
            foreach ($trHeaders as $key => $label) {
                $content .= ("<td class='text-muted'>$label");
                $content .= ("</td>");
            }
            $content .= ("</tr>");

            $no = 0;
            $totals = array();
            foreach ($myItems as $iSpec) {
                $no++;
                $content .= ("<tr>");
                $content .= ("<td align='right'>$no.");
                $content .= ("</td>");
                foreach ($trHeaders as $key => $label) {

                    $content .= ("<td>");
                    $content .= formatField($key, $iSpec[$key]);
                    $content .= ("</td>");
                    if (is_numeric($iSpec[$key])) {
                        if (!isset($totals[$key])) {
                            $totals[$key] = 0;
                        }
                        $totals[$key] += $iSpec[$key];
                    }
                }
                $content .= ("</tr>");
            }

            $content .= ("<tr bgcolor='#f5f5f5'>");
            $content .= ("<td align='right'>");
            $content .= ("</td>");
            foreach ($trHeaders as $key => $label) {
                $content .= ("<td>");
                if (isset($totals[$key])) {
                    $content .= formatField($key, $totals[$key]);
                }
                $content .= ("</td>");
            }
            $content .= ("</tr>");

            $content .= ("</table class='table table-condensed'>");
            $content .= ("</div>");
        }
        else {
            $content .= ("<div class='text-muted'>");
            $content .= ("- no transactional activities you have been made within selected date(s) -");
            $content .= ("</div class='text-muted'>");
        }
        $content .= ("</div class='col-md-8'>");


        if (isset($followerItems) && sizeof($followerItems) > 0) {

            $content .= ("<div class='col-md-6'>");
            $content .= ("<h3 class='text-blue'><a title='click to show/hide entries' data-toggle='tooltip' data-placement='top' href='JavaScript:void(0)' onclick=\"
        if(document.getElementById('folHistory').style.display=='none'){document.getElementById('folHistory').style.display='block'}else{document.getElementById('folHistory').style.display='none'}
\">related activities (" . sizeof($followerItems) . ")</a></h3>");

            $content .= ("<div id='folHistory' style='display:none;'>");
            $content .= ("<table class='table table-bordered table-condensed'>");
            $content .= ("<tr bgcolor='#f0f0f0'>");
            $content .= ("<td align='right' class='text-muted'>no.");
            $content .= ("</td>");
            foreach ($trHeaders_related as $key => $label) {
                $content .= ("<td class='text-muted'>$label");
                $content .= ("</td>");
            }
            $content .= ("</tr>");

            $no = 0;
            $totals = array();
            foreach ($followerItems as $iSpec) {
                $no++;
                $content .= ("<tr>");
                $content .= ("<td align='right'>$no.");
                $content .= ("</td>");
                foreach ($trHeaders_related as $key => $label) {

                    $content .= ("<td>");
                    $content .= formatField($key, $iSpec[$key]);
                    $content .= ("</td>");
                    if (is_numeric($iSpec[$key])) {
                        if (!isset($totals[$key])) {
                            $totals[$key] = 0;
                        }
                        $totals[$key] += $iSpec[$key];
                    }
                }
                $content .= ("</tr>");
            }


            $content .= ("</table class='table table-condensed'>");
            $content .= ("</div>");

            $content .= ("</div class='col-md-8'>");

        }


        $content .= ("</div class='row'>");
        $content .= ("</div class='panel-body'>");
//        $content .= ("</div class='panel panel-default'>");


//        $content .= ("<div class='panel panel-default'>");
        $content .= ("<div class='panel-body'>");
        $content .= "<h3 class='text-muted text-center' style='border:2px #cccccc dashed;'>asset movements</h3><br>";
        $aCtr = 0;

//        arrprint($recaps);die();
        if (sizeof($names) > 0) {


            foreach ($names as $nameID => $nameSpec) {
                $content .= ("<h3 class='text-info'>$nameID </h3>");
                $content .= ("<div class=\"row\">");

                $names[$nameID]['total'] = array();
                if (sizeof($nameSpec) > 1) {
                    $nameSpec['total'] = array();

                    foreach ($nameSpec as $jenis => $valSpec) {
//                        $nameSpec['total']=array_merge($nameSpec['total'],$nameSpec[$jenis]);
                        $nameSpec['total'] += $nameSpec[$jenis];
                        $names[$nameID]['total'] += $names[$nameID][$jenis];
                    }
                }
//                arrprint($nameSpec);
//                arrprint($names);
                foreach ($nameSpec as $jenis => $valSpec) {
                    $totals[$nameID] = array(
                        "qty_in" => 0,
                        "qty_out" => 0,
                        "value_in" => 0,
                        "value_out" => 0,
                    );

//                    switch($jenis){
//                        case "total":
//                            break;
//                        default:
//                            $cols=array(
//
//                            );
//                            break;
//                    }

                    if (isset($names[$nameID][$jenis]) && sizeof($names[$nameID][$jenis]) > 0) {
                        $aCtr++;
                        $jenisLabel = isset($trans[$jenis]['label']) ? $trans[$jenis]['label'] : $jenis;
                        $content .= ("<div class='col-md-4'>");
                        $content .= "<h4 class='text-muted'>" . $jenisLabel . "</h4>";

                        $content .= "<div class='table-responsive'>";
                        $content .= "<table class='table table-bordered table-condensed'>";
                        $content .= "<tr bgcolor='#f0f0f0'>";

                        $content .= "<td class='text-muted' align='right'>no.</td>";

//                        $content .= "<td class='text-muted'>item names</td>";
//                        $content .= "<td class='text-muted'>IN</td>";
//                        $content .= "<td class='text-muted'>OUT</td>";
//                        $content .= "<td class='text-muted'>IN (IDR)</td>";
//                        $content .= "<td class='text-muted'>OUT (IDR)</td>";
                        if (isset($columns[$nameID][$jenis]) && sizeof($columns[$nameID][$jenis]) > 0) {
                            foreach ($columns[$nameID][$jenis] as $key => $label) {
                                $content .= "<td class='text-muted'>$label</td>";
                            }
                        }

                        $content .= "</tr>";
                        $iCtr = 0;
//                    echo "$nameID<br>";
                        foreach ($names[$nameID][$jenis] as $iID => $iName) {
                            $iCtr++;
//                        echo "-- $iID/$iName<br>";
//                        echo "-- -- valueIn: ".$recaps[$nameID][$jenis][$iID]['value_in']."<br>";
//                        echo "-- -- valueOut: ".$recaps[$nameID][$jenis][$iID]['value_out']."<br>";
                            $qty_in = isset($recaps[$nameID][$jenis][$iID]['qty_in']) ? $recaps[$nameID][$jenis][$iID]['qty_in'] : 0;
                            $qty_out = isset($recaps[$nameID][$jenis][$iID]['qty_out']) ? $recaps[$nameID][$jenis][$iID]['qty_out'] : 0;
                            $val_in = isset($recaps[$nameID][$jenis][$iID]['value_in']) ? number_format($recaps[$nameID][$jenis][$iID]['value_in']) : 0;
                            $val_out = isset($recaps[$nameID][$jenis][$iID]['value_out']) ? number_format($recaps[$nameID][$jenis][$iID]['value_out']) : 0;


                            if ($jenis == "total") {
                                $qty = ($recaps[$nameID][$jenis][$iID]['qty_in'] - $recaps[$nameID][$jenis][$iID]['qty_out']);
                                $value = ($recaps[$nameID][$jenis][$iID]['value_in'] - $recaps[$nameID][$jenis][$iID]['value_out']);

                                if ($qty > 0) {
                                    $qty_in = abs($qty);
                                    $qty_out = 0;
                                }
                                if ($value > 0) {
                                    $val_in = abs($value);
                                    $val_out = 0;
                                }

                                $totals[$nameID]['qty_in'] += $recaps[$nameID][$jenis][$iID]['qty_in'];
                                $totals[$nameID]['qty_out'] += $recaps[$nameID][$jenis][$iID]['qty_out'];
                                $totals[$nameID]['value_in'] += $recaps[$nameID][$jenis][$iID]['value_in'];
                                $totals[$nameID]['value_out'] += $recaps[$nameID][$jenis][$iID]['value_out'];

                                $totals[$nameID]['value'] = abs(($totals[$nameID]['value_in']) - ($totals[$nameID]['value_out']));
                                $totals[$nameID]['qty'] = abs(($totals[$nameID]['qty_in']) - ($totals[$nameID]['qty_out']));

                            }
                            else {
                                $totals[$nameID]['qty_in'] += $qty_in;
                                $totals[$nameID]['qty_out'] += $qty_out;
                                $totals[$nameID]['value_in'] += $recaps[$nameID][$jenis][$iID]['value_in'];
                                $totals[$nameID]['value_out'] += $recaps[$nameID][$jenis][$iID]['value_out'];

//                                $totals[$nameID]['value'] = abs(abs($totals[$nameID]['value_in'])-abs($totals[$nameID]['value_out']));
//                                $totals[$nameID]['qty'] = abs(abs($totals[$nameID]['qty_in'])-abs($totals[$nameID]['qty_out']));
                            }

//                        echo "-- -- valueIn: ".$val_in."<br>";
//                        echo "-- -- valueOut: ".$val_out."<br>";

                            $content .= "<tr>";
                            $content .= "<td align='right'>$iCtr.</td>";
//                            $content .= "<td>$iName</td>";
//                            $content .= "<td align='right'>$qty_in</td>";
//                            $content .= "<td align='right'>$qty_out</td>";
//                            $content .= "<td align='right'>$val_in</td>";
//                            $content .= "<td align='right'>$val_out</td>";


                            if (isset($columns[$nameID][$jenis]) && sizeof($columns[$nameID][$jenis]) > 0) {
                                foreach ($columns[$nameID][$jenis] as $key => $label) {
                                    $content .= "<td class='text-muted'>" . formatField($key, $recaps[$nameID][$jenis][$iID][$key]) . "</td>";
                                }
                            }
                            $content .= "</tr>";
                        }


                        $qty_in = $totals[$nameID]['qty_in'];
                        $qty_out = $totals[$nameID]['qty_out'];
                        $val_in = number_format($totals[$nameID]['value_in']);
                        $val_out = number_format($totals[$nameID]['value_out']);
                        $content .= "<tr bgcolor='#f0f0f0'>";
                        $content .= "<td align='right'>&nbsp;</td>";
//                        $content .= "<td>total</td>";
//                        $content .= "<td align='right'>$qty_in</td>";
//                        $content .= "<td align='right'>$qty_out</td>";
//                        $content .= "<td align='right'>$val_in</td>";
//                        $content .= "<td align='right'>$val_out</td>";


                        if (isset($columns[$nameID][$jenis]) && sizeof($columns[$nameID][$jenis]) > 0) {
                            foreach ($columns[$nameID][$jenis] as $key => $label) {
                                $strTotal = isset($totals[$nameID][$key]) ? $totals[$nameID][$key] : "";
                                $content .= "<td class='text-muted'>" . formatField($key, $strTotal) . "</td>";
                            }
                        }

                        $content .= "</tr>";

                        $content .= "</table class='table table-bordered table-condensed'>";
                        $content .= "</div class='table-responsive'>";

                        $content .= ("</div class=col-md-3>");

                    }
                    else {
                        $content .= ("<div class=\"box-body\">");
                        $content .= ("<div class='text-muted'>");
                        $content .= ("you haven't made any activities causing asset movements within selected date(s).<br>");
                        $content .= ("try to select other date(s) or you can click BACK button to go to previous page<br>");
                        $content .= ("</div class='text-muted'>");
                        $content .= ("</div>");
                    }
                }


                $content .= ("</div class=\"row\">");
            }


        }
        else {
            $content .= ("<div class=\"box-body\">");
            $content .= ("<div class='text-muted'>");
            $content .= ("you did not make any <strong>$trName</strong> activity at selected date(s).<br>");
            $content .= ("you may try to select other date(s) or you can click <strong>BACK</strong> button to go to previous page<br>");
            $content .= ("</div class='text-muted'>");
            $content .= ("</div>");
        }

        $content .= ("</div class='panel-body'>");
//        $content .= ("</div class='panel panel-default'>");


        if (is_array($addLink)) {
            $addLinkStr = "<a href='" . $addLink['link'] . "' class='btn btn-success'>" . $addLink['label'] . "</a>";
        }
        else {
            $addLinkStr = "";
        }

        $p = New Layout("$title", "$subTitle", "application/template/history.html");
        $p->addTags(
            array(
                "jenisTr" => $jenisTr,
                "subJenisTr" => $subJenisTr,
                "trName" => $trName,
                "menu_left" => callMenuLeft(),
                "trans_menu" => callTransMenu(),
                "float_menu_atas" => callFloatMenu('atas'),
                "float_menu_bawah" => callFloatMenu(),
                "btn_back" => callBackNav(),
                "content" => $content,
                "profile_name" => $this->session->login['nama'],
                "add_link" => $addLinkStr,
                "date1" => $filters['date1'],
                "date2" => $filters['date2'],
                "date_min" => $filters['dates']['start'],
                "date_max" => $filters['dates']['end'],
                "url" => $thisPage,
                "newTrTarget" => isset($addLink['link']) ? $addLink['link'] : "JavaScript:void(0)",
                "newTrDisp" => isset($addLink['link']) ? "inline-table" : "none",
            )
        );

        $p->render();
        break;

    case "viewMySettlement":


        $cf_button = $this->config->item('button');
        $segment_uri_array = $this->uri->segment_array();
        $segment_total = $this->uri->total_segments();
        $segment_page = $segment_total;
        $content = "";

        if (isset($stepLabels) && sizeof($stepLabels) > 0) {
            $content .= ("<ul class='nav nav-tabs'>");
            foreach ($stepLabels as $step => $label) {
                $color = $steps[$step]['target'] == $currentState ? "#454549" : "#999999";
                $borderColor = $steps[$step]['target'] == $currentState ? "#cccccc" : "#ffffff";
                $bgColor = $steps[$step]['target'] == $currentState ? "#ffffff" : "#f0f0f0";
                $content .= ("<li class='nav-item'>");
                $content .= "<a class='nav-link btn' style='background:$bgColor;color:$color;border-width:1px 1px 0px 1px; border-color:$borderColor; border-style: solid;' onclick =\"location.href='" . $stepLinks[$step] . "?date1=" . $filters['date1'] . "&date2=" . $filters['date2'] . "';\">";
                if ($steps[$step]['target'] == $currentState) {
                    $content .= "<span class='fa fa-adjust'></span> ";
                }
                $content .= "$label</a>";
                $content .= ("</li>");
            }
            $content .= ("</ul class='pager'>");
        }


//        arrprint($names);die();

//        arrprint($recaps);die();


        $content .= ("<div class='panel panel-default'>");
        $content .= ("<div class='panel-body'>");
        $content .= ("<div class='row'>");
        $content .= ("<div class='col-md-8'>");
        $content .= ("<h3 class='text-blue'>activities</h3>");
        if (sizeof($trItems) > 0) {

            $content .= ("<table class='table table-bordered table-condensed'>");

            $content .= ("<tr bgcolor='#f0f0f0'>");
            $content .= ("<td align='right' class='text-muted'>no.");
            $content .= ("</td>");
            foreach ($trHeaders as $key => $label) {
                $content .= ("<td class='text-muted'>$label");
                $content .= ("</td>");
            }

            $content .= ("</tr>");

            $no = 0;
            $totals = array();
            foreach ($trItems as $iSpec) {
                $no++;
                $content .= ("<tr>");
                $content .= ("<td align='right'>$no.");
                $content .= ("</td>");
                foreach ($trHeaders as $key => $label) {

                    $content .= ("<td>");
                    $content .= formatField($key, $iSpec[$key]);
                    $content .= ("</td>");
                    if (is_numeric($iSpec[$key])) {
                        if (!isset($totals[$key])) {
                            $totals[$key] = 0;
                        }
                        $totals[$key] += $iSpec[$key];
                    }
                }
                $content .= ("</tr>");
            }

            $content .= ("<tr bgcolor='#f5f5f5'>");
            $content .= ("<td align='right'>");
            $content .= ("</td>");
            foreach ($trHeaders as $key => $label) {
                $content .= ("<td>");
                if (isset($totals[$key])) {
                    $content .= formatField($key, $totals[$key]);
                }
                $content .= ("</td>");
            }
            $content .= ("</tr>");

            $content .= ("</table class='table table-condensed'>");
        }
        else {
            $content .= ("<div class='text-muted'>");
            $content .= ("- no transactional activities you have been made within selected date(s) -");
            $content .= ("</div class='text-muted'>");
        }
        $content .= ("</div class='col-md-8'>");
        $content .= ("</div class='row'>");
        $content .= ("</div class='panel panel-default'>");
        $content .= ("</div class='panel-body'>");


        $content .= ("<div class='panel panel-default'>");
        $content .= ("<div class='panel-body'>");
        $content .= "<h3 class='text-blue'>asset movements</h3>";
        $aCtr = 0;
        if (sizeof($names) > 0) {
            $content .= ("<div class=\"row\">");
            foreach ($names as $nameID => $valSpec) {
                $totals[$nameID] = array(
                    "qty_in" => 0,
                    "qty_out" => 0,
                    "value_in" => 0,
                    "value_out" => 0,
                );
                if (isset($names[$nameID]) && sizeof($names[$nameID]) > 0) {
                    $nameID_alias = isset($accountAlias[$nameID]) ? $accountAlias[$nameID] : $nameID;

                    $aCtr++;
                    $content .= ("<div class='col-md-4'>");
                    $content .= "<h4 class='text-muted'>$nameID_alias</h4>";

                    $content .= "<div class='table-responsive'>";
                    $content .= "<table class='table table-bordered table-condensed'>";
                    $content .= "<tr bgcolor='#f0f0f0'>";
                    $content .= "<td class='text-muted' align='right'>no.</td>";
                    $content .= "<td class='text-muted'>item names</td>";
                    $content .= "<td class='text-muted'>IN qty</td>";
                    $content .= "<td class='text-muted'>OUT qty</td>";
                    $content .= "<td class='text-muted'>IN IDR</td>";
                    $content .= "<td class='text-muted'>OUT IDR</td>";
                    $content .= "</tr>";
                    $iCtr = 0;
                    foreach ($names[$nameID] as $iID => $iName) {
                        $iCtr++;
                        $qty_in = isset($recaps[$nameID][$iID]['qty_in']) ? $recaps[$nameID][$iID]['qty_in'] : 0;
                        $qty_out = isset($recaps[$nameID][$iID]['qty_out']) ? $recaps[$nameID][$iID]['qty_out'] : 0;
                        $val_in = isset($recaps[$nameID][$iID]['value_in']) ? number_format($recaps[$nameID][$iID]['value_in']) : 0;
                        $val_out = isset($recaps[$nameID][$iID]['value_out']) ? number_format($recaps[$nameID][$iID]['value_out']) : 0;
                        $content .= "<tr>";
                        $content .= "<td align='right'>$iCtr.</td>";
                        $content .= "<td>$iName</td>";
                        $content .= "<td align='right'>$qty_in</td>";
                        $content .= "<td align='right'>$qty_out</td>";
                        $content .= "<td align='right'>$val_in</td>";
                        $content .= "<td align='right'>$val_out</td>";
                        $content .= "</tr>";

                        $totals[$nameID]['qty_in'] += $qty_in;
                        $totals[$nameID]['qty_out'] += $qty_out;
                        $totals[$nameID]['value_in'] += $recaps[$nameID][$iID]['value_in'];
                        $totals[$nameID]['value_out'] += $recaps[$nameID][$iID]['value_out'];

                    }


                    $qty_in = $totals[$nameID]['qty_in'];
                    $qty_out = $totals[$nameID]['qty_out'];
                    $val_in = number_format($totals[$nameID]['value_in']);
                    $val_out = number_format($totals[$nameID]['value_out']);
                    $content .= "<tr bgcolor='#f0f0f0'>";
                    $content .= "<td align='right'>&nbsp;</td>";
                    $content .= "<td>total</td>";
                    $content .= "<td align='right'>$qty_in</td>";
                    $content .= "<td align='right'>$qty_out</td>";
                    $content .= "<td align='right'>$val_in</td>";
                    $content .= "<td align='right'>$val_out</td>";
                    $content .= "</tr>";

                    $content .= "</table class='table table-bordered table-condensed'>";
                    $content .= "</div class='table-responsive'>";

                    $content .= ("</div class=col-md-3>");

                }
                else {
                    $content .= ("<div class=\"box-body\">");
                    $content .= ("<div class='text-muted'>");
                    $content .= ("you haven't made any activities causing asset movements within selected date(s).<br>");
                    $content .= ("try to select other date(s) or you can click BACK button to go to previous page<br>");
                    $content .= ("</div class='text-muted'>");
                    $content .= ("</div>");
                }

            }
            $content .= ("</div class=\"row\">");


        }
        else {
            $content .= ("<div class=\"box-body\">");
            $content .= ("<div class='text-muted'>");
            $content .= ("you did not make any <strong>$trName</strong> activity at selected date(s).<br>");
            $content .= ("you may try to select other date(s) or you can click <strong>BACK</strong> button to go to previous page<br>");
            $content .= ("</div class='text-muted'>");
            $content .= ("</div>");
        }

        $content .= ("</div class='panel-body'>");
        $content .= ("</div class='panel panel-default'>");


        if (is_array($addLink)) {
            $addLinkStr = "<a href='" . $addLink['link'] . "' class='btn btn-success'>" . $addLink['label'] . "</a>";
        }
        else {
            $addLinkStr = "";
        }

        $p = New Layout("$title", "$subTitle", MODUL_TEMPLATE_PATH . "template/history.html");
        $p->addTags(
            array(
                "jenisTr" => $jenisTr,
                "subJenisTr" => $subJenisTr,
                "trName" => $trName,
                "menu_left" => callMenuLeft(),
                "trans_menu" => callTransMenu(),
                "float_menu_atas" => callFloatMenu('atas'),
                "float_menu_bawah" => callFloatMenu(),
                "btn_back" => callBackNav(),
                "content" => $content,
                "profile_name" => $this->session->login['nama'],
                "add_link" => $addLinkStr,
                "date1" => $filters['date1'],
                "date2" => $filters['date2'],
                "date_min" => $filters['dates']['start'],
                "date_max" => $filters['dates']['end'],
                "url" => $thisPage,
                "newTrTarget" => isset($addLink['link']) ? $addLink['link'] : "JavaScript:void(0)",
                "newTrDisp" => isset($addLink['link']) ? "inline-table" : "none",
            )
        );

        $p->render();
        break;

    case "toDayRecap":

        $contens = "";
        $custom_button = "";
        // cekBiru();
        // $uri_4 = $segment_uri_array['4'];
        // $date1 = isset($_GET['date1']) ? $_GET['date1'] : "";
        // $date2 = isset($_GET['date2']) ? $_GET['date2'] : "";
        // arrPrint($customButton);
        if (isset($customButton)) {
            if (sizeof($customButton) > 0) {
                foreach ($customButton as $ky => $preg) {
                    foreach ($preg as $k => $mbuh) {
                        $$k = $preg[$k];
                    }
                    $custom_button .= "{text:'$label',action:function(e,dt,node,config){window.open('" . base_url() . $target . $customButtonTarget . "','download');}},";
                    // $custom_button .= "{text:'$label',action:function(e,dt,node,config){window.open('".base_url().$target.$uri_4."?date1=$date1&date2=$date2','download');}},";
                }
            }
        }
        // cekLime($custom_button . " $target");
        $cf_button = $this->config->item('button');
        $segment_total = $this->uri->total_segments();
        $segment_page = $segment_total;
        $arrayHistoryCanceleds = isset($arrayHistoryCanceled) ? $arrayHistoryCanceled : array();

        $content = "";
        $content .= "<div class='box box-info'>";
        $content .= "<div class='box-header'>";
        $content .= "<h4><span cclass=\"glyphicon glyphicon-flash\"></span> $recapTitle</h4>";
        $content .= "</div class='box box-header'>";

        $content .= ("<div class=\"box-body\">");
        if (sizeof($arrayHistory) > 0) {
            $content .= ("<form name='fSelect'>");
            $content .= ("<div class='table-responsive'>");
            $content .= "<table class='table hover datatables table-condensed table-bordered no-padding'>";

            //region thead
            $content .= ("<thead>");
            $content .= ("<tr bgcolor='#f0f0f0'>");

            foreach ($arrayHistoryLabels as $key => $label) {
                // arrPrint($label);
                $content .= ("<th class='text-uppercase text-muted text-center'>");
                if (is_array($label)) {
                    $content .= ($label['label']);
                }
                else {
                    $content .= ($label);
                }
                $content .= ("</th>");
            }

            $content .= ("</tr>");
            $content .= ("</thead>");

            //endregion head
            //region tbody
            // arrPrint($arrayHistory);
            $content .= ("<tbody>");
            $rowCtr = 0;
            foreach ($arrayHistory as $ii => $row) {

                $rslt_style = "";
                if (isset($history_canceled[$ii]) && (sizeof($history_canceled[$ii]) > 0)) {
                    //                    arrPrintWebs($history_canceled[$ii]);
                    foreach ($history_canceled[$ii] as $hist_cancel) {
                        if ($rslt_style == "") {
                            $rslt_style = $hist_cancel;
                        }
                        else {
                            $rslt_style = $rslt_style . $hist_cancel;
                        }
                    }
                }
                $rowCtr++;
                $content .= ("<tr id='tr$rowCtr' style='$rslt_style'>");
                foreach ($arrayHistoryLabels as $key => $label) {
                    $content .= ("<td>");
                    $content .= ($row[$key]);
                    $content .= ("</td>");
                }
                $content .= ("</tr>");
            }
            $content .= ("</tbody>");
            //endregion tbody

            //region tfoot
            $content .= ("<tfoot>");
            $content .= "<tr class='tfooter bg-grey-1'>";
            foreach ($arrayHistoryLabels as $key => $label) {
                $content .= ("<th>");
                if (isset($arrayHistorySumField) && isset($arrayHistorySumField[$key])) {
                    $content .= formatField($key, $arrayHistorySumField[$key]);
                }
                else {
                    $content .= "--";
                }
                $content .= ("</th>");
            }
            $content .= "</tr>";
            $content .= ("</tfoot>");
            //endregion tfoot

            $content .= ("</table class='table table-bordered'>");
            $content .= ("</div class='table-responsive'>");
            $content .= ("</form>");
        }
        else {
//            $content .= ("no history found.<br>");
//            $content .= ("to go back to index, you can click BACK button<br>");
            $msg = "no history found.<br>to go back to index, you can click BACK button<br>";
            $content .= tplNoData($msg);
        }
        $content .= ("</div>");
        $content .= ("</div>");

//         $content .= "<script>
//                     $(document).ready( function(){
//
//                         var table = $('table.datatables').dataTable({
//                             dom: 'lBfrtip',
//                             fixedHeader: true,
//                             lengthMenu: [ [10, 20, 50, 100, -1], [10, 20, 50, 100, 'All'] ],
//                             pageLength: -1,
//                             buttons: [
//                                         { extend: 'print', footer: true },
//                                           $custom_button
//                                     ],
// //                            buttons: [
// //                                        'copy', 'csv', 'excel', 'pdf', 'print'
// //                                    ],
// //                            buttons: [
// //                                        {
// //                                            extend: 'colvisGroup',
// //                                            text: 'Office info',
// //                                            show: [ 1, 2 ],
// //                                            hide: [ 3, 4, 5 ]
// //                                        },
// //                                        {
// //                                            extend: 'colvisGroup',
// //                                            text: 'HR info',
// //                                            show: [ 3, 4, 5 ],
// //                                            hide: [ 1, 2 ]
// //                                        },
// //                                        {
// //                                            extend: 'colvisGroup',
// //                                            text: 'Show all',
// //                                            show: ':hidden'
// //                                        }
// //                                    ]
//                             footerCallback: function ( row, data, start, end, display ) {
//                                         var api = this.api(), data;
//
//                                         // Remove the formatting to get integer data for summation
//                                         var intVal = function ( i ) {
//                                             return typeof i === 'string' ?
//                                                 i.replace(/[$,]/g, '')*1 :
//                                                 typeof i === 'number' ?
//                                                     i : 0;
//                                         };
//
//                                         var arrayFooter = $('tfoot>tr>th');
//                                         var dpageTotal = [];
//                                         jQuery.each(arrayFooter, function(i,d){
//
//                                             var id_n_index = parseFloat(i);
//                                             dpageTotal[id_n_index] = 0;
//
//                                             jQuery.each( $(api.column(id_n_index, { page: 'current'}).data() ), function(ii, obj){
//
//                                                 var pos = obj.indexOf('<');
//                                                 if(pos!==-1){
//                                                     dpageTotal[id_n_index] += intVal( $(obj).html() );
//                                                 }
//                                                 else{
//
//                                                 }
//
//                                             });
//
//                                         if( !isNaN(dpageTotal[id_n_index]) && dpageTotal[id_n_index] > 0 ){
//                                             $( api.column(id_n_index).footer() ).html(
//                                                 \"<div class='text-right text-primary text-bold'>\"+addCommas(dpageTotal[id_n_index])+\"</div>\"
//                                             );
//                                         }
//
//
//                                         });
//
// // Total over all pages
// //                                        var total2=0;
// //                                        jQuery.each( $(api.column(2).data()), function(i, obj){
// //                                            total2 += intVal( $('span', obj).html() );
// //                                        });
// //
// //                                        var total3=0;
// //                                        jQuery.each( $(api.column(3).data()), function(i, obj){
// //                                            total3 += intVal( $('span', obj).html() );
// //                                        });
// //
// //                                        var total4=0;
// //                                        jQuery.each( $(api.column(4).data()), function(i, obj){
// //                                            total4 += intVal( $('span', obj).html() );
// //                                        });
// //
// //                                        var total5=0;
// //                                        jQuery.each( $(api.column(5).data()), function(i, obj){
// //                                            total5 += intVal( $('span', obj).html() );
// //                                        });
//
//
//                                         // Total over this page
// //                                        pageTotal2 = api
// //                                            .column( 2, { page: 'current'} )
// //                                            .data()
// //                                            .reduce( function (a, b) {
// //                                                return intVal(a) + intVal(b);
// //                                            }, 0 );
//
// //                                        var pageTotal2=0;
// //                                        jQuery.each( $(api.column(2, { page: 'current'}).data()), function(i, obj){
// //                                            pageTotal2 += intVal( $('span', obj).html() );
// //                                        });
// //
// //                                        var pageTotal3=0;
// //                                        jQuery.each( $(api.column(3, { page: 'current'}).data()), function(i, obj){
// //                                            pageTotal3 += intVal( $('span', obj).html() );
// //                                        });
// //
// //                                        var pageTotal4=0;
// //                                        jQuery.each( $(api.column(4, { page: 'current'}).data()), function(i, obj){
// //                                            pageTotal4 += intVal( $('span', obj).html() );
// //                                        });
// //
// //                                        var pageTotal5=0;
// //                                        jQuery.each( $(api.column(5, { page: 'current'}).data()), function(i, obj){
// //                                            pageTotal5 += intVal( $('span', obj).html() );
// //                                        });
//
//                                         // Update footer
// //                                        $( api.column( 2 ).footer() ).html(
// //                                            \"<div class='text-right text-primary text-bold'>\"+addCommas(pageTotal2)+\"</div>\"
// //                                            + \"<div class='text-right'>\"+addCommas(total2)+\"</div>\"
// //                                        );
//
// //                                        $( api.column( 3 ).footer() ).html(
// //                                            \"<div class='text-right text-success text-bold'>\"+addCommas(pageTotal3)+\"</div>\"
// //                                            + \"<div class='text-right'>\"+addCommas(total3)+\"</div>\"
// //                                        );
//
// //                                        $( api.column( 4 ).footer() ).html(
// //                                            \"<div class='text-right text-success text-bold'>\"+addCommas(pageTotal4)+\"</div>\"
// //                                            + \"<div class='text-right'>\"+addCommas(total4)+\"</div>\"
// //                                        );
//
// //                                        $( api.column( 5 ).footer() ).html(
// //                                            \"<div class='text-right text-danger text-bold'>\"+addCommas(pageTotal5)+\"</div>\"
// //                                            + \"<div class='text-right'>\"+addCommas(total5)+\"</div>\"
// //                                        );
//
//                                     }
//                                 });
//
//                             });
//
//                             $('.table-responsive').floatingScroll();
//                     </script>";

        echo $content;
        break;

    case "viewSettlement":
        $content="";
        // $items=array();
        // echo $action_label;
        if (is_array($addLink)) {
            $addLinkStr = "<a href='" . $addLink['link'] . "' class='btn btn-success'>" . $addLink['label'] . "</a>";
        }
        else {
            $addLinkStr = "";
        }
        $content .= ("<div class=\"box-body\">");
        if (sizeof($items) > 0) {
            //region button settlement $settlementLink
            // $btnSettle = "<a type='button' class='btn btn-success btn-block' value='settlement penjualan '>";
            $btnSettle  = "<div class='col-mfd-6'>";
//            $btnSettle .= "<a class='btn btn-block btn-success' title='klik untuk melakukan settlement' onclick=\"if(confirm('Semua transaksi penjualan akan disetor. Lanjutkan?')==1){document.getElementById('result').src='" . $action_target . "';this.style.visibility='hidden';top.HoldOn.open();}\"><span class='glyphicon glyphicon-ok'></span> $action_label</a>";

            $linkSettlement = "
                BootstrapDialog.closeAll();
                BootstrapDialog.show({
                    message: $('<div>Loading Preview Settlement...</div>').load('$preview_target',{action_target:'$action_target'}),
                    title: 'Preview Settlement',
                    size: 'custom-width',
                    draggable: true,
                    closable: false,
                    animate: false,
                    onShown: function(){
                        console.log('modal dialog settlement terbuka nih.....');
                    }
                })
            ";

            $btnSettle .= "<a class='btn btn-block btn-success' title='klik untuk melakukan settlement' onclick=\"$linkSettlement\"><span class='glyphicon glyphicon-ok'></span> $action_label</a>";

            $btnSettle .= "</div class='col-mdf-6'>";
            //endregion
            $content .= ("<div class='bg-danger'>");
            $content .= ("<div><span class='text text-bold' style='font-size:25px;'>Transaksi penjualan siap disetor</span></div>");
            $content .= ("<div class='table-responsive'>");
            $content .= "<table class='table hover datatables table-condensed table-bordered no-padding'>";

            //region thead
            $content .= ("<thead>");
            $content .= ("<tr bgcolor='#f0f0f0'>");

            foreach ($itemsLabel as $key => $label) {
                // arrPrint($label);
                $content .= ("<th class='text-uppercase text-muted text-center'>");
                if (is_array($label)) {
                    $content .= ($label['label']);
                }
                else {
                    $content .= ($label);
                }
                $content .= ("</th>");
            }
            // $content .= ("<th class='text-uppercase text-muted text-center'>");
            // $content .= ("</th>");

            $content .= ("</tr>");
            $content .= ("</thead>");

            //endregion head

            //region tbody
            $content .= ("<tbody>");
            $rowCtr = 0;
            foreach ($items as $row) {
                $rowCtr++;
                $content .= ("<tr id='tr$rowCtr'>");
                foreach ($itemsLabel as $key => $label) {

                    $content .= ("<td>");
                    $content .= (isset($row[$key]) ? $row[$key] : "");
                    $content .= ("</td>");

                }
                $content .= ("</tr>");
            }
            $content .= ("</tbody>");
            //endregion tbody

            //region tfoot
            $content .= ("<tfoot>");
            $content .= "<tr class='tfooter bg-grey-1'>";
            foreach ($itemsLabel as $key => $label) {
                $content .= ("<th>");
                if (isset($arrayHistorySumField) && sizeof($arrayHistorySumField) > 0) {
                    if (isset($arrayHistorySumField[$key])) {
                        $content .= $arrayHistorySumField[$key];
                    }
                    else {
                        $content .= "-";
                    }
                }
                else {
                    $content .= "-";
                }
                $content .= ("</th>");
            }
            $content .= "</tr>";
            $content .= ("</tfoot>");
            //endregion tfoot
            $content .= ("</table class='table table-bordered'>");
            $content .="<div><span>$btnSettle</span></div>";
            $content .= ("</div class='table-responsive'>");
            $content .= ("</div >");
            // $content .= ("</form>");

        }
        else {
            //            $content .= ("no history found.<br>");
            //            $content .= ("to go back to index, you can click BACK button<br>");
            $msg = "God job . Semua Transaksi sudah disetor<br>";
            $content .= tplNoData($msg);
        }
        $content .= ("</div>");
        $content .= ("<br>");

        $contentPending ="";
        if(sizeof($arrayHistory)>0){
            // arrPrint($arrayHistory);
            //region belum otorisasi

            if(isset($arrayHistory["pending"]) && sizeof($arrayHistory["pending"])>0){
                $contentPending .= ("<div class='bg-warning'>");
                $contentPending .= ("<div><span class='text text-bold' style='font-size:25px;'>Menunggu Otorisasi</span></div>");
                $contentPending .= ("<div class='table-responsive'>");
                $contentPending .= "<table class='table hover datatables table-condensed table-bordered no-padding'>";

                //region thead
                $contentPending .= ("<thead>");
                $contentPending .= ("<tr bgcolor='#f0f0f0'>");

                foreach ($arrayHistoryLabelPending as $key => $label) {
                    // arrPrint($label);
                    $contentPending .= ("<th class='text-uppercase text-muted text-center'>");
                    if (is_array($label)) {
                        $contentPending .= ($label['label']);
                    }
                    else {
                        $contentPending .= ($label);
                    }
                    $contentPending .= ("</th>");
                }
                // $contentPending .= ("<th class='text-uppercase text-muted text-center'>");
                // $contentPending .= ("</th>");

                $contentPending .= ("</tr>");
                $contentPending .= ("</thead>");

                //endregion head

                //region tbody
                $contentPending .= ("<tbody>");
                $rowCtr = 0;
                foreach ($arrayHistory["pending"] as $row) {
                    $rowCtr++;
                    $contentPending .= ("<tr id='tr$rowCtr'>");
                    foreach ($arrayHistoryLabelPending as $key => $label) {
                        $contentPending .= ("<td>");
                        $contentPending .= (isset($row[$key]) ? formatField_he_format($key,$row[$key]) : "");
                        $contentPending .= ("</td>");

                    }
                    $contentPending .= ("</tr>");
                }
                $contentPending .= ("</tbody>");
                //endregion tbody

                //region tfoot
                $contentPending .= ("<tfoot>");
                $contentPending .= "<tr class='tfooter bg-grey-1'>";



//                foreach ($itemsLabel as $key => $label) {
//
//                    if (isset($arrayHistorySumField) && sizeof($arrayHistorySumField) > 0) {
//                        $contentPending .= ("<th>");
//                        if (isset($arrayHistorySumField[$key])) {
//                            $contentPending .= $arrayHistorySumField[$key];
//                            arrPrint($contentPending);
//                        }
////                        else {
////                            $contentPending .= "-";
////                        }
//                        $contentPending .= ("</th>");
//                    }
////                    else {
//////                        $contentPending .= "-";
////                    }
//
//                }
                $contentPending .= "</tr>";
                $contentPending .= ("</tfoot>");
                //endregion tfoot
                $contentPending .= ("</table class='table table-bordered'>");
                $contentPending .= ("</div class='table-responsive'>");
                $contentPending .= ("</div >");
            }
            if(isset($arrayHistory["history"]) && sizeof($arrayHistory["history"])>0){
                $contentPending .= ("<div class='bgg-warning'>");
                $contentPending .= ("<div><span class='text text-bold' style='font-size:25px;'>History Settlement <span class='text-sm'><i><r>(7 settlement terakhir)</r></i></span></span></div>");
                $contentPending .= ("<div class='table-responsive'>");
                $contentPending .= "<table class='table hover datatables table-condensed table-bordered no-padding'>";

                //region thead
                $contentPending .= ("<thead>");
                $contentPending .= ("<tr bgcolor='#f0f0f0'>");

                foreach ($arrayHistoryLabels as $key => $label) {
                    // arrPrint($label);
                    $contentPending .= ("<th class='text-uppercase text-muted text-center'>");
                    if (is_array($label)) {
                        $contentPending .= ($label['label']);
                    }
                    else {
                        $contentPending .= ($label);
                    }
                    $contentPending .= ("</th>");
                }
                // $contentPending .= ("<th class='text-uppercase text-muted text-center'>");
                // $contentPending .= ("</th>");

                $contentPending .= ("</tr>");
                $contentPending .= ("</thead>");

                //endregion head

                //region tbody
                $contentPending .= ("<tbody>");
                $rowCtr = 0;
                foreach ($arrayHistory["history"] as $row) {
                    $rowCtr++;
                    $contentPending .= ("<tr id='tr$rowCtr'>");
                    foreach ($arrayHistoryLabels as $key => $label) {
                        if($key=="sisa"){
                            $contentPending .= ("<td>");
                            $contentPending .= (isset($row[$key]) ? formatField($key,$row[$key]*-1) : "");
                            $contentPending .= ("</td>");
                        }
                        else{
                            $contentPending .= ("<td>");
                            $contentPending .= (isset($row[$key]) ? formatField($key,$row[$key]) : "");
                            $contentPending .= ("</td>");
                        }
                    }
                    $contentPending .= ("</tr>");
                }
                $contentPending .= ("</tbody>");
                //endregion tbody

                //region tfoot
//                $contentPending .= ("<tfoot>");
//                $contentPending .= "<tr class='tfooter bg-grey-1'>";
//                foreach ($itemsLabel as $key => $label) {
//                    $contentPending .= ("<th>");
//                    if (isset($arrayHistorySumField) && sizeof($arrayHistorySumField) > 0) {
//                        if (isset($arrayHistorySumField[$key])) {
//                            $contentPending .= $arrayHistorySumField[$key];
//                        }
//                        else {
//                            $contentPending .= "-";
//                        }
//                    }
//                    else {
//                        $contentPending .= "-";
//                    }
//                    $contentPending .= ("</th>");
//                }
//                $contentPending .= "</tr>";
//                $contentPending .= ("</tfoot>");
                //endregion tfoot
                $contentPending .= ("</table class='table table-bordered'>");
                $contentPending .= ("</div class='table-responsive'>");
                $contentPending .= ("</div >");
            }
            //endregion
        }
        $content .=$contentPending;


        $p = New Layout("$title", "$subTitle", MODUL_TEMPLATE_PATH . "template/settlement.html");

        $p->addTags(array(
            "jenisTr" => $jenisTr,
            "trName" => $trName,
            "navigasi" => $btnNavigasi,
            "menu_left" => callMenuLeft(),
            //                                "trans_menu" => callTransMenu(),
            "float_menu_atas" => callFloatMenu('atas'),
            "float_menu_bawah" => callFloatMenu(),
            "menu_taskbar" => callMenuTaskbar(),
            "btn_back" => callBackNav(),
            "content" => $content,
            "profile_name" => $this->session->login['nama'],
            "add_link" => $addLinkStr,
            "date1" => $filters['date1'],
            "date2" => $filters['date2'],
            "date_min" => isset($filters['dates']['start']) ? $filters['dates']['start'] : "",
            "date_max" => isset($filters['dates']['end']) ? $filters['dates']['end'] : "",
            "url" => $thisPage,
            "newTrTarget" => isset($addLink['link']) ? $addLink['link'] : "JavaScript:void(0)",
            "newTrDisp" => isset($addLink['link']) ? "inline-table" : "none",
        ));
        $p->render();

        break;


}