<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 class="text-red">เดือน <?php echo $thai_month_arr[$month]." ".$year1; ?></p>
    </div>
    <div class="box-body">
      <div class="form-group">
        <table id="example" class="table table-striped table-bordered" style="width:100%;font-size: 14px;">
          <thead style="white-space: nowrap">
            <tr>
              <th style="white-space: nowrap;" rowspan="3">ลำดับ</th>
              <th style="white-space: nowrap;" rowspan="3">รายการ</th>
              <th style="white-space: nowrap;" rowspan="3">ใบสั่งทำ</th>
              <th style="white-space: nowrap;color: red" rowspan="3" >ส่วนต่าง</th>
              <th style="white-space: nowrap;color: red" rowspan="3" >ตรวจไม่ผ่าน</th>
              <th style="color: red" rowspan="3" >ส่งงานสั่งแก้ไข</th>
              <th rowspan="3" style="color: blue;">รวมตรวจใบเสร็จ</th>
              <th colspan="5">ตรวจใบเสร็จ (วันสั่งทำ-วันตรวจ)</th>
              <th rowspan="3" style="color: blue;">รวมตรวจรับสาขา</th>
              <th colspan="5">ตรวจรับเอกสารสาขา (วันตรวจ-วันตรวจรับ)</th>
              <th rowspan="3" style="color: blue;">รวมส่งห้องทะเบียน</th>
              <th colspan="5">ส่งงานไปห้องทะเบียน (วันตรวจรับ-วันนำส่งทะเบียน)</th>
              <th rowspan="3" style="color: blue;">รวมทะเบียนตรวจรับ</th>
              <th colspan="5">ห้องทะเบียนตรวจรับ (วันนำส่งทะเบียน-ทะเบียนตรวจรับ)</th>
            </tr>
            <tr>
              <td>1</td>
              <td>2</td>
              <td>3</td>
              <td>4</td>
              <td>>4</td>
              <td>1-7</td>
              <td>8-14</td>
              <td>15-21</td>
              <td>22-27</td>
              <td>>27</td>
              <td>1-2</td>
              <td>3-4</td>
              <td>5-6</td>
              <td>7-8</td>
              <td>>8</td>
              <td>1-2</td>
              <td>3-4</td>
              <td>5-6</td>
              <td>7-8</td>
              <td>>8</td>
            </tr>
            <tr>
              <td style="color: red;">1</td>
              <td style="color: red;">0.5</td>
              <td style="color: red;">-1</td>
              <td style="color: red;">-1.5</td>
              <td style="color: red;">-2</td>
              <td style="color: red;">1.5</td>
              <td style="color: red;">1</td>
              <td style="color: red;">0.5</td>
              <td style="color: red;">-1</td>
              <td style="color: red;">-1.5</td>
              <td style="color: red;">1.5</td>
              <td style="color: red;">1</td>
              <td style="color: red;">0.5</td>
              <td style="color: red;">0</td>
              <td style="color: red;">-1</td>
              <td style="color: red;">0</td>
              <td style="color: red;">0</td>
              <td style="color: red;">0</td>
              <td style="color: red;">0</td>
              <td style="color: red;">0</td>
            </tr>
          </thead>
          <tbody>
        <?php
            for($i=0;$i<count($gwork);$i++){
                $gwork[$i]+=array("allbill"=>0);
                $gwork[$i]+=array("return"=>0);
                $gwork[$i]+=array("resent"=>0);
                //ตรวจใบเสร็จ
                $gwork[$i]+=array("chkbill"=>0);
                $gwork[$i]+=array("chkbill1"=>0);
                $gwork[$i]+=array("chkbill2"=>0);
                $gwork[$i]+=array("chkbill3"=>0);
                $gwork[$i]+=array("chkbill4"=>0);
                $gwork[$i]+=array("chkbill5"=>0);
                //ตรวจรับเอกสารสาขา
                $gwork[$i]+=array("chkdocbranch"=>0);
                $gwork[$i]+=array("chkdocbranch1"=>0);
                $gwork[$i]+=array("chkdocbranch2"=>0);
                $gwork[$i]+=array("chkdocbranch3"=>0);
                $gwork[$i]+=array("chkdocbranch4"=>0);
                $gwork[$i]+=array("chkdocbranch5"=>0);
                //ส่งงานไปห้องทะเบียน
                $gwork[$i]+=array("sentreg"=>0);
                $gwork[$i]+=array("sentreg1"=>0);
                $gwork[$i]+=array("sentreg2"=>0);
                $gwork[$i]+=array("sentreg3"=>0);
                $gwork[$i]+=array("sentreg4"=>0);
                $gwork[$i]+=array("sentreg5"=>0);
                //ห้องทะเบียนตรวจรับ
                $gwork[$i]+=array("regreceipt"=>0);
                $gwork[$i]+=array("regreceipt1"=>0);
                $gwork[$i]+=array("regreceipt2"=>0);
                $gwork[$i]+=array("regreceipt3"=>0);
                $gwork[$i]+=array("regreceipt4"=>0);
                $gwork[$i]+=array("regreceipt5"=>0);
            }
            $sql="SELECT *
                  from ehongdb.dbo.reg_bill a
                    LEFT OUTER JOIN(
                      SELECT br_id,BR_NAME,SZONE_CODE,PR_CODE
                      FROM EHONGDB.dbo.BRANCH
                    ) b on a.BR_ID=b.BR_ID
                  where (a.status<>'V') and (month(a.bill_date)=".$_REQUEST['month']." and year(a.bill_date)=".$year1.") ";
            if($_REQUEST['branch']!="%")$sql.="and a.br_id like '".$_REQUEST['branch']."' ";
            if($_REQUEST['brand']!="%")$sql.="and a.brand_name like '".$_REQUEST['brand']."' ";
            if($_REQUEST['sale_zone']!="%")$sql.="and b.szone_code like '".$_REQUEST['sale_zone']."' ";
            if($_REQUEST['province']!="%")$sql.="and b.PR_CODE like '".$_REQUEST['province']."' ";
            if($_REQUEST['bike_condition']!="%"){
              $sql.="and a.ct_no like '".$_REQUEST['bike_condition']."%' ";
            }
            if($_REQUEST['gwork']!="%")$sql.="and g_id like '".$_REQUEST['gwork']."' ";
            $sql.="order by bill_date";
            // echo $sql."<br>";
            // $stmt = sqlsrv_query($conn,$sql);
            //$reg_group=sqlsrv_num_rows( $stmt );
            $stmt=$conn->prepare($sql);
            $stmt->execute();
            $allbillno=array();
            while($row = $stmt->fetch()) {
              for($i=0;$i<count($gwork);$i++){
                if($gwork[$i]['g_id']==$row['g_id']){
                  $gwork[$i]['allbill']++;
                  //ตรวจแล้วไม่ผ่าน
                  if(!empty($row['chkdate0']) and $row['chkstatus0']=='N'){
                    $gwork[$i]['return']++;
                  }
                  //รวมตรวจใบเสร็จ
                  if(!empty($row['chkdate0']) and $row['chkstatus0']=='Y'){
                    $allbillno[]=$row['BILL_NO'];
                    $date1=new DateTime($row['BILL_DATE']);
                    //ถ้ามีการตีกลับเริ่มจากวันที่ส่งเข้ามาใหม่ *ถ้าไม่มีตีกลับchkreturndate0จะnullเสมอ
                    if(!empty($row['chkreturndate0'])){
                      $date1=new DateTime($row['chkreturndate0']);
                      $gwork[$i]['resent']++;
                    }else{
                      $gwork[$i]['chkbill']++;
                    }
                    $date2=new DateTime($row['chkdate0']);
                    $diff=$date1->diff($date2);
                    $df=($diff->format("%a")+1);
                    if($df<=1)$gwork[$i]['chkbill1']++;
                    if($df==2)$gwork[$i]['chkbill2']++;
                    if($df==3)$gwork[$i]['chkbill3']++;
                    if($df==4)$gwork[$i]['chkbill4']++;
                    if($df>=5)$gwork[$i]['chkbill5']++;
                  }
                  //ตรวจรับเอกสารสาขา
                  if(!empty($row['chkdate0']) and !empty($row['chkdate1'])){
                    $gwork[$i]['chkdocbranch']++;
                    $date1=new DateTime($row['chkdate0']);
                    $date2=new DateTime($row['chkdate1']);
                    $diff=$date1->diff($date2);
                    $df=($diff->format("%a")+1);
                    if($df>=1 and $df<=7)$gwork[$i]['chkdocbranch1']++;
                    if($df>=8 and $df<=14)$gwork[$i]['chkdocbranch2']++;
                    if($df>=15 and $df<=21)$gwork[$i]['chkdocbranch3']++;
                    if($df>=22 and $df<=27)$gwork[$i]['chkdocbranch4']++;
                    if($df>27)$gwork[$i]['chkdocbranch5']++;
                  }
                  //ส่งงานไปห้องทะเบียน
                  if(!empty($row['chkdate0']) and !empty($row['chkdate1']) and !is_null($row['chkdate2']) and $row['chkstatus2']=='C'){
                    $gwork[$i]['sentreg']++;
                    $date1=new DateTime($row['chkdate1']);
                    $date2=new DateTime($row['chkdate2']);
                    $diff=$date1->diff($date2);
                    $df=($diff->format("%a")+1);
                    if($df>=1 and $df<=2)$gwork[$i]['sentreg1']++;
                    if($df>=3 and $df<=4)$gwork[$i]['sentreg2']++;
                    if($df>=5 and $df<=6)$gwork[$i]['sentreg3']++;
                    if($df>=7 and $df<=8)$gwork[$i]['sentreg4']++;
                    if($df>8)$gwork[$i]['sentreg5']++;
                  }
                  //ห้องทะเบียนตรวจรับ
                  if(!empty($row['chkdate2']) and !empty($row['ACPDATE'])){
                    $gwork[$i]['regreceipt']++;
                    $date1=new DateTime($row['chkdate2']);
                    $date2=new DateTime($row['ACPDATE']);
                    $diff=$date1->diff($date2);
                    $df=($diff->format("%a")+1);
                    if($df>=1 and $df<=2)$gwork[$i]['regreceipt1']++;
                    if($df>=3 and $df<=4)$gwork[$i]['regreceipt2']++;
                    if($df>=5 and $df<=6)$gwork[$i]['regreceipt3']++;
                    if($df>=7 and $df<=8)$gwork[$i]['regreceipt4']++;
                    if($df>8)$gwork[$i]['regreceipt5']++;
                  }
                }
              }
            }
            for($i=0;$i<count($gwork);$i++){
              echo "<tr style='white-space: nowrap;'>";
              echo "<td>".$gwork[$i]['g_id']."</td>";
              echo "<td>".$gwork[$i]['g_name']."</td>";
              echo "<td><a data-toggle='modal' data-target='#gworkmodal'>".$gwork[$i]['allbill']."</a></td>";
              echo "<td>".($gwork[$i]['chkbill']-$gwork[$i]['allbill'])."</td>";
              echo "<td>".$gwork[$i]['return']."</td>";
              echo "<td>".$gwork[$i]['resent']."</td>";
              echo "<td>".$gwork[$i]['chkbill']."</td>";
              echo "<td>".$gwork[$i]['chkbill1']."</td>";
              echo "<td>".$gwork[$i]['chkbill2']."</td>";
              echo "<td>".$gwork[$i]['chkbill3']."</td>";
              echo "<td>".$gwork[$i]['chkbill4']."</td>";
              echo "<td>".$gwork[$i]['chkbill5']."</td>";
              echo "<td>".$gwork[$i]['chkdocbranch']."</td>";
              echo "<td>".$gwork[$i]['chkdocbranch1']."</td>";
              echo "<td>".$gwork[$i]['chkdocbranch2']."</td>";
              echo "<td>".$gwork[$i]['chkdocbranch3']."</td>";
              echo "<td>".$gwork[$i]['chkdocbranch4']."</td>";
              echo "<td>".$gwork[$i]['chkdocbranch5']."</td>";
              echo "<td>".$gwork[$i]['sentreg']."</td>";
              echo "<td>".$gwork[$i]['sentreg1']."</td>";
              echo "<td>".$gwork[$i]['sentreg2']."</td>";
              echo "<td>".$gwork[$i]['sentreg3']."</td>";
              echo "<td>".$gwork[$i]['sentreg4']."</td>";
              echo "<td>".$gwork[$i]['sentreg5']."</td>";
              echo "<td>".$gwork[$i]['regreceipt']."</td>";
              echo "<td>".$gwork[$i]['regreceipt1']."</td>";
              echo "<td>".$gwork[$i]['regreceipt2']."</td>";
              echo "<td>".$gwork[$i]['regreceipt3']."</td>";
              echo "<td>".$gwork[$i]['regreceipt4']."</td>";
              echo "<td>".$gwork[$i]['regreceipt5']."</td>";
              echo "</tr>";
            }
        ?>
          </tbody>
        </table>
      </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>
      <p class="text-red">เดือน <?php echo $thai_month_arr[$month]." ".$year1; ?></p>
    </div>
    <div class="box-body">
      <div class="form-group">
        <table id="tabla1" class="table table-striped table-bordered" style="width:100%;font-size: 14px;">
          <thead style="white-space: nowrap">
            <tr>
              <th style="white-space: nowrap;" rowspan="3">ลำดับ</th>
              <th style="white-space: nowrap;" rowspan="3">รายการ</th>
              <th style="white-space: nowrap;" rowspan="3">รายการสั่งทำ</th>
              <th rowspan="3" style="color: blue;">รวมเบิกเงิน</th>
              <th colspan="5">เบิกดำเนินการ (วันตรวจรับ-วันเบิก)</th>
              <th rowspan="3" style="color: blue;">รวมตีเช็ค</th>
              <th colspan="5">วันตีเช็ค (วันเบิก-วันตีเช็ค)</th>
            </tr>
            <tr>
              <td style="white-space: nowrap;">1-7</td>
              <td style="white-space: nowrap;">8-14</td>
              <td style="white-space: nowrap;">15-21</td>
              <td style="white-space: nowrap;">22-27</td>
              <td style="white-space: nowrap;">>27</td>
              <td style="white-space: nowrap;">1-6</td>
              <td style="white-space: nowrap;">7-14</td>
              <td style="white-space: nowrap;">15-21</td>
              <td style="white-space: nowrap;">22-27</td>
              <td style="white-space: nowrap;">>27</td>
            </tr>
            <tr>
              <td style="color: red;">0</td>
              <td style="color: red;">0</td>
              <td style="color: red;">0</td>
              <td style="color: red;">0</td>
              <td style="color: red;">0</td>
              <td style="color: red;">0</td>
              <td style="color: red;">0</td>
              <td style="color: red;">0</td>
              <td style="color: red;">0</td>
              <td style="color: red;">0</td>
            </tr>
          </thead>
          <tbody>
        <?php
            for($i=0;$i<count($reglist);$i++){
                $reglist[$i]+=array("reglist"=>0);
                //เบิกดำเนินการ
                $reglist[$i]+=array("berglist"=>0);
                $reglist[$i]+=array("berglist1"=>0);
                $reglist[$i]+=array("berglist2"=>0);
                $reglist[$i]+=array("berglist3"=>0);
                $reglist[$i]+=array("berglist4"=>0);
                $reglist[$i]+=array("berglist5"=>0);
                //วันตีเช็ค
                $reglist[$i]+=array("getcheck"=>0);
                $reglist[$i]+=array("getcheck1"=>0);
                $reglist[$i]+=array("getcheck2"=>0);
                $reglist[$i]+=array("getcheck3"=>0);
                $reglist[$i]+=array("getcheck4"=>0);
                $reglist[$i]+=array("getcheck5"=>0);
            }
            $sql="SELECT *
                  from ehongdb.dbo.reg_billdata a
                    LEFT OUTER JOIN(
                      SELECT br_id,BR_NAME,SZONE_CODE,PR_CODE
                      FROM EHONGDB.dbo.BRANCH
                    ) b on a.BR_ID=b.BR_ID
                  where (a.status<>'V') ";
            if(count($allbillno)>0){
              $sql.="and BILL_NO in(";
              $sql.="'".$allbillno[0]."'";
              for($i=1;$i<count($allbillno);$i++){
                $sql.=",'".$allbillno[$i]."'";
              }
              $sql.=")";
            }
            $sql.="order by BILL_DATE";
            // echo $sql."<br>";
            $stmt=$conn->prepare($sql);
            $stmt->execute();
            while($row = $stmt->fetch()) {
              for($i=0;$i<count($reglist);$i++){
                if($reglist[$i]['fid']==$row['FEE_NO']){
                  //รายการสั่งทำที่ตรวจรับในเดือน
                  $reglist[$i]['reglist']++;
                  //เบิกดำเนินการ
                  if(!empty($row['CHK_BERG']) and !empty($row['acpdate'])){
                    $reglist[$i]['berglist']++;
                    $date1=new DateTime($row['acpdate']);
                    $date2=new DateTime($row['CHK_BERG']);
                    $diff=$date1->diff($date2);
                    $df=($diff->format("%a")+1);
                    if($df>=1 and $df<=7)$reglist[$i]['berglist1']++;
                    if($df>=8 and $df<=14)$reglist[$i]['berglist2']++;
                    if($df>=15 and $df<=21)$reglist[$i]['berglist3']++;
                    if($df>=22 and $df<=27)$reglist[$i]['berglist4']++;
                    if($df>27)$reglist[$i]['berglist5']++;
                  }
                  //วันตีเช็ค
                  if(!empty($row['CHK_BERG']) and !empty($row['chq_no']) and !empty($row['chq_date'])){
                    $reglist[$i]['getcheck']++;
                    $date1=new DateTime($row['CHK_BERG']);
                    $date2=new DateTime($row['chq_date']);
                    $diff=$date1->diff($date2);
                    $df=($diff->format("%a")+1);
                    if($df>=1 and $df<=6)$reglist[$i]['getcheck1']++;
                    if($df>=7 and $df<=14)$reglist[$i]['getcheck2']++;
                    if($df>=15 and $df<=21)$reglist[$i]['getcheck3']++;
                    if($df>=22 and $df<=27)$reglist[$i]['getcheck4']++;
                    if($df>27)$reglist[$i]['getcheck5']++;
                  }
                }
              }
            }
            for($i=0;$i<count($reglist);$i++){
              echo "<tr style='white-space: nowrap;'>";
              echo "<td>".$reglist[$i]['fid']."</td>";
              echo "<td>".$reglist[$i]['fname']."</td>";
              echo "<td>".$reglist[$i]['reglist']."</td>";
              echo "<td>".$reglist[$i]['berglist']."</td>";
              echo "<td>".$reglist[$i]['berglist1']."</td>";
              echo "<td>".$reglist[$i]['berglist2']."</td>";
              echo "<td>".$reglist[$i]['berglist3']."</td>";
              echo "<td>".$reglist[$i]['berglist4']."</td>";
              echo "<td>".$reglist[$i]['berglist5']."</td>";
              echo "<td>".$reglist[$i]['getcheck']."</td>";
              echo "<td>".$reglist[$i]['getcheck1']."</td>";
              echo "<td>".$reglist[$i]['getcheck2']."</td>";
              echo "<td>".$reglist[$i]['getcheck3']."</td>";
              echo "<td>".$reglist[$i]['getcheck4']."</td>";
              echo "<td>".$reglist[$i]['getcheck5']."</td>";
              echo "</tr>";
            }
        ?>
          </tbody>
        </table>
      </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>
      <p class="text-red">เดือน <?php echo $thai_month_arr[$month]." ".$year1; ?></p>
    </div>
    <div class="box-body">
      <div class="form-group">
        <table id="tabla2" class="table table-striped table-bordered" style="width:100%;font-size: 14px;">
          <thead style="white-space: nowrap">
            <tr>
              <th style="white-space: nowrap;" rowspan="3">ลำดับ</th>
              <th style="white-space: nowrap;" rowspan="3">รายการ</th>
              <th style="white-space: nowrap;" rowspan="3">จำนวนรายการ</th>
              <th rowspan="3" style="color: blue;">จำนวนรายการตีเช็ค</th>
              <th colspan="5">วันที่รับงานจากขนส่ง (วันตีเช็ค-วันรับงาน)</th>
              <th rowspan="3" style="color: blue;">รวมส่งออก</th>
              <th colspan="5">ส่งงานไปห้องสาขา (วันรับงาน-วันส่งงานห้องสาขา)</th>
              <th rowspan="3" style="color: blue;">รวมตรวจรับ</th>
              <th colspan="5">ห้องส่งสาขาตรวจรับ (วันส่งงานห้องสาขา-วันตรวจรับ)</th>
              <th rowspan="3" style="color: blue;">รวมส่งออก</th>
              <th colspan="5">ส่งออกสาขา (วันตรวจรับ-วันส่งออกสาขา)</th>
              <th rowspan="3" style="color: blue;">รวมสาขารับ</th>
              <th colspan="5">สาขาตรวจรับ (วันส่งออกสาขา-สาขาตรวจรับ)</th>
              <th rowspan="3" style="color: blue;">รวมลูกค้ารับ</th>
              <th colspan="5">ลูกค้ารับงาน (สาขาตรวจรับ-ลูกค้ารับงาน)</th>
            </tr>
            <tr>
              <td style="white-space: nowrap;"><30</td>
              <td style="white-space: nowrap;">30-45</td>
              <td style="white-space: nowrap;">46-50</td>
              <td style="white-space: nowrap;">51-65</td>
              <td style="white-space: nowrap;">>65</td>
              <td style="white-space: nowrap;">1-3</td>
              <td style="white-space: nowrap;">4-6</td>
              <td style="white-space: nowrap;">7-9</td>
              <td style="white-space: nowrap;">10-12</td>
              <td style="white-space: nowrap;">>12</td>
              <td style="white-space: nowrap;">1-3</td>
              <td style="white-space: nowrap;">4-6</td>
              <td style="white-space: nowrap;">7-9</td>
              <td style="white-space: nowrap;">10-12</td>
              <td style="white-space: nowrap;">>12</td>
              <td style="white-space: nowrap;">1-7</td>
              <td style="white-space: nowrap;">8-14</td>
              <td style="white-space: nowrap;">15-21</td>
              <td style="white-space: nowrap;">22-30</td>
              <td style="white-space: nowrap;">>30</td>
              <td style="white-space: nowrap;">1-14</td>
              <td style="white-space: nowrap;">15-21</td>
              <td style="white-space: nowrap;">22-27</td>
              <td style="white-space: nowrap;">28-35</td>
              <td style="white-space: nowrap;">>35</td>
              <td style="white-space: nowrap;">1-14</td>
              <td style="white-space: nowrap;">15-21</td>
              <td style="white-space: nowrap;">22-27</td>
              <td style="white-space: nowrap;">28-35</td>
              <td style="white-space: nowrap;">>35</td>
            </tr>
            <tr>
              <td style="color: red;">1.5</td>
              <td style="color: red;">1</td>
              <td style="color: red;">0.5</td>
              <td style="color: red;">0.5</td>
              <td style="color: red;">-1</td>
              <td style="color: red;">0</td>
              <td style="color: red;">0</td>
              <td style="color: red;">0</td>
              <td style="color: red;">0</td>
              <td style="color: red;">0</td>
              <td style="color: red;">0</td>
              <td style="color: red;">0</td>
              <td style="color: red;">0</td>
              <td style="color: red;">0</td>
              <td style="color: red;">0</td>
              <td style="color: red;">0</td>
              <td style="color: red;">0</td>
              <td style="color: red;">0</td>
              <td style="color: red;">0</td>
              <td style="color: red;">0</td>
              <td style="color: red;">0</td>
              <td style="color: red;">0</td>
              <td style="color: red;">0</td>
              <td style="color: red;">0</td>
              <td style="color: red;">0</td>
              <td style="color: red;">0</td>
              <td style="color: red;">0</td>
              <td style="color: red;">0</td>
              <td style="color: red;">0</td>
              <td style="color: red;">0</td>
            </tr>
          </thead>
          <tbody>
        <?php
            for($i=0;$i<count($fdoclist);$i++){
                $fdoclist[$i]+=array("fdoc_all"=>0);
                //วันที่รับงานจากขนส่ง
                $fdoclist[$i]+=array("gettrans"=>0);
                $fdoclist[$i]+=array("gettrans1"=>0);
                $fdoclist[$i]+=array("gettrans2"=>0);
                $fdoclist[$i]+=array("gettrans3"=>0);
                $fdoclist[$i]+=array("gettrans4"=>0);
                $fdoclist[$i]+=array("gettrans5"=>0);
                //ส่งงานไปห้องส่งสาขา
                $fdoclist[$i]+=array("tosentroom"=>0);
                $fdoclist[$i]+=array("tosentroom1"=>0);
                $fdoclist[$i]+=array("tosentroom2"=>0);
                $fdoclist[$i]+=array("tosentroom3"=>0);
                $fdoclist[$i]+=array("tosentroom4"=>0);
                $fdoclist[$i]+=array("tosentroom5"=>0);
                //ห้องส่งสาขาตรวจรับ
                $fdoclist[$i]+=array("sentroomacpt"=>0);
                $fdoclist[$i]+=array("sentroomacpt1"=>0);
                $fdoclist[$i]+=array("sentroomacpt2"=>0);
                $fdoclist[$i]+=array("sentroomacpt3"=>0);
                $fdoclist[$i]+=array("sentroomacpt4"=>0);
                $fdoclist[$i]+=array("sentroomacpt5"=>0);
                //ส่งออกสาขา
                $fdoclist[$i]+=array("sentbranch"=>0);
                $fdoclist[$i]+=array("sentbranch1"=>0);
                $fdoclist[$i]+=array("sentbranch2"=>0);
                $fdoclist[$i]+=array("sentbranch3"=>0);
                $fdoclist[$i]+=array("sentbranch4"=>0);
                $fdoclist[$i]+=array("sentbranch5"=>0);
                //สาขาตรวจรับ
                $fdoclist[$i]+=array("branchacpt"=>0);
                $fdoclist[$i]+=array("branchacpt1"=>0);
                $fdoclist[$i]+=array("branchacpt2"=>0);
                $fdoclist[$i]+=array("branchacpt3"=>0);
                $fdoclist[$i]+=array("branchacpt4"=>0);
                $fdoclist[$i]+=array("branchacpt5"=>0);
                //ลูกค้ารับงาน
                $fdoclist[$i]+=array("cusacpt"=>0);
                $fdoclist[$i]+=array("cusacpt1"=>0);
                $fdoclist[$i]+=array("cusacpt2"=>0);
                $fdoclist[$i]+=array("cusacpt3"=>0);
                $fdoclist[$i]+=array("cusacpt4"=>0);
                $fdoclist[$i]+=array("cusacpt5"=>0);
            }
            $sql="SELECT *
                  from ehongdb.dbo.reg_billdatadocument a
                    LEFT OUTER join(
                      SELECT BILL_NO,FEE_NO,chq_date,chq_no
                      FROM [EHONGDB].[dbo].[REG_BILLDATA]
                    ) b on a.BILL_NO=b.BILL_NO and a.FEE_NO=b.FEE_NO
                  where (a.status<>'V') ";
            if(count($allbillno)>0){
              $sql.="and a.BILL_NO in(";
              $sql.="'".$allbillno[0]."'";
              for($i=1;$i<count($allbillno);$i++){
                $sql.=",'".$allbillno[$i]."'";
              }
              $sql.=")";
            }
            $sql.="order by a.FDOC_NO";
            // echo $sql."<br>";
            $stmt=$conn->prepare($sql);
            $stmt->execute();
            while($row = $stmt->fetch()) {
              for($i=0;$i<count($fdoclist);$i++){
                if($fdoclist[$i]['fdoc_no']==$row['FDOC_NO']){
                  //รายการสั่งทำที่ตีเช็คในเดือน
                  $fdoclist[$i]['fdoc_all']++;
                  //วันที่รับงานจากขนส่ง
                  if(!empty($row['chq_date']) and !empty($row['FNDATE'])){
                    $fdoclist[$i]['gettrans']++;
                    $date1=new DateTime($row['chq_date']);
                    $date2=new DateTime($row['FNDATE']);
                    $diff=$date1->diff($date2);
                    $df=($diff->format("%a")+1);
                    if($df>=1 and $df<=29)$fdoclist[$i]['gettrans1']++;
                    if($df>=30 and $df<=45)$fdoclist[$i]['gettrans2']++;
                    if($df>=46 and $df<=50)$fdoclist[$i]['gettrans3']++;
                    if($df>=51 and $df<=65)$fdoclist[$i]['gettrans4']++;
                    if($df>65)$fdoclist[$i]['gettrans5']++;
                  }
                  //ส่งงานไปห้องส่งสาขา
                  if(!empty($row['chksntlogistic_date']) and !empty($row['FNDATE'])){
                    $fdoclist[$i]['tosentroom']++;
                    $date1=new DateTime($row['FNDATE']);
                    $date2=new DateTime($row['chksntlogistic_date']);
                    $diff=$date1->diff($date2);
                    $df=($diff->format("%a")+1);
                    if($df>=1 and $df<=3)$fdoclist[$i]['tosentroom1']++;
                    if($df>=4 and $df<=6)$fdoclist[$i]['tosentroom2']++;
                    if($df>=7 and $df<=9)$fdoclist[$i]['tosentroom3']++;
                    if($df>=10 and $df<=12)$fdoclist[$i]['tosentroom4']++;
                    if($df>12)$fdoclist[$i]['tosentroom5']++;
                  }
                  //ห้องส่งสาขาตรวจรับ
                  if(!empty($row['chksntlogistic_date']) and !empty($row['chkacplogistic_date'])){
                    $fdoclist[$i]['sentroomacpt']++;
                    $date1=new DateTime($row['chksntlogistic_date']);
                    $date2=new DateTime($row['chkacplogistic_date']);
                    $diff=$date1->diff($date2);
                    $df=($diff->format("%a")+1);
                    if($df>=1 and $df<=3)$fdoclist[$i]['sentroomacpt1']++;
                    if($df>=4 and $df<=6)$fdoclist[$i]['sentroomacpt2']++;
                    if($df>=7 and $df<=9)$fdoclist[$i]['sentroomacpt3']++;
                    if($df>=10 and $df<=12)$fdoclist[$i]['sentroomacpt4']++;
                    if($df>12)$fdoclist[$i]['sentroomacpt5']++;
                  }
                  //ส่งออกสาขา
                  if(!empty($row['chkacplogistic_date']) and !empty($row['SENTBRDATE'])){
                    $fdoclist[$i]['sentbranch']++;
                    $date1=new DateTime($row['chkacplogistic_date']);
                    $date2=new DateTime($row['SENTBRDATE']);
                    $diff=$date1->diff($date2);
                    $df=($diff->format("%a")+1);
                    if($df>=1 and $df<=7)$fdoclist[$i]['sentbranch1']++;
                    if($df>=8 and $df<=14)$fdoclist[$i]['sentbranch2']++;
                    if($df>=15 and $df<=21)$fdoclist[$i]['sentbranch3']++;
                    if($df>=22 and $df<=30)$fdoclist[$i]['sentbranch4']++;
                    if($df>30)$fdoclist[$i]['sentbranch5']++;
                  }
                  //สาขาตรวจรับ
                  if(!empty($row['BRACPDATE']) and !empty($row['SENTBRDATE'])){
                    $fdoclist[$i]['branchacpt']++;
                    $date1=new DateTime($row['SENTBRDATE']);
                    $date2=new DateTime($row['BRACPDATE']);
                    $diff=$date1->diff($date2);
                    $df=($diff->format("%a")+1);
                    if($df>=1 and $df<=14)$fdoclist[$i]['branchacpt1']++;
                    if($df>=15 and $df<=21)$fdoclist[$i]['branchacpt2']++;
                    if($df>=22 and $df<=27)$fdoclist[$i]['branchacpt3']++;
                    if($df>=28 and $df<=35)$fdoclist[$i]['branchacpt4']++;
                    if($df>35)$fdoclist[$i]['branchacpt5']++;
                  }
                  //ลูกค้ารับงาน
                  if(!empty($row['CUSTACPDATE']) and !empty($row['BRACPDATE'])){
                    $fdoclist[$i]['cusacpt']++;
                    $date1=new DateTime($row['BRACPDATE']);
                    $date2=new DateTime($row['CUSTACPDATE']);
                    $diff=$date1->diff($date2);
                    $df=($diff->format("%a")+1);
                    if($df>=1 and $df<=14)$fdoclist[$i]['cusacpt1']++;
                    if($df>=15 and $df<=21)$fdoclist[$i]['cusacpt2']++;
                    if($df>=22 and $df<=27)$fdoclist[$i]['cusacpt3']++;
                    if($df>=28 and $df<=35)$fdoclist[$i]['cusacpt4']++;
                    if($df>35)$fdoclist[$i]['cusacpt5']++;
                  }
                }
              }
            }
            for($i=0;$i<count($fdoclist);$i++){
              echo "<tr style='white-space: nowrap;'>";
              echo "<td>".$fdoclist[$i]['fdoc_no']."</td>";
              echo "<td>".$fdoclist[$i]['fdoc_name']."</td>";
              echo "<td>".$fdoclist[$i]['fdoc_all']."</td>";
              echo "<td>".$fdoclist[$i]['gettrans']."</td>";
              echo "<td>".$fdoclist[$i]['gettrans1']."</td>";
              echo "<td>".$fdoclist[$i]['gettrans2']."</td>";
              echo "<td>".$fdoclist[$i]['gettrans3']."</td>";
              echo "<td>".$fdoclist[$i]['gettrans4']."</td>";
              echo "<td>".$fdoclist[$i]['gettrans5']."</td>";
              echo "<td>".$fdoclist[$i]['tosentroom']."</td>";
              echo "<td>".$fdoclist[$i]['tosentroom1']."</td>";
              echo "<td>".$fdoclist[$i]['tosentroom2']."</td>";
              echo "<td>".$fdoclist[$i]['tosentroom3']."</td>";
              echo "<td>".$fdoclist[$i]['tosentroom4']."</td>";
              echo "<td>".$fdoclist[$i]['tosentroom5']."</td>";
              echo "<td>".$fdoclist[$i]['sentroomacpt']."</td>";
              echo "<td>".$fdoclist[$i]['sentroomacpt1']."</td>";
              echo "<td>".$fdoclist[$i]['sentroomacpt2']."</td>";
              echo "<td>".$fdoclist[$i]['sentroomacpt3']."</td>";
              echo "<td>".$fdoclist[$i]['sentroomacpt4']."</td>";
              echo "<td>".$fdoclist[$i]['sentroomacpt5']."</td>";
              echo "<td>".$fdoclist[$i]['sentbranch']."</td>";
              echo "<td>".$fdoclist[$i]['sentbranch1']."</td>";
              echo "<td>".$fdoclist[$i]['sentbranch2']."</td>";
              echo "<td>".$fdoclist[$i]['sentbranch3']."</td>";
              echo "<td>".$fdoclist[$i]['sentbranch4']."</td>";
              echo "<td>".$fdoclist[$i]['sentbranch5']."</td>";
              echo "<td>".$fdoclist[$i]['branchacpt']."</td>";
              echo "<td>".$fdoclist[$i]['branchacpt1']."</td>";
              echo "<td>".$fdoclist[$i]['branchacpt2']."</td>";
              echo "<td>".$fdoclist[$i]['branchacpt3']."</td>";
              echo "<td>".$fdoclist[$i]['branchacpt4']."</td>";
              echo "<td>".$fdoclist[$i]['branchacpt5']."</td>";
              echo "<td>".$fdoclist[$i]['cusacpt']."</td>";
              echo "<td>".$fdoclist[$i]['cusacpt1']."</td>";
              echo "<td>".$fdoclist[$i]['cusacpt2']."</td>";
              echo "<td>".$fdoclist[$i]['cusacpt3']."</td>";
              echo "<td>".$fdoclist[$i]['cusacpt4']."</td>";
              echo "<td>".$fdoclist[$i]['cusacpt5']."</td>";
              echo "</tr>";
            }
        ?>
          </tbody>
        </table>
      </div>
    </div>
  </div>
</div>
