<!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';
?>
</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>
      <div class="col-md-12">
        <div class="box box-warning">
          <div class="box-header with-border">
            <h3 class="box-title">ค้นหารายงานรวม</h3>
          </div>
          <?php
            if (isset($_POST['search'])) {
              $DMY1 = $_POST["DMY1"]; // วันที่
              $DMY2 = $_POST["DMY2"]; // ถึงวันที่

              $calcdate1 = substr($DMY1,0,4); $calcdate2 = substr($DMY1,5,2); $calcdate3 = substr($DMY1,8,2);
              $calcdate = $calcdate3."/".$calcdate2."/".$calcdate1;

              $calcdate12 = substr($DMY2,0,4); $calcdate22 = substr($DMY2,5,2); $calcdate32 = substr($DMY2,8,2);
              $calcdate25 = $calcdate32."/".$calcdate22."/".$calcdate12;

              $MY = $calcdate1."_".$calcdate2;

              $day1 = $_POST["DMY1"];
              $day2 = $_POST["DMY2"];
              $BR_ID = $_POST['BR_ID'];
              $szone_code = $_POST['szone_code'];
              $zstaff_id = $_POST['zstaff_id'];

              if ($BR_ID != "") { $BR_ID_AND = "AND c.BR_ID = '$BR_ID'";
              } else {$BR_ID_AND = ""; }
              if ($szone_code != "") { $szone_code_AND = "AND d.szone_code = '$szone_code'";
              } else { $szone_code_AND = ""; }
              if ($zstaff_id != "") { $zstaff_id_AND = "AND d.zstaff_id = '$zstaff_id'";
              } else { $zstaff_id_AND = ""; }
            }
            else {
              $D = date('d');
              $Y = date('Y')+543;

              $Eday = date('d');
              $year = date('Y');
              $month2 = date('m');
              $Eday1 = date('Y-m-t',strtotime($year."-".$month2."-".'01'));
              $Eday2 = substr($Eday1,8,2);
              $day1 = $year."-".$month2."-01";
              $day2 = $year."-".$month2."-".$Eday;

              $BR_ID = "";
              $szone_code = "";
              $zstaff_id = "";
            }
          ?>
          <!-- target="_blank" info_2.php-->
          <form role="form" action="infofrom_dashboard.php" method="POST" enctype="multipart/form-data" >
            <div class="box-body">
              <div class="row">
                <div class="col-xs-2">
                  <p>วันที่</p>
                  <input type="date" class="form-control" placeholder="" name="DMY1" value="<?php echo $day1; ?>">
                </div>
                <div class="col-xs-2">
                  <p>ถึงวันที่</p>
                  <input type="date" class="form-control" placeholder="" name="DMY2" value="<?php echo $day2; ?>">
                </div>
                <div class="col-xs-2">
                  <p>สาขา</p>
                  <select class="form-control" name="BR_ID" >
                    <?php
                    $sql = "SELECT * FROM EHONGDB.dbo.BRANCH WHERE BR_NAME NOT IN ('รวมทุกสาขา') AND BR_ID = '$BR_ID' ORDER BY BR_ID";
                    $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_NAME NOT IN ('รวมทุกสาขา') ORDER BY BR_ID";
                    $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="szone_code" placeholder="ผจก.เขต">
                    <?php
                    $sql = "SELECT * FROM EHONGDB.dbo.branch_salezone WHERE szone_code = '$szone_code' 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="zstaff_id" placeholder="ผจก.เขต">
                    <?php
                    $sql = "SELECT DISTINCT zstaff_id,zstaff_name FROM EHONGDB.dbo.branch_salezone WHERE zstaff_id = '$zstaff_id' ORDER BY zstaff_id,zstaff_name";
                    $select=$conn->prepare($sql);
                    $select->execute();
                    while($fetch=$select->fetch()) {
                    ?>
                    <option value="<?php echo $fetch['zstaff_id'];?>"><?php echo $fetch['zstaff_id']." : ".$fetch['zstaff_name'];?></option>
                    <?php } ?>
                    <option value="">-- รวมทุกภาค --</option>
                    <?php
                    $sql = "SELECT DISTINCT zstaff_id,zstaff_name FROM EHONGDB.dbo.branch_salezone ORDER BY zstaff_id,zstaff_name";
                    $select=$conn->prepare($sql);
                    $select->execute();
                    while($fetch=$select->fetch()) {
                    ?>
                    <option value="<?php echo $fetch['zstaff_id'];?>"><?php echo $fetch['zstaff_id']." : ".$fetch['zstaff_name'];?></option>
                    <?php } ?>
                  </select>
                </div>
              </div>
            </div>

            <div class="box-footer">
              <input type="submit" class="btn btn-warning" name="search" value="ดูรายงานย้อนหลัง">
            </div>
          </form>

        </div>
      </div>

      <?php if (isset($_POST['search'])) { ?>
        <?php
        $DMY1 = $_POST["DMY1"]; // วันที่
        $DMY2 = $_POST["DMY2"]; // ถึงวันที่

        $calcdate1 = substr($DMY1,0,4); $calcdate2 = substr($DMY1,5,2); $calcdate3 = substr($DMY1,8,2);
        $calcdate = $calcdate3."/".$calcdate2."/".$calcdate1;

        $calcdate12 = substr($DMY2,0,4); $calcdate22 = substr($DMY2,5,2); $calcdate32 = substr($DMY2,8,2);
        $calcdate25 = $calcdate32."/".$calcdate22."/".$calcdate12;

        $MY = $calcdate1."_".$calcdate2;
        // echo $DMY1.$DMY2.$MY;
        $BR_ID = $_POST['BR_ID'];
        $szone_code = $_POST['szone_code'];
        $zstaff_id = $_POST['zstaff_id'];

        if ($BR_ID != "") { $BR_ID_AND = "AND c.BR_ID = '$BR_ID'";
        } else {$BR_ID_AND = ""; }
        if ($szone_code != "") { $szone_code_AND = "AND d.szone_code = '$szone_code'";
        } else { $szone_code_AND = ""; }
        if ($zstaff_id != "") { $zstaff_id_AND = "AND d.zstaff_id = '$zstaff_id'";
        } else { $zstaff_id_AND = ""; }
      ?>
        <div class="col-md-6">
          <div class="box box-danger">
            <div class="box-body">
              <div class="form-group">
                <div class="col-md-12">
                  <p class="text-center">
                    <strong>สาขา</strong>
                  </p>
                  <?php
                    $sql_1 = "SELECT
                      infofrom
                      ,sum(t1.infosum) as infosum
                      ,sum(t1.info_1) as info_1
                    FROM [HPSDB].[dbo].[hps_ctmain_".$MY."] a
                    left outer join(SELECT CT_NO,BR_ID,infofrom,infofromchk
                      ,count(infofrom) as infosum
                      ,sum(case when (infofrom is null) then 1 else 0 end) as info_1
                    FROM [EHONGDB].[dbo].[PRESALE_AUDITSALE_SUMMARY] GROUP BY CT_NO,BR_ID,infofrom,infofromchk) t1 on (a.CT_NO=t1.CT_NO)
                    left outer join(SELECT * FROM [EHONGDB].[dbo].[BRANCH]) c on (a.BR_ID=c.BR_ID)
                    left outer join(SELECT * FROM [EHONGDB].[dbo].[branch_salezone]) d on (c.SZONE_CODE=d.szone_code)
                    WHERE a.BILL_DATE BETWEEN '$DMY1 00:00:00' AND '$DMY2 00:00:00'
                     and (a.status<>'X') and (a.product_id like 'มซ%') and (a.ct_no like '0%' or a.ct_no like '2%')
                     $BR_ID_AND $szone_code_AND $zstaff_id_AND
                    GROUP BY infofrom
                    ORDER BY infofrom";
                    $select_1=$conn->prepare($sql_1);
                    $select_1->execute();
                    $suminfo = 0;
                    while($fetch_1=$select_1->fetch()){
                      $suminfo += $fetch_1['infosum']+$fetch_1['info_1'];
                    }

                    $sql = "SELECT
                      infofrom
                      ,sum(t1.infosum) as infosum
                      ,sum(t1.info_1) as info_1
                    FROM [HPSDB].[dbo].[hps_ctmain_".$MY."] a
                    left outer join(SELECT CT_NO,BR_ID,infofrom,infofromchk
                      ,count(infofrom) as infosum
                      ,sum(case when (infofrom is null) then 1 else 0 end) as info_1
                    FROM [EHONGDB].[dbo].[PRESALE_AUDITSALE_SUMMARY] GROUP BY CT_NO,BR_ID,infofrom,infofromchk) t1 on (a.CT_NO=t1.CT_NO)
                    left outer join(SELECT * FROM [EHONGDB].[dbo].[BRANCH]) c on (a.BR_ID=c.BR_ID)
                    left outer join(SELECT * FROM [EHONGDB].[dbo].[branch_salezone]) d on (c.SZONE_CODE=d.szone_code)
                    WHERE a.BILL_DATE BETWEEN '$DMY1 00:00:00' AND '$DMY2 00:00:00'
                     and (a.status<>'X') and (a.product_id like 'มซ%') and (a.ct_no like '0%' or a.ct_no like '2%')
                     $BR_ID_AND $szone_code_AND $zstaff_id_AND
                    GROUP BY infofrom
                    ORDER BY infofrom";
                    $select=$conn->prepare($sql);
                    $select->execute();
                    while($fetch=$select->fetch()){
                      if ($fetch['infofrom'] == "") {
                        $infofrom = "ว่าง";
                      }
                      else {
                        $infofrom = $fetch['infofrom'];
                      }

                      $infosum = $fetch['infosum']+$fetch['info_1'];
                      $persen = $infosum/$suminfo*100;

                      if ($persen <= '29') {
                        $color = "red";
                      }
                      if ($persen >= '30') {
                        $color = "yellow";
                      }
                      if ($persen >= '50') {
                        $color = "aqua";
                      }
                      if ($persen >= '80') {
                        $color = "green";
                      }

                      ?>
                  <div class="progress-group">
                    <span class="progress-text"><?php echo $infofrom; ?> - <b class="text-<?php echo $color; ?>"><?php echo number_format($persen,2)."%"; ?></b> </span>
                    <span class="progress-number"><b class="text-<?php echo $color; ?>"><?php echo $infosum; ?></b> / <?php echo number_format($suminfo); ?></span>

                    <div class="progress sm">
                      <div class="progress-bar progress-bar-<?php echo $color; ?>" style="width:<?php echo number_format($persen,2); ?>%"></div>
                    </div>
                  </div>
                  <?php } ?>
                </div>
              </div>
            </div>
          </div>
        </div>

        <div class="col-md-6">
          <div class="box box-success">
            <div class="box-body">
              <div class="form-group-">
                <div class="col-md-12">
                  <p class="text-center">
                    <strong>อนุมัติ</strong>
                  </p>
                  <?php
                    $sql_1 = "SELECT
                      infofromchk
                      infofromchk
                      ,sum(t1.infosum) as infosum
                      ,sum(t1.info_1) as info_1
                    FROM [HPSDB].[dbo].[hps_ctmain_".$MY."] a
                    left outer join(SELECT CT_NO,BR_ID,infofrom,infofromchk
                      ,count(infofromchk) as infosum
                      ,sum(case when (infofromchk is null) then 1 else 0 end) as info_1
                    FROM [EHONGDB].[dbo].[PRESALE_AUDITSALE_SUMMARY] GROUP BY CT_NO,BR_ID,infofrom,infofromchk) t1 on (a.CT_NO=t1.CT_NO)
                    left outer join(SELECT * FROM [EHONGDB].[dbo].[BRANCH]) c on (a.BR_ID=c.BR_ID)
                    left outer join(SELECT * FROM [EHONGDB].[dbo].[branch_salezone]) d on (c.SZONE_CODE=d.szone_code)
                    WHERE a.BILL_DATE BETWEEN '$DMY1 00:00:00' AND '$DMY2 00:00:00'
                     and (a.status<>'X') and (a.product_id like 'มซ%') and (a.ct_no like '0%' or a.ct_no like '2%')
                     $BR_ID_AND $szone_code_AND $zstaff_id_AND
                    GROUP BY infofromchk
                    ORDER BY infofromchk";
                    $select_1=$conn->prepare($sql_1);
                    $select_1->execute();
                    $suminfo_1 = 0;
                    while($fetch_1=$select_1->fetch()){
                      $suminfo_1 += $fetch_1['infosum']+$fetch_1['info_1'];
                    }

                    $sql = "SELECT
                      infofromchk
                      ,sum(t1.infosum) as infosum
                      ,sum(t1.info_1) as info_1
                    FROM [HPSDB].[dbo].[hps_ctmain_".$MY."] a
                    left outer join(SELECT CT_NO,BR_ID,infofrom,infofromchk
                      ,count(infofromchk) as infosum
                      ,sum(case when (infofromchk is null) then 1 else 0 end) as info_1
                    FROM [EHONGDB].[dbo].[PRESALE_AUDITSALE_SUMMARY] GROUP BY CT_NO,BR_ID,infofrom,infofromchk) t1 on (a.CT_NO=t1.CT_NO)
                    left outer join(SELECT * FROM [EHONGDB].[dbo].[BRANCH]) c on (a.BR_ID=c.BR_ID)
                    left outer join(SELECT * FROM [EHONGDB].[dbo].[branch_salezone]) d on (c.SZONE_CODE=d.szone_code)
                    WHERE a.BILL_DATE BETWEEN '$DMY1 00:00:00' AND '$DMY2 00:00:00'
                     and (a.status<>'X') and (a.product_id like 'มซ%') and (a.ct_no like '0%' or a.ct_no like '2%')
                     $BR_ID_AND $szone_code_AND $zstaff_id_AND
                    GROUP BY infofromchk
                    ORDER BY infofromchk";
                    $select=$conn->prepare($sql);
                    $select->execute();
                    while($fetch=$select->fetch()){
                      if ($fetch['infofromchk'] == "") {
                        $infofrom = "ว่าง";
                      }
                      else {
                        $infofrom = $fetch['infofromchk'];
                      }

                      $infosum = $fetch['infosum']+$fetch['info_1'];
                      $persen = $infosum/$suminfo_1*100;

                      if ($persen <= '29') {
                        $color = "red";
                      }
                      if ($persen >= '30') {
                        $color = "yellow";
                      }
                      if ($persen >= '50') {
                        $color = "aqua";
                      }
                      if ($persen >= '80') {
                        $color = "green";
                      }

                      ?>
                  <div class="progress-group">
                    <span class="progress-text"><?php echo $infofrom; ?> - <b class="text-<?php echo $color; ?>"><?php echo number_format($persen,2)."%"; ?></b> </span>
                    <span class="progress-number"><b class="text-<?php echo $color; ?>"><?php echo $infosum; ?></b> / <?php echo number_format($suminfo_1); ?></span>

                    <div class="progress sm">
                      <div class="progress-bar progress-bar-<?php echo $color; ?>" style="width:<?php echo number_format($persen,2); ?>%"></div>
                    </div>
                  </div>
                  <?php } ?>
                  <!-- /.progress-group -->
                </div>
              </div>
            </div>
          </div>
        </div>


      <?php } else { ?>
        <?php
        $MY = date('Y')."_".date('m');
        $Eday = date('d');
        $year = date('Y');
        $month2 = date('m');
        $Eday1 = date('Y-m-t',strtotime($year."-".$month2."-".'01'));
        $Eday2 = substr($Eday1,8,2);
        $DMY1 = $year."-".$month2."-01";
        $DMY2 = $year."-".$month2."-".$Eday;
        ?>
        <div class="col-md-6">
          <div class="box box-danger">
            <div class="box-body">
              <div class="form-group">
                <div class="col-md-12">
                  <p class="text-center">
                    <strong>สาขา</strong>
                  </p>
                  <?php
                    $sql_1 = "SELECT
                      infofrom
                      ,sum(t1.infosum) as infosum
                      ,sum(t1.info_1) as info_1
                    FROM [HPSDB].[dbo].[hps_ctmain_".$MY."] a
                    left outer join(SELECT CT_NO,BR_ID,infofrom,infofromchk
                      ,count(infofrom) as infosum
                      ,sum(case when (infofrom is null) then 1 else 0 end) as info_1
                    FROM [EHONGDB].[dbo].[PRESALE_AUDITSALE_SUMMARY] GROUP BY CT_NO,BR_ID,infofrom,infofromchk) t1 on (a.CT_NO=t1.CT_NO)
                    left outer join(SELECT * FROM [EHONGDB].[dbo].[BRANCH]) c on (a.BR_ID=c.BR_ID)
                    left outer join(SELECT * FROM [EHONGDB].[dbo].[branch_salezone]) d on (c.SZONE_CODE=d.szone_code)
                    WHERE a.BILL_DATE BETWEEN '$DMY1 00:00:00' AND '$DMY2 00:00:00'
                     and (a.status<>'X') and (a.product_id like 'มซ%') and (a.ct_no like '0%' or a.ct_no like '2%')
                    GROUP BY infofrom
                    ORDER BY infofrom";
                    $select_1=$conn->prepare($sql_1);
                    $select_1->execute();
                    $suminfo = 0;
                    while($fetch_1=$select_1->fetch()){
                      $suminfo += $fetch_1['infosum']+$fetch_1['info_1'];
                    }

                    $sql = "SELECT
                      infofrom
                      ,sum(t1.infosum) as infosum
                      ,sum(t1.info_1) as info_1
                    FROM [HPSDB].[dbo].[hps_ctmain_".$MY."] a
                    left outer join(SELECT CT_NO,BR_ID,infofrom,infofromchk
                      ,count(infofrom) as infosum
                      ,sum(case when (infofrom is null) then 1 else 0 end) as info_1
                    FROM [EHONGDB].[dbo].[PRESALE_AUDITSALE_SUMMARY] GROUP BY CT_NO,BR_ID,infofrom,infofromchk) t1 on (a.CT_NO=t1.CT_NO)
                    left outer join(SELECT * FROM [EHONGDB].[dbo].[BRANCH]) c on (a.BR_ID=c.BR_ID)
                    left outer join(SELECT * FROM [EHONGDB].[dbo].[branch_salezone]) d on (c.SZONE_CODE=d.szone_code)
                    WHERE a.BILL_DATE BETWEEN '$DMY1 00:00:00' AND '$DMY2 00:00:00'
                     and (a.status<>'X') and (a.product_id like 'มซ%') and (a.ct_no like '0%' or a.ct_no like '2%')
                    GROUP BY infofrom
                    ORDER BY infofrom";
                    $select=$conn->prepare($sql);
                    $select->execute();
                    while($fetch=$select->fetch()){
                      if ($fetch['infofrom'] == "") {
                        $infofrom = "ว่าง";
                      }
                      else {
                        $infofrom = $fetch['infofrom'];
                      }

                      $infosum = $fetch['infosum']+$fetch['info_1'];
                      $persen = $infosum/$suminfo*100;

                      if ($persen <= '29') {
                        $color = "red";
                      }
                      if ($persen >= '30') {
                        $color = "yellow";
                      }
                      if ($persen >= '50') {
                        $color = "aqua";
                      }
                      if ($persen >= '80') {
                        $color = "green";
                      }

                      ?>
                  <div class="progress-group">
                    <span class="progress-text"><?php echo $infofrom; ?> - <b class="text-<?php echo $color; ?>"><?php echo number_format($persen,2)."%"; ?></b> </span>
                    <span class="progress-number"><b class="text-<?php echo $color; ?>"><?php echo $infosum; ?></b> / <?php echo number_format($suminfo); ?></span>

                    <div class="progress sm">
                      <div class="progress-bar progress-bar-<?php echo $color; ?>" style="width:<?php echo number_format($persen,2); ?>%"></div>
                    </div>
                  </div>
                  <?php } ?>
                </div>
              </div>
            </div>
          </div>
        </div>

        <div class="col-md-6">
          <div class="box box-success">
            <div class="box-body">
              <div class="form-group-">
                <div class="col-md-12">
                  <p class="text-center">
                    <strong>อนุมัติ</strong>
                  </p>
                  <?php
                    $sql_1 = "SELECT
                      infofromchk
                      infofromchk
                      ,sum(t1.infosum) as infosum
                      ,sum(t1.info_1) as info_1
                    FROM [HPSDB].[dbo].[hps_ctmain_".$MY."] a
                    left outer join(SELECT CT_NO,BR_ID,infofrom,infofromchk
                      ,count(infofromchk) as infosum
                      ,sum(case when (infofromchk is null) then 1 else 0 end) as info_1
                    FROM [EHONGDB].[dbo].[PRESALE_AUDITSALE_SUMMARY] GROUP BY CT_NO,BR_ID,infofrom,infofromchk) t1 on (a.CT_NO=t1.CT_NO)
                    left outer join(SELECT * FROM [EHONGDB].[dbo].[BRANCH]) c on (a.BR_ID=c.BR_ID)
                    left outer join(SELECT * FROM [EHONGDB].[dbo].[branch_salezone]) d on (c.SZONE_CODE=d.szone_code)
                    WHERE a.BILL_DATE BETWEEN '$DMY1 00:00:00' AND '$DMY2 00:00:00'
                     and (a.status<>'X') and (a.product_id like 'มซ%') and (a.ct_no like '0%' or a.ct_no like '2%')
                    GROUP BY infofromchk
                    ORDER BY infofromchk";
                    $select_1=$conn->prepare($sql_1);
                    $select_1->execute();
                    $suminfo_1 = 0;
                    while($fetch_1=$select_1->fetch()){
                      $suminfo_1 += $fetch_1['infosum']+$fetch_1['info_1'];
                    }

                    $sql = "SELECT
                      infofromchk
                      ,sum(t1.infosum) as infosum
                      ,sum(t1.info_1) as info_1
                    FROM [HPSDB].[dbo].[hps_ctmain_".$MY."] a
                    left outer join(SELECT CT_NO,BR_ID,infofrom,infofromchk
                      ,count(infofromchk) as infosum
                      ,sum(case when (infofromchk is null) then 1 else 0 end) as info_1
                    FROM [EHONGDB].[dbo].[PRESALE_AUDITSALE_SUMMARY] GROUP BY CT_NO,BR_ID,infofrom,infofromchk) t1 on (a.CT_NO=t1.CT_NO)
                    left outer join(SELECT * FROM [EHONGDB].[dbo].[BRANCH]) c on (a.BR_ID=c.BR_ID)
                    left outer join(SELECT * FROM [EHONGDB].[dbo].[branch_salezone]) d on (c.SZONE_CODE=d.szone_code)
                    WHERE a.BILL_DATE BETWEEN '$DMY1 00:00:00' AND '$DMY2 00:00:00'
                     and (a.status<>'X') and (a.product_id like 'มซ%') and (a.ct_no like '0%' or a.ct_no like '2%')
                    GROUP BY infofromchk
                    ORDER BY infofromchk";
                    $select=$conn->prepare($sql);
                    $select->execute();
                    while($fetch=$select->fetch()){
                      if ($fetch['infofromchk'] == "") {
                        $infofrom = "ว่าง";
                      }
                      else {
                        $infofrom = $fetch['infofromchk'];
                      }

                      $infosum = $fetch['infosum']+$fetch['info_1'];
                      $persen = $infosum/$suminfo_1*100;

                      if ($persen <= '29') {
                        $color = "red";
                      }
                      if ($persen >= '30') {
                        $color = "yellow";
                      }
                      if ($persen >= '50') {
                        $color = "aqua";
                      }
                      if ($persen >= '80') {
                        $color = "green";
                      }

                      ?>
                  <div class="progress-group">
                    <span class="progress-text"><?php echo $infofrom; ?> - <b class="text-<?php echo $color; ?>"><?php echo number_format($persen,2)."%"; ?></b> </span>
                    <span class="progress-number"><b class="text-<?php echo $color; ?>"><?php echo $infosum; ?></b> / <?php echo number_format($suminfo_1); ?></span>

                    <div class="progress sm">
                      <div class="progress-bar progress-bar-<?php echo $color; ?>" style="width:<?php echo number_format($persen,2); ?>%"></div>
                    </div>
                  </div>
                  <?php } ?>
                  <!-- /.progress-group -->
                </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'; ?>
<?php include '3datatable.php' ?>
</body>
</html>
