File: //var/www/html/qcr24/app/application/controllers/api/Staff.php
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Staff extends CI_Controller
{
var $arr;
var $obj;
function __construct()
{
parent::__construct();
$this->load->model('api/mstaff');
$this->arr = array();
$this->obj = new stdClass();
$this->http_methods = array('POST', 'GET', 'PUT', 'DELETE');
$this->logo = base_url() . 'public/images/logo_new.jpg';
//$this->load->library('notification');
}
private function displayOutput($response)
{
header('Content-Type: application/json');
echo json_encode($response);
exit(0);
}
//Login
public function login()
{
$ap = json_decode(file_get_contents('php://input'), true);
if ($this->checkHttpMethods($this->http_methods[0])) {
if (sizeof($ap)) {
if (empty($ap['device_type'])) {
$response = array('status' => 0, 'message' => 'Device type is required', 'staff_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['email'])) {
$response = array('status' => 0, 'message' => 'Email field is required', 'staff_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['password'])) {
$response = array('status' => 0, 'message' => 'Password field is required', 'staff_details' => $this->obj);
$this->displayOutput($response);
}
$ap['password'] = md5($ap['password']);
$check_staff_condition = array('email' => $ap['email'], 'password' => $ap['password']);
$staff_details = $this->mstaff->getRow('master_admin', $check_staff_condition);
//echo $this->db->last_query();die;
if (empty($staff_details)) {
$response = array('status' => 0, 'message' => 'Invalid username or password', 'staff_details' => $this->obj);
} elseif ($staff_details['status'] != '0') {
$response = array('status' => 0, 'message' => 'Account Deactivated', 'staff_details' => $this->obj);
} else {
$condition = array('user_id' => $staff_details['user_id']);
$login_data['login_status'] = 1;
$login_data['updated_by'] = $staff_details['user_id'];
$login_data['updated_ts'] = date('Y-m-d h:i:s');
$login_data['date_of_last_logged_in'] = date('Y-m-d H:i:s');
$update_login_status = $this->mstaff->update('master_admin', $condition, $login_data);
if ($update_login_status) {
$response = array('status' => 1, 'message' => 'Login Successfully', 'staff_details' => $staff_details);
$api_token_details = $this->mstaff->getRow('api_token_admin', $condition);
if (empty($api_token_details)) {
$api_token_data['user_id'] = $staff_details['user_id'];
$api_token_data['device_type'] = $ap['device_type'];
$api_token_data['token_key'] = ($ap['deviceToken'])?$ap['deviceToken']:md5(mt_rand() . '_' . $staff_details['user_id']);
$api_token_data['date_of_creation'] = date('Y-m-d H:i:s');
$api_token_data['session_start_time'] = date('Y-m-d H:i:s');
$api_token_data['session_end_time'] = '';
$insert_data = $this->mstaff->insert('api_token_admin', $api_token_data);
$api_token_details = $this->mstaff->getRow('api_token_admin', $condition);
if ($insert_data) {
$response = array('status' => 1, 'message' => 'Login Successfully', 'staff_details' => $staff_details, 'api_token_details' => $api_token_details);
} else {
$response = array('status' => 0, 'message' => 'Unable to generate access token', 'staff_details' => $staff_details, 'api_token_details' => $api_token_details);
}
} else {
$api_token_data['session_start_time'] = date('Y-m-d H:i:s');
$api_token_data['token_key'] = ($ap['deviceToken'])?$ap['deviceToken']:md5(mt_rand() . '_' . $staff_details['user_id']);
$api_token_data['device_type'] = $ap['device_type'];
$update_data = $this->mstaff->update('api_token_admin', $condition, $api_token_data);
$api_token_details = $this->mstaff->getRow('api_token_admin', $condition);
if ($update_data) {
//************************************************************************************//
//************************This Part is for Activity Log*******************************//
$activityLogData = array(
'activity_type' => '<b>Login</b>',
'description' => 'Login time - '.$api_token_data['session_start_time'],
'link' => 'admin/dashboard',
'icon' => '<i class="fa fa-history" aria-hidden="true"></i>',
'created_by' => $staff_details['user_id'],
);
$this->activity_log_app($activityLogData);
//************************This Part is for Activity Log*******************************//
//************************************************************************************//
$response = array('status' => 1, 'message' => 'Login Successfully', 'staff_details' => $staff_details, 'api_token_details' => $api_token_details);
} else {
$response = array('status' => 0, 'message' => 'Unable to update access token', 'staff_details' => $staff_details, 'api_token_details' => $api_token_details);
}
}
} else {
$response = array('status' => 0, 'message' => 'Oops!something went wrong...', 'staff_details' => $this->obj);
}
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'staff_details' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'staff_details' => $this->obj);
}
$this->displayOutput($response);
}
//Change Password
public function changePassword()
{
$ap = json_decode(file_get_contents('php://input'), true);
if ($this->checkHttpMethods($this->http_methods[0])) {
if (sizeof($ap)) {
if (empty($ap['token_key'])) {
$response = array('status' => 0, 'message' => 'Token Key is required', 'result' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['device_type'])) {
$response = array('status' => 0, 'message' => 'Device type is required', 'result' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['old_password'])) {
$response = array('status' => 0, 'message' => 'Old password is required', 'result' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['new_password'])) {
$response = array('status' => 0, 'message' => 'New password is required', 'result' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['user_id'])) {
$response = array('status' => 0, 'message' => 'User ID is required', 'result' => $this->obj);
$this->displayOutput($response);
}
$access_token_result = $this->check_access_token($ap['token_key'], $ap['device_type'], $ap['user_id']);
if (empty($access_token_result)) {
$response = array('status' => 2, 'message' => 'Unauthorize Token', 'result' => $this->obj);
$this->displayOutput($response);
} else {
$condition = array('user_id' => $ap['user_id']);
$staff_details = $this->mstaff->getRow('master_admin', $condition);
if ($staff_details['password'] != md5($ap['old_password'])) {
$response = array('status' => 0, 'message' => "Old password didn't match with previous one", 'result' => $this->obj);
$this->displayOutput($response);
}
if (strtolower($ap['new_password']) == strtolower($ap['old_password'])) {
$response = array('status' => 0, 'message' => "New password same as old password,try something else", 'result' => $this->obj);
$this->displayOutput($response);
}
$data = array('updated_by' => $ap['user_id'], 'updated_ts' => date('Y-m-d H:i:s'), 'password' => md5($ap['new_password']));
$this->mstaff->update('master_admin', $condition, $data);
//************************************************************************************//
//************************This Part is for Activity Log*******************************//
$activityLogData = array(
'activity_type' => '<b>Change Password</b>',
'description' => 'Password - '.$staff_details['full_name'].' Updated',
'link' => 'admin/user',
'icon' => '<i class="fa fa-history" aria-hidden="true"></i>',
'created_by' => $ap['user_id'],
);
$this->activity_log_app($activityLogData);
//************************This Part is for Activity Log*******************************//
//************************************************************************************//
$response = array('status' => 1, 'message' => "Password changed successfully", 'result' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'result' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'result' => $this->obj);
}
$this->displayOutput($response);
}
public function getCarList()
{
$ap = json_decode(file_get_contents('php://input'), true);
if ($this->checkHttpMethods($this->http_methods[0])) {
if (sizeof($ap)) {
if (empty($ap['token_key'])) {
$response = array('status' => 0, 'message' => 'Token Key is required', 'car_list' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['device_type'])) {
$response = array('status' => 0, 'message' => 'Device type is required', 'car_list' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['user_id'])) {
$response = array('status' => 0, 'message' => 'User ID is required', 'car_list' => $this->obj);
$this->displayOutput($response);
}
$access_token_result = $this->check_access_token($ap['token_key'], $ap['device_type'], $ap['user_id']);
if (empty($access_token_result)) {
$response = array('status' => 2, 'message' => 'Unauthorize Token', 'car_list' => $this->obj);
$this->displayOutput($response);
} else {
$search_text = isset($ap['search_text'])?$ap['search_text']:'';
$car_list = $this->mstaff->get_car_list($search_text);
if (!empty($car_list)) {
foreach ($car_list as $car_key => $car) {
if (!empty($car['car_pic'])) {
$car_list[$car_key]['car_pic'] = '/public/admin_images/car_pics/' . $car['car_pic'];
} else {
$car_list[$car_key]['car_pic'] = '';
}
if (!empty($car['insurance_expire_pic'])) {
$car_list[$car_key]['insurance_expire_pic'] = '/public/admin_images/insurance_expire_pics/' . $car['insurance_expire_pic'];
} else {
$car_list[$car_key]['insurance_expire_pic'] = '';
}
}
$response = array('status' => 1, 'message' => 'Car List Fetched Successfully', 'car_list' => $car_list);
} else {
$response = array('status' => 1, 'message' => 'No Data Found', 'car_list' => $this->obj);
}
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'car_list' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'car_list' => $this->obj);
}
$this->displayOutput($response);
}
public function addCar()
{
if ($this->checkHttpMethods($this->http_methods[0])) {
if (!empty($this->input->post())) {
if (empty($this->input->post('token_key'))) {
$response = array('status' => 0, 'message' => 'Token Key is required', 'car_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('device_type'))) {
$response = array('status' => 0, 'message' => 'Device type is required', 'car_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('user_id'))) {
$response = array('status' => 0, 'message' => 'User ID is required', 'car_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('make'))) {
$response = array('status' => 0, 'message' => 'Make is required', 'car_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('car_no'))) {
$response = array('status' => 0, 'message' => 'Car no field is required', 'car_details' => $this->obj);
$this->displayOutput($response);
}
if (!empty($this->input->post('car_no'))) {
$result = $this->mstaff->checkCarRegistered(array('car_no' => $this->input->post('car_no'), 'car_id !=' => $this->input->post('car_id')));
if (!empty($result)) {
$response = array('status' => 0, 'message' => 'Car no. already exist', 'car_details' => $this->obj);
$this->displayOutput($response);
}
}
if (empty($this->input->post('vehicle_type'))) {
$response = array('status' => 0, 'message' => 'Vehicle Type is required', 'car_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('company_id'))) {
$response = array('status' => 0, 'message' => 'Company ID is required', 'car_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('odometer_reading'))) {
$response = array('status' => 0, 'message' => 'Odometer reading is required', 'car_details' => $this->obj);
$this->displayOutput($response);
}
$access_token_result = $this->check_access_token($this->input->post('token_key'), $this->input->post('device_type'), $this->input->post('user_id'));
if (empty($access_token_result)) {
$response = array('status' => 2, 'message' => 'Unauthorize Token', 'car_details' => $this->obj);
$this->displayOutput($response);
} else {
$car_data = array();
$car_data['car_no'] = $this->input->post('car_no');
$car_data['company_id'] = $this->input->post('company_id');
$car_data['car_type'] = $this->input->post('vehicle_type');
$car_data['total_odometer_reading'] = $this->input->post('odometer_reading');
$car_data['make'] = $this->input->post('make');
$car_data['model'] = $this->input->post('model');
$car_data['year'] = $this->input->post('year');
$car_data['fuel_type'] = $this->input->post('fuel_type');
$car_data['service_kilometer'] = $this->input->post('service_kilometer');
$car_data['transmission_service'] = $this->input->post('transmission_service');
$car_data['spark_plug_for_eg'] = $this->input->post('spark_plug_for_eg');
$car_data['is_hybrid'] = $this->input->post('is_hybrid');
$car_data['status'] = $this->input->post('status');
$car_data['created_by'] = $this->input->post('user_id');
$car_data['created_ts'] = date('Y-m-d h:i:s');
if ($this->input->post('rego_expire_date')) {
$car_data['rego_expire_date'] = date('Y-m-d', strtotime(str_replace('/', '-', $this->input->post('rego_expire_date'))));
}
if ($this->input->post('insurance_expire_date')) {
$car_data['insurance_expire_date'] = date('Y-m-d', strtotime(str_replace('/', '-', $this->input->post('insurance_expire_date'))));
}
if (isset($_FILES['car_pic']['name']) && !empty($_FILES['car_pic']['name'])) {
$path = './public/admin_images/car_pics/';
$upload_file = $this->single_image_upload($path, $_FILES['car_pic'], 'car_pic');
if ($upload_file['status'] == 1) {
$car_data['car_pic'] = $upload_file['result'];
}
}
if (isset($_FILES['insurance_expire_pic']['name']) && !empty($_FILES['insurance_expire_pic']['name'])) {
$path = './public/admin_images/insurance_expire_pics/';
$upload_file = $this->single_image_upload($path, $_FILES['insurance_expire_pic'], 'insurance_expire_pic');
if ($upload_file['status'] == 1) {
$car_data['insurance_expire_pic'] = $upload_file['result'];
}
}
}
$added_car = $this->mstaff->insert('master_car', $car_data);
if ($added_car) {
//************************************************************************************//
//************************This Part is for Activity Log*******************************//
$activityLogData = array(
'activity_type' => '<b>Add Car</b>',
'description' => 'New Car - '.$this->input->post('car_no').' Added',
'link' => 'admin/car',
'icon' => '<i class="fa fa-history" aria-hidden="true"></i>',
'created_by' => $this->input->post('user_id'),
);
$this->activity_log_app($activityLogData);
//************************This Part is for Activity Log*******************************//
//************************************************************************************//
$response = array('status' => 1, 'message' => 'Car Added successfully', 'car_details' => $this->obj);
} else {
$response = array('status' => 0, 'message' => 'Oops!Something went wrong...', 'car_details' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'car_details' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'car_details' => $this->obj);
}
$this->displayOutput($response);
}
public function editCar()
{
if ($this->checkHttpMethods($this->http_methods[0])) {
if (!empty($this->input->post())) {
if (empty($this->input->post('token_key'))) {
$response = array('status' => 0, 'message' => 'Token Key is required', 'car_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('device_type'))) {
$response = array('status' => 0, 'message' => 'Device type is required', 'car_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('user_id'))) {
$response = array('status' => 0, 'message' => 'User ID is required', 'car_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('car_id'))) {
$response = array('status' => 0, 'message' => 'Car ID is required', 'car_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('make'))) {
$response = array('status' => 0, 'message' => 'Make is required', 'car_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('car_no'))) {
$response = array('status' => 0, 'message' => 'Car no field is required', 'car_details' => $this->obj);
$this->displayOutput($response);
}
if (!empty($this->input->post('car_no'))) {
$result = $this->mstaff->checkCarRegistered(array('car_no' => $this->input->post('car_no'), 'car_id !=' => $this->input->post('car_id')));
if (!empty($result)) {
$response = array('status' => 0, 'message' => 'Car no. already exist', 'car_details' => $this->obj);
$this->displayOutput($response);
}
}
if (empty($this->input->post('vehicle_type'))) {
$response = array('status' => 0, 'message' => 'Vehicle Type is required', 'car_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('company_id'))) {
$response = array('status' => 0, 'message' => 'Company ID is required', 'car_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('odometer_reading'))) {
$response = array('status' => 0, 'message' => 'Odometer reading is required', 'car_details' => $this->obj);
$this->displayOutput($response);
}
$access_token_result = $this->check_access_token($this->input->post('token_key'), $this->input->post('device_type'), $this->input->post('user_id'));
if (empty($access_token_result)) {
$response = array('status' => 2, 'message' => 'Unauthorize Token', 'car_details' => $this->obj);
$this->displayOutput($response);
} else {
$available_car_cnt = $this->mstaff->available_car_cnt($this->input->post('car_id'));
if($available_car_cnt == 0){
$response = array('status' => 0, 'message' => 'This Car is allready rentout mode', 'car_details' => $this->obj);
$this->displayOutput($response);
}
$car_details = $this->db->from('master_car')->where('car_id',$this->input->post('car_id'))->get()->row_array();
$rent_out_details = $this->db->from('rent_out_vehcile')->where('car_id',$this->input->post('car_id'))->get()->row_array();
if(!empty($rent_out_details) && ($this->input->post('odometer_reading') < $car_details['total_odometer_reading'])){
$response = array('status' => 0, 'message' => 'Odometer reading should not less than previous reading', 'car_details' => $this->obj);
$this->displayOutput($response);
}
$car_data = array();
$car_data['car_no'] = $this->input->post('car_no');
$car_data['company_id'] = $this->input->post('company_id');
$car_data['car_type'] = $this->input->post('vehicle_type');
$car_data['total_odometer_reading'] = $this->input->post('odometer_reading');
$car_data['make'] = $this->input->post('make');
$car_data['model'] = $this->input->post('model');
$car_data['year'] = $this->input->post('year');
$car_data['fuel_type'] = $this->input->post('fuel_type');
$car_data['service_kilometer'] = $this->input->post('service_kilometer');
$car_data['transmission_service'] = $this->input->post('transmission_service');
$car_data['spark_plug_for_eg'] = $this->input->post('spark_plug_for_eg');
$car_data['is_hybrid'] = $this->input->post('is_hybrid');
$car_data['status'] = $this->input->post('status');
$car_data['updated_by'] = $this->input->post('user_id');
$car_data['updated_ts'] = date('Y-m-d h:i:s');
if ($this->input->post('rego_expire_date')) {
$car_data['rego_expire_date'] = date('Y-m-d', strtotime(str_replace('/', '-', $this->input->post('rego_expire_date'))));
}
if ($this->input->post('insurance_expire_date')) {
$car_data['insurance_expire_date'] = date('Y-m-d', strtotime(str_replace('/', '-', $this->input->post('insurance_expire_date'))));
}
if (isset($_FILES['car_pic']['name']) && !empty($_FILES['car_pic']['name'])) {
$path = './public/admin_images/car_pics/';
$upload_file = $this->single_image_upload($path, $_FILES['car_pic'], 'car_pic');
if ($upload_file['status'] == 1) {
$car_data['car_pic'] = $upload_file['result'];
}
}
if (isset($_FILES['insurance_expire_pic']['name']) && !empty($_FILES['insurance_expire_pic']['name'])) {
$path = './public/admin_images/insurance_expire_pics/';
$upload_file = $this->single_image_upload($path, $_FILES['insurance_expire_pic'], 'insurance_expire_pic');
if ($upload_file['status'] == 1) {
$car_data['insurance_expire_pic'] = $upload_file['result'];
}
}
}
$condition = array('car_id' => $this->input->post('car_id'));
$update_car = $this->mstaff->update('master_car', $condition, $car_data);
if ($update_car) {
//************************************************************************************//
//************************This Part is for Activity Log*******************************//
$activityLogData = array(
'activity_type' => '<b>Update Car</b>',
'description' => 'Car - '.$this->input->post('car_no').' Updated',
'link' => 'admin/car/editcar/'.$this->input->post('car_id'),
'icon' => '<i class="fa fa-history" aria-hidden="true"></i>',
'created_by' => $this->input->post('user_id'),
);
$this->activity_log_app($activityLogData);
//************************This Part is for Activity Log*******************************//
//************************************************************************************//
$response = array('status' => 1, 'message' => 'Car updated successfully', 'car_details' => $this->obj);
} else {
$response = array('status' => 0, 'message' => 'Oops!Something went wrong...', 'car_details' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'car_details' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'car_details' => $this->obj);
}
$this->displayOutput($response);
}
public function updateProfile()
{
//$ap = json_decode(file_get_contents('php://input'), true);
if ($this->checkHttpMethods($this->http_methods[0])) {
if (!empty($this->input->post())) {
if (empty($this->input->post('token_key'))) {
$response = array('status' => 0, 'message' => 'Token Key is required', 'profile_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('device_type'))) {
$response = array('status' => 0, 'message' => 'Device type is required', 'profile_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('user_id'))) {
$response = array('status' => 0, 'message' => 'User ID is required', 'profile_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('full_name'))) {
$response = array('status' => 0, 'message' => 'Full Name field is required', 'profile_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('mobile_no'))) {
$response = array('status' => 0, 'message' => 'Mobile No field is required', 'profile_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('gender'))) {
$response = array('status' => 0, 'message' => 'Gender field is required', 'profile_details' => $this->obj);
$this->displayOutput($response);
}
$access_token_result = $this->check_access_token($this->input->post('token_key'), $this->input->post('device_type'));
if (empty($access_token_result)) {
$response = array('status' => 2, 'message' => 'Unauthorize Token', 'driver_details' => $this->obj);
$this->displayOutput($response);
} else {
$profile_data['full_name'] = $this->input->post('full_name');
$profile_data['gender'] = $this->input->post('gender');
$profile_data['mobile_no'] = $this->input->post('mobile_no');
$profile_data['address'] = $this->input->post('address');
$profile_data['abn'] = $this->input->post('abn');
$profile_data['tfn'] = $this->input->post('tfn');
$profile_data['updated_by'] = $this->input->post('user_id');
$profile_data['updated_ts'] = date('Y-m-d H:i:s');
if (isset($_FILES['user_image']['name']) && !empty($_FILES['user_image']['name'])) {
$path = './public/admin_images/user_images/';
$upload_file = $this->single_image_upload($path, $_FILES['user_image'], 'user_image');
if ($upload_file['status'] == 1) {
$profile_data['user_image'] = $upload_file['result'];
}
}
$condition = array('user_id' => $this->input->post('user_id'));
$profile_details = $this->mstaff->update('master_admin', $condition, $profile_data);
if ($profile_details) {
//************************************************************************************//
//************************This Part is for Activity Log*******************************//
$activityLogData = array(
'activity_type' => '<b>Update Profile</b>',
'description' => 'Profile - '.$this->input->post('full_name').' Updated',
'link' => 'admin/user/edituser/'.$this->input->post('user_id'),
'icon' => '<i class="fa fa-history" aria-hidden="true"></i>',
'created_by' => $this->input->post('user_id'),
);
$this->activity_log_app($activityLogData);
//************************This Part is for Activity Log*******************************//
//************************************************************************************//
$response = array('status' => 1, 'message' => 'My Profile Updated successfully', 'profile_details' => $profile_data);
} else {
$response = array('status' => 0, 'message' => 'Oops!Something went wrong...', 'profile_details' => $this->obj);
}
}
} else {
$response = array('status' => 1, 'message' => 'Please fill up all required fields', 'profile_details' => $this->obj);
}
} else {
$response = array('status' => 1, 'message' => 'Wrong http method type', 'profile_details' => $this->obj);
}
$this->displayOutput($response);
}
//Profile Details
public function myProfile()
{
$ap = json_decode(file_get_contents('php://input'), true);
if ($this->checkHttpMethods($this->http_methods[0])) {
if (sizeof($ap)) {
if (empty($ap['token_key'])) {
$response = array('status' => 0, 'message' => 'Token Key is required', 'profile_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['device_type'])) {
$response = array('status' => 0, 'message' => 'Device type is required', 'profile_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['user_id'])) {
$response = array('status' => 0, 'message' => 'User ID is required', 'profile_details' => $this->obj);
$this->displayOutput($response);
}
$access_token_result = $this->check_access_token($ap['token_key'], $ap['device_type'], $ap['user_id']);
if (empty($access_token_result)) {
$response = array('status' => 2, 'message' => 'Unauthorize Token', 'profile_details' => $this->obj);
$this->displayOutput($response);
} else {
$profile_details = $this->mstaff->get_user_details($ap['user_id']);
if (!empty($profile_details['user_image'])) {
$profile_details['user_image'] = '/public/admin_images/user_images/' . $profile_details['user_image'];
} else {
$profile_details['user_image'] = '';
}
if (!empty($profile_details)) {
$response = array('status' => 1, 'message' => 'Profile Details Fetched Successfully', 'profile_details' => $profile_details);
} else {
$response = array('status' => 1, 'message' => 'No Data Found', 'profile_details' => $this->obj);
}
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'profile_details' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'profile_details' => $this->obj);
}
$this->displayOutput($response);
}
// Logout
public function logout()
{
$ap = json_decode(file_get_contents('php://input'), true);
if ($this->checkHttpMethods($this->http_methods[0])) {
if (sizeof($ap)) {
if (empty($ap['token_key'])) {
$response = array('status' => 0, 'message' => 'Token Key is required', 'result' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['device_type'])) {
$response = array('status' => 0, 'message' => 'Device type is required', 'result' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['user_id'])) {
$response = array('status' => 0, 'message' => 'User ID is required', 'result' => $this->obj);
$this->displayOutput($response);
}
// if (empty($ap['shift_id'])) {
// $response = array('status' => 1, 'message' => 'Shift ID is required', 'result' => $this->obj);
// $this->displayOutput($response);
// }
$access_token_result = $this->check_access_token($ap['token_key'], $ap['device_type'], $ap['user_id']);
if (empty($access_token_result)) {
$response = array('status' => 2, 'message' => 'Unauthorize Token', 'result' => $this->obj);
$this->displayOutput($response);
} else {
$condition = array('user_id' => $ap['user_id']);
$user_data['login_status'] = 0;
$login_data['updated_by'] = $ap['user_id'];
$login_data['updated_ts'] = date('Y-m-d h:i:s');
$this->mstaff->update('master_admin', $condition, $user_data);
$condition['device_type'] = $ap['device_type'];
$api_token_data = array();
$api_token_data['token_key'] = '';
$api_token_data['session_end_time'] = date('Y-m-d H:i:s');
$this->mstaff->update('api_token_admin', $condition, $api_token_data);
//************************************************************************************//
//************************This Part is for Activity Log*******************************//
$activityLogData = array(
'activity_type' => '<b>Logout</b>',
'description' => 'Logout time - '.$api_token_data['session_end_time'],
'link' => 'admin/login',
'icon' => '<i class="fa fa-history" aria-hidden="true"></i>',
'created_by' => $ap['user_id'],
);
$this->activity_log_app($activityLogData);
//************************This Part is for Activity Log*******************************//
//************************************************************************************//
$response = array('status' => 1, 'message' => "Logout Successfully", 'result' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'result' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'result' => $this->obj);
}
$this->displayOutput($response);
}
public function getDriverList()
{
$ap = json_decode(file_get_contents('php://input'), true);
if ($this->checkHttpMethods($this->http_methods[0])) {
if (sizeof($ap)) {
if (empty($ap['token_key'])) {
$response = array('status' => 0, 'message' => 'Token Key is required', 'driver_list' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['device_type'])) {
$response = array('status' => 0, 'message' => 'Device type is required', 'driver_list' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['user_id'])) {
$response = array('status' => 0, 'message' => 'User ID is required', 'driver_list' => $this->obj);
$this->displayOutput($response);
}
$access_token_result = $this->check_access_token($ap['token_key'], $ap['device_type'], $ap['user_id']);
if (empty($access_token_result)) {
$response = array('status' => 2, 'message' => 'Unauthorize Token', 'driver_list' => $this->obj);
$this->displayOutput($response);
} else {
$driver_list = $this->mstaff->get_driver_list();
if (!empty($driver_list)) {
foreach ($driver_list as $driver_key => $driver) {
$driver_list[$driver_key]['licence_image'] = '';
$driver_list[$driver_key]['licence_expiry_image'] = '';
$driver_list[$driver_key]['passport_no_image'] = '';
$driver_list[$driver_key]['passport_expiry_image'] = '';
$driver_list[$driver_key]['utility_bill_image'] = '';
$driver_list[$driver_key]['profile_photo'] = '';
if (!empty($driver['licence_image'])) {
$driver_list[$driver_key]['licence_image'] = base_url().'public/admin_images/driver/licence_image/' . $driver['licence_image'];
}
if (!empty($driver['licence_expiry_image'])) {
$driver_list[$driver_key]['licence_expiry_image'] = base_url().'public/admin_images/driver/licence_expiry_image/' . $driver['licence_expiry_image'];
}
if (!empty($driver['passport_no_image'])) {
$driver_list[$driver_key]['passport_no_image'] = base_url().'public/admin_images/driver/passport_no_image/' . $driver['passport_no_image'];
}
if (!empty($driver['passport_expiry_image'])) {
$driver_list[$driver_key]['passport_expiry_image'] = base_url().'public/admin_images/driver/passport_expiry_image/' . $driver['passport_expiry_image'];
}
if (!empty($driver['utility_bill_image'])) {
$driver_list[$driver_key]['utility_bill_image'] = base_url().'public/admin_images/driver/utility_bill_image/' . $driver['utility_bill_image'];
}
if (!empty($driver['profile_photo'])) {
$driver_list[$driver_key]['profile_photo'] = base_url().'public/admin_images/driver/profile_image/' . $driver['profile_photo'];
}
$driver_bond_details = $this->mstaff->get_driver_bond_details($driver['driver_id']);
$driver_list[$driver_key]['bond_details'] = $driver_bond_details;
}
$response = array('status' => 1, 'message' => 'Driver List Fetched Successfully', 'driver_list' => $driver_list);
} else {
$response = array('status' => 1, 'message' => 'No Data Found', 'driver_list' => $this->obj);
}
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'driver_list' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'driver_list' => $this->obj);
}
$this->displayOutput($response);
}
public function validateDriver()
{
if ($this->checkHttpMethods($this->http_methods[0])) {
if (!empty($this->input->post())) {
if (empty($this->input->post('token_key'))) {
$response = array('status' => 0, 'message' => 'Token Key is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('device_type'))) {
$response = array('status' => 0, 'message' => 'Device type is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('user_id'))) {
$response = array('status' => 0, 'message' => 'User ID is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('driver_id'))) {
$response = array('status' => 0, 'message' => 'Driver ID is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('first_name'))) {
$response = array('status' => 0, 'message' => 'First Name is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('last_name'))) {
$response = array('status' => 0, 'message' => 'Last Name is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('pin'))) {
$response = array('status' => 0, 'message' => 'Pin is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('mobile'))) {
$response = array('status' => 0, 'message' => 'Mobile is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('is_australian_licence'))) {
$response = array('status' => 0, 'message' => 'Australian licence is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if ($this->input->post('is_australian_licence') == 'No') {
if (empty($this->input->post('passport_no'))) {
$response = array('status' => 0, 'message' => 'Passport no is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('passport_expiry'))) {
$response = array('status' => 0, 'message' => 'Passport Expiry is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('utility_bill_id'))) {
$response = array('status' => 0, 'message' => 'Utility bill is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
}
if (empty($this->input->post('bank_name'))) {
$response = array('status' => 0, 'message' => 'Bank name is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('account_no'))) {
$response = array('status' => 0, 'message' => 'Account no. is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('approve_or_reject'))) {
$response = array('status' => 0, 'message' => 'Approve or reject flag is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
// if (empty($this->input->post('bond_amount'))) {
// $response = array('status' => 0, 'message' => 'Bond amount is required', 'driver_details' => $this->obj);
// $this->displayOutput($response);
// }
// if (empty($this->input->post('bond_date'))) {
// $response = array('status' => 0, 'message' => 'Bond date is required', 'driver_details' => $this->obj);
// $this->displayOutput($response);
// }
$result = $this->mstaff->checkDriverDetails(array('driver_id' => $this->input->post('driver_id')));
if (empty($result)) {
$response = array('status' => 0, 'message' => 'Driver ID not exist', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if ($result['status'] != '0') {
$response = array('status' => 0, 'message' => 'Driver already validated', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
$access_token_result = $this->check_access_token($this->input->post('token_key'), $this->input->post('device_type'), $this->input->post('user_id'));
if (empty($access_token_result)) {
$response = array('status' => 2, 'message' => 'Unauthorize Token', 'driver_details' => $this->obj);
$this->displayOutput($response);
} else {
$driver_data = array();
$driver_data['first_name'] = $this->input->post('first_name');
$driver_data['middle_name'] = $this->input->post('middle_name');
$driver_data['last_name'] = $this->input->post('last_name');
$driver_data['flat_no'] = $this->input->post('flat_no');
$driver_data['street_no'] = $this->input->post('street_no');
$driver_data['street_name'] = $this->input->post('street_name');
$driver_data['suburb'] = $this->input->post('suburb');
$driver_data['pin'] = $this->input->post('pin');
$driver_data['mobile'] = $this->input->post('mobile');
if ($this->input->post('dob')) {
$driver_data['dob'] = date('Y-m-d', strtotime(str_replace('/', '-', $this->input->post('dob'))));
}
$driver_data['licence_no'] = $this->input->post('licence_no');
if ($this->input->post('licence_expiry')) {
$driver_data['licence_expiry'] = date('Y-m-d', strtotime(str_replace('/', '-', $this->input->post('licence_expiry'))));
}
$driver_data['is_australian_licence'] = $this->input->post('is_australian_licence');
if($driver_data['is_australian_licence'] == 'No'){
$driver_data['passport_no'] = $this->input->post('passport_no');
if ($this->input->post('passport_expiry')) {
$driver_data['passport_expiry'] = date('Y-m-d', strtotime(str_replace('/', '-', $this->input->post('passport_expiry'))));
}
$driver_data['utility_bill_id'] = $this->input->post('utility_bill_id');
}
$driver_data['bank_name'] = $this->input->post('bank_name');
$driver_data['bsb'] = $this->input->post('bsb');
$driver_data['account_no'] = $this->input->post('account_no');
$driver_data['no_of_at_fault_accidents'] = $this->input->post('no_of_at_fault_accidents');
$driver_data['no_of_not_at_fault_accidents'] = $this->input->post('no_of_not_at_fault_accidents');
$driver_data['admin_notes'] = $this->input->post('admin_notes');
$driver_data['status'] = $this->input->post('approve_or_reject');
$driver_data['updated_by'] = $this->input->post('user_id');
$driver_data['updated_ts'] = date('Y-m-d H:i:s');
if (isset($_FILES['licence_image']['name']) && !empty($_FILES['licence_image']['name'])) {
$path = './public/admin_images/driver/licence_image/';
$upload_file = $this->single_image_upload($path, $_FILES['licence_image'], 'licence_image');
if ($upload_file['status'] == 1) {
$driver_data['licence_image'] = $upload_file['result'];
}
}
if (isset($_FILES['licence_expiry_image']['name']) && !empty($_FILES['licence_expiry_image']['name'])) {
$path = './public/admin_images/driver/licence_expiry_image/';
$upload_file = $this->single_image_upload($path, $_FILES['licence_image'], 'licence_expiry_image');
if ($upload_file['status'] == 1) {
$driver_data['licence_expiry_image'] = $upload_file['result'];
}
}
$driver_data['passport_no_image'] = '';
$driver_data['passport_expiry_image'] = '';
$driver_data['utility_bill_image'] = '';
if($driver_data['is_australian_licence'] == 'No'){
if (isset($_FILES['passport_no_image']['name']) && !empty($_FILES['passport_no_image']['name'])) {
$path = './public/admin_images/driver/passport_no_image/';
$upload_file = $this->single_image_upload($path, $_FILES['passport_no_image'], 'passport_no_image');
if ($upload_file['status'] == 1) {
$driver_data['passport_no_image'] = $upload_file['result'];
}
}
if (isset($_FILES['passport_expiry_image']['name']) && !empty($_FILES['passport_expiry_image']['name'])) {
$path = './public/admin_images/driver/passport_expiry_image/';
$upload_file = $this->single_image_upload($path, $_FILES['passport_expiry_image'], 'passport_expiry_image');
if ($upload_file['status'] == 1) {
$driver_data['passport_expiry_image'] = $upload_file['result'];
}
}
if (isset($_FILES['utility_bill_image']['name']) && !empty($_FILES['utility_bill_image']['name'])) {
$path = './public/admin_images/driver/utility_bill_image/';
$upload_file = $this->single_image_upload($path, $_FILES['utility_bill_image'], 'utility_bill_image');
if ($upload_file['status'] == 1) {
$driver_data['utility_bill_image'] = $upload_file['result'];
}
}
}
if (isset($_FILES['profile_image']['name']) && !empty($_FILES['profile_image']['name'])) {
$path = './public/admin_images/driver/profile_image/';
$upload_file = $this->single_image_upload($path, $_FILES['profile_image'], 'profile_image');
if ($upload_file['status'] == 1) {
$driver_data['profile_photo'] = $upload_file['result'];
}
}
$this->db->trans_start(); # Starting Transaction
$driver_id = $this->input->post('driver_id');
$this->db->update('master_driver', $driver_data, array('driver_id' => $driver_id));
//********/ As discuss with Lovedep on 22/01/2023 remove bond from driver validation as we take bond with 1st rent out by Mrityunjoy************//
// $bond_data = array(
// 'driver_id' => $driver_id,
// 'bond_amount' => $this->input->post('bond_amount'),
// 'transaction_type' => 'CREDIT',
// 'bond_date' => date('Y-m-d', strtotime(str_replace('/', '-', $this->input->post('bond_date')))),
// 'bond_payment_method' => $this->input->post('bond_payment_method'),
// 'bond_reference_no' => $this->input->post('bond_reference_no'),
// 'bond_reference_type' => 'VALIDATE',
// 'bond_reference_id' => $driver_id,
// 'created_by' => $this->input->post('user_id'),
// 'created_ts' => date('Y-m-d H:i:s')
// );
// $this->db->insert('bond_wallet', $bond_data);
//********/ As discuss with Lovedep on 22/01/2023 remove bond from driver validation as we take bond with 1st rent out by Mrityunjoy************//
$this->db->trans_complete(); # Completing transaction
if ($this->db->trans_status() === FALSE) {
# Something went wrong.
$this->db->trans_rollback();
$response = array('status' => 0, 'message' => 'Oops!Driver validation not completed', 'driver_details' => $this->obj);
} else {
# Everything is Perfect.
# Committing data to the database.
$this->db->trans_commit();
if($this->input->post('approve_or_reject') == 1){
$response = array('status' => 1, 'message' => 'Driver validated successfully', 'driver_details' => $this->obj);
} else {
$response = array('status' => 1, 'message' => 'Driver rejected successfully', 'driver_details' => $this->obj);
}
}
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'driver_details' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'driver_details' => $this->obj);
}
$this->displayOutput($response);
}
public function editDriver()
{
if ($this->checkHttpMethods($this->http_methods[0])) {
if (!empty($this->input->post())) {
if (empty($this->input->post('token_key'))) {
$response = array('status' => 0, 'message' => 'Token Key is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('device_type'))) {
$response = array('status' => 0, 'message' => 'Device type is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('user_id'))) {
$response = array('status' => 0, 'message' => 'User ID is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('driver_id'))) {
$response = array('status' => 0, 'message' => 'Driver ID is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('first_name'))) {
$response = array('status' => 0, 'message' => 'First Name is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('last_name'))) {
$response = array('status' => 0, 'message' => 'Last Name is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('pin'))) {
$response = array('status' => 0, 'message' => 'Pin is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
// if (empty($this->input->post('mobile'))) {
// $response = array('status' => 0, 'message' => 'Mobile is required', 'driver_details' => $this->obj);
// $this->displayOutput($response);
// }
if (empty($this->input->post('is_australian_licence'))) {
$response = array('status' => 0, 'message' => 'Australian licence is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if ($this->input->post('is_australian_licence') == 'No') {
if (empty($this->input->post('passport_no'))) {
$response = array('status' => 0, 'message' => 'Passport no is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('passport_expiry'))) {
$response = array('status' => 0, 'message' => 'Passport Expiry is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('utility_bill_id'))) {
$response = array('status' => 0, 'message' => 'Utility bill is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
}
if (empty($this->input->post('bank_name'))) {
$response = array('status' => 0, 'message' => 'Bank name is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('account_no'))) {
$response = array('status' => 0, 'message' => 'Account no. is required', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
$result = $this->mstaff->checkDriverDetails(array('driver_id' => $this->input->post('driver_id')));
if (empty($result)) {
$response = array('status' => 0, 'message' => 'Driver ID not exist', 'driver_details' => $this->obj);
$this->displayOutput($response);
}
$access_token_result = $this->check_access_token($this->input->post('token_key'), $this->input->post('device_type'), $this->input->post('user_id'));
if (empty($access_token_result)) {
$response = array('status' => 2, 'message' => 'Unauthorize Token', 'driver_details' => $this->obj);
$this->displayOutput($response);
} else {
$driver_data = array();
$driver_data['first_name'] = $this->input->post('first_name');
$driver_data['middle_name'] = $this->input->post('middle_name');
$driver_data['last_name'] = $this->input->post('last_name');
$driver_data['flat_no'] = $this->input->post('flat_no');
$driver_data['street_no'] = $this->input->post('street_no');
$driver_data['street_name'] = $this->input->post('street_name');
$driver_data['suburb'] = $this->input->post('suburb');
$driver_data['pin'] = $this->input->post('pin');
if ($this->input->post('dob')) {
$driver_data['dob'] = date('Y-m-d', strtotime(str_replace('/', '-', $this->input->post('dob'))));
}
$driver_data['licence_no'] = $this->input->post('licence_no');
if ($this->input->post('licence_expiry')) {
$driver_data['licence_expiry'] = date('Y-m-d', strtotime(str_replace('/', '-', $this->input->post('licence_expiry'))));
}
$driver_data['is_australian_licence'] = $this->input->post('is_australian_licence');
if ($driver_data['is_australian_licence'] == 'No') {
$driver_data['passport_no'] = $this->input->post('passport_no');
if ($this->input->post('passport_expiry')) {
$driver_data['passport_expiry'] = date('Y-m-d', strtotime(str_replace('/', '-', $this->input->post('passport_expiry'))));
}
$driver_data['utility_bill_id'] = $this->input->post('utility_bill_id');
}
$driver_data['bank_name'] = $this->input->post('bank_name');
$driver_data['bsb'] = $this->input->post('bsb');
$driver_data['account_no'] = $this->input->post('account_no');
$driver_data['no_of_at_fault_accidents'] = $this->input->post('no_of_at_fault_accidents');
$driver_data['no_of_not_at_fault_accidents'] = $this->input->post('no_of_not_at_fault_accidents');
$driver_data['admin_notes'] = $this->input->post('admin_notes');
$driver_data['status'] = '1';
$driver_data['updated_by'] = $this->input->post('driver_id');
$driver_data['updated_ts'] = date('Y-m-d H:i:s');
if (isset($_FILES['licence_image']['name']) && !empty($_FILES['licence_image']['name'])) {
$path = './public/admin_images/driver/licence_image/';
$upload_file = $this->single_image_upload($path, $_FILES['licence_image'], 'licence_image');
if ($upload_file['status'] == 1) {
$driver_data['licence_image'] = $upload_file['result'];
}
}
if (isset($_FILES['licence_expiry_image']['name']) && !empty($_FILES['licence_expiry_image']['name'])) {
$path = './public/admin_images/driver/licence_expiry_image/';
$upload_file = $this->single_image_upload($path, $_FILES['licence_image'], 'licence_expiry_image');
if ($upload_file['status'] == 1) {
$driver_data['licence_expiry_image'] = $upload_file['result'];
}
}
if ($driver_data['is_australian_licence'] == 'No') {
if (isset($_FILES['passport_no_image']['name']) && !empty($_FILES['passport_no_image']['name'])) {
$path = './public/admin_images/driver/passport_no_image/';
$upload_file = $this->single_image_upload($path, $_FILES['passport_no_image'], 'passport_no_image');
if ($upload_file['status'] == 1) {
$driver_data['passport_no_image'] = $upload_file['result'];
}
}
if (isset($_FILES['passport_expiry_image']['name']) && !empty($_FILES['passport_expiry_image']['name'])) {
$path = './public/admin_images/driver/passport_expiry_image/';
$upload_file = $this->single_image_upload($path, $_FILES['passport_expiry_image'], 'passport_expiry_image');
if ($upload_file['status'] == 1) {
$driver_data['passport_expiry_image'] = $upload_file['result'];
}
}
if (isset($_FILES['utility_bill_image']['name']) && !empty($_FILES['utility_bill_image']['name'])) {
$path = './public/admin_images/driver/utility_bill_image/';
$upload_file = $this->single_image_upload($path, $_FILES['utility_bill_image'], 'utility_bill_image');
if ($upload_file['status'] == 1) {
$driver_data['utility_bill_image'] = $upload_file['result'];
}
}
}
if (isset($_FILES['profile_image']['name']) && !empty($_FILES['profile_image']['name'])) {
$path = './public/admin_images/driver/profile_image/';
$upload_file = $this->single_image_upload($path, $_FILES['profile_image'], 'profile_image');
if ($upload_file['status'] == 1) {
$driver_data['profile_photo'] = $upload_file['result'];
}
}
$this->db->trans_start(); # Starting Transaction
$driver_id = $this->input->post('driver_id');
$this->db->update('master_driver', $driver_data, array('driver_id' => $driver_id));
$this->db->trans_complete(); # Completing transaction
if ($this->db->trans_status() === FALSE) {
# Something went wrong.
$this->db->trans_rollback();
$response = array('status' => 0, 'message' => 'Oops!Driver not updated', 'driver_details' => $this->obj);
} else {
# Everything is Perfect.
# Committing data to the database.
$this->db->trans_commit();
//************************************************************************************//
//************************This Part is for Activity Log*******************************//
$activityLogData = array(
'activity_type' => '<b>Update Driver</b>',
'description' => 'Driver - '.$this->input->post('first_name').' '.$this->input->post('middle_name').' '.$this->input->post('last_name').' Updated',
'link' => 'admin/driver/editdriver/'.$driver_id,
'icon' => '<i class="fa fa-history" aria-hidden="true"></i>',
'created_by' => $this->input->post('user_id'),
);
$this->activity_log_app($activityLogData);
//************************This Part is for Activity Log*******************************//
//************************************************************************************//
$response = array('status' => 1, 'message' => 'Driver updated successfully', 'driver_details' => $this->obj);
}
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'driver_details' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'driver_details' => $this->obj);
}
$this->displayOutput($response);
}
public function getRentOutList()
{
$ap = json_decode(file_get_contents('php://input'), true);
if ($this->checkHttpMethods($this->http_methods[0])) {
if (sizeof($ap)) {
if (empty($ap['token_key'])) {
$response = array('status' => 0, 'message' => 'Token Key is required', 'rentout_list' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['device_type'])) {
$response = array('status' => 0, 'message' => 'Device type is required', 'rentout_list' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['user_id'])) {
$response = array('status' => 0, 'message' => 'User ID is required', 'rentout_list' => $this->obj);
$this->displayOutput($response);
}
$access_token_result = $this->check_access_token($ap['token_key'], $ap['device_type'], $ap['user_id']);
if (empty($access_token_result)) {
$response = array('status' => 2, 'message' => 'Unauthorize Token', 'rentout_list' => $this->obj);
$this->displayOutput($response);
} else {
$rentout_list = $this->mstaff->getRentoutDetails();
if (!empty($rentout_list)) {
foreach ($rentout_list as $rentout_key => $rentout) {
if (!empty($rentout['expire']) && ($rentout['expire'] !='0000-00-00')) {
$rentout_list[$rentout_key]['expire'] = date('d/m/Y',strtotime($rentout['expire']));
} else {
$rentout_list[$rentout_key]['expire'] = '';
}
if (!empty($rentout['cover_note_img'])) {
$rentout_list[$rentout_key]['cover_note_img'] = '/public/admin_images/rent_out/cover_note_imgs/' . $rentout['cover_note_img'];
} else {
$rentout_list[$rentout_key]['cover_note_img'] = '';
}
if (!empty($rentout['front_img'])) {
$rentout_list[$rentout_key]['front_img'] = '/public/admin_images/rent_out/front_imgs/' . $rentout['front_img'];
} else {
$rentout_list[$rentout_key]['front_img'] = '';
}
if (!empty($rentout['rear_img'])) {
$rentout_list[$rentout_key]['rear_img'] = '/public/admin_images/rent_out/rear_imgs/' . $rentout['rear_img'];
} else {
$rentout_list[$rentout_key]['rear_img'] = '';
}
if (!empty($rentout['driver_side_img'])) {
$rentout_list[$rentout_key]['driver_side_img'] = '/public/admin_images/rent_out/driver_side_imgs/' . $rentout['driver_side_img'];
} else {
$rentout_list[$rentout_key]['driver_side_img'] = '';
}
if (!empty($rentout['passenger_side_img'])) {
$rentout_list[$rentout_key]['passenger_side_img'] = '/public/admin_images/rent_out/passenger_side_imgs/' . $rentout['passenger_side_img'];
} else {
$rentout_list[$rentout_key]['passenger_side_img'] = '';
}
if (!empty($rentout['odometer_img'])) {
$rentout_list[$rentout_key]['odometer_img'] = '/public/admin_images/rent_out/odometer_imgs/' . $rentout['odometer_img'];
} else {
$rentout_list[$rentout_key]['odometer_img'] = '';
}
if (!empty($rentout['service_sticker_img'])) {
$rentout_list[$rentout_key]['service_sticker_img'] = '/public/admin_images/rent_out/service_sticker_imgs/' . $rentout['service_sticker_img'];
} else {
$rentout_list[$rentout_key]['service_sticker_img'] = '';
}
if (!empty($rentout['fuel_guage_img'])) {
$rentout_list[$rentout_key]['fuel_guage_img'] = '/public/admin_images/rent_out/fuel_guage_imgs/' . $rentout['fuel_guage_img'];
} else {
$rentout_list[$rentout_key]['fuel_guage_img'] = '';
}
}
$response = array('status' => 1, 'message' => 'Rent Out List Fetched Successfully', 'rentout_list' => $rentout_list);
} else {
$response = array('status' => 1, 'message' => 'No Data Found', 'rentout_list' => $this->obj);
}
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'rentout_list' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'rentout_list' => $this->obj);
}
$this->displayOutput($response);
}
public function addRentOut()
{
if ($this->checkHttpMethods($this->http_methods[0])) {
if (!empty($this->input->post())) {
if (empty($this->input->post('token_key'))) {
$response = array('status' => 0, 'message' => 'Token Key is required', 'rentout_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('device_type'))) {
$response = array('status' => 0, 'message' => 'Device type is required', 'rentout_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('user_id'))) {
$response = array('status' => 0, 'message' => 'User ID is required', 'rentout_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('driver_id'))) {
$response = array('status' => 0, 'message' => 'Driver ID is required', 'rentout_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('car_id'))) {
$response = array('status' => 0, 'message' => 'Car ID is required', 'rentout_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('odometer_reading'))) {
$response = array('status' => 0, 'message' => 'Odometer Reading is required', 'rentout_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('weekly_rent'))) {
$response = array('status' => 0, 'message' => 'Weekly Rent is required', 'rentout_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('insurance_company'))) {
$response = array('status' => 0, 'message' => 'Insurance Company is required', 'rentout_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('expire'))) {
$response = array('status' => 0, 'message' => 'Expire is required', 'rentout_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('payment_method'))) {
$response = array('status' => 0, 'message' => 'Payment method is required', 'rentout_details' => $this->obj);
$this->displayOutput($response);
}
$access_token_result = $this->check_access_token($this->input->post('token_key'), $this->input->post('device_type'), $this->input->post('user_id'));
if (empty($access_token_result)) {
$response = array('status' => 2, 'message' => 'Unauthorize Token', 'rentout_details' => $this->obj);
$this->displayOutput($response);
} else {
$car_id=$this->input->post('car_id');
$car_id_array=explode('#$',$car_id);
$odometer_reading=$this->input->post('odometer_reading');
$car_details = $this->mstaff->edit_car($car_id_array[0]);
if($car_details['total_odometer_reading'] > $odometer_reading){
$response = array('status' => 0, 'message' => 'Rent Out <b>Odometer Reading</b> must be grater than this car previous <b>Odometer Reading</b>.', 'rentout_details' => $this->obj);
$this->displayOutput($response);
}
$rentout_data = array();
$rentout_data['driver_id'] = $this->input->post('driver_id');
$rentout_data['car_id'] = $car_id_array[0];
$rentout_data['odometer_reading'] =$odometer_reading;
$rentout_data['basic_excess'] = $this->input->post('basic_excess');
$rentout_data['age_excess'] = $this->input->post('age_excess');
$rentout_data['overseas_dL_excess'] = $this->input->post('overseas_dL_excess');
$rentout_data['weekly_rent'] = $this->input->post('weekly_rent');
$rentout_data['payment_method'] = $this->input->post('payment_method');
$rentout_data['payment_reference_no'] = $this->input->post('payment_reference_no');
$rentout_data['bond_amount']= $this->input->post('bond_amount');
//$rentout_data['company_id']= $this->input->post('company_id');
$rentout_data['notes']= $this->input->post('notes');
$rentout_data['rent_out_no']='RO'.time().'/CAR'.$car_id_array[1];
$rentout_data['created_by'] = $this->input->post('user_id');
$rentout_data['created_ts'] = date('Y-m-d H:i:s');
if ($this->input->post('expire')) {
$rentout_data['expire'] = date('Y-m-d',strtotime(str_replace('/', '-', $this->input->post('expire'))));
}
if (isset($_FILES['cover_note_img']['name']) && !empty($_FILES['cover_note_img']['name'])) {
$path = './public/admin_images/rent_out/cover_note_imgs/';
$upload_file = $this->single_image_upload($path, $_FILES['cover_note_img'], 'cover_note_img');
if ($upload_file['status'] == 1) {
$rentout_data['cover_note_img'] = $upload_file['result'];
}
}
if (isset($_FILES['front_img']['name']) && !empty($_FILES['front_img']['name'])) {
$path = './public/admin_images/rent_out/front_imgs/';
$upload_file = $this->single_image_upload($path, $_FILES['front_img'], 'front_img');
if ($upload_file['status'] == 1) {
$rentout_data['front_img'] = $upload_file['result'];
}
}
if (isset($_FILES['rear_img']['name']) && !empty($_FILES['rear_img']['name'])) {
$path = './public/admin_images/rent_out/rear_imgs/';
$upload_file = $this->single_image_upload($path, $_FILES['rear_img'], 'rear_img');
if ($upload_file['status'] == 1) {
$rentout_data['rear_img'] = $upload_file['result'];
}
}
if (isset($_FILES['driver_side_img']['name']) && !empty($_FILES['driver_side_img']['name'])) {
$path = './public/admin_images/rent_out/driver_side_imgs/';
$upload_file = $this->single_image_upload($path, $_FILES['driver_side_img'], 'driver_side_img');
if ($upload_file['status'] == 1) {
$rentout_data['driver_side_img'] = $upload_file['result'];
}
}
if (isset($_FILES['passenger_side_img']['name']) && !empty($_FILES['passenger_side_img']['name'])) {
$path = './public/admin_images/rent_out/passenger_side_imgs/';
$upload_file = $this->single_image_upload($path, $_FILES['passenger_side_img'], 'passenger_side_img');
if ($upload_file['status'] == 1) {
$rentout_data['passenger_side_img'] = $upload_file['result'];
}
}
if (isset($_FILES['odometer_img']['name']) && !empty($_FILES['odometer_img']['name'])) {
$path = './public/admin_images/rent_out/odometer_imgs/';
$upload_file = $this->single_image_upload($path, $_FILES['odometer_img'], 'odometer_img');
if ($upload_file['status'] == 1) {
$rentout_data['odometer_img'] = $upload_file['result'];
}
}
if (isset($_FILES['service_sticker_img']['name']) && !empty($_FILES['service_sticker_img']['name'])) {
$path = './public/admin_images/rent_out/service_sticker_imgs/';
$upload_file = $this->single_image_upload($path, $_FILES['service_sticker_img'], 'service_sticker_img');
if ($upload_file['status'] == 1) {
$rentout_data['service_sticker_img'] = $upload_file['result'];
}
}
if (isset($_FILES['fuel_guage_img']['name']) && !empty($_FILES['fuel_guage_img']['name'])) {
$path = './public/admin_images/rent_out/fuel_guage_imgs/';
$upload_file = $this->single_image_upload($path, $_FILES['fuel_guage_img'], 'fuel_guage_img');
if ($upload_file['status'] == 1) {
$rentout_data['fuel_guage_img'] = $upload_file['result'];
}
}
}
//print_r($rentout_data);die;
$rentout_added = $this->mstaff->insert('rent_out_vehcile', $rentout_data);
//echo $this->db->last_query();die;
$condition = array('car_id' => $car_id);
$car_data= array(
'total_odometer_reading' =>$odometer_reading,
'insurance_expire_date' => date('Y-m-d',strtotime(str_replace('/', '-', $this->input->post('expire')))),
'user_type' =>'DRIVER',
'updated_by' => $this->input->post('user_id'),
'updated_ts' => date('Y-m-d H:i:s')
);
$this->mstaff->update_car($condition, $car_data);
$bond_data = array(
'driver_id' => $this->input->post('driver_id'),
'bond_amount' => $this->input->post('bond_amount'),
'transaction_type' => 'CREDIT',
'bond_date' => date('Y-m-d'),
'bond_payment_method' => $this->input->post('bond_payment_method'),
'bond_reference_no' => $this->input->post('bond_reference_no'),
'bond_reference_type' => 'RENTOUT',
'bond_reference_id' => $rentout_added,
'created_by' => $this->input->post('user_id'),
'created_ts' => date('Y-m-d H:i:s')
);
$this->db->insert('bond_wallet', $bond_data);
$this->db->trans_complete(); # Completing transaction
if (!$this->db->trans_status()) {
# Something went wrong.
$this->db->trans_rollback();
$response = array('status' => 0, 'message' => 'Oops!Something went wrong...', 'rentout_details' => $this->obj);
} else {
# Everything is Perfect.
# Committing data to the database.
$this->db->trans_commit();
//************************************************************************************//
//************************This Part is for Activity Log*******************************//
$activityLogData = array(
'activity_type' => '<b>Add Rentout</b>',
'description' => 'New Rentout - '.$rentout_data['rent_out_no'].' Added',
'link' => 'admin/rentOut',
'icon' => '<i class="fa fa-history" aria-hidden="true"></i>',
'created_by' => $this->input->post('user_id'),
);
$this->activity_log_app($activityLogData);
//************************This Part is for Activity Log*******************************//
//************************************************************************************//
$response = array('status' => 1, 'message' => 'Rentout added successfully', 'rentout_details' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'rentout_details' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'rentout_details' => $this->obj);
}
$this->displayOutput($response);
}
public function editRentOut()
{
if ($this->checkHttpMethods($this->http_methods[0])) {
if (!empty($this->input->post())) {
if (empty($this->input->post('token_key'))) {
$response = array('status' => 0, 'message' => 'Token Key is required', 'rentout_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('device_type'))) {
$response = array('status' => 0, 'message' => 'Device type is required', 'rentout_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('user_id'))) {
$response = array('status' => 0, 'message' => 'User ID is required', 'rentout_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('driver_id'))) {
$response = array('status' => 0, 'message' => 'Driver ID is required', 'rentout_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('odometer_reading'))) {
$response = array('status' => 0, 'message' => 'Odometer Reading is required', 'rentout_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('weekly_rent'))) {
$response = array('status' => 0, 'message' => 'Weekly Rent is required', 'rentout_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('insurance_company'))) {
$response = array('status' => 0, 'message' => 'Insurance Company is required', 'rentout_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('expire'))) {
$response = array('status' => 0, 'message' => 'Expire is required', 'rentout_details' => $this->obj);
$this->displayOutput($response);
}
$access_token_result = $this->check_access_token($this->input->post('token_key'), $this->input->post('device_type'), $this->input->post('user_id'));
if (empty($access_token_result)) {
$response = array('status' => 2, 'message' => 'Unauthorize Token', 'rentout_details' => $this->obj);
$this->displayOutput($response);
} else {
$car_id=$this->input->post('car_id');
$odometer_reading=$this->input->post('odometer_reading');
$car_details = $this->mstaff->edit_car($car_id);
$rentoutDetails = $this->mstaff->getRentoutDetails($this->input->post('rent_out_id'));
if($car_details['total_odometer_reading']>$odometer_reading){
$response = array('status' => 0, 'message' => 'Rent Out <b>Odometer Reading</b> must be grater than this car previous <b>Odometer Reading</b>.', 'rentout_details' => $this->obj);
$this->displayOutput($response);
}
$rentout_data = array();
$rentout_data['driver_id'] = $this->input->post('driver_id');
$rentout_data['odometer_reading'] =$odometer_reading;
$rentout_data['basic_excess'] = $this->input->post('basic_excess');
$rentout_data['age_excess'] = $this->input->post('age_excess');
$rentout_data['overseas_dL_excess'] = $this->input->post('overseas_dL_excess');
$rentout_data['weekly_rent'] = $this->input->post('weekly_rent');
$rentout_data['payment_reference_no'] = $this->input->post('payment_reference_no');
$rentout_data['bond_amount']= $this->input->post('bond_amount');
$rentout_data['company_id']= $this->input->post('company_id');
$rentout_data['notes']= $this->input->post('notes');
$rentout_data['updated_by'] = $this->input->post('user_id');
$rentout_data['updated_ts'] = date('Y-m-d H:i:s');
if ($this->input->post('expire')) {
$rentout_data['expire'] = date('Y-m-d',strtotime(str_replace('/', '-', $this->input->post('expire'))));
}
if (isset($_FILES['cover_note_img']['name']) && !empty($_FILES['cover_note_img']['name'])) {
$path = './public/admin_images/rent_out/cover_note_imgs/';
$upload_file = $this->single_image_upload($path, $_FILES['cover_note_img'], 'cover_note_img');
if ($upload_file['status'] == 1) {
$rentout_data['cover_note_img'] = $upload_file['result'];
}
}
if (isset($_FILES['front_img']['name']) && !empty($_FILES['front_img']['name'])) {
$path = './public/admin_images/rent_out/front_imgs/';
$upload_file = $this->single_image_upload($path, $_FILES['front_img'], 'front_img');
if ($upload_file['status'] == 1) {
$rentout_data['front_img'] = $upload_file['result'];
}
}
if (isset($_FILES['rear_img']['name']) && !empty($_FILES['rear_img']['name'])) {
$path = './public/admin_images/rent_out/rear_imgs/';
$upload_file = $this->single_image_upload($path, $_FILES['rear_img'], 'rear_img');
if ($upload_file['status'] == 1) {
$rentout_data['rear_img'] = $upload_file['result'];
}
}
if (isset($_FILES['driver_side_img']['name']) && !empty($_FILES['driver_side_img']['name'])) {
$path = './public/admin_images/rent_out/driver_side_imgs/';
$upload_file = $this->single_image_upload($path, $_FILES['driver_side_img'], 'driver_side_img');
if ($upload_file['status'] == 1) {
$rentout_data['driver_side_img'] = $upload_file['result'];
}
}
if (isset($_FILES['passenger_side_img']['name']) && !empty($_FILES['passenger_side_img']['name'])) {
$path = './public/admin_images/rent_out/passenger_side_imgs/';
$upload_file = $this->single_image_upload($path, $_FILES['passenger_side_img'], 'passenger_side_img');
if ($upload_file['status'] == 1) {
$rentout_data['passenger_side_img'] = $upload_file['result'];
}
}
if (isset($_FILES['odometer_img']['name']) && !empty($_FILES['odometer_img']['name'])) {
$path = './public/admin_images/rent_out/odometer_imgs/';
$upload_file = $this->single_image_upload($path, $_FILES['odometer_img'], 'odometer_img');
if ($upload_file['status'] == 1) {
$rentout_data['odometer_img'] = $upload_file['result'];
}
}
if (isset($_FILES['service_sticker_img']['name']) && !empty($_FILES['service_sticker_img']['name'])) {
$path = './public/admin_images/rent_out/service_sticker_imgs/';
$upload_file = $this->single_image_upload($path, $_FILES['service_sticker_img'], 'service_sticker_img');
if ($upload_file['status'] == 1) {
$rentout_data['service_sticker_img'] = $upload_file['result'];
}
}
if (isset($_FILES['fuel_guage_img']['name']) && !empty($_FILES['fuel_guage_img']['name'])) {
$path = './public/admin_images/rent_out/fuel_guage_imgs/';
$upload_file = $this->single_image_upload($path, $_FILES['fuel_guage_img'], 'fuel_guage_img');
if ($upload_file['status'] == 1) {
$rentout_data['fuel_guage_img'] = $upload_file['result'];
}
}
}
$condition = array('rent_out_id' => $this->input->post('rent_out_id'));
$rentout_edit = $this->mstaff->update('rent_out_vehcile', $condition, $rentout_data);
$condition = array('car_id' => $car_id);
$car_data= array(
'total_odometer_reading' =>$odometer_reading,
'insurance_expire_date' => date('Y-m-d',strtotime(str_replace('/', '-', $this->input->post('expire')))),
'user_type' =>'DRIVER',
'updated_by' => $this->input->post('user_id'),
'updated_ts' => date('Y-m-d H:i:s')
);
$this->mstaff->update_car($condition, $car_data);
if ($rentout_edit) {
//************************************************************************************//
//************************This Part is for Activity Log*******************************//
$activityLogData = array(
'activity_type' => '<b>Update Rentout</b>',
'description' => 'Rentout - '.$rentoutDetails['rent_out_no'].' updated',
'link' => 'admin/rentOut/editrentout/'.$this->input->post('rent_out_id'),
'icon' => '<i class="fa fa-history" aria-hidden="true"></i>',
'created_by' => $this->input->post('user_id'),
);
$this->activity_log_app($activityLogData);
//************************This Part is for Activity Log*******************************//
//************************************************************************************//
$response = array('status' => 1, 'message' => 'Rentout Updated successfully', 'rentout_details' => $this->obj);
} else {
$response = array('status' => 0, 'message' => 'Oops!Something went wrong...', 'rentout_details' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'rentout_details' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'rentout_details' => $this->obj);
}
$this->displayOutput($response);
}
public function getRentInList()
{
$ap = json_decode(file_get_contents('php://input'), true);
if ($this->checkHttpMethods($this->http_methods[0])) {
if (sizeof($ap)) {
if (empty($ap['token_key'])) {
$response = array('status' => 0, 'message' => 'Token Key is required', 'rentin_list' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['device_type'])) {
$response = array('status' => 0, 'message' => 'Device type is required', 'rentin_list' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['user_id'])) {
$response = array('status' => 0, 'message' => 'User ID is required', 'rentin_list' => $this->obj);
$this->displayOutput($response);
}
$access_token_result = $this->check_access_token($ap['token_key'], $ap['device_type'], $ap['user_id']);
if (empty($access_token_result)) {
$response = array('status' => 2, 'message' => 'Unauthorize Token', 'rentin_list' => $this->obj);
$this->displayOutput($response);
} else {
$rentin_list = $this->mstaff->getRentinDetails();
if (!empty($rentin_list)) {
foreach ($rentin_list as $rentin_key => $rentin) {
if (!empty($rentin['damage_img'])) {
$rentin_list[$rentin_key]['damage_img'] = '/public/admin_images/rent_in/damage_imgs/' . $rentin['damage_img'];
} else {
$rentin_list[$rentin_key]['damage_img'] = '';
}
if (!empty($rentin['front_img'])) {
$rentin_list[$rentin_key]['front_img'] = '/public/admin_images/rent_in/front_imgs/' . $rentin['front_img'];
} else {
$rentin_list[$rentin_key]['front_img'] = '';
}
if (!empty($rentin['rear_img'])) {
$rentin_list[$rentin_key]['rear_img'] = '/public/admin_images/rent_in/rear_imgs/' . $rentin['rear_img'];
} else {
$rentin_list[$rentin_key]['rear_img'] = '';
}
if (!empty($rentin['driver_side_img'])) {
$rentin_list[$rentin_key]['driver_side_img'] = '/public/admin_images/rent_in/driver_side_imgs/' . $rentin['driver_side_img'];
} else {
$rentin_list[$rentin_key]['driver_side_img'] = '';
}
if (!empty($rentin['passenger_side_img'])) {
$rentin_list[$rentin_key]['passenger_side_img'] = '/public/admin_images/rent_in/passenger_side_imgs/' . $rentin['passenger_side_img'];
} else {
$rentin_list[$rentin_key]['passenger_side_img'] = '';
}
if (!empty($rentout['odometer_img'])) {
$rentin_list[$rentin_key]['odometer_img'] = '/public/admin_images/rent_in/odometer_imgs/' . $rentin['odometer_img'];
} else {
$rentin_list[$rentin_key]['odometer_img'] = '';
}
if (!empty($rentin['fuel_guage_img'])) {
$rentin_list[$rentin_key]['fuel_guage_img'] = '/public/admin_images/rent_in/fuel_guage_imgs/' . $rentin['fuel_guage_img'];
} else {
$rentin_list[$rentin_key]['fuel_guage_img'] = '';
}
}
$response = array('status' => 1, 'message' => 'Rent In List Fetched Successfully', 'rentin_list' => $rentin_list);
} else {
$response = array('status' => 1, 'message' => 'No Data Found', 'rentin_list' => $this->obj);
}
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'rentin_list' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'rentin_list' => $this->obj);
}
$this->displayOutput($response);
}
public function addRentIn()
{
if ($this->checkHttpMethods($this->http_methods[0])) {
if (!empty($this->input->post())) {
$driver_rent_out_id=$this->input->post('driver_id');
$driver_rent_out_array=explode('-',$driver_rent_out_id);
$driver_id=$driver_rent_out_array[0];
$rent_out_id=$driver_rent_out_array[1];
if (empty($this->input->post('token_key'))) {
$response = array('status' => 0, 'message' => 'Token Key is required', 'rentin_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('device_type'))) {
$response = array('status' => 0, 'message' => 'Device type is required', 'rentin_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('user_id'))) {
$response = array('status' => 0, 'message' => 'User ID is required', 'rentin_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($driver_id)) {
$response = array('status' => 0, 'message' => 'Driver ID is required', 'rentin_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('odometer_reading'))) {
$response = array('status' => 0, 'message' => 'Odometer Reading is required', 'rentin_details' => $this->obj);
$this->displayOutput($response);
}
$access_token_result = $this->check_access_token($this->input->post('token_key'), $this->input->post('device_type'), $this->input->post('user_id'));
if (empty($access_token_result)) {
$response = array('status' => 2, 'message' => 'Unauthorize Token', 'rentin_details' => $this->obj);
$this->displayOutput($response);
} else {
$car_id=$this->input->post('car_id');
$odometer_reading=$this->input->post('odometer_reading');
$car_details = $this->mstaff->edit_car($car_id);
if($car_details['total_odometer_reading']>$odometer_reading){
$response = array('status' => 0, 'message' => 'Rent In <b>Odometer Reading</b> must be grater than this car previous <b>Odometer Reading</b>.', 'rentin_details' => $this->obj);
$this->displayOutput($response);
}
$rentin_data['driver_id'] = $driver_id;
$rentin_data['rent_out_id'] = $rent_out_id;
$rentin_data['odometer_reading'] =$odometer_reading;
$rentin_data['damage'] =$this->input->post('damage');
$rentin_data['damage_amount'] = $this->input->post('damage_amount');
$rentin_data['fuel'] = $this->input->post('fuel');
// $rentin_data['bond_refund_amount'] = $this->input->post('bond_refund_amount');
$rentin_data['bond_refund_request'] = $this->input->post('bond_refund_request');
$rentin_data['notes']= $this->input->post('notes');
$rentin_data['rent_in_no']= 'RI'.time().'/CAR'.$this->input->post('car_no');
$rentin_data['created_by'] = $this->input->post('user_id');
$rentin_data['created_ts'] = date('Y-m-d H:i:s');
if ($this->input->post('bond_refund_date')) {
$rentin_data['bond_refund_date'] = date('Y-m-d',strtotime(str_replace('/', '-', $this->input->post('bond_refund_date'))));
}
if (isset($_FILES['damage_img']['name']) && !empty($_FILES['damage_img']['name'])) {
$path = './public/admin_images/rent_in/damage_imgs/';
$upload_file = $this->single_image_upload($path, $_FILES['damage_img'], 'damage_img');
if ($upload_file['status'] == 1) {
$rentin_data['damage_img'] = $upload_file['result'];
}
}
if (isset($_FILES['front_img']['name']) && !empty($_FILES['front_img']['name'])) {
$path = './public/admin_images/rent_in/front_imgs/';
$upload_file = $this->single_image_upload($path, $_FILES['front_img'], 'front_img');
if ($upload_file['status'] == 1) {
$rentin_data['front_img'] = $upload_file['result'];
}
}
if (isset($_FILES['rear_img']['name']) && !empty($_FILES['rear_img']['name'])) {
$path = './public/admin_images/rent_in/rear_imgs/';
$upload_file = $this->single_image_upload($path, $_FILES['rear_img'], 'rear_img');
if ($upload_file['status'] == 1) {
$rentin_data['rear_img'] = $upload_file['result'];
}
}
if (isset($_FILES['driver_side_img']['name']) && !empty($_FILES['driver_side_img']['name'])) {
$path = './public/admin_images/rent_in/driver_side_imgs/';
$upload_file = $this->single_image_upload($path, $_FILES['driver_side_img'], 'driver_side_img');
if ($upload_file['status'] == 1) {
$rentin_data['driver_side_img'] = $upload_file['result'];
}
}
if (isset($_FILES['passenger_side_img']['name']) && !empty($_FILES['passenger_side_img']['name'])) {
$path = './public/admin_images/rent_in/passenger_side_imgs/';
$upload_file = $this->single_image_upload($path, $_FILES['passenger_side_img'], 'passenger_side_img');
if ($upload_file['status'] == 1) {
$rentin_data['passenger_side_img'] = $upload_file['result'];
}
}
if (isset($_FILES['odometer_img']['name']) && !empty($_FILES['odometer_img']['name'])) {
$path = './public/admin_images/rent_in/odometer_imgs/';
$upload_file = $this->single_image_upload($path, $_FILES['odometer_img'], 'odometer_img');
if ($upload_file['status'] == 1) {
$rentin_data['odometer_img'] = $upload_file['result'];
}
}
if (isset($_FILES['fuel_guage_img']['name']) && !empty($_FILES['fuel_guage_img']['name'])) {
$path = './public/admin_images/rent_in/fuel_guage_imgs/';
$upload_file = $this->single_image_upload($path, $_FILES['fuel_guage_img'], 'fuel_guage_img');
if ($upload_file['status'] == 1) {
$rentin_data['fuel_guage_img'] = $upload_file['result'];
}
}
}
$rentin_added = $this->mstaff->insert('rent_in_vehcile', $rentin_data);
$condition = array('car_id' => $car_id);
$car_data= array(
'total_odometer_reading' =>$odometer_reading,
'user_type' =>'DRIVER',
'updated_by' => $this->input->post('user_id'),
'updated_ts' => date('Y-m-d H:i:s')
);
$this->mstaff->update_car($condition, $car_data);
$bond_data = array(
'driver_id' => $driver_id,
'bond_amount' => $this->input->post('bond_refund_amount'),
'transaction_type' => 'DEBIT',
'bond_date' => date('Y-m-d',strtotime(str_replace('/', '-', $this->input->post('bond_refund_date')))),
'bond_payment_method' => $this->input->post('bond_payment_method'),
'bond_reference_no' => $this->input->post('bond_reference_no'),
'bond_reference_type' => 'RENTIN',
'bond_reference_id' => $rentin_added,
'created_by' => $this->input->post('user_id'),
'created_ts' => date('Y-m-d H:i:s')
);
$this->db->insert('bond_wallet', $bond_data);
if($this->input->post('bond_refund_request') == 'Yes'){
$bond_refund_data = array(
'driver_id' => $driver_id,
'total_bond_amount' => $this->input->post('bond_refund_amount'),
'refund_type' =>$this->input->post('refund_type'),
'amount_want_to_refund' =>$this->input->post('amount_want_to_refund'),
'notice_date' => date('Y-m-d',strtotime(str_replace('/', '-', $this->input->post('notice_date')))),
'bond_refund_due_date' => date('Y-m-d',strtotime(str_replace('/', '-', $this->input->post('bond_refund_due_date')))),
'action_type' => 'RENTIN',
'remarks' => $this->input->post('remarks'),
'reference_id' => $result,
'created_by' => $this->input->post('user_id'),
'created_ts' => date('Y-m-d H:i:s')
);
$this->db->insert('bond_refund', $bond_refund_data);
}
$condition = array('rent_out_id' => $rent_out_id);
$this->mstaff->update_rent_out($condition, array('is_rent_in'=>'1'));
//-----------------For Inactive Driver-------------------------//
$this->db->update('master_driver',array('status'=>'2'),array('driver_id'=>$driver_id));
//-----------------For Inactive Driver-------------------------//
$this->db->trans_complete(); # Completing transaction
if ($this->db->trans_status() === FALSE) {
# Something went wrong.
$this->db->trans_rollback();
$response = array('status' => 0, 'message' => 'Oops!Something went wrong...', 'rentin_details' => $this->obj);
} else {
# Everything is Perfect.
# Committing data to the database.
$this->db->trans_commit();
//************************************************************************************//
//************************This Part is for Activity Log*******************************//
$activityLogData = array(
'activity_type' => '<b>Add Rent In</b>',
'description' => 'New Rent In - '.$rentin_data['rent_in_no'].' Added',
'link' => 'admin/rentIn',
'icon' => '<i class="fa fa-history" aria-hidden="true"></i>',
'created_by' => $this->input->post('user_id'),
);
$this->activity_log_app($activityLogData);
//************************This Part is for Activity Log*******************************//
//************************************************************************************//
$response = array('status' => 1, 'message' => 'Rentin added successfully', 'rentin_details' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'rentin_details' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'rentin_details' => $this->obj);
}
$this->displayOutput($response);
}
public function editRentIn()
{
if ($this->checkHttpMethods($this->http_methods[0])) {
if (!empty($this->input->post())) {
if (empty($this->input->post('token_key'))) {
$response = array('status' => 0, 'message' => 'Token Key is required', 'rentin_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('device_type'))) {
$response = array('status' => 0, 'message' => 'Device type is required', 'rentin_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('user_id'))) {
$response = array('status' => 0, 'message' => 'User ID is required', 'rentin_details' => $this->obj);
$this->displayOutput($response);
}
if (empty($this->input->post('odometer_reading'))) {
$response = array('status' => 0, 'message' => 'Odometer Reading is required', 'rentin_details' => $this->obj);
$this->displayOutput($response);
}
$access_token_result = $this->check_access_token($this->input->post('token_key'), $this->input->post('device_type'), $this->input->post('user_id'));
if (empty($access_token_result)) {
$response = array('status' => 2, 'message' => 'Unauthorize Token', 'rentin_details' => $this->obj);
$this->displayOutput($response);
} else {
$car_id=$this->input->post('car_id');
$odometer_reading=$this->input->post('odometer_reading');
$car_details = $this->mstaff->edit_car($car_id);
$rentinDetails = $this->mstaff->getRentinDetails($this->input->post('rent_in_id'));
if($car_details['total_odometer_reading']>$odometer_reading){
$response = array('status' => 0, 'message' => 'Rent Out <b>Odometer Reading</b> must be grater than this car previous <b>Odometer Reading</b>.', 'rentout_details' => $this->obj);
$this->displayOutput($response);
}
if($this->input->post('damage')=='No'){
$rentin_data['damage_amount'] ='';
//@unlink('./public/admin_images/rent_in/damage_imgs/' . $this->input->post('damage_img_old'));
$rentin_data['damage_img'] = '';
}else{
$rentin_data['damage_amount'] = $this->input->post('damage_amount');
if (isset($_FILES['damage_img']['name']) && !empty($_FILES['damage_img']['name'])) {
$path = './public/admin_images/rent_in/damage_imgs/';
$upload_file = $this->single_image_upload($path, $_FILES['damage_img'], 'damage_img');
if ($upload_file['status'] == 1) {
$rentin_data['damage_img'] = $upload_file['result'];
}
}
}
if($this->input->post('bond_refund_request')=='No'){
$bond_refund_amount='';
$bond_refund_date='';
}else{
$bond_refund_amount=$this->input->post('damage_amount');
$bond_refund_date=date('Y-m-d',strtotime(str_replace('/', '-', $this->input->post('bond_refund_date'))));
}
$rentin_data['odometer_reading'] =$odometer_reading;
$rentin_data['damage'] =$this->input->post('damage');
$rentin_data['fuel'] = $this->input->post('fuel');
$rentin_data['bond_refund_amount'] = $bond_refund_amount;
$rentin_data['bond_refund_request'] = $this->input->post('bond_refund_request');
$rentin_data['bond_refund_date'] = $bond_refund_date;
$rentin_data['notes']= $this->input->post('notes');
$rentin_data['updated_by'] = $this->input->post('user_id');
$rentin_data['updated_ts'] = date('Y-m-d H:i:s');
if (isset($_FILES['front_img']['name']) && !empty($_FILES['front_img']['name'])) {
$path = './public/admin_images/rent_in/front_imgs/';
$upload_file = $this->single_image_upload($path, $_FILES['front_img'], 'front_img');
if ($upload_file['status'] == 1) {
$rentin_data['front_img'] = $upload_file['result'];
}
}
if (isset($_FILES['rear_img']['name']) && !empty($_FILES['rear_img']['name'])) {
$path = './public/admin_images/rent_in/rear_imgs/';
$upload_file = $this->single_image_upload($path, $_FILES['rear_img'], 'rear_img');
if ($upload_file['status'] == 1) {
$rentin_data['rear_img'] = $upload_file['result'];
}
}
if (isset($_FILES['driver_side_img']['name']) && !empty($_FILES['driver_side_img']['name'])) {
$path = './public/admin_images/rent_in/driver_side_imgs/';
$upload_file = $this->single_image_upload($path, $_FILES['driver_side_img'], 'driver_side_img');
if ($upload_file['status'] == 1) {
$rentin_data['driver_side_img'] = $upload_file['result'];
}
}
if (isset($_FILES['passenger_side_img']['name']) && !empty($_FILES['passenger_side_img']['name'])) {
$path = './public/admin_images/rent_in/passenger_side_imgs/';
$upload_file = $this->single_image_upload($path, $_FILES['passenger_side_img'], 'passenger_side_img');
if ($upload_file['status'] == 1) {
$rentin_data['passenger_side_img'] = $upload_file['result'];
}
}
if (isset($_FILES['odometer_img']['name']) && !empty($_FILES['odometer_img']['name'])) {
$path = './public/admin_images/rent_in/odometer_imgs/';
$upload_file = $this->single_image_upload($path, $_FILES['odometer_img'], 'odometer_img');
if ($upload_file['status'] == 1) {
$rentin_data['odometer_img'] = $upload_file['result'];
}
}
if (isset($_FILES['fuel_guage_img']['name']) && !empty($_FILES['fuel_guage_img']['name'])) {
$path = './public/admin_images/rent_in/fuel_guage_imgs/';
$upload_file = $this->single_image_upload($path, $_FILES['fuel_guage_img'], 'fuel_guage_img');
if ($upload_file['status'] == 1) {
$rentin_data['fuel_guage_img'] = $upload_file['result'];
}
}
}
$condition = array('rent_in_id' => $this->input->post('rent_in_id'));
$rentin_edit = $this->mstaff->update('rent_in_vehcile', $condition, $rentin_data);
$condition = array('car_id' => $car_id);
$car_data= array(
'total_odometer_reading' =>$odometer_reading,
'user_type' =>'DRIVER',
'updated_by' => $this->input->post('user_id'),
'updated_ts' => date('Y-m-d H:i:s')
);
$this->mstaff->update_car($condition, $car_data);
if ($rentin_edit) {
//************************************************************************************//
//************************This Part is for Activity Log*******************************//
$activityLogData = array(
'activity_type' => '<b>Update Rent out</b>',
'description' => 'Rent out - '.$rentinDetails['rent_in_no'].' updated',
'link' => 'admin/rentIn/editrentin/'.$this->input->post('rent_in_id'),
'icon' => '<i class="fa fa-history" aria-hidden="true"></i>',
'created_by' => $this->input->post('user_id'),
);
$this->activity_log_app($activityLogData);
//************************This Part is for Activity Log*******************************//
//************************************************************************************//
$response = array('status' => 1, 'message' => 'Rentin updated successfully', 'rentin_details' => $this->obj);
} else {
$response = array('status' => 0, 'message' => 'Oops!Something went wrong...', 'rentin_details' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'rentin_details' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'rentin_details' => $this->obj);
}
$this->displayOutput($response);
}
public function getCarListRent()
{
$ap = json_decode(file_get_contents('php://input'), true);
if ($this->checkHttpMethods($this->http_methods[0])) {
if (sizeof($ap)) {
if (empty($ap['token_key'])) {
$response = array('status' => 0, 'message' => 'Token Key is required', 'car_list' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['device_type'])) {
$response = array('status' => 0, 'message' => 'Device type is required', 'car_list' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['user_id'])) {
$response = array('status' => 0, 'message' => 'User ID is required', 'car_list' => $this->obj);
$this->displayOutput($response);
}
$access_token_result = $this->check_access_token($ap['token_key'], $ap['device_type'], $ap['user_id']);
if (empty($access_token_result)) {
$response = array('status' => 2, 'message' => 'Unauthorize Token', 'car_list' => $this->obj);
$this->displayOutput($response);
} else {
$car_list = $this->mstaff->get_car_list_rent();
if (!empty($car_list)) {
$response = array('status' => 1, 'message' => 'Car List Fetched Successfully', 'car_list' => $car_list);
} else {
$response = array('status' => 1, 'message' => 'No Data Found', 'car_list' => $this->obj);
}
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'car_list' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'car_list' => $this->obj);
}
$this->displayOutput($response);
}
public function getDriverListRentOut()
{
$ap = json_decode(file_get_contents('php://input'), true);
if ($this->checkHttpMethods($this->http_methods[0])) {
if (sizeof($ap)) {
if (empty($ap['token_key'])) {
$response = array('status' => 0, 'message' => 'Token Key is required', 'driver_list' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['device_type'])) {
$response = array('status' => 0, 'message' => 'Device type is required', 'driver_list' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['user_id'])) {
$response = array('status' => 0, 'message' => 'User ID is required', 'driver_list' => $this->obj);
$this->displayOutput($response);
}
$access_token_result = $this->check_access_token($ap['token_key'], $ap['device_type'], $ap['user_id']);
if (empty($access_token_result)) {
$response = array('status' => 2, 'message' => 'Unauthorize Token', 'driver_list' => $this->obj);
$this->displayOutput($response);
} else {
$driver_list = $this->mstaff->get_driver_list_rent_out();
if (!empty($driver_list)) {
$response = array('status' => 1, 'message' => 'Driver List Fetched Successfully', 'driver_list' => $driver_list);
} else {
$response = array('status' => 1, 'message' => 'No Data Found', 'driver_list' => $this->obj);
}
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'driver_list' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'driver_list' => $this->obj);
}
$this->displayOutput($response);
}
public function getDriverListRentIn()
{
$ap = json_decode(file_get_contents('php://input'), true);
if ($this->checkHttpMethods($this->http_methods[0])) {
if (sizeof($ap)) {
if (empty($ap['token_key'])) {
$response = array('status' => 0, 'message' => 'Token Key is required', 'driver_list' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['device_type'])) {
$response = array('status' => 0, 'message' => 'Device type is required', 'driver_list' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['user_id'])) {
$response = array('status' => 0, 'message' => 'User ID is required', 'driver_list' => $this->obj);
$this->displayOutput($response);
}
$access_token_result = $this->check_access_token($ap['token_key'], $ap['device_type'], $ap['user_id']);
if (empty($access_token_result)) {
$response = array('status' => 2, 'message' => 'Unauthorize Token', 'driver_list' => $this->obj);
$this->displayOutput($response);
} else {
$driver_list = $this->mstaff->get_driver_list_rent_in();
if (!empty($driver_list)) {
$response = array('status' => 1, 'message' => 'Driver List Fetched Successfully', 'driver_list' => $driver_list);
} else {
$response = array('status' => 1, 'message' => 'No Data Found', 'driver_list' => $this->obj);
}
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'driver_list' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'driver_list' => $this->obj);
}
$this->displayOutput($response);
}
public function getPaymentMethod()
{
$ap = json_decode(file_get_contents('php://input'), true);
if ($this->checkHttpMethods($this->http_methods[0])) {
if (sizeof($ap)) {
if (empty($ap['token_key'])) {
$response = array('status' => 0, 'message' => 'Token Key is required', 'payment_method_list' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['device_type'])) {
$response = array('status' => 0, 'message' => 'Device type is required', 'payment_method_list' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['user_id'])) {
$response = array('status' => 0, 'message' => 'User ID is required', 'payment_method_list' => $this->obj);
$this->displayOutput($response);
}
$access_token_result = $this->check_access_token($ap['token_key'], $ap['device_type'], $ap['user_id']);
if (empty($access_token_result)) {
$response = array('status' => 2, 'message' => 'Unauthorize Token', 'payment_method_list' => $this->obj);
$this->displayOutput($response);
} else {
$payment_method_list = array('Cash', 'Bank Transfer', 'EFT POS','Direct Debit');
$response = array('status' => 1, 'message' => 'Payment Method Fetched Successfully', 'payment_method_list' => $payment_method_list);
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'payment_method_list' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'payment_method_list' => $this->obj);
}
$this->displayOutput($response);
}
public function getCompanyList()
{
$ap = json_decode(file_get_contents('php://input'), true);
if ($this->checkHttpMethods($this->http_methods[0])) {
if (sizeof($ap)) {
if (empty($ap['token_key'])) {
$response = array('status' => 0, 'message' => 'Token Key is required', 'company_list' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['device_type'])) {
$response = array('status' => 0, 'message' => 'Device type is required', 'company_list' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['user_id'])) {
$response = array('status' => 0, 'message' => 'User ID is required', 'company_list' => $this->obj);
$this->displayOutput($response);
}
$access_token_result = $this->check_access_token($ap['token_key'], $ap['device_type'], $ap['user_id']);
if (empty($access_token_result)) {
$response = array('status' => 2, 'message' => 'Unauthorize Token', 'company_list' => $this->obj);
$this->displayOutput($response);
} else {
$company_list = $this->mstaff->get_company_list();
if (!empty($company_list)) {
$response = array('status' => 1, 'message' => 'Company List Fetched Successfully', 'company_list' => $company_list);
} else {
$response = array('status' => 1, 'message' => 'No Data Found', 'company_list' => $this->obj);
}
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'company_list' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'company_list' => $this->obj);
}
$this->displayOutput($response);
}
//Forgot password
public function forgotPassword()
{
if ($this->checkHttpMethods($this->http_methods[0])) {
if (!empty($this->input->post())) {
if (empty($this->input->post('email'))) {
$response = array('status' => 0, 'message' => 'Email field is required', 'result' => $this->obj);
$this->displayOutput($response);
}
$condition['email'] = $this->input->post('email');
$user_details = $this->mstaff->getRow('master_admin', $condition);
if (empty($user_details)) {
$response = array('status' => 0, 'message' => 'Sorry! User does not exist in our database', 'result' => $this->obj);
$this->displayOutput($response);
} else {
$encoded_key = base64_encode(rand().$user_details['user_id']);
$user_data['recovery_key'] = $encoded_key;
$condition_user = array('user_id' => $user_details['user_id']);
$this->mstaff->update('master_admin', $condition_user, $user_data);
$mail['name'] = $user_details['full_name'];
$mail['to'] = $user_details['email'];
$mail['subject'] = 'Quantum Recover Password';
$link = base_url('forgot_password/recover_password_staff/?recovery_key=' . $encoded_key);
$mail_temp = file_get_contents('./global/mail/forgotpassword_template.html');
$mail_temp = str_replace("{web_url}", SITEURL, $mail_temp);
$mail_temp = str_replace("{logo}", base_url('public/admin_assets/img/logo.png'), $mail_temp);
$mail_temp = str_replace("{name}", $mail['name'], $mail_temp);
$mail_temp = str_replace("{link}", $link, $mail_temp);
$mail_temp = str_replace("{current_year}", CURRENT_YEAR, $mail_temp);
$mail['message'] = $mail_temp;
// echo '<pre>';print_r($mail);die;
if ($this->sendMail($mail)) {
//************************************************************************************//
//************************This Part is for Activity Log*******************************//
$activityLogData = array(
'activity_type' => '<b>Forgot Password</b>',
'description' => $user_details['full_name'].'Password Forgotted',
'link' => '',
'icon' => '<i class="fa fa-history" aria-hidden="true"></i>',
'created_by' => $user_details['user_id'],
);
$this->activity_log_app($activityLogData);
//************************This Part is for Activity Log*******************************//
//************************************************************************************//
$response = array('status' => 1, 'message' => 'Password recovery mail has been sent to your email', 'result' => $this->obj);
} else {
$response = array('status' => 0, 'message' => 'Uanble to send recovery mail.', 'result' => $this->obj);
}
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'result' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'result' => $this->obj);
}
$this->displayOutput($response);
}
public function getUtilityBillList()
{
$utility_bill_list = $this->mstaff->get_address_proof_list();
if (!empty($utility_bill_list)) {
$response = array('status' => 1, 'message' => 'Utility Bill List Fetched Successfully', 'utility_bill_list' => $utility_bill_list);
} else {
$response = array('status' => 1, 'message' => 'No Data Found', 'utility_bill_list' => $this->obj);
}
$this->displayOutput($response);
}
public function getVehicle()
{
$ap = json_decode(file_get_contents('php://input'), true);
if ($this->checkHttpMethods($this->http_methods[0])) {
if (sizeof($ap)) {
if (empty($ap['token_key'])) {
$response = array('status' => 0, 'message' => 'Token Key is required', 'total_vehicle' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['device_type'])) {
$response = array('status' => 0, 'message' => 'Device type is required', 'total_vehicle' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['user_id'])) {
$response = array('status' => 0, 'message' => 'User ID is required', 'total_vehicle' => $this->obj);
$this->displayOutput($response);
}
$access_token_result = $this->check_access_token($ap['token_key'], $ap['device_type'], $ap['user_id']);
if (empty($access_token_result)) {
$response = array('status' => 2, 'message' => 'Unauthorize Token', 'total_vehicle' => $this->obj);
$this->displayOutput($response);
} else {
$total_vehicle = $this->mstaff->get_vehicle();
if (!empty($total_vehicle)) {
$response = array('status' => 1, 'message' => 'Total Vehicle Fetched Successfully', 'total_vehicle' => $total_vehicle);
} else {
$response = array('status' => 1, 'message' => 'No Data Found', 'total_vehicle' => $this->obj);
}
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'total_vehicle' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'total_vehicle' => $this->obj);
}
$this->displayOutput($response);
}
public function getOnGoingVehicle()
{
$ap = json_decode(file_get_contents('php://input'), true);
if ($this->checkHttpMethods($this->http_methods[0])) {
if (sizeof($ap)) {
if (empty($ap['token_key'])) {
$response = array('status' => 0, 'message' => 'Token Key is required', 'on_going_vehicle' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['device_type'])) {
$response = array('status' => 0, 'message' => 'Device type is required', 'on_going_vehicle' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['user_id'])) {
$response = array('status' => 0, 'message' => 'User ID is required', 'on_going_vehicle' => $this->obj);
$this->displayOutput($response);
}
$access_token_result = $this->check_access_token($ap['token_key'], $ap['device_type'], $ap['user_id']);
if (empty($access_token_result)) {
$response = array('status' => 2, 'message' => 'Unauthorize Token', 'on_going_vehicle' => $this->obj);
$this->displayOutput($response);
} else {
$on_going_vehicle = $this->mstaff->get_on_rentin_vehicle();
if (!empty($on_going_vehicle)) {
$response = array('status' => 1, 'message' => 'On Going Vehicle Fetched Successfully', 'on_going_vehicle' => $on_going_vehicle);
} else {
$response = array('status' => 1, 'message' => 'No Data Found', 'on_going_vehicle' => $this->obj);
}
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'on_going_vehicle' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'on_going_vehicle' => $this->obj);
}
$this->displayOutput($response);
}
public function getPendingDriverValidate()
{
$ap = json_decode(file_get_contents('php://input'), true);
if ($this->checkHttpMethods($this->http_methods[0])) {
if (sizeof($ap)) {
if (empty($ap['token_key'])) {
$response = array('status' => 0, 'message' => 'Token Key is required', 'pending_driver_validate' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['device_type'])) {
$response = array('status' => 0, 'message' => 'Device type is required', 'pending_driver_validate' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['user_id'])) {
$response = array('status' => 0, 'message' => 'User ID is required', 'pending_driver_validate' => $this->obj);
$this->displayOutput($response);
}
$access_token_result = $this->check_access_token($ap['token_key'], $ap['device_type'], $ap['user_id']);
if (empty($access_token_result)) {
$response = array('status' => 2, 'message' => 'Unauthorize Token', 'pending_driver_validate' => $this->obj);
$this->displayOutput($response);
} else {
$driver_list = $this->mstaff->get_pending_driver_validate();
if (!empty($driver_list)) {
foreach ($driver_list as $driver_key => $driver) {
$driver_list[$driver_key]['licence_image'] = '';
$driver_list[$driver_key]['licence_expiry_image'] = '';
$driver_list[$driver_key]['passport_no_image'] = '';
$driver_list[$driver_key]['passport_expiry_image'] = '';
$driver_list[$driver_key]['utility_bill_image'] = '';
$driver_list[$driver_key]['profile_photo'] = '';
if (!empty($driver['is_australian_licence'])) {
$driver_list[$driver_key]['country'] = ($driver['is_australian_licence'] == 'Yes') ? 'Australia' : 'International';
}
if (!empty($driver['licence_image'])) {
$driver_list[$driver_key]['licence_image'] = base_url().'public/admin_images/driver/licence_image/' . $driver['licence_image'];
}
if (!empty($driver['licence_expiry_image'])) {
$driver_list[$driver_key]['licence_expiry_image'] = base_url().'public/admin_images/driver/licence_expiry_image/' . $driver['licence_expiry_image'];
}
if (!empty($driver['passport_no_image'])) {
$driver_list[$driver_key]['passport_no_image'] = base_url().'public/admin_images/driver/passport_no_image/' . $driver['passport_no_image'];
}
if (!empty($driver['passport_expiry_image'])) {
$driver_list[$driver_key]['passport_expiry_image'] = base_url().'public/admin_images/driver/passport_expiry_image/' . $driver['passport_expiry_image'];
}
if (!empty($driver['utility_bill_image'])) {
$driver_list[$driver_key]['utility_bill_image'] = base_url().'public/admin_images/driver/utility_bill_image/' . $driver['utility_bill_image'];
}
if (!empty($driver['profile_photo'])) {
$driver_list[$driver_key]['profile_photo'] = base_url().'public/admin_images/driver/profile_image/' . $driver['profile_photo'];
}
$driver_bond_details = $this->mstaff->get_driver_bond_details($driver['driver_id']);
$driver_list[$driver_key]['bond_details'] = $driver_bond_details;
}
$response = array('status' => 1, 'message' => 'Pending Validate Driver List Fetched Successfully', 'driver_list' => $driver_list);
}
else {
$response = array('status' => 1, 'message' => 'No Data Found', 'pending_driver_validate' => $this->obj);
}
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'pending_driver_validate' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'pending_driver_validate' => $this->obj);
}
$this->displayOutput($response);
}
public function get_available_vehicle_list()
{
$ap = json_decode(file_get_contents('php://input'), true);
if ($this->checkHttpMethods($this->http_methods[0])) {
if (sizeof($ap)) {
if (empty($ap['token_key'])) {
$response = array('status' => 0, 'message' => 'Token Key is required', 'available_vehicle_list' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['device_type'])) {
$response = array('status' => 0, 'message' => 'Device type is required', 'available_vehicle_list' => $this->obj);
$this->displayOutput($response);
}
if (empty($ap['user_id'])) {
$response = array('status' => 0, 'message' => 'User ID is required', 'available_vehicle_list' => $this->obj);
$this->displayOutput($response);
}
$access_token_result = $this->check_access_token($ap['token_key'], $ap['device_type'], $ap['user_id']);
if (empty($access_token_result)) {
$response = array('status' => 2, 'message' => 'Unauthorize Token', 'available_vehicle_list' => $this->obj);
$this->displayOutput($response);
} else {
$car_list = $this->mstaff->get_available_vehicle();
if (!empty($car_list)) {
foreach ($car_list as $car_key => $car) {
if (!empty($car['car_pic'])) {
$car_list[$car_key]['car_image'] = base_url('/public/admin_images/car_pics/') . $car['car_pic'];
} else {
$car_list[$car_key]['car_image'] = '';
}
}
$response = array('status' => 1, 'message' => 'Available Vehicle List Fetched Successfully', 'available_vehicle_list' => $car_list);
}else {
$response = array('status' => 1, 'message' => 'No Data Found', 'available_vehicle_list' => $this->obj);
}
}
} else {
$response = array('status' => 0, 'message' => 'Please fill up all required fields', 'available_vehicle_list' => $this->obj);
}
} else {
$response = array('status' => 0, 'message' => 'Wrong http method type', 'available_vehicle_list' => $this->obj);
}
$this->displayOutput($response);
}
private function sendMail($data)
{
$this->load->library('email');
$config = array();
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.hostinger.com';
$config['smtp_port'] = '587';
// $config['smtp_user'] = 'quantum@syscentricdev.com';
// $config['smtp_pass'] = 'Syscentric@123';
$config['smtp_user'] = 'info@qcr24.com.au';
$config['smtp_pass'] = '3_6~40baX)';
$config['newline'] = "\r\n";
$config['mailtype'] = 'html';
$this->email->initialize($config);
$this->email->set_crlf("\r\n");
$this->email->from('info@qcr24.com.au', 'Quantum');
$this->email->to($data['email']);
$this->email->subject($data['subject']);
$this->email->message($data['message']);
$this->email->send();
// echo $this->email->print_debugger(); die;
return true;
}
private function checkHttpMethods($http_method_type)
{
if ($_SERVER['REQUEST_METHOD'] == $http_method_type) {
return 1;
}
}
private function check_access_token($token_key, $device_type, $user_id = 0)
{
$condition_token = array('token_key' => $token_key, 'device_type' => $device_type);
if ($user_id > 0) {
$condition_token['user_id'] = $user_id;
}
$access_token_result = $this->mstaff->getRow('api_token_admin', $condition_token);
return $access_token_result;
}
private function single_image_upload($path, $upload_file, $document_type)
{
$config = array(
'upload_path' => $path,
'allowed_types' => 'gif|jpg|png|jpeg',
'overwrite' => 1,
'encrypt_name' => true
);
//print_r($config);die;
$this->load->library('upload', $config);
$this->upload->initialize($config);
if (!$this->upload->do_upload($document_type)) {
//echo $this->upload->display_errors();die;
$message = array('result' => $this->upload->display_errors(), 'status' => 0);
} else {
//echo 'success';die;
$data = array('upload_data' => $this->upload->data());
//print_r($data);die;
$message = array('result' => $data['upload_data']['file_name'], 'status' => 1);
}
return $message;
}
//************************************************************************************//
//************************This Part is for Activity Log*******************************//
private function activity_log_app($activityLogData) {
if ($activityLogData) {
$activityLogData['user_type']='Staff';
$activityLogData['created_ts'] = date('Y-m-d H:i:s');
}
$this->db->insert('activity_log_app', $activityLogData);
}
//************************This Part is for Activity Log*******************************//
//************************************************************************************//
}