<?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['date_1'];
      $date_2 = $_REQUEST['date_2'];

      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 = "";
      }

      ?>
      <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 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> -->
                    </tr>
                  </thead>
                  <tbody style="white-space: nowrap">
                    <?php
                    $sql = "SELECT * from EHONGDB.dbo.reg_bill a
                    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)
                    left outer join(SELECT G_ID AS GW_ID, G_NAME FROM EHONGDB.dbo.REG_GWORK) gw on (a.g_id=gw.GW_ID)
                    left outer join (select emp_id as emp_xid,fname,lname from ehongdb.dbo.employee) ch on(a.chkusr1=ch.emp_xid)
                      left outer join(SELECT ct_no AS CT_NOXXX, fw_status, status, notpaycost FROM EHONGDB.dbo.hps_ctmain) ctno on (ctno.CT_NOXXX=a.CT_NO)
                      left outer join (select * from EHONGDB.dbo.hps_ctstatusname) cts on (cts.ct_status=ctno.status)
                    where (bill_no is not null)
                    and (a.status<>'V') and (a.chkdate0 is not null) and (a.chkdate1 is null)
                    and YEAR(a.bill_date) = $date_2 and MONTH(a.bill_date) = $date_1
                    $idcoed_1 $idcoed_2 $idcoed_3
                    order by a.BILL_DATE";
                    // 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 = '';
                      }
                      if ($fetch['chkdate0'] != '') {
                        $chkdate01 = substr($fetch['chkdate0'],0,4)+543; $chkdate02 = substr($fetch['chkdate0'],5,2); $chkdate03 = substr($fetch['chkdate0'],8,2);
                        $chkdate0 = $chkdate03."/".$chkdate02."/".$chkdate01;
                      } else {
                        $chkdate0 = '';
                      }

                      $DateStart = $BILL_DATE3; //วันเริ่มต้น
                      $MonthStart = $BILL_DATE2; //เดือนเริ่มต้น
                      $YearStart = $BILL_DATE1-543; //ปีเริ่มต้น
                      $DateEnd = date('d'); //วันสิ้นสุด
                      $MonthEnd = date('m'); //เดือนสิ้นสุด
                      $YearEnd = date('Y'); //ปีสิ้นสุด
                      $Start = mktime(0,0,0,$MonthStart ,$DateStart ,$YearStart);
                      $End = mktime(0,0,0,$MonthEnd,$DateEnd,$YearEnd);
                      $DateNum=ceil(($End-$Start)/86400); // 28
                    ?>
                    <tr>
                      <td style="background-color:; color:; text-align:;"><?php echo number_format($item); ?>.</td>
                      <td style="background-color:; color:; text-align:;"><?php echo $BILL_DATE; ?></td>
                      <td style="background-color:; color:red; text-align:center;"><?php echo $DateNum; ?></td>
                      <td style="background-color:; color:; text-align:;"><?php echo $fetch['GW_ID']." : ".$fetch['G_NAME']; ?></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']; ?></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:red; text-align:;"><?php echo $fetch['ct_statusname']; ?></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:; text-align:;"><?php echo $chkdate0; ?></td> -->
                      <!-- <td style="background-color:; color:; text-align:;"><?php echo $fetch['chkusr1']." : ".$fetch['fname']." ".$fetch['lname']; ?></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>
