<?php echo $this->extend('/template'); ?>
<?php echo $this->section('content') ?>

<head>
    <title><?php echo $balik == '0' ? 'MONITORING PEMUDIK' : 'MONITORING BALIK RANTAU'; ?></title>

</head>

<div class="row">
    <div class="col-md-4">
        <h3>
            <img src="/assets/images/pemprovsmr/header_icon.png" width="35px">&nbsp;<b><?php echo $balik == '0' ? 'MONITORING PEMUDIK' : 'MONITORING BALIK RANTAU'; ?></b>
            <a href="#" class="easyui-linkbutton"  plain="true" onclick="reload_data()"><img src="/assets/images/pemprovsmr/refresh.png" width="30px"></a>
        </h3>

    </div>
    <div class="col-md-2"><div id="rekap"></div>

</div>
    <div class="col-md-6" style="text-align:right;">
    <?php include("searchmoni.php"); ?>
    </div>
</div>


<div class="containers">
    <?php //echo 'Jumlah Cetak : '.$jmlcetak; ?>
    <table id="dg" title="<?php echo $balik == '0' ? 'DAFTAR PEMUDIK' : 'DAFTAR BALIK RANTAU'; ?>" class="easyui-datagrid" style="width:100%;height:auto" url="/monidata"  toolbar="#toolbar" rownumbers="true" fitColumns="true" singleSelect="true" data-options="
            pagination:true,
            scrollbarSize:0,
            nowrap:false,
            remoteFilter:true,
            fitColumns:true,
            pageSize:50,
            noWrap:false,
            queryParams: {
                '<?php echo csrf_token() ?>': '<?php echo csrf_hash() ?>',
                'getkd' : '<?php echo $getkd; ?>',
                'balik' : '<?php echo $balik; ?>',
                't':'<?php echo $t; ?>',
                'ar':'<?php echo $ar; ?>'
            },
            rowStyler: function(index,row){
                    if (row.sdh_dapatbus == '19999'){
                        return 'background-color:#f4a1a1;color:#000;font-weight:bold;';
                    }
                },

            ">
        <thead>
            <tr>
                <th field="koded" width="15" sortable="true">KODE</th>
                <th field="nik" width="15" align="left">NIK</th>
                <th field="nama" width="20">NAMA</th>
                <th field="wilayaht" width="10" align="left">TUJUAN</th>
                <th field="armadat" width="15" align="left">ARMADA</th>
                <th field="absen" width="10" align="center">ABSEN</th>
                <th field="aksi2" width="10" align="center">e-TIKET</th>
            </tr>
        </thead>
    </table>

    <div id="toolbar">
        <a href="/moni/<?php echo $balik; ?>" class="easyui-linkbutton"><span class="fa fa-circle" style="color:red"></span></a>
        <?php if($t > 0 AND $ar > 0)
        { 
            $counter = 0;
            for($counter;$counter <= $jmlcetak-1; $counter++) {
            ?>
            <a href="/etiketcetak/1/<?php echo $ar; ?>/<?php echo $counter; ?>" class="easyui-linkbutton"><span class="fa fa-credit-card" ></span></a>

        <?php 
            }
    
        }    
        ?>
    </div>


</div>

<script>
    $(document).ready(function() {
        $('#dg').datagrid({
            onLoadSuccess: function(index, field, value) {
                moniresume();
                /*
                console.log(index);
                console.log(field);
                console.log(value);
                
                dt = $('#dg').datagrid('getData');
                sdh_absen = 0;
                $.each(dt.rows, function(key, value) {
                    sdh_absen += parseInt(value.sdh_absen);
                });

                total = dt.total;
                */

                //html = '<table width="100%" border="1"><tr><th style="text-align:center">TOTAL</th><th style="text-align:center">SDH ABSEN</th></tr>';
                //html += '<tr><td style="text-align:center"><h4>'+total+'</h4></td><td style="text-align:center"><h4>'+sdh_absen+'</h4></td></tr></table>';
                //$('#rekap').html(html);
                
            }
        });
        


    });


    function moniresume() {
        $.ajax({
            type: 'post',
            url: "<?php echo base_url(); ?>/moniresume",
            data: {
                t: '<?php echo $t; ?>',
                ar: '<?php echo $ar; ?>',
                balik: '<?php echo $balik; ?>',
                "<?= csrf_token() ?>": "<?= csrf_hash() ?>"
            },
            success: function(data) {
                var respon = $.parseJSON(data);
                console.log(respon);
                total = parseInt(respon[0])+parseInt(respon[1]);

                html = '<table width="100%" border="1"><tr><th style="text-align:center">TOTAL</th><th style="text-align:center">SDH ABSEN</th></tr>';
                html += '<tr><td style="text-align:center"><h4>'+total+'</h4></td><td style="text-align:center"><h4>'+respon[1]+'</h4></td></tr></table>';
                $('#rekap').html(html);


            }
        });

    }



    function reload_data()
    {
        $('#dg').datagrid('reload');
    }

    function absenubah(w, s) {
        $.ajax({
            type: 'post',
            url: "<?php echo base_url(); ?>/absenubah",
            data: {
                s: s,
                w: w,
                "<?= csrf_token() ?>": "<?= csrf_hash() ?>"
            },
            success: function(data) {
                console.log(respon);
                var respon = $.parseJSON(data);
                $('#dg').datagrid('reload');


            }
        });

    }

    function onLoadSuccess(data) {
        var merges = [{
            index: 2,
            rowspan: 2
        }, {
            index: 5,
            rowspan: 2
        }, {
            index: 7,
            rowspan: 2
        }];

        for (var i = 0; i < merges.length; i++) {
            $(this).datagrid('mergeCells', {
                index: merges[i].index,
                field: 'koded',
                rowspan: merges[i].rowspan
            });
        }
    }

</script>

<script type="text/javascript">
    $(function() {
        var dg = $('#dg').datagrid();
        dg.datagrid('enableFilter', [{
                field: 'nik',
                type: 'textbox'
            }, {
                field: 'nama',
                type: 'textbox'
            }, {
                field: 'koded',
                type: 'textbox'
            }, {
                field: 'absen',
                type: 'label'
            }, {
                field: 'aksi',
                type: 'label'
            }, {
                field: 'aksi2',
                type: 'label'
            }, {
                field: 'statust',
                type: 'combobox',
                trigger: 'none',
                options: {
                    panelHeight: 'auto',
                    selectOnNavigation: false,
                    queryParams: {
                        '<?php echo csrf_token() ?>': '<?php echo csrf_hash() ?>'
                    },
                    url: '/status_combo',
                    onChange: function(value) {
                        if (value == '') {
                            dg.datagrid('removeFilterRule', 'status');
                        } else {
                            dg.datagrid('addFilterRule', {
                                field: 'status',
                                value: value
                            });
                        }

                        dg.datagrid('doFilter');
                    }

                }
            }, {
                field: 'wilayaht',
                type: 'label'
            }, {
                field: 'armadat',
                type: 'label'
            }, {
                field: 'wilayahtX',
                type: 'combobox',
                trigger: 'none',
                options: {
                    editable: false,
                    panelHeight: 'auto',
                    selectOnNavigation: false,
                    queryParams: {
                        '<?php echo csrf_token() ?>': '<?php echo csrf_hash() ?>'
                    },
                    url: '/wilayah_combo',
                    onChange: function(value) {
                        if (value == '') {
                            dg.datagrid('removeFilterRule', 'wilayah_id');
                        } else {
                            dg.datagrid('addFilterRule', {
                                field: 'wilayah_id',
                                op: 'equal',
                                value: value
                            });
                        }
                        dg.datagrid('doFilter');
                    }
                }
            },




        ]);
    });

    function ver_unver(i, s) {
        $.ajax({
            type: 'post',
            url: "<?php echo base_url(); ?>/ver_unver",
            data: {
                i: i,
                s: s,
                "<?= csrf_token() ?>": "<?= csrf_hash() ?>"

            },
            success: function(data) {
                $('#dg').datagrid('reload');
            }

        });

    }


</script>



<style>
    .easyui-dialog {
        background-color: #f7d9d9;
    }

    .pulkanan {
        display: inline-block;
        text-align: right;
        float: inline-end;
        font-weight: bold;
    }
</style>

<?php echo $this->endSection() ?>


