<?php
include"initialize_page.php";
include"systemfunctions.php";
?>
<?php include('resources/header.php') ?>
<title></title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<?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 gutter">
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <ul class="boxli">
                     <div class="panel">
                    <li style="margin: 0px">
                        <?php if(isset($_POST['firstname']) && isset($_POST['lastname']))
                                                    {   
                                                        ?>
                        <h4>Pay to Individual</h4>
                    <?php }else { ?>
                        <h4>Pay to Company</h4>
                    <?php } ?>
                       <p><strong>Make Payment instantly </strong></p>
                       
                       <div class="panel" id="successmessage" style="display: none;">
                            
                            <div class="panel-body">
                                <h4><i class="fa fa-check-circle" aria-hidden="true" style="
    font-size: 20px;
    margin: 5px;
    color: #15689e;
"></i> Payment Made Successfully.
                            </div>
                        </div>
                       
                      
                       
                                
                            <div class="panel-body">
                                
                                    <form method="post" action="" id="pay_now_individual_company">
                                        <div class="form-group">
                                            <input type="hidden" name="q" value="pay_now_individual_company" class="form-control">
                                        </div>                                      
                                        <div class="col-sm-12 form-group">
                                            <div class="col-sm-3" style="text-align: right;">
                                            <label ><strong>*Name:</strong> </label>
                                            </div>
                                            <div class="col-sm-5">
                                                <?php 
                                                $name="";
                                                    if(isset($_POST['firstname']))
                                                    {
                                                        $name=$_POST['firstname'];
                                                    }
                                                    if(isset($_POST['lastname']))
                                                    {
                                                        $name.=' '.$_POST['lastname'];
                                                    }

                                                    if(isset($_POST['name']))
                                                    {
                                                        $name=$_POST['name'];
                                                    }
                                                ?>
                                            <input class="form-control" type="text" name="x_name" value="<?php echo $name; ?>" required ></div>
                                        </div>

                                        <div class="col-sm-12 form-group">
                                            <div class="col-sm-3" style="text-align: right;">
                                            <label><strong>*Amount:</strong> </label>
                                            </div>
                                            <div class="col-sm-5">
                                            <input class="form-control" type="text" name="x_amount" required ></div>
                                        </div>


                                        <div class="col-sm-12 form-group">
                                            <div class="col-sm-3" style="text-align: right;">
                                            <label><strong>*Bank:</strong> </label>
                                        </div>
                                            <div class="col-sm-5">
                                            <input class="form-control" type="text" name="x_bank" required ></div>
                                        </div>
                                        
                                        <div class="col-sm-12 form-group">
                                            <div class="col-sm-3" style="text-align: right;">
                                            <label><strong>*pay to account number:</strong> </label>
                                            <label class="smalltext">where the payment will be sent</label></div>
                                            <div class="col-sm-5">
                                            <input class="form-control" type="text" name="x_account_number" required></div>
                                        </div>
                                       
                                        <div class="col-sm-12 form-group">
                                            <div class="col-sm-3" style="text-align: right;">
                                                <label><strong>*Pay from account</strong></label>
                                            </div>
                                            <div class="col-sm-5">
                                                 <select class="form-control" name="x_account_id" 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_result1 = mysqli_query($con, $select_query);
                                                $num1 = mysqli_num_rows($select_result1);



                                                if ($num > 0) {

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

                                                <?php
                                            }
                                        }
                                        ?>
                                    </select>
                                            </div>
                                        </div>
                                        
                                        <div class="col-sm-12 form-group">
                                            <div class="col-sm-3" style="text-align: right;">
                                            <label><strong>*service description:</strong> </label>
                                            </div>
                                            <div class="col-sm-5">
                                            <input class="form-control" type="text" name="x_service_description" required ></div>
                                        </div>

                                        <div class="col-sm-12">
                                          <div class="col-sm-3"> </div>
                                          <div class="col-sm-5"> 
                                        <input type="submit" name="Proceed" value="Submit" class="btn btn-info"/></div>
                                         </div>
                                    </form>
                               
                            </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 () {
        $("#pay_now_individual_company").submit(function (e) {
            e.preventDefault();
             $('[type="submit"]').attr('disabled',true);
            $.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 == 1)
                    {
                        //setTimeout(function(){  }, 3000);
                        $('#successmessage').show();
                        setInterval(function(){ 
                        window.location.href = '<?php echo website_settingdata('x_weburl'); ?>user/paynow.php';
                         }, 3000);
                    }
                    if (data == 0)
                    {
                         $('[type="submit"]').attr('disabled',false);
                        alert("All fields are compulsory.");
                    }
                    if(data==2)
                    {
                         $('[type="submit"]').attr('disabled',false);
                        alert('Dont have enough Balance to make Payment');
                    }
                    if(data==3)
                    {
                         $('[type="submit"]').attr('disabled',false);
                        alert('Amount should be numeric');
                    }
                   
                }
            });
        });
    });

</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>

<style>
    label{
        margin: 0px;
    }
    .smalltext{
        font-size: 11px;
    }
</style>