File: //var/www/html/taxicamera/applicationold/controllers/admin/Driver.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Driver extends MY_Controller {
public function __construct() {
parent::__construct();
//$this->redirect_guest();
$this->admin=$this->session->userdata('admin');
$this->load->library('imageupload');
$this->load->helper('download');
$this->load->model('admin/mdriver');
}
public function index() {
//echo $this->session->userdata('email');die;
$this->_load_list_view_new_driver();
}
private function _load_list_view_new_driver() {
// FUNCTION WRIITTEN IN COMMON HELPER
$data['content'] = 'admin/driver/list_new_driver';
$data['driver_list'] = $this->mdriver->get_driver_list();
//pr($data['driver_list']);
$this->load->view('admin/layouts/index', $data);
}
public function driver_master_list() {
$data['content'] = 'admin/driver/list_driver_master';
$data['driver_list'] = $this->mdriver->get_driver_master_list();
//pr($data['driver_list']);
$data['driver_list_inc'] = $this->mdriver->get_driver_master_list_inc();
$data['driver_list_trash'] = $this->mdriver->get_driver_master_list_trash();
$this->load->view('admin/layouts/index', $data);
}
public function add_new_driver(){
if($this->input->post()){
$this->form_validation->set_rules('first_name','First Name','required');
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|is_unique[master_user.email]',array('is_unique'=>'This %s already exists.'));
$this->form_validation->set_rules('dc_no', 'DC No', 'trim|required|is_unique[master_user.dc_no]',array('is_unique'=>'This %s already exists.'));
if($this->form_validation->run()==FALSE){
$this->_load_add_new_driver();
}else{
//echo '<pre>'; print_r($this->input->post());die;
$user_data['role_id']=2;
$user_data['dc_no']=$this->input->post('dc_no');
$user_data['email']=$this->input->post('email');
$user_data['password']='';
$user_data['org_password']='';
$user_data['is_active'] = '0';
$user_data['status'] = '0';
//$user_data['created_by']=1;
$user_data['created_by']=$this->session->userdata('user_data');
$user_data['created_ts']=date('Y-m-d h:i:s');
$user_id=$this->mcommon->insert('master_user',$user_data);
if($user_id){
$profile_data['user_id'] = $user_id;
$profile_data['first_name'] = $this->input->post('first_name');
$profile_data['middle_name'] = $this->input->post('middle_name');
$profile_data['last_name'] = $this->input->post('last_name');
$profile_data['dob'] = $this->input->post('dob');
$profile_data['mobile'] = $this->input->post('mobile');
$profile_data['landline_no'] = $this->input->post('landline_no');
$profile_data['abn'] = $this->input->post('abn');
$profile_data['flat_no'] = $this->input->post('flat_no');
$profile_data['street_no'] = $this->input->post('street_no');
$profile_data['street_name'] = $this->input->post('street_name');
$profile_data['suburb'] = $this->input->post('suburb');
$profile_data['state'] = $this->input->post('state');
$profile_data['pin'] = $this->input->post('pin');
$profile_data['bank_name'] = $this->input->post('bank_name');
$profile_data['bsb'] = $this->input->post('bsb');
$profile_data['account_no'] = $this->input->post('account_no');
$profile_data['dr_driver_type'] = $this->input->post('dr_driver_type');
$profile_data['dr_licence_no'] = $this->input->post('dr_licence_no');
$profile_data['created_by'] = $this->session->userdata('user_data');
$profile_data['created_ts'] = date('Y-m-d h:i:s');
if($this->input->post('dr_licence_expiry')){
$profile_data['dr_licence_expiry'] = date('Y-m-d',strtotime(str_replace('/', '-', $this->input->post('dr_licence_expiry'))));
}
if($this->input->post('dr_dc_expiry')){
$profile_data['dr_dc_expiry'] = date('Y-m-d',strtotime(str_replace('/', '-', $this->input->post('dr_dc_expiry'))));
}
$profile_data['dr_commission_id'] = $this->input->post('dr_commission_id');
$profile_data['dr_rental'] = $this->input->post('dr_rental');
//$profile_data['created_by'] = 1;
$profile_data['created_by']=$this->session->userdata('admin');
$profile_data['created_ts'] = date('Y-m-d h:i:s');
//echo '<pre>'; print_r($_FILES['profile_photo']);die;
if($_FILES['profile_photo']['name']){
$path = './public/upload_image/profile_photo/';
$upload_file = $this->single_image_upload($path, $_FILES['profile_photo'],'profile_photo');
if($upload_file['status']==1){
$profile_data['profile_photo']=$upload_file['result'];
}
}
$profile_id=$this->mcommon->insert('user_profile',$profile_data);
if($_FILES['driver_certificate']['name'][0]){
$path = './public/upload_image/driver_certificate/';
$upload_file = $this->upload_Product_images($path, $_FILES['driver_certificate'], $user_id,'driver_certificate');
}
if($_FILES['driving_license']['name'][0]){
$path = './public/upload_image/driving_license/';
$upload_file = $this->upload_Product_images($path, $_FILES['driving_license'], $user_id,'driving_license');
}
if($_FILES['login_card']['name'][0]){
$path = './public/upload_image/login_card/';
$upload_file = $this->upload_Product_images($path, $_FILES['login_card'], $user_id,'login_card');
}
if($_FILES['paper_dc']['name'][0]){
$path = './public/upload_image/paper_dc/';
$upload_file = $this->upload_Product_images($path, $_FILES['paper_dc'], $user_id,'paper_dc');
}
if($_FILES['signature']['name'][0]){
$path = './public/upload_image/signature/';
$upload_file = $this->upload_Product_images($path, $_FILES['signature'], $user_id,'signature');
}
$this->session->set_flashdata('success_msg','Driver Added Successfully');
redirect(base_url('admin/driver'));
}
else{
$this->session->set_flashdata('error_msg','Oops!Something went wrong...');
redirect(base_url('admin/driver'));
}
}
}
else{
$this->_load_add_new_driver();
}
}
private function _load_add_new_driver(){
$data['content']='admin/driver/add_new_driver';
$data['commission_type']=$this->mcommon->getDetails('master_commission',array('status'=>1));
//print_r($data['commission_type']);die;
$this->load->view('admin/layouts/index',$data);
}
public function edit_new_driver($user_id){
if($this->input->post()){
$this->form_validation->set_rules('first_name','First Name','required');
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|callback_check_email',array('check_email'=>'This %s already exists.'));
$this->form_validation->set_rules('dc_no', 'DC No', 'trim|required|callback_check_dc_no',array('check_dc_no'=>'This %s already exists.'));
if($this->form_validation->run()==FALSE){
$this->_load_edit_new_driver($user_id);
}else{
//echo '<pre>'; print_r($this->input->post());die;
$user_data['role_id']=2;
$user_data['dc_no']=$this->input->post('dc_no');
$user_data['email']=$this->input->post('email');
//$user_data['password']='';
//$user_data['updated_by']=1;
$user_data['updated_by']=$this->session->userdata('user_data');
$user_data['updated_ts']=date('Y-m-d h:i:s');
$condition_user=array('user_id'=>$user_id);
$this->mcommon->update('master_user',$condition_user,$user_data);
$profile_id=$this->input->post('profile_id');
if($profile_id){
$profile_data['user_id'] = $user_id;
$profile_data['first_name'] = $this->input->post('first_name');
$profile_data['middle_name'] = $this->input->post('middle_name');
$profile_data['last_name'] = $this->input->post('last_name');
$profile_data['dob'] = $this->input->post('dob');
$profile_data['mobile'] = $this->input->post('mobile');
$profile_data['landline_no'] = $this->input->post('landline_no');
$profile_data['abn'] = $this->input->post('abn');
$profile_data['flat_no'] = $this->input->post('flat_no');
$profile_data['street_no'] = $this->input->post('street_no');
$profile_data['street_name'] = $this->input->post('street_name');
$profile_data['suburb'] = $this->input->post('suburb');
$profile_data['state'] = $this->input->post('state');
$profile_data['pin'] = $this->input->post('pin');
$profile_data['bank_name'] = $this->input->post('bank_name');
$profile_data['bsb'] = $this->input->post('bsb');
$profile_data['account_no'] = $this->input->post('account_no');
$profile_data['dr_driver_type'] = $this->input->post('dr_driver_type');
$profile_data['dr_licence_no'] = $this->input->post('dr_licence_no');
$profile_data['updated_by']=$this->session->userdata('user_data');
$profile_data['updated_ts']=date('Y-m-d h:i:s');
if($this->input->post('dr_licence_expiry')){
$profile_data['dr_licence_expiry'] = date('Y-m-d',strtotime(str_replace('/', '-', $this->input->post('dr_licence_expiry'))));
}
if($this->input->post('dr_dc_expiry')){
$profile_data['dr_dc_expiry'] = date('Y-m-d',strtotime(str_replace('/', '-', $this->input->post('dr_dc_expiry'))));
}
$profile_data['dr_commission_id'] = $this->input->post('dr_commission_id');
$profile_data['dr_rental'] = $this->input->post('dr_rental');
//$profile_data['created_by'] = 1;
$profile_data['created_by']=$this->session->userdata('admin');
$profile_data['created_ts'] = date('Y-m-d h:i:s');
//echo '<pre>'; print_r($_FILES['profile_photo']);die;
if($_FILES['profile_photo']['name']){
$path = './public/upload_image/profile_photo/';
$upload_file = $this->single_image_upload($path, $_FILES['profile_photo'],'profile_photo');
if($upload_file['status']==1){
$profile_data['profile_photo']=$upload_file['result'];
}
}
$condition_profile=array('profile_id'=>$profile_id);
$profile_id=$this->mcommon->update('user_profile',$condition_profile,$profile_data);
if($_FILES['driver_certificate']['name'][0]){
$path = './public/upload_image/driver_certificate/';
$upload_file = $this->upload_Product_images($path, $_FILES['driver_certificate'], $user_id,'driver_certificate');
}
if($_FILES['driving_license']['name'][0]){
$path = './public/upload_image/driving_license/';
$upload_file = $this->upload_Product_images($path, $_FILES['driving_license'], $user_id,'driving_license');
}
if($_FILES['login_card']['name'][0]){
$path = './public/upload_image/login_card/';
$upload_file = $this->upload_Product_images($path, $_FILES['login_card'], $user_id,'login_card');
}
if($_FILES['paper_dc']['name'][0]){
$path = './public/upload_image/paper_dc/';
$upload_file = $this->upload_Product_images($path, $_FILES['paper_dc'], $user_id,'paper_dc');
}
if($_FILES['signature']['name'][0]){
$path = './public/upload_image/signature/';
$upload_file = $this->upload_Product_images($path, $_FILES['signature'], $user_id,'signature');
}
$condition_user=array('user_id'=>$user_id,'dc_no'=>$user_data['dc_no']);
$user_data = $this->mcommon->getRow('master_user',$condition_user,$user_data);
$this->session->set_flashdata('success_msg','Driver Updated Successfully');
if(!empty($user_data) && $user_data['is_active'] == 1){
redirect(base_url('admin/driver/driver_master_list'));
}
else{
redirect(base_url('admin/driver'));
}
}
else{
$this->session->set_flashdata('error_msg','Oops!Something went wrong...');
redirect(base_url('admin/driver'));
}
}
}
else{
$this->_load_edit_new_driver($user_id);
}
}
public function check_email() {
$email = $this->input->post('email');// get fiest name
$user_id = $this->input->post('user_id');// get last name
$result = $this->mdriver->check_email_exist($email,$user_id);
//echo $result;die;
return $result;
}
public function check_dc_no() {
$dc_no = $this->input->post('dc_no');// get fiest name
$user_id = $this->input->post('user_id');// get last name
$result = $this->mdriver->check_dc_no_exist($dc_no,$user_id);
//echo $result;die;
return $result;
}
private function _load_edit_new_driver($user_id){
$data['content']='admin/driver/edit_new_driver';
$data['commission_type']=$this->mcommon->getDetails('master_commission',array('status'=>1));
$data['driver_data']=$this->mdriver->get_driver_data($user_id);
$data['driver_doc']=$this->mdriver->get_driver_doc($user_id);
//pr($data['driver_doc']);
$this->load->view('admin/layouts/index',$data);
}
public function delete_content(){
$condition['category_id']=$this->input->post('category_id');
$category_information = $this->mcategory->get_details($this->input->post('subject_id'));
if($category_information['category_image']){
unlink('./uploads/category/'.$category_information['category_image']);
}
$this->mcategory->delete($condition);
$response=array('status'=>1,'message'=>'Success');
echo header('Content-Type: application/json');
echo json_encode($response);
}
public function change_status(){
$category_id=$this->input->post('category_id');
$query = $this->mcategory->change_status($category_id);
if($query){
echo json_encode('Updated');
}else{
echo json_encode('Not Updated');
}
}
private function upload_Product_images($path,$files,$user_id,$document_type){
//echo"<pre>";print_r($product_id); die;
$config = array(
'upload_path' => $path,
'allowed_types' => 'gif|jpg|png|jpeg|pdf|doc|docx',
'overwrite' => 1,
);
$this->load->library('upload', $config);
$images = array();
foreach ($files['name'] as $key => $image) {
$_FILES['images[]']['name']= $files['name'][$key];
$_FILES['images[]']['type']= $files['type'][$key];
$_FILES['images[]']['tmp_name']= $files['tmp_name'][$key];
$_FILES['images[]']['error']= $files['error'][$key];
$_FILES['images[]']['size']= $files['size'][$key];
$fileName = $document_type.'_'.time() .'_'. $key .'_'. str_replace(" ","_",$image);
$images[] = $fileName;
$config['file_name'] = $fileName;
$this->upload->initialize($config);
if ($this->upload->do_upload('images[]')) {
if($document_type == 'signature'){
$this->mcommon->delete('user_docs',array('document_type'=>'signature','user_id'=>$user_id));
}
$ap['user_id'] = $user_id;
$ap['document_type'] = $document_type;
$ap['document_path'] = $fileName;
$ap['created_ts'] = date('Y-m-d H:i:s');
/************ Sreela (21/10/19) end ********************/
$this->mcommon->insert('user_docs',$ap);
} else {
//echo $this->upload->display_errors(); die;
return false;
}
}
return $images;
}
private function single_image_upload($path,$files,$document_type){
$fileName = $document_type.'_'.time().'_'. str_replace(" ","_",$files['name']);
$config = array(
'upload_path' => $path,
'allowed_types' => 'gif|jpg|png|jpeg|pdf|doc|docx',
'overwrite' => 1,
'file_name' =>$fileName
);
//print_r($config);die;
$this->load->library('upload', $config);
if (!$this->upload->do_upload($document_type)){
$message = array('result' => 'The file you are attempting is not correct. Please select gif|jpg|png|jpeg file','status'=>0);
}else{
$data = array('upload_data' => $this->upload->data());
$message = array('result' => $data['upload_data']['file_name'],'status'=>1);
}
return $message;
}
public function delete_document(){
$image_id=$_POST['image_id'];
$img_link=$_POST['img_link'];
$type=$_POST['type'];
//echo $img_link;die;
if($type=='profile'){
$condition=array("profile_id"=>$image_id);
$user_data['profile_photo']='';
$status=$this->mcommon->update('user_profile',$condition,$user_data);
}
else{
$condition=array("driver_docs_id"=>$image_id);
$status=$this->mcommon->delete('user_docs',$condition);
}
if($status){
if(file_exists($img_link)){
unlink($img_link);
}
$return_data=array('status'=>true,'msg'=>'Document deleted successfully');
}
else{
$return_data=array('status'=>false,'msg'=>'Document not deleted');
}
echo json_encode($return_data);
}
/*
author: soma
purpose: Set a driver deactive
date: 13-9-2019
*/
public function set_deactive_driver($user_id)
{
$result = array();
$result = $this->mdriver->set_deactive_driver($user_id);
if($result)
{
$this->session->set_flashdata('success_msg','Driver deactivated successfully');
redirect('admin/driver/driver_master_list');
}else{
$this->session->set_flashdata('error_msg','Oops!Something went wrong...');
}
}
/*
author: soma
purpose: Set a driver Active
date: 13-9-2019
*/
public function set_active_driver($user_id)
{
$result = array();
$result = $this->mdriver->set_active_driver($user_id);
if($result)
{
$this->session->set_flashdata('success_msg','Driver activated successfully...');
redirect('admin/driver/driver_master_list');
}else{
$this->session->set_flashdata('error_msg','Oops!Something went wrong...');
}
}
/*
author: soma
purpose: delete a driver
date: 13-9-2019
*/
public function delete_driver($user_id)
{
$result = array();
$result = $this->mdriver->delete_driver($user_id);
if($result)
{
redirect('admin/driver/driver_master_list');
}
}
/*
author: soma
purpose: restore driver
date: 13-9-2019
*/
public function restore_driver($user_id)
{
$result = array();
$result = $this->mdriver->restore_driver($user_id);
if($result)
{
redirect('admin/driver/driver_master_list');
}
}
/*
author: sreela
purpose: Set a Generate Agreement
date: 26-9-2019
*/
public function randomPassword(){
$alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
$pass = array(); //remember to declare $pass as an array
$alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
for ($i = 0; $i < 8; $i++) {
$n = rand(0, $alphaLength);
$pass[] = $alphabet[$n];
}
return implode($pass); //turn the array into a string
}
public function generate_agreement($user_id){
$data = array();
$joindata = array('select' =>'master_user.email,master_user.dc_no,user_profile.*',
'first_table' =>'master_user',
'second_table' =>'user_profile',
'dependency1' =>'master_user.user_id = user_profile.user_id',
'join_type1' =>'INNER'
);
//pr($joindata);
$condition = array('master_user.user_id' => $user_id,'role_id' => '2');
$driver_details = $this->mcommon->joinQuery($joindata,$condition,'row','','');
//pr($driver_details);
if(!empty($driver_details)){
$data['driver_details'] = $driver_details;
}
else{
$data['driver_details'] = '';
}
$driver_commission = $this->mcommon->getFullDetails('master_commission');
if(!empty($driver_commission)){
$data['driver_commission'] = $driver_commission;
}
else{
$data['driver_commission'] = '';
}
$con_car = array('status' => 1);
$all_cars = $this->mcommon->getDetails('master_car',$con_car);
if(!empty($all_cars)){
$data['all_cars'] = $all_cars;
}
else{
$data['all_cars'] = '';
}
$dr_sign = array('user_id' => $user_id,'document_type' =>'signature');
$sign = $this->mcommon->getRow('user_docs',$dr_sign);
if(!empty($sign)){
$data['dr_sign'] = $sign['document_path'];
}
else{
$data['dr_sign'] = '';
}
//pr($data);
$data['content'] = 'admin/driver/generate_agreement';
$data['company_list'] = $this->mcommon->getDetails('master_company',array('company_status'=>1));
$this->load->view('admin/layouts/index', $data);
}
public function getCompanyDetails(){
$companyarr = array();
$company_id = $this->input->post('company_id');
$condition = array('company_id' => $company_id);
$company_details = $this->mcommon->getRow('master_company',$condition);
//pr($company_details);
if(!empty($company_details)){
$companyarr['company_details'] = $company_details;
}
else{
$companyarr['company_details'] = '';
}
echo json_encode($companyarr);exit;
}
public function ajaxAddRowCompany(){
$resultarr = array();
$company_cnt_no = $this->input->post('company_cnt_no');
$resultarr['company_cnt'] = ++$company_cnt_no;
$data['company_cnt_no'] = $resultarr['company_cnt'];
$data['company_list'] = $this->mcommon->getDetails('master_company',array('company_status'=>1));
$resultarr['html'] = $this->load->view('admin/driver/ajax_generate_agreement', $data, true);
echo json_encode($resultarr);exit;
}
public function generateAgreement(){
//pr($_POST);
$agreement_details = array();
if($this->input->post()){
$driver_id = $this->input->post('driver_id');
$driver_name = $this->input->post('driver_first_name');
$driver_email = $this->input->post('driver_email');
$dc_no = $this->input->post('driver_accreditation_no');
$total_installment_amt_paid = '0.00';
$logo = base_url('public/images/logo.png');
/*$data['logo'] = 'public/images/logo.png';
$data['agremnt_data'] = $_POST;
$html = $this->load->view('admin/driver/pdf_generate_agreement', $data, true);
$dompdf = new Dompdf\Dompdf();
$dompdf->set_option("isPhpEnabled", true);
$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$pdf = $dompdf->output();
//echo $pdf;die();
$filename='driver_agreement_'.$driver_id;
$file = './public/driver_agreement_pdf/'.$filename.'.pdf';
//echo $file;die();
//unlink($file);
@file_put_contents($file, $pdf);*/
/************************* insert/update in master agreement ****************************/
$commencement_date = !empty($this->input->post('commencement_date'))? date('Y-m-d',strtotime(str_replace('/', '-', $this->input->post('commencement_date')))):'';
$completion_date = !empty($this->input->post('completion_date'))? date('Y-m-d',strtotime(str_replace('/', '-', $this->input->post('completion_date')))):'';
$policy_expirydt = !empty($this->input->post('policy_expirydt'))? date('Y-m-d',strtotime(str_replace('/', '-', $this->input->post('policy_expirydt')))):'';
$cond = array('driver_id' => $driver_id);
$agreement_data = $this->mcommon->getRow('master_agreement',$cond);
$agree_insrt_arry = array('driver_id' => $driver_id,
'agreement_time' => $this->input->post('payment_time'),
'agreement_place' => $this->input->post('payment_place'),
'drv_payment_method' => $this->input->post('payment_method'),
'agreement_start_dt' => $commencement_date,
'agreement_end_dt' => $completion_date,
'garage_address' => $this->input->post('garage_addr'),
'garage_suburb' => $this->input->post('garage_suburb'),
'garage_pincode' => $this->input->post('garage_postcode'),
'drv_insurer' => $this->input->post('insurance_policy_details'),
'drv_insurance_type' => $this->input->post('insurance_type'),
'drv_insurance_number' => $this->input->post('policy_number'),
'drv_insurance_expiry_date' => $policy_expirydt,
'additional_terms' => $this->input->post('additional_terms'),
'created_on' =>date('Y-m-d')
);
//echo '<pre>'; print_r($agree_insrt_arry);die;
if(empty($agreement_data)){
$agree_insrt_arry['created_on'] = date('Y-m-d');
$this->mcommon->insert('master_agreement',$agree_insrt_arry);
}
else{
$agree_insrt_arry['updated_on'] = date('Y-m-d');
$this->mcommon->update('master_agreement',$cond,$agree_insrt_arry);
}
/************************* insert/update in master Bond ****************************/
$bond_data = $this->mcommon->getRow('master_bond',$cond);
$bond_insrt_arry = array('driver_id' => $driver_id,
'bond_amt' => $this->input->post('bond_amt'),
'initial_amt_paid' => $this->input->post('bond_initial_amt'),
'installment_shift' => $this->input->post('amount_per_shift'),
'installment_amt_paid' => $total_installment_amt_paid,
'bond_settlement_flag' => '0'
);
if(empty($bond_data)){
$bond_insrt_arry['created_by'] = $this->session->userdata('user_data');
$bond_insrt_arry['created_on'] = date('Y-m-d');
$this->mcommon->insert('master_bond',$bond_insrt_arry);
}
else{
$bond_insrt_arry['updated_by'] = $this->session->userdata('user_data');
$bond_insrt_arry['updated_on'] = date('Y-m-d');
$this->mcommon->update('master_bond',$bond_insrt_arry,$cond);
}
/************************* insert in Company agreement mapping ****************************/
$company_agre_data = $this->mcommon->getRow('dr_company_agreement_mapping',$cond);
if(!empty($company_agre_data)){
$this->db->delete('dr_company_agreement_mapping', array('driver_id' => $driver_id));
}
$company_id = $this->input->post("company_id");
if(!empty($company_id)){
foreach($company_id as $key => $compny_list){
$company_agrr_arry = array('driver_id' =>$driver_id,
'company_id'=>$compny_list
);
$this->mcommon->insert('dr_company_agreement_mapping',$company_agrr_arry);
}
}
/****************** update driver Commission ****************************/
$cond_commission = array('user_id' => $driver_id);
$agree_upd_arry = array(
'dr_commission_id' => $this->input->post('commission_type'),
'dr_rental' => $this->input->post('rent_per_day')
);
$this->mcommon->update('user_profile',$cond_commission,$agree_upd_arry);
/****************** change the driver status to active ****************************/
$password = $this->randomPassword();
$condition = array('user_id' => $driver_id);
$update_arr = array('status' =>'1',
'updated_by' =>$this->session->userdata('user_data'),
'updated_ts' =>date('Y-m-d H:i:s'),
'is_active' =>'1',
'password' =>md5($password),
'org_password'=>$password
);
$this->mcommon->update('master_user',$condition,$update_arr);
/****************** change the driver status to active end ****************************/
/****************** Agreement pdf (21/10/19)****************************/
$cond_agrmnt = array('driver_id' => $driver_id);
$dr_agreement_detail = $this->mcommon->getRow('master_agreement',$cond_agrmnt);
if(!empty($dr_agreement_detail)){
$agreement_details['payment_time'] = $dr_agreement_detail['agreement_time'];
$agreement_details['payment_place'] = $dr_agreement_detail['agreement_place'];
$agreement_details['payment_method'] = $dr_agreement_detail['drv_payment_method'];
$agreement_details['commencement_date'] = date('d/m/Y',strtotime($dr_agreement_detail['agreement_start_dt']));
$agreement_details['completion_date'] = date('d/m/Y',strtotime($dr_agreement_detail['agreement_end_dt']));
$agreement_details['garage_addr'] = $dr_agreement_detail['garage_address'];
$agreement_details['garage_suburb'] = $dr_agreement_detail['garage_suburb'];
$agreement_details['garage_pincode'] = $dr_agreement_detail['garage_pincode'];
$agreement_details['insurance_policy_details'] = $dr_agreement_detail['drv_insurer'];
$agreement_details['insurance_type'] = $dr_agreement_detail['drv_insurance_type'];
$agreement_details['policy_number'] = $dr_agreement_detail['drv_insurance_number'];
$agreement_details['policy_expirydt'] = date('d/m/Y',strtotime($dr_agreement_detail['drv_insurance_expiry_date']));
$agreement_details['additional_terms'] = $dr_agreement_detail['additional_terms'];
}
$bond_detail = $this->mcommon->getRow('master_bond',$cond_agrmnt);
if(!empty($bond_detail)){
$agreement_details['bond_amt'] = $bond_detail['bond_amt'];
$agreement_details['bond_initial_amt'] = $bond_detail['initial_amt_paid'];
$agreement_details['amount_per_shift'] = $bond_detail['installment_shift'];
}
$commission_cond = array('user_id' => $driver_id);
$commission_detail = $this->mcommon->getRow('user_profile',$commission_cond);
if(!empty($commission_detail)){
$agreement_details['commission_type'] = $commission_detail['dr_commission_id'];
$agreement_details['rent_per_day'] = $commission_detail['dr_rental'];
}
$joindata = array('select' =>'master_user.email,master_user.dc_no,user_profile.*,ud.document_path',
'first_table' =>'master_user',
'second_table' =>'user_profile',
'dependency1' =>'master_user.user_id = user_profile.user_id',
'join_type1' =>'INNER JOIN',
/*****************************/
'third_table' =>'user_docs ud',
'dependency2' =>'ud.user_id = master_user.user_id',
'join_type2' =>'INNER JOIN'
);
$driver_condn = array('master_user.user_id' => $driver_id,'role_id' => '2','ud.document_type'=>'signature');
$driver_details = $this->mcommon->joinQuery($joindata,$driver_condn,'row','','');
//pr($driver_details);
if(!empty($driver_details)){
$agreement_details['driver_first_name'] = $driver_details['first_name'];
$agreement_details['driver_middle_name'] = $driver_details['middle_name'];
$agreement_details['driver_last_name'] = $driver_details['last_name'];
$agreement_details['driver_dob'] = $driver_details['dob'];
$agreement_details['driver_business_name'] = '';
$agreement_details['driver_business_abn'] = $driver_details['abn'];
$agreement_details['driver_mobile'] = $driver_details['mobile'];
$agreement_details['driver_email'] = $driver_details['email'];
$agreement_details['driver_licence_no'] = $driver_details['dr_licence_no'];
$agreement_details['driver_licence_expdt'] = date('d/m/Y',strtotime($driver_details['dr_licence_expiry']));
$agreement_details['driver_accreditation_no'] = $driver_details['dc_no'];
$agreement_details['driver_accreditation_expdt']= date('d/m/Y',strtotime($driver_details['dr_dc_expiry']));
$agreement_details['driver_flatno'] = $driver_details['flat_no'];
$agreement_details['driver_streetno'] = $driver_details['street_no'];
$agreement_details['driver_streetname'] = $driver_details['street_name'];
$agreement_details['driver_suburb'] = $driver_details['suburb'];
$agreement_details['driver_postcode'] = $driver_details['pin'];
$agreement_details['created_ts'] = date('d/m/Y',strtotime($driver_details['created_ts']));
$data['driver_signature'] = 'public/upload_image/signature/'.$driver_details['document_path'];
}
$joindata_comp = array('select' =>'master_company.*',
'first_table' =>'master_company',
'second_table' =>'dr_company_agreement_mapping',
'dependency1' =>'master_company.company_id = dr_company_agreement_mapping.company_id',
'join_type1' =>'INNER JOIN',
);
//pr($joindata);
$condition_comp = array('dr_company_agreement_mapping.driver_id' => $driver_id);
$company_details = $this->mcommon->joinQuery($joindata_comp,$condition_comp,'result','','');
if(!empty($company_details)){
$agreement_details['company_details'] = $company_details;
$data['company_signature'] = 'public/upload_image/signature/'.$company_details[0]['signature_file'];
}
else{
$agreement_details['company_details'] = '';
}
$con_car = array('status' => 1);
$all_cars = $this->mcommon->getDetails('master_car',$con_car);
if(!empty($all_cars)){
$data['all_cars'] = $all_cars;
}
else{
$data['all_cars'] = '';
}
//pr($agreement_details);
$data['logo'] = 'public/images/logo.png';
$data['agremnt_data'] = $agreement_details;
$html = $this->load->view('admin/driver/pdf_generate_agreement', $data, true);
$dompdf = new Dompdf\Dompdf();
$dompdf->set_option("isPhpEnabled", true);
$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$canvas = $dompdf->get_canvas();
$canvas->page_text(555, 750, "{PAGE_NUM}/{PAGE_COUNT}", $font, 10, array(0,0,0));
$canvas->page_script('
$pdf->line(10,730,800,730,array(0,0,0),1);
');
$pdf = $dompdf->output();
//echo $pdf;die();
$filename='driver_agreement_'.$driver_id;
$file = './public/driver_agreement_pdf/'.$filename.'.pdf';
//echo "jhj".$file;die();
//unlink($file);
@file_put_contents($file, $pdf);
/****************** Send password to the driver ****************************/
$params['name'] = $driver_name;
$params['to'] = $driver_email;
//$params['to'] = 'sreelabiswas.kundu@met-technologies.com';
$params['password'] = $password;
$params['subject'] = 'PunjabMotor - Driver Activation Mail';
$mail_temp = file_get_contents('./global/mail/driver_activation.html');
$mail_temp = str_replace("{web_url}", base_url(), $mail_temp);
$mail_temp = str_replace("{logo}", $logo, $mail_temp);
$mail_temp = str_replace("{shop_name}", 'Punjabmotor', $mail_temp);
$mail_temp = str_replace("{name}", $params['name'], $mail_temp);
$mail_temp = str_replace("{username}", $dc_no, $mail_temp);
$mail_temp = str_replace("{passwd}", $params['password'], $mail_temp);
$mail_temp = str_replace("{current_year}", date('Y'), $mail_temp);
$params['message'] = $mail_temp;
$nme = "driver_agreement_".$driver_id.".pdf";
$attach = base_url('public/driver_agreement_pdf/'.$nme);
$msg = driver_agreement($params,$attach);
//$msg = registration_mail($params);
/****************** Send password to the driver end****************************/
redirect('admin/driver/driver_master_list');
}
}
public function downloadAgreement($user_id){
$driver_id = $user_id;
$agreement_details = array();
$cond = array('driver_id' => $driver_id);
$agreement_data = $this->mcommon->getRow('master_agreement',$cond);
if(!empty($agreement_data)){
$agreement_details['payment_time'] = $agreement_data['agreement_time'];
$agreement_details['payment_place'] = $agreement_data['agreement_place'];
$agreement_details['payment_method'] = $agreement_data['drv_payment_method'];
$agreement_details['commencement_date'] = !empty($agreement_data['agreement_start_dt'])?date('d/m/Y',strtotime($agreement_data['agreement_start_dt'])):'';
$agreement_details['completion_date'] = !empty($agreement_data['agreement_end_dt'])?date('d/m/Y',strtotime($agreement_data['agreement_end_dt'])):'';
$agreement_details['garage_addr'] = $agreement_data['garage_address'];
$agreement_details['garage_suburb'] = $agreement_data['garage_suburb'];
$agreement_details['garage_pincode'] = $agreement_data['garage_pincode'];
$agreement_details['insurance_policy_details'] = $agreement_data['drv_insurer'];
$agreement_details['insurance_type'] = $agreement_data['drv_insurance_type'];
$agreement_details['policy_number'] = $agreement_data['drv_insurance_number'];
$agreement_details['policy_expirydt'] = !empty($agreement_data['drv_insurance_expiry_date'])?date('d/m/Y',strtotime($agreement_data['drv_insurance_expiry_date'])):'';
$agreement_details['additional_terms'] = $agreement_data['additional_terms'];
}
$bond_data = $this->mcommon->getRow('master_bond',$cond);
if(!empty($bond_data)){
$agreement_details['bond_amt'] = $bond_data['bond_amt'];
$agreement_details['bond_initial_amt'] = $bond_data['initial_amt_paid'];
$agreement_details['amount_per_shift'] = $bond_data['installment_shift'];
}
$cond_commission = array('user_id' => $driver_id);
$commission_data = $this->mcommon->getRow('user_profile',$cond_commission);
if(!empty($commission_data)){
$agreement_details['commission_type'] = $commission_data['dr_commission_id'];
$agreement_details['rent_per_day'] = $commission_data['dr_rental'];
}
$joindata = array('select' =>'master_user.email,master_user.dc_no,user_profile.*,ud.document_path',
'first_table' =>'master_user',
'second_table' =>'user_profile',
'dependency1' =>'master_user.user_id = user_profile.user_id',
'join_type1' =>'INNER JOIN',
/*****************************/
'third_table' =>'user_docs ud',
'dependency2' =>'ud.user_id = master_user.user_id',
'join_type2' =>'INNER JOIN'
);
$driver_condn = array('master_user.user_id' => $driver_id,'role_id' => '2','ud.document_type' =>'signature');
$driver_details = $this->mcommon->joinQuery($joindata,$driver_condn,'row','','');
//pr($driver_details);
if(!empty($driver_details)){
$agreement_details['driver_first_name'] = $driver_details['first_name'];
$agreement_details['driver_middle_name'] = $driver_details['middle_name'];
$agreement_details['driver_last_name'] = $driver_details['last_name'];
$agreement_details['driver_dob'] = $driver_details['dob'];
$agreement_details['driver_business_name'] = '';
$agreement_details['driver_business_abn'] = $driver_details['abn'];
$agreement_details['driver_mobile'] = $driver_details['mobile'];
$agreement_details['driver_email'] = $driver_details['email'];
$agreement_details['driver_licence_no'] = $driver_details['dr_licence_no'];
$agreement_details['driver_licence_expdt'] = !empty($agreement_data['dr_licence_expiry'])?date('d/m/Y',strtotime($agreement_data['dr_licence_expiry'])):'';
$agreement_details['driver_accreditation_no'] = $driver_details['dc_no'];
$agreement_details['driver_accreditation_expdt']= !empty($agreement_data['dr_dc_expiry'])?date('d/m/Y',strtotime($agreement_data['dr_dc_expiry'])):'';
$agreement_details['driver_flatno'] = $driver_details['flat_no'];
$agreement_details['driver_streetno'] = $driver_details['street_no'];
$agreement_details['driver_streetname'] = $driver_details['street_name'];
$agreement_details['driver_suburb'] = $driver_details['suburb'];
$agreement_details['driver_postcode'] = $driver_details['pin'];
$agreement_details['created_ts'] = !empty($driver_details['created_ts'])?date('d/m/Y',strtotime($agreement_data['created_ts'])):'';
$data['driver_signature'] = 'public/upload_image/signature/'.$driver_details['document_path'];
}
$joindata_comp = array('select' =>'master_company.*',
'first_table' =>'master_company',
'second_table' =>'dr_company_agreement_mapping',
'dependency1' =>'master_company.company_id = dr_company_agreement_mapping.company_id',
'join_type1' =>'INNER JOIN'
);
//pr($joindata);
$condition_comp = array('dr_company_agreement_mapping.driver_id' => $driver_id);
$company_details = $this->mcommon->joinQuery($joindata_comp,$condition_comp,'result','','');
//pr($company_details);
if(!empty($company_details)){
$agreement_details['company_details'] = $company_details;
$data['company_signature'] = 'public/upload_image/signature/'.$company_details[0]['signature_file'];
}
else{
$agreement_details['company_details'] = '';
}
$con_car = array('status' => 1);
$all_cars = $this->mcommon->getDetails('master_car',$con_car);
if(!empty($all_cars)){
$data['all_cars'] = $all_cars;
}
else{
$data['all_cars'] = '';
}
//pr($agreement_details);
$data['logo'] = 'public/images/logo.png';
//$data['logo'] = base_url('public/images/logo.png');
$data['agremnt_data'] = $agreement_details;
$html = $this->load->view('admin/driver/pdf_generate_agreement', $data, true);
//echo $html;die;
$dompdf = new Dompdf\Dompdf();
//$dompdf->set_option("isPhpEnabled", true);
$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$pdf = $dompdf->output();
//echo $pdf;die();
$filename='driver_agreement_'.$driver_id.'_'.$driver_details['dc_no'];
$file = './public/driver_agreement_pdf/'.$filename.'.pdf';
@file_put_contents($file, $pdf);
// $nme = "driver_agreement_".$user_id.".pdf";
// $pth = file_get_contents(base_url()."public/driver_agreement_pdf/".$nme);
// force_download($nme, $pth);
$dompdf->stream($filename);
}
public function cropDriverSignature(){
$response = array();
$image = getImageSize($_POST['img'], $info); # $info, only to handle problems with earlier php versions...
//echo $image[2];exit;
switch($image[2]) {
case 1:
# GIF image
$img_r = imageCreateFromGIF($_POST['img']);
break;
case 2:
# JPEG image
$img_r = imageCreateFromJPEG($_POST['img']);
break;
case 3:
# PNG image
$img_r = imageCreateFromPNG($_POST['img']);
break;
}
//echo $img_r;exit;
$dst_r = ImageCreateTrueColor( $_POST['w'], $_POST['h'] );
imagecopyresampled($dst_r, $img_r, 0, 0, $_POST['x'], $_POST['y'], $_POST['w'], $_POST['h'], $_POST['w'],$_POST['h']);
//header('Content-type: image/png');
//imagecopy($dst_r,$img_r);
// The second parameter should be the path of your destination
switch($image[2]) {
case 1:
# GIF image
$file_name = 'crop_'.time() . '.gif';
$imageName = './public/upload_image/signature/'.$file_name;
header("Content-type: image/gif");
imageGIF($dst_r,$imageName);
break;
case 2:
# JPEG image
$file_name = 'crop_'.time() . '.jpeg';
$imageName = './public/upload_image/signature/'.$file_name;
header("Content-type: image/jpeg");
imageJPEG($dst_r,$imageName);
break;
case 3:
# PNG image
$file_name = 'crop_'.time() . '.png';
$imageName = './public/upload_image/signature/'.$file_name;
header("Content-type: image/png");
imagePNG($dst_r,$imageName);
break;
}
//echo"hjkdhk";exit;
//imagedestroy($dst_r);
//imagedestroy($img_r);
$condition = array('user_id' =>$_POST['driver_id'],'document_type' =>'signature');
$update_arr = array('document_path' =>$file_name);
$this->mcommon->update('user_docs',$condition,$update_arr);
$response['html'] = '<img src="'.base_url().$imageName.'" class="img-thumbnail" />';
$response['file_name'] = $file_name;
echo json_encode($response);
}
}