<?php
$pageName  = "TAX Verification";
include($_SERVER['DOCUMENT_ROOT'] . "/user/layout/header.php");


require_once($_SERVER['DOCUMENT_ROOT'] . "/include/Transfer/WireFunction.php");

if (!isset($_SESSION['is_cot_code'])) {
    header("Location:./wire-transfer");
    exit();
}


if (isset($_POST['tax_submit'])) {
    $taxCode = $_POST['tax_code'];
    $acct_tax = $row['acct_tax'];

    if ($taxCode === $acct_tax) {
        if ($page['imf_code'] == '0') {

            $acct_otp = substr(number_format(time() * rand(), 0, '', ''), 0, 4);

            $sql =  "UPDATE users SET acct_otp=:acct_otp WHERE id=:id";
            $stmt = $conn->prepare($sql);
            $stmt->execute([
                'acct_otp' => $acct_otp,
                'id' => $user_id
            ]);


            $full_name = $row['firstname'] . " " . $row['lastname'];
            $APP_NAME = WEB_TITLE;
            $APP_URL = WEB_URL;
            $SITE_ADDRESS = $page['url_address'];
            $user_email = $row['acct_email'];

            $message = $sendMail->pinRequest($full_name, $acct_otp, $APP_NAME, $APP_URL, $SITE_ADDRESS);
            // User Email
            $subject = "One-Time Code - $APP_NAME";
            $email_message->send_mail($email, $message, $subject);


            $_SESSION['wire-transfer'] = $user_id;
            $_SESSION['is_wire_transfer'] = "wire";
            $_SESSION['is__transfer'] = "None";
            $_SESSION['is_transfer']  = "transfer";
            $_SESSION['is_tax_code'] = "None";

            header("Location:./wire-pin.php");
        } else {

            $_SESSION['wire-transfer'] = $user_id;
            $_SESSION['is_tax_code'] = "Cot";
            $_SESSION['is_transfer']  = "transfer";

            header("Location:./imf.php");
        }
    } else {
        // notify_alert('Invalid TAX Code','danger','3000','Close');
        toast_alert('error', 'Invalid TAX Code');
    }
}


?>


<!-- App Header -->
<div class="appHeader transparent">
    <div class="left">
        <a href="<?= $web_url ?>/user/dashboard.php" class="headerButton">
            <ion-icon name="chevron-back-outline"></ion-icon>
        </a>
    </div>
    <div class="pageTitle"></div>
    <div class="right">
        <a onclick="location.reload();" class="headerButton">
            <ion-icon name="refresh"></ion-icon>
        </a>
    </div>
</div>
<!-- * App Header -->

<!-- App Capsule -->
<div id="appCapsule">

    <div class="section mt-2 text-center">
        <h1>Enter TAX Code</h1>
        <h4>Enter 4 digit verification code</h4>
    </div>
    <div class="section mb-5 p-2">
        <form method="POST">
            <div class="form-group basic">
                <input type="text" name="tax_code" autocomplete="off" class="form-control verification-input" id="smscode" placeholder="••••" minlength="3" maxlength="4">

                <input type="number" value="<?= $temp_trans['amount'] ?>" name="amount" hidden id="amount">
                <input type="text" value="<?= $temp_trans['bank_name'] ?>" name="bank_name" hidden id="bank_name">
                <input type="text" value="<?= $temp_trans['account_name'] ?>" name="account_name" hidden id="account_name">
                <input type="number" value="<?= $temp_trans['account_number'] ?>" name="account_number" hidden id="account_number">
                <input type="text" value="<?= $temp_trans['account_type'] ?>" name="account_type" hidden id="account_type">
                <input type="text" value="<?= $temp_trans['trans_type'] ?>" name="trans_type" hidden id="trans_type">
                <input type="text" value="<?= $temp_trans['bank_country'] ?>" name="bank_country" hidden id="bank_country">
                <input type="number" value="<?= $temp_trans['user_id'] ?>" name="user_id" id="user_id" hidden>
                <input type="text" value="<?= $temp_trans['routine_number'] ?>" name="routine_number" id="routine_number" hidden>
                <input type="text" value="<?= $temp_trans['swift_code'] ?>" name="swift_code" id="swift_code" hidden>


            </div>

            <div class="form-button-group transparent">
                <button type="submit" name="tax_submit" class="btn btn-primary btn-block btn-lg">Verify</button>
            </div>

        </form>
    </div>

</div>
<!-- * App Capsule -->

<?php



include($_SERVER['DOCUMENT_ROOT'] . "/user/layout/footer.php");

?>