<?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 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>
                    </tr>
                  </thead>
                  <tbody style="white-space: nowrap">
                    <?php
                    $sql = "SELECT  * from ehongdb.dbo.reg_packdata a
                    left outer join (select packbarcode as pkgcode,count(*) as cnt from ehongdb.dbo.reg_billdatadocument group by packbarcode) b on(a.packbarcode=b.pkgcode)
                    left outer join (select emp_id,fname from ehongdb.dbo.employee) c on(a.packusr=c.emp_id)
                    left outer join(SELECT * FROM [EHONGDB].[dbo].[BRANCH]) ax on (ax.BR_ID=a.packbranch)
                    left outer join(SELECT * FROM [EHONGDB].[dbo].[branch_salezone]) bx on (ax.SZONE_CODE=bx.szone_code)
                    where (month(packdate)='$date_1') and (year(packdate)='$date_2') and (packsentdate is null)
                    $idcoed_1 $idcoed_2 $idcoed_3";
                    // echo $sql;
                    $select=$conn->prepare($sql);
                    $select->execute();
                    $item = 1;
                    while($fetch=$select->fetch()){
                      if ($fetch['packdate'] != '') {
                        $packdate1 = substr($fetch['packdate'],0,4)+543; $packdate2 = substr($fetch['packdate'],5,2); $packdate3 = substr($fetch['packdate'],8,2);
                        $packdate = $packdate3."/".$packdate2."/".$packdate1;
                      } else {
                        $packdate = '';
                      }
                      if ($fetch['packsentdate'] != '') {
                        $packsentdate1 = substr($fetch['packsentdate'],0,4)+543; $packsentdate2 = substr($fetch['packsentdate'],5,2); $packsentdate3 = substr($fetch['packsentdate'],8,2);
                        $packsentdate = $packsentdate3."/".$packsentdate2."/".$packsentdate1;
                      } else {
                        $packsentdate = '';
                      }
                    ?>
                    <tr>
                      <td style="background-color:; color:; text-align:;"><?php echo number_format($item); ?>.</td>
                      <td style="background-color:; color:; text-align:;"><?php echo $fetch['packbarcode']; ?></td>
                      <td style="background-color:; color:; text-align:;"><?php echo $packdate; ?></td>
                      <td style="background-color:; color:; text-align:;"><?php echo $fetch['packbarcode']; ?></td>
                      <td style="background-color:; color:; text-align:;"><?php echo $fetch['packbranch']." : ".$fetch['BR_NAME']; ?></td>
                      <td style="background-color:; color:; text-align:;"><?php echo $fetch['fname']; ?></td>
                      <td style="background-color:; color:; text-align:right;"><?php echo $fetch['cnt']; ?></td>
                      <td style="background-color:; color:; text-align:;"><?php echo $packsentdate." ".$fetch['packsenttime']; ?></td>
                      <td style="background-color:; color:; text-align:;"><?php echo $fetch['packsenttype']; ?></td>
                      <td style="background-color:; color:; text-align:;"><?php echo $fetch['packcarry']; ?></td>
                      <td style="background-color:; color:; text-align:;"><?php echo $fetch['packcomment']; ?></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>
