Commit 204377ef by Jansa Jose

import product data

parent 18df11cb
...@@ -26,12 +26,15 @@ class ImportData extends CI_Controller { ...@@ -26,12 +26,15 @@ class ImportData extends CI_Controller {
public function importCsvData(){ public function importCsvData(){
if($_POST['import_id'] == '1'){ if($_POST['import_id'] == '1'){
$status = $this->addMechanic($_FILES); $this->addMechanics($_FILES);
}else if($_POST['import_id'] == '2'){
$this->addCustomers($_FILES);
}else if($_POST['import_id'] == '3'){
$this->addProduct($_FILES);
} }
} }
public function addMechanic($files =array()){ public function addMechanics($files =array()){
$this->load->model('Mechanic_model'); $this->load->model('Mechanic_model');
if(isset($files) && !empty($files)){ if(isset($files) && !empty($files)){
$filename=$_FILES["file"]["name"]; $filename=$_FILES["file"]["name"];
...@@ -159,6 +162,197 @@ class ImportData extends CI_Controller { ...@@ -159,6 +162,197 @@ class ImportData extends CI_Controller {
} }
} }
public function addCustomers($files=array()){
$this->load->model('Customer_model');
if(isset($files) && !empty($files)){
$filename=$_FILES["file"]["name"];
$ext=pathinfo($filename, PATHINFO_EXTENSION);
if($ext=="csv"){
$count = 0;
$respMsg = '';
$respError = 0;
$respSuccess = 0;
$file = fopen($filename, "r");
while (($custData = fgetcsv($file, 10000, ",")) !== FALSE){
$err = 0;
$count++;
$errMsg = '';
$new = array();
if($count == 1){
continue;
}
if($err == 0 && (!isset($custData[0]) || empty($custData[0]))){
$err = 1;
$errMsg = 'Provide a First Name';
}
else if($err == 0 && (!isset($custData[1]) || empty($custData[1]))){
$err = 1;
$errMsg = 'Provide a Last Name';
}
else if($err == 0 && (!isset($custData[3]) || empty($custData[3]))){
$err = 1;
$errMsg = 'Provide a Phone Number';
}
else if($err == 0 && (!isset($custData[4]) || empty($custData[5]))){
$err = 1;
$errMsg = 'Provide an Email ID';
}
else if($err == 0 && (!isset($custData[6]) || empty($custData[6]))){
$err = 1;
$errMsg = 'Provide a Password';
}
else if($err == 0 && (!isset($custData[2]) || empty($custData[2]))){
$err = 1;
$errMsg = 'Provide Date Of Birth';
}
else if($err == 0 && (!isset($custData[5]) || empty($custData[5]))){
$err = 1;
$errMsg = 'Provide an Address';
}
if($err == 1){
$respError++;
$respMsg .= '<br>ERROR : Row-'.($count-1).', '.$errMsg;
}
$custData[6] = md5($custData[6]);
$new = array(
'first_name'=>$custData[0],
'last_name'=>$custData[1],
'password'=>$custData[6],
'phone'=>$custData[3],
'email'=>$custData[4],
'address'=>$custData[5],
'date_of_birth'=>$custData[2],
'profile_image'=>'',
);
$status = $this->Customer_model->createCustomer($new);
if($status == 1){
$respSuccess++;
}else if($status == 2){
$respError++;
$respMsg .= '<br>ERROR : Row-'.($count-1).', Email ID already in use.';
}else if($status == 3){
$respError++;
$respMsg .= '<br>ERROR : Row-'.($count-1).', Phone Number already in use. ';
}
}
if($count > 0){
$respMsg = "Successfully Uploaded File with, ".
$respSuccess.": Success & ".$respError.": Errors.<br>".$respMsg;
$flashMsg = array('message'=>$respMsg,'class'=>'success');
$this->session->set_flashdata('message', $flashMsg);
redirect(base_url('ImportData/import_data'));
}
}
}
}
public function addProduct($files =array()){
if(isset($files) && !empty($files)){
$filename=$_FILES["file"]["name"];
$ext=pathinfo($filename, PATHINFO_EXTENSION);
if($ext=="csv"){
$count = 0;
$respMsg = '';
$respError = 0;
$respSuccess = 0;
$file = fopen($filename, "r");
while (($prdData = fgetcsv($file, 10000, ",")) !== FALSE){
$err = 0;
$count++;
$errMsg = '';
$new = array();
if($count == 1){
continue;
}
if($err == 0 && (!isset($prdData[0]) || empty($prdData[0]))){
$err = 1;
$errMsg = 'Provide a Product Name';
}
else if($err == 0 && (!isset($prdData[1]) || empty($prdData[1]))){
$err = 1;
$errMsg = 'Provide a Brand Name';
}
else if($err == 0 && (!isset($prdData[2]) || empty($prdData[2]))){
$err = 1;
$errMsg = 'Provide a Part Id';
}
else if($err == 0 && (!isset($prdData[3]) || empty($prdData[3]))){
$err = 1;
$errMsg = 'Provide a short Description';
}
else if($err == 0 && (!isset($prdData[4]) || empty($prdData[4]))){
$err = 1;
$errMsg = 'Provide an Amount';
}
else if($err == 0 && (!isset($prdData[5]) || empty($prdData[5]))){
$err = 1;
$errMsg = 'Provide a Year';
}
else if($err == 0 && (!isset($prdData[6]) || empty($prdData[6]))){
$err = 1;
$errMsg = 'Provide a Vehicle Brand';
}
else if($err == 0 && (!isset($prdData[7]) || empty($prdData[7]))){
$err = 1;
$errMsg = 'Provide a Vehicle Model';
}
else if($err == 0 && (!isset($prdData[8]) || empty($prdData[8]))){
$err = 1;
$errMsg = 'Provide a Product Description';
}
else if($err == 0 && (!isset($prdData[9]) || empty($prdData[9]))){
$err = 1;
$errMsg = 'About Produt';
}
if($err == 1){
$respError++;
$respMsg .= '<br>ERROR : Row-'.($count-1).', '.$errMsg;
}
$brand_id = $this->Import_model->checkBrand($prdData[1]);
$cardetail_id = $this->Import_model->checkCardetails($prdData[5],$prdData[6],$prdData[7]);
$new = array(
'product_name'=>$prdData[0],
'brand_id'=>$brand_id,
'part_id'=>$prdData[2],
'short_description'=>$prdData[3],
'amount'=>$prdData[4],
'cardetail_id'=>$cardetail_id,
'description'=>$prdData[8],
'about'=>$prdData[9]
);
$status = $this->Import_model->addProduct($new);
if($status == 1){
$respSuccess++;
}else{
$respError++;
$respMsg .= '<br>ERROR : Row-'.($count-1).', Something Went Wrong.';
}
}
if($count > 0){
$respMsg = "Successfully Uploaded File with, ".
$respSuccess.": Success & ".$respError.": Errors.<br>".$respMsg;
$flashMsg = array('message'=>$respMsg,'class'=>'success');
$this->session->set_flashdata('message', $flashMsg);
redirect(base_url('ImportData/import_data'));
}
}
}
}
} }
......
...@@ -784,7 +784,7 @@ ...@@ -784,7 +784,7 @@
$respArr = array('status'=>0,'error'=>'901','message'=>'All Field is Required'); $respArr = array('status'=>0,'error'=>'901','message'=>'All Field is Required');
echo json_encode($respArr);exit; echo json_encode($respArr);exit;
} }
if(!isset($postData['vehicle_id']) && empty($postData['vehicle_id'])){
if(!isset($postData['vehicle_year']) || empty($postData['vehicle_year'])){ if(!isset($postData['vehicle_year']) || empty($postData['vehicle_year'])){
$err = 1; $err = 1;
$msg = 'Provide a Vehicle year'; $msg = 'Provide a Vehicle year';
...@@ -821,6 +821,7 @@ ...@@ -821,6 +821,7 @@
$err = 1; $err = 1;
$msg = 'Car Location is Required'; $msg = 'Car Location is Required';
} }
}
if($err == 1){ if($err == 1){
$respArr['message'] = $msg; $respArr['message'] = $msg;
......
...@@ -156,72 +156,72 @@ ...@@ -156,72 +156,72 @@
echo json_encode($respArr);exit; echo json_encode($respArr);exit;
} }
public function get_pending_services(){ // public function get_pending_services(){
header('Content-type: application/json'); // header('Content-type: application/json');
$headers = apache_request_headers(); // $headers = apache_request_headers();
if(!isset($headers['Auth']) || empty($headers['Auth'])){ // if(!isset($headers['Auth']) || empty($headers['Auth'])){
$respArr['status'] = 'error'; // $respArr['status'] = 'error';
$respArr['message'] = 'Authtoken is Required'; // $respArr['message'] = 'Authtoken is Required';
echo json_encode($respArr);exit; // echo json_encode($respArr);exit;
} // }
$authRes = $this->Webservice_mechanic_model->get_mechanic_authtoken($headers['Auth']); // $authRes = $this->Webservice_mechanic_model->get_mechanic_authtoken($headers['Auth']);
if($authRes['status'] == 'error'){ // if($authRes['status'] == 'error'){
echo json_encode($authRes);exit; // echo json_encode($authRes);exit;
} // }
$per_page = 10; // $per_page = 10;
$page = (isset($postData['page']) && $postData['page'] >= 1)?(int)$postData['page']:1; // $page = (isset($postData['page']) && $postData['page'] >= 1)?(int)$postData['page']:1;
$start = ($page - 1) * $per_page; // $start = ($page - 1) * $per_page;
$post = file_get_contents("php://input"); // $post = file_get_contents("php://input");
$postData = json_decode($post, true); // $postData = json_decode($post, true);
$postData['mechanic_id'] = $authRes['data']['mechanic_id']; // $postData['mechanic_id'] = $authRes['data']['mechanic_id'];
$bookDataCount = $this->Webservice_mechanic_model->getBookedService($postData,0,0,2); // $bookDataCount = $this->Webservice_mechanic_model->getBookedService($postData,0,0,2);
$bookDataResult = $this->Webservice_mechanic_model->getBookedService($postData,$start,$per_page,2); // $bookDataResult = $this->Webservice_mechanic_model->getBookedService($postData,$start,$per_page,2);
$total = 0; // $total = 0;
if($bookDataCount['status'] == 'success'){ // if($bookDataCount['status'] == 'success'){
$total = count($bookDataCount['data']); // $total = count($bookDataCount['data']);
} // }
if($total >= $per_page){ // if($total >= $per_page){
$totalPages = (int)($total % $per_page ==0 ? $total / $per_page :($total / $per_page)+1); // $totalPages = (int)($total % $per_page ==0 ? $total / $per_page :($total / $per_page)+1);
} // }
else{ // else{
$totalPages = 1; // $totalPages = 1;
} // }
if($bookDataResult['status'] == 'success'){ // if($bookDataResult['status'] == 'success'){
$respArr = array( // $respArr = array(
'status' => 'success', // 'status' => 'success',
'message'=>'success', // 'message'=>'success',
'data' => $bookDataResult['data'], // 'data' => $bookDataResult['data'],
'meta' => array( // 'meta' => array(
'total_pages' => $totalPages, // 'total_pages' => $totalPages,
'total' => $total, // 'total' => $total,
'current_page' => ($page == 0)?1:$page, // 'current_page' => ($page == 0)?1:$page,
'per_page' => $per_page // 'per_page' => $per_page
) // )
); // );
}else{ // }else{
$respArr = array( // $respArr = array(
'status' => 'error', // 'status' => 'error',
'message'=>'No data', // 'message'=>'No data',
'data' => [], // 'data' => [],
'meta' => array( // 'meta' => array(
'total_pages' => $totalPages, // 'total_pages' => $totalPages,
'total' => $total, // 'total' => $total,
'current_page' => ($page == 0)?1:$page, // 'current_page' => ($page == 0)?1:$page,
'per_page' => $per_page // 'per_page' => $per_page
) // )
); // );
} // }
echo json_encode($respArr);exit; // echo json_encode($respArr);exit;
} // }
public function get_service_history(){ public function get_service_history(){
header('Content-type: application/json'); header('Content-type: application/json');
...@@ -247,7 +247,7 @@ ...@@ -247,7 +247,7 @@
$postData = json_decode($post, true); $postData = json_decode($post, true);
$postData['mechanic_id'] = $authRes['data']['mechanic_id']; $postData['mechanic_id'] = $authRes['data']['mechanic_id'];
$bookDataCount = $this->Webservice_mechanic_model->getBookedService($postData,0,0,3); $bookDataCount = $this->Webservice_mechanic_model->getBookedService($postData,0,0,0,3);
$bookDataResult = $this->Webservice_mechanic_model->getBookedService($postData,$start,$per_page,0,3); $bookDataResult = $this->Webservice_mechanic_model->getBookedService($postData,$start,$per_page,0,3);
$total = 0; $total = 0;
......
...@@ -5,5 +5,40 @@ class Import_model extends CI_Model { ...@@ -5,5 +5,40 @@ class Import_model extends CI_Model {
parent::_construct(); parent::_construct();
} }
public function checkBrand($brand){
$result = $this->db->get_where('product_brand',array('brand_name'=>$brand));
if(!empty($result) || $result->num_rows() > 0 || !empty($result = $result->row())){
return $result->brand_id;
}else{
$this->db->insert('product_brand',array('brand_name'=>$brand,'brand_logo'=>''));
return $last_id = $this->db->insert_id();
}
}
public function checkCardetails($year,$brand,$model){
$brandData = $this->db->get_where('vehicles_brand',array('maker'=>$brand));
if(empty($brandData) || $brandData->num_rows() < 0 || empty($brandData = $brandData->row_array())){
$this->db->insert('vehicles_brand',array('maker'=>$brand));
$brandData['veh_brand_id'] = $this->db->insert_id();
}
$modelData = $this->db->get_where('vehicles_model',array('veh_brand_id'=>$brandData['veh_brand_id'],'model'=>$model));
if(empty($modelData) || $modelData->num_rows < 0 || empty($modelData = $modelData->row_array())){
$this->db->insert('vehicles_model',array('veh_brand_id'=>$brandData['veh_brand_id'],'model'=>$model));
$modelData['veh_modal_id'] = $this->db->insert_id();
}
$carData = $this->db->get_where('cardetails',array('year'=>$year,'veh_modal_id'=>$modelData['veh_modal_id']));
if(empty($carData) || $carData->num_rows < 0 || empty($carData = $carData->row_array())){
$carData['id'] = $this->db->insert_id();
}
return $carData['id'];
}
public function addProduct($new = array()){
if($this->db->insert('products',$new)){
return 1;
}
}
} }
?> ?>
\ No newline at end of file
...@@ -78,10 +78,13 @@ class Webservice_mechanic_model extends CI_Model { ...@@ -78,10 +78,13 @@ class Webservice_mechanic_model extends CI_Model {
} }
if($type == 1){ if($type == 1){
$where['BUK.scheduled_date'] = date('Y-m-d'); //$where['BUK.scheduled_date'] = date('Y-m-d');
}else if($type == 2){ $this->db->where('BUK.scheduled_date >=', date('Y-m-d'));
$where['BUK.scheduled_date'] = date("Y-m-d", strtotime('tomorrow')); $this->db->order_by('BUK.scheduled_date','ASC');
} }
// else if($type == 2){
// $where['BUK.scheduled_date'] = date("Y-m-d", strtotime('tomorrow'));
// }
$this->db->select("BUK.scheduled_date as date,BUK.scheduled_time as time,BUK.booking_id as service_id,CSTVEH.car_name,BUK.mileage,BUK.issues_selected,BUK.custom_issue_data,BUK.service_type as type,MCHBUK.amount as total_amount"); $this->db->select("BUK.scheduled_date as date,BUK.scheduled_time as time,BUK.booking_id as service_id,CSTVEH.car_name,BUK.mileage,BUK.issues_selected,BUK.custom_issue_data,BUK.service_type as type,MCHBUK.amount as total_amount");
$this->db->from('bookings as BUK'); $this->db->from('bookings as BUK');
...@@ -92,7 +95,6 @@ class Webservice_mechanic_model extends CI_Model { ...@@ -92,7 +95,6 @@ class Webservice_mechanic_model extends CI_Model {
$this->db->limit($per_page,$start); $this->db->limit($per_page,$start);
} }
$bookData = $this->db->get(); $bookData = $this->db->get();
//pr($this->db->last_query());
if(!empty($bookData) && $bookData->num_rows() > 0){ if(!empty($bookData) && $bookData->num_rows() > 0){
$bookData = $bookData->result_array(); $bookData = $bookData->result_array();
foreach ($bookData as $key => $value) { foreach ($bookData as $key => $value) {
......
...@@ -187,6 +187,12 @@ class Webservice_model extends CI_Model { ...@@ -187,6 +187,12 @@ class Webservice_model extends CI_Model {
if(empty($postData)){ if(empty($postData)){
return $respArr; return $respArr;
} }
if(isset($postData['vehicle_id']) && !empty($postData['vehicle_id'])){
$result = $this->db->get_where('customer_vehicle',array('customer_veh_id'=>$postData['vehicle_id']))->row();
$postData['mileage'] = '';
$last_id = $result->customer_veh_id;
}else{
$car_name = $postData['vehicle_year'].' '.$postData['vehicle_make'].' '.$postData['vehicle_model']; $car_name = $postData['vehicle_year'].' '.$postData['vehicle_make'].' '.$postData['vehicle_model'];
$vehJson = array( $vehJson = array(
'vehicle' => $car_name, 'vehicle' => $car_name,
...@@ -212,6 +218,9 @@ class Webservice_model extends CI_Model { ...@@ -212,6 +218,9 @@ class Webservice_model extends CI_Model {
); );
if($this->db->insert('customer_vehicle',$insert_array)){ if($this->db->insert('customer_vehicle',$insert_array)){
$last_id = $this->db->insert_id(); $last_id = $this->db->insert_id();
}
}
$book_data = array( $book_data = array(
'mileage' => $postData['mileage'], 'mileage' => $postData['mileage'],
'customer_id' => $customer_id, 'customer_id' => $customer_id,
...@@ -225,7 +234,6 @@ class Webservice_model extends CI_Model { ...@@ -225,7 +234,6 @@ class Webservice_model extends CI_Model {
$respArr['data']['booking_id'] = $book_id; $respArr['data']['booking_id'] = $book_id;
return $respArr; return $respArr;
} }
}
return $respArr; return $respArr;
} }
......
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