<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>EHONGMD</title>
  <?php
  include '_plugin.php';
  include '_connect.php';
?>
</head>
<body class="hold-transition skin-red sidebar-mini">
<div class="wrapper">

<?php
include '_header.php';
include '_menu.php';
?>
  <div class="content-wrapper">
    <section class="content">
      <div class="row">
      <!-- ค้นหา -->
      <!-- ตาราง -->
      <?php include 'act_search_3.php' ?>
      <?php
        $Y = date('Y')+543;
        $Eday = date('d');
        $year = date('Y');
        $month2 = date('m');
        $Eday1 = date('Y-m-t',strtotime($year."-".$month2."-".'01'));
        $Eday2 = substr($Eday1,8,2);
        $day1 = $year."-01-01";
        $day2 = $year."-".$month2."-".$Eday;
      ?>
      <div class="col-md-4">
        <div class="box box-warning">
          <div class="box-header with-border">
            <h3 class="box-title">ค้นหาเลขสัญญา</h3>
          </div>
          <form role="form" action="act_index_new3.php" method="POST" enctype="multipart/form-data" target="">
            <div class="box-body">
              <div class="row">
                <div class="col-xs-4">
                  <p>วันที่</p>
                  <input type="date" class="form-control" placeholder="" name="DMY_1" value="<?php echo $day1; ?>">
                </div>
                <div class="col-xs-4">
                  <p>ถึงวันที่</p>
                  <input type="date" class="form-control" placeholder="" name="DMY_2" value="<?php echo $day2; ?>">
                </div>
              </div>
            </div>
            <div class="box-footer">
              <input type="submit" name="submit4" class="btn btn-warning" value="ค้นหา">
            </div>

          </form>
        </div>
      </div>

      <?php
        if (isset($_POST['submit4'])) {
          $DMY_1 = $_POST['DMY_1'];
          $DMY_2 = $_POST['DMY_2'];
      ?>
      <div class="col-md-12">
        <div class="box box-success">
          <div class="box-header">
            <h3 class="box-title"><p class="text-success">รายงานรถตีเทิร์น</p></h3>
          </div>
          <div class="box-body">
            <div class="form-group">
              <table id="example" class="table table-striped table-bordered" style="width:100%">
                <thead style="white-space: nowrap">
                  <tr>
                    <th rowspan="" style="background-color:black; color:#fff; text-align:center;"><b>No.</b></th>
                    <td rowspan="" style="background-color:black; color:#fff; text-align:center;">เพิ่ม</td>
                    <th rowspan="" style="background-color:black; color:#fff; text-align:center;"><b>#ใบตีเทิร์น</b></th>
                    <td rowspan="" style="background-color:black; color:#fff; text-align:center;">ประเภท</td>
                    <th rowspan="" style="background-color:black; color:#fff; text-align:center;"><b>วันที่</b></th>
                    <th rowspan="" style="background-color:black; color:#fff; text-align:center;"><b>ชื่อ-นามสกุลลูกค้า</b></th>
                    <th rowspan="" style="background-color:yellow; color:#000; text-align:center;"><b>เลขเครื่อง</b></th>
                    <th rowspan="" style="background-color:black; color:#fff; text-align:center;"><b>เลขตัวถัง</b></th>
                    <th rowspan="" style="background-color:black; color:#fff; text-align:center;"><b>ยี่ห้อ</b></th>
                    <th rowspan="" style="background-color:black; color:#fff; text-align:center;"><b>ยอดตีเทิร์นทั้งหมด</b></th>
                    <th rowspan="" style="background-color:black; color:#fff; text-align:center;"><b>ยอดตีเทิร์นรถใหม่</b></th>
                    <th rowspan="" style="background-color:black; color:#fff; text-align:center;"><b>ยอดเงินคืน</b></th>
                    <th rowspan="" style="background-color:black; color:#fff; text-align:center;"><b>สถานะ</b></th>

                  </tr>
                </thead>
                <tbody style="white-space: nowrap">
                  <?php
                  $sql = "SELECT * FROM EHONGDB.dbo.product_turnbill WHERE bill_date between '$DMY_1' and '$DMY_2'";
                  // echo $sql;
                  $select=$conn->prepare($sql);
                  $select->execute();
                  $item = 1;
                  while($fetch=$select->fetch()){
                    if ($fetch['BILL_DATE'] != '') {
                      $BILL_DATE1 = substr($fetch['BILL_DATE'],0,4)+543; $BILL_DATE2 = substr($fetch['BILL_DATE'],5,2); $BILL_DATE3 = substr($fetch['BILL_DATE'],8,2);
                      $BILL_DATE = $BILL_DATE3."/".$BILL_DATE2."/".$BILL_DATE1;
                    } else {
                      $BILL_DATE = '';
                    }
                  ?>
                  <tr>
                    <td style="background-color:; color:; text-align:right;"><?php echo number_format($item); ?>.</td>
                    <td style="background-color:; color:red; text-align:center;"> <a href="act_insert_return.php?BILL_NO=<?php echo $fetch['BILL_NO']; ?>"> เพิ่ม </a> </td>
                    <td style="background-color:; color:red; text-align:;"><?php echo $fetch['BILL_NO']; ?></td>
                    <td style="background-color:; color:red; text-align:center;;"><?php echo $fetch['BUY_TYPE']; ?></td>
                    <td style="background-color:; color:; text-align:;"><?php echo $BILL_DATE; ?></td>
                    <td style="background-color:; color:red; text-align:;"><?php echo $fetch['PS_NAME']; ?></td>
                    <td style="background-color:; color:; text-align:;"><?php echo $fetch['SERIAL_NO']; ?></td>
                    <td style="background-color:; color:; text-align:;"><?php echo $fetch['PSERIAL_NO']; ?></td>
                    <td style="background-color:; color:; text-align:;"><?php echo $fetch['BRAND_NAME']; ?></td>
                    <td style="background-color:; color:red; text-align:;"><?php echo $fetch['SUM_TOTAL']; ?></td>
                    <td style="background-color:; color:red; text-align:;"><?php echo $fetch['SUM_MONEY1']; ?></td>
                    <td style="background-color:; color:red; text-align:;"><?php echo $fetch['SUM_MONEY2']; ?></td>
                    <td style="background-color:; color:red; text-align:;"><?php echo $fetch['STATUS']; ?></td>
                  </tr>
                  <?php $item++; } ?>
                </tbody>
            </table>
            </div>
          </div>
        </div>
      </div>
      <?php
        }
      ?>

      </div>
    </section>
  </div>
</div>




<?php
include '_footer.php';
include '_form.php';
?>
<div class="control-sidebar-bg"></div>
<?php include '_script_2.php'; ?>
<?php include 'scroll.php' ?>
</body>
</html>
