Commit 8f8b9ad9 by Jansa Jose

daily commit

parent 238e55f8
......@@ -41,5 +41,17 @@ class Orders extends CI_Controller {
}
echo json_encode($return_arr);exit;
}
public function changeOrderStatus(){
$status = 0;
$return_arr = array('status'=>'0');
if(!isset($_POST) || empty($_POST) || !isset($_POST['order_id']) || empty($_POST['order_id']) || empty(decode_param($_POST['order_id']))){
echo json_encode($return_arr);exit;
}
$status = $this->Order_model->changeOrderStatus($_POST);
$return_arr['status'] = $status;
echo json_encode($return_arr);exit;
}
}
?>
\ No newline at end of file
......@@ -1515,7 +1515,7 @@
public function orderPlacedSuccess($ref=''){
$settings = getSettings();
$url = $settings['web_url']."/track?status=success&ref=".$ref;
$url = $settings['web_url']."/track?ref=".$ref;
header("Location: ".$url);
}
......@@ -1526,8 +1526,52 @@
$post = file_get_contents("php://input");
$postData = json_decode($post,true);
$result = $this->Webservice_model->productSearch($postData);
echo json_encode($result);exit;
$total = 0;
$per_page = 10;
$page = (isset($postData['page']) && $postData['page'] != 1) ?$postData['page'] :'1';
$page_limit = ($page - 1) * $per_page;
$result = $this->Webservice_model->productSearch($postData,0,0);
$prodList = $this->Webservice_model->productSearch($postData,$page_limit,$per_page);
if($result['status'] == 'success'){
$total = count($result['data']);
}
if($total >= $per_page){
$totalPages = (int)($total%$per_page == 0?$total/$per_page:($total/$per_page)+1);
}
else{
$totalPages = 1;
}
if($prodList['status'] == 'success'){
$respArr = array(
'status' => 'success',
'message'=>'success',
'data' => $prodList['data'],
'meta' => array(
'total_pages' => $totalPages,
'total' => $total,
'current_page' => ($page == 0)?1:$page,
'per_page' => $per_page
)
);
}else{
$respArr = array(
'status' => 'error',
'message'=>'No data',
'data' => [],
'meta' => array(
'total_pages' => $totalPages,
'total' => $total,
'current_page' => ($page == 0)?1:$page,
'per_page' => $per_page
)
);
}
echo json_encode($respArr);exit;
}
//Get Brands
......@@ -1644,6 +1688,379 @@
$result = $this->Webservice_model->rateProduct($postData);
echo json_encode($result);exit;
}
public function get_latest_product_list(){
header('Content-type:application/json');
$headers = apache_request_headers();
if(!isset($headers['Auth']) || empty($headers['Auth'])){
$respArr['status'] = 'error';
$respArr['message'] = 'Authtoken is Required';
echo json_encode($respArr);exit;
}
$authRes = $this->Webservice_model->get_customer_authtoken($headers['Auth']);
if($authRes['status'] == 'error'){
echo json_encode($authRes);exit;
}
$per_page = 10;
$page = (isset($_GET['page']) && $_GET['page'] >= 1)?(int)$_GET['page']:1;
$start = ($page - 1) * $per_page;
$productResult = $this->Webservice_model->get_latest_product_list(0,0);
$productList = $this->Webservice_model->get_latest_product_list($start,$per_page);
$product = array();
$total = 0;
if($productResult['status'] == 'success'){
$total = count($productResult['data']);
}
if($total >= $per_page){
$totalPages = (int)($total % $per_page ==0 ? $total / $per_page :($total / $per_page)+1);
}
else{
$totalPages = 1;
}
if($productList['status'] == 'success'){
$respArr = array(
'status' => 'success',
'message'=>'success',
'data' => array(
'latest_products' => $productList['data']
),
'meta' => array(
'total_pages' => $totalPages,
'total' => $total,
'current_page' => ($page == 0)?1:$page,
'per_page' => $per_page
)
);
}else{
$respArr = array(
'status' => 'error',
'message'=>'No data',
'data' => array(
'latest_products' => []
),
'meta' => array(
'total_pages' => $totalPages,
'total' => $total,
'current_page' => ($page == 0)?1:$page,
'per_page' => $per_page
)
);
}
echo json_encode($respArr);exit;
}
public function get_trending_product_list(){
header('Content-type:application/json');
$headers = apache_request_headers();
if(!isset($headers['Auth']) || empty($headers['Auth'])){
$respArr['status'] = 'error';
$respArr['message'] = 'Authtoken is Required';
echo json_encode($respArr);exit;
}
$authRes = $this->Webservice_model->get_customer_authtoken($headers['Auth']);
if($authRes['status'] == 'error'){
echo json_encode($authRes);exit;
}
$per_page = 10;
$page = (isset($_GET['page']) && $_GET['page'] >= 1)?(int)$_GET['page']:1;
$start = ($page - 1) * $per_page;
$productResult = $this->Webservice_model->get_trending_product_list(0,0);
$productList = $this->Webservice_model->get_trending_product_list($start,$per_page);
$product = array();
$total = 0;
if($productResult['status'] == 'success'){
$total = count($productResult['data']);
}
if($total >= $per_page){
$totalPages = (int)($total % $per_page ==0 ? $total / $per_page :($total / $per_page)+1);
}
else{
$totalPages = 1;
}
if($productList['status'] == 'success'){
$respArr = array(
'status' => 'success',
'message'=>'success',
'data' => array(
'trending_products' => $productList['data']
),
'meta' => array(
'total_pages' => $totalPages,
'total' => $total,
'current_page' => ($page == 0)?1:$page,
'per_page' => $per_page
)
);
}else{
$respArr = array(
'status' => 'error',
'message'=>'No data',
'data' => array(
'trending_products' => []
),
'meta' => array(
'total_pages' => $totalPages,
'total' => $total,
'current_page' => ($page == 0)?1:$page,
'per_page' => $per_page
)
);
}
echo json_encode($respArr);exit;
}
public function product_details(){
header('Content-type:application/json');
$headers = apache_request_headers();
if(!isset($headers['Auth']) || empty($headers['Auth'])){
$respArr['status'] = 'error';
$respArr['message'] = 'Authtoken is Required';
echo json_encode($respArr);exit;
}
$authRes = $this->Webservice_model->get_customer_authtoken($headers['Auth']);
if($authRes['status'] == 'error'){
echo json_encode($authRes);exit;
}
$post = file_get_contents("php://input");
$postData = json_decode($post,true);
$result = $this->Webservice_model->SingleProductSearch($postData);
echo json_encode($result);exit;
}
public function add_address(){
header('Content-type:application/json');
$headers = apache_request_headers();
if(!isset($headers['Auth']) || empty($headers['Auth'])){
$respArr['status'] = 'error';
$respArr['message'] = 'Authtoken is Required';
echo json_encode($respArr);exit;
}
$authRes = $this->Webservice_model->get_customer_authtoken($headers['Auth']);
if($authRes['status'] == 'error'){
echo json_encode($authRes);exit;
}
$post = file_get_contents("php://input");
$postData = json_decode($post,true);
$postData['customer_id'] = $authRes['data']['customer_id'];
$result = $this->Webservice_model->saveUserAddress($postData);
echo json_encode($result);exit;
}
public function address_details(){
header('Content-type:application/json');
$headers = apache_request_headers();
if(!isset($headers['Auth']) || empty($headers['Auth'])){
$respArr['status'] = 'error';
$respArr['message'] = 'Authtoken is Required';
echo json_encode($respArr);exit;
}
$authRes = $this->Webservice_model->get_customer_authtoken($headers['Auth']);
if($authRes['status'] == 'error'){
echo json_encode($authRes);exit;
}
$postData['user_id'] = $authRes['data']['customer_id'];
$result = $this->Webservice_model->getUserAddress($postData);
echo json_encode($result);exit;
}
public function getLatestPrdts(){
header('Content-type:application/json');
$headers = apache_request_headers();
$per_page = 10;
$page = (isset($postData['page']) && $postData['page'] != 1) ?$postData['page'] :'1';
$page_limit = ($page - 1) * $per_page;
$latestResult = $this->Webservice_model->get_latest_product_list(0,0);
$latestList = $this->Webservice_model->get_latest_product_list($page_limit,$per_page);
if($latestResult['status'] == 'success'){
$total = count($latestResult['data']);
}
if($total >= $per_page){
$totalPages = (int)($total % $per_page ==0 ? $total / $per_page :($total / $per_page)+1);
}
else{
$totalPages = 1;
}
if($latestList['status'] == 'success'){
$respArr = array(
'status' => 'success',
'message'=>'success',
'data' => $latestList['data'],
'meta' => array(
'total_pages' => $totalPages,
'total' => $total,
'current_page' => ($page == 0)?1:$page,
'per_page' => $per_page
)
);
}else{
$respArr = array(
'status' => 'error',
'message'=>'No data',
'data' => [],
'meta' => array(
'total_pages' => $totalPages,
'total' => $total,
'current_page' => ($page == 0)?1:$page,
'per_page' => $per_page
)
);
}
echo json_encode($respArr);exit;
}
public function getTrendingPrdts(){
header('Content-type:application/json');
$headers = apache_request_headers();
$post = file_get_contents("php://input");
$postData = json_decode($post,true);
$total = 0;
$per_page = 10;
$page = (isset($postData['page']) && $postData['page'] != 1) ?$postData['page'] :'1';
$page_limit = ($page - 1) * $per_page;
$trendResult = $this->Webservice_model->get_trending_product_list(0,0);
$trendList = $this->Webservice_model->get_trending_product_list($page_limit,$per_page);
if($trendResult['status'] == 'success'){
$total = count($trendResult['data']);
}
if($total >= $per_page){
$totalPages = (int)($total%$per_page == 0?$total/$per_page:($total/$per_page)+1);
}
else{
$totalPages = 1;
}
if($trendList['status'] == 'success'){
$respArr = array(
'status' => 'success',
'message'=>'success',
'data' => $trendList['data'],
'meta' => array(
'total_pages' => $totalPages,
'total' => $total,
'current_page' => ($page == 0)?1:$page,
'per_page' => $per_page
)
);
}else{
$respArr = array(
'status' => 'error',
'message'=>'No data',
'data' => [],
'meta' => array(
'total_pages' => $totalPages,
'total' => $total,
'current_page' => ($page == 0)?1:$page,
'per_page' => $per_page
)
);
}
echo json_encode($respArr);exit;
}
public function getMyOrders(){
header('Content-type:application/json');
$headers = apache_request_headers();
$post = file_get_contents("php://input");
$postData = json_decode($post,true);
$total = 0;
$per_page = 10;
$page = (isset($postData['page']) && $postData['page'] != 1) ?$postData['page'] :'1';
$page_limit = ($page - 1) * $per_page;
$result = $this->Webservice_model->getMyOrders($postData,0,0);
$resultList = $this->Webservice_model->getMyOrders($postData,$page_limit,$per_page);
if($result['status'] == 'success'){
$total = count($result['data']);
}
if($total >= $per_page){
$totalPages = (int)($total%$per_page == 0?$total/$per_page:($total/$per_page)+1);
}
else{
$totalPages = 1;
}
if($resultList['status'] == 'success'){
$respArr = array(
'status' => 'success',
'message'=>'success',
'data' => $resultList['data'],
'meta' => array(
'total_pages' => $totalPages,
'total' => $total,
'current_page' => ($page == 0)?1:$page,
'per_page' => $per_page
)
);
}else{
$respArr = array(
'status' => 'error',
'message'=>'No data',
'data' => [],
'meta' => array(
'total_pages' => $totalPages,
'total' => $total,
'current_page' => ($page == 0)?1:$page,
'per_page' => $per_page
)
);
}
echo json_encode($respArr);exit;
}
public function cancelOrder(){
header('Content-type:application/json');
$headers = apache_request_headers();
$post = file_get_contents("php://input");
$postData = json_decode($post,true);
$result = $this->Webservice_model->cancelOrder($postData);
echo json_encode($result);exit;
}
}
......
......@@ -6,7 +6,8 @@ class Order_model extends CI_Model {
}
public function getOrders(){
$this->db->select("ORD.format_order_id,ORD.quantity,ORD.amount,ORD.status,PRD.product_name,TRIM(CONCAT(CUST.first_name,' ' ,IFNULL(CUST.last_name,''))) as customer_name,ORD.order_id");
$this->db->select("ORD.*,PRD.product_name,
TRIM(CONCAT(CUST.first_name,' ',IFNULL(CUST.last_name,''))) as customer_name");
$this->db->from('orders AS ORD');
$this->db->join('products AS PRD','PRD.product_id = ORD.product_id');
$this->db->join('customers AS CUST','CUST.customer_id = ORD.customer_id');
......@@ -20,7 +21,8 @@ class Order_model extends CI_Model {
if($order_id == ''){
return 0;
}
$result = $this->db->query("SELECT ORD.*,PRD.product_name,PRD.short_description,PRDB.brand_name,TRIM(CONCAT(CUST.first_name,' ' ,IFNULL(CUST.last_name,''))) as customer_name,
$result = $this->db->query("SELECT ORD.*,PRD.product_name,PRD.short_description,PRDB.brand_name,
TRIM(CONCAT(CUST.first_name,' ',IFNULL(CUST.last_name,''))) AS customer_name,
CASE WHEN ORD.status = 0 THEN 'Inactive'
WHEN ORD.status = 1 THEN 'Payment Processing'
WHEN ORD.status = 2 THEN 'Order Places'
......@@ -30,7 +32,7 @@ class Order_model extends CI_Model {
WHEN ORD.status = 6 THEN 'Returned'
WHEN ORD.status = 7 THEN 'Cancelled'
WHEN ORD.status = 8 THEN 'Deleted'
ELSE 'Payment Failed' END AS status
ELSE 'Payment Failed' END AS ord_status
FROM orders AS ORD
JOIN products AS PRD on PRD.product_id = ORD.product_id
JOIN product_brand AS PRDB on PRDB.brand_id = PRD.brand_id
......@@ -48,6 +50,23 @@ class Order_model extends CI_Model {
return (empty($result))?'':$result->result();
}
public function changeOrderStatus($data=array()){
$order_id = decode_param($data['order_id']);
if(empty($order_id) || $data['status'] == '' || empty($data['expected_date'])){
return 0;
}
if($data['status'] == '3' || $data['status'] == '4'){
$data['expected_delivery'] = $data['expected_date'];
}else if($data['status'] == '5'){
$data['delivered'] = $data['expected_date'];
}
unset($data['expected_date'],$data['order_id']);
$status = 0;
if($this->db->update('orders',$data,array('order_id'=>$order_id))){
$status = 1;
}
return $status;
}
}
?>
......@@ -591,14 +591,16 @@ class Webservice_model extends CI_Model {
return 1;
}
public function productSearch($postData){
public function productSearch($postData,$start='',$per_page=''){
$respArr = array('status'=>'error');
if(empty($postData)){
return $respArr;
}
$per_page = 10;
$page = (isset($data['page']))?$data['page']:'0';
$lmt = '';
if($start != 0 || $per_page != 0){
$lmt .= "LIMIT $start,$per_page";
}
$where = '';
if(isset($postData['key']) && !empty($postData['key'])){
......@@ -630,8 +632,7 @@ class Webservice_model extends CI_Model {
LEFT JOIN product_rating AS REV ON REV.product_id = PRD.product_id
WHERE $where PRD.status='1'
GROUP BY PRD.product_id,PI.product_id
LIMIT $page,$per_page");
//pr($this->db->last_query());
$lmt ");
if(!empty($result) && $result->num_rows() > 0){
$respArr['status'] = 'success';
$respArr['data'] = $result->result_array();
......@@ -655,33 +656,75 @@ class Webservice_model extends CI_Model {
public function SingleProductSearch($postData){
$respArr = array('status'=>'error');
if(empty($postData)){
if(empty($postData['product_id'])){
return $respArr;
}
$total = 0;
$per_page = 10;
$page = (isset($postData['page']) && $postData['page'] != 1) ?$postData['page'] :'1';
$page_limit = ($page - 1) * $per_page;
$sql = "SELECT ROUND(AVG(REV.rating),2) AS rating, COUNT(REV.id) AS count,PRD.*
$sql = "SELECT ROUND(AVG(REV.rating),2) AS rating, COUNT(REV.id) AS count,PRD.*,PRDB.brand_name
FROM products AS PRD
LEFT JOIN product_rating AS REV ON REV.product_id = PRD.product_id
LEFT JOIN product_brand AS PRDB ON PRDB.brand_id = PRD.brand_id
WHERE PRD.product_id =".$postData['product_id'];
$this->db->query($sql);
$result = $this->db->query($sql);
if(!empty($result) && $result->num_rows() > 0){
$respArr['status'] = 'success';
$respArr['data'] = $result->row();
$prdt_img = $this->db->get_where('product_images',array('product_id'=>$postData['product_id'],'status'=>'1'))->result();
$reviews = $this->db->get_where('product_rating',array('product_id'=>$postData['product_id'],'status'=>'1'))->result();
$review = $this->getReviewCount($postData['product_id'],0,0);
$reviewList = $this->getReviewCount($postData['product_id'],$page_limit,$per_page);
if(count($review) > 0){
$total = count($review);
}
if($total >= $per_page){
$totalPages = (int)($total%$per_page == 0?$total/$per_page:($total/$per_page)+1);
}
else{
$totalPages = 1;
}
$respArr['data']->images = '';
$respArr['data']->reviews = '';
if(count($prdt_img) > 0){
$respArr['data']->images = $prdt_img;
}
if(count($reviews) > 0){
$respArr['data']->reviews = $reviews ;
}
if(count($reviewList) > 0){
$respArr['data']->reviews['data'] = $reviewList;
$respArr['data']->reviews['meta'] = array(
'total_pages' => $totalPages,
'total' => $total,
'current_page' => ($page == 0)?1:$page,
'per_page' => $per_page);
} else{
$respArr['data']->reviews['data'] = [];
$respArr['data']->reviews['meta'] = array(
'total_pages' => $totalPages,
'total' => $total,
'current_page' => ($page == 0)?1:$page,
'per_page' => $per_page);
}
}
return $respArr;
}
public function getReviewCount($product_id,$start,$per_page){
$this->db->select("PRD.*,TRIM(CONCAT(CUST.first_name,' ',IFNULL(CUST.last_name,''))) as customer_name");
$this->db->join('customers CUST','CUST.customer_id = PRD.customer_id');
$this->db->order_by('PRD.id DESC');
if($start != 0 || $per_page != 0){
$this->db->limit($per_page,$start);
}
$reviews = $this->db->get_where('product_rating PRD',array('PRD.product_id'=>$product_id,'PRD.status'=>'1'))->result();
return $reviews;
}
public function saveUserAddress($postData = array()){
$respArr = array('status'=>'error','message'=>'Something Went Wrong.. Try Again Later');
if(empty($postData)){
......@@ -812,10 +855,11 @@ class Webservice_model extends CI_Model {
}
$result = $this->db->query("SELECT TRANS.datetime,TRANS.amount,TRANS.status,PRD.product_id,
PRD.product_name,PRD.short_description,ORDS.format_order_id,ORDS.quantity,ORDS.expected_delivery,ORDS.delivered,ORDS.status AS odr_status
PRD.product_name,PRD.short_description,ORDS.format_order_id,ORDS.quantity,ORDS.expected_delivery,ORDS.delivered,ORDS.status AS odr_status,PRDR.id AS review_id
FROM transaction TRANS
JOIN orders ORDS ON ORDS.order_id = TRANS.booking_id
JOIN products PRD ON PRD.product_id = ORDS.product_id
LEFT JOIN product_rating PRDR ON (ORDS.product_id = PRDR.product_id AND ORDS. customer_id = PRDR.customer_id)
WHERE TRANS.id =".$postData['ref_id']);
if(!empty($result) && !empty($result = $result->row())){
$prdt_img = $this->db->get_where('product_images',array('product_id'=>$result->product_id))->result();
......@@ -836,12 +880,123 @@ class Webservice_model extends CI_Model {
return $respArr;
}
$postData['datetime'] = date('Y-m-d h:i:s');
$result = $this->db->get_where('product_rating',array('product_id'=>$postData['product_id'],'customer_id'=>$postData['customer_id']))->row();
if(!empty($result) && !empty($result = $result->row())){
$respArr['status'] = 'error';
$respArr['message'] = 'Sorry Your are Already Rated for this Product';
return $respArr;
}
if($this->db->insert('product_rating',$postData)){
$respArr['status'] = 'success';
$respArr['message'] = 'Rated Successfully';
}
return $respArr;
}
public function get_latest_product_list($start = '',$per_page=''){
$respArr = array('status'=>'error','message'=>'Something Went Wrong.');
$lmt = '';
if($start != 0 || $per_page != 0){
$lmt .= "LIMIT $start,$per_page";
}
$result = $this->db->query("SELECT ROUND(AVG(REV.rating),2) AS rating,
COUNT(REV.id) AS reviews,PRD.*,PI.image as product_image
FROM products AS PRD
LEFT JOIN product_images AS PI ON
(PI.id=(SELECT MIN(id)
FROM product_images
WHERE product_id= PRD.product_id AND
PRD.status='1'))
LEFT JOIN product_rating AS REV ON REV.product_id = PRD.product_id
WHERE PRD.status='1'
GROUP BY PRD.product_id,PI.product_id
ORDER BY PRD.product_id DESC
$lmt");
if(!empty($result) && $result->num_rows() > 0){
$respArr['status'] = 'success';
$respArr['message'] = 'success';
$respArr['data'] = $result->result_array();
}
return $respArr;
}
public function get_trending_product_list($start='',$per_page=''){
$respArr = array('status'=>'error','message'=>'Something Went Wrong.');
$lmt = '';
if($start != 0 || $per_page != 0){
$lmt .= "LIMIT $start,$per_page";
}
$sql = $this->db->query("SELECT COUNT(ORDS.product_id) as count,PRD.product_id FROM products PRD LEFT JOIN orders AS ORDS ON ORDS.product_id = PRD.product_id WHERE PRD.status='1' GROUP BY PRD.product_id ORDER BY count DESC $lmt ");
if(!empty($sql) && $sql->num_rows() > 0){
foreach ($sql->result_array() as $key => $value) {
$result = $this->db->query("SELECT ROUND(AVG(REV.rating),2) AS rating,
COUNT(REV.id) AS reviews,PRD.*,PI.image as product_image
FROM products AS PRD
LEFT JOIN product_images AS PI ON
(PI.id=(SELECT MIN(id)
FROM product_images
WHERE product_id= PRD.product_id AND
PRD.status='1'))
LEFT JOIN product_rating AS REV ON REV.product_id = PRD.product_id
WHERE PRD.status='1' AND PRD.product_id =".$value['product_id']);
if(!empty($result) && $result->num_rows() > 0){
$new_array[$key] = $result->row_array();
}
}
$respArr['status'] = 'success';
$respArr['message'] = 'success';
$respArr['data'] = $new_array;
}
return $respArr;
}
public function getMyOrders($postData,$start='',$per_page=''){
$respArr = array('status'=>'error');
if(empty($postData['customer_id'])){
$respArr['message'] = "Customer Id is Required";
return $respArr;
}
$lmt = '';
if($start != 0 || $per_page != 0){
$lmt .= "LIMIT $start,$per_page";
}
$result = $this->db->query("SELECT PRD.product_name,PRD.short_description,TRANS.id AS transId,
TRANS.status AS tranStatus,TRANS.datetime,ORD.*,PI.image as product_image
FROM orders ORD
JOIN products PRD ON ORD.product_id = PRD.product_id
JOIN transaction TRANS ON (ORD.order_id = TRANS.booking_id AND TRANS.payment_for= '2')
LEFT JOIN product_images AS PI ON (PI.id=
(SELECT MIN(id)
FROM product_images
WHERE product_id= PRD.product_id AND
PRD.status='1'))
WHERE ORD.customer_id=".$postData['customer_id']." ORDER BY ORD.order_id DESC $lmt");
if(empty($result) || empty($result = $result->result())){
$respArr['status'] = "error";
return $respArr;
}
$respArr['status'] = "success";
$respArr['data'] = $result;
return $respArr;
}
public function cancelOrder($postData){
$respArr = array('status'=>'error');
if(empty($postData['order_id'])){
$respArr['message'] = "Order Id is Required";
return $respArr;
}
if($this->db->update('orders',array('status'=>'7'),array('order_id'=>$postData['order_id']))){
$respArr['status'] = 'success';
$respArr['message'] = 'Order Cancelled Successfully';
}
return $respArr;
}
}
?>
......@@ -29,12 +29,12 @@
<tr>
<th class="hidden">ID</th>
<th width="12%;">Order ID</th>
<th width="18%;">Product</th>
<th width="14%;">Customer</th>
<th width="22%;">Product</th>
<th width="15%;">Customer</th>
<th width="9%;">Quantity</th>
<th width="9%;">Amount</th>
<th width="18%;">Status</th>
<th width="20%;">Action</th>
<th width="17%;">Status</th>
<th width="16%;">Action</th>
</tr>
</thead>
<tbody>
......@@ -47,15 +47,18 @@
<th class="center"><?= $odrData->customer_name ?></th>
<th class="center"><?= $odrData->quantity ?></th>
<th class="center"><?= $odrData->amount ?></th>
<th class="center">
<th class="center" id="orderStatus_<?= encode_param($odrData->order_id) ?>">
<?php
switch($odrData->status){
case 0: echo 'Inactive'; break;
case 1: echo 'Payment Processing'; break;
case 2: echo 'Order Places'; break;
case 3: echo 'Order Packed'; break;
case 4: echo 'Order Shipped'; break;
case 5: echo 'Ordered Delivered'; break;
case 3: echo 'Order Packed <br>
(Deliver by '.$odrData->expected_delivery.')'; break;
case 4: echo 'Order Shipped <br>
(Deliver by '.$odrData->expected_delivery.')'; break;
case 5: echo 'Ordered Delivered <br>
(Deliver by '.$odrData->delivered.')'; break;
case 6: echo 'Returned'; break;
case 7: echo 'Cancelled'; break;
case 8: echo 'Deleted'; break;
......@@ -68,8 +71,9 @@
order_id="<?= encode_param($odrData->order_id) ?>">
<i class="fa fa-fw fa-eye"></i>View
</a>
<a class="btn btn-sm btn-success" id="changeOrderStatus" style="background-color:#ac2925" order_id="<?= encode_param($odrData->order_id) ?>"><i class="fa fa-cog"></i>Change Status</a>
<?php if($odrData->status == '2' || $odrData->status == '3' || $odrData->status == '4'){ ?>
<a class="btn btn-sm btn-success" order_status="<?= $odrData->status ?>" id="changeOrderStatus" style="background-color:#4CAF50;" order_id="<?= encode_param($odrData->order_id) ?>"><i class="fa fa-cog"></i>Status</a>
<?php } ?>
</td>
</tr>
<?php } }?>
......
......@@ -1440,9 +1440,22 @@ jQuery('[id="viewOrderDetails"]').on('click',function() {
'<div class="row"> '+
'<div class="col-md-4">Status</div>'+
'<div class="col-md-1">:</div>'+
'<div class="col-md-6"><label>'+resp_data.order_data.status+'</label></div> '+
'</div> '+
'</div> '+
'<div class="col-md-6"><label>'+resp_data.order_data.ord_status+'</label></div> '+
'</div> ';
if(resp_data.order_data.status == '3' || resp_data.order_data.status == '4'){
html += '<div class="row"> '+
'<div class="col-md-4">Expected Delivery Date</div>'+
'<div class="col-md-1">:</div>'+
'<div class="col-md-6"><label>'+resp_data.order_data.expected_delivery+'</label></div> '+
'</div> ';
}else if(resp_data.order_data.status == '5'){
html += '<div class="row"> '+
'<div class="col-md-4">Delivered On</div>'+
'<div class="col-md-1">:</div>'+
'<div class="col-md-6"><label>'+resp_data.order_data.delivered+'</label></div> '+
'</div> ';
}
html += '</div> '+
optionalHtml+
'</div>';
......@@ -1466,66 +1479,173 @@ jQuery('[id="viewOrderDetails"]').on('click',function() {
jQuery('[id="changeOrderStatus"]').on('click',function() {
var order_id = jQuery(this).attr('order_id');
var order_status = jQuery(this).attr('order_status');
if(order_id=='' || order_id==undefined || order_id=='undefined' || order_id==null || order_id=='null'){
return true;
}
modalTrigger('Change Order Detail Status','');
addModalLoader();
jQuery.ajax({
url : base_url+"Orders/changeOrderStatus",
type : 'POST',
data : {'order_id':order_id,'view_all':'1'},
success: function(resp){
if(resp == '' || resp == undefined || resp == 'undefined' || resp == null || resp == 'null'){
remModalLoader();
jQuery('[id="modal_content"]').html('Something went wrong, please try again later...!');
return false;
}
var resp_data = jQuery.parseJSON(resp);
if(resp_data['status'] == '0'){
remModalLoader();
jQuery('[id="modal_content"]').html('Something went wrong, please try again later...!');
return false;
}
var html = '',
imgCount = 0,
optionalHtml = '';
if(issues_selected != ''){
var comma = '';
issueHtml += '<form id="customQuote" role="form" method="post">'+
'<div class="col-md-12" style="padding-top:10px">'+
'<div class="col-md-3"><div class="row"><label>Selected Issue</label></div></div>'+
'<div class="col-md-6"><div class="row"><label>Description</label></div></div>'+
'<div class="col-md-3"><div class="row"><label>Amount</label></div></div>'+
'<div class="row">'+
'</div>'+
'</div>'+
'<div class="col-md-12">'+
'<div class="box-footer textCenterAlign">'+
'<button type="button" onclick="submitCustQuote(event);" class="btn btn-primary">Submit</button>'+
'</div>'+
'</div>'+
'</form>';
}
var stat = '',
dropOption = '<option selected disabled value="">--Change Status--</option>';
switch (order_status){
case '2': stat = 'Order Places';
dropOption += '<option value="3">Order Packed</option>';
dropOption += '<option value="4">Order Shipped</option>';
dropOption += '<option value="5">Order Delivered</option>';
break;
case '3': stat = 'Order Packed';
dropOption += '<option value="4">Order Shipped</option>';
dropOption += '<option value="5">Order Delivered</option>';
break;
case '4': stat = 'Ordered Shipped';
dropOption += '<option value="5">Order Delivered</option>';
break;
}
remModalLoader();
jQuery('[id="modal_content"]').html(html);
jQuery('[id^="optionalImage_"]').error(function() {
jQuery('[id^="optionalImage_"]').attr('src',base_url+'assets/images/no_image_text.png');
});
},
fail: function(xhr, textStatus, errorThrown){
remModalLoader();
jQuery('[id="modal_content"]').html('Something went wrong, please try again later...!');
},
error: function (ajaxContext) {
remModalLoader();
jQuery('[id="modal_content"]').html('Something went wrong, please try again later...!');
var html = '<form id="changeOrderStatus" role="form" method="post">'+
'<div class="col-md-12" style="padding-top:10px">'+
'<div class="col-md-3"><div class="row"><label>Current Status</label></div></div>'+
'<div class="col-md-1"> : </div>'+
'<div class="col-md-3"><div class="row"><label>'+stat+'</label></div></div>'+
'</div>'+
'<div class="col-md-12" style="padding-top:10px">'+
'<div class="col-md-3"><div class="row"><label>Change Status</label></div></div>'+
'<div class="col-md-1"> : </div>'+
'<div class="col-md-3">'+
'<div class="row">'+
'<select id="orderStatus" onchange="statusChangeFun()" name="status" class="form-control required">'+
dropOption+
'</select>'+
'</div>'+
'</div>'+
'<div class="col-md-5" id="deliverydatediv"></div>'+
'</div>'+
'<input type="hidden" name="order_id" id="order_id" value="'+order_id+'">'+
'<div class="col-md-12" style="padding-top:10px">'+
'<div class="box-footer textCenterAlign">'+
'<button type="button" onclick="changeOrderStatus(event);" class="btn btn-primary">Submit</button>'+
'</div>'+
'</div>'+
'</form>';
remModalLoader();
jQuery('[id="modal_content"]').html(html);
});
function statusChangeFun(){
var status = jQuery('[id="orderStatus"]').val();
if(status == '3' || status == '4'){
jQuery('[id="deliverydatediv"]').html('<div class="col-md-4">'+
'<div class="row">'+
'<label>Deliver On</label>'+
'</div>'+
'</div>'+
'<div class="col-md-1"> : </div>'+
'<div class="col-md-6">'+
'<div class="row">'+
'<input type="date" id="expected_delivery" class="form-control required" name="expected_delivery">'+
'</div>'+
'</div>');
}else if(status == '5'){
jQuery('[id="deliverydatediv"]').html('<div class="col-md-4">'+
'<div class="row">'+
'<label>Delivered on</label>'+
'</div>'+
'</div>'+
'<div class="col-md-1"> : </div>'+
'<div class="col-md-6">'+
'<div class="row">'+
'<input type="date" id="delivery" class="form-control required" name="expected_delivery">'+
'</div>'+
'</div>');
}
}
function changeOrderStatus(e){
e.preventDefault();
var errFlag = '1';
jQuery('[id^="orderStatus"]').removeClass('errInput');
var status = jQuery('[id="orderStatus"]').val();
var order_id = jQuery('[id="order_id"]').val();
if(status == '' || status == 'null' || status == 'NULL' || status == null){
jQuery('[id="orderStatus"]').addClass('errInput');
return false;
}
if(status != '' || status != 'null' || status != 'NULL' || status != null){
errFlag = '0';
if(status == '3' || status == '4'){
var expected_delivery = jQuery('[id="expected_delivery"]').val();
if(expected_delivery == '' || expected_delivery == 'null'){
jQuery('[id="expected_delivery"]').addClass('errInput');
errFlag = '1';
}
}else if(status == '5'){
var expected_delivery = jQuery('[id="delivery"]').val();
if(expected_delivery == '' || expected_delivery == 'null'){
jQuery('[id="delivery"]').addClass('errInput');
errFlag = '1';
}
}
}
if(errFlag == '1'){
return false;
}
jQuery.ajax({
url : base_url+"Orders/changeOrderStatus",
type : 'POST',
data : {'order_id':order_id,'status':status,'expected_date':expected_delivery},
success: function(resp){
if(resp == '' || resp == undefined || resp == 'undefined' || resp == null || resp == 'null'){
remModalLoader();
jQuery('[id="modal_content"]').html('Something went wrong, please try again later...!');
return false;
}
});
});
\ No newline at end of file
var resp_data = jQuery.parseJSON(resp);
if(resp_data['status'] == '0'){
remModalLoader();
jQuery('[id="modal_content"]').html('Something went wrong, please try again later...!');
return false;
}
else{
remModalLoader();
if(status == '3'){
var html = 'Order Packed <br>(Deliver by '+expected_delivery+')';
}else if(status == '4'){
var html = 'Order Shipped <br>(Deliver by '+expected_delivery+')';
}else if(status == '5'){
var html = 'Order Delivered <br>(Delivered on '+expected_delivery+')';
}
jQuery('[id="orderStatus_'+order_id+'"]').html(html);
jQuery('[id="modal_content"]').html('Status Changed Successfully.');
setTimeout(function(){
modalHide();
}, 1000);
return false;
}
},
fail: function(xhr, textStatus, errorThrown){
remModalLoader();
jQuery('[id="modal_content"]').html('Something went wrong, please try again later...!');
setTimeout(function(){
modalHide();
}, 1000);
},
error: function (ajaxContext) {
remModalLoader();
jQuery('[id="modal_content"]').html('Something went wrong, please try again later...!');
setTimeout(function(){
modalHide();
}, 1000);
}
});
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment