<?php 

@session_start();


	if($_SESSION['SECEXP'] !=''){

	}else{
		echo "Go And Fuck Your Self";die;
	}
?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=11" >
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="<?php echo SITEURL?>/css/ie7.css">
<![endif]-->
<!--[if IE 8]>
<link rel="stylesheet" type="text/css" href="<?php echo SITEURL?>/css/ie7.css">
<![endif]-->
<link rel="stylesheet" type="text/css" href="<?php echo SITEURL?>/css/ie7.css">

</head>

<body>
	<div class="container" style=" background:#fff;">
	<div class="menus">
      <ul style="">
          <?php echo innerAdminMenu()?>
      </ul>
    </div>	


		<p><?php echo $_REQUEST['frmdate']?> To <?php echo $_REQUEST['todate']?></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 as U WHERE userType="1"';
			$D = $DB->dbRows($sql);
			

			
			$tot = 0;
			foreach($D as $D){
							$sqlLT = 'SELECT logStatus FROM '.$DB->pre.'user_logs WHERE userID="'.$D['id'].'" ORDER BY id desc limit 0,1';
							$LT = $DB->dbRow($sqlLT);
							if($LT['logStatus'] == 1){
				?>
                <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 adminID="'.$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>
