<? 
session_start();
if(isset($_SESSION['ses_name']))
{
$user=$_SESSION['ses_name'];
}

include("include/config.php");
require_once "include/Database_functions.php";
$sqlObj=new sqlclass();

$img_hr="images/menu4.jpg";
$img_acc="images/menu3-o.jpg";
?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Brothers - ERP</title>
<link href="style/style.css" rel="stylesheet" type="text/css" />

<script language="javascript">
var path="<?=$lnk;?>";
function getXMLHTTP()
	 { //fuction to return the xml http object
	var xmlhttp=false;	
		try
		{
		xmlhttp=new XMLHttpRequest();
		}
		catch(e)	
		{		
			try{			
				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
				}
			catch(e)
			{
				try
				{
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e1)
				{
				xmlhttp=false;
				}
			}
		}
	return xmlhttp;
	}   
function Search()
{  
	var billno= document.search_frm.bill_no.value;
	var strURL=path+"ajax/search_account.php?billno="+billno;
	var req = getXMLHTTP();
   if (req)
   {
     req.onreadystatechange = function()
     {
		 
			if ((req.readyState == 0)||(req.readyState == 1)||(req.readyState == 2)||(req.readyState == 3))
      		{
			//document.getElementById('order').innerHTML='<div align="center"><img src="'+path+'images/ajax_loader.gif"/></div>';
			//document.getElementById('Cakeorder').innerHTML='<div align="center"><img src="'+path+'images/ajax_loader.gif"/></div>';
			}
		 
		 
      if (req.readyState == 4)
      {
	 // only if "OK"
	 	if (req.status == 200)
	 	{ 
	   document.getElementById('list').innerHTML=req.responseText;
	//	document.getElementById('Cakeorder').innerHTML=req.responseText;
	 	}
	  else 
	 	{
   	   alert("There was a problem while using XMLHTTP:\n" + req.statusText);

	 }
     }
     }
   req.open("GET", strURL, true);
   req.send(null);
   }
}

function Searchdate()
{  
	var fday  = document.search_frm.dd.value;
	var fmon  = document.search_frm.mon.value;
	var fyear = document.search_frm.yr.value;

	var fday1  = document.search_frm.dd1.value;
	var fmon1 = document.search_frm.mon1.value;
	var fyear1 = document.search_frm.yr1.value;
	var strURL=path+"search_account_date.php?fday="+fday+"&fmon="+fmon+"&fyear="+fyear+"&fday1="+fday1+"&fmon1="+fmon1+"&fyear1="+fyear1;
	
	var req = getXMLHTTP();
   if (req)
   {
     req.onreadystatechange = function()
     {
		 
			if ((req.readyState == 0)||(req.readyState == 1)||(req.readyState == 2)||(req.readyState == 3))
      		{
			//document.getElementById('order').innerHTML='<div align="center"><img src="'+path+'images/ajax_loader.gif"/></div>';
			//document.getElementById('Cakeorder').innerHTML='<div align="center"><img src="'+path+'images/ajax_loader.gif"/></div>';
			}
		 
		 
      if (req.readyState == 4)
      {
	 // only if "OK"
	 	if (req.status == 200)
	 	{ 
	   document.getElementById('list').innerHTML=req.responseText;
	//	document.getElementById('Cakeorder').innerHTML=req.responseText;
	 	}
	  else 
	 	{
   	   alert("There was a problem while using XMLHTTP:\n" + req.statusText);

	 }
     }
     }
   req.open("GET", strURL, true);
   req.send(null);
   }
}
</script>
<script>
function balance(i)
{
var rec=document.getElementById('rec_amnt'+i).value;
var amnt=document.getElementById('amnt'+i).value;
var result=parseFloat(amnt) - parseFloat(rec);

document.getElementById('amnt_pend'+i).value=result;
}

function status(i)
{
	var sl=document.getElementById('sel'+i).value;
	var amnt=document.getElementById('amnt'+i).value;
	var rec=document.getElementById('rec_amnt'+i).value;
	var bill=document.getElementById('bill'+i).value;
	var id=document.getElementById('id'+i).value;
	var client=document.getElementById('client'+i).value;
	
	if(sl == "")
	{
		alert("Select Status");
		return false;
	}	
	if(sl == "not paid")
	{
		alert("Select Status");
		return false;
	}
	if(rec == "")
	{
		alert("Enter Recieved Amount");
		return false;
	}
	else
	{
	location.href="get_reciept.php?sl="+sl+"&rec="+rec+"&bill="+bill+"&id="+id+"&amnt="+amnt+"&client="+client;
	}
}
</script>
</head>
<body>
<div id="main_div">
<? include("header.php");?>

<div style="width:1024px; float:left; clear:none">
  <div id="matter_center_in">
  <form name="search_frm" id="search_frm" method="post" action="accounts.php" >
    <table width="98%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="361"></td>
        <td width="148"><table><tr><td>From:</td><td>
	<select class="select" name="dd" style="max-width:50px;">
	 <option value="" selected="selected" >Dat</option>
	<? for($i=1;$i<31;$i++){
	if($i<10)
	$i='0'.$i;
	?>
     <option value="<?php echo $i;?>"><?php echo $i;?></option>
	<? }?>
    </select>
	</td><td><select class="select" name="mon" style="max-width:50px;">
	 <option value="" selected="selected"  >Mon</option>
	<? for($i=1;$i<=12;$i++){
	if($i==1)$j='Jan';if($i==2)$j='Feb';if($i==3)$j='Mar';if($i==4)$j='Apr';if($i==5)$j='May';if($i==6)$j='Jun';
	if($i==7)$j='Jul';if($i==8)$j='Aug';if($i==9)$j='Oct';if($i==10)$j='Sep';if($i==11)$j='Nov';if($i==12)$j='Dec';
	?>
     <option value="<?php echo $i;?>"><?php echo $j;?></option>
	<? }?>
    </select>
	</td><td>
	<select class="select" name="yr" style="max-width:50px;">
	 <option value="" selected="selected" >Yr</option>
	<? for($i=1;$i<13;$i++){
	if($i<10)
	$i='0'.$i;
	?>
     <option value="<?php echo $i;?>"><?php echo $i;?></option>
	<? }?>
    </select>
	
	</td></tr></table></td>
        <td width="145"><table><tr><td width="17">To:</td>
		<td width="100">
	<select class="select" name="dd1" style="max-width:50px;">
	 <option value="" selected="selected" >Dat</option>
	<? for($i=1;$i<31;$i++){
	if($i<10)
	$i='0'.$i;
	?>
     <option value="<?php echo $i;?>"><?php echo $i;?></option>
	<? }?>
    </select>
	</td><td width="100"><select class="select" name="mon1" style="max-width:50px;">
	 <option value="" selected="selected"  >Mon</option>
	<? for($i=1;$i<=12;$i++){
	if($i==1)$j='Jan';if($i==2)$j='Feb';if($i==3)$j='Mar';if($i==4)$j='Apr';if($i==5)$j='May';if($i==6)$j='Jun';
	if($i==7)$j='Jul';if($i==8)$j='Aug';if($i==9)$j='Oct';if($i==10)$j='Sep';if($i==11)$j='Nov';if($i==12)$j='Dec';
	?>
     <option value="<?php echo $i;?>"><?php echo $j;?></option>
	<? }?>
    </select>
	</td><td width="100">
	<select class="select" name="yr1" style="max-width:50px;">
	 <option value="" selected="selected" >Yr</option>
	<? for($i=1;$i<13;$i++){
	if($i<10)
	$i='0'.$i;
	?>
     <option value="<?php echo $i;?>"><?php echo $i;?></option>
	<? }?>
    </select>
	
	</td><td><input type="button" value="Search" onclick="Searchdate()" /></td>
	</tr></table></td>
        <td width="84"></td>
        <td width="144"><input type="text" name="bill_no" /></td>
        <td width="98" align="center"><input type="button" value="search" onclick="Search();" /></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td colspan="2">&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
    </table>
	</form>
	<div id="list">
    <table width="98%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <th width="8%" align="left" valign="middle">Bill No</th>
      <th width="6%" align="left" valign="middle">Date</th>
    <th width="9%" align="left" valign="middle">Tax</th>
      <th width="17%" align="left" valign="middle">Amount Payabale</th>
      <th width="9%" align="left" valign="middle">Received</th>
      <th width="8%" align="left" valign="middle">Pending</th>
      <th width="9%" align="left" valign="middle">Due date</th>
      <th width="4%" align="left" valign="middle">&nbsp;</th>
      <th width="5%">&nbsp;</th>
        </tr>

<?php
$i=1;
$array=mysql_query("select * from tbl_bill_amnt order by bill_no asc");
while($res=mysql_fetch_array($array))
{
?>	
    <tr>
      <td class="tr_td"><?php echo $res['bill_no']; ?></td>
      <td class="tr_td"><?php echo $res['date'];?></td>
      <td class="tr_td"><?php echo $res['tax'];?></td>
      <td class="tr_td"><input type="hidden" name="bill" id="bill<?=$i?>" value="<?php echo $res['bill_no']; ?>" />
	  <input type="hidden" name="id" id="id<?=$i?>" value="<?php echo $res['id']; ?>" />
	  <input type="hidden" name="amnt" id="amnt<?=$i?>" value="<?php echo $res['grand_total'];?>"/><?php echo $res['grand_total'];?></td>
      <td class="tr_td"><input type="text" name="rec_amnt" id="rec_amnt<?=$i?>" value="<?=$res['recieved_amnt']; ?>" onchange="balance('<?=$i?>');" /></td>
	  <td class="tr_td"><input type="text" name="amnt_pend" id="amnt_pend<?=$i?>"  readonly="" value="<?=$res['pending_amnt'];?>"/></td>
	 <td class="tr_td tr_td_r"><input type="text" value="<?php print date('Y-m-d');?>" /> </td>
      <td align="center" class="tr_td">
	  <select name="status" id="sel<?=$i?>" onchange="status('<?=$i?>');">
	  <option value="" selected="selected">--Select--</option>
	  <option value="paid">Paid</option>
	  <option value="not paid">Not Paid</option>
	  <option value="part paid">Partially Paid</option>
	  </select>
	  <input type="hidden" name="client" id="client<?=$i?>" value="<?php echo $res['client']; ?>" />
 </td>
	   <td align="center" class="tr_td_r" >
	  <a href="delete_bill.php?id=<?php echo $res['id']; ?>&bill=<?php echo $res['bill_no']; ?>"><img src="images/icon1.jpg" width="21" height="21" /></a></td>
    </tr>
<?php
$i++;
}
?>      </table>
</div>
<? 
include("bottom_footer.php");?>
</div>

<?php include("footer.php");?>

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