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

<div class="panel panel-primary">
  <div class="panel-heading">
    <h3 class="panel-title">แสดงประวัติการซื้อเลข</h3>
  </div>
  <div class="panel-body">

  <?php

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

  $sql = "select * from tb_number where num_clear='Yes' order by num_created desc"; 
  $Query = mysqli_query($link,$sql);
  $num_rows = mysqli_num_rows($Query);

  if($num_rows){

  	$count = 0;
	$text_tpye = "";

  echo "
	<table class='table table-bordered'>
    <thead>
    <tr>
    <th bgcolor='default'><center>ลำดับ</th>
    <th bgcolor='default'><center>ตัวเลข</th>
    <th bgcolor='default'><center>ราคาบน</th>
    <th bgcolor='default'><center>ราคาล่าง</th>
    <th bgcolor='default'><center>วันที่ซื้อ</th>
    <th bgcolor='default'><center>ซื้อโดย</th>
    <th bgcolor='default'><center>ประเภท</th>
    </tr>
    </thead>
    <tbody>";

	while($Result = mysqli_fetch_array($Query)){
		$num_id = $Result['num_id'];
		$num_buy = $Result['num_buy'];
		$num_one = $Result['num_one'];
		$num_two = $Result['num_two'];
		$num_type = $Result['num_type'];
		$num_created = $Result['num_created'];
		$accid = $Result['acc_id'];

		$strSQL = "SELECT * FROM tb_account WHERE acc_id='$accid'";
		$objQuery = mysqli_query($link,$strSQL);
		$Result_acc = mysqli_fetch_array($objQuery);
		$acc_fname = $Result_acc['acc_fname'];
		$acc_lname = $Result_acc['acc_lname'];
		$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'];

		$count = $count+1;

		if($num_type == 'a'){
			$text_tpye = "ประเภทเลข 2 ตัว";
		}
		elseif($num_type == 'b'){
			$text_tpye = "ประเภทเลข 3 ตัว";
		}
		elseif($num_type == 'c'){
			$text_tpye = "ประเภทเลขวิ่ง";
		}
		elseif($num_type == 'd'){
			$text_tpye = "ประเภทเลขใบ";
		}
		else{
			$text_tpye = "ไม่พบข้อมูล";
		}

		echo"<tr>
        <td align='center'>$count</td>
        <td align='center'>$num_buy</td>
        <td align='center'>$num_one</td>
        <td align='center'>$num_two</td>
        <td align='center'>$num_created</td>
        <td align='center'>$acc_fname $acc_lname</td>
        <td align='center'>$text_tpye</td>
      </tr>";

	} // while

	echo "</tbody></table>";
  } // if

  ?>

  </div>

</div>

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