Server : Apache/2.4.18 (Ubuntu) System : Linux canvaswebdesign 3.13.0-71-generic #114-Ubuntu SMP Tue Dec 1 02:34:22 UTC 2015 x86_64 User : oppastar ( 1041) PHP Version : 7.0.33-0ubuntu0.16.04.15 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, Directory : /var/www/kanvakanva.com/public_html/application/controllers/admin/ |
Upload File : |
<?php if (!defined('BASEPATH')) { exit('No direct script access allowed'); } class Orders extends Admin_Controller { function __construct() { parent::__construct(); $this->load->helper(['url']); $this->load->library('session'); $this->load->model('order_m'); $this->load->model('order_detail_m'); $this->load->model('configuration_m'); $this->load->model('customer_m'); } //this is to list all orders public function index() { $this->load->library('pagination'); $config['base_url'] = base_url() . 'admin/orders/index/'; $config['per_page'] = 50; $limit = $this->uri->segment(4); $config['first_link'] = 'First'; $config['last_link'] = 'Last'; $config['next_link'] = 'Next'; $config['prev_link'] = 'Prev'; $config['full_tag_open'] = '<div class="pagging text-center"><nav><ul class="pagination justify-content-center">'; $config['full_tag_close'] = '</ul></nav></div>'; $config['num_tag_open'] = '<li class="page-item"><span class="page-link">'; $config['num_tag_close'] = '</span></li>'; $config['cur_tag_open'] = '<li class="page-item active"><span class="page-link">'; $config['cur_tag_close'] = '<span class="sr-only">(current)</span></span></li>'; $config['next_tag_open'] = '<li class="page-item"><span class="page-link">'; $config['next_tagl_close'] = '<span aria-hidden="true">»</span></span></li>'; $config['prev_tag_open'] = '<li class="page-item"><span class="page-link">'; $config['prev_tagl_close'] = '</span>Next</li>'; $config['first_tag_open'] = '<li class="page-item"><span class="page-link">'; $config['first_tagl_close'] = '</span></li>'; $config['last_tag_open'] = '<li class="page-item"><span class="page-link">'; $config['last_tagl_close'] = '</span></li>'; $config['total_rows'] = $this->order_m->record_count('all', 'all'); $this->data['orders'] = $this->order_m->get_all_orders( 'all', 'all', $config['per_page'], $limit ); $this->pagination->initialize($config); //load view $this->data['subview'] = 'admin/orders/index'; $this->load->view('admin/templates/header', $this->data); $this->load->view('admin/_layout_main', $this->data); $this->load->view('admin/templates/footer', $this->data); } public function filter() { $this->load->library('pagination'); $config['base_url'] = base_url() . 'admin/orders/filter/'; $config['per_page'] = 50; $limit = $this->uri->segment(4); $config['first_link'] = 'First'; $config['last_link'] = 'Last'; $config['next_link'] = 'Next'; $config['prev_link'] = 'Prev'; $config['full_tag_open'] = '<div class="pagging text-center"><nav><ul class="pagination justify-content-center">'; $config['full_tag_close'] = '</ul></nav></div>'; $config['num_tag_open'] = '<li class="page-item"><span class="page-link">'; $config['num_tag_close'] = '</span></li>'; $config['cur_tag_open'] = '<li class="page-item active"><span class="page-link">'; $config['cur_tag_close'] = '<span class="sr-only">(current)</span></span></li>'; $config['next_tag_open'] = '<li class="page-item"><span class="page-link">'; $config['next_tagl_close'] = '<span aria-hidden="true">»</span></span></li>'; $config['prev_tag_open'] = '<li class="page-item"><span class="page-link">'; $config['prev_tagl_close'] = '</span>Next</li>'; $config['first_tag_open'] = '<li class="page-item"><span class="page-link">'; $config['first_tagl_close'] = '</span></li>'; $config['last_tag_open'] = '<li class="page-item"><span class="page-link">'; $config['last_tagl_close'] = '</span></li>'; //check post form if ($this->input->post('orderId')) { $this->session->record_count = $this->order_m->record_count( 'orderId', $this->input->post('orderId') ); $this->session->filter = 'orderId'; $this->session->data_filter = $this->input->post('orderId'); } elseif ($this->input->post('customerName')) { $this->session->record_count = $this->order_m->record_count( 'customerName', $this->input->post('customerName') ); $this->session->filter = 'customerName'; $this->session->data_filter = $this->input->post('customerName'); } elseif ($this->input->post('orderStatus')) { if ($this->input->post('orderStatus') === 'not paid') { $orderStatus = 0; } else { $orderStatus = $this->input->post('orderStatus'); } $this->session->record_count = $this->order_m->record_count( 'orderStatus', $orderStatus ); $this->session->filter = 'orderStatus'; $this->session->data_filter = $this->input->post('orderStatus'); } $config['total_rows'] = $this->session->record_count; $this->data['orders'] = $this->order_m->get_all_orders( $this->session->filter, $this->session->data_filter, $config['per_page'], $limit ); $this->pagination->initialize($config); $this->data['subview'] = 'admin/orders/index'; $this->load->view('admin/templates/header', $this->data); $this->load->view('admin/_layout_main', $this->data); $this->load->view('admin/templates/footer', $this->data); } public function laporan_pdf() { //add PDF attachment DOMPDF $data['title'] = 'Delivery Receipt'; if (!$this->input->post("id_orders")) { echo "<script>window.close();</script>"; } $id_orders = $this->input->post("id_orders"); // get data each ids foreach ($id_orders as $id) { $data['data'][$id]['order'] = $this->order_m->get_order($id); $data['data'][$id][ 'order_details' ] = $this->order_detail_m->get_orders_detail($id); $data['data'][$id]['weight'] = $this->order_detail_m->get_weight($id); } $data['id_orders'] = $id_orders; $data['configuration'] = $this->db ->select('*') ->from('configuration') ->where('id_configuration', 1) ->get() ->row(); //Print Pdf Invoice $this->load->library('dompdf_gen'); $html = $this->load->view('admin/pdf/laporan_pdf', $data, true); $this->dompdf->loadHtml($html); $this->dompdf->setPaper('A4', 'portrait'); $this->dompdf->render(); $this->dompdf->stream('delivery_receipt.pdf', ["Attachment" => 0]); $output = $this->dompdf->output(); $file_to_save = 'uploads/pdf/delivery_receipt.pdf'; file_put_contents($file_to_save, $output); } public function pdf() { $this->load->helper('pdf_helper'); if (!$this->input->post("id_orders")) { echo "<script>window.close();</script>"; } $id_orders = $this->input->post("id_orders"); $data['data'] = []; foreach ($id_orders as $id) { $data['data'][$id]['order'] = $this->order_m->get_order($id); $data['data'][$id]['customer'] = $this->customer_m->get_customer( $data['data'][$id]['order']->customer_id ); $data['data'][$id][ 'order_details' ] = $this->order_detail_m->get_orders_detail($id); $data['data'][$id]['weight_gram'] = 0; foreach ($data['data'][$id]['order_details'] as $detail) { //get size_id $size_id = $this->db ->select('id_product_size') ->from('product_size') ->where('product_size', $detail->size) ->get() ->row()->id_product_size; //get product weight $this->db ->select('weight') ->from('stocks') ->where('product_id', $detail->item_id) ->where('size_id', $size_id); $item_weight = $this->db->get()->row()->weight * $detail->quantity; $data['data'][$id]['weight_gram'] = $data['data'][$id]['weight_gram'] + $item_weight; } } $data['id_orders'] = $id_orders; $data['configuration'] = $this->db ->select('*') ->from('configuration') ->where('id_configuration', 1) ->get() ->row(); $this->load->view('admin/pdfreport', $data); } //to VIEW and EDIT order in admin public function view($id) { if (isset($_POST['payment_status'])) { if ($this->input->post('payment_status') == 2) { //Status CANCEL, email to customer $data['title'] = 'Order Cancel'; //get order detail and customer detail $data_order = $this->order_m->get_order($id); $data['order'] = $data_order; /* $data['order_details'] = $this->order_detail_m->get_orders_detail($this->session->userdata('order_id')); */ //get website logo $this->db ->select('logo') ->from('configuration') ->where('id_configuration', 1); $data['logo'] = $this->db->get()->row()->logo; $config['protocol'] = 'smtp'; $config['smtp_host'] = 'ssl://smtp.gmail.com'; //change this $config['smtp_port'] = '465'; $config['smtp_user'] = 'info@kanvakanva.com'; //change this $config['smtp_pass'] = 'Akunk4nva'; //change this $config['mailtype'] = 'html'; $config['charset'] = 'iso-8859-1'; $config['wordwrap'] = true; $config['newline'] = "\r\n"; //use double quotes to comply with RFC 822 standard $this->load->library('email'); $this->email->initialize($config); $data['customer'] = $this->customer_m->get_customer( $data['order']->customer_id ); $data['emails'] = $this->configuration_m->get_emails(); $this->email->from( 'info@kanvakanva.com', $data['emails']->website_name ); $this->email->to($data['customer']->email); $this->email->subject('Order Cancel'); $email = $this->load->view('email/order_cancel', $data, true); $this->email->message($email); $this->email->send(); //----end send email $data = [ 'payment_status' => $this->input->post('payment_status'), ]; $this->db->where('id_orders', $id); $this->db->update('orders', $data); //return the quantity back to stock //get order details $order_details = $this->order_detail_m->get_orders_detail($id); foreach ($order_details as $item) { //get current purchased quantity $purchased_quantity = $item->quantity; //get size id from product size $this->db ->select('id_product_size') ->from('product_size') ->where('product_size', $item->size); $size_id = (int) $this->db->get()->row()->id_product_size; //get current stock $this->db ->select('stock') ->from('stocks') ->where('size_id', $size_id) ->where('product_id', $item->item_id); $current_stock = $this->db->get()->row()->stock; $data = [ 'stock' => $current_stock + $purchased_quantity, ]; $this->db->where('size_id', $size_id); $this->db->where('product_id', $item->item_id); $this->db->update('stocks', $data); } /* --------- REMOVE POINT ---------- */ $this->db->select('point'); $this->db->from('get_point'); $this->db->where('orders_id', $id); $order_point = $this->db->get()->row('point'); $point = $this->customer_m->get_point($data_order->customer_id); $data_cust = array( 'point' => $point - $order_point ); $this->db->where('id_customers', $data_order->customer_id); $this->db->update('customers', $data_cust); $this->db->delete('get_point', array('orders_id' => $id)); /* --------- END REMOVE POINT ---------- */ $this->session->set_flashdata( 'success', '<br><p style="background:orange; color:white; padding:5px; font-weight:bold;">Payment status updated Successful</p>' ); redirect('admin/orders/view/' . $id); } if ($this->input->post('payment_status') == 3) { //Status PRODUCT SENT, email to customer $data['title'] = 'Product Sent'; //get order detail and customer detail $data['order'] = $this->order_m->get_order($id); /* $data['order_details'] = $this->order_detail_m->get_orders_detail($this->session->userdata('order_id')); */ //get website logo $this->db ->select('logo') ->from('configuration') ->where('id_configuration', 1); $data['logo'] = $this->db->get()->row()->logo; $config['protocol'] = 'smtp'; $config['smtp_host'] = 'ssl://smtp.gmail.com'; //change this $config['smtp_port'] = '465'; $config['smtp_user'] = 'info@kanvakanva.com'; //change this $config['smtp_pass'] = 'Akunk4nva'; //change this $config['mailtype'] = 'html'; $config['charset'] = 'iso-8859-1'; $config['wordwrap'] = true; $config['newline'] = "\r\n"; //use double quotes to comply with RFC 822 standard $this->load->library('email'); $this->email->initialize($config); $data['customer'] = $this->customer_m->get_customer( $data['order']->customer_id ); $data['emails'] = $this->configuration_m->get_emails(); $jml_resi = $this->input->post('jml_resi'); if($jml_resi == 1 || $jml_resi == ''){ $data['no_resi'] = $this->input->post('no_resi'); }else{ $list_resi = ''; for ($i=1; $i <= $jml_resi; $i++) { if($i == 1){ $list_resi .= $this->input->post('no_resi_'.$i); }else{ $list_resi .= ';'.$this->input->post('no_resi_'.$i); } } $data['no_resi'] = $list_resi; } $data['list_brand'] = $this->input->post('list_brand'); $this->email->from( 'info@kanvakanva.com', $data['emails']->website_name ); $this->email->to($data['customer']->email); //$this->email->to('ahmadmuflih1@gmail.com'); $this->email->cc($data['emails']->from_email); $this->email->subject('Product Sent Notification'); $email = $this->load->view('email/product_sent', $data, true); $this->email->message($email); $this->email->send(); //----end send email $data = [ 'send_date' => date('Y-m-d'), 'payment_status' => $this->input->post('payment_status'), 'no_resi' => $data['no_resi'], ]; $this->db->where('id_orders', $id); $this->db->update('orders', $data); $this->session->set_flashdata( 'success', '<br><p style="background:orange; color:white; padding:5px; font-weight:bold;">Payment status updated Successful</p>' ); redirect('admin/orders/view/' . $id); } if ($this->input->post('payment_status') == 4) { //Status PRODUCT PACKED $data = [ 'payment_status' => 4 ]; $this->db->where('id_orders', $id); $this->db->update('orders', $data); $this->session->set_flashdata( 'success', '<br><p style="background:orange; color:white; padding:5px; font-weight:bold;">Payment status updated Successful</p>' ); redirect('admin/orders/view/' . $id); } if ($this->input->post('payment_status') == 1) { //to change date to mysql format if (!$this->input->post('payment_date')) { $payment_date = $date = date('Y-m-d'); } else { $payment_date = date( 'Y-m-d', strtotime($this->input->post('payment_date')) ); } //Status BANK TRANSFER PAID, email to customer //----SEND EMAIL TO CUSTOMER (BANK TRANSFER) if ($this->input->post('payment_status') == 1) { $data['title'] = 'Payment Confirmation'; //get order detail and customer detail $data_order = $this->order_m->get_order($id); $data['order'] = $data_order; /* $data['order_details'] = $this->order_detail_m->get_orders_detail($this->session->userdata('order_id')); */ //get website logo $this->db ->select('logo') ->from('configuration') ->where('id_configuration', 1); $data['logo'] = $this->db->get()->row()->logo; $config['protocol'] = 'smtp'; $config['smtp_host'] = 'ssl://smtp.gmail.com'; //change this $config['smtp_port'] = '465'; $config['smtp_user'] = 'info@kanvakanva.com'; //change this $config['smtp_pass'] = 'Akunk4nva'; //change this $config['mailtype'] = 'html'; $config['charset'] = 'iso-8859-1'; $config['wordwrap'] = true; $config['newline'] = "\r\n"; //use double quotes to comply with RFC 822 standard $this->load->library('email'); $this->email->initialize($config); $data['customer'] = $this->customer_m->get_customer( $data['order']->customer_id ); $data['emails'] = $this->configuration_m->get_emails(); $this->email->from( 'info@kanvakanva.com', $data['emails']->website_name ); $this->email->to($data['customer']->email); //$this->email->to('ahmadmuflih1@gmail.com'); $this->email->cc($data['emails']->from_email); $this->email->subject('Payment Confirmation Notification'); $email = $this->load->view('email/payment_confirmation', $data, true); $this->email->message($email); $r = $this->email->send(); /*if (!$r) echo $this->email->print_debugger(); ;*/ //----end send email /* ------- GET POINT ------- */ $this->db->select('order_point,order_rupiah'); $this->db->from('reward_config'); $this->db->where('id_reward_config', '1'); $reward = $this->db->get()->row(); $order_point = $reward->order_point; $order_rupiah = $reward->order_rupiah; if($order_point > 0 && $order_rupiah > 0){ $total_order = $data_order->total_amount - $data_order->shipping_fee; $hitung_point = ($total_order/$order_rupiah) * $order_point; if($hitung_point > 0){ $data_point = array( 'id_customers' => $data_order->customer_id, 'title' => "From Order #".$id, 'orders_id' => $id, 'point' => $hitung_point, 'created_at' => date("Y-m-d H:i:s") ); $this->db->insert('get_point', $data_point); $point = $this->customer_m->get_point($data_order->customer_id); $data_cust = array( 'point' => $point + $hitung_point ); $this->db->where('id_customers', $data_order->customer_id); $this->db->update('customers', $data_cust); } } /* ------- END GET POINT ------- */ } $data = [ 'payment_status' => $this->input->post('payment_status'), 'payment_date' => $payment_date, ]; $this->db->where('id_orders', $id); $this->db->update('orders', $data); $this->session->set_flashdata( 'success', '<br><p style="background:orange; color:white; padding:5px; font-weight:bold;">Payment status updated Successful</p>' ); redirect('admin/orders/view/' . $id); } } //get order detail and customer detail $this->data['order'] = $this->order_m->get_order($id); $this->data['customer'] = $this->customer_m->get_customer( $this->data['order']->customer_id ); $this->data['order_details'] = $this->order_detail_m->get_orders_detail( $id ); $this->data['subview'] = 'admin/orders/view'; $this->load->view('admin/templates/header', $this->data); $this->load->view('admin/_layout_main', $this->data); $this->load->view('admin/templates/footer', $this->data); } function send_giftcard($order_detail_id = null) { if ($order_detail_id == null) { show_404(); } if (!isset($_POST['sendgiftcard'])) { show_404(); } $data['giftcode'] = $this->security->xss_clean( $this->input->post('giftcode') ); //get all order detail and order data $this->db ->select('*') ->from('orders_detail') ->where('id_orders_detail', $order_detail_id); $data['order_detail'] = $this->db->get()->row(); $this->db ->select('*') ->from('orders') ->where('id_orders', $data['order_detail']->orders_id); $data['order'] = $this->db->get()->row(); //send email $data['title'] = 'YOUR GIFT CARD CODE'; //get order detail and customer detail //get website logo $this->db ->select('logo') ->from('configuration') ->where('id_configuration', 1); $data['logo'] = $this->db->get()->row()->logo; $config['protocol'] = 'smtp'; $config['smtp_host'] = 'ssl://smtp.gmail.com'; //change this $config['smtp_port'] = '465'; $config['smtp_user'] = 'info@kanvakanva.com'; //change this $config['smtp_pass'] = 'Akunk4nva'; //change this $config['mailtype'] = 'html'; $config['charset'] = 'iso-8859-1'; $config['wordwrap'] = true; $config['newline'] = "\r\n"; //use double quotes to comply with RFC 822 standard $this->load->library('email'); $this->email->initialize($config); $data['customer'] = $this->customer_m->get_customer( $data['order']->customer_id ); $data['emails'] = $this->configuration_m->get_emails(); $this->email->from('info@kanvakanva.com', $data['emails']->website_name); $this->email->to($data['order_detail']->voucher_email); $this->email->cc($data['emails']->from_email); $this->email->subject('You have Gift Card from ' . $data['customer']->name); $email = $this->load->view('email/giftcard', $data, true); $this->email->message($email); $this->email->send(); //----end send email //change status to voucher sent, and add voucher code $data_voucher = [ 'voucher_code' => $data['giftcode'], 'voucher_sent' => 'yes', ]; $this->db->where('id_orders_detail', $order_detail_id); $this->db->update('orders_detail', $data_voucher); $this->session->set_flashdata( 'success', '<br><p style="background:orange; color:white; padding:5px; font-weight:bold;">Gift Card Code successfully sent.</p>' ); redirect('admin/orders/view/' . $data['order_detail']->orders_id); } function ajax_get_preview() { if (!$this->input->is_ajax_request()) { exit('No direct script access allowed'); } $order_id = (int) $this->input->post('orderId'); //get order data $data['order'] = $this->db ->select('*') ->from('orders') ->where('id_orders', $order_id) ->get() ->row(); $data['order_detail'] = $this->db ->select('*') ->from('orders_detail') ->where('orders_id', $data['order']->id_orders) ->get() ->result(); $this->load->view('admin/orders/ajax_modal_review', $data); } }