<?php

session_start();

// Cek apakah user sudah login
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
  // Jika belum login, redirect ke halaman login
  header("Location: login.php");
  exit();
}
// koneksi ke database
include 'connection.php';

// Mendapatkan data target_service untuk isi
$target_service = "SELECT * FROM target_service";
$result_target_service = $conn->query($target_service);

// Mendapatkan data target_service_per_unit untuk isi
$target_service_per_unit = "SELECT * FROM target_service_per_unit";
$result_target_per_unit = $conn->query($target_service_per_unit);

// Mendapatkan data target_service_dealer untuk isi
$target_service_dealer = "SELECT * FROM target_service_dealer";
$result_target_dealer = $conn->query($target_service_dealer);



// require 'vendor/autoload.php';
require 'PhpSpreadsheet-1.10.1/src/Bootstrap.php';

use Shuchkin\SimpleXLSXGen;
use Shuchkin\SimpleXLSX;


// Fungsi untuk mengunduh template Excel
if (isset($_GET['download'])) {
  // Data header dan konten untuk file Excel
  $header = ['Site ID', 'Nama Dealer', 'Jumlah Teknisi', 'Bulan', 'Tahun', 'Unit KSB', 'Unit KSG', 'Jasa KSB', 'Jasa KSG', 'Part WS', 'Oli WS', 'Hari Kerja'];
  $rows = [];

  // Mengambil data dari database
  $query = "SELECT site_id, name_dealer, jml_tech, bulan, tahun, unit_ksb, unit_ksg, jasa_ksb, jasa_ksg, part_ws, oli_ws, hari_kerja FROM target_service";
  $result = $conn->query($query);
  while ($data = $result->fetch_assoc()) {
    $rows[] = [
      $data['site_id'],
      $data['name_dealer'],
      $data['jml_tech'],
      $data['bulan'],
      $data['tahun'],
      $data['unit_ksb'],
      $data['unit_ksg'],
      $data['jasa_ksb'],
      $data['jasa_ksg'],
      $data['part_ws'],
      $data['oli_ws'],
      $data['hari_kerja']
    ];
  }

  // Membuat file Excel
  $xlsx = SimpleXLSXGen::fromArray(array_merge([$header], $rows));
  $xlsx->downloadAs('master_target_service.xlsx'); // Mengunduh file
  exit;
}

if (isset($_POST['upload'])) {
  $file = $_FILES['excel_file']['tmp_name'];
  $xlsx = SimpleXLSX::parse($file);

  if ($xlsx) {
    $sheetData = $xlsx->rows();

    // Memulai dari baris kedua (mengabaikan header)
    for ($i = 1; $i < count($sheetData); $i++) {
      $site_id = $sheetData[$i][0];
      $name_dealer = $sheetData[$i][1];
      $jml_tech = (int)$sheetData[$i][2];
      $bulan = $sheetData[$i][3];
      $tahun = $sheetData[$i][4];
      $unit_ksb = (float)$sheetData[$i][5];
      $unit_ksg = (float)$sheetData[$i][6];
      $jasa_ksb = (float)$sheetData[$i][7];
      $jasa_ksg = (float)$sheetData[$i][8];
      $part_ws = (float)$sheetData[$i][9];
      $oli_ws = (float)$sheetData[$i][10];
      $hari_kerja = (int)$sheetData[$i][11];

      // Cek apakah site_id dan name_dealer sudah ada
      $stmt = $conn->prepare("SELECT COUNT(*) FROM target_service WHERE site_id = ? AND bulan = ? AND tahun = ?");
      $stmt->bind_param("sss", $site_id, $bulan, $tahun);
      $stmt->execute();
      $stmt->bind_result($count);
      $stmt->fetch();
      $stmt->close();

      if ($count > 0) {
        // Update data jika sudah ada
        $stmt = $conn->prepare("UPDATE target_service SET jml_tech = ?, unit_ksb = ?, unit_ksg = ?, jasa_ksb = ?, jasa_ksg = ?, part_ws = ?, oli_ws = ?, hari_kerja = ? WHERE site_id = ? AND bulan = ? AND tahun = ?");
        $stmt->bind_param("iddddddisss", $jml_tech, $unit_ksb, $unit_ksg, $jasa_ksb, $jasa_ksg, $part_ws, $oli_ws, $hari_kerja, $site_id, $bulan, $tahun);
        $stmt->execute();
        $stmt->close();
      } else {
        // Insert data baru
        $stmt = $conn->prepare("INSERT INTO target_service (site_id, name_dealer, jml_tech, bulan, tahun, unit_ksb, unit_ksg, jasa_ksb, jasa_ksg, part_ws, oli_ws, hari_kerja) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
        $stmt->bind_param("ssissddddddi", $site_id, $name_dealer, $jml_tech, $bulan, $tahun, $unit_ksb, $unit_ksg, $jasa_ksb, $jasa_ksg, $part_ws, $oli_ws, $hari_kerja);
        $stmt->execute();
        $stmt->close();
      }
    }

    echo "<script>
            alert('File berhasil di upload');
            window.location.href = 'target.php';
          </script>";
    exit;
  } else {
    echo "Error loading Excel file";
  }
}
// use PhpOffice\PhpSpreadsheet\Spreadsheet;
// use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
// use PhpOffice\PhpSpreadsheet\IOFactory;

// // Fungsi untuk mengunduh template Excel
// if (isset($_GET['download'])) {
//   $spreadsheet = new Spreadsheet();
//   $sheet = $spreadsheet->getActiveSheet();

//   // Menulis header kolom dengan bold
//   $headers = [
//     'A1' => 'Site ID', 'B1' => 'Nama Dealer', 'C1' => 'Jumlah Teknisi', 'D1' => 'Bulan', 'E1' => 'Tahun',
//     'F1' => 'Unit KSB', 'G1' => 'Unit KSG', 'H1' => 'Jasa KSB', 'I1' => 'Jasa KSG',
//     'J1' => 'Part WS', 'K1' => 'Oli WS', 'L1' => 'Hari Kerja'
//   ];

//   foreach ($headers as $cell => $headerText) {
//     $sheet->setCellValue($cell, $headerText);
//   }
//   $sheet->getStyle('A1:L1')->getFont()->setBold(true); // Set header bold

//   // Mengambil data dari tabel target_service
//   $query = "SELECT site_id, name_dealer, jml_tech, bulan, tahun, unit_ksb, unit_ksg, jasa_ksb, jasa_ksg, part_ws, oli_ws, hari_kerja FROM target_service";
//   $result = $conn->query($query);
//   $row = 2; // Mulai dari baris kedua

//   while ($data = $result->fetch_assoc()) {
//     $sheet->setCellValue('A' . $row, $data['site_id']);
//     $sheet->setCellValue('B' . $row, $data['name_dealer']);
//     $sheet->setCellValue('C' . $row, $data['jml_tech']);
//     $sheet->setCellValue('D' . $row, $data['bulan']);
//     $sheet->setCellValue('E' . $row, $data['tahun']);
//     $sheet->setCellValue('F' . $row, $data['unit_ksb']);
//     $sheet->setCellValue('G' . $row, $data['unit_ksg']);
//     $sheet->setCellValue('H' . $row, $data['jasa_ksb']);
//     $sheet->setCellValue('I' . $row, $data['jasa_ksg']);
//     $sheet->setCellValue('J' . $row, $data['part_ws']);
//     $sheet->setCellValue('K' . $row, $data['oli_ws']);
//     $sheet->setCellValue('L' . $row, $data['hari_kerja']);
//     $row++;
//   }

//   $writer = new Xlsx($spreadsheet);
//   $filename = 'master_target_service.xlsx';

//   header('Content-Type: application/vnd.ms-excel');
//   header('Content-Disposition: attachment;filename="' . $filename . '"');
//   header('Cache-Control: max-age=0');

//   $writer->save('php://output');
//   exit;
// }

// // Fungsi untuk mengunggah dan memproses file Excel
// if (isset($_POST['upload'])) {
//   $file = $_FILES['excel_file']['tmp_name'];
//   $spreadsheet = IOFactory::load($file);
//   $sheetData = $spreadsheet->getActiveSheet()->toArray();

//   // Memulai dari baris kedua (mengabaikan header)
//   for ($i = 1; $i < count($sheetData); $i++) {
//     $site_id = $sheetData[$i][0];
//     $name_dealer = $sheetData[$i][1];
//     $jml_tech = (int)$sheetData[$i][2];
//     $bulan = $sheetData[$i][3];
//     $tahun = $sheetData[$i][4];
//     $unit_ksb = (double)$sheetData[$i][5];
//     $unit_ksg = (double)$sheetData[$i][6];
//     $jasa_ksb = (double)$sheetData[$i][7];
//     $jasa_ksg = (double)$sheetData[$i][8];
//     $part_ws = (double)$sheetData[$i][9];
//     $oli_ws = (double)$sheetData[$i][10];
//     $hari_kerja = (int)$sheetData[$i][11];

//     // Cek apakah site_id dan name_dealer sudah ada
//     $stmt = $conn->prepare("SELECT COUNT(*) FROM target_service WHERE site_id = ? AND bulan = ? AND tahun = ?");
//     $stmt->bind_param("sss", $site_id, $bulan, $tahun);
//     $stmt->execute();
//     $stmt->bind_result($count);
//     $stmt->fetch();
//     $stmt->close();

//     if ($count > 0) {
//       // Update data jika sudah ada
//       $stmt = $conn->prepare("UPDATE target_service SET jml_tech = ?, unit_ksb = ?, unit_ksg = ?, jasa_ksb = ?, jasa_ksg = ?, part_ws = ?, oli_ws = ?, hari_kerja = ? WHERE site_id = ? AND bulan = ? AND tahun = ?");
//       $stmt->bind_param("iddddddisss", $jml_tech, $unit_ksb, $unit_ksg, $jasa_ksb, $jasa_ksg, $part_ws, $oli_ws, $hari_kerja, $site_id, $bulan, $tahun);
//       $stmt->execute();
//       $stmt->close();
//     } else {
//       // Insert data baru
//       $stmt = $conn->prepare("INSERT INTO target_service (site_id, name_dealer, jml_tech, bulan, tahun, unit_ksb, unit_ksg, jasa_ksb, jasa_ksg, part_ws, oli_ws, hari_kerja) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
//       $stmt->bind_param("ssissddddddi", $site_id, $name_dealer, $jml_tech, $bulan, $tahun, $unit_ksb, $unit_ksg, $jasa_ksb, $jasa_ksg, $part_ws, $oli_ws, $hari_kerja);
//       $stmt->execute();
//       $stmt->close();
//     }
//   }

//   // Menampilkan alert dan mengarahkan ulang ke halaman yang sama
//   echo "<script>
//           alert('File berhasil di upload');
//           window.location.href = 'target.php';
//         </script>";
//   exit;
// }
?>

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0" name="viewport">
  <title>Query Master Service</title>
  <meta content="" name="description">
  <meta content="" name="keywords">

  <!-- Bootstrap CSS -->
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet">
  <!-- DataTables CSS -->
  <link rel="stylesheet" href="https://cdn.datatables.net/1.13.6/css/dataTables.bootstrap5.min.css">
  <!-- Google Fonts -->
  <link href="https://fonts.gstatic.com" rel="preconnect">
  <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i|Nunito:300,300i,400,400i,600,600i,700,700i|Poppins:300,300i,400,400i,500,500i,600,600i,700,700i" rel="stylesheet">

  <!-- Vendor CSS Files -->
  <link href="assets/vendor/bootstrap-icons/bootstrap-icons.css" rel="stylesheet">
  <link href="assets/vendor/boxicons/css/boxicons.min.css" rel="stylesheet">
  <link href="assets/vendor/quill/quill.snow.css" rel="stylesheet">
  <link href="assets/vendor/quill/quill.bubble.css" rel="stylesheet">
  <link href="assets/vendor/remixicon/remixicon.css" rel="stylesheet">
  <link href="assets/vendor/simple-datatables/style.css" rel="stylesheet">

  <!-- Template Main CSS File -->
  <link href="assets/css/style.css" rel="stylesheet">

  <!-- Favicons -->
  <link href="assets/img/favicon.png" rel="icon">
  <link href="assets/img/apple-touch-icon.png" rel="apple-touch-icon">

  <!-- UNICONS -->
  <link rel="stylesheet" href="https://unicons.iconscout.com/release/v4.0.8/css/line.css">

  <style>
    thead th {
      border: 1px solid rgb(230, 230, 230) !important;
    }

    table {
      overflow-y: auto;
      overflow-x: auto !important;
      min-height: 40px;
    }

    .top {
      display: flex;
      justify-content: space-between;
      align-items: center;
    }

    .bottom {
      display: flex;
      justify-content: space-between;
      align-items: center;
    }
  </style>
</head>

<body>

  <?php
  include 'header.php';
  ?>

  <?php
  $activeMenu = 'target'; // Sesuaikan dengan halaman yang sedang dibuka
  include 'sidebar.php';
  ?>



  <main id="main" class="main">

    <div class="pagetitle">
      <h1>Target</h1>
      <nav>
        <ol class="breadcrumb">
          <li class="breadcrumb-item"><a href="index.html">Home</a></li>
          <li class="breadcrumb-item active">Target</li>
        </ol>
      </nav>
    </div><!-- End Page Title -->

    <section class="section dashboard">

      <div class="card">
        <div class="card-body">

          <!-- Default Tabs -->
          <ul class="nav mt-4 nav-tabs d-flex" id="myTabjustified" role="tablist">
            <li class="nav-item flex-fill" role="presentation">
              <button class="nav-link w-100 active" id="per-dealer-tab" data-bs-toggle="tab" data-bs-target="#per-dealer-justified" type="button" role="tab" aria-controls="per-dealer" aria-selected="true">Data Per Dealer</button>
            </li>
            <li class="nav-item flex-fill" role="presentation">
              <button class="nav-link w-100" id="per-unit-tab" data-bs-toggle="tab" data-bs-target="#per-unit-justified" type="button" role="tab" aria-controls="per-unit" aria-selected="false">Data Per Unit</button>
            </li>
            <li class="nav-item flex-fill" role="presentation">
              <button class="nav-link w-100" id="input-awal-tab" data-bs-toggle="tab" data-bs-target="#input-awal-justified" type="button" role="tab" aria-controls="input-awal" aria-selected="false">Data Awal</button>
            </li>
            <li class="nav-item flex-fill" role="presentation">
              <button class="nav-link w-100" id="tambah-baru-tab" data-bs-toggle="tab" data-bs-target="#tambah-baru-justified" type="button" role="tab" aria-controls="tambah-baru" aria-selected="false">Tambah Data</button>
            </li>
          </ul>
          <div class="tab-content pt-2" id="myTabjustifiedContent">
            <div class="tab-pane fade show active" id="per-dealer-justified" role="tabpanel" aria-labelledby="per-dealer-tab">
              <h5 class="card-title">Target Per Dealer</h5>
              <p>
                Data Ini berisi tentang data untuk perhitungan Achievement di masing-masing Dealer
              </p>
              <div class="overflow-auto">
                <!-- Table with stripped rows -->
                <table id="targetDealer" class="table table-hover table-bordered text-center">
                  <thead>
                    <tr>
                      <th></th>
                      <th>Nama Dealer</th>
                      <th>Bulan</th>
                      <th>Tahun</th>
                      <th>Target Jasa</th>
                      <th>Part dan Oli</th>
                      <th>Teknisi</th>
                    </tr>
                  </thead>
                  <tbody>
                    <?php
                    if ($result_target_dealer->num_rows > 0) {
                      while ($target = $result_target_dealer->fetch_assoc()) {
                    ?>
                        <tr>
                          <td>
                            <form action="target_dealer_edit.php" method="GET">
                              <input type="hidden" name="dealer_code" value="<?php echo $target['site_id']; ?>">
                              <input type="hidden" name="name_dealer" value="<?php echo $target['name_dealer']; ?>">
                              <input type="hidden" name="bulan" value="<?php echo $target['bulan']; ?>">
                              <input type="hidden" name="tahun" value="<?php echo $target['tahun']; ?>">
                              <button type="submit" class="btn btn-outline-warning" style="--bs-btn-ptambah-baruing-y: .1rem; --bs-btn-ptambah-baruing-x: .5rem; --bs-btn-font-size: .80rem;"><i class="uil uil-pen"></i></button>
                            </form>
                          </td>

                          <td class="text-start align-middle"><?php echo $target['name_dealer']; ?></td>
                          <td class="align-middle"><?php echo $target['bulan']; ?></td>
                          <td class="align-middle"><?php echo $target['tahun']; ?></td>
                          <td class="text-end align-middle">Rp<?php echo number_format($target['total_jasa'], 0, ',', '.'); ?></td>
                          <td class="text-end align-middle">Rp<?php echo number_format($target['part_n_oli'], 0, ',', '.'); ?></td>
                          <td class="text-end align-middle"><?php echo number_format($target['jml_tech'], 0, ',', '.'); ?></td>
                        </tr>
                    <?php
                      }
                    }
                    ?>
                  </tbody>
                </table>
                <!-- End Table with stripped rows -->
              </div>


            </div>
            <div class="tab-pane fade" id="per-unit-justified" role="tabpanel" aria-labelledby="per-unit-tab">
              <h5 class="card-title">Target Per Unit</h5>
              <p>
                Data Ini berisi tentang data untuk perhitungan Productivity di masing-masing Dealer
              </p>
              <div class="overflow-auto">
                <!-- Table with stripped rows -->
                <table id="targetUnit" class="table table-hover table-bordered text-center">
                  <thead>
                    <tr>
                      <th></th>
                      <th>Nama Dealer</th>
                      <th>Bulan</th>
                      <th>Tahun</th>
                      <th>RUT</th>
                      <th>Jasa/u</th>
                      <th>Part/u</th>
                      <th>Oli/u</th>
                    </tr>
                  </thead>
                  <tbody>
                    <?php
                    if ($result_target_per_unit->num_rows > 0) {
                      while ($target = $result_target_per_unit->fetch_assoc()) {
                    ?>
                        <tr>
                          <td>
                            <form action="target_dealer_edit.php" method="GET">
                              <input type="hidden" name="dealer_code" value="<?php echo $target['site_id']; ?>">
                              <input type="hidden" name="name_dealer" value="<?php echo $target['name_dealer']; ?>">
                              <input type="hidden" name="bulan" value="<?php echo $target['bulan']; ?>">
                              <input type="hidden" name="tahun" value="<?php echo $target['tahun']; ?>">
                              <button type="submit" class="btn btn-outline-warning" style="--bs-btn-ptambah-baruing-y: .1rem; --bs-btn-ptambah-baruing-x: .5rem; --bs-btn-font-size: .80rem;"><i class="uil uil-pen"></i></button>
                            </form>
                          </td>

                          <td class="text-start align-middle"><?php echo $target['name_dealer']; ?></td>
                          <td class="align-middle"><?php echo $target['bulan']; ?></td>
                          <td class="align-middle"><?php echo $target['tahun']; ?></td>
                          <td class="text-end align-middle"><?php echo number_format($target['rut'], 0, ',', '.'); ?></td>
                          <td class="text-end align-middle">Rp<?php echo number_format($target['jasa_per_unit'], 0, ',', '.'); ?></td>
                          <td class="text-end align-middle">Rp<?php echo number_format($target['part_per_unit'], 0, ',', '.'); ?></td>
                          <td class="text-end align-middle">Rp<?php echo number_format($target['oli_per_unit'], 0, ',', '.'); ?></td>
                        </tr>
                    <?php
                      }
                    }
                    ?>
                  </tbody>
                </table>
                <!-- End Table with stripped rows -->
              </div>

            </div>
            <div class="tab-pane fade" id="input-awal-justified" role="tabpanel" aria-labelledby="input-awal-tab">
              <h5 class="card-title">Data Awal</h5>
              <p>
                Data ini akan di olah untuk menentukan Data Per Unit dan Data Per Dealer
              </p>
              <div class="overflow-auto">
                <!-- Table with stripped rows -->
                <table id="targetAwal" class="table table-hover table-bordered text-center">
                  <thead>
                    <tr>
                      <th></th>
                      <th>Kode Dealer</th>
                      <th>Bulan</th>
                      <th>Tahun</th>
                      <th>U KSB</th>
                      <th>U KSG</th>
                      <th>J KSB</th>
                      <th>J KSG</th>
                      <th>Part ws</th>
                      <th>Oli ws</th>
                      <th>HK</th>
                    </tr>
                  </thead>
                  <tbody>
                    <?php
                    if ($result_target_service->num_rows > 0) {
                      while ($target = $result_target_service->fetch_assoc()) {
                    ?>
                        <tr>
                          <td>
                            <form action="target_dealer_edit.php" method="GET">
                              <input type="hidden" name="dealer_code" value="<?php echo $target['site_id']; ?>">
                              <input type="hidden" name="name_dealer" value="<?php echo $target['name_dealer']; ?>">
                              <input type="hidden" name="bulan" value="<?php echo $target['bulan']; ?>">
                              <input type="hidden" name="tahun" value="<?php echo $target['tahun']; ?>">
                              <button type="submit" class="btn btn-outline-warning" style="--bs-btn-ptambah-baruing-y: .1rem; --bs-btn-ptambah-baruing-x: .5rem; --bs-btn-font-size: .80rem;"><i class="uil uil-pen"></i></button>
                            </form>
                          </td>

                          <td class="text-start align-middle"><?php echo $target['site_id']; ?></td>
                          <td class="align-middle"><?php echo $target['bulan']; ?></td>
                          <td class="align-middle"><?php echo $target['tahun']; ?></td>
                          <td class="align-middle"><?php echo $target['unit_ksb']; ?></td>
                          <td class="align-middle"><?php echo $target['unit_ksg']; ?></td>
                          <td class="text-end align-middle">Rp<?php echo number_format($target['jasa_ksb'], 0, ',', '.'); ?></td>
                          <td class="text-end align-middle">Rp<?php echo number_format($target['jasa_ksg'], 0, ',', '.'); ?></td>
                          <td class="text-end align-middle">Rp<?php echo number_format($target['part_ws'], 0, ',', '.'); ?></td>
                          <td class="text-end align-middle">Rp<?php echo number_format($target['oli_ws'], 0, ',', '.'); ?></td>
                          <td class="align-middle"><?php echo number_format($target['hari_kerja'], 0, ',', '.'); ?></td>
                        </tr>
                    <?php
                      }
                    }
                    ?>
                  </tbody>
                </table>
                <!-- End Table with stripped rows -->

              </div>

            </div>
            <div class="tab-pane fade" id="tambah-baru-justified" role="tabpanel" aria-labelledby="tambah-baru-tab">
              <h5 class="card-title">Tambah Data</h5>
              <p>Silahkan Masukkan data berdasarkan</p>
              <div class="row">
                <div class="alert alert-light text-center mt-4 mb-1" role="alert">
                  <h4>Input Manual</h4>
                  <div class="col-md-12">
                    <!-- Button untuk membuka modal -->
                    <a type="button" class="btn btn-outline-info mt-3 mb-3 w-100" href="target_dealer_tambah.php">
                      Input
                    </a>
                  </div>
                </div>
                <div class="alert alert-light text-center mt-4 mb-1" role="alert">
                  <h4>Import Excel</h4>
                  <div class="card-body d-flex justify-content-between mt-4">
                    <!-- Tombol Download Master -->
                    <div class="col-sm-5">
                      <a href="?download=true" class="btn btn-outline-primary w-100">
                        <i class="uil uil-file-download"></i> Download Master
                      </a>
                    </div>

                    <!-- Form Upload Excel -->
                    <div class="col-sm-5">
                      <form action="" method="post" enctype="multipart/form-data">
                        <input class="form-control" type="file" name="excel_file" required>
                        <button type="submit" name="upload" class="btn btn-outline-success w-100 mt-2">
                          <i class="uil uil-file-upload"></i> Upload Excel
                        </button>
                      </form>
                    </div>
                  </div>
                </div>
              </div>

            </div>
          </div><!-- End Default Tabs -->

        </div>
      </div>

    </section>

  </main><!-- End #main -->


  <?php
  include 'footer.php';
  ?>

  <a href="#" class="back-to-top d-flex align-items-center justify-content-center"><i class="bi bi-arrow-up-short"></i></a>

  <!-- Vendor JS Files -->
  <script src="assets/vendor/apexcharts/apexcharts.min.js"></script>
  <script src="assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
  <script src="assets/vendor/chart.js/chart.umd.js"></script>
  <script src="assets/vendor/echarts/echarts.min.js"></script>
  <script src="assets/vendor/quill/quill.js"></script>
  <script src="assets/vendor/simple-datatables/simple-datatables.js"></script>
  <script src="assets/vendor/tinymce/tinymce.min.js"></script>
  <script src="assets/vendor/php-email-form/validate.js"></script>

  <!-- jQuery (harus sebelum DataTables) -->
  <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

  <!-- DataTables JS -->
  <script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
  <script src="https://cdn.datatables.net/1.13.6/js/dataTables.bootstrap5.min.js"></script>



  <!-- Main JS File -->
  <script src="assets/js/main.js"></script>

  <script>
    $(document).ready(function() {
      $('#targetDealer').DataTable({
        "lengthMenu": [
          [10, 25, 50, -1],
          [10, 25, 50, "All"]
        ], // Mengubah teks lengthMenu
        "paging": true, // Enable pagination
        "searching": true, // Enable searching
        "ordering": true, // Enable column ordering
        "language": {
          "info": "Menampilkan _START_ sampai _END_ dari _TOTAL_ entri",
          "infoEmpty": "Menampilkan 0 sampai 0 dari 0 entri",
          "search": "Cari:", // Mengubah teks pencarian
          "lengthMenu": "Tampilkan _MENU_ data",
          "paginate": {
            "previous": "<span aria-hidden='true'>&laquo;</span>",
            "next": "<span aria-hidden='true'>&raquo;</span>"
          }
        },
        "pagingType": "full_numbers", // Gaya pagination full dengan Bootstrap
        "dom": '<"top"lf>rt<"bottom"ip><"clear">' // Menempatkan lengthMenu (l) dan searching (f) di atas
      });
      $('#targetUnit').DataTable({
        "lengthMenu": [
          [10, 25, 50, -1],
          [10, 25, 50, "All"]
        ], // Mengubah teks lengthMenu
        "paging": true, // Enable pagination
        "searching": true, // Enable searching
        "ordering": true, // Enable column ordering
        "language": {
          "info": "Menampilkan _START_ sampai _END_ dari _TOTAL_ entri",
          "infoEmpty": "Menampilkan 0 sampai 0 dari 0 entri",
          "search": "Cari:", // Mengubah teks pencarian
          "lengthMenu": "Tampilkan _MENU_ data",
          "paginate": {
            "previous": "<span aria-hidden='true'>&laquo;</span>",
            "next": "<span aria-hidden='true'>&raquo;</span>"
          }
        },
        "pagingType": "full_numbers", // Gaya pagination full dengan Bootstrap
        "dom": '<"top"lf>rt<"bottom"ip><"clear">' // Menempatkan lengthMenu (l) dan searching (f) di atas
      });
      $('#targetAwal').DataTable({
        "lengthMenu": [
          [10, 25, 50, -1],
          [10, 25, 50, "All"]
        ], // Mengubah teks lengthMenu
        "paging": true, // Enable pagination
        "searching": true, // Enable searching
        "ordering": true, // Enable column ordering
        "language": {
          "info": "Menampilkan _START_ sampai _END_ dari _TOTAL_ entri",
          "infoEmpty": "Menampilkan 0 sampai 0 dari 0 entri",
          "search": "Cari:", // Mengubah teks pencarian
          "lengthMenu": "Tampilkan _MENU_ data",
          "paginate": {
            "previous": "<span aria-hidden='true'>&laquo;</span>",
            "next": "<span aria-hidden='true'>&raquo;</span>"
          }
        },
        "pagingType": "full_numbers", // Gaya pagination full dengan Bootstrap
        "dom": '<"top"lf>rt<"bottom"ip><"clear">' // Menempatkan lengthMenu (l) dan searching (f) di atas
      });
    });
  </script>


</body>

</html>