Advertisement
jamboljack

API RTLH

Dec 1st, 2017
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 42.90 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. require APPPATH . '/libraries/REST_Controller.php';
  4.  
  5. class Dataapi extends REST_Controller {
  6.     function __construct($config = 'rest') {
  7.         parent::__construct($config);
  8.     }
  9.  
  10.     // Data Login
  11.     function login_post() {
  12.         $username = trim($this->post('username'));
  13.         $password = trim($this->post('password'));
  14.  
  15.         $this->db->select('*');
  16.         $this->db->from('rtlh_users');
  17.         $this->db->where('user_username', $username);
  18.         $hasiluser = $this->db->get()->row(); // Hasil Cek Username
  19.  
  20.         if (count($hasiluser) == 0) {
  21.             $response = [  
  22.                     'resp_error' => true,
  23.                     'resp_msg'   => 'Username Tidak Terdaftar'
  24.                 ];
  25.         } else {
  26.             $this->db->select('u.*, p.penduduk_nama');
  27.             $this->db->from('rtlh_users u');
  28.             $this->db->join('rtlh_penduduk_dukcapil p', 'u.user_username = p.penduduk_nik');
  29.             $this->db->where('u.user_username', $username);
  30.             $this->db->where('u.user_password', sha1($password));
  31.             $this->db->where('u.user_status', 'Aktif');
  32.             $hasilakun = $this->db->get()->row(); // Hasil Cek Username dan Password
  33.  
  34.             if (count($hasilakun) == 0) {
  35.                 $response = [  
  36.                     'resp_error' => true,
  37.                     'resp_msg'   => 'Username atau Password Salah.'
  38.                 ];
  39.             } else {
  40.                 $response[] = array(
  41.                                     'resp_error' => false,
  42.                                     'resp_msg'   => 'Success',
  43.                                     'username'   => trim($hasilakun->user_username),
  44.                                     'nama'       => trim($hasilakun->penduduk_nama),
  45.                                     'avatar'     => base_url('img/icon/'.$hasilakun->user_image),
  46.                                     'level'      => $hasilakun->user_level
  47.                                 );
  48.             }
  49.         }
  50.  
  51.         $this->response($response, 200);
  52.     }
  53.  
  54.     // Data RTLH per Fasilitator
  55.     function listbyfasilitator_get() {
  56.         $username   = trim($this->get('username'));
  57.  
  58.         if ($username == '') { // Jika Username Kosong
  59.             $response = [  
  60.                     'resp_error'    => true,
  61.                     'resp_msg'      => 'ID Fasilitator Masih Kosong.'
  62.             ];
  63.  
  64.             $this->response($response, 200);
  65.         } else {
  66.             $this->db->select('r.*, p.penduduk_no_kk, p.penduduk_nama, p.penduduk_jk, p.penduduk_alamat,
  67.                p.penduduk_rt, p.penduduk_rw, c.nama_kec, k.nama_kel, p.penduduk_tmpt_lhr, p.penduduk_tgl_lahir');
  68.             $this->db->from('rtlh_rtlh r');
  69.             $this->db->join('rtlh_penduduk_dukcapil p', 'r.penduduk_nik = p.penduduk_nik');
  70.             $this->db->join('rtlh_kec c', 'p.no_kec = c.no_kec');
  71.             $this->db->join('rtlh_kel k', 'p.no_kel = k.no_kel');
  72.             $this->db->where('k.no_kec = c.no_kec');
  73.             $this->db->where('r.rtlh_aktif', 1); // Aktif
  74.             $this->db->where('r.rtlh_step >=', 3); // Verifikasi ke Atas
  75.             $this->db->where('r.user_pengampu', $username);
  76.  
  77.             $listRTLH = $this->db->get()->result();
  78.  
  79.             if (count($listRTLH) > 0) {
  80.                 $response  = [
  81.                     'resp_error'    => false,
  82.                     'resp_msg'      => "Success",
  83.                     'items'         => []
  84.                 ];
  85.  
  86.                 foreach ($listRTLH as $r) {
  87.                     $rtlh_id = $r->rtlh_id;
  88.                     // 0 Persen
  89.                     $this->db->select('*');
  90.                     $this->db->from('rtlh_foto_rumah');
  91.                     $this->db->where('rtlh_id', $rtlh_id);
  92.                     $this->db->where('foto_tipe', '0');
  93.                     $this->db->order_by('foto_id', 'asc');
  94.                     $listFoto = $this->db->get()->result();
  95.                     if (count($listFoto) == 0) {
  96.                         $foto_rmh_0     = '';
  97.                         $foto_atap_0    = '';
  98.                         $foto_dinding_0 = '';
  99.                         $foto_lantai_0  = '';
  100.                         $is_valid_0     = false;
  101.                     } else {
  102.                         foreach($listFoto as $f) {
  103.                             $foto_nama = trim($f->foto_nama);
  104.                             switch ($foto_nama) {
  105.                                 case 'Rumah': // Rumah
  106.                                     $foto_1         = $f->foto_file;
  107.                                     $foto_rmh_0     = base_url('img/foto_rumah/'.$f->foto_file);
  108.                                     break;
  109.                                 case 'Atap': // Atap
  110.                                     $foto_2         = $f->foto_file;
  111.                                     $foto_atap_0    = base_url('img/foto_rumah/'.$f->foto_file);
  112.                                     break;
  113.                                 case 'Dinding': // Dinding
  114.                                     $foto_3         = $f->foto_file;
  115.                                     $foto_dinding_0 = base_url('img/foto_rumah/'.$f->foto_file);
  116.                                     break;
  117.                                 case 'Lantai': // Lantai
  118.                                     $foto_4         = $f->foto_file;
  119.                                     $foto_lantai_0 = base_url('img/foto_rumah/'.$f->foto_file);
  120.                                     break;
  121.                             }
  122.                         }
  123.                         // Kondisi Form Valid/Tidak
  124.                         if (!empty($foto_1) && !empty($foto_2) && !empty($foto_3) && !empty($foto_4)) {
  125.                             $is_valid_0     = true;
  126.                         } else {
  127.                             $is_valid_0     = false;
  128.                         }
  129.                     }
  130.  
  131.                     // 50 Persen
  132.                     $this->db->select('*');
  133.                     $this->db->from('rtlh_foto_rumah');
  134.                     $this->db->where('rtlh_id', $rtlh_id);
  135.                     $this->db->where('foto_tipe', '50');
  136.                     $this->db->order_by('foto_id', 'asc');
  137.                     $listFoto1 = $this->db->get()->result();
  138.                     if (count($listFoto1) == 0) {
  139.                         $foto_rmh_50     = '';
  140.                         $foto_atap_50    = '';
  141.                         $foto_dinding_50 = '';
  142.                         $foto_lantai_50  = '';
  143.                         $is_valid_50    = false;
  144.                     } else {
  145.                         foreach($listFoto1 as $f) {
  146.                             $foto_nama = trim($f->foto_nama);
  147.                             switch ($foto_nama) {
  148.                                 case 'Rumah': // Rumah
  149.                                     $foto_5         = $f->foto_file;
  150.                                     $foto_rmh_50    = base_url('img/foto_rumah/'.$f->foto_file);
  151.                                     break;
  152.                                 case 'Atap': // Atap
  153.                                     $foto_6         = $f->foto_file;
  154.                                     $foto_atap_50   = base_url('img/foto_rumah/'.$f->foto_file);
  155.                                     break;
  156.                                 case 'Dinding': // Dinding
  157.                                     $foto_7         = $f->foto_file;
  158.                                     $foto_dinding_50= base_url('img/foto_rumah/'.$f->foto_file);
  159.                                     break;
  160.                                 case 'Lantai': // Lantai
  161.                                     $foto_8         = $f->foto_file;
  162.                                     $foto_lantai_50 = base_url('img/foto_rumah/'.$f->foto_file);
  163.                                     break;
  164.                             }
  165.                         }
  166.                         // Kondisi Form Valid/Tidak
  167.                         if (!empty($foto_5) && !empty($foto_6) && !empty($foto_7) && !empty($foto_8)) {
  168.                             $is_valid_50     = true;
  169.                         } else {
  170.                             $is_valid_50     = false;
  171.                         }
  172.                     }
  173.  
  174.                      // 100 Persen
  175.                     $this->db->select('*');
  176.                     $this->db->from('rtlh_foto_rumah');
  177.                     $this->db->where('rtlh_id', $rtlh_id);
  178.                     $this->db->where('foto_tipe', '100');
  179.                     $this->db->order_by('foto_id', 'asc');
  180.                     $listFoto2 = $this->db->get()->result();
  181.                     if (count($listFoto2) == 0) {
  182.                         $foto_rmh_100     = '';
  183.                         $foto_atap_100    = '';
  184.                         $foto_dinding_100 = '';
  185.                         $foto_lantai_100  = '';
  186.                         $is_valid_100     = false;
  187.                     } else {
  188.                         foreach($listFoto2 as $f) {
  189.                             $foto_nama = trim($f->foto_nama);
  190.                             switch ($foto_nama) {
  191.                                 case 'Rumah': // Rumah
  192.                                     $foto_9           = $f->foto_file;
  193.                                     $foto_rmh_100     = base_url('img/foto_rumah/'.$f->foto_file);
  194.                                     break;
  195.                                 case 'Atap': // Atap
  196.                                     $foto_10          = $f->foto_file;
  197.                                     $foto_atap_100    = base_url('img/foto_rumah/'.$f->foto_file);
  198.                                     break;
  199.                                 case 'Dinding': // Dinding
  200.                                     $foto_11          = $f->foto_file;
  201.                                     $foto_dinding_100 = base_url('img/foto_rumah/'.$f->foto_file);
  202.                                     break;
  203.                                 case 'Lantai': // Lantai
  204.                                     $foto_12          = $f->foto_file;
  205.                                     $foto_lantai_100  = base_url('img/foto_rumah/'.$f->foto_file);
  206.                                     break;
  207.                             }
  208.                         }
  209.                         // Kondisi Form Valid/Tidak
  210.                         if (!empty($foto_9) && !empty($foto_10) && !empty($foto_11) && !empty($foto_12)) {
  211.                             $is_valid_100     = true;
  212.                         } else {
  213.                             $is_valid_100     = false;
  214.                         }
  215.                     }
  216.  
  217.                     // Cek Foto Profil
  218.                     if (empty($r->rtlh_foto)) {
  219.                         $is_valid_foto = false;
  220.                     } else {
  221.                         $is_valid_foto = true;
  222.                     }
  223.  
  224.                     // Cek Scan KTP
  225.                     if (empty($r->rtlh_foto_ktp) && empty($r->rtlh_foto_kk)) {
  226.                         $is_valid_ktp_kk = false;
  227.                     } else {
  228.                         $is_valid_ktp_kk = true;
  229.                     }
  230.  
  231.                     $response['items'][] = [
  232.                             'tanggal'   => tgl_indo($r->rtlh_post),
  233.                             'rtlh_id'   => $r->rtlh_id,
  234.                             'kd_wilayah'=> trim($r->rtlh_kode_wilayah),
  235.                             'nik'       => trim($r->penduduk_nik),
  236.                             'no_rtlh'   => trim($r->rtlh_no_urut),
  237.                             'alias'      => trim($r->penduduk_nama),
  238.                             'alamat'    => $r->penduduk_alamat.' RT. '.$r->penduduk_rt.' RW. '.$r->penduduk_rw.' DESA '.$r->nama_kel.' KEC. '.$r->nama_kec,
  239.                             'jk'        => trim($r->penduduk_jk),
  240.                             'tmpt_lahir'=> trim($r->penduduk_tmpt_lhr),
  241.                             'tgl_lahir' => $r->penduduk_tgl_lahir,
  242.                             'pbdt'      => trim($r->rtlh_pbdt),
  243.                             'status'    => trim($r->rtlh_prioritas),
  244.                             'data'      => [
  245.                                     'data_pendukung' => [
  246.                                         'is_form_valid'             => true,
  247.                                         'penghasilan_perbulan'      => $r->penghasilan_id,
  248.                                         'pengeluaran_perbulan'      => $r->pengeluaran_id,
  249.                                         'status_kepemilikan_tanah'  => $r->status_tanah_id,
  250.                                         'bukti_kepemilikan_tanah'   => $r->bukti_tanah_id,
  251.                                         'status_kepemilikan_rumah'  => $r->pemilik_rumah_id,
  252.                                         'aset_rumah_lain'           => $r->rtlh_rumah_lain,
  253.                                         'aset_tanah_lain'           => $r->rtlh_tanah_lain,
  254.                                         'imb'                       => $r->rtlh_imb,
  255.                                         'bantuan_perumahan'         => $r->bantuan_id
  256.                                     ],
  257.                                     'data_kondisi_fisik_rumah' => [
  258.                                         'is_form_valid'             => true,
  259.                                         'pondasi_bangunan'          => $r->bantuan_id,
  260.                                         'kondisi_balok_kolom'       => $r->rtlh_kondisi_balok,
  261.                                         'kondisi_konstruksi_atap'   => $r->rtlh_kondisi_atap,
  262.                                         'jendela_lubang_cahaya'     => $r->rtlh_jendela,
  263.                                         'ventilasi'                 => $r->ventilasi_id,
  264.                                         'sanitasi'                  => $r->rtlh_sanitasi,
  265.                                         'kondisi_sanitasi'          => $r->rtlh_kondisi_sanitasi,
  266.                                         'jenis_sanitasi'            => $r->sanitasi_id,
  267.                                         'septitank'                 => $r->rtlh_septitank,
  268.                                         'kondisi_septitank'         => $r->rtlh_kondisi_septitank,
  269.                                         'sumber_air_minum'          => $r->air_minum_id,
  270.                                         'sumber_listrik'            => $r->listrik_id
  271.                                     ],
  272.                                     'aspek_persyaratan' => [
  273.                                         'is_form_valid'             => true,
  274.                                         'luas_rumah'                => $r->rtlh_luas,
  275.                                         'jumlah_penghuni'           => $r->rtlh_jml_orang,
  276.                                         'no_kk_lain'                => $r->rtlh_no_kk_lain,
  277.                                         'jml_kk'                    => $r->rtlh_jml_kk,
  278.                                         'tinggi_bangunan'           => $r->tinggi_id,
  279.                                         'rg_keluarga'               => $r->rtlh_ruang_keluarga
  280.                                     ],
  281.                                     'aspek_komponen' => [
  282.                                         'is_form_valid'             => true,
  283.                                         'material_atap'             => $r->material_atap_id,
  284.                                         'kondisi_atap'              => $r->kondisi_atap_id,
  285.                                         'material_dinding_terluas'  => $r->material_dinding_id,
  286.                                         'kondisi_dinding'           => $r->kondisi_dinding_id,
  287.                                         'material_lantai'           => $r->material_lantai_id,
  288.                                         'luas_lantai'               => $r->luas_lantai_id
  289.                                     ],
  290.                                     'foto_pemilik' => [
  291.                                         "foto_pemilik" => [
  292.                                             'type'                  => 'online',
  293.                                             'source'                => base_url('img/foto/'.$r->rtlh_foto),
  294.                                             'latitude'              => '',
  295.                                             'longitude'             => '',
  296.                                             'height'                => 800,
  297.                                             'width'                 => 600
  298.                                         ],
  299.                                         'is_form_valid'             => $is_valid_foto
  300.                                     ],
  301.                                     "foto_ktp_kk" => [
  302.                                         "ktp"       => [
  303.                                             'type'                  => 'online',
  304.                                             'source'                => base_url('img/foto_ktp_kk/'.$r->rtlh_foto_ktp),
  305.                                             'latitude'              => '',
  306.                                             'longitude'             => '',
  307.                                             'height'                => 0,
  308.                                             'width'                 => 300
  309.                                         ],
  310.                                         "kk"       => [
  311.                                             'type'                  => 'online',
  312.                                             'source'                => base_url('img/foto_ktp_kk/'.$r->rtlh_foto_kk),
  313.                                             'latitude'              => '',
  314.                                             'longitude'             => '',
  315.                                             'height'                => 0,
  316.                                             'width'                 => 300
  317.                                         ],
  318.                                         'is_form_valid'             => $is_valid_ktp_kk
  319.                                     ],
  320.                                     "lokasi_rumah" => [
  321.                                         'is_form_valid'             => true,
  322.                                         'latitude'                  => $r->rtlh_lat,
  323.                                         'longitude'                 => $r->rtlh_long,
  324.                                         'batas_utara'               => $r->rtlh_bts_utara,
  325.                                         'batas_timur'               => $r->rtlh_bts_timur,
  326.                                         'batas_selatan'             => $r->rtlh_bts_selatan,
  327.                                         'batas_barat'               => $r->rtlh_bts_barat
  328.                                     ],
  329.                                     "foto_bangunan_0" => [
  330.                                         "bangunan"  => [
  331.                                             'type'                  => 'online',
  332.                                             'source'                => $foto_rmh_0,
  333.                                             'latitude'              => '',
  334.                                             'longitude'             => '',
  335.                                             'height'                => 600,
  336.                                             'width'                 => 800
  337.                                         ],
  338.                                         "atap"  => [
  339.                                             'type'                  => 'online',
  340.                                             'source'                => $foto_atap_0,
  341.                                             'latitude'              => '',
  342.                                             'longitude'             => '',
  343.                                             'height'                => 600,
  344.                                             'width'                 => 800
  345.                                         ],
  346.                                         "dinding"  => [
  347.                                             'type'                  => 'online',
  348.                                             'source'                => $foto_dinding_0,
  349.                                             'latitude'              => '',
  350.                                             'longitude'             => '',
  351.                                             'height'                => 600,
  352.                                             'width'                 => 800
  353.                                         ],
  354.                                         "lantai"  => [
  355.                                             'type'                  => 'online',
  356.                                             'source'                => $foto_lantai_0,
  357.                                             'latitude'              => '',
  358.                                             'longitude'             => '',
  359.                                             'height'                => 600,
  360.                                             'width'                 => 800
  361.                                         ],
  362.                                         'is_form_valid'             => $is_valid_0
  363.                                     ],
  364.                                     "foto_bangunan_50" => [
  365.                                         "bangunan"  => [
  366.                                             'type'                  => 'online',
  367.                                             'source'                => $foto_rmh_50,
  368.                                             'latitude'              => '',
  369.                                             'longitude'             => '',
  370.                                             'height'                => 600,
  371.                                             'width'                 => 800
  372.                                         ],
  373.                                         "atap"  => [
  374.                                             'type'                  => 'online',
  375.                                             'source'                => $foto_atap_50,
  376.                                             'latitude'              => '',
  377.                                             'longitude'             => '',
  378.                                             'height'                => 600,
  379.                                             'width'                 => 800
  380.                                         ],
  381.                                         "dinding"  => [
  382.                                             'type'                  => 'online',
  383.                                             'source'                => $foto_dinding_50,
  384.                                             'latitude'              => '',
  385.                                             'longitude'             => '',
  386.                                             'height'                => 600,
  387.                                             'width'                 => 800
  388.                                         ],
  389.                                         "lantai"  => [
  390.                                             'type'                  => 'online',
  391.                                             'source'                => $foto_lantai_50,
  392.                                             'latitude'              => '',
  393.                                             'longitude'             => '',
  394.                                             'height'                => 600,
  395.                                             'width'                 => 800
  396.                                         ],
  397.                                         'is_form_valid'             => $is_valid_50
  398.                                     ],
  399.                                     "foto_bangunan_100" => [
  400.                                         "bangunan"  => [
  401.                                             'type'                  => 'online',
  402.                                             'source'                => $foto_rmh_100,
  403.                                             'latitude'              => '',
  404.                                             'longitude'             => '',
  405.                                             'height'                => 600,
  406.                                             'width'                 => 800
  407.                                         ],
  408.                                         "atap"  => [
  409.                                             'type'                  => 'online',
  410.                                             'source'                => $foto_atap_100,
  411.                                             'latitude'              => '',
  412.                                             'longitude'             => '',
  413.                                             'height'                => 600,
  414.                                             'width'                 => 800
  415.                                         ],
  416.                                         "dinding"  => [
  417.                                             'type'                  => 'online',
  418.                                             'source'                => $foto_dinding_100,
  419.                                             'latitude'              => '',
  420.                                             'longitude'             => '',
  421.                                             'height'                => 600,
  422.                                             'width'                 => 800
  423.                                         ],
  424.                                         "lantai"  => [
  425.                                             'type'                  => 'online',
  426.                                             'source'                => $foto_lantai_100,
  427.                                             'latitude'              => '',
  428.                                             'longitude'             => '',
  429.                                             'height'                => 600,
  430.                                             'width'                 => 800
  431.                                         ],
  432.                                         'is_form_valid'             => $is_valid_100
  433.                                     ]
  434.                             ]
  435.                     ];
  436.                 }
  437.             } else {
  438.                 $response  = [
  439.                     'resp_error'    => true,
  440.                     'resp_msg'      => "Data Tidak Ada."
  441.                 ];
  442.             }
  443.  
  444.             $this->response($response, 200);
  445.         }
  446.     }
  447.  
  448.     // Insert ke Table RTLH
  449.     function insertrtlh_post() {
  450.         // Upload File ZIP Android
  451.         $config['upload_path']      = './temp_sync/dataoperator/';
  452.         $config['max_size']         = '*';
  453.  
  454.         $this->load->library('upload');
  455.         $this->upload->initialize($config);
  456.         $upload         = $this->upload->do_upload('zipfile');
  457.         $upload_data    = $this->upload->data();
  458.         $file_name      = $upload_data['full_path']; // File Full Path
  459.         $nama_file      = $upload_data['raw_name'];
  460.         $json_file      = $upload_data['raw_name'].'.json'; // JSON File
  461.  
  462.         $zip = new ZipArchive;
  463.         if ($zip->open($file_name) === TRUE) {
  464.             // Buat Folder jika belum Ada
  465.             if (!file_exists('./temp_sync/dataoperator/data_ekstrak/'.$nama_file)) {
  466.                 mkdir('./temp_sync/dataoperator/data_ekstrak/'.$nama_file, 0755, true);
  467.             } else {
  468.                 // Delete Folder Lama
  469.                 $src = './temp_sync/dataoperator/data_ekstrak/'.$nama_file;
  470.                 $dir = opendir($src);
  471.                 while(false !== ( $file = readdir($dir)) ) {
  472.                     if (( $file != '.' ) && ( $file != '..' )) {
  473.                         if ( is_dir($src . '/' . $file) ) {
  474.                             delete_dir($src . '/' . $file);
  475.                         }
  476.                         else {
  477.                             unlink($src . '/' . $file);
  478.                         }
  479.                     }
  480.                 }
  481.                 closedir($dir);
  482.                 rmdir($src);
  483.                 // Buat Folder baru lagi
  484.                 mkdir('./temp_sync/dataoperator/data_ekstrak/'.$nama_file, 0755, true);
  485.             }
  486.             $zip->extractTo('./temp_sync/dataoperator/data_ekstrak/'.$nama_file);
  487.             $zip->close();
  488.         } else {
  489.             $response  = [
  490.                     'resp_error'    => true,
  491.                     'resp_msg'      => "Ekstrak ZIP Gagal."
  492.                 ];
  493.         }
  494.         unlink($file_name); // Delete Zip
  495.         // $this->response($response, 200);
  496.        
  497.         // Baca File JSON
  498.         if(file_exists('./temp_sync/dataoperator/data_ekstrak/'.$nama_file.'/'.$json_file)) {
  499.             $document   = file_get_contents(FCPATH.'temp_sync/dataoperator/data_ekstrak/'.$nama_file.'/'.$json_file);
  500.             $data       = json_decode($document);
  501.            
  502.             // Cek Data API Dukcapil
  503.             $this->load->library('curl');
  504.             $nik    = trim($data->nik); // NIK
  505.             $this->curl->http_header('Content-Type: application/json');
  506.             $this->curl->create('http://222.124.25.110:8000/dukcapil/get_json/DISPERKIM/NIK');
  507.             $this->curl->post(json_encode(["user_id"=>"DISPERKIM","password"=>"rumah","nik"=> $nik]));
  508.             $response   = $this->curl->execute();
  509.             $curl_jason = json_decode($response, true, 512, JSON_BIGINT_AS_STRING);
  510.  
  511.             if(count($curl_jason) > 0) {
  512.                 $kd_wilayah    = substr($curl_jason['content'][0]['NIK'], 0, 6);
  513.                 $nik           = $curl_jason['content'][0]['NIK'];
  514.                 $nama          = $curl_jason['content'][0]['NAMA_LGKP'];
  515.                 $jk            = $curl_jason['content'][0]['JENIS_KLMIN'];
  516.                 $tempatlahir   = $curl_jason['content'][0]['TMPT_LHR'];
  517.                 $tgllahir      = $curl_jason['content'][0]['TGL_LHR'];
  518.                 $no_kk         = $curl_jason['content'][0]['NO_KK'];
  519.                 $alamat        = $curl_jason['content'][0]['ALAMAT'];
  520.                 $no_kec        = $curl_jason['content'][0]['NO_KEC'];
  521.                 $no_kel        = $curl_jason['content'][0]['NO_KEL'];
  522.                 $rt            = $curl_jason['content'][0]['NO_RT'];
  523.                 $rw            = $curl_jason['content'][0]['NO_RW'];
  524.                 $pekerjaan     = $curl_jason['content'][0]['JENIS_PKRJN'];
  525.             } else {
  526.                 $this->curl->http_header('Content-Type: application/json');
  527.                 $this->curl->create('http://180.246.204.97:8000/dukcapil/get_json/DISPERKIM/NIK');
  528.                 $this->curl->post(json_encode(["user_id"=>"DISPERKIM","password"=>"rumah","nik"=>$nik]));
  529.                 $response   = $this->curl->execute();
  530.                 $curl_jason = json_decode($response, true, 512, JSON_BIGINT_AS_STRING);
  531.                
  532.                 if(count($curl_jason) > 0) {
  533.                     $kd_wilayah    = substr($curl_jason['content'][0]['NIK'], 0, 6);
  534.                     $nik           = $curl_jason['content'][0]['NIK'];
  535.                     $nama          = $curl_jason['content'][0]['NAMA_LGKP'];
  536.                     $jk            = $curl_jason['content'][0]['JENIS_KLMIN'];
  537.                     $tempatlahir   = $curl_jason['content'][0]['TMPT_LHR'];
  538.                     $tgllahir      = $curl_jason['content'][0]['TGL_LHR'];
  539.                     $no_kk         = $curl_jason['content'][0]['NO_KK'];
  540.                     $alamat        = $curl_jason['content'][0]['ALAMAT'];
  541.                     $no_kec        = $curl_jason['content'][0]['NO_KEC'];
  542.                     $no_kel        = $curl_jason['content'][0]['NO_KEL'];
  543.                     $rt            = $curl_jason['content'][0]['NO_RT'];
  544.                     $rw            = $curl_jason['content'][0]['NO_RW'];
  545.                     $pekerjaan     = $curl_jason['content'][0]['JENIS_PKRJN'];
  546.                 } else {
  547.                     $response  = [
  548.                         'resp_error'    => true,
  549.                         'resp_msg'      => "NIK Tidak Di Temukan."
  550.                     ];
  551.  
  552.                     $this->response($response, 200);
  553.                 }
  554.             }
  555.  
  556.             // Cek Data PBDT atau NON PBDT
  557.             $this->db->select('*');
  558.             $this->db->from('rtlh_data_pbdt');
  559.             $this->db->where('pbdt_nik', $nik);
  560.             $dtnik = $this->db->get()->row();
  561.  
  562.             if(count($dtnik) > 0) {
  563.                 $status_pbdt = 'PBDT';
  564.             } else {
  565.                 $status_pbdt = 'NON PBDT';
  566.             }
  567.  
  568.             // No. Urut RTLH
  569.             $this->db->select('RIGHT(r.rtlh_no_urut, 4) as kode', FALSE);
  570.             $this->db->from('rtlh_rtlh r');
  571.             $this->db->join('rtlh_penduduk_dukcapil p', 'r.penduduk_nik = p.penduduk_nik');
  572.             $this->db->where('p.no_kec', $no_kec); // per Kecamatan
  573.             $this->db->where('p.no_kel', $no_kel); // per Kelurahan
  574.             $this->db->where('p.penduduk_rt', $rt); // per RT
  575.             $this->db->where('p.penduduk_rw', $rw); // per RW
  576.             $this->db->order_by('r.rtlh_id', 'desc');
  577.             $this->db->limit(1);
  578.  
  579.             $query = $this->db->get();
  580.             if ($query->num_rows() <> 0) {
  581.                 $data = $query->row();
  582.                 $kode = intval($data->kode) + 1;
  583.             } else {
  584.                 $kode = 1;
  585.             }
  586.  
  587.             $nourut     = str_pad($kode, 4, "0", STR_PAD_LEFT);
  588.             $kel        = substr($no_kel, 2, 2);
  589.             $no_RTLH    = '3320'.$kec.$kel.$rt.$rw.$nourut;
  590.  
  591.             // Insert Variabel
  592.             // Variabel Prioritas Darurat
  593.             $lstPondasi                 = $data->data->data_kondisi_fisik_rumah->pondasi_bangunan; // Pondasi Bangunan
  594.             $lstKondisiBalok            = $data->data->data_kondisi_fisik_rumah->kondisi_balok_kolom; // Kondisi Balok dan Kolom
  595.             $lstKondisiKonstruksiAtap   = $data->data->data_kondisi_fisik_rumah->kondisi_konstruksi_atap; // Kondisi Konstruksi Atap
  596.             // Variabel Status Prioritas
  597.             $lstSanitasi                = $data->data->data_kondisi_fisik_rumah->sanitasi; // Kmr. Mandi & Jamban (ADA/TIDAK ADA)
  598.             $lstKondisiAtap             = $data->data->aspek_komponen->kondisi_atap; // Kondisi Atap (BOCOR SEDANG, BOCOR BERAT (2,3))
  599.             $lstKondisiDinding          = $data->data->aspek_komponen->kondisi_dinding; // Kondisi Dinding (RUSAK SEDANG, RUSAK BERAT (2,3))
  600.             $lstMaterialLantai          = $data->data->aspek_komponen->material_lantai; // Material Lantai (TANAH (6))
  601.  
  602.             // jika TIDAK ADA, nilai = 1
  603.             if ($lstSanitasi == 2) {
  604.                 $nilaiSanitasi = 1;
  605.             } else {
  606.                 $nilaiSanitasi = 0;
  607.             }
  608.  
  609.             // jika BOCOR, nilai = 1
  610.             if ($lstKondisiAtap == 2 || $lstKondisiAtap == 3) {
  611.                 $nilaiKondisiAtap = 1;
  612.             } else {
  613.                 $nilaiKondisiAtap = 0;
  614.             }
  615.  
  616.             // jika RUSAK, nilai = 1
  617.             if ($lstKondisiDinding == 2 || $lstKondisiDinding == 3) {
  618.                 $nilaiKondisiDinding = 1;
  619.             } else {
  620.                 $nilaiKondisiDinding = 1;
  621.             }
  622.  
  623.             // jika TANAH, nilai = 1
  624.             if ($lstMaterialLantai == 6) {
  625.                 $nilaiLantai = 1;
  626.             } else {
  627.                 $nilaiLantai = 1;
  628.             }
  629.  
  630.             $BatasDarurat       = ($lstPondasi+$lstKondisiBalok+$lstKondisiKonstruksiAtap);
  631.             $JumlahPrioritas    = ($nilaiSanitasi+$nilaiKondisiAtap+$nilaiKondisiDinding+$nilaiLantai);
  632.  
  633.             if ($BatasDarurat == 6) {  // Jika TIDAK LAYAK Semua = 6
  634.                 $StatusPrioritas = 'DARURAT';
  635.             } else {
  636.                 switch ($JumlahPrioritas) {
  637.                     case ($JumlahPrioritas == 4): // Jika 4 Komponen
  638.                         $StatusPrioritas = 'PRIORITAS 1';
  639.                         break;
  640.                     case ($JumlahPrioritas == 3): // Jika 3 Komponen
  641.                         $StatusPrioritas = 'PRIORITAS 2';
  642.                         break;
  643.                     case ($JumlahPrioritas == 2): // Jika 2 Komponen
  644.                         $StatusPrioritas = 'PRIORITAS 3';
  645.                         break;
  646.                     case ($JumlahPrioritas == 1): // Jika 1 Komponen
  647.                         $StatusPrioritas = 'PRIORITAS 4';
  648.                         break;
  649.                     case ($JumlahPrioritas == 0): // Jika 0 Komponen
  650.                         $StatusPrioritas = 'PRIORITAS 5';
  651.                         break;
  652.                     default:
  653.                         $StatusPrioritas = 'TIDAK MASUK PRIORITAS';
  654.                 }
  655.             }
  656.  
  657.             // Input Data Penduduk, Cek jika Ada Data atau Belum
  658.             $checkNIK   = "SELECT penduduk_nik FROM rtlh_penduduk_dukcapil WHERE penduduk_nik='$nik'";
  659.             $hasil      = $this->db->query($checkNIK)->row();
  660.             if (count($hasil) == 0) {
  661.                 $data = array(              
  662.                             'penduduk_nik'      => $nik,
  663.                             'penduduk_no_kk'    => $no_kk,
  664.                             'penduduk_nama'     => $nama,
  665.                             'penduduk_tmpt_lhr' => $tempatlahir,
  666.                             'penduduk_tgl_lahir'=> $tgllahir,
  667.                             'penduduk_jk'       => $jk,
  668.                             'no_kec'            => $no_kec,
  669.                             'no_kel'            => $no_kel,
  670.                             'penduduk_alamat'   => $alamat,
  671.                             'penduduk_rt'       => $rt,
  672.                             'penduduk_rw'       => $rw,
  673.                             'penduduk_kerja'    => $pekerjaan,
  674.                             'penduduk_update'   => date('Y-m-d H:i:s')
  675.                         );
  676.                
  677.                 $this->db->insert('rtlh_penduduk_dukcapil', $data);
  678.             } else {
  679.                 $data = array(
  680.                             'penduduk_no_kk'    => $no_kk,
  681.                             'penduduk_nama'     => $nama,
  682.                             'penduduk_tmpt_lhr' => $tempatlahir,
  683.                             'penduduk_tgl_lahir'=> $tgllahir,
  684.                             'penduduk_jk'       => $jk,
  685.                             'no_kec'            => $no_kec,
  686.                             'no_kel'            => $no_kel,
  687.                             'penduduk_alamat'   => $alamat,
  688.                             'penduduk_rt'       => $rt,
  689.                             'penduduk_rw'       => $rw,
  690.                             'penduduk_kerja'    => $pekerjaan,
  691.                             'penduduk_update'   => date('Y-m-d H:i:s')
  692.                         );
  693.                
  694.                 $this->db->where('penduduk_nik', $nik);
  695.                 $this->db->update('rtlh_penduduk_dukcapil', $data);
  696.             }
  697.  
  698.             // Input ke RTLH
  699.             $data = array(
  700.                 'rtlh_kode_wilayah'     => $kd_wilayah,
  701.                 'rtlh_no_urut'          => trim($no_RTLH),
  702.                 'penduduk_nik'          => $nik,
  703.                 'rtlh_pbdt'             => $status_pbdt,
  704.                 'no_kec'                => $no_kec,
  705.                 'no_kel'                => $no_kel,
  706.                 'penghasilan_id'        => $data->data->data_pendukung->penghasilan_perbulan,
  707.                 'pengeluaran_id'        => $data->data->data_pendukung->pengeluaran_perbulan,
  708.                 'status_tanah_id'       => $data->data->data_pendukung->status_kepemilikan_tanah,
  709.                 'bukti_tanah_id'        => $data->data->data_pendukung->bukti_kepemilikan_tanah,
  710.                 'pemilik_rumah_id'      => $data->data->data_pendukung->status_kepemilikan_rumah,
  711.                 'rtlh_rumah_lain'       => $data->data->data_pendukung->aset_rumah_lain,
  712.                 'rtlh_tanah_lain'       => $data->data->data_pendukung->aset_tanah_lain,
  713.                 'rtlh_imb'              => $data->data->data_pendukung->imb,
  714.                 'bantuan_id'            => $data->data->data_pendukung->bantuan_perumahan,
  715.                 'rtlh_pondasi'          => $data->data->data_kondisi_fisik_rumah->pondasi_bangunan,
  716.                 'rtlh_kondisi_balok'    => $data->data->data_kondisi_fisik_rumah->kondisi_balok_kolom,
  717.                 'rtlh_kondisi_atap'     => $data->data->data_kondisi_fisik_rumah->kondisi_konstruksi_atap,
  718.                 'rtlh_jendela'          => $data->data->data_kondisi_fisik_rumah->jendela_lubang_cahaya,
  719.                 'ventilasi_id'          => $data->data->data_kondisi_fisik_rumah->ventilasi,
  720.                 'rtlh_sanitasi'         => $data->data->data_kondisi_fisik_rumah->sanitasi,
  721.                 'rtlh_kondisi_sanitasi' => $data->data->data_kondisi_fisik_rumah->kondisi_sanitasi,
  722.                 'sanitasi_id'           => $data->data->data_kondisi_fisik_rumah->jenis_sanitasi,
  723.                 'rtlh_septitank'        => $data->data->data_kondisi_fisik_rumah->septitank,
  724.                 'rtlh_kondisi_septitank'=> $data->data->data_kondisi_fisik_rumah->kondisi_septitank,
  725.                 'air_minum_id'          => $data->data->data_kondisi_fisik_rumah->sumber_air_minum,
  726.                 'listrik_id'            => $data->data->data_kondisi_fisik_rumah->sumber_listrik,
  727.                 'rtlh_luas'             => $data->data->aspek_persyaratan->luas_rumah,
  728.                 'rtlh_jml_orang'        => $data->data->aspek_persyaratan->jumlah_penghuni,
  729.                 'rtlh_no_kk_lain'       => $data->data->aspek_persyaratan->no_kk_lain,
  730.                 'rtlh_jml_kk'           => $data->data->aspek_persyaratan->jml_kk,
  731.                 'tinggi_id'             => $data->data->aspek_persyaratan->tinggi_bangunan,
  732.                 'rtlh_ruang_keluarga'   => $data->data->aspek_persyaratan->rg_keluarga,
  733.                 'material_atap_id'      => $data->data->aspek_komponen->material_atap,
  734.                 'kondisi_atap_id'       => $data->data->aspek_komponen->kondisi_atap,
  735.                 'material_dinding_id'   => $data->data->aspek_komponen->material_dinding_terluas,
  736.                 'kondisi_dinding_id'    => $data->data->aspek_komponen->kondisi_dinding,
  737.                 'material_lantai_id'    => $data->data->aspek_komponen->material_lantai,
  738.                 'luas_lantai_id'        => $data->data->aspek_komponen->luas_lantai,
  739.                 'rtlh_lat'              => $data->data->lokasi_rumah->latitude,
  740.                 'rtlh_long'             => $data->data->lokasi_rumah->longitude,
  741.                 'rtlh_bts_timur'        => $data->data->lokasi_rumah->batas_timur,
  742.                 'rtlh_bts_barat'        => $data->data->lokasi_rumah->batas_barat,
  743.                 'rtlh_bts_utara'        => $data->data->lokasi_rumah->batas_utara,
  744.                 'rtlh_bts_selatan'      => $data->data->lokasi_rumah->batas_selatan,
  745.                 'rtlh_status'           => 'Baru',
  746.                 'rtlh_prioritas'        => $StatusPrioritas,
  747.                 'rtlh_foto'             => $data->data->foto_pemilik->foto_pemilik->source,
  748.                 'user_username'         => '3319042107870002',
  749.                 'rtlh_post'             => date('Y-m-d H:i:s'),
  750.                 'rtlh_update'           => date('Y-m-d H:i:s')
  751.             );
  752.  
  753.             $this->db->insert('rtlh_rtlh', $data);
  754.  
  755.         } else {
  756.             echo 'File Tidak Ada.';
  757.         }
  758.     }
  759. }
  760. /* Location: ./application/controllers/api/Dataapi.php */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement