<?php
session_start();
include_once ('../include/session.php');
require_once '../include/class.user.php';
if (!isset($_SESSION['acc_no'])) {
    header("Location: login.php");
    exit();
}


$reg_user = new USER();

$stmt = $reg_user->runQuery("SELECT * FROM account WHERE acc_no=:acc_no");
$stmt->execute(array(":acc_no" => $_SESSION['acc_no']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);



$email = $row['email'];


$temp = $reg_user->runQuery("SELECT * FROM transfer WHERE email = '$email' ");
$temp->execute(array(":acc_no" => $_SESSION['acc_no']));
$rows = $temp->fetch(PDO::FETCH_ASSOC);


?>

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>Transfer History - Skyutah Capitals</title>
            
            <?php include 'header.php';?>

            <style type="text/css">
                .Successful{
              --tw-text-opacity: 1;
              color: rgb(100 116 139 / var(--tw-text-opacity));
                --tw-bg-opacity: 1;
                background-color: rgb(209 250 229 / var(--tw-bg-opacity));
                }
                .Pending{
                 --tw-text-opacity: 1;
                color: rgb(100 116 139 / var(--tw-text-opacity));
                    --tw-bg-opacity: 1;
                background-color: rgb(241 245 249 / var(--tw-bg-opacity));
                }

                .On-hold{
                --tw-text-opacity: 1;
                color: rgb(217 119 6 / var(--tw-text-opacity));
                --tw-bg-opacity: 1;
                background-color: rgb(254 243 199 / var(--tw-bg-opacity));
                }

                .Failed{
                --tw-text-opacity: 1;
                color: rgb(244 63 94 / var(--tw-text-opacity));
                --tw-bg-opacity: 1;
                background-color: rgb(255 228 230 / var(--tw-bg-opacity));
                }

                .Cancelled{
                --tw-text-opacity: 1;
                color: rgb(241 245 249 / var(--tw-text-opacity));
                --tw-bg-opacity: 1;
                background-color: rgb(51 65 85 / var(--tw-bg-opacity));
                }

            </style>

             <main>
                    <div class="vd jd tto vv oq ar ri">
                        <!-- Page header -->
                        <div class="_y js jn id">
                            <!-- Left: Title -->
                            <div class="rw _a">
                                <h1 class="gg zj text-slate-800 font-bold">Transfer History</h1>
                            </div>

                            <!-- Right: Actions -->
                            <div class="sq fa _j fm ji fy">
                                <input type='button' id='btn' class='btn hb xs yo' value='Print Statement' onclick='printtag("DivIdToPrint");' >
                            </div>
                        </div>

                        
                        <!-- Table -->
                        <div class="bg-white by rounded-sm border border-slate-200 ry">
                            <div x-data="handleSelect">
                                <div class="lz">
                                    <div id='DivIdToPrint'>
                                    <table class="av oq">
                                        <thead class="gb g_ gq text-slate-500 hq ck cx border-slate-200">
                                            <tr>
                                                <th class="v_ wk xe vm co"><div class="g_ gh">Transaction ID</div></th>
                                                <th class="v_ wk xe vm co"><div class="g_ gh">Amount</div></th>
                                                <th class="v_ wk xe vm co"><div class="g_ gh">Beneficiary Name</div></th>
                                                <th class="v_ wk xe vm co"><div class="g_ gh">Beneficiary Account No.</div></th>
                                                <th class="v_ wk xe vm co"><div class="g_ gh">Transaction Type</div></th>
                                                <th class="v_ wk xe vm co"><div class="g_ gh">Bank</div></th>
                                                <th class="v_ wk xe vm co"><div class="g_ gh">Description</div></th>
                                                <th class="v_ wk xe vm co"><div class="g_ gh">Date/Time</div></th>
                                                <th class="v_ wk xe vm co"><div class="g_ gh">Status</div></th>
                                            </tr>
                                        </thead>
                                        <?php 
                                        $acc_no = $_SESSION['acc_no'];
                                        $email = $row['email'];
                                        $his = $reg_user->runQuery("SELECT * FROM transfer WHERE email = '$email'");
                                        $his->execute(array(":acc_no"=>$_SESSION['acc_no']));
                                        while($rows = $his->fetch(PDO::FETCH_ASSOC)){?>
                                        <tbody class="text-sm lg lb">
                                            <tr>
                                                <td class="v_ wk xe vm co"><div class="gk yj">#<?php echo $rows['id']; ?></div></td>
                                                <td class="v_ wk xe vm co"><div class="inline-flex gk pt yj rounded-full gp vk vy"><?php echo $row['currency']; ?> <?php echo $rows['amount']; ?></div></td>
                                                <td class="v_ wk xe vm co"><div class="gk yj"><?php echo $rows['acc_name']; ?></div></td>
                                                <td class="v_ wk xe vm co"><div class="gk yj"><?php echo $rows['acc_no']; ?></div></td>
                                                <td class="v_ wk xe vm co"><div class="gk text-slate-800"><?php echo $rows['transtype']; ?></div></td>
                                                <td class="v_ wk xe vm co"><div><?php echo $rows['bank_name']; ?></div></td>
                                                <td class="v_ wk xe vm co"><div><?php echo $rows['remarks']; ?></div></td>
                                                <td class="v_ wk xe vm co"><div><?php echo $rows['date']; ?></div></td>
                                                <td class="v_ wk xe vm co"> <div class="gh"> <div class="gb inline-flex gk <?php echo $rows['status']; ?> rounded-full gp vk mt"><?php echo $rows['status']; ?></div> </div> </td>
                                            </tr>
                                        </tbody>
                                        <?php } ?>
                                    </table>
                                </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </main>
            </div>
        </div>

        <script>
            function printtag(tagid) {
            var hashid = "#"+ tagid;
            var tagname =  $(hashid).prop("tagName").toLowerCase() ;
            var attributes = ""; 
            var attrs = document.getElementById(tagid).attributes;
              $.each(attrs,function(i,elem){
                attributes +=  " "+  elem.name+" ='"+elem.value+"' " ;
              })
            var divToPrint= $(hashid).html() ;
            var head = "<html><head>"+ $("head").html() + "</head>" ;
            var allcontent = head + "<body  onload='window.print()' ><center><img src='https://skyutahcapitals.com/sitelogo.png' width='30%'><br>Account Statement</center><br>Account Name: <?php echo $row['fname']; ?> <?php echo $row['lname']; ?><br> Account Number: <?php echo $row['acc_no']; ?><br>Address: <?php echo $row['addr']; ?><br>Date/Time: <?php echo "" . date("d/m/Y") ;?>  <?php echo " " . date("h:i:sa");?>"+ "<" + tagname + attributes + ">" +  divToPrint + "</" + tagname + ">" +  "</body></html>"  ;
            var newWin=window.open('','Print-Window');
            newWin.document.open();
            newWin.document.write(allcontent);
            newWin.document.close();
           // setTimeout(function(){newWin.close();},10);
        }</script>
        <script src="assets/plugins/table/DataTables/pdfmake-0.1.27/build/pdfmake.min.js"></script>
        <script src="bower_components/jquery/dist/jquery.min.js"></script>
            <?php include 'footer.php';?>