<?php
ob_start();
include('../includes/db_conx.php');

isset($_SESSION['detect_login']);
if (!isset($_SESSION['detect_login'])) {
    header("location: ../online/customer_login");
    exit();
} else {
    $id = $_SESSION['id'];
    // echo $id;
    // get all the varible from the database for personal information 
    include('../includes/cus-info.php');

    include('../includes/dash-header.php');
}
?>

<!-- header begin-->

<style>
    @media (min-width: 576px) {
        .modal-sm {
            max-width: 450px;
        }
    }
</style>


<!-- header begin-->
<?php
$name_bene =  $_SESSION['name_bene'];
$trans_amount =  $_SESSION['trans_amount'];

?>

<body>

    <?php
    include('../includes/side-nav.php');
    ?>
    <div class="main-content" id="panel">
        <!-- Topnav -->
        <?php
        // include('../includes/top-nav.php');
        ?>


        <div class="header pb-4">
            <div class="container-fluid">
                <div class="header-body">
                </div>
            </div>
        </div>
        <!-- header end -->

        <div class="header pb-6 d-flex align-items-center" style="min-height: 300px; background-image: url(../asset/images/shutterstock_1145329577-scaled.jpg); background-size: cover; background-position: center top;">
            <!-- Mask -->
            <span class="mask bg-gradient-default opacity-4"></span>
        </div>


        <div class="container-fluid mt--6">
            <div class="content-wrapper">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="card bg-white">
                            <div class="card-body">
                                <div class="">
                                    <h3 class="">Bank Transfer</h3>
                                    <p>
                                        <marquee direction="left">Be sure to verify details before executing transfer!</marquee>
                                    </p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>


                <div class="card">
                    <div class="card-header header-elements-inline">
                        <h3 class="mb-0">Transfer Funds</h3>
                        <div class="header-elements">
                            <?php

                            if (empty($name_bene)) {
                                header('location: other_bank?stats=notAvailable');
                            }
                            ?>
                        </div>
                    </div>



                </div>


            </div>



        </div>
    </div>






    <!-- footer begin -->
    <footer class="footer pt-0">

    </footer>
    </div>
    </div>
    <?php
    include('../includes/dash_footer.php') ?>

</body>


<?php




function swal_success()
{
    echo "
                        <script> 
                            $(document).ready(function(){
                            Swal.fire({
                                title: 'Transaction Status',
                                text: 'Successful',
                                icon: 'success',
                                showCancelButton: false,
                                confirmButtonColor: '#3085d6',
                                cancelButtonColor: '#d33',
                                confirmButtonText: 'Generate Receipt'
                            }).then((result) => {
                                if (result.isConfirmed) {
                                window.location.replace('receipt.php');
                                }
                            })

                        });
                        // this is the end of the swal jquery in the php function page 
                        </script>
                            ";
}

function swal_error($msg)
{

    echo "
                            <script> 
                                $(document).ready(function(){
                                    Swal.fire({
                                        icon: 'error',
                                        title: 'Oops...',
                                        text: '" . $msg . "',
                                    })

                                });
                            </script>
                        ";
}



$name_bene = $_SESSION['name_bene'];
$account_bene = $_SESSION['account_bene'];
$swift_code = $_SESSION['swift_code'];
$name_bank = $_SESSION['name_bank'];
$address = $_SESSION['address'];
$b_email = $_SESSION['b_email'];
$trans_amount = $_SESSION['trans_amount'];
$b_country = $_SESSION['b_country'];
$new_amount = $_SESSION['new_amount'];
$description = $_SESSION['description'];
$transaction_id = $_SESSION['transaction_id'];

$fmt_amt = number_format($trans_amount, 2);

$sql_6 = "UPDATE confidential_table SET avaliable_balance = '$new_amount' WHERE id = '$id' ";
$result_6 = $db_conx->query($sql_6);
if ($result_6) {
    echo 'Balance update success';
} else {
    echo 'failed';
}

// now we have to check if the account number for if it is available in the platform 
$sql_7 = "SELECT * FROM confidential_table WHERE account_no = '$account_bene'";
$result_7 = $db_conx->query($sql_7);

if ($result_7->num_rows > 0) {
    $row = mysqli_fetch_assoc($result_7);
    // Code is found in the database, you can access the data using $row
    $bene_bal = $row['avaliable_balance'];
    $new_bene_bal = $trans_amount + $bene_bal;



    // now we have to update the beneficiary account 
    $sql_8 = "UPDATE confidential_table SET avaliable_balance = '$new_bene_bal' WHERE account_no = '$account_bene'";
    $result_8 = $db_conx->query($sql_8);

  
}

$sql_1 = "INSERT INTO transfer(u_id,name_bank,address_bank,b_name,b_acc_no,b_email,amount,t_time,ref,trans_status,mode,description) VALUES('$id','$name_bank','$address','$name_bene','$account_bene','$b_email','$trans_amount','$current_time','$transaction_id','1','transfer','$description')";
$result = $db_conx->query($sql_1);
if ($result) {
    swal_success();



//     $f = substr($account_no, 0, 5);
//     $l = substr($account_no, -3);

//     $sa = $f . '***' . $l;

//     $to = $email;
//     // IMF code
//     $permitted_chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';

//     $hash =  substr(str_shuffle($permitted_chars), 0, 15);

//     $toEmail = $email;
//     $notificationSubject = 'Fund Transfer';



//     // Subject
//     $subject = $sitename . '| Fund Transfer ';

//     // Message
//     // Message
//     $messageBody = '<html xmlns="http://www.w3.org/1999/xhtml">

//                 <head>
//                     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
//                     <meta name="viewport" content="width=device-width, initial-scale=1.0" />
//                     <title>' . $sitename . '</title>
//                     <style type="text/css">


//                         /* my own styling starts from here */
//                         .logo_section{
//                             display: block;
//                             margin: 20px auto;
//                             text-align: center!important;
//                             width: 100px;
//                         }

//                         img{
//                             max-width: 100%;
//                             max-height: 100%;
//                         }

//                         .top_wrap{
//                             display: flex;
//                         }

//                     </style>


//                 </head>

//                 <body>
//                     <div>

//                         <table cellspacing="0" cellpadding="0" width="689" border="0">
//                             <tbody>
//                                 <tr>
//                                     <td colspan="5" height="97">
//                                         <div align="left">
//                                             <h1 style="font-size: 25px;">
//                                                 Transaction Alert [Debit: ' . $currency . $fmt_amt . ']   
//                                             </h1>


//                                         </div>
//                                     </td>
//                                     <td colspan="5" height="97">
//                                         <div align="right">
//                                             <img src=""https://' . $sitelink . '/images/logo_mail.png""  href=""https://' . $sitelink . '" >
//                                         </div>
//                                     </td>
//                                 </tr>
//                                 <tr>
//                                     <td colspan="2">
//                                         &nbsp;
//                                     </td>
//                                     <td colspan="10">
//                                         <div align="right">
//                                            ' . $current_time . '
//                                         </div>
//                                     </td>
//                                 </tr>
//                                 <tr>
//                                     <td colspan="10">
//                                         Dear &nbsp;<strong>' . $name . '</strong>
//                                     </td>
//                                 </tr>
//                                 <tr>
//                                     <td colspan="10"></td>
//                                 </tr>
//                                 <tr>
//                                     <td colspan="10">
//                                         <h4>
//                                             <u>' . $sitename . 'electronic Notification Service
//                                                 (eNS)</u>
//                                         </h4>
//                                     </td>
//                                 </tr>
//                                 <tr>
//                                     <td colspan="10"></td>
//                                 </tr>
//                                 <tr>
//                                     <td colspan="10">
//                                         We wish to inform you that a Debit transaction
//                                         occurred on your account with us.
//                                     </td>
//                                 </tr>
//                                 <tr>
//                                     <td colspan="10">
//                                         &nbsp;
//                                     </td>
//                                 </tr>
//                                 <tr>
//                                     <td colspan="10">
//                                         The details of this transaction are shown below:
//                                     </td>
//                                 </tr>
//                                 <tr>
//                                     <td colspan="10"></td>
//                                 </tr>
//                                 <tr>
//                                     <td colspan="10">
//                                         <h4>
//                                             <u>Transaction Notification</u>
//                                         </h4>
//                                     </td>
//                                 </tr>
//                                 <tr>
//                                     <td>
//                                         <table width="720px" border="0">
//                                             <tbody>
//                                                 <tr>
//                                                     <td width="130">
//                                                         Account Number
//                                                     </td>
//                                                     <td width="10">
//                                                         :
//                                                     </td>
//                                                     <td colspan="8" width="549">
//                                                         ' . $account_no . '
//                                                     </td>
//                                                 </tr>
//                                                 <tr>
//                                                     <td width="130">
//                                                         Transaction Location
//                                                     </td>
//                                                     <td>
//                                                         :
//                                                     </td>
//                                                     <td colspan="8">
//                                                         E-CHANNNELS
//                                                     </td>
//                                                 </tr>
//                                                 <tr>
//                                                     <td width="130" height="19">
//                                                         Description
//                                                     </td>
//                                                     <td>
//                                                         :
//                                                     </td>
//                                                     <td colspan="8">
//                                                         ' . $description . '

//                                                     </td>
//                                                 </tr>
//                                                 <tr>
//                                                     <td width="130">
//                                                         Amount
//                                                     </td>
//                                                     <td>
//                                                         :
//                                                     </td>
//                                                     <td colspan="8">
//                                                        ' . $currency . '&nbsp;' . $fmt_amt . '
//                                                     </td>
//                                                 </tr>
//                                                 <tr>
//                                                     <td width="130">
//                                                         Value Date
//                                                     </td>
//                                                     <td>
//                                                         :
//                                                     </td>
//                                                     <td colspan="8">
//                                                        ' . $current_date . '
//                                                     </td>
//                                                 </tr>
//                                                 <tr>
//                                                     <td width="130">
//                                                         Remarks
//                                                     </td>
//                                                     <td>
//                                                         :
//                                                     </td>
//                                                     <td colspan="8">
//                                                      ' . $sitename . ' - from  ' . $account_no . '

//                                                         REF ' . $hash . '<wbr> to ' . $account_bene . '   ReF:ReF:' . $transaction_id . '
//                                                     </td>
//                                                 </tr>
//                                                 <tr>
//                                                     <td width="130">
//                                                         Time of Transaction
//                                                     </td>
//                                                     <td>
//                                                         :
//                                                     </td>
//                                                     <td colspan="8">
//                                                        ' . $current_time . '
//                                                     </td>
//                                                 </tr>
//                                                 <tr>
//                                                     <td width="130">
//                                                         Document Number
//                                                     </td>
//                                                     <td>
//                                                         :
//                                                     </td>
//                                                     <td colspan="8">
//                                                         0
//                                                     </td>
//                                                 </tr>
//                                                 <tr>
//                                                     <td colspan="10">
//                                                         <br>
//                                                     </td>
//                                                 </tr>
//                                                 <tr>
//                                                     <td colspan="7">
//                                                         The balances on this account as at&nbsp; ' . $current_time . '
//                                                         &nbsp;are as follows;
//                                                     </td>
//                                                 </tr>
//                                                 <tr>
//                                                     <td colspan="10"></td>
//                                                 </tr>
//                                                 <tr>
//                                                     <td width="130">
//                                                         Available Balance
//                                                     </td>
//                                                     <td>
//                                                         <div align="center">
//                                                             :
//                                                         </div>
//                                                     </td>
//                                                     <td colspan="8">
//                                                        ' . $currency . ' &nbsp;' . $avaliable_balance . '&nbsp;
//                                                     </td>
//                                                 </tr>

//                                                 <tr>
//                                                     <td colspan="10">
//                                                         &nbsp;
//                                                     </td>
//                                                 </tr>
//                                             </tbody>
//                                         </table>
//                                     </td>
//                                 </tr>
//                             </tbody>
//                         </table>


//                         <table>
//                             <tbody>
//                                 <tr>
//                                     <td colspan="7">
//                                         The privacy and security of your Bank Account details is important to us. If you would prefer that
//                                         we do not
//                                         display your account balance in every transaction alert sent to you via email please contact us on
//                                         <b>' . $site_email . '&nbsp;</b>
//                                     </td>
//                                 </tr>
//                                 <tr>
//                                     <td colspan="10">
//                                         &nbsp;
//                                     </td>
//                                 </tr>
//                                 <tr>
//                                     <td height="25" colspan="10">
//                                         Thank you for choosing  ' . $sitename . '&nbsp;
//                                     </td>
//                                 </tr>
//                                 <tr>
//                                     <td colspan="10">
//                                         &nbsp;
//                                     </td>
//                                 </tr>
//                                 <tr>
//                                     <td height="19" colspan="1">
//                                         <table width="500px" border="0">
//                                             <tbody>
//                                                 <tr>
//                                                     <td>
//                                                         <a href="#"
//                                                             rel="noreferrer" target="_blank"
//                                                             >
//                                                             <img height="150" style="object-fit:contain"
//                                                                 src=""https://' . $sitelink . '/images/logo_mail_footer.jpg""
//                                                                 width="auto" class="CToWUd" data-bit="iit"></a>
//                                                     </td>
//                                                 </tr>
//                                             </tbody>
//                                         </table>
//                                     </td>
//                                 </tr>


//                             </tbody>
//                         </table>
//                         <div class="yj6qo"></div>
//                         <div class="adL">

//                         </div>
//                     </div>

//                 </body>


//                 </html>';





//     sendMail(
//         $toEmail,
//         $messageBody,
//         $notificationSubject
//     );




//     // now it is time to save the transaction in session so we can generate the receipt 
// }


} 







?>
<script>
    $(document).ready(function() {
        $("#modal-form").modal('show');
    });
    $("#modal-form").modal({
        backdrop: 'static',
        keyboard: false
    });
</script>




<!-- -->

</html>

<script>
</script>
<script type="text/javascript">
    $('.preloader').fadeOut(1000);
</script>

<?php
ob_end_flush() ?>