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.
399 lines
16 KiB
399 lines
16 KiB
<?php |
|
namespace App\Controllers\Kewilayahan\Sebaran; |
|
|
|
use App\Libraries\AldLibrary; |
|
use CodeIgniter\Database\RawSql; |
|
|
|
class Pembayaran extends \App\Controllers\Kewilayahan\Kytp |
|
{ |
|
protected function dataC($request, $tahun, $bulan) |
|
{ |
|
$Ald = new AldLibrary; |
|
$username = session('nip'); |
|
|
|
$opsiWilZona = $Ald->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(); |
|
//npwp |
|
$npwp = $db->table('KPDL_MV_LOKASI_SUBJEK A')->select('A.NPWP')->distinct()->where('A.NPWP IS NOT NULL')->where('EXTRACT (YEAR FROM A.creation_date)<=', $tahun); |
|
|
|
if ($opsiWilZona == 'wilayah') { |
|
$npwp->whereIn('ADM4_PCODE', $adm4_pcode); |
|
} |
|
|
|
if ($opsiWilZona == 'zona') { |
|
$npwp->whereIn('ID_POLY_ZONA', $id_poly_zona); |
|
} |
|
|
|
if ($opsiWilZona == 'perekam') { |
|
$npwp = $npwp->whereIn('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 []; |
|
} |
|
|
|
//opsiWilZona = '' (Default) |
|
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']) && substr($currentPegawai->NAMA_UNIT_ES4, 0, 16) == 'Seksi Pengawasan') { //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']) || $currentPegawai->NAMA_UNIT_ES4 == 'Seksi Penjaminan Kualitas Data') { //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(); |
|
} |
|
|
|
$dataSub = $db->newQuery() |
|
->select("'" . $tahun . '-' . $bulan . "' AS THN_BLN, NVL(WARNA_BYR, 'grey') WARNA_BYR, COUNT(1) AS Y") |
|
->fromSubquery($npwp, 'A') |
|
->join('KPDL_MV_PENERIMAAN_AGG B', new RawSql("A.NPWP=B.NPWP and B.THNBYR = '" . $tahun . "' and B.BULAN=" . $bulan), 'left') |
|
->groupBy("NVL(WARNA_BYR, 'grey')"); |
|
|
|
$data = $db->newQuery() |
|
->select("A.THN_BLN, A.WARNA_BYR, A.Y, B.ID_WARNA, B.RGB, B.NAMA_WARNA") |
|
->fromSubquery($dataSub, "A") |
|
->join('KPDL_REF_WARNA_PEMBAYARAN B', 'A.WARNA_BYR=B.WARNA', 'inner') |
|
->orderBy('B.ID_WARNA'); |
|
// print_r($data->getCompiledSelect()); |
|
// exit; |
|
$data = $data->get()->getResult(); |
|
|
|
$ret = []; |
|
|
|
foreach ($data as $b) { |
|
$name = ''; |
|
switch ($b->WARNA_BYR) { |
|
case 'black':$name = '<0'; |
|
break; |
|
case 'grey':$name = 'Rp0'; |
|
break; |
|
case 'red':$name = '< 5 jt'; |
|
break; |
|
case 'yellow':$name = '<48 jt'; |
|
break; |
|
case 'green':$name = '<100 jt'; |
|
break; |
|
case 'blue':$name = '> 100 jt'; |
|
break; |
|
} |
|
|
|
array_push($ret, ['name' => $b->NAMA_WARNA, |
|
'color' => $b->WARNA_BYR, |
|
'key' => $Ald->encryptMe($b->WARNA_BYR, $username), |
|
'y' => floatval($b->Y), |
|
'thn_bln' => $b->THN_BLN, |
|
] |
|
); |
|
} |
|
|
|
return $ret; |
|
} |
|
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) |
|
{ |
|
//pembatasan |
|
if (!in_array(session('tpkantor'), ['KPDJP', 'Kanwil', 'KPP'])) { |
|
return []; |
|
} |
|
|
|
$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')); |
|
|
|
$query = $Ald->decryptKpdl($request->query ?? '', $username) ?? ''; //Warna |
|
|
|
$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}] |
|
$tahun = 2024; |
|
$db = \Config\Database::connect(); |
|
$data = $db->table('KPDL_MV_LOKASI_SUBJEK A')->distinct() |
|
->select('A.NPWP, A.NAMA_WP, A.ALAMAT_MFWP, A.KELURAHAN_MFWP, A.KECAMATAN_MFWP, A.KOTA_MFWP, A.PROPINSI_MFWP, |
|
A.KPPADM_MFWP, A.NAMA_AR_MFWP, A.FLAG_WPS_WPK, A.STATUS_WP_MFWP, A.JNS_WP_MFWP, A.STATUS_SPT_TAHUNAN_TERAKHIR, |
|
A.TGL_DAFTAR, JUMLAH_PEMBAYARAN_THN_TERAKHIR')->where('A.NPWP IS NOT NULL')->where('EXTRACT (YEAR FROM A.creation_date)<=', $tahun); |
|
|
|
if ($opsiWilZona == 'wilayah') { |
|
$data->whereIn('ADM4_PCODE', $adm4_pcode); |
|
} |
|
|
|
if ($opsiWilZona == 'zona') { |
|
$data->whereIn('ID_POLY_ZONA', $id_poly_zona); |
|
} |
|
|
|
if ($opsiWilZona == 'perekam') { |
|
$data->whereIn('CREATED_BY', $nip_ar_perekam); |
|
} |
|
|
|
if ($opsiWilZona == 'pengampu') { |
|
$data->whereIn('NIP_AR_PENGAMPU', $nip_ar_pengampu); |
|
} |
|
|
|
//opsiWilZona = '' (Default) |
|
|
|
if (session('kppadm') != '000') { |
|
$data->groupStart(); |
|
$data->join('KPDL_ZP_NAS_DIFF B', 'ID_POLY_ZONA = B.OGC_FID'); |
|
if (session('tpkantor') == 'Kanwil') { // kanwil |
|
|
|
$data->orGroupStart(); |
|
$data->where('B.KD_KANWIL', session('kwladm')); |
|
$data->groupEnd(); |
|
} |
|
if (session('tpkantor') == 'KPP') { //KPP |
|
|
|
$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']) && substr($currentPegawai->NAMA_UNIT_ES4, 0, 16) == 'Seksi Pengawasan') { //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']) || $currentPegawai->NAMA_UNIT_ES4 == 'Seksi Penjaminan Kualitas Data') { //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(); |
|
} |
|
// print_r($data->getCompiledSelect()); |
|
// exit; |
|
$npwp = $data; |
|
|
|
$tahunBulan = $request->tahunBulan ?? "2024-09"; |
|
$tahunBulanArr = explode("-", $tahunBulan); |
|
$tahun = $tahunBulanArr[0]; |
|
$bulan = $tahunBulanArr[1]; |
|
$data = $db->newQuery()->fromSubquery($npwp, "A") |
|
// ->join('MFWP B', "A.NPWP = B.NPWP", "left") |
|
->join('KPDL_MV_PENERIMAAN_AGG C', "A.NPWP = C.NPWP AND C.THNBYR = '" . $tahun . "' and BULAN=" . $bulan, "left") |
|
->join('REF_KPP D', "A.KPPADM_MFWP = D.KD_KPP", "left") |
|
->join('KPDL_REF_STATUS_SPT E', "A.STATUS_SPT_TAHUNAN_TERAKHIR = E.ID_STATUS_SPT", "left"); |
|
if ($query == 'grey') { |
|
$data->Where("C.WARNA_BYR IS NULL"); |
|
} else { |
|
$data->where("C.WARNA_BYR", $query); |
|
} |
|
|
|
if ($globalFilter) { |
|
$columnFilter = ["NAMA_WP", "ALAMAT_MFWP"]; |
|
$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 == 'NPWP') { |
|
$data->like("A.NPWP", 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 == 'NPWP') { |
|
|
|
$data->orderBy("A.NPWP", $value->desc ? 'desc' : 'asc'); |
|
} else { |
|
|
|
$data->orderBy($value->id, $value->desc ? 'desc' : 'asc'); |
|
} |
|
} |
|
} |
|
|
|
if ($type == 'count') { |
|
$data = $data->select("count(1) as JML"); |
|
return $data->get(); |
|
} |
|
if ($type == 'raw') { |
|
$data = $data->select("A.NPWP, A.NAMA_WP, A.ALAMAT_MFWP, A.KELURAHAN_MFWP, A.KECAMATAN_MFWP, A.KOTA_MFWP, A.PROPINSI_MFWP, |
|
A.KPPADM_MFWP, A.NAMA_AR_MFWP, A.FLAG_WPS_WPK, A.STATUS_WP_MFWP, A.JNS_WP_MFWP, A.STATUS_SPT_TAHUNAN_TERAKHIR, |
|
A.TGL_DAFTAR,COALESCE(C.JML,0) JML,CASE WHEN C.WARNA_BYR IS NULL THEN 'grey' ELSE C.WARNA_BYR END WARNA_BYR, |
|
E.KETERANGAN, D.NM_KANTOR"); |
|
// print_r($data->getCompiledSelect()); |
|
// exit; |
|
return $data->get($size - 1, $start); |
|
} |
|
|
|
} |
|
}
|
|
|