<?php
defined('BASEPATH') or exit('No direct script access allowed');

class Member_model extends CI_Model
{

	//caste caste
	public function get_caste()
	{
		return $this->db->select("*")->order_by("caste", "ASC")->get('caste')->result_array();
	}
	//insert value
	public function add_caste($data)
	{
		$res = $this->db->select("*")->where("caste", $data['caste'])->get("caste")->result_array();
		if (count($res) > 0) {
			return "ex";
		}
		$this->db->insert('caste', $data);
		$insert_id = $this->db->insert_id();
		return  $insert_id;
	}
	public function insert_cash_book($data)
	{
		$this->db->insert('cash_book', $data);
		$insert_id = $this->db->insert_id();
		return  $insert_id;
	}

	public function cb_loan_amount()
	{
		$this->db->select('*');
		$result = $this->db->get('loan')->result_array();
		return $result;
	}
	public function cb_thrift_amount()
	{
		$this->db->select('*');
		$result = $this->db->get('thrift')->result_array();
		return $result;
	}
	public function cb_share_amount()
	{
		$this->db->select('*');
		$result = $this->db->get('share')->result_array();
		return $result;
	}

	//delete caste
	public function delete_caste($id)
	{
		$this->db->where('id', $id);
		$this->db->delete('caste');
	}
	// edit by id 
	public function display_caste($id)
	{
		return $this->db->where('id', $id)->get('caste')->row();
	}
	//update value
	public function  update_caste($requestData)
	{
		return $this->db->where('id', $requestData['id'])->update('caste', $requestData);
	}
	// division model for the society r693


	//bank bank
	public function get_bank()
	{
		return $this->db->select("*")->order_by("bank", "ASC")->get('bank')->result_array();
	}
	//insert value
	public function add_bank($data)
	{
		$res = $this->db->select("*")->where("bank", $data['bank'])->get("bank")->result_array();
		if (count($res) > 0) {
			return "ex";
		}
		$this->db->insert('bank', $data);
		$insert_id = $this->db->insert_id();
		return  $insert_id;
	}

	//delete bank
	public function delete_bank($id)
	{
		$this->db->where('id', $id);
		$this->db->delete('bank');
	}
	// edit by id 
	public function display_bank($id)
	{
		return $this->db->where('id', $id)->get('bank')->row();
	}
	//update value
	public function  update_bank($requestData)
	{
		return $this->db->where('id', $requestData['id'])->update('bank', $requestData);
	}


	//insert value
	public function add_division($data)
	{
		$result = $this->db->select("*")->where("division", $data['division'])->get("division")->result_array();
		if (count($result) > 0) {
			return 1;
		} else {
			$this->db->insert('division', $data);
			return 0;
		}
	}

	//get value
	public function get_division()
	{
		return $this->db->get('division')->result_array();
	}

	public function get_division_mail_id()
	{
		return $this->db->select("division_mail")->get('division')->result_array();
	}

	// delete value
	public function delete_division($id)
	{
		$this->db->where('id', $id);
		$this->db->delete('division');
	}
	// edit by id 
	public function display_division($id)
	{
		return $this->db->where('id', $id)
			->get('division')->row();
	}
	//update value
	public function  update_division($requestData)
	{
		return $this->db->where('id', $requestData['id'])
			->update('division', $requestData);
	}
	// section 

	//insert value
	public function add_section($data)
	{
		$res = $this->db->select("*")->where("section", $data['section'])->get("section")->result_array();
		if (count($res) > 0) {
			return "ex";
		}
		$this->db->insert('section', array("section" => $data['section']));
		$insert_id = $this->db->insert_id();
		return  $insert_id;
	}
	//get value
	public function get_section()
	{
		return $this->db->get('section')->result_array();
	}


	// delete value
	public function delete_section($id)
	{
		$this->db->where('id', $id);
		$this->db->delete('section');
	}

	public function get_exist_section($section)
	{
		$this->db->select('*');

		$this->db->where('section', $section);
		// 		$this->db->where('is_deleted', '0');
		$result = $this->db->get('section')->result_array();
		return $result;
	}
	//search section
	public function getsection($inps)
	{
		$this->db->select('s.*');
		$this->db->join('mapdivisionsection m', 'm.section_id=s.id');
		$this->db->join('division d', 'd.id=m.division_id');
		if (isset($inps['division']) && $inps['division'] != "") {
			$this->db->where('d.division', $inps['division']);
		}
		$this->db->order_by('s.section asc');
		$result = $this->db->get('section s')->result_array();
		return $result;
	}

	public function loan_search($inps)
	{
		$this->db->select('loan_os_amt');
		$this->db->where('me_no', $inps['me_no']);
		$result = $this->db->get('loan')->row();
		return $result;
	}
	public function get_loan_os($inps)
	{
		$this->db->select('loan_os_amt');
		$this->db->where('me_no', $inps);
		$result = $this->db->get('loan')->row();
		return $result;
	}
	// edit by id 
	public function display_section($id)
	{
		return $this->db->where('id', $id)
			->get('section')->row();
	}
	//update value
	public function  update_section($requestData)
	{
		return $this->db->where('id', $requestData['id'])
			->update('section', $requestData);
	}
	// designation 

	//insert value
	public function add_designation($data)
	{
		$res = $this->db->select("*")->where("designation", $data['designation'])->get("designation")->result_array();
		if (count($res) > 0) {
			return "ex";
		}
		$this->db->insert('designation', $data);
		$insert_id = $this->db->insert_id();
		return  $insert_id;
	}
	//get value
	public function get_design()
	{
		return $this->db->select("*")->order_by('designation asc')->get('designation')->result_array();
	}

	// delete value
	public function delete_designation($id)
	{
		$this->db->where('id', $id);
		$this->db->delete('designation');
	}
	// edit by id 
	public function display_designation($id)
	{
		return $this->db->where('id', $id)
			->get('designation')->row();
	}
	//update value
	public function  update_designation($requestData)
	{
		return $this->db->where('id', $requestData['id'])
			->update('designation', $requestData);
	}

	public function get_cheque_details()
	{
		return $this->db->select("*")->order_by('id asc')->get('cheque_details')->result_array();
	}

	public function add_cheque($data)
	{
		$res = $this->db->select("*")->where("cheque_no", $data['cheque_no'])->get("cheque_details")->result_array();
		if (count($res) > 0) {
			return "ex";
		}
		$this->db->insert('cheque_details', $data);
		$insert_id = $this->db->insert_id();
		return  $insert_id;
	}

	public function  update_cheque($requestData)
	{
		return $this->db->where('id', $requestData['id'])
			->update('cheque_details', $requestData);
	}

	public function delete_cheque($id)
	{
		$this->db->where('id', $id);
		$this->db->delete('cheque_details');
	}
	// edit by id 
	public function display_cheque($id)
	{
		return $this->db->where('id', $id)
			->get('cheque_details')->row();
	}
	public function get_cheque($date)
	{
		return $this->db->where('cheque_date', $date)
			->get('cheque_details')->result_array();
	}
	public function get_cheque_by_chequeno($cheque_no)
	{
		return $this->db->where_in('cheque_no', $cheque_no)
			->get('cheque_details')->result_array();
	}
	// relationship model for the society r693

	//insert value
	public function add_relationship($data)
	{
		$res = $this->db->select("*")->where("relationship", $data['n_relation'])->get("relationship")->result_array();
		if (count($res) > 0) {
			return "ex";
		}
		$this->db->insert('relationship', array("relationship" => $data['n_relation']));
		$insert_id = $this->db->insert_id();
		return  $insert_id;
	}
	// delete value
	public function delete_relationship($id)
	{
		$this->db->where('id', $id);
		$this->db->delete('relationship');
	}
	// edit by id 
	public function display_relationship($id)
	{
		return $this->db->where('id', $id)
			->get('relationship')->row();
	}
	//update value
	public function  update_relationship($requestData)
	{

		return $this->db->where('id', $requestData['id'])
			->update('relationship', array("relationship" => $requestData['n_relation']));
	}

	public function get_password()
	{
		return $this->db->get('users')->result_array();
	}
	public function display_password($id)
	{
		return $this->db->where('id', $id)
			->get('users')->row();
	}
	//update value
	public function  update_password($requestData)
	{
		return $this->db->where('id', $requestData['id'])
			->update('users', $requestData);
	}

	//get member number
	public function get_member($me_no)
	{
		$this->db->select('*');
		$this->db->where('me_no', $me_no);
		// $this->db->where('is_deleted', '0');
		$this->db->order_by('me_no', 'asc');
		$result = $this->db->get('member')->result_array();
		return $result[0];
	}
	public function get_ledger_member($me_no)
	{
		$this->db->select('*');
		$this->db->where('me_no', $me_no);
		$result = $this->db->get('member')->result_array();
		return $result[0];
	}
	public function get_members()
	{
		return $this->db->get('member')->result_array();
	}
	public function get_default()
	{
		return $this->db->get('common')->result_array();
	}
	public function get_common()
	{
		$this->db->select('*');
		$this->db->order_by('id asc');
		$this->db->limit('1');
		$result =  $this->db->get('common')->result_array();
		return $result;
	}
	function filename_exists($me_no)
	{
		$this->db->select('*');
		$this->db->from('member');
		$this->db->where('me_no', $me_no);
		$query = $this->db->get();
		$result = $query->result_array();
		return $result;
	}
	//get mobile number
	public function get_mobile($mem_mob)
	{
		$this->db->select('*');
		$this->db->where('mem_mob', $mem_mob);
		$this->db->where('is_deleted', '0');
		$result = $this->db->get('member')->result_array();
		return $result[0];
	}
	//get relationship
	public function get_relationship()
	{
		return $this->db->select("*")->order_by('relationship asc')->get('relationship')->result_array();
	}
	//get division
	public function division()
	{
		$this->db->select('*');
		$this->db->order_by('division asc');
		$result =  $this->db->get('division')->result_array();
		return $result;
	}
	//get member
	public function members()
	{
		$this->db->select('*');
		$result =   $this->db->order_by('me_no asc')->where('is_deleted', '0')->get('member')->result_array();
		return $result;
	}
	//get section
	public function section()
	{
		$this->db->select('*');
		$this->db->order_by('section asc');
		$result =  $this->db->get('section')->result_array();
		return $result;
	}
	//add value
	public function add($data)
	{
		$this->db->trans_start();
		$this->db->insert('member', $data);

		$insert_id = $this->db->insert_id();

		$this->db->trans_complete();

		return $insert_id;
	}
	//add thrift
	public function add_default_thrift($me_no = '', $thrift = '')
	{
		if ($thrift == "") {
			$this->db->select('*');
			$this->db->order_by('id asc');
			$this->db->limit('1');
			$result =  $this->db->get('common')->result_array();
			$thrift = $result[0]['default_thrift'];
		}
		$data = array("me_no" => $me_no, "thrift_amt" => $thrift, "added_on" => date("Y-m-d H:i:s"), "added_by" => $_SESSION['name']);
		$this->db->trans_start();
		$this->db->insert('thrift', $data);

		$insert_id = $this->db->insert_id();

		$this->db->trans_complete();

		return $insert_id;
	}
	public function add_default_books($me_no = '', $books = '')
	{
		if ($books == "") {
			$this->db->select('*');
			$this->db->order_by('id asc');
			$this->db->limit('1');
			$result =  $this->db->get('common')->result_array();
			$books = $result[0]['default_books'];
		}
		$data = array("me_no" => $me_no, "books_amt" => $books, "added_on" => date("Y-m-d H:i:s"), "added_by" => $_SESSION['name']);
		$this->db->trans_start();
		$this->db->insert('books_forms', $data);

		$insert_id = $this->db->insert_id();

		$this->db->trans_complete();

		return $insert_id;
	}
	//add share
	public function add_default_ent_fees($me_no = '', $ent_fees = '')
	{
		if ($ent_fees == "") {
			$this->db->select('*');
			$this->db->order_by('id asc');
			$this->db->limit('1');
			$result =  $this->db->get('common')->result_array();
			$ent_fees = $result[0]['ent_fees'];
		}
		$data = array("me_no" => $me_no, "ent_fees" => $ent_fees, "added_on" => date("Y-m-d H:i:s"), "added_by" => $_SESSION['name']);
		$this->db->trans_start();
		$this->db->insert('ent_fees', $data);

		$insert_id = $this->db->insert_id();

		$this->db->trans_complete();

		return $insert_id;
	}
	public function add_default_others($me_no = '', $others = '')
	{
		// print_r($others);die;

		if ($others == "") {
			$this->db->select('*');
			$this->db->order_by('id asc');
			$this->db->limit('1');
			$result =  $this->db->get('common')->result_array();
			$d_others = $result[0]['d_others'];
		}
		$data = array("me_no" => $me_no, "others_amt" => $others, "added_on" => date("Y-m-d H:i:s"), "added_by" => $_SESSION['name']);
		$this->db->trans_start();
		$this->db->insert('others', $data);

		$insert_id = $this->db->insert_id();

		$this->db->trans_complete();

		return $insert_id;
	}
	//add share
	public function add_default_share($me_no = '', $share = '')
	{
		if ($share == "") {
			$this->db->select('*');
			$this->db->order_by('id asc');
			$this->db->limit('1');
			$result =  $this->db->get('common')->result_array();
			$share = $result[0]['default_share'];
		}
		$data = array("me_no" => $me_no, "share_amt" => $share, "tot_share" => $share, "added_on" => date("Y-m-d H:i:s"), "added_by" => $_SESSION['name']);
		$this->db->trans_start();
		$this->db->insert('share', $data);

		$insert_id = $this->db->insert_id();

		$this->db->trans_complete();

		return $insert_id;
	}
	//add insurence
	public function add_default_insurance($me_no = '', $ins = '')
	{
		if ($ins == "") {
			$this->db->select('*');
			$this->db->order_by('id asc');
			$this->db->limit('1');
			$result =  $this->db->get('common')->result_array();
			$ins = $result[0]['default_insurance'];
		}
		$data = array("me_no" => $me_no, "insurance" => $ins, "tot_insurance" => $ins, "added_on" => date("Y-m-d H:i:s"), "added_by" => $_SESSION['name']);
		$this->db->trans_start();
		$this->db->insert('insurance', $data);

		$insert_id = $this->db->insert_id();

		$this->db->trans_complete();

		return $insert_id;
	}
	public function insert_others($ins_others)
	{
		$this->db->where('me_no', $ins_others['me_no']);
		$this->db->update('others', $ins_others);
		return true;
	}
	//check deactive member
	public function deactive_members()
	{
		$this->db->select('*');
		$result =   $this->db->where('is_deleted', '1')->get('member')->result_array();
		return $result;
	}
	//check closed member
	public function closed_members()
	{
		$this->db->select('*');
		$result =   $this->db->where('is_deleted', '2')->get('member')->result_array();
		return $result;
	}
	public function close_members($inps)
	{
		$this->db->select('*');
		$result =   $this->db->where('is_deleted', '2')->where('close_month', $inps['month'])->where('close_year', $inps['year'])->get('member')->result_array();
		return $result;
	}
	//update member
	public function update($data)
	{
		$this->db->where('me_no', $data['me_no']);
		$this->db->update('member', $data);
		return true;
	}
	//members search
	public function member_search($inps)
	{
		$this->db->select('*');
		if (isset($inps['division']) && $inps['division'] != "") {
			$this->db->where('division', $inps['division']);
		}
		if (isset($inps['section']) && $inps['section'] != "") {
			$this->db->where('section', $inps['section']);
		}
		$this->db->where('is_deleted', '0');
		$result = $this->db->get('member')->result_array();
		return $result;
	}
	public function member_search_deactive($inps)
	{
		$this->db->select('*');
		if (isset($inps['division']) && $inps['division'] != "") {
			$this->db->where('division', $inps['division']);
		}
		if (isset($inps['section']) && $inps['section'] != "") {
			$this->db->where('section', $inps['section']);
		}
		$this->db->where('is_deleted', '1');
		$result = $this->db->get('member')->result_array();
		return $result;
	}

	public function member_search_close($inps)
	{
		$this->db->select('*');
		if (isset($inps['division']) && $inps['division'] != "") {
			$this->db->where('division', $inps['division']);
		}
		if (isset($inps['section']) && $inps['section'] != "") {
			$this->db->where('section', $inps['section']);
		}
		$this->db->where('is_deleted', '2');
		$result = $this->db->get('member')->result_array();
		return $result;
	}
	public function get_division_section($data)
	{
		$this->db->where('me_no', $data['me_no']);
		$this->db->get('member', $data);
		return true;
	}
	//-----------------------------------------------------------------------------//
	//---------------------------------Thrift Details------------------------------//
	//-----------------------------------------------------------------------------//

	public function get_thrift_all()
	{
		$this->db->select('*');
		$result =   $this->db->select("t.*,m.mem_name,m.division,m.section")->join("member m", "m.me_no=t.me_no")->where('t.is_deleted', '0')->get('thrift t')->result();
		return $result;
	}
	public function get_due_all()
	{
		$this->db->select('*');
		$result =   $this->db->select("o.*,m.mem_name,m.division,m.section")->join("member m", "m.me_no=o.me_no")->get('old_dues o')->result();
		return $result;
	}
	public function get_particular($me_no)
	{
		$this->db->select('*');
		$this->db->from('member');
		$this->db->join('thrift', 'thrift.me_no = member.me_no');
		$this->db->where('thrift.me_no', $me_no);
		$query = $this->db->get();
		return $query->result_array();
	}
	public function get_particular_dueby($me_no)
	{
		$this->db->select('*');
		$this->db->from('member');
		$this->db->join('old_dues', 'old_dues.me_no = member.me_no');
		$this->db->where('old_dues.me_no', $me_no);
		$query = $this->db->get();
		return $query->result_array();
	}
	public function get_pa_demand($me_no)
	{
		$this->db->select('*');
		$this->db->from('member');
		$this->db->join('payment', 'payment.me_no = member.me_no');
		$this->db->where('payment.is_deleted', '0');
		$this->db->where('payment.me_no', $me_no);
		$query = $this->db->get();
		return $query->result_array();
	}
	public function get_thrift($me_no)
	{
		$this->db->select('*');
		$result =   $this->db->select("t.*,m.mem_name,m.division,m.section")->join("member m", "m.me_no=t.me_no")->where('t.me_no', $me_no)->where('t.is_deleted', '0')->get('thrift t')->result_array();
		return $result[0];
	}

	public function update_thrift($data)
	{
		$this->db->where('me_no', $data['me_no']);
		$this->db->update('thrift', $data);
		return true;
	}
	//-----------------------------------------------------------------------------//
	//---------------------------------others Details------------------------------//
	//-----------------------------------------------------------------------------//

	public function get_others_all()
	{
		$this->db->select('*');
		$result =   $this->db->select("t.*,m.mem_name,m.division,m.section")->join("member m", "m.me_no=t.me_no")->where('t.is_deleted', '0')->get('others t')->result();
		return $result;
	}
	public function get_particular_others($me_no)
	{
		$this->db->select('*');
		$this->db->from('member');
		$this->db->join('others', 'others.me_no = member.me_no');
		$this->db->where('others.me_no', $me_no);
		$query = $this->db->get();
		return $query->result_array();
	}
	public function get_pa_demand_others($me_no)
	{
		$this->db->select('*');
		$this->db->from('member');
		$this->db->join('payment', 'payment.me_no = member.me_no');
		$this->db->where('payment.me_no', $me_no);
		$query = $this->db->get();
		return $query->result_array();
	}
	public function get_others($me_no)
	{
		$this->db->select('*');
		$result =   $this->db->select("t.*,m.mem_name,m.division,m.section")->join("member m", "m.me_no=t.me_no")->where('t.me_no', $me_no)->where('t.is_deleted', '0')->get('others t')->result_array();
		return $result[0];
	}

	public function update_others($data)
	{
		$this->db->where('me_no', $data['me_no']);
		$this->db->update('others', $data);
		return true;
	}
	//-----------------------------------------------------------------------------//
	//---------------------------------Share Details------------------------------//
	//-----------------------------------------------------------------------------//

	public function get_share_all()
	{
		$this->db->select('*');
		$result =   $this->db->select("s.*,m.mem_name,m.division,m.section")->join("member m", "m.me_no=s.me_no")->where('s.is_deleted', '0')->get('share s')->result();
		return $result;
	}
	public function get_particular_share($me_no)
	{
		$this->db->select('*');
		$this->db->from('member');
		$this->db->join('share', 'share.me_no = member.me_no');
		$this->db->where('share.me_no', $me_no);
		$query = $this->db->get();
		return $query->result_array();
	}
	public function get_pa_demand_share($me_no)
	{
		$this->db->select('*');
		$this->db->from('member');
		$this->db->join('payment', 'payment.me_no = member.me_no');
		$this->db->where('payment.me_no', $me_no);
		$query = $this->db->get();
		return $query->result_array();
	}
	public function get_share($me_no)
	{
		$this->db->select('*');
		$result =   $this->db->select("s.*,m.mem_name,m.division,m.section")->join("member m", "m.me_no=s.me_no")->where('s.me_no', $me_no)->where('s.is_deleted', '0')->get('share s')->result_array();
		return $result[0];
	}

	public function update_share($data)
	{
		$this->db->where('me_no', $data['me_no']);
		$this->db->update('share', $data);
		return true;
	}
	//-----------------------------------------------------------------------------//
	//---------------------------------Loan Details------------------------------//
	//-----------------------------------------------------------------------------//
	public function total_loan_amount()
	{
		$this->db->select('*');
		$result =   $this->db->get('loan')->result_array();
		return $result;
	}
	public function get_particular_loan($me_no)
	{
		$this->db->select('*');
		$this->db->from('member');
		$this->db->join('loan', 'loan.me_no = member.me_no');
		$this->db->where('loan.me_no', $me_no);
		$query = $this->db->get();
		return $query->result_array();
	}
	public function get_pa_loan($me_no)
	{
		$this->db->select('*');
		$this->db->from('member');
		$this->db->join('loan', 'loan.me_no = member.me_no');
		$this->db->join('payment', 'payment.me_no = member.me_no');
		$this->db->where('loan.me_no', $me_no);
		$this->db->where('payment.p_pay', '0');
		$query = $this->db->get();
		return $query->result_array();
	}
	public function get_par_loan($me_no)
	{
		$this->db->select('*');
		$this->db->from('member');
		$this->db->join('loan', 'loan.me_no = member.me_no');
		$this->db->join('payment', 'payment.me_no = member.me_no');
		$this->db->where('loan.me_no', $me_no);
		$this->db->where('payment.p_pay', '1');
		$query = $this->db->get();
		return $query->result_array();
	}

	public function get_loan_all()
	{
		$this->db->select('*');
		$result =   $this->db->select("s.*,m.mem_name,m.division,m.section,m.close_month,m.close_year")->join("member m", "m.me_no=s.me_no")->where('s.is_deleted', '0')->order_by('m.me_no asc')->get('loan s')->result();
		return $result;
	}

	public function get_old_dues()
	{
		$this->db->select('*');
		$result =   $this->db->select("s.*,m.mem_name,m.division,m.section,m.close_month,m.close_year")->join("member m", "m.me_no=s.me_no")->where('s.is_deleted', '0')->order_by('m.me_no asc')->get('old_dues s')->result();
		return $result;
	}

	public function get_loan($me_no)
	{
		$this->db->select('*');
		$result =   $this->db->select("s.*,m.mem_name,m.division,m.section")->join("member m", "m.me_no=s.me_no")->where('s.me_no', $me_no)->where('s.is_deleted', '0')->get('loan s')->result_array();
		return $result[0];
	}
	public function get_old_due($me_no)
	{
		$this->db->select('*');
		$result =   $this->db->select("s.*,m.mem_name,m.division,m.section")->join("member m", "m.me_no=s.me_no")->where('s.me_no', $me_no)->where('s.is_deleted', '0')->get('old_dues s')->result_array();
		return $result[0];
	}
	
	public function update_loan($data)
	{
		$this->db->where('me_no', $data['me_no']);
		$this->db->update('loan', $data);
		return true;
	}
	public function update_old_due($data)
	{
		$this->db->where('me_no', $data['me_no']);
		$this->db->update('old_dues', $data);
		return true;
	}
	
	public function get_division_address($div)
	{
		$result = $this->db->select("address")->where("division", $div)->get("division")->result_array();
		return $result[0]['address'];
	}

	//-----------------------------------------------------------------------------//
	//---------------------------------Insurence Details------------------------------//
	//-----------------------------------------------------------------------------//
	public function get_insurance_all()
	{
		$this->db->select('*');
		$result = $this->db->select("i.*,m.mem_name,m.division,m.section")->join("member m", "m.me_no=i.me_no")->where('i.is_deleted', '0')->get('insurance i')->result();
		return $result;
	}
	public function get_particular_insu($me_no)
	{
		$this->db->select('*');
		$this->db->from('member');
		$this->db->join('insurance', 'insurance.me_no = member.me_no');
		$this->db->where('insurance.me_no', $me_no);
		$query = $this->db->get();
		return $query->result_array();
	}
	public function get_pa_insu($me_no)
	{
		$this->db->select('*');
		$this->db->from('member');
		$this->db->join('payment', 'payment.me_no = member.me_no');
		$this->db->where('payment.me_no', $me_no);
		$query = $this->db->get();
		return $query->result_array();
	}
	public function get_insurance($me_no)
	{
		$this->db->select('*');
		$result =   $this->db->select("i.*,m.mem_name,m.division,m.section")->join("member m", "m.me_no=i.me_no")->where('i.me_no', $me_no)->where('i.is_deleted', '0')->get('insurance i')->result_array();
		return $result[0];
	}

	public function update_insurance($data)
	{
		$this->db->where('me_no', $data['me_no']);
		$this->db->update('insurance', $data);
		return true;
	}
	//-----------------------------------------------------------------------------//
	//---------------------------------Demand Details------------------------------//
	//-----------------------------------------------------------------------------//
	public function get_demand($me_no)
	{
		$this->db->select('*');
		$this->db->where('me_no', $me_no);
		$this->db->where('is_deleted', '0');
		$result = $this->db->get('demand')->result_array();
		return $result[0];
	}
	public function get_loan1($surety_memno)
	{
		$this->db->select('*');
		$this->db->where('surety_memno', $surety_memno);
		$this->db->where('is_deleted', '0');
		$result = $this->db->get('loan')->result_array();
		return $result[0];
	}
	public function get_thriftamt($me_no)
	{
		$this->db->select('*');
		$this->db->where('me_no', $me_no);
		$result = $this->db->get('thrift')->result_array();
		return $result[0];
	}
	public function get_shareamt($me_no)
	{
		$this->db->select('*');
		$this->db->where('me_no', $me_no);
		$result = $this->db->get('share')->result_array();
		return $result[0];
	}
	public function get_payment($me_no)
	{
		$this->db->select('*');
		$this->db->where('me_no', $me_no);
		$this->db->where('is_deleted', '0');
		$result = $this->db->get('payment')->result_array();
		return $result;
	}
	//Total

	public function totol_member()
	{
		$this->db->select('count(me_no) as me_no');
		$result = $this->db->get('member')->result_array();
		return $result;
	}
	public function totol_active_member()
	{
		$this->db->select('count(me_no) as me_no');
		$this->db->where('is_deleted', '0');
		$result = $this->db->get('member')->result_array();
		return $result;
	}
	public function totol_inactive_member()
	{
		$this->db->select('count(me_no) as me_no');
		$this->db->where('is_deleted', '1');
		$result = $this->db->get('member')->result_array();
		return $result;
	}

	public function totol_thrift_amount()
	{
		$this->db->select('sum(tot_thrift) as tot_thrift');
		$result = $this->db->get('thrift')->result_array();
		return $result;
	}

	public function totol_active_thrift()
	{
		$this->db->select('sum(tot_thrift) as tot_thrift');
		$this->db->from('thrift');
		$this->db->join('member', 'member.me_no = thrift.me_no');
		$this->db->where('member.is_deleted', '0');
		$query = $this->db->get()->result_array();

		return  $query;
	}
	public function totol_inactive_thrift()
	{
		$this->db->select('sum(tot_thrift) as tot_thrift');
		$this->db->from('thrift');
		$this->db->join('member', 'member.me_no = thrift.me_no');
		$this->db->where('member.is_deleted', '1');
		$query = $this->db->get()->result_array();
		return  $query;
	}
	public function totol_share_amount()
	{
		$this->db->select('sum(tot_share) as tot_share');
		$result = $this->db->get('share')->result_array();
		return $result;
	}

	public function totol_active_share()
	{
		$this->db->select('sum(tot_share) as tot_share');
		$this->db->from('share');
		$this->db->join('member', 'member.me_no = share.me_no');
		$this->db->where('member.is_deleted', '0');
		$query = $this->db->get()->result_array();

		return  $query;
	}
	public function totol_inactive_share()
	{
		$this->db->select('sum(tot_share) as tot_share');
		$this->db->from('share');
		$this->db->join('member', 'member.me_no = share.me_no');
		$this->db->where('member.is_deleted', '1');
		$query = $this->db->get()->result_array();
		return  $query;
	}
	public function totol_ins_amount()
	{
		$this->db->select('sum(tot_insurance) as tot_insurance');
		$result = $this->db->get('insurance')->result_array();
		return $result;
	}

	public function totol_active_ins()
	{
		$this->db->select('sum(tot_insurance) as tot_insurance');
		$this->db->from('insurance');
		$this->db->join('member', 'member.me_no = insurance.me_no');
		$this->db->where('member.is_deleted', '0');
		$query = $this->db->get()->result_array();

		return  $query;
	}
	public function totol_inactive_ins()
	{
		$this->db->select('sum(tot_insurance) as tot_insurance');
		$this->db->from('insurance');
		$this->db->join('member', 'member.me_no = insurance.me_no');
		$this->db->where('member.is_deleted', '1');
		$query = $this->db->get()->result_array();
		return  $query;
	}

	public function totol_loan_amount()
	{
		$this->db->select('sum(loan_os_amt) as os_pay');
		$result = $this->db->get('loan')->result_array();
		return $result;
	}

	public function last_demand_amount($inps)
	{
		$this->db->select('sum(d_total) as demand');
		$this->db->where('d_month', $inps['month']);
		$this->db->where('d_year', $inps['year']);
		$result = $this->db->get('demand')->result_array();
		return $result;
	}

	public function last_recovery_amount($inps)
	{
		$this->db->select('payment.payment_month,payment.payment_year,sum(last_principal) as recover_last_principal,sum(ex_os) as recover_ex_os,sum(os_pay) as recover_os_pay,sum(last_int) as recover_last_int,sum(loan_pri_amt) as recover_pri,sum(loan_int_amt) as recover_int,sum(p_int) as recover_p_int,sum(thrift_amt) as recover_thrift,sum(old_thrift) as recover_old_thrift,sum(old_p_int) as recover_old_p_int,sum(old_others) as recover_old_others,sum(insurance) as recover_insurance,sum(others) as recover_others,sum(tot_pay) as recover_total');
		$this->db->from('payment');
		$this->db->join('member', 'payment.me_no = member.me_no');
		$this->db->group_by('payment.payment_month');
		$this->db->group_by('payment.payment_year');
		if ($inps['division'] != "") {
			$this->db->where_in('member.division', $inps['division']);
		}
		if ($inps['section'] != "") {
			$this->db->where_in('member.section', $inps['section']);
		}
		$this->db->where_in('payment_month', $inps['month']);
		$this->db->where_in('payment_year', $inps['year']);
		$this->db->where('p_pay', '0');
		// $this->db->where('member.is_deleted', '0');

		$payment =   $this->db->get()->result();
		return  $payment;
	}

	public function last_partial_amount($inps)
	{
		$this->db->select('payment.payment_month,payment.payment_year,sum(last_principal) as recover_last_principal,sum(ex_os) as recover_ex_os,sum(os_pay) as recover_os_pay,sum(last_int) as recover_last_int,sum(loan_pri_amt) as recover_pri,sum(loan_int_amt) as recover_int,sum(p_int) as recover_p_int,sum(thrift_amt) as recover_thrift,sum(old_thrift) as recover_old_thrift,sum(old_p_int) as recover_old_p_int,sum(old_others) as recover_old_others,sum(insurance) as recover_insurance,sum(others) as recover_others,sum(tot_pay) as recover_total');
		$this->db->from('payment');
		$this->db->join('member', 'payment.me_no = member.me_no');
		$this->db->group_by('payment.payment_month');
		$this->db->group_by('payment.payment_year');
		if ($inps['division'] != "") {
			$this->db->where_in('member.division', $inps['division']);
		}
		if ($inps['section'] != "") {
			$this->db->where_in('member.section', $inps['section']);
		}
		$this->db->where_in('payment_month', $inps['month']);
		$this->db->where_in('payment_year', $inps['year']);
		$this->db->where('p_pay', '1');
		// $this->db->where('member.is_deleted', '0');

		$payment =   $this->db->get()->result();
		return  $payment;
	}
	public function get_div()
	{
		$this->db->select('*');
		$this->db->from('mapdivisionsection');
		$this->db->join('division', 'division.id = mapdivisionsection.division_id');
		$this->db->join('section', 'section.id = mapdivisionsection.section_id');
		$query = $this->db->get()->result_array();
		return  $query;
	}
	public function get_divisions($inps)
	{
		$this->db->select('member.division,member.section,sum(share_amt) as share_amt,sum(loan_int_amt) as loan_int_amt,sum(thrift_amt) as thrift_amt,sum(old_thrift) as old_thrift,sum(old_p_int) as old_p_int,sum(loan_pri_amt) as loan_pri_amt,sum(last_principal) as last_principal,sum(ex_os) as ex_os,sum(os_pay) as os_pay,sum(last_int) as last_int,sum(p_int) as p_int,sum(others) as others,sum(tot_pay) as tot_pay,sum(share_amt) as share_amt,sum(books) as books,sum(ent_fees) as ent_fees,sum(due_by) as due_by,sum(f_pri) as f_pri,sum(f_old_pri) as f_old_pri,sum(f_ex_os) as f_ex_os,sum(f_os_pay) as f_os_pay,sum(f_int) as f_int,sum(f_old_int) as f_old_int,sum(f_p_int) as f_p_int');
		$this->db->from('payment');
		$this->db->join('member', 'payment.me_no = member.me_no');
		$this->db->group_by('member.division');
		$this->db->group_by('member.section');
		$this->db->where('payment.is_deleted', '0');
		$this->db->where_in('payment_month', $inps['month']);
		$this->db->where_in('payment_year', $inps['year']);
		$payment =   $this->db->group_by('member.division,member.section')->get()->result_array();
		return  $payment;
	}

	public function get_divisions_receipt($inps)
	{
		$this->db->select('member.division,sum(share_amt) as share_amt,sum(loan_int_amt) as loan_int_amt,sum(thrift_amt) as thrift_amt,sum(loan_pri_amt) as loan_pri_amt,sum(old_thrift) as old_thrift,sum(old_p_int) as old_p_int,sum(last_principal) as last_principal,sum(ex_os) as ex_os,sum(os_pay) as os_pay,sum(last_int) as last_int,sum(p_int) as p_int,sum(others) as others,sum(tot_pay) as tot_pay,sum(share_amt) as share_amt,sum(books) as books,sum(ent_fees) as ent_fees,sum(due_by) as due_by,sum(f_pri) as f_pri,sum(f_old_pri) as f_old_pri,sum(f_ex_os) as f_ex_os,sum(f_os_pay) as f_os_pay,sum(f_int) as f_int,sum(f_old_int) as f_old_int,sum(f_p_int) as f_p_int');
		$this->db->from('payment');
		$this->db->join('member', 'payment.me_no = member.me_no');
		$this->db->group_by('member.division');
		$this->db->where('payment.is_deleted', '0');
		$this->db->where_in('payment_month', $inps['month']);
		$this->db->where_in('payment_year', $inps['year']);
		$payment =   $this->db->group_by('member.division')->get()->result_array();
		return  $payment;
	}


	public function ledger_search($inps)
	{
		// $query = $this->db->select('group_id')->get('cash_group')->result_array();
		// $group_id = array_column($query, "group_id");
		// if (count($group_id) > 0) {
		if ($inps['ledger'] == "thrift") {
			$result = $this->db->select('sum(thrift_amt) as thrift_amt,sum(old_thrift) as old_thrift,paid_on');
			$this->db->from('payment');
			$this->db->join('member', 'payment.me_no = member.me_no');
			$this->db->where('payment.is_deleted', '0');
			$this->db->where('member.is_deleted', '0');
			// $this->db->where_in('payment.group_id', $group_id);
			$this->db->where_in('payment_month', $inps['month']);
			$this->db->where_in('payment_year', $inps['year']);
			$payment =   $this->db->group_by('paid_on')->get()->result_array();
			return  $payment;
		}
		if ($inps['ledger'] == "share") {
			$result = $this->db->select('sum(share_amt) as share_amt,paid_on');
			$this->db->from('payment');
			$this->db->join('member', 'payment.me_no = member.me_no');
			$this->db->where('payment.is_deleted', '0');
			$this->db->where('member.is_deleted', '0');
			$this->db->where_in('payment_month', $inps['month']);
			$this->db->where_in('payment_year', $inps['year']);
			$payment =   $this->db->group_by('paid_on')->get()->result_array();
			return  $payment;
		}
		if ($inps['ledger'] == "principal") {
			$result = $this->db->select('sum(loan_pri_amt) as loan_pri_amt,sum(last_principal) as last_principal,sum(ex_os) as ex_os,sum(os_pay) as os_pay,paid_on');
			$this->db->from('payment');
			$this->db->join('member', 'payment.me_no = member.me_no');
			$this->db->where('payment.is_deleted', '0');
			$this->db->where('member.is_deleted', '0');
			$this->db->where_in('payment_month', $inps['month']);
			$this->db->where_in('payment_year', $inps['year']);
			$payment =   $this->db->group_by('paid_on')->get()->result_array();
			return  $payment;
		}
		if ($inps['ledger'] == "interest") {
			$result = $this->db->select('sum(loan_int_amt) as loan_int_amt,sum(last_int) as last_int,paid_on');
			$this->db->from('payment');
			$this->db->join('member', 'payment.me_no = member.me_no');
			$this->db->where('payment.is_deleted', '0');
			$this->db->where('member.is_deleted', '0');
			$this->db->where_in('payment_month', $inps['month']);
			$this->db->where_in('payment_year', $inps['year']);
			$payment =   $this->db->group_by('paid_on')->get()->result_array();
			return  $payment;
		}
		if ($inps['ledger'] == "others") {
			$result = $this->db->select('sum(others) as others,paid_on');
			$this->db->from('payment');
			$this->db->join('member', 'payment.me_no = member.me_no');
			$this->db->where('payment.is_deleted', '0');
			$this->db->where('member.is_deleted', '0');
			$this->db->where_in('payment_month', $inps['month']);
			$this->db->where_in('payment_year', $inps['year']);
			$payment =   $this->db->group_by('paid_on')->get()->result_array();
			return  $payment;
		}
		if ($inps['ledger'] == "p_int") {
			$result = $this->db->select('sum(p_int) as p_int,sum(p_int) as old_p_int,paid_on');
			$this->db->from('payment');
			$this->db->join('member', 'payment.me_no = member.me_no');
			$this->db->where('payment.is_deleted', '0');
			$this->db->where('member.is_deleted', '0');
			$this->db->where_in('payment_month', $inps['month']);
			$this->db->where_in('payment_year', $inps['year']);
			$payment =   $this->db->group_by('paid_on')->get()->result_array();
			return  $payment;
		}
		if ($inps['ledger'] == "Office Expense ") {
			$result = $this->db->select('sum(camount) as amount,paid_on,list as to');
			$this->db->from('total_expense');
			// $this->db->where_in('payment.group_id', $group_id);
			$this->db->where_in('list', $inps['ledger']);
			$this->db->where_in('expense_month', $inps['month']);
			$this->db->where_in('expense_year', $inps['year']);
			$payment =   $this->db->group_by('paid_on')->get()->result_array();
			return  $payment;
		} else {
			$result = $this->db->select('sum(amount) as amount,paid_on,to');
			$this->db->from('expense');
			$this->db->where('to', $inps['ledger']);
			$this->db->where_in('expense_month', $inps['month']);
			$this->db->where_in('expense_year', $inps['year']);
			$payment =    $this->db->group_by('paid_on')->get()->result_array();
			return  $payment;
		}
		// }
		// echo $this->db->last_query();
		// return $payment;
	}
	public function current_month_income_t($cmonth)
	{
		$res = $this->db->select("thrift_amt")->where('payment_month', $cmonth)->get("payment")->result_array();
		return  $res;
	}
	public function previous_month_incom_t($pmonth)
	{
		$res = $this->db->select("thrift_amt")->where('payment_month', $pmonth)->get("payment")->result_array();
		return  $res;
	}
	public function current_month_income_s($cmonth)
	{
		$res = $this->db->select("share_amt")->where('payment_month', $cmonth)->get("payment")->result_array();
		return  $res;
	}
	public function previous_month_income_s($pmonth)
	{
		$res = $this->db->select("share_amt")->where('payment_month', $pmonth)->get("payment")->result_array();
		return  $res;
	}
	public function current_month_income_p($cmonth)
	{
		$res = $this->db->select("loan_pri_amt")->where('payment_month', $cmonth)->get("payment")->result_array();
		return  $res;
	}
	public function previous_month_income_p($pmonth)
	{
		$res = $this->db->select("loan_pri_amt")->where('payment_month', $pmonth)->get("payment")->result_array();
		return  $res;
	}
	public function current_month_income_i($cmonth)
	{
		$res = $this->db->select("loan_int_amt")->where('payment_month', $cmonth)->get("payment")->result_array();
		return  $res;
	}
	public function previous_month_income_i($pmonth)
	{
		$res = $this->db->select("loan_int_amt")->where('payment_month', $pmonth)->get("payment")->result_array();
		return  $res;
	}

	public function current_month_expense($cmonth)
	{
		$this->db->select('*');
		$this->db->from('expense');
		$this->db->where('expense_month', $cmonth);
		$payment =   $this->db->get()->result_array();
		// $this->db->and_where('expense_month',$pmonth);
		// $payment =   $this->db->group_by('statement')->get()->result_array();
		// echo $this->db->last_query();
		return  $payment;
	}
	public function get_other_income($cmonth, $cyear)
	{
		$this->db->select("*");
		$this->db->order_by('list', 'ASC');
		$this->db->where('value', '0');
		$this->db->where('income_month', $cmonth);
		$this->db->where('income_year', $cyear);
		$res =  $this->db->get("income")->result_array();
		return  $res;
	}
	public function get_other_income1($pmonth, $pyear, $cmonth, $cyear)
	{
		$this->db->select('*');
		$this->db->order_by('list', 'ASC');
		// $current_month = array("'income_month' = $cmonth AND 'income_year'= $cyear");
		// $this->db->where($current_month);
		$this->db->where('value', '1');
		$this->db->where('income_month', $cmonth);
		$this->db->where('income_year', $cyear);
		$res =  $this->db->get("income")->result_array();
		// echo $this->db->last_query();
		return  $res;
	}

	public function get_other_expense($cmonth, $cyear)
	{
		$this->db->select("*");
		$this->db->order_by('list', 'ASC');
		$this->db->where('expense_month', $cmonth);
		$this->db->where('expense_year', $cyear);
		$res =  $this->db->get("total_expense")->result_array();
		return  $res;
	}
	public function insert_expense($data)
	{
		$insert = $this->db->insert('expense', $data);
		return  $insert;
	}
	public function insert_expense1($data)
	{
		$insert = $this->db->insert('total_expense', $data);
		return  $insert;
	}
	public function insert_income($data)
	{
		$insert = $this->db->insert('income', $data);
		return  $insert;
	}
	public function get_expense1($cmonth, $cyear)
	{
		$this->db->select('*');
		$this->db->order_by('to', 'ASC');
		// $current_month = array("'income_month' = $cmonth AND 'income_year'= $cyear");
		// $this->db->where($current_month);
		$this->db->where('expense_month', $cmonth);
		$this->db->where('expense_year', $cyear);
		$res =  $this->db->get("expense")->result_array();
		// echo $this->db->last_query();
		return  $res;
	}
	public function get_cash_book($data)
	{
		$this->db->select('*');
		$this->db->order_by('added_datetime', 'ASC');
		// $current_month = array("'income_month' = $cmonth AND 'income_year'= $cyear");
		// $this->db->where($current_month);
		if ($data['month'] != "") {
			$this->db->where('paid_month', $data['month']);
		}
		if ($data['year'] != "") {
			$this->db->where('paid_year', $data['year']);
		}
		if ($data['added_on'] != "") {
			$this->db->where('paid_date', $data['added_on']);
		}
		$this->db->where('is_deleted', 0);
		$res =  $this->db->get("cash_book")->result_array();
		// echo $this->db->last_query();
		return  $res;
	}
	public function update_cash_book($data)
	{
		$res =  $this->db->where('id', $data['id'])->update('cash_book', $data);
		// echo $this->db->last_query();
		return  $res;
	}
	public function update_expense($data)
	{
		$res =  $this->db->where('id', $data['id'])->update('expense', $data);
		return  $res;
	}
	public function debit_category()
	{
		$res =  $this->db->get('debit_category')->result_array();
		return  $res;
	}
	public function get_category()
	{
		$res =  $this->db->order_by('category asc')->get('category')->result_array();
		return  $res;
	}
	public function display_category($id)
	{
		return $this->db->where('id', $id)
			->get('category')->row();
	}
	//update value
	public function  update_category($requestData)
	{
		return $this->db->where('id', $requestData['id'])
			->update('category', $requestData);
	}
	public function add_category($data)
	{
		$result = $this->db->select("*")->where("category", $data['category'])->get("category")->result_array();
		if (count($result) > 0) {
			return 1;
		} else {
			$this->db->insert('category', $data);
			return 0;
		}
	}
	public function add_sub_category($data)
	{
		$result = $this->db->select("*")->where("sub_category", $data['sub_category'])->get("sub_category")->result_array();
		if (count($result) > 0) {
			return 1;
		} else {
			$this->db->insert('sub_category', $data);
			return 0;
		}
	}
	public function get_sub_category()
	{
		$res =  $this->db->where('status', "0")->order_by('sub_category asc')->get('sub_category')->result_array();
		return  $res;
	}
	public function display_sub_category($id)
	{
		return $this->db->where('id', $id)
			->get('sub_category')->row();
	}
	//update value
	public function  update_sub_category($requestData)
	{
		return $this->db->where('id', $requestData['id'])
			->update('sub_category', $requestData);
	}
	public function income_tcategory()
	{
		$res =  $this->db->where('value', "0")->get('tamil')->result_array();
		return  $res;
	}
	public function income_others_category()
	{
		$res =  $this->db->where('value', "1")->get('category')->result_array();
		return  $res;
	}
	public function income_others_tcategory()
	{
		$res =  $this->db->where('value', "1")->get('tamil')->result_array();
		return  $res;
	}
	public function income_sub_category()
	{
		$res =  $this->db->where('value', "2")->get('sub_category')->result_array();
		return  $res;
	}
	public function income_tsub_category()
	{
		$res =  $this->db->where('value', "2")->get('tamil')->result_array();
		return  $res;
	}
	public function expense_category()
	{
		$res =  $this->db->where('value', "1")->get('expense_category')->result_array();
		return  $res;
	}
	public function expense_tcategory()
	{
		$res =  $this->db->where('value', "3")->get('tamil')->result_array();
		return  $res;
	}
	public function expense_others_category()
	{
		$res =  $this->db->where('value', "2")->get('expense_category')->result_array();
		return  $res;
	}
	public function expense_others_tcategory()
	{
		$res =  $this->db->where('value', "4")->get('tamil')->result_array();
		return  $res;
	}
	public function expense_others_sub_category()
	{
		$res =  $this->db->where('value', "2")->get('expense_sub_category')->result_array();
		return  $res;
	}
	public function expense_others_tsub_category()
	{
		$res =  $this->db->where('value', "5")->get('tamil')->result_array();
		return  $res;
	}
	public function expense_Statement_category()
	{
		$res =  $this->db->where('value', "1")->get('expense_sub_category')->result_array();
		return  $res;
	}
	public function expense_Statement_tcategory()
	{
		$res =  $this->db->where('value', "6")->get('tamil')->result_array();
		return  $res;
	}
	function expense_category_search($expense)
	{
		$this->db->where('find', $expense);
		$this->db->order_by('category', 'ASC');
		$query = $this->db->get('tamil');
		foreach ($query->result() as $row) {
			$output = ' <input type="text" id="itamil_id" class="form-control validate" readonly name="tamil" value=' . $row->category . '>';
		}
		// print_r($output);
		return $output;
	}
	function sub_category_search($category_id)
	{
		$this->db->where('category', $category_id);
		$this->db->order_by('sub_category', 'ASC');
		$query = $this->db->get('sub_category');
		$output = '<option value="">--Select--</option>';
		foreach ($query->result() as $row) {
			$output .= '<option value="' . $row->id . '">' . $row->sub_category . '</option>';
		}
		// print_r($output);
		return $output;
	}
	function income_t_search($income)
	{
		$this->db->where('find', $income);
		$this->db->order_by('category', 'ASC');
		$query = $this->db->get('tamil');
		foreach ($query->result() as $row) {
			$output = ' <input type="text" id="itamil_id" class="form-control validate" readonly name="tamil" value=' . $row->category . '>';
		}
		// print_r($output);
		return $output;
	}

	function income_sub_t_others_search($income)
	{
		$this->db->where('find', $income);
		$this->db->order_by('category', 'ASC');
		$query = $this->db->get('tamil');
		foreach ($query->result() as $row) {
			$output = ' <input type="text" id="itamil_id" class="form-control validate" readonly name="sub_tamil" value=' . $row->category . '>';
		}
		return $output;
	}
	function expense_sub_t_others_search1($income)
	{
		$this->db->where('find', $income);
		$this->db->order_by('category', 'ASC');
		$query = $this->db->get('tamil');
		foreach ($query->result() as $row) {
			$output = ' <input type="text" id="itamil_id" class="form-control validate" readonly name="sub_tamil1" value=' . $row->category . '>';
		}
		return $output;
	}
	public function get_expense_category($inps)
	{
		$this->db->select('s.*');
		$this->db->join('map_category m', 'm.expense_Statement_category=s.id');
		$this->db->join('expense_category c', 'c.id=m.expense_category');
		if (isset($inps) && $inps != "") {
			$this->db->where('c.id', $inps);
		}
		$this->db->order_by('s.category asc');
		$result = $this->db->get('expense_sub_category s')->result_array();
		return $result;
	}

	public function get_income_others($inps)
	{
		$this->db->select('s.*');
		$this->db->join('map_income_category m', 'm.income_sub_category=s.id');
		$this->db->join('category c', 'c.id=m.income_category');
		if (isset($inps) && $inps != "") {
			$this->db->where('c.id', $inps);
		}
		$this->db->order_by('s.category asc');
		$result = $this->db->get('sub_category s')->result_array();
		return $result;
	}


	public function get_my($inps)
	{
		$this->db->select('member.division,sum(share_amt) as share_amt,sum(loan_int_amt) as loan_int_amt,sum(thrift_amt) as thrift_amt,sum(loan_pri_amt) as loan_pri_amt,sum(others) as others,sum(tot_pay) as tot_pay');
		$this->db->from('payment');
		$this->db->join('member', 'payment.me_no = member.me_no');
		$this->db->where('payment_month', $inps['month']);
		$this->db->where('payment_year', $inps['year']);
		$payment =   $this->db->group_by('member.division')->get()->result_array();
		return  $payment;
	}

	public function dcp_search($data)
	{
		if ($data['type'] == "thrift") {
			$this->db->select("member.me_no,member.mem_name,tot_thrift as cb,payment.payment_month,sum(payment.thrift_amt) as amt");
			$this->db->from('member');
			$this->db->join('thrift', 'thrift.me_no = member.me_no');
			$this->db->join('payment', 'payment.me_no = member.me_no');
			if ($data['year'] != "") {
				$this->db->where('payment.payment_year', $data['year']);
			}
			$this->db->where('payment.is_deleted', '0');
			$this->db->order_by("member.me_no", "asc");
			$this->db->order_by("payment.payment_month", "asc");
			$this->db->group_by('member.me_no');
			$this->db->group_by('member.mem_name');
			$this->db->group_by('thrift.tot_thrift');
			$this->db->group_by('payment.payment_month');
			$result = $this->db->group_by('payment.payment_month')->get()->result_array();
			return $result;
		}
		if ($data['type'] == "share") {
			$this->db->select("member.me_no,member.mem_name,share.tot_share as cb,payment.payment_month,sum(payment.share_amt) as amt");
			$this->db->from('member');
			$this->db->join('share', 'share.me_no = member.me_no');
			$this->db->join('payment', 'payment.me_no = member.me_no');
			if ($data['year'] != "") {
				$this->db->where('payment.payment_year', $data['year']);
			}
			$this->db->where('payment.is_deleted', '0');
			$this->db->order_by("member.me_no", "asc");
			$this->db->order_by("payment.payment_month", "asc");
			$this->db->group_by('member.me_no');
			$this->db->group_by('member.mem_name');
			$this->db->group_by('share.tot_share');
			$this->db->group_by('payment.payment_month');
			$result = $this->db->group_by('payment.payment_month')->get()->result_array();
			return $result;
		}
		if ($data['type'] == "principal") {
			$this->db->select("member.me_no,member.mem_name,loan.loan_os_amt as cb,payment.payment_month,sum(payment.os_pay + payment.loan_pri_amt)  as amt");
			$this->db->from('member');
			$this->db->join('loan', 'loan.me_no = member.me_no');
			$this->db->join('payment', 'payment.me_no = member.me_no');
			if ($data['year'] != "") {
				$this->db->where('payment.payment_year', $data['year']);
			}
			$this->db->where('payment.is_deleted', '0');
			$this->db->order_by("member.me_no", "asc");
			$this->db->order_by("payment.payment_month", "asc");
			$this->db->group_by('member.me_no');
			$this->db->group_by('member.mem_name');
			$this->db->group_by('loan.loan_os_amt');
			$this->db->group_by('payment.payment_month');
			$result = $this->db->group_by('payment.payment_month')->get()->result_array();
			return $result;
		}
	}
	public function get_member_transfer($data)
	{
		$this->db->select('*');
		if ($data['month'] != "") {
			$this->db->where('month(date)', $data['month']);
		}
		if ($data['year'] != "") {
			$this->db->where('year(date)', $data['year']);
		}
		$result =   $this->db->get('transfer')->result();
		return $result;
	}
	public function get_member_transfer_details($data)
	{
		$this->db->select('*');
		$this->db->join("member", "member.me_no=transfer.mem_no");
		if ($data['month'] != "") {
			$this->db->where('month(date)', $data['month']);
		}
		if ($data['year'] != "") {
			$this->db->where('year(date)', $data['year']);
		}
		$this->db->order_by('member.section asc');
		$result =   $this->db->get('transfer')->result();
		return $result;
	}
	public function get_edited_loan($data)
	{
		$this->db->select('*');
		$this->db->join("loan l", "m.me_no=l.me_no");
		if ($data['division'] != "") {
			$this->db->where('m.division', $data['division']);
		}
		if ($data['section'] != "") {
			$this->db->where('m.section', $data['section']);
		}
		if ($data['month'] != "") {
			$this->db->where('month(l.updated_on)', $data['month']);
		}
		if ($data['year'] != "") {
			$this->db->where('year(l.updated_on)', $data['year']);
		}
		$this->db->where('m.is_deleted', '0');
		$result =   $this->db->get('member m')->result();
		return $result;
	}
	public function get_edited_loan_details($data)
	{
		$this->db->select('*');
		$this->db->join("loan l", "m.me_no=l.me_no");
		if ($data['division'] != "") {
			$this->db->where('m.division', $data['division']);
		}
		if ($data['section'] != "") {
			$this->db->where('m.section', $data['section']);
		}
		if ($data['month'] != "") {
			$this->db->where('month(l.updated_on)', $data['month']);
		}
		if ($data['year'] != "") {
			$this->db->where('year(l.updated_on)', $data['year']);
		}
		$this->db->where('m.is_deleted', '0');
		$result =   $this->db->get('member m')->result();
		return $result;
	}

	public function get_due_by($data)
	{
		$this->db->select('*');
		$this->db->join("payment p", "m.me_no=p.me_no");
		if ($data['division'] != "") {
			$this->db->where('m.division', $data['division']);
		}
		if ($data['section'] != "") {
			$this->db->where('m.section', $data['section']);
		}
		if ($data['month'] != "") {
			$this->db->where('p.payment_month', $data['month']);
		}
		if ($data['year'] != "") {
			$this->db->where('p.payment_year', $data['year']);
		}
		$this->db->where('m.is_deleted', '0');
		$this->db->where('p.due_by != ', '0');
		$result =   $this->db->get('member m')->result();
		return $result;
	}
	public function get_due_by_details($data)
	{
		$this->db->select('*');
		$this->db->join("payment p", "m.me_no = p.me_no");
		if ($data['division'] != "") {
			$this->db->where('m.division', $data['division']);
		}
		if ($data['section'] != "") {
			$this->db->where('m.section', $data['section']);
		}
		if ($data['month'] != "") {
			$this->db->where('p.payment_month', $data['month']);
		}
		if ($data['year'] != "") {
			$this->db->where('p.payment_year', $data['year']);
		}
		// $where = "p.due_by is  NOT equal to NULL ";
		// $this->db->where($where);
		$this->db->where('p.due_by != ', '0');
		$this->db->where('m.is_deleted', '0');
		$this->db->where('p.is_deleted', '0');
		$result =   $this->db->get('member m')->result();
		// print_r($result);die;
		return $result;
	}

	public function get_edited_thrift($data)
	{
		$this->db->select('*');
		$this->db->join("thrift t", "m.me_no=t.me_no");
		if ($data['division'] != "") {
			$this->db->where('m.division', $data['division']);
		}
		if ($data['section'] != "") {
			$this->db->where('m.section', $data['section']);
		}
		if ($data['month'] != "") {
			$this->db->where('month(updated_on)', $data['month']);
		}
		if ($data['year'] != "") {
			$this->db->where('year(updated_on)', $data['year']);
		}
		$this->db->where('m.is_deleted', '0');
		$result =   $this->db->get('member m')->result();
		return $result;
	}
	public function get_edited_thrift_details($data)
	{
		$this->db->select('*');
		$this->db->join("thrift t", "m.me_no=t.me_no");
		if ($data['division'] != "") {
			$this->db->where('m.division', $data['division']);
		}
		if ($data['section'] != "") {
			$this->db->where('m.section', $data['section']);
		}
		if ($data['month'] != "") {
			$this->db->where('month(updated_on)', $data['month']);
		}
		if ($data['year'] != "") {
			$this->db->where('year(updated_on)', $data['year']);
		}
		$this->db->where('m.is_deleted', '0');
		$result =   $this->db->get('member m')->result();
		return $result;
	}

	public function new_member($data)
	{
		$this->db->select('*');
		if ($data['division'] != "") {
			$this->db->where('m.division', $data['division']);
		}
		if ($data['section'] != "") {
			$this->db->where('m.section', $data['section']);
		}
		if ($data['month'] != "") {
			$this->db->where('month(mem_doj)', $data['month']);
		}
		if ($data['year'] != "") {
			$this->db->where('year(mem_doj)', $data['year']);
		}
		$this->db->where('m.is_deleted', '0');
		$result =   $this->db->get('member m')->result_array();
		return $result;
	}
}
