<?php 
include "../functions/dblink.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";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/excellentexport@3.7.0/dist/excellentexport.min.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
          }
        .container {
            width: 1200px;
            margin: 50px auto;
        }
        .flex-container { 
            display: flex;
        }
        .btn-export {
            background: #1abc9c;
            color: #fff;
            width: 150px;
            height: 35px;
            cursor: pointer;
            border-radius: 5px;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        .table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 10px;
        }
        .table td {
            border: 1px solid #000;
            padding: 5px;
        }
    </style>
</head>
<body>
<div class="container" style="margin-left: 10px;">
  <div class="flex-container">
  <a id="autoexport" onclick="return ExcellentExport.convert({anchor: this,filename: 'Quotation',format: 'xlsx'},
                    [{name: 'tab1',from: {table: 'table_master'}}]
              )" 
     class="btn-export" style="text-decoration: none">
    Export DB->XLSX
  </a>
  <?php session_start();
    if($_SESSION['Status']=='ADMIN'){ ?>
        <a href="../home.php" class="btn-export" style="margin-left: 5px; text-decoration: none;">Home</a>
    <?php }else{ ?>
        <a href="../homeOther.php" class="btn-export" style="margin-left: 5px; text-decoration: none;">Home</a>
    <?php } ?>
  <a href="../logout.php" class="btn-export" style="margin-left: 5px; text-decoration: none;">Logout</a>
  <a style="margin: 8px 10px;"><?php echo $string;?></a>
  </div>

  <table id="table_master" class="table">
    <thead>
      <tr>

        <td>Date</td>
        <td>Quot.No.</td>
        <td>Cust.Name</td>
        <td>ส่วนลด</td>
        <td>สินค้า1</td>
        <td>จำนวน</td>
        <td>สินค้า2</td>
        <td>จำนวน</td>
        <td>สินค้า3</td>
        <td>จำนวน</td>
        <td>สินค้า4</td>
        <td>จำนวน</td>
        <td>สินค้า5</td>
        <td>จำนวน</td>
        <td>สินค้า6</td>
        <td>จำนวน</td>
        <td>สินค้า7</td>
        <td>จำนวน</td>
        <td>สินค้า8</td>
        <td>จำนวน</td>
        <td>สินค้า9</td>
        <td>จำนวน</td>
        <td>สินค้า10</td>
        <td>จำนวน</td>
        <td>ผู้ขาย</td>
        <td>เงิน(บาท)</td>									
      </tr>
    </thead>
    <?php
        
    $result = mysqli_query($con,$sql) ;
		while($row = mysqli_fetch_assoc($result)){
    ?>
    <tbody>
      <tr>

        <td><?php echo $row['QDATE']; ?></td>
        <td><?php echo $row['QNO']; ?></td>
        <td><?php echo $row['QC_NAME']; ?></td>
        <td><?php echo $row['QC_DISC']; ?></td>
        <td><?php echo $row['QPDNAME1']; ?></td>
        <td><?php echo number_format($row['QQTY1']); ?></td>
        <td><?php echo $row['QPDNAME2']; ?></td>
        <td><?php echo number_format($row['QQTY2']); ?></td>
        <td><?php echo $row['QPDNAME3']; ?></td>
        <td><?php echo number_format($row['QQTY3']); ?></td>
        <td><?php echo $row['QPDNAME4']; ?></td>
        <td><?php echo number_format($row['QQTY4']); ?></td>
        <td><?php echo $row['QPDNAME5']; ?></td>
        <td><?php echo number_format($row['QQTY5']); ?></td>
        <td><?php echo $row['QPDNAME6']; ?></td>
        <td><?php echo number_format($row['QQTY6']); ?></td>
        <td><?php echo $row['QPDNAME7']; ?></td>
        <td><?php echo number_format($row['QQTY7']); ?></td>
        <td><?php echo $row['QPDNAME8']; ?></td>
        <td><?php echo number_format($row['QQTY8']); ?></td>
        <td><?php echo $row['QPDNAME9']; ?></td>
        <td><?php echo number_format($row['QQTY9']); ?></td>
        <td><?php echo $row['QPDNAME10']; ?></td>
        <td><?php echo number_format($row['QQTY10']); ?></td>
        <td><?php echo $row['QSMFNAME']; ?></td>
        <td><?php echo number_format($row['QSUM']); ?></td>
      </tr>
	<?php } ?>
    </tbody>
  </table>
</div>   
</body>
</html>