    <!-- Main Content -->
    <div class="hk-pg-wrapper">
			<!-- Container -->
            <div class="container-fluid mt-xl-50 mt-sm-30 mt-15">

            <div class="hk-pg-header mb-10">
                    <div>
						<h4 class="hk-pg-title"><span class="pg-title-icon"><span class="feather-icon"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-activity"><polyline points="22 12 18 12 15 21 9 3 6 12 2 12"></polyline></svg></span></span>Manage Ticket</h4>
                    </div>
					<div class="d-flex dropdown">
                    </div>
                </div>


				<div class="row">
          <div class="col-xl-12">
            <section class="hk-sec-wrapper">
              <h5 class="hk-sec-title">Ticket</h5>
              <p class="mb-40"></p>
                <div class="table-wrap">
                        <br/></br>
                  <div class="table-responsive">
                        <table id="orders-table" class="table dataTable no-footer">
                                        <thead>
                                            <tr>
                                                <th>Date Time</th>
                                                <th>Customer Name</th>
                                                <th>No Ticket</th>
                                                <th>Status</th>
                                                <th>Action</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                        </tbody>
                        </table>
                  </div>
                </div>

                    
                    <!--- Card Body END -->
          </section>
          </div>
        </div>
		


    </div>


    <script src="https://texapp.is3.cloudhost.id/api/v2/assets/vendors/sweetalert2/sweetalert2.min.js"></script>
  <script src="https://texapp.is3.cloudhost.id/api/v2/assets/vendors/promise-polyfill/polyfill.min.js"></script> 
<script type="text/javascript">


        $(document).ready(function () {

            
            var dataTable = $('#orders-table').DataTable({
                "ajax": {
                    "url": "<?php echo base_url('ticket/getData'); ?>",
                    "type": "GET",
                    "data": function(d) {
                        d.length = $('#orders-table').DataTable().page.len();
                    }
                },
                "columns": [
                    { "data": "date_created" },
                    { "data": "client_name" },
                    { "data": "kode" },
                    { "data": "status_id" }, // Ini sekarang menggunakan paidStatusLabel
                    { "data": null, // Menggunakan null karena kita akan merender tombol di sini
                    "render": function(data, type, row) {
                        return '<button class="btn btn-icon btn-primary mr-1" onclick="editTicket(\'' + row.kode + '\')"><i class="fa-solid fa-pencil"></i></button>' +
                              '<a href="' + row.image_url + '" class="btn btn-icon btn-info mr-1"><i class="fa-solid fa-save"></i></a>' +
                              '<button class="btn btn-icon btn-danger delete-btnz" onclick="contoh(\'' + row.kode + '\')"><i class="fa-solid fa-trash"></i></button>';
            }
        }
                ],
                "order": [[0, 'desc']]

                        
              });
              
        });
        function editTicket(ticketCode) {
                $.ajax({
                    url: '<?php echo base_url('ticket/post/sentinv'); ?>', // Ganti dengan URL yang sesuai
                    type: 'POST',
                    data: { kode: ticketCode },
                    success: function(response) {
                      if (response.order_id) {
                // Redirect ke halaman baru dengan order_id
                            window.location.href = '<?php echo base_url('invoice/update?kode='); ?>' + response.order_id;
                        } else {
                            // Tampilkan pesan jika order_id tidak ada
                            alert('Order ID tidak ditemukan.');
                        }                       
                    },
                    error: function(xhr, status, error) {
                        // Tampilkan pesan kesalahan yang lebih informatif
                        var errorMessage = 'Terjadi kesalahan saat memproses permintaan.';
                        if (xhr.responseJSON && xhr.responseJSON.message) {
                            errorMessage = xhr.responseJSON.message; // Ambil pesan dari respons JSON jika ada
                        }
                        console.error(error);
                        showError(errorMessage);
                      }
                });
            }
            function showError(message) {
                  Swal.fire({
                      title: 'Error!',
                      text: message,
                      icon: 'error',
                      confirmButtonText: 'OK'
                  });
              }
              

        function contoh(e) {

var url = "<?php echo base_url('ticket/deleteOrder'); ?>?kode=" + e;
console.log(e);
const swalWithBootstrapButtons = Swal.mixin({
    customClass: {
      confirmButton: 'btn btn-success',
      cancelButton: 'btn btn-danger mr-2'
    },
    buttonsStyling: false,
  })
  
  swalWithBootstrapButtons.fire({
    title: 'Are you sure?',
    text: "You won't be able to revert this!",
    icon: 'warning',
    showCancelButton: true,
    confirmButtonClass: 'mr-2',
    confirmButtonText: 'Yes, delete it!',
    cancelButtonText: 'No, cancel!',
    reverseButtons: true
  }).then((result) => {
    if (result.value) {
        $.getJSON(url, function(data) {
           console.log(data);

           
         }),
      swalWithBootstrapButtons.fire(
        'Deleted!',
        'Your file has been deleted.',
        'success'
      )

      setTimeout(function() {
            location.reload();
        }, 2000);

    } else if (
      // Read more about handling dismissals
      result.dismiss === Swal.DismissReason.cancel
    ) {
      swalWithBootstrapButtons.fire(
        'Cancelled',
        'Your imaginary file is safe :)',
        'error'
      )
    }
  })
  

}

    </script>

            <!-- /Container -->



