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

<!-- <script src="https://code.jquery.com/jquery-3.0.0-alpha1.js"></script> -->

<script type="text/javascript">

$( document ).ready(function() {
	$('table.display').DataTable({

		 "ordering": false,
		 "searching": false,
        "paging": false,
        "info":     false,
		"dom": 'lBfrtip',
		buttons: [
	       {
	           extend: 'pdf',
	           //footer: true,
	           exportOptions: {
	                columns: [0,1,2,3]
	            }
	       },
	       {
	           extend: 'print',
	           exportOptions: {
	                columns: [0,1,2,3]
	            }

	       },
	       {
	           extend: 'excel',
	           exportOptions: {
	                columns: [0,1,2,3]
	            }
	       }
	    ]
	});
});

</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;
    }
 a.dt-button {
    padding: 2px 5px;
 }
div.dt-buttons {
    float: right;
} 
    
</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) {

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

									$var = $_REQUEST['date2'];									
									$date2= date('Y-m-d', strtotime($var));
									
									$fromto="(".date('d-m-Y', strtotime($date1))." - ".date('d-m-Y', strtotime($date2)).")";
									$printtitle="Summary Report for ".$fromto;
								}
								else {
								    $tomorrow = new DateTime('tomorrow');
                                    $date2=$tomorrow->format('Y-m-d');
                                    $date1=$dt->format('Y-m-d');

									$fromto="(".$dt->format('d-m-Y').")";
									$printtitle="Daily Summary Report ".$fromto;
									
						        }
						        
						        echo $printtitle;
								
								?>
								
							</div>
						</div>
						<div class="portlet-body">
							<div class="table-toolbar">

								<div class='col-md-12'>
                                <form class='form-inline col-md-12' action='report_daily_sum_sb.php' method='post'>
                					<b style="float: left; padding: 6px;">Select Date Range:</b>											
                						<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>						
                
                				</form>
                				</div>
				<?php //get_location_dates_list($con,"report_daily_sum.php"); 
						
                                ?>	

							</div>
							
							<!--- table for total summary -->
						
							<table class="table table-striped table-bordered table-hover display" id="sample_1">
							<thead>
							<tr class="backcol">
    				 			<th style="width:10%">Sr No.</th>
    				 			<th style="width:10%">VAC</th>
                                <th style="width:10%">Applicantion Count</th>
                                <th style="width:10%">Service Charge Amount</th>
                                <th style="width:10%">Bank Charge Amount</th>
    			            </tr>
							</thead>
							<tbody>
							<?php
                            ///// get service charge and bank fee /////
                            $sql = "SELECT * FROM `setting_table` order by s_id";
                            $sresult = mysqli_query($con,$sql);
                            while($srow = mysqli_fetch_array($sresult)){
                            
                            	if($srow["setting_name"]=='Service Charge') $sfee=$srow["value"];
                            	if($srow["setting_name"]=='Bank Fee') $bankfee=$srow["value"];
                            }
                            //////////
                            
                            $result = mysqli_query($con,"select deliloc_id, deliloc_name from deli_location_table order by deliloc_name ASC");
                            $i=1;
							while($row = mysqli_fetch_array($result)){
							    
							    $result1 = mysqli_query($con,"select * from applicant_table WHERE deliverycenter='$row[deliloc_id]' AND DATE(created_date) between '".$date1."' AND '".$date2."'");
							    $totalapplicant=mysqli_num_rows($result1);
							    $totalservicefee=0;
							    $totalbankfee=0;
							    while($row1 = mysqli_fetch_array($result1)){
							    
							        if(get_visa_fee($row1["visa_type"],$con)!=0){
							            $totalservicefee=$totalservicefee+$sfee;
							            $totalbankfee=$totalbankfee+$bankfee;
							        }
							    }
							?>
							<tr  class='odd gradeX'>
								<td><?php echo $i++;?></td>
								<td><?php echo $row['deliloc_name'];?></td>
								<td><?php echo $totalapplicant; ?></td>
								<td><?php echo number_format($totalservicefee,2);?></td>
								<td><?php echo number_format($totalbankfee,2);?></td>
							</tr>


							<?php }	?>
							
							</tbody>
							</table>
							
							<div class="row">
							<!--- table for Center wise visa type total summary -->
							<?php
							$dresult = mysqli_query($con,"select deliloc_id, deliloc_name from deli_location_table order by deliloc_name ASC");
							while($drow = mysqli_fetch_array($dresult)){ 
							
							    $grandtotalservicefee=0;
							    $grandtotalbankfee=0;
							    $totalvisaapplicant=0;
							?>
							 <div class="col-md-12">
							<br><br><br>
							<h4>Category wise application count for <?php echo $drow["deliloc_name"]; ?> VAC : <?php echo $fromto ; ?></h4>
							
							<table class="table table-striped table-bordered table-hover display" id="sample_2">
							<thead>
							<tr class="backcol">
    				 			<th style="width:10%">Sr No.</th>
    				 			<th style="width:30%">Visa type</th>
                                <th style="width:25%">No. Of Applications</th>
                                <th style="width:20%">Service Charge Amount</th>
                                <th style="width:20%">Bank Charge Amount</th>
    			            </tr>
							</thead>
							<tbody>
							<?php
                            $result = mysqli_query($con,"select visatype_id, visatype_name from visatype_table order by visatype_name ASC");
                            $i=1;
							while($row = mysqli_fetch_array($result)){
							    
							    $result1 = mysqli_query($con,"select * from applicant_table WHERE visa_type='$row[visatype_id]' AND deliverycenter='$drow[deliloc_id]' AND DATE(created_date) between '".$date1."' AND '".$date2."'");
							    $totalapplicant=mysqli_num_rows($result1);
							    if($totalapplicant!=0){
							    $totalservicefee=0;
							    $totalbankfee=0;
							    while($row1 = mysqli_fetch_array($result1)){
							    
							        if(get_visa_fee($row1["visa_type"],$con)!=0){
							            $totalservicefee=$totalservicefee+$sfee;
							            $totalbankfee=$totalbankfee+$bankfee;
							        }
							    }
							?>
							<tr  class='odd gradeX'>
								<td><?php echo $i++;?></td>
								<td><?php echo get_parent_mainvisatype_name($row['visatype_id'],$con)." ".$row['visatype_name'];?></td>
								<td style="text-align:right;"><?php echo $totalapplicant; $totalvisaapplicant=$totalvisaapplicant+$totalapplicant;?></td>
								<td style="text-align:right;"><?php echo number_format($totalservicefee,2); $grandtotalservicefee=$grandtotalservicefee+$totalservicefee; ?></td>
								<td style="text-align:right;"><?php echo number_format($totalbankfee,2); $grandtotalbankfee=$grandtotalbankfee+$totalbankfee; ?></td>
							</tr>


							<?php } 
							}	?>
							<td></td>
							<td><b>Total</b></td>
							<td style="text-align:right;"><b><?php echo $totalvisaapplicant;?></b></td>
							<td style="text-align:right;"><b><?php echo number_format($grandtotalservicefee,2);?></b></td>
							<td style="text-align:right;"><b><?php echo number_format($grandtotalbankfee,2);?></b></td>
							</tbody>
							</table>
							</div>
							<?php }	?>
							
							</div>
						</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": false,
        "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>
