<?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>
				 <?php echo innerAdminMenu()?>
			</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>Admin 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 userType="1"';
			$D = $DB->dbRows($sql);
			
			$tot = 0;
			foreach($D as $D){
				?>
                <tr>
        	<td><a href="<?php echo SITEURL?>/agent-list/?adminID=<?php echo $D['id']?>&id=<?php echo $_REQUEST['id']?>&u=<?php echo $_REQUEST['u']?>"><?php echo $D['name']?></a></td>
            <td>
            	<?php
					
					$sqlU = 'SELECT id FROM '.$DB->pre.'users WHERE underHead="'.$D['id'].'" AND isActive="1" AND userType="2"';
					$U = $DB->dbRows($sqlU);
					$win90 = '';
					$win80 = '';
					$win70 = '';
					foreach($U as $U){
						$sqlR = 'SELECT id FROM '.$DB->pre.'users WHERE underHead="'.$U['id'].'" AND isActive="1" AND userType="3"';
						$R = $DB->dbRows($sqlR);
						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 += getSale1($L);
							if($D['winrate'] == '90'){
							$win90 += winClaimeAdmin1($R['id'],'90');
							}
							if($D['winrate'] == '80'){
							$win80 += winClaimeAdmin1($R['id'],'80');
							}
							if($D['winrate'] == '70'){
							$win70 += winClaimeAdmin1($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 winClaimeAdmin1($userID,$win){
			global $DB;					 
			$sql = 'SELECT * FROM '.$DB->pre.'result_win WHERE uID="'.$userID.'" AND lotDate="'.date('Y-m-d').'"';
			$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);
	
			}
			function getSale1($L){
			$tot = 0;
			foreach($L as $L){
				$tot +=$L['T'];
			}
			return $tot;
		}
		
		?>
        </table>
			

	</div>

</body>
</html>
