<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Transfer_money extends CI_Controller{ 	 

	function __construct(){ 
		parent::__construct();
		$this->load->helper('userlogin');
		checkIfUserLoggedIn($this->session->userdata($this->config->item('sess_prefix').'sess_user_id'));
		$this->data['user_details']=$this->User_mdl->user_details($this->session->userdata($this->config->item('sess_prefix').'sess_user_id'));
		$this->data['user_accounts_listing']=$this->User_mdl->user_accounts_listing($this->data['user_details']->user_id);
 		$this->data['title']='Transfer Money';
 	}
	
	public function index(){
		$this->data['page_name']='Transfer Money';
		$this->data['transfer_history_listing']=$this->User_mdl->transfer_history_listing($this->session->userdata($this->config->item('sess_prefix').'sess_user_id'));
		$this->data['vectra_history_listing']=$this->User_mdl->vectra_history_listing($this->session->userdata($this->config->item('sess_prefix').'sess_user_id'));
		$this->data['active_class']='transfer_money';
		$this->load->view('Frontend/includes/header',$this->data);
		$this->load->view('Frontend/transfer_money/send',$this->data);
		$this->load->view('Frontend/includes/footer',$this->data);
	}
	
	
	public function inter_wire(){
		$this->data['page_name']='International Wire Transfer';
		$this->data['active_class']='inter_wire';
		$this->load->view('Frontend/includes/header',$this->data);
		$this->load->view('Frontend/transfer_money/inter_wire',$this->data);
		$this->load->view('Frontend/includes/footer',$this->data);
	}
	
	public function transfer_details(){
		$this->data['page_name']='Transfer Money';
		$this->data['active_class']='transfer_money';
		$this->load->view('Frontend/includes/header',$this->data);
		$this->load->view('Frontend/transfer_money/send',$this->data);
		$this->load->view('Frontend/includes/footer',$this->data);
	}
	
	public function history(){	
		$this->data['page_name']='All History';
		$this->data['active_class']='transfer_history';
		$this->data['transfer_history_listing']=$this->User_mdl->transfer_history_listing($this->session->userdata($this->config->item('sess_prefix').'sess_user_id'));
		$this->load->view('Frontend/includes/header',$this->data);
		$this->load->view('Frontend/transfer_money/history',$this->data);
		$this->load->view('Frontend/includes/footer',$this->data);
	}
	
	public function details(){
		$txn_id = $this->uri->segment(3);
		if(isset($txn_id) && $txn_id!=''){
			$this->data['page_name']='Transaction Details';
			$this->data['active_class']='transfer_history';
			$this->data['transaction_details']=$this->User_mdl->transaction_details($txn_id);
			$this->load->view('Frontend/includes/header',$this->data);
			$this->load->view('Frontend/transfer_money/details',$this->data);
			$this->load->view('Frontend/includes/footer',$this->data);
		}else{
			redirect(base_url().'transfer_money/history');
		}
	}
	
	public function change_acct_det(){
		$account_id = $_GET['account_id'];
		$acct_det=$this->User_mdl->change_acct_det($account_id);
		echo $acct_det->account_no.'||'.$acct_det->available_balance.'||'.$this->config->item('amt_currencies_array_config')[$acct_det->account_cur]['name'].'||'.$this->config->item('amt_currencies_array_config')[$acct_det->account_cur]['csign'].'||'.$this->config->item('bank_account_types_array_config')[$acct_det->account_category]['name'];
		//$this->load->view('Frontend/transfer_money/ajax_change_acct_det',$this->data_ajax);
	}
	
	public function generateRandomString($length = 10) {
		$characters = '123456789ABCDEFGHIJKLMNPQRSTUVWXYZ';
		$charactersLength = strlen($characters);
		$randomString = '';
		for ($i = 0; $i < $length; $i++) {
			$randomString .= $characters[rand(0, $charactersLength - 1)];
		}
		return $randomString;
	}
	
	public function save_entry(){
		$txn_id = $this->generateRandomString();
		//$vat_code_one = $this->generateRandomString(2);
		//$vat_code_two = $this->generateRandomString(3);
		$this->User_mdl->transfer_money_entry($this->session->userdata($this->config->item('sess_prefix').'sess_user_id'),$txn_id);
	}
	
}