<?php
include "../functions/dblink.php" ;
if(isset($_POST['begin']) and isset($_POST['finish'])){
	$begin=$_POST['begin'];
	$finish=$_POST['finish'];
	$sql = "SELECT * FROM cust001 WHERE C_DATE BETWEEN '$begin' AND '$finish' " ;
}
if(isset($_POST['kind'])){
	$kind=$_POST['kind'];
	$sql = "SELECT * FROM cust001 WHERE C_KIND LIKE '%$kind%' " ;
}
if(isset($_POST['name'])){
	$name=$_POST['name'];
	$sql = "SELECT * FROM cust001 WHERE C_NAME LIKE '%$name%' " ;
}

if(isset($_GET['act'])){
	if($_GET['act']== 'excel'){
		header("Content-Type: application/xls");
		header("Content-Disposition: attachment; filename=Customer.xls");
		header("Pragma: no-cache");
		header("Expires: 0");
	}
}
?>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>Customer 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>DB EXPORT TO EXCEL</h4>
					<div style="width: 500px;">
					<p>
						<a href="?act=excel" class="btn btn-primary"> Customer Export->Excel </a>
						<a href="custExportForm.php" class="btn btn-primary"> Previous Menu </a>
						<a href="../home.php" class="btn btn-primary"> Home </a>
						<a href="../logout" 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;">ประเภท</th>
								<th style="text-align: center;">ชื่อบริษัท</th>
								<th style="text-align: center;">ที่อยู่</th>
								<th style="text-align: center;">เบอร์โทร.</th>
                                <th style="text-align: center;">ผู้ติดต่อ</th>
								<th style="text-align: center;">Tax No.</th>
								<th style="text-align: center;">ชื่อผู้ขาย</th>
								<th style="text-align: center;">ส่วนลด(70)</th>
								<th style="text-align: center;">หมายเหตุ</th>									
							</tr>
						</thead>
						<?php
							/*include "../functions/dblink.php" ;
							$sql = "SELECT * FROM cust001 WHERE C_DATE BETWEEN '$begin' AND '$finish' " ;*/
							$result = mysqli_query($con,$sql) ;
							while($row = mysqli_fetch_assoc($result)){ ?>
								<tr>
                                    <td style="text-align: left;"><?php echo $row['C_DATE']; ?></td>
									<td style="text-align: left;"><?php echo $row['C_KIND']; ?></td>
									<td style="text-align: left;"><?php echo $row['C_SURNAME'].' '.$row['C_NAME']; ?></td>
									<td style="text-align: left;"><?php echo $row['C_ADRS'].' '.$row['C_DSTRT'].' '.$row['C_PRVN'].' '.$row['C_ZIP']; ?></td>
									<td style="text-align: left;"><?php echo $row['C_TELC1'].'-'.$row['C_TEL1'].','.$row['C_TELC2'].'-'.$row['C_TEL2']; ?></td>
									<td style="text-align: left;"><?php echo $row['C_CONTRCT']; ?></td>
									<td style="text-align: left;"><?php echo $row['C_TAX_NO']; ?></td>
									<td style="text-align: left;"><?php echo $row['C_SMSUR'].' '.$row['C_SMFNAME'].' '.$row['C_SMLNAME']; ?></td>
									<td style="text-align: center;"><?php echo number_format($row['C_DISC'],1); ?></td>
                                    <td style="text-align: left;"><?php echo $row['NOTE']; ?></td>
								</tr>
						<?php } ?>
					</table>
				</div>
			</div>
		</div>
	</body>
</html>