<?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' " ;
      $string="Date : $begin to $finish";
  }
  if(isset($_POST['kind'])){
      $kind=$_POST['kind'];
      $sql = "SELECT * FROM cust001 WHERE C_KIND LIKE '%$kind%'" ;
      $string="ประเภท(ธุรกิจ) : $kind";
  }
  if(isset($_POST['name'])){
      $name=$_POST['name'];
      $sql = "SELECT * FROM cust001 WHERE C_NAME LIKE '%$name%' " ;
      $string="ชื่อลูกค้า : $name";
  }
?>
<!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: 'Customer',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>ประเภท</td>
        <td>ชื่อบริษัท</td>
        <td>ที่อยู่</td>
        <td>เบอร์โทร.</td>
        <td>ผู้ติดต่อ</td>
        <td>Tax No.</td>
        <td>ชื่อผู้ขาย</td>
        <td>ส่วนลด(70)</td>
        <td>หมายเหตุ</td>									
      </tr>
    </thead>
    <?php 
        /*$begin='2018-01-01'; $finish='2018-12-30';
        $sql = "SELECT * FROM cust001 WHERE C_DATE BETWEEN '$begin' AND '$finish' " ;*/
        $result = mysqli_query($con,$sql) ;
		while($row = mysqli_fetch_assoc($result)){
    ?>
    <tbody>
      <tr>
        <td><?php echo $row['C_DATE']; ?></td>
        <td><?php echo $row['C_KIND']; ?></td>
        <td><?php echo $row['C_SURNAME'].' '.$row['C_NAME']; ?></td>
        <td><?php echo $row['C_ADRS'].' '.$row['C_DSTRT'].' '.$row['C_PRVN'].' '.$row['C_ZIP']; ?></td>
        <td><?php echo $row['C_TELC1'].'-'.$row['C_TEL1'].','.$row['C_TELC2'].'-'.$row['C_TEL2']; ?></td>
        <td><?php echo $row['C_CONTRCT']; ?></td>
        <td><?php echo $row['C_TAX_NO']; ?></td>
        <td><?php echo $row['C_SMSUR'].' '.$row['C_SMFNAME'].' '.$row['C_SMLNAME']; ?></td>
        <td><?php echo number_format($row['C_DISC'],1); ?></td>
        <td><?php echo $row['NOTE']; ?></td>
      </tr>
	<?php } ?>
    </tbody>
  </table>
</div>   
</body>
</html>