PageRenderTime 25ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/application/modules/schedule_group_movement/controllers/Schedule_group_movement.php

https://bitbucket.org/bo_hmb/bo_hmb
PHP | 291 lines | 197 code | 68 blank | 26 comment | 16 complexity | ae0574f9b62ae2891dd85cae8207a64b 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 Schedule_group_movement 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'] = 'Schedule Group Movement';
  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_schedule');
  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. // $this->userLevel = $userGroup;
  20. foreach ($this->group as $key => $value) {
  21. $userGroup[$value->name] = $value->description;
  22. }
  23. $this->userLevel = $userGroup;
  24. }
  25. }
  26. public function index()
  27. {
  28. // Page components
  29. // $this->data['userGroup'] = $this->userLevel;
  30. $this->data['pageTitle'] = 'Schedule Group Movement';
  31. $this->data['pageCss'] = $this->load->view('assets/_pageCss', $this->data, true);;
  32. $this->data['pageJs'] = $this->load->view('assets/_pageJs', $this->data, true);
  33. $this->data['content'] = $this->load->view('main', $this->data, true);
  34. // Render page
  35. $this->renderPage();
  36. }
  37. public function load_data()
  38. {
  39. $nm_jadwal = $this->input->post('nm_jadwal',TRUE);
  40. $tgl_keberangkatan = $this->input->post('tgl_keberangkatan',TRUE);
  41. $tgl_kepulangan = $this->input->post('tgl_kepulangan',TRUE);
  42. $cols = array();
  43. if (!empty($nm_jadwal)) { $cols['nm_jadwal'] = $nm_jadwal; }
  44. if (!empty($tgl_keberangkatan)) { $cols['tgl_keberangkatan'] = $tgl_keberangkatan; }
  45. if (!empty($tgl_kepulangan)) { $cols['tgl_kepulangan'] = $tgl_kepulangan; }
  46. if(array_key_exists('Super Admin', $this->userLevel)) {
  47. $where = "active = '1'";
  48. } else {
  49. $where = "active = '1'";
  50. }
  51. $list = $this->M_schedule->get_datatables($where, $cols);
  52. $last_query = $this->db->last_query();
  53. // die(print_r($last_query));
  54. $iTotalRecords = $this->M_schedule->count_all($where);
  55. $iDisplayLength = intval($_REQUEST['length']);
  56. $iDisplayLength = $iDisplayLength < 0 ? $iTotalRecords : $iDisplayLength;
  57. $iDisplayStart = intval($_REQUEST['start']);
  58. $sEcho = intval($_REQUEST['draw']);
  59. $records = array();
  60. $records["data"] = array();
  61. $end = $iDisplayStart + $iDisplayLength;
  62. $end = $end > $iTotalRecords ? $iTotalRecords : $end;
  63. $no = $iDisplayStart;
  64. foreach ($list as $r) {
  65. $no++;
  66. $btn_action = '<div class="btn-group btn-group-xs btn-group-solid">
  67. <button type="button" class="btn btn-xs blue 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-search"></i></button>
  68. <a type="button" class="btn btn-xs btn-outline red tooltips" data-container="body" data-placement="top" data-original-title="Tooltip in top" href="'.base_url().'schedule_group_movement/cetak/'.$r->id.'" target="_blank"><i class="fa fa-file-pdf-o"></i></a>
  69. <a type="button" class="btn btn-xs btn-outline green tooltips" data-container="body" data-placement="top" data-original-title="Tooltip in top" href="'.base_url().'schedule_group_movement/cetak_excel/'.$r->id.'" target="_blank"><i class="fa fa-file-excel-o"></i></a>
  70. </div>';
  71. // selisih hari data-id="'.$r->id.'"
  72. // $lama_hari = ((abs(strtotime($r->tgl_kepulangan) - strtotime($r->tgl_keberangkatan)))/(60*60*24));
  73. $records["data"][] = array(
  74. $no,
  75. $btn_action,
  76. $r->nm_jadwal,
  77. $x=date('d-m-Y', strtotime($r->tgl_keberangkatan)),
  78. $x=date('d-m-Y', strtotime($r->tgl_kepulangan)),
  79. );
  80. }
  81. if (isset($_REQUEST["customActionType"]) && $_REQUEST["customActionType"] == "group_action") {
  82. $records["customActionStatus"] = "OK"; // pass custom message(useful for getting status of group actions)
  83. $records["customActionMessage"] = "Group action successfully has been completed. Well done!"; // pass custom message(useful for getting status of group actions)
  84. }
  85. $records["draw"] = $sEcho;
  86. $records["recordsTotal"] = $iTotalRecords;
  87. $records["recordsFiltered"] = $iTotalRecords;
  88. echo json_encode($records);
  89. }
  90. public function load_detail()
  91. {
  92. $id = $this->input->get('id');
  93. $data['main'] = $this->m_customer->get_where(array('id' => $id ))->row();
  94. return response($this->load->view('detail', $data, TRUE), 'html');
  95. }
  96. public function load_add_form()
  97. {
  98. $data['title'] = 'Tambah Data Hotel';
  99. $data['schedule'] = $this->M_schedule->get()->result();
  100. return response($this->load->view('add_', $data, TRUE), 'html');
  101. }
  102. public function add()
  103. {
  104. $this->validateInput();
  105. $data = array(
  106. 'id_jadwal' => $this->input->post('id_jadwal',TRUE),
  107. 'hari' => $this->input->post('hari',TRUE),
  108. 'tgl' => $this->input->post('tgl',TRUE),
  109. 'lokasi' => $this->input->post('lokasi',TRUE),
  110. 'active' => '1',
  111. 'id_user' => $this->currentUser->id,
  112. );
  113. $query = $this->M_movement->_insert($data);
  114. // Check if query was success
  115. if ($query) {
  116. $response = array('status' => true, 'action' => 'Success', 'message' => 'Data berhasil ditambahkan');
  117. } else {
  118. $response = array('status' => false, 'action' => 'Failed', 'message' => 'Data gagal ditambahkan');
  119. }
  120. return response($response, 'json');
  121. }
  122. public function load_edit_form()
  123. {
  124. $id = $this->input->get('id');
  125. $data['main'] = $this->M_movement->get_where(array('id' => $id))->row();
  126. $data['schedule'] = $this->M_schedule->get()->result();
  127. return response($this->load->view('edit_', $data, TRUE), 'html');
  128. }
  129. public function edit()
  130. {
  131. // Check if ajax request
  132. $this->ajaxRequest();
  133. // Validate the submitted data
  134. $this->validateInput();
  135. // Preparing the data before update
  136. $id = $this->input->post('id');
  137. $data = array(
  138. 'id_jadwal' => $this->input->post('id_jadwal',TRUE),
  139. 'hari' => $this->input->post('hari',TRUE),
  140. 'tgl' => $this->input->post('tgl',TRUE),
  141. 'lokasi' => $this->input->post('lokasi',TRUE),
  142. );
  143. $query = $this->M_movement->_update(array('id' => $id), $data);
  144. // Check if query was success
  145. if ($query) {
  146. $results = array('status' => true, 'action' => 'Success', 'message' => 'updated successfully');
  147. } else {
  148. $results = array('status' => false, 'action' => 'Failed', 'message' => 'Failed to update');
  149. }
  150. // Return the result to the view
  151. return response($results);
  152. }
  153. public function delete()
  154. {
  155. $id = $this->input->post('id');
  156. $data = array(
  157. 'active' => '0',
  158. );
  159. // die(print_r($data));
  160. $query = $this->M_movement->_update(array('id' => $id), $data);
  161. // Check if query was success
  162. if ($query) {
  163. $results = array('status' => true, 'action' => 'Success', 'message' => 'berhasil');
  164. } else {
  165. $results = array('status' => false, 'action' => 'Failed', 'message' => 'Gagal');
  166. }
  167. // Return the result to the view
  168. return response($results, 'json');
  169. }
  170. public function validateInput()
  171. {
  172. // Load form validation library
  173. $this->load->library('form_validation');
  174. // Set validation rules
  175. $this->form_validation->set_rules('id_jadwal', '', 'trim|required');
  176. $this->form_validation->set_rules('hari', '', 'trim|required');
  177. $this->form_validation->set_rules('tgl', 'tgl', 'trim|required');
  178. $this->form_validation->set_rules('lokasi', '', 'trim|required');
  179. // Run the validation
  180. if ($this->form_validation->run() === false) {
  181. $response = array(
  182. 'status' => false,
  183. 'action' => 'Failed',
  184. 'message' => $this->form_validation->error_string('<h5>', '</h5>')
  185. );
  186. return response($response, 'json');
  187. }
  188. }
  189. public function cetak($id=null)
  190. {
  191. $data = [];
  192. $data['title'] = "Report";
  193. //get data main
  194. $data['main'] = $this->M_schedule->get_where(array('id' => $id))->row();
  195. $data['master'] = $this->M_schedule->get_where_group_movement(array('id_jadwal' => $id))->row();
  196. $data['detail'] = $this->M_schedule->get_where_group_movement_det(array('id_gorup_movement' => $data['master']->id))->result();
  197. $data['hotel_makkah'] = $this->M_schedule->hotel($data['master']->id_hotel_makkah);
  198. $data['hotel_madinah'] = $this->M_schedule->hotel($data['master']->id_hotel_madinah);
  199. // $html = $this->load->view('welcome_message', $data, true);
  200. $html = $this->load->view('schedule_group_movement/print_view', $data, TRUE);
  201. //this the the PDF filename that user will get to download
  202. $pdfFilePath = "GM.pdf";
  203. //mPDF versi 7
  204. $mpdf = new \Mpdf\Mpdf([
  205. 'mode' => 'utf-8',
  206. 'format' => 'Legal-L',
  207. 'orientation' => 'L'
  208. ]);
  209. $mpdf->WriteHTML($html);
  210. $mpdf->Output();
  211. }
  212. public function cetak_excel($id=null)
  213. {
  214. $data['main'] = $this->M_schedule->get_where(array('id' => $id))->row();
  215. $data['master'] = $this->M_schedule->get_where_group_movement(array('id_jadwal' => $id))->row();
  216. $data['detail'] = $this->M_schedule->get_where_group_movement_det(array('id_gorup_movement' => 7))->result();
  217. $data['hotel_makkah'] = $this->M_schedule->hotel($data['master']->id_hotel_makkah);
  218. $data['hotel_madinah'] = $this->M_schedule->hotel($data['master']->id_hotel_madinah);
  219. // $html = $this->load->view('welcome_message', $data, true);
  220. $this->load->view('schedule_group_movement/print_view_excel', $data);
  221. }
  222. }
  223. ?>