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

<head>
    <title>ATUR ARMADA</title>
    <script>
        var baseUrl = "<?php echo base_url(); ?>";
        var siteUrl = "<?php echo site_url(); ?>";
    </script>
    <?php
    /*
header( "Access-Control-Allow-Origin: *" );
header( "Access-Control-Allow-Credentials: true" );
header( "Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS" );
header( "Access-Control-Max-Age: 604800" );
header( "Access-Control-Request-Headers: x-requested-with" );
header( "Access-Control-Allow-Headers: x-requested-with, x-requested-by" );
*/
    ?>


</head>


<h3>
    <img src="/assets/images/pemprovsmr/header_icon.png" width="35px">&nbsp;<b>JADWAL & PUBLISH e-TIKET
    </b>
</h3>

<b>PERHATIAN : </b><br />
Dengan meng-klik OK, maka e-TIKET resmi di-publsih<br />
Para calon Pemudik, apabila cek status sudah akan mendapatkan informasi mengenai <b>e-TIKET</b><br /><br />

<form id="fm" method="post" novalidate>
    <div class="row">
        <div class="col-sm-8">
            <div class="fitem">
                <input class="easyui-combobox" style="border-radius:30px;" id='tujuan' name="tujuan[]" data-options="
                        url: '/tujuancombo',
                        method:'post',
                        required:'true',
                        queryParams: {'<?php echo csrf_token() ?>': '<?php echo csrf_hash() ?>','balik':'<?php echo $balik; ?>','mode': '1'},
                        valueField:'wilayah_id',
                        textField:'nama',
                        multiple:true,
                        panelHeight:'300px',
                        editable:false,
                        width:'100%',
                        nowrap:false,
                        label: '<?php echo $balik == 0 ? "Tujuan Mudik (bisa pilih lebih dari satu)" : "Wilayah Asal"; ?>',
                        labelWidth:'300px',
                        labelPosition: 'top',
                        onSelect: function(rec){
                var url = '/armadacombo/'+rec.wilayah_id;
                $('#armada_id').combobox('reload', url);}
                ">
            </div><br />

            <div class="row">
                <div class="col-sm-6">
                    <div id="finalisasi" class="easyui-panel" title="KEBERANGKATAN BUS" style="width:100%;height:200px;padding:10px;">
                        <div style="margin-top:10px"></div>
                        <input name="tglberangkatb" class="easyui-datebox" label="Tanggal Keberangkatan" labelPosition="left" labelWidth="180px" required="true" data-options="width:'100%',formatter:myformatter,parser:myparser">
                        <div style="margin-top:10px"></div>
                        <input name="jamberangkatb" class="easyui-textbox" label="Jam Daftar Ulang" labelPosition="left" labelWidth="180px" required="true" data-options="width:'100%'">
                        <div style="margin-top:10px"></div>
                        <input name="tptkumpulb" class="easyui-textbox" label="<?php echo $balik == '0' ? 'Tempat Berkumpul' :  'Tujuan'; ?>" labelPosition="left" labelWidth="180px" required="true" data-options="width:'100%'">

                    </div>
                </div>
                <div class="col-sm-6">


                <center>
                <a href="javascript:void(0)" class="btn btn-primary" onclick="finalisasi()" style="width:150px;height:35px;">OK PUBLISH</a>
</form>
</center>
<center>
    <br /><br />
    <form id="fmu" method="post" novalidate>
        <a href="javascript:void(0)" class="btn btn-primary" onclick="unfinalisasi()" style="width:150px;height:35px;">BATALKAN PUBLISH</a>
    </form>
</center>






                </div>
            </div>
        </div>
        <div class="col-sm-4">


</div>
</div>





<script>
    $(document).ready(function() {

    });

    function finalisasi() {
        $('#fm').form('submit', {
            url: "/finalisasiproses",
            onSubmit: function(param) {
                param.csrftoken_erb2021 = '<?= csrf_hash() ?>';
                param.balik = '<?php echo $balik; ?>';
                return $(this).form('validate');
            },
            success: function(result) {
                alert('sukses');
            }
        });
    }

    function unfinalisasi() {
        $('#fmu').form('submit', {
            url: "/unfinalisasi",
            onSubmit: function(param) {
                param.csrftoken_erb2021 = '<?= csrf_hash() ?>',param.balik = '<?php echo $balik; ?>';
                return $(this).form('validate');
            },
            success: function(result) {
                alert('sukses');
            }
        });
    }



    function mapmudik(wid) {
        var aTag = $("#sah");
        $('html,body').animate({
            scrollTop: aTag.offset().top
        }, 3000);
    }





    function potensitotal() {
        $.ajax({
            type: 'post',
            url: "<?php echo base_url(); ?>/rekap",
            data: {
                "<?= csrf_token() ?>": "<?= csrf_hash() ?>"
            },
            success: function(data) {
                var respon = $.parseJSON(data);
                console.log(respon);
                html = '<table class="rekapmudik">';
                html += '<tr><th>JML PEMUDIK</th><th>TOTAL ARMADA</th><th>TOTAL SEAT</th><th>ARMADA TERPAKAI</th><th>SISA ARMADA</th><th>ARMADA CADANGAN</th></tr>';
                html += '<tr><td>' + respon.pemudik + '</td><td>' + respon.totarmada + '</td><td>' + respon.totseat + '</td><td>' + respon.totarmada_terpakai + '</td><td>' + respon.totarmada_sisa + '</td><td>' + respon.totarmada_cadangan + '</tr></table>';
                $('#potensitotal').html(html);
                //$('#potensitotal').html('Jumlah potensi Pemudik : ' + respon.total);
            }

        });

    }



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

            }

        });

    }



    function cellStyler(val, row) {
        if (val <= 0)
            return;
        else
            return '<span style="color:#000;font-size:20px;font-weight:bold">' + val + '</span>';
    }

    function cellStyler2(val, row) {
        if (row.armada)
            return '<span style="color:#000;font-size:16px;font-weight:bold">' + val + '</span>';
    }

    function cellStyler3(val, row) {
        if (row.kurangsisa < 0)
            return '<span style="color:#000;font-size:20px;font-weight:bold;border-style:solid;padding:10px 10px 10px 10px;border-color:red;background-color:red;color:#fff;">-' + val + '</span>';
        else if (row.kurangsisa > 0)
            return '<span style="color:#000;font-size:20px;font-weight:bold">' + val + '</span>';
        else return '';
    }
</script>

<script>
    $('#dgarmada').datagrid({
        onDblClickRow: function(index, field, value) {
            console.log(field.armada_id);
            var rowdg = $('#dg').datagrid('getSelected');
            if (!rowdg) {
                alert("Sila klik Kota Tujuan terlebih dulu");
                return;
            }
            wilayah_id = rowdg.wilayah_id;
            $.ajax({
                type: 'post',
                url: '/tunjukar',
                data: {
                    "<?php echo csrf_token() ?>": "<?php echo csrf_hash() ?>",
                    'armada_id': field.armada_id,
                    'wilayah_id': wilayah_id
                },
                success: function(datas) {
                    //var respon = $.parseJSON(data);
                    $('#dgarmada').datagrid('reload');
                    $('#dg').datagrid('reload');
                    potensitotal();
                }

            });

        }
    });
</script>

<script type="text/javascript">
    $('#dg').datagrid({
        view: detailview,
        detailFormatter: function(index, row) {
            var html = '<div class="ddv" style="padding:5px 0"></div>';
            return html;
        },
        onExpandRow: function(index, row) {
            var ddv = $(this).datagrid('getRowDetail', index).find('div.ddv');
            ddv.panel({
                height: 'auto',
                border: false,
                cache: false,
                href: '/aturdetil/' + row.wilayah_id,
                onLoad: function() {
                    $('#dg').datagrid('fixDetailRowHeight', index);
                }
            });
            $('#dg').datagrid('fixDetailRowHeight', index);
        }
    });

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

        });



    }

    function myformatter(date) {
        var y = date.getFullYear();
        var m = date.getMonth() + 1;
        var d = date.getDate();
        return (d < 10 ? ('0' + d) : d) + '-' + (m < 10 ? ('0' + m) : m) + '-' + y;
    }

    function myparser(s) {
        if (!s) return new Date();
        var ss = (s.split('-'));
        var y = parseInt(ss[2], 10);
        var m = parseInt(ss[1], 10);
        var d = parseInt(ss[0], 10);
        if (!isNaN(y) && !isNaN(m) && !isNaN(d)) {
            return new Date(y, m - 1, d);
        } else {
            return new Date();
        }
    }
</script>

<script>
    $(function() {
        var dg = $('#dgarmada').datagrid();
        dg.datagrid('enableFilter', [{
                field: 'perusahaan',
                type: 'textbox'
            }, {
                field: 'nama',
                type: 'textbox'
            }, {
                field: 'nopol',
                type: 'textbox'
            }, {
                field: 'jenist',
                type: 'label'
            }, {
                field: 'kapasitas',
                type: 'label'
            }


        ]);
    });
</script>




<script>
    $(function() {
        var dg = $('#dg').datagrid();
        dg.datagrid('enableFilter', [{
                field: 'nama',
                type: 'textbox'
            }, {
                field: 'potensi',
                type: 'label'
            }, {
                field: 'kurangsisa',
                type: 'label'
            }, {
                field: 'armada',
                type: 'label'
            }


        ]);
    });
</script>


<style>
    #potensitotal {
        font-size: 13px;
        font-weight: bold;
        color: #ad7a0d;
        float: right;
        padding-right: 10px;
    }

    table.rekapmudik {
        border-style: solid;
        padding: 5px;
        border-width: 1px;
        margin-bottom: 10px;
        margin-right: 0px;
    }

    .rekapmudik th,
    td {
        border-style: solid;
        border-width: 1px;
        padding: 5px;
        text-align: center;
    }

    .rekapmudik td {
        font-size: 18px;
        font-weight: bold;
        background-color: #f4edde;
    }

    .rekapmudik th {
        background-color: #888;
        color: #fff;
    }

    #sah {
        min-height: 700px;
    }

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