    <!-- 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 Invoices></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">Data Table</h5>
              <p class="mb-40"></p>
                <div class="table-wrap">
                        <br/></br>
                        <div id="ordersList"></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() {
    $.ajax({
        url: "<?= base_url('admin/get/revenue') ?>",
        method: "GET",
        dataType: "json",
        success: function(response) {
          console.log(response); // 🔍 Cek struktur JSON di console browser

            let orders = response.data;
            let html = "";

            if (orders.length === 0) {
                html = "<p class='text-muted'>Tidak ada data.</p>";
            } else {
              orders.forEach(tahunData => {
                  html += `<div class="list-group mb-3">
                      <button class="list-group-item list-group-item-action active" data-bs-toggle="collapse" data-bs-target="#tahun_${tahunData.tahun.tahun}">
                          Tahun: ${tahunData.tahun.tahun || "Unknown"} (Total: ${tahunData.tahun.sum_net_amount || 0})
                      </button>
                      <div id="tahun_${tahunData.tahun.tahun}" class="collapse ms-3">`;

                  // ✅ Pastikan "bulan" ada
                  if (tahunData.tahun.bulan && Array.isArray(tahunData.tahun.bulan)) {
                      tahunData.tahun.bulan.forEach(bulanData => {
                          html += `<button class="list-group-item list-group-item-action" data-bs-toggle="collapse" data-bs-target="#bulan_${tahunData.tahun.tahun}_${bulanData.bulan}">
                              Bulan: ${bulanData.bulan} (Total: ${bulanData.sum_net_amount})
                          </button>
                          <div id="bulan_${tahunData.tahun.tahun}_${bulanData.bulan}" class="collapse ms-3">`;

                          // ✅ Cek "minggu"
                          if (bulanData.minggu && typeof bulanData.minggu === "object") {
                              Object.entries(bulanData.minggu).forEach(([minggu, mingguData]) => {
                                  html += `<button class="list-group-item list-group-item-action" data-bs-toggle="collapse" data-bs-target="#minggu_${tahunData.tahun.tahun}_${bulanData.bulan}_${minggu}">
                                      Minggu: ${minggu} (Total: ${mingguData.sum_net_amount})
                                  </button>
                                  <div id="minggu_${tahunData.tahun.tahun}_${bulanData.bulan}_${minggu}" class="collapse ms-3">`;

                                  // ✅ Cek "hari"
                                  if (mingguData.hari && typeof mingguData.hari === "object") {
                                      Object.entries(mingguData.hari).forEach(([hari, orders]) => {
                                          html += `<div class="list-group-item list-group-item-secondary">
                                              Hari: ${hari}
                                          </div>`;

                                          orders.forEach(order => {
                                              html += `<div class="list-group-item">
                                                  <strong>${order.bill_no}</strong> - ${order.customer_name} - Rp${order.net_amount} (${order.paid_status})
                                              </div>`;
                                          });
                                      });
                                  }

                                  html += `</div>`;
                              });
                          }

                          html += `</div>`;
                      });
                  }

                  html += `</div></div>`;
              });
            }

            $("#ordersList").html(html);
        },
        error: function() {
            $("#ordersList").html("<p class='text-danger'>Gagal mengambil data.</p>");
        }
    });
});

    </script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>

            <!-- /Container -->



