<?php //error_reporting(0); ?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>EHONGMD | รายงานทะเบียนตรวจสอบ</title>
  <script src="bower_components/jquery/dist/jquery.min.js"></script>
  <link rel="shortcut icon" href="dist/img/logo_1.png" />
  <?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
      $BR_IDS = $_REQUEST['BR_IDS'];
      $ZSONE_CODES = $_REQUEST['ZSONE_CODES'];
      $ZSTAFFS = $_REQUEST['ZSTAFFS'];
      $ST = $_REQUEST['ST'];
      $date_1 = $_REQUEST['datetb'];

      if ($BR_IDS != "") {
        $idcoed_1 = "and ax.BR_ID = '$BR_IDS'";
      }
      else {
        $idcoed_1 = "";
      }
      if ($ZSONE_CODES != "") {
        $idcoed_2 = "and bx.szone_code = '$ZSONE_CODES'";
      }
      else {
        $idcoed_2 = "";
      }
      if ($ZSTAFFS != "") {
        $idcoed_3 = "and bx.zstaff_id = '$ZSTAFFS'";
      }
      else {
        $idcoed_3 = "";
      }

      if ($ST == "b2_x1") {
        $b2st = "AND YEAR(a.rt_date) $date_1";
      }
      if ($ST == "b2_x2") {
        $b2st = "AND YEAR(a.rt_date) $date_1";
      }
      if ($ST == "b2_x3") {
        $b2st = "AND YEAR(a.rt_date) $date_1";
      }
      if ($ST == "b2") {
        $b2st = "";
      }
      ?>
      <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">
              <!-- example31 -->
              <div style="overflow-x:auto;">
                <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;">NO.</th>
                      <th rowspan="" style="background-color:black; color:#fff; text-align:center;">ยอดคืนเงิน</th>
                      <th colspan="" style="background-color:black; color:#fff; text-align:center;">สถานะ</th>
                      <th colspan="" style="background-color:black; color:#fff; text-align:center;">หมายเหตุ</th>
                      <th colspan="" style="background-color:black; color:#fff; text-align:center;">ใบฝากเงิน</th>
                      <th rowspan="" style="background-color:black; color:#fff; text-align:center;">วันที่ฝาก</th>
                      <th colspan="" style="background-color:black; color:#fff; text-align:center;">ยอดเบิกเงิน</th>
                      <th colspan="" style="background-color:black; color:#fff; text-align:center;">#สั่งทำ</th>
                      <th colspan="" style="background-color:black; color:#fff; text-align:center;">#สัญญา</th>
                      <th colspan="" style="background-color:black; color:#fff; text-align:center;">ชื่อ-สกุล ลูกค้า</th>
                      <th colspan="" style="background-color:black; color:#fff; text-align:center;">สาขา</th>
                      <th colspan="" style="background-color:black; color:#fff; text-align:center;">รายการ</th>
                      <th colspan="" style="background-color:black; color:#fff; text-align:center;">วันเบิก</th>
                      <th colspan="" style="background-color:black; color:#fff; text-align:center;">วันที่สั่งทำ</th>
                      <th colspan="" style="background-color:black; color:#fff; text-align:center;">ขนส่งจังหวัด</th>
                      <th colspan="" style="background-color:black; color:#fff; text-align:center;">ซื้อจาก</th>
                      <th colspan="" style="background-color:black; color:#fff; text-align:center;">ยี่ห้อ</th>
                      <th colspan="" style="background-color:black; color:#fff; text-align:center;">รุ่น</th>
                      <th colspan="" style="background-color:black; color:#fff; text-align:center;">สี</th>
                      <th colspan="" style="background-color:black; color:#fff; text-align:center;">เลขเครื่อง</th>
                      <th colspan="" style="background-color:black; color:#fff; text-align:center;">เลขตัวถัง</th>
                      <th colspan="" style="background-color:black; color:#fff; text-align:center;">เลขทะเบียน</th>
                    </tr>
                  </thead>
                  <tbody style="white-space: nowrap">

                    <!-- select  *,datediff(day,rt_date,getdate()) as divdate from reg_billdata a
                    left outer join (select bill_no as xbill_no,ps_name,model_no,color_name,pserial_no,plate1,plate2 from reg_bill) b on(a.bill_no=b.xbill_no)
                    left outer join (select pr_code,pr_name from prov) c on(a.bg_prov=c.pr_code)
                    where (fee_no is not null) and ((fee_no between '00' and '09') or (fee_no in ('15')))  and status<>'V'
                    $str
                    order by bg_prov,bg_no,bill_date -->
                    <?php
                    $sql = "SELECT * from EHONGDB.dbo.REG_BILLDATA a
                    left outer join (select bill_no as xbill_no,ps_id,ps_name,model_no,color_name,pserial_no,plate1,plate2 from ehongdb.dbo.reg_bill) b on(a.bill_no=b.xbill_no)
                    left outer join (select pr_code,pr_name from ehongdb.dbo.prov) c on(a.bg_prov=c.pr_code)
                    left outer join(SELECT * FROM [EHONGDB].[dbo].[BRANCH]) ax on (ax.BR_ID=a.BR_ID)
                    left outer join(SELECT * FROM [EHONGDB].[dbo].[branch_salezone]) bx on (ax.SZONE_CODE=bx.szone_code)
                    where (bill_no is not null) and rt_date is not null
                    and ((fee_no between '00' and '09') or (fee_no in ('15'))) and (fee_no is not null) and status<>'V'
                    $b2st
                    $idcoed_1 $idcoed_2 $idcoed_3";
                    // echo $sql;
                    $select=$conn->prepare($sql);
                    $select->execute();
                    $item = 1;
                    while($fetch=$select->fetch()){
                      if ($fetch['rtpayin_date'] != '') {
                        $rtpayin_date1 = substr($fetch['rtpayin_date'],0,4)+543; $rtpayin_date2 = substr($fetch['rtpayin_date'],5,2); $rtpayin_date3 = substr($fetch['rtpayin_date'],8,2);
                        $rtpayin_date = $rtpayin_date3."/".$rtpayin_date2."/".$rtpayin_date1;
                      } else {
                        $rtpayin_date = '';
                      }
                      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 = '';
                      }
                      if ($fetch['CHK_BERG'] != '') {
                        $CHK_BERG1 = substr($fetch['CHK_BERG'],0,4)+543; $CHK_BERG2 = substr($fetch['CHK_BERG'],5,2); $CHK_BERG3 = substr($fetch['CHK_BERG'],8,2);
                        $CHK_BERG = $CHK_BERG3."/".$CHK_BERG2."/".$CHK_BERG1;
                      } else {
                        $CHK_BERG = '';
                      }
                    ?>
                    <tr>
                      <td style="background-color:; color:; text-align:;"><?php echo number_format($item); ?>.</td>
                      <td style="background-color:; color:; text-align:right;"><?php echo number_format($fetch['rt_amnt'],2); ?></td>
                      <td style="background-color:; color:; text-align:center;"><?php echo $fetch['rt_status']; ?></td>
                      <td style="background-color:; color:; text-align:;"><?php echo $fetch['rt_comment']; ?></td>
                      <td style="background-color:; color:; text-align:;"><?php echo $fetch['rtpayin_no']; ?></td>
                      <td style="background-color:; color:; text-align:;"><?php echo $rtpayin_date; ?></td>
                      <td style="background-color:; color:; text-align:right;"><?php echo number_format($fetch['FEE_COST'],2); ?></td>
                      <th style="background-color:; color:; text-align:;"> <a href="http://192.168.10.53/xehong-linux/index.php?sid=sale&fid=registbill&bill_no=<?php echo $fetch['BILL_NO']; ?>&vcmd=load#" target="_blank"><?php echo $fetch['BILL_NO']." - ".$fetch['sale_type']; ?></a></th>
                      <th style="background-color:; color:; text-align:;"> <a href="http://192.168.10.53/xehong-linux/index.php?sid=hps&fid=view&presaleno=&mo_no=&ct_no=<?php echo $fetch['CT_NO']; ?>#" target="_blank"><?php echo $fetch['CT_NO']; ?></a></th>
                      <th style="background-color:; color:; text-align:;"> <a href="http://192.168.10.53/xehong-linux/index.php?sid=person&fid=maindata&ps_id=<?php echo $fetch['ps_id']; ?>&vcmd=load&typemenu=2#" target="_blank"><?php echo $fetch['ps_name']; ?></a></th>
                      <td style="background-color:; color:; text-align:;"><?php echo $fetch['BR_ID']." : ".$fetch['BR_NAME']; ?></td>
                      <td style="background-color:; color:; text-align:;"><?php echo $fetch['FEE_NO']." : ".$fetch['FEE_NAME']; ?></td>
                      <td style="background-color:; color:; text-align:;"><?php echo $CHK_BERG; ?></td>
                      <td style="background-color:; color:; text-align:;"><?php echo $BILL_DATE; ?></td>
                      <td style="background-color:; color:; text-align:;"><?php echo $fetch['BG_PROV']." - ".$fetch['pr_name']; ?></td>
                      <td style="background-color:; color:; text-align:;"><?php echo $fetch['XSUPPLIER_NO']; ?></td>
                      <td style="background-color:; color:; text-align:;"><?php echo $fetch['XBRAND_NAME']; ?></td>
                      <td style="background-color:; color:; text-align:;"><?php echo $fetch['model_no']; ?></td>
                      <td style="background-color:; color:; text-align:;"><?php echo $fetch['color_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['plate1']." - ".$fetch['plate2']; ?></td>
                    </tr>
                    <?php
                      $item++; }
                    ?>
                  </tbody>
              </table>
            </div>
            </div>
          </div>
        </div>
      </div>
      </div>
    </section>
  </div>
</div>

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