<?php

if (!defined('BASEPATH')) exit('No direct script access allowed');

class Flexi_report_m extends CI_Model
{
	public function __construct()
	{

		$this->load->database();
	}

	function transasction_report($select,$table,$column='',$from='',$to='',$condition='')
	{
		$this->db->select($select);
		if(!empty($from))
		{
			$this->db->where($column.'>=', $from);

			$this->db->where($column.'<=', $to);
		}

		if(!empty($condition))
		{
			$this->db->where($condition);
		}

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

	function sending_blance($from='',$to='',$condition='')
	{
		$this->db->select('lt.*,u.username');
		$this->db->from('load_blance_transfer as lt');
		if(!empty($from))
		{
			$this->db->where('created_at >=', $from);
			$this->db->where('created_at <=', $to);
		}

		if(!empty($condition))
		{
			$this->db->where($condition);
		}
		$this->db->join('users_login as u', 'lt.receiver_id=u.user_id', 'left');

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

	function receiving_blance($from='',$to='',$condition='')
	{
		$this->db->select('lt.*,u.username');
		$this->db->from('load_blance_transfer as lt');
		if(!empty($from))
		{
			$this->db->where('created_at >=', $from);
			$this->db->where('created_at <=', $to);
		}

		if(!empty($condition))
		{
			$this->db->where($condition);
		}
		$this->db->join('users_login as u', 'lt.sender_id=u.user_id', 'left');

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

	public function package_order_history($condition='')
	{
		
		$this->db->select('*');
		$this->db->from('flexiload_fund_req');
		if(!empty($condition))
		{
			$this->db->where($condition);
		}
		$query=$this->db->get();
		return $query->result();
	}
	public function flexi_income($user_id,$time){

        $qury = $this->db->query("SELECT COUNT(id) as total_package, sum(income) as total_earn FROM flexiload_fund_req WHERE user_id='$user_id' AND status=1 AND created_at >= curdate()+'%' - INTERVAL'$time' day AND created_at <= CURDATE()+'%' + INTERVAL 1 DAY");

        return $qury->row();

    }

}
