<?php
if(isset($_POST['begin']) AND isset($_POST['finish'])){
	$begin=$_POST['begin'];
	$finish=$_POST['finish'];$sql = "SELECT * FROM quot002 
	WHERE (QDATE BETWEEN '$begin' AND '$finish') AND (QLOCK=0 OR QLOCK='' OR QLOCK IS NULL)";
	$prev="href='quotExportForm.php' ";
	$string="Quotation Date : $begin to $finish";
}
if(isset($_POST['no1']) AND isset($_POST['no2'])){
	$no1=$_POST['no1'];
	$no2=$_POST['no2'];
	$sql = "SELECT * FROM quot002 
	WHERE (QNO BETWEEN '$no1' AND '$no2') AND (QLOCK=0 OR QLOCK='' OR QLOCK IS NULL) ";
	$prev="href='quotExportFormNo.php' ";
	$string="Quotation No. : $no1 to $no2";
}
if(isset($_POST['name'])){
	$name=$_POST['name'];
	$sql = "SELECT * FROM quot002 
	WHERE (QC_NAME LIKE '%$name%') AND (QLOCK=0 OR QLOCK='' OR QLOCK IS NULL) ";
	$prev="href='quotExportFormName.php' ";
	$string="ชื่อลูกค้า : $name";
}
if(isset($_POST['sell'])){
	$sell=$_POST['sell'];
	$sql = "SELECT * FROM quot002 
	WHERE (QSMFNAME LIKE '%$sell%') AND (QLOCK=0 OR QLOCK='' OR QLOCK IS NULL) ";
	$prev="href='quotExportFormSell.php' ";
	$string="ชื่อพนักงานขาย : $sell";
}

if(isset($_GET['act'])){
	if($_GET['act']=='excel'){
		header("Content-Type: application/xls");
		header("Content-Disposition: attachment; filename=Quotation.xls");
		header("Pragma: no-cache");
		header("Expires: 0");
	}
}
?>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>Quotation DB Export To Excel</title>
		<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
	</head>
	<body>
		<div class="container">
			<div class="row">
				<div class="col-md-5">
					<br /><br /><br />
					<h4 style="width: 800px;">DB EXPORT TO EXCEL</h4>
					<div style="width: 500px;">
						<p>
							<a href="?act=excel" class="btn btn-primary"> Quotation Export->Excel </a>
							<a href="quotExportForm.php" class="btn btn-primary"> Previous Menu </a>
							<?php session_start();
							if($_SESSION['Status']=='ADMIN'){ ?>
								<a href="../home.php" class="btn btn-primary"> Home </a>
							<?php }else{ ?>
								<a href="../homeOther.php" class="btn btn-primary"> Home </a>
							<?php } ?>  
							<a href="../logout.php" class="btn btn-primary"> Logout </a>
						</p>
					</div>
					
					<table border="1" class="table table-hover">
						<thead>
							<tr>
								<th style="text-align: center;">Date</th>
								<th style="text-align: center;">Quot.No.</th>
								<th style="text-align: center;">Cust.Name</th>
								<th style="text-align: center;">ส่วนลด</th>
								<th style="text-align: center;">สินค้า1</th>
                                <th style="text-align: center;">จำนวน</th>
                                <th style="text-align: center;">สินค้า2</th>
                                <th style="text-align: center;">จำนวน</th>
                                <th style="text-align: center;">สินค้า3</th>
                                <th style="text-align: center;">จำนวน</th>
                                <th style="text-align: center;">สินค้า4</th>
                                <th style="text-align: center;">จำนวน</th>
                                <th style="text-align: center;">สินค้า5</th>
                                <th style="text-align: center;">จำนวน</th>
                                <th style="text-align: center;">สินค้า6</th>
                                <th style="text-align: center;">จำนวน</th>
                                <th style="text-align: center;">สินค้า7</th>
                                <th style="text-align: center;">จำนวน</th>
                                <th style="text-align: center;">สินค้า8</th>
                                <th style="text-align: center;">จำนวน</th>
                                <th style="text-align: center;">สินค้า9</th>
                                <th style="text-align: center;">จำนวน</th>
                                <th style="text-align: center;">สินค้า10</th>
                                <th style="text-align: center;">จำนวน</th>
                                <th style="text-align: center;">ผู้ขาย</th>
								<th style="text-align: center;">เงิน(บาท)</th>									
							</tr>
						</thead>
						<?php
							include "../functions/dblink.php" ;
                            $result = mysqli_query($con,$sql) ;
							while($row = mysqli_fetch_assoc($result)){ ?>
								<tr>
                                    <td style="text-align: left;"><?php echo $row['QDATE']; ?></td>
									<td style="text-align: left;"><?php echo $row['QNO']; ?></td>
									<td style="text-align: left;"><?php echo $row['QC_NAME']; ?></td>
									<td style="text-align: left;"><?php echo $row['QC_DISC']; ?></td>
									<td style="text-align: left;"><?php echo $row['QPDNAME1']; ?></td>
									<td style="text-align: right;"><?php echo number_format($row['QQTY1']); ?></td>
                                    <td style="text-align: left;"><?php echo $row['QPDNAME2']; ?></td>
									<td style="text-align: right;"><?php echo number_format($row['QQTY2']); ?></td>
                                    <td style="text-align: left;"><?php echo $row['QPDNAME3']; ?></td>
									<td style="text-align: right;"><?php echo number_format($row['QQTY3']); ?></td>
                                    <td style="text-align: left;"><?php echo $row['QPDNAME4']; ?></td>
									<td style="text-align: right;"><?php echo number_format($row['QQTY4']); ?></td>
                                    <td style="text-align: left;"><?php echo $row['QPDNAME5']; ?></td>
									<td style="text-align: right;"><?php echo number_format($row['QQTY5']); ?></td>
                                    <td style="text-align: left;"><?php echo $row['QPDNAME6']; ?></td>
									<td style="text-align: right;"><?php echo number_format($row['QQTY6']); ?></td>
                                    <td style="text-align: left;"><?php echo $row['QPDNAME7']; ?></td>
									<td style="text-align: right;"><?php echo number_format($row['QQTY7']); ?></td>
                                    <td style="text-align: left;"><?php echo $row['QPDNAME8']; ?></td>
									<td style="text-align: right;"><?php echo number_format($row['QQTY8']); ?></td>
                                    <td style="text-align: left;"><?php echo $row['QPDNAME9']; ?></td>
									<td style="text-align: right;"><?php echo number_format($row['QQTY9']); ?></td>
                                    <td style="text-align: left;"><?php echo $row['QPDNAME10']; ?></td>
									<td style="text-align: right;"><?php echo number_format($row['QQTY10']); ?></td>
                                    <td style="text-align: left;"><?php echo $row['QSMFNAME']; ?></td>
									<td style="text-align: right;"><?php echo number_format($row['QSUM']); ?></td>
								</tr>
						<?php } ?>
					</table>
				</div>
			</div>
		</div>
	</body>
</html>