<?php
class Import_Model extends CI_Model
{

	private $tableName = array(
		'MASTER_MENU'			=> 'acc_menu_master',
		'MASTER_MODULE'			=> 'acc_menu_module',
		'MASTER_ROLES'			=> 'acc_user_roles',
		'MASTER_USER'			=> 'acc_users',
		'MASTER_STATES'			=> 'acc_state_master',
		'MASTER_PAGINATION'		=> 'comp_pagination_master',
		'MASTER_BRANCH'			=> 'comp_branch',
		'MASTER_COUNTRY'		=> 'comp_country_master',
		'MASTER_VISA_TYPE'		=> 'comp_visa_type_master',
		'MASTER_UPLOAD_LOG'		=> 'comp_import_master',
		'MASTER_COLLEGE'		=> 'comp_college_master',
		'MASTER_COURSE'			=> 'comp_course_master',
		'MASTER_FEE_TYPE'		=> 'comp_fee_type_master',
		'MASTER_FEE_STRUCTURE'	=> 'comp_fee_structure_master',
		'MASTER_TAX_TYPE'		=> 'comp_tax_type_master',
		'MASTER_TAX'			=> 'comp_tax_master',
		'MASTER_PAYMENT_MODE'	=> 'comp_payment_mode_master',
		'MASTER_QUALIFICATION'	=> 'comp_qualification_master',
		'MASTER_RELATION'		=> 'comp_relation_master',
		'MASTER_DOCUMENT_TYPE'	=> 'comp_document_type_master',
		'MASTER_FILE_STATUS'	=> 'comp_file_status_master',
		'MASTER_FILE_STATUS_GROUP'	=> 'comp_file_status_group_master',
		'MASTER_REFERENCE_TYPE'	=> 'comp_reference_type_master',
		'MASTER_FORM'			=> 'comp_from_master',
		'MASTER_FEE_STRUCTURE_ITEMS' => 'comp_fee_structure_items',
		'MASTER_PROCESS_CHECKLIST' => 'comp_process_checklist_master',
		'MASTER_AFTER_VISA_CHECKLIST' => 'comp_after_visa_checklist_master',
		'MASTER_CASES' => 'case_master',
		'MASTER_CLIENT' => 'comp_client_master',
		'MASTER_MARITAL_STATUS' => 'comp_marital_status',
		'MASTER_BANK' => 'comp_bank',
		'MASTER_CLIENT_TYPE' => 'comp_client_type_master',
		'MASTER_INVOICE_TYPE' => 'comp_invoice_type',
		'MASTER_CURRENCY' => 'comp_currency_master',
		'MASTER_OTHER_CHARGES' => 'comp_other_charges',
		'MASTER_LEAD_TYPE' => 'comp_lead_type',
		'MASTER_LEAD_CATEGORY' => 'comp_lead_category',
		'MASTER_LEAD_STATUS' => 'comp_lead_status',
		'MASTER_LEAD_SOURCE' => 'comp_lead_source',
		'MASTER_LEAD' => 'comp_lead_master'
	);

	function __construct()
	{
		parent::__construct();
	}

	public function addNewData($data, $queryArray = array())
	{
		// fx::pr($data);
		if (count($queryArray) > 0) {
			$this->db->where($queryArray);
			$this->db->update($this->tableName['MASTER_UPLOAD_LOG'], $data);
			return $this->db->affected_rows();
		}
		$this->db->insert($this->tableName['MASTER_UPLOAD_LOG'], $data);
		return $this->db->insert_id();
	}

	public function getData($id)
	{
		$this->db->where("log_id", $id);
		return $this->db->get($this->tableName['MASTER_UPLOAD_LOG'])->row();
	}

	public function checkDedupeInMaster($where, $masterName)
	{
		$this->db->where($where, NULL, false);
		$this->db->limit(1);
		return $this->db->get($masterName)->result_array();
	}

	public function insertMultipleMaster($data, $masterName)
	{
		return $this->db->insert_batch($masterName, $data);
	}

	public function insertSingleMaster($data, $masterName)
{
    $this->db->insert($masterName, $data);
    return $this->db->insert_id();
}

	public function getAllStateList()
	{
		return $this->db->get($this->tableName['MASTER_STATES'])->result_array();
	}

	public function getVisaTypeList()
	{
		return $this->db->get($this->tableName['MASTER_VISA_TYPE'])->result_array();
	}

	public function getAllDocumentTypeList()
	{
		return $this->db->get($this->tableName['MASTER_DOCUMENT_TYPE'])->result_array();
	}

	public function getAllClientVendorList()
	{
		return $this->db->get($this->tableName['MASTER_CLIENT_TYPE'])->result_array();
	}

	public function getAllClientList()
	{
		return $this->db->get($this->tableName['MASTER_CLIENT'])->result_array();
	}

	public function getBranchList()
	{
		return $this->db->get($this->tableName['MASTER_BRANCH'])->result_array();
	}

	public function getAllMaritalStatusList()
	{
		return $this->db->get($this->tableName['MASTER_MARITAL_STATUS'])->result_array();
	}

	public function getAllCountryList()
	{
		return $this->db->get($this->tableName['MASTER_COUNTRY'])->result_array();
	}

	public function getAllFileStatusList()
	{
		return $this->db->get($this->tableName['MASTER_FILE_STATUS'])->result_array();
	}

	public function getLeadCategoryList()
	{
		return $this->db->get($this->tableName['MASTER_LEAD_CATEGORY'])->result_array();
	}

	public function getLeadTypeList()
	{
		return $this->db->get($this->tableName['MASTER_LEAD_TYPE'])->result_array();
	}

	public function getLeadSourceList()
	{
		return $this->db->get($this->tableName['MASTER_LEAD_SOURCE'])->result_array();
	}

	public function getLeadStatusList()
	{
		return $this->db->get($this->tableName['MASTER_LEAD_STATUS'])->result_array();
	}

	public function getUsersList()
	{
		$this->db->select("concat_ws(' ', user_first_name, user_last_name) as name, user_id as id");
		$this->db->from($this->tableName['MASTER_USER']);
		return $this->db->get()->result_array();
	}

	public function getAllCollegeList()
	{
		return $this->db->get($this->tableName['MASTER_COLLEGE'])->result_array();
	}

	public function getAllRoleList()
	{
		return $this->db->get($this->tableName['MASTER_ROLES'])->result_array();
	}

	public function getAllTaxTypeList()
	{
		return $this->db->get($this->tableName['MASTER_TAX_TYPE'])->result_array();
	}

	public function getAllStatusGroupList()
	{
		return $this->db->get($this->tableName['MASTER_FILE_STATUS_GROUP'])->result_array();
	}

	public function getAllFeeTypeList()
	{
		return $this->db->get($this->tableName['MASTER_FEE_TYPE'])->result_array();
	}
}
