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/kamariallee.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->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() { //pagination in action. 20 results per page $this->load->library('pagination'); $config['base_url'] = base_url() . 'admin/orders/index'; $config['per_page'] = 20; $config["uri_segment"] = 4; //fetch all orders $config['total_rows'] = $this->order_m->record_count(); $this->pagination->initialize($config); $this->data['orders'] = $this->order_m->get_all_orders($config["per_page"], $this->uri->segment(4)); //load view $this->data['subview'] = 'admin/orders/index'; $this->load->view('admin/templates/header', $this->data_header); $this->load->view('admin/_layout_main', $this->data); $this->load->view('admin/templates/footer'); } //to VIEW and EDIT order in admin public function view($id) { //get orders $this->db->select('*')->from('orders')->where('id_orders', $id); $current_order = $this->db->get()->row(); if(count((array) $current_order) < 1) {show_404();} if (isset($_POST['payment_status'])) { if ($this->input->post('payment_status') == 2) { //Status CANCEL $data = array( 'payment_status' => 2, 'cancel_date' => date('Y-m-d') ); $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 stock $this->db->select('stock')->from('product_details')->where('product_id', $item->item_id)->where('sku', $item->sku)->where('attributes', $item->attributes); $current_stock = $this->db->get()->row()->stock; $data = array( 'stock' => $current_stock + $item->quantity, ); $this->db->where('product_id', $item->item_id); $this->db->where('sku', $item->sku); $this->db->where('attributes', $item->attributes); $this->db->update('product_details', $data); } //return customer point reward back to customers table.. //get customer_id $this->db->select('customer_id')->from('orders')->where('id_orders', $id); $customer_id = (int) $this->db->get()->row()->customer_id; //get customer current point $this->db->select('current_pointreward')->from('customers')->where('id_customers', $customer_id); $current_point = (int) $this->db->get()->row()->current_pointreward; //get minus point from order $this->db->select('minus_reward')->from('orders')->where('id_orders', $id); $rewards = $this->db->get()->row(); $minus_point = (int) $rewards->minus_reward; $updated_point = $current_point + $minus_point; //update point reward $data = array( 'current_pointreward' => $updated_point ); $this->db->where('id_customers', $customer_id); $this->db->update('customers', $data); //----SEND EMAIL TO CUSTOMER //get order detail and customer detail $data['order'] = $this->order_m->get_order($id); $data['customer'] = $this->customer_m->get_customer($data['order']->customer_id); $data['minus_point'] = $minus_point; //get website data $this->db->select('logo, from_email, website_name, email_smtp_host, email_smtp_port, email_smtp_password, email_smtp')->from('configuration')->where('id_configuration', 1); $website_data = $this->db->get()->row(); $data['logo'] = $website_data->logo; $data['website_name'] = $website_data->website_name; $data['emails'] = $this->configuration_m->get_emails(); $data['title'] = 'Order Cancel'; $this->load->library('email'); //get email setting $config['protocol'] = 'smtp'; $config['smtp_host'] = $website_data->email_smtp_host; $config['smtp_port'] = $website_data->email_smtp_port; $config['smtp_user'] = $website_data->email_smtp; $config['smtp_pass'] = $website_data->email_smtp_password; $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->email->initialize($config); $this->email->from($data['emails']->from_email, $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 $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Payment status updated Successful</p>'); redirect('admin/orders/view/' . $id); } if ($this->input->post('payment_status') == 1) { //Status BANK TRANSFER PAID $data = array( 'payment_status' => 1, 'payment_date' => date('Y-m-d') ); $this->db->where('id_orders', $id); $this->db->update('orders', $data); //update current point rewards //get customer_id //$this->db->select('customer_id')->from('orders')->where('id_orders', $id); //$customer_id = (int) $this->db->get()->row()->customer_id; //get add and minus point from order // $this->db->select('plus_reward')->from('orders')->where('id_orders', $id); // $rewards = $this->db->get()->row(); // $plus_point = (int) $rewards->plus_reward; // $updated_point = $current_point + $plus_point; //update point reward // $data = array( // 'current_pointreward' => $updated_point // ); // $this->db->where('id_customers', $customer_id); // $this->db->update('customers', $data); //if cancel date exist before, then need to deduct stock back from stocks. Sometimes customer forget to pay, the system change to cancel. Tomorrow they want to pay, so status can change back to paid. //return the quantity back to stock //get order details if($current_order->cancel_date != NULL) { $order_details = $this->order_detail_m->get_orders_detail($id); foreach ($order_details as $item) { //get current stock $this->db->select('stock')->from('product_details')->where('product_id', $item->item_id)->where('sku', $item->sku)->where('attributes', $item->attributes); $current_stock = $this->db->get()->row()->stock; $data = array( 'stock' => $current_stock - $item->quantity, ); $this->db->where('product_id', $item->item_id); $this->db->where('sku', $item->sku); $this->db->where('attributes', $item->attributes); $this->db->update('product_details', $data); } } //SEND EMAIL TO CUSTOMER $data['title'] = 'Payment Confirmation'; //get order detail and customer detail $data['order'] = $this->order_m->get_order($id); $data['customer'] = $this->customer_m->get_customer($data['order']->customer_id); //get website data $this->db->select('logo, from_email, website_name, email_smtp_host, email_smtp_port, email_smtp_password, email_smtp')->from('configuration')->where('id_configuration', 1); $website_data = $this->db->get()->row(); $data['logo'] = $website_data->logo; $data['website_name'] = $website_data->website_name; $data['emails'] = $this->configuration_m->get_emails(); // $data['plus_point'] = $plus_point; $this->load->library('email'); //get email setting $config['protocol'] = 'smtp'; $config['smtp_host'] = $website_data->email_smtp_host; $config['smtp_port'] = $website_data->email_smtp_port; $config['smtp_user'] = $website_data->email_smtp; $config['smtp_pass'] = $website_data->email_smtp_password; $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->email->initialize($config); $this->email->from($data['emails']->from_email, $data['emails']->website_name); if($data['customer']) { $this->email->to($data['customer']->email); $data['customer_name'] = $data['customer']->name; } else { $this->email->to($data['order']->email); $data['customer_name'] = $data['order']->recipient_name; } $data['guest_account'] = TRUE; $this->email->subject('Payment Confirmation'); $email = $this->load->view('email/payment_confirmation', $data, TRUE); $this->email->message($email); if ($this->email->send() == TRUE) { echo 'Email Send SuccessFully>>>>>>>>>>>'; } else { echo 'Email Not Send>>>>>>>>>>>'; } //----end send email $this->session->set_flashdata('success', '<br><p style="background:green; 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 $data = array( 'payment_status' => 3, 'sent_date' => date('Y-m-d'), 'no_resi' => $this->input->post('no_resi') ); $this->db->where('id_orders', $id); $this->db->update('orders', $data); //SEND EMAIL TO CUSTOMER $data['title'] = 'Product Sent'; //get order detail and customer detail $data['order'] = $this->order_m->get_order($id); $data['customer'] = $this->customer_m->get_customer($data['order']->customer_id); $data['no_resi'] = $this->input->post('no_resi'); //get website data $this->db->select('logo, from_email, website_name, email_smtp_host, email_smtp_port, email_smtp_password, email_smtp')->from('configuration')->where('id_configuration', 1); $website_data = $this->db->get()->row(); $data['logo'] = $website_data->logo; $data['website_name'] = $website_data->website_name; $data['emails'] = $this->configuration_m->get_emails(); $this->load->library('email'); //get email setting $config['protocol'] = 'smtp'; $config['smtp_host'] = $website_data->email_smtp_host; $config['smtp_port'] = $website_data->email_smtp_port; $config['smtp_user'] = $website_data->email_smtp; $config['smtp_pass'] = $website_data->email_smtp_password; $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->email->initialize($config); $this->email->from($data['emails']->from_email, $data['emails']->website_name); if($data['customer']) { $this->email->to($data['customer']->email); $data['customer_name'] = $data['customer']->name; } else { $this->email->to($data['order']->email); $data['customer_name'] = $data['order']->recipient_name; } $data['guest_account'] = TRUE; $this->email->subject('Product Sent'); $email = $this->load->view('email/product_sent', $data, TRUE); $this->email->message($email); if ($this->email->send() == TRUE) { echo 'Email Send SuccessFully>>>>>>>>>>>'; } else { echo 'Email Not Send>>>>>>>>>>>'; } //----end send email $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Order 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_header); $this->load->view('admin/_layout_main', $this->data); $this->load->view('admin/templates/footer'); } public function generate_invoice_pdf($id) { //add PDF attachment DOMPDF $data['title'] = 'Invoice'; //get order $this->db->select('*')->from('orders')->where('id_orders', $id); $data['order'] = $this->db->get()->row(); $data['customer'] = $this->customer_m->get_customer($data['order']->customer_id); $data['emails'] = $this->configuration_m->get_emails(); $data['bank'] = $this->configuration_m->get_bank(); $this->db->select('logo')->from('configuration')->where('id_configuration', 1); $data['logo'] = $this->db->get()->row()->logo; //get order detail and customer detail $this->db->select('*')->from('orders_detail')->where('orders_id', $id); $data['order_details'] = $this->db->get()->result(); $this->load->library('dompdf_gen'); $html= $this->load->view('invoice_pdf', $data ,true); $this->dompdf->load_html($html); $this->dompdf->render(); $this->dompdf->stream('invoice.pdf', array("Attachment" => 0)); $output = $this->dompdf->output(); $file_to_save = 'uploads/pdf/invoice.pdf'; file_put_contents($file_to_save, $output); } }