decryptMe($request->getPost('opsiWilZona'), $username); $adm4_pcode = []; foreach ($request->getPost('adm4_pcode') ?? [] as $key => $value) { $adm4_pcode[] = $Ald->decryptKpdl($value, $username); } $id_poly_zona = []; foreach ($request->getPost('id_poly_zona') ?? [] as $key => $value) { $id_poly_zona[] = $Ald->decryptMe($value, $username); } $nip_ar_perekam = []; foreach ($request->getPost('nip_ar_perekam') ?? [] as $key => $value) { $nip_ar_perekam[] = $Ald->decryptMe($value, $username); } $nip_ar_pengampu = []; foreach ($request->getPost('nip_ar_pengampu') ?? [] as $key => $value) { $nip_ar_pengampu[] = $Ald->decryptMe($value, $username); } $db = \Config\Database::connect(); $KpdlLibrary = new KpdlLibrary; if ($bulan == 'semua') { $npwp = $db->table('KPDL_MV_LOKASI_SUBJEK A') ->select("TO_CHAR(CREATION_DATE,'MM') BULAN, count(1) JML") ->join('KPDL_REF_STATUS_SPT', 'ID_STATUS_SPT = STATUS_SPT_TAHUNAN_TERAKHIR', 'left') ->join('PEGAWAI C', 'NIP_AR_ZONA = C.NIP9', 'left') ->join('KPDL_MV_OBJEK_PERSUBJEK D', 'A.ID_KPDL_SUBJEK = D.ID_KPDL_SUBJEK', 'left') ->join('PEGAWAI E', 'NIP_AR_PENGAMPU = E.NIP9', 'left') ->where("TO_CHAR(CREATION_DATE, 'YYYY') =", date('Y')) ->where("TO_CHAR(CREATION_DATE,'MM') <=", date('m')) ->groupBy("TO_CHAR(CREATION_DATE,'MM')"); if ($opsiWilZona == 'wilayah') { $npwp = $npwp->whereIn('ADM4_PCODE', $adm4_pcode); } if ($opsiWilZona == 'zona') { $npwp = $npwp->whereIn('ID_POLY_ZONA', $id_poly_zona); } if ($opsiWilZona == 'perekam') { $npwp = $npwp->whereIn('A.CREATED_BY', $nip_ar_perekam); } if ($opsiWilZona == 'pengampu') { $npwp = $npwp->whereIn('NIP_AR_PENGAMPU', $nip_ar_pengampu); } //pembatasan if (!in_array(session('tpkantor'), ['KPDJP', 'Kanwil', 'KPP'])) { return []; } if (session('kppadm') != '000') { $npwp->groupStart(); if (session('tpkantor') == 'Kanwil') { // kanwil $npwp->join('KPDL_ZP_NAS_DIFF B', 'ID_POLY_ZONA = B.OGC_FID'); $npwp->orGroupStart(); $npwp->where('B.KD_KANWIL', session('kwladm')); $npwp->groupEnd(); } if (session('tpkantor') == 'KPP') { //KPP $npwp->join('KPDL_ZP_NAS_DIFF B', 'ID_POLY_ZONA = B.OGC_FID'); $currentPegawai = currentPegawai(); if (in_array($currentPegawai->KD_JAB_STRUKTURAL, ['602'])) { //AR //zona $npwp->orGroupStart() ->where('B.KD_UNIT_OR', $currentPegawai->KD_UNIT_ORGANISASI) ->where('A.KPPADM_ZONA', session('kppadm')) ->where('A.NIP_AR_ZONA', session('nip')) ->groupEnd(); //perekam $npwp->orGroupStart() ->where('A.KODE_PEG_PEREKAM', session('kppadm') . '-' . $currentPegawai->KD_UNIT_ORGANISASI . '-' . session('nip')) //direkam saat di seksi aktif saat ini ->groupEnd(); //pengampu $npwp->orGroupStart() ->where('A.NIP_AR_PENGAMPU', session('nip')) ->where('A.KPPADM_PENGAMPU', session('kppadm')) ->groupEnd(); } else if (in_array($currentPegawai->KD_JAB_STRUKTURAL, ['401'])) { //kasi //zona $npwp->orGroupStart() ->where('B.KD_UNIT_OR', $currentPegawai->KD_UNIT_ORGANISASI) ->where('A.KPPADM_ZONA', session('kppadm')) ->groupEnd(); //perekam $npwp->orGroupStart() ->where('A.KODE_SEKSI_PEREKAM', session('kppadm') . '-' . $currentPegawai->KD_UNIT_ORGANISASI) ->groupEnd(); //pengampu $npwp->join('PEGAWAI C', 'A.NIP_AR_PENGAMPU=C.NIP9', 'left'); $npwp->orGroupStart() ->where('C.KD_UNIT_ORGANISASI', $currentPegawai->KD_UNIT_ORGANISASI) ->where('C.KPPADM', session('kppadm')) ->where('A.KPPADM_PENGAMPU', session('kppadm')) ->groupEnd(); } else if (in_array($currentPegawai->KD_JAB_STRUKTURAL, ['304'])) { //Kepala Kantor //zona $npwp->orGroupStart() ->where('A.KPPADM_ZONA', session('kppadm')) ->groupEnd(); //perekam $npwp->orGroupStart() ->where('A.KPP_ADM_PEREKAM', session('kppadm') . '-' . $currentPegawai->KD_UNIT_ORGANISASI) ->groupEnd(); //pengampu $npwp->join('PEGAWAI C', 'A.NIP_AR_PENGAMPU=C.NIP9', 'left'); $npwp->orGroupStart() ->where('A.KPPADM_PENGAMPU', session('kppadm')) ->groupEnd(); } else { return []; } } $npwp->groupEnd(); } $npwp = $npwp->getCompiledSelect(); // print_r($npwp); // exit; $data = $db->table('BULAN A') ->select("A.KODE as BULAN, C.JML") ->join("(" . $npwp . ") C", 'A.KODE = C.BULAN', 'left') ->orderBy('BULAN'); return $KpdlLibrary->single_array($data->get()->getResult(), 'JML'); } else { $tgl_format = date('Y') . '-' . $bulan . '-' . '01'; $generateTgl = "SELECT TO_CHAR(LAST_DAY(to_date('" . $tgl_format . "','YYYY-MM-DD')) - level + 1,'DD') AS TGL FROM dual CONNECT BY LEVEL <= (trunc(LAST_DAY(to_date('" . $tgl_format . "','YYYY-MM-DD'))) - to_date('" . $tgl_format . "','YYYY-MM-DD') + 1)"; $data = $db->table('KPDL_MV_LOKASI_SUBJEK A') ->select("TO_CHAR(CREATION_DATE,'DD') as TGL, COUNT(1) JML") ->where("to_char(CREATION_DATE,'YYYY') = ", date('Y')) ->where("to_char(CREATION_DATE,'MM') = " . $bulan) ->groupBy("TO_CHAR(CREATION_DATE,'DD')"); if ($opsiWilZona == 'wilayah') { $data = $data->whereIn('ADM4_PCODE', $adm4_pcode); } if ($opsiWilZona == 'zona') { $data = $data->whereIn('ID_POLY_ZONA', $id_poly_zona); } if ($opsiWilZona == 'perekam') { $data = $data->whereIn('CREATED_BY', $nip_ar_perekam); } if ($opsiWilZona == 'pengampu') { $data = $data->whereIn('NIP_AR_PENGAMPU', $nip_ar_pengampu); } //pembatasan if (!in_array(session('tpkantor'), ['KPDJP', 'Kanwil', 'KPP'])) { return []; } if (session('kppadm') != '000') { $data->groupStart(); if (session('tpkantor') == 'Kanwil') { // kanwil $data->join('KPDL_ZP_NAS_DIFF B', 'ID_POLY_ZONA = B.OGC_FID'); $data->orGroupStart(); $data->where('B.KD_KANWIL', session('kwladm')); $data->groupEnd(); } if (session('tpkantor') == 'KPP') { //KPP $data->join('KPDL_ZP_NAS_DIFF B', 'ID_POLY_ZONA = B.OGC_FID'); $currentPegawai = currentPegawai(); if (in_array($currentPegawai->KD_JAB_STRUKTURAL, ['602'])) { //AR //zona $data->orGroupStart() ->where('B.KD_UNIT_OR', $currentPegawai->KD_UNIT_ORGANISASI) ->where('A.KPPADM_ZONA', session('kppadm')) ->where('A.NIP_AR_ZONA', session('nip')) ->groupEnd(); //perekam $data->orGroupStart() ->where('A.KODE_PEG_PEREKAM', session('kppadm') . '-' . $currentPegawai->KD_UNIT_ORGANISASI . '-' . session('nip')) //direkam saat di seksi aktif saat ini ->groupEnd(); //pengampu $data->orGroupStart() ->where('A.NIP_AR_PENGAMPU', session('nip')) ->where('A.KPPADM_PENGAMPU', session('kppadm')) ->groupEnd(); } else if (in_array($currentPegawai->KD_JAB_STRUKTURAL, ['401'])) { //kasi //zona $data->orGroupStart() ->where('B.KD_UNIT_OR', $currentPegawai->KD_UNIT_ORGANISASI) ->where('A.KPPADM_ZONA', session('kppadm')) ->groupEnd(); //perekam $data->orGroupStart() ->where('A.KODE_SEKSI_PEREKAM', session('kppadm') . '-' . $currentPegawai->KD_UNIT_ORGANISASI) ->groupEnd(); //pengampu // $data->join('PEGAWAI C', 'A.NIP_AR_PENGAMPU=C.NIP9', 'left'); $data->orGroupStart() ->where('C.KD_UNIT_ORGANISASI', $currentPegawai->KD_UNIT_ORGANISASI) ->where('C.KPPADM', session('kppadm')) ->where('A.KPPADM_PENGAMPU', session('kppadm')) ->groupEnd(); } else if (in_array($currentPegawai->KD_JAB_STRUKTURAL, ['304'])) { //Kepala Kantor //zona $data->orGroupStart() ->where('A.KPPADM_ZONA', session('kppadm')) ->groupEnd(); //perekam $data->orGroupStart() ->where('A.KPP_ADM_PEREKAM', session('kppadm') . '-' . $currentPegawai->KD_UNIT_ORGANISASI) ->groupEnd(); //pengampu $data->join('PEGAWAI C', 'A.NIP_AR_PENGAMPU=C.NIP9', 'left'); $data->orGroupStart() ->where('A.KPPADM_PENGAMPU', session('kppadm')) ->groupEnd(); } else { return []; } } $data->groupEnd(); } $data = $data->getCompiledSelect(); // print_r($data); // exit; $dataRet = $db->newQuery() ->select("A.TGL, B.JML") ->from("(" . $generateTgl . ") A") ->join("(" . $data . ") B", "A.TGL = B.TGL", 'left') ->orderBy("TGL"); return $KpdlLibrary->single_array($dataRet->get()->getResult(), 'JML'); } } protected function generateSeries($bulan) { $db = \Config\Database::connect(); $tgl_format = date('Y') . '-' . $bulan . '-' . '01'; $generateTgl = $db->query("SELECT TO_CHAR(LAST_DAY(to_date('" . $tgl_format . "','YYYY-MM-DD')) - level + 1,'DD') AS TGL FROM dual CONNECT BY LEVEL <= (trunc(LAST_DAY(to_date('" . $tgl_format . "','YYYY-MM-DD'))) - to_date('" . $tgl_format . "','YYYY-MM-DD') + 1) ORDER BY TGL"); $data = $generateTgl->getResult(); $data_arr = []; foreach ($data as $row) { array_push($data_arr, $row->TGL); } return $data_arr; } public function detail() { $dataRaw = $this->dataRaw('raw')->getResultArray(); $dataCount = $this->dataRaw('count')->getRow(); $ret = [ 'data' => $dataRaw, 'meta' => ['totalRowCount' => $dataCount->JML], ]; return $this->respond($ret, 200); } private function dataRaw($type) { $Ald = new AldLibrary; $username = session('nip'); $start = $this->request->getGet('start'); $size = $this->request->getGet('size'); $size = ($size > 101) ? 101 : $size; $request = json_decode(file_get_contents('php://input')); $selectedBulan = $Ald->decryptKpdl($request->selectedBulan ?? '', $username) ?? 'semua'; // 1 - 12 / semua $query = $request->query; //bulan (1-12) / tanggal (1-31) $opsiWilZona = $Ald->decryptMe($request->opsiWilZona ?? '', $username); $adm4_pcode = []; foreach ($request->adm4_pcode ?? [] as $key => $value) { $adm4_pcode[] = $Ald->decryptKpdl($value, $username); } $id_poly_zona = []; foreach ($request->id_poly_zona ?? [] as $key => $value) { $id_poly_zona[] = $Ald->decryptMe($value, $username); } $nip_ar_perekam = []; foreach ($request->nip_ar_perekam ?? [] as $key => $value) { $nip_ar_perekam[] = $Ald->decryptMe($value, $username); } $nip_ar_pengampu = []; foreach ($request->nip_ar_pengampu ?? [] as $key => $value) { $nip_ar_pengampu[] = $Ald->decryptMe($value, $username); } $globalFilter = $this->request->getGet('globalFilter'); //string $filters = json_decode($this->request->getGet('filters')); // [{"id":"MERK_USAHA","value":"toko"},{"id":"ALAMAT","value":"graha"}] $sorting = json_decode($this->request->getGet('sorting')); // [{"id":"ALAMAT","desc":false}] $db = \Config\Database::connect(); $data = $db->table('KPDL_MV_LOKASI_SUBJEK A'); $data->join('KPDL_REF_STATUS_SPT', 'ID_STATUS_SPT = STATUS_SPT_TAHUNAN_TERAKHIR', 'left'); $data->join('PEGAWAI C', 'NIP_AR_ZONA = C.NIP9', 'left'); $data->join('KPDL_MV_OBJEK_PERSUBJEK D', 'A.ID_KPDL_SUBJEK = D.ID_KPDL_SUBJEK', 'left'); $data->join('PEGAWAI E', 'NIP_AR_PENGAMPU = E.NIP9', 'left'); if ($opsiWilZona == 'wilayah') { $data->whereIn('ADM4_PCODE', $adm4_pcode); } if ($opsiWilZona == 'zona') { $data->whereIn('ID_POLY_ZONA', $id_poly_zona); } if (session('kppadm') != '000') { $data->groupStart(); if (session('tpkantor') == 'Kanwil') { // kanwil $data->join('KPDL_ZP_NAS_DIFF B', 'ID_POLY_ZONA = B.OGC_FID'); $data->orGroupStart(); $data->where('B.KD_KANWIL', session('kwladm')); $data->groupEnd(); } if (session('tpkantor') == 'KPP') { //KPP $data->join('KPDL_ZP_NAS_DIFF B', 'ID_POLY_ZONA = B.OGC_FID'); $currentPegawai = currentPegawai(); if (in_array($currentPegawai->KD_JAB_STRUKTURAL, ['602'])) { //AR //zona $data->orGroupStart() ->where('B.KD_UNIT_OR', $currentPegawai->KD_UNIT_ORGANISASI) ->where('A.KPPADM_ZONA', session('kppadm')) ->where('A.NIP_AR_ZONA', session('nip')) ->groupEnd(); //perekam $data->orGroupStart() ->where('A.KODE_PEG_PEREKAM', session('kppadm') . '-' . $currentPegawai->KD_UNIT_ORGANISASI . '-' . session('nip')) //direkam saat di seksi aktif saat ini ->groupEnd(); //pengampu $data->orGroupStart() ->where('A.NIP_AR_PENGAMPU', session('nip')) ->where('A.KPPADM_PENGAMPU', session('kppadm')) ->groupEnd(); } else if (in_array($currentPegawai->KD_JAB_STRUKTURAL, ['401'])) { //kasi //zona $data->orGroupStart() ->where('B.KD_UNIT_OR', $currentPegawai->KD_UNIT_ORGANISASI) ->where('A.KPPADM_ZONA', session('kppadm')) ->groupEnd(); //perekam $data->orGroupStart() ->where('A.KODE_SEKSI_PEREKAM', session('kppadm') . '-' . $currentPegawai->KD_UNIT_ORGANISASI) ->groupEnd(); //pengampu // $data->join('PEGAWAI C', 'A.NIP_AR_PENGAMPU=C.NIP9', 'left'); $data->orGroupStart() ->where('C.KD_UNIT_ORGANISASI', $currentPegawai->KD_UNIT_ORGANISASI) ->where('C.KPPADM', session('kppadm')) ->where('A.KPPADM_PENGAMPU', session('kppadm')) ->groupEnd(); } else if (in_array($currentPegawai->KD_JAB_STRUKTURAL, ['304'])) { //Kepala Kantor //zona $data->orGroupStart() ->where('A.KPPADM_ZONA', session('kppadm')) ->groupEnd(); //perekam $data->orGroupStart() ->where('A.KPP_ADM_PEREKAM', session('kppadm') . '-' . $currentPegawai->KD_UNIT_ORGANISASI) ->groupEnd(); //pengampu $data->join('PEGAWAI C', 'A.NIP_AR_PENGAMPU=C.NIP9', 'left'); $data->orGroupStart() ->where('A.KPPADM_PENGAMPU', session('kppadm')) ->groupEnd(); } else { return []; } } $data->groupEnd(); } if ($opsiWilZona == 'perekam') { $data->whereIn('CREATED_BY', $nip_ar_perekam); } if ($opsiWilZona == 'pengampu') { $data->whereIn('NIP_AR_PENGAMPU', $nip_ar_pengampu); } $data->where("TO_CHAR(CREATION_DATE,'YYYY')", date('Y')); if ($selectedBulan == 'semua') { $data->where("TO_CHAR(CREATION_DATE,'MM')", sprintf("%02d", $query)); } else { $data->where("TO_CHAR(CREATION_DATE,'DD')", sprintf("%02d", $query)); $data->where("TO_CHAR(CREATION_DATE,'MM')", sprintf("%02d", $selectedBulan)); } if ($globalFilter) { $columnFilter = ["NAMA", "ALAMAT", "MERK_USAHA"]; $data->GroupStart(); $data->orGroupStart(); foreach ($columnFilter as $key => $value) { $data->orLike("UPPER(" . $value . ")", strtoupper($globalFilter), 'both'); } $data->groupEnd(); $data->groupEnd(); } if (count($filters)) { $data->GroupStart(); foreach ($filters as $key => $value) { if ($value->id == 'NM_AR_ZONA') { $data->like("UPPER(C.NAMA)", strtoupper($value->value), 'both'); } else if ($value->id == 'NM_AR_PENGAMPU') { $data->like("UPPER(E.NAMA)", strtoupper($value->value), 'both'); } else if ($value->id == 'NAMA') { $data->like("UPPER(A.NAMA)", strtoupper($value->value), 'both'); } else { $data->like("UPPER(" . $value->id . ")", strtoupper($value->value), 'both'); } } $data->groupEnd(); } if (count($sorting)) { foreach ($sorting as $key => $value) { if ($value->id == 'NM_AR_ZONA') { $data->orderBy("C.NAMA", $value->desc ? 'desc' : 'asc'); } else if ($value->id == 'NAMA_AR_PENGAMPU') { $data->orderBy("E.NAMA", $value->desc ? 'desc' : 'asc'); } else if ($value->id == 'NAMA') { $data->orderBy("A.NAMA", $value->desc ? 'desc' : 'asc'); } else { $data->orderBy($value->id, $value->desc ? 'desc' : 'asc'); } } } if ($type == 'count') { $data->select('count(1) as JML'); return $data->get(); } if ($type == 'raw') { $data->select("UUID, A.NAMA,GEO_LOK_LAT, GEO_LOK_LING,ALAMAT, PROVINSI, KABUPATEN, KECAMATAN, KELURAHAN, RT, RW, A.NPWP, NO_IDENTITAS, MERK_USAHA, NM_KANTOR_PENGAMPU, JUMLAH_PEMBAYARAN_THN_TERAKHIR,STATUS_SPT_TAHUNAN_TERAKHIR, NM_KPP_ZONA ,NIP_AR_ZONA, NM_PEREKAM, KPP_ADM_PEREKAM, TO_CHAR(CREATION_DATE, 'YYYY-MM-DD HH24:II:SS')CREATION_DATE, KETERANGAN, C.NAMA NM_AR_ZONA, E.NAMA NM_AR_PENGAMPU, STATUS_WP_MFWP,JNS_WP_MFWP, COALESCE(D.SUM_NILAI,0) SUM_NILAI, FLAG_WPS_WPK "); // print_r($data->getCompiledSelect()); // exit; return $data->get($size - 1, $start); } } }