|
|
|
<?php
|
|
|
|
namespace App\Controllers\Kewilayahan\Sebaran;
|
|
|
|
|
|
|
|
use App\Libraries\AldLibrary;
|
|
|
|
use CodeIgniter\Database\RawSql;
|
|
|
|
|
|
|
|
class Sof 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')->select('NPWP')->distinct()->where('NPWP IS NOT NULL');
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
$sqlBulanIni = $db->newQuery()
|
|
|
|
->select("'" . $tahun . '-' . $bulan . "' AS THN_BLN, B.LAPISAN, count(1) JML", false)
|
|
|
|
->fromSubquery($npwp, 'A')
|
|
|
|
->join("KPDL_MV_PENERIMAAN_AGG_SF B", new RawSql("A.NPWP=B.NPWP and B.THNBYR = '" . $tahun . "' and B.BULAN=" . $bulan), 'inner')
|
|
|
|
->groupBy("B.LAPISAN")->getCompiledSelect();
|
|
|
|
|
|
|
|
$sqlBulanLalu = $db->newQuery()
|
|
|
|
->select("'" . $tahun . '-' . $bulan - 1 . "' AS THN_BLN, B.LAPISAN, count(1) JML", false)
|
|
|
|
->fromSubquery($npwp, 'A')
|
|
|
|
->join("KPDL_MV_PENERIMAAN_AGG_SF B", new RawSql("A.NPWP=B.NPWP and B.THNBYR = '" . $tahun . "' and B.BULAN=" . $bulan - 1), 'inner')
|
|
|
|
->groupBy("B.LAPISAN")->getCompiledSelect();
|
|
|
|
|
|
|
|
$sql2BulanLalu = $db->newQuery()
|
|
|
|
->select("'" . $tahun . '-' . $bulan - 2 . "' AS THN_BLN, B.LAPISAN, count(1) JML", false)
|
|
|
|
->fromSubquery($npwp, 'A')
|
|
|
|
->join("KPDL_MV_PENERIMAAN_AGG_SF B", new RawSql("A.NPWP=B.NPWP and B.THNBYR = '" . $tahun . "' and B.BULAN=" . $bulan - 2), 'inner')
|
|
|
|
->groupBy("B.LAPISAN")->getCompiledSelect();
|
|
|
|
|
|
|
|
$sqlSemua = $db->newQuery()
|
|
|
|
->select("L.LAPISAN , NVL(A.JML, 0) AS JML_C, NVL(B.JML,0) JML_P1, NVL(C.JML,0) JML_P2")
|
|
|
|
->from('KPDL_REF_LAPISAN L')
|
|
|
|
->join("(" . $sqlBulanIni . ") A", "L.LAPISAN = A.LAPISAN", "left", false)
|
|
|
|
->join("(" . $sqlBulanLalu . ") B", "L.LAPISAN = B.LAPISAN", "left", false)
|
|
|
|
->join("(" . $sql2BulanLalu . ") C", "L.LAPISAN = C.LAPISAN", "left", false)
|
|
|
|
->orderBy("L.LAPISAN");
|
|
|
|
|
|
|
|
$data = $sqlSemua->get()->getResult();
|
|
|
|
foreach ($data as $key => $value) {
|
|
|
|
$value->key = $Ald->encryptKpdl($value->LAPISAN, $username);
|
|
|
|
$value->JML_C = floatval($value->JML_C);
|
|
|
|
$value->THNBLN_C = $Ald->encryptMe($tahun . '-' . $bulan, $username);
|
|
|
|
$value->JML_P1 = floatval($value->JML_P1);
|
|
|
|
$value->THNBLN_P1 = $Ald->encryptMe($tahun . '-' . ($bulan - 1), $username);
|
|
|
|
$value->JML_P2 = floatval($value->JML_P2);
|
|
|
|
$value->THNBLN_P2 = $Ald->encryptMe($tahun . '-' . ($bulan - 2), $username);
|
|
|
|
}
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
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');
|
|
|
|
// $start = ($start > 100) ? 100 : $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) ?? ''; // lapisan 1-5000 / lapisan 10000-200000 / etc
|
|
|
|
|
|
|
|
$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')->distinct()->select('A.NPWP, A.STATUS_SPT_TAHUNAN_TERAKHIR, JNS_WP_MFWP, STATUS_WP_MFWP, JUMLAH_PEMBAYARAN_THN_TERAKHIR')->where('A.NPWP IS NOT NULL');
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
$npwp = $data;
|
|
|
|
|
|
|
|
$tahunBulan = $Ald->decryptMe($request->tahunBulan ?? '', $username) ?? "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_SF C', "A.NPWP = C.NPWP AND C.THNBYR = '" . $tahun . "' and BULAN=" . $bulan, "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");
|
|
|
|
|
|
|
|
$data->where("C.LAPISAN", $query);
|
|
|
|
|
|
|
|
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, 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, A.STATUS_SPT_TAHUNAN_TERAKHIR,
|
|
|
|
B.TANGGAL_DAFTAR,C.LAPISAN,JUMLAH_PEMBAYARAN_THN_TERAKHIR,
|
|
|
|
E.KETERANGAN");
|
|
|
|
// print_r($data->getCompiledSelect());
|
|
|
|
// exit;
|
|
|
|
return $data->get($size - 1, $start);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|