<?php
if (isset($_POST['submit_1']) != "") {
  $namesll = "สาขา";
  $sll = "a.BR_ID,a.BR_NAME";
  $SLnumber = "a.BR_ID as NUMBERS,ax.BR_NAME";
  $SLnumber2 = "a.BR_ID,ax.BR_NAME";
  $SLnumber3 = "('0001') as NUMBERS";
  $SLnumber4 = "a.packbranch as NUMBERS,ax.BR_NAME";
  $SLnumber5 = "a.packbranch,ax.BR_NAME";
  $bst_sll = "";
  $bst = "";
  $nb = "2";
}
if (isset($_POST['submit_2']) != "") {
  $namesll = "เขต";
  $sll = "b.szone_code,b.szone_name";
  $SLnumber = "bx.szone_code as NUMBERS,bx.szone_name";
  $SLnumber2 = "bx.szone_code,bx.szone_name";
  $SLnumber3 = "('01') as NUMBERS";
  $SLnumber4 = "bx.szone_code as NUMBERS,bx.szone_name";
  $SLnumber5 = "bx.szone_code,bx.szone_name";
  $bst_sll = ",bst.EMP_SC,bst.EMP_NAME,bst.EMP_TLE";
  $bst = "left outer join(SELECT * FROM [CONFIG].[dbo].[EMP_BST]) bst on (bst.EMP_SC=b.szone_code)";
  $nb = "4";
}
if (isset($_POST['submit_3']) != "") {
  $namesll = "ภาค";
  $sll = "b.zstaff_id,b.zstaff_name";
  $SLnumber = "bx.zstaff_id as NUMBERS,bx.zstaff_name";
  $SLnumber2 = "bx.zstaff_id,bx.zstaff_name";
  $SLnumber3 = "('01') as NUMBERS";
  $SLnumber4 = "bx.zstaff_id as NUMBERS,bx.zstaff_name";
  $SLnumber5 = "bx.zstaff_id,bx.zstaff_name";
  $bst_sll = "";
  $bst = "";
  $nb = "2";
}

if ($br_id != "") {
  $BR_ID_AND = "AND a.BR_ID = '$br_id'";
  $bid = "amd a.BR_ID = '$br_id'";
} else {
  $BR_ID_AND = "";
  $bid = "";
}
if ($zone_codex != "") {
  $szone_code_AND = "AND b.szone_code = '$zone_codex'";
  $szc = "and bx.szone_code = '$zone_codex' ";
} else {
  $szone_code_AND = "";
  $szc = "";
}
if ($zstaff_idx != "") {
  $zstaff_id_AND = "AND b.zstaff_id = '$zstaff_idx'";
  $zid = "and bx.zstaff_id = '$zstaff_idx' ";
} else {
  $zstaff_id_AND = "";
  $zid = "";
}
?>
<?php
include '_reg_report.php';
?>
<div class="col-md-12">
<div class="box box-success">
  <div class="box-header">
    <h3 class="box-title"><p class="text-success">รายงานทะเบียนตรวจสอบ <?php echo $namesll; ?></p></h3>
    <p class="text-red">เดือน <?php echo $thai_month_arr[$date_1]." ".$date_2; ?></p>
  </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="2" style="background-color:black; color:#fff; text-align:center;">NO.</th>
              <th rowspan="2" style="background-color:black; color:#fff; text-align:center;"><?php echo $namesll; ?></th>
              <?php
                if (isset($_POST['submit_2']) != "") {
              ?>
              <th rowspan="2" style="background-color:black; color:#fff; text-align:center;">ผู้ดูแล</th>
              <th rowspan="2" style="background-color:black; color:#fff; text-align:center;">เบอร์โทร</th>
              <?php
                }
              ?>
              <th colspan="3" style="background-color:black; color:#fff; text-align:center;">ทะเบียนค้างรับงาน</th>
              <th colspan="2" style="background-color:black; color:#fff; text-align:center;">ลูกค้าค้างรับ</th>
              <th colspan="10" style="background-color:black; color:#fff; text-align:center;">ทะเบียนตรวจไม่ผ่าน</th>

              <th colspan="2" style="background-color:black; color:#fff; text-align:center;">ทะเบียนค้างรับงาน (ไฟแนนซ์)</th>
            </tr>
            <tr>
              <th style="background-color:blue; color:#fff; text-align:center;">บรรจุซองค้างส่ง</th>
              <th style="background-color:blue; color:#fff; text-align:center;">สาขาค้างรับ</th>

              <th style="background-color:blue; color:#fff; text-align:center;">ลูกค้าค้างรับ</th>
              <!-- <th style="background-color:blue; color:#fff; text-align:center;">น้อยกว่า 45 วัน</th>
              <th style="background-color:blue; color:#fff; text-align:center;">เกิน 45 วัน</th> -->
              <th style="background-color:green; color:#fff; text-align:center;"><i class="fa fa-arrow-circle-left" aria-hidden="true"></i> 45 วัน</th>
              <th style="background-color:red; color:#fff; text-align:center;"><i class="fa fa-arrow-circle-right" aria-hidden="true"></i> 45 วัน</th>

              <th style="background-color:yellow; color:#000; text-align:center;">ตรวจใบเสร็จไม่ผ่าน</th>
              <th style="background-color:yellow; color:red; text-align:center;">รอเอกสารสาขา</th>

              <th style="background-color:Gold; color:#000; text-align:center;">เอกสารไม่พร้อม</th>
              <th style="background-color:Gold; color:#000; text-align:center;"><i class="fa fa-arrow-circle-left" aria-hidden="true"></i> <?php echo $datetb_3_543; ?></th>
              <th style="background-color:Gold; color:#000; text-align:center;"><?php echo $datetb_2_543; ?></th>
              <th style="background-color:Gold; color:#000; text-align:center;"><?php echo $datetb_1_543; ?></th>

              <th style="background-color:yellow; color:#000; text-align:center;">รายงานตีคืนจากขนส่ง</th>
              <th style="background-color:yellow; color:#000; text-align:center;"><i class="fa fa-arrow-circle-left" aria-hidden="true"></i> <?php echo $datetb_3_543; ?></th>
              <th style="background-color:yellow; color:#000; text-align:center;"><?php echo $datetb_2_543; ?></th>
              <th style="background-color:yellow; color:#000; text-align:center;"><?php echo $datetb_1_543; ?></th>

              <th style="background-color:red; color:#fff; text-align:center;">สาขาค้างรับ (ไฟแนนซ์)</th>
              <th style="background-color:red; color:#fff; text-align:center;">ลูกค้าค้างรับ (ไฟแนนซ์)</th>
            </tr>
          </thead>
          <tbody style="white-space: nowrap">
            <?php
            $sql = "SELECT $sll $bst_sll FROM [EHONGDB].[dbo].[BRANCH] a
            left outer join(SELECT * FROM [EHONGDB].[dbo].[branch_salezone]) b on (a.SZONE_CODE=b.szone_code)
            $bst
            WHERE a.BR_ID != '%'
            $BR_ID_AND $szone_code_AND $zstaff_id_AND
            GROUP BY $sll $bst_sll
            ORDER BY $sll";
            // echo $sql;
            $select=$conn_z->prepare($sql);
            $select->execute();
            $item = 1;
            $sum_exco_1 = 0;
            $sum_exco_2 = 0;
            $sum_exco_3 = 0;
            $sum_exco_4 = 0;
            $sum_exco_a1 = 0;
            $sum_exco_a2 = 0;
            $sum_exco_a2_x1 = 0;
            $sum_exco_a2_x2 = 0;
            $sum_exco_a2_x3 = 0;
            $sum_exco_b1 = 0;
            $sum_exco_b2 = 0;
            $sum_echonumber_245a = 0;
            $sum_echonumber_245b = 0;
            $sum_echonumberk1 = 0;
            $sum_exco_b2_x1 = 0;
            $sum_exco_b2_x2 = 0;
            $sum_exco_b2_x3 = 0;
            while($fetch=$select->fetch()){
            ?>
            <tr>
              <td style="background-color:; color:; text-align:;"><?php echo number_format($item); ?>.</td>
              <?php
              if (isset($_POST['submit_1']) != "") {
                $echonumber_1 = isset($number_1[$fetch['BR_ID']]) ? $number_1[$fetch['BR_ID']] : "0";
                $echonumber_2 = isset($number_2[$fetch['BR_ID']]) ? $number_2[$fetch['BR_ID']] : "0";
                $echonumber_3 = isset($number_3[$fetch['BR_ID']]) ? $number_3[$fetch['BR_ID']] : "0";
                $echonumber_4 = isset($number_4[$fetch['BR_ID']]) ? $number_4[$fetch['BR_ID']] : "0";
                $echonumber_a1 = isset($number_a1[$fetch['BR_ID']]) ? $number_a1[$fetch['BR_ID']] : "0";

                $echonumber_a2 = isset($number_a2[$fetch['BR_ID']]) ? $number_a2[$fetch['BR_ID']] : "0";
                $echonumber_a2_x1 = isset($number_a2_x1[$fetch['BR_ID']]) ? $number_a2_x1[$fetch['BR_ID']] : "0";
                $echonumber_a2_x2 = isset($number_a2_x2[$fetch['BR_ID']]) ? $number_a2_x2[$fetch['BR_ID']] : "0";
                $echonumber_a2_x3 = isset($number_a2_x3[$fetch['BR_ID']]) ? $number_a2_x3[$fetch['BR_ID']] : "0";


                $echonumber_b1 = isset($number_b1[$fetch['BR_ID']]) ? $number_b1[$fetch['BR_ID']] : "0";
                $echonumber_b2 = isset($number_b2[$fetch['BR_ID']]) ? $number_b2[$fetch['BR_ID']] : "0";
                $echonumber_b2_x3 = isset($number_b2_x3[$fetch['BR_ID']]) ? $number_b2_x3[$fetch['BR_ID']] : "0";
                $echonumber_b2_x2 = isset($number_b2_x2[$fetch['BR_ID']]) ? $number_b2_x2[$fetch['BR_ID']] : "0";
                $echonumber_b2_x1 = isset($number_b2_x1[$fetch['BR_ID']]) ? $number_b2_x1[$fetch['BR_ID']] : "0";


                $echonumber_245a = isset($number_245a[$fetch['BR_ID']]) ? $number_245a[$fetch['BR_ID']] : "0";
                $echonumber_245b = isset($number_245b[$fetch['BR_ID']]) ? $number_245b[$fetch['BR_ID']] : "0";

                $echonumberk1 = isset($numberk1[$fetch['BR_ID']]) ? $numberk1[$fetch['BR_ID']] : "0";
              ?>
                <td style="background-color:; color:; text-align:;"><?php echo $fetch['BR_ID']." : ".$fetch['BR_NAME']; ?></td>
              <?php
              }
              if (isset($_POST['submit_2']) != "") {
                $echonumber_1 = isset($number_1[$fetch['szone_code']]) ? $number_1[$fetch['szone_code']] : "0";
                $echonumber_2 = isset($number_2[$fetch['szone_code']]) ? $number_2[$fetch['szone_code']] : "0";
                $echonumber_3 = isset($number_3[$fetch['szone_code']]) ? $number_3[$fetch['szone_code']] : "0";
                $echonumber_4 = isset($number_4[$fetch['szone_code']]) ? $number_4[$fetch['szone_code']] : "0";
                $echonumber_a1 = isset($number_a1[$fetch['szone_code']]) ? $number_a1[$fetch['szone_code']] : "0";

                $echonumber_a2 = isset($number_a2[$fetch['szone_code']]) ? $number_a2[$fetch['szone_code']] : "0";
                $echonumber_a2_x1 = isset($number_a2_x1[$fetch['szone_code']]) ? $number_a2_x1[$fetch['szone_code']] : "0";
                $echonumber_a2_x2 = isset($number_a2_x2[$fetch['szone_code']]) ? $number_a2_x2[$fetch['szone_code']] : "0";
                $echonumber_a2_x3 = isset($number_a2_x3[$fetch['szone_code']]) ? $number_a2_x3[$fetch['szone_code']] : "0";

                $echonumber_b1 = isset($number_b1[$fetch['szone_code']]) ? $number_b1[$fetch['szone_code']] : "0";
                $echonumber_b2 = isset($number_b2[$fetch['szone_code']]) ? $number_b2[$fetch['szone_code']] : "0";
                $echonumber_b2_x3 = isset($number_b2_x3[$fetch['szone_code']]) ? $number_b2_x3[$fetch['szone_code']] : "0";
                $echonumber_b2_x2 = isset($number_b2_x2[$fetch['szone_code']]) ? $number_b2_x2[$fetch['szone_code']] : "0";
                $echonumber_b2_x1 = isset($number_b2_x1[$fetch['szone_code']]) ? $number_b2_x1[$fetch['szone_code']] : "0";

                $echonumber_245a = isset($number_245a[$fetch['szone_code']]) ? $number_245a[$fetch['szone_code']] : "0";
                $echonumber_245b = isset($number_245b[$fetch['szone_code']]) ? $number_245b[$fetch['szone_code']] : "0";

                $echonumberk1 = isset($numberk1[$fetch['szone_code']]) ? $numberk1[$fetch['szone_code']] : "0";
              ?>
                <td style="background-color:; color:; text-align:;"><?php echo $fetch['szone_code']." : ".$fetch['szone_name']; ?></td>
                <td style="background-color:; color:; text-align:;"><?php echo $fetch['EMP_NAME']; ?></td>
                <td style="background-color:; color:; text-align:;"><?php echo $fetch['EMP_TLE']; ?></td>
              <?php
              }
              if (isset($_POST['submit_3']) != "") {
                $echonumber_1 = isset($number_1[$fetch['zstaff_id']]) ? $number_1[$fetch['zstaff_id']] : "0";
                $echonumber_2 = isset($number_2[$fetch['zstaff_id']]) ? $number_2[$fetch['zstaff_id']] : "0";
                $echonumber_3 = isset($number_3[$fetch['zstaff_id']]) ? $number_3[$fetch['zstaff_id']] : "0";
                $echonumber_4 = isset($number_4[$fetch['zstaff_id']]) ? $number_4[$fetch['zstaff_id']] : "0";
                $echonumber_a1 = isset($number_a1[$fetch['zstaff_id']]) ? $number_a1[$fetch['zstaff_id']] : "0";

                $echonumber_a2 = isset($number_a2[$fetch['zstaff_id']]) ? $number_a2[$fetch['zstaff_id']] : "0";
                $echonumber_a2_x1 = isset($number_a2_x1[$fetch['zstaff_id']]) ? $number_a2_x1[$fetch['zstaff_id']] : "0";
                $echonumber_a2_x2 = isset($number_a2_x2[$fetch['zstaff_id']]) ? $number_a2_x2[$fetch['zstaff_id']] : "0";
                $echonumber_a2_x3 = isset($number_a2_x3[$fetch['zstaff_id']]) ? $number_a2_x3[$fetch['zstaff_id']] : "0";

                $echonumber_b1 = isset($number_b1[$fetch['zstaff_id']]) ? $number_b1[$fetch['zstaff_id']] : "0";
                $echonumber_b2 = isset($number_b2[$fetch['zstaff_id']]) ? $number_b2[$fetch['zstaff_id']] : "0";

                $echonumber_245a = isset($number_245a[$fetch['zstaff_id']]) ? $number_245a[$fetch['zstaff_id']] : "0";
                $echonumber_245b = isset($number_245b[$fetch['zstaff_id']]) ? $number_245b[$fetch['zstaff_id']] : "0";
                $echonumber_b2_x3 = isset($number_b2_x3[$fetch['zstaff_id']]) ? $number_b2_x3[$fetch['zstaff_id']] : "0";
                $echonumber_b2_x2 = isset($number_b2_x2[$fetch['zstaff_id']]) ? $number_b2_x2[$fetch['zstaff_id']] : "0";
                $echonumber_b2_x1 = isset($number_b2_x1[$fetch['zstaff_id']]) ? $number_b2_x1[$fetch['zstaff_id']] : "0";

                $echonumberk1 = isset($numberk1[$fetch['zstaff_id']]) ? $numberk1[$fetch['zstaff_id']] : "0";
              ?>
                <td style="background-color:; color:; text-align:;"><?php echo $fetch['zstaff_id']." : ".$fetch['zstaff_name']; ?></td>
              <?php }
              // $br_id
              // $zone_codex
              // $zstaff_idx
              // echo $fetch['BR_ID'];
              // echo $fetch['szone_code'];
                if ($br_id != "") {
                  $BR_IDS = $br_id;
                }
                else {
                  $BR_IDS = $fetch['BR_ID'];
                }
                if ($zone_codex != "") {
                  $ZSONE_CODES = $zone_codex;
                }
                else {
                  $ZSONE_CODES = $fetch['szone_code'];
                }
                if ($zstaff_idx != "") {
                  $ZSTAFFS = $zstaff_idx;
                }
                else {
                  $ZSTAFFS = $fetch['zstaff_id'];
                }
              ?>
              <td style="background-color:; color:; text-align:right;"><a href="reg_indexecho_4.php?BR_IDS=<?php echo $BR_IDS; ?>&ZSONE_CODES=<?php echo $ZSONE_CODES; ?>&ZSTAFFS=<?php echo $ZSTAFFS; ?>&ST=b1&date_1=<?php echo $date_1; ?>&date_2=<?php echo $date_2_1; ?>" style="color:#000" target="_blank"><?php echo number_format($echonumber_b1); ?></a></td>
              <td style="background-color:; color:; text-align:right;"><a href="reg_indexecho_1.php?BR_IDS=<?php echo $BR_IDS; ?>&ZSONE_CODES=<?php echo $ZSONE_CODES; ?>&ZSTAFFS=<?php echo $ZSTAFFS; ?>&ST=1" style="color:#000" target="_blank"><?php echo number_format($echonumber_1); ?></a></td>

              <td style="background-color:; color:; text-align:right;"><a href="reg_indexecho_1.php?BR_IDS=<?php echo $BR_IDS; ?>&ZSONE_CODES=<?php echo $ZSONE_CODES; ?>&ZSTAFFS=<?php echo $ZSTAFFS; ?>&ST=2" style="color:#000" target="_blank"><?php echo number_format($echonumber_2); ?></a></td>
              <td style="background-color:; color:blue; text-align:right;"><a href="reg_indexecho_1.php?BR_IDS=<?php echo $BR_IDS; ?>&ZSONE_CODES=<?php echo $ZSONE_CODES; ?>&ZSTAFFS=<?php echo $ZSTAFFS; ?>&ST=245a" style="color:blue" target="_blank"><?php echo number_format($echonumber_245a); ?></a></td>
              <td style="background-color:; color:red; text-align:right;"><a href="reg_indexecho_1.php?BR_IDS=<?php echo $BR_IDS; ?>&ZSONE_CODES=<?php echo $ZSONE_CODES; ?>&ZSTAFFS=<?php echo $ZSTAFFS; ?>&ST=245b" style="color:red" target="_blank"><?php echo number_format($echonumber_245b); ?></a></td>

              <td style="background-color:; color:; text-align:right;"><a href="reg_indexecho_2.php?BR_IDS=<?php echo $BR_IDS; ?>&ZSONE_CODES=<?php echo $ZSONE_CODES; ?>&ZSTAFFS=<?php echo $ZSTAFFS; ?>&ST=a1" style="color:#000" target="_blank"><?php echo number_format($echonumber_a1); ?></a></td>

              <td style="background-color:; color:red; text-align:right;"><a href="reg_indexecho_6.php?BR_IDS=<?php echo $BR_IDS; ?>&ZSONE_CODES=<?php echo $ZSONE_CODES; ?>&ZSTAFFS=<?php echo $ZSTAFFS; ?>&ST=k1&date_1=<?php echo $date_1; ?>&date_2=<?php echo $date_2_1; ?>" style="color:red" target="_blank"><?php echo number_format($echonumberk1); ?></a> </td>

              <td style="background-color:; color:; text-align:right;"><a href="reg_indexecho_3.php?BR_IDS=<?php echo $BR_IDS; ?>&ZSONE_CODES=<?php echo $ZSONE_CODES; ?>&ZSTAFFS=<?php echo $ZSTAFFS; ?>&ST=a2&datetb=" style="color:#000" target="_blank"><?php echo number_format($echonumber_a2); ?></a></td>
              <td style="background-color:; color:; text-align:right;"><a href="reg_indexecho_3.php?BR_IDS=<?php echo $BR_IDS; ?>&ZSONE_CODES=<?php echo $ZSONE_CODES; ?>&ZSTAFFS=<?php echo $ZSTAFFS; ?>&ST=a2&datetb=<=<?php echo $datetb_3; ?>" style="color:#000" target="_blank"><?php echo number_format($echonumber_a2_x3); ?></a></td>
              <td style="background-color:; color:; text-align:right;"><a href="reg_indexecho_3.php?BR_IDS=<?php echo $BR_IDS; ?>&ZSONE_CODES=<?php echo $ZSONE_CODES; ?>&ZSTAFFS=<?php echo $ZSTAFFS; ?>&ST=a2&datetb==<?php echo $datetb_2; ?>" style="color:#000" target="_blank"><?php echo number_format($echonumber_a2_x2); ?></a></td>
              <td style="background-color:; color:; text-align:right;"><a href="reg_indexecho_3.php?BR_IDS=<?php echo $BR_IDS; ?>&ZSONE_CODES=<?php echo $ZSONE_CODES; ?>&ZSTAFFS=<?php echo $ZSTAFFS; ?>&ST=a2&datetb==<?php echo $datetb_1; ?>" style="color:#000" target="_blank"><?php echo number_format($echonumber_a2_x1); ?></a></td>

              <td style="background-color:; color:; text-align:right;"><a href="reg_indexecho_5.php?BR_IDS=<?php echo $BR_IDS; ?>&ZSONE_CODES=<?php echo $ZSONE_CODES; ?>&ZSTAFFS=<?php echo $ZSTAFFS; ?>&ST=b2&datetb=" style="color:#000" target="_blank"><?php echo number_format($echonumber_b2); ?></a></td>
              <td style="background-color:; color:; text-align:right;"><a href="reg_indexecho_5.php?BR_IDS=<?php echo $BR_IDS; ?>&ZSONE_CODES=<?php echo $ZSONE_CODES; ?>&ZSTAFFS=<?php echo $ZSTAFFS; ?>&ST=b2_x1&datetb=<=<?php echo $datetb_3; ?>" style="color:#000" target="_blank"><?php echo number_format($echonumber_b2_x1); ?></a></td>
              <td style="background-color:; color:; text-align:right;"><a href="reg_indexecho_5.php?BR_IDS=<?php echo $BR_IDS; ?>&ZSONE_CODES=<?php echo $ZSONE_CODES; ?>&ZSTAFFS=<?php echo $ZSTAFFS; ?>&ST=b2_x2&datetb==<?php echo $datetb_2; ?>" style="color:#000" target="_blank"><?php echo number_format($echonumber_b2_x2); ?></a></td>
              <td style="background-color:; color:; text-align:right;"><a href="reg_indexecho_5.php?BR_IDS=<?php echo $BR_IDS; ?>&ZSONE_CODES=<?php echo $ZSONE_CODES; ?>&ZSTAFFS=<?php echo $ZSTAFFS; ?>&ST=b2_x3&datetb==<?php echo $datetb_1; ?>" style="color:#000" target="_blank"><?php echo number_format($echonumber_b2_x3); ?></a></td>

              <td style="background-color:; color:; text-align:right;"><a href="reg_indexecho_1.php?BR_IDS=&ZSONE_CODES=&ZSTAFFS=&ST=3" style="color:#000" target="_blank"><?php echo number_format($echonumber_3); ?></a></td>
              <td style="background-color:; color:; text-align:right;"><a href="reg_indexecho_1.php?BR_IDS=&ZSONE_CODES=&ZSTAFFS=&ST=4" style="color:#000" target="_blank"><?php echo number_format($echonumber_4); ?></a></td>

            </tr>
            <?php
              $item++;
              $sum_exco_1 += $echonumber_1;
              $sum_exco_2 += $echonumber_2;
              $sum_exco_3 += $echonumber_3;
              $sum_exco_4 += $echonumber_4;
              $sum_exco_a1 += $echonumber_a1;

              $sum_exco_a2 += $echonumber_a2;
              $sum_exco_a2_x1 += $echonumber_a2_x1;
              $sum_exco_a2_x2 += $echonumber_a2_x2;
              $sum_exco_a2_x3 += $echonumber_a2_x3;

              $sum_exco_b1 += $echonumber_b1;
              $sum_exco_b2 += $echonumber_b2;
              $sum_exco_b2_x1 += $echonumber_b2_x1;
              $sum_exco_b2_x2 += $echonumber_b2_x2;
              $sum_exco_b2_x3 += $echonumber_b2_x3;

              $sum_echonumber_245a += $echonumber_245a;
              $sum_echonumber_245b += $echonumber_245b;

              $sum_echonumberk1 += $echonumberk1;
              }
            ?>
          </tbody>
          <tfoot>
            <tr>
              <th colspan="<?php echo $nb; ?>" style="background-color:black; color:#fff; text-align:center;">รวม</th>
              <th style="background-color:blue; color:#fff; text-align:right;"> <a href="reg_indexecho_4.php?BR_IDS=<?php echo $br_id; ?>&ZSONE_CODES=<?php echo $zone_codex; ?>&ZSTAFFS=<?php echo $zstaff_idx; ?>&ST=b1&date_1=<?php echo $date_1; ?>&date_2=<?php echo $date_2_1; ?>" target="_blank" style="color:#fff"><?php echo number_format($sum_exco_b1); ?></a></th>
              <th style="background-color:blue; color:#fff; text-align:right;"> <a href="reg_indexecho_1.php?BR_IDS=<?php echo $br_id; ?>&ZSONE_CODES=<?php echo $zone_codex; ?>&ZSTAFFS=<?php echo $zstaff_idx; ?>&ST=SUM1" target="_blank" style="color:#fff"><?php echo number_format($sum_exco_1); ?></a></th>

              <th style="background-color:blue; color:#fff; text-align:right;"> <a href="reg_indexecho_1.php?BR_IDS=<?php echo $br_id; ?>&ZSONE_CODES=<?php echo $zone_codex; ?>&ZSTAFFS=<?php echo $zstaff_idx; ?>&ST=SUM2" target="_blank" style="color:#fff"><?php echo number_format($sum_exco_2); ?></a></th>
              <th style="background-color:green; color:#fff; text-align:right;"> <a href="reg_indexecho_1.php?BR_IDS=<?php echo $br_id; ?>&ZSONE_CODES=<?php echo $zone_codex; ?>&ZSTAFFS=<?php echo $zstaff_idx; ?>&ST=SUM245a" target="_blank" style="color:#fff"><?php echo number_format($sum_echonumber_245a); ?></a> </th>
              <th style="background-color:red; color:#fff; text-align:right;"> <a href="reg_indexecho_1.php?BR_IDS=<?php echo $br_id; ?>&ZSONE_CODES=<?php echo $zone_codex; ?>&ZSTAFFS=<?php echo $zstaff_idx; ?>&ST=SUM245b" target="_blank" style="color:#fff"><?php echo number_format($sum_echonumber_245b); ?></a> </th>

              <th style="background-color:yellow; color:#000; text-align:right;"> <a href="reg_indexecho_2.php?BR_IDS=<?php echo $br_id; ?>&ZSONE_CODES=<?php echo $zone_codex; ?>&ZSTAFFS=<?php echo $zstaff_idx; ?>&ST=a1" target="_blank" style="color:#000"><?php echo number_format($sum_exco_a1); ?></a></th>

              <th style="background-color:yellow; color:red; text-align:right;" style="color:#000"><a href="reg_indexecho_6.php?BR_IDS=<?php echo $br_id; ?>&ZSONE_CODES=<?php echo $zone_codex; ?>&ZSTAFFS=<?php echo $zstaff_idx; ?>&ST=k1&date_1=<?php echo $date_1; ?>&date_2=<?php echo $date_2_1; ?>" style="color:red" target="_blank"><?php echo number_format($sum_echonumberk1); ?></a> </th>

              <th style="background-color:Gold; color:#000; text-align:right;"> <a href="reg_indexecho_3.php?BR_IDS=<?php echo $br_id; ?>&ZSONE_CODES=<?php echo $zone_codex; ?>&ZSTAFFS=<?php echo $zstaff_idx; ?>&ST=a2&datetb=" target="_blank" style="color:#000"><?php echo number_format($sum_exco_a2); ?></a></th>
              <th style="background-color:Gold; color:#000; text-align:right;"> <a href="reg_indexecho_3.php?BR_IDS=<?php echo $br_id; ?>&ZSONE_CODES=<?php echo $zone_codex; ?>&ZSTAFFS=<?php echo $zstaff_idx; ?>&ST=a2&datetb=<=<?php echo $datetb_3; ?>" target="_blank" style="color:#000"><?php echo number_format($sum_exco_a2_x3); ?></a></th>
              <th style="background-color:Gold; color:#000; text-align:right;"> <a href="reg_indexecho_3.php?BR_IDS=<?php echo $br_id; ?>&ZSONE_CODES=<?php echo $zone_codex; ?>&ZSTAFFS=<?php echo $zstaff_idx; ?>&ST=a2&datetb==<?php echo $datetb_2; ?>" target="_blank" style="color:#000"><?php echo number_format($sum_exco_a2_x2); ?></a></th>
              <th style="background-color:Gold; color:#000; text-align:right;"> <a href="reg_indexecho_3.php?BR_IDS=<?php echo $br_id; ?>&ZSONE_CODES=<?php echo $zone_codex; ?>&ZSTAFFS=<?php echo $zstaff_idx; ?>&ST=a2&datetb==<?php echo $datetb_1; ?>" target="_blank" style="color:#000"><?php echo number_format($sum_exco_a2_x1); ?></a></th>

              <th style="background-color:yellow; color:#000; text-align:right;"> <a href="reg_indexecho_5.php?BR_IDS=<?php echo $br_id; ?>&ZSONE_CODES=<?php echo $zone_codex; ?>&ZSTAFFS=<?php echo $zstaff_idx; ?>&ST=b2&datetb=" target="_blank" style="color:#000"><?php echo number_format($sum_exco_b2); ?></a></th>
              <th style="background-color:yellow; color:#000; text-align:right;"> <a href="reg_indexecho_5.php?BR_IDS=<?php echo $br_id; ?>&ZSONE_CODES=<?php echo $zone_codex; ?>&ZSTAFFS=<?php echo $zstaff_idx; ?>&ST=b2_x1&datetb=<=<?php echo $datetb_3; ?>" target="_blank" style="color:#000"><?php echo number_format($sum_exco_b2_x1); ?></a></th>
              <th style="background-color:yellow; color:#000; text-align:right;"> <a href="reg_indexecho_5.php?BR_IDS=<?php echo $br_id; ?>&ZSONE_CODES=<?php echo $zone_codex; ?>&ZSTAFFS=<?php echo $zstaff_idx; ?>&ST=b2_x2&datetb==<?php echo $datetb_2; ?>" target="_blank" style="color:#000"><?php echo number_format($sum_exco_b2_x2); ?></a></th>
              <th style="background-color:yellow; color:#000; text-align:right;"> <a href="reg_indexecho_5.php?BR_IDS=<?php echo $br_id; ?>&ZSONE_CODES=<?php echo $zone_codex; ?>&ZSTAFFS=<?php echo $zstaff_idx; ?>&ST=b2_x3&datetb==<?php echo $datetb_1; ?>" target="_blank" style="color:#000"><?php echo number_format($sum_exco_b2_x3); ?></a></th>


              <th style="background-color:red; color:#fff; text-align:right;"> <a href="reg_indexecho_1.php?BR_IDS=<?php echo $br_id; ?>&ZSONE_CODES=<?php echo $zone_codex; ?>&ZSTAFFS=<?php echo $zstaff_idx; ?>&ST=3" style="color:#fff" target="_blank" style="color:#fff"><?php echo number_format($sum_exco_3); ?></a></th>
              <th style="background-color:red; color:#fff; text-align:right;"> <a href="reg_indexecho_1.php?BR_IDS=<?php echo $br_id; ?>&ZSONE_CODES=<?php echo $zone_codex; ?>&ZSTAFFS=<?php echo $zstaff_idx; ?>&ST=4" style="color:#fff" target="_blank" style="color:#fff"><?php echo number_format($sum_exco_4); ?></a></th>

            </tr>
          </tfoot>
      </table>
    </div>
    </div>
  </div>
</div>
</div>
