<?php  error_reporting(0);
$PageSecurity = 3;
 	$modid=$_REQUEST['modid'];
	$frmid=$_REQUEST['frmid'];
	$rurl="&modid=".$modid."&frmid=".$frmid;
	   $cnp=$_REQUEST['cnp'];
	//echo $_SERVER['PHP_SELF'];
 include ('includes/session.inc');
  include ('includes/function_lib.php');
 global $db;
   echo '<link href="'.$rootpath. '/css/'. $_SESSION['Theme'] .'/default.css" rel="stylesheet" type="text/css" />';
 if($_REQUEST['id']=='')
	  $_SESSION['ACGCurrentREF']=$_SERVER['HTTP_REFERER'];
   
   //echo  $_SESSION['ACGCurrentREF'];
  $GETAccountLedgerDetails="SELECT AccountsID,AccountName ,   UnderGroup    FROM accountledger  where AccountsID='".$cnp."' ";
  	$Result_Ledtails=DB_query($GETAccountLedgerDetails,$db);
	$RowLedtails=DB_fetch_array($Result_Ledtails);
 	$AccountName=$RowLedtails['AccountName'];
 	$UnderGroup=$RowLedtails['UnderGroup'];
	 
	
	  
 ?><center><h2><?php echo $fromtitle=  $s->getField('voucher_master','VoucherType',$_REQUEST['VPrefix'],'GroupName');?></h2></center>
 <?php 
   if($_REQUEST['id']!='')
   {
	$query1="select  * from purchase_billbook where id='".$_REQUEST['id']."'";
	$result1=DB_query($query1,$db);
	$myrow1=DB_fetch_array($result1) ;
	$billno=$myrow['bill'];
	$bill_date=$myrow1['bill_date'];
	$grand_total=$myrow1['grand_total'];
	$pending_amount=$myrow1['pending_amount'];
	$billno=$myrow1['bill'];
		 
   }
   if($_REQUEST['Submit'])
   {
    $adjustment=$_REQUEST['adjust'];
	$dataArray['pending_amount']=$_REQUEST['grand_total']-$adjustment;
	$dataArray['bill']=$_REQUEST['billno'];
 	$cond="id='".$_REQUEST['id']."'";
	$s->RecordEdit('purchase_billbook', $dataArray, $cond);
	
	 $data['purchase_billbookid']=$_REQUEST['id'];
	 $data['grand_total']=$_REQUEST['grand_total'];
	 $data['adjustment']=$_REQUEST['adjustment'];
	 $data['pending_amount']=$_REQUEST['grand_total']-$adjustment;
	 $data['posted_date']=date('Y-m-d');
	 $s->RecordInsert('account_purchase_billbook', $data );
   ?>
   	<script language='javascript'>
  	opener.window.location="<?php  echo $_SESSION['ACGCurrentREF'];?>&amount=<?php echo $adjustment;?>&cnp=<?php  echo $cnp?>";self.close(); 
	</script>

   <?php 
   
   }
 ?>
 <form action="" method="post">
 
 <table width="100%" border="1">
  <tr>
    <td>Bill No &nbsp;</td>
    <td>Bill Date</td>
    <td>Pend. Amount </td><td>Adjust. Amount </td><td>&nbsp; </td>
  </tr>
  <tr>
    <td>
		
		 
	<input name="billno" type="text"  value="<?php echo $billno ?>"/></td>
    <td><input name="bill_date" type="text" value="<?php echo $bill_date ?>"/></td>
    <td><input name="grand_total" type="grand_total"  value="<?php echo $pending_amount ?>" /></td>
	 <td><input name="adjust" type="text"  /></td> <td><input name="Submit" type="submit" value="Go" /></td>
  </tr>
</table>
</form>
 
 <table width="100%" border="1">
  <tr>
    <th>Bill Now </th>
    <th>Bill Date </th>
    <th>Amount </th><th>Pending Amount</th><th></th>
  </tr>
<?php   echo $query="select S1.vendor_code,s2.*  from suppliers S1,purchase_billbook S2  where 
	 S1.vendor_code=S2.vendor  and S1.vendor_name='".$AccountName."' and S1.account_group='".$UnderGroup."'";
    	$result=DB_query($query,$db);
		$i=1;
		 
	 	if(DB_num_rows($result)>0)
		{
	 		while($myrow=DB_fetch_array($result))
			{
			  if($myrow['pending_amount']!=0){
			?>
    <tr><td><?php  echo $myrow['bill']?></td>
    <td><?php  echo $myrow['bill_date']?></td>
    <td><?php  echo $myrow['grand_total']?></td>
	<td><?php  
	if($myrow['bill_status']=='Pending' && $myrow['bill_status']=='0.00')
	echo $myrow['grand_total'];
	else
	echo $myrow['pending_amount'];?></td>
	<td><a href="<?php echo $_SERVER['REQUEST_URI'].'&id='.$myrow['id']?>">PayAmount</a></td>
  </tr>
  <?php }} }  ?>
</table>

