You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
342 lines
14 KiB
342 lines
14 KiB
7 months ago
|
<?php
|
||
3 months ago
|
namespace App\Controllers\Kewilayahan\Monitoring;
|
||
7 months ago
|
|
||
6 months ago
|
use App\Libraries\AldLibrary;
|
||
7 months ago
|
use CodeIgniter\API\ResponseTrait;
|
||
|
use CodeIgniter\Controller;
|
||
6 months ago
|
use DateTime;
|
||
|
use DateTimeZone;
|
||
7 months ago
|
|
||
3 months ago
|
class Kegiatan extends Controller
|
||
7 months ago
|
{
|
||
|
|
||
|
use ResponseTrait;
|
||
6 months ago
|
public function __construct()
|
||
|
{
|
||
|
|
||
|
$kppadm = session('kppadm');
|
||
|
if (!in_array($kppadm, ['000'])) {
|
||
6 months ago
|
// exit;
|
||
6 months ago
|
}
|
||
|
|
||
|
}
|
||
|
|
||
7 months ago
|
public function index()
|
||
|
{
|
||
|
if (session('isLogin')) {
|
||
|
echo view('inc/head');
|
||
|
echo view('inc/navbar');
|
||
|
echo view('inc/sidebar');
|
||
|
echo view('kewilayahan/monitoring/monitoring');
|
||
|
echo view('inc/footer');
|
||
|
} else {
|
||
|
return redirect()->to('auth');
|
||
|
}
|
||
|
}
|
||
|
|
||
6 months ago
|
public function data()
|
||
|
{
|
||
|
|
||
|
$config = config(\Config\App::class, false);
|
||
|
|
||
|
$Ald = new AldLibrary;
|
||
|
$username = session('nip');
|
||
|
$kanwil = [];
|
||
|
foreach ($this->request->getPost('kanwil') ?? [] as $key => $value) {
|
||
|
$kanwil[] = $Ald->decryptMe($value, $username);
|
||
|
}
|
||
|
$kpp = [];
|
||
|
foreach ($this->request->getPost('kpp') ?? [] as $key => $value) {
|
||
|
$kpp[] = $Ald->decryptMe($value, $username);
|
||
|
}
|
||
|
|
||
|
$tanggalAwal = $this->request->getPost('tanggalAwal');
|
||
|
$tanggalAkhir = $this->request->getPost('tanggalAkhir');
|
||
|
$tgl_awal = new DateTime($tanggalAwal);
|
||
|
$tgl_awal->setTimezone(new DateTimeZone($config->appTimezone));
|
||
|
|
||
|
$tgl_akhir = new DateTime($tanggalAkhir);
|
||
|
$tgl_akhir->setTimezone(new DateTimeZone($config->appTimezone));
|
||
|
|
||
|
$db = \Config\Database::connect();
|
||
|
$sql = "SELECT
|
||
|
A.KD_KANWIL,
|
||
|
A.NAMA_KANWIL ,
|
||
|
A.KPPADM,
|
||
|
A.KODE_SEKSI,
|
||
|
A.KODE_PEG,
|
||
|
A.NAMA_KANTOR,
|
||
|
A.NAMA_UNIT_ES4,
|
||
|
A.NAMA_JABATAN,
|
||
|
A.NAMA,
|
||
|
COALESCE (B.JML,
|
||
|
0) JML,
|
||
|
'TRUE' AS ISEXIST_INWAS
|
||
|
FROM
|
||
|
--KASI DAN AR WAS
|
||
|
(
|
||
|
SELECT
|
||
|
KPPADM,
|
||
|
KPPADM || '-' || KD_UNIT_ORGANISASI AS KODE_SEKSI,
|
||
|
KPPADM || '-' || KD_UNIT_ORGANISASI || '-' || NIP9 AS KODE_PEG,
|
||
|
P.NIP9,
|
||
|
P.NAMA,
|
||
|
NAMA_KANTOR,
|
||
|
KD_UNIT_ORGANISASI,
|
||
|
P.NAMA_UNIT_ES4,
|
||
|
KD_JAB_STRUKTURAL,
|
||
|
NAMA_JABATAN,
|
||
|
B.KD_KANWIL,
|
||
|
C.NAMA AS NAMA_KANWIL
|
||
|
FROM
|
||
|
PEGAWAI P
|
||
|
LEFT JOIN REF_KPP B ON
|
||
|
(P.KPPADM = B.KD_KPP)
|
||
|
LEFT JOIN REF_KANWIL C ON
|
||
|
(B.KD_KANWIL = C.KODE)
|
||
|
WHERE
|
||
|
P.KD_JAB_STRUKTURAL IN ('602', '401')
|
||
|
AND (KD_UNIT_ORGANISASI BETWEEN '0421071700' AND '0421072200'
|
||
|
OR KD_UNIT_ORGANISASI BETWEEN '0424071800' AND '0424072300') AND kppadm in :kpp: ) A
|
||
|
LEFT JOIN -- KPDL_PETUGAS_PEREKAM_AGG
|
||
|
( SELECT KODE_SEKSI_PEREKAM, KODE_PEG_PEREKAM, NIP_PEREKAM , count(1) jml
|
||
|
FROM --KPDL_PETUGAS_REKAM
|
||
6 months ago
|
(SELECT KODE_SEKSI_PEREKAM, KODE_PEG_PEREKAM,
|
||
|
ID_KPDL_SUBJEK, KPP_ADM_PEREKAM , CREATED_BY NIP_PEREKAM,
|
||
|
CREATION_DATE, ORG_APPROVAL_KASI, NIP_APPROVAL_KASI,
|
||
|
TGL_APPROVAL_KASI, STS_APPROVAL_KASI, TGL_APPROVAL_PKD,
|
||
|
STS_APPROVAL_PKD
|
||
|
FROM KPDL_MV_LOKASI_SUBJEK a WHERE trunc(a.CREATION_DATE) BETWEEN DATE :tanggalawal: AND DATE :tanggalakhir:) A
|
||
6 months ago
|
GROUP BY KODE_SEKSI_PEREKAM, KODE_PEG_PEREKAM, NIP_PEREKAM) B ON
|
||
|
(A.KODE_PEG = B.KODE_PEG_PEREKAM)
|
||
|
UNION ALL
|
||
|
-- EX ANGGOTA WAS
|
||
|
SELECT
|
||
|
A.KD_KANWIL,
|
||
|
A.NAMA_KANWIL,
|
||
|
A.KPPADM,
|
||
|
A.KODE_SEKSI,
|
||
|
B.KODE_PEG_PEREKAM,
|
||
|
A.NAMA_KANTOR,
|
||
|
A.NAMA_UNIT_ES4,
|
||
|
' EX ANGGOTA' AS NAMA_JABATAN,
|
||
|
C.NAMA,
|
||
|
COALESCE (B.JML,
|
||
|
0) JML,
|
||
|
'FALSE' AS ISEXIST_INWAS
|
||
|
FROM
|
||
|
-- KPDL_SEKSIWAS_SEINDONESIA
|
||
|
( SELECT
|
||
|
KPPADM,
|
||
|
KPPADM||'-'||KD_UNIT_ORGANISASI AS kode_seksi, KPPADM||'-'||KD_UNIT_ORGANISASI ||'-'||nip9 AS kode_peg, p.NIP9, p.nama,
|
||
|
NAMA_KANTOR, KD_UNIT_ORGANISASI, p.NAMA_UNIT_ES4, KD_JAB_STRUKTURAL, NAMA_JABATAN, b.kd_kanwil, c.nama AS nama_kanwil FROM PEGAWAI p
|
||
|
LEFT JOIN ref_kpp b ON (p.kppadm = b.kd_kpp)
|
||
|
LEFT JOIN ref_kanwil c ON (b.kd_kanwil= c.kode)
|
||
|
WHERE p.KD_JAB_STRUKTURAL ='401'
|
||
|
AND (KD_UNIT_ORGANISASI BETWEEN '0421071700' AND '0421072200' OR KD_UNIT_ORGANISASI BETWEEN '0424071800' AND '0424072300' )
|
||
|
AND kppadm in :kpp:) A
|
||
|
JOIN
|
||
|
--KASI DAN AR WAS
|
||
|
(
|
||
|
SELECT
|
||
|
B.KODE_SEKSI_PEREKAM ,
|
||
|
KODE_PEG_PEREKAM ,
|
||
|
NIP_PEREKAM,
|
||
|
JML
|
||
|
FROM
|
||
|
-- KPDL_PETUGAS_PEREKAM_AGG
|
||
|
( SELECT KODE_SEKSI_PEREKAM, KODE_PEG_PEREKAM, NIP_PEREKAM , count(1) jml
|
||
|
FROM --KPDL_PETUGAS_REKAM
|
||
6 months ago
|
( SELECT KODE_SEKSI_PEREKAM, KODE_PEG_PEREKAM,
|
||
|
ID_KPDL_SUBJEK, KPP_ADM_PEREKAM, CREATED_BY NIP_PEREKAM,
|
||
|
CREATION_DATE, ORG_APPROVAL_KASI, NIP_APPROVAL_KASI,
|
||
|
TGL_APPROVAL_KASI, STS_APPROVAL_KASI, TGL_APPROVAL_PKD,
|
||
|
STS_APPROVAL_PKD
|
||
|
FROM KPDL_MV_LOKASI_SUBJEK a WHERE trunc(a.CREATION_DATE) BETWEEN DATE :tanggalawal: AND DATE :tanggalakhir:) a
|
||
6 months ago
|
GROUP BY KODE_SEKSI_PEREKAM, KODE_PEG_PEREKAM, NIP_PEREKAM) B
|
||
|
WHERE
|
||
|
B.KODE_PEG_PEREKAM NOT IN (
|
||
|
SELECT
|
||
|
KPPADM || '-' || KD_UNIT_ORGANISASI || '-' || NIP9
|
||
|
FROM
|
||
|
PEGAWAI P
|
||
|
WHERE
|
||
|
P.KD_JAB_STRUKTURAL IN ('602', '401')
|
||
|
AND (KD_UNIT_ORGANISASI BETWEEN '0421071700' AND '0421072200'
|
||
|
OR KD_UNIT_ORGANISASI BETWEEN '0424071800' AND '0424072300'))) B
|
||
|
ON
|
||
|
(A.KODE_SEKSI = B.KODE_SEKSI_PEREKAM)
|
||
|
LEFT JOIN PEGAWAI C ON
|
||
|
(B.NIP_PEREKAM = C.NIP9) ORDER BY KD_KANWIL ASC, NAMA_KANTOR DESC, NAMA_UNIT_ES4 ASC, NAMA_JABATAN DESC";
|
||
6 months ago
|
|
||
6 months ago
|
$data = $db->query($sql, [
|
||
|
'tanggalawal' => $tgl_awal->format('Y-m-d'),
|
||
|
'tanggalakhir' => $tgl_akhir->format('Y-m-d'),
|
||
|
'kpp' => $kpp,
|
||
|
])->getResultArray();
|
||
|
helper('array');
|
||
|
$groupingData = array_group_by($data, ['KD_KANWIL', 'KPPADM', 'KODE_SEKSI']);
|
||
|
|
||
|
$bentukanArray = [];
|
||
|
$data1 = [];
|
||
|
foreach ($groupingData as $key1 => $value1) { //kanwil
|
||
|
$data1['KEY_LABEL'] = $key1;
|
||
|
$data1['LABEL'] = '';
|
||
|
$data1['JUMLAH'] = 0;
|
||
|
$data1['JUMLAH_AR'] = 0;
|
||
|
$data1['RATA_RATA'] = 0;
|
||
|
$data1['subRows'] = [];
|
||
|
|
||
|
$data2 = [];
|
||
|
foreach ($value1 as $key2 => $value2) { //kpp
|
||
|
$data2['KEY_LABEL'] = $key1 . '-' . $key2;
|
||
|
$data2['LABEL'] = '';
|
||
|
$data2['JUMLAH'] = 0;
|
||
|
$data2['JUMLAH_AR'] = 0;
|
||
|
$data2['RATA_RATA'] = 0;
|
||
|
$data2['subRows'] = [];
|
||
|
|
||
|
$data3 = [];
|
||
|
foreach ($value2 as $key3 => $value3) { //seksi
|
||
|
$data3['KEY_LABEL'] = $key1 . '-' . $key3;
|
||
|
$data3['LABEL'] = '';
|
||
|
$data3['NAMA_KANTOR'] = '';
|
||
|
$data3['JUMLAH'] = 0;
|
||
|
$data3['JUMLAH_AR'] = 0;
|
||
|
$data3['RATA_RATA'] = 0;
|
||
|
$data3['subRows'] = [];
|
||
|
|
||
|
$data4 = [];
|
||
|
foreach ($value3 as $key4 => $value4) { //AR
|
||
|
$data4['KEY_LABEL'] = $key1 . '-' . $value4['KODE_PEG'];
|
||
|
$data4['LABEL'] = $value4['NAMA'];
|
||
|
$data4['JUMLAH'] = (float) $value4['JML'];
|
||
|
|
||
|
foreach ($value4 as $key5 => $value5) {
|
||
|
$data4[$key5] = $value5;
|
||
|
}
|
||
|
|
||
|
$data3['LABEL'] = $value4['NAMA_UNIT_ES4'];
|
||
|
$data3['NAMA_KANTOR'] = $value4['NAMA_KANTOR'];
|
||
|
$data2['LABEL'] = $value4['NAMA_KANTOR'];
|
||
|
$data1['LABEL'] = $value4['NAMA_KANWIL'];
|
||
|
|
||
|
$data3['JUMLAH'] += $data4['JUMLAH'];
|
||
|
$data3['JUMLAH_AR'] += ($value4['ISEXIST_INWAS'] == 'TRUE' && $value4['NAMA_JABATAN'] == 'Account Representative' ? 1 : 0);
|
||
|
array_push($data3['subRows'], $data4);
|
||
|
}
|
||
|
$data3['RATA_RATA'] = $data3['JUMLAH_AR'] == 0 ? 0 : $data3['JUMLAH'] / $data3['JUMLAH_AR'];
|
||
|
$data2['JUMLAH'] += $data3['JUMLAH'];
|
||
|
$data2['JUMLAH_AR'] += $data3['JUMLAH_AR'];
|
||
|
array_push($data2['subRows'], $data3);
|
||
|
}
|
||
|
$data2['RATA_RATA'] = $data2['JUMLAH_AR'] == 0 ? 0 : $data2['JUMLAH'] / $data2['JUMLAH_AR'];
|
||
|
$data1['JUMLAH'] += $data2['JUMLAH'];
|
||
|
$data1['JUMLAH_AR'] += $data2['JUMLAH_AR'];
|
||
|
array_push($data1['subRows'], $data2);
|
||
|
}
|
||
|
$data1['RATA_RATA'] = $data1['JUMLAH_AR'] == 0 ? 0 : $data1['JUMLAH'] / $data1['JUMLAH_AR'];
|
||
|
array_push($bentukanArray, $data1);
|
||
|
}
|
||
|
$dataReturn['data'] = $bentukanArray;
|
||
|
|
||
|
$tempData = $bentukanArray;
|
||
|
$dataChart = $this->urutKanwil($bentukanArray);
|
||
|
$dataReturn['urutKanwil'] = $dataChart['urutKanwil'];
|
||
|
$dataReturn['urutKpp'] = $dataChart['urutKpp'];
|
||
|
$dataReturn['urutSeksi'] = $dataChart['urutSeksi'];
|
||
|
$dataReturn['urutPegawai'] = $dataChart['urutPegawai'];
|
||
|
|
||
|
return $this->respond($dataReturn, 200);
|
||
|
}
|
||
|
|
||
|
protected function urutKanwil($tempData)
|
||
|
{
|
||
|
array_sort_by_multiple_keys($tempData, ['RATA_RATA' => SORT_DESC, 'KEY_LABEL' => SORT_ASC]);
|
||
|
//kanwil
|
||
|
$kanwil = array_slice($tempData, 0, 5);
|
||
|
|
||
|
//kpp
|
||
|
$kppInKanwil = [];
|
||
|
foreach ($tempData as $key => $value) {
|
||
|
foreach ($value['subRows'] as $key2 => $value2) {
|
||
|
array_push($kppInKanwil, $value2);
|
||
|
}
|
||
|
}
|
||
|
array_sort_by_multiple_keys($kppInKanwil, ['RATA_RATA' => SORT_DESC, 'KEY_LABEL' => SORT_ASC]);
|
||
|
$kpp = array_slice($kppInKanwil, 0, 5);
|
||
|
|
||
|
//seksi
|
||
|
$seksiInKpp = [];
|
||
|
foreach ($kppInKanwil as $key => $value) {
|
||
|
foreach ($value['subRows'] as $key2 => $value2) {
|
||
|
array_push($seksiInKpp, $value2);
|
||
|
}
|
||
|
}
|
||
|
array_sort_by_multiple_keys($seksiInKpp, ['RATA_RATA' => SORT_DESC, 'KEY_LABEL' => SORT_ASC]);
|
||
|
$seksi = array_slice($seksiInKpp, 0, 5);
|
||
|
|
||
|
//ar Aktif
|
||
|
$arInSeksi = [];
|
||
|
foreach ($seksiInKpp as $key => $value) {
|
||
|
foreach ($value['subRows'] as $key2 => $value2) {
|
||
|
if ($value2['NAMA_JABATAN'] == 'Account Representative' && $value2['ISEXIST_INWAS'] == 'TRUE') {
|
||
|
array_push($arInSeksi, $value2);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
array_sort_by_multiple_keys($arInSeksi, ['JUMLAH' => SORT_DESC]);
|
||
|
$ar = array_slice($arInSeksi, 0, 5);
|
||
|
|
||
|
foreach ($kanwil as $key => $value) {
|
||
|
unset($kanwil[$key]['subRows']);
|
||
|
}
|
||
|
|
||
|
foreach ($kpp as $key => $value) {
|
||
|
unset($kpp[$key]['subRows']);
|
||
|
}
|
||
|
foreach ($seksi as $key => $value) {
|
||
|
unset($seksi[$key]['subRows']);
|
||
|
}
|
||
|
|
||
|
$data['urutKanwil'] = $kanwil;
|
||
|
$data['urutKpp'] = $kpp;
|
||
|
$data['urutSeksi'] = $seksi;
|
||
|
$data['urutPegawai'] = $ar;
|
||
|
return $data;
|
||
|
}
|
||
|
|
||
|
protected function urutKpp($tempData)
|
||
|
{
|
||
|
|
||
|
$kppInKanwil = [];
|
||
|
foreach ($tempData as $key => $value) {
|
||
|
foreach ($value['subRows'] as $key2 => $value2) {
|
||
|
array_push($kppInKanwil, $value2);
|
||
|
// # code...
|
||
|
}
|
||
|
}
|
||
|
array_sort_by_multiple_keys($kppInKanwil, ['RATA_RATA' => SORT_DESC, 'KEY_LABEL' => SORT_ASC]);
|
||
|
//hilangkan child subRows
|
||
|
$dataRet = array_slice($kppInKanwil, 0, 5);
|
||
|
return $dataRet;
|
||
|
}
|
||
|
|
||
|
protected function urutSeksi($tempData)
|
||
|
{
|
||
|
|
||
|
$kppInKanwil = [];
|
||
|
foreach ($tempData as $key => $value) {
|
||
|
foreach ($value['subRows'] as $key2 => $value2) {
|
||
|
array_push($kppInKanwil, $value2);
|
||
|
}
|
||
|
}
|
||
|
array_sort_by_multiple_keys($kppInKanwil, ['RATA_RATA' => SORT_DESC, 'KEY_LABEL' => SORT_ASC]);
|
||
|
|
||
|
//hilangkan child subRows
|
||
|
$dataRet = array_slice($kppInKanwil, 0, 5);
|
||
|
return $dataRet;
|
||
|
}
|
||
|
|
||
7 months ago
|
}
|