<!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" />
<title>Untitled Document</title>
<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;
	}
	.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>Counter Sale</a></span>
                <span><a>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" cellpadding="3" style="width:100%;text-align:center;font-size:18px;font-weight:600;">
                	<thead>
                    	<tr>
                        	<th></th>
                            <th>Lot Date Time</th>
                            <th>TranNo</th>
                            <th>Lot Print Time</th>
                            <th>Point</th>
                            <th>Win</th>
                            <th>Cancel</th>
                        </tr>
                    </thead>
                    <tbody>
                    <?php
                    	$sql = 'SELECT * FROM '.$DB->pre.'lottary WHERE lotdate="'.$_REQUEST['d'].'" AND uID="'.$_REQUEST['userID'].'" GROUP BY tranID';
						$D = $DB->dbRows($sql);
						foreach($D as $D){
					?>
                    	<tr <?php echo ($D['status']=='0'?'style="background-color:#F780E4"':'');?> >
                        	<td><?php echo ($D['status']=='0'?'Cancel':'');?></td>
                            <td><?php echo $D['lotdate']?> <?php echo $D['lotTime']?></td>
                            <td><?php echo $D['tranID']?></td>
                            <td><?php echo $D['lotdate']?> <?php echo $D['printTime']?></td>
                            <td><?php echo $D['ticketTot']?></td>
                            <td><?php
                              		$sqlCT = 'SELECT claimAmount FROM '.$DB->pre.'result_win WHERE barcode="'.$D['barcode'].'"';
                          			$CT = $DB->dbRow($sqlCT);
                          			echo $CT['claimAmount'].'/-';
                              ?></td>
                            <td>00</td>
                        </tr>
                        <?php }?>
                    </tbody>
                </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>
                <p>User ID : <b>KD</b></p>
                <p>Date From : <b>10/03/2021</b></p>
                <p>Date To : <b>11/03/2021</b></p>
            </div>
            <hr />
            <table border="1" style="width:100%;margin-bottom:10px;" cellspacing="0" cellpadding="3">
            	<thead>
                	<tr>
                    	<th>Date</th>
                        <th>Play</th>
                        <th>Win</th>
                        <th>Cancel</th>
                        <th>Point</th>
                    </tr>
                </thead>
                <tbody>
                <?php 
					$sql = 'SELECT ticketTot as S FROM '.$DB->pre.'lottary WHERE lotdate="'.$_REQUEST['d'].'" AND uID="'.$_REQUEST['userID'].'" group by tranID';
					$D = $DB->dbRows($sql);
					$totSale = 0;
					$win = 0;
					$cancel = 0;
					foreach($D as $D){
						$totSale += $D['S'];
						$win = getWinByDate1($_REQUEST['d']);
						$cancel = getCancelByDate1($_REQUEST['d']);
					}
				?>
                	<tr>
                    	<td><?php echo date('d-m-Y',strtotime($_REQUEST['d']))?></td>
                        <td><?php echo $totSale?></td>
                        <td><?php echo getWinByDate1($_REQUEST['d'])?></td>
                        <td><?php echo getCancelByDate1($_REQUEST['d'])?></td>
                        <td><?php echo ($totSale-($win+$cancel));?></td>
                    </tr>
                	<tr>
                    	<th>Total</th>
                        <td><?php echo $totSale;?></td>
                        <td><?php echo $win?></td>
                        <td><?php echo $cancel?></td>
                        <td><?php echo ($totSale-($win+$cancel));?></td>
                    </tr>
                </tbody>
            </table>
        </div>
        </div>
    </div>
</body>
</html>

<?php

function getCancelByBarcode($lotdate){
	global $DB;
	$sql = 'SELECT ticketTot as S FROM '.$DB->pre.'lottary WHERE lotdate="'.$lotdate.'" AND uID="'.$_REQUEST['userID'].'" AND status="0" group by tranID';
	$D = $DB->dbRows($sql);
	$tot = 0;
	foreach($D as $D){
		$tot += $D['S'];
	}
	
	return $tot;
	
}
function getWinByBarcode($lotdate){
	global $DB;
	$sql = 'SELECT claimAmount as S FROM '.$DB->pre.'result_win WHERE date(dateAdded)="'.$lotdate.'" AND uID="'.$_REQUEST['userID'].'"  group by barcode';
	$D = $DB->dbRows($sql);
	$tot = 0;
	foreach($D as $D){
		$tot += $D['S'];
	}
	
	return $tot;
}
function getCancelByDate1($lotdate){
	global $DB;
	$sql = 'SELECT ticketTot as S FROM '.$DB->pre.'lottary WHERE lotdate="'.$lotdate.'" AND uID="'.$_REQUEST['userID'].'" AND status="0" group by tranID';
	$D = $DB->dbRows($sql);
	$tot = 0;
	foreach($D as $D){
		$tot += $D['S'];
	}
	
	return $tot;
	
}
function getWinByDate1($lotdate){
	global $DB;
	$sql = 'SELECT claimAmount as S FROM '.$DB->pre.'result_win WHERE date(dateAdded)="'.$lotdate.'" AND uID="'.$_REQUEST['userID'].'"  group by barcode';
	$D = $DB->dbRows($sql);
	$tot = 0;
	foreach($D as $D){
		$tot += $D['S'];
	}
	
	return $tot;
}


?>
