<?php 
    include "head.php" ;
    session_start();
    $page = "Package" ;
    date_default_timezone_set("Asia/Kolkata");

    if(isset($_SESSION['user_id']) && isset($_SESSION['user_name']) && $_SESSION['user_cate'] === "user"){
        $user_id = $_SESSION['user_id'] ;
        $username = $_SESSION['user_name'] ;
        $email = $_SESSION['user_email'] ;
        $phone = $_SESSION['user_phone'] ;
        // $ticket = $_SESSION['last_ticket'] ;
        // $vendor_image = $_SESSION['vendor_image'] ;
    }else{
        header("Location:login.php") ;
    }
?>
	<body>

		<!-- Main Wrapper -->
		<div class="main-wrapper">
		
			<!-- Header -->
			<?php include "header.php" ; ?>
			<!-- /Header -->
			
			<!-- Breadcrumb -->
			<?php include "breadcrumbuser.php" ; ?>
			<!-- /Breadcrumb -->
			
			<!-- Page Content -->
			<div class="content">
				<div class="container-fluid">

					<div class="row">
						<div class="col-md-5 col-lg-4 col-xl-3 theiaStickySidebar">
						
							<!-- Profile Sidebar -->
							<?php include "sidebar.php" ; ?>
							<!-- /Profile Sidebar -->
							
						</div>
						<div class="col-md-7 col-lg-8 col-xl-9">
							
							<div class="row">
								<div class="col-md-12">
									<div class="d-flex justify-content-between align-items-start">
									    <h4 class="mb-4">Buy Package</h4>
    									<a href="#" class="btn btn-sm bg-info-light" data-toggle="modal" data-target="#buypack">
    										<i class="fas fa-money-check"></i> TopUp 
    									</a>
									</div>
									<div class="appointment-tab">
										
										<div class="tab-content">
										
											<!-- Upcoming Appointment Tab -->
											<div class="tab-pane show active" id="upcoming-appointments">
												<div class="card card-table mb-0">
													<div class="card-body">
														<div class="table-responsive">
															<table class="table table-hover table-center mb-0">
																<thead>
																	<tr>
																		<th>Name</th>
																		<th>Mobile Number</th>
																		<th>Email Id</th>
																		<th>Area</th>
																		<th>City</th>
																		<!--<th class="text-center">Request</th>-->
																	</tr>
																</thead>
																<tbody>
																    <?php
                                        						        $pro_sql = "SELECT * FROM user_profile WHERE user_id = '$user_id' " ;
                                        						        $pro_res = $config->query($pro_sql);
                                        						        $pro = $pro_res->fetch_assoc();
                                        						    ?>
																	<tr>
																		<td>
																			<h2 class="table-avatar">
																				<!--<a href="patient-profile.html" class="avatar avatar-sm mr-2"><img class="avatar-img rounded-circle" src="assets/img/patients/patient.jpg" alt="User Image"></a>-->
																				<a href="patient-profile.html"><?= $username; ?></a>
																			</h2>
																		</td>
																		<td><?= $phone; ?></td>
																		<td><?= $email ?> </td>
																		<td><?= $pro['area'] ?></td>
																		<td><?= $pro['city'] ?></td>
																		<!--<td>-->
																		<!--	<div class="table-action">-->
																		<!--		<button href="javascript:void(0);" class="btn btn-sm bg-success-light request" value="<?#= $user_id; ?>">-->
																		<!--			<i class="fas fa-check-circle"></i> Request-->
																		<!--		</button>-->
																		<!--	</div>-->
																		<!--</td>-->
																	</tr>
																	
																</tbody>
															</table>		
														</div>
													</div>
												</div>
											</div>
											<!-- /Upcoming Appointment Tab -->
									   
										</div>
									</div>
								</div>
							</div>
							
	                        <div class="row">
								<div class="col-md-12">
									<h4 class="mb-4">Order History</h4>
									<div class="appointment-tab">
										
										<div class="tab-content">
										
											<!-- Upcoming Appointment Tab -->
											<div class="tab-pane show active" id="upcoming-appointments">
												<div class="card card-table mb-0">
													<div class="card-body">
														<div class="table-responsive">
															<table class="table table-hover table-center mb-0">
																<thead>
																	<tr>
																		<th>S.No</th>
																		<th>Order Date</th>
																		<th>Order Id</th>
																		<th>Transaction Id</th>
																		<th>Paid Amount</th>
																		<th>Bonus</th>
																		<th>Status</th>
																	</tr>
																</thead>
																<tbody>
																    <?php 
																        $sno = 1;
                    											        $sql = "SELECT * FROM buypack_master WHERE user_id = '$user_id' ORDER BY buy_id DESC" ;
                    											        $res = $config->query($sql);
                    											        while($s_row = $res->fetch_assoc()){
                    											            $status = $s_row['buy_status'];
                    											            $order_id = $s_row['buy_id'];
                    											            if(strlen($order_id) == 1){
                    											                $order = 'AEU00'.$order_id;
                    											            }else if(strlen($order_id) == 2){
                    											                $order = 'AEU0'.$order_id;
                    											            }else{
                    											                $order = 'AEU'.$order_id;
                    											            }
                    											    ?>
																	<tr>
																		<td><?= $sno; ?></td>
																		<td><?= date('d-m-Y',strtotime($s_row['buy_on'])); ?></td>
																		<td><?= $order ?></td>
																		<td><?= $s_row['transaction_id']; ?></td>
																		<td><?= $s_row['buy_amount']; ?></td>
																		<td><?= $s_row['add_on']; ?></td>
																		<td>
																		    <?php
																		        if($status == 2){
																		            $o_status = "Success" ;
																		            $btn = "success" ;
																		        }else if($status == 1){
																		            $o_status = "Pending" ;
																		            $btn = "warning" ;
																		        }else{
																		            $o_status = "Failed" ;
																		            $btn = "danger" ;
																		        }
																		    ?>
																			<div class="table-action">
																				<a href="javascript:void(0);" class="btn btn-sm bg-<?= $btn; ?>-light"><?= $o_status; ?></a>
																			</div>
																		</td>
																	</tr>
																	<?php $sno++; } ?>
																</tbody>
															</table>		
														</div>
													</div>
												</div>
											</div>
											<!-- /Upcoming Appointment Tab -->
									   
											
										</div>
									</div>
								</div>
							</div>							
						</div>
					</div>

				</div>

		    </div>		
			<!-- /Page Content -->
			<!-- Footer -->
		    <?php include "footer.php" ; ?>
			<!-- /Footer -->
		   
		</div>
		<!-- /Main Wrapper -->
	    <!-- Appointment Details Modal -->
		<div class="modal fade custom-modal" id="buypack">
			<div class="modal-dialog modal-dialog-centered">
				<div class="modal-content">
					<div class="modal-header">
						<h5 class="modal-title">Topup Wallet</h5>
						<button type="button" class="close" data-dismiss="modal" aria-label="Close">
							<span aria-hidden="true">&times;</span>
						</button>
					</div>
					<div class="modal-body">
						<form action="payment.php" method="POST">
						    <div class="row">
						        <div class="col-md-12 mb-3">
						            <label class="form-label">Email</label>
						            <input type="email" class="form-control" name="email" value="<?= $email ?>" readonly>
						        </div>
						        <div class="col-md-12 mb-3">
						            <label class="form-label">Phone</label>
						            <input type="number" class="form-control" name="phone" value="<?= $phone ?>" readonly>
						        </div>
						        <div class="col-md-12 mb-3">
						            <label class="form-label" >Topup Amount</label>
						            <input type="number" class="form-control" name="amount" min="" max="" step="0.01" required >
						            <input type="hidden" name="purpose" value="Package Purchase" >
						            <input type="hidden" name="name" value="<?= $username ?>" >
						            <input type="hidden" name="bid" value="<?= $user_id ?>" >
						            <input type="hidden" name="type" value="1" >
						        </div>
						        <div class="col-md-12 d-flex justify-content-end">
						            <input type="submit" name="pay" class="btn btn-info" value="Pay">
						        </div>
						    </div>
						</form>
					</div>
				</div>
			</div>
		</div>
		<!--<div class="modal fade custom-modal" id="buypack">-->
		<!--	<div class="modal-dialog modal-dialog-centered">-->
		<!--		<div class="modal-content">-->
		<!--			<div class="modal-header">-->
		<!--				<h5 class="modal-title">Scan To Pay</h5>-->
		<!--				<button type="button" class="close" data-dismiss="modal" aria-label="Close">-->
		<!--					<span aria-hidden="true">&times;</span>-->
		<!--				</button>-->
		<!--			</div>-->
		<!--			<div class="modal-body">-->
		<!--				<ul class="info-details">-->
						    
		<!--					<li>-->
		<!--						<div class="details-header">-->
		<!--							<div class="row">-->
		<!--								<div class="col-md-12">-->
		<!--								    <img class="qrcode img-fluid" src="assets/img/qrcode/qrcode.jpg" alt="payment QR-Code">-->
		<!--								</div>-->
		<!--							</div>-->
		<!--						</div>-->
		<!--					</li>-->
		<!--				</ul>-->
		<!--			</div>-->
		<!--		</div>-->
		<!--	</div>-->
		<!--</div>-->
		<!-- /Appointment Details Modal -->

		<!-- jQuery -->
		<script src="assets/js/jquery.min.js"></script>
		
		<!-- Bootstrap Core JS -->
		<script src="assets/js/popper.min.js"></script>
		<script src="assets/js/bootstrap.min.js"></script>
		
		<!-- Sticky Sidebar JS -->
        <script src="assets/plugins/theia-sticky-sidebar/ResizeSensor.js"></script>
        <script src="assets/plugins/theia-sticky-sidebar/theia-sticky-sidebar.js"></script>
		
		<!-- Custom JS -->
		<script src="assets/js/script.js"></script>
		
		<script>
            $('.request').on('click', function() {
                // let rid = $(this).val();
                let urid = <?php echo $_SESSION['user_id']; ?>;
                let ticket = <?php echo rand(999999,111111); ?>;
                swal({
                    title: "Request to activate package",
                    text: "Enter your transaction id",
                    content: "input",
                    icon: "info",
                    buttons: true,
                    dangerMode: true,
                }).then((value) => {
                    if(value) {
                        $.ajax({
                            type: "POST",
                            url: "order_confirm.php",
                            data: {urid:urid,ticket:ticket,tran_id:value},
                            success: function(data){
                                swal({
                                    title: "Your ticket "+ticket, 
                                    text: "Our team will contact you soon.If you have any emergency contact admin!",
                                    icon: "success",
                                    button: {
                                        className: "agree",
                                    },
                                });
                                $('.agree').on('click', function() {
                                    window.location.href="user_wallet.php";
                                });
                            }
                        });
                  } else {
                    swal("Request Cancelled.",{
                        icon: "error",
                    });
                  }
                });
            });
            
		</script>
		<script>
    		<?php if(isset($_SESSION['check']) && !empty($_SESSION['check'])) { ?>
    		    swal({
                    title: "<?= $_SESSION['check'] ?>", 
                    text: "",
                    icon: "<?= $_SESSION['alert'] ?>",
                    button: {
                        className: "agree",
                    },
                });
            <?php unset($_SESSION['check']) ; } ?>
        </script>

	</body>

<!-- doccure/my-patients.html  30 Nov 2019 04:12:09 GMT -->
</html>



