<!-- 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 PKA PHMJ</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 >Unit Misioner / Email</th>


                          <th>Jumlah Kegiatan</th>


                          <th style="width:140px;">Pada</th>


                          <th style="width:180px;">Oleh</th>


                          <th style="width: 130px;">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('/','-'));


    })


    data_pka = function(periode_thn){


        $('#tabel_produk').hide();


        $.ajax({ 


            url: base_url + 'pka/data_pka_admin/'+periode_thn,


            type: "post",


            // data:{<?php echo $this->security->get_csrf_token_name(); ?>:'<?php echo $this->security->get_csrf_hash(); ?>'},


            // data:{},


            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;


                    if(result[i].acc == "0"){


                      var link_acc = `<a href="javascript:void(0)" onclick="acc('`+result[i].no_pka+`')" class="btn btn-success btn-icon-split btn-sm" title="ACC">


                                        <span class="icon text-white-50">


                                          <i class="fas fa-file-signature"></i>


                                        </span>


                                      </a>`;


                      var link_refisi = `<a href="javascript:void(0)" onclick="refisi('`+result[i].no_pka+`')" class="btn btn-secondary btn-icon-split btn-sm" title="Revisi">


                                        <span class="icon text-white-50">


                                          <i class="fas fa-file-prescription"></i>


                                        </span>


                                      </a>`;


                    }else{


                      var link_acc = "";


                      var link_refisi ="";


                    }


                    


                    // var satuan;


                    // if(result[i].satuan == 1){


                    //     satuan = 'Pcs';


                    // }else{


                    //     satuan = 'Kg';


                    // }


                    // var link_edit = "<a href='javascript:void(0)' onclick=\"getpopup('aksesoris/edit','"++"','popupedit','"+result[i].id_kma+"');\"><span class='btn btn-info fa fa-edit' title='Edit Aksesoris'></span></a>";


                    var link_detail = `<a href="#" onclick="getcontens('page/detail_pka_phmj','`+result[i].no_pka+`');" class="btn btn-primary btn-icon-split btn-sm" title="Detail">


                                        <span class="icon text-white-50">


                                          <i class="fas fa-eye"></i>


                                        </span>


                                      </a>`;


                    var id_row = result[i].kode_pka+','+result[i].no_pka+','+result[i].periode_thn;


                    var link_edit = `<a href="#" onclick="getcontens('page/edit_pka_admin','`+id_row+`');" class="btn btn-info btn-icon-split btn-sm" title="Edit">


                                        <span class="icon text-white-50">


                                          <i class="fas fa-edit"></i>


                                        </span>


                                      </a>`;


                    


                    var link_hapus = `<a href="javascript:void(0)" onclick="hapus_pka('`+result[i].no_pka+`')" class="btn btn-danger btn-icon-split btn-sm" title="Hapus">


                                        <span class="icon text-white-50">


                                          <i class="fas fa-trash-alt"></i>


                                        </span>


                                      </a>`;


                    if(result[i].acc == "1" & result[i].evaluasi == "0"){


                      var link_evaluasi = `<a href="javascript:void(0)" onclick="kirim_evaluasi_pka('`+result[i].no_pka+`')" class="btn btn-warning btn-icon-split btn-sm" title="Kirim Evaluasi">


                                        <span class="icon text-white-50">


                                          <i class="fas fa-paper-plane"></i>


                                        </span>


                                      </a>`;


                    }else{


                      var link_evaluasi = `<a href="javascript:void(0)" class="btn btn-warning btn-icon-split btn-sm disabled" title="Kirim Evaluasi">


                                        <span class="icon text-white-50">


                                          <i class="fas fa-paper-plane"></i>


                                        </span>


                                      </a>`;


                    }











                    if (result[i].acc == "0") {


                      var status = `


                        <span class="mr-2">


                          <i class="fas fa-circle text-warning"></i> Sedang Diproses


                        </span>`;


                    }else if(result[i].acc == "1"){


                      var status = `


                        <span class="mr-2">


                          <i class="fas fa-circle text-success"></i> Berhasil Diterima


                        </span>`;


                    }else{


                      var status = `


                        <span class="mr-2">


                          <i class="fas fa-circle text-danger"></i> Revisi


                        </span>`;


                    }


                    if (result[i].evaluasi == "1" & result[i].acc == "1") {


                      var ev = `


                      <span class="mr-2">


                          <i class="fas fa-circle text-info"></i> Sudah Evaluasi


                        </span>`;


                    }else if (result[i].evaluasi == "2" & result[i].acc == "1") {


                      var ev = `


                      <span class="mr-2">


                          <i class="fas fa-circle text-primary"></i> Sedang Evaluasi


                        </span>`;


                    }else if (result[i].evaluasi == "0" & result[i].acc == "1") {


                      var ev = `


                      <span class="mr-2">


                          <i class="fas fa-circle text-secondary"></i> Belum Evaluasi


                        </span>`;


                    }else{


                      var ev = ``;


                    }


                    ////////////////////


                    if (result[i].updateby == null) {


                      var updateby = "";


                    }else{


                      var updateby = `<span><i class="fas fa-edit text-info"></i>`+result[i].updateby+`</span>`;


                    }


                    var oleh =`<span><i class="fas fa-plus text-primary"></i> `+result[i].username+`</span><br>`+updateby





                    var waktu_buat = `<span title="`+result[i].tgl_buat+" "+result[i].waktu_buat+`"><i class="fas fa-plus text-primary"></i> `+result[i].tgl_buat+"</span>";


                    if (result[i].tgl_update =="") {


                      waktu_update ="";


                    }else{


                      var waktu_update = `<span title="`+result[i].tgl_update+" "+result[i].waktu_update+`"><i class="fas fa-edit text-info"></i>`+result[i].tgl_update+"</span>";


                    }








                    var d ='<div class="btn-group" role="group" aria-label="Basic example">';


                    var dd = '</div>';


                    data.push([no,result[i].nm_um+"<br>"+result[i].email,result[i].jml+" Kegiatan",waktu_buat+"<br>"+waktu_update,oleh,status+"<br>"+ev,d+link_detail/*+" "+link_edit+" "+link_acc+" "+link_refisi+" "+link_evaluasi+" "+link_hapus*/+dd]);


                }


                $('#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_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');


                }


          })


        }


      });


    }


    refisi = 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_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 Refisi", "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');


                }


          })


      }


    }


});








    }





    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>


