<?php
@session_start();
if($_SESSION['SECEXP'] !=''){

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

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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;">
		 <input id="hideAdminID" name="hideAdminID" type="hidden" value="<?php echo $_REQUEST['id']?>">
                        <input id="hideDrawTime" name="hideDrawTime" type="hidden" value="<?php echo drawTime();?>">
        <div class="menus">
          <ul style="">
              <?php echo innerAdminMenu()?>
          </ul>
        </div>
        <div class="row" style="margin-bottom:-10px;">
        	<h4 style="margin-bottom:-17px; margin-top:5px;"><?php date_default_timezone_set('Asia/Kolkata'); echo date('m-d-Y')?> &emsp; <?php echo date('h:i:s')?> &emsp; Start</h4>
        	<h4>Date: <?php echo $_REQUEST['frmdate']?> &emsp; to &emsp; <?php echo $_REQUEST['todate']?> </h4>
        </div>

		<div class="row">
			<div id="table02">
            	<table width="100%" border="1" cellspacing="0" cellpadding="7">
                	<tr>

                        <th>User Id </th>
                        <th>Sales </th>
                        <th>Win 90 </th>
                        <th>Win 80 </th>
                        <th>Win 70 </th>
                        <th>10 Cr </th>
                        <th>20 Cr </th>
                        <th>Comm </th>
                        <th>Net Amount</th>
                        <th>Bonus </th>
                        <th>Net Pay</th>
                    </tr>
                    <?php
                    	$sql = 'SELECT * FROM '.$DB->pre.'users WHERE underHead="'.$_REQUEST['id'].'"  AND userType="2"';
						$D = $DB->dbRows($sql);
						
						$win = '';
						$comm = '';
						$win90 = '';
						$bonus = '';
						$dateClause = '(lotdate between "'.$_REQUEST['frmdate'].'" AND "'.$_REQUEST['todate'].'")';
						foreach($D as $k=>$D){
							$sqlR = 'SELECT id,userCode,winrate FROM '.$DB->pre.'users WHERE underHead="'.$D['id'].'" AND isActive="1" AND userType="3"';
							$R = $DB->dbRows($sqlR);
							
							foreach($R as $R){
								 
							$tot = 0;
							$win90 = '';
							$win80 = '';
							$win70 = '';
							$sqlL = 'SELECT sum(distinct(ticketTot)) as T FROM '.$DB->pre.'lottary WHERE uID="'.$R['id'].'" AND status="1" AND '.$dateClause.' GROUP BY tranID';
							$L = $DB->dbRows($sqlL);
							//print_r($L);
							$tot += getSale3($L);
							if($R['winrate'] == '90'){
							$win90 += winClaimeAdmin3($R['id'],'90');
							}
							if($R['winrate'] == '80'){
							$win80 += winClaimeAdmin3($R['id'],'80');
							}
							if($R['winrate'] == '70'){
							$win70 += winClaimeAdmin3($R['id'],'70');
							}
							?>
                            <tr>
                                <td><?php echo $R['userCode']?> </td>
                                <td><?php echo $tot;?></td>
                                <td><?php echo $win90?> </td>
                                <td><?php echo $win80?> </td>
                                <td><?php echo $win70?> </td>
                                <td>0 </td>
                                <td>0 </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
							}
						}
					?>
                    
                    
                </table>
			</div>
				
			
		</div>

	</div>
<?php
function getSale3($L){
	$tot = 0;
	foreach($L as $L){
		$tot +=$L['T'];
	}
	return $tot;
}
		
		function winClaimeAdmin3($userID,$win){
			global $DB;	
			$dateClause = '(lotdate between "'.$_REQUEST['frmdate'].'" AND "'.$_REQUEST['todate'].'")';				 
			$sql = 'SELECT * FROM '.$DB->pre.'result_win WHERE '.$dateClause.' AND 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);

		}

?>
</body>
</html>
