<?php
  
  
   print "<table border='1' width='50%' align='center'>";

   print "<tr>
				<td>Sr No</td>
				<td>Member Name</td>
				<td>Member ID</td>
				<td>PV</td>
				<td>Purchase Date</td>
				<td>Incentive</td>
		  </tr>";

	$db = new PDO('mysql:host=localhost;dbname=mybooster;', 'root', 'root');
	$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);

	$data='';
	$data =  getNetworkPayout($db, $_REQUEST['refer_id'], $_REQUEST['payout_id']);


	$i = 1;
	$incentive = 0;

	foreach($data as $row)
	{

		echo "<tr>";
		echo "<td>" . $i++  . "</td>";
		echo "<td>" . getMemberName($row['refer_id'], $db)  . "</td>";
		echo "<td>" . $row['refer_id']  . "</td>";
		echo "<td>" . $row['pv']   . "</td>";
		echo "<td>" . $row['date_time']   . "</td>";
		echo "<td>" . $row['pv'] * 0.1  . "</td>";
		echo "</tr>";
		$incentive += $row['pv'] * 0.1;
	
	}

	echo "<tr>";
	echo "<td colspan=5>TOTAL</td>";
	echo "<td>" . $incentive  . "</td>";
	echo "</tr>";
	


	function getNetworkPayout($db, $refer_id, $payout_id)
	{
		try{
			
			$sql = "SELECT * from my_payout_child where sponsored_id='$refer_id' AND power_leg=0 AND node='r' AND pv > 0 AND applied=1 AND payout_id='$payout_id' order by date_time asc";
			$stmt= $db->prepare($sql);
			$stmt->execute();
    		$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
			return $result;
	
		}


		catch(Exception $e)
		{
			$e->getMessage();
			return false;

		}

	}

	function getMemberName($refer_id, $db)
	{
		try{

			$sql = "SELECT concat(name, ' ', last_name) as name from my_registration where refer_id=$refer_id";
			//echo $sql . "<br/>";
			$stmt= $db->prepare($sql);
			$stmt->execute();
    		$result = $stmt->fetch(PDO::FETCH_ASSOC);
			//var_dump($result);
			return ucwords($result['name']);
	
		}


		catch(Exception $e)
		{
			echo $e->getMessage();
			return false;

		}

	}

































?>