PageRenderTime 56ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/application/modules/structure_marketing/controllers/Structure_marketing.php

https://bitbucket.org/bo_hmb/bo_hmb
PHP | 312 lines | 221 code | 66 blank | 25 comment | 19 complexity | 076284dbcf6b4db3ebef000ebdf6feea 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 Structure_marketing 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'] = 'Structure Marketing';
  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_level_marketing');
  15. $this->kode_cabang = $this->currentUser->kode_cabang;
  16. if($this->cekCurrentUser > 0) {
  17. $this->group = $this->ion_auth->get_users_groups( $this->currentUser->id)->result();
  18. foreach ($this->group as $key => $value) {
  19. $userGroup[$value->name] = $value->description;
  20. $this->data['userGroup'] = $this->userLevel;
  21. }
  22. $this->userLevel = $userGroup;
  23. }
  24. // $this->output->enable_profiler(TRUE);
  25. }
  26. public function index()
  27. {
  28. // Page components
  29. $this->data['pageTitle'] = 'Structure Marketing';
  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 get_hotel_where($where) {
  37. // $query = $this->M_level_marketing->get_where($where);
  38. // return $query;
  39. // }
  40. // public function get_hotel_where_in($where) {
  41. // $query = $this->M_level_marketing->get_where_in($where);
  42. // return $query;
  43. // }
  44. public function load_data()
  45. {
  46. $nm_marketing = $this->input->post('nm_marketing',TRUE);
  47. $level = $this->input->post('level',TRUE);
  48. $nama_atasan = $this->input->post('nama_atasan',TRUE);
  49. $level_atasan = $this->input->post('level_atasan',TRUE);
  50. $nm_cabang = $this->input->post('id_atasan',TRUE);
  51. $active = '1';
  52. $cols = array();
  53. if (!empty($nm_marketing)) { $cols['nm_marketing'] = $nm_marketing; }
  54. if (!empty($level)) { $cols['level'] = $level; }
  55. if (!empty($nama_atasan)) { $cols['nama_atasan'] = $nama_atasan; }
  56. if (!empty($level_atasan)) { $cols['level_atasan'] = $level_atasan; }
  57. if (!empty($nm_cabang)) { $cols['nm_cabang'] = $nm_cabang; }
  58. if(array_key_exists('Super Admin', $this->userLevel)) {
  59. $where = "active = '1'";
  60. } else {
  61. $where = "active = '1' AND kd_cabang = '$this->kode_cabang'";
  62. }
  63. $list = $this->M_level_marketing->get_datatables($where, $cols);
  64. $last_query = $this->db->last_query();
  65. // die(print_r($last_query));
  66. $iTotalRecords = $this->M_level_marketing->count_all($where);
  67. $iDisplayLength = intval($_REQUEST['length']);
  68. $iDisplayLength = $iDisplayLength < 0 ? $iTotalRecords : $iDisplayLength;
  69. $iDisplayStart = intval($_REQUEST['start']);
  70. $sEcho = intval($_REQUEST['draw']);
  71. $records = array();
  72. $records["data"] = array();
  73. $end = $iDisplayStart + $iDisplayLength;
  74. $end = $end > $iTotalRecords ? $iTotalRecords : $end;
  75. $no = $iDisplayStart;
  76. foreach ($list as $r) {
  77. $no++;
  78. $btn_action = '<div class="btn-group btn-group-xs btn-group-solid">
  79. <button type="button" class="btn btn-xs blue btn-outline btn-detail tooltips" data-container="body" data-placement="top" data-original-title="Tooltip in top" data-id="'.$r->id.'"><i class="fa fa-search"></i></button>
  80. <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>
  81. <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>
  82. </div>';
  83. $records["data"][] = array(
  84. $no,
  85. $btn_action,
  86. $r->nm_marketing,
  87. $r->level,
  88. $r->nama_atasan,
  89. $r->level_atasan,
  90. $r->nm_cabang,
  91. );
  92. }
  93. if (isset($_REQUEST["customActionType"]) && $_REQUEST["customActionType"] == "group_action") {
  94. $records["customActionStatus"] = "OK"; // pass custom message(useful for getting status of group actions)
  95. $records["customActionMessage"] = "Group action successfully has been completed. Well done!"; // pass custom message(useful for getting status of group actions)
  96. }
  97. $records["draw"] = $sEcho;
  98. $records["recordsTotal"] = $iTotalRecords;
  99. $records["recordsFiltered"] = $iTotalRecords;
  100. echo json_encode($records);
  101. }
  102. public function load_detail()
  103. {
  104. $id = $this->input->get('id');
  105. $data['dataid'] = $id;
  106. $data['main'] = $this->M_level_marketing->get_where(array('id_marketing' => $id ))->row();
  107. $data['mainatasan'] = $this->db->query('SELECT
  108. tv_level_marketing.nm_marketing,
  109. tv_level_marketing.id_atasan,
  110. tv_level_marketing.id_marketing
  111. FROM
  112. tv_level_marketing
  113. WHERE
  114. tv_level_marketing.id_atasan = "'.$data['main']->id_atasan.'"')->result();
  115. // $this->checkParent($data['main']->id_atasan);
  116. return response($this->load->view('detail', $data, TRUE), 'html');
  117. }
  118. public function checkParent($idParent){
  119. $resultQCP = $this->db->query('SELECT
  120. tv_level_marketing.nm_marketing,
  121. tv_level_marketing.id_atasan,
  122. tv_level_marketing.id_marketing
  123. FROM
  124. tv_level_marketing
  125. WHERE
  126. tv_level_marketing.id_atasan = "'.$idParent.'"')->result();
  127. if(count($resultQCP) > 0){
  128. echo '<ul>';
  129. foreach ($resultQCP as $data) {
  130. echo '<li>';
  131. echo '<a href="#">'.$data->nm_marketing.'</a>';
  132. $this->checkParent($data->id_atasan);
  133. echo '</li>';
  134. }
  135. echo '</ul>';
  136. }
  137. }
  138. public function get($orderBy = 'name')
  139. {
  140. $query = $this->m_groups->get($orderBy);
  141. return $query;
  142. }
  143. public function load_add_form()
  144. {
  145. $data['title'] = 'Add Data Level Marketing';
  146. $data['marketing'] = $this->M_level_marketing->get_marketing(array('active' => '1'))->result();
  147. return response($this->load->view('add_', $data, TRUE), 'html');
  148. }
  149. public function add()
  150. {
  151. $this->ajaxRequest();
  152. $this->validateInput();
  153. $arrmarketing = $this->input->post('id_id_atasan');
  154. foreach($arrmarketing as $val)
  155. {
  156. $marketingarr = @$marketingarr . $val. ",";
  157. }
  158. $data = array(
  159. 'id_marketing' => $this->input->post('id_marketing',TRUE),
  160. 'id_atasan' => $this->input->post('id_atasan',TRUE),
  161. 'id_id_atasan' => substr(trim($marketingarr), 0, -1),
  162. 'active' => '1',
  163. 'id_user' => $this->currentUser->id,
  164. );
  165. $query = $this->M_level_marketing->_insert($data);
  166. // Check if query was success
  167. if ($query) {
  168. $response = array('status' => true, 'action' => 'Success', 'message' => 'Data berhasil ditambahkan');
  169. } else {
  170. $response = array('status' => false, 'action' => 'Failed', 'message' => 'Data gagal ditambahkan');
  171. }
  172. return response($response, 'json');
  173. }
  174. public function load_edit_form()
  175. {
  176. $id = $this->input->get('id');
  177. $data['atasan'] = Modules::run('marketing/get', array('id' => $id))->result();
  178. $data['main'] = $this->M_level_marketing->get_where(array('id' => $id))->row();
  179. $data['marketing'] = $this->M_level_marketing->get_marketing(array('active' => '1'))->result();
  180. $data['lvl_mkt'] = $this->M_level_marketing->get_lvl_where(array('id' => $id ))->row();
  181. // $this->output->enable_profiler(TRUE);
  182. return response($this->load->view('edit_', $data, TRUE), 'html');
  183. }
  184. public function edit()
  185. {
  186. $this->validateInput();
  187. // Preparing the data before update
  188. $id = $this->input->post('id');
  189. $arrmarketing = $this->input->post('id_id_atasan');
  190. foreach($arrmarketing as $val)
  191. {
  192. $marketingarr = @$marketingarr . $val. ",";
  193. }
  194. $data = array(
  195. 'id_marketing' => $this->input->post('id_marketing',TRUE),
  196. 'id_atasan' => $this->input->post('id_atasan',TRUE),
  197. 'id_id_atasan' => substr(trim($marketingarr), 0, -1),
  198. 'user_update' => $this->currentUser->id,
  199. );
  200. $query = $this->M_level_marketing->_update(array('id' => $id), $data);
  201. // Check if query was success
  202. if ($query) {
  203. $results = array('status' => true, 'action' => 'Success', 'message' => 'updated successfully');
  204. } else {
  205. $results = array('status' => false, 'action' => 'Failed', 'message' => 'Failed to update');
  206. }
  207. // Return the result to the view
  208. return response($results);
  209. }
  210. public function delete()
  211. {
  212. $id = $this->input->post('id');
  213. $data = array(
  214. 'active' => '0',
  215. 'user_update' => $this->currentUser->id,
  216. );
  217. // die(print_r($data));
  218. $query = $this->M_level_marketing->_update(array('id' => $id), $data);
  219. // Check if query was success
  220. if ($query) {
  221. $results = array('status' => true, 'action' => 'Success', 'message' => 'berhasil');
  222. } else {
  223. $results = array('status' => false, 'action' => 'Failed', 'message' => 'Gagal');
  224. }
  225. // Return the result to the view
  226. return response($results, 'json');
  227. }
  228. public function validateInput()
  229. {
  230. // Load form validation library
  231. $this->load->library('form_validation');
  232. // Set validation rules
  233. $this->form_validation->set_rules('id_marketing', '', 'trim|required');
  234. $this->form_validation->set_rules('id_atasan', '', 'trim|required');
  235. // Run the validation
  236. if ($this->form_validation->run() === false) {
  237. $response = array(
  238. 'status' => false,
  239. 'action' => 'Failed',
  240. 'message' => $this->form_validation->error_string('<h5>', '</h5>')
  241. );
  242. return response($response, 'json');
  243. }
  244. }
  245. }
  246. ?>