Advertisement
jamboljack

Save Data IMB

Aug 28th, 2018
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.11 KB | None | 0 0
  1. // Simpan Data dari Member
  2.     public function savedata_post()
  3.     {
  4.         $username = trim($this->post('username'));
  5.  
  6.         if ($username == '') {
  7.             $response = [
  8.                 'resp_error' => true,
  9.                 'resp_msg'   => 'Username Kosong.',
  10.             ];
  11.         } elseif ($this->post('nama') == '') {
  12.             $response = [
  13.                 'resp_error' => true,
  14.                 'resp_msg'   => 'Nama Pemohon Tidak Boleh Kosong.',
  15.             ];
  16.         } elseif ($this->post('tempat_lahir') == '') {
  17.             $response = [
  18.                 'resp_error' => true,
  19.                 'resp_msg'   => 'Tempat Lahir Tidak Boleh Kosong.',
  20.             ];
  21.         } elseif ($this->post('tanggal_lahir') == '') {
  22.             $response = [
  23.                 'resp_error' => true,
  24.                 'resp_msg'   => 'Tanggal Lahir Tidak Boleh Kosong.',
  25.             ];
  26.         } elseif ($this->post('alamat') == '') {
  27.             $response = [
  28.                 'resp_error' => true,
  29.                 'resp_msg'   => 'Alamat Pemohon Tidak Boleh Kosong.',
  30.             ];
  31.         } elseif ($this->post('provinsi_id') == '') {
  32.             $response = [
  33.                 'resp_error' => true,
  34.                 'resp_msg'   => 'Provinsi Tidak Boleh Kosong.',
  35.             ];
  36.         } elseif ($this->post('kabupaten_id') == '') {
  37.             $response = [
  38.                 'resp_error' => true,
  39.                 'resp_msg'   => 'Kabupaten Tidak Boleh Kosong.',
  40.             ];
  41.         } elseif ($this->post('kecamatan_id') == '') {
  42.             $response = [
  43.                 'resp_error' => true,
  44.                 'resp_msg'   => 'Kecamatan Tidak Boleh Kosong.',
  45.             ];
  46.         } elseif ($this->post('desa_id') == '') {
  47.             $response = [
  48.                 'resp_error' => true,
  49.                 'resp_msg'   => 'Desa/Kelurahan Tidak Boleh Kosong.',
  50.             ];
  51.         } elseif ($this->post('kode_pos') == '') {
  52.             $response = [
  53.                 'resp_error' => true,
  54.                 'resp_msg'   => 'Kode Pos Tidak Boleh Kosong.',
  55.             ];
  56.         } elseif ($this->post('email') == '') {
  57.             $response = [
  58.                 'resp_error' => true,
  59.                 'resp_msg'   => 'Email Tidak Boleh Kosong.',
  60.             ];
  61.         } elseif ($this->post('no_telepon') == '') {
  62.             $response = [
  63.                 'resp_error' => true,
  64.                 'resp_msg'   => 'No. Telepon Tidak Boleh Kosong.',
  65.             ];
  66.         } elseif ($this->post('no_ktp') == '') {
  67.             $response = [
  68.                 'resp_error' => true,
  69.                 'resp_msg'   => 'No. KTP Tidak Boleh Kosong.',
  70.             ];
  71.         } elseif ($this->post('pekerjaan') == '') {
  72.             $response = [
  73.                 'resp_error' => true,
  74.                 'resp_msg'   => 'Pekerjaan Tidak Boleh Kosong.',
  75.             ];
  76.         } elseif ($this->post('id_imb') == '') {
  77.             $response = [
  78.                 'resp_error' => true,
  79.                 'resp_msg'   => 'Jenis IMB Tidak Boleh Kosong.',
  80.             ];
  81.         } else {
  82.             $id        = $this->post('id');
  83.             $checkdata = $this->db->get_where('c39_imb_pemohon', array('id' => $id))->row();
  84.             if (count($checkdata) > 0) {
  85.                 // Update Data
  86.                 $data = array(
  87.                     'nama'                => strtoupper(trim($this->post('nama'))),
  88.                     'tempat_lahir'        => strtoupper(trim($this->post('tempat_lahir'))),
  89.                     'tanggal_lahir'       => date('Y-m-d', strtotime($this->post('tanggal_lahir'))),
  90.                     'alamat'              => strtoupper(trim($this->post('alamat'))),
  91.                     'provinsi_id'         => $this->post('provinsi_id'),
  92.                     'kabupaten_id'        => $this->post('kabupaten_id', 'true'),
  93.                     'kecamatan_id'        => $this->post('kecamatan_id', 'true'),
  94.                     'desa_id'             => $this->post('desa_id', 'true'),
  95.                     'kode_pos'            => trim($this->post('kode_pos')),
  96.                     'email'               => trim($this->post('email')),
  97.                     'no_telepon'          => trim($this->post('no_telepon')),
  98.                     'no_ktp'              => trim($this->post('no_ktp')),
  99.                     'pekerjaan'           => strtoupper(trim($this->post('pekerjaan'))),
  100.                     'id_imb'              => trim($this->post('id_imb')),
  101.                     'pemohon_date_update' => date('Y-m-d'),
  102.                     'pemohon_time_update' => date('Y-m-d H:i:s'),
  103.                 );
  104.  
  105.                 $this->db->where('id', $id);
  106.                 $this->db->update('c39_imb_pemohon', $data);
  107.  
  108.                 $dataPerus = array(
  109.                     'nama_pemilik' => strtoupper(trim($this->post('nama_pemilik'))),
  110.                     'alamat_prsh'  => strtoupper(trim($this->post('alamat_prsh'))),
  111.                     'telp_prsh'    => trim($this->post('telp_prsh')),
  112.                     'fax_prsh'     => trim($this->post('fax_prsh')),
  113.                     'email_prsh'   => trim($this->post('email_prsh')),
  114.                     'nama_pjwb'    => strtoupper(trim($this->post('nama_pjwb'))),
  115.                 );
  116.  
  117.                 $this->db->where('id_pemohon', $id);
  118.                 $this->db->update('c39_imb_perusahaan', $dataPerus);
  119.  
  120.                 $response = [
  121.                     'resp_error' => false,
  122.                     'resp_msg'   => 'Data Permohonan Ter-Update.',
  123.                 ];
  124.             } else {
  125.                 $no_register = $this->db->get_where('c39_imb_noreg_tmp', array('tahun' => date('Y')))->row();
  126.                 if (count($no_register) > 0) {
  127.                     $xno = $no_register->nomor;
  128.                     $zno = ($xno + 1);
  129.                 } else {
  130.                     $zno = 1;
  131.                 }
  132.  
  133.                 $noreg = $zno . "." . date('m') . "/IMB.SIPTO/15.04/" . date('Y');
  134.                 $query = $this->db->get('c39_imb_noreg_tmp');
  135.                 if ($query->num_rows() > 0) {
  136.                     $data_reg = array(
  137.                         'nomor'  => trim($zno),
  138.                         'tahun'  => date('Y'),
  139.                         'no_reg' => trim($noreg),
  140.                     );
  141.  
  142.                     $this->db->where('id', 1);
  143.                     $this->db->update('c39_imb_noreg_tmp', $data_reg);
  144.                 } else {
  145.                     $data_reg = array(
  146.                         'nomor'  => trim($zno),
  147.                         'tahun'  => trim($thn),
  148.                         'no_reg' => trim($noreg),
  149.                     );
  150.  
  151.                     $this->db->insert('c39_imb_noreg_tmp', $data_reg);
  152.                 }
  153.  
  154.                 $data = array(
  155.                     'user_username'       => $username,
  156.                     'tanggal'             => date('Y-m-d'),
  157.                     'no_register'         => trim($noreg),
  158.                     'nama'                => strtoupper(trim($this->post('nama'))),
  159.                     'tempat_lahir'        => strtoupper(trim($this->post('tempat_lahir'))),
  160.                     'tanggal_lahir'       => date('Y-m-d', strtotime($this->post('tanggal_lahir'))),
  161.                     'alamat'              => strtoupper(trim($this->post('alamat'))),
  162.                     'provinsi_id'         => $this->post('provinsi_id'),
  163.                     'kabupaten_id'        => $this->post('kabupaten_id', 'true'),
  164.                     'kecamatan_id'        => $this->post('kecamatan_id', 'true'),
  165.                     'desa_id'             => $this->post('desa_id', 'true'),
  166.                     'kode_pos'            => trim($this->post('kode_pos')),
  167.                     'email'               => trim($this->post('email')),
  168.                     'no_telepon'          => trim($this->post('no_telepon')),
  169.                     'no_ktp'              => trim($this->post('no_ktp')),
  170.                     'pekerjaan'           => strtoupper(trim($this->post('pekerjaan'))),
  171.                     'id_imb'              => trim($this->post('id_imb')),
  172.                     'pemohon_date_update' => date('Y-m-d'),
  173.                     'pemohon_time_update' => date('Y-m-d H:i:s'),
  174.                 );
  175.  
  176.                 $this->db->insert('c39_imb_pemohon', $data);
  177.                 $id = $this->db->insert_id();
  178.  
  179.                 $dataPerus = array(
  180.                     'id_pemohon'   => $id,
  181.                     'nama_pemilik' => strtoupper(trim($this->post('nama_pemilik'))),
  182.                     'alamat_prsh'  => strtoupper(trim($this->post('alamat_prsh'))),
  183.                     'telp_prsh'    => trim($this->post('telp_prsh')),
  184.                     'fax_prsh'     => trim($this->post('fax_prsh')),
  185.                     'email_prsh'   => trim($this->post('email_prsh')),
  186.                     'nama_pjwb'    => strtoupper(trim($this->post('nama_pjwb'))),
  187.                 );
  188.  
  189.                 $this->db->insert('c39_imb_perusahaan', $dataPerus);
  190.  
  191.                 $response = [
  192.                     'resp_error' => false,
  193.                     'resp_msg'   => 'Data Permohonan Tersimpan.',
  194.                 ];
  195.             }
  196.         }
  197.  
  198.         $this->response($response, 200);
  199.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement