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


								$totalvisafee=0;
							  	$totalservicefee=0;
							  	$totalbankfee=0;

								$sql = "";

								if(isset($_REQUEST['date1']) && $_REQUEST['date2']!=NULL && $_REQUEST['user']!=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));

									//$sql="select * from qcareer where apply_date between '".$date1."' AND '".$date2."'";
									
									if($_REQUEST['user']==0){

						        		$sql = "select * from applicant_table where DATE(created_date) between '".$date1."' AND '".$date2."'";
						        	}
						        	else{
						        		
						        		$sql = "select * from applicant_table where takenby ='$_REQUEST[user]' AND DATE(created_date) between '".$date1."' AND '".$date2."'";

						        	}

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

						            $printtitle="Daily User Report ".get_session_user_name($_REQUEST["user"],$con)." (Date: ".date('d-m-Y', strtotime($date1))." - ".date('d-m-Y', strtotime($date2)).")"; 
						        }

						        elseif($_REQUEST['date2']==NULL && $_REQUEST['user']!=NULL) {

						        	

						        	if($_REQUEST['user']==0){

						        		$sql = "select * from applicant_table";
						        	}
						        	else{
						        		
						        		$sql="select * from applicant_table WHERE takenby ='$_REQUEST[user]'";

						        	}

									$result = mysqli_query($con,$sql);

									$printtitle="Daily User Report ".get_session_user_name($_REQUEST["user"],$con)." (Date: ".$dt->format('d-m-Y').")";
									
						        }

						        else {

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

									$result = mysqli_query($con,$sql);

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

						        //echo $sql;
						        echo $printtitle;
								
								?>
								
							</div>
						</div>
						<div class="portlet-body">
							<div class="table-toolbar">
								<div class="row filterbox">
									<form class="form-inline col-md-12" action="report_daily_user.php" method="post">
									<div class="col-md-3">
										Select User : <select name="user" class="form-control" required>
									  	<option value=""> - Select -</option>
									  	<option value="0"> All </option>
								
										<?php    
				                            $urs = mysqli_query($con,"select u_id, name from adminusers order by name ASC");
		                            		while($urow=mysqli_fetch_array($urs)){ 
		                                
		                                 	  	echo "<option value=".$urow["u_id"]."> ".$urow["name"]." </option>";
											  	
											} 
										?>	
									</select>	
									</div>
									<div class="col-md-9">										
											Select Date Range : <div class="input-group input-large date-picker input-daterange" style="" 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>
					                       
					                        	 <button class="btn green"> Search </button>
					                     			

									</div>
									</form>
								</div>
							</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%">Taken By</th>
                                            <th style="width:10%">Visa Category</th>
                                            <th style="width:10%">Visa Type</th>                                           
                                            <th style="width:10%">Application Date</th>
                                            <th style="width:10%">Passport No</th>
                                            <th style="width:10%">DoB</th>
                                            <th style="width:10%">Nationality</th>
                                            <th style="width:10%">Visa Fee</th>
                                            <th style="width:10%">Service Charge</th>
                                            <th style="width:10%">Bank Charge</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 get_session_user_name($row['takenby'],$con);?></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 date('d-m-Y', strtotime(substr($row['created_date'], 0, 10)));?></td>
								<td><?php echo $row['passport_no'];?></td>
								<td><?php echo date('d-m-Y', strtotime($row['birth_date']));?></td>
								<td><?php echo $row['nationality'];?></td>
								<td>
									<?php echo number_format(get_visa_fee($row['visa_type'],$con),2);
										  $totalvisafee=$totalvisafee+get_visa_fee($row['visa_type'],$con); ?>
								</td>
								<td>
									<?php if(get_visa_fee($row['visa_type'],$con)!=0){
									    echo number_format(get_service_fee($con),2);
										$totalservicefee=$totalservicefee+get_service_fee($con);
									}
										else echo number_format(0,2);?>
								</td>
								<td><?php if(get_visa_fee($row['visa_type'],$con)!=0){
								    echo number_format(get_bank_fee($con),2);
									$totalbankfee=$totalbankfee+get_bank_fee($con);
								}
										else echo number_format(0,2);?>
								</td>
															
							</tr>
							</tbody>
							<tfoor>


							<?php }	
							echo "<tr class='odd gradeX'>";
                                                                  
                                echo "<td></td>";                              

                                echo "<td></td>";

                                echo "<td></td>";

                                echo "<td></td>";

                                echo "<td></td>";  
                                echo "<td></td>";   

                                echo "<td></td>";

                                echo "<td></td>";

                                echo "<td></td>";

                                echo "<td><b>Total</b></td>";

                                echo "<td>".number_format($totalvisafee,2)."</td>";

                                echo "<td>".number_format($totalservicefee,2)."</td>";

                                echo "<td>".number_format($totalbankfee,2)."</td>";                                  

                                echo "</tr>";

                                ?>
							</tfoor>
							</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">

$( document ).ready(function() {	
	$('#sample_2').DataTable({
		
		"pageLength": -1,
        "paging": false,
        "info": false,
        "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>
