<?php
include ('../ro_head.php'); 
isauth_have("Document report");
?>
<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>

<style type="text/css">
	h3{
		background-color: #c6deef;
		padding: 10px 0px 10px 20px;
		font-size: 18px;
	}
.table-scrollable {
    overflow-x: initial;
    overflow-y: initial;
    }
.backcol{
	background: #ececec;
}
tbody{
	font-size: 12px;
}
table.dataTable thead th {
    font-size: 12px;
}    
</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>
								<?php 

                                $_REQUEST['date1']=substr($_REQUEST["dates"], 0, 10);
                                $_REQUEST['date2']=substr($_REQUEST["dates"], -10);
                                
								$totalvisafee=0;
							  	$totalservicefee=0;
							  	$totalbankfee=0;

								$sql = "";

								if(isset($_REQUEST['date1']) && $_REQUEST['date2']!=NULL && $_REQUEST['location']!=NULL) {  //// both location and date

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

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

									if($_REQUEST['location']!=0) {

										$sql = "select * from applicant_table where deliverycenter='$_REQUEST[location]' AND DATE(created_date) between '".$date1."' AND '".$date2."'";

										$printtitle="Ageing Report for ".get_deliverycenter_name($_REQUEST['location'], $con)." (Date: ".date('d-m-Y', strtotime($date1))." - ".date('d-m-Y', strtotime($date2)).")"; 

									}
									else{

										$sql = "select * from applicant_table where DATE(created_date) between '".$date1."' AND '".$date2."'";

										$printtitle="Ageing Report for All Location (Date: ".date('d-m-Y', strtotime($date1))." - ".date('d-m-Y', strtotime($date2)).")"; 
									}					           

						           
						        }

						        elseif($_REQUEST['date1']==NULL && $_REQUEST['date2']==NULL && $_REQUEST['location']!=NULL) { //// only location


						        	if($_REQUEST['location']!=0) { 

										$sql = "select * from applicant_table where deliverycenter='$_REQUEST[location]'";
										$printtitle="Ageing Report for ".get_deliverycenter_name($_REQUEST['location'], $con); 
									}
									else { 

										$sql = "select * from applicant_table";
										$printtitle="Ageing Report for All Location"; 
									}
						        }


						        else {

						         	$sql="select * from applicant_table WHERE DATE(created_date) >= CURDATE() AND DATE(created_date) < CURDATE() + INTERVAL 1 DAY";

									$printtitle="Ageing Report (Date: ".$dt->format('d-m-Y').")";
									
						        }

						        //echo $sql;
						        $result = mysqli_query($con,$sql);
						        echo $printtitle;

								?>
								
							</div>
						</div>
						<div class="portlet-body">
							<div class="table-toolbar">
								<?php get_location_daterange($con,"report_aging.php"); ?>	
							</div>
							<br/><br/>
							<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:05%">Reference No</th>
                                            <th style="width:10%">Applicant Name</th>                                  
                                            <th style="width:10%">Passport No</th>
                                            <th style="width:10%">Email</th>
                                            <th style="width:10%">Phone No</th>
                                            <th style="width:10%">Visa Category</th>
                                            <th style="width:10%">Visa Type</th> 
                                            <th style="width:10%">Location</th>
                                            <!-- <th style="width:10%">Collected Date</th> -->
                                            <th style="width:10%">Standby Days</th>

											<?php    
				       //                      $dhead = mysqli_query($con,"select * from doc_position_table where docp_status=1 order by docp_id ASC");
				       //              		while($dheadrow=mysqli_fetch_array($dhead)){ 
				                        
				       //                   	  	echo "<th style='width:10%'>".$dheadrow["docp_name"]." Date</th>
				       //                   	  		";
											  	
											// } 
											?>
							                
							</tr>



							</thead>
							<tbody>

								<?php

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


								<tr  class='odd gradeX'>
								<td><?php echo $row['v_uid'];?></td>

								<td><?php echo $row['refer_no'];?></td>
								
								<td><?php echo $row['surname']." ".$row['givenname'];?></td>	
							
								<td><?php echo $row['passport_no'];?></td>								

								<?php 

								if($row["parent"]==0){
										
									echo "<td>".$row['email']."</td>";
									echo "<td>".$row['phone_no']."</td>";								
								}
								else{

									$dres = mysqli_query($con,"select phone_no, email from applicant_table where app_id='$row[parent]'");
									$drow=mysqli_fetch_array($dres);
									
									echo "<td>".$drow['email']."</td>";
									echo "<td>".$drow['phone_no']."</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 echo get_deliverycenter_name($row['deliverycenter'], $con);?></td>						

								<?php    
	                        
	                         	  	$sql="select * from docpos_log_table where docpos_log_appid='$row[app_id]' AND docpos_log_dposid='8'";
	                         	  	$dposdate = mysqli_query($con, $sql);
	                    			$dposdaterow=mysqli_fetch_array($dposdate);
	                         	  	
	                         	  	if($dposdaterow["docpos_log_dt"]!=NULL){
	                         	  		
	                         	  		// echo "<td>".date('d-m-Y', strtotime($dposdaterow["docpos_log_dt"]))."</td>";		                         	  	
										
										$date1 = new DateTime(substr($dposdaterow["docpos_log_dt"], 0, 10));
										$date2 = new DateTime();
										 
										$diff = $date2->diff($date1)->format("%a");
										echo "<td style='color:red;'>".$diff."</td>";													
								  	
									}
									else{										                             

                                		echo "<td></td>";

									} 						

							 }	
							

                                ?>

							</tbody>
							</table>
						</div>
					</div>
					<!-- END EXAMPLE TABLE PORTLET-->
				</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>
<script type="text/javascript">
$(function() {

    var start = moment().subtract(1, 'days');
    var end = moment();

    function cb(start, end) {
        $('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
    }

    $('#reportrange').daterangepicker({
        startDate: start,
        endDate: end,
        ranges: {
           'Today': [moment(), moment()],
           'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
           'Last 7 Days': [moment().subtract(6, 'days'), moment()],
           'Last 30 Days': [moment().subtract(29, 'days'), moment()],
           'This Month': [moment().startOf('month'), moment().endOf('month')],
           'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
        }
    }, cb);

    cb(start, end);
    
});

$( document ).ready(function() {	
	$('#sample_2').DataTable({
		
		"pageLength": -1,
        "paging": false,
        "info": true,
        "bSort": true,
        "bFilter": false, 
        "bHeader": false,       
		"dom": 'lBfrtip',
		
		buttons: [
	       {
	           extend: 'pdf',
	           title: '<?php echo $printtitle;?>',	
	           orientation: 'landscape',
	           exportOptions: {
	                //columns: [0,1,2,3,4,5,6,7,8,9]
	            }
	       },
	       {
	           extend: 'excel',
	           title: '<?php echo $printtitle;?>',	
	           orientation: 'landscape',
	           exportOptions: {
	                //columns: [0,1,2,3,4,5,6,7,8,9]
	            }
	       },
	       {
	           extend: 'print',
	           title: '<?php echo $printtitle;?>',	          
	           exportOptions: {
	                //columns: [0,1,2,3,4,5,6,7,8,9]
	            }
	          
	       }
	            
	    ]  
	});	
});

</script>
<!-- END JAVASCRIPTS -->
</body>
<!-- END BODY -->
</html>
