Advertisement
jamboljack

Save Data Proposal

Oct 25th, 2018
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.00 KB | None | 0 0
  1. public function savedataproposal_post()
  2.     {
  3.         $username   = trim($this->post('username'));
  4.         $lecture_id = $this->post('lecture_id');
  5.  
  6.         if ($username == '') {
  7.             $response = [
  8.                 'resp_error' => true,
  9.                 'resp_msg'   => 'Username kosong.',
  10.             ];
  11.         } elseif ($this->post('tanggal1') == '') {
  12.             $response = [
  13.                 'resp_error' => true,
  14.                 'resp_msg'   => 'Dari Tanggal harus diisi.',
  15.             ];
  16.         } elseif ($this->post('tanggal2') == '') {
  17.             $response = [
  18.                 'resp_error' => true,
  19.                 'resp_msg'   => 'Sampai Tanggal harus diisi.',
  20.             ];
  21.         } elseif ($this->post('judul') == '') {
  22.             $response = [
  23.                 'resp_error' => true,
  24.                 'resp_msg'   => 'Judul harus diisi.',
  25.             ];
  26.         } elseif ($this->post('lstPusatStudi') == '') {
  27.             $response = [
  28.                 'resp_error' => true,
  29.                 'resp_msg'   => 'Pusat Studi harus dipilih.',
  30.             ];
  31.         } elseif ($this->post('lstSkim') == '') {
  32.             $response = [
  33.                 'resp_error' => true,
  34.                 'resp_msg'   => 'Kategori harus dipilih.',
  35.             ];
  36.         } elseif ($this->post('tempat') == '') {
  37.             $response = [
  38.                 'resp_error' => true,
  39.                 'resp_msg'   => 'Tempat Penelitian harus diisi.',
  40.             ];
  41.         } elseif ($this->post('metode') == '') {
  42.             $response = [
  43.                 'resp_error' => true,
  44.                 'resp_msg'   => 'Metode Penelitian harus diisi.',
  45.             ];
  46.         } elseif ($this->post('masalah') == '') {
  47.             $response = [
  48.                 'resp_error' => true,
  49.                 'resp_msg'   => 'Masalah Penelitian harus diisi.',
  50.             ];
  51.         } elseif ($this->post('tujuan') == '') {
  52.             $response = [
  53.                 'resp_error' => true,
  54.                 'resp_msg'   => 'Tujuan Penelitian harus diisi.',
  55.             ];
  56.         } elseif ($this->post('luaran') == '') {
  57.             $response = [
  58.                 'resp_error' => true,
  59.                 'resp_msg'   => 'Luaran yang dihasilkan harus diisi.',
  60.             ];
  61.         } elseif ($this->post('dana') == '' || $this->post('dana') == 0) {
  62.             $response = [
  63.                 'resp_error' => true,
  64.                 'resp_msg'   => 'Dana Usulan harus diisi.',
  65.             ];
  66.         } elseif (empty($_FILES['file_pdf']['name'])) {
  67.             $response = [
  68.                 'resp_error' => true,
  69.                 'resp_msg'   => 'File Proposal harus diisi.',
  70.             ];
  71.         } else {
  72.             $jam                     = time();
  73.             $config['file_name']     = 'Proposal_' . $username . '_' . $jam . '.pdf';
  74.             $config['upload_path']   = './upload_file/proposal/';
  75.             $config['allowed_types'] = 'pdf';
  76.             $config['overwrite']     = true;
  77.             $config['max_size']      = 0;
  78.             $this->load->library('upload', $config);
  79.             if (!$this->upload->do_upload('file_pdf')) {
  80.                 $response = [
  81.                     'resp_error' => true,
  82.                     'resp_msg'   => 'File harus PDF.',
  83.                 ];
  84.             } else {
  85.                 // Cek Masih ada Tanggungan apa tidak
  86.                 $checkTanggungan = $this->db->get_where('v_dosen', array('user_username' => $username))->row();
  87.                 if ($checkTanggungan->lecture_tanggungan == 'Ada') {
  88.                     $response = [
  89.                         'resp_error' => true,
  90.                         'resp_msg'   => 'Anda masih punya Tanggungan Proposal',
  91.                     ];
  92.                 } else {
  93.                     $dtBudget      = $this->db->get_where('lemlit_skim', array('skim_id' => $this->post('lstSkim')))->row();
  94.                     $budget        = $dtBudget->skim_budget;
  95.                     $budget_rupiah = number_format($budget, 0, '', ',');
  96.                     $dana          = $this->post('dana');
  97.  
  98.                     if ($dana > $budget) {
  99.                         $response = [
  100.                             'resp_error' => true,
  101.                             'resp_msg'   => 'Usulan Dana Melebihi Budget, Budget = ' . $budget_rupiah,
  102.                         ];
  103.                     } else {
  104.                         $data = array(
  105.                             'user_username'     => $username,
  106.                             'skim_id'           => $this->post('lstSkim'),
  107.                             'pusat_studi_id'    => $this->post('lstPusatStudi'),
  108.                             'propose_title'     => strtoupper($this->post('judul')),
  109.                             'propose_title_seo' => seo_title($this->post('judul')),
  110.                             'propose_place'     => strtoupper($this->post('tempat')),
  111.                             'propose_method'    => trim($this->post('metode')),
  112.                             'propose_masalah'   => trim($this->post('masalah')),
  113.                             'propose_fund'      => $this->post('dana'),
  114.                             'propose_budget'    => $budget,
  115.                             'propose_purpose'   => trim($this->post('tujuan')),
  116.                             'propose_luaran'    => trim($this->post('luaran')),
  117.                             'propose_date1'     => $this->post('tanggal1'),
  118.                             'propose_date2'     => $this->post('tanggal2'),
  119.                             'propose_proposal'  => $this->upload->file_name,
  120.                             'propose_date'      => date('Y-m-d'),
  121.                             'propose_update'    => date('Y-m-d H:i:s'),
  122.                         );
  123.  
  124.                         $this->db->insert('lemlit_propose', $data);
  125.  
  126.                         $propose_id = $this->db->insert_id();
  127.                         $data       = array(
  128.                             'propose_id'           => $propose_id,
  129.                             'lecture_id'           => $lecture_id,
  130.                             'team_position_level'  => 'Ketua',
  131.                             'team_position_status' => 'Confirm',
  132.                             'team_position_update' => date('Y-m-d H:i:s'),
  133.                         );
  134.  
  135.                         $this->db->insert('lemlit_team_position', $data);
  136.  
  137.                         // Update Data Tanggungan menjadi Ada
  138.                         $data = array(
  139.                             'lecture_tanggungan' => 'Ada',
  140.                             'lecture_update'     => date('Y-m-d H:i:s'),
  141.                         );
  142.  
  143.                         $this->db->where('user_username', $username);
  144.                         $this->db->update('lemlit_lecture', $data);
  145.  
  146.                         // Send Notifikasi ke Admin
  147.                         $pesanNotif = 'Pengajuan Proposal Baru : ' . $username . 'A.n : ' . $checkTanggungan->user_name;
  148.                         $dataNotif  = array(
  149.                             'user_pengirim'    => $username,
  150.                             'user_username'    => $username,
  151.                             'notifikasi_date'  => date('Y-m-d'),
  152.                             'notifikasi_desc'  => $pesanNotif,
  153.                             'notifikasi_level' => 'Admin',
  154.                         );
  155.  
  156.                         $this->db->insert('lemlit_notifikasi', $dataNotif);
  157.  
  158.                         $listUser = $this->db->get_where('lemlit_users', array('device_id !=' => '', 'user_level' => 'Admin'))->result();
  159.                         if (count($listUser) > 0) {
  160.                             foreach ($listUser as $r) {
  161.                                 sendNotification($r->device_id, $pesanNotif);
  162.                             }
  163.                         }
  164.  
  165.                         $response = [
  166.                             'resp_error' => false,
  167.                             'resp_msg'   => 'Proposal Berhasil di Simpan.',
  168.                         ];
  169.                     }
  170.                 }
  171.             }
  172.         }
  173.  
  174.         $this->response($response, 200);
  175.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement