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.
 
 
 
 
 
 

186 lines
6.8 KiB

<?php
namespace App\Controllers\Kewilayahan\PoiGoogleMatoa;
use App\Libraries\AldLibrary;
use App\Libraries\KpdlLibrary;
class PoiGoogleMatoa extends \App\Controllers\Kewilayahan\Kytp
{
protected function get_poi_agg($request)
{
ini_set('max_input_vars', 3000);
$KpdlLib = new KpdlLibrary();
$Ald = new AldLibrary();
$username = session('nip');
$opsiWilZona = $Ald->decryptMe($request->getPost('opsiWilZona'), $username) ?? null;
$adm4_pcode = [];
foreach ($request->getPost('adm4_pcode') ?? [] as $key => $value) {
array_push($adm4_pcode, $Ald->decryptKpdl($value, $username));
}
$id_poly_zona = [];
foreach ($request->getPost('id_poly_zona') ?? [] as $key => $value) {
array_push($id_poly_zona, $Ald->decryptKpdl($value, $username));
}
$db = \Config\Database::connect();
$sqlGenerate = $db->table("KPDL_MV_JML_POI_AGG A")
->select("BULAN, sum(JML) as JML")
->where('TAHUN =', date('Y'))
->where('BULAN <=', (int) date('m'))
->groupBy('BULAN');
if ($opsiWilZona == 'wilayah') {
$sqlGenerate->whereIn('ADM4_PCODE', $adm4_pcode);
}
if ($opsiWilZona == 'zona') {
$sqlGenerate->whereIn('ID_POLY_ZONA', $id_poly_zona);
}
//pembatasan
if (!in_array(session('tpkantor'), ['KPDJP', 'Kanwil', 'KPP'])) {
return [];
}
if (session('kppadm') != '000') {
$sqlGenerate->groupStart();
if (session('tpkantor') == 'Kanwil') {
$sqlGenerate->join('KPDL_ZP_NAS_DIFF B', 'ID_POLY_ZONA = B.OGC_FID');
$sqlGenerate->where('B.KD_KANWIL', session('kwladm'));
}
if (session('tpkantor') == 'KPP') { //KPP
$sqlGenerate->join('KPDL_ZP_NAS_DIFF B', 'ID_POLY_ZONA = B.OGC_FID');
$currentPegawai = currentPegawai();
if (in_array($currentPegawai->KD_JAB_STRUKTURAL, ['602'])) { //AR
//zona
$sqlGenerate->orGroupStart()
->where('B.KD_UNIT_OR', $currentPegawai->KD_UNIT_ORGANISASI)
->where('B.KD_KPP', session('kppadm'))
->where('B.NIP_AR', session('nip'))
->groupEnd();
} else if (in_array($currentPegawai->KD_JAB_STRUKTURAL, ['401'])) { //kasi
//zona
$sqlGenerate->orGroupStart()
->where('B.KD_UNIT_OR', $currentPegawai->KD_UNIT_ORGANISASI)
->where('B.KD_KPP', session('kppadm'))
->groupEnd();
} else if (in_array($currentPegawai->KD_JAB_STRUKTURAL, ['304'])) { //Kepala Kantor
//zona
$sqlGenerate->orGroupStart()
->where('B.KD_KPP', session('kppadm'))
->groupEnd();
} else {
return [];
}
}
$sqlGenerate->groupEnd();
}
// print_r($sqlGenerate->getCompiledSelect());
// exit;
$sqlGenerate = $sqlGenerate->getCompiledSelect();
$data = $db->table("BULAN a")
->select("KODE as BULAN, JML")
->join("(" . $sqlGenerate . ") b", "KODE = BULAN", 'left', false)
->orderBy("BULAN", 'asc', false)->get()->getResult();
$dataPoiAgg = $KpdlLib->single_array($data, 'JML');
return $dataPoiAgg;
}
protected function get_kpdl_agg($request)
{
$Ald = new AldLibrary();
$KpdlLib = new KpdlLibrary();
$username = session('nip');
$opsiWilZona = $Ald->decryptMe($request->getPost('opsiWilZona'), $username) ?? null;
$adm4_pcode = [];
foreach ($request->getPost('adm4_pcode') ?? [] as $key => $value) {
array_push($adm4_pcode, $Ald->decryptKpdl($value, $username));
}
$id_poly_zona = [];
foreach ($request->getPost('id_poly_zona') ?? [] as $key => $value) {
array_push($id_poly_zona, $Ald->decryptKpdl($value, $username));
}
$db = \Config\Database::connect();
$sqlGenerate = $db->table("KPDL_MV_JML_KPDL_AGG")
->select("BULAN, sum(JML) as JML")
->where('TAHUN =', date('Y'))
->where('BULAN <=', (int) date('m'))
->groupBy('BULAN');
if ($opsiWilZona == 'wilayah') {
$sqlGenerate->whereIn('ADM4_PCODE', $adm4_pcode);
}
if ($opsiWilZona == 'zona') {
$sqlGenerate->whereIn('ID_POLY_ZONA', $id_poly_zona);
}
//pembatasan
if (!in_array(session('tpkantor'), ['KPDJP', 'Kanwil', 'KPP'])) {
return [];
}
if (session('kppadm') != '000') {
$sqlGenerate->groupStart();
if (session('tpkantor') == 'Kanwil') {
$sqlGenerate->join('KPDL_ZP_NAS_DIFF B', 'ID_POLY_ZONA = B.OGC_FID');
$sqlGenerate->where('B.KD_KANWIL', session('kwladm'));
}
if (session('tpkantor') == 'KPP') { //KPP
$sqlGenerate->join('KPDL_ZP_NAS_DIFF B', 'ID_POLY_ZONA = B.OGC_FID');
$currentPegawai = currentPegawai();
if (in_array($currentPegawai->KD_JAB_STRUKTURAL, ['602'])) { //AR
//zona
$sqlGenerate->orGroupStart()
->where('B.KD_UNIT_OR', $currentPegawai->KD_UNIT_ORGANISASI)
->where('B.KD_KPP', session('kppadm'))
->where('B.NIP_AR', session('nip'))
->groupEnd();
} else if (in_array($currentPegawai->KD_JAB_STRUKTURAL, ['401'])) { //kasi
//zona
$sqlGenerate->orGroupStart()
->where('B.KD_UNIT_OR', $currentPegawai->KD_UNIT_ORGANISASI)
->where('B.KD_KPP', session('kppadm'))
->groupEnd();
} else if (in_array($currentPegawai->KD_JAB_STRUKTURAL, ['304'])) { //Kepala Kantor
//zona
$sqlGenerate->orGroupStart()
->where('B.KD_KPP', session('kppadm'))
->groupEnd();
} else {
return [];
}
}
$sqlGenerate->groupEnd();
}
$sqlGenerate = $sqlGenerate->getCompiledSelect();
$data = $db->table("BULAN a")
->select("KODE as BULAN, JML")
->join("(" . $sqlGenerate . ") b", "KODE = BULAN", 'left', false)
->orderBy("BULAN", 'asc', false)->get()->getResult();
$dataPoiAgg = $KpdlLib->single_array($data, 'JML');
return $dataPoiAgg;
}
}