PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/application/modules/marketing/controllers/Marketing.php

https://bitbucket.org/bo_hmb/bo_hmb
PHP | 288 lines | 208 code | 61 blank | 19 comment | 19 complexity | a1649d592181ed0d64f3088be3b7ce40 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 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'] = '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_marketing');
  15. $this->load->model('M_level');
  16. $this->load->model('M_workarea');
  17. // $this->output->enable_profiler(TRUE);
  18. if($this->cekCurrentUser > 0) {
  19. $this->group = $this->ion_auth->get_users_groups( $this->currentUser->id)->result();
  20. $this->kode_cabang = $this->currentUser->kode_cabang;
  21. foreach ($this->group as $key => $value) {
  22. $userGroup[$value->name] = $value->description;
  23. }
  24. $this->userLevel = $userGroup;
  25. }
  26. }
  27. public function index()
  28. {
  29. // Page components
  30. // $this->data['userGroup'] = $this->userLevel;
  31. $this->data['pageTitle'] = 'Marketing';
  32. $this->data['pageCss'] = $this->load->view('assets/_pageCss', $this->data, true);;
  33. $this->data['pageJs'] = $this->load->view('assets/_pageJs', $this->data, true);
  34. $this->data['content'] = $this->load->view('main', $this->data, true);
  35. // Render page
  36. $this->renderPage();
  37. }
  38. public function get_marketing_where($where) {
  39. $query = $this->M_marketing->get_marketing_where($where);
  40. return $query;
  41. }
  42. public function load_data()
  43. {
  44. $nik = $this->input->post('nik',TRUE);
  45. $nm_marketing = $this->input->post('nm_marketing',TRUE);
  46. $no_telp = $this->input->post('no_telp',TRUE);
  47. $rekening = $this->input->post('rekening',TRUE);
  48. $nm_cabang = $this->input->post('nm_cabang',TRUE);
  49. $level = $this->input->post('level',TRUE);
  50. $cols = array();
  51. if (!empty($nik)) { $cols['nik'] = $nik; }
  52. if (!empty($nm_marketing)) { $cols['nm_marketing'] = $nm_marketing; }
  53. if (!empty($no_telp)) { $cols['no_telp'] = $no_telp; }
  54. if (!empty($rekening)) { $cols['rekening'] = $rekening; }
  55. if (!empty($kd_cabang)) { $cols['nm_cabang'] = $nm_cabang; }
  56. if (!empty($id_level)) { $cols['level'] = $level; }
  57. if(array_key_exists('Super Admin', $this->userLevel)) {
  58. $where = "marketing.active = '1'";
  59. } else {
  60. $where = "marketing.active = '1' AND marketing.kd_cabang = '$this->kode_cabang'";
  61. }
  62. $list = $this->M_marketing->get_datatables($where, $cols);
  63. $last_query = $this->db->last_query();
  64. // die(print_r($last_query));
  65. $iTotalRecords = $this->M_marketing->count_all($where);
  66. $iDisplayLength = intval($_REQUEST['length']);
  67. $iDisplayLength = $iDisplayLength < 0 ? $iTotalRecords : $iDisplayLength;
  68. $iDisplayStart = intval($_REQUEST['start']);
  69. $sEcho = intval($_REQUEST['draw']);
  70. $records = array();
  71. $records["data"] = array();
  72. $end = $iDisplayStart + $iDisplayLength;
  73. $end = $end > $iTotalRecords ? $iTotalRecords : $end;
  74. $no = $iDisplayStart;
  75. foreach ($list as $r) {
  76. $no++;
  77. $btn_action = '<div class="btn-group btn-group-xs btn-group-solid">
  78. <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>
  79. <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>
  80. </div>';
  81. $records["data"][] = array(
  82. $no,
  83. $btn_action,
  84. $r->nik,
  85. $r->nm_marketing,
  86. $r->no_telp,
  87. $r->rekening,
  88. $r->nm_cabang,
  89. $r->level,
  90. );
  91. }
  92. if (isset($_REQUEST["customActionType"]) && $_REQUEST["customActionType"] == "group_action") {
  93. $records["customActionStatus"] = "OK"; // pass custom message(useful for getting status of group actions)
  94. $records["customActionMessage"] = "Group action successfully has been completed. Well done!"; // pass custom message(useful for getting status of group actions)
  95. }
  96. $records["draw"] = $sEcho;
  97. $records["recordsTotal"] = $iTotalRecords;
  98. $records["recordsFiltered"] = $iTotalRecords;
  99. echo json_encode($records);
  100. }
  101. public function load_detail()
  102. {
  103. $id = $this->input->get('id');
  104. $data['main'] = $this->m_customer->get_where(array('id' => $id ))->row();
  105. return response($this->load->view('detail', $data, TRUE), 'html');
  106. }
  107. public function load_add_form()
  108. {
  109. $data['title'] = 'Add Data Marketing';
  110. $data['level'] = $this->M_level->get()->result();
  111. $data['workarea'] = $this->M_workarea->get()->result();
  112. $data['marketing'] = $this->M_marketing->get_marketing_where(array('active' => '1'))->result();
  113. return response($this->load->view('add_', $data, TRUE), 'html');
  114. }
  115. public function add()
  116. {
  117. $this->ajaxRequest();
  118. $cek = $this->M_marketing->get_marketing_where(array('kd_cabang'=>$this->input->post('kd_cabang')))->num_rows();
  119. $id_marketing = $this->input->post('kd_cabang').'-'.sprintf('%04d',$cek+1);
  120. $data = array(
  121. 'nik' => $id_marketing,
  122. 'nm_marketing' => $this->input->post('nm_marketing',TRUE),
  123. 'kd_cabang' => $this->input->post('kd_cabang',TRUE),
  124. 'id_level' => $this->input->post('id_level',TRUE),
  125. 'no_telp' => $this->input->post('no_telp',TRUE),
  126. 'rekening' => $this->input->post('rekening',TRUE),
  127. 'active' => '1',
  128. 'id_user' => $this->currentUser->id,
  129. );
  130. $query = $this->M_marketing->_insert($data);
  131. $id_marketing = $this->db->insert_id();
  132. $dataLevel = array(
  133. 'id_marketing' => $id_marketing,
  134. 'id_atasan' => $this->input->post('id_atasan',TRUE),
  135. 'id_id_atasan' => $this->input->post('id_atasan',TRUE),
  136. 'active' => '1',
  137. 'id_user' => $this->currentUser->id,
  138. );
  139. $queryLevel = $this->M_marketing->_insert_level($dataLevel);
  140. // Check if query was success
  141. if ($query) {
  142. $response = array('status' => true, 'action' => 'Success', 'message' => 'Data berhasil ditambahkan');
  143. } else {
  144. $response = array('status' => false, 'action' => 'Failed', 'message' => 'Data gagal ditambahkan');
  145. }
  146. return response($response, 'json');
  147. }
  148. public function load_edit_form()
  149. {
  150. $id = $this->input->get('id');
  151. $data['main'] = $this->M_marketing->get_where(array('marketing.id' => $id))->row();
  152. $data['marketing'] = $this->M_marketing->get_marketing_where(array('active' => '1'))->result();
  153. $data['level'] = $this->M_level->get()->result();
  154. $data['workarea'] = $this->M_workarea->get()->result();
  155. return response($this->load->view('edit_', $data, TRUE), 'html');
  156. }
  157. public function edit()
  158. {
  159. // Check if ajax request
  160. // Validate the submitted data
  161. $this->validateInput();
  162. // Preparing the data before update
  163. $id = $this->input->post('id');
  164. $data = array(
  165. // 'nik' => $this->input->post('nik',TRUE),
  166. 'nm_marketing' => $this->input->post('nm_marketing',TRUE),
  167. 'kd_cabang' => $this->input->post('kd_cabang',TRUE),
  168. 'id_level' => $this->input->post('id_level',TRUE),
  169. 'no_telp' => $this->input->post('no_telp',TRUE),
  170. 'rekening' => $this->input->post('rekening',TRUE),
  171. 'user_update' => $this->currentUser->id,
  172. );
  173. $query = $this->M_marketing->_update(array('id' => $id), $data);
  174. // Check if query was success
  175. if ($query) {
  176. $results = array('status' => true, 'action' => 'Success', 'message' => 'updated successfully');
  177. } else {
  178. $results = array('status' => false, 'action' => 'Failed', 'message' => 'Failed to update');
  179. }
  180. // Return the result to the view
  181. return response($results);
  182. }
  183. public function delete()
  184. {
  185. $id = $this->input->post('id');
  186. $data = array(
  187. 'active' => '0',
  188. 'user_update' => $this->currentUser->id,
  189. );
  190. // die(print_r($data));
  191. $query = $this->M_marketing->_update(array('id' => $id), $data);
  192. // Check if query was success
  193. if ($query) {
  194. $results = array('status' => true, 'action' => 'Success', 'message' => 'berhasil');
  195. } else {
  196. $results = array('status' => false, 'action' => 'Failed', 'message' => 'Gagal');
  197. }
  198. // Return the result to the view
  199. return response($results, 'json');
  200. }
  201. public function validateInput()
  202. {
  203. // Load form validation library
  204. $this->load->library('form_validation');
  205. // Set validation rules
  206. $this->form_validation->set_rules('nik', 'nik', 'trim|required');
  207. $this->form_validation->set_rules('nm_marketing', 'nm marketing', 'trim|required');
  208. $this->form_validation->set_rules('no_telp', 'no telp', 'trim|required');
  209. $this->form_validation->set_rules('rekening', 'rekeningg', 'trim|required');
  210. $this->form_validation->set_rules('kd_cabang', 'kd cabang', 'trim|required');
  211. $this->form_validation->set_rules('id_level', 'id tingkatan', 'trim|required');
  212. // Run the validation
  213. if ($this->form_validation->run() === false) {
  214. $response = array(
  215. 'status' => false,
  216. 'action' => 'Failed',
  217. 'message' => $this->form_validation->error_string('<h5>', '</h5>')
  218. );
  219. return response($response, 'json');
  220. }
  221. }
  222. public function get($where) {
  223. $query=$this->M_marketing->get($where);
  224. return $query;
  225. }
  226. }
  227. ?>