<style type="text/css">
  table.dataTable tr.DTTT_selected {
    background-color: #9FAFD1;
}
</style>
                <!-- Content Header (Page header) -->
                <section class="content-header">
                    <h1>
                        Manage Hapus Mahasiswa
                    </h1>
                        <ol class="breadcrumb">
                        <li><a href="<?=base_index();?>"><i class="fa fa-dashboard"></i> Home</a></li>
                        <li><a href="<?=base_index();?>hapus-mahasiswa">Hapus Mahasiswa</a></li>
                        <li class="active">Hapus Mahasiswa List</li>
                    </ol>
                </section>

                <!-- Main content -->
                <section class="content">
                    <div class="row">
                        <div class="col-xs-12">
                            <div class="box">
                             
                                <div class="box-body table-responsive">

<div class="box box-danger">
            <div class="box-header with-border">
              <h3 class="box-title">Filter</h3>
            </div>
            <div class="box-body">
           <form class="form-horizontal">
                      <div class="form-group" id="show_angkatan">
                        <label for="Semester" class="control-label col-lg-2">Angkatan</label>
                        <div class="col-lg-3" >
                        <select id="angkatan_awal" name="angkatan_awal" data-placeholder="Pilih Angkatan ..." class="form-control chzn-select" tabindex="2" style="z-index: 1" required="">
 <?php 
              $url_rest = get_service_url('rest');
              $temp_data_semester = [
                'act' => 'GetSemester',
                  'token' => get_token(),
                  'filter' => "a_periode_aktif='1' and right(id_semester,1) in('1','2')",
                  'order' => 'id_semester desc'
              ];

            $temp_rec = json_decode($db->run($temp_data_semester,$url_rest));
            dump($temp_rec);

               $semester = $db->fetch_custom('select *,left(semester,4) as smt from semester order by semester desc');
               $sem_akhir =  $db->fetch_custom('select *,left(semester,4) as smt from semester order by semester desc');
                    foreach ($semester as $isi) {
                      if ($temp_rec->data[0]->id_semester==$isi->semester) {
                          echo "<option value='".$isi->semester."' selected>".$isi->nama_semester."</option>";
                          $smt_selected = $isi->semester;    
                        } else {
                          echo "<option value='".$isi->semester."'>".$isi->nama_semester."</option>";    
                        }
                      }
                       ?>
                        </select>
                      </div> 
                      <div class="col-lg-2" style="width: 20px;padding: 0;padding-top: 7px;">S/D</div>
                        <div class="col-lg-3" >
                        <select id="angkatan_akhir" name="angkatan_akhir" data-placeholder="Pilih Angkatan ..." class="form-control chzn-select" tabindex="2" style="z-index: 1" required="">
                        <?php    
                        foreach ($sem_akhir as $isi) {
                      if ($temp_rec->data[0]->id_semester==$isi->semester) {
                          echo "<option value='".$isi->semester."' selected>".$isi->nama_semester."</option>";
                          $smt_selected = $isi->semester;    
                        } else {
                          echo "<option value='".$isi->semester."'>".$isi->nama_semester."</option>";    
                        }
                      } ?>
                        </select>
                      </div>
                      </div><!-- /.form-group -->
<div class="form-group" id="show_prodi">
                                        <label for="Semester" class="control-label col-lg-2">Prodi</label>
                                        <div class="col-lg-5">
                                        <select id="jurusan" name="jurusan" data-placeholder="Pilih Semester ..." class="form-control chzn-select" tabindex="2">
                               <?php 
 $jurusan_sms = "";
        if ($_SESSION['level']!=1) {
              $jurusan_sms = "where id_sms='".$_SESSION['id_sms']."'";
        }  else {
          echo '<option value="all">Semua</option>';
        }
foreach ($db->fetch_custom("select * from jurusan $jurusan_sms") as $isi) {
                                  echo "<option value='$isi->id_sms'>$isi->jenjang $isi->nama_jurusan</option>";
                               } ?>
                              </select>
 <div id="error_prodi"></div>
                 </div>
                                      </div><!-- /.form-group -->
<div class="form-group">
                        <label for="Jenis Pendaftaran" class="control-label col-lg-2">Jenis Pendaftaran</label>
                        <div class="col-lg-5">
                          <select name="id_jns_daftar" id="id_jns_daftar" data-placeholder="Pilih Jenis Pendaftaran ..." class="form-control chzn-select" tabindex="2" >
               <option value="all">Semua</option>
               <?php foreach ($db->fetch_custom("select * from jenis_pendaftaran") as $isi) {
                echo "<option value='$isi->id_jns_daftar'>$isi->nm_jns_daftar</option>";
               } ?>
              </select>
                        </div>
                      </div><!-- /.form-group -->
<div class="form-group" id="show_status">
              <label for="Semester" class="control-label col-lg-2">Status Mahasiswa</label>
              <div class="col-lg-6">
              <select id="status_mhs" name="status_mhs" data-placeholder="Kosongkan Jika Semua Status ..." class="form-control chzn-select" tabindex="2" multiple="">
              <option value="AKTIF">Aktif</option>
     <?php foreach ($db->fetch_custom("select * from jenis_keluar") as $isi) {
echo "<option value='$isi->id_jns_keluar'>$isi->ket_keluar</option>";
} ?>
    </select>

</div>
            </div><!-- /.form-group -->
 <div class="form-group">
                        <label for="Semester" class="control-label col-lg-2">Pencarian</label>
                        <div class="col-lg-5" >
                        <select id="pencarian" name="pencarian" data-placeholder="Pilih Pencarian ..." class="form-control chzn-select" tabindex="2" style="z-index: 1" required="">
                        <option value="all">Semua</option>
                        <option value="nim">Cari berdasarkan NIM</option>
                        <option value="nama">Cari berdasarkan NAMA</option>
                        <option value="nik">Cari berdasarkan NIK</option>
                        <option value="no_history">Cari/Tampilkan Mahasiswa Tidak Punya Prodi/History</option>
                         <option value="no_nik">Cari/Tampilkan Mahasiswa Tidak Punya NIK</option>
              </select>
            </div>
            <div class="col-lg-4" style="padding-left: 0;">
              <input type="text" name="keyword" id="keyword" class="form-control" placeholder="Input Keyword Pencarian" style="display: none" required="">
              <div id="error_nim"></div>
            </div>
              
                      </div><!-- /.form-group -->
                      <div class="form-group">
                        <label for="tags" class="control-label col-lg-2">&nbsp;</label>
                        <div class="col-lg-10">
                          <span id="filter" class="btn btn-primary btn-flat">Submit</span>
                        </div>
                      </div><!-- /.form-group -->
                    </form>
            </div>
            <!-- /.box-body -->
          </div>

<!-- <div class="alert alert-info alert-dismissible" style="margin-bottom:5px">
<div id="progressBarCoba"></div>
</div>

<button class="btn btn-primary hapus_coba">Hapus Coba</button>
 -->
<div class="box-body showing-progress" style="display: none">
              <div class="row" id="show_progress" >
               <div class="col-md-12">
                 <span class='current-count-progress'></span> <!-- <span class="pull-right">Please wait...</span> -->
                        <div class="progress" style="margin-bottom:2px">

                          <div class="progress-bar progress-bar-striped" id="progressbar" role="progressbar"  aria-valuemin="0" aria-valuemax="100" style="width: 10%">
                            10%
                          </div>
                        </div></div>
</div>
<div class="alert alert-info alert-dismissible" style="margin-bottom:5px">
<div id="progressBarServer"></div>
</div>
<a href="<?=base_index();?>hapus-mahasiswa" class="btn btn-default batal" style=""><i class="fa fa-reply"></i> Batal Hapus</a>
</div>
<div class="callout callout-danger">
<h4>Informasi!</h4>
<p>Data yang tampil adalah data yang diambil langsung dari NEO FEEDER, mohon berhati - hati jika anda mau hapus data.</p>
</div>
<div class="row" id="aksi_top_krs" style="display: none">
    <div class="col-sm-5" style="margin-bottom: 10px;">
      
      <div class="input-group input-group-sm">
          <span class="input-group-btn">
            <button type="button" class="btn btn-danger btn-flat selected-data">Terpilih</button>
          </span>
       <select class="form-control col-lg-5" name="aksi_krs" id="aksi_krs">
      <option value="biodata">Hapus Biodata dan History</option>
      <option value="history">Hapus Hanya History </option>
      <option value="edit_history" class="edit_history">Edit History</option>
    </select>
          <span class="input-group-btn">
            <button type="button" class="btn btn-primary btn-flat submit-proses">Submit</button>
          </span>
    </div>
    </div>
</div>
                          <table id="dtb_hapus_mhs" class="table table-bordered table-striped" width="100%">
                                   <thead>
                                     <tr>    
                 <!--        <th><input type="checkbox"  id="bulkDelete"  /> <button id="deleteTriger"><i class="fa fa-trash"></i></button></th> -->
      <th style="padding-right:0;width: 4%"><label class="mt-checkbox mt-checkbox-single mt-checkbox-outline "> <input type="checkbox" class="group-checkable bulk-check"> <span></span></label></th>
       <th>Status</th>
                          <th>Nama</th>              
                          <th>NIM</th>
                          <th>Nama Ibu</th>
                          <th>Tanggal Lahir </th>
                          <th>Tempat Lahir</th>
                          <th>Angkatan</th>
                          <th>Status</th>
                          <th>SMT Keluar</th>
                          <th>NIK</th>
                          <th>Prodi</th>
                        </tr>
                                      </thead>
                                        <tbody>
                                        </tbody>
                                    </table>
                                                     
                                </div><!-- /.box-body -->
                            </div><!-- /.box -->
                        </div>
                    </div>
<div class="modal modal-danger" id="mass_info" data-backdrop="static" data-keyboard="false" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div class="modal-dialog"> <div class="modal-content"><div class="modal-header"> <h4 class="modal-title">Hapus Data Massal</h4> </div> <div class="modal-body" style="height: 100px"> 
<div class="form-group" style="margin-bottom:38px">
                        <label style="padding-top:6px" for="Jurusan" class="control-label col-lg-2">Angkatan</label>
                        <div class="col-lg-10">
                          <select  name="sem_delete" id="sem_delete"  class="form-control " tabindex="2" required>
<?php 
               $semester = $db->fetch_custom('select *,left(semester,4) as smt from semester where right(semester,1) not in (0,3) order by semester desc');
                    foreach ($semester as $isi) {
                      if ($isi->smt <= date('Y')) {
                  echo "<option value='".$isi->semester."'>".$isi->nama_semester."</option>";      
                      }
                  } ?>
              </select>
                        </div>
<input type="hidden" id="semester_selected">
                      </div><!-- /.form-group -->
<div class="form-group">
                                        <label for="Semester" class="control-label col-lg-2">Prodi</label>
                                        <div class="col-lg-10">
                                        <select id="jurusan_delete" name="jurusan_delete" data-placeholder="Pilih Semester ..." class="form-control" tabindex="2">
                                               <?php 
 $jurusan_sms = "";
        if ($_SESSION['level']!=1) {
              $jurusan_sms = "where id_sms='".$_SESSION['id_sms']."'";
        }  else {
          echo '<option value="all">Semua</option>';
        }
foreach ($db->fetch_custom("select * from jurusan $jurusan_sms") as $isi) {
                                  echo "<option value='$isi->id_sms'>$isi->jenjang $isi->nama_jurusan</option>";
                               } ?>
                              </select>
 <div id="error_prodi"></div>
                 </div>
                                      </div><!-- /.form-group -->
 </div> <div class="modal-footer"> <button type="button" id="delete_mhs_massal" class="btn btn-danger">Delete</button> <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button> </div> </div><!-- /.modal-content --> </div><!-- /.modal-dialog --> </div><!-- /.modal -->
     <div class="modal" id="modal_history" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div class="modal-dialog modal-lg"> <div class="modal-content"><div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true"><i class="glyphicon glyphicon-remove"></i></span></button> <h4 class="modal-title">Edit History Pendidikan Mahasiswa</h4> </div> <div class="modal-body" id="isi_perhitungan"> </div> </div><!-- /.modal-content --> </div><!-- /.modal-dialog --> </div>
        <?php
      
      
  foreach ($db->fetch_all("sys_menu") as $isi) {

  //jika url = url dari table menu
  if ($path_url==$isi->url) {
   if ($role_act["up_act"]=="Y") {
  $edit = '<a href="'.base_index()."hapus-mahasiswa/edit/'+aData[indek]+'".'" class="btn btn-primary btn-flat"><i class="fa fa-pencil"></i></a>';
  } else {
    $edit ="";
  }
  if ($role_act['del_act']=='Y') {
   $del = "<span data-id='+aData[indek]+' data-uri=".base_admin()."modul/hapus_mahasiswa/hapus.php".' class="btn btn-danger hapus_mahasiswa_feeder btn-flat"><i class="fa fa-trash"></i></span>';
  } else {
    $del="";
  }
                   } 
  }
  
?>  
                </section><!-- /.content -->
        <script type="text/javascript">

var table_mhs = $("#dtb_hapus_mhs").DataTable({
           'bProcessing': true,
            'searching': false,
            'bServerSide': true,
               "ordering": false,
                 "columnDefs": [ {
              "targets": [0],
              "orderable": false,
              "searchable": true

            } ],
            "ajax":{
              url :"<?=base_admin();?>modul/hapus_mahasiswa/hapus_mahasiswa_data.php",
            type: "post",  // method  , by default get
            data: function ( d ) {
                d.angkatan = $("#sem_filter").val();
                d.status_mhs = $("#status_mhs").val();
                d.angkatan_awal = $("#angkatan_awal").val();
                d.angkatan_akhir = $("#angkatan_akhir").val();
                d.pencarian = $("#pencarian").val();
                d.keyword = $("#keyword").val();
                  d.status_sync = $("#status_sync").val();
                d.id_jns_daftar = $("#id_jns_daftar").val();
             <?php
            if ($_SESSION['level']!=1) {
              ?>
              d.jurusan = "<?=$_SESSION['id_sms'];?>";
              <?php
            } else {
              ?>
              d.jurusan =  $("#jurusan").val();
              <?php
            }
            ?>
            },
          error: function (xhr, error, thrown) {
            console.log(xhr);
              $(".dtb_akm-error").html("");
              $("#dtb_akm").append('<tbody class="dtb_akm-error"><tr><th colspan="9">No data found in the server</th></tr></tbody>');
              $("#dtb_akm_processing").css("display","none");

            }
          },
          "language": {
             searchPlaceholder: "Pencarian dengan NIM atau Nama",
          "processing": "<i class=\"fa fa-spinner fa-spin\"></i> Loading data, please wait..." //add a loading image,simply putting <img src="loader.gif" /> tag.
   },

        });
$(document).ready(function() {
  $.fn.modal.Constructor.prototype.enforceFocus = function() {};
  $("#pencarian").change(function(){
    if (this.value=='all') {
      $("#keyword").hide();
      $("#keyword").val('');
      $("#pencarian").parent().parent().removeClass('has-error');
      $("#error_nim").html('');
      $("#show_angkatan").show();
      $("#show_status").show();
      $("#show_prodi").show();
    } else {
      $("#show_angkatan").hide();
      $("#show_status").hide();
      $("#show_prodi").hide();
      $("#keyword").show();
      if (this.value=='nim') {
        $("#keyword").attr("placeholder", "Isikan NIM Mahasiswa dicari");
      } else if (this.value=='nama') {
        $("#keyword").attr("placeholder", "Isikan Nama Mahasiswa dicari");
      } else if (this.value=='nik') {
        $("#keyword").attr("placeholder", "Isikan NIK Mahasiswa dicari");
      } else if (this.value=='no_nik') {
        $("#show_angkatan").show();
        $("#show_status").show();
        $("#show_prodi").show();
        $("#keyword").attr("placeholder", "");
        $("#keyword").val('');
        $("#keyword").hide();
      } else {
        $("#keyword").attr("placeholder", "");
        $("#keyword").val('');
        $("#keyword").hide();
      }
    }
  });



//filter
$('#filter').on('click', function() {
    if($("#keyword").is(":visible") && $("#keyword").val()=="") {
      $("#pencarian").parent().parent().addClass('has-error');
      $("#error_nim").html('<span for="nim" class="help-block">Silakan isi Keyword Pencarian</span>');
      return;
    }
    if($("#keyword").is(":visible") && $("#keyword").val()!="") {
      $("#pencarian").parent().parent().removeClass('has-error');
       $("#error_nim").html('');
    }
  table_mhs.ajax.reload();
});

$("#bulkDelete").on('click',function() { // bulk checked
          var status = this.checked;
          $(".deleteRow").each( function() {
            $(this).prop("checked",status);
          });
        });


$('#delete_mhs_massal').on("click", function(event){
  event.preventDefault();
   $('#mass_info').modal('hide');
    $("#loadnya").show();

          $.ajax({
              type: "POST",
              url: "<?=base_admin();?>modul/hapus_mahasiswa/hapus.php?act=delete_all",
              data: {data_ids:$("#sem_delete").val(),jurusan:  $("#jurusan_delete").val()},
               async: true,
              success: function(result) {
               // console.log(result);
                $("#loadnya").hide();
                window.location.reload();
              },
              async:true
            });
        });

    $(".table").on('click','.hapus_mahasiswa_feeder',function(event) {

    event.preventDefault();
    var currentBtn = $(this);

    uri = currentBtn.attr('data-uri');
    id = currentBtn.attr('data-id'); 
    

    $('#ucing')
        .modal({ keyboard: false })
        .one('click', '#delete', function (e) {
        $("#loadnya").show();
                $.ajax({
          type: "POST",
          url: uri+"?act=delete&id="+id,
          success: function(data){
             $("#loadnya").hide();
              console.log(data);
              table_mhs.draw(false);
          }
          });
          $('#ucing').modal('hide');

        });

  });




$(".bulk-check").on('click',function() { // bulk checked
          var status = this.checked;
          if (status) {
            select_deselect('select');
          } else {
            select_deselect('unselect');
          }
          
          $(".check-selected").each( function() {
            $(this).prop("checked",status);
          });
        });

  function init_selected() {
      var selected = check_selected();
      var btn_hide = $('#aksi_top_krs');
      if (selected.length > 0) {
          btn_hide.show()
      } else {
          btn_hide.hide()
      }
  }
 function check_selected() {
      var table_select = $('#dtb_hapus_mhs tbody tr.selected');
      var array_data_delete = [];
      table_select.each(function() {
          var check_data = $(this).find('.data_selected_id').attr('data-id');
          if (typeof check_data != 'undefined') {
              array_data_delete.push(check_data)
          }
      });
      $('.selected-data').text(array_data_delete.length + ' Data Terpilih');
      $(".edit_history").show();
      $(".edit_biodata").show();
      if (array_data_delete.length>1) {
            $(".edit_history").hide();
            $(".edit_biodata").hide();
          }
      return array_data_delete
  }
  

  function select_deselect(type) {
      if (type == 'select') {
          $('#dtb_hapus_mhs tbody tr').addClass('DTTT_selected selected')
      } else {
          $('#dtb_hapus_mhs tbody tr').removeClass('DTTT_selected selected')
      }
    init_selected()
  }
  $(document).on('click', '#dtb_hapus_mhs tbody tr .check-selected', function(event) {
      var btn = $(this).find('button');
      if (btn.length == 0) {
          $(this).parents('tr').toggleClass('DTTT_selected selected');
          var selected = check_selected();
            $(".edit_history").show();
            $(".edit_biodata").show();
          if (selected.length>1) {
            $(".edit_history").hide();
            $(".edit_biodata").hide();
          }
          console.log(selected.length);
          init_selected();

      }
  });

var messagesArray = [];  // Array to store the messages
var sukses = 0;
var gagal = 0;
var start_time;

// Chunk size
var chunkSize = 5;

function generateSessionName() {
    // Generate a random 10-character hex string (similar to bin2hex(random_bytes(5)) in PHP)
    const randomString = [...Array(10)].map(() => Math.floor(Math.random() * 16).toString(16)).join('');

    // Generate a unique ID based on the current timestamp (similar to uniqid in PHP)
    const uniqueId = Date.now().toString(36) + Math.random().toString(36).substr(2, 9);

    // Combine both to form the session name
    return randomString + uniqueId;
}

// Function to send chunks of data
function sendChunks(dataArray,aksi) {
    var total = dataArray.length;
    var numChunks = Math.ceil(total / chunkSize); // Calculate total number of chunks

    function processChunk(chunkIndex) {
        if (chunkIndex >= numChunks) {
            // All chunks processed
            showFinalReport();
            return;
        }

        // Calculate the chunk data
        var start = chunkIndex * chunkSize;
        var end = Math.min(start + chunkSize, total);
        var chunkData = dataArray.slice(start, end); // Get the current chunk
        var session_name = generateSessionName();

        $.ajax({
            type: 'POST',
            url: '<?=base_admin();?>modul/hapus_mahasiswa/set_session.php?act=set',
            data: { data: chunkData,sess_name:session_name },  // Send the chunk of data
             async: false,  
            success: function(result) {
              //session_name = result;
            }
        });
        // Send the chunk using SSE
       // var eventSource = new EventSource('<?=base_admin();?>modul/hapus_mahasiswa/hapus.php?act=del_massal&data_ids=' + chunkData.join());
        //var eventSource = new EventSource('<?=base_admin();?>modul/hapus_mahasiswa/hapus_coba.php?name='+session_name);
        if (aksi==='biodata') {
          var eventSource = new EventSource('<?=base_admin();?>modul/hapus_mahasiswa/delete_biodata.php?name='+session_name);
        } else {
          var eventSource = new EventSource('<?=base_admin();?>modul/hapus_mahasiswa/delete_history.php?name='+session_name);
        }
        

        // Listen for events
        eventSource.onmessage = function(event) {
          console.log(event);
            var data = JSON.parse(event.data);

            // Handle progress update
            if (data.status === 'success') {
                $("#progressBarServer").html(data.message + "<br>");
                sukses ++;
            } else if (data.status === 'error') {
                $("#progressBarServer").append(data.message + "<br>");
                messagesArray.push(data.message);
                gagal ++;
            } else if (data.status === 'proses') {
                $("#progressBarServer").html(data.message + "<br>");
                messagesArray.push(data.message);
            }

            // Update the progress bar
            var persen = (((chunkIndex + 1) / numChunks) * 100).toFixed(1);
            $(".current-count-progress").html("Sedang Proses Hapus " + (chunkIndex+1)*chunkData.length + "/" + numChunks*chunkData.length);
            $("#progressbar").css("width", persen + "%");
            $("#progressbar").html(persen + "%");

            // Check if all chunks are processed
            if (data.status === 'complete') {
                eventSource.close();
                processChunk(chunkIndex + 1); // Move to the next chunk
            }
        };

        // Handle errors
        eventSource.onerror = function(event) {
         console.error('SSE error occurred:', event);
          //$("#progressBarServer").html(event);
            console.log("Error receiving updates for chunk " + chunkIndex);
            eventSource.close();
            processChunk(chunkIndex + 1); // Continue to next chunk even if there's an error
        };
    }

    processChunk(0);  // Start processing the first chunk
}

$('.submit-proses').click(function() {
    var data_array_id = check_selected();  // Get selected IDs
    if (data_array_id.length === 0) return; // If no data selected, do nothing

    if ($("#aksi_krs").val()=='edit_history' || $("#aksi_krs").val()=='edit_biodata') {
      var all_ids = data_array_id.toString();
      aksi = $("#aksi_krs").val();
        $("#loadnya").show();
         var id = $(this).data("id");
            $.ajax({
          type: "POST",
          url: "<?=base_admin();?>modul/hapus_mahasiswa/edit.php",
          data: {aksi: aksi, data_ids:all_ids},
          success: function(result) {
            $("#loadnya").hide();
            $('#isi_perhitungan').html(result);
          }
        });

      $('#modal_history').modal({ keyboard: false,backdrop:'static' });
    } else {
      start_time = new Date().getTime();  // Start the timer
      aksi = $("#aksi_krs").val();
      $('.showing-progress').show();  // Show progress section
      sendChunks(data_array_id,aksi);  // Start sending data in chunks
    }
});

function millisToMinutesAndSeconds(s) {
    var ms = s % 1000;
    s = (s - ms) / 1000;
    var secs = s % 60;
    s = (s - secs) / 60;
    var mins = s % 60;
    var hrs = (s - mins) / 60;

    return (hrs < 1 ? '' : hrs + ' Jam : ') + (mins < 1 ? '' : mins + ' Menit : ') + secs + ' detik';
}

function showFinalReport() {
    var end_time = new Date().getTime();
    let finalReport = '';
    var waktu = "Total Waktu Hapus Data: " + millisToMinutesAndSeconds(end_time - start_time);

    let msg = '<div class="alert alert-warning" role="alert">';
    msg += '<font color="#3c763d">' + sukses + ' data berhasil dihapus</font><br />';
    msg += '<font color="#ce4844">' + gagal + ' data tidak bisa dihapus</font>';

    // Display error details if there are any error messages
    if (messagesArray.length > 0) {
        // Loop through the messagesArray and add incrementing numbers
        messagesArray.forEach((message, index) => {
            finalReport += (index + 1) + ". " + message + "<br>";  // Incrementing number and line break
        });

        msg += '<a data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">';
        msg += '<br>Klik Disini untuk Melihat Detail error</a>';
        msg += '<div class="collapse" id="collapseExample">';
        msg += finalReport;
        msg += '<div class="bs-callout bs-callout-danger"></div><br /></div>';
    }

    msg += '</div>' + waktu;
    $("#isi_informasi").html(msg);
    $('#informasi').modal('show');
}



});
</script>  
            