<?php
	
	include("../config/mysql_connect.php");
	//include("check_admin.php"); ใส่ไม่ได้เพราะไม่มีการเรียก session

	$acc_id = $_REQUEST['id'];
	$tpye_id = $_REQUEST['type'];
	$status = $_REQUEST['status'];

	if($status == 'pay'){

		$sql = "select * from tb_number where acc_id='$acc_id' and num_type='$tpye_id' and num_payment='No'"; 
	 	$Query = mysqli_query($link,$sql);
	  	$num_rows = mysqli_num_rows($Query);

	  	if($num_rows){

		while($Result = mysqli_fetch_array($Query)){
		$num_id = $Result['num_id'];

		$sql_update = "update tb_number set num_payment='Yes' where num_id='$num_id' and num_type='$tpye_id'";
		$objQuery = mysqli_query($link,$sql_update);

		}

		}

		echo "<meta http-equiv=refresh content=0;url=report.php>";


	}
	elseif($status == 'payall'){

		$sql = "select * from tb_number where acc_id='$acc_id' and num_payment='No'"; 
	 	$Query = mysqli_query($link,$sql);
	  	$num_rows = mysqli_num_rows($Query);

	  	if($num_rows){

		while($Result = mysqli_fetch_array($Query)){
		$num_id = $Result['num_id'];

		$sql_update = "update tb_number set num_payment='Yes' where num_id='$num_id'";
		$objQuery = mysqli_query($link,$sql_update);

		}

		}

		echo "<meta http-equiv=refresh content=0;url=report.php>";


	}
	elseif($status == 'unpay'){

		$sql = "select * from tb_number where acc_id='$acc_id' and num_type='$tpye_id' and num_clear='No' and num_payment='Yes' or num_payment='Next'"; 
	 	$Query = mysqli_query($link,$sql);
	  	$num_rows = mysqli_num_rows($Query);

	  	if($num_rows){

		while($Result = mysqli_fetch_array($Query)){
		$num_id = $Result['num_id'];

		$sql_update = "update tb_number set num_payment='No' where num_id='$num_id' and num_type='$tpye_id'";
		$objQuery = mysqli_query($link,$sql_update);

		}

		}

		echo "<meta http-equiv=refresh content=0;url=report.php>";


	}
	elseif($status == 'unpayall'){

		$sql = "select * from tb_number where acc_id='$acc_id' and num_clear='No' and num_payment='Yes' or num_payment='Next'"; 
	 	$Query = mysqli_query($link,$sql);
	  	$num_rows = mysqli_num_rows($Query);

	  	if($num_rows){

		while($Result = mysqli_fetch_array($Query)){
		$num_id = $Result['num_id'];

		$sql_update = "update tb_number set num_payment='No' where num_id='$num_id'";
		$objQuery = mysqli_query($link,$sql_update);

		}

		}

		echo "<meta http-equiv=refresh content=0;url=report.php>";


	}
	elseif($status == 'next'){

		$sql = "select * from tb_number where acc_id='$acc_id' and num_type='$tpye_id' and num_payment='No'"; 
	 	$Query = mysqli_query($link,$sql);
	  	$num_rows = mysqli_num_rows($Query);

	  	if($num_rows){

		while($Result = mysqli_fetch_array($Query)){
		$num_id = $Result['num_id'];

		$sql_update = "update tb_number set num_payment='Next' where num_id='$num_id' and num_type='$tpye_id'";
		$objQuery = mysqli_query($link,$sql_update);

		}

		}

		echo "<meta http-equiv=refresh content=0;url=report.php>";


	}
	elseif($status == 'nextall'){

		$sql = "select * from tb_number where acc_id='$acc_id' and num_payment='No'"; 
	 	$Query = mysqli_query($link,$sql);
	  	$num_rows = mysqli_num_rows($Query);

	  	if($num_rows){

		while($Result = mysqli_fetch_array($Query)){
		$num_id = $Result['num_id'];

		$sql_update = "update tb_number set num_payment='Next' where num_id='$num_id'";
		$objQuery = mysqli_query($link,$sql_update);

		}

		}

		echo "<meta http-equiv=refresh content=0;url=report.php>";


	}
	else{
		echo "Nooooooooooooo";
	}

?>