<?php 

@session_start();


	if($_REQUEST['id'] !=''){

	}else{
		die;
	}
?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link rel="stylesheet" type="text/css" href="<?php echo SITEURL?>/css/style.css">
<script type="text/x-javascript" src="<?php echo SITEURL?>/js/jquery.min1.js"></script>
<script type="text/x-javascript" src="<?php echo SITEURL?>/mod/page/x-page.inc.js"></script>

</head>

<body style="background-color:#9BDC74">
	<div class="container">
		<div class="row inline">
			<div class="navstyle">
				<li>Date 
					<input type="date" name="Date">
					to 
					<input type="date" name="Date">
					&nbsp;
					<button class="btn" type="button" name="Screen">Screen </button>
					<button class="btn" type="button" name="Screen">Print </button>
					<button class="btn" type="button" name="Screen">Exit </button>
						<a class="timer" id="timer"></a>
                        
                        <input id="hideAdminID" name="hideAdminID" type="hidden" value="<?php echo $_REQUEST['id']?>">
                        <input id="hideDrawTime" name="hideDrawTime" type="hidden" value="<?php echo drawTime();?>">

						<a href="#"><img src="<?php echo SITEURL?>/images/admin.jpg"></a>
				</li>

				
			</div>
			<div class="menus">
			<ul>
				  <li><a class="active" href="<?php echo SITEURL?>/agent/?u=<?php echo $_REQUEST['u']?>&flag=<?php echo $_REQUEST['flag']?>&id=<?php echo $_REQUEST['id']?>">Home </a></li>
				  <li><a href="<?php echo SITEURL?>/agent-list1/?u=<?php echo $_REQUEST['u']?>&flag=<?php echo $_REQUEST['flag']?>&id=<?php echo $_REQUEST['id']?>">Agent </a></li>
				  <li><a href="<?php echo SITEURL?>/live-list/?u=<?php echo $_REQUEST['u']?>&flag=<?php echo $_REQUEST['flag']?>&id=<?php echo $_REQUEST['id']?>">AB </a></li>
				  <li><a href="<?php echo SITEURL?>/balance/?u=<?php echo $_REQUEST['u']?>&flag=<?php echo $_REQUEST['flag']?>&id=<?php echo $_REQUEST['id']?>">Balance </a></li>
				  				  <li><a href="<?php echo SITEURL?>/live-list/?u=<?php echo $_REQUEST['u']?>&flag=<?php echo $_REQUEST['flag']?>&id=<?php echo $_REQUEST['id']?>">Live </a></li>
				  <li><a href="<?php echo SITEURL?>/live-betting/?u=<?php echo $_REQUEST['u']?>&flag=<?php echo $_REQUEST['flag']?>&id=<?php echo $_REQUEST['id']?>">Live Beting </a></li>
				  <li><a href="<?php echo SITEURL?>/today/?u=<?php echo $_REQUEST['u']?>&flag=<?php echo $_REQUEST['flag']?>&id=<?php echo $_REQUEST['id']?>">Today </a></li>
				  <li><a href="<?php echo SITEURL?>/winning/?u=<?php echo $_REQUEST['u']?>&flag=<?php echo $_REQUEST['flag']?>&id=<?php echo $_REQUEST['id']?>">Winning </a></li>
				  <li><a href="<?php echo SITEURL?>/live-bz/?u=<?php echo $_REQUEST['u']?>&flag=<?php echo $_REQUEST['flag']?>&id=<?php echo $_REQUEST['id']?>">Live BZ </a></li>
				  <li><a href="<?php echo SITEURL?>/barcode/?u=<?php echo $_REQUEST['u']?>&flag=<?php echo $_REQUEST['flag']?>&id=<?php echo $_REQUEST['id']?>">Barcode </a></li>
				  <li><a href="<?php echo SITEURL?>/r-play/?u=<?php echo $_REQUEST['u']?>&flag=<?php echo $_REQUEST['flag']?>&id=<?php echo $_REQUEST['id']?>">R-Play </a></li>
				  <li><a href="#">Only WinT </a></li>
				  <li><a href="#">Pack </a></li>
				  <li><a href="#">lastLog </a></li>
				  <li><a href="#">Password </a></li>
			</ul>
		</div>

		</div>


		<p><?php echo date('d-M-Y')?> To <?php echo date('d-M-Y')?></p>	
        
        <table border="1px" cellpadding="1px" cellspacing="1" width="98%" style="font-size:20px;">
        <tr>
        	<td>Agent Name</td>
            <td>Sales</td>
            <td>Win 90</td>
            <td>Win 80</td>
            <td>Win 70</td>
            <td>10 Cr</td>
            <td>20 Cr</td>
            <td>Comm</td>
            <td>Net Amt</td>
            <td>Bonus</td>
            <td>Net To Pay</td>
        </tr>
        <?php
        
			$sql = 'SELECT * FROM '.$DB->pre.'users WHERE (underHead="'.$_REQUEST['adminID'].'") AND userType="2" AND isActive="1"';
			$D = $DB->dbRows($sql);
			$tot = 0;
			foreach($D as $D){
				?>
                <tr>
        	<td><a href="<?php echo SITEURL?>/retailer-list/?agentID=<?php echo $D['id']?>&id=<?php echo $_REQUEST['id']?>&u=<?php echo $_REQUEST['u']?>"><?php echo $D['name']?></a></td>
            <td>
            	<?php
					$sqlR = 'SELECT id FROM '.$DB->pre.'users WHERE underHead="'.$D['id'].'" AND isActive="1" AND userType="3"';
					$R = $DB->dbRows($sqlR);
					$win90 = '';
					$win80 = '';
					$win70 = '';
                	foreach($R as $R){ 
							$sqlL = 'SELECT sum(distinct(ticketTot)) as T FROM '.$DB->pre.'lottary WHERE uID="'.$R['id'].'" AND lotDate="'.date('Y-m-d').'" GROUP BY tranID';
							$L = $DB->dbRows($sqlL);
							$tot += getSale2($L);
							
							if($D['winrate'] == '90'){
							$win90 += winClaimeAdmin2($R['id'],'90');
							}
							if($D['winrate'] == '80'){
							$win80 += winClaimeAdmin2($R['id'],'80');
							}
							if($D['winrate'] == '70'){
							$win70 += winClaimeAdmin2($R['id'],'70');
							}
						}
					echo $tot;
				?>
            
            </td>
            <td><?php echo $win90;	?></td>
            <td><?php echo $win80;	?></td>
            <td><?php echo $win70;	?></td>
            <td>0 Cr</td>
            <td>0 Cr</td>
            <td><?php echo $comm = (($tot/100)*$D['commission']);?></td>
            <td><?php echo ($tot-$comm)?></td>
            <td><?php echo $bonus = (($tot/100)*$D['bonus']);?></td>
            <td><?php $sum = ($tot-(($comm-$bouns)));echo ($sum-$win90)?></td>
        </tr>
                <?php
			}
			
		function getSale2($L){
			$tot = 0;
			foreach($L as $L){
				$tot +=$L['T'];
			}
			return $tot;
		}
		
		function winClaimeAdmin2($userID,$win){
			global $DB;					 
			$sql = 'SELECT * FROM '.$DB->pre.'result_win WHERE uID="'.$userID.'"';
			$S = $DB->dbRows($sql);
			//print_r($S);
			$point = 0;
			$cv = 0;
			foreach($S as $S){
			//	echo $S['point'];
				$point += ($S['point']*$win)*$S['cv'];
				//$cv += $S['cv'];
				
			}
			$str = $point;
			return ($str);
	
			}
		?>
        </table>
			

	</div>

</body>
</html>
