<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>
<form id="xyz">
    <div id="form_input" class="card-body" disabled>
             <input type="hidden" id="id_cabang" name="id_cabang" class="form-control" value="<?= ((isset($data))? $data->id_cabang :'') ?>">

        <?php
            $data_cabang = $this->Db_model->get('p_approval_reimbursement', 'level_user, level_approval, id', array('id_cabang' => $data->id_cabang)); 
            //$this->db->query("SELECT level_user, level_approval FROM p_approval_reimbursement WHERE id_cabang = '$data->id_cabang'");

            $jumlah_level = $data_cabang->num_rows();
            $i = 1;
            foreach ($data_cabang->result() as $val) {
                $level = explode(',', $val->level_approval);
        ?>
        <div class="form-group">
            <p><b><?= $this->fungsi->get_nama_level($val->level_user) ?></b></p>
            <input type="hidden" id="level_user_<?= $i ?>" name="level_user_<?= $i ?>" class="form-control" value="<?= ((isset($val))? $val->level_user:'') ?>">
            <input type="hidden" id="id_<?= $i ?>" name="id_<?= $i ?>" class="form-control" value="<?= ((isset($val))? $val->id:'') ?>">
            <div class="row">
                <div class="col-md-2">
                    <input type="checkbox" id="level1_<?= $i ?>" name="level_<?= $i ?>-[]" value="7" <?=(isset($level) AND in_array('7', $level))? 'checked' : ''?> /> Supervisi
                </div>
                <div class="col-md-3">
                    <input type="checkbox" id="level2_<?= $i ?>" name="level_<?= $i ?>-[]" value="2" <?=(isset($level) AND in_array('2', $level))? 'checked' : ''?>/> Kepala Departemen
                </div>
                <div class="col-md-3">
                    <input type="checkbox" id="level3_<?= $i ?>" name="level_<?= $i ?>-[]" value="5" <?=(isset($level) AND in_array('5', $level))? 'checked' : ''?>/> Kepala Cabang
                </div>
                <div class="col-md-2">
                    <input type="checkbox" id="level4<?= $i ?>" name="level_<?= $i ?>-[]" value="6" <?=(isset($level) AND in_array('6', $level))? 'checked' : ''?>/> Finance
                </div>
                <div class="col-md-2">
                    <input type="checkbox" id="level5_<?= $i ?>" name="level_<?= $i ?>-[]" value="4" <?=(isset($level) AND in_array('4', $level))? 'checked' : ''?>/> Direksi
                </div>
            </div>
        </div><hr><br>
        <?php
             $i++;
            }
        ?>   
        <input type="hidden" name="jumlah_level" id="jumlah_level" value="<?= $jumlah_level ?>" class="form-control">
    </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 class="btn_save ladda-button" data-style="expand-left"></button> -->
                <button type="submit" id="btn_save" class="btn_save ladda-button" data-style="expand-left"></button>
            </div>
        </div><!-- ./row -->
    </div>

</form>

<script type="text/javascript">
     $(document).ready(function(e) {
        $("#xyz").on('submit', (function(e) {
            e.preventDefault();

            var loading = Ladda.create(document.getElementById("btn_save"));

            loading.start();

            $.ajax({
                url: "<?= site_url() ?>/pengaturan/reimbursement/save",
                type: "POST",
                data: new FormData(this),
                contentType: false,
                cache: false,
                dataType: 'json',
                processData: false,
                success: function(result) {
                  if(result.success == true){
                    if (result.type == 'save') {
                        loading.stop();
                        $('#message').show();
                        $('#message').html(result.message);
                        list_data();
                        $('#modal_form').modal('hide');
                    } else {
                        loading.stop();
                        $('#message').show();
                        $('#message').html(result.message);
                        list_data();
                        $('#modal_form').modal('hide');
                    }
                  }else{
                    loading.stop();
                    $('#message').show();
                    $('#message').html(result.message);
                  }                    
                },
                error: function() {
                    loading.stop();
                    $('#message').show();
                    $('#message').html('<font color="#eb3a28"><i class="fa fa-close(alias)">&nbsp;</i><strong>Gagal : Terjadi Kesalahan</strong></font>');
                }
            });
        }));
    });
</script>

