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.
162 lines
5.4 KiB
162 lines
5.4 KiB
<?php |
|
namespace App\Controllers\Kewilayahan; |
|
|
|
use App\Controllers\Kewilayahan\Sebaran\Identifikasi; |
|
use App\Controllers\Kewilayahan\Sebaran\PayComp; |
|
use App\Controllers\Kewilayahan\Sebaran\Pembayaran; |
|
use App\Controllers\Kewilayahan\Sebaran\Sof; |
|
use CodeIgniter\API\ResponseTrait; |
|
use CodeIgniter\Controller; |
|
|
|
class Kytp extends Controller |
|
{ |
|
use ResponseTrait; |
|
public function index() |
|
{ |
|
$db = \Config\Database::connect(); |
|
// $data['all_propinsi'] = $db->table('KPDL_V_BATAS_DESA')->select('ADM1_PCODE, ADM1_EN')->distinct()->get()->getResult() ; |
|
// dd($data['all_propinsi']); |
|
$data = []; |
|
if (session('isLogin')) { |
|
echo view('inc/head'); |
|
echo view('inc/navbar'); |
|
echo view('inc/sidebar'); |
|
echo view('kewilayahan/kytp/kpdl', $data); |
|
echo view('inc/footer'); |
|
} else { |
|
return redirect()->to('auth'); |
|
} |
|
} |
|
|
|
public function graph_matoa() |
|
{ |
|
|
|
$dataReturn['poi_agg'] = $this->get_poi_agg(); |
|
$dataReturn['kpdl_agg'] = $this->get_kpdl_agg(); |
|
return json_encode($dataReturn); |
|
} |
|
|
|
public function sebaranPembayaran() |
|
{ |
|
$ret = []; |
|
$tahun = $this->request->getPost('tahun') ?? date('Y'); |
|
$bulan = $this->request->getPost('bulan') ?? date('m'); |
|
|
|
$sebaranPembayaran = new Pembayaran; |
|
|
|
$dataReturn['dataC'] = $sebaranPembayaran->dataC($this->request, $tahun, $bulan); |
|
$dataReturn['dataMin1'] = $sebaranPembayaran->dataC($this->request, $tahun, $bulan - 1); |
|
$dataReturn['dataMin2'] = $sebaranPembayaran->dataC($this->request, $tahun, $bulan - 2); |
|
return $this->respond($dataReturn, 200); |
|
// return json_encode($dataReturn); |
|
} |
|
|
|
public function sebaranIdentifikasi() |
|
{ |
|
$ret = []; |
|
|
|
$sebaran = new Identifikasi; |
|
|
|
$dataReturn['data'] = $sebaran->data($this->request); |
|
return $this->respond($dataReturn, 200); |
|
// return json_encode($dataReturn); |
|
} |
|
public function sebaranPayComp() |
|
{ |
|
$tahun = $this->request->getPost('tahun') ?? date('Y'); |
|
$bulan = $this->request->getPost('bulan') ?? date('m'); |
|
|
|
$sebaran = new PayComp; |
|
|
|
$dataReturn['dataC'] = $sebaran->dataC($this->request, $tahun, $bulan); |
|
$dataReturn['dataMin1'] = $sebaran->dataC($this->request, $tahun, $bulan - 1); |
|
$dataReturn['dataMin2'] = $sebaran->dataC($this->request, $tahun, $bulan - 2); |
|
|
|
return $this->respond($dataReturn, 200); |
|
} |
|
|
|
public function sebaranSof() |
|
{ |
|
$tahun = $this->request->getPost('tahun') ?? date('Y'); |
|
$bulan = $this->request->getPost('bulan') ?? date('m'); |
|
|
|
$sebaran = new Sof; |
|
$dataReturn['data'] = $sebaran->dataC($this->request, $tahun, $bulan); |
|
|
|
return $this->respond($dataReturn, 200); |
|
} |
|
|
|
private function get_poi_agg() |
|
{ |
|
|
|
$opsiWilZona = $this->request->getPost('opsiWilZona') ?? null; |
|
$adm4_pcode = $this->request->getPost('adm4_pcode') ?? []; |
|
$id_poly_zona = $this->request->getPost('id_poly_zona') ?? []; |
|
|
|
$db = \Config\Database::connect(); |
|
$sqlGenerate = $db->table("KPDL_MV_JML_POI_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); |
|
} |
|
|
|
$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 = $this->single_array($data, 'JML'); |
|
return $dataPoiAgg; |
|
} |
|
|
|
private function get_kpdl_agg() |
|
{ |
|
$opsiWilZona = $this->request->getPost('opsiWilZona'); |
|
$adm4_pcode = $this->request->getPost('adm4_pcode') ?? []; |
|
$id_poly_zona = $this->request->getPost('id_poly_zona') ?? []; |
|
|
|
$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); |
|
} |
|
|
|
$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 = $this->single_array($data, 'JML'); |
|
return $dataPoiAgg; |
|
} |
|
private function single_array($a, $key) |
|
{ |
|
$ret = []; |
|
foreach ($a as $b) { |
|
array_push($ret, floatval($b->$key)); |
|
} |
|
for ($i = 0; $i < 12; $i++) { |
|
if (!isset($ret[$i])) { |
|
array_push($ret, 0); |
|
} |
|
} |
|
return $ret; |
|
} |
|
}
|
|
|