<?php
include $_SERVER['DOCUMENT_ROOT']."/personal/onlinebanking/dashboard/functions/getProfileDetails.php";

$thisTransactionID = $_GET['transaction'];

// Check if Product exists
$checkThisTransaction = mysqli_query($connect, "SELECT * FROM transactions WHERE ID = '$thisTransactionID' AND UserID = '$CustomerID'");
$numOfTransactions = mysqli_num_rows($checkThisTransaction);

$transDetails = mysqli_fetch_assoc($checkThisTransaction);
$ID = $transDetails['ID'];
$ReferenceNum = $transDetails['ReferenceNum'];
$Amount = $transDetails['Amount'];
$Status = $transDetails['Status'];
$Type = $transDetails['Type'];
$SenderName = $transDetails['SenderName'];
$ReceiverAccNum = $transDetails['ReceiverAccNum'];
$Narration = $transDetails['Narration'];
$DateTrans = $transDetails['TransDate'];

$Note = $transDetails['Note'];

$SwiftCode  = $transDetails['SwiftCode'];
$IbanCode  = $transDetails['Iban'];
$transferType  = $transDetails['transferType'];
$bankAddress = $transDetails['bankAddress'];

$accNumVarR = $ReceiverAccNum;
$accNumVarR = substr_replace($accNumVarR, str_repeat("*", 4), 4, 4);

//================get Time and Date ================
$SplitTimeDate = explode(' ', $DateTrans);
$Date = $SplitTimeDate[0];
$Time = $SplitTimeDate[1];
//============get Accurate AM/PM Time ================
$TimeSplit = explode(':', $Time);
$Time1 = $TimeSplit[0];
$Time2 = $TimeSplit[1];
$accurateTime = $Time1.":".$Time2;

//============get Accurate Date ================
$getDateSplit = explode('-', $Date);
$year = $getDateSplit[0];
$month = $getDateSplit[1];
$day = $getDateSplit[2];
// ACCURATE MONTH 
switch ($month) {
case 12:
    $MonthText = "December";
    break;
case 11:
    $MonthText = "November";
    break;
case 10:
    $MonthText = "October";
    break;
case 9:
    $MonthText = "September";
    break;
case 8:
    $MonthText = "August";
    break;
case 7:
    $MonthText = "July";
    break;
case 6:
    $MonthText = "June";
    break;
case 5:
    $MonthText = "May";
    break;
case 4:
    $MonthText = "April";
    break;
case 3:
    $MonthText = "March";
    break;
    case 2:
    $MonthText = "February";
    break;
    case 1:
    $MonthText = "January";
    break;
                                
    default:
    # code...
    break;
}
//=========== GET TRACK TRANSACTION OPTIONS ======================================================
// $trackThisTransation = mysqli_query($connect, "SELECT * FROM trackTrans WHERE transactionID = '$ID'");
// $trackTransAvailable = mysqli_fetch_assoc($trackThisTransation);

// $transactionTrackID = $trackTransAvailable['ID'];
// $TransactionLevel = $trackTransAvailable['Level'];
// // $TransactionCode = $trackTransAvailable['Code'];
// $TransactionPercentage = $trackTransAvailable['Percentage'];



if(isset($_SESSION['UserID']) && $numOfTransactions > 0) {?>
  <!DOCTYPE html>
<html class="no-js" lang="en">

<head>
  <!-- Meta Tags -->
  <meta charset="utf-8">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="author" content="Laralink">
  <link rel="icon" type="image/x-icon" href="/personal/favicon.png">
  <!-- Site Title -->
  <title><?php echo $Narration; ?></title>
  <link rel="stylesheet" href="/personal/assets/css/style.css">
</head>

<body>
  <div class="tm_container">
    <div class="tm_invoice_wrap">
      <div class="tm_invoice tm_style1 tm_type1" id="tm_download_section">
        <div class="tm_invoice_in">
          <div class="tm_invoice_head tm_top_head tm_mb15 tm_align_center">
            <div class="tm_invoice_left">
              <div class="tm_logo"><h2 style="color:red;">AK BANK</h2></div>
            </div>
            <div class="tm_invoice_right tm_text_right tm_mobile_hide">
              <div class="tm_f50 tm_text_uppercase tm_white_color" style="transform: scale(0.76);"><?php echo $Type; ?></div>
            </div>
            <div class="tm_shape_bg tm_accent_bg tm_mobile_hide"></div>
          </div>
          <div class="tm_invoice_info tm_mb25">
            <div class="tm_card_note tm_mobile_hide"><b class="tm_primary_color">Naration:  <br></b> <?php echo $Type; ?>@<br><?php echo $Narration; ?></div>
            <div class="tm_invoice_info_list tm_white_color">
              <!-- <p class="tm_invoice_number tm_m0">Invoice No: <b>#LL93784</b></p> -->
              <p class="tm_invoice_date tm_m0">Date: <b><?php echo $MonthText." ".$day.", ".$year; ?> <?php echo date('h:i A ', strtotime($accurateTime)); ?></b></p>
            </div>
            <div class="tm_invoice_seperator tm_accent_bg"></div>
          </div>
          <div class="tm_invoice_head tm_mb10">
            <div class="tm_invoice_left">
            <?php
        if ($Type == "FUND TRANSFER") {?>
          <p class="tm_mb2"><b class="tm_primary_color">Sent To:</b></p>
              <p>
              Sender name: <b><?php echo $AccFullname; ?></b> <br>
              Receiver Account Number: <b><?php echo $accNumVarR; ?></b> <br>
              Transaction status: <?php if($Status == 0){
                        echo '<span style="color: red;">Unsuccessful</span>';
                    }elseif($Status == 1) {
                        echo '<span style="color: #DFA100;" class="pending">pending</span>';
                    }else {
                        echo '<span style="color: green;" class="paid">Successful</span>';
                    } 
                    ?>
              </p>
        <?php
        }else {?>
            <p class="tm_mb2"><b class="tm_primary_color">Received To:</b></p>
              <p>
              Sender name: <b><?php echo $SenderName; ?></b> <br>
              Transaction status: <?php if($Status == 0){
                        echo '<span style="color: red;">Unsuccessful</span>';
                    }elseif($Status == 1) {
                        echo '<span style="color: #DFA100;" class="pending">pending</span>';
                    }else {
                        echo '<span style="color: green;" class="paid">Successful</span>';
                    } 
                    ?>
              </p>
            <?php

        }
    ?>

            </div>
            <div class="tm_invoice_right tm_text_right">
              <!-- <p class="tm_mb2"><b class="tm_primary_color">Pay To:</b></p> -->
              <p>
              Reference No : <b><?php echo $ReferenceNum; ?></b><br>
              Date : <b><?php echo $MonthText." ".$day.", ".$year; ?> <?php echo date('h:i A ', strtotime($accurateTime)); ?></b>
              </p>
            </div>
          </div>
          <div class="tm_table tm_style1">
            <div class="">
              <div class="tm_table_responsive">
                <table>
                  <thead>
                    <tr class="tm_accent_bg">
                      <th class="tm_width_3 tm_semi_bold tm_white_color">Transfer Type</th>
                      <th class="tm_width_4 tm_semi_bold tm_white_color">Amount</th>
                      <th class="tm_width_2 tm_semi_bold tm_white_color">Status</th>
                      <th class="tm_width_1 tm_semi_bold tm_white_color">Transaction Type</th>
                    </tr>
                  </thead>
                  <tbody>
                    <tr>
                      <td class="tm_width_3"><?php echo $transferType; ?></td>
                      <td class="tm_width_4"><?php echo $Curr.$Amount; ?></td>
                      <td class="tm_width_2"><?php if($Status == 0){
                        echo '<span style="color: red;">UNSUCCESSFUL</span>';
                    }elseif($Status == 1) {
                        echo '<span style="color: #DFA100;" class="pending">PENDING</span>';
                    }else {
                        echo '<span style="color: green;" class="paid">SUCCESSFUL</span>';
                    } 
                    ?></td>
                      <td class="tm_width_1"><?php echo $Type; ?></td>
                    </tr>
                    
                  </tbody>
                </table>
              </div>
            </div>
            
            <div class="tm_invoice_footer tm_border_top tm_mb15 tm_m0_md">
            <br>
              <div class="tm_left_footer">
              <br>

                <p class="tm_mb2"><b class="tm_primary_color">More info:</b></p>
                <?php
                if($transferType == "International Transfer" && $Type == "FUND TRANSFER") {
                ?>
                <p class="tm_m0">Swift Code - <?php echo $SwiftCode; ?></p>
                <p class="tm_m0">IBAN Code - <?php echo $IbanCode; ?></p>
                <p class="tm_m0">Bank Address : <br> <?php if($bankAddress == ''){echo "NAN";}else {echo $bankAddress;} ?></p>
                <?php
                }
                ?>
                

              </div>
              <div class="tm_right_footer">
                <table class="tm_mb15">
                  <tbody>
                    
                    <tr class="tm_gray_bg">
                      <td class="tm_width_3 tm_primary_color">Tax <span class="tm_ternary_color">()</span></td>
                      <td class="tm_width_3 tm_primary_color tm_text_right">+<?php echo $Curr.'0'; ?></td>
                    </tr>
                    <tr class="tm_gray_bg">
                      <td class="tm_width_3 tm_primary_color">Amount <span class="tm_ternary_color"></span></td>
                      <td class="tm_width_3 tm_primary_color tm_text_right"><?php echo $Curr.$Amount; ?></td>
                    </tr>
                    <tr class="tm_accent_bg">
                      <td class="tm_width_3 tm_border_top_0 tm_bold tm_f16 tm_white_color">Available Balance</td>
                      <td class="tm_width_3 tm_border_top_0 tm_bold tm_f16 tm_white_color tm_text_right"><?php echo $AccBal; ?></td>
                    </tr>
                  </tbody>
                </table>
              </div>
            </div>
            <div class="tm_invoice_footer tm_type1">
              <div class="tm_left_footer"></div>
              <div class="tm_right_footer">
                <div class="tm_sign tm_text_center">
                  <img src="/personal/images/sign.svg" alt="Sign">
                  <p class="tm_m0 tm_ternary_color"></p>
                  <p class="tm_m0 tm_f16 tm_primary_color">Management</p>
                </div>
              </div>
            </div>
          </div>
          <div class="tm_note tm_text_center tm_font_style_normal">
            <hr class="tm_mb15">
            <p class="tm_mb2"><b class="tm_primary_color">Notice:</b></p>
            <p class="tm_m0">Your Account information is private, please do not disclose your login credentials or card details to anyone, evade clicking od suspicious links in email or text messages, if in doubt kindly contact us <a href="mailto:info@akfinancialbank.com" style="text-decoration: none;">info@akfinancialbank.com</a></p>
          </div><!-- .tm_note -->
        </div>
      </div>
      <div class="tm_invoice_btns tm_hide_print">
        <a href="javascript:window.print()" class="tm_invoice_btn tm_color1">
          <span class="tm_btn_icon">
            <svg xmlns="http://www.w3.org/2000/svg" class="ionicon" viewBox="0 0 512 512"><path d="M384 368h24a40.12 40.12 0 0040-40V168a40.12 40.12 0 00-40-40H104a40.12 40.12 0 00-40 40v160a40.12 40.12 0 0040 40h24" fill="none" stroke="currentColor" stroke-linejoin="round" stroke-width="32"/><rect x="128" y="240" width="256" height="208" rx="24.32" ry="24.32" fill="none" stroke="currentColor" stroke-linejoin="round" stroke-width="32"/><path d="M384 128v-24a40.12 40.12 0 00-40-40H168a40.12 40.12 0 00-40 40v24" fill="none" stroke="currentColor" stroke-linejoin="round" stroke-width="32"/><circle cx="392" cy="184" r="24" fill='currentColor'/></svg>
          </span>
          <span class="tm_btn_text">Print</span>
        </a>
        <button id="tm_download_btn" class="tm_invoice_btn tm_color2">
          <span class="tm_btn_icon">
            <svg xmlns="http://www.w3.org/2000/svg" class="ionicon" viewBox="0 0 512 512"><path d="M320 336h76c55 0 100-21.21 100-75.6s-53-73.47-96-75.6C391.11 99.74 329 48 256 48c-69 0-113.44 45.79-128 91.2-60 5.7-112 35.88-112 98.4S70 336 136 336h56M192 400.1l64 63.9 64-63.9M256 224v224.03" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32"/></svg>
          </span>
          <span class="tm_btn_text">Download</span>
        </button>
      </div>
    </div>
  </div>
  <script src="assets/js/jquery.min.js"></script>
  <script src="assets/js/jspdf.min.js"></script>
  <script src="assets/js/html2canvas.min.js"></script>
  <script src="assets/js/main.js"></script>
</body>
</html>
<?php
}else {
    header("Location: /auth/transactions/");
    die();
}
?>