<?php
session_start();
error_reporting(0);
$role=$_SESSION['role'];
$user_name=$_SESSION['user_name'];
	if($_SESSION['user_name']==""){ 
		header('Location: index.php');
	}
	include("database_connection.php");
	$date=date('d-M-Y'); 

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Bankwise:Allocation</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php //title();?>
<link type="text/css" rel="stylesheet" href="Library/css/style-menu.css"   />
<link type="text/css" rel="stylesheet" href="Library/css/style-content.css"   />
<script type="text/javascript" src="Library/js/jquery-1.3.1.min.js" > </script> 
<script type="text/javascript">

    function PrintElem(elem)
    {
        Popup($(elem).html());
    }

    function Popup(data) 
    {
        var mywindow = window.open('', 'Billing Application Dashboard', 'height=650,width=750');
        mywindow.document.write('<html><head><title>Billing Application Dashboard</title>');
        /*optional stylesheet*/ //mywindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />');
        mywindow.document.write('</head><body >');
        mywindow.document.write(data);
        mywindow.document.write('</body></html>');

        mywindow.print();
        mywindow.close();

        return true;
    }

</script>


<style>
.borderHeader{
	border:1px;
	border-style:solid;
	height:73px;
	background-color:white;
}
.centerimage{
	margin-top:20px;
}
.pagename
{
	text-align:center;
	margin-top:-60px;
	color:#8B0000;
}

.airtellogo
{
   margin-top:-60px;

}	
.center {
 text-align: center
}
td { 
	
	height:15px;
}
</style>
<link type="text/css" href="menu/menu_admin.css" rel="stylesheet" />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script language="JavaScript" src="newdate/calendar_us.js"></script>
  <link rel="stylesheet" href="newdate/calendar.css">


</head>
<body>
	<div class="borderHeader">

	<div align=left><img src="images/kmspl.PNG" /></div><div class="pagename"><h2>VIEW ALLOCATION BANK WISE  </h2></div>
</div>
	<?php 
	if(($_SESSION['uniqe_id']=='S'))
	{
	include("menu/menu_superadmin.php");
	}
	elseif(($_SESSION['uniqe_id']=='A'))
	{
	include("menu/menu_admin.php");
	}
	else
	{
	header('Location: index.php');
	}
	?>
	<form method="post" action=" " name="view_fereporttoday" id="view_fereporttoday">
	<?php
	if(isset($_POST['txtsubmit']) && $_POST['txtsubmit']=='REFRESH')
	{
	$_POST['dump_date']='';
	
	}
	if(isset($_POST['txtsubmit']) && $_POST['txtsubmit']=='SEARCH')
 	{  
	$dump_date=$_POST['dump_date'];	
	
	}

	date_default_timezone_set('Asia/Calcutta');
	?>
	<table style="width:100%"   align="center"> 
	<tr>
	<td align="center" style="width:85%;">
	<table  border="1" bgcolor="white" style="width:85%;" class="table table-striped" > 
	<tr>
	<td align="center" ><b>Date</b> &nbsp;<input type ="text" name="dump_date" value="<?php echo $_POST['dump_date'];?>" style="width:100px; height"35px;"; required />
	  <script language="JavaScript">

                        new tcal ({

                            // form name

                            'formname': 'view_fereporttoday',

                            // input name

                            'controlname': 'dump_date'

                        });
                    </script>
		   &nbsp;&nbsp;
 &nbsp;&nbsp;<input type="submit" name="txtsubmit"  value="SEARCH" id="searchbutton" > 
		
			<input type="submit" name="txtsubmit"  value="REFRESH" id="searchbutton"> 
	<!--<table style="width:100%"   align="center"> 
	<tr>
	<td align="center" style="width:85%;">
	<table  border="1" bgcolor="white" style="width:85%;" class="table table-striped" > 
	<tr>
	<td align="center" ><a href="export_fereporttoday.php"><b>Export Data</b></a></td>
	</tr>
	</table>-->
	</td>
	</tr>
	</table>
	<table style="width:100%"   align="center"> 
	<tr>
	<td align="center" style="width:85%;">
	<table  border="1" bgcolor="white" style="width:85%;" class="table table-striped" > 
	<thead>
	<tr height="25">
				<th class="center" ><b>Sr No</b></th>				
				<th class="center"><b>Bank Name</b></th>
				<th class="center"><b>Prev-Allocation</b></th>	
				<th class="center"><b>Allocation</b></th>	
				<th class="center"><b>Diff</b></th>	
				<th class="center"><b>Pending</b></th>
				<th class="center"><b>PDF</b></th>			
				
			</tr>
		 </thead>
		 <tbody>
		<?php		
		if(strlen($dump_date)>0)
		{
		$previousmonth=date('M-Y', strtotime(date('M-Y')." -1 month"));
		$currentmonth=date('M-Y');
		$backmonth=date('M-Y', strtotime(date('M-Y')." -2 month"));
		$time1 = 24*3600*1;
	$dd=explode('-',$dump_date);
	$m=$dd[0];
	$d=$dd[1];
	$y=$dd[2];
	$dt=$d.'-'.$m.'-'.$y;
	$timestamp= strtotime($dt);
	$tm=$timestamp-$time1;
	$prev= date('m-d-Y', $tm);
		$queryr="SELECT distinct(bank_name) FROM `allocation_tbl` WHERE  month in ('$backmonth','$previousmonth','$currentmonth')  order by `bank_name` asc";
		$resultr = MYSQLI_QUERY($conn,$queryr);
	        }	
		else
		{
		}
	
		
	 $j=1;
	while($data=mysqli_fetch_array($resultr)) {
	
	$bank_name=$data['bank_name'];
	$dir=$data['bank_name'];
	if($data['bank_name']=="SBI AUTO LOAN")
	{
	$sqlalloc="select count(id) as num from allocation_tbl where bank_name='$bank_name'  and dump_date = '$dump_date'  and city!='DOCS'" ;
	}
	else
	{
	$sqlalloc="select count(id) as num from allocation_tbl where bank_name='$bank_name'  and dump_date = '$dump_date' " ;
	}
	$resultalloc=mysqli_query($conn,$sqlalloc);
	$dataalloc=mysqli_fetch_array($resultalloc);
	$allocation=$dataalloc[0];	
	$allocationt +=$allocation;
        if($data['bank_name']=="SBI AUTO LOAN")
	{
	$sqlalloc2="select count(id) as num from allocation_tbl where bank_name='$bank_name'  and dump_date = '$prev'  and city!='DOCS'" ;
	}
	else
	{
	$sqlalloc2="select count(id) as num from allocation_tbl where bank_name='$bank_name'  and dump_date = '$prev' " ;
	}
	$resultalloc2=mysqli_query($conn,$sqlalloc2);
	$dataalloc2=mysqli_fetch_array($resultalloc2);
	$allocation2=$dataalloc2[0];	
	$allocation2t +=$allocation2;
	$diff=$allocation-$allocation2;
	$difft +=$diff;
	
	if($data['bank_name']=="SBI AUTO LOAN")
	{
	$sqlpending="select count(id) as num from allocation_tbl where bank_name='$bank_name'  and status='4' and city!='DOCS' " ;
	}
	else
	{
	$sqlpending="select count(id) as num from allocation_tbl where bank_name='$bank_name'  and status='4' " ;
	}
	$resultpending=mysqli_query($conn,$sqlpending);
	$datapending=mysqli_fetch_array($resultpending);
	$pending=$datapending[0];		
	$pendingt +=$pending;
	if($data['bank_name']=="SBI AUTO LOAN")
	{
	$sqlpdf="select count(id) as num from allocation_tbl where bank_name='$bank_name'  and pdf_download='OK' and city!='DOCS' and dump_date = '$dump_date' " ;
	}
	else
	{
	$sqlpdf="select count(id) as num from allocation_tbl where bank_name='$bank_name'  and pdf_download='OK' and dump_date = '$dump_date' " ;
	}
	$resultpdf=mysqli_query($conn,$sqlpdf);
	$datapdf=mysqli_fetch_array($resultpdf);
	$pdf=$datapdf[0];		
	$pdft +=$pdf;
	if($data['bank_name']=="SBI AUTO LOAN")
	{
	$bank_name="SBI";
	}
	else
	{
	$bank_name=$bank_name;
	}
	if($j%2==0)
		 {
		 $color="#FFFAFA";  
		 }
		 else
		 {
		 $color="white";  
 		}
		if($pending>0)
		{
		$bg="#FFA07A";
		}
		else
		{
		$bg="white";
		}
		if($pending2>0)
		{
		$bg2="#FFFF00";
		}
		else
		{
		$bg2="white";
		}
		$allocations=$allocation+$pending;
		if($diff>0)
		{
		$fc="#228B22";
		}
		elseif($diff<0)
		{
		$fc="#FF0000";
		}
		else
		{
		$fc="#000000";
		}
		if($allocations>0)
		{
	?>

<tr  bgcolor=" <?php echo $color;?>" height="15">
<td   align="center"><font size="2"><b><?php echo $j ;?></b></font></td>
<td align="center"><font size="2"><b><?php echo strtoupper($bank_name);?></b></font></td>
<td align="center"><font size="4"><b><?php echo strtoupper($allocation2);?></b></font></td>
<td align="center"><font size="4"><b><?php echo strtoupper($allocation);?></b></font></td>
<td align="center"><font size="4" font color=<?php echo $fc;?> ><b><?php echo strtoupper($diff);?></b></font></td>
<td  align="center"  style="height:10px;"><font size="4" ><a href="" onClick="window.open('bankwisepending.php?id=<?php echo "$dir"; ?>','popup','width=1050,height=500,scrollbars=yes,resizable=no,toolbar=no,directories=no,location=center,menubar=no,status=no,left=100,top=100'); return false"><b><?php echo $pending;?></b></a></font></td>
<td align="center"><font size="4"><b><?php echo strtoupper($pdf);?></b></font></td>

</tr>
<?php
	$j++; } } ?>
<tr >
<td align="center"><font size="2"><b></b></font></td>
<td align="center"><font size="2"><b>Total</b></font></td>
<td align="center"><font size="4"><b><?php echo $allocation2t;?></b></font></td>
<td align="center"><font size="4"><b><?php echo $allocationt;?></b></font></td>
<td align="center"><font size="4"><b><?php echo $difft;?></b></font></td>
<td  align="center" ><font size="4"><b><?php echo $pendingt;?></b></font></td>
<td  align="center" ><font size="4"><b><?php echo $pdft;?></b></font></td>
</tr>
</tbody>
 </table>
</td>
</tr>
</table>

</div>
</body>
</html>			
