<?php    include('includes/AccountGroupMaster_Class.php');
  $table='cashbankvoucher';
$action=$_REQUEST['action'];
$daction=$_REQUEST['daction'];
$msgErr='';
$status=true;
  
	       $VPrefixName= $s->getField('voucher_master','VoucherType',$_REQUEST['VPrefix'],'VPrefix');;?>
 
<script language="javascript">
function getvocuher(str)
{
 
// document.getElementById("voucher_code").value=str;
   if (str=="")
  {
  document.getElementById("voucher_code").innerHTML="";
  return;
  } 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("voucher_code").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","GetBankPayment_Voucher.php?q="+str,true);
xmlhttp.send();

}
function selectDRCR(str)
{
if(str=='Dr'){
  	 document.getElementById("credit").disabled=true;
      document.getElementById("debit").disabled=false;
  }
 else{
  document.getElementById("debit").disabled=true;
   
    document.getElementById("credit").disabled=false;
   }
}
</script>
<script type="text/javascript">
function showLegder(str)
{
 
  if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  } 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","GetSubLedger.php?q="+str,true);
xmlhttp.send();
}
</script>
	<?php
if($_REQUEST['Save'])
{
 extract($_REQUEST);
	 
	if($BranchID=='000')
	{
	   $msgErr[]='Please Enter BranchID';
	   $status=false;
	}
	 
	 if(empty($voucherdate))
	{
	   $msgErr[]='Please Enter Voucher Date';
	   $status=false;
	}
 	
	if($CaseBankId=='000')
	{
	   $msgErr[]='Please Select CaseBankId';
	   $status=false;
	}
	
	if($ledger_id=='000')
	{
	   $msgErr[]='Please Select Ledger';
	   $status=false;
	}
	
	if($cheque_no=='')
	{
	   $msgErr[]='Please Enter ChequeNo';
	   $status=false;
	}
	if($Amount=='')
	{
	   $msgErr[]='Please Enter Amount';
	   $status=false;
	}
} 
//************************Edit*********************************************** 
if(!$_REQUEST['Save'] &&  $status && $action=='Edit')
{
		$id=$_REQUEST['voucherId'];
		$condition="B.voucherId='".$_REQUEST['TransId']."' and A.voucherMasterId='".$id."'";
	// echo "select * from cashbankvoucher_master A,cashbankvoucher B where $condition ";
		$GetData=DB_query("select * from cashbankvoucher_master A,cashbankvoucher B where $condition ",$db);
		$RowData=DB_fetch_array($GetData);
		$BranchID=$RowData['BranchID'];
		$VoucherNo=$RowData['VoucherNo'];
		$voucher_code=$RowData['voucher_code'];
		$voucherdate=ConvertSQLDate($RowData['VDate']);
		$sub_ledger_id=$RowData['sub_ledger_id'];
		$ledger_id=$RowData['ledger_id'];
		$vendorid=$RowData['vendorid'];
		$clientid=$RowData['clientid'];
		$dr_cr=$RowData['dr_cr'];
		$debit=$RowData['debit'];
		$credit=$RowData['credit'];
		$narration=$RowData['narration'];
		$Amount=$RowData['Amount'];
	   	$CaseBankId=$RowData['CaseBankId'];
		$cheque_no=$RowData['cheque_no'];
 } 
 

if($_REQUEST['Save'] &&  $status && $action=='Edit' && $status)
{
$data_bankvoucher_master['BranchID']=$_REQUEST['BranchID']; 	
$data_bankvoucher_master['VDate']=FormatDateForSQL($_REQUEST['voucherdate']);;
$data_bankvoucher_master['VoucherNo']=$_REQUEST['VoucherNo'];
$data_bankvoucher_master['voucher_code']=$_REQUEST['voucher_code'];
$data_bankvoucher_master['CaseBankId']=$_REQUEST['CaseBankId'];
$data_bankvoucher_master['Amount']=$_REQUEST['Amount'];
if($VPrefixName=='CP' ||$VPrefixName=='BP')
{
$data_bankvoucher_master['dr_cr']='Cr';
$data_bankvoucher_master['credit']=$_REQUEST['Amount'];
$data_bankvoucher_master['debit']=0;

}
else{
$data_bankvoucher_master['dr_cr']='Dr';
$data_bankvoucher_master['debit']=$_REQUEST['Amount'];
$data_bankvoucher_master['credit']=0;
}

$data_bankvoucher_master['ModifyDate']=date("Y-m-d");
$data_bankvoucher_master['PreFix']=$_REQUEST['VPrefix'];
	$cond="voucherMasterId='".$_REQUEST['voucherId']."'";
	$UpdateRecord= $s->RecordEdit('cashbankvoucher_master',$data_bankvoucher_master,$cond);
	
 	if($VPrefixName=='CP' ||$VPrefixName=='BP')
	{
		$data1['debit']=$_REQUEST['Amount'];
		$data1['dr_cr']='Dr';
		$data1['credit']=0;
	}
	else{
		$data1['dr_cr']='Cr';
		$data1['credit']=$_REQUEST['Amount'];
		$data1['debit']=0;
	}
 	$data1['TransId']=$_REQUEST['TransId'];
	$data1['cheque_no']=$_REQUEST['cheque_no'];
	$data1['ledger_id']=($_REQUEST['ledger_id']);
	$data1['sub_ledger_id']=$_REQUEST['sub_ledger_id'];
	$data1['vendorid']=$_REQUEST['vendorid'];
	$data1['clientid']=$_REQUEST['clientid'];
  	$data1['Amount']=$_REQUEST['Amount'];
  	$data1['cheque_no']=$_REQUEST['cheque_no'];
 	$data1['narration']=$_REQUEST['narration'];
 	$cond1="voucherId='".$_REQUEST['TransId']."'";
	$UpdateRecord= $s->RecordEdit('cashbankvoucher',$data1,$cond1);
    // $s->pageLocation('main.php?route=Payments&action=Edit&VPrefix='.$_REQUEST['VPrefix'].'&TransId='.$_REQUEST['TransId'].'&voucherId='.$_REQUEST['voucherId']);
 $s->pageLocation("index.php?route=ViewPayment&VPrefix=".$_REQUEST['VPrefix']."&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."");
}
 
//************************INSERT*********************************************** 
if($_REQUEST['Cancel']!='')
{
	unset($_SESSION['billno']);
	unset($_SESSION['adjustment']);
	unset($_SESSION['pending']);
	unset($_SESSION['ID']);
	unset($_SESSION['BranchID']);
	unset($_SESSION['voucher_code']);
	unset($_SESSION['VoucherNo']);
	unset($_SESSION['ledger_id']);
	unset($_SESSION['vendorid']);
	unset($_SESSION['cheque_no']);
	unset($_SESSION['narration']);
	unset($_SESSION['CaseBankId']);
	unset($_SESSION['voucherdate']);
	unset($_SESSION['Amount']);
	unset($_SESSION['billbookid']);
	unset($_SESSION['clientid']);
}
if($_REQUEST['Save']  && $_REQUEST['action']=='' && $status)
{
/*$data_master['Amount']=0; 
$data_master['BranchID']=0; 
$data_master['VoucherNo']=''; 	
$insert2= $s->RecordInsert('cashbankvoucher_master',$data_master);
$lastid=DB_Last_Insert_ID($db,'cashbankvoucher_master', 'voucherMasterId');

$data_bankvoucher_master['BranchID']=$_REQUEST['BranchID']; 
$data_bankvoucher_master['VDate']=FormatDateForSQL($_REQUEST['voucherdate']);;
 $data_bankvoucher_master['VoucherNo']=$_REQUEST['VoucherNo'];
$data_bankvoucher_master['voucher_code']=$_REQUEST['voucher_code'];
$data_bankvoucher_master['CaseBankId']=$_REQUEST['CaseBankId'];
$data_bankvoucher_master['Amount']=$_REQUEST['Amount'];
if($VPrefixName=='CP' ||$VPrefixName=='BP')
{
$data_bankvoucher_master['credit']=$_REQUEST['Amount'];
$data_bankvoucher_master['dr_cr']='Cr';
$data_bankvoucher_master['debit']=0;

}
 else{
 $data_bankvoucher_master['debit']=$_REQUEST['Amount'];
 $data_bankvoucher_master['dr_cr']='Dr';
 $data_bankvoucher_master['credit']=0;

}

$data_bankvoucher_master['ModifyDate']=date("Y-m-d");
$data_bankvoucher_master['PreFix']=$_REQUEST['VPrefix'];
$cond="voucherMasterId='".$lastid."'";
$UpdateRecord= $s->RecordEdit('cashbankvoucher_master',$data_bankvoucher_master,$cond);
	 
 	if($VPrefixName=='CP' ||$VPrefixName=='BP')
	{
	$data['debit']=$_REQUEST['debit'];
	$data['dr_cr']='Dr';
	}
 	else
	{
	    $data['credit']=$_REQUEST['credit'];
		$data['dr_cr']='Cr';
	}
   	$data['TransId']=$lastid;
	$data['cheque_no']=$_REQUEST['cheque_no'];
	$data['ledger_id']=($_REQUEST['ledger_id']);
	$data['sub_ledger_id']=$_REQUEST['sub_ledger_id'];
	$data['vendorid']=$_REQUEST['vendorid'];
	$data['clientid']=$_REQUEST['clientid'];
   	$data['Amount']=$_REQUEST['Amount'];
  	$data['cheque_no']=$_REQUEST['cheque_no'];
 	$data['narration']=$_REQUEST['narration'];
  	$insert2= $s->RecordInsert('cashbankvoucher',$data);*/
	 
$purch_sql="Select grand_total,bill_status,pending_amount from purchase_billbook where bill='".$_SESSION['billno']."'";
$purch_res=DB_query($purch_sql,$db);

$invoice_sql="Select grand_total,invoice_status,pending_amount from invoice where invoice_id='".$_SESSION['billbookid']."'";
$invoice_res=DB_query($invoice_sql,$db);


if(DB_num_rows($purch_res)>0)
{
$purch_row=DB_fetch_array($purch_res);
$grandtotal=$purch_row['grand_total'];

if($purch_row['pending_amount']=='0.00')
{ 
	if($_REQUEST['Amount']!=$grandtotal)
	{
		$pending=$grandtotal-$_REQUEST['Amount'];
		$update_purch_billbook="Update purchase_billbook set pending_amount='".$pending."' where bill='".$_SESSION['billno']."'";
		$update_res=DB_query($update_purch_billbook,$db);
	}
else if($_REQUEST['Amount']==$grandtotal)
	{
		$update_purch_billbook="Update purchase_billbook set bill_status='Payed', pending_amount='0.00' where bill='".$_SESSION['billno']."'";
		$update_res=DB_query($update_purch_billbook,$db);
	}
}
else if($purch_row['pending_amount']!='0.00')
{ 
	if($_REQUEST['Amount']!=$purch_row['pending_amount'])
	{
		$pending1=$purch_row['pending_amount']-$_REQUEST['Amount'];
		$update_purch_billbook="Update purchase_billbook set pending_amount='".$pending1."' where bill='".$_SESSION['billno']."'";
		$update_res=DB_query($update_purch_billbook,$db);
	}
	else if($_REQUEST['Amount']==$purch_row['pending_amount'])
	{
		$update_purch_billbook="Update purchase_billbook set bill_status='Payed', pending_amount='0.00' where bill='".$_SESSION['billno']."'";
		$update_res=DB_query($update_purch_billbook,$db);
	}
}
}
else if(DB_num_rows($invoice_res)>0)
{
$invoice_row=DB_fetch_array($invoice_res);
$inv_grandtotal=$invoice_row['grand_total'];

if($invoice_row['pending_amount']=='0.00')
{
	if($_REQUEST['Amount']!=$inv_grandtotal)
	{
		$pending=$inv_grandtotal-$_REQUEST['Amount'];
		$update_invoice="Update invoice set pending_amount='".$pending."' where invoice_id='".$_SESSION['billbookid']."'";
		$update_res=DB_query($update_invoice,$db);
	}
else if($_REQUEST['Amount']==$inv_grandtotal)
	{
		$update_invoice="Update invoice set invoice_status='Payed', pending_amount='0.00' where invoice_id='".$_SESSION['billbookid']."'";
		$update_res=DB_query($update_invoice,$db);
	}
}
else if($invoice_row['pending_amount']!='0.00')
{
	if($_REQUEST['Amount']!=$invoice_row['pending_amount'])
	{
		$pending1=$invoice_row['pending_amount']-$_REQUEST['Amount'];
		$update_invoice="Update invoice set pending_amount='".$pending1."' where invoice_id='".$_SESSION['billbookid']."'";
		$update_res=DB_query($update_invoice,$db);
	}
	else if($_REQUEST['Amount']==$invoice_row['pending_amount'])
	{
		$update_invoice="Update invoice set invoice_status='Payed', pending_amount='0.00' where invoice_id='".$_SESSION['billbookid']."'";
		$update_res=DB_query($update_invoice,$db);
	}
}
}

unset($_SESSION['billno']);
unset($_SESSION['adjustment']);
unset($_SESSION['pending']);
unset($_SESSION['ID']);
unset($_SESSION['BranchID']);
unset($_SESSION['voucher_code']);
unset($_SESSION['VoucherNo']);
unset($_SESSION['ledger_id']);
unset($_SESSION['vendorid']);
unset($_SESSION['cheque_no']);
unset($_SESSION['narration']);
unset($_SESSION['CaseBankId']);
unset($_SESSION['voucherdate']);
unset($_SESSION['Amount']);

$s->pageLocation("index.php?route=ViewPayment&VPrefix=".$_REQUEST['VPrefix']."&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."");
 // $s->pageLocation('main.php?route=Payments&BranchID='.$_REQUEST['BranchID'].'&voucherdate='.$_REQUEST['voucherdate'].'&dr_cr='.$dr_cr.'&voucher_code='.$_REQUEST['voucher_code'].'&VoucherNo='.$_REQUEST['VoucherNo']);
 }
 
 
 
if($_REQUEST['BillNo'])
	 {
 		$VPrefix        =	$_REQUEST['VPrefix'] ;
		$BranchID		=	$_REQUEST['BranchID'] ;
		$voucherdate	=	$_REQUEST['voucherdate'] ;
		$voucher_code	=	$_REQUEST['voucher_code'] ;
		$VoucherNo		=	$_REQUEST['VoucherNo'] ;
		$CaseBankId		=	$_REQUEST['CaseBankId'];
		$clientid		=	$_REQUEST['clientid'];
		$vendorid   	=	$_REQUEST['vendorid'];
		$ledger_id		=	$_REQUEST['ledger_id'] ;
		$cheque_no		=	$_REQUEST['cheque_no'];
		$BillNo			=	$_REQUEST['BillNo'];
		$Amount			=	$_REQUEST['Amount'];
		
		$_SESSION['VPrefix']   =$_REQUEST['VPrefix'];
		$_SESSION['clientid']   =$_REQUEST['clientid'];
		$_SESSION['vendorid']   =$_REQUEST['vendorid'];
		$_SESSION['BranchID']   =$_REQUEST['BranchID'] ;
		$_SESSION['voucherdate']   =$_REQUEST['voucherdate'] ;
		$_SESSION['voucher_code']   =$_REQUEST['voucher_code'] ;
		$_SESSION['VoucherNo']   =$_REQUEST['VoucherNo'] ;
		$_SESSION['CaseBankId']   =$_REQUEST['CaseBankId'];
		$_SESSION['ledger_id']   =$_REQUEST['ledger_id'] ;
		$_SESSION['cheque_no']   =$_REQUEST['cheque_no'];
		$_SESSION['BillNo']   =$_REQUEST['BillNo'];
		$_SESSION['Amount']   =$_REQUEST['Amount'];
		$_SESSION['narration']=$_REQUEST['narration'];
		
		if($_REQUEST['action']=='Edit')
		$s->pageLocation("index.php?route=invoice-detail&action=".$_REQUEST['action']."&VPrefix=".$_REQUEST['VPrefix']."&TransId=".$_REQUEST['TransId']."&voucherId=".$_REQUEST['voucherId']."&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']);
		else
		$s->pageLocation("index.php?route=invoice-detail&VPrefix=".$_REQUEST['VPrefix']."&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']);
 	 } 

 
 
 
 ?>
	<style type="text/css">
<!--
.style1 {color: #FF0000}
.style3 {font-weight: bold}
-->
    </style> <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td ><div align="right"><A HREF="javascript:history.go(-1)"> [Go Back]</A> </div></td>
  </tr>
</table>
	
<form action="" method="post">
<table width="50%" border="0" cellspacing="3" cellpadding="3">
  <tr>
    <td colspan="2"><h1>
	<?php echo $fromtitle=  $s->getField('voucher_master','VoucherType',$_REQUEST['VPrefix'],'GroupName');
		echo "&nbsp;[".$VPrefixName."]&nbsp;";
	  ?> </h1></td>
  </tr>
  
  <?php if(isset($daction))
  {?>
    <tr>
     <td colspan="4" ><div class="success"><?php echo "Record ".$daction." Successfully" ?></div></td>
  </tr>
  <?php }
  if(isset($msgErr)&&$msgErr!='' )
   {?>
    <tr>
  
    <td colspan="4" ><div class="error"><?php 

for( $kp=0;$kp<count($msgErr);$kp++)
 {
		echo  '&nbsp;&nbsp; *'.$msgErr[$kp].'<br>';
 }
  ?></div></td>
  </tr>
  
   <?php }?>
   
   
  <tr>
    <td width="35%"><strong>BranchID</strong></td>
    <td width="65%">
 	<?php $_REQUEST['ledgid']=1;
 	$result_location = DB_query("SELECT loccode,locationname FROM  locations  WHERE 1=1",$db);
  			?>
			
			<select name="BranchID" style="width:200px;"  onchange="getvocuher(this.value)" tabindex="1">
			<option value="000">Please Select BranchID Name</option>
			<?php 			
 			while($myrow_location = DB_fetch_row($result_location))
			{
			
			  $p='';
			  if($myrow_location[0]==$_SESSION['BranchID'])
			  $p="selected";
			?>
			<option value="<?php echo $myrow_location[0]; ?>" <?php echo $p;?>><?php echo $myrow_location[1]; ?></option>
			<?php }?>
			</select>	 </td>
	 <td><strong>Date</strong></td>
	  <td>
<?php 	  if($_REQUEST['voucherdate']=='')
	$voucherdate=date("d/m/Y");?>
	  <input name="voucherdate" type="text" size="27" class="datepicker"  value="<?php if(isset($_SESSION['voucherdate']))echo $_SESSION['voucherdate']; else echo date('d/m/Y');?>" tabindex="2"> 	</td>
  </tr>
  <tr>
    <td><strong>Voucher No.</strong> </td>
    <td>
	<div id="voucher_code">
	<input name="voucher_code" type="text"  size="5"  value="<?php  echo $_SESSION['voucher_code'];?>"  tabindex="3" readonly="true"/>
 	<input name="VoucherNo" type="text" size="27"  value="<?php echo  $_SESSION['VoucherNo'];?>"   tabindex="4" readonly="true"> 	</td>
	<td ><strong>Cash/Bank</strong></td>
	<td>
	
	<?php 
if($fromtitle=='Bank Payment' ||$fromtitle=='Bank Receipt'  )
{
	$result_bank = DB_query("SELECT B.AccountsID,B.AccountName from accountgroupmaster A ,accountledger B where A.GroupId=52 and B.UnderGroup=A.GroupId and B.AccountName!='Cash In Hand'",$db);
  }else{
	$result_bank = DB_query("SELECT  B.AccountsID,B.AccountName from accountgroupmaster A ,accountledger B where  A.GroupId=52 and  B.UnderGroup=A.GroupId  and B.AccountName='Cash In Hand'",$db);
}	
  			?>
			 
			<select name="CaseBankId">
			<option value="000">--Select Bank--</option>
			<?php 			
 			while($myrow_bank = DB_fetch_row($result_bank))
			{
			  $p='';
			  if($myrow_bank[0]==$_SESSION['CaseBankId'])
			  $p="selected";
			?>
			<option value="<?php echo $myrow_bank[0]; ?>" <?php echo $p;?>><?php echo $myrow_bank[1]; ?></option>
			<?php }?>
			</select>	</td>
  </tr>
  
   <tr>
    <td colspan="4"><table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><strong>Ledger Name</strong></td>
	
    <td>
	  <span class="style3">
	  <?php 
	    if($VPrefixName=='CP' || $VPrefixName=='CR')
			echo "Payee";
		else   if($VPrefixName=='BR'  || $VPrefixName=='BP')
			echo "Cheque No";
		?>
	  </span>		</td>
    <td><strong>Amount</strong></td>
	<td>&nbsp;</td>
    <td><strong>Narration</strong></td>
  </tr>
  <tr>
    <td>
	<?php
  	$result_ledger = DB_query("SELECT AccountsID,AccountName  FROM accountledger  WHERE 1=1 order by AccountName ",$db);
  			?><select name="ledger_id" tabindex="5"  onchange="showLegder(this.value)">
			<option value="000">Please select Ledger</option>
			<?php 			
 			while($myrow_ledger = DB_fetch_row($result_ledger))
			{
			  $p='';
			  if($myrow_ledger[0]==$_SESSION['ledger_id'])
			  $p="selected";
			?>
			<option value="<?php echo $myrow_ledger[0]; ?>"<?php echo $p; ?>><?php echo $myrow_ledger[1]; ?></option>
			<?php }?>
			</select>
			
			<div id="txtHint">
			<?php  
			/*$result_ledger = DB_query("SELECT LedgerId,SubLedgerName  FROM mastersubledger  WHERE LedgerId='".$sub_ledger_id."' order by SubLedgerName",$db);
		if(DB_num_rows($result_ledger)>0)
		{
		?>
		SubLedger: 
		<select name="sub_ledger_id" tabindex="5"  >
		<option value="0">Please select Ledger</option>
		<?php 			
		while($myrow_ledger = DB_fetch_row($result_ledger))
		{
		$p='';
		if($myrow_ledger[0]==$_SESSION['sub_ledger_id'])
		$p="selected";
		?>
		<option value="<?php echo $myrow_ledger[0]; ?>"<?php echo $p; ?>><?php echo $myrow_ledger[1]  ?></option>
		<?php }?>
		</select>
		
		<?php }*/
		
		$sql="SELECT AccountsID,AccountName,UnderGroup FROM accountledger  WHERE AccountsID='".$_SESSION['ledger_id']."'";
		$result=DB_query($sql,$db);
		$row=DB_fetch_array($result);
		$accountgroup=$row['UnderGroup'];
		
		
	$result_ledger = DB_query("SELECT client_code,c_name  FROM clientmaster where ledger_id='".$_SESSION['ledger_id']."' ",$db);
		if(DB_num_rows($result_ledger)>0 )
		{
		?>
		    <strong>Clients:</strong> 
		<select name="clientid" tabindex="5" >
		<option value="0">Please select Ledger</option>
		<?php 			
		while($myrow_ledger = DB_fetch_row($result_ledger))
		{
		$p='';
		if($myrow_ledger[0]==$_SESSION['clientid'])
		$p="selected";
		?>
		<option value="<?php echo $myrow_ledger[0]; ?>"<?php echo $p; ?>><?php echo $myrow_ledger[1]; ?></option>
		<?php }?>
		</select>
		<?php }
		

		$result_ledger = DB_query("SELECT vendor_code,vendor_name  FROM suppliers  WHERE account_group='".$_SESSION['ledger_id']."'",$db);
		if(DB_num_rows($result_ledger)>0)
		{
		?>
		<strong>Vendor:</strong> 
		<select name="vendorid" tabindex="5" >
		<option value="0">Select</option>
		<?php 			
		while($myrow_ledger=DB_fetch_array($result_ledger))
		{
		$p='';
		if($myrow_ledger['vendor_code']==$_SESSION['vendorid'])
		$p="selected";
		?>
		<option value="<?php echo $myrow_ledger['vendor_code']; ?>"<?php echo $p;?>><?php echo $myrow_ledger['vendor_name']; ?></option>
		<?php }?>
		</select>
		
		<?php }?>
		
		
		</div> </td>
    <td>
 	<input name="cheque_no" type="text" value="<?php  echo $_SESSION['cheque_no'];?>"   />	 	 </td>
    <td>
	<div id='hiddebit'>
 	<input type="text" name="Amount" id="Amount" value="<?php if(isset($_SESSION['adjustment'])) {echo $_SESSION['adjustment'];}else echo $_SESSION['Amount']; ?>"  tabindex="7"/>
 	</div></td>
    <td><input name="BillNo" type="submit" value="BillNo"/></td>
    <td><input type="text" name="narration" value="<?php echo $_SESSION['narration']; ?>"   tabindex="9"/></td>
  </tr>
</table>     </td>
    </tr>
 <?php
//echo "<br>1=".$_SESSION['billno'];
//echo "<br>2=".$_SESSION['adjustment'];
//echo "<br>3=".$_SESSION['pending'];
//echo "<br>4=".$_SESSION['ID'];
//echo "<br>5=".$_SESSION['billbookid'];
 ?>
  <tr>
    <td>&nbsp;</td>
    <td> 
       <input type="submit" name="Save" value="Save"  tabindex="10"> <input type="submit" name="Cancel" value="Cancel" /></td><td colspan="2"><div align="right"><span class="style1">* Required Field</span>&nbsp;</div></td>
  </tr>
</table>
</form>
 

 
  