<!-- 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 Request Revisi PKA</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="table-responsive">


                <table class="table table-bordered" id="tabel_data_pka" width="100%" cellspacing="0">


                  <thead>


                    <tr>


                      <th>No</th>


                      <th>Unit Misioner</th>


                      <th>Periode</th>


                      <th>No PKA</th>


                      <th>Alasan</th>


                      <th>Pada</th>


                      <th>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>


<script type="text/javascript">


$(document).ready(function(){


    


    var base_url = "<?=base_url()?>";


    


    var data_pka = function(){


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


        $.ajax({ 


            url: base_url + 'Request_revisi_pka/data_request_revisi_pka',


            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)


                    var no = i+1;





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


                      $status =`<span class="mr-2">


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


                                </span>`;





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


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


                                          <i class="fas fa-vote-yea"></i>


                                        </span>


                                      </a>`;


                      var link_tolak = `<a href="javascript:void(0)" onclick="tolak('`+result[i].id_req_rev+`');" class="btn btn-danger btn-icon-split btn-sm" title="Tolak">


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


                                          <i class="fas fa-window-close"></i>


                                        </span>


                                      </a>`;


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


                      $status =`<span class="mr-2">


                                  <i class="fas fa-circle fa-sm text-success"></i> Disetujui


                                </span>`;


                      var link_acc = ``;


                      var link_tolak = ``;


                    }else{


                      $status =`<span class="mr-2">


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


                                </span>`;


                      var link_acc = ``;


                      var link_tolak = ``;


                    }


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


                    var dd = `</div>`;


                    data.push([no,result[i].nama_um,result[i].periode_thn,result[i].no_pka,result[i].alasan,result[i].tgl_buat,result[i].username,$status,d+link_acc+" "+link_tolak+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_',


                    },


                });


               


            },


            beforeSend: function () {





            },


            complete: function () {


                // $('#tabel_produk').show();


            }


        });


    }


    data_pka();





    acc = function(id_req_rev,no_pka){


      bootbox.confirm("Apakah Anda Yakin Akan Menyetujui revisi?", function(result){ 


        if (result==true) {


          $.ajax({ 


            url: base_url + 'Request_revisi_pka/terima_revisi',


            type: "post",


            data:{id_req_rev:id_req_rev,no_pka:no_pka},


            dataType: "json",


            async : 'false',


            success: function(response){


              if(response == true){


                Command: toastr["success"]("Data Request Berhasil Diterima", "Berhasil");


                getcontens('page/data_req_rev_admin');


              }else{


                Command: toastr["error"]("Simpan error, data tidak berhasil diterima", "Error");


              }


            }


          })


        }


      })


    }


    tolak = function(id_req_rev){


      bootbox.confirm("Apakah Anda Yakin Akan Menolak revisi?", function(result){ 


        if (result==true) {


          $.ajax({ 


            url: base_url + 'Request_revisi_pka/tolak_revisi',


            type: "post",


            data:{id_req_rev:id_req_rev},


            dataType: "json",


            async : 'false',


            success: function(response){


               if(response == true){


                Command: toastr["success"]("Data Request Berhasil Ditolak", "Berhasil");


                getcontens('page/data_req_rev_admin');


              }else{


                Command: toastr["error"]("Simpan error, data tidak berhasil ditolak", "Error");


              }


            }


          })


        }


      })


    }


  });


</script>


