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.
 
 
 
 
 
 

234 lines
8.4 KiB

<?php
namespace App\Controllers\Kewilayahan\Sebaran;
use App\Libraries\AldLibrary;
class KLU extends \App\Controllers\Kewilayahan\Kytp
{
protected function data($request, $jenischart)
{
$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 = $db->table('KPDL_MV_LOKASI_SUBJEK A')->select("NPWP, NVL(KD_GOLPOK,'ZZ') KD_GOLPOK, NVL(NM_GOLPOK,'TIDAK DIKETAHUI') NM_GOLPOK, NVL(JUMLAH_PEMBAYARAN_THN_TERAKHIR,0) JUMLAH_PEMBAYARAN_THN_TERAKHIR")->distinct()
->where('NPWP IS NOT NULL'); //default jenis chart = kluterdaftar
if ($jenischart == 'dataKluYgBayar') {
$npwp = $npwp->where("JUMLAH_PEMBAYARAN_THN_TERAKHIR >", 0);
}
if ($jenischart == 'dataKluYgTidakBayar') {
$npwp = $npwp->where("JUMLAH_PEMBAYARAN_THN_TERAKHIR <=", 0);
}
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('CREATED_BY', $nip_ar_perekam);
}
if ($opsiWilZona == 'pengampu') {
$npwp = $npwp->whereIn('NIP_AR_PENGAMPU', $nip_ar_pengampu);
}
$agg = "count(DISTINCT NPWP) as JML";
if ($jenischart == 'dataRupiahBayar') {
$agg = "SUM(JUMLAH_PEMBAYARAN_THN_TERAKHIR) as JML";
}
$data = $db->newQuery()
->fromSubquery($npwp, "A")
->select("KD_GOLPOK, NM_GOLPOK," . $agg)
->groupBy("KD_GOLPOK, NM_GOLPOK")->orderBy("JML", "desc");
$data = $data->get()->getResult();
$ret = [];
foreach ($data as $b) {
array_push($ret,
[
'name' => $b->NM_GOLPOK,
'key' => $Ald->encryptMe($b->KD_GOLPOK, $username),
'y' => floatval($b->JML),
]
);
}
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)
{
$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->decryptMe($request->query ?? '', $username) ?? ''; //KD Golongan Pokok
$jenischart = $request->jenisChart ?? ''; //Jenis Chart
$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();
$npwp = $db->table('KPDL_MV_LOKASI_SUBJEK A')->select("A.NPWP, A.STATUS_WP_MFWP, A.JNS_WP_MFWP,A.STATUS_SPT_TAHUNAN_TERAKHIR,
NVL(KD_GOLPOK,'ZZ') KD_GOLPOK,
NVL(NM_GOLPOK,'TIDAK DIKETAHUI') NM_GOLPOK,
NVL(JUMLAH_PEMBAYARAN_THN_TERAKHIR,0) JUMLAH_PEMBAYARAN_THN_TERAKHIR")
->distinct()
->where('NPWP IS NOT NULL'); //default jenis chart = kluterdaftar
if ($jenischart == 'dataKluYgBayar') {
$npwp = $npwp->where("JUMLAH_PEMBAYARAN_THN_TERAKHIR >", 0);
}
if ($jenischart == 'dataKluYgTidakBayar') {
$npwp = $npwp->where("JUMLAH_PEMBAYARAN_THN_TERAKHIR <=", 0);
}
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('CREATED_BY', $nip_ar_perekam);
}
if ($opsiWilZona == 'pengampu') {
$npwp = $npwp->whereIn('NIP_AR_PENGAMPU', $nip_ar_pengampu);
}
$data = $db->newQuery()->fromSubquery($npwp, "A")
->join('MFWP B', "A.NPWP = B.NPWP", "left")
->join('REF_KPP D', "B.KPPADM = D.KD_KPP", "left")
->join('KPDL_REF_STATUS_SPT E', "A.STATUS_SPT_TAHUNAN_TERAKHIR = E.ID_STATUS_SPT", "left");
if ($query != 'lainnya') {
$data->where("NVL(KD_GOLPOK,'ZZ')", $query);
} else {
$limaBesar = []; //Lima Besar
foreach ($request->limaBesar ?? [] as $key => $value) {
$limaBesar[] = $Ald->decryptMe($value, $username);
}
$data->whereNotIn("NVL(KD_GOLPOK,'ZZ')", $limaBesar);
}
if ($globalFilter) {
$columnFilter = ["NAMA_WP", "ALAMAT"];
$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.KD_GOLPOK,A.NM_GOLPOK, B.NAMA_WP, B.ALAMAT, B.KELURAHAN, B.KECAMATAN, B.KOTA, B.PROPINSI,
B.KPPADM, B.NAMA_AR, B.FLAG_WPS_WPK, D.NM_KANTOR, A.STATUS_WP_MFWP, A.JNS_WP_MFWP,
B.TANGGAL_DAFTAR, A.JUMLAH_PEMBAYARAN_THN_TERAKHIR,E.KETERANGAN");
// print_r($data->getCompiledSelect());
// exit;
return $data->get($size - 1, $start);
}
}
}