<?php include('../../connectdb.inc.php'); ?>
<html>
<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" href="<?php echo SITEURL?>/css/net/netIE7IE8.css">
<![endif]-->

<!--[if IE 8]>
<link rel="stylesheet" href="<?php echo SITEURL?>/css/net/netIE7IE8.css">
<![endif]-->

<?php
	preg_match('/MSIE (.*?);/', $_SERVER['HTTP_USER_AGENT'], $matches);
	if(count($matches)<2){
	  preg_match('/Trident\/\d{1,2}.\d{1,2}; rv:([0-9]*)/', $_SERVER['HTTP_USER_AGENT'], $matches);
	}
	if($matches[1] > 8){
	?>
    <link rel="stylesheet" href="<?php echo SITEURL?>/css/net/netIE10.css">
    <?php
	}
?>




<style>
	


	.salsePrint1{width:250px; border: 0px solid black;}
	.salsePrint2{font-weight: 700; padding-left: 5px; list-style-type:none;}
	.salsePrint3{width:100%;font-weight: lighter; padding-left: 1rem; margin-left:0px; border:0px solid red;}
	.salsePrint3_1{width:45%; font-weight:900; display:inline-block;}
	.salsePrint3_2{width:45%;display:inline-block;}
	.salsePrint4{font-weight: 600; margin-top: 15px;list-style-type:none;padding-left:1rem;}


@media print {
  body {
		height: auto;
		width:100% ;
		font-size:12px;
		letter-spacing:1px;
		line-height:13px;
		margin-top:-8%;
		margin-left:0 !important;
	}
	.container .a-form{
		width:180px !important;
	}
	.bx1_only_print{
		line-height:12px;
		width:40px !important;
	}
	.name{
		margin-bottom:0%;
	}
	.tick01{
		display:inline-flex;
	}
	.tick01 .bx1_only_print{
		width:65px !important;
	}
	.tick01 .bx2_only_print{
		width:30px !important;
	}
}
</style>
</head>

<body style="">
	<div class="container">
		<?php
			$DB->data = array();
        	$sqlW = 'SELECT commission,bonus,userCode FROM '.$DB->pre.'users WHERE id="'.$_REQUEST['userID'].'"';
			$W = $DB->dbRow($sqlW);

			
		?>

		<div class="row">
			<div class="a-form salsePrint1">
				<ul class="tick_li salsePrint2">
					<li><img src="<?php echo SITEURL?>/images/logo.png">Rashree</li>
					<li>Sales Report</li>
					<li>User ID : <?php echo $W['userCode']?></li>
					<li>Date From: <?php echo $_REQUEST['frmdate']?></li>
					<li>Date To: <?php echo $_REQUEST['todate']?></li>
				</ul>
                <?php
					$where = ' (lotdate between "'.$_REQUEST['frmdate'].'" AND "'.$_REQUEST['todate'].'")';
					$DB->data = array();
					$sql = 'SELECT lotdate FROM '.$DB->pre.'lottary WHERE '.$where .' AND uID="'.$_REQUEST['userID'].'" GROUP BY lotdate' ;
					$D = $DB->dbRows($sql);
						
						$tot = 0;
						$cancel = 0;
						$win = 0;
						$comm = 0;
						$tempComm = 0;
						$netPay = 0;
						$bonus = 0;
						$tempBonus = 0;
						$tempNetAmt = 0;
						$tempNetPay = 0;
						foreach($D as $k=>$D){
							$tot += getSumByDate1($D['lotdate']);
						//	echo $cancel += getCancelByDate1($D['lotdate']);
							$win += getWinByDate1($D['lotdate']);
							$comm = (($tot/100)*$W['commission']);
							$tempComm += $comm;
							$netAmtPay = ($tot-($win+$comm));
							$bonus = (($netAmtPay/100)*$W['bonus']);
							
							$tempBonus += $bonus;
							$tempNetAmt += $netAmtPay;
							 $tempNetPay = ($netAmtPay-$bonus);
							
							
					 } ?>
				<div class="row">
					<hr>

					<div class="ticket_2 salsePrint3">

                                 <div class="salsePrint3_1">
                                 <b>Sale</b>
                                 </div>
                                 
                                 <div class="salsePrint3_2">
                                 	<b><?php echo $tot?></b>
                                 </div>
					</div>
					<hr>

					<div class="ticket_2 salsePrint3">

                                 <div class="salsePrint3_1">
                                 <b>Winning</b>
                                 </div>
                                 
                                 <div class="salsePrint3_2">
                                 	<b><?php echo $win?></b>
                                 </div>
					</div>
					<div class="ticket_2 salsePrint3">

                                 <div class="salsePrint3_1">
                                 <b>Commission</b>
                                 </div>
                                 
                                 <div class="salsePrint3_2">
                                 	<b><?php echo $comm?></b>
                                 </div>
					</div>
					<hr>

					<div class="ticket_2 salsePrint3">

                                 <div class="salsePrint3_1">
                                 	<b>Net Amount</b>
                                 </div>
                                 
                                 <div class="salsePrint3_2">
                                 	<b><?php echo $netAmtPay?></b>
                                 </div>
					</div>
					
					<div class="ticket_2 salsePrint3">

                                 <div class="salsePrint3_1">
                                 	<b>Bonus</b>
                                 </div>
                                 
                                 <div class="salsePrint3_2">
                                 	<b><?php echo $bonus?></b>
                                 </div>
					</div>
					<hr>

					<div class="ticket_2 salsePrint3">

                                 <div class="salsePrint3_1">
                                 	<b>Net To Pay</b>
                                 </div>
                                 
                                 <div class="salsePrint3_2">
                                 	<b><?php echo $tempNetPay;?></b>
                                 </div>
					</div>
					<hr>
					
				</div>

				<div class="text_second_only_print">
					<ul class="tick_li_print salsePrint4">
                    <?php date_default_timezone_set('Asia/Kolkata');?>
						<li>Print Date  : <?php echo date('d-M-Y')?> </li>
						<li>Print Time  : <?php echo date('h:i:s')?></li>
					</ul>
				</div>

 
			</div>
				
			
		</div>

	</div>

</body>
</html>

<?php
function getSumByDate1($lotdate){
	global $DB;
//	$sql = 'SELECT ticketTot as S FROM '.$DB->pre.'lottary WHERE status="1" AND lotdate="'.$lotdate.'" AND uID="'.$_REQUEST['userID'].'" group by tranID';
$DB->data = array();
	$sql = 'SELECT sum(S) as S from (SELECT ticketTot as S FROM '.$DB->pre.'lottary WHERE status="1" AND lotdate="'.$lotdate.'" AND uID="'.$_REQUEST['userID'].'" AND status="1" group by tranID) as C';
	$D = $DB->dbRow($sql);
	$tot = 0;
	if($D['S'] > 0){
    	$tot = $D['S'];
     }
	return $tot;
}
function getCancelByDate1($lotdate){
	global $DB;
	$DB->data = array();
	$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';
	$D = $DB->dbRow($sql);
	$tot = 0;
	if($D[S] > 0){
    	$tot = $D['S'];
    }
	
	return $tot;
	
}
function getWinByDate1($lotdate){
	global $DB;
	$DB->data = array();
$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';
	$D = $DB->dbRow($sql);
	$tot = 0;
	if($D['S'] > 0){
    	$tot = $D['S'];
    }
	
	return $tot;
}

?>
