<!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" />
<style>
	.cls-container{
		width:100%;
	}
	.cls-row{
		width:100%;
	}
	.cls-left-sidebar{
		width:70%;
		float:left;
	}
	.cls-right-sidebar{
		width:26%;
		float:right;
		padding-left:10px;
		padding-right:10px;
	}
	.cls-left-sidebar p{
		font-size:18px;
		font-weight:500;
		margin-right:20px;		
	}
	.cls-left-sidebar span a{
		cursor:pointer;
		text-decoration:none;
		margin-left:20px;
		margin-bottom:20px;
	}
	.cls-right-sidebar p{
		margin:0px;
		font-size:13px;
	}
</style>
</head>

<body bgcolor="#CCFF66">
	<div class="cls-container">
    	<div class="cls-row">
    	<div class="cls-left-sidebar">
        	<div class="cls-row" style="display:inline-flex;">
            	<span><a href="<?php echo SITEURL?>/lottery/lottery-account/?userID=<?php echo $_REQUEST['userID']?>&frmdate=<?php echo $_REQUEST['frmdate']?>&todate=<?php echo $_REQUEST['todate']?>">Counter Sale</a></span>
                <span><a href="<?php echo SITEURL?>/lottery/lottery-netpay/?userID=<?php echo $_REQUEST['userID']?>&frmdate=<?php echo $_REQUEST['frmdate']?>&todate=<?php echo $_REQUEST['todate']?>" >Net to Pay</a></span>
            </div>
            <div class="cls-row" style="background-color:#fff;;height:620px;overflow:auto;">
            	<table border="1" bordercolor="#000000" cellspacing="0" style="width:100%;text-align:center;">
                	<thead>
                    	<tr>
                            <th>Date</th>
                            <th>Play</th>
                            <th>Win</th>
                            <th>Cancel</th>
                            <th>Comm</th>
                            <th>Net Amount</th>
                            <th>Bonus</th>
                            <th>Net To Pay</th>
                        </tr>
                    </thead>
                    <tbody>
                    <?php
						$where = '';
						
						$sqlW = 'SELECT commission,bonus FROM '.$DB->pre.'users WHERE id="'.$_REQUEST['userID'].'"';
						$W = $DB->dbRow($sqlW);
						
						if($_REQUEST['frmdate'] == '' && $_REQUEST['todate'] == ''){
							$where = 'lotdate="'.date('Y-m-d').'"';
						}else{
							$where = ' (lotdate between "'.$_REQUEST['frmdate'].'" AND "'.$_REQUEST['todate'].'")';	
						}
                    	$sql = 'SELECT distinct lotdate FROM '.$DB->pre.'lottary WHERE '.$where .' AND uID="'.$_REQUEST['userID'].'" ' ;
                    	$DB->data = array();
						$D = $DB->dbRows($sql);
						
						$tot = 0;
						$tempTot = 0;
						$cancel = 0;
						$tempCancel = 0;
						$win = 0;
						$tempWin = 0;
						$comm = 0;
						$tempComm = 0;
						$netPay = 0;
						$bonus = 0;
						$tempBonus = 0;
						$tempNetAmt = 0;
						$tempNetPay = 0;
						foreach($D as $k=>$D){
							$tot = getSumByDate($D['lotdate']);
							$tempTot += $tot;
							$cancel = getCancelByDate($D['lotdate']);
							$tempCancel += $cancel;
							$win = getWinByDate($D['lotdate']);
							$tempWin += $win;
                         // echo $tot.'--'.$W['commission'];
							$comm = ( (($tot)/100)*$W['commission']);
							$tempComm += $comm;
							$netAmtPay = ($tot-($win+$comm));
							$bonus = (($netAmtPay/100)*$W['bonus']);
							
							$tempBonus += $bonus;
							$tempNetAmt += $netAmtPay;
							$tempNetPay += ($netAmtPay-$bonus);
							
							
					?>
                    	<tr>

                            <td><a href="<?php echo SITEURL?>/lottery/lottery-account-date/?d=<?php echo $D['lotdate'];?>&userID=<?php echo $_REQUEST['userID']?>" style="text-decoration:none;"><?php echo date('d-m-Y',strtotime($D['lotdate']))?></a></td>
                            <td><?php echo $tot;?></td>
                            <td><?php echo $win;?></td>
                            <td><?php echo $cancel;?></td>
                            <td><?php echo $comm;?></td>
                            <td><?php echo ($tot-($win+$comm));?></td>
                            <td><?php echo $bonus?></td>
                            <td><?php echo ($netAmtPay-$bonus)?></td>
                        </tr>
                        <?php } ?>
                    </tbody>
                    <tfoot>
                    	<tr style="background-color:#FC3;">
                            <th>Total</th>
                            <td><?php echo $tempTot?></td>
                            <td><?php echo $tempWin?></td>
                            <td><?php echo $tempCancel;?></td>
                            <td><?php echo $tempComm;?></td>
                            <td><?php echo $tempNetAmt?></td>
                            <td><?php echo $tempBonus?></td>
                            <td><?php echo $tempNetPay?></td>
                        </tr>
                    </tfoot>
                </table>
            </div>
        </div>
        <div class="cls-right-sidebar" style="background-color:#fff;height:636px;overflow:auto;">
        	<div class="cls-row">
            	<h4>User Reports</h4>
                <p>$#$</p>
                <p>Sales Report</p>
                <?php
                	$sqlU = 'SELECT userCode FROM '.$DB->pre.'users WHERE id="'.$_REQUEST['userID'].'"';
                	$DB->data = array();
					$U = $DB->dbRow($sqlU);
				?>
                <p>User ID : <b><?php echo $U['userCode']?></b></p>
                <p>Date From : <b><?php echo date('d-m-Y',strtotime($_REQUEST['frmdate']))?></b></p>
                <p>Date To : <b><?php echo date('d-m-Y',strtotime($_REQUEST['todate']))?></b></p>
            </div>
            <hr />
            
            
            
            <table style="margin-left: 10px; margin-bottom:10px" border="0" width="90%">          	
                	<tr>
                    	<th style="text-align:left;">Sales</th>
                        
                        <td style="text-align:right;"><?php echo $tempTot;?></td>
                    </tr>
              		<tr>
                    	<th style="text-align:left;">Win</th>
                        
                        <td style="text-align:right;"><?php echo $tempWin;?></td>
                    </tr>
                    <tr>
                    	<th style="text-align:left;">Commission</th>
                        
                        <td style="text-align:right;"><?php echo $tempComm;?></td>
                    </tr>
            </table>
            <hr>
            <table style="margin-left: 10px; margin-bottom:10px" border="0" width="90%">            	
                	<tr>
                    	<th style="text-align:left;">Net Amount</th>
                        
                        <td style="text-align:right;">&nbsp;<?php echo $tempNetAmt?></td>
                    </tr>
            </table>
            <table style="margin-left: 10px; margin-bottom:10px" border="0" width="90%">            	
                	<tr>
                    	<th style="text-align:left;">Bonus </th>
                        
                        <td style="text-align:right;"><?php echo $tempBonus?></td>
                    </tr>
            </table>
            <hr>
            <table style="margin-left: 10px; margin-bottom:10px" border="0" width="90%">            	
                	<tr>
                    	<th style="text-align:left;">Net to Pay</th>
                        
                        <td style="text-align:right;"><?php echo $tempNetPay?></td>
                    </tr>
            </table>
            <hr>
            <p><b>Print Date Time : <?php date_default_timezone_set('Asia/Kolkata');echo date('d-m-Y').'&nbsp;&nbsp;'.date('h:i:s')?> </b></p>
        </div>
        </div>
    </div>
</body>
</html>
<?php
function getSumByDate($lotdate){
	global $DB;
	$sql = 'SELECT sum(S) as S from (SELECT ticketTot as S FROM '.$DB->pre.'lottary WHERE status="1" AND lotdate="'.$lotdate.'" AND status="1" AND uID="'.$_REQUEST['userID'].'" group by tranID) as C';
	$DB->data = array();
	$D = $DB->dbRow($sql);
	$tot = 0;
	if($D['S'] > 0){
		$tot = $D['S'];
	}

	return $tot;
}
function getCancelByDate($lotdate){
	global $DB;
	$sql = 'SELECT sum(S) as S from (SELECT ticketTot as S FROM '.$DB->pre.'lottary WHERE lotdate="'.$lotdate.'" AND uID="'.$_REQUEST['userID'].'" AND status="0" group by tranID) as C';
	$DB->data = array();
	$D = $DB->dbRow($sql);
	$tot = 0;
	if($D['S'] > 0){
		$tot = $D['S'];
	}
	
	return $tot;
	
}
function getWinByDate($lotdate){
	global $DB;
	$sql = 'SELECT sum(S) as S from (SELECT claimAmount as S FROM '.$DB->pre.'result_win WHERE date(dateAdded)="'.$lotdate.'" AND uID="'.$_REQUEST['userID'].'"  group by barcode) as C';
	$DB->data = array();
	$D = $DB->dbRow($sql);
	$tot = 0;
	if($D['S'] > 0){
		$tot = $D['S'];
	}
	
	return $tot;
}

?>
