<?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">
<style>
.only_win_t table, th{
	border: 1px solid black;
	width: 149px;
}
</style>
</head>

<body>
	<div class="container">
		<div class="menus">
          <ul style="">
              <?php echo innerAdminMenu()?>
          </ul>
        </div>

		<div class="row">
			
            
            <div class="a-form" style="width: 296px; float: left; border: 1px solid black; background-color: rgb(112, 255, 172);">
				<table class="only_win_t">
                <?php
                	$sqlA = 'SELECT id,userCode,name FROM '.$DB->pre.'users WHERE status="1" AND isActive="1" AND underHead="'.$_REQUEST['id'].'" AND userType="2"';
					$A = $DB->dbRows($sqlA);
					
					$dateClause = '(lotdate between "'.$_REQUEST['frmdate'].'" AND "'.$_REQUEST['todate'].'")';
					
					foreach($A as $A){
						$sqlR = 'SELECT id,userCode,name FROM '.$DB->pre.'users WHERE status="1" AND isActive="1" AND underHead="'.$A['id'].'" AND userType="3"';
						$R = $DB->dbRows($sqlR);
						foreach($R as $R){
							$sqlL1 = 'SELECT distinct(barcode),lotdate,lotTime,qtyTot,tranID,lotTime  FROM '.$DB->pre.'lottary WHERE uID="'.$R['id'].'" AND '.$dateClause;
							$L1 = $DB->dbRows($sqlL1);
							$claim1 = 0;
							foreach($L1 as $k=>$L1){
								$claim1 += getPendignClaim($_REQUEST['id'],$R['id'],$L1['barcode'],$L1['lotTime']);
							}
							if($claim1 >0){
							?>
                            <tr>
                                <th><?php echo $R['userCode']?></th>
                                <th><?php echo $claim1;?></th>
                            </tr>
                            
                            <?php
							}
							
						}
					}
				?>
					
				</table>
			</div>

			<div class="a-form" style="width: 75%; float: right; border: 1px solid black; background-color: rgb(252, 253, 184);">
				<table style="margin-top:1px;">
					<tr>
						<th>Sr.No. </th>
						<th>Date </th>
						<th>Time </th>
						<th>T.No. </th>
						<th>User ID </th>
						<th>Play </th>
						<th>Pending </th>

					</tr>
                    <?php
                    	$sqlA1 = 'SELECT id,userCode,name FROM '.$DB->pre.'users WHERE status="1" AND isActive="1" AND underHead="'.$_REQUEST['id'].'" AND userType="2"';
					$A1 = $DB->dbRows($sqlA1);
					foreach($A1 as $A1){
						$sqlR1 = 'SELECT id,userCode,name FROM '.$DB->pre.'users WHERE status="1" AND isActive="1" AND underHead="'.$A1['id'].'" AND userType="3"';
						$R1 = $DB->dbRows($sqlR1);
						foreach($R1 as $R1){
							$sqlL = 'SELECT distinct(barcode),lotdate,lotTime,qtyTot,tranID,lotTime  FROM '.$DB->pre.'lottary WHERE uID="'.$R1['id'].'" AND '.$dateClause;
							$L = $DB->dbRows($sqlL);
							foreach($L as $k=>$L){
							$claim = getPendignClaim1($_REQUEST['id'],$R1['id'],$L['barcode'],$L['lotTime']);
							if($claim >0){
					?>
					<tr>
						<th><?php echo ($k+1)?></th>
						<th><?php echo $L['lotdate'] ?></th>
						<th><?php echo $L['lotTime']?></th>
						<th><a href="<?php echo SITEURL?>/user-sell-ticket/?tranID=<?php echo $L['tranID']?>&u=<?php echo $_REQUEST['u']?>&id=<?php echo $_REQUEST['id']?>"><?php echo $L['tranID']?></th>
						<th><?php echo $R1['userCode']?></th>
						<th><?php echo $L['qtyTot']?></th>
						<th><?php echo $claim;?></th>
					</tr>
                    <?php 
							}
							}
						}
					}
					?>
			</div>

	</div>
<?php

function getPendignClaim1($adminID,$retailer,$barcode,$lotTime){
	global $DB;
	 $sql = 'SELECT distinct(L.barcode),L.cv,L.point FROM '.$DB->pre.'result_tran as R
			LEFT JOIN '.$DB->pre.'lottary as L on R.cellID=L.cellID AND R.sernum=L.sernum AND R.lotnum=L.lotnum AND R.lotdate=L.lotdate
			WHERE R.lotdate="'.date('Y-m-d').'" AND R.uID="'.$adminID.'" AND L.uID="'.$retailer.'" AND barcode="'.$barcode.'" AND R.lotTime="'.$lotTime.'"
			';
	$D = $DB->dbRow($sql);
	$tot = 0;
	$sqlW = 'SELECT winrate FROM '.$DB->pre.'users WHERE id="'.$retailer.'"';
	$W = $DB->dbRow($sqlW);
	
	$sqlR = 'SELECT barcode FROM '.$DB->pre.'result_win WHERE barcode="'.$D['barcode'].'"';
	$R = $DB->dbRow($sqlR);
	if($R['barcode'] == ''){
		$tot +=(($D['point']*$W['winrate'])*$D['cv']);
	}
		
	
	return  $tot;

}
function getPendignClaim($adminID,$retailer,$barcode,$lotTime){
	global $DB;
	  $sql = 'SELECT distinct(L.barcode),L.cv,L.point FROM '.$DB->pre.'result_tran as R
			LEFT JOIN '.$DB->pre.'lottary as L on R.cellID=L.cellID AND R.sernum=L.sernum AND R.lotnum=L.lotnum AND R.lotdate=L.lotdate
			WHERE R.lotdate="'.date('Y-m-d').'" AND R.uID="'.$adminID.'" AND L.uID="'.$retailer.'" AND barcode="'.$barcode.'" AND R.lotTime="'.$lotTime.'" ;
			';
	$D = $DB->dbRows($sql);
	$tot = 0;
	$sqlW = 'SELECT winrate FROM '.$DB->pre.'users WHERE id="'.$retailer.'"';
	$W = $DB->dbRow($sqlW);
	foreach($D as $D){
		if($D['barcode']){
		$sqlR = 'SELECT barcode FROM '.$DB->pre.'result_win WHERE barcode="'.$D['barcode'].'"';
		$R = $DB->dbRow($sqlR);
		if($R['barcode'] == ''){
			$tot +=(($D['point']*$W['winrate'])*$D['cv']);
		}
		}
	}
	return $tot;

}	


?>
</body>
</html>
