<?php include("../Header/Session.php"); ?>
<?php include("../Header/Connection.php"); ?>

<!DOCTYPE html>
<html lang="en">
<?php include ("../Header/head.php"); ?>
<body class="skin-default fixed-layout">

<!-- Main wrapper - style you can find in pages.scss -->
<div id="main-wrapper">    
<?php include ("../Header/header.php"); ?>
<?php include ("../Header/left_menu.php"); ?>
<?php include ("../Header/right_sidebar.php"); ?>
        
<!-- Page wrapper  -->
<div class="page-wrapper">
<!-- Container fluid  -->
<div class="container-fluid">
<!-- Bread crumb and right sidebar toggle -->
<!--?php include ("../Header/breadcumb.php"); ?-->
<br><br>
<!-- End Bread crumb and right sidebar toggle -->
<!-- Start Page Content -->
<!-- ============================================================== -->
<?php
$invoice_id = htmlspecialchars($_GET['invoice_id'],ENT_QUOTES);
$order_id = htmlspecialchars($_GET['order_id'],ENT_QUOTES);
$trans_code = htmlspecialchars($_GET['trans_code'],ENT_QUOTES);	

$sql_order_item = " SELECT *
					FROM package_payment
                    WHERE id  = '$invoice_id'
					AND order_id  = '$order_id'
					AND trans_code  = '$trans_code'
					AND status='1'
					LIMIT 1";
$result_order_item = $mysqli-> query($sql_order_item);
if ($result_order_item -> num_rows > 0)
{
	$row_order_item = $result_order_item ->fetch_assoc();
	$full_amount  = $row_order_item['full_amount'];
    $ref_code  = $row_order_item['ref_code'];
}

$sql_user = "SELECT * 
FROM user 
WHERE ref_code='$ref_code'
And status='1'";
$result_user = $mysqli->query($sql_user);
if ($result_user ->num_rows > 0)
{
	$row_user = $result_user ->fetch_assoc();
	$type_of_user = $row_user['type_of_user'];
    $name = $row_user['name'];
    $last_name = $row_user['last_name'];
    $email = $row_user['email'];
    $phone_number = $row_user['phone_number'];
    $address = $row_user['address'];

    $User_ID = $ref_code;
    $Name = $name." ".$last_name;
    $Address = $address;
}  

date_default_timezone_set("Asia/Kuala_Lumpur");
$Today = date('Y-m-d');
$number = randomRefferalNumber();


?>




<div class="row">
<div class="col-lg-12">
<input type="button" class="btn btn-success" onclick="printDiv('printableArea')" value="Click to Print This Page" /><br><br>
<a href="pay_package.php?order_id=<?php echo $order_id; ?>&trans_code=<?php echo $trans_code; ?>" class="btn btn-success">Back</a><br>

 <div id="printableArea"  class="content">
      <div class="content">
      <div class="container-fluid">
        <!--Level 0-->
        <div class="row">
          <table style="width:100%">
            <tr>
             <th>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
             <th>
                <b>
                UMRAH HAJI MABRUR SDN BHD<br>
                NO.89, JALAN SUSUR LARKIN PERDANA 1<br>
                LARKIN PERDANA, 80350 JOHOR BAHRU JOHOR<br>
                TEL: 07-234 8948 | 011-1133 7747 | 017-788 5543<br>
                EMAIL : support@mygoldsdnbhd.com <br>
                WEB: www.mygoldsdnbhd.com<br><br><br>  
                </b>
             </th> 
              <th>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
             <th>
            </tr>
          </table>


          <table style="width:100%">
            <tr>
             <th>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
             <th>
                <b>
                ID NUMBER: <?php echo $User_ID; ?> <br>
                NAME:      <?php echo $Name; ?>    <br>
                ADDRESS:   <?php echo $Address; ?> <br>
                </b>
             </th>
             <th>
             <b>
                CASH SALES<br>
                DOCUMENT NO: INV00<?php echo $invoice_id; ?><br>
                DATE: <?php echo $Today; ?><br>
                </b>
             </th> 
             <th>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
             <th>
            </tr>
          </table>
          
          <table style="margin-top:20px;" class="display nowrap table table-hover table-striped table-bordered" cellspacing="0" width="100%">
            <thead>
                <tr>
                    <th>Invoice ID</th>
                    <th>Member Info</th>
                    <th>Amount</th>
                    <th>Balance</th>
                    <th>Payment Date</th>
                </tr>
            </thead>                                      
            <tbody>
                <?php
                $q = "SELECT *
                FROM package_payment
                Where id = '$invoice_id'
                And order_id = '$order_id'
                And trans_code = '$trans_code'
                And status = '1'
                order by id Asc";

                $result = $mysqli->query($q);
                if ($result->num_rows > 0)
                {
                    while($record = $result -> fetch_assoc())
                    {  
						$invoice_id = $record['id'];
                        $ref_code  = $record['ref_code'];
                        $amount  = $record['amount'];
                        $balance = $record['balance'];
                        $created_date = date('d-m-Y H:i:s', strtotime($record['created_date']));

                        $sql_user = "SELECT * 
                        FROM user 
                        WHERE ref_code='$ref_code'
                        And status='1'";
                        $result_user = $mysqli->query($sql_user);
	                    if ($result_user ->num_rows > 0)
	                    {
		                    $row_user = $result_user ->fetch_assoc();
		                    $type_of_user = $row_user['type_of_user'];
                            $name = $row_user['name'];
                            $last_name = $row_user['last_name'];
                            $email = $row_user['email'];
                            $phone_number = $row_user['phone_number'];
	                    }  
                ?>
                <form method="post" action="../Controller/Database_sql.php" onsubmit="return confirm('Do you want to proceed?');" enctype="multipart/form-data">
                <tr>
                    <td>INV00<?php echo $invoice_id; ?></td>
                    <td><?php echo $ref_code;?> | <?php echo $name;?></td>
                    <td>USD <?php echo number_format($amount,2); ?></td>
                    <td>USD <?php echo number_format($balance,2); ?></td>
                    <td><?php echo $created_date; ?></td>
                    <?php
                    }  
                }
                ?>
                </form> 
                </tr>
            </tbody>
        </table>

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


<!-- ============================================================== -->
<!-- End PAge Content -->

</div>
<!-- End Container fluid  -->
</div>
<!-- End Page wrapper  -->

<!-- Footer Start-->
<?php include ("../Footer/footer.php"); ?>
<!-- Footer End-->

</div>
<!-- End Wrapper -->
<!-- All Jquery -->
    

<!-- All Jquery Start-->
<?php include ("../Header/all_jquery.php"); ?>
<!-- All Jquery End-->

<script>
   function printDiv(divName) {
     var printContents = document.getElementById(divName).innerHTML;
     var originalContents = document.body.innerHTML;

     document.body.innerHTML = printContents;

     window.print();

     document.body.innerHTML = originalContents;
}
</script>

</body>

</html>