<?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

$package_id = $_GET['package_id'];

$sql_wallet = "SELECT * FROM wallet 
WHERE ref_code='$ref_code' LIMIT 1";
$result_wallet = $mysqli->query($sql_wallet);
$row_wallet = $result_wallet->fetch_assoc();
$product_wallet = $row_wallet['product_wallet'];

$sql_rules = "SELECT *
            FROM system_setting
            Where status='1'";
$result_rules = $mysqli->query($sql_rules);
$row_rules = $result_rules->fetch_assoc();
$withdraw_profit_button = $row_rules['withdraw_profit_button'];
$purchase_package_status = $row_rules['purchase_package_status'];
?>



<div class="row">
<div class="col-12">
<div class="card">
    <div class="card-body">
        <h4 class="card-title">My Package</h4>
        <?php if ($withdraw_profit_button == '0')
        {
        ?>
        <div class="alert alert-info"> <i class="ti-user"></i> <b>Capital Withdraw Notice</b><br>
        Capital Withdrawn is unable for a moment. Please try again later within 10 minutes from now
        </div>
        <?php
		}
        ?>
        
        1.  Capital withdrawal for account registered in less than 1 year will be charged 10%<br>
        2. Capital withdrawal request will be processed in 7 to 14 working days
        <div class="table-responsive m-t-40">            
            <table class="display nowrap table table-hover table-striped table-bordered" cellspacing="0" width="100%">
                <thead>
                    <tr>
                        <th>Package ID</th>
                        <th>Member ID</th>
                        <th>Package Name</th>
                        <th>Package Balance Price</th>
                        <th>Purchase Date</th>
                        <th>Withdraw Charge</th>
                        <?php
                        if ($level == '2' && $withdraw_profit_button == '1')
                        {
                        ?>
                        <th>Action</th>
                        <?php
                        }
                        ?>
                    </tr>
                </thead>                                      
                <tbody>
                    <?php
                    if ($level == '1')
                    {
                        $q = "SELECT *
                        FROM package_sale
                        Where id = '$package_id'
                        order by id Desc";
					}
                    else
                    if ($level == '2')
                    {
                        $q = "SELECT *
                        FROM package_sale
                        Where id = '$package_id'
                        order by id Desc";
					}

                    $result = $mysqli-> query($q);
	                if ($result -> num_rows > 0)
	                {
		                $record = $result ->fetch_assoc();
						$id = $record['id'];
                        $purchase_code = $record['purchase_code'];
                        $ref_code = $record['ref_code'];
                        $package_name = $record['package_name'];
                        $package_price = $record['package_price'];
                        $package_status_1 = $record['status'];
                        $package_purchase_date = $record['created_date'];
                        $package_withdraw_status = $record['withdraw_status'];
                        $created_date = date('d-m-Y', strtotime($record['created_date']));

                        /*
                        if ($package_status_1 == '1')
                        {
                            $package_status = 'Active';
						}
                        else
                        if ($package_status_1 == '2')
                        {
                            $package_status = 'Unactive';
						}
                        */

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

                        $date_1_year = date("Y-m-d", strtotime(date("Y-m-d", strtotime($package_purchase_date)) . " + 365 day"));

                        if ($today < $date_1_year)
                        {
                           $fees_percent = 10 ;
	                    }
	                    else
	                    if ($today > $date_1_year)
	                    {
	                        $fees_percent = 0 ;
	                    }
                    ?>
                    <form method="post" action="../Controller/Database_sql.php" onsubmit="return confirm('Do you want to proceed?');" enctype="multipart/form-data">
                    <tr>
                        <td>PCK<?php echo $id; ?></td>
                        <td><?php echo $ref_code; ?></td>
                        <td><?php echo $package_name; ?></td>
                        <td>$<?php echo $package_price; ?></td>
                        <td><?php echo $created_date; ?></td>
                        <td><?php echo $fees_percent; ?>%</td>
                        <?php
                          if ($level == '2' && $withdraw_profit_button == '1' )
                          {
                          ?>
                            <td>
                              <?php
                              if ($package_withdraw_status == '0')
                              {
                              ?>
                            
                                  <input type="hidden" class="form-control" name="purchase_code" value="<?php echo $purchase_code;?>" >
                                  <input type="hidden" class="form-control" name="ref_code" value="<?php echo $ref_code;?>" >
                                  <input type="hidden" class="form-control" name="PCK_id" value="<?php echo $id;?>" >

                                  Please Keyin Your Password To Withdraw Capital<br>
                                  <input type="password" class="form-control" name="password" required><br><br>
                                  
                                  Amount To Withdraw<br>
                                  <input type="number" step="0.01" min="0" max="<?php echo $package_price; ?>" class="form-control" name="amount_to_withdraw" required><br><br>

                                  <button name="Capital_Withdraw" class="btn btn-success"><i class="fa fa-check"></i> Withdraw Capital</button>
						      <?php
                              }    
                              else
                              echo "Capital Already Withdrawn";
                              ?>
                            </td>
                        <?php
                          }  
                          }
                          ?>
                    </form> 
                    </tr>
                </tbody>
            </table>
            </form>                                 
        </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-->

</body>

</html>