Advertisement
Guest User

Administrator.php

a guest
Aug 14th, 2017
438
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 36.22 KB | None | 0 0
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2.  
  3. class Administrator extends CI_Controller
  4. {
  5. public function __construct ()
  6. {
  7. parent::__construct();
  8. //Codeigniter : Write Less Do More
  9. $this->is_logged_in();
  10. $this->load->library(array('upload'));
  11. }
  12.  
  13. public function is_logged_in ()
  14. {
  15. $sess = $this->session->userdata('logged_in');
  16. $level = $this->session->userdata('level');
  17. if ($sess != true || $level != 'admin') {
  18. $this->session->set_flashdata('not_login', 'Anda harus login!');
  19. redirect('welcome/form_login');
  20. }
  21. }
  22.  
  23. public function dashboard ()
  24. {
  25. $data['title'] = 'Admin Pages';
  26. $this->load->view('admin/v_home', $data);
  27. }
  28.  
  29. // manajemen meja
  30. public function meja ()
  31. {
  32. $getmeja = $this->crud_model->get_db('meja');
  33.  
  34. if ($getmeja->num_rows() > 0) {
  35. $data['data'] = $getmeja;
  36. }
  37.  
  38. $data['title'] = 'Admin Pages';
  39. $this->load->view('admin/v_data_meja', $data);
  40. }
  41.  
  42. public function add_meja ()
  43. {
  44. $no_max = $this->crud_model->getNoMax('meja', 'nomor_meja');
  45. if ($no_max->num_rows() > 0) {
  46. foreach ($no_max->result() as $key) {
  47. $data['nomor_meja'] = $key->nomor_meja;
  48. }
  49. }
  50. $data['title'] = 'Admin Pages';
  51. $this->load->view('admin/v_form_add_meja', $data);
  52. }
  53.  
  54. public function validation_add_table ()
  55. {
  56. // validation
  57. $config = array(
  58. // username
  59. array(
  60. 'field' => 'nomor_table',
  61. 'label' => 'Nomor',
  62. 'rules' => 'trim|required'
  63. ),
  64. array(
  65. 'field' => 'kapasitas',
  66. 'label' => 'Kapasitas Kursi',
  67. 'rules' => 'trim|required|max_length[2]'
  68. )
  69. );
  70. $this->form_validation->set_rules($config);
  71.  
  72. if ($this->form_validation->run() == false) {
  73. $this->add_meja();
  74. } else {
  75. // ambil value form
  76. $data = array(
  77. 'nomor_meja' => $this->input->post('nomor_table'),
  78. 'kapasitas' => $this->input->post('kapasitas')
  79. );
  80. $insert = $this->crud_model->insert_db('meja', $data);
  81. if ($insert) {
  82. // flash success
  83. $this->session->set_flashdata('successfull', 'Tambah Data Berhasil!');
  84. redirect('pages/administrator/meja');
  85. }
  86. }
  87. }
  88.  
  89. public function edit_meja ($id)
  90. {
  91. $model = $this->crud_model->get_update('meja', array('nomor_meja' => $id), 1);
  92. if ($model->num_rows() > 0) {
  93. foreach ($model->result() as $key) {
  94. $data['result'] = $key;
  95. }
  96. }
  97. $data['title'] = 'Pages Admin';
  98. $this->load->view('admin/v_edit_meja', $data);
  99. }
  100.  
  101. // edit meja
  102. public function validation_edit_table ()
  103. {
  104. // validation
  105. $config = array(
  106. // username
  107. array(
  108. 'field' => 'nomor_meja',
  109. 'label' => 'Nomor Meja',
  110. 'rules' => 'trim|required'
  111. ),
  112. array(
  113. 'field' => 'kapasitas',
  114. 'label' => 'Kapasitas Kursi',
  115. 'rules' => 'trim|required|max_length[2]'
  116. )
  117. );
  118. $this->form_validation->set_rules($config);
  119.  
  120. $id = $this->input->post('nmr_meja');
  121.  
  122. if ($this->form_validation->run() == false) {
  123. $this->edit_meja($id);
  124. } else {
  125. // lolos validasi
  126. $data = array(
  127. 'nomor_meja' => $this->input->post('nomor_meja'),
  128. 'kapasitas' => $this->input->post('kapasitas')
  129. );
  130. $where = array('nomor_meja' => $id);
  131.  
  132. // update ke database
  133. $update = $this->crud_model->set_update('meja', $data, $where);
  134.  
  135. if ($update) {
  136. $this->session->set_flashdata('successfull', 'Update Data Berhasil');
  137. redirect('pages/administrator/meja');
  138. }
  139. }
  140. }
  141.  
  142. public function delete_meja ($id)
  143. {
  144. $delete = $this->crud_model->delete('meja', array('nomor_meja' => $id));
  145.  
  146. if ($delete) {
  147. $this->session->set_flashdata('successfull', 'Data berhasil di hapus!');
  148. redirect('pages/administrator/meja');
  149. }
  150. }
  151.  
  152. // manajemen menu
  153. public function menu ($data = array())
  154. {
  155. $getmenu = $this->crud_model->get_db('menu');
  156.  
  157. if ($getmenu->num_rows() > 0) {
  158. $data['data'] = $getmenu;
  159. }
  160.  
  161. $data['title'] = 'Admin Pages';
  162. $this->load->view('admin/v_data_menu', $data);
  163. }
  164.  
  165. public function add_menu ()
  166. {
  167. // ambil nomor id menu terakhir
  168. $no_max = $this->crud_model->getNoMax('menu', 'id_menu');
  169. foreach ($no_max->result() as $key => $value) {
  170. if ($value->id_menu != null) {
  171. $id = substr($value->id_menu, 2, 2);
  172. $id++;
  173. if ($id < 10) {
  174. $kode = 'NU0' . $id;
  175. } else {
  176. $kode = 'NU' . $id;
  177. }
  178. $data['last_id'] = $kode;
  179. } else {
  180. $data['last_id'] = "NU01";
  181. }
  182. }
  183.  
  184. $data['title'] = 'Admin Pages';
  185. $this->load->view('admin/v_form_add_menu', $data);
  186. }
  187.  
  188. public function do_upload ()
  189. {
  190. // mengambil ekstensi file
  191. $ext = pathinfo($_FILES['upload_menu']['name']);
  192. $ext = $ext['extension'];
  193.  
  194. // sett conf upload image
  195. $filename = 'menu_' . time();
  196. $conf_upload = array(
  197. 'upload_path' => 'assets/upload/images_menu/',
  198. 'allowed_types' => 'jpg|png',
  199. 'max_size' => 2048,
  200. 'max_height' => 1200,
  201. 'max_width' => 675,
  202. 'file_name' => $filename,
  203. 'file_ext' => $ext
  204. );
  205.  
  206. // validation form
  207. $config = array(
  208. // kode nomor
  209. array(
  210. 'field' => 'kd_menu',
  211. 'label' => 'Kode Menu',
  212. 'rules' => 'trim|required|min_length[4]|max_length[4]'
  213. ),
  214. // nama menu makanan
  215. array(
  216. 'field' => 'nama_menu',
  217. 'label' => 'Nama Menu',
  218. 'rules' => 'required'
  219. ),
  220. // harga
  221. array(
  222. 'field' => 'harga_menu',
  223. 'label' => 'Harga',
  224. 'rules' => 'trim|required|numeric|regex_match[/^[0-9]/]'
  225. ),
  226. // keterangan
  227. array(
  228. 'field' => 'keterangan',
  229. 'label' => 'Keterangan',
  230. 'rules' => 'trim|required'
  231. )
  232. );
  233.  
  234. $this->upload->initialize($conf_upload);
  235. $this->form_validation->set_rules($config);
  236.  
  237. if ($this->form_validation->run() == false || $this->upload->do_upload('upload_menu') == false) {
  238. $data = array('error' => $this->upload->display_errors());
  239. $this->add_menu($data);
  240. } else {
  241. // lulus validasi
  242. $path_images = $conf_upload['upload_path'];
  243. $path_images .= $conf_upload['file_name'];
  244. $path_images .= '.' . $conf_upload['file_ext'];
  245.  
  246. // resize images
  247. // $conf_resize = array (
  248. // 'image_library' => 'gd2',
  249. // 'source_image' => $this->upload->upload_path.$this->upload->file_name,
  250. // 'create_thumb' => true,
  251. // 'maintain_ratio' => true,
  252. // 'width' => 100,
  253. // 'height' => 100
  254. // );
  255. //
  256. // // load library image_lib
  257. // $this->load->library('image_lib', $conf_resize);
  258. // $resize = $this->image_lib->resize();
  259.  
  260. // ambil value form
  261. $data = array(
  262. 'id_menu' => $this->input->post('kd_menu'),
  263. 'nama_menu' => $this->input->post('nama_menu'),
  264. 'harga_menu' => $this->input->post('harga_menu'),
  265. 'path_images' => $path_images,
  266. 'keterangan' => $this->input->post('keterangan')
  267. );
  268. // insert ke database
  269. $insert = $this->crud_model->insert_db('menu', $data);
  270.  
  271. if ($insert) {
  272. // flash success
  273. $this->session->set_flashdata('successfull', 'Tambah Data Berhasil!');
  274. redirect('pages/administrator/menu');
  275. }
  276. }
  277.  
  278. }
  279.  
  280. public function delete_menu ($id)
  281. {
  282. $delete = $this->crud_model->delete('menu', array('id_menu' => $id));
  283.  
  284. if ($delete) {
  285. $this->session->set_flashdata('successfull', 'Data berhasil di hapus!');
  286. redirect('pages/administrator/menu');
  287. }
  288. }
  289.  
  290. /* Crud Admin */
  291. public function data_admin ()
  292. {
  293. $get_data = $this->crud_model->join_db('admin', '*', 'user', 'admin.username=user.username');
  294.  
  295. if ($get_data->num_rows() > 0) {
  296. $data['data'] = $get_data;
  297. }
  298.  
  299. $data['title'] = 'Admin Pages';
  300. $this->load->view('admin/v_data_admin', $data);
  301. }
  302.  
  303. public function add_user ($level)
  304. {
  305. $data['title'] = 'Admin Pages';
  306. $data['level'] = $level;
  307. $this->load->view('admin/v_form_add_user', $data);
  308. }
  309.  
  310. // validation form user (admin && pemilik)
  311. public function validation_user ()
  312. {
  313. // rules
  314. $rules = array(
  315. array(
  316. 'field' => 'username',
  317. 'label' => 'username',
  318. //'rules'=>'trim|required|is_unique[user.username]',
  319. 'rules' => 'callback_username_check'
  320. ),
  321. array(
  322. 'field' => 'password',
  323. 'label' => 'password',
  324. 'rules' => 'trim|required|min_length[8]'
  325. ),
  326. array(
  327. 'field' => 'confirmPassword',
  328. 'label' => 'confirmPassword',
  329. 'rules' => 'trim|required|matches[password]'
  330. ),
  331. array(
  332. 'field' => 'fullname',
  333. 'label' => 'fullname',
  334. 'rules' => 'required'
  335. ),
  336. array(
  337. 'field' => 'email',
  338. 'label' => 'email',
  339. 'rules' => 'trim|required|valid_email'
  340. ),
  341. array(
  342. 'field' => 'alamat',
  343. 'label' => 'alamat',
  344. 'rules' => 'required'
  345. )
  346. );
  347. $this->form_validation->set_rules($rules);
  348. $level = $this->input->post('level');
  349.  
  350. if ($this->form_validation->run() == false) {
  351. $this->add_user($level);
  352. } else {
  353. // lolos validasi
  354. # ambil nilai dari form
  355. $username = $this->input->post('username');
  356. $password = $this->input->post('password');
  357.  
  358. $table_user = array(
  359. 'username' => $username,
  360. 'password' => password_hash($password, PASSWORD_DEFAULT),
  361. 'level' => $level
  362. );
  363.  
  364. $table_data = array(
  365. 'username' => $username,
  366. 'password' => password_hash($password, PASSWORD_DEFAULT),
  367. 'fullname' => $this->input->post('fullname'),
  368. 'email' => $this->input->post('email'),
  369. 'alamat' => $this->input->post('alamat')
  370. );
  371.  
  372. // panggil db_insert
  373. $this->crud_model->insert_db('user', $table_user);
  374. $insert = $this->crud_model->insert_db($level, $table_data);
  375.  
  376. if ($insert) {
  377. $this->session->set_flashdata('successfull', 'Data berhasil ditambahkan!');
  378. redirect('pages/administrator/data_' . $level);
  379. }
  380. }
  381. }
  382.  
  383. public function edit_user ($table, $id)
  384. {
  385. $get_where = $this->crud_model->get_db_where($table, array('id_' . $table => $id));
  386. $get = $get_where;
  387.  
  388. if ($get->num_rows() > 0) {
  389. foreach ($get->result() as $key) {
  390. $data['user'] = $key;
  391. $data['table'] = $table;
  392. }
  393. } else {
  394. $data = 'No data is available';
  395. }
  396. $data['title'] = 'Pages Admin';
  397.  
  398. $this->load->view('admin/v_form_edit_user', $data);
  399. }
  400.  
  401. public function validation_update ()
  402. {
  403. $table = $this->input->post('level');
  404. $id = $this->input->post('id');
  405.  
  406. // set rules
  407. $config = array(
  408. // username
  409. array(
  410. 'field' => 'username',
  411. 'label' => 'Username',
  412. 'rules' => 'trim|required'
  413. ),
  414. array(
  415. 'field' => 'fullname',
  416. 'label' => 'Nama Lengkap',
  417. 'rules' => 'required'
  418. ),
  419. array(
  420. 'field' => 'email',
  421. 'label' => 'Email',
  422. 'rules' => 'trim|required'
  423. ),
  424. array(
  425. 'field' => 'alamat',
  426. 'label' => 'Alamat',
  427. 'rules' => 'required'
  428. )
  429. );
  430. $this->form_validation->set_rules($config);
  431.  
  432. if ($this->form_validation->run() == false) {
  433. // gagal validasi
  434. $this->edit_user($table, $id);
  435. } else {
  436. // lulus validasi
  437. $data = array(
  438. 'username' => $this->input->post('username'),
  439. 'fullname' => $this->input->post('fullname'),
  440. 'alamat' => $this->input->post('alamat'),
  441. 'email' => $this->input->post('email')
  442. );
  443. $where = array($table, 'id_' . $table => $id);
  444. $update = $this->crud_model->set_update($table, $data, $where);
  445.  
  446. if ($update) {
  447. // update berhasil
  448. $this->session->set_flashdata('successfull', 'Update data berhasil');
  449. redirect('pages/administrator/data_' . $table);
  450. }
  451. }
  452. }
  453.  
  454. public function username_check ($username)
  455. {
  456. $get = $this->crud_model->get_db_where('user', array('username' => $username));
  457.  
  458. foreach ($get->result() as $key) {
  459. $user = $key->username;
  460.  
  461. if ($user == $username) {
  462. $this->form_validation->set_message('username_check', '{field} sudah digunakan. Silahkan coba yang lain');
  463.  
  464. return false;
  465. } else {
  466. return true;
  467. }
  468. }
  469. }
  470.  
  471. # crud pemilik
  472. public function data_pemilik ()
  473. {
  474. $getdb = $this->crud_model->join_db('user', '*', 'pemilik', 'user.username=pemilik.username');
  475.  
  476. $data['data'] = $getdb;
  477. $data['title'] = 'Pages Admin';
  478.  
  479. $this->load->view('admin/v_data_pemilik', $data);
  480. }
  481.  
  482. # crud pelanggan
  483. public function data_pelanggan ()
  484. {
  485. $get_data = $this->crud_model->join_db('pelanggan', '*', 'user', 'pelanggan.username=user.username');
  486.  
  487. if ($get_data->num_rows() > 0) {
  488. $data['data'] = $get_data;
  489. }
  490.  
  491. $data['title'] = 'Admin Pages';
  492. $this->load->view('admin/v_data_pelanggan', $data);
  493. }
  494.  
  495. # crud data pelayan
  496. public function data_pelayan ()
  497. {
  498. $get = $this->crud_model->join_db('user', '*', 'pelayan', 'user.username=pelayan.username');
  499. $data['data'] = $get;
  500. $data['title'] = 'Pages Admin';
  501. $this->load->view('admin/v_data_pelayan', $data);
  502. }
  503.  
  504. public function add_pelayan ()
  505. {
  506. // ambil ID terakhir
  507. $max_id = $this->crud_model->getNoMax('pelayan', 'id_pelayan');
  508. foreach ($max_id->result() as $key => $value) {
  509. if (!empty($value)) {
  510. $id = substr($value->id_pelayan, 1, 2);
  511. $id++;
  512. if ($id < 10) {
  513. $id = "P0" . $id;
  514. } else {
  515. $id = "P" . $id;
  516. }
  517. $data['id_pelayan'] = $id;
  518. } else {
  519. $data['id_pelayan'] = 'P01';
  520. }
  521. }
  522.  
  523. $data['title'] = 'Pages Admin';
  524. $this->load->view('admin/v_form_add_pelayan', $data);
  525. }
  526.  
  527. public function validation_pelayan ()
  528. {
  529. $id_pelayan = $this->input->post('id');
  530. //validasi form
  531. $rules = array(
  532. // username
  533. array(
  534. 'field' => 'username',
  535. 'label' => 'Username',
  536. 'rules' => 'trim|required|is_unique[user.username]',
  537. array('rule3' => 'username sudah digunakan.')
  538. //'rules'=>'callback_username_check'
  539. ),
  540. // password
  541. array(
  542. 'field' => 'password',
  543. 'label' => 'Password',
  544. 'rules' => 'required|min_length[8]'
  545. ),
  546. // password confirm
  547. array(
  548. 'field' => 'confirmPassword',
  549. 'label' => 'Konfirmasi Password',
  550. 'rules' => 'required|matches[password]'
  551. ),
  552. // nama pelayan
  553. array(
  554. 'field' => 'nama_pelayan',
  555. 'label' => 'Nama Pelayan',
  556. 'rules' => 'required'
  557. ),
  558. // nomor telepon
  559. array(
  560. 'field' => 'no_tlp',
  561. 'label' => 'Nomor Telepon',
  562. 'rules' => 'trim|required|min_length[12]|max_length[15]'
  563. ),
  564. // alamat
  565. array(
  566. 'field' => 'alamat',
  567. 'label' => 'Alamat',
  568. 'rules' => 'required'
  569. )
  570. );
  571. $role = $this->form_validation->set_rules($rules);
  572. $this->form_validation->set_message('is_unique', '{field} sudah digunakan. Silahkan ganti yang lain');
  573.  
  574. if ($this->form_validation->run() == false) {
  575. $this->add_pelayan();
  576. } else {
  577. //lolos validasi
  578. $data = array(
  579. 'id_pelayan' => $id_pelayan,
  580. 'username' => $this->input->post('username'),
  581. 'password' => password_hash($this->input->post('password'), PASSWORD_DEFAULT),
  582. 'nama_pelayan' => $this->input->post('nama_pelayan'),
  583. 'alamat' => $this->input->post('alamat'),
  584. 'no_telepon_pelayan' => $this->input->post('no_tlp')
  585. );
  586. $data_user = array(
  587. 'username' => $this->input->post('username'),
  588. 'password' => password_hash($this->input->post('password'), PASSWORD_DEFAULT),
  589. 'level' => 'pelayan'
  590. );
  591.  
  592. $insert_user = $this->crud_model->insert_db('user', $data_user);
  593.  
  594. if ($insert_user == true) {
  595. // insert ke table pelayan
  596. $insert = $this->crud_model->insert_db('pelayan', $data);
  597. if ($insert) {
  598. $this->session->set_flashdata('successfull', 'Data berhasil ditambahkan!');
  599. redirect('pages/administrator/data_pelayan');
  600. }
  601. }
  602. }
  603. }
  604.  
  605. public function edit_pelayan ($id)
  606. {
  607. $get = $this->crud_model->get_update('pelayan', array('id_pelayan' => $id));
  608. if (!empty($get)) {
  609. foreach ($get->result() as $v) {
  610. $data['table'] = $v;
  611. }
  612. }
  613. $data['title'] = 'Pages Admin';
  614. $this->load->view('admin/v_form_edit_pelayan', $data);
  615. }
  616.  
  617. public function validation_editpelayan ()
  618. {
  619. // ambil nilai id pelayan
  620. $id = $this->input->post('id');
  621. $oldusername = $this->input->post('olduser');
  622.  
  623. $rules = array(
  624. array(
  625. 'field' => 'username',
  626. 'label' => 'Username',
  627. 'rules' => 'trim|required'
  628. ),
  629. array(
  630. 'field' => 'nama_pelayan',
  631. 'label' => 'Nama Pelayan',
  632. 'rules' => 'required'
  633. ),
  634. array(
  635. 'field' => 'no_tlp',
  636. 'label' => 'Nomor Telepon',
  637. 'rules' => 'trim|required|min_length[11]|max_length[15]'
  638. ),
  639. array(
  640. 'label' => 'Alamat',
  641. 'field' => 'alamat',
  642. 'rules' => 'required'
  643. )
  644. );
  645. $this->form_validation->set_rules($rules);
  646.  
  647. if ($this->form_validation->run() == false) {
  648. $this->edit_pelayan($id);
  649. } else {
  650. $data = array(
  651. 'username' => $this->input->post('username'),
  652. 'nama_pelayan' => $this->input->post('nama_pelayan'),
  653. 'alamat' => $this->input->post('alamat'),
  654. 'no_telepon_pelayan' => $this->input->post('no_tlp')
  655. );
  656. $where = array('id_pelayan' => $id);
  657. $user = array('username' => $oldusername);
  658.  
  659. $update = $this->crud_model->set_update('user', array('username' => $this->input->post('username')), $user);
  660. $updatte = $this->crud_model->set_update('pelayan', $data, $where);
  661.  
  662. if ($update == true && $updatte == true) {
  663. $this->session->set_flashdata('successfull', 'Update data berhasil!');
  664. redirect('pages/administrator/data_pelayan');
  665. }
  666. }
  667. }
  668.  
  669. ########################## CodeIgniter ###############################
  670. # Delete All Data User
  671. public function delete_user ($level, $id)
  672. {
  673. $uri = $this->uri->segment(4);
  674. $uri = explode("_", $uri);
  675. $uri_segment = $uri[1];
  676.  
  677. if ($uri_segment == 'pelanggan') {
  678. $get = $this->crud_model->get_db_where('pelanggan', array('id_pelanggan' => $id));
  679. } elseif ($uri_segment == 'admin') {
  680. $get = $this->crud_model->get_db_where('admin', array('id_admin' => $id));
  681. } elseif ($uri_segment == 'pelayan') {
  682. $get = $this->crud_model->get_db_where('pelayan', array('id_pelayan' => $id));
  683. } elseif ($uri_segment == 'pemilik') {
  684. $get = $this->crud_model->get_db_where('pemilik', array('id_pemilik' => $id));
  685. } else {
  686. $get = '';
  687. }
  688.  
  689. if (!empty($get)) {
  690. foreach ($get->result() as $key) {
  691. // ambil data username
  692. $username = $key->username;
  693. }
  694. }
  695.  
  696. // delete
  697. $del_id = $this->crud_model->delete($uri_segment, array('id_' . $uri_segment => $id));
  698. $del_lv = $this->crud_model->delete('user', array('username' => $username));
  699.  
  700. if ($del_id && $del_lv) {
  701. $this->session->set_flashdata('successfull', 'Data berhasil dihapus!');
  702. redirect('pages/administrator/data_' . $uri_segment);
  703. }
  704. }
  705.  
  706. # kelola menu pemesanan
  707. public function pemesanan ()
  708. {
  709. $where = array('status_order !=' => '0');
  710. $getData = $this->crud_model->join_db_where('*', 'pesan', 'pelanggan', 'pesan.pelanggan_id=pelanggan.id_pelanggan', $where);
  711.  
  712. if ($getData->num_rows() > 0) {
  713. $r = $getData;
  714. }
  715.  
  716. $data['title'] = 'Pages Pemesanan';
  717. $data['data'] = $r;
  718.  
  719. $this->load->view('admin/v_data_pemesanan', $data);
  720. }
  721.  
  722. public function detail($id_pesan)
  723. {
  724. $this->detail_pemesanan($id_pesan);
  725. }
  726.  
  727. public function detail_pesanan ($id_pesan)
  728. {
  729. // join pesan-booking
  730. $get = $this->crud_model->join_db_where('*', 'booking', 'menu', 'booking.menu_id=menu.id_menu', array('booking.pesan_id' => $id_pesan))->result();
  731. $select = 'pelanggan.id_pelanggan, pelanggan.nama, pelanggan.email, pelanggan.alamat, pelanggan.no_telp,';
  732. $select .= 'pesan.id_pesan, pesan.meja_nomor, pesan.tanggal_pesan, pesan.tanggal_booking, pesan.total_pesanan, pesan.total_biaya, pesan.status_order, pesan.keterangan';
  733. // data pelanggan
  734. $get_pelanggan = $this->crud_model->join_db_where($select, 'pesan', 'pelanggan', 'pesan.pelanggan_id = pelanggan.id_pelanggan', array('pesan.id_pesan' => $id_pesan))->result();
  735.  
  736. // echo "<pre>";
  737. // var_dump($get_pelanggan);
  738. // echo "</pre>";
  739. // die();
  740.  
  741. $data['title'] = 'Detail Transaksi';
  742. $data['list_menu'] = $get;
  743. $data['pelanggan'] = $get_pelanggan;
  744.  
  745. $this->load->view('admin/v_pemesanan_detail', $data);
  746. }
  747.  
  748. public function pembayaran($id_pesan)
  749. {
  750. // data transaksi pembayaran
  751. $get_pembayaran = $this->crud_model->join_db_where('*', 'pesan', 'pembayaran', 'pesan.id_pesan = pembayaran.pesan_id', array('pesan.id_pesan'=>$id_pesan))->result();
  752. $data['title'] = 'Pages Kasir';
  753. $data['data'] = $get_pembayaran;
  754.  
  755. $this->load->view('admin/v_bukti_pembayaran', $data);
  756. }
  757.  
  758. public function updatestatusorder($id_pesan)
  759. {
  760. $val = $this->input->post('updateStatusOrder');
  761.  
  762. if (empty($val)) {
  763. $this->session->set_flashdata('error', 'Data tidak ditemukan');
  764. redirect('pages/administrator/detail_pesanan/'.$id_pesan);
  765. } else {
  766. $data['status_order'] = $val;
  767. $where = array('id_pesan' => $id_pesan);
  768.  
  769. // update ke table pesan
  770. $updateStatusOrder = $this->crud_model->set_update('pesan', $data, $where);
  771.  
  772. if ($updateStatusOrder) {
  773. $this->session->set_flashdata('successfull', 'Status Pembayaran sudah terupdate');
  774.  
  775. //send email konfirmasi pembayaran telah diterima
  776.  
  777. // redirect ke halaman pemesanan
  778. redirect('pages/administrator/detail_pesanan/' . $id_pesan);
  779. }
  780. }
  781. }
  782.  
  783. public function cancel_pesanan($id_pesan)
  784. {
  785. $get = $this->crud_model->get_db_where('pesan', array('id_pesan'=>$id_pesan));
  786.  
  787. $data = array(
  788. 'id_pesan' => $id_pesan,
  789. 'data' => $get->result()
  790. );
  791. $this->load->view('admin/cancel_order', $data);
  792. }
  793.  
  794. public function process_cancel()
  795. {
  796. //set rules
  797. $rules = array(
  798. // array(
  799. // 'field' => 'no_pesanan',
  800. // 'label' => 'Nomor Pesanan',
  801. // 'rules' => 'trim|required|numeric'
  802. // ),
  803. array(
  804. 'field' => 'keterangan',
  805. 'label' => 'Keterangan Pesan',
  806. 'rules' => 'required'
  807. )
  808. );
  809. $this->form_validation->set_rules($rules);
  810. $id_pesan = $this->input->post('id_pesan');
  811.  
  812. if ($this->form_validation->run() === false) {
  813. $this->session->set_flashdata('required', 'Form tidak boleh kosong!');
  814. $this->detail_pesanan($id_pesan);
  815. } else {
  816. $data = array(
  817. 'pesan_id' => $this->input->post('id_pesan'),
  818. 'keterangan' => $this->input->post('keterangan')
  819. );
  820. // insert ke table cancel
  821. $insertCancel = $this->crud_model->insert_db('cancel', $data);
  822.  
  823. if ($insertCancel) {
  824. // insert cancel berhasil, update status order di table pesan
  825. $where = array('id_pesan'=>$id_pesan);
  826. $data = array(
  827. 'status_order' => '0',
  828. 'keterangan' => 'CANCEL: '.$this->input->post('keterangan')
  829. );
  830. $updateStatusOrder = $this->crud_model->set_update('pesan', $data, $where);
  831.  
  832. if ($updateStatusOrder) {
  833. $this->session->set_flashdata('successfully', 'Pesanan berhasil dibatalkan');
  834. redirect('pages/administrator/detail_pesanan/'.$id_pesan);
  835. }
  836. } else {
  837. $this->session->set_flashdata('required', 'Ada kesalahan');
  838. $this->detail_pesanan($id_pesan);
  839. }
  840. }
  841. }
  842.  
  843. public function send_mail_payment($id_pesan, $email_to)
  844. {
  845. $this->is_logged_in();
  846. $this->load->library('email');
  847.  
  848. $where = array('id_pesan'=>$id_pesan);
  849. $get = $this->crud_model->join_db_where('*', 'pesan', 'booking', 'pesan.id_pesan=booking.pesan_id', $where, 1);
  850.  
  851. if ($get->num_rows() != null) {
  852. $r = $get->result();
  853. } else {
  854. $r = '';
  855. }
  856.  
  857. $subject = 'Njun Njan Restaurant';
  858. $message = '
  859. <h1>This message has been sent for testing purposes.</h1>
  860. ';
  861.  
  862. $bulan = array(
  863. '01' => 'Januari', '02' => 'Februari', '03' => 'Maret', '04' => 'April', '05' => 'Mei',
  864. '06' => 'Juni', '07' => 'Juli', '08' => 'Agustus', '09' => 'September', '10' => 'Oktober',
  865. '11' => 'November', '12' => 'Desember'
  866. );
  867.  
  868. $hari = array(
  869. 0=>'Minggu', 1=>'Senin', 2=>'Selasa', 3=>'Rabu', 4=>'Kamis', 5=>'Jumat', 6=>'Sabtu'
  870. );
  871.  
  872. $tgl = $r[0]->tanggal_pesan;
  873.  
  874. // Get full html:
  875. $body = '
  876. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  877. <html xmlns="http://www.w3.org/1999/xhtml">
  878. <head>
  879. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  880. <title>A Simple Responsive HTML Email</title>
  881. <style type="text/css">
  882. body {margin: 0; padding: 0; min-width: 100%!important;}
  883. .content {width: 100%; max-width: 600px;}
  884. body[yahoo] .class {}
  885. @media only screen and (min-device-width: 601px) {
  886. .content {width: 600px !important;}
  887. }
  888. .header {padding: 40px 30px 20px 30px;}
  889. .col425 {width: 425px!important;}
  890. .subhead {font-size: 15px; color: #ffffff; font-family: sans-serif; letter-spacing: 10px;}
  891. .h1 {font-size: 33px; line-height: 38px; font-weight: bold;}
  892. .h1, .h2, .bodycopy {color: #153643; font-family: sans-serif;}
  893. .innerpadding {padding: 30px 30px 30px 30px;}
  894. .borderbottom {border-bottom: 1px solid #f2eeed;}
  895. .h2 {padding: 0 0 15px 0; font-size: 24px; line-height: 28px; font-weight: bold;}
  896. .bodycopy {font-size: 16px; line-height: 22px;}
  897. .button {text-align: center; font-size: 18px; font-family: sans-serif; font-weight: bold; padding: 0 30px 0 30px;}
  898. .button a {color: #ffffff; text-decoration: none;}
  899. @media only screen and (min-device-width: 601px) {
  900. .content {width: 600px !important;}
  901. .col425 {width: 425px!important;}
  902. .col380 {width: 380px!important;}
  903. }
  904. img {height: auto;}
  905. .footer {padding: 20px 30px 15px 30px;}
  906. .footercopy {font-family: sans-serif; font-size: 14px; color: #ffffff;}
  907. .footercopy a {color: #ffffff; text-decoration: underline;}
  908. @media only screen and (max-width: 550px), screen and (max-device-width: 550px) {
  909. body[yahoo] .buttonwrapper {background-color: transparent!important;}
  910. body[yahoo] .button a {background-color: #e05443; padding: 15px 15px 13px!important; display: block!important;}
  911. }
  912. body[yahoo] .unsubscribe {display: block; margin-top: 20px; padding: 10px 50px; background: #2f3942; border-radius: 5px; text-decoration: none!important; font-weight: bold;}
  913. body[yahoo] .hide {display: none!important;}
  914. </style>
  915. </head>
  916. <body yahoo bgcolor="#f6f8f1">
  917.  
  918. <table width="100%" bgcolor="#f6f8f1" border="0" cellpadding="0" cellspacing="0">
  919. <tr>
  920. <td>
  921. <table class="content" align="center" cellpadding="0" cellspacing="0" border="0">
  922. <tr>
  923. <td class="header" bgcolor="#c7d8a7">
  924. <table width="100%" border="0" cellspacing="0" cellpadding="0">
  925. <tr>
  926. <td class="subhead" style="padding: 0 0 0 3px;">
  927. Restaurant
  928. </td>
  929. </tr>
  930. <tr>
  931. <td class="h1" style="padding: 5px 0 0 0;">
  932. Njun Njan
  933. </td>
  934. </tr>
  935. </table>
  936. </td>
  937. </tr>
  938. <tr>
  939. <td class="innerpadding borderbottom">
  940. <table width="100%" border="0" cellspacing="0" cellpadding="0">
  941. <tr>
  942. <td class="h2">
  943. Mohon segera selesaikan pembayaran Anda!
  944. </td>
  945. </tr>
  946. <tr>
  947. <td class="bodycopy">
  948. Checkout berhasil pada hari '.
  949. $hari[date('w', strtotime($tgl))].', '.
  950. date('d', strtotime($tgl)).' '.
  951. $bulan[date('m', strtotime($tgl))].' '. date('Y H:i', strtotime($tgl)) .' WIB
  952. </td>
  953. </tr>
  954. </table>
  955. </td>
  956. </tr>
  957.  
  958. <tr>
  959. <td class="innerpadding borderbottom">
  960. <strong>BANK BCA</strong> Nomor Rekening <strong>731 025 2527</strong> a.n Ibnoe Farid
  961. </td>
  962. </tr>
  963. <tr>
  964. <td class="innerpadding borderbottom">
  965. <strong>BANK BNI</strong> Nomor Rekening <strong>023 827 2088</strong> a.n Ibnoe Farid
  966. </td>
  967. </tr>
  968. <tr>
  969. <td class="innerpadding borderbottom">
  970. <strong>BANK MANDIRI</strong> Nomor Rekening <strong>0700 000 899 992</strong> a.n Ibnoe Farid
  971. </td>
  972. </tr>
  973.  
  974. <tr>
  975. <td class="innerpadding borderbottom bodycopy">'; ?>
  976. <?php foreach ($r as $v): ?>
  977. <?php $body .= "Kode Booking : <strong>".$v->kode_booking."</strong>
  978. <br>
  979. Nomor Pesanan : <strong>".$v->id_pesan."</strong>
  980. <br>
  981. Total Pembayaran : Rp <strong>".number_format($v->total_biaya, 0, '', '.')."</strong>,-";
  982. ?>
  983. <?php endforeach;?>
  984. <?php $body .= '</td>
  985. </tr>
  986. </table>
  987. </td>
  988. </tr>
  989.  
  990. <tr>
  991. <td class="footer" bgcolor="#44525f">
  992. <table width="100%" border="0" cellspacing="0" cellpadding="0">
  993. <tr>
  994. <td align="center" class="footercopy">
  995. Email dibuat secara otomatis. Mohon tidak mengirimkan balasan ke email ini.<br/>
  996. </td>
  997. </tr>
  998. <tr><td></td></tr>
  999. <tr>
  1000. <td align="center" style="padding: 20px 0 0 0;">
  1001. <table border="0" cellspacing="0" cellpadding="0">
  1002. <tr>
  1003. <td align="center" class="footercopy">
  1004. <span class="bodycopy" style="color: whitesmoke">
  1005. Jika butuh bantuan, gunakan halaman Kontak Kami <br>
  1006. © 2017, <span style="color: #0bcb9a">Njun Njan Restaurant</span>
  1007. </span>
  1008. </td>
  1009. </tr>
  1010. </table>
  1011. </td>
  1012. </tr>
  1013. </table>
  1014. </td>
  1015. </tr>
  1016. </table>
  1017.  
  1018. </body>
  1019. </html>
  1020. ';
  1021.  
  1022. // Also, for getting full html you may use the following internal method:
  1023. //$body = $this->email->full_html($subject, $message);
  1024.  
  1025. $result = $this->email
  1026. ->from('eko.okda@gmail.com')
  1027. ->to($email_to)
  1028. ->subject($subject)
  1029. ->message($body)
  1030. ->send();
  1031.  
  1032. if ($result) {
  1033. return true;
  1034. }
  1035. return false;
  1036. }
  1037.  
  1038. public function order_cancel()
  1039. {
  1040. // get data cancel
  1041. $this->db->select('pelanggan.*, pesan.*, cancel.id_cancel, cancel.tanggal_cancel');
  1042. $this->db->from('pesan');
  1043. $this->db->join('cancel', 'pesan.id_pesan=cancel.pesan_id');
  1044. $this->db->join('pelanggan', 'pesan.pelanggan_id=pelanggan.id_pelanggan');
  1045. $get = $this->db->get()->result();
  1046.  
  1047. $data['title'] = 'Page Admin';
  1048. $data['result'] = $get;
  1049. $this->load->view('admin/v_data_cancel', $data);
  1050. }
  1051.  
  1052. public function cancel_detail($id_cancel)
  1053. {
  1054. // get data cancel
  1055. $this->db->select('pelanggan.*, pesan.*, cancel.id_cancel, cancel.tanggal_cancel');
  1056. $this->db->from('pesan');
  1057. $this->db->join('cancel', 'pesan.id_pesan=cancel.pesan_id');
  1058. $this->db->join('pelanggan', 'pesan.pelanggan_id=pelanggan.id_pelanggan');
  1059. $this->db->where(array('cancel.id_cancel'=>$id_cancel));
  1060. $get = $this->db->get();
  1061.  
  1062. $data['title'] = 'Page Admin';
  1063. $data['result'] = $get->result();
  1064.  
  1065. $this->load->view('admin/v_data_cancel_detail', $data);
  1066. }
  1067.  
  1068. public function cetak($id_cancel)
  1069. {
  1070. // get data cancel
  1071. $this->db->select('pelanggan.*, pesan.*, cancel.id_cancel, cancel.tanggal_cancel');
  1072. $this->db->from('pesan');
  1073. $this->db->join('cancel', 'pesan.id_pesan=cancel.pesan_id');
  1074. $this->db->join('pelanggan', 'pesan.pelanggan_id=pelanggan.id_pelanggan');
  1075. $this->db->where(array('cancel.id_cancel'=>$id_cancel));
  1076. $get = $this->db->get();
  1077.  
  1078. $data['title'] = 'Page Admin';
  1079. $data['result'] = $get->result();
  1080.  
  1081. $this->load->view('admin/v_data_cetak', $data);
  1082. }
  1083.  
  1084. public function do_cetak_pesanan()
  1085. {
  1086. // get data
  1087. $this->form_validation->set_rules('pilihBulan', 'Bulan', 'trim|required');
  1088.  
  1089. if ($this->form_validation->run() === false) {
  1090. $this->session->set_flashdata('error', 'Data tidak ditemukan');
  1091. redirect('pages/administrator/pemesanan');
  1092. } else {
  1093. $bulan = $this->input->post('pilihBulan');
  1094.  
  1095. // get data cancel
  1096. $sql = "SELECT DISTINCT booking.kode_booking, pesan.*, pelanggan.id_pelanggan, pelanggan.nama FROM booking LEFT JOIN pesan ON pesan.id_pesan=booking.pesan_id LEFT JOIN pelanggan ON pelanggan.id_pelanggan=pesan.pelanggan_id WHERE MONTH(pesan.tanggal_booking)='$bulan' AND pesan.status_order != '0' ORDER BY booking.kode_booking ASC";
  1097. $sql = $this->db->query($sql);
  1098. if ($sql->num_rows() < 1) {
  1099. $data['result'] = '';
  1100. $this->session->set_flashdata('error', 'Data tidak ditemukan');
  1101. redirect('pages/administrator/pemesanan');
  1102. } else {
  1103. $data['result'] = $sql;
  1104. }
  1105. }
  1106.  
  1107. $data['title'] = 'Page Admin';
  1108. $data['bulan'] = $bulan;
  1109.  
  1110. $this->load->view('admin/v_data_cetak_pemesanan_bulanan', $data);
  1111. }
  1112.  
  1113. public function do_cetak_bulanan()
  1114. {
  1115. // get data
  1116. $this->form_validation->set_rules('pilihBulan', 'Bulan', 'trim|required');
  1117.  
  1118. if ($this->form_validation->run() === false) {
  1119. redirect('pages/administrator/order_cancel');
  1120. } else {
  1121. $bulan = $this->input->post('pilihBulan');
  1122.  
  1123. // get data cancel
  1124. $sql = "SELECT * FROM cancel LEFT JOIN pesan ON pesan.id_pesan=cancel.pesan_id LEFT JOIN pelanggan ON pelanggan.id_pelanggan=pesan.pelanggan_id WHERE MONTH(cancel.tanggal_cancel)='$bulan';";
  1125. $sql = $this->db->query($sql);
  1126. if ($sql->num_rows() < 1) {
  1127. $data['result'] = '';
  1128. $this->session->set_flashdata('error', 'Data tidak ditemukan');
  1129. redirect('pages/administrator/order_cancel');
  1130. } else {
  1131. $data['result'] = $sql;
  1132. }
  1133. }
  1134.  
  1135. $data['title'] = 'Page Admin';
  1136. $data['bulan'] = $bulan;
  1137.  
  1138. $this->load->view('admin/v_data_cetak_bulanan', $data);
  1139. }
  1140.  
  1141. public function edit_menu($id_menu)
  1142. {
  1143. $where = array('id_menu' => $id_menu);
  1144. $set = $this->crud_model->get_update('menu', $where)->result();
  1145.  
  1146. $data['title'] = 'Pages Admin';
  1147. $data['data'] = $set;
  1148.  
  1149. $this->load->view('admin/v_form_edit_menu', $data);
  1150. }
  1151.  
  1152. public function update_menu()
  1153. {
  1154. $picture = $_FILES['upload_menu']['name'];
  1155. $id_menu = $this->input->post('id_menu');
  1156.  
  1157. if (!empty($picture)) {
  1158. // mengambil ekstensi file
  1159. $ext = pathinfo($_FILES['upload_menu']['name']);
  1160. $ext = $ext['extension'];
  1161. // sett conf upload image
  1162. $filename = 'menu_' . time();
  1163. $conf_upload = array(
  1164. 'upload_path' => 'assets/upload/images_menu/',
  1165. 'allowed_types' => 'jpg|png',
  1166. 'max_size' => 2048,
  1167. 'max_height' => 1200,
  1168. 'max_width' => 960,
  1169. 'file_name' => $filename,
  1170. 'file_ext' => $ext
  1171. );
  1172.  
  1173. $this->upload->initialize($conf_upload);
  1174.  
  1175. if ($this->upload->do_upload('upload_menu') === false) {
  1176. $this->session->set_flashdata('error', $this->upload->display_errors().' min: 768px dan max: 1200px');
  1177. $this->edit_menu($id_menu);
  1178. return false;
  1179. }
  1180. $path_images = $conf_upload['upload_path'];
  1181. $path_images .= $conf_upload['file_name'];
  1182. $path_images .= '.' . $conf_upload['file_ext'];
  1183. }
  1184.  
  1185. // rules
  1186. $rules = array(
  1187. array(
  1188. 'field' => 'kode_menu',
  1189. 'label' => 'Kode Menu',
  1190. 'rules' => 'trim|required|max_length[4]'
  1191. ),
  1192. array(
  1193. 'field' => 'nama_menu',
  1194. 'label' => 'Nama Menu',
  1195. 'rules' => 'required'
  1196. ),
  1197. array(
  1198. 'field' => 'harga_menu',
  1199. 'label' => 'Harga Menu',
  1200. 'rules' => 'trim|required|numeric'
  1201. ),
  1202. array(
  1203. 'field' => 'keterangan',
  1204. 'label' => 'Keterangan',
  1205. 'rules' => 'required'
  1206. )
  1207. );
  1208.  
  1209. $this->form_validation->set_rules($rules);
  1210.  
  1211. if ($this->form_validation->run() === false) {
  1212. $data = array('error' => $this->upload->display_errors());
  1213. $this->edit_menu($this->input->post('id_menu'));
  1214. } else {
  1215. // lulus validasi
  1216. $data = array(
  1217. 'id_menu' => $this->input->post('kode_menu'),
  1218. 'nama_menu' => $this->input->post('nama_menu'),
  1219. 'harga_menu' => $this->input->post('harga_menu'),
  1220. 'keterangan' => $this->input->post('keterangan')
  1221. );
  1222.  
  1223. if (!empty($_FILES['upload_menu']['name'])) {
  1224. $data['path_images'] = $path_images;
  1225. }
  1226.  
  1227. // var_dump($data);
  1228. // die();
  1229.  
  1230. // update ke database
  1231. $where = array('id_menu'=>$this->input->post('id_menu'));
  1232. $update = $this->crud_model->set_update('menu', $data, $where);
  1233.  
  1234. if ($update) {
  1235. // flash success
  1236. $data['title'] = 'Pages Admin';
  1237. $this->session->set_flashdata('successfull', 'Update Data Berhasil!');
  1238. redirect('pages/administrator/menu');
  1239. }
  1240. }
  1241.  
  1242. }
  1243.  
  1244. // validate image upload
  1245. public function validate_image()
  1246. {
  1247. $pict = $_FILES['upload_menu']['name'];
  1248.  
  1249. if (empty($pict)) {
  1250. return true;
  1251. } else {
  1252. // mengambil ekstensi file
  1253. $ext = pathinfo($_FILES['upload_menu']['name']);
  1254. $ext = $ext['extension'];
  1255.  
  1256. // sett conf upload image
  1257. $filename = 'menu_' . time();
  1258. $conf_upload = array(
  1259. 'upload_path' => 'assets/upload/images_menu/',
  1260. 'allowed_types' => 'jpg|png',
  1261. 'max_size' => 2048,
  1262. 'max_height' => 1200,
  1263. 'max_width' => 768,
  1264. 'file_name' => $filename,
  1265. 'file_ext' => $ext
  1266. );
  1267.  
  1268. $this->upload->initialize($conf_upload);
  1269.  
  1270. if (!$this->upload->do_upload('upload_menu')) {
  1271. $this->form_validation->set_message('validate_image', $this->upload->display_errors());
  1272. return false;
  1273. } else {
  1274. // echo "<pre>";
  1275. // print_r($this->upload->initialize($conf_upload));
  1276. // echo "</pre>";
  1277. // die();
  1278. return true;
  1279. }
  1280. }
  1281.  
  1282. }
  1283.  
  1284. }
  1285. /* End of file */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement