<?php

  $sql = "select * from tb_number where acc_id='$acc_id' and num_type='c' and num_clear='No'"; 
  $Query = mysqli_query($link,$sql);
  $num_rows = mysqli_num_rows($Query);
    
  $count = 0;
  $sum_n2 = 0;

  if($num_rows){

?>

  <table class="table table-bordered">
    <thead>
      <tr class="info">
        <th><center>ลำดับ</th>
        <th><center>วันที่ซื้อ</th>
        <th><center>เลขวิ่ง</th>
        <th><center>เลขวิ่งบน</th>
        <th><center>เลขวิ่งล่าง</th>
        <th><center>ผลรางวัล</th>
        <th><center>คิดเป็นเงิน</th>
      </tr>
    </thead>
    <tbody>

	<?php

  // ตารางรวมเลข 3 ตัว

  $payment_status = "ไม่มีข้อมูล";

	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_payment = $Result['num_payment'];
  $num_clear = $Result['num_clear'];
	$num_created = $Result['num_created'];

  $n1 = "-";
  $n2 = "-";

  if($num_payment == 'No'){
    $payment_status = "<a href='payment_save.php?id=$acc_id&type=c&status=pay' class='btn btn-danger btn-xs'><span class='glyphicon glyphicon-usd'></span> รอลูกค้าชำระเงิน</a>

    <a href='payment_save.php?id=$acc_id&type=c&status=next' class='btn btn-warning btn-xs'><span class='glyphicon glyphicon-remove'></span> ข้ามรายการนี้</a>
    ";
  }
  elseif($num_payment == 'Yes'){
    $payment_status = "<a href='payment_save.php?id=$acc_id&type=c&status=unpay' class='btn btn-success btn-xs'><span class='glyphicon glyphicon-usd'></span> ชำระเงินแล้ว</a>";
  }
  elseif($num_payment == 'Next'){
    $payment_status = "<a href='payment_save.php?id=$acc_id&type=c&status=unpay' class='btn btn-warning btn-xs'><span class='glyphicon glyphicon-remove'></span> รายการนี้ถูกกดข้ามแล้ว</a>";
  }


  if($num_one != 0){

  $count = $count+1;

  if($def_info == 'On'){
    
    if($e1 == $num_buy || $e2 == $num_buy || $e3 == $num_buy){
      $n1 = "ถูกรางวัล";
      $n2 = ($num_one*$rate5)+(($num_one*$acc_com5)/100)-$num_one;
      $sum_n2 = $n2+$sum_n2;
      $n2 = number_format($n2);
      $n2 = "<font color='green'>$n2</font>";

    }
    else{
      $n1 = "ไม่ถูกรางวัล";
      $n2 = -($num_one-(($num_one*$acc_com5)/100));
      $sum_n2 = $n2+$sum_n2;
      $n2 = number_format($n2);
      $n2 = "<font color='red'>$n2</font>";
    }

  }
  else{

  }

    echo"<tr>
        <td align='center'>$count</td>
        <td align='center'>$num_created</td>
        <td align='center'>$num_buy</td>
        <td align='center'>$num_one</td>
        <td align='center'>-</td>
        <td align='center'>$n1</td>
        <td align='center'>$n2</td>
      </tr>";

  }

  if($num_two != 0){

  $count = $count+1;

  if($def_info == 'On'){
    
    if($e5 == $num_buy || $e6 == $num_buy){
      $n1 = "ถูกรางวัล";
      $n2 = ($num_two*$rate6)+(($num_two*$acc_com5)/100)-$num_two;
      $sum_n2 = $n2+$sum_n2;
      $n2 = number_format($n2);
      $n2 = "<font color='green'>$n2</font>";

    }
    else{
      $n1 = "ไม่ถูกรางวัล";
      $n2 = -($num_two-(($num_two*$acc_com5)/100));
      $sum_n2 = $n2+$sum_n2;
      $n2 = number_format($n2);
      $n2 = "<font color='red'>$n2</font>";
    }

  }

    echo"<tr>
        <td align='center'>$count</td>
        <td align='center'>$num_created</td>
        <td align='center'>$num_buy</td>
        <td align='center'>-</td>
        <td align='center'>$num_two</td>
        <td align='center'>$n1</td>
        <td align='center'>$n2</td>
      </tr>";

  }

  if( $num_one == 0 && $num_two == 0 && $num_buy != 0){

    $count = $count+1;

    echo"<tr>
        <td align='center' bgcolor='#ff6666'>$count</td>
        <td align='center' bgcolor='#ff6666'>$num_created</td>
        <td align='center' bgcolor='#ff6666'>$num_buy</td>
        <td align='center' bgcolor='#ff6666'>-</td>
        <td align='center' bgcolor='#ff6666'>-</td>
        <td align='center' bgcolor='#ff6666'>-</td>
        <td align='center' bgcolor='#ff6666'>-</td>
      </tr>";

  }

	}

  $num3 = $sum_n2;
  $sum_n2 = number_format($sum_n2);

  echo"<tr>
        <td align='center'></td>
        <td align='center'></td>
        <td align='center'></td>
        <td align='center'></td>
        <td align='center'></td>
        <td align='center'><b>ยอดรวม</b></td>
        <td align='center'><b>$sum_n2</b></td>
      </tr>";

	?>

    </tbody>
  </table>

  <?php 

    //echo "$payment_status<hr>"; 

      } // if $num_rows

      else{

      $num3 = 0;

      }

  ?>