<?php
 session_start();
 require_once('../connect.php');
 require_once('sql_required.php');

$datetoday = date('Y-m-d'); 
$active_tab = "walk";
if (!isset($_SESSION['unique_id'])) { ?>
    <script language="javascript">
      window.location.href = '../index.php';
    </script>
<?php } 

$requestID = $_GET['requestID'];
$sqlRequest = "SELECT * FROM tbl_purchase WHERE id = '$requestID'";
$resultRequest = $conn->query($sqlRequest);
$rowRequest = mysqli_fetch_assoc($resultRequest);
  $member_id = $rowRequest['member_id'];
  $purchase_id = $rowRequest['purchase_id'];

$sql_user = "SELECT * FROM tbl_user_account WHERE unique_id = '$member_id'";
$result_user = $conn->query($sql_user);
$row_user = mysqli_fetch_assoc($result_user);

?>  
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>Purchase Details</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
  <link rel="icon" href="images/logo.png" type="image/png" sizes="16x16">
  <link rel="stylesheet" href="plugins/fontawesome-free/css/all.min.css">
  <link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
  <link rel="stylesheet" href="dist/css/adminlte.min.css">
  <link rel="stylesheet" href="plugins/overlayScrollbars/css/OverlayScrollbars.min.css">
  <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">
  <link rel="stylesheet" type="text/css" href="css/style1.css">
  <link href="plugins/fancybox/fancybox.min.css" type="text/css" rel="stylesheet">
<style type="text/css">
  .content-wrapper {
    background: #151e27!important;
  }
  @media(max-width:800px) {
    .modal-content {
      position: fixed; bottom: 40%; width: 96%; left: 7;
    }
    .modal-dialog {
      margin: 0!important; padding: 0!important;
    }
  }
  .page-item.active .page-link {
    background-color: #27313d!important;
    border-color: #27313d!important;
    color: #000;
  }
  .page-item .page-link {
    background-color: #151e27!important;
    border-color: grey!important;
    color: grey!important;
  }
  .txn-history {
    text-align: left;
  }
  .txn-list {
    background-color: #1d2532;
    padding: 12px 10px; 
    color: #777;
    font-size: 14px;
    margin: 7px 0;
    box-shadow: 0 2px 5px 0 rgba(0,0,0,.16), 0 2px 10px 0 rgba(0,0,0,.12)!important;
    cursor: pointer;
  }
  .transaction-amount {
    float: right;
    color: #fff;
    font-weight: 800;
  }
  .transaction-number {
   float: right;
  }
/*  @media(max-width:991px) {
    #order_full_screen {
      display: none!important;
    }
    #order_small_screen {
      display: block!important;
    }
  }*/
  .transaction a {
    color: #808080!important;
  }  

  .transaction a.active {
    background-color: transparent!important;
    border-top: transparent;
    border-left: transparent;
    border-right: transparent;
    border-bottom: 2px solid #ffd700!important;
    color: #ffd700!important;
    font-weight: bold;
  }  

  .transaction a:hover{
    border-bottom: 2px solid #ffd700!important;
    border-top: 0px!important;
    border-left: 0px!important;
    border-right: 0px!important;
  }
  .alert-success {
    color: #3c763d;
    background-color: #dff0d8;
    border-color: #d6e9c6;
    border-radius: 0;
  }

  .alert-danger {
    color: #a94442;
    background-color: #f2dede;
    border-color: #ebccd1;
    border-radius: 0;
  }
  .form-control {
    border-radius: 10px;
  }
  .form-control:focus {
    border: 1px solid #ffd700!important;
  }

  .display-item-flex {
    display: flex;
    justify-content: space-between;
  }
</style>
</head>
<body class="hold-transition sidebar-mini layout-footer-fixed layout-fixed" style="background: #151e27;">
<div id="preloader" class="loading" style="display: none"></div>
<div class="wrapper">
  <nav class="main-header navbar navbar-expand navbar-white" style="background: #151e27; border-bottom: 0; box-shadow: none!important;">
    <ul class="navbar-nav">
      <li class="nav-item">
        <a href="walkinPurchase.php?<?php echo generate_string($permitted_chars, 100); ?>" class="withanimation back_arrow"><i class="fas fa-angle-left pr-2" style="font-size: 20px; color: #ffd700;"></i></a><span class="brand-text" style="font-size: 20px;"><span style="font-size: 20px; font-weight: bolder; line-height: 20px; color: #fff;">Purchase Details</span></a>
      </li>
    </ul>
    <ul class="navbar-nav ml-auto">
      <a class="nav-link" data-widget="pushmenu" href="#" role="button"><i class="fas fa-bars"></i></a>
    </ul>
  </nav>

<?php include ("navbar.php")?>
<div class="content-wrapper">
  <section class="content">
    <div class="container-fluid pt-3">
      <div class="col-lg-6 offset-lg-3">

        <div class="display-item-flex">
          <div class="text-white">Purchase ID</div>
          <div class="font-weight-bold text-warning"><?php echo $rowRequest['purchase_id']; ?></div>
        </div>

        <div class="display-item-flex">
          <div class="text-white">Member Name</div>
          <div class="font-weight-bold text-warning"><?php echo $row_user['firstname'].' '.$row_user['lastname']; ?></div>
        </div>
        <hr>

        <div class="text-white font-weight-bold">Product List</div>

        <table class="table table-striped table-bordered mt-2 text-white">
          <thead>
            <tr>
              <th>Product</th>
              <th>Quantity</th>
              <th>Per Item Price</th>
            </tr>
          </thead>
          <tbody>
            <?php 
              $sqlRequestProduct = "SELECT * FROM tbl_purchase_product WHERE purchase_id = '$purchase_id'";
              $resultRequestProduct = $conn->query($sqlRequestProduct);
                while($rowRequestProduct = mysqli_fetch_array($resultRequestProduct)) {

                  $productID = $rowRequestProduct['product_id'];

                  $sqlProductName = "SELECT product_name FROM tbl_product WHERE product_id = '$productID'";
                  $resultProductName = $conn->query($sqlProductName);
                  $rowProductName = mysqli_fetch_assoc($resultProductName);
            ?>
            <tr>
              <td class="textColor"><?php echo $rowProductName['product_name']; ?></td>
              <td>x<?php echo $rowRequestProduct['product_quantity']; ?></td>
              <td>&#8369; <?php echo $rowRequestProduct['product_price']; ?>.00</td>
            </tr>
            <?php } ?>
          </tbody>
        </table>

        <div class="display-item-flex" style="font-size: 20px">
          <div class="text-white">Total Request</div>
          <div class="font-weight-bold text-warning">&#8369; <?php echo $rowRequest['total_purchase']; ?></div>
        </div>

        <hr>

        <div class="display-item-flex">
          <div class="text-white">Date Request</div>
          <div class="font-weight-bold text-white"><?php echo date('F d Y', strtotime($rowRequest['date_purchase'])); ?></div>
        </div>

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

<script src="plugins/jquery/jquery.min.js"></script>
<script src="plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="plugins/overlayScrollbars/js/jquery.overlayScrollbars.min.js"></script>
<script src="plugins/fancybox/fancybox.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
  $('a[data-toggle="tab"]').on('show.bs.tab', function(e) {
      localStorage.setItem('activeTab', $(e.target).attr('href'));
  });
  var activeTab = localStorage.getItem('activeTab');
  if(activeTab){
      $('#myTab a[href="' + activeTab + '"]').tab('show');
  }
});
$(function () {
  $(".withanimation").click(function(e) {
      e.preventDefault();
      $(".loading").show();
      var url=$(this).attr("href");
      setTimeout(function() {
          window.location=url;
      }, 500);
  });
});
setTimeout(function(){
  $('#message').html('');
}, 5000);

if ( window.history.replaceState ) {
  window.history.replaceState( null, null, window.location.href );
}
</script>
</body>
</html>
