 <?php
session_start();

require_once("../config.php");


// Check if user is logged in
if (!isset($_SESSION['SESS_LOGGEDIN']) || $_SESSION['SESS_LOGGEDIN'] !== true) {
    header("Location: " . $config_basedir . "logout.php");
    exit();
}







$id = $_SESSION['SESS_USERID'];


    $stmt = $pdo->prepare("SELECT * FROM logins WHERE id = :id");
    $stmt->bindParam(':id', $id, PDO::PARAM_INT);
    $stmt->execute();

    $serow = $stmt->fetch(PDO::FETCH_ASSOC);

    if ($serow) {
        // Process user data
    } else {
        echo "User not found.";
    }



?>


 
 
 
 
 
 
 
 
  <?php 
            
            
           

if(isset($success_goback)){
    echo"<body onload='goBack()'>";
}

?>
<script>
function goBack() {
  window.history.go(-2);
}
</script>
 
 
 




<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Transaction Receipt</title>

    <link rel="icon" type="image/png" href="../img/favicon.png">

     <!-- Google font -->
	<link rel="preconnect" href="https://fonts.gstatic.com">
	<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet">
	
    <link rel="stylesheet" href="npm/dist/css/dist/css/bootstrap.min.css">
 
    
    
    <script
      src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
      integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
      crossorigin="anonymous"
    ></script>
    
    
    

    <style>
        * {
            box-sizing: border-box;
        }
        #mainDiv {
            margin: 10% auto;
            width: calc(100% - 10px);
            max-width: 500px;
            height: auto;
            background-color: #fff;
            padding: 15px;
        }
        #button {
            margin: 0 auto;
            width: calc(100% - 10px);
            max-width: 500px;
            height: auto;
            padding: 15px;
        }
        #headerDiv {
            
            
        background-image: linear-gradient(rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.9)), 
      url('../img/LOGO.png'); no-repeat center center fixed; 
      
    
      
      
        background-repeat: no-repeat;
        background-position: center;
        background-attachment: scroll;
        background-size: contain;
      }
    </style>
</head>
<body class="bg-success">
    <div id="mainDiv" class="bg-light">
        <div id="headerDiv" class="mt-2 px-2">
            <div class="row">
                <div class="col text-start">
                  <h6 style="font-weight: bold; font-size: 14px;;">TRANSACTION RECEIPT</h6>
                </div>
                <div class="col text-end">
                  <img
                    src="../img/LOGO.png"
                    
                    alt="logo"
                    style="width: 100px; height: 30px"
                  />
                </div>
            </div>

            <div class="row text-center mt-2">
                <div class="h6 col" style="font-weight: bold"><?php echo $domain_name ?></div>
            </div>

           
           
           
           
            <div class="row mt-2 bg-primary text-center p-1">
                <div class="col">
                    <p style="margin: 0; padding: 0; color: #fff;"><strong><?php echo $cdate ?></strong></p>
                </div>

            </div>

           
           
           
           
           
           
           
           
           
            <tr class="mt-3">
                <td
                  align="left"
                  bgcolor="#ffffff"
                  style="
                    padding: 24px;
                    font-family: 'Source Sans Pro', Helvetica, Arial, sans-serif;
                    font-size: 16px;
                    line-height: 24px;
                  "
                >
            
            
            
            
            
            
            
      <?php

if (isset($_GET['id'])) {
    $id = intval($_GET['id']);

    $stmt = $pdo->prepare("SELECT * FROM transactions WHERE id = ?");
    $stmt->execute([$id]);
    $ordrow = $stmt->fetch(PDO::FETCH_ASSOC);

    if ($ordrow) {
        echo "<table border='0' cellpadding='0' cellspacing='0' width='100%'>";

        // Determine status
        $status = strtolower(trim($ordrow['status']));
        if ($status === 'successful') {
            $statusLabel = "<span style='color:green; font-weight:bold;'>Successful</span>";
        } elseif ($status === 'pending' || $status === '0' || $ordrow['status'] == 0) {
            $statusLabel = "<span style='color:red; font-weight:bold;'>Pending</span>";
        } else {
            $statusLabel = "<span style='color:gray; font-weight:bold;'>Declined</span>";
        }

        echo "<tr><td width='75%'>Status:</td><td width='25%'>$statusLabel</td></tr>";

        echo "<tr><td width='75%'>DATE/TIME:</td><td width='25%'>" . htmlspecialchars($ordrow['date']) . "</td></tr>";
        echo "<tr><td width='75%'>Transaction Type:</td><td width='25%'>";

        // Transaction type
        if ($ordrow['tran_type'] == 1) {
            echo "<p style='color:red'>Debit Transaction Receipt</p>";
        } elseif ($ordrow['tran_type'] == 2) {
            echo "<p style='color:green'>Credit Transaction Receipt</p>";
        }

        if ($ordrow['tran_type2'] == 1) {
            echo "<p style='color:red'>Debit Transaction Receipt</p>";
        } elseif ($ordrow['tran_type2'] == 2) {
            echo "<p style='color:green'>Credit Transaction Receipt</p>";
        }

        echo "</td></tr>";

        // Show beneficiary details only if sending money (debit)
        // if ($ordrow['tran_type'] == 1 || $ordrow['tran_type2'] == 1) {
            echo "<tr><td>Beneficiary Acct. No:</td><td>";
            $acct = $ordrow['ben_acct_no'];
            if (strlen($acct) >= 6) {
                $masked = substr($acct, 0, 3) . str_repeat('*', strlen($acct) - 6) . substr($acct, -3);
            } else {
                $masked = str_repeat('*', strlen($acct)); // fallback if too short
            }
            echo htmlspecialchars($masked);
            echo "</td></tr>";

            echo "<tr><td>Beneficiary Name:</td><td>" . htmlspecialchars($ordrow['ben_name']) . "</td></tr>";
            echo "<tr><td>Beneficiary Bank:</td><td>" . htmlspecialchars($ordrow['bank_name']) . "</td></tr>";
        // }

        // Narration method
        echo "<tr><td>Narration:</td><td>";
        switch ($ordrow['method']) {
            case 1:
                echo "Same Bank";
                break;
            case 2:
                echo "Local Bank";
                break;
            case 3:
                echo "Wired/Intl Bank";
                break;
            default:
                echo "Unknown";
        }
        echo "</td></tr>";

        echo "<tr><td>Sender:</td><td>" . htmlspecialchars($ordrow['name']) . "</td></tr>";
        echo "<tr><td>Description:</td><td>" . htmlspecialchars($ordrow['note']) . "</td></tr>";

        echo "
            <tr>
                <td style='border-top: 2px dashed #d2c7ba; border-bottom: 2px dashed #d2c7ba;'><strong>Amount</strong></td>
                <td style='border-top: 2px dashed #d2c7ba; border-bottom: 2px dashed #d2c7ba;'>
                    <strong>" . htmlspecialchars($ordrow['cur']) . " " . number_format($ordrow['trans_amount'], 2) . "</strong>
                </td>
            </tr>
        ";

        echo "</table>";
    } else {
        echo "Transaction not found.";
    }
} else {
    echo "Transaction ID missing.";
}
?>











            <div class="row mt-3 mb-3">
            <img
                src="tools/frame.png"
                alt="image"
                style="width: 120px; height: 100px;"
            />
            </div>












            <div class="row bg-primary text-light">
                <span style="font-size: smaller; line-height: 12px; padding: 2px 3px">
                  Thanks for banking with us. Receipt generated from <br />
                  <?php echo $config_sitename ?></span
                >
            </div>
        </div>

        <div class="mt-3 text-center">
           <div class="mt-3 text-center">
               
           

          <form action='e_statement.php' method='POST' >
    <input type='hidden' name='goback' value='' />
    <button type="submit" name='back' class="btn btn-danger btn-sm">Go back</button>    
</form>

<script>
function confirmGoBack() {
    if (confirm("Are you sure you want to go back?")) {
        window.history.back();
        return false;  // Prevent form submission
    }
    return false;  // Prevent form submission if user cancels
}
</script>

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




</body>
</html>
