PageRenderTime 41ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/application/modules/workarea/controllers/Workarea.php

https://bitbucket.org/bo_hmb/bo_hmb
PHP | 319 lines | 239 code | 60 blank | 20 comment | 25 complexity | 2613d387e0c9853d02890d9e70ff3d75 MD5 | raw file
Possible License(s): Apache-2.0, MIT, LGPL-2.1, MPL-2.0-no-copyleft-exception, GPL-2.0
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Workarea extends AdminController {
  3. public function __construct()
  4. {
  5. parent::__construct();
  6. $this->tanggal = date("Y-m-d");
  7. $this->jam = date("H:i:s");
  8. $this->bulan = date('m');
  9. $this->tahun = date('Y');
  10. // Module components
  11. $this->data['module'] = 'Working Area';
  12. $this->data['pluginCss'] = $this->load->view('assets/_pluginCss', $this->data, true);
  13. $this->data['pluginJs'] = $this->load->view('assets/_pluginJs', $this->data, true);
  14. $this->load->model('M_workarea');
  15. // $this->output->enable_profiler(TRUE);
  16. if($this->cekCurrentUser > 0) {
  17. $this->group = $this->ion_auth->get_users_groups( $this->currentUser->id)->result();
  18. $this->kode_cabang = $this->currentUser->kode_cabang;
  19. foreach ($this->group as $key => $value) {
  20. $userGroup[$value->name] = $value->description;
  21. }
  22. $this->userLevel = $userGroup;
  23. }
  24. }
  25. public function index()
  26. {
  27. // Page components
  28. $this->data['userGroup'] = $this->userLevel;
  29. $this->data['pageTitle'] = 'Work Area';
  30. $this->data['pageCss'] = $this->load->view('assets/_pageCss', $this->data, true);;
  31. $this->data['pageJs'] = $this->load->view('assets/_pageJs', $this->data, true);
  32. $this->data['content'] = $this->load->view('main', $this->data, true);
  33. // Render page
  34. $this->renderPage();
  35. }
  36. public function load_data()
  37. {
  38. $kd_cabang = $this->input->post('kd_cabang',TRUE);
  39. $nm_cabang = $this->input->post('nm_cabang',TRUE);
  40. $alamat = $this->input->post('alamat',TRUE);
  41. $rekening = $this->input->post('rekening',TRUE);
  42. $no_telp = $this->input->post('no_telp',TRUE);
  43. $kota = $this->input->post('kota',TRUE);
  44. $prov = $this->input->post('prov',TRUE);
  45. $pimpinan = $this->input->post('pimpinan',TRUE);
  46. $no_hp_pimpinan = $this->input->post('no_hp_pimpinan',TRUE);
  47. $biaya_pesawat_kepusat = $this->input->post('biaya_pesawat_kepusat',TRUE);
  48. $nm_marketing = $this->input->post('nm_marketing',TRUE);
  49. $jenis_cabang = $this->input->post('jenis_cabang',TRUE);
  50. $cols = array();
  51. if (!empty($kd_cabang)) { $cols['kd_cabang'] = $kd_cabang; }
  52. if (!empty($nm_cabang)) { $cols['nm_cabang'] = $nm_cabang; }
  53. if (!empty($alamat)) { $cols['alamat'] = $alamat; }
  54. if (!empty($rekening)) { $cols['rekening'] = $rekening; }
  55. if (!empty($no_telp)) { $cols['no_telp'] = $no_telp; }
  56. if (!empty($kota)) { $cols['kota'] = $kota; }
  57. if (!empty($prov)) { $cols['prov'] = $prov; }
  58. if (!empty($pimpinan)) { $cols['pimpinan'] = $pimpinan; }
  59. if (!empty($no_hp_pimpinan)) { $cols['no_hp_pimpinan'] = $no_hp_pimpinan; }
  60. if (!empty($biaya_pesawat_kepusat)) { $cols['biaya_pesawat_kepusat'] = $biaya_pesawat_kepusat; }
  61. if (!empty($nm_marketing)) { $cols['nm_marketing'] = $nm_marketing; }
  62. if (!empty($jenis_cabang)) { $cols['jenis_cabang'] = $jenis_cabang; }
  63. if(array_key_exists('Super Admin', $this->userLevel)) {
  64. $where = "cabang.active = '1'";
  65. } else {
  66. $where = "cabang.active = '1'";
  67. }
  68. $list = $this->M_workarea->get_datatables($where, $cols);
  69. $last_query = $this->db->last_query();
  70. // die(print_r($last_query));
  71. $iTotalRecords = $this->M_workarea->count_all($where);
  72. $iDisplayLength = intval($_REQUEST['length']);
  73. $iDisplayLength = $iDisplayLength < 0 ? $iTotalRecords : $iDisplayLength;
  74. $iDisplayStart = intval($_REQUEST['start']);
  75. $sEcho = intval($_REQUEST['draw']);
  76. $records = array();
  77. $records["data"] = array();
  78. $end = $iDisplayStart + $iDisplayLength;
  79. $end = $end > $iTotalRecords ? $iTotalRecords : $end;
  80. $no = $iDisplayStart;
  81. foreach ($list as $r) {
  82. $no++;
  83. $btn_action = '<div class="btn-group btn-group-xs btn-group-solid">
  84. <button type="button" class="btn btn-xs yellow btn-outline btn-edit tooltips" data-container="body" data-placement="top" data-original-title="Tooltip in top" data-id="'.$r->id.'"><i class="fa fa-edit"></i></button>
  85. <button class="btn btn-xs btn-outline red btn-update-status" data-id="'.$r->id.'" data-toggle="confirmation" data-placement="top" data-btn-ok-label="Yes" data-btn-ok-icon="icon-user-following" data-btn-ok-class="btn-success" data-btn-cancel-label="No" data-btn-cancel-icon="icon-user-unfollow" data-btn-cancel-class="btn-danger"><i class="fa fa-trash"></i></button>
  86. </div>';
  87. $records["data"][] = array(
  88. $no,
  89. $btn_action,
  90. $r->kd_cabang,
  91. $r->nm_cabang,
  92. $r->alamat,
  93. $r->rekening,
  94. $r->no_telp,
  95. $r->name_regencies,
  96. $r->name_provinces,
  97. $r->pimpinan,
  98. $r->no_hp_pimpinan,
  99. // $r->biaya_pesawat_kepusat,
  100. $r->nm_marketing,
  101. $r->jenis_cabang,
  102. );
  103. }
  104. if (isset($_REQUEST["customActionType"]) && $_REQUEST["customActionType"] == "group_action") {
  105. $records["customActionStatus"] = "OK"; // pass custom message(useful for getting status of group actions)
  106. $records["customActionMessage"] = "Group action successfully has been completed. Well done!"; // pass custom message(useful for getting status of group actions)
  107. }
  108. $records["draw"] = $sEcho;
  109. $records["recordsTotal"] = $iTotalRecords;
  110. $records["recordsFiltered"] = $iTotalRecords;
  111. echo json_encode($records);
  112. }
  113. public function load_detail()
  114. {
  115. $id = $this->input->get('id');
  116. $data['main'] = $this->M_workarea->get_where(array('id' => $id ))->row();
  117. return response($this->load->view('detail', $data, TRUE), 'html');
  118. }
  119. public function load_add_form()
  120. {
  121. $data['title'] = 'Tambah Data Work Area';
  122. // $data['marketing'] = Modules::run('marketing/get_marketing_where', array('active' => '1'))->result();
  123. $data = array(
  124. 'provinsi' => Modules::run('master_indonesia/get_provinsi'),
  125. 'kota' => Modules::run('master_indonesia/get_kota'),
  126. 'provinsi_selected' => '',
  127. 'kota_selected' => '',
  128. 'marketing' => Modules::run('marketing/get_marketing_where', array('active' => '1'))->result(),
  129. );
  130. return response($this->load->view('add_workarea', $data, TRUE), 'html');
  131. }
  132. public function add()
  133. {
  134. $this->ajaxRequest();
  135. $data = array(
  136. 'kd_cabang' => $this->input->post('kd_cabang',TRUE),
  137. 'nm_cabang' => $this->input->post('nm_cabang',TRUE),
  138. 'alamat' => $this->input->post('alamat',TRUE),
  139. 'rekening' => $this->input->post('rekening',TRUE),
  140. 'no_telp' => $this->input->post('no_telp',TRUE),
  141. 'kota' => $this->input->post('kota',TRUE),
  142. 'prov' => $this->input->post('prov',TRUE),
  143. 'pimpinan' => $this->input->post('pimpinan',TRUE),
  144. 'no_hp_pimpinan' => $this->input->post('no_hp_pimpinan',TRUE),
  145. 'biaya_pesawat_kepusat' => $this->input->post('biaya_pesawat_kepusat',TRUE),
  146. 'referensi_cabang' => $this->input->post('referensi_cabang',TRUE),
  147. 'jenis_cabang' => $this->input->post('jenis_cabang',TRUE),
  148. 'active' => '1',
  149. 'id_user' => $this->currentUser->id,
  150. );
  151. $query = $this->M_workarea->_insert($data);
  152. // Check if query was success
  153. if ($query) {
  154. $response = array('status' => true, 'action' => 'Success', 'message' => 'Data berhasil ditambahkan');
  155. } else {
  156. $response = array('status' => false, 'action' => 'Failed', 'message' => 'Data gagal ditambahkan');
  157. }
  158. return response($response, 'json');
  159. }
  160. public function load_edit_form()
  161. {
  162. $id = $this->input->get('id');
  163. $data = array(
  164. 'provinsi' => Modules::run('master_indonesia/get_provinsi'),
  165. 'kota' => Modules::run('master_indonesia/get_kota'),
  166. 'provinsi_selected' => '',
  167. 'kota_selected' => '',
  168. 'marketing' => Modules::run('marketing/get_marketing_where', array('active' => '1'))->result(),
  169. 'main' => $this->M_workarea->get_where(array('id' => $id))->row(),
  170. );
  171. return response($this->load->view('edit_workarea', $data, TRUE), 'html');
  172. }
  173. public function edit()
  174. {
  175. // Check if ajax request
  176. $this->ajaxRequest();
  177. // Validate the submitted data
  178. // $this->validateInput();
  179. // Preparing the data before update
  180. $id = $this->input->post('id');
  181. $data = array(
  182. 'kd_cabang' => $this->input->post('kd_cabang',TRUE),
  183. 'nm_cabang' => $this->input->post('nm_cabang',TRUE),
  184. 'alamat' => $this->input->post('alamat',TRUE),
  185. 'rekening' => $this->input->post('rekening',TRUE),
  186. 'no_telp' => $this->input->post('no_telp',TRUE),
  187. 'kota' => $this->input->post('kota',TRUE),
  188. 'prov' => $this->input->post('prov',TRUE),
  189. 'pimpinan' => $this->input->post('pimpinan',TRUE),
  190. 'no_hp_pimpinan' => $this->input->post('no_hp_pimpinan',TRUE),
  191. 'biaya_pesawat_kepusat' => $this->input->post('biaya_pesawat_kepusat',TRUE),
  192. 'referensi_cabang' => $this->input->post('referensi_cabang',TRUE),
  193. 'jenis_cabang' => $this->input->post('jenis_cabang',TRUE),
  194. 'user_update' => $this->currentUser->id,
  195. );
  196. $query = $this->M_workarea->_update(array('id' => $id), $data);
  197. // Check if query was success
  198. if ($query) {
  199. $results = array('status' => true, 'action' => 'Success', 'message' => 'updated successfully');
  200. } else {
  201. $results = array('status' => false, 'action' => 'Failed', 'message' => 'Failed to update');
  202. }
  203. // Return the result to the view
  204. return response($results);
  205. }
  206. public function delete()
  207. {
  208. $id = $this->input->post('id');
  209. $data = array(
  210. 'active' => '0',
  211. 'user_update' => $this->currentUser->id,
  212. );
  213. // die(print_r($data));
  214. $query = $this->M_workarea->_update(array('id' => $id), $data);
  215. // Check if query was success
  216. if ($query) {
  217. $results = array('status' => true, 'action' => 'Success', 'message' => 'berhasil');
  218. } else {
  219. $results = array('status' => false, 'action' => 'Failed', 'message' => 'Gagal');
  220. }
  221. // Return the result to the view
  222. return response($results, 'json');
  223. }
  224. public function validateInput()
  225. {
  226. // Load form validation library
  227. $this->load->library('form_validation');
  228. // Set validation rules
  229. $this->form_validation->set_rules('kd_cabang', 'kd cabang', 'trim|required');
  230. $this->form_validation->set_rules('nm_cabang', 'nm cabang', 'trim|required');
  231. $this->form_validation->set_rules('alamat', 'alamat', 'trim|required');
  232. $this->form_validation->set_rules('no_telp', 'no telp', 'trim|required');
  233. $this->form_validation->set_rules('kota', 'kota', 'trim|required');
  234. $this->form_validation->set_rules('prov', 'prov', 'trim|required');
  235. $this->form_validation->set_rules('pimpinan', 'pimpinan', 'trim|required');
  236. $this->form_validation->set_rules('no_hp_pimpinan', 'no hp pimpinan', 'trim|required');
  237. $this->form_validation->set_rules('biaya_pesawat_kepusat', 'biaya pesawat kepusat', 'trim|required');
  238. // Run the validation
  239. if ($this->form_validation->run() === false) {
  240. $response = array(
  241. 'status' => false,
  242. 'action' => 'Failed',
  243. 'message' => $this->form_validation->error_string('<h5>', '</h5>')
  244. );
  245. return response($response, 'json');
  246. }
  247. }
  248. public function get_workarea()
  249. {
  250. $query = $this->M_workarea->get()->result();
  251. return $query;
  252. }
  253. public function _get_where($where)
  254. {
  255. $query = $this->M_workarea->get_where($where);
  256. return $query;
  257. }
  258. }
  259. ?>