<br><hr><br>
<?php
  session_start();
  include '../_connect.php';
  $ps_name = $_REQUEST["ps_name"];
  if ($ps_name != "") {
    $sql = "SELECT
    	a.ct_no,
    	a.ps_id,
    	a.ps_name,
    	a.serial_no,
    	a.pserial_no,
    	a.product_name,
    	b.REG_EXPIRE,
    	b.PLC_EXPIRE
    FROM EHONGDB.dbo.hps_ctmain a
    left outer join (select
    	REG_EXPIRE,
    	PLC_EXPIRE,
    	SERIAL_NO
    from EHONGDB.dbo.PRODUCT_PRODUCTSERIAL) b on (a.serial_no=b.SERIAL_NO)
    WHERE ps_name = '$ps_name' AND product_id like '%มซ%' 
    order by a.ct_no";
    // echo $sql;
    $select=$conn->prepare($sql);
    $select->execute();
    while ($fetch=$select->fetch()) {
      $ct_no = $fetch['ct_no'];
      $ps_id = $fetch['ps_id'];
      $ps_name = $fetch['ps_name'];
      $serial_no = $fetch['serial_no'];
      $product_name = $fetch['product_name'];
      $pserial_no = $fetch['pserial_no'];

      if ($fetch['REG_EXPIRE'] != '') {
        $REG_EXPIRE1 = substr($fetch['REG_EXPIRE'],0,4)+543; $REG_EXPIRE2 = substr($fetch['REG_EXPIRE'],5,2); $REG_EXPIRE3 = substr($fetch['REG_EXPIRE'],8,2);
        $REG_EXPIRE = $REG_EXPIRE3."/".$REG_EXPIRE2."/".$REG_EXPIRE1;
      } else {
        $REG_EXPIRE = "";
      }
      if ($fetch['PLC_EXPIRE'] != '') {
        $PLC_EXPIRE1 = substr($fetch['PLC_EXPIRE'],0,4)+543; $PLC_EXPIRE2 = substr($fetch['PLC_EXPIRE'],5,2); $PLC_EXPIRE3 = substr($fetch['PLC_EXPIRE'],8,2);
        $PLC_EXPIRE = $PLC_EXPIRE3."/".$PLC_EXPIRE2."/".$PLC_EXPIRE1;
      } else {
        $PLC_EXPIRE = "";
      }
?>
<div class="box-shadowx" align="left">
  <b style="color:brown;">ผู้ซื้อ :</b>  <?php echo $ps_name; ?> <br>
  <b style="color:brown;">สินค้า :</b> <?php echo $product_name; ?> <br>
  <b style="color:brown;">เลขเครื่อง :</b> <?php echo $serial_no; ?> <br>
  <b style="color:brown;">เลขตัวถัง :</b> <?php echo $pserial_no; ?> <br>
  <b style="color:brown;">วันหมดอายุ ทะเบียน :</b> <?php echo $REG_EXPIRE; ?> <br>
  <b style="color:brown;">วันหมดอายุ พ.ร.บ. :</b> <?php echo $PLC_EXPIRE; ?>
  <hr>
  <center>
    <a href="img_rb.php?ct_no=<?php echo $ct_no; ?>"><input type="submit" name="" class="button_1 button1_1" value="ขอสำเนาหน้าเล่ม"></a>
  </center>
</div>
<br>
<?php } ?>
<?php } else { ?>
  <div class="box-shadowx">
    ไม่พบข้อมูล
  </div>
<?php } ?>
