<?php
$con = mysqli_connect('localhost', 'mfudevlo_batuawallet', 'batua@wallet6602#', 'mfudevlo_batuawalletdb');

$mobile = isset($_GET['mobile']) ? mysqli_real_escape_string($con, $_GET['mobile']) : '';
if (empty($mobile) || strlen($mobile) < 10) { exit("No New Deposit"); }

// ১. Add Money চেক
$sql_add = "SELECT id, amount FROM add_money_requests WHERE mobile='$mobile' AND status='approved' AND is_read=0 LIMIT 1";
$res_add = mysqli_query($con, $sql_add);

if ($row = mysqli_fetch_assoc($res_add)) {
    $id = $row['id'];
    echo "আপনার একাউন্টে " . $row['amount'] . " টাকা Add Money সফল হয়েছে।";
    mysqli_query($con, "UPDATE add_money_requests SET is_read=1 WHERE id='$id'");
} 
else {
    // ২. B2B চেক (রিসিভারের জন্য)
    $sql_trans = "SELECT id, amount, sender_mobile FROM internal_transfers WHERE receiver_mobile='$mobile' AND is_read=0 LIMIT 1";
    $res_trans = mysqli_query($con, $sql_trans);
    
    if ($row_t = mysqli_fetch_assoc($res_trans)) {
        $tid = $row_t['id'];
        echo "আপনি " . $row_t['sender_mobile'] . " এর কাছ থেকে " . $row_t['amount'] . " টাকা রিসিভ করেছেন।";
        mysqli_query($con, "UPDATE internal_transfers SET is_read=1 WHERE id='$tid'");
    } else {
        echo "No New Deposit";
    }
}
mysqli_close($con);
?>