<?php error_reporting(0); ?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>EHONGMD | ตรวจสอบ ทะเบียนภาษี, พ.ร.บ. ไกล้หมดอายุ</title>
  <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">
      <!-- ค้นหา -->
      <!-- ตาราง -->
      <script src="bower_components/jquery/dist/jquery.min.js"></script>
      <?php
      $thai_month_arr=array(
          "0"=>"",
          "01"=>"มกราคม",
          "02"=>"กุมภาพันธ์",
          "03"=>"มีนาคม",
          "04"=>"เมษายน",
          "05"=>"พฤษภาคม",
          "06"=>"มิถุนายน",
          "07"=>"กรกฎาคม",
          "08"=>"สิงหาคม",
          "09"=>"กันยายน",
          "10"=>"ตุลาคม",
          "11"=>"พฤศจิกายน",
          "12"=>"ธันวาคม"
      );
      if (isset($_POST['submit'])) {
        $is_y = $_POST['y'];
        $is_m = $_POST['m'];
        $is_m_1 = $thai_month_arr[date("$is_m")];

      }
      else {
        $is_y = date('Y')+543;
        $is_m = date('m');
        $is_m_1 = $thai_month_arr[date("$is_m")];
      }
      ?>
      <div class="col-md-12">
        <div class="box box-success">
          <div class="box-header with-border">
            <h3 class="box-title">EHONGMD | ตรวจสอบ ภาษี, พ.ร.บ. ไกล้หมดอายุ</h3>
          </div>
          <!-- target="_blank" lettersum.php-->
          <form role="form" action="" method="POST" enctype="multipart/form-data" >
            <div class="box-body">
              <div class="row">
                <div class="col-xs-2">
                  <p>ปี</p>
                  <input type="text" class="form-control" placeholder="" name="y" value="<?php echo $is_y; ?>">
                </div>
                <div class="col-xs-2">
                  <p>เดือน</p>
                  <select name="m" id="month_check" class="form-control">
                    <option value="<?php echo $is_m; ?>"><?php echo $is_m_1; ?></option>
                    <option value="01">มกราคม</option>
                    <option value="02">กุมภาพันธ์</option>
                    <option value="03">มีนาคม</option>
                    <option value="04">เมษายน</option>
                    <option value="05">พฤษภาคม</option>
                    <option value="06">มิถุนายน</option>
                    <option value="07">กรกฎาคม</option>
                    <option value="08">สิงหาคม</option>
                    <option value="09">กันยายน</option>
                    <option value="10">ตุลาคม</option>
                    <option value="11">พฤศจิกายน</option>
                    <option value="12">ธันวาคม</option>
                   </select>
                 </div>
              </div>
            </div>
            <div class="box-footer">
              <input type="submit" name="submit" id="" class="btn btn-success" value="ตรวจสอบ">
              <!-- <button class="btn btn-success"><a style="color:#FFF;" href="transport_index_5.php" target="_blank">พิมพ์ใบรับรองแทนใบเสร็จรับเงิน FC</a></button> -->
            </div>
          </form>

        </div>
      </div>

      <?php
      if (isset($_POST['submit'])) {
        $y = $_POST['y']-543;
        $m = $_POST['m'];
        date_default_timezone_set('Asia/Bangkok');
        $dm1 = date("$y-$m-d");
        $dm = date("t",strtotime("$dm1"));
      ?>
      <!-- ไกล้หมดอายุ -->
      <?php
      // ภาษี ไกล้หมดอายุ
      $sql = "SELECT
      	day(b.reg_expire) as days,count(a.CT_NO) as CT_NO
      FROM EHONGDB.dbo.hps_ctmain a
      left outer join (select * from EHONGDB.dbo.PRODUCT_PRODUCTSERIAL) b on (a.CT_NO=b.firstct_no)
      WHERE (month(b.reg_expire)='$m') and (year(b.reg_expire)='$y')
      group by day(b.reg_expire)
      order by days";
      $select=$conn->prepare($sql);
      $select->execute();
      $expiration_1=array();
        foreach($select as $fetch){
      $expiration_1[$fetch['days']]=$fetch['CT_NO'];
      };
      // echo $sql;
      // พ.ร.บ. ไกล้หมดอายุ
      $sql = "SELECT
        day(b.plc_expire) as days,count(a.CT_NO) as CT_NO
      FROM EHONGDB.dbo.hps_ctmain a
      left outer join (select * from EHONGDB.dbo.PRODUCT_PRODUCTSERIAL) b on (a.CT_NO=b.firstct_no)
      WHERE (month(b.plc_expire)='$m') and (year(b.plc_expire)='$y')
      group by day(b.plc_expire)
      order by days";
      // echo $sql;
      $select=$conn->prepare($sql);
      $select->execute();
      $expiration_2=array();
        foreach($select as $fetch){
      $expiration_2[$fetch['days']]=$fetch['CT_NO'];
      };
      // echo $sql;
      ?>
      <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="" 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;">รายการ</th>
                    <?php
                      for($i=1;$i<=$dm;$i++) {
                    ?>
                    <th style="background-color:LightBlue; color:#000; text-align:center;"><?php echo $i; ?></th>
                    <?php } ?>
                    <th style="background-color:yellow; color:#000; text-align:center;">รวม</th>
                  </tr>
                </thead>
                <tbody style="white-space: nowrap">
                  <tr>
                    <td style="background-color:; color:; text-align:;">ทะเบียนภาษีหมดอายุ ไกล้หมดอายุ</td>
                  <?php
                    for($i=1;$i<=$dm;$i++) {
                      $ex_01=$expiration_1[$i];
                      $sum_ex_01 += $ex_01;
                  ?>
                    <td style="text-align:center;"><a href="expiration.date.select.php?y=<?php echo $y; ?>&m=<?php echo $m; ?>&d=<?php echo $i; ?>&status=1" target="_blank"><?php echo number_format($ex_01); ?></a></td>
                  <?php } ?>
                  <th style="background-color:yellow; color:#000; text-align:center;"><a href="expiration.date.select.php?y=<?php echo $y; ?>&m=<?php echo $m; ?>&d=<?php echo $dm; ?>&status=s1" target="_blank"><?php echo number_format($sum_ex_01); ?></a></th>
                  </tr>
                  <tr>
                    <td style="background-color:; color:; text-align:;">พ.ร.บ. ไกล้หมดอายุ</td>
                    <?php
                      for($i=1;$i<=$dm;$i++) {
                        $ex_02=$expiration_2[$i];
                        $sum_ex_02 += $ex_02;
                    ?>
                      <td style="text-align:center;"><a href="expiration.date.select.php?y=<?php echo $y; ?>&m=<?php echo $m; ?>&d=<?php echo $i; ?>&status=2" target="_blank"><?php echo number_format($ex_02); ?></a></td>
                    <?php } ?>
                    <th style="background-color:yellow; color:#000; text-align:center;"><a href="expiration.date.select.php?y=<?php echo $y; ?>&m=<?php echo $m; ?>&d=<?php echo $dm; ?>&status=s2" target="_blank"><?php echo number_format($sum_ex_02); ?></a></th>
                  </tr>
                </tbody>
            </table>
            </div>
            </div>
          </div>
        </div>
      </div>
      <!-- หมดอายุ ไม่ต่อ -->
      <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">
              <!-- example32 -->
              <div style="overflow-x:auto;">
              <table id="" 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;">รายการ</th>
                    <?php
                      for($i=1;$i<=$dm;$i++) {
                    ?>
                    <th style="background-color:LightBlue; color:#000; text-align:center;"><?php echo $i; ?></th>
                    <?php } ?>
                    <th style="background-color:yellow; color:#000; text-align:center;">รวม</th>
                  </tr>
                </thead>
                <tbody style="white-space: nowrap">
                  <?php
                  // ภาษี หมดอายุ
                  $d1 = date('d');
                  $m1 = date('m');
                  $y1 = date('Y');
                  $ymd_2 = date('Y-m-d');
                  $sql = "SELECT
                  	day(b.reg_expire) as days,count(a.CT_NO) as CT_NO
                  FROM EHONGDB.dbo.hps_ctmain a
                  left outer join (select * from EHONGDB.dbo.PRODUCT_PRODUCTSERIAL) b on (a.CT_NO=b.firstct_no)
                  WHERE b.reg_expire < '$ymd_2'
                  group by day(b.reg_expire)
                  order by days";
                  $select=$conn->prepare($sql);
                  $select->execute();
                  $expiration_3=array();
                    foreach($select as $fetch){
                  $expiration_3[$fetch['days']]=$fetch['CT_NO'];
                  };
                  // echo $sql;
                  // พ.ร.บ. หมดอายุ
                  $sql = "SELECT
                    day(b.plc_expire) as days,count(a.CT_NO) as CT_NO
                  FROM EHONGDB.dbo.hps_ctmain a
                  left outer join (select * from EHONGDB.dbo.PRODUCT_PRODUCTSERIAL) b on (a.CT_NO=b.firstct_no)
                  WHERE b.plc_expire < '$ymd_2'
                  group by day(b.plc_expire)
                  order by days";
                  $select=$conn->prepare($sql);
                  $select->execute();
                  $expiration_4=array();
                    foreach($select as $fetch){
                  $expiration_4[$fetch['days']]=$fetch['CT_NO'];
                  };
                  // echo $sql;
                  ?>
                  <tr>
                    <td style="background-color:; color:red; text-align:;">ทะเบียนภาษีหมดอายุ ไม่ต่อ</td>
                  <?php
                    for($i=1;$i<=$dm;$i++) {
                      $ex_03=$expiration_3[$i];
                      $sum_ex_03 += $ex_03;
                  ?>
                  <td style="text-align:center;"><a href="expiration.date.select.php?y=<?php echo $y; ?>&m=<?php echo $m; ?>&d=<?php echo $i; ?>&status=3" target="_blank"><?php echo number_format($ex_03); ?></a></td>
                  <?php } ?>
                  <th style="background-color:yellow; color:#000; text-align:center;"><a href="expiration.date.select.php?y=<?php echo $y; ?>&m=<?php echo $m; ?>&d=<?php echo $dm; ?>&status=s3" target="_blank"><?php echo number_format($sum_ex_03); ?></a></th>
                  </tr>
                  <tr>
                    <td style="background-color:; color:red; text-align:;">พ.ร.บ. หมดอายุ ไม่ต่อ</td>
                    <?php
                      for($i=1;$i<=$dm;$i++) {
                        $ex_04=$expiration_4[$i];
                        $sum_ex_04 += $ex_04;
                    ?>
                    <td style="text-align:center;"><a href="expiration.date.select.php?y=<?php echo $y; ?>&m=<?php echo $m; ?>&d=<?php echo $i; ?>&status=4" target="_blank"><?php echo number_format($ex_04); ?></a></td>
                    <?php } ?>
                    <th style="background-color:yellow; color:#000; text-align:center;"><a href="expiration.date.select.php?y=<?php echo $y; ?>&m=<?php echo $m; ?>&d=<?php echo $dm; ?>&status=s4" target="_blank"><?php echo number_format($sum_ex_04); ?></a></th>
                  </tr>
                  <?php //$item++; } ?>
                </tbody>
            </table>
            </div>
            </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';
  include 'scroll0.php';
?>
</body>
</html>
