<?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'])) {
        $month = $_POST['month'];
        $year = $_POST['year'];
        $year1 = $year-543;
        $branch = $_POST['branch'];
        $sale_zone = $_POST['sale_zone'];
        // $zstaff_idx = $_POST['zstaff_id'];
        $province = $_POST['province'];
        $brand = $_POST['brand'];
      }
      else {
        date_default_timezone_set('Asia/Bangkok');
        $month = date('m');
        $year = date('Y')+543;
        $year1 = $year-543;
      }
      // echo $status;
      ?>
      <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>
                  <select name="month" class="form-control">
                    <option value="<?php echo $month; ?>"><?php echo $thai_month_arr[$month]; ?></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 class="col-xs-2">
                  <p>ปี</p>
                  <input type="number" class="form-control" placeholder="" name="year" value="<?php echo $year; ?>">
                </div>
                <div class="col-xs-2">
                  <p>สาขา</p>
                  <select name="branch" id="" class="form-control">
                    <?php
                      $sql = "SELECT * FROM EHONGDB.dbo.BRANCH WHERE BR_ID NOT IN ('%') AND BR_ID = '$branch'";
                      $select=$conn->prepare($sql);
                      $select->execute();
                      while($fetch=$select->fetch()){
                    ?>
                      <option value="<?php echo $fetch['BR_ID']; ?>"><?php echo $fetch['BR_ID']." : ".$fetch['BR_NAME']; ?></option>
                    <?php } ?>
                    <option value="%">ทั้งหมด</option>
                    <?php
                      $sql = "SELECT * FROM EHONGDB.dbo.BRANCH WHERE BR_ID NOT IN ('%')";
                      $select=$conn->prepare($sql);
                      $select->execute();
                      while($fetch=$select->fetch()) {
                    ?>
                      <option value="<?php echo $fetch['BR_ID']; ?>"><?php echo $fetch['BR_ID']." : ".$fetch['BR_NAME']; ?></option>
                    <?php } ?>
                   </select>
                 </div>
                 <div class="col-xs-2">
                   <p>เขต</p>
                   <select class="form-control" name="sale_zone" placeholder="">
                     <?php
                     $sql = "SELECT * FROM EHONGDB.dbo.branch_salezone WHERE szone_code = '$sale_zone' ORDER BY szone_code";
                     $select=$conn->prepare($sql);
                     $select->execute();
                     while($fetch=$select->fetch()) {
                     ?>
                     <option value="<?php echo $fetch['szone_code'];?>"><?php echo $fetch['szone_code']." : ".$fetch['staff_nick'];?></option>
                     <?php } ?>
                     <option value="%">รวมทุกเขต</option>
                     <?php
                     $sql = "SELECT * FROM EHONGDB.dbo.branch_salezone ORDER BY szone_code";
                     $select=$conn->prepare($sql);
                     $select->execute();
                     while($fetch=$select->fetch()) {
                     ?>
                     <option value="<?php echo $fetch['szone_code'];?>"><?php echo $fetch['szone_code']." : ".$fetch['staff_nick'];?></option>
                     <?php } ?>
                   </select>
                 </div>

                 <div class="col-xs-2">
                   <p>จังหวัด</p>
                   <select class="form-control" name="province" placeholder="">
                     <?php
                     $sql = "SELECT a.PR_CODE ,b.PR_NAME from EHONGDB.dbo.branch a
                             LEFT OUTER JOIN (SELECT PR_CODE,PR_NAME FROM [EHONGDB].[dbo].[PROV]) b on a.PR_CODE=b.PR_CODE
                             WHERE a.PR_CODE is not null and a.PR_CODE = '$province'
                             group by a.PR_CODE,b.PR_NAME";
                     $select=$conn->prepare($sql);
                     $select->execute();
                     while($fetch=$select->fetch()) {
                     ?>
                     <option value="<?php echo $fetch['PR_CODE'];?>"><?php echo $fetch['PR_CODE']." : ".$fetch['PR_NAME'];?></option>
                     <?php } ?>
                     <option value="%">ทุกจังหวัด</option>
                     <?php
                     $sql = "SELECT a.PR_CODE ,b.PR_NAME from EHONGDB.dbo.branch a
                             LEFT OUTER JOIN (SELECT PR_CODE,PR_NAME FROM [EHONGDB].[dbo].[PROV]) b on a.PR_CODE=b.PR_CODE
                             WHERE a.PR_CODE is not null
                             group by a.PR_CODE,b.PR_NAME";
                     $select=$conn->prepare($sql);
                     $select->execute();
                     while($fetch=$select->fetch()) {
                     ?>
                     <option value="<?php echo $fetch['PR_CODE'];?>"><?php echo $fetch['PR_CODE']." : ".$fetch['PR_NAME'];?></option>
                     <?php } ?>
                   </select>
                 </div>
                 <div class="col-xs-2">
                   <p>ยี่ห้อ</p>
                   <select class="form-control" name="brand" placeholder="">
                     <?php
                     $sql = "SELECT brand_no,brand_name from EHONGDB.dbo.product_basebrand
                             where serie_no in ('002') and brand_name = '$brand'
                             group by brand_no,brand_name
                             order by brand_name";
                     $select=$conn->prepare($sql);
                     $select->execute();
                     while($fetch=$select->fetch()) {
                     ?>
                     <option value="<?php echo $fetch['brand_name'];?>"><?php echo $fetch['brand_name'];?></option>
                     <?php } ?>
                     <option value="%">ทั้งหมด</option>
                     <?php
                     $sql = "SELECT brand_no,brand_name from EHONGDB.dbo.product_basebrand
                             where serie_no in ('002')
                             group by brand_no,brand_name
                             order by brand_name";
                     $select=$conn->prepare($sql);
                     $select->execute();
                     while($fetch=$select->fetch()) {
                     ?>
                     <option value="<?php echo $fetch['brand_name'];?>"><?php echo $fetch['brand_name'];?></option>
                     <?php } ?>
                   </select>
                   <br>

                 </div>
                 <div class="col-xs-2">
                   <p>สภาพรถ</p>
                   <select class="form-control" name="bike_condition">
                     <option value="%">ทั้งหมด</option>
                     <option value="0" <?php echo (isset($_REQUEST['bike_condition'])?($_REQUEST['bike_condition']=='0'?'selected':''):''); ?>>รถใหม่</option>
                     <option value="2" <?php echo (isset($_REQUEST['bike_condition'])?($_REQUEST['bike_condition']=='2'?'selected':''):''); ?>>รถเก่า</option>
                   </select>
                 </div>
                 <div class="col-xs-2">
                   <p>กลุ่มงานสั่งทำ</p>
                   <select class="form-control" name="gwork">
                     <option value="%">ทุกกลุ่มงานสั่งทำ</option>
                     <?php
                     $sql = "SELECT [G_ID],[G_NAME],[ITEMS],[SHW] FROM [EHONGDB].[dbo].[REG_GWORK]";
                     $select=$conn->prepare($sql);
                     $select->execute();
                     $gwork=array();
                     while($fetch=$select->fetch()) {
                       $gwork[]=array(
                        "g_id"=>$fetch['G_ID'],
                        "g_name"=>$fetch['G_NAME']
                      );
                      echo "<option value='".$fetch['G_ID']."' ".(isset($_REQUEST['gwork'])?($_REQUEST['gwork']==$fetch['G_ID']?'selected':''):'').">".$fetch['G_ID'].":".$fetch['G_NAME']."</option>";
                    } ?>
                   </select>
                 </div>
                 <div class="col-xs-2">
                   <p>รายการสั่งทำ</p>
                   <select class="form-control" name="fee">
                     <option value="%">ทุกรายการ</option>
                     <?php
                     $sql = "SELECT [FEE_NO],[FEE_NAME],[STATUS] FROM [EHONGDB].[dbo].[REG_FEEDATA] WHERE STATUS='N' and ((fee_no between '00' and '09') or (fee_no in ('15')))";
                     $select=$conn->prepare($sql);
                     $select->execute();
                     $reglist=array();
                     while($fetch=$select->fetch()) {
                       $reglist[]=array(
                         "fid"=>$fetch['FEE_NO'],
                         "fname"=>$fetch['FEE_NAME']
                       );
                       echo "<option value='".$fetch['FEE_NO']."' ".(isset($_REQUEST['fee'])?($_REQUEST['fee']==$fetch['FEE_NO']?'selected':''):'').">".$fetch['FEE_NO'].":".$fetch['FEE_NAME']."</option>";
                    } ?>
                   </select>
                 </div>
                 <div class="col-xs-2">
                   <p>ชิ้นงาน</p>
                   <select class="form-control" name="gid">
                     <option value="%">ทุกชิ้นงาน</option>
                     <?php
                     $sql = "SELECT [GDID],[GDNAME] FROM [EHONGDB].[dbo].[REG_FEEDATASUB]";
                     $select=$conn->prepare($sql);
                     $select->execute();
                     $fdoclist=array();
                     while($fetch=$select->fetch()) {
                       $fdoclist[]=array(
                         "fdoc_no"=>$fetch['GDID'],
                         "fdoc_name"=>$fetch['GDNAME']
                       );
                       echo "<option value='".$fetch['GDID']."' ".(isset($_REQUEST['gid'])?($_REQUEST['gid']==$fetch['GDID']?'selected':''):'').">".$fetch['GDID'].":".$fetch['GDNAME']."</option>";
                    } ?>
                   </select>
                 </div>

                 <div class="col-xs-2">
                  <p>การแสดงข้อมูล</p>
                  <select class="form-control" name="datatype">
                    <option value="1" <?php echo (isset($_REQUEST['datatype'])?($_REQUEST['datatype']==1?'selected':''):''); ?>>ตามการเกิดงาน</option>
                    <option value="2" <?php echo (isset($_REQUEST['datatype'])?($_REQUEST['datatype']==2?'selected':''):''); ?>>ติดตามงาน</option>
                  </select>
                </div>
              </div>
            </div>
            <div class="box-footer">
              <input type="submit" name="submit" id="" class="btn btn-success" value="แสดงข้อมูล">
              <!-- <input type="submit" name="submit_2" id="" class="btn btn-success" value="รายงาน เขต">
              <input type="submit" name="submit_3" id="" class="btn btn-success" value="รายงาน ภาค"> -->
            </div>
          </form>

        </div>
      </div>

      <?php
      if (isset($_POST['submit'])) {
        if($_REQUEST['datatype']=="1" ){
          include 'report_reg1.php';
        } else {
          include 'report_reg2.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>
