<!-- Page Heading -->
          <!-- <h1 class="h3 mb-2 text-gray-800">Tables</h1>
          <p class="mb-4">DataTables is a third party plugin that is used to generate the demo table below. For more information about DataTables, please visit the <a target="_blank" href="https://datatables.net">official DataTables documentation</a>.</p> -->
          <!-- DataTales Example -->
          <div class="card shadow mb-4">
            <div class="card-header py-3">
              <h6 class="m-0 font-weight-bold text-primary">Data Evaluasi PKA Triwulan (No PKA: <?=$id_row?>)</h6>
            </div>
            <div class="card-body">
              <!-- <a href='javascript:void(0)' onclick="getcontens('page/tambah_pka');" class="btn btn-primary btn-icon-split btn-sm mb-4">
                    <span class="icon text-white-50">
                      <i class="fas fa-plus"></i>
                    </span>
                    <span class="text">Tambah Data PKA</span>
              </a> -->
              <!-- <div class="row">
                <div class="form-group  col-md-6">
                      <label for="exampleFormControlSelect1">Periode PKA</label>
                      <select class="form-control" id="periode_thn" name="periode_thn" required>
                      </select>
                </div>
              </div> -->
              <div class="row">
                <div class="col-md-12">
                  <div class="table-responsive">
                    <table class="table table-bordered" id="tabel_data_pka" width="100%" cellspacing="0">
                      <thead>
                        <tr>
                          <th>No</th>
                          <th>KMA</th>
                          <th>Jenis Kegiatan</th>
                          <th>Unit Misioner</th>
                          <th>Bidang</th>
                          <th>Nama Kegiatan</th>
                          <th>Tujuan Kegiatan</th>
                          <th>Status</th>
                          <th>Aksi</th>
                        </tr>
                      </thead>
                      <!-- <tfoot>
                        <tr>
                          <th>Name</th>
                          <th>Position</th>
                          <th>Office</th>
                          <th>Age</th>
                          <th>Start date</th>
                          <th>Salary</th>
                        </tr>
                      </tfoot> -->
                      <tbody>
                      </tbody>
                    </table>
                  </div>
                </div>
              </div>
            </div>
          </div>
<script type="text/javascript">
$(document).ready(function(){
    var base_url = "<?=base_url()?>";
    // periode_thn = function(param){
    //   jQuery.ajax({
    //     url: base_url+"pka/select_periode_thn",
    //     dataType:'json',
    //     success:function(response){
    //       var data = response;
    //       var $id = $('#periode_thn');
    //       $id.empty();
    //       $id.append('<option value="all">- Semua Periode -</option>');
    //       for (var i = 0; i < data.length; i++) {
    //         $id.append('<option value="'+data[i].periode_thn+'">' + data[i].periode_thn + '</option>');
    //       }        
    //     }            
    //   });
    // }
    // periode_thn();
    // $('#periode_thn').change(function(){
    //   var periode_thn = $('#periode_thn').val(); 
    //   data_pka(periode_thn.replace('/','-'));
    // })
    var id_row = "<?=$id_row?>"
    data_pka = function(){
        $('#tabel_produk').hide();
        $.ajax({ 
            url: base_url + 'pka_ev_tri/data_ev_pka_tri/'+id_row,
            type: "post",
            // data:{<?php echo $this->security->get_csrf_token_name(); ?>:'<?php echo $this->security->get_csrf_hash(); ?>'},
            // data:{$d},
            dataType: "json",
            async : 'false',
            success: function(result){
            //   alert(JSON.stringify(result))
              var data = [];
                for ( var i=0 ; i<result.length ; i++ ) {
                  // alert(result[i].kode_pka)
                  // alert(result[i].acc)
                    var no = i+1;
                    // alert()
                    
                    if(result[i].ev_tri == '0'){
                      link_detail ="";              
                                      
                    }else{
                      link_detail =`<a href="javascript:void(0)" onclick="getpopup('Popup/detail_evtri','popupevaluasi','`+result[i].kma+`');" class="btn btn-success btn-icon-split btn-sm">
                                        <span class="icon text-white-50">
                                          <i class="fas fa-eye"></i>
                                        </span>
                                      </a>`;
                    }
                    if(result[i].ev_tri == "0"){
                      stt = "Belum Dievaluasi";
                    }else if(result[i].ev_tri == "1"){
                      stt = "Sudah Dievaluasi";
                    }
                    data.push([no,result[i].kma,result[i].nm_jk,result[i].nm_um,result[i].nm_bd,result[i].nama_kegiatan,result[i].tujuan_kegiatan,stt,'<div class="btn-group" role="group" aria-label="Basic example">'+link_detail+'</div>']);
                }
                $('#tabel_data_pka').DataTable({
                    //"bJQueryUI"     : true,
                    data                : data,
                    deferRender         : true,
                    processing          : true,
                    ordering            : true,
                    retrieve            : false,
                    paging              : true,
                    deferLoading        : 57,
                    bDestroy            : true,
                    autoWidth           : false,
                    bFilter             : true,
                    iDisplayLength      : 10,
                    responsive: true,
                    language: {
                      searchPlaceholder: 'Cari',
                      sSearch: '',
                      lengthMenu: '_MENU_',
                    },
                });
            },
                error: function(jqXHR, textStatus, errorThrown) {
                  $('#loading').modal('show');
                        Command: toastr["error"](errorThrown, "Error");
                },
                beforeSend: function () {
                  $('#loading').modal('show');
                },
                complete: function () {
                    $('#loading').modal('hide');
                }
        });
    }
    data_pka("all");
    acc = function(no_pka){
      bootbox.confirm("Apakah Anda Yakin Akan Meng-ACC Data?", function(result){ 
        if (result==true) {
          // alert(kode_pka)
          $.ajax({ 
            url: base_url + 'pka/acc_pka_admin/',
            type: "post",
            data:{no_pka:no_pka},
            dataType: "json",
            async : 'false',
            success: function(result){
              if (result === true) {
                Command: toastr["success"]("Selamat Anda Berhasil Meng-ACC Data", "Berhasil");
                getcontens('page/data_evaluasi_pka_admin');
              }else{
                Command: toastr["info"]("Gagal Input Data", "Info");
              }
            },
            error: function(jqXHR, textStatus, errorThrown) {
                  $('#loading').modal('show');
                        Command: toastr["error"](errorThrown, "Error");
                },
                beforeSend: function () {
                  $('#loading').modal('show');
                },
                complete: function () {
                    $('#loading').modal('hide');
                }
          })
        }
      });
    }
    Revisi_evaluasi = function(no_pka){
      bootbox.prompt({
        title: "Masukkan pesan untuk user terkait!",
        inputType: 'textarea',
        callback: function (result) {
          if (result !=null) {
            $.ajax({ 
                url: base_url + 'pka/refisi_ev_pka_admin',
                type: "post",
                data:{no_pka:no_pka,message:result},
                dataType: "json",
                async : 'false',
                success: function(result){
                  if (result === true) {
                    Command: toastr["success"]("Selamat Anda Berhasil Mengirim Data Revisi", "Berhasil");
                    getcontens('page/data_evaluasi_pka_admin');
                  }else{
                    Command: toastr["info"]("Gagal Input Data", "Info");
                  }
                },
                error: function(jqXHR, textStatus, errorThrown) {
                      $('#loading').modal('show');
                            Command: toastr["error"](errorThrown, "Error");
                    },
                    beforeSend: function () {
                      $('#loading').modal('show');
                    },
                    complete: function () {
                        $('#loading').modal('hide');
                    }
              })
          }
        }
      });
    }
    acc_evaluasi = function(no_pka){
      bootbox.confirm("Apakah Anda Yakin Akan Meng-ACC Data Evaluasi?", function(result){ 
        if (result==true) {
              $.ajax({ 
                url: base_url + 'pka/acc_ev_pka_admin',
                type: "post",
                data:{no_pka:no_pka},
                dataType: "json",
                async : 'false',
                success: function(result){
                  if (result === true) {
                    Command: toastr["success"]("Selamat Anda Berhasil Meng-ACC Data Revisi", "Berhasil");
                    getcontens('page/data_evaluasi_pka_admin');
                  }else{
                    Command: toastr["info"]("Gagal Input Data", "Info");
                  }
                },
                error: function(jqXHR, textStatus, errorThrown) {
                      $('#loading').modal('show');
                            Command: toastr["error"](errorThrown, "Error");
                    },
                    beforeSend: function () {
                      $('#loading').modal('show');
                    },
                    complete: function () {
                        $('#loading').modal('hide');
                    }
              })
        }
      })
    }
    hapus_pka = function(no_pka){
      bootbox.confirm("Apakah Anda Yakin Akan Menghapus Data?", function(result){ 
        if (result==true) {
          $.ajax({ 
            url: base_url + 'pka/hapus_pka_admin',
            type: "post",
            data:{no_pka:no_pka,message:result},
            dataType: "json",
            async : 'false',
            success: function(result){
              if (result === true) {
                Command: toastr["success"]("Selamat Anda Berhasil Menghapus Data", "Berhasil");
                getcontens('page/data_pka_admin');
              }else{
                Command: toastr["info"]("Gagal Input Data", "Info");
              }
            },
            error: function(jqXHR, textStatus, errorThrown) {
                  $('#loading').modal('show');
                        Command: toastr["error"](errorThrown, "Error");
                },
                beforeSend: function () {
                  $('#loading').modal('show');
                },
                complete: function () {
                    $('#loading').modal('hide');
                }
          })
        }
      });
    }
    kirim_evaluasi_pka = function(no_pka){
      bootbox.confirm("Apakah Anda Yakin Akan Mengirim Evaluasi?", function(result){ 
        if (result==true) {
          $.ajax({ 
            url: base_url + 'pka/kirim_evaluasi_pka_admin',
            type: "post",
            data:{no_pka:no_pka,message:result},
            dataType: "json",
            async : 'false',
            success: function(result){
              // alert(JSON.stringify(result))
              if (result === true) {
                Command: toastr["success"]("Selamat Anda Berhasil Mengirim Evaluasi", "Berhasil");
                getcontens('page/data_pka_admin');
              }else{
                Command: toastr["info"]("Gagal Input Data", "Info");
              }
            },
            error: function(jqXHR, textStatus, errorThrown) {
                  $('#loading').modal('show');
                        Command: toastr["error"](errorThrown, "Error");
                },
                beforeSend: function () {
                  $('#loading').modal('show');
                },
                complete: function () {
                    $('#loading').modal('hide');
                }
          })
        }
      });
    }
  });
</script>
