<?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>Account Statement - Skyutah Capitals</title>
            
            <?php include 'header.php';?>

             <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">Account Statement</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">
                            <header class="mn mr">
                                <h2 class="g_ text-slate-800">Here is your Credit and Debit Transaction Statement</h2>
                            </header>
                            <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">Transaction Type</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/Sender</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>
                                            </tr>
                                        </thead>
                                        <?php 
                $uname = $_SESSION['acc_no'];
                $debcre = $reg_user->runQuery("SELECT * FROM alerts WHERE uname = '$uname'");
                $debcre->execute();
                while($rows = $debcre->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="gk yj"><?php include('ss.php');  ?></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 text-slate-800"><?php echo $rows['sender_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']; ?> &nbsp;<?php echo $rows['time']; ?></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';?>