<?php error_reporting(0); ?>

<?php /*?>
<?php
$host = "localhost";
$username = "root"; 
$password = ""; 
$db = "mygoldplt_websystem"; 
?>
<?php */?>

<?php
$host = "localhost";
$username = "mygoldpl_mygoldplt"; 
$password = "295@pS7(F4"; 
$db = "mygoldpl_mygoldplt"; 
?>

<?php
$mysqli = new mysqli($host,$username,$password,$db);
?>

<?php
date_default_timezone_set("Asia/Kuala_Lumpur");

$query_all = "SELECT * 
FROM transactions 
WHERE description Like '%Free ship%'
AND type_of_process != 'Auto_Wallet'
AND status = '1'";
$result_all= $mysqli-> query($query_all);
if ($result_all -> num_rows > 0)
{
	while($record_all = $result_all -> fetch_assoc())
	{   			
	    $trans_id = $record_all['id'];
		$user_ref_code = $record_all['user_ref_code'];
		$in_transactions = $record_all['in_transactions'];

		//Get Agent Wallet Info
		$sql_my_wallet = "SELECT * 
		FROM wallet
		WHERE ref_code='$user_ref_code' LIMIT 1";
		$result_my_wallet = $mysqli-> query($sql_my_wallet);
		if ($result_my_wallet -> num_rows > 0)
		{
			$row_my_wallet = $result_my_wallet ->fetch_assoc();
			$my_cash_wallet = $row_my_wallet['cash_wallet'];
		}

		$new_my_cash_wallet = $my_cash_wallet - $in_transactions ;

		$sql_user = "SELECT *
		FROM wallet
		Where ref_code = '$user_ref_code'";
		$result_user = $mysqli-> query($sql_user);
		if ($result_user -> num_rows > 0)
		{
			$row_user = $result_user ->fetch_assoc();
			$wallet_id = $row_user['id'];
		}

		//Update My Wallet Info
		if ($new_my_cash_wallet > 0)
		{
			$Update_my_wallet = "UPDATE wallet SET
			cash_wallet='$new_my_cash_wallet'
			WHERE id = '$wallet_id' ";
			$result_my_wallet = $mysqli->query($Update_my_wallet);
		}
		else
		{
			$Update_my_wallet = "UPDATE wallet SET
			cash_wallet='0'
			WHERE id = '$wallet_id' ";
			$result_my_wallet = $mysqli->query($Update_my_wallet);
		}
				
		$Delete_transaction_info = "Delete 
		From transactions
		WHERE id ='$trans_id' ";               
		$result_delete_transaction_info = $mysqli->query($Delete_transaction_info);
	}
}
?>
