BlackBoY_

v3 index.php

Jun 20th, 2023 (edited)
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.11 KB | None | 0 0
  1. <script>
  2. $("#jenispekerjaan").hide();
  3. $("#namakantor").hide();
  4. $("#namapembina").hide();
  5.  
  6. function formatRupiah(angka, prefix) {
  7. var number_string = angka.replace(/[^,\d]/g, '').toString(),
  8. split = number_string.split(','),
  9. sisa = split[0].length % 3,
  10. rupiah = split[0].substr(0, sisa),
  11. ribuan = split[0].substr(sisa).match(/\d{3}/gi);
  12. // tambahkan titik jika yang di input sudah menjadi angka ribuan
  13. if (ribuan) {
  14. separator = sisa ? ',' : '';
  15. rupiah += separator + ribuan.join(',');
  16. }
  17. rupiah = split[1] != undefined ? rupiah + ',' + split[1] : rupiah;
  18. return prefix == undefined ? rupiah : (rupiah ? 'Rp. ' + rupiah : '');
  19. }
  20.  
  21. <?php
  22. include 'config.php';
  23. $query = "SELECT BLTH_PROSES, KODE_WILAYAH, NAMA_WILAYAH, SUM(JUMLAH) JUMLAH, SUM(JUMLAH_KOTA) JUMLAH_KOTA, SUM(JUMLAH_KAB) JUMLAH_KAB
  24. FROM (
  25. SELECT BLTH_PROSES, KODE_WILAYAH, NAMA_WILAYAH, SUM(TOTAL) JUMLAH,
  26. CASE WHEN LOKASI='KOTA' THEN SUM(TOTAL) END AS JUMLAH_KOTA,
  27. CASE WHEN LOKASI='KAB/DESA' THEN SUM(TOTAL) END AS JUMLAH_KAB
  28. FROM IPROJECT_PU_JAKON_KOTAKAB_RKP
  29. WHERE KODE_SEGMEN = 'JAKON'
  30. AND TGL_PROSES = (
  31. SELECT MAX(TGL_PROSES)
  32. FROM IPROJECT_PU_JAKON_KOTAKAB_RKP
  33. WHERE BLTH_PROSES=DATE(DATE_SUB(NOW(), INTERVAL DAYOFMONTH(NOW())-1 DAY))
  34. )
  35. GROUP BY BLTH_PROSES, KODE_WILAYAH, NAMA_WILAYAH, LOKASI) A
  36. GROUP BY BLTH_PROSES, KODE_WILAYAH, NAMA_WILAYAH";
  37.  
  38. $result_query = mysqli_query($host, $query);
  39. if (!$result_query) {
  40. die('Invalid query: ' . mysqli_error($host));
  41. }
  42. $labels = [];
  43. $data_kota = [];
  44. $data_desa = [];
  45. $data_combined = [];
  46. while ($row = mysqli_fetch_assoc($result_query)) {
  47. $labels[] = $row['NAMA_WILAYAH'];
  48. $data_kota[] = $row['JUMLAH_KOTA'];
  49. $data_desa[] = $row['JUMLAH_KAB'];
  50. }
  51. ?>
  52.  
  53. var ctx = document.getElementById('bar').getContext('2d');
  54.  
  55. // Membuat data untuk grafik batang
  56. var data = {
  57. labels: <?php echo json_encode($labels); ?>,
  58. datasets: [{
  59. label: 'KOTA',
  60. backgroundColor: '#fa5c7c',
  61. borderColor: '#fa5c7c',
  62. data: <?php echo json_encode($data_kota); ?>
  63. }, {
  64. label: 'KAB/DESA',
  65. backgroundColor: '#727cf5',
  66. borderColor: '#727cf5',
  67. data: <?php echo json_encode($data_desa); ?>
  68. }]
  69. };
  70.  
  71. // Konfigurasi grafik batang
  72. var options = {
  73. responsive: true,
  74. maintainAspectRatio: false
  75. };
  76.  
  77. // Membuat objek grafik batang baru
  78. var barChart = new Chart(ctx, {
  79. type: 'bar',
  80. data: data,
  81. options: options
  82. });
  83.  
  84. function round(number, decimals) {
  85. const factor = 10 ** decimals;
  86. return Math.round(number * factor) / factor;
  87. }
  88.  
  89. function wilayah(id) {
  90. $.ajax({
  91. type: "GET",
  92. url: "pu_jakon_wilayah.php",
  93. data: {
  94. kode_wilayah: id,
  95. },
  96. success: function(response) {
  97. var tableHtml = "";
  98. var footHtml = "";
  99. var title = "";
  100. var lastIndex = response.length - 1;
  101. var lastItem = response[lastIndex];
  102. // console.log('tes',lastItem.Total);
  103. var total = lastItem.Total;
  104. var totalkota = lastItem.TotalKota;
  105. var totalkab = lastItem.TotalDesa;
  106. var total_kota = totalkota / total * 100;
  107. var totaldesa = totalkab / total * 100
  108. title += "<h3 class='card-title' > " + response[0].NAMA_WILAYAH + "</h3>";
  109. $.each(response, function(index, value) {
  110. var kota = value.JUMLAH_KOTA
  111. var desa = value.JUMLAH_KAB
  112. var jumlah = value.JUMLAH
  113. var jumlah_kota = kota / jumlah * 100
  114. var jumlah_desa = desa / jumlah * 100
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121. tableHtml += "<input type='hidden' id='wilayah' value='" + value.KODE_WILAYAH + "'>";
  122. tableHtml += "<tr>";
  123. tableHtml += "<td>" + (index + 1) + "</td>";
  124.  
  125. tableHtml += "<td>" + value.KODE_KANTOR + "</td>";
  126. tableHtml += "<td>" + value.NAMA_KANTOR + "</td>";
  127. tableHtml += "<td>" + formatRupiah(value.JUMLAH) + "</td>";
  128. tableHtml += "<td>" + formatRupiah(kota) + "</td>";
  129. tableHtml += "<td>" + formatRupiah(desa) + "</td>";
  130. tableHtml += "<td>" + round(jumlah_kota, 1) + "%</td>";
  131. tableHtml += "<td>" + round(jumlah_desa, 1) + "%</td>";
  132. tableHtml += "</tr>";
  133. // footHtml += "<tr>";
  134. // footHtml += "<th>TOTAL</th>";
  135. // footHtml += "</tr>";
  136. });
  137.  
  138. footHtml += "<tr>";
  139. footHtml += "<th>TOTAL</th>";
  140. footHtml += "<th></th>";
  141. footHtml += "<th></th>";
  142. footHtml += "<th>" + total.toLocaleString() + "</th>";
  143. footHtml += "<th>" + totalkota.toLocaleString() + "</th>";
  144. footHtml += "<th>" + totalkab.toLocaleString() + "</th>";
  145. footHtml += "<th>" + round(total_kota, 1) + "%</th>";
  146. footHtml += "<th>" + round(totaldesa, 1) + "%</th>";
  147. footHtml += "</tr>";
  148. location.href = "#jenispekerjaan";
  149.  
  150. $("#bpu_wilayah").html(tableHtml);
  151. $("#foot_wilayah").html(footHtml);
  152. $("#title_wilayah").html(title);
  153.  
  154. $("#jenispekerjaan").fadeIn(1500);
  155. $("#namakantor").hide();
  156. $("#namapembina").hide();
  157. // Process the response here
  158. // console.log(response);
  159. }
  160. });
  161. }
  162.  
  163. $("#year_blt").select2()
  164.  
  165. function year_blt(year) {
  166. $.ajax({
  167. type: "GET",
  168. url: "year_blthproses_jakon.php",
  169. data: {
  170. year: year
  171. },
  172. success: function(response) {
  173. // var tahun = response[0].YEAR
  174. // var bulan = response[0].BLTH_PROSES
  175. var tableHtml = "<option value=''>Choose</option>"; // Tambahkan opsi "Choose"
  176. $.each(response, function(index, value) {
  177. var optionValue = value.BLTH_PROSES;
  178. var optionText = value.BULAN;
  179. var tahun = value.YEAR
  180. tableHtml += "<option value='" + optionValue + " " + tahun + "'>" + optionText + "</option>";
  181.  
  182. });
  183.  
  184. $("#month_year").html(tableHtml);
  185. }
  186. });
  187. }
  188.  
  189. function month_blt(month_year) {
  190. // Split month_year value into month and year
  191. var parts = month_year.split(" ");
  192. var month = parts[0];
  193. var year = parts[1];
  194.  
  195. $.ajax({
  196. type: "GET",
  197. url: "month_blthproses_jakon.php",
  198. data: {
  199. month: month,
  200. year: year
  201. },
  202. success: function(response) {
  203. // console.log('masuk', response);
  204. var tableHtml = "";
  205. var footHtml = "";
  206. var title = "";
  207.  
  208. var lastIndex = response.length - 1;
  209. var total = 0;
  210. var totalkota = 0;
  211. var totalkab = 0;
  212.  
  213. if (lastIndex >= 0) {
  214. var lastItem = response[lastIndex];
  215. total = lastItem.Total;
  216. totalkota = lastItem.TotalKota;
  217. totalkab = lastItem.TotalDesa;
  218. }
  219.  
  220. var total_kota = totalkota / total * 100;
  221. var totaldesa = totalkab / total * 100;
  222.  
  223. var labels = [];
  224. var data_kota = [];
  225. var data_desa = [];
  226.  
  227. $.each(response, function(index, value) {
  228. console.log('tes', value)
  229. var kota = value.JUMLAH_KOTA;
  230. var desa = value.JUMLAH_KAB;
  231. var jumlah = value.JUMLAH;
  232. var jumlah_kota = kota / jumlah * 100;
  233. var jumlah_desa = desa / jumlah * 100;
  234.  
  235. labels.push(value.NAMA_WILAYAH);
  236. data_kota.push(kota);
  237. data_desa.push(desa);
  238.  
  239. tableHtml += "<input type='hidden' id='years' value='" + value.YEAR + "'>";
  240. tableHtml += "<input type='hidden' id='months' value='" + value.MONTH + "'>";
  241. tableHtml += "<tr>";
  242. tableHtml += "<td>" + (index + 1) + "</td>";
  243. tableHtml += "<td><a class='colored' onclick='filter_wilayah(\"" + value.KODE_WILAYAH + "\")' >" + value.KODE_WILAYAH + "</a></td>";
  244. tableHtml += "<td>" + value.NAMA_WILAYAH + "</td>";
  245. tableHtml += "<td>" + formatRupiah(value.JUMLAH) + "</td>";
  246. tableHtml += "<td>" + formatRupiah(kota) + "</td>";
  247. tableHtml += "<td>" + formatRupiah(desa) + "</td>";
  248. tableHtml += "<td>" + round(jumlah_kota, 1) + "%</td>";
  249. tableHtml += "<td>" + round(jumlah_desa, 1) + "%</td>";
  250. tableHtml += "</tr>";
  251. });
  252.  
  253. footHtml += "<tr>";
  254. footHtml += "<th>TOTAL</th>";
  255. footHtml += "<th></th>";
  256. footHtml += "<th></th>";
  257. footHtml += "<th>" + total.toLocaleString() + "</th>";
  258. footHtml += "<th>" + totalkota.toLocaleString() + "</th>";
  259. footHtml += "<th>" + totalkab.toLocaleString() + "</th>";
  260. footHtml += "<th>" + round(total_kota, 1) + "%</th>";
  261. footHtml += "<th>" + round(totaldesa, 1) + "%</th>";
  262. footHtml += "</tr>";
  263.  
  264. $("#filter").html(tableHtml); // Update the table body with the new HTML
  265. $("#filter_foot").html(footHtml); // Update the table footer with the new HTML
  266.  
  267. // Update the chart data
  268. barChart.data.labels = labels;
  269. barChart.data.datasets[0].data = data_kota;
  270. barChart.data.datasets[1].data = data_desa;
  271. barChart.update(); // Redraw the chart
  272. }
  273. });
  274. }
  275. function filter_wilayah(id) {
  276. var year = $("#years").val();
  277. var month = $("#months").val();
  278.  
  279. $.ajax({
  280. type: "GET",
  281. url: "filter_wilayah_jakon.php",
  282. data: {
  283. kode_wilayah: id,
  284. year: year,
  285. month: month,
  286. },
  287. success: function(response) {
  288. var tableHtml = "";
  289. var footHtml = "";
  290. var title = "";
  291. var lastIndex = response.length - 1;
  292. var lastItem = response[lastIndex];
  293. // console.log('tes',lastItem.Total);
  294. var total = lastItem.Total;
  295. var totalkota = lastItem.TotalKota;
  296. var totalkab = lastItem.TotalDesa;
  297. var total_kota = totalkota / total * 100;
  298. var totaldesa = totalkab / total * 100
  299. title += "<h3 class='card-title' > " + response[0].NAMA_WILAYAH + "</h3>";
  300. $.each(response, function(index, value) {
  301. var kota = value.JUMLAH_KOTA
  302. var desa = value.JUMLAH_KAB
  303. var jumlah = value.JUMLAH
  304. var jumlah_kota = kota / jumlah * 100
  305. var jumlah_desa = desa / jumlah * 100
  306.  
  307.  
  308.  
  309.  
  310. tableHtml += "<input type='hidden' id='wilayah' value='" + value.KODE_WILAYAH + "'>";
  311. tableHtml += "<input type='hidden' id='yea' value='" + value.YEAR + "'>";
  312. tableHtml += "<input type='hidden' id='mont' value='" + value.MONTH + "'>";
  313. tableHtml += "<tr>";
  314. tableHtml += "<td>" + (index + 1) + "</td>";
  315.  
  316. tableHtml += "<td>" + value.KODE_KANTOR + "</td>";
  317. tableHtml += "<td>" + value.NAMA_KANTOR + "</td>";
  318. tableHtml += "<td>" + formatRupiah(value.JUMLAH) + "</td>";
  319. tableHtml += "<td>" + formatRupiah(kota) + "</td>";
  320. tableHtml += "<td>" + formatRupiah(desa) + "</td>";
  321. tableHtml += "<td>" + round(jumlah_kota, 1) + "%</td>";
  322. tableHtml += "<td>" + round(jumlah_desa, 1) + "%</td>";
  323. tableHtml += "</tr>";
  324. // footHtml += "<tr>";
  325. // footHtml += "<th>TOTAL</th>";
  326. // footHtml += "</tr>";
  327. });
  328.  
  329. footHtml += "<tr>";
  330. footHtml += "<th>TOTAL</th>";
  331. footHtml += "<th></th>";
  332. footHtml += "<th></th>";
  333. footHtml += "<th>" + total.toLocaleString() + "</th>";
  334. footHtml += "<th>" + totalkota.toLocaleString() + "</th>";
  335. footHtml += "<th>" + totalkab.toLocaleString() + "</th>";
  336. footHtml += "<th>" + round(total_kota, 1) + "%</th>";
  337. footHtml += "<th>" + round(totaldesa, 1) + "%</th>";
  338. footHtml += "</tr>";
  339. location.href = "#jenispekerjaan";
  340.  
  341. $("#bpu_wilayah").html(tableHtml);
  342. $("#foot_wilayah").html(footHtml);
  343. $("#title_wilayah").html(title);
  344.  
  345. $("#jenispekerjaan").fadeIn(1500);
  346. $("#namakantor").hide();
  347. $("#namapembina").hide();
  348. // Process the response here
  349. // console.log(response);
  350. }
  351. });
  352.  
  353. }
  354. </script>
Add Comment
Please, Sign In to add comment