<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>EHONGMD</title>
  <?php
  include '_plugin.php';
  include '_connect.php';
  ?>
  <script src="bower_components/jquery/dist/jquery.min.js"></script>

</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">

<?php
include '_header.php';
include '_menu.php';
?>
  <div class="content-wrapper">
    <section class="content">
      <div class="row">
      <!-- ค้นหา -->
      <?php
      $month = $_POST['M'];
      $year = $_POST['Y']-543;
      $month2 =  $month;
      $day2 = date('d');
      $day3 = '';
      ?>
      <?php
      include '_connect.php';
      $_month_name = array("01"=>"มกราคม",  "02"=>"กุมภาพันธ์",  "03"=>"มีนาคม",
         "04"=>"เมษายน",  "05"=>"พฤษภาคม",  "06"=>"มิถุนายน",
         "07"=>"กรกฎาคม",  "08"=>"สิงหาคม",  "09"=>"กันยายน",
         "10"=>"ตุลาคม", "11"=>"พฤศจิกายน",  "12"=>"ธันวาคม");
      $m = date('m');

      $now_month = date("$year-$month-01");
      $mk_time = strtotime($now_month);
      $day_no = date("t",$mk_time);
      $wan_no = date("w",$mk_time);
      $box_day = $day_no+$wan_no;
      $rows_week = ceil($box_day/7);
      $total_box=$rows_week*7;
      $timeDate = strtotime($year.'-'.$month."-01"); //เปลี่ยนวันที่เป็น timestamp
      $lastDay = date("t", $timeDate); //จำนวนวันของเดือน
      include 'reg_search_1.php'
      ?>
      <?php
      $sql = "select day(chk_berg) as dx,count(bill_no) as cnt from regemp.dbo.reg_billdata_berg_".$year."_".$month2." where (status<>'V') and (chkdate2 is not null and chkstatus2='C') and (acpdate is not null) and (chk_berg is not null) group by day(chk_berg) order by day(chk_berg)";
      $rs=$conn->prepare($sql);
      $rs->execute();
      $xrow2x=array();
        foreach($rs as $row){
      $xrow2x[$row['dx']]=$row['cnt'];
      };
      // 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>
            <p><?php echo "เดือน ".$_month_name[$month2]." ".$_POST['Y']; ?></p>
          </div>
          <div class="box-body">
            <div class="form-group" style="overflow-x:auto;">
              <table id="example11" class="table table-bordered table-striped">
                <tr>
                  <th><center>รายการ</center></td>
                  <?php
                    $dcnt0x=0;
                    for($day=1;$day<=$lastDay;$day++) { ?>
                  <th><center><?php echo substr("".$day, -2); ?></center></td>
                  <?php } ?>
                  <th><center>สรุป</center></td>
                </tr>
                <tr>
                  <td align='center'><p class="text-green">รายการเบิกแล้ว (เรียงวันที่เบิก)</p></td>
                  <?php
                    for($i=1;$i<=$lastDay;$i++){
                    $dcnt0x = isset($xrow2x[$i]) ? $xrow2x[$i] : "0";
                  ?>
                  <td align='center'>
                     <!-- href="reg_index_3.php?Y=<?php echo $year;?>&M=<?php echo $month2;?>&D=<?php echo $i;?>" target="_blank" -->
                    <a class="text-blue"><?php echo number_format($dcnt0x);?></a>
                  </td>
                  <?php }
                    $xrow2x = array_sum($xrow2x);
                  ?>
                  <td align='center'>
                    <!-- href="reg_index_3.php?Y=<?php echo $year;?>&M=<?php echo $month2;?>&D=<?php echo $day3;?>&D1=<?php echo $i-1?>" target="_blank" -->
                    <a class="text-red"><?php echo number_format($xrow2x); ?></a>
                  </td>
                </tr>
              </table>
            </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'; ?>
</body>
</html>
