MOON
Server: Apache
System: Linux nserver.cafsindia.com 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: cafsindia (1002)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: /home/cafsindia/ntc_cafsinfotech_in_bk/application/controllers/Order_dispatch.php
<?php if ( ! defined('BASEPATH')) exit('No direct script is allowed');
require_once("Base_controller.php");
class Order_dispatch  extends Base_controller{	
	public $control_name;
	public function __construct(){
		parent::__construct('order_dispatch');
		if(!$this->Appconfig->isAppvalid()){
			redirect('config');
		}
		$this->control_name = strtolower($this->router->fetch_class());
		$cart_data      = $this->session->userdata('cart_data');
		if(!$cart_data){
			$cart_data = array();
			$this->session->set_userdata('cart_data', $cart_data);
			$cart_data    = $this->session->userdata('cart_data');
		}
	}

	// LOAD PAGE WITH TABLE DATA
	public function index(){
		$data['list_view'] = $this->get_cart_view();
		$this->load->view("$this->control_name/manage",$data);
	}
	
	//LOAD MODEL PAGE VIEW WITH DATA
	public function view($form_view_id=-1){
		$data[] = "";		
		$this->load->view("$this->control_name/form",$data);
	}
	
	//IMPORT FILE VIEW INFORMATION
	public function import(){
		$data['module_id']     = $this->control_name;		
		$excel_format_qry = 'select prime_excel_format_id,excel_name from cw_util_excel_format where excel_module_id = "'.$this->control_name.'" and trans_status = 1';
		$excel_format   = $this->db->query("CALL sp_a_run ('SELECT','$excel_format_qry')");
		$excel_result    = $excel_format->result();
		$excel_format->next_result();
		$excel_format_drop[""] = "---- Excel Format ----";
		foreach($excel_result as $excel){
			$prime_excel_format_id = $excel->prime_excel_format_id;
			$excel_name            = $excel->excel_name;
			$excel_format_drop[$prime_excel_format_id] = $excel_name;
		}
		$data['excel_format_drop'] = $excel_format_drop;		
		$this->load->view("$this->control_name/import",$data);
	}
	
	//Product Search Auto complete
	public function item_search(){
		$search_by       = (int)$this->input->post_get('search_by');
		$search_product  = $this->input->post_get('search_product');
		if($search_by === 1){
			$this->db->select('prime_warehouse_product_id,product_name,warehouse_brand.brand_name as brand');
			$this->db->from('warehouse_product');
			$this->db->join('warehouse_brand','warehouse_brand.prime_warehouse_brand_id = warehouse_product.brand_name');
			$this->db->join('customer','customer.prime_customer_id = warehouse_product.customer_name');
			$this->db->where('warehouse_product.trans_status', 1);
			$this->db->group_start();
				$this->db->like('product_name',$search_product);
				$this->db->or_like('warehouse_brand.brand_name',$search_product);
			$this->db->group_end();	
			$search_info = $this->db->get()->result();
			foreach($search_info as $search){
				$prime_warehouse_product_id = $search->prime_warehouse_product_id;
				$product_name            = $search->product_name;
				$brand_name              = $search->brand;
				$label = "$product_name  - $brand_name";
				$suggestions[] = array('value'=>$prime_warehouse_product_id,'label'=>$label,'search_by'=>$search_by);
			}
			if(empty($suggestions)){
				$suggestions[] = array('value' => "0", 'label' => "No data found for this search");
			}			
		}else
		if($search_by === 2){
			$this->db->select('prime_customer_request_id,cust_req_no,customer.customer_name as customer');
			$this->db->from('customer_request');
			$this->db->join('customer','customer.prime_customer_id = customer_request.customer_name');
			$this->db->where('customer_request.trans_status', 1);
			$this->db->where('customer_request.request_mode', 2);
			$this->db->where('customer_request.status', 1);
			$this->db->group_start();
				$this->db->like('cust_req_no',$search_product);
			$this->db->group_end();
			$search_info = $this->db->get()->result();
			foreach($search_info as $search_rslt){
				$prime_customer_request_id = $search_rslt->prime_customer_request_id;
				$cust_req_no               = $search_rslt->cust_req_no;
				$customer                  = $search_rslt->customer;
				$label                     = "$cust_req_no - $customer";
				$suggestions[] = array('value'=>$cust_req_no,'label'=>$label,'search_by'=>$search_by);
			}
			if(empty($suggestions)){
				$suggestions[] = array('value' => "0", 'label' => "No data found for this search");
			}
		}
		echo json_encode($suggestions);
	}
	public function add_products(){
		$cart_data          = $this->session->userdata('cart_data');
		$search_by          = (int)$this->input->post('search_by');
		$search_product     = $this->input->post('search_product');
		$cart_data['error'] = array();
		if($search_by === 1){
			$this->db->select('prime_warehouse_product_id,warehouse_product.product_type,product_name,warehouse_brand.brand_name as brand');
			$this->db->from('warehouse_product');
			$this->db->join('warehouse_brand','warehouse_brand.prime_warehouse_brand_id = warehouse_product.brand_name');
			$this->db->join('customer','customer.prime_customer_id = warehouse_product.customer_name');
			$this->db->where('warehouse_product.trans_status', 1);
			$this->db->where('prime_warehouse_product_id',$search_product);
			$search_info = $this->db->get()->row();
			$prime_warehouse_product_id = $search_info->prime_warehouse_product_id;
			$product_name            = $search_info->product_name;
			$product_type            = $search_info->product_type;
			$brand_name              = $search_info->brand;
			if(!$cart_data['order_info'][$prime_warehouse_product_id]){
				$cart_data['order_info'][$prime_warehouse_product_id] = array('product_id'=>$prime_warehouse_product_id,'product_name'=>$product_name,'brand_name'=>$brand_name,'product_type' => '','packing_type'=>"",'repacking'=>"",'warehouse_name'=>"",'location'=>"",'location_space'=>"",'batch_no'=>"",'stock_expiry_date'=>"",'price'=>0,'quantity'=>1);
			}else{
				// updated for cart array
				$cart_quantity = (int)$cart_data['order_info'][$prime_warehouse_product_id]['quantity']+1;
				$cart_data['order_info'][$prime_warehouse_product_id] = array('product_id'=>$prime_warehouse_product_id,'product_name'=>$product_name,'product_type' => '','brand_name'=>$brand_name,'packing_type'=>"",'repacking'=>"",'warehouse_name'=>"",'location'=>"",'location_space'=>"",'batch_no'=>"",'stock_expiry_date'=>"",'price'=>0,'quantity'=>$cart_quantity);
			}
		}else
		if($search_by === 2){
			$this->db->select('*,customer.customer_name as customer_name');
			$this->db->from('customer_request');
			$this->db->join('customer','customer.prime_customer_id = customer_request.customer_name');
			$this->db->where('customer_request.trans_status', 1);
			$this->db->where('cust_req_no',$search_product);
			$cust_info = $this->db->get()->row();
			$request_id        = $cust_info->prime_customer_request_id;
			$prime_customer_id = $cust_info->prime_customer_id;
			$cust_req_no       = $cust_info->cust_req_no;
			$customer_name     = $cust_info->customer_name;
			$from_date         = $cust_info->from_date;
			$to_date           = $cust_info->to_date;
			$pickup_location   = $cust_info->pickup_location;
			$pickup_landmark   = $cust_info->pickup_landmark;
			$pickup_time       = $cust_info->pickup_time;
			$can_process = false;
			if((int)$request_id > 0){
				if(!$cart_data['cust_req'][$cust_req_no]){					
					$cart_data['cust_req'][$cust_req_no] = $cust_req_no;
					$can_process = true;
				}else{
					$cart_data['error'][] = "Adding same request numbers"; 
					$can_process = false;
				}				
				if(!$cart_data['cust_info']){
					$cart_data['cust_info'] = array('prime_customer_id'=>$prime_customer_id,'customer_name'=>$customer_name,'from_date'=>$from_date,'to_date'=>$to_date,'pickup_location'=>$pickup_location,'pickup_landmark'=>$pickup_landmark,'pickup_time'=>$pickup_time,);
					$can_process = true;
				}else{
					$chk_customer_id = $cart_data['cust_info']['prime_customer_id'];
					if((int)$chk_customer_id !== (int)$prime_customer_id){
						$cart_data['error'][] = "Add Same request numbers from same customer"; 
						$can_process = false;
					}else{
						$can_process = true;
					}
				}		
			}
			if($can_process){
				$this->db->select('warehouse_product.prime_warehouse_product_id,warehouse_product.product_type,warehouse_product.product_name,warehouse_brand.brand_name, customer_request_product_information.quantity as quantity');
				$this->db->from('customer_request_product_information');
				$this->db->join('warehouse_product','warehouse_product.prime_warehouse_product_id = customer_request_product_information.product');
				$this->db->join('warehouse_brand','warehouse_brand.prime_warehouse_brand_id = warehouse_product.brand_name');
				$this->db->where('customer_request_product_information.trans_status', 1);
				$this->db->where('prime_customer_request_id',$request_id);
				$product_info = $this->db->get()->result();
				foreach($product_info  as $product){
					$product_id    = $product->prime_warehouse_product_id;
					$product_name  = $product->product_name;
					$brand_name    = $product->brand_name;
					$product_type  = $product->product_type;
					$db_quantity   = $product->quantity;
					
					if(!$cart_data['order_info'][$product_id]){
					$cart_data['order_info'][$product_id] = array('product_id'=>$product_id,'product_name'=>$product_name,'brand_name'=>$brand_name,'packing_type'=>"",'product_type'=>'','repacking'=>"",'warehouse_name'=>"",'location'=>"",'location_space'=>"",'batch_no'=>"",'stock_expiry_date'=>"",'price'=>0,'quantity'=>$db_quantity);
					}else{
						$quantity     = $cart_data['order_info'][$product_id]['quantity'];
						$db_quantity  = $db_quantity + $quantity;
						$cart_data['order_info'][$product_id] = array('product_id'=>$product_id,'product_name'=>$product_name,'brand_name'=>$brand_name,'packing_type'=>"",'product_type'=>'','repacking'=>"",'warehouse_name'=>"",'location'=>"",'location_space'=>"",'batch_no'=>"",'stock_expiry_date'=>"",'price'=>0,'quantity'=>$db_quantity);
					}
				}
			}
		}
		$this->session->set_userdata('cart_data', $cart_data);
		$cart_view          = $this->get_cart_view();
		$cart_data          = $this->session->userdata('cart_data');
		echo json_encode(array('cart_view'=>$cart_view,'error'=>$cart_data['error']),JSON_FORCE_OBJECT);
	}
	//SAVE RECEIVED ORDERS TO DB
	public function get_cart_view(){
		$cart_data = $this->session->userdata('cart_data');
		$this->db->select('cw_zct_19_id,cw_zct_19_value');
		$this->db->from('zct_19');
		$this->db->where('zct_19.cw_zct_19_status', 1);
		$product_type_list = $this->db->get()->result();		
		$this->db->select('prime_warehouse_information_id,warehouse_name');
		$this->db->from('warehouse_information');
		$this->db->where('warehouse_information.trans_status', 1);
		$warehouse_rslt = $this->db->get()->result();
		$tr_line = "";
		foreach(array_reverse($cart_data['order_info']) as $data){
			$prime_id         = $data['product_id'];
			$product_name     = $data['product_name'];
			$brand_name       = $data['brand_name'];
			$packing_type     = $data['packing_type'];
			$product_type     = $data['product_type'];
			$repacking        = $data['repacking'];
			$warehouse_name   = $data['warehouse_name'];
			$location         = $data['location'];
			$location_space   = $data['location_space'];
			$batch_no         = $data['batch_no'];
			$stock_expiry_date= $data['stock_expiry_date'];	
			$price            = $data['price'];	
			$quantity         = $data['quantity'];		
			if(!$stock_expiry_date){
				$stock_expiry_date = "";
			}	
			if($repacking === "1"){
				$yes_selected = "selected";
			}else
			if($repacking === "2"){
				$no_selected = "selected";
			}else{
				$yes_selected = "";
				$no_selected = "";
			}
			$product_line     = "<option value=''>--Select--</option>";
			$warehouse_line   = "<option value=''>--Select--</option>";
			$location_line    = "<option value=''>--Select--</option>";
			
			foreach($product_type_list as $product_list){
				$cw_zct_19_id 	   = $product_list->cw_zct_19_id;
			    $product_type_name = $product_list->cw_zct_19_value;
			    if($product_type === $cw_zct_19_id){
					$pro_selected = "selected";
				}else{
					$pro_selected = "";
				}
				$product_line .="<option value='$cw_zct_19_id' $pro_selected>$product_type_name</option>";
			}

			foreach($warehouse_rslt as $warehouse_info){
				$prime_warehouse_information_id = $warehouse_info->prime_warehouse_information_id;				
				$warehouse                      = $warehouse_info->warehouse_name;
				if($warehouse_name === $prime_warehouse_information_id){
					$ware_selected = "selected";
				}else{
					$ware_selected = "";
				}
				$warehouse_line .="<option value='$prime_warehouse_information_id' $ware_selected>$warehouse</option>";
			}

			$this->db->select('prime_warehouse_locations_id,floor_number,zct_21.cw_zct_21_value as location');
			$this->db->from('warehouse_locations');
			$this->db->join('zct_21','zct_21.cw_zct_21_id = warehouse_locations.bin_or_floor_location');
			$this->db->where('warehouse_locations.trans_status', 1);
			$this->db->where('warehouse_locations.warehouse_name',$warehouse_name);
			$warehouse_location_rslt = $this->db->get()->result();
			foreach($warehouse_location_rslt as $location_info){
				$prime_warehouse_locations_id = $location_info->prime_warehouse_locations_id;
				$location_name                = $location_info->floor_number." - ".$location_info->location;
				if($location === $prime_warehouse_locations_id){
					$location_selected = "selected";
				}else{
					$location_selected = "";
				}
				$location_line .="<option value='$prime_warehouse_locations_id' $location_selected>$location_name</option>";
			}

			$tr_line .= "<tr id='tr_data'>
							<td>
								$product_name <br/>$brand_name
								<input type='hidden' name='product_id[]' id='product_id_$prime_id' value='$prime_id'>
								<input type='hidden' name='product_name[]' id='product_name_$prime_id' value='$product_name'>
								<input type='hidden' name='brand_name[]' id='brand_name_$prime_id' value='$brand_name'>
								<input type='hidden' name='packing_type[]' id='packing_type_$prime_id' value='$packing_type'>
							</td>
							<td>
								<select name='product_type[]' id='product_type_$prime_id' onchange=get_packing_type('$prime_id')>
									$product_line
								</select>
							</td>
							<td>
								<select name='repacking[]' id='repacking_$prime_id' onchange=update_product('$prime_id');>
									<option value=''>--Select--</option>
										<option value='1' $yes_selected>Yes</option>
										<option value='2' $no_selected>No</option>
								</select>
							</td>
							<td>
								<select name='warehouse_name[]' id='warehouse_name_$prime_id' onchange=get_warehouse_info('$prime_id')>
									$warehouse_line
								</select>
							</td>
							<td>
								<select name='location[]' id='location_$prime_id' onchange=update_product('$prime_id');>
									$location_line
								</select>
							</td>
							<td>
								<input name='location_space[]' id='location_space_$prime_id'' value='$location_space' style='width:100px;' onchange=update_product('$prime_id');>
							</td>
							<td>
								<input name='batch_no[]' id='batch_no_$prime_id'' value='$batch_no' class='number' style='width:100px;' onchange=update_product('$prime_id');>
							</td>
							<td>
								<input name='stock_expiry_date[]' id='stock_expiry_date_$prime_id' value='$stock_expiry_date' class='datepicker' style='width:100px;'>
							</td>
							<td>
								<input name='price[]' id='price_$prime_id'' value='$price' class='number' style='width:100px;' onchange=update_product('$prime_id');>
							</td>
							<td>
								<input name='quantity[]' id='quantity_$prime_id' value='$quantity' class='number' style='width:100px;' onchange=update_product('$prime_id');>
							</td>							
						</tr>";
						/*
							<td>
								<button type='button' class='btn btn-edit btn-xs btn_action' id='update_product_$prime_id' onclick=update_product('$prime_id');><i class='fa fa-pencil-square-o fa-large' aria-hidden='true'></i> Update</button>
							</td>
						*/
		}		
		$cust_info         = $cart_data['cust_info'];
		$customer_name     = $cust_info['customer_name'];	
		$prime_customer_id = $cust_info['prime_customer_id'];
		$cart_content = "<h4 class='tab_head' style='margin:8px 0px;'>Product List</h4>
							<input name='prime_customer_id' id='prime_customer_id' value='$prime_customer_id' onchange=check_prime_id(); type='hidden'>	
							<table class='table table-striped'>
								<thead>
									<tr>
										<td>Product</td>
										<td>Type</td>
										<td>Repacking</td>
										<td>Warehouse</td>
										<td>Location</td>
										<td>Location Space</td>
										<td>Batch No</td>
										<td>Stock Expiry Date</td>
										<td>Value</td>
										<td>Qty.</td>
									</tr>
								</thead>
								<tbody>
									$tr_line
								</tbody>
					 		</table>";
		if($cust_info['from_date']){
			$from_date  = date('d-m-Y',strtotime($cust_info['from_date']));
		}else{
			$from_date  = '';
		}
		if($cust_info['to_date']){
			$to_date  = date('d-m-Y',strtotime($cust_info['to_date']));
		}else{
			$to_date  = '';
		}
		if($cust_info['pickup_time']){
			$pickup_time  = date('d-m-Y h:m:s',strtotime($cust_info['pickup_time']));
		}else{
			$pickup_time  = '';
		}
		$pickup_location  = $cust_info['pickup_location'];
		$pickup_landmark  = $cust_info['pickup_landmark'];
		$cust_content = "<table class='table' style='background-color:#ffffff;'>
							<tr>
								<td style='padding:4px;'><span style='color: #4e5b9a; font-size: 12px; font-weight: bold;'>Customer Name</span><br/>$customer_name</td>
								<td style='padding:4px;'><span style='color: #4e5b9a; font-size: 12px; font-weight: bold;'>From date</span><br/>$from_date</td>
								<td style='padding:4px;'><span style='color: #4e5b9a; font-size: 12px; font-weight: bold;'>To date</span><br/>$to_date</td>
							</tr>
							<tr>
								<td style='padding:4px;'><span style='color: #4e5b9a; font-size: 12px; font-weight: bold;'>Loaction</span><br/>$pickup_location</td>
								<td style='padding:4px;'><span style='color: #4e5b9a; font-size: 12px; font-weight: bold;'>Landmark</span><br/>$pickup_landmark</td>
								<td style='padding:4px;'><span style='color: #4e5b9a; font-size: 12px; font-weight: bold;'>Time</span><br/>$pickup_time</td>
							</tr>
						</table>";
		return array('cust_content'=>$cust_content,'cart_content'=>$cart_content);
	}
	/****************** CART OPERATION  - END ***********************/
	public function save_order_dispatch(){
		$cart_data         = $this->session->userdata('cart_data');		
		$cust_info         = $cart_data['cust_info'];
		$prime_customer_id = $cust_info['prime_customer_id'];
		$table_content     = $this->get_cart_view();
		if((int)$prime_customer_id > 0){
			$sku_no            = $this->unique_code($code="ODR");
			$dispatch_data = array(
				'sku_no'         => $sku_no,
				'customer_id'    => $prime_customer_id,
				'dispatch_date'  => date("Y-m-d H:i:s"),
			);
			$dispatch_data['trans_created_by']   = $this->session->userdata('logged_id');
			$dispatch_data['trans_created_date'] = date("Y-m-d H:i:s");
			$this->db->insert('cw_order_dispatch',$dispatch_data);
			$order_dispatch_id = $this->db->insert_id();
			$product_info = $cart_data['order_info'];		
			$count             = count($product_id);
			foreach ($product_info as $key => $value) {
				$product_type = $value['product_type'];
				if((int)$product_type === 1){
					$pack_type = "tonnes";
				}else
				if((int)$product_type === 4){
					$pack_type = "temperature";
				}else{
					$pack_type = "tonnes";
				}
				
				$this->db->from('warehouse_product');
				$this->db->where('warehouse_product.trans_status', 1);
				$this->db->where('warehouse_product.prime_warehouse_product_id', $value['product_id']);
				$avail_qty = $this->db->get()->row();
				$availabale_quantity = $avail_qty->availabale_quantity;
				$total_quantity = $availabale_quantity - $value['quantity'];
				$upd_qty  = array(
					'availabale_quantity' => $total_quantity,
					'trans_created_by'    => $this->session->userdata('logged_id'),
					'trans_created_date'  => date("Y-m-d H:i:s")
				);
				
				$product_data  = array(
					'order_dispatch_id'  => $order_dispatch_id,
					'product_id'         => $value['product_id'],
					$pack_type           =>	$value['packing_type'],
					'product_type'       => $value['product_type'],	
					'stock_expiry_date'  => $value['stock_expiry_date'],
					'repacking'          => $value['repacking'],
					'warehouse_name'     => $value['warehouse_name'],
					'location'           => $value['location'],
					'location_space'     => $value['location_space'],
					'batch_no'           => $value['batch_no'],
					'price'              => $value['price'],
					'quantity'           => $value['quantity']
				);
				$product_data['trans_created_by'] = $this->session->userdata('logged_id');
				$product_data['trans_created_date'] = date("Y-m-d H:i:s");
				$insert_data = $this->db->insert('cw_product_dispatch',$product_data);	
				
				$this->db->where('prime_warehouse_product_id',$value['product_id']);
				$this->db->update('cw_warehouse_product',$upd_qty);
			}
			$cust_req_array    = $cart_data['cust_req'];
			foreach ($cust_req_array as $key => $value) {
				$this->db->where('cust_req_no',$key);
				$update_data = $this->db->update('customer_request',array('status'=>2));
			}
			$cart_data = array();
			$this->session->set_userdata('cart_data',$cart_data);
			$cart_data      = $this->session->userdata('cart_data');
			$table_content  = $this->get_cart_view();
			
			if($insert_data){
				echo json_encode(array('success'=>true,'message'=>'Order Created Successfully','table_content'=>$table_content));
			}else{
				echo json_encode(array('success'=>false,'message'=>'Please Try After Sometime','table_content'=>$table_content));
			}
		}else{
			echo json_encode(array('success'=>false,'message'=>'Please add customer and try Again','table_content'=>$table_content));
		}
		
	}
	//UPDATE PRODUCT TO CART
	public function update_product(){
		$product_id         = (int)trim($this->input->post('product_id'));
		$product_name       = $this->input->post('product_name');
		$brand_name         = $this->input->post('brand_name');
		$packing_type       = $this->input->post('packing_type');
		$product_type       = $this->input->post('product_type');
		$repacking          = $this->input->post('repacking');
		$warehouse_name     = $this->input->post('warehouse_name');
		$location           = $this->input->post('location');
		$location_space     = $this->input->post('location_space');
		$batch_no      		= $this->input->post('batch_no');
		$stock_expiry_date  = $this->input->post('stock_expiry_date');
		$price     			= $this->input->post('price');
		$quantity           = $this->input->post('quantity');
		$cart_data          = $this->session->userdata('cart_data');
		if(!$stock_expiry_date || $stock_expiry_date === "01-01-1970" || $stock_expiry_date === ""){
			$stock_expiry_date = "";
		}		
		if($cart_data['order_info'][$product_id]){
			$cart_data['order_info'][$product_id] = array('product_id'=>$product_id,'product_name'=>$product_name,'brand_name'=>$brand_name,'packing_type'=>$packing_type,'product_type'=>$product_type,'repacking'=>$repacking,'warehouse_name'=>$warehouse_name,'location'=>$location,'location_space'=>$location_space,'batch_no'=>$batch_no,'stock_expiry_date'=>$stock_expiry_date,'price'=>$price,'quantity'=>$quantity);
		}
		$this->session->set_userdata('cart_data', $cart_data);
		$cart_view = $this->get_cart_view();
		echo json_encode(array('cart_view'=>$cart_view));
	}
	
	public function get_warehouse_info(){
		$warehouse_name = $this->input->post('warehouse_name');
		$this->db->select('prime_warehouse_locations_id,floor_number,zct_21.cw_zct_21_value as location');
		$this->db->from('warehouse_locations');
		$this->db->join('zct_21','zct_21.cw_zct_21_id = warehouse_locations.bin_or_floor_location');
		$this->db->where('warehouse_locations.trans_status', 1);
		$this->db->where('warehouse_locations.warehouse_name',$warehouse_name);
		$warehouse_rslt = $this->db->get()->result();
		foreach($warehouse_rslt as $location_info){
			$prime_warehouse_locations_id = $location_info->prime_warehouse_locations_id;
			$location                     = $location_info->floor_number." - ".$location_info->location;
			$get_warehouse_info[$prime_warehouse_locations_id] = $location;
		}
		echo json_encode(array('sts'=>true,'get_warehouse_info' => $get_warehouse_info));
	}
	
	public function cancel_order(){
		$cart_data = array();
		$this->session->set_userdata('cart_data',$cart_data);
		echo json_encode(array('sts'=>true,'message'=>"Product removed successfully"));
	}
	
	//CHECK QUANTITY AVAILABLITY
	public function check_quantity(){
		$product      = (int)$this->input->post('product');
		$quantity     = (int)$this->input->post('quantity');
		if($this->product_exists($product, TRUE)){
			$remaining_quantity = (int)$this->availabile_product($product);
			if((int)$remaining_quantity >= $quantity){
				echo json_encode(array('success' => TRUE));
			}else{
				$cart_data = $this->session->userdata('cart_data');
				if($cart_data['order_info'][$product]){
					$cart_data['order_info'][$product]['quantity'] = $remaining_quantity;
				}
				$this->session->set_userdata('cart_data', $cart_data);
				echo json_encode(array('success' => FALSE, 'message' => "Quantity Not Available in Warehouse.. Available Quantity is $remaining_quantity",'remaining_quantity' => $remaining_quantity));
			}
		}else{
			echo json_encode(array('success' => FALSE, 'message' => "Product Doesn't exists"));
		}
	}
	
	//GET AVAILABLE PRODUCT
	public function availabile_product($product){
		$this->db->select('IFNULL(cw_warehouse_product.availabale_quantity, 0) as quantity');
		$this->db->from('cw_warehouse_product');
		$this->db->where('cw_warehouse_product.prime_warehouse_product_id', $product);
		$this->db->where('cw_warehouse_product.trans_status', 1);
		$availabile_product_info       = $this->db->get();
		$availabile_product            = $availabile_product_info->result();
		return $availabile_product[0]->quantity;
	}
	
	//CHECKING PRODUCT IS EXISTS
	public function product_exists($product){
		$this->db->select('count(*) as count');
		$this->db->from('warehouse_product');
		$this->db->where('prime_warehouse_product_id', (int)$product);
		$this->db->where('trans_status',1);
		$count = $this->db->get()->result();
		$count = (int)$count[0]->count;
		if($count > 0){
			return TRUE;
		}else{	
			return FALSE;
		}
	}
}
?>