<?php
include"initialize_page.php";
include"systemfunctions.php";
?>
<?php include('resources/header.php') ?>
<title></title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<?php $select_query = "select x_status from x_anotheracc where x_userid = '$user_id' limit 0,1";
                                    $select_result = mysqli_query($con,$select_query);
                                    $num = mysqli_num_rows($select_result);
                                    
$website_url=website_settingdata('x_weburl');
                                    
                                    if($num > 0)
                                    {
                                        while($row = mysqli_fetch_array($select_result))
                                        {
                                            if($row['x_status']=='Dormant')
                                            { ?>
                                            <script type="text/javascript">
                                                alert("This account is Dormant and can\'t perform this operation");
                                                location.href='<?php echo $website_url;?>user/start.php';
                                            </script>   
                                                   
    
                                        <?php   } 
                                        if($row['x_status']=='Restricted')
                                            { ?>
                                            <script type="text/javascript">
                                                alert("This account is Restricted and can\'t perform this operation");
                                                location.href='<?php echo $website_url;?>user/start.php';
                                            </script>   
                                                   
    
                                        <?php   } 
                                         }
                            
                                    }

        ?>
        
<?php include('resources/css-file.php') ?>
<?php include('resources/navigation.php') ?> 

<style>
    .hide{
        display:none;
    }</style> 
<!-- Dashboard wrapper starts -->
<div class="dashboard-wrapper">
    <div class="main-container">				
        <div class="row">
            <div class="col-sm-12 ac-summ">
                <h2>Funds Transfer</h2>
            </div>
        </div>
        <div class="row gutter">
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <ul class="boxli">
                    <li>
                        <h4>International Funds Transfer</h4>
                        <?php
                        if (!isset($_POST['Proceed'])) {
                            ?>
                            <p>With Quantum Varlik Wealth Management Online Wires, you can send money to both personal and business accounts in Switzerland and other countries globally.</p>
                            <p>Please make sure that you have enough funds available in your account to transfer. Also, don't forget to validate receiver's account number and make sure to carefully review the information entered in this section before proceeding.<p>
                        <?php } ?>
                        <div class="panel">
                            <div class="panel-heading">
                                <h4>Fund Transfer</h4>
                            </div>     
                            <div class="panel-body">
                                <?php
                                if (isset($_POST['Proceed'])) {
                                    ?>
                                    <p>You are about to send out a transfer from your account, If the information of the receiver provided is correct click proceed to continue.</p>
                                    <form method="post" action="" id="internationtransfer">
                                        <?php
                                        ?>
                                        <div class="form-preview" >
                                        <div class="form-group">
                                            <input type="hidden" name="q" value="international_transfer" class="form-control">
                                        </div>                                      
                                        <div class="form-group">
                                            <label>Receiver's Bank Name: </label>
                                            <strong><?php echo $_REQUEST['rbankname']; ?></strong>
                                            <input class="form-control" type="hidden" name="rbankname"  value="<?php echo $_REQUEST['rbankname']; ?>">
                                        </div>
                                        <div class="form-group">
                                            <label>Receiver's Account Number: </label>
                                            <strong><?php echo $_REQUEST['raccountnumber']; ?></strong>
                                            <input class="form-control" type="hidden" name="raccountnumber"  value="<?php echo $_REQUEST['raccountnumber']; ?>">
                                        </div>
                                        <div class="form-group">
                                            <label>Receiver's Bank Address</label>
                                            <strong><?php echo $_REQUEST['receiver_address']; ?></strong>
                                            <input class="form-control" type="hidden" name="receiver_address" value="<?php echo $_REQUEST['receiver_address']; ?>">
                                        </div>
										<div class="form-group">
                                            <label>Receiver's Bank Swift/BIC Code: </label>
                                            <strong><?php echo $_REQUEST['swiftbic']; ?></strong>
                                            <input class="form-control" type="hidden" name="swiftbic"  value="<?php echo $_REQUEST['swiftbic']; ?>">
                                        </div>
                                        <div class="form-group">
                                            <label>Receiver's Account Name: </label>
                                            <strong><?php echo $_REQUEST['recname']; ?></strong>
                                            <input class="form-control" type="hidden" name="recname"  value="<?php echo $_REQUEST['recname']; ?>">
                                        </div>
                                        <div class="form-group">
                                            <label>Quantum Varlik Wealth Management Code: </label>
                                            <strong><?php echo $_REQUEST['xsxwxixfxtxcodeu']; ?></strong>
                                            <input class="form-control" type="hidden" name="xsxwxixfxtxcodeu"  value="<?php echo $_REQUEST['xsxwxixfxtxcodeu']; ?>">
                                        </div>
										
										<div class="form-group">
                                            <label>Routing Number: </label>
                                            <strong><?php echo $_REQUEST['routing']; ?></strong>
                                            <input class="form-control" type="hidden" name="routing"  value="<?php echo $_REQUEST['routing']; ?>">
                                        </div>
										
                                        <div class="form-group">
                                            <label>Country: </label>
                                            <strong><?php echo $_REQUEST['ucountry']; ?></strong>
                                            <input class="form-control" type="hidden" name="ucountry"   value="<?php echo $_REQUEST['ucountry']; ?>">
                                        </div>
                                        <div class="form-group">
                                            <label>Sender's Account Number: </label>
                                           <strong>
                                        <?php
                                        $account_id = $_REQUEST['accountid'];
                                        $select_query = "select * from x_anotheracc where x_userid = '$user_id' and x_status ='Y' AND x_id ='$account_id'";
                                        $select_result = mysqli_query($con, $select_query);
                                        $num = mysqli_num_rows($select_result);
                                        if ($num > 0) {
                                            while ($row = mysqli_fetch_array($select_result)) {
                                                $account_no = $row['x_time'];
                                                $account_type = $row['x_actype'];
                                                echo $account_no . ' (' . $account_type . ')';
                                            }
                                        }
                                        ?>
                                    </strong>
                                    <input class="form-control" type="hidden" id="accountid" name="accountid" value="<?php echo $_REQUEST['accountid']; ?>">
                                    <span id="accountbal"> </span>
                                        </div>
                                        <div class="form-group">
                                            <label>Amount to Transfer: </label>
                                            <strong><?php echo currency_data('x_currencysymbol', $currency_id); ?><?php echo $_REQUEST['transferamountx']; ?></strong>
                                            <input class="form-control" type="hidden" id="transferamountx" name="transferamountx" value="<?php echo $_REQUEST['transferamountx']; ?>">
                                        </div>
                                        <div class="form-group">
                                            <label>Date of Transfer: </label>
                                            <strong><?php echo $_REQUEST['datetransfer']; ?></strong>
                                            <input class="form-control" type="hidden" name="datetransfer" value="<?php echo $_REQUEST['datetransfer']; ?>" >
                                        </div>
                                        <div class="form-group">
                                            <label>Transfer Description: </label>
                                            <strong><?php echo $_REQUEST['transferdescription']; ?></strong>
                                            <input class="form-control" name="transferdescription" type="hidden" value="<?php echo $_REQUEST['transferdescription']; ?>" >
                                        </div>
                                       
                                        <?php
                                        ?>
                                        </div>
                                         <div class="form-preview text-center" style="border:none;"><button type="submit" class="btn btn-info">Proceed</button></div>
                                    </form>
                                    <p>Note: It is important to carefully review all information on this section before proceeding, entering the wrong information may lead to delay in processing or cancellation of your transfer.</p>

                                    <p>By clicking proceed you have authorized Quantum Varlik Wealth Management to withdraw, debit or charge the necessary funds from your designated account in order to complete this transfer.

                                    <p>A transfer remains "In Process" until fully processed and it will appear as "In Process" on your Transfer Activity tab under my accounts. Transfers remain "In Process" until the close of business on the day the funds are scheduled to be credited to the receiving account.</p>

                                    <p>Certain transfers may take longer to complete. We will send you an email alert with delivery details immediately after a transfer is deposited to the receiving bank.</p>
                                    <?php
                                } else {
                                    ?>
                                    <form method="post" action="">
                                        <div class="form-group">
                                            <input type="hidden" name="q" value="international_transfer" class="form-control">
                                        </div>                                      
                                        <div class="form-group">
                                            <label>Receiver's Bank Name</label>
                                            <input class="form-control" type="text" name="rbankname" required >
                                        </div>
                                        <div class="form-group">
                                            <label>Receiver's Account Number</label>
                                            <input class="form-control" type="text" name="raccountnumber" id="receiveracnumberid" required>
                                        </div>
                                        <div class="form-group">
                                            <label>Receiver's Bank Address</label>
                                            <input class="form-control" type="text" name="receiver_address" required>
                                        </div>
                                        <div class="form-group">
                                            <label>Receiver's Account Name </label>
                                            <input class="form-control" type="text" name="recname" id="receivernameid" required>
                                        </div> 
										
										<div class="form-group">
                                            <label>Receiver's Bank Swift/BIC Code</label>
                                            <input class="form-control" type="text" name="swiftbic" required >
                                        </div>
										
                                        <div class="form-group">
                                            <label>Quantum Varlik Wealth Management Code</label>
                                            <input class="form-control" type="text" name="xsxwxixfxtxcodeu" required >
                                        </div>
										<div class="form-group">
                                            <label>Routing Number</label>
                                            <input class="form-control" type="text" name="routing" required >
                                        </div>
                                        <div class="form-group">
                                            <label>Country</label>
                                            <input class="form-control" type="text" name="ucountry" required >
                                        </div>
                                        <div class="form-group">
                                            <label>Sender's Account Number</label>
                                            <select class="form-control" name="accountid" id= "accountid" required>
                                        <option value = "" selected
                                                >Select Account</option>
                                                <?php
                                                $select_query = "select * from x_anotheracc where x_userid = '$user_id' and x_status ='Y'";
                                                $select_result = mysqli_query($con, $select_query);
                                                $num = mysqli_num_rows($select_result);



                                                if ($num > 0) {

                                                    while ($row = mysqli_fetch_array($select_result)) {
                                                        $account_no = $row['x_time'];
                                                        $account_type = $row['x_actype'];
                                                        $account_id = $row['x_id'];
                                                        ?>	
                                                        <option value = "<?php echo $account_id; ?>" ><?php echo $account_no; ?> (<?php echo $account_type; ?>)</option>

                                                <?php
                                                    }
                                                }
                                                else
                                                {
                                                    $select_query = "select * from x_anotheracc where x_id = ".$_SESSION["account_id"]." and x_status ='Y'";
                                                    $select_result = mysqli_query($con, $select_query);
                                                    $num = mysqli_num_rows($select_result);

                                                    if ($num > 0) {

                                                        while ($row = mysqli_fetch_array($select_result)) {
                                                            $account_no = $row['x_time'];
                                                            $account_type = $row['x_actype'];
                                                            $account_id = $row['x_id'];

                                                            echo "<option value=".$account_id.">".$account_no." (". $account_type.")</option>";

                                                        }
                                                    }
                                                }
                                        ?>
                                    </select>
                                    <span id="accountbal"> </span>
                                        </div>





                                        <div id = "tramtORfee"class="form-group hide">
                                            <label id="transfer_fee" ></label>
                                            <input class="form-control" type="text" name="transferamountx" id="transferamountx" required >
                                           <span id="converted_amount"></span>
                                        </div>
                                        <!--<div class="form-group">
                                                <label>Sender's Account Number </label>
                                                <input class="form-control" type="text" value="<?php echo user_details($user_id, 'x_time'); ?>" readonly >
                                        </div>-->
                                        <div class="form-group">
                                            <label>Date of Transfer</label>
                                            <input class="form-control" name="datetransfer" type="text" value="<?php echo date("Y-m-d"); ?>" >
                                        </div>
                                        <div class="form-group">
                                            <label>Transfer Description</label>
                                            <textarea class="form-control" rows="3" name="transferdescription" required></textarea>
                                        </div>
                                        <input type="submit" name="Proceed" value="Proceed" class="btn btn-info"/>

                                    </form>
                                <?php } ?>
                            </div>
                        </div>
                    </li>
                </ul>	
            </div>
        </div>	
        </br>
    </div>
    <!-- Main container ends -->
</div>
<!-- Dashboard wrapper ends -->
<?php include('resources/footer.php') ?>
<?php include('resources/js-file.php') ?>
<script src="js/jQuery.style.switcher.js"></script>

<script type="text/javascript">
    $(document).ready(function () {
        $("#internationtransfer").submit(function (e) {
            e.preventDefault();
            $.ajax({
                url: "controller.php", // Url to which the request is send
                type: 'POST', // Type of request to be send, called as method
                data: new FormData(this), // Data sent to server, a set of key/value pairs (i.e. form fields and values)
                contentType: false, // The content type used when sending data to the server.
                cache: false, // To unable request pages to be cached
                processData: false, // To send DOMDocument or non processed data file it is set to false
                success: function (data)   // A function to be called if request succeeds
                {
                    if (data == 10)
                    {
                        //setTimeout(function(){  }, 3000);
                        window.location.href = '<?php echo website_settingdata('x_weburl'); ?>user/local1b.php';
                    }
                    if (data == 0)
                    {
                        alert("Amount should be in numeric..");
                    }
                    if (data == 1)
                    {
                        var accid = $("#accountid option:selected").val();
                        var fee = getFee(accid);

                        // alert("Min Amount For International Funds Transfer is  <?php echo currency_data("x_currencysymbol", $currency_id); ?>  <?php echo local_minmax1("min"); ?> and Max Amount is <?php echo currency_data("x_currencysymbol", $currency_id); ?> <?php echo local_minmax1("max"); ?>..");
                    }
                    if (data == 2)
                    {
                        alert("Amount Less in your account to transfer..");
                    }
                    if (data == 7)
                    {
                        alert("Account number is not Valid Please Check...");
                    }
                    if (data == 25)
                    {
                        alert("Your Account is Inactive please contact at your Branch...");
                    }

                }
            });
        });
    });

</script>

<script type="text/javascript">
    $(document).ready(function () {
        //test amount on fill


        $('#receiveracnumberid').change(function (e) {
            $("#transferamountx").val("");
            $("#converted_amount").text("");

            var accountnu = $("#receiveracnumberid").val();
            if (accountnu != "")
            {
                $.post("controller.php", {q: "test_accountnumber", accountnu: accountnu}, function (data)
                {
                    //alert(data);
                    if (data == 0)
                    {
                        //alert(accountnu + " is not Valid Account Number Please Check...");
                    } else
                    {
                        $("#receivernameid").val(data);
                    }
                }
                );

            }

        });

    });

</script>
<script type = "text/javascript" >
    $(document).ready(function () {
        //test amount on fill


        $('#transferamountx').change(function (e) {

            var amount = $("#transferamountx").val();
            var recevier_account = $("#receiveracnumberid").val();
            if (amount != "")
            {
                var accid = $("#accountid option:selected").val();

                $.post("controller.php", {q: "test_amount_localtransfer1", amount: amount, accid: accid, receveraccountno: recevier_account}, function (data)
                {
                   
                    if (data == 0)
                    {
                        alert("Amount should be in numeric..");
                    }
                    if (data == 1)
                    {

                        getFee(accid);
                        //alert("Min Amount For International Funds Transfer is  <?php echo currency_data("x_currencysymbol", $currency_id); ?>  <?php echo local_minmax1("min"); ?> and Max Amount is <?php echo currency_data("x_currencysymbol", $currency_id); ?> <?php echo local_minmax1("max"); ?>..");	 
                    }
                    if (data == 2)
                    {
                        alert("Amount Less in your account to transfer..");
                    } else
                    {
                        $("#converted_amount").text(data);

                        //alert();
                    }
                }
                );


            }

        });

    });


    function getFee(accid)
    {

        $.post("controller.php", {q: "get_currency", accid: accid}, function (data)
        {

            //alert("Min Amount For International Funds Transfer is  <?php echo currency_data("x_currencysymbol", $currency_id); ?>  <?php echo local_minmax1("min"); ?> and Max Amount is <?php echo currency_data("x_currencysymbol", $currency_id); ?> <?php
echo local_minmax1("max")

//var fee = "Min Amount For International Funds Transfer is " + data + <?php echo local_minmax1("min");  
?> +" and Max Amount is "+ data + <?php echo local_minmax1("max"); ?>+ " ..." ;

            var fee = "Min Amount For International Funds Transfer is " + data +<?php echo local_minmax1("min"); ?> + " and Max Amount is " + data + <?php echo local_minmax1("max"); ?> + " ...";

            alert(fee);


        }
        );


        //return fee;						
    }



</script>

<script type="text/javascript">
    $(document).ready(function () {
        //test amount on fill

        $("#accountid").on('change', function (e) {

            var accid = $("#accountid option:selected").val();

            if (accid != "")
            {


                $.post("controller.php", {q: "get_balance", accid: accid}, function (data)
                {
                    //alert(data); 
                    $("#accountbal").text(data);
                    $("#tramtORfee").removeClass('hide');

                }
                );
                $.post("controller.php", {q: "get_fee_international", accid: accid}, function (data)
                {
                    //alert(data); 

                    $("#transfer_fee").text(data);
                    $("#tramtORfee").removeClass('hide');

                }
                );

            } else
            {
                $("#accountbal").text("");
                $("#tramtORfee").addClass('hide');
            }
        });


    });

</script>
