File: //var/www/html/qcr24/app/application/controllers/admin/RentOut.php
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class RentOut extends MY_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('admin/mrentout');
$this->load->model('mcommon');
$this->load->library('advantagepay');
}
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see https://codeigniter.com/driver_guide/general/urls.html
*/
public function index()
{
$data['rentoutDetails'] = $this->mrentout->getRentoutDetails();
//echo '<pre>'; print_r($data['rentoutDetails']);die;
$data['content'] = 'admin/rent_out/list';
$this->load->view('admin/layouts/index', $data);
}
public function add()
{
$data['cars'] = $this->mrentout->get_car();
$data['drivers'] = $this->mrentout->get_driver();
$data['countries'] = $this->mrentout->get_countries();
// $data['companies'] = $this->mcommon->getDetails('master_company','status="0"');
$data['content'] = 'admin/rent_out/add';
$this->load->view('admin/layouts/index', $data);
}
public function viewrentout($rent_out_id)
{
$data = array();
$data['countries'] = $this->mrentout->get_countries();
$data['rentoutDetails'] = $this->mrentout->getRentoutDetails($rent_out_id);
$data['content'] = 'admin/rent_out/view';
$this->load->view('admin/layouts/index', $data);
}
public function editrentout($rent_out_id)
{
$data['cars'] = $this->mrentout->get_car();
$data['drivers'] = $this->mrentout->get_driver();
// echo '<pre>'; print_r($data['drivers']);die;
// $data['companies'] = $this->mcommon->getDetails('master_company','status="0"');
$data['countries'] = $this->mrentout->get_countries();
$data['rentoutDetails'] = $this->mrentout->getRentoutDetails($rent_out_id);
// echo '<pre>'; print_r($data['rentoutDetails']);die;
$data['content'] = 'admin/rent_out/edit';
$this->load->view('admin/layouts/index', $data);
}
public function submitrentout()
{
//$this->generate_pdf();die;
//echo '<pre>'; print_r($this->input->post());die;
$car_id = $this->input->post('car_id');
$car_id_array = explode('#$', $car_id);
$odometer_reading = $this->input->post('odometer_reading');
$car_details = $this->mrentout->edit_car($car_id_array[0]);
if ($car_details['total_odometer_reading'] > $odometer_reading) {
$return_data = array('status' => false, 'msg' => 'Rent Out <b>Odometer Reading</b> must be grater than this car previous <b>Odometer Reading</b>.');
echo json_encode($return_data);
die;
}
$data = array(
'driver_id' => $this->input->post('driver_id'),
'car_id' => $car_id_array[0],
'odometer_reading' => $odometer_reading,
'basic_excess' => $this->input->post('basic_excess'),
'age_excess' => $this->input->post('age_excess'),
'overseas_dL_excess' => $this->input->post('overseas_dL_excess'),
'weekly_rent' => $this->input->post('weekly_rent'),
'bond_amount' => $this->input->post('bond_amount'),
'insurance_company' => $this->input->post('insurance_company'),
'insurance_username' => $this->input->post('insurance_username'),
'insurance_password' => $this->input->post('insurance_password'),
'expire' => date('Y-m-d', strtotime(str_replace('/', '-', $this->input->post('expire')))),
'notes' => $this->input->post('notes'),
'rent_out_no' => 'RO' . time() . '/CAR' . $car_id_array[1],
'payment_method' => $this->input->post('payment_method'),
'payment_reference_no' => $this->input->post('payment_reference_no'),
'created_by' => $this->admin_session_data['user_id'],
'created_ts' => date('Y-m-d H:i:s')
);
if (!empty($_FILES['cover_note_img']['name'])) {
$path1 = 'cover_note_img';
$cover_note_img = $this->image_upload($path1);
$data['cover_note_img'] = $cover_note_img;
}
if (!empty($_FILES['front_img']['name'])) {
$path2 = 'front_img';
$front_img = $this->image_upload($path2);
$data['front_img'] = $front_img;
}
if (!empty($_FILES['rear_img']['name'])) {
$path3 = 'rear_img';
$rear_img = $this->image_upload($path3);
$data['rear_img'] = $rear_img;
}
if (!empty($_FILES['driver_side_img']['name'])) {
$path4 = 'driver_side_img';
$driver_side_img = $this->image_upload($path4);
$data['driver_side_img'] = $driver_side_img;
}
if (!empty($_FILES['passenger_side_img']['name'])) {
$path5 = 'passenger_side_img';
$passenger_side_img = $this->image_upload($path5);
$data['passenger_side_img'] = $passenger_side_img;
}
if (!empty($_FILES['odometer_img']['name'])) {
$path6 = 'odometer_img';
$odometer_img = $this->image_upload($path6);
$data['odometer_img'] = $odometer_img;
}
if (!empty($_FILES['service_sticker_img']['name'])) {
$path7 = 'service_sticker_img';
$service_sticker_img = $this->image_upload($path7);
$data['service_sticker_img'] = $service_sticker_img;
}
if (!empty($_FILES['fuel_guage_img']['name'])) {
$path8 = 'fuel_guage_img';
$fuel_guage_img = $this->image_upload($path8);
$data['fuel_guage_img'] = $fuel_guage_img;
}
try {
// Direct Debit Customer Create / Update
$customer_response_array = array();
$customer_response = (object) array();
$advantage_pay_token = array();
if ($this->input->post('payment_method') == 'Direct Debit') {
$advantage_pay_token = $this->advantagepay->getToken($car_details['advantage_pay_credentials']);
$advantage_pay_token = json_decode($advantage_pay_token, true);
// echo '<pre>';
// print_r($advantage_pay_token);
// echo '<br>';
// print_r($car_details);
// echo '</pre>';
// die;
if (!$advantage_pay_token) {
$return_data = array('status' => false, 'msg' => 'Token not generated');
echo json_encode($return_data);
die;
}
$driver_details = $this->mrentout->get_driver_details($data['driver_id']);
$direct_debit_customer_details = $this->mrentout->get_direct_debit_customer_details($data['driver_id'], $car_details['company_id']);
if (!empty($direct_debit_customer_details['advantage_pay_customer_id'])) {
$customer_data = array(
"ExternalID" => $data['driver_id'],
"CustomRef" => $this->input->post('CustomRef'),
"Postcode" => $driver_details['pin'],
"FirstName" => $this->input->post('FirstName'),
"LastName" => $this->input->post('LastName'),
"MobileNumber" => array(
"CountryISO" => $this->input->post('CountryISO'),
"Number" => $this->input->post('Number')
),
"SendDirectDebitErrorEmails" => (($this->input->post('SendDirectDebitErrorEmails')) ? TRUE : FALSE),
"SendPaymentReceiptEmails" => (($this->input->post('SendPaymentReceiptEmails')) ? TRUE : FALSE)
);
$customer_response = $this->advantagepay->updateCustomer($customer_data, $advantage_pay_token['access_token'], $direct_debit_customer_details['advantage_pay_customer_id']);
} else {
$customer_data = array(
"IsConsumer" => true,
"ExternalID" => $data['driver_id'],
"CustomRef" => $this->input->post('CustomRef'),
"Postcode" => $driver_details['pin'],
"Email" => $this->input->post('Email'),
"FirstName" => $this->input->post('FirstName'),
"LastName" => $this->input->post('LastName'),
"MobileNumber" => array(
"CountryISO" => $this->input->post('CountryISO'),
"Number" => $this->input->post('Number')
),
"SendDirectDebitErrorEmails" => (($this->input->post('SendDirectDebitErrorEmails')) ? TRUE : FALSE),
"SendPaymentReceiptEmails" => (($this->input->post('SendPaymentReceiptEmails')) ? TRUE : FALSE)
);
$customer_response = $this->advantagepay->createCustomer($customer_data, $advantage_pay_token['access_token']);
}
//print_r($customer_data);die;
$customer_response_array = json_decode($customer_response, true);
//echo '<pre>';print_r($customer_response);die;
if (!$customer_response_array) {
$return_data = array('status' => false, 'msg' => 'Customer not created');
echo json_encode($return_data);
die;
}
if (isset($customer_response_array['ErrorCode'])) {
$return_data = array('status' => false, 'msg' => $customer_response_array['Messages'][0]);
echo json_encode($return_data);
die;
}
if (!isset($customer_response_array['Code']) || empty($customer_response_array['Code'])) {
$return_data = array('status' => false, 'msg' => 'Customer not created');
echo json_encode($return_data);
die;
}
}
$this->db->trans_start(); # Starting Transaction
if (!empty($customer_response_array)) {
if (!empty($direct_debit_customer_details['advantage_pay_customer_id'])) {
$direct_debit_customers_data = array(
'advantage_pay_customer_response' => $customer_response,
'updated_by' => $this->admin_session_data['user_id'],
'updated_ts' => date('Y-m-d H:i:s')
);
$this->db->update('direct_debit_customers', $direct_debit_customers_data, array('direct_debit_customer_id' => $direct_debit_customer_details['direct_debit_customer_id']));
$data['direct_debit_customer_id'] = $direct_debit_customer_details['direct_debit_customer_id'];
$this->db->update('master_driver', array('country_code' => $this->input->post('CountryISO')), array('driver_id' => $data['driver_id']));
} else {
$direct_debit_customers_data = array(
'driver_id' => $data['driver_id'],
'company_id' => $car_details['company_id'],
'advantage_pay_customer_id' => $customer_response_array['Code'],
'advantage_pay_customer_response' => $customer_response,
'created_by' => $this->admin_session_data['user_id'],
'created_ts ' => date('Y-m-d H:i:s')
);
$this->db->insert('direct_debit_customers', $direct_debit_customers_data);
$data['direct_debit_customer_id'] = $this->db->insert_id();
}
$this->db->update('master_driver', array('country_code' => $this->input->post('CountryISO')), array('driver_id' => $data['driver_id']));
}
$result = $this->mrentout->submit_rentout($data);
//echo $this->db->last_query();
$direct_debit_response_array = array();
if ($this->input->post('payment_method') == 'Direct Debit') {
//echo 1;die;
$direct_debit_data = array(
"Customer" => array(
"Code" => $customer_response_array['Code']
),
"Description" => $this->input->post('Description'),
"ExternalID" => $result,
"UpfrontAmount" => (($this->input->post('UpfrontAmount')) ? $this->input->post('UpfrontAmount') : NULL),
"UpfrontDate" => (($this->input->post('UpfrontDate') && $this->input->post('UpfrontAmount')) ? date('Y-m-d', strtotime(str_replace('/', '-', $this->input->post('UpfrontDate')))) : NULL),
"RecurringAmount" => $data['weekly_rent'],
"RecurringDateStart" => (($this->input->post('RecurringDateStart')) ? date('Y-m-d', strtotime(str_replace('/', '-', $this->input->post('RecurringDateStart')))) : NULL),
"Frequency" => (($this->input->post('Frequency')) ? $this->input->post('Frequency') : ''),
"EndConditionAmount" => NULL,
"FailureOption" => (($this->input->post('FailureOption')) ? $this->input->post('FailureOption') : ''),
"OnchargedFees" => ['dishonour'],
"ReminderDays" => 1,
//(($this->input->post('ReminderDays'))?$this->input->post('ReminderDays'):0)
);
//print_r($direct_debit_data);die;
$direct_debit_response = $this->advantagepay->createDirectDebits($direct_debit_data, $advantage_pay_token['access_token']);
$direct_debit_response_array = json_decode($direct_debit_response, true);
//echo '<pre>';print_r($customer_response);die;
if (!$direct_debit_response_array) {
$return_data = array('status' => false, 'msg' => 'Direct debit not created');
echo json_encode($return_data);
die;
}
if (isset($direct_debit_response_array['ErrorCode'])) {
$return_data = array('status' => false, 'msg' => $direct_debit_response_array['Messages'][0]);
echo json_encode($return_data);
die;
}
if (!isset($direct_debit_response_array['Code']) || empty($direct_debit_response_array['Code'])) {
$return_data = array('status' => false, 'msg' => 'Direct debit not created');
echo json_encode($return_data);
die;
}
$this->db->update('rent_out_vehcile', array('direct_debit_response' => $direct_debit_response, 'direct_debit_status_response' => $direct_debit_response, 'direct_debit_id' => $direct_debit_response_array['Code']), array('rent_out_id' => $result));
//echo $this->db->last_query();
}
$condition = array('car_id' => $car_id_array[0]);
$car_data = array(
'total_odometer_reading' => $odometer_reading,
'insurance_expire_date' => date('Y-m-d', strtotime(str_replace('/', '-', $this->input->post('expire')))),
'user_type' => 'USER',
'updated_by' => $this->admin_session_data['user_id'],
'updated_ts' => date('Y-m-d H:i:s')
);
$this->mrentout->update_car($condition, $car_data);
//echo $this->db->last_query();
$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' => $result,
'created_by' => $this->admin_session_data['user_id'],
'created_ts' => date('Y-m-d H:i:s')
);
$this->db->insert('bond_wallet', $bond_data);
//echo $this->db->last_query();
$this->db->trans_complete(); # Completing transaction
if ($this->db->trans_status() === FALSE) {
# Something went wrong.
$this->db->trans_rollback();
$return_data = array('status' => false, 'msg' => 'Oops!Something went wrong...');
echo json_encode($return_data);
die;
} 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 - ' . $data['rent_out_no'] . ' Added',
'link' => 'admin/rentOut',
'icon' => '<i class="fa fa-history" aria-hidden="true"></i>',
);
$this->activity_log($activityLogData);
//************************This Part is for Activity Log*******************************//
//************************************************************************************//
$return_data = array('status' => true, 'msg' => 'Rent Out Added Successfully', 'direct_debit_response_array' => $direct_debit_response_array, 'rent_out_id' => $result);
echo json_encode($return_data);
die;
}
} catch (Exception $e) {
// this will not catch DB related errors. But it will include them, because this is more general.
$return_data = array('status' => false, 'msg' => $e->getMessage());
echo json_encode($return_data);
die;
}
}
public function updaterentout()
{
$car_id = $this->input->post('hid_car_id');
$odometer_reading = $this->input->post('odometer_reading');
$car_details = $this->mrentout->edit_car($car_id);
$rentoutDetails = $this->mrentout->getRentoutDetails($this->input->post('hid_rent_out_id'));
if ($car_details['total_odometer_reading'] > $odometer_reading) {
$return_data = array('status' => false, 'msg' => 'Rent Out <b>Odometer Reading</b> must be grater than this car previous <b>Odometer Reading</b>.');
echo json_encode($return_data);
die;
}
$data = array(
'driver_id' => $this->input->post('driver_id'),
// 'odometer_reading' =>$this->input->post('odometer_reading'),
// 'basic_excess' => $this->input->post('basic_excess'),
// 'age_excess' => $this->input->post('age_excess'),
// 'overseas_dL_excess' => $this->input->post('overseas_dL_excess'),
// 'weekly_rent' => $this->input->post('weekly_rent'),
// 'bond_amount'=> $this->input->post('bond_amount'),
'insurance_company' => $this->input->post('insurance_company'),
'insurance_username' => $this->input->post('insurance_username'),
'insurance_password' => $this->input->post('insurance_password'),
'expire' => date('Y-m-d', strtotime(str_replace('/', '-', $this->input->post('expire')))),
'notes' => $this->input->post('notes'),
'updated_by' => $this->admin_session_data['user_id'],
'updated_ts' => date('Y-m-d H:i:s')
);
if (!empty($_FILES['cover_note_img']['name'])) {
$path1 = 'cover_note_img';
$cover_note_img = $this->image_upload($path1);
@unlink('./public/admin_images/rent_out/cover_note_imgs/' . $this->input->post('cover_note_img_old'));
$data['cover_note_img'] = $cover_note_img;
}
if (!empty($_FILES['front_img']['name'])) {
$path2 = 'front_img';
$front_img = $this->image_upload($path2);
@unlink('./public/admin_images/rent_out/front_imgs/' . $this->input->post('front_img_old'));
$data['front_img'] = $front_img;
}
if (!empty($_FILES['rear_img']['name'])) {
$path3 = 'rear_img';
$rear_img = $this->image_upload($path3);
@unlink('./public/admin_images/rent_out/rear_imgs/' . $this->input->post('rear_img_old'));
$data['rear_img'] = $rear_img;
}
if (!empty($_FILES['driver_side_img']['name'])) {
$path4 = 'driver_side_img';
$driver_side_img = $this->image_upload($path4);
@unlink('./public/admin_images/rent_out/driver_side_imgs/' . $this->input->post('driver_side_img_old'));
$data['driver_side_img'] = $driver_side_img;
}
if (!empty($_FILES['passenger_side_img']['name'])) {
$path5 = 'passenger_side_img';
$passenger_side_img = $this->image_upload($path5);
@unlink('./public/admin_images/rent_out/passenger_side_imgs/' . $this->input->post('passenger_side_img_old'));
$data['passenger_side_img'] = $passenger_side_img;
}
if (!empty($_FILES['odometer_img']['name'])) {
$path6 = 'odometer_img';
$odometer_img = $this->image_upload($path6);
@unlink('./public/admin_images/rent_out/odometer_imgs/' . $this->input->post('odometer_img_old'));
$data['odometer_img'] = $odometer_img;
}
if (!empty($_FILES['service_sticker_img']['name'])) {
$path7 = 'service_sticker_img';
$service_sticker_img = $this->image_upload($path7);
@unlink('./public/admin_images/rent_out/service_sticker_imgs/' . $this->input->post('service_sticker_img_old'));
$data['service_sticker_img'] = $service_sticker_img;
}
if (!empty($_FILES['fuel_guage_img']['name'])) {
$path8 = 'fuel_guage_img';
$fuel_guage_img = $this->image_upload($path8);
@unlink('./public/admin_images/rent_out/fuel_guage_imgs/' . $this->input->post('fuel_guage_img_old'));
$data['fuel_guage_img'] = $fuel_guage_img;
}
$condition = array('rent_out_id' => $this->input->post('hid_rent_out_id'));
$result = $this->mrentout->update_rentout($condition, $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' => 'USER',
'updated_by' => $this->admin_session_data['user_id'],
'updated_ts' => date('Y-m-d H:i:s')
);
$this->mrentout->update_car($condition, $car_data);
if ($result) {
//************************************************************************************//
//************************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('hid_rent_out_id'),
'icon' => '<i class="fa fa-history" aria-hidden="true"></i>',
);
$this->activity_log($activityLogData);
//************************This Part is for Activity Log*******************************//
//************************************************************************************//
$return_data = array('status' => true, 'msg' => 'Rent Out Updated Successfully');
echo json_encode($return_data);
die;
}
}
public function image_upload($path)
{
// Upload folder location***
$config = array();
$config['upload_path'] = './public/admin_images/rent_out/' . $path . 's';
// Allowed file type***
$config['allowed_types'] = '*';
$config['encrypt_name'] = TRUE;
// load upload library***
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ($this->upload->do_upload($path)) {
return $this->upload->data()['file_name'];
} else {
echo 'File Name' . $path . ' Errors' . $this->upload->display_errors();
die;
}
}
public function generate_pdf()
{
$this->load->library('pdf');
$html = $this->load->view('rentalPdf', [], true);
$this->pdf->createPDF($html, 'mypdf', false);
}
public function get_driver_details()
{
try {
$driver_id = $this->input->post('driver_id');
$car_id = $this->input->post('car_id');
$car_details = $this->mrentout->edit_car($car_id);
$driver_details = $this->mrentout->get_driver_details($driver_id);
$direct_debit_customer_details = $this->mrentout->get_direct_debit_customer_details($driver_id, $car_details['company_id']);
// echo '<pre>';
// print_r($car_details);
// echo '<br>';
// print_r($driver_details);
// echo '<br>';
// print_r($direct_debit_customer_details);
// echo '<br>';
// print_r($this->admin_session_data);
// echo '</pre>';
// die;
$advantage_pay_token = $this->advantagepay->getToken($car_details['advantage_pay_credentials']);
// echo '<pre>';
// echo 'Advantage Pay Token 123:';
// echo ($advantage_pay_token);
// echo '</pre>';
// die;
$advantage_pay_token = json_decode($advantage_pay_token, true);
if (!$advantage_pay_token) {
$return_data = array('status' => false, 'msg' => 'Token not generated');
echo json_encode($return_data);
die;
}
if (!empty($direct_debit_customer_details['advantage_pay_customer_id'])) {
$driver_details_response = $this->advantagepay->viewCustomer($direct_debit_customer_details['advantage_pay_customer_id'], $advantage_pay_token['access_token']);
$driver_details_response_array = json_decode($driver_details_response, true);
//echo '<pre>';print_r($driver_details_response_array);die;
if (isset($driver_details_response_array['Code']) || !empty($driver_details_response_array['Code'])) {
$this->db->update(
'direct_debit_customers',
array(
'advantage_pay_customer_response' => $driver_details_response,
'updated_by' => $this->admin_session_data['user_id'],
'updated_ts' => date('Y-m-d H:i:s')
),
array('direct_debit_customer_id' => $direct_debit_customer_details['direct_debit_customer_id'])
);
$return_data = array('status' => true, 'advantage_pay_customer_id' => $driver_details_response_array['Code'], 'driver_details' => $driver_details_response_array);
}
$driver_details = $this->mrentout->get_direct_debit_customer_details($driver_id, $car_details['company_id']);
} else {
$driver_details_response = $this->advantagepay->viewCustomer('', $advantage_pay_token['access_token'], array('email' => $driver_details['email']));
$driver_details_response_arr = json_decode($driver_details_response, true);
$driver_details_response_array = $driver_details_response_arr['Records'][0];
//echo '<pre>';print_r($driver_details_response_array);die;
if (isset($driver_details_response_array['Code']) || !empty($driver_details_response_array['Code'])) {
$this->db->insert(
'direct_debit_customers',
array(
'driver_id' => $driver_id,
'company_id' => $car_details['company_id'],
'advantage_pay_customer_id' => $driver_details_response_array['Code'],
'advantage_pay_customer_response' => $driver_details_response,
'created_by' => $this->admin_session_data['user_id'],
'created_ts ' => date('Y-m-d H:i:s')
)
);
$driver_details = $this->mrentout->get_direct_debit_customer_details($driver_id, $car_details['company_id']);
} else {
$driver_details = $this->mrentout->get_driver_details($driver_id);
}
}
$actual_bond_amount = $this->mrentout->getdriverbondamount($driver_id);
$return_data = array('status' => true, 'driver_details' => $driver_details, 'actual_bond_amount' => $actual_bond_amount);
echo json_encode($return_data);
die;
} catch (Exception $e) {
$return_data = array('status' => false, 'msg' => $e->getMessage());
echo json_encode($return_data);
die;
}
}
public function get_car_details()
{
$car_id = $this->input->post('car_id');
$car_details = $this->mrentout->get_car_details($car_id);
$return_data = array('status' => true, 'car_details' => $car_details);
echo json_encode($return_data);
die;
}
public function generatePdf($rent_out_id)
{
$this->load->library('pdf');
$data['rentoutDetails'] = $this->mrentout->getRentoutDetailsForPDF($rent_out_id);
$data['state_details'] = $this->mrentout->getZipCodeWise($data['rentoutDetails']['pin']);
$filename = 'rental-' . time();
$html = $this->load->view('admin/rent_out/rentalPdf', $data, true);
// $this->pdf->create($html, $filename);
// echo $html;die;
$this->pdf->loadHtml($html);
$this->pdf->set_paper("a4", "landscape");
$this->pdf->render();
$this->pdf->stream("" . $filename . ".pdf", array("Attachment" => 0));
}
public function send_email_authorization()
{
$rent_out_id = $this->input->post('rent_out_id');
$rent_out_details = $this->mrentout->getRentoutDetails($rent_out_id);
$direct_debit_response = json_decode($rent_out_details['direct_debit_response'], true);
$mail['name'] = $rent_out_details['first_name'] . ' ' . $rent_out_details['middle_name'] . ' ' . $rent_out_details['last_name'];
$mail['email'] = $rent_out_details['email'];
$mail['subject'] = 'Quantum Direct Debit Authorization';
$link = $direct_debit_response['AuthorisationLink']['Link'];
$mail_temp = file_get_contents('./global/mail/directdebitauth.html');
$mail_temp = str_replace("{web_url}", base_url(), $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)) {
$response = array('status' => true, 'message' => 'Direct debit authorization mail has been sent successfully');
} else {
$response = array('status' => false, 'message' => 'Uanble to send recovery mail.');
}
echo json_encode($response);
die;
}
}