<?php
exit('No direct script access allowed');
class A_Order extends MY_Controller {
/*
* Developed by: DVORE
* Date : 2017-12-04
* WEB APPLICATION
*/
var $current_page = FALSE;
function __construct() {
parent::__construct();
$this->load->database();
if ($this->session->login != "yes") {
redirect('admin');
}
$this->load->model("Vore_order_model");
// ini_set('display_errors', 1);
$this->current_page = "Orders";
$this->session->taxe1 = 0.0975;
$this->session->taxe2 = 0.05;
$this->dependence->set_js_footer($this->config->config['dvore_url'] . 'themes/'.$this->theme_settings->admin->link.'js/dvore/VORE_SHOP_order.js');
}
function all($id = FALSE) {
$page_data['all_categories'] = $this->Vore_core_model->DVORE_getALlCategories();
$result_by_page = 10;
$current_page = (!empty($para2)) ?
$para2 : 1;
$conditions = [];
$conditions = $_POST;
}
$page_data['conditions'] = $conditions;
$nbre_result = $this->Vore_order_model->getAllOrders_nbre($conditions);
$page_data['orders'] = $this->Vore_order_model->getAllOrdersByLimit($result_by_page, $current_page, $conditions);
$page_data['all_order_status'] = $this->Vore_order_model->getAllOrderStatus();
$page_data['onlineOrder_access'] = $this->Vore_core_model->getModuleAccess(15);
$page_data['search_data'] = $conditions;
$order_pagination_parameters = new PaginationParameter();
$order_pagination_parameters->ajax_url = base_url() . "a_Order/order_list_ajax";
$order_pagination_parameters->nbre_result = $nbre_result;
$order_pagination_parameters->result_by_page = $result_by_page;
$order_pagination_parameters->current_page = $current_page;
$order_pagination_parameters->target = "#dvore_order_list_tbody";
$order_pagination_parameters->action = "search";
$page_data['order_pagination_parameters'] = $order_pagination_parameters;
$page_data['sub_page_name'] = "all";
$page_data['page_title'] = get_trad('order_list');
$page_data['custom_header'] = true;
$page_data['page_name'] = "order/index";
$this->load->view('admin', 'site/index', $page_data);
}
function view($order_id = FALSE) {
$page_data['all_categories'] = $this->Vore_core_model->DVORE_getALlCategories();
$page_data['all_order_status'] = $this->Vore_order_model->getAllOrderStatus();
$order = $this->Vore_order_model->getOrderById($order_id);
$this->Vore_order_model->updateOrderDateView($order_id);
$page_data['order'] = $order;
}
$page_data['client_modal_url'] = dvore_base_url("a_OnlineOrder/modal_search_customer");
if(!empty($order->cart_id)){
$page_data['product_modal_url'] = dvore_base_url("admin/online-order/add/". $order->cart_id);
}else{
$page_data['product_modal_url'] = dvore_base_url("admin/online-order/add/new/". $order_id);
}
$page_data['product_modal_status'] = 2;
$page_data['order_id'] = (!empty($order_id)) ?
$order_id : 0;
$page_data['sub_page_name'] = "add_v1/index";
$page_data['page_title'] = get_trad('order');
$page_data['custom_header'] = true;
$page_data['page_name'] = "order/index";
$this->load->view('admin', 'site/index', $page_data);
}
function select_customer($cart_id) {
$page_data['form_action'] = base_url("a_Order/ajax_select_customer_to_cart/".$cart_id);
$page_data['all_customers'] = $this->Vore_core_model->getAllCustomer();
$page_data['sub_page_name'] = "select_customer";
$page_data['page_title'] = "#" . $order->id . " - <span>" . $order->date_added . "</span>";
$page_data['page_name'] = "order/index";
$page_data['custom_header'] = true;
$this->load->view('admin', 'site/index', $page_data);
}
/**
*
* AJAX FUNCTION
*
*/
function order_list_ajax($page) {
$result_by_page = 10;
$current_page = (!empty($page)) ?
$page : 1;
$conditions = [];
$conditions = $_POST;
}
$orders = $this->Vore_order_model->getAllOrdersByLimit($result_by_page, $current_page, $conditions);
$page_data['orders'] = $orders;
$this->load->view('admin', 'site/admin/order/ajax_list', $page_data);
}
/**
*
* @para
*
* @return
*/
public function ajax_create_cart() {
$insert_id = $this->Vore_order_model->DVORE_createBasicCart();
echo $insert_id;
}
/**
*
* @para
*
* @return
*/
public function ajax_select_customer_to_cart($cart_id) {
if($_POST['select_customer']){
$insert = $this->Vore_order_model->DVORE_selectCustomerToCart($cart_id, $_POST['select_customer'], 4);
if($insert == true){
redirect("admin/order/add/" . $cart_id);
}
}
}
/**
* Delete cart item in order/cart
* @para $cart_id
*
* @return
*/
public function ajax_delete_cart_item($cart_id) {
$row_id = $this->input->post('item_id');
$this->Vore_order_model->DVORE_delete_item_database_cart($cart_id, $row_id);
}
/**
* List categories in the order/add
* @para $cart_id
*
* @return
*/
public function ajax_list_product_by_category($cart_id) {
if ($_POST['sub_category_id'] != "0") {
$all_products = $this->Vore_product_model->DVORE_getAllProductsByCategory_forOrders($_POST['category_id'], $_POST['sub_category_id']);
} else {
$all_products = $this->Vore_product_model->DVORE_getAllProductsByCategory_forOrders($_POST['category_id']);
}
$page_data['cart'] = $this->Vore_order_model->DVORE_getCartByID($cart_id);
$page_data['all_products'] = $all_products;
$this->load->view('admin', 'site/admin/order/add_ajax_list', $page_data);
}
/**
* Add item inside the cart_details from order/add
* @para $cart_id
*
* @return
*/
public function ajax_add_product_to_cart($cart_id) {
$product_id = $this->input->post("product_id");
$product_qty = $this->input->post("qty");
$this->Vore_product_model->DVORE_addProductToCart($product_id, $product_qty, $cart_id);
$cart = $this->Vore_order_model->DVORE_getCartByID($cart_id);
$i = 0;
foreach ($cart->cart_details as $key => $value) {
$i++;
}
$data = [];
$data["i"] = $i;
$data['cart'] = $cart;
}
function ajax_order_change_cart_content($cart_id) {
$cart = $this->Vore_order_model->DVORE_getCartByID($cart_id);
$page_data['cart'] = $cart;
$page_data['cart_products'] = $cart->cart_details;
$this->load->view('admin', 'site/admin/order/cart_ajax_list', $page_data);
}
/**
* Update cart quantity in order/cart
* @para $cart_id
*
* @return
*/
function ajax_cart_update_quantity($cart_id) {
$qty = $this->input->post('value');
$row_id = $this->input->post('row_id');
if ($this->session->status == 1 || $this->session->status == 4) {
$this->Vore_order_model->update_item_database_cart($cart_id, $row_id, $qty);
// $this->ajax_cart_display($row_id);
}
}
/**
* Update user shipping information
* @para $user_id
*/
function ajax_update_order_shipping_info($user_address_id) {
if ($_POST) {
$this->Vore_order_model->DVORE_update_order_shipping_info($user_address_id, $_POST);
}
}
/**
* Update user shipping information
* @para $user_id
*/
function ajax_update_order_billing_info($user_payment_id) {
if ($_POST) {
$this->Vore_order_model->DVORE_update_order_billing_info($user_payment_id, $_POST);
}
}
function ajax_order_checkout_update_cart($cart_id) {
$cart = $this->Vore_order_model->DVORE_getCartByID($cart_id);
if ($_POST) {
$this->Vore_order_model->DVORE_update_order_cart_info($cart_id, $_POST, $cart->user_id);
}
}
function ajax_send_final_step($cart_id) {
$cart = $this->Vore_order_model->DVORE_getCartByID($cart_id);
$this->Vore_order_model->DVORE_create_order_sale($cart);
}
}
function ajax_delete_order(){
if(!empty($this->input->post("id"))){
$update_data = [];
$update_data['status'] = -1;
$this->db->where("id", $this->input->post("id"));
$this->db->update("VORE_SHOP_sale", $update_data);
}
}
function modal_search_product(){
$page_data['modal_folder'] = "admin/";
$page_data['modal_file'] = "_order_search_product";
$this->load->view("admin", "modal/index", $page_data);
}
function modal_search_customer(){
$page_data['modal_folder'] = "admin/";
$page_data['modal_file'] = "_order_search_customer";
$page_data['modal_footer'] = "none";
$page_data['ajax_url'] = base_url("a_Order/ajax_search_customer_by_id");
$page_data['customers'] = $this->Vore_order_model->DVORE_searchCustomerAll();
$this->load->view("admin", "modal/index", $page_data);
}
function new_order($order_id){
$this->load->model("Vore_customer_model");
$order = $this->Vore_order_model->getOrderById($order_id);
$page_data['order'] = $order;
}
$page_data['all_order_status'] = $this->Vore_order_model->getAllOrderStatus();
$page_data['order_id'] = (!empty($order_id)) ?
$order_id : 0;
$page_data['client_modal_url'] = dvore_base_url("a_OnlineOrder/modal_search_customer");
$page_data['product_modal_url'] = dvore_base_url("a_Order/modal_search_product");
$page_data['product_modal_status'] = 1;
$page_data['sub_page_name'] = "add_v1/index";
$page_data['page_title'] = get_trad('create_order');
$page_data['custom_header'] = true;
$page_data['page_name'] = "order/index";
$this->load->view('admin', 'site/index', $page_data);
}
// CUSTOMER
function ajax_search_customer_list(){
$value = $this->input->post("value");
$data = [];
$object = $this->Vore_order_model->DVORE_searchCustomer($value);
$data['customers'] = $object;
}
$this->load->view('admin', 'site/admin/order/add_v1/ajax_search_customer_list', $data);
}
function ajax_search_customer_by_id(){
$id = $this->input->post("user_id");
$data = [];
$object = $this->Vore_order_model->getCustomerById($id);
$data['customer'] = $object;
}
$this->load->view('admin', 'site/admin/order/add_v1/ajax_search_customer_result', $data);
}
// PRODUCT
function ajax_search_product_list(){
$value = $this->input->post("value");
$data = [];
$object = $this->Vore_order_model->DVORE_searchProduct($value);
$data['products'] = $object;
}
$this->load->view('admin', 'site/admin/order/add_v1/ajax_search_product_list', $data);
}
function ajax_search_product_by_id(){
$id = $this->input->post("product_id");
$order_id = $this->input->post("order_id");
$data = [];
$object = $this->Vore_order_model->DVORE_searchProductById($id, $order_id);
}
$data['product'] = $object;
$this->load->view('admin', 'site/admin/order/add_v1/ajax_search_product_result', $data);
}else{
echo $id;
}
}
function ajax_update_order_modification(){
$order_id = $this->input->post("order_id");
$data = [];
$data['status'] = "failed";
if($order_id == 0){ // create
$insert_id = $this->Vore_order_model->DVORE_createOrder();
$data['status'] = "created";
$data['order_id'] = $insert_id;
}else{ // update
$this->Vore_order_model->DVORE_updateOrder();
$data['status'] = "updated";
}
}
function ajax_update_order_customer(){
$user_id = $this->input->post("user_id");
$order_id = $this->input->post("order_id");
if($order_id == 0){
$insert_id = $this->Vore_order_model->DVORE_createOrder();
$new_order_id = $insert_id;
}else{
$new_order_id = $order_id;
}
$this->Vore_order_model->DVORE_updateOrderCustomer($new_order_id, $user_id);
}
echo $new_order_id;
}
function ajax_update_order_product(){
$product_id = $this->input->post("product_id");
$order_id = $this->input->post("order_id");
$qty = (!empty($this->input->post("qty"))) ?
$this->input->post("qty") : 1;
if($order_id == 0){
$insert_id = $this->Vore_order_model->DVORE_createOrder();
$new_order_id = $insert_id;
}else{
$new_order_id = $order_id;
}
$this->Vore_order_model->DVORE_updateOrderProducts($new_order_id, $product_id, $qty);
}
echo $new_order_id;
}
function ajax_delete_order_product($order_id, $row_id) {
$this->Vore_order_model->delete_order_product_item($order_id, $row_id);
}
function ajax_save_products_qty(){
$products_object = (!empty($this->input->post("products_object"))) ?
$this->input->post("products_object") : false;
$order_id = (!empty($this->input->post("order_id"))) ?
$this->input->post("order_id") : false;
if(!empty($products_object) && !empty($order_id)){
$msg = $this->Vore_order_model->DVORE_changeOrderProductsQty($order_id, $products_object);
}else{
$msg = "failed";
}
echo $msg;
}
function ajax_change_payment_status(){
$payment_status = (!empty($this->input->post("payment_status"))) ?
$this->input->post("payment_status") : false;
$order_id = (!empty($this->input->post("order_id"))) ?
$this->input->post("order_id") : false;
$status_name = $this->Vore_order_model->DVORE_changePaymentStatus($order_id, $payment_status);
}
echo $status_name;
}
function order_notes_ajax() {
$this->Vore_order_model->DVORE_orderUpdateNotes($_POST);
}
}
}