<?php include("../templates/header.php"); ?>
<?php include("check_admin.php"); ?>

<?php
  include("../config/mysql_connect.php");

  $thai_day_arr=array("อาทิตย์","จันทร์","อังคาร","พุธ","พฤหัสบดี","ศุกร์","เสาร์");
  $thai_month_arr=array(
    "0"=>"",
    "1"=>"มกราคม",
    "2"=>"กุมภาพันธ์",
    "3"=>"มีนาคม",
    "4"=>"เมษายน",
    "5"=>"พฤษภาคม",
    "6"=>"มิถุนายน", 
    "7"=>"กรกฎาคม",
    "8"=>"สิงหาคม",
    "9"=>"กันยายน",
    "10"=>"ตุลาคม",
    "11"=>"พฤศจิกายน",
    "12"=>"ธันวาคม"                 
  );

  function thai_date($time){
    global $thai_day_arr,$thai_month_arr;
    $thai_date_return="วัน".$thai_day_arr[date("w",$time)];
    $thai_date_return.= "ที่ ".date("j",$time);
    $thai_date_return.=" ".$thai_month_arr[date("n",$time)];
    $thai_date_return.= " พ.ศ. ".(date("Y",$time)+543);
    return $thai_date_return;
  }

  $strSQL_acc = "SELECT * FROM tb_account";
  $objQuery_acc = mysqli_query($link,$strSQL_acc);
  while($Result_acc = mysqli_fetch_array($objQuery_acc)){

  $acc_id = $Result_acc['acc_id'];
  $acc_fname = $Result_acc['acc_fname'];
  $acc_lname = $Result_acc['acc_lname'];
  $acc_phone = $Result_acc['acc_phone'];
  $acc_commisssion = $Result_acc['acc_commission'];
  $rate1 = $Result_acc['rate1'];
  $rate2 = $Result_acc['rate2'];
  $rate3 = $Result_acc['rate3'];
  $rate4 = $Result_acc['rate4'];
  $rate5 = $Result_acc['rate5'];
  $rate6 = $Result_acc['rate6'];
  $acc_com5 = $Result_acc['acc_com5'];

  $Clear = "select * from tb_number where acc_id='$acc_id' and num_clear ='No'"; 
  $QueryClear = mysqli_query($link,$Clear);
  $ResultClear = mysqli_fetch_array($QueryClear);
  $num_payment = $ResultClear['num_payment'];
  $num_clear = $ResultClear['num_clear'];

  if($num_payment == 'No' || $num_payment == 'Yes' || $num_payment == 'Next'){

  $strSQL = "SELECT * FROM setting_default";
  $objQuery = mysqli_query($link,$strSQL);
  $Result = mysqli_fetch_array($objQuery);
  $def_status = $Result['def_status'];
  $def_info = $Result['def_info'];

  if($def_info == 'On'){
  $straward = "SELECT * FROM tb_award ORDER BY awa_id DESC";
  $awardQuery = mysqli_query($link,$straward);
  $Resultaward = mysqli_fetch_array($awardQuery);
  $awa_6 = $Resultaward['awa_6'];
  $awa_2 = $Resultaward['awa_2'];
  $awa_date = $Resultaward['awa_date'];

  $awa_n6 = substr($awa_6 , -2);  // เลขท้าย 2 ตัว
  $awa_n3 = substr($awa_6 , -3);  // เลขท้าย 3 ตัว

  $e1 = substr($awa_n3 , -1, 1);  // X ตัว
  $e2 = substr($awa_n3 , -2, 1);  // X-X ตัว
  $e3 = substr($awa_n3 , -3, 1);  // X-X ตัว

  $e5 = substr($awa_2 , -1, 1);  // X ตัว
  $e6 = substr($awa_2 , -2, 1);  // X-X ตัว

  $set1 = "$e1$e2$e3";
  $set2 = "$e2$e3$e1";
  $set3 = "$e3$e1$e2";
  $set4 = "$e3$e2$e1";
  $set5 = "$e2$e1$e3";
  $set6 = "$e1$e3$e2";

  }
  else{

  }

  ?>

  <div class="panel panel-primary">
  <div class="panel-heading">
    <h3 class="panel-title"><span class='glyphicon glyphicon-play'></span> <?php echo "$acc_fname  $acc_lname : $acc_phone"; ?></h3>
  </div>
  <div class="panel-body">

<!-- 
//============================================================================
-->

<?php include("payment-1.php"); ?>
<?php include("payment-2.php"); ?>
<?php include("payment-3.php"); ?>
<?php include("payment-4.php"); ?>
<?php include("payment-5.php"); ?>

<!-- 
//============================================================================
-->

  </div>
</div>

<?php 
} //if $num_clear
?>

<?php
} //while $Result_acc 
?>


<?php include("../templates/footer.php"); ?>