Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- $("#jenispekerjaan").hide();
- $("#namakantor").hide();
- $("#namapembina").hide();
- function formatRupiah(angka, prefix) {
- var number_string = angka.replace(/[^,\d]/g, '').toString(),
- split = number_string.split(','),
- sisa = split[0].length % 3,
- rupiah = split[0].substr(0, sisa),
- ribuan = split[0].substr(sisa).match(/\d{3}/gi);
- // tambahkan titik jika yang di input sudah menjadi angka ribuan
- if (ribuan) {
- separator = sisa ? ',' : '';
- rupiah += separator + ribuan.join(',');
- }
- rupiah = split[1] != undefined ? rupiah + ',' + split[1] : rupiah;
- return prefix == undefined ? rupiah : (rupiah ? 'Rp. ' + rupiah : '');
- }
- <?php
- include 'config.php';
- $query = "SELECT BLTH_PROSES, KODE_WILAYAH, NAMA_WILAYAH, SUM(JUMLAH) JUMLAH, SUM(JUMLAH_KOTA) JUMLAH_KOTA, SUM(JUMLAH_KAB) JUMLAH_KAB
- FROM (
- SELECT BLTH_PROSES, KODE_WILAYAH, NAMA_WILAYAH, SUM(TOTAL) JUMLAH,
- CASE WHEN LOKASI='KOTA' THEN SUM(TOTAL) END AS JUMLAH_KOTA,
- CASE WHEN LOKASI='KAB/DESA' THEN SUM(TOTAL) END AS JUMLAH_KAB
- FROM IPROJECT_PU_JAKON_KOTAKAB_RKP
- WHERE KODE_SEGMEN = 'JAKON'
- AND TGL_PROSES = (
- SELECT MAX(TGL_PROSES)
- FROM IPROJECT_PU_JAKON_KOTAKAB_RKP
- WHERE BLTH_PROSES=DATE(DATE_SUB(NOW(), INTERVAL DAYOFMONTH(NOW())-1 DAY))
- )
- GROUP BY BLTH_PROSES, KODE_WILAYAH, NAMA_WILAYAH, LOKASI) A
- GROUP BY BLTH_PROSES, KODE_WILAYAH, NAMA_WILAYAH";
- $result_query = mysqli_query($host, $query);
- if (!$result_query) {
- die('Invalid query: ' . mysqli_error($host));
- }
- $labels = [];
- $data_kota = [];
- $data_desa = [];
- $data_combined = [];
- while ($row = mysqli_fetch_assoc($result_query)) {
- $labels[] = $row['NAMA_WILAYAH'];
- $data_kota[] = $row['JUMLAH_KOTA'];
- $data_desa[] = $row['JUMLAH_KAB'];
- }
- ?>
- var ctx = document.getElementById('bar').getContext('2d');
- // Membuat data untuk grafik batang
- var data = {
- labels: <?php echo json_encode($labels); ?>,
- datasets: [{
- label: 'KOTA',
- backgroundColor: '#fa5c7c',
- borderColor: '#fa5c7c',
- data: <?php echo json_encode($data_kota); ?>
- }, {
- label: 'KAB/DESA',
- backgroundColor: '#727cf5',
- borderColor: '#727cf5',
- data: <?php echo json_encode($data_desa); ?>
- }]
- };
- // Konfigurasi grafik batang
- var options = {
- responsive: true,
- maintainAspectRatio: false
- };
- // Membuat objek grafik batang baru
- var barChart = new Chart(ctx, {
- type: 'bar',
- data: data,
- options: options
- });
- function round(number, decimals) {
- const factor = 10 ** decimals;
- return Math.round(number * factor) / factor;
- }
- function wilayah(id) {
- $.ajax({
- type: "GET",
- url: "pu_jakon_wilayah.php",
- data: {
- kode_wilayah: id,
- },
- success: function(response) {
- var tableHtml = "";
- var footHtml = "";
- var title = "";
- var lastIndex = response.length - 1;
- var lastItem = response[lastIndex];
- // console.log('tes',lastItem.Total);
- var total = lastItem.Total;
- var totalkota = lastItem.TotalKota;
- var totalkab = lastItem.TotalDesa;
- var total_kota = totalkota / total * 100;
- var totaldesa = totalkab / total * 100
- title += "<h3 class='card-title' > " + response[0].NAMA_WILAYAH + "</h3>";
- $.each(response, function(index, value) {
- var kota = value.JUMLAH_KOTA
- var desa = value.JUMLAH_KAB
- var jumlah = value.JUMLAH
- var jumlah_kota = kota / jumlah * 100
- var jumlah_desa = desa / jumlah * 100
- tableHtml += "<input type='hidden' id='wilayah' value='" + value.KODE_WILAYAH + "'>";
- tableHtml += "<tr>";
- tableHtml += "<td>" + (index + 1) + "</td>";
- tableHtml += "<td>" + value.KODE_KANTOR + "</td>";
- tableHtml += "<td>" + value.NAMA_KANTOR + "</td>";
- tableHtml += "<td>" + formatRupiah(value.JUMLAH) + "</td>";
- tableHtml += "<td>" + formatRupiah(kota) + "</td>";
- tableHtml += "<td>" + formatRupiah(desa) + "</td>";
- tableHtml += "<td>" + round(jumlah_kota, 1) + "%</td>";
- tableHtml += "<td>" + round(jumlah_desa, 1) + "%</td>";
- tableHtml += "</tr>";
- // footHtml += "<tr>";
- // footHtml += "<th>TOTAL</th>";
- // footHtml += "</tr>";
- });
- footHtml += "<tr>";
- footHtml += "<th>TOTAL</th>";
- footHtml += "<th></th>";
- footHtml += "<th></th>";
- footHtml += "<th>" + total.toLocaleString() + "</th>";
- footHtml += "<th>" + totalkota.toLocaleString() + "</th>";
- footHtml += "<th>" + totalkab.toLocaleString() + "</th>";
- footHtml += "<th>" + round(total_kota, 1) + "%</th>";
- footHtml += "<th>" + round(totaldesa, 1) + "%</th>";
- footHtml += "</tr>";
- location.href = "#jenispekerjaan";
- $("#bpu_wilayah").html(tableHtml);
- $("#foot_wilayah").html(footHtml);
- $("#title_wilayah").html(title);
- $("#jenispekerjaan").fadeIn(1500);
- $("#namakantor").hide();
- $("#namapembina").hide();
- // Process the response here
- // console.log(response);
- }
- });
- }
- $("#year_blt").select2()
- function year_blt(year) {
- $.ajax({
- type: "GET",
- url: "year_blthproses_jakon.php",
- data: {
- year: year
- },
- success: function(response) {
- // var tahun = response[0].YEAR
- // var bulan = response[0].BLTH_PROSES
- var tableHtml = "<option value=''>Choose</option>"; // Tambahkan opsi "Choose"
- $.each(response, function(index, value) {
- var optionValue = value.BLTH_PROSES;
- var optionText = value.BULAN;
- var tahun = value.YEAR
- tableHtml += "<option value='" + optionValue + " " + tahun + "'>" + optionText + "</option>";
- });
- $("#month_year").html(tableHtml);
- }
- });
- }
- function month_blt(month_year) {
- // Split month_year value into month and year
- var parts = month_year.split(" ");
- var month = parts[0];
- var year = parts[1];
- $.ajax({
- type: "GET",
- url: "month_blthproses_jakon.php",
- data: {
- month: month,
- year: year
- },
- success: function(response) {
- // console.log('masuk', response);
- var tableHtml = "";
- var footHtml = "";
- var title = "";
- var lastIndex = response.length - 1;
- var total = 0;
- var totalkota = 0;
- var totalkab = 0;
- if (lastIndex >= 0) {
- var lastItem = response[lastIndex];
- total = lastItem.Total;
- totalkota = lastItem.TotalKota;
- totalkab = lastItem.TotalDesa;
- }
- var total_kota = totalkota / total * 100;
- var totaldesa = totalkab / total * 100;
- var labels = [];
- var data_kota = [];
- var data_desa = [];
- $.each(response, function(index, value) {
- console.log('tes', value)
- var kota = value.JUMLAH_KOTA;
- var desa = value.JUMLAH_KAB;
- var jumlah = value.JUMLAH;
- var jumlah_kota = kota / jumlah * 100;
- var jumlah_desa = desa / jumlah * 100;
- labels.push(value.NAMA_WILAYAH);
- data_kota.push(kota);
- data_desa.push(desa);
- tableHtml += "<input type='hidden' id='years' value='" + value.YEAR + "'>";
- tableHtml += "<input type='hidden' id='months' value='" + value.MONTH + "'>";
- tableHtml += "<tr>";
- tableHtml += "<td>" + (index + 1) + "</td>";
- tableHtml += "<td><a class='colored' onclick='filter_wilayah(\"" + value.KODE_WILAYAH + "\")' >" + value.KODE_WILAYAH + "</a></td>";
- tableHtml += "<td>" + value.NAMA_WILAYAH + "</td>";
- tableHtml += "<td>" + formatRupiah(value.JUMLAH) + "</td>";
- tableHtml += "<td>" + formatRupiah(kota) + "</td>";
- tableHtml += "<td>" + formatRupiah(desa) + "</td>";
- tableHtml += "<td>" + round(jumlah_kota, 1) + "%</td>";
- tableHtml += "<td>" + round(jumlah_desa, 1) + "%</td>";
- tableHtml += "</tr>";
- });
- footHtml += "<tr>";
- footHtml += "<th>TOTAL</th>";
- footHtml += "<th></th>";
- footHtml += "<th></th>";
- footHtml += "<th>" + total.toLocaleString() + "</th>";
- footHtml += "<th>" + totalkota.toLocaleString() + "</th>";
- footHtml += "<th>" + totalkab.toLocaleString() + "</th>";
- footHtml += "<th>" + round(total_kota, 1) + "%</th>";
- footHtml += "<th>" + round(totaldesa, 1) + "%</th>";
- footHtml += "</tr>";
- $("#filter").html(tableHtml); // Update the table body with the new HTML
- $("#filter_foot").html(footHtml); // Update the table footer with the new HTML
- // Update the chart data
- barChart.data.labels = labels;
- barChart.data.datasets[0].data = data_kota;
- barChart.data.datasets[1].data = data_desa;
- barChart.update(); // Redraw the chart
- }
- });
- }
- function filter_wilayah(id) {
- var year = $("#years").val();
- var month = $("#months").val();
- $.ajax({
- type: "GET",
- url: "filter_wilayah_jakon.php",
- data: {
- kode_wilayah: id,
- year: year,
- month: month,
- },
- success: function(response) {
- var tableHtml = "";
- var footHtml = "";
- var title = "";
- var lastIndex = response.length - 1;
- var lastItem = response[lastIndex];
- // console.log('tes',lastItem.Total);
- var total = lastItem.Total;
- var totalkota = lastItem.TotalKota;
- var totalkab = lastItem.TotalDesa;
- var total_kota = totalkota / total * 100;
- var totaldesa = totalkab / total * 100
- title += "<h3 class='card-title' > " + response[0].NAMA_WILAYAH + "</h3>";
- $.each(response, function(index, value) {
- var kota = value.JUMLAH_KOTA
- var desa = value.JUMLAH_KAB
- var jumlah = value.JUMLAH
- var jumlah_kota = kota / jumlah * 100
- var jumlah_desa = desa / jumlah * 100
- tableHtml += "<input type='hidden' id='wilayah' value='" + value.KODE_WILAYAH + "'>";
- tableHtml += "<input type='hidden' id='yea' value='" + value.YEAR + "'>";
- tableHtml += "<input type='hidden' id='mont' value='" + value.MONTH + "'>";
- tableHtml += "<tr>";
- tableHtml += "<td>" + (index + 1) + "</td>";
- tableHtml += "<td>" + value.KODE_KANTOR + "</td>";
- tableHtml += "<td>" + value.NAMA_KANTOR + "</td>";
- tableHtml += "<td>" + formatRupiah(value.JUMLAH) + "</td>";
- tableHtml += "<td>" + formatRupiah(kota) + "</td>";
- tableHtml += "<td>" + formatRupiah(desa) + "</td>";
- tableHtml += "<td>" + round(jumlah_kota, 1) + "%</td>";
- tableHtml += "<td>" + round(jumlah_desa, 1) + "%</td>";
- tableHtml += "</tr>";
- // footHtml += "<tr>";
- // footHtml += "<th>TOTAL</th>";
- // footHtml += "</tr>";
- });
- footHtml += "<tr>";
- footHtml += "<th>TOTAL</th>";
- footHtml += "<th></th>";
- footHtml += "<th></th>";
- footHtml += "<th>" + total.toLocaleString() + "</th>";
- footHtml += "<th>" + totalkota.toLocaleString() + "</th>";
- footHtml += "<th>" + totalkab.toLocaleString() + "</th>";
- footHtml += "<th>" + round(total_kota, 1) + "%</th>";
- footHtml += "<th>" + round(totaldesa, 1) + "%</th>";
- footHtml += "</tr>";
- location.href = "#jenispekerjaan";
- $("#bpu_wilayah").html(tableHtml);
- $("#foot_wilayah").html(footHtml);
- $("#title_wilayah").html(title);
- $("#jenispekerjaan").fadeIn(1500);
- $("#namakantor").hide();
- $("#namapembina").hide();
- // Process the response here
- // console.log(response);
- }
- });
- }
- </script>
Add Comment
Please, Sign In to add comment