HEX
Server: Apache/2.4.41 (Amazon) OpenSSL/1.0.2k-fips PHP/5.6.40
System: Linux ip-172-31-40-18 4.14.146-93.123.amzn1.x86_64 #1 SMP Tue Sep 24 00:45:23 UTC 2019 x86_64
User: apache (48)
PHP: 5.6.40
Disabled: NONE
Upload Files
File: //var/www/html/qcr24/app/application/controllers/admin/BondRefund.php
<?php
defined('BASEPATH') or exit('No direct script access allowed');

class BondRefund extends MY_Controller
{

	public function __construct()
	{
		parent::__construct();
		$this->load->model('admin/mbondRefund');
	}
	/**
	 * 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['bondRefundDetails'] = $this->mbondRefund->getbondrefundDetails();
		$data['content'] = 'admin/bond_refund/list';
		$this->load->view('admin/layouts/index', $data);
	}

	public function add()
	{
		$data['drivers'] = $this->mbondRefund->get_rentout_driver();
		$data['content'] = 'admin/bond_refund/add';
		$this->load->view('admin/layouts/index', $data);
	}

	public function getdriverbondamount()
	{
		$driver_id=$this->input->post('driver_id');
		$actual_bond_amount= $this->mbondRefund->getdriverbondamount($driver_id);
		
		echo json_encode(array('status'=>true,'actual_bond_amount'=>$actual_bond_amount));
	}

	public function editbondrefund($bond_refund_id)
	{
		// $data['drivers'] = $this->mbondRefund->get_rentout_driver();
		$data['drivers'] = $this->mbondRefund->get_rentout_driver();
		$data['bondRefundDetails'] = $this->mbondRefund->getbondrefundDetails($bond_refund_id);
		$data['content'] = 'admin/bond_refund/edit';
		$this->load->view('admin/layouts/index', $data);
	}

	public function submitbondrefund()
	{
		$data = array(
			'driver_id' => $this->input->post('driver_id'),
			'total_bond_amount' => $this->input->post('total_bond_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' => 'BONDREFUND',
			'remarks' => $this->input->post('remarks'),
			'created_by' => $this->admin_session_data['user_id'],
			'created_ts' => date('Y-m-d H:i:s')
		);												

		$result = $this->mbondRefund->submit_bondrefund($data);

		$bond_data = array(
			'driver_id' => $this->input->post('driver_id'),
			'bond_amount' => $this->input->post('amount_want_to_refund'),
			'transaction_type' => 'DEBIT',
			'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' => 'BONDREFUND',
			'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);

		if ($result) {

			//************************************************************************************//	
			//************************This Part is for Activity Log*******************************//

			$activityLogData = array(
				'activity_type' => '<b>Add Bond Refund</b>',
				'description' => 'New Bond Added with amount - '.$this->input->post('total_bond_amount'),
				'link' => 'admin/bondRefund',
				'icon' => '<i class="fa fa-history" aria-hidden="true"></i>',
			);

			$this->activity_log($activityLogData);

			//************************This Part is for Activity Log*******************************//
			//************************************************************************************//
			
			$this->session->set_flashdata('success_msg', 'Bond Refund Added Successfully');
			redirect("admin/bondRefund");
		}
	}

	public function updatebondrefund(){
		//echo '<pre>'; print_r($this->input->post());die;

		if(empty($this->input->post('hid_bond_refund_id'))){
			$this->session->set_flashdata('error_msg', 'Bond Refund ID is required');
			redirect("admin/bondRefund");
		}
		$data = array(
			'remarks' => $this->input->post('remarks'),
			'updated_by' => $this->admin_session_data['user_id'],
			'updated_ts' => date('Y-m-d H:i:s')
		);												

		$result = $this->db->update('bond_refund',$data,array('bond_refund_id'=>$this->input->post('hid_bond_refund_id')));

		if ($result) {

			//************************************************************************************//	
			//************************This Part is for Activity Log*******************************//

			$activityLogData = array(
				'activity_type' => '<b>Update Bond Refund</b>',
				'description' => 'Bond Refund Updated with remarks',
				'link' => 'admin/bondRefund',
				'icon' => '<i class="fa fa-history" aria-hidden="true"></i>',
			);

			$this->activity_log($activityLogData);

			//************************This Part is for Activity Log*******************************//
			//************************************************************************************//
			
			$this->session->set_flashdata('success_msg', 'Bond Refund updated Successfully');
			redirect("admin/bondRefund");
		}

	}

	public function bondSettled()
	{
		$bond_refund_id = $this->input->post('bond_refund_id');
		$data = array(
			'is_settele' => 1,
			'settle_date' => date('Y-m-d H:i:s'),
			'updated_by' => $this->admin_session_data['user_id'],
			'updated_ts' => date('Y-m-d H:i:s')
		);	
		
		$condition = array('bond_refund_id' => $bond_refund_id);
		$result = $this->mbondRefund->update_bondSettled($condition, $data);

		if($result){
			echo json_encode(array('status'=>true,'msg'=>'Bond Settled Successfully'));
		}else{
			echo json_encode(array('status'=>false,'msg'=>'Opps!. Some thing went wrong'));
		}

		
	}
}