PageRenderTime 62ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/application/modules/movement/controllers/Movement.php

https://bitbucket.org/bo_hmb/bo_hmb
PHP | 377 lines | 255 code | 89 blank | 33 comment | 43 complexity | 5872614f53f604634ae14f02f940b682 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 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'] = 'Itinerary';
  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->load->model('M_movement');
  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. $this->data['userGroup'] = $this->userLevel;
  21. $userGroup[$value->name] = $value->description;
  22. }
  23. $this->userLevel = $userGroup;
  24. }
  25. }
  26. public function schedule()
  27. {
  28. // Page components
  29. $this->data['pageTitle'] = 'Movement';
  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['content'] = $this->load->view('main', $this->data, true);
  35. // Render page
  36. $this->renderPage();
  37. }
  38. public function load_data($id)
  39. {
  40. //$id_jadwal = $this->input->post('id_jadwal',TRUE);
  41. $hari = $this->input->post('hari',TRUE);
  42. $tgl = $this->input->post('tgl',TRUE);
  43. $lokasi = $this->input->post('lokasi',TRUE);
  44. $cols = array();
  45. //if (!empty($id_jadwal)) { $cols['id_jadwal'] = $id_jadwal; }
  46. if (!empty($hari)) { $cols['hari'] = $hari; }
  47. if (!empty($tgl)) { $cols['tgl'] = $tgl; }
  48. if (!empty($lokasi)) { $cols['lokasi'] = $lokasi; }
  49. if(array_key_exists('Super Admin', $this->userLevel)) {
  50. $where = "active = '1' AND id_jadwal = '".$id."'";
  51. } else {
  52. $where = "active = '1' AND id_jadwal = '".$id."'";
  53. }
  54. $list = $this->M_movement->get_datatables($where, $cols);
  55. $last_query = $this->db->last_query();
  56. // die(print_r($last_query));
  57. $iTotalRecords = $this->M_movement->count_all($where);
  58. $iDisplayLength = intval($_REQUEST['length']);
  59. $iDisplayLength = $iDisplayLength < 0 ? $iTotalRecords : $iDisplayLength;
  60. $iDisplayStart = intval($_REQUEST['start']);
  61. $sEcho = intval($_REQUEST['draw']);
  62. $records = array();
  63. $records["data"] = array();
  64. $end = $iDisplayStart + $iDisplayLength;
  65. $end = $end > $iTotalRecords ? $iTotalRecords : $end;
  66. $no = $iDisplayStart;
  67. foreach ($list as $r) {
  68. $no++;
  69. $btn_action = '<div class="btn-group btn-group-xs btn-group-solid">
  70. <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.'"><i class="fa fa-search"></i></button>
  71. <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>
  72. <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>
  73. </div>';
  74. $records["data"][] = array(
  75. $no,
  76. $btn_action,
  77. //$r->id_jadwal,
  78. $r->hari,
  79. $tgl=date('d-m-Y', strtotime($r->tgl)),
  80. $r->lokasi,
  81. );
  82. }
  83. if (isset($_REQUEST["customActionType"]) && $_REQUEST["customActionType"] == "group_action") {
  84. $records["customActionStatus"] = "OK"; // pass custom message(useful for getting status of group actions)
  85. $records["customActionMessage"] = "Group action successfully has been completed. Well done!"; // pass custom message(useful for getting status of group actions)
  86. }
  87. $records["draw"] = $sEcho;
  88. $records["recordsTotal"] = $iTotalRecords;
  89. $records["recordsFiltered"] = $iTotalRecords;
  90. echo json_encode($records);
  91. }
  92. public function load_detail()
  93. {
  94. $id = $this->input->get('id');
  95. $data['main'] = $this->m_barang_order->get_where(array('id' => $id ))->row();
  96. return response($this->load->view('detail', $data, TRUE), 'html');
  97. }
  98. public function load_add_form($id)
  99. {
  100. $data['title'] = 'Tambah Data Barang Beli';
  101. $data['jadwal'] = $id;
  102. return response($this->load->view('add', $data, TRUE), 'html');
  103. }
  104. public function add()
  105. {
  106. $this->ajaxRequest();
  107. $cek = count($this->input->post('tgl'));
  108. for ($i=0; $i < $cek; $i++) {
  109. $h = date('l', strtotime($this->input->post('tgl')[$i]));
  110. if ($h=='Sunday') $hari='Minggu';
  111. else if ($h=='Monday') $hari='Senin';
  112. else if ($h=='Tuesday') $hari='Selasa';
  113. else if ($h=='Wednesday') $hari='Rabu';
  114. else if ($h=='Thursday') $hari='Kamis';
  115. else if ($h=='Friday') $hari='Jumat';
  116. else if ($h=='Saturday') $hari='Sabtu';
  117. $data_order_detail = array(
  118. 'id_jadwal' => $this->input->post('id_jadwal',TRUE),
  119. 'hari' => $hari,
  120. 'tgl' => $this->input->post('tgl',TRUE)[$i],
  121. 'lokasi' => $this->input->post('lokasi',TRUE)[$i],
  122. 'active' => '1',
  123. 'id_user' => $this->currentUser->id,
  124. );
  125. $query = $this->M_movement->_insert($data_order_detail);
  126. }
  127. $query = 'true';
  128. if ($query) {
  129. $response = array('status' => true, 'action' => 'Success', 'message' => 'Data berhasil ditambahkan');
  130. } else {
  131. $response = array('status' => false, 'action' => 'Failed', 'message' => 'Data gagal ditambahkan');
  132. }
  133. return response($response, 'json');
  134. }
  135. public function load_edit_form()
  136. {
  137. $id = $this->input->get('id');
  138. $data['main'] = $this->M_movement->get_where(array('id' => $id))->row();
  139. $data['schedule'] = $this->M_schedule->get()->result();
  140. return response($this->load->view('edit', $data, TRUE), 'html');
  141. }
  142. public function edit()
  143. {
  144. // Check if ajax request
  145. $this->ajaxRequest();
  146. // Validate the submitted data
  147. // Preparing the data before update
  148. $id = $this->input->post('id');
  149. $h = date('l', strtotime($this->input->post('tgl')));
  150. if ($h=='Sunday') $hari='Minggu';
  151. else if ($h=='Monday') $hari='Senin';
  152. else if ($h=='Tuesday') $hari='Selasa';
  153. else if ($h=='Wednesday') $hari='Rabu';
  154. else if ($h=='Thursday') $hari='Kamis';
  155. else if ($h=='Friday') $hari='Jumat';
  156. else if ($h=='Saturday') $hari='Sabtu';
  157. $data = array(
  158. 'id_jadwal' => $this->input->post('id_jadwal',TRUE),
  159. 'hari' => $hari,
  160. 'tgl' => $this->input->post('tgl',TRUE),
  161. 'lokasi' => $this->input->post('lokasi',TRUE),
  162. 'user_update' => $this->currentUser->id,
  163. );
  164. $query = $this->M_movement->_update(array('id' => $id), $data);
  165. // Check if query was success
  166. if ($query) {
  167. $results = array('status' => true, 'action' => 'Success', 'message' => 'updated successfully');
  168. } else {
  169. $results = array('status' => false, 'action' => 'Failed', 'message' => 'Failed to update');
  170. }
  171. // Return the result to the view
  172. return response($results);
  173. }
  174. public function delete()
  175. {
  176. $id = $this->input->post('id');
  177. $data = array(
  178. 'active' => '0',
  179. 'user_update' => $this->currentUser->id,
  180. );
  181. // die(print_r($data));
  182. $query = $this->M_movement->_update(array('id' => $id), $data);
  183. // Check if query was success
  184. if ($query) {
  185. $results = array('status' => true, 'action' => 'Success', 'message' => 'berhasil');
  186. } else {
  187. $results = array('status' => false, 'action' => 'Failed', 'message' => 'Gagal');
  188. }
  189. // Return the result to the view
  190. return response($results, 'json');
  191. }
  192. public function validateInput()
  193. {
  194. // Load form validation library
  195. $this->load->library('form_validation');
  196. // Set validation rules
  197. $this->form_validation->set_rules('no_faktur', 'no faktur', 'trim|required');
  198. $this->form_validation->set_rules('tgl_faktur', 'tgl_faktur', 'trim|required');
  199. $this->form_validation->set_rules('jenis', 'jenis', 'trim|required');
  200. $this->form_validation->set_rules('diterima', 'diterima', 'trim|required');
  201. $this->form_validation->set_rules('total_bayar', 'total_bayar', 'trim|required');
  202. // Run the validation
  203. if ($this->form_validation->run() === false) {
  204. $response = array(
  205. 'status' => false,
  206. 'action' => 'Failed',
  207. 'message' => $this->form_validation->error_string('<h5>', '</h5>')
  208. );
  209. return response($response, 'json');
  210. }
  211. }
  212. public function load_export1()
  213. {
  214. $data['title'] = '';
  215. $data['schedule'] = Modules::run('schedule/get_schedule_where', array('active' => '1'))->result();
  216. return response($this->load->view('export1', $data, TRUE), 'html');
  217. }
  218. public function load_export_date()
  219. {
  220. $data['title'] = '';
  221. //$data['schedule'] = Modules::run('schedule/get_schedule_where', array('active' => '1'))->result();
  222. return response($this->load->view('export_date', $data, TRUE), 'html');
  223. }
  224. public function cetak($id=null)
  225. {
  226. $data = [];
  227. $data['title'] = "Report";
  228. //get data main
  229. $data['main'] = $this->M_movement->get_cetak($id);
  230. $data['detail'] = $this->M_movement->get_detail(array('active' => '1','no_faktur' => $data['main']->no_faktur))->result();
  231. // $html = $this->load->view('welcome_message', $data, true);
  232. $html = $this->load->view('spending/print_view', $data, TRUE);
  233. //this the the PDF filename that user will get to download
  234. $pdfFilePath = "report.pdf";
  235. //mPDF versi 7
  236. $mpdf = new \Mpdf\Mpdf();
  237. $mpdf->WriteHTML($html);
  238. $mpdf->Output();
  239. }
  240. public function export1()
  241. {
  242. $data = [];
  243. $data['title'] = "Report";
  244. //get data main
  245. $id = $this->input->post('id_jadwal');
  246. $data['main'] = $this->M_movement->get_sum_schedule($id);
  247. $data['detail'] = $this->M_movement->get_by_schedule($id);
  248. //$this->load->view('spending/print_export1', $data);
  249. $html = $this->load->view('spending/print_export1', $data, TRUE);
  250. //this the the PDF filename that user will get to download
  251. $pdfFilePath = "report.pdf";
  252. //mPDF versi 7
  253. $mpdf = new \Mpdf\Mpdf();
  254. $mpdf->WriteHTML($html);
  255. $mpdf->Output();
  256. }
  257. public function export_date()
  258. {
  259. $data = [];
  260. $data['title'] = "Report";
  261. //get data main
  262. $data['main'] = $this->M_movement->get_sum_date($this->input->post('date_star'),$this->input->post('date_to'));
  263. $data['detail'] = $this->M_movement->get_by_date($this->input->post('date_star'),$this->input->post('date_to'));
  264. $data['date_star'] = $this->input->post('date_star');
  265. $data['date_to'] = $this->input->post('date_to');
  266. //$this->load->view('spending/print_export1', $data);
  267. $html = $this->load->view('spending/print_export_date', $data, TRUE);
  268. //this the the PDF filename that user will get to download
  269. $pdfFilePath = "report.pdf";
  270. //mPDF versi 7
  271. $mpdf = new \Mpdf\Mpdf();
  272. $mpdf->WriteHTML($html);
  273. $mpdf->Output();
  274. }
  275. public function get_where($where)
  276. {
  277. $query = $this->M_movement->get_where($where);
  278. return $query;
  279. }
  280. public function count_all($where)
  281. {
  282. $query = $this->M_movement->count_all($where);
  283. return $query;
  284. }
  285. }
  286. ?>