Commit 238e55f8 by Jansa Jose

dc

parent 4fec86f5
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Orders extends CI_Controller {
public function __construct() {
parent::__construct();
date_default_timezone_set("Asia/Kolkata");
$this->load->model('Order_model');
if(!$this->session->userdata('logged_in')) {
redirect(base_url('Login'));
}
}
public function listOrders(){
$template['page'] = 'Orders/list_orders';
$template['pTitle'] = "View Orders";
$template['pDescription'] = "View and Manage Orders";
$template['menu'] = "Order Management";
$template['smenu'] = "View Orders";
$template['orderData'] = $this->Order_model->getOrders();
$this->load->view('template',$template);
}
public function getOrderData(){
$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;
}
$order_id = decode_param($_POST['order_id']);
$return_arr['order_data'] = $this->Order_model->getOrderDetails($order_id);
$return_arr['product_image'] = $this->Order_model->getProductImage($order_id);
if(!empty($return_arr)){
$return_arr['status'] = 1;
echo json_encode($return_arr);exit;
}
echo json_encode($return_arr);exit;
}
}
?>
\ No newline at end of file
...@@ -77,6 +77,15 @@ class Product extends CI_Controller { ...@@ -77,6 +77,15 @@ class Product extends CI_Controller {
}else if($err == 0 && (!isset($_POST['amount']) || empty($_POST['amount']))){ }else if($err == 0 && (!isset($_POST['amount']) || empty($_POST['amount']))){
$err = 1; $err = 1;
$errMsg = 'Provide a Amount'; $errMsg = 'Provide a Amount';
}else if($err == 0 && (!isset($_POST['vehYear']) || empty($_POST['vehYear']))){
$err = 1;
$errMsg = 'Select Vehicle Year';
}else if($err == 0 && (!isset($_POST['vehMake']) || empty($_POST['vehMake']))){
$err = 1;
$errMsg = 'Select Vehicle Make';
}else if($err == 0 && (!isset($_POST['vehModel']) || empty($_POST['vehModel']))){
$err = 1;
$errMsg = 'Select Vehicle Model';
} }
if($err == 1){ if($err == 1){
...@@ -121,29 +130,33 @@ class Product extends CI_Controller { ...@@ -121,29 +130,33 @@ class Product extends CI_Controller {
} }
} }
public function editproduct($brand_id){ public function editproduct($product_id){
$flashMsg = array('message'=>'Something went wrong, please try again..!','class'=>'error'); $flashMsg = array('message'=>'Something went wrong, please try again..!','class'=>'error');
if(empty($brand_id) || !is_numeric($brand_id = decode_param($brand_id))){ if(empty($product_id) || !is_numeric($product_id = decode_param($product_id))){
$this->session->set_flashdata('message',$flashMsg); $this->session->set_flashdata('message',$flashMsg);
redirect(base_url('Product/viewProducts')); redirect(base_url('Product/viewProducts'));
} }
$template['page'] = 'Product/addProducts'; $template['page'] = 'Product/addProduct';
$template['menu'] = 'brand Management'; $template['menu'] = 'Brand Management';
$template['smenu'] = 'Edit brand'; $template['smenu'] = 'Edit brand';
$template['pTitle'] = "Edit brand"; $template['pTitle'] = "Edit brand";
$template['pDescription'] = "Update brand Data"; $template['pDescription'] = "Update brand Data";
$template['brand_id'] = encode_param($brand_id); $template['product_id'] = encode_param($product_id);
$template['brand_data'] = $this->Product_model->getbrand($brand_id,1); $template['brand_data'] = $this->Brand_model->getbrand('',1);
$template['product_data'] = $this->Product_model->getProduct($product_id);
$template['product_image'] = $this->Product_model->getProductImage($product_id);
$template['brand_id'] = $template['product_data']->brand_id;
$this->load->view('template',$template); $this->load->view('template',$template);
} }
public function updateproduct($brand_id = ''){ public function updateproduct($product_id = ''){
$err = 0; $err = 0;
$errMsg = ''; $errMsg = '';
$flashMsg = array('message'=>'Something went wrong, please try again..!','class'=>'error'); $flashMsg = array('message'=>'Something went wrong, please try again..!','class'=>'error');
if(empty($brand_id) || !isset($_POST) || empty($_POST) || !is_numeric(decode_param($brand_id))){ if(empty($product_id) || !isset($_POST) || empty($_POST) || !is_numeric(decode_param($product_id))){
$this->session->set_flashdata('message',$flashMsg); $this->session->set_flashdata('message',$flashMsg);
redirect(base_url('Product/viewProducts')); redirect(base_url('Product/viewProducts'));
} }
...@@ -151,23 +164,33 @@ class Product extends CI_Controller { ...@@ -151,23 +164,33 @@ class Product extends CI_Controller {
$this->session->set_flashdata('message',$flashMsg); $this->session->set_flashdata('message',$flashMsg);
redirect(base_url('Product/addProduct')); redirect(base_url('Product/addProduct'));
} }
if($err == 0 && (!isset($_POST['brand_name']) || empty($_POST['brand_name']))){ if($err == 0 && (!isset($_POST['brand_id']) || empty($_POST['brand_id']))){
$err = 1; $err = 1;
$errMsg = 'Provide a brand Name'; $errMsg = 'Please Select a Brand';
} }else if($err == 0 && (!isset($_POST['short_description']) || empty($_POST['short_description']))){
if($err == 0){
$config = set_upload_service("assets/uploads/brands");
$this->load->library('upload');
$config['file_name'] = time()."_".$_FILES['brand_logo']['name'];
$this->upload->initialize($config);
if(!$this->upload->do_upload('brand_logo')){
$err = 1; $err = 1;
$errMsg = $this->upload->display_errors(); $errMsg = 'Provide a short Description';
}else{ }else if($err == 0 && (!isset($_POST['product_name']) || empty($_POST['product_name']))){
$upload_data = $this->upload->data(); $err = 1;
$_POST['brand_logo'] = $config['upload_path']."/".$upload_data['file_name']; $errMsg = 'Provide a Product Name';
} }else if($err == 0 && (!isset($_POST['description']) || empty($_POST['description']))){
$err = 1;
$errMsg = 'Provide a Description';
}else if($err == 0 && (!isset($_POST['about']) || empty($_POST['about']))){
$err = 1;
$errMsg = 'Provide a About';
}else if($err == 0 && (!isset($_POST['amount']) || empty($_POST['amount']))){
$err = 1;
$errMsg = 'Provide a Amount';
}else if($err == 0 && (!isset($_POST['vehYear']) || empty($_POST['vehYear']))){
$err = 1;
$errMsg = 'Select Vehicle Year';
}else if($err == 0 && (!isset($_POST['vehMake']) || empty($_POST['vehMake']))){
$err = 1;
$errMsg = 'Select Vehicle Make';
}else if($err == 0 && (!isset($_POST['vehModel']) || empty($_POST['vehModel']))){
$err = 1;
$errMsg = 'Select Vehicle Model';
} }
if($err == 1){ if($err == 1){
...@@ -175,9 +198,37 @@ class Product extends CI_Controller { ...@@ -175,9 +198,37 @@ class Product extends CI_Controller {
$this->session->set_flashdata('message',$flashMsg); $this->session->set_flashdata('message',$flashMsg);
redirect(base_url('Product/addProduct')); redirect(base_url('Product/addProduct'));
} }
$existingImages = (isset($_POST['existingImages']) && !empty($_POST['existingImages']))?
$_POST['existingImages']:'';
unset($_POST['existingImages']);
$product = $this->Product_model->updateProduct(decode_param($product_id),$_POST);
if($product){
$evtMediaData = array();
if(!empty($files = $_FILES)){
$images = array();
$this->load->library('upload');
$config = set_upload_service("assets/uploads/products");
for ($typ = 0; $typ < count($files['product_image']['name']); $typ++) {
$_FILES['file']['name'] = $files['product_image']['name'][$typ];
$_FILES['file']['type'] = $files['product_image']['type'][$typ];
$_FILES['file']['size'] = $files['product_image']['size'][$typ];
$_FILES['file']['error'] = $files['product_image']['error'][$typ];
$_FILES['file']['tmp_name'] = $files['product_image']['tmp_name'][$typ];
$config['file_name'] = time()."_".$_FILES['file']['name'];
$this->upload->initialize($config);
if($this->upload->do_upload('file')){
$imgData = $this->upload->data();
$evtMediaData[] = array(
'product_id'=>decode_param($product_id),
'image'=>"assets/uploads/products/".$imgData['file_name']);
}
}
$status = $this->Product_model->updateProductImage(decode_param($product_id),$evtMediaData,$existingImages);
}
}
$status = $this->Product_model->updateProducts(decode_param($brand_id),$_POST); if($status || $product){
if($status == 1){
$flashMsg =array('message'=>'Successfully Updated brand Details..!','class'=>'success'); $flashMsg =array('message'=>'Successfully Updated brand Details..!','class'=>'success');
$this->session->set_flashdata('message', $flashMsg); $this->session->set_flashdata('message', $flashMsg);
redirect(base_url('Product/viewProducts')); redirect(base_url('Product/viewProducts'));
...@@ -187,6 +238,23 @@ class Product extends CI_Controller { ...@@ -187,6 +238,23 @@ class Product extends CI_Controller {
} }
} }
public function getProductData(){
$return_arr = array('status'=>'0');
if(!isset($_POST) || empty($_POST) || !isset($_POST['product_id']) || empty($_POST['product_id']) ||
empty(decode_param($_POST['product_id']))){
echo json_encode($return_arr);exit;
}
$product_id = decode_param($_POST['product_id']);
$return_arr['product_data'] = $this->Product_model->getProduct($product_id);
$return_arr['product_image'] = $this->Product_model->getProductImage($product_id);
if(!empty($return_arr)){
$return_arr['status'] = 1;
echo json_encode($return_arr);exit;
}
echo json_encode($return_arr);exit;
}
} }
?> ?>
\ No newline at end of file
<?php
class Order_model extends CI_Model {
public function _consruct(){
parent::_construct();
}
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->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');
$result = $this->db->get()->result();
if(!empty($result)){
return $result;
}
}
public function getOrderDetails($order_id){
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,
CASE WHEN ORD.status = 0 THEN 'Inactive'
WHEN ORD.status = 1 THEN 'Payment Processing'
WHEN ORD.status = 2 THEN 'Order Places'
WHEN ORD.status = 3 THEN 'Order Packed'
WHEN ORD.status = 4 THEN 'Order Shipped'
WHEN ORD.status = 5 THEN 'Ordered Delivered'
WHEN ORD.status = 6 THEN 'Returned'
WHEN ORD.status = 7 THEN 'Cancelled'
WHEN ORD.status = 8 THEN 'Deleted'
ELSE 'Payment Failed' END AS 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
JOIN customers AS CUST on CUST.customer_id = ORD.customer_id
WHERE ORD.order_id = $order_id");
if(empty($result)){
return;
}
return $result->row();
}
public function getProductImage($order_id){
$result = $this->db->query("SELECT PRDI.image FROM orders AS ORD join product_images AS PRDI on PRDI.product_id = ORD.product_id WHERE ORD.order_id = $order_id");
return (empty($result))?'':$result->result();
}
}
?>
...@@ -9,6 +9,16 @@ class Product_model extends CI_Model { ...@@ -9,6 +9,16 @@ class Product_model extends CI_Model {
if(empty($product_data)){ if(empty($product_data)){
return 0; return 0;
} }
$cardata = $this->db->get_where('cardetails',array('year'=>$product_data['vehYear'],'make'=>$product_data['vehMake'],'model'=>$product_data['vehModel']))->row();
if($cardata){
$product_data['cardetail_id'] = $cardata->id;
}else{
$this->db->insert('cardetails',array('year'=>$product_data['vehYear'],'make'=>$product_data['vehMake'],'model'=>$product_data['vehModel']));
$product_data['cardetail_id'] = $this->db->insert_id();
}
unset($product_data['vehYear']);
unset($product_data['vehMake']);
unset($product_data['vehModel']);
$status = $this->db->insert('products',$product_data); $status = $this->db->insert('products',$product_data);
$last_id = $this->db->insert_id(); $last_id = $this->db->insert_id();
...@@ -19,7 +29,7 @@ class Product_model extends CI_Model { ...@@ -19,7 +29,7 @@ class Product_model extends CI_Model {
$cond = ($view_all != 0)?' products.status IN (0,1) ':' products.status IN (1) '; $cond = ($view_all != 0)?' products.status IN (0,1) ':' products.status IN (1) ';
$cond .= (!empty($product_id))?" AND products.product_id = '$product_id'":""; $cond .= (!empty($product_id))?" AND products.product_id = '$product_id'":"";
$result = $this->db->query("SELECT products.*,product_brand.brand_name FROM products join product_brand on product_brand.brand_id = products.brand_id WHERE $cond"); $result = $this->db->query("SELECT cardetails.make,cardetails.year,cardetails.model,products.*,product_brand.brand_name FROM products join product_brand on product_brand.brand_id = products.brand_id join cardetails on cardetails.id = products.cardetail_id WHERE $cond");
if(empty($result)){ if(empty($result)){
return; return;
} }
...@@ -30,6 +40,7 @@ class Product_model extends CI_Model { ...@@ -30,6 +40,7 @@ class Product_model extends CI_Model {
if(empty($product_id)){ if(empty($product_id)){
return 0; return 0;
} }
$this->db->update('product_images',array('status'=>$status),array('product_id'=>$product_id));
$status = $this->db->update('products',array('status'=>$status), array('product_id'=>$product_id)); $status = $this->db->update('products',array('status'=>$status), array('product_id'=>$product_id));
return $status; return $status;
} }
...@@ -38,7 +49,16 @@ class Product_model extends CI_Model { ...@@ -38,7 +49,16 @@ class Product_model extends CI_Model {
if(empty($product_id) || empty($product_data)){ if(empty($product_id) || empty($product_data)){
return 0; return 0;
} }
$cardata = $this->db->get_where('cardetails',array('year'=>$product_data['vehYear'],'make'=>$product_data['vehMake'],'model'=>$product_data['vehModel']))->row();
if($cardata){
$product_data['cardetail_id'] = $cardata->id;
}else{
$this->db->insert('cardetails',array('year'=>$product_data['vehYear'],'make'=>$product_data['vehMake'],'model'=>$product_data['vehModel']));
$product_data['cardetail_id'] = $this->db->insert_id();
}
unset($product_data['vehYear']);
unset($product_data['vehMake']);
unset($product_data['vehModel']);
$status = $this->db->update('products',$product_data,array('product_id'=>$product_id)); $status = $this->db->update('products',$product_data,array('product_id'=>$product_id));
return ($status)?1:0; return ($status)?1:0;
} }
...@@ -51,5 +71,35 @@ class Product_model extends CI_Model { ...@@ -51,5 +71,35 @@ class Product_model extends CI_Model {
return ($status)?1:0; return ($status)?1:0;
} }
function updateProductImage($product_id = '', $imagearray = array(), $existingImages = array()){
if(empty($product_id)){
return 0;
}
if(!empty($existingImages)){
$this->db->query("DELETE FROM product_images
WHERE id NOT IN (".implode(",",$existingImages).") AND product_id=$product_id");
} else {
$this->db->query("DELETE FROM product_images WHERE product_id='$product_id'");
}
if(!empty($imagearray)){
$status = $this->db->insert_batch('product_images',$imagearray);
}
return $status;
}
function getProductImage($product_id = ''){
if(empty($product_id)){
return 0;
}
$status = $this->db->get_where('product_images',array('product_id'=>$product_id))->result_array();
return $status;
}
function getVehdata(){
return $this->db->get_where('cardetails')->result_array();
}
} }
?> ?>
\ No newline at end of file
<div class="content-wrapper">
<section class="content-header">
<h1>
<?= $pTitle ?>
<small><?= $pDescription ?></small>
</h1>
<ol class="breadcrumb">
<li><a href="<?= base_url() ?>"><i class="fa fa-star-o" aria-hidden="true"></i>Home</a></li>
<li><?= $menu ?></li>
<li class="active"><?= $smenu ?></li>
</ol>
</section>
<section class="content">
<div class="row">
<div class="col-sm-12">
<?php if($this->session->flashdata('message')) {
$flashdata = $this->session->flashdata('message'); ?>
<div class="alert alert-<?= $flashdata['class'] ?>">
<button class="close" data-dismiss="alert" type="button">×</button>
<?= $flashdata['message'] ?>
</div>
<?php } ?>
</div>
<div class="col-xs-12">
<div class="box box-warning">
<div class="box-body">
<table id="mechanicUsers" class="table table-bordered table-striped datatable ">
<thead>
<tr>
<th class="hidden">ID</th>
<th width="12%;">Order ID</th>
<th width="18%;">Product</th>
<th width="14%;">Customer</th>
<th width="9%;">Quantity</th>
<th width="9%;">Amount</th>
<th width="18%;">Status</th>
<th width="20%;">Action</th>
</tr>
</thead>
<tbody>
<?php if(!empty($orderData)){
foreach($orderData as $odrData) { ?>
<tr>
<th class="hidden"><?= $odrData->order_id ?></th>
<th class="center"><?= $odrData->format_order_id ?></th>
<th class="center"><?= $odrData->product_name ?></th>
<th class="center"><?= $odrData->customer_name ?></th>
<th class="center"><?= $odrData->quantity ?></th>
<th class="center"><?= $odrData->amount ?></th>
<th class="center">
<?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 6: echo 'Returned'; break;
case 7: echo 'Cancelled'; break;
case 8: echo 'Deleted'; break;
case 9: echo 'Payment Failed'; break;
}
?>
</th>
<td class="center">
<a class="btn btn-sm btn-info" id="viewOrderDetails"
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>
</td>
</tr>
<?php } }?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</section>
</div>
\ No newline at end of file
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
<th width="150px;">Short Description</th> <th width="150px;">Short Description</th>
<th width="150px;">Amount</th> <th width="150px;">Amount</th>
<th width="100px;">Status</th> <th width="100px;">Status</th>
<!-- <th width="300px;">Action</th> --> <th width="300px;">Action</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
...@@ -56,7 +56,11 @@ ...@@ -56,7 +56,11 @@
<th class="center"><?= $product->short_description ?></th> <th class="center"><?= $product->short_description ?></th>
<th class="center"><?= $product->amount ?></th> <th class="center"><?= $product->amount ?></th>
<th class="center"><?= ($product->status == 1)?'Active':'De-activate' ?></th> <th class="center"><?= ($product->status == 1)?'Active':'De-activate' ?></th>
<!-- <td class="center"> <td class="center">
<a class="btn btn-sm btn-info" id="viewProductDetails"
product_id="<?= encode_param($product->product_id) ?>">
<i class="fa fa-fw fa-eye"></i>View
</a>
<a class="btn btn-sm btn-primary" <a class="btn btn-sm btn-primary"
href="<?= base_url('Product/editproduct/'.encode_param($product->product_id)) ?>"> href="<?= base_url('Product/editproduct/'.encode_param($product->product_id)) ?>">
<i class="fa fa-fw fa-edit"></i>Edit <i class="fa fa-fw fa-edit"></i>Edit
...@@ -66,7 +70,7 @@ ...@@ -66,7 +70,7 @@
onClick="return doconfirm()"> onClick="return doconfirm()">
<i class="fa fa-fw fa-trash"></i>Delete <i class="fa fa-fw fa-trash"></i>Delete
</a> </a>
</td> --> </td>
</tr> </tr>
<?php } } ?> <?php } } ?>
</tbody> </tbody>
......
...@@ -92,10 +92,14 @@ ...@@ -92,10 +92,14 @@
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="form-group col-xs-3"> <div class="form-group col-xs-4">
<label>Vin Audit API</label> <label>Vin Audit API</label>
<input type="text" name="vin_audit_api" class="form-control required" placeholder="Enter Vin Audit API" value="<?= $data['vin_audit_api'] ?>"> <input type="text" name="vin_audit_api" class="form-control required" placeholder="Enter Vin Audit API" value="<?= $data['vin_audit_api'] ?>">
</div> </div>
<div class="form-group col-xs-3">
<label>Web Url</label>
<input type="text" name="web_url" class="form-control required" placeholder="Enter Web Url" value="<?= $data['web_url'] ?>">
</div>
</div> </div>
</div> </div>
<div class="box-footer" style="padding-left:46%"> <div class="box-footer" style="padding-left:46%">
......
...@@ -127,6 +127,10 @@ ...@@ -127,6 +127,10 @@
<a href="<?= base_url('Bookings/listBookings') ?>"><i class="fa fa-book" aria-hidden="true"> <a href="<?= base_url('Bookings/listBookings') ?>"><i class="fa fa-book" aria-hidden="true">
</i><span>Request Management</span></a> </i><span>Request Management</span></a>
</li> </li>
<li>
<a href="<?= base_url('Orders/listOrders') ?>"><i class="fa fa-book" aria-hidden="true">
</i><span>Order Management</span></a>
</li>
<li class="treeview"> <li class="treeview">
<a href="#"> <a href="#">
<i class="fa fa-bars" aria-hidden="true"></i> <i class="fa fa-bars" aria-hidden="true"></i>
......
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