PageRenderTime 49ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/application/modules/group_manivest/controllers/Group_manivest.php

https://bitbucket.org/bo_hmb/bo_hmb
PHP | 332 lines | 243 code | 63 blank | 26 comment | 24 complexity | e7bde54b4c0552e9540b4a905c44cff0 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 Group_manivest 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'] = 'Group Manifest';
  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_group_manivest');
  15. $this->load->model('M_schedule');
  16. // $this->output->enable_profiler(TRUE);
  17. if($this->cekCurrentUser > 0) {
  18. $this->group = $this->ion_auth->get_users_groups( $this->currentUser->id)->result();
  19. foreach ($this->group as $key => $value) {
  20. $userGroup[$value->name] = $value->description;
  21. }
  22. $this->userLevel = $userGroup;
  23. }
  24. }
  25. public function schedule()
  26. {
  27. // Page components
  28. $this->data['userGroup'] = $this->userLevel;
  29. $this->data['pageTitle'] = 'Group_manivest';
  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['id_data'] = $this->uri->segment(3);
  33. $this->data['jadwal'] = $this->M_schedule->get_where(array('id' => $this->uri->segment(3)))->row();
  34. $this->data['cek'] = count($this->M_group_manivest->get_where(array('id_jadwal' => $this->uri->segment(3)))->result());
  35. $this->data['content'] = $this->load->view('main', $this->data, true);
  36. // Render page
  37. $this->renderPage();
  38. }
  39. public function load_data($id)
  40. {
  41. //$id_jadwal = $this->input->post('id_jadwal',TRUE);
  42. $group_code = $this->input->post('group_code',TRUE);
  43. $brach = $this->input->post('brach',TRUE);
  44. $brach_code = $this->input->post('brach_code',TRUE);
  45. $total_pax = $this->input->post('total_pax',TRUE);
  46. $personn_incharge = $this->input->post('personn_incharge',TRUE);
  47. $dep_date = $this->input->post('dep_date',TRUE);
  48. $return_date = $this->input->post('return_date',TRUE);
  49. $carrier = $this->input->post('carrier',TRUE);
  50. $pnr = $this->input->post('pnr',TRUE);
  51. $flight_detail = $this->input->post('flight_detail',TRUE);
  52. $bus = $this->input->post('bus',TRUE);
  53. $cols = array();
  54. //if (!empty($id_jadwal)) { $cols['id_jadwal'] = $id_jadwal; }
  55. if (!empty($group_code)) { $cols['group_code'] = $group_code; }
  56. if (!empty($brach)) { $cols['brach'] = $brach; }
  57. if (!empty($brach_code)) { $cols['brach_code'] = $brach_code; }
  58. if (!empty($total_pax)) { $cols['total_pax'] = $total_pax; }
  59. if (!empty($personn_incharge)) { $cols['personn_incharge'] = $personn_incharge; }
  60. if (!empty($dep_date)) { $cols['dep_date'] = $dep_date; }
  61. if (!empty($return_date)) { $cols['return_date'] = $return_date; }
  62. if (!empty($carrier)) { $cols['carrier'] = $carrier; }
  63. if (!empty($pnr)) { $cols['pnr'] = $pnr; }
  64. if (!empty($flight_detail)) { $cols['flight_detail'] = $flight_detail; }
  65. if (!empty($bus)) { $cols['bus'] = $bus; }
  66. if(array_key_exists('Super Admin', $this->userLevel)) {
  67. $where = "active = '1' AND group_manivest.id_jadwal = '".$id."'";
  68. } else {
  69. $where = "active = '1' AND group_manivest.id_jadwal = '".$id."'";
  70. }
  71. $list = $this->M_group_manivest->get_datatables($where, $cols);
  72. $last_query = $this->db->last_query();
  73. // die(print_r($last_query));
  74. $iTotalRecords = $this->M_group_manivest->count_all($where);
  75. $iDisplayLength = intval($_REQUEST['length']);
  76. $iDisplayLength = $iDisplayLength < 0 ? $iTotalRecords : $iDisplayLength;
  77. $iDisplayStart = intval($_REQUEST['start']);
  78. $sEcho = intval($_REQUEST['draw']);
  79. $records = array();
  80. $records["data"] = array();
  81. $end = $iDisplayStart + $iDisplayLength;
  82. $end = $end > $iTotalRecords ? $iTotalRecords : $end;
  83. $no = $iDisplayStart;
  84. foreach ($list as $r) {
  85. $no++;
  86. $btn_action = '<div class="btn-group btn-group-xs btn-group-solid">
  87. <button type="button" class="btn btn-xs blue btn-outline btn-agenda tooltips" data-container="body" data-placement="top" data-original-title="Tooltip in top" data-id="'.$r->id_jadwal.'"><i class="fa fa-search"></i></button>
  88. <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>
  89. <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>
  90. </div>';
  91. $records["data"][] = array(
  92. $no,
  93. $btn_action,
  94. $r->group_code,
  95. $r->brach,
  96. $r->brach_code,
  97. $r->total_pax,
  98. $r->personn_incharge,
  99. $d=date('d-m-Y', strtotime($r->dep_date)),
  100. $e=date('d-m-Y', strtotime($r->return_date)),
  101. $r->carrier,
  102. $r->pnr,
  103. $r->flight_detail,
  104. $r->bus,
  105. );
  106. }
  107. if (isset($_REQUEST["customActionType"]) && $_REQUEST["customActionType"] == "group_action") {
  108. $records["customActionStatus"] = "OK"; // pass custom message(useful for getting status of group actions)
  109. $records["customActionMessage"] = "Group action successfully has been completed. Well done!"; // pass custom message(useful for getting status of group actions)
  110. }
  111. $records["draw"] = $sEcho;
  112. $records["recordsTotal"] = $iTotalRecords;
  113. $records["recordsFiltered"] = $iTotalRecords;
  114. echo json_encode($records);
  115. }
  116. public function load_detail()
  117. {
  118. $id = $this->input->get('id');
  119. $data['main'] = $this->m_customer->get_where(array('id' => $id ))->row();
  120. return response($this->load->view('detail', $data, TRUE), 'html');
  121. }
  122. public function load_add_form($id)
  123. {
  124. $data['id_jadwal'] = $id;
  125. $data['main'] = $this->M_schedule->get_where(array('id' => $id ))->row();
  126. return response($this->load->view('add_', $data, TRUE), 'html');
  127. }
  128. public function add()
  129. {
  130. // $this->validateInput();
  131. $data = array(
  132. 'id_jadwal' => $this->input->post('id_jadwal',TRUE),
  133. 'group_code' => $this->input->post('group_code',TRUE),
  134. 'brach' => $this->input->post('brach',TRUE),
  135. 'brach_code' => $this->input->post('brach_code',TRUE),
  136. 'total_pax' => $this->input->post('total_pax',TRUE),
  137. 'personn_incharge' => $this->input->post('personn_incharge',TRUE),
  138. 'dep_date' => $this->input->post('dep_date',TRUE),
  139. 'return_date' => $this->input->post('return_date',TRUE),
  140. 'carrier' => $this->input->post('carrier',TRUE),
  141. 'pnr' => $this->input->post('pnr',TRUE),
  142. 'flight_detail' => $this->input->post('flight_detail',TRUE),
  143. 'bus' => $this->input->post('bus',TRUE),
  144. 'active' => '1',
  145. 'id_user' => $this->currentUser->id,
  146. );
  147. $query = $this->M_group_manivest->_insert($data);
  148. // Check if query was success
  149. if ($query) {
  150. $response = array('status' => true, 'action' => 'Success', 'message' => 'Data berhasil ditambahkan');
  151. } else {
  152. $response = array('status' => false, 'action' => 'Failed', 'message' => 'Data gagal ditambahkan');
  153. }
  154. return response($response, 'json');
  155. }
  156. public function load_edit_form()
  157. {
  158. $id = $this->input->get('id');
  159. $data['main'] = $this->M_group_manivest->get_where(array('id' => $id))->row();
  160. $data['schedule'] = $this->M_schedule->get()->result();
  161. return response($this->load->view('edit_', $data, TRUE), 'html');
  162. }
  163. public function edit()
  164. {
  165. // Check if ajax request
  166. $this->ajaxRequest();
  167. // Validate the submitted data
  168. $this->validateInput();
  169. // Preparing the data before update
  170. $id = $this->input->post('id');
  171. $data = array(
  172. 'group_code' => $this->input->post('group_code',TRUE),
  173. 'brach' => $this->input->post('brach',TRUE),
  174. 'brach_code' => $this->input->post('brach_code',TRUE),
  175. 'total_pax' => $this->input->post('total_pax',TRUE),
  176. 'personn_incharge' => $this->input->post('personn_incharge',TRUE),
  177. 'dep_date' => $this->input->post('dep_date',TRUE),
  178. 'return_date' => $this->input->post('return_date',TRUE),
  179. 'carrier' => $this->input->post('carrier',TRUE),
  180. 'pnr' => $this->input->post('pnr',TRUE),
  181. 'flight_detail' => $this->input->post('flight_detail',TRUE),
  182. 'bus' => $this->input->post('bus',TRUE),
  183. 'user_update' => $this->currentUser->id,
  184. );
  185. $query = $this->M_group_manivest->_update(array('id' => $id), $data);
  186. // Check if query was success
  187. if ($query) {
  188. $results = array('status' => true, 'action' => 'Success', 'message' => 'updated successfully');
  189. } else {
  190. $results = array('status' => false, 'action' => 'Failed', 'message' => 'Failed to update');
  191. }
  192. // Return the result to the view
  193. return response($results);
  194. }
  195. public function delete()
  196. {
  197. $id = $this->input->post('id');
  198. $data = array(
  199. 'active' => '0',
  200. 'user_update' => $this->currentUser->id,
  201. );
  202. // die(print_r($data));
  203. $query = $this->M_group_manivest->_update(array('id' => $id), $data);
  204. // Check if query was success
  205. if ($query) {
  206. $results = array('status' => true, 'action' => 'Success', 'message' => 'berhasil');
  207. } else {
  208. $results = array('status' => false, 'action' => 'Failed', 'message' => 'Gagal');
  209. }
  210. // Return the result to the view
  211. return response($results, 'json');
  212. }
  213. public function validateInput()
  214. {
  215. // Load form validation library
  216. $this->load->library('form_validation');
  217. $this->form_validation->set_rules('group_code', 'group code', 'trim|required');
  218. $this->form_validation->set_rules('brach', 'brach', 'trim|required');
  219. // Run the validation
  220. if ($this->form_validation->run() === false) {
  221. $response = array(
  222. 'status' => false,
  223. 'action' => 'Failed',
  224. 'message' => $this->form_validation->error_string('<h5>', '</h5>')
  225. );
  226. return response($response, 'json');
  227. }
  228. }
  229. public function export_pdf($id=null)
  230. {
  231. $data = [];
  232. $data['title'] = "Report";
  233. //get data main
  234. $data['main'] = $this->M_schedule->get_where(array('id' => $id))->row();
  235. $data ['master'] = $this->M_schedule->get_where_group_manivest($id);
  236. $data ['detail'] = $this->M_schedule->get_where_detail_group_manivest($id);
  237. // $html = $this->load->view('welcome_message', $data, true);
  238. $html = $this->load->view('group_manivest/print_view', $data, TRUE);
  239. //this the the PDF filename that user will get to download
  240. $pdfFilePath = "GM.pdf";
  241. //mPDF versi 7
  242. $mpdf = new \Mpdf\Mpdf([
  243. 'mode' => 'utf-8',
  244. 'format' => 'Legal-L',
  245. 'orientation' => 'L'
  246. ]);
  247. $mpdf->WriteHTML($html);
  248. $mpdf->Output();
  249. }
  250. public function export_excel($id)
  251. {
  252. $data['main'] = $this->M_schedule->get_where(array('id' => $id))->row();
  253. $data ['master'] = $this->M_schedule->get_where_group_manivest($id);
  254. $data ['detail'] = $this->M_schedule->get_where_detail_group_manivest($id);
  255. // $html = $this->load->view('welcome_message', $data, true);
  256. $this->load->view('group_manivest/print_view_excel', $data);
  257. }
  258. public function export_excel_sv($id)
  259. {
  260. $data['main'] = $this->M_schedule->get_where(array('id' => $id))->row();
  261. $data ['master'] = $this->M_schedule->get_where_group_manivest($id);
  262. $data ['detail'] = $this->M_schedule->get_where_detail_group_manivest2($id);
  263. // $html = $this->load->view('welcome_message', $data, true);
  264. $this->load->view('group_manivest/print_view_excel_2', $data);
  265. }
  266. }
  267. ?>