<script type="text/javascript">
    $(function() {
        $("#form_input #bulan").inputmask({'alias':'datetime','inputFormat': 'mm-yyyy'});
        $("#form_input #bulan").datepicker( {
            format: "mm-yyyy",
            viewMode: "months",
            orientation: 'bottom',
            minViewMode: "months",
            autoclose: true
        });

        $('#form_input #id_karyawan').select2({
            placeholder: 'Pilih Karyawan',
            ajax: {
                url: '<?= route("dropdown.karyawan.encrypt") ?>',
                dataType: 'json',
                delay: 250,
                processResults: function (data) {
                return {
                        results: data
                    };
                },
                cache: true
            },
            minLength: 3,
        });

    });

    function formatangka(objek) {
        a = objek.value;
        b = a.replace(/[^\d]/g,"");
        c = "";
        panjang = b.length;
        j = 0;
        for (i = panjang; i > 0; i--) {
            j = j + 1;
            if (((j % 3) == 1) && (j != 1)) {
            c = b.substr(i-1,1) + "." + c;
            } else {
            c = b.substr(i-1,1) + c;
            }
        }
        objek.value = c;
    }
</script>
<div class="card-header">
    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
    <h3 class="title modal-title"></h3>
</div>
<div id="form_input" class="card-body">
    <input type="hidden" id="key" value="<?= ((isset($data))?$data->id:"") ?>">

        <?php
            $id_karyawan = ((isset($data->id_karyawan))?$data->id_karyawan:'');
            if(empty($id_karyawan)){
        ?>
                <div class="form-group">
                    <label>Bulan<i class="text-danger">*</i></label>
                    <input type="text" id="bulan" class="form-control" value="<?= date("m-Y") ?>" autocomplete="off" placeholder="mm-yyyy">
                </div>
                <div class="form-group">
                    <label>Nama Karyawan<i class="text-danger">*</i></label>
                    <select id="id_karyawan" class="custom-select form-control" style="width:100%"></select>
                </div>
        <?php
            }else{
        ?>
                <div class="form-group">
                    <label>Bulan</label><br>
                    <label><b><?=((isset($data))?date_format(date_create($data->bulan),"m-Y"):"") ?></b></label>
                </div>
                <div class="form-group">
                    <label>Nama Karyawan</label><br>
                    <label><b><?=((isset($data))?$data->nik." - ".$data->nm_karyawan:"") ?></b></label>
                </div>
        <?php
            }
        ?>

</div>
<div class="card-footer">
    <div class="row">
        <div class="col-md-7 text-left">
            <div id="message"></div>
        </div>
        <div class="col-md-5 text-right">
            <button id="btn_new_input" class="btn" style="display:none">TAMBAH BARU</button>
            <button class="btn_save ladda-button" data-style="expand-left"></button>
        </div>
    </div><!-- ./row -->
</div>
