<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='index.php'; </script>";
 return;
}
include("../opendb.php");
?>
<html>
    <head>
<link rel="stylesheet" href="../css/form.css" type="text/css" />
<link type="text/css" href="../jquery/jquery-ui.min.css" rel="stylesheet" />	
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript" src="../cal/jquery-ui1.js"></script>
<script type="text/javascript" src="../jquery/jquery-1.7.min.js"></script>
<script type="text/javascript" src="../jquery/jquery-ui.min.js"></script>
<script type="text/javascript" src="../jquery/jquery.jqEasyCharCounter.min.js"></script>
<script type="text/javascript">

$(function() {

    $("#fr_date").datepicker({
	dateFormat: "yy-mm-dd"
   });
 $("#to_date").datepicker({
	dateFormat: "yy-mm-dd"
   });
 });
  </script>

</head>
<body>
<form method='post'><center><table border=1 class=report style="width: 50px;">
<tr><td align=center colspan=2><h3 >Expense Budget And Target Report</h3></td></tr>
<tr><td>FROM</td><td>To</td></tr>
<tr><td align='center'><input type='text'  readonly name='frmdt' value='2017-04-01' id='fr_date'></td><td align=center><input type=text readonly name=todt id='to_date' value=<? echo date('Y-m-d')?>></td></tr>
<tr><td colspan=2 align=center ><input type=submit name=btn value=Show></td></tr>

</table>
</form>
<?
$btn=$_REQUEST['btn'];
$frmdt=$_REQUEST['frmdt'];
$todt=$_REQUEST['todt'];
if($btn)
{
?>
<center>
    
<table cellspacing=1 cellpadding=1 border=1 class='report'  width=50%>
<tr><hr><td align=center colspan=4><h3 >Expense Budget And Target Report</h3></td></hr></tr>
<tr><td>No:</td><td>Exp Head</td><td >Target</td><td>Exp Amt</td></hr></tr>
<?
$i=1;
$query=mysqli_query($db,"select head,target from brtagetexp where brcode='$brcode' ");
//echo "select distinct invno,invdate,invtype,disc,clamt from warspareinvoice where brcode='$brcode'";
$budtot=0;
$exptot=0;
//print "<table>";
while($row1=mysqli_fetch_array($query))
{
    $query1=mysqli_query($db,"select sum(dramt) from journal2 where  brcode='$brcode' and partic='$row1[0]' and date>='$frmdt' and date<='$todt'");
    $row12=mysqli_fetch_array($query1);
    $budtot+=$row1[1];
    print "<tr><td>$i</td><td width 30>$row1[0]</td><td>$row1[1]</td>";
    if($row12[0]!=0)
    {
         print"<td>$row12[0]</td>";
$exptot+=$row12[0];
       
    }
    else
    {
         print "<td>0</td>";
       }
    
    print"</tr>";
    	$i++;
}
print"<tr bgcolor='lightsteelblue'><td></td><b><td align=right><b> Total</td><td><b>$budtot</td><td><b>$exptot</td></tr>";
//print "</table>";
}
//print "</table>";
?>
</table>
</body>
</html>