Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: ben mediavore
Added: Mar 9, 2018 2:23 PM
Views: 8
Tags: tab
  1. <?php
  2.  
  3. if (!defined('BASEPATH'))
  4.   exit('No direct script access allowed');
  5.  
  6. class A_Order extends MY_Controller {
  7.   /*
  8.    *  Developed by: DVORE
  9.    *  Date    : 2017-12-04
  10.    *  WEB APPLICATION
  11.    */
  12.  
  13.   var $current_page = FALSE;
  14.  
  15.   function __construct() {
  16.         parent::__construct();
  17.         $this->load->database();
  18.         if ($this->session->login != "yes") {
  19.           redirect('admin');
  20.         }
  21.         $this->load->model("Vore_order_model");
  22. //      ini_set('display_errors', 1);
  23.         $this->current_page = "Orders";
  24.         $this->session->taxe1 = 0.0975;
  25.         $this->session->taxe2 = 0.05;
  26.        
  27.         $this->dependence->set_js_footer($this->config->config['dvore_url'] . 'themes/'.$this->theme_settings->admin->link.'js/dvore/VORE_SHOP_order.js');
  28.   }
  29.  
  30.   function all($id = FALSE) {
  31.         $page_data['all_categories'] = $this->Vore_core_model->DVORE_getALlCategories();
  32.         $result_by_page = 10;
  33.         $current_page = (!empty($para2)) ? $para2 : 1;
  34.         $conditions = [];
  35.         if (!empty($_POST)) {
  36.           $conditions = $_POST;
  37.         }
  38.         $page_data['conditions'] = $conditions;
  39.        
  40.         $nbre_result = $this->Vore_order_model->getAllOrders_nbre($conditions);
  41.  
  42.         $page_data['orders'] = $this->Vore_order_model->getAllOrdersByLimit($result_by_page, $current_page, $conditions);
  43.         $page_data['all_order_status'] = $this->Vore_order_model->getAllOrderStatus();
  44.         $page_data['onlineOrder_access'] = $this->Vore_core_model->getModuleAccess(15);
  45.  
  46.         $page_data['search_data'] = $conditions;
  47.  
  48.         $order_pagination_parameters = new PaginationParameter();
  49.         $order_pagination_parameters->ajax_url = base_url() . "a_Order/order_list_ajax";
  50.         $order_pagination_parameters->nbre_result = $nbre_result;
  51.         $order_pagination_parameters->result_by_page = $result_by_page;
  52.         $order_pagination_parameters->current_page = $current_page;
  53.         $order_pagination_parameters->target = "#dvore_order_list_tbody";
  54.         $order_pagination_parameters->action = "search";
  55.         $page_data['order_pagination_parameters'] = $order_pagination_parameters;
  56.  
  57.         $page_data['sub_page_name'] = "all";
  58.         $page_data['page_title'] = get_trad('order_list');
  59.         $page_data['custom_header'] = true;
  60.         $page_data['page_name'] = "order/index";
  61.         $this->load->view('admin', 'site/index', $page_data);
  62.   }
  63.  
  64.   function view($order_id = FALSE) {
  65.         $page_data['all_categories'] = $this->Vore_core_model->DVORE_getALlCategories();
  66.         $page_data['all_order_status'] = $this->Vore_order_model->getAllOrderStatus();
  67.        
  68.         if(!empty($order_id)){
  69.           $order = $this->Vore_order_model->getOrderById($order_id);
  70.           $this->Vore_order_model->updateOrderDateView($order_id);
  71.           $page_data['order'] = $order;
  72.         }
  73.         $page_data['client_modal_url'] = dvore_base_url("a_OnlineOrder/modal_search_customer");
  74.         if(!empty($order->cart_id)){
  75.           $page_data['product_modal_url'] = dvore_base_url("admin/online-order/add/". $order->cart_id);
  76.         }else{
  77.           $page_data['product_modal_url'] = dvore_base_url("admin/online-order/add/new/". $order_id);
  78.         }
  79.        
  80.         $page_data['product_modal_status'] = 2;
  81.        
  82.         $page_data['order_id'] = (!empty($order_id)) ? $order_id : 0;
  83.         $page_data['sub_page_name'] = "add_v1/index";
  84.         $page_data['page_title'] = get_trad('order');
  85.         $page_data['custom_header'] = true;
  86.         $page_data['page_name'] = "order/index";
  87.         $this->load->view('admin', 'site/index', $page_data);
  88.   }
  89.  
  90.   function select_customer($cart_id) {
  91.         $page_data['form_action'] = base_url("a_Order/ajax_select_customer_to_cart/".$cart_id);
  92.         $page_data['all_customers'] = $this->Vore_core_model->getAllCustomer();
  93.         $page_data['sub_page_name'] = "select_customer";
  94.         $page_data['page_title'] = "#" . $order->id . " - <span>" . $order->date_added . "</span>";
  95.         $page_data['page_name'] = "order/index";
  96.         $page_data['custom_header'] = true;
  97.         $this->load->view('admin', 'site/index', $page_data);
  98.   }
  99.  
  100.   /**
  101.    *
  102.    * AJAX FUNCTION  
  103.    *  
  104.    */
  105.   function order_list_ajax($page) {
  106.         $result_by_page = 10;
  107.         $current_page = (!empty($page)) ? $page : 1;
  108.         $conditions = [];
  109.         if (!empty($_POST)) {
  110.           $conditions = $_POST;
  111.         }
  112.  
  113.         $orders = $this->Vore_order_model->getAllOrdersByLimit($result_by_page, $current_page, $conditions);
  114.         $page_data['orders'] = $orders;
  115.  
  116.         $this->load->view('admin', 'site/admin/order/ajax_list', $page_data);
  117.   }
  118.  
  119.   /**
  120.    *
  121.    * @para
  122.    *
  123.    * @return
  124.    */
  125.   public function ajax_create_cart() {
  126.         $insert_id = $this->Vore_order_model->DVORE_createBasicCart();
  127.         echo $insert_id;
  128.   }
  129.  
  130.   /**
  131.    *
  132.    * @para
  133.    *
  134.    * @return
  135.    */
  136.   public function ajax_select_customer_to_cart($cart_id) {
  137.         if($_POST['select_customer']){
  138.           $insert = $this->Vore_order_model->DVORE_selectCustomerToCart($cart_id, $_POST['select_customer'], 4);
  139.           if($insert == true){
  140.                 redirect("admin/order/add/" . $cart_id);
  141.           }
  142.         }
  143.        
  144.   }
  145.  
  146.   /**
  147.    * Delete cart item in order/cart
  148.    * @para $cart_id
  149.    *
  150.    * @return
  151.    */
  152.   public function ajax_delete_cart_item($cart_id) {
  153.         $row_id = $this->input->post('item_id');
  154.         $this->Vore_order_model->DVORE_delete_item_database_cart($cart_id, $row_id);
  155.   }
  156.  
  157.  
  158.   /**
  159.    * List categories in the order/add
  160.    * @para $cart_id
  161.    *
  162.    * @return
  163.    */
  164.   public function ajax_list_product_by_category($cart_id) {
  165.         if ($_POST['sub_category_id'] != "0") {
  166.           $all_products = $this->Vore_product_model->DVORE_getAllProductsByCategory_forOrders($_POST['category_id'], $_POST['sub_category_id']);
  167.         } else {
  168.           $all_products = $this->Vore_product_model->DVORE_getAllProductsByCategory_forOrders($_POST['category_id']);
  169.         }
  170.         $page_data['cart'] = $this->Vore_order_model->DVORE_getCartByID($cart_id);
  171.         $page_data['all_products'] = $all_products;
  172.         $this->load->view('admin', 'site/admin/order/add_ajax_list', $page_data);
  173.   }
  174.  
  175.   /**
  176.    * Add item inside the cart_details from order/add
  177.    * @para $cart_id
  178.    *
  179.    * @return
  180.    */
  181.   public function ajax_add_product_to_cart($cart_id) {
  182.         $product_id = $this->input->post("product_id");
  183.         $product_qty = $this->input->post("qty");
  184.  
  185.         $this->Vore_product_model->DVORE_addProductToCart($product_id, $product_qty, $cart_id);
  186.  
  187.         $cart = $this->Vore_order_model->DVORE_getCartByID($cart_id);
  188.         $i = 0;
  189.         foreach ($cart->cart_details as $key => $value) {
  190.           $i++;
  191.         }
  192.  
  193.         $data = [];
  194.         $data["i"] = $i;
  195.         $data['cart'] = $cart;
  196.  
  197.         echo json_encode($data);
  198.   }
  199.  
  200.   function ajax_order_change_cart_content($cart_id) {
  201.         $cart = $this->Vore_order_model->DVORE_getCartByID($cart_id);
  202.         $page_data['cart'] = $cart;
  203.         $page_data['cart_products'] = $cart->cart_details;
  204.         $this->load->view('admin', 'site/admin/order/cart_ajax_list', $page_data);
  205.   }
  206.  
  207.   /**
  208.    * Update cart quantity in order/cart
  209.    * @para $cart_id
  210.    *
  211.    * @return
  212.    */
  213.   function ajax_cart_update_quantity($cart_id) {
  214.         $qty = $this->input->post('value');
  215.         $row_id = $this->input->post('row_id');
  216.         if ($this->session->status == 1 || $this->session->status == 4) {
  217.           $this->Vore_order_model->update_item_database_cart($cart_id, $row_id, $qty);
  218. //          $this->ajax_cart_display($row_id);
  219.         }
  220.   }
  221.  
  222.   /**
  223.    * Update user shipping information
  224.    * @para $user_id
  225.    */
  226.   function ajax_update_order_shipping_info($user_address_id) {
  227.         if ($_POST) {
  228.           $this->Vore_order_model->DVORE_update_order_shipping_info($user_address_id, $_POST);
  229.         }
  230.   }
  231.  
  232.   /**
  233.    * Update user shipping information
  234.    * @para $user_id
  235.    */
  236.   function ajax_update_order_billing_info($user_payment_id) {
  237.  
  238.         if ($_POST) {
  239.           $this->Vore_order_model->DVORE_update_order_billing_info($user_payment_id, $_POST);
  240.         }
  241.   }
  242.  
  243.   function ajax_order_checkout_update_cart($cart_id) {
  244.         $cart = $this->Vore_order_model->DVORE_getCartByID($cart_id);
  245.         if ($_POST) {
  246.           $this->Vore_order_model->DVORE_update_order_cart_info($cart_id, $_POST, $cart->user_id);
  247.         }
  248.   }
  249.  
  250.   function ajax_send_final_step($cart_id) {
  251.         $cart = $this->Vore_order_model->DVORE_getCartByID($cart_id);
  252.         if (!empty($cart)) {
  253.           $this->Vore_order_model->DVORE_create_order_sale($cart);
  254.         }
  255.   }
  256.  
  257.   function ajax_delete_order(){
  258.         if(!empty($this->input->post("id"))){
  259.           $update_data = [];
  260.           $update_data['status'] = -1;
  261.          
  262.           $this->db->where("id", $this->input->post("id"));
  263.           $this->db->update("VORE_SHOP_sale", $update_data);
  264.         }
  265.   }
  266.  
  267.   function modal_search_product(){
  268.         $page_data['modal_folder'] = "admin/";
  269.         $page_data['modal_file'] = "_order_search_product";
  270.  
  271.         $this->load->view("admin", "modal/index", $page_data);
  272.   }
  273.  
  274.   function modal_search_customer(){
  275.         $page_data['modal_folder'] = "admin/";
  276.         $page_data['modal_file'] = "_order_search_customer";
  277.         $page_data['modal_footer'] = "none";
  278.         $page_data['ajax_url'] = base_url("a_Order/ajax_search_customer_by_id");
  279.         $page_data['customers'] = $this->Vore_order_model->DVORE_searchCustomerAll();
  280.  
  281.         $this->load->view("admin", "modal/index", $page_data);
  282.   }
  283.  
  284.   function new_order($order_id){
  285.         $this->load->model("Vore_customer_model");
  286.         if(!empty($order_id)){
  287.           $order = $this->Vore_order_model->getOrderById($order_id);
  288.           $page_data['order'] = $order;
  289.         }
  290.        
  291.         $page_data['all_order_status'] = $this->Vore_order_model->getAllOrderStatus();
  292.         $page_data['order_id'] = (!empty($order_id)) ? $order_id : 0;
  293.         $page_data['client_modal_url'] = dvore_base_url("a_OnlineOrder/modal_search_customer");
  294.         $page_data['product_modal_url'] = dvore_base_url("a_Order/modal_search_product");
  295.         $page_data['product_modal_status'] = 1;
  296.         $page_data['sub_page_name'] = "add_v1/index";
  297.         $page_data['page_title'] = get_trad('create_order');
  298.         $page_data['custom_header'] = true;
  299.         $page_data['page_name'] = "order/index";
  300.         $this->load->view('admin', 'site/index', $page_data);
  301.   }
  302.  
  303.   // CUSTOMER
  304.   function ajax_search_customer_list(){
  305.         $value = $this->input->post("value");
  306.         $data = [];
  307.        
  308.         if(!empty($value)){
  309.           $object = $this->Vore_order_model->DVORE_searchCustomer($value);
  310.           $data['customers'] = $object;
  311.         }
  312.        
  313.         $this->load->view('admin', 'site/admin/order/add_v1/ajax_search_customer_list', $data);
  314.   }
  315.  
  316.   function ajax_search_customer_by_id(){
  317.         $id = $this->input->post("user_id");
  318.         $data = [];
  319.        
  320.         if(!empty($id)){
  321.           $object = $this->Vore_order_model->getCustomerById($id);
  322.           $data['customer'] = $object;
  323.         }
  324.        
  325.         $this->load->view('admin', 'site/admin/order/add_v1/ajax_search_customer_result', $data);
  326.   }
  327.  
  328.   // PRODUCT
  329.   function ajax_search_product_list(){
  330.         $value = $this->input->post("value");
  331.         $data = [];
  332.        
  333.         if(!empty($value)){
  334.           $object = $this->Vore_order_model->DVORE_searchProduct($value);
  335.           $data['products'] = $object;
  336.         }
  337.        
  338.         $this->load->view('admin', 'site/admin/order/add_v1/ajax_search_product_list', $data);
  339.   }
  340.   function ajax_search_product_by_id(){
  341.         $id = $this->input->post("product_id");
  342.         $order_id = $this->input->post("order_id");
  343.         $data = [];
  344.         if(!empty($id)){
  345.           $object = $this->Vore_order_model->DVORE_searchProductById($id, $order_id);
  346.         }
  347.         if(is_object($object)){
  348.           $data['product'] = $object;
  349.           $this->load->view('admin', 'site/admin/order/add_v1/ajax_search_product_result', $data);
  350.         }else{
  351.           echo $id;
  352.         }
  353.   }
  354.  
  355.   function ajax_update_order_modification(){
  356.         $order_id = $this->input->post("order_id");
  357.         $data = [];
  358.         $data['status'] = "failed";
  359.        
  360.         if($order_id == 0){ // create
  361.           $insert_id = $this->Vore_order_model->DVORE_createOrder();
  362.           $data['status'] = "created";
  363.           $data['order_id'] = $insert_id;
  364.         }else{ // update
  365.           $this->Vore_order_model->DVORE_updateOrder();
  366.           $data['status'] = "updated";
  367.         }
  368.        
  369.         echo json_encode($data);
  370.   }
  371.  
  372.   function ajax_update_order_customer(){
  373.         $user_id = $this->input->post("user_id");
  374.         $order_id = $this->input->post("order_id");
  375.        
  376.         if(!empty($user_id)){
  377.           if($order_id == 0){
  378.                 $insert_id = $this->Vore_order_model->DVORE_createOrder();
  379.                 $new_order_id = $insert_id;
  380.           }else{
  381.                 $new_order_id = $order_id;
  382.           }
  383.           $this->Vore_order_model->DVORE_updateOrderCustomer($new_order_id, $user_id);
  384.         }
  385.         echo $new_order_id;
  386.   }
  387.  
  388.   function ajax_update_order_product(){
  389.         $product_id = $this->input->post("product_id");
  390.         $order_id = $this->input->post("order_id");
  391.         $qty = (!empty($this->input->post("qty"))) ? $this->input->post("qty") : 1;
  392.         if(!empty($product_id)){
  393.           if($order_id == 0){
  394.                 $insert_id = $this->Vore_order_model->DVORE_createOrder();
  395.                 $new_order_id = $insert_id;
  396.           }else{
  397.                 $new_order_id = $order_id;
  398.           }
  399.           $this->Vore_order_model->DVORE_updateOrderProducts($new_order_id, $product_id, $qty);
  400.         }
  401.         echo $new_order_id;
  402.   }
  403.  
  404.   function ajax_delete_order_product($order_id, $row_id) {
  405.         $this->Vore_order_model->delete_order_product_item($order_id, $row_id);
  406.   }
  407.  
  408.   function ajax_save_products_qty(){
  409.         $products_object = (!empty($this->input->post("products_object"))) ? $this->input->post("products_object") : false;
  410.         $order_id = (!empty($this->input->post("order_id"))) ? $this->input->post("order_id") : false;
  411.        
  412.         if(!empty($products_object) && !empty($order_id)){
  413.           $msg = $this->Vore_order_model->DVORE_changeOrderProductsQty($order_id, $products_object);
  414.         }else{
  415.           $msg = "failed";
  416.         }
  417.         echo $msg;
  418.   }
  419.  
  420.   function ajax_change_payment_status(){
  421.         $payment_status = (!empty($this->input->post("payment_status"))) ? $this->input->post("payment_status") : false;
  422.         $order_id = (!empty($this->input->post("order_id"))) ? $this->input->post("order_id") : false;
  423.        
  424.         if(!empty($payment_status) && !empty($order_id)){
  425.           $status_name = $this->Vore_order_model->DVORE_changePaymentStatus($order_id, $payment_status);
  426.         }
  427.         echo $status_name;
  428.   }
  429.  
  430.   function order_notes_ajax() {
  431.         if (!empty($_POST)) {
  432.           $this->Vore_order_model->DVORE_orderUpdateNotes($_POST);
  433.         }
  434.   }
  435.  
  436. }
  437.