<?php
include ('../ro_head.php'); 
isauth_have("Application list");
?>
<link href="../assets/css/daterangepicker.css" rel="stylesheet" type="text/css"/>
<link rel="stylesheet" type="text/css" href="../assets/global/plugins/select2/select2.css"/>
<link rel="stylesheet" type="text/css" href="../assets/global/plugins/datatables/plugins/bootstrap/dataTables.bootstrap.css"/>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/r/dt/jq-2.1.4,jszip-2.5.0,pdfmake-0.1.18,dt-1.10.9,af-2.0.0,b-1.0.3,b-colvis-1.0.3,b-html5-1.0.3,b-print-1.0.3,se-1.0.1/datatables.min.css"/>
<script type="text/javascript" src="https://cdn.datatables.net/r/dt/jq-2.1.4,jszip-2.5.0,pdfmake-0.1.18,dt-1.10.9,af-2.0.0,b-1.0.3,b-colvis-1.0.3,b-html5-1.0.3,b-print-1.0.3,se-1.0.1/datatables.min.js"></script>
<script type="text/javascript">
function myFunction(str) {
            
            if (confirm("Do you want to delete this Applicant with dependants?") == true) {
                window.location = 'application_delete.php?id='+str;
            }
            
        }
</script>

<script type="text/javascript">

$( document ).ready(function() {
	$('#sample_2').DataTable({

		"pageLength": -1,
        "paging": false,
        "info":     false,
		"dom": 'lBfrtip',
		 "order": [[ 0, "desc" ]],
		 //"scrollX": true,
		buttons: [
	       {
	           extend: 'pdf',
	           //footer: true,
	           exportOptions: {
	                columns: [0,1,2,3,4,5,6,7,8]
	            }
	       },
	       {
	           extend: 'print',
	           exportOptions: {
	                columns: [0,1,2,3,4,5,6,7,8]
	            }

	       },
	       {
	           extend: 'excel',
	           exportOptions: {
	                columns: [0,1,2,3,4,5,6,7,8]
	            }
	       }
	    ]
	});
});



$(document).ready(function(){

	$("button#paysubmit").click(function(){

		$.ajax({
			type: "POST",
			url: "paystatus_crud.php",
			data: $('form.feedbackpay').serialize(),
			success: function(message){
				$("#feedbackpay").html(message)
				$("#myModal_autocomplete3").modal('hide');

				location.reload();
			},
			error: function(){
				alert("Error");
			}
		});
	});

	$("button#appstatusupdate").click(function(){

	 	$.ajax({
	 		type: "POST",
	 		url: "docstatus.php",
	 		data: $('form.feedback3').serialize(),
	 		success: function(message){
	 			$("#feedback3").html(message)
	 			$("#myModal_autocomplete3").modal('hide');

	 			location.reload();
	 		},
	 		error: function(){
	 			alert("Error");
	 		}
	 	});
	});


	$("#upstatusModal").on("show.bs.modal", function(e) {
    var link = $(e.relatedTarget);
    $(this).find(".modal-body").load(link.attr("href"));
	});
	
	$("#payModal").on("show.bs.modal", function(e) {
    var link = $(e.relatedTarget);
    $(this).find(".modal-body").load(link.attr("href"));
	});


});

</script>

<style type="text/css">
	h3{
		background-color: #c6deef;
		padding: 10px 0px 10px 20px;
		font-size: 18px;
	}
.table-scrollable {
    overflow-x: initial;
    overflow-y: initial;
    }
</style>
<!-- END PAGE LEVEL STYLES -->

<!-- BEGIN CONTAINER -->
<div class="page-container">
<?php include_once("../ro_sidebar.php"); ?>
    <!-- BEGIN CONTENT -->
	<div class="page-content-wrapper">
		<div class="page-content">


			<!-- BEGIN PAGE HEADER-->

			<!-- END PAGE HEADER-->
			<!-- BEGIN PAGE CONTENT-->
			<div class="row">
				<div class="col-md-12">
					<!-- BEGIN EXAMPLE TABLE PORTLET-->
					<div class="portlet box grey-cascade">
						<div class="portlet-title">
							<div class="caption">
								<i class="fa fa-globe"></i>Application List 
							</div>
						</div>
						<div class="portlet-body">
							<div class="table-toolbar">
								<div class="row">
									<div class="col-md-3">
										<div class="btn-group">
											<a href="newapplication.php"><button id="sample_editable_1_new" class="btn green">
											Add New <i class="fa fa-plus"></i>
											</button></a>
										</div>
									</div>
									<div class="col-md-6">

										<form class="form-inline col-md-12" action="application.php" method="post">
											<div class="input-group input-large date-picker input-daterange" style="float: left;" data-date="10/11/2012" data-date-format="yyyy-mm-dd">
					                            <input type="text" class="form-control" name="date1">
					                            <span class="input-group-addon"> to </span>
					                            <input type="text" class="form-control" name="date2">					                           
					                        </div>
					                        <div class="col-md-2">
					                        	 <button class="btn green"> Search </button>
					                        </div>	
												<!-- 	<input type="text" placeholder="Start Date" class="datepicker form-control input-small input-inline" name="date1">
													- <input type="text" placeholder="End Date" class="datepicker form-control input-small input-inline" name="date2"> -->
													
										</form>

									</div>
									<div class="col-md-3">
										<form name="addproduct" action="application.php" method="post" style="float:right;">

												<input type="text" class="form-control input-inline" style="font-size: 10px; width: 215px;" name="stext" placeholder="Reference no or Passport">
												<button type="submit" class="btn green">Search</button>
										</form>

									</div>
								</div>
							</div>
							<table class="table table-striped table-bordered table-hover" id="sample_2">
							<thead>
							<tr class="backcol">
								<!--<th class="table-checkbox">
									<input type="checkbox" class="group-checkable" data-set="#sample_1 .checkboxes"/>
								</th>-->
								 			
								 			<th style="width:05%">Seq No</th>
								 			 <th style="width:10%">Application Date</th>
								 			<th style="width:10%">Reference No</th>
                                            <th style="width:20%">Applicant Name</th>
                                            <th style="width:10%">Passport No</th>
                                            <th style="width:10%">DoB</th>
                                            <th style="width:10%">Visa Category</th>
                                             <th style="width:10%">Visa Type</th>
                                             <th style="width:05%">Agent Name</th>
                                             <th style="width:05%">Company Name</th>
                                           <th style="width:10%">Current Status</th>
                                           <th style="width:10%">Taken By</th>
                                           <!--  <th style="width:10%">Status</th> -->
                                            <th style="width:05%">Payment(BDT)</th>
                                            <?php if(ismenuauth("List action")==true){ ?>
                                            <th style="width:10%">View detail</th>
                                            <?php } ?>
                                            <?php if(ismenuauth("Update payment status")==true){ ?>			
                                            <th style="width:10%">Update Payment</th>
                                            <?php } ?>
							</tr>



							</thead>
							<tbody>

								<?php							


								$sql = "";

								if(isset($_REQUEST['date1']) && $_REQUEST['date2']!=NULL) {

						            $var = $_REQUEST['date1'];
									$date1= date('Y-m-d', strtotime($var));

									$var = $_REQUEST['date2'];
									//$date = str_replace('/', '-', $var);
									$date2= date('Y-m-d', strtotime($var));

									if($_SESSION["level"]==1){
										$sql = "select * from applicant_table where DATE(created_date) between '".$date1."' AND '".$date2."'";
									}
									else{
										$userid=get_session_user_id($con);
										$sql = "select * from applicant_table where takenby=".$userid." AND DATE(created_date) between '".$date1."' AND '".$date2."'";	
									}
									

									//var_dump($sql) or die();
						            //echo $sql;
						            $result = mysqli_query($con,$sql);
						        }

					
						        elseif(isset($_REQUEST['stext']) && $_REQUEST['stext']!=NULL) {
						        	if($_SESSION["level"]==1){
										$result = mysqli_query($con,"select * from applicant_table WHERE passport_no='$_REQUEST[stext]' OR refer_no='$_REQUEST[stext]'");
									}
									else{
										$userid=get_session_user_id($con);
										$result = mysqli_query($con,"select * from applicant_table WHERE  ( passport_no='$_REQUEST[stext]' OR refer_no='$_REQUEST[stext]')");
									}
									
									
						        }
						        
						        else {
						        	if($_SESSION["level"]==1){
										$result = mysqli_query($con,"select * from applicant_table WHERE DATE(created_date) >= CURDATE() AND DATE(created_date) < CURDATE() + INTERVAL 1 DAY");
									}
									else{
										$userid=get_session_user_id($con);
										$result = mysqli_query($con,"select * from applicant_table WHERE takenby=".$userid." AND DATE(created_date) >= CURDATE() AND DATE(created_date) < CURDATE() + INTERVAL 1 DAY");
									}
									
									
						        }

								while($row = mysqli_fetch_array($result)){
							?>


								<tr  class='odd gradeX'>
								<td><?php echo $row['v_uid'];?></td>
								<td><?php echo date('d-m-Y', strtotime(substr($row['created_date'], 0, 10)));?></td>
								<td><?php echo $row['refer_no'];?></td>
								
								<td>
									<?php echo $row['salu']." ".$row['givenname']." ".$row['surname']."<br/>";
									 	$cresult = mysqli_query($con,"SELECT app_id FROM applicant_table WHERE parent='".$row['app_id']."'");
										$crow=mysqli_num_rows($cresult);
										echo "<span style='font-size: 10px; color: brown;'>".$crow. " Dependent</span>";
									?>
								</td>								
								
								<td><?php echo $row['passport_no'];?></td>
								<td><?php echo date('d-m-Y', strtotime($row['birth_date']));?></td>
								<td><?php echo get_parent_mainvisatype_name($row["visa_type"],$con);?></td>
								<td><?php echo get_visatype_name($row["visa_type"],$con);?></td>
								<td><?php if($row['agent']==2) echo $row['agent_name'];?></td>
								<td><?php if($row['agent']==3) echo $row['agent_name'];?></td>
								<td><?php echo get_position_name($row['doc_position'],$con);?></td>
								<td><?php echo get_session_user_name($row['takenby'],$con);?></td>
								<!-- <td><?php //echo get_app_status_name($row['appstatus'], $con);?></td> -->
											
								<td><?php
                                    	if($row["paystatus"]==0){
                                    	echo "<span style='color:red;'>".number_format($row["total_fee"],2)."</span>";
                                    
                                    }else{
//                                    	echo "<a href='#' class='btn btn-danger btn-xs' onclick='statusFunction(".$row["user_id"].",".$row["status"].")' title='Deactive' data-toggle='tooltip' data-placement='top' data-original-title='Deactive'>Deactive</a>";
                                    	echo "<span style='color:green;'>".number_format($row["total_fee"],2)."</span>";
                                    	//echo "<a href='#' class='btn btn-success btn-xs' onclick='statusFunction(".$row["app_id"].",".$row["pstatus"].")' title='Click to change' data-toggle='tooltip' data-placement='top' data-original-title='Active'>Done : ".$row["total_fee"]." BDT</a>";

                                    }
									?>

								</td>

								<?php if(ismenuauth("List action")==true){ ?>

								<td>
								<div class='btn-group pull-left'>
											<button class='btn dropdown-toggle' data-toggle='dropdown'>Action <i class='fa fa-angle-down'></i>
										 	</button>
											<ul class='dropdown-menu pull-right'>


												<li>
										 			<a href="applicationupdate.php?appid=<?php echo get_parent_id($row['app_id'],$con); ?>">View Details</a>
										 		</li>
										 		<li>
										 			<a href="viewdocuments.php?appid=<?php echo $row['app_id']; ?>">View Documents</a>
										 		</li>
										 		<!-- <li>
										 			<a href="do.php?id=<?php // echo get_parent_id($row['app_id'],$con);  ?>" data-toggle="modal" data-target="#upstatusModal" data-remote="false">Update Status	</a>
												</li> 
												<li>
										 			<a href="paydo.php?id=<?php //echo get_parent_id($row['app_id'],$con);  ?>" data-toggle="modal" data-target="#payModal" data-remote="false">Update Payment Status </a>
												</li> -->
												<li>
										 			<a href="barcode.php?appid=<?php echo $row['app_id'];  ?>" target="_blank">Generate Barcode</a>
												</li>
												<li>
										 			<a href="recieptvisa_print.php?appid=<?php echo get_parent_id($row['app_id'],$con);  ?>" target="_blank">Visa Fee Print Reciept</a>
												</li>
												<li>
										 			<a href="recieptservice_print.php?appid=<?php echo get_parent_id($row['app_id'],$con);  ?>" target="_blank">Service Fee Print Reciept</a>
												</li>
												<li>
										 			<a href="reciept_deposit.php?appid=<?php echo get_parent_id($row['app_id'],$con);  ?>" target="_blank">Deposit Slip Print</a>
												</li>
												<?php if($_SESSION["level"]==1){?>
												<li>
										 			<a href="#" onclick='myFunction("<?php echo $row["app_id"]; ?>")'>Delete</a>
												</li>
												<?php } ?>

										 	</ul>
										 </div>
								</td>
								<?php } ?>
								<?php if(ismenuauth("Update payment status")==true){ ?>
								<td><a href="paydo.php?id=<?php echo get_parent_id($row['app_id'],$con);  ?>" class="btn btn-xs btn-primary" data-toggle="modal" data-target="#payModal" data-remote="false">Update Payment </a>
									<br/><br/><a href="reciept_accounts.php?appid=<?php echo get_parent_id($row['app_id'],$con);  ?>" target="_blank" class="btn btn-xs btn-primary">Print Reciept</a></td>
								<?php } ?>
							</tr>


							<?php

								}
							?>

							</tbody>
							</table>
						</div>
					</div>
					<!-- END EXAMPLE TABLE PORTLET-->
				</div>
			</div>
				</div>
			</div>

	
<!-- Status bootstrap modal example -->
<div class="modal fade" id="payModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Update Payment Status</h4>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" id="paysubmit" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>




			<!-- END PAGE CONTENT-->
		</div>
	</div>
	<!-- END CONTENT -->

</div>
<!-- END CONTAINER -->
<!-- BEGIN FOOTER -->
<?php include_once("../ro_footer.php"); ?>

<!-- END FOOTER -->
<!-- BEGIN JAVASCRIPTS(Load javascripts at bottom, this will reduce page load time) -->
<?php include_once("../ro_js.php"); ?>
<!-- <script src="../assets/global/plugins/jquery.min.js" type="text/javascript"></script> -->

<!-- END CORE PLUGINS -->
<!-- BEGIN PAGE LEVEL PLUGINS -->
<script type="text/javascript" src="../assets/global/plugins/select2/select2.min.js"></script>
<script type="text/javascript" src="../assets/global/plugins/datatables/media/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="../assets/global/plugins/datatables/plugins/bootstrap/dataTables.bootstrap.js"></script>
<script type="text/javascript" src="../assets/global/plugins/bootstrap-datepicker/js/bootstrap-datepicker.min.js"></script>
<!-- END PAGE LEVEL PLUGINS -->
<!-- BEGIN PAGE LEVEL SCRIPTS -->
<script src="../assets/js/table-managed.js" type="text/javascript"></script>
<!-- <script src="../assets/global/plugins/bootstrap-daterangepicker/daterangepicker.min.js" type="text/javascript"></script> -->
<script src="../assets/admin/layout/scripts/components-picker.js"></script>
<script>
jQuery(document).ready(function() {
   Metronic.init(); // init metronic core components
Layout.init(); // init current layout
QuickSidebar.init(); // init quick sidebar
Demo.init(); // init demo features
  // TableManaged.init();
  ComponentsPickers.init();
});
</script>
<!-- END JAVASCRIPTS -->
</body>
<!-- END BODY -->
</html>
