<?
class payment_summerymodel extends Model
{
    function payment_summerymodel()
    {
            parent::Model();
    }



    /**
     * @author: Md. Sabbir Ali
     * @email: sabbircsecuet@gmail.com
     * @description: This function return Reseller Payment Summery List
     * @copyright 2011
     */
	function reseller_payment_summeryList($startdate,$enddate,$reseller1id,$reseller2id,$reseller3id,$reseller4id)
	{
		if($startdate=="NULL")
        {
            $startdateStr = "";
        }
		else
        {
            $startdateStr = " AND a.creationdate >= '$startdate 00:00:01'";
        }

		if($enddate=="NULL")
        {
            $enddateStr = "";
        }
        else
        {
            $enddateStr = " AND a.creationdate <= '$enddate 23:59:59'";
        }
        
        if($reseller1id=="NULL")
        {
            $reseller1idStr = "";
        }
        else
        {
            $reseller1idStr = " AND a.id_reseller = '$reseller1id' AND level=1";
        }
        
        if($reseller2id=="NULL")
        {
            $reseller2idStr = "";
        }
        else
        {
            $reseller2idStr = " AND a.id_reseller = '$reseller2id' AND level=2";
        }
        
        if($reseller3id=="NULL")
        {
            $reseller3idStr = "";
        }
        else
        {
            $reseller3idStr = " AND a.id_reseller = '$reseller3id' AND level=3";
        }
        
        
        if($reseller4id=="NULL")
        {
            $reseller4idStr = "";
        }
        else
        {
            $reseller4idStr = " AND a.id_reseller = '$reseller4id' AND level=4";
        }
        
        $sql = "SELECT a.* FROM resellerpayment a WHERE a.id != '-1' $startdateStr $enddateStr $reseller1idStr $reseller2idStr $reseller3idStr $reseller4idStr ORDER BY a.creationdate DESC";

	    $query = $this->db->query($sql);
	    if($query->num_rows()>0)
		  return $query->result();
	    else
		 return 0;
	}
    
    
    
    /**
     * @author: Md. Sabbir Ali
     * @email: sabbircsecuet@gmail.com
     * @description: This function return Client Payment Summery List
     * @copyright 2011
     */
    function client_payment_summeryList($startdate,$enddate,$wholesale_id,$gk_register_id,$ivr_id)
    {
        if($startdate=="NULL")
        {
            $startdateStr = "";
        }
        else
        {
            $startdateStr = " AND a.paymentdate >= '$startdate'";
        }

        if($enddate=="NULL")
        {
            $enddateStr = "";
        }
        else
        {
            $enddateStr = " AND a.paymentdate <= '$enddate'";
        }
        
        if($wholesale_id=="NULL")
        {
            $wholesale_idStr = "";
        }
        else
        {
            $wholesale_idStr = " AND a.id_client = $wholesale_i AND clienttype=2";
        }
        
        if($gk_register_id=="NULL")
        {
            $gk_register_idStr = "";
        }
        else
        {
            $gk_register_idStr = " AND a.id_client = $gk_register_id AND clienttype=1";
        }
        
        if($ivr_id=="NULL")
        {
            $ivr_idStr = "";
        }
        else
        {
            $ivr_idStr = " AND a.id_client = $ivr_id AND clienttype=1";
        }
        
        $sql = "SELECT a.id,a.id_client,a.login,a.description,a.id_reseller,a.paymentdate,a.clienttype,a.type,a.amount FROM clientpayment a WHERE a.id != '-1' $startdateStr $enddateStr $wholesale_idStr $gk_register_idStr $ivr_idStr ORDER BY a.paymentdate DESC";

        $query = $this->db->query($sql);
        if($query->num_rows()>0)
          return $query->result();
        else
         return 0;
    }
}