<?php include('Trial_function.php');
unset($_SESSION['Trial_GrandDebit']); 
unset($_SESSION['Trial_GrandCredit']);
$_SESSION['Trial_GrandDebit']=array();
$_SESSION['Trial_GrandCredit']=array();
$modid=$_REQUEST['modid'];
$frmid=$_REQUEST['frmid'];
$rurl="&modid=".$modid."&frmid=".$frmid;

	if($_REQUEST['action']=='del')
	{
		$condition="voucherId='".$_REQUEST['id']."'";
		$s->DeleteRecord('journal_voucher_master',  $condition);
		$condition1="TransId='".$_REQUEST['id']."'";
		$s->DeleteRecord('journalvoucher',  $condition1);
	}
	 if($_REQUEST['action']=='addnew')
	 {
		$data_master['Amount']=0; 
		$data_master['BranchID']=0; 
		$data_master['VoucherNo']=''; 	
		$insert2= $s->RecordInsert('temp_journal_voucher_master',$data_master);
		$lastid=DB_Last_Insert_ID($db,'temp_journal_voucher_master', 'vocucherId');
		$s->pageLocation("index.php?route=JournalVoucher&TransId=".$lastid);
	 }
 
 
 
/* $GetGT=DB_query("select AccountsID , CompanyId , AccountName  from accountledger  where AccountsID='".$_REQUEST['Lid']."'",$db);
$RowGT=DB_fetch_array($GetGT);
=str_replace("'","\'",$RowGT['AccountName']);

echo $_REQUEST['Ledgerid']
*/ 

?>
<div class="contentmain"> <br />

<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">
<h1>Voucher</h1>
<br />
 
 <table width="100%" border="0" cellspacing="1" cellpadding="2">
  <tr>
	<th scope="col"><strong>VoucherId</strong></th>	
	 <th scope="col"><strong>PreFix</strong></th>
	 	<th scope="col"><strong>Branch</strong></th>

 	<th scope="col"><strong>Ledger</strong></th>
	<th scope="col"><strong>Payment</strong></th>
	<th scope="col"><strong>Created Date</strong></th>
	<th scope="col"><strong>Debit</strong></th>
	<th scope="col"><strong>Credit</strong></th>
	
	<th scope="col"><strong>Amount</strong></th>
	<th scope="col"><strong>View</strong></th>
 	</tr>
 
  
   <?php
   $viewjournal=true;


   if(isset($_REQUEST['Lid']) && $_REQUEST['CashBankId']!=0)
   {
          $GetCashBankPayment = "Select *,A.Amount as Amount ,B.credit as Bcredit ,B.debit  as Bdebit,B.dr_cr as BDCR from cashbankvoucher_master A,cashbankvoucher B where B.TransId=A.voucherMasterId and (B.ledger_id='".$_REQUEST['Lid']."' )   ";
    $ResultCashBank = DB_query($GetCashBankPayment,$db);
 
	if(DB_num_rows($ResultCashBank)==0)
	{
 	     $GetCashBankPayment = "Select *,A.Amount as Amount,A.credit as Bcredit ,A.debit  as Bdebit  ,A.dr_cr as BDCR from cashbankvoucher_master A,cashbankvoucher B where B.TransId=A.voucherMasterId    and A.CaseBankId='".$_REQUEST['CashBankId']."' and A.BranchId='".$_REQUEST['CBranch']."'   ";
		$ResultCashBank = DB_query($GetCashBankPayment,$db);
	}
	
	$GetRecord = "Select * from journal_voucher_master A,journalvoucher B where B.TransId=A.voucherId and   B.ledger_id='".$_REQUEST['Lid']."'  ";
  $ResultData = DB_query($GetRecord,$db);
    }
   else{
          $GetRecord = "Select * from journal_voucher_master A,journalvoucher B where B.TransId=A.voucherId    group by A.voucherId";
	     $ResultData = DB_query($GetRecord,$db);
		 
	 }
    // $ResultCashBank = DB_query($GetCashBankPayment,$db);
    $lx=1;
   $j=0;
   if( $viewjournal){
//echo " ------------FOR JVoucher Entry--------------------------------------------------------<br> "; 
		 
		   if(DB_num_rows($ResultData)>0)
		   while($RowData = DB_fetch_array($ResultData))
		   {  if($j%2==0)
			 $bgcolor="#CCCCCC";
			 else{
			 $bgcolor="#FFFFFF";
			 }
 		   ?><tr bgcolor="<?php echo $bgcolor;?>" >
		   <td><div align="center"><?php echo  $lx++;?></div></td>
			<td>&nbsp;</td>
			<td><?php  
			  echo $s->getField('locations','prefix', $RowData['branch'] ,'locationname');
			 ?>	  </td>
 			 <td><div align="center"><?php    
			 
			  echo $s->getField('accountledger','AccountsID', $RowData['ledger_id'] ,'AccountName');
			?></div></td>
				  
				   <td>&nbsp;</td>
			<td>
			<div align="center">
				<?php echo $RowData['created_date'];
				  $val= SumJV_ByTrans($_REQUEST['Lid'],$RowData['voucherId']);  ?>				  </div></td>
				  <td><div align="center"><?php echo $val[0];
				   if($val[0]!=0 && $val[0]!='')
				   $_SESSION['Trial_GrandCredit'][]=$val[0];
				  ?></div></td>
				   <td><div align="center"><?php echo $val[1]; 
				   if($val[1]!=0 && $val[1]!='')
					$_SESSION['Trial_GrandDebit'][]=$val[1]; 
				   ?>
			 </div></td>
			 <td><div align="center"><?php echo $RowData['current_amount']; ?></div></td>
		   <td><div align="center"><a href="index.php?route=JournalVoucherDetails&action=Edit&id=<?php echo  $RowData['voucherId'].$rurl?>">1<img src="images/search.gif"  width="10" height="10"/></a></div></td>
			</tr>
			<?php
			$j++; }   
	}
    
	//****************************CASE BANK VOUCHER ENTRY*********************************************************
	 
if($_REQUEST['CBranch']!='')	 
   $GetRecord2 = "Select *,B.ledger_id  as ledgerid,  B.dr_cr , B.Amount from cashbankvoucher_master A,cashbankvoucher B where B.TransId=A.voucherMasterId and   A.client_id='".$_REQUEST['ClientId']."'  and BranchID='".$_REQUEST['CBranch']."'";
 else
   $GetRecord2 = "Select *,B.ledger_id  as ledgerid,  B.dr_cr , B.Amount from cashbankvoucher_master A,cashbankvoucher B where B.TransId=A.voucherMasterId and   A.client_id='".$_REQUEST['ClientId']."'   ";
 
  $ResultData2 = DB_query($GetRecord2,$db);
    
    
//echo " ----FOR JVoucher Entry----------------------------------------------------------------------------<br> "; 		 
		   if(DB_num_rows($ResultData2)>0)
		   while($RowData2 = DB_fetch_array($ResultData2))
		   {  if($j++%2==0)
			 $bgcolor="#CCCCCC";
			 else{
			 $bgcolor="#FFFFFF";
			 }
			 
			 
		   ?><tr bgcolor="<?php echo $bgcolor;?>" >
		    <td><div align="center"><?php echo  $lx++;?></div></td>
			<td><?php echo $RowData2['BranchID']; ?></td>
			<td><?php echo $s->getField('locations','prefix', $RowData2['BranchID'] ,'locationname');	 ?>	  </td>
				
				
			
			 <td><div align="center"><?php    
			   echo $s->getField('accountledger','AccountsID', $RowData2['ledgerid'] ,'AccountName');  
			  
			?></div></td>
				  
				   <td><?php 	 echo $s->getField('accountledger','AccountsID',$RowData2['CaseBankId'],'AccountName');
		 ?></td>
				 <td><div align="center"><?php 
			 echo $RowData2['VDate'];
		 	 
			  ?></div></td>
			
			  <td><div align="center"><?php echo "0";
			   
			   $_SESSION['Trial_GrandDebit'][]=0;
			  ?></div></td>
			   <td><div align="center"><?php echo $RowData2['Amount'];
			   if($RowData2['Amount']!=0 && $RowData2['Amount']!='')
			    $_SESSION['Trial_GrandCredit'][]=$RowData2['Amount']; 
			   ?></div></td>
			 <td><div align="center"><?php echo $RowData2['Amount']; ?></div></td>
		   <td><div align="center">
		   
		   <a href="index.php?route=Disp-payments&action=Edit&voucherId=<?php echo  $RowData2['voucherMasterId']?>&VPrefix=<?php echo  $RowData2['PreFix']?>&TransId=<?php echo  $RowData2['voucherMasterId'].$rurl?>">2<img src="images/search.gif"  width="10" height="10"/></a></div></td>
			</tr>
			<?php }   
	 

   
// echo " ------------FOR Voucher Entry-----------------------------------------------------<br> ";
    if(DB_num_rows($ResultCashBank)>0)
   {  
  // echo "FOR Voucher Entry- 55-->".DB_num_rows($ResultCashBank);

    while($RowData = DB_fetch_array($ResultCashBank))
   {  
    if($j++%2==0)
     $bgcolor="#CCCCCC";
	 else{
	 $bgcolor="#FFFFFF";
	 }
	 $Credit=0.00;$Debit=0.00;
	      $PreFix= $s->getField('voucher_master','VoucherType',$RowData['PreFix'],'VPrefix');
	 
	 if(($PreFix=='CP'|| $PreFix=='BP') )
		 $Debit  	 =$RowData['Amount'];
	 if(($PreFix=='CR'|| $PreFix=='BR') )
 	 $Credit  =$RowData['Amount'];
   ?><tr bgcolor="<?php echo $bgcolor;?>" >
   <td><div align="center"><?php echo  $lx++;?></div></td>
    <td><?php
	  
    echo $PreFix;?>	 </td>
    <td><?php  
 	  echo $RowData['BranchID'];
 	 ?>	  </td>
 	 <td><div align="center"><?php  
      echo $s->getField('accountledger','AccountsID', $RowData['ledger_id'] ,'AccountName');  
 	//  echo  $RowData['ledger_id'] ;
	?></div></td>
		  
	    <td><?php 	 echo $s->getField('accountledger','AccountsID',$RowData['CaseBankId'],'AccountName');
		 ?>	  </td>
 	     <td><div align="center">
      <?php  echo $RowData['VDate'];
	   
	 	     $val= SumJV_ByTrans($_REQUEST['Lid'],$RowData['voucherId']);	 
	  ?></div></td>
	   
	   <td><div align="center"><?php echo  $Debit ;
	  if($Debit!=0 && $Debit!='')
	  $_SESSION['Trial_GrandDebit'][]=$Debit;
	  ?></div></td>
	  <td><div align="center"><?php echo  $Credit;
	   if($Credit!=0 && $Credit!='')
	   $_SESSION['Trial_GrandCredit'][]=$Credit;
	   ?></div></td>
	  
	 <td><div align="center"><?php echo $RowData['Amount']; ?></div></td>
   <td><div align="center">
  
   <a href="index.php?route=ViewTrialBankCash&action=Edit&Lid=<?php echo $_REQUEST['Lid']  ?>&VPrefix=<?php echo  $RowData['PreFix']?>&TransId=<?php  echo $RowData['TransId'].$rurl ?>&voucherId=<?php echo  $RowData['voucherId']?>">3<img src="images/search.gif"  width="10" height="10"/></a></div></td>
	</tr>
 
	<?php }   
	
	}
       
   
   
  ///------------FOR IVOICE ENTRY--------------------------------------------------- 
  if(isset($_REQUEST['Lid'])){
    $ResultInvoice=DB_query("select *  from invoice where ledger_id='".$_REQUEST['Ledgername']."' and branch_name='".$_REQUEST['CBranch']."' and CompanyId='".$_SESSION['ACGCompanyId']."'",$db);

 // $ResultInvoice=DB_query("select *  from invoice where ledger_id='".$_REQUEST['Ledgername']."'",$db);
   //echo "ledger_id-->".DB_num_rows($ResultInvoice);
     if(DB_num_rows($ResultInvoice)>0) 
	 {
		while($RowDataInvoice = DB_fetch_array($ResultInvoice))
		{  
		if($j++%2==0)
		 $bgcolor="#CCCCCC";
		 else{
		 $bgcolor="#FFFFFF";
		 }
		 $Credit=0.00;$Debit=0.00;
		  $Debit =0 ;
		  $Credit=$RowDataInvoice['value_of_goods'];
	   ?><tr bgcolor="<?php echo $bgcolor;?>" >
	   <td><div align="center"><?php echo  $lx++;?></div></td>
		<td><?php echo $RowDataInvoice['invoice_code']; ?></td>
		<td><?php  
		echo ucwords(strtolower($s->getField('locations','prefix',$RowDataInvoice['branch_name'] ,'locationname')));
		 
		 ?>	  </td>
			
		 <td><div align="center">
		 
		   <?php  
		    echo $s->getField('accountledger','AccountsID', $RowDataInvoice['ledger_id'] ,'AccountName');  
		    ?>
		 </div></td>
		    <td><?php echo "Invoice";//echo $s->getField('accountledger','AccountsID',$RowData['CaseBankId'],'AccountName');	 ?>		</td>
		 <td><div align="center"><?php  echo $RowDataInvoice['invoice_date']; ?></div></td>		   
		 <td><div align="center"><?php echo $Debit ;
		  if($Debit!=0 && $Debit!='')
		  $_SESSION['Trial_GrandDebit'][]= $Debit ;
		  ?></div></td>
		  <td><div align="center"><?php echo $Credit;
		   if($Credit!=0 && $Credit!='')
		   $_SESSION['Trial_GrandCredit'][]=$Credit;
		   ?></div></td>		  
	   <td><div align="center"><?php echo $RowDataInvoice['value_of_goods']; ?></div></td>
	   <td><div align="center">	 
	   <a href="InvoiceDetails.php?action=Edit&Lid=<?php echo $_REQUEST['Lid']  ?>&InvoiceId=<?php echo  $RowDataInvoice['invoice_id'].$rurl?>">4<img src="images/search.gif"  width="10" height="10"/></a></div></td>
		</tr>
	 
		<?php }    
	 }	
	}
	
	
	  if(isset($_REQUEST['Lid'])){
     	$ResultInvoice=DB_query("select *  from invoice A ,clientmaster B where B.ledger_id='".$_REQUEST['Ledgername']."' and A.client_id=B.id and  A.branch_name='".$_REQUEST['CBranch']."' and A.CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
	// echo "ledger_id-->".DB_num_rows($ResultInvoice);

    if(DB_num_rows($ResultInvoice)>0) 
	 {
		while($RowDataInvoice = DB_fetch_array($ResultInvoice))
		{  
		if($j++%2==0)
		 $bgcolor="#CCCCCC";
		 else{
		 $bgcolor="#FFFFFF";
		 }
		 $Credit=0.00;$Debit=0.00;
		  $Credit =0 ;
		  $Debit=$RowDataInvoice['grand_total'];
	   ?><tr bgcolor="<?php echo $bgcolor;?>" >
	   <td><div align="center"><?php echo  $lx++;?></div></td>
		<td><?php echo $RowDataInvoice['invoice_code']; ?></td>
		<td><?php // echo $RowDataInvoice['branch_name']; 
		echo  $s->getField('locations','prefix', $RowDataInvoice['brance_name'] ,'locationname');
		 ?>	  </td>
			
		 <td><div align="center"><?php    
		  echo $s->getField('accountledger','AccountsID', $RowDataInvoice['ledger_id'] ,'AccountName');
		?></div></td>
		    <td><?php echo "Invoice";//echo $s->getField('accountledger','AccountsID',$RowData['CaseBankId'],'AccountName');	 ?>		</td>
		 <td><div align="center"><?php  echo $RowDataInvoice['invoice_date']; ?></div></td>		   
		 <td><div align="center"><?php echo $Debit ;
		  if($Debit!=0 && $Debit!='')
		  $_SESSION['Trial_GrandDebit'][]= $Debit ;
		  ?></div></td>
		  <td><div align="center"><?php echo $Credit;
		   if($Credit!=0 && $Credit!='')
		   $_SESSION['Trial_GrandCredit'][]=$Credit;
		   ?></div></td>		  
	   <td><div align="center"><?php echo $RowDataInvoice['grand_total']; ?></div></td>
	   <td><div align="center">	 
	   <a href="InvoiceDetails.php?action=Edit&Lid=<?php echo $_REQUEST['Lid']  ?>&InvoiceId=<?php echo  $RowDataInvoice['invoice_id'].$rurl?>">5<img src="images/search.gif"  width="10" height="10"/></a></div></td>
		</tr>
	 
		<?php }    
	 }	 
	}
   ?>
   
   <?php 
   
// echo "----------------Excise Duty------------------------------------------";
   
   	  if(isset($_REQUEST['Lid'])){
       	$ResultInvoice=DB_query("select *  from invoice A    where  (A.excise_legder='".$_REQUEST['Lid']."' or A.excise_legder='".$_REQUEST['Ledgername']."' ) and  A.branch_name='".$_REQUEST['CBranch']."' and A.CompanyId='".$_SESSION['ACGCompanyId']."' ",$db);
	// echo "excise_legder-->".DB_num_rows($ResultInvoice);
    if(DB_num_rows($ResultInvoice)>0) 
	 {
		while($RowDataInvoice = DB_fetch_array($ResultInvoice))
		{  
		if($j++%2==0)
		 $bgcolor="#CCCCCC";
		 else{
		 $bgcolor="#FFFFFF";
		 }
		 $Credit=0.00;$Debit=0.00;
		  $Credit =0 ;
		  $Debit=$RowDataInvoice['excise_duty'];
	   ?><tr bgcolor="<?php echo $bgcolor;?>" >
	   <td><div align="center"><?php echo  $lx++;?></div></td>
		<td><?php echo $RowDataInvoice['branch_name']; ?></td>
		<td><?php    echo $RowDataInvoice['excise_legder'];
		 
		 ?>	  </td>
			
		 <td><div align="center"><?php  
		   echo $s->getField('accountledger','AccountsID', $RowDataInvoice['ledger_id'] ,'AccountName');  
		?></div></td>
		    <td><?php echo "Invoice";//echo $s->getField('accountledger','AccountsID',$RowData['CaseBankId'],'AccountName');	 ?>		</td>
		 <td><div align="center"><?php  echo $RowDataInvoice['invoice_date']; ?></div></td>		   
		 <td><div align="center"><?php echo $Debit ;
		  if($Debit!=0 && $Debit!='')
		  $_SESSION['Trial_GrandDebit'][]= $Debit ;
		  ?></div></td>
		  <td><div align="center"><?php echo $Credit;
		   if($Credit!=0 && $Credit!='')
		   $_SESSION['Trial_GrandCredit'][]=$Credit;
		   ?></div></td>		  
	   <td><div align="center"><?php echo $RowDataInvoice['excise_duty']; ?></div></td>
	   <td><div align="center">	 
	   <a href="InvoiceDetails.php?action=Edit&Lid=<?php echo $_REQUEST['Lid']  ?>&InvoiceId=<?php echo  $RowDataInvoice['invoice_id'].$rurl?>">6<img src="images/search.gif"  width="10" height="10"/></a></div></td>
		</tr>
	 
		<?php }    
	 }	 
	}
	
	
	 if(isset($_REQUEST['Lid'])){
      	$ResultInvoice=DB_query("select *  from invoice A    where  ( A.edu_cess_ledger ='".$_REQUEST['Lid']."'  or A.edu_cess_ledger='".$_REQUEST['Ledgername']."' ) and  A.branch_name='".$_REQUEST['CBranch']."' and A.CompanyId='".$_SESSION['ACGCompanyId']."'   ",$db);
			//echo "edu_cess_ledger-->".DB_num_rows($ResultInvoice);
    if(DB_num_rows($ResultInvoice)>0) 
	 {
		while($RowDataInvoice = DB_fetch_array($ResultInvoice))
		{  
		if($j++%2==0)
		 $bgcolor="#CCCCCC";
		 else{
		 $bgcolor="#FFFFFF";
		 }
		 $Credit=0.00;$Debit=0.00;
		  $Credit =0 ;
		  $Debit=$RowDataInvoice['edu_cess'];
	   ?><tr bgcolor="<?php echo $bgcolor;?>" >
	   <td><div align="center"><?php echo  $lx++;?></div></td>
		<td><?php echo $RowDataInvoice['invoice_code']; ?></td>
		<td><?php  
		  
		echo $RowDataInvoice['edu_cess_ledger'];
		 ?>	  </td>
			
		 <td><div align="center"><?php    
		  echo $s->getField('accountledger','AccountsID', $RowDataInvoice['ledger_id'] ,'AccountName'); 
		 
		?></div></td>
		    <td><?php echo "Invoice";//echo $s->getField('accountledger','AccountsID',$RowData['CaseBankId'],'AccountName');	 ?>		</td>
		 <td><div align="center"><?php  echo $RowDataInvoice['invoice_date']; ?></div></td>		   
		 <td><div align="center"><?php echo $Debit ;
		  if($Debit!=0 && $Debit!='')
		  $_SESSION['Trial_GrandDebit'][]= $Debit ;
		  ?></div></td>
		  <td><div align="center"><?php echo $Credit;
		   if($Credit!=0 && $Credit!='')
		   $_SESSION['Trial_GrandCredit'][]=$Credit;
		   ?></div></td>		  
	   <td><div align="center"><?php echo $RowDataInvoice['edu_cess']; ?></div></td>
	   <td><div align="center">	 
	   <a href="InvoiceDetails.php?action=Edit&Lid=<?php echo $_REQUEST['Lid']  ?>&InvoiceId=<?php echo  $RowDataInvoice['invoice_id'].$rurl?>">7<img src="images/search.gif"  width="10" height="10"/></a></div></td>
		</tr>
	 
		<?php }    
	 }	 
	}
	
	
	 if(isset($_REQUEST['Lid'])){
	  
      	$ResultInvoice=DB_query("select *  from invoice A    where  (A.she_cess_ledger='".$_REQUEST['Lid']."'  or A.she_cess_ledger='".$_REQUEST['Ledgername']."' ) and  A.branch_name='".$_REQUEST['CBranch']."' and A.CompanyId='".$_SESSION['ACGCompanyId']."' ",$db);
		//echo "she_cess_ledger-->".DB_num_rows($ResultInvoice);
    if(DB_num_rows($ResultInvoice)>0) 
	 {
		while($RowDataInvoice = DB_fetch_array($ResultInvoice))
		{  
		if($j++%2==0)
		 $bgcolor="#CCCCCC";
		 else{
		 $bgcolor="#FFFFFF";
		 }
		 $Credit=0.00;$Debit=0.00;
		  $Credit =0 ;
		  $Debit=$RowDataInvoice['she_cess'];
	   ?><tr bgcolor="<?php echo $bgcolor;?>" >
	   <td><div align="center"><?php echo  $lx++;?></div></td>
		<td><?php echo $RowDataInvoice['invoice_code']; ?></td>
		<td><?php  	 
		 		echo  $RowDataInvoice['she_cess_ledger'];
		 ?>	  </td>
			
		 <td><div align="center"><?php 
		   echo $s->getField('accountledger','AccountsID', $RowDataInvoice['ledger_id'] ,'AccountName');    
		 
		?></div></td>
		    <td><?php echo "Invoice";//echo $s->getField('accountledger','AccountsID',$RowData['CaseBankId'],'AccountName');	 ?>		</td>
		 <td><div align="center"><?php  echo $RowDataInvoice['invoice_date']; ?></div></td>		   
		 <td><div align="center"><?php echo $Debit ;
		  if($Debit!=0 && $Debit!='')
		  $_SESSION['Trial_GrandDebit'][]= $Debit ;
		  ?></div></td>
		  <td><div align="center"><?php echo $Credit;
		   if($Credit!=0 && $Credit!='')
		   $_SESSION['Trial_GrandCredit'][]=$Credit;
		   ?></div></td>		  
	   <td><div align="center"><?php echo $RowDataInvoice['she_cess']; ?></div></td>
	   <td><div align="center">	 
	   <a href="InvoiceDetails.php?action=Edit&Lid=<?php echo $_REQUEST['Lid']  ?>&InvoiceId=<?php echo  $RowDataInvoice['invoice_id'].$rurl?>">8<img src="images/search.gif"  width="10" height="10"/></a></div></td>
		</tr>
	 
		<?php }    
	 }	 
	}
	
 	
	 if(isset($_REQUEST['Lid'])){
      	$ResultInvoice=DB_query("select *  from invoice A    where  (A.vat_cst_ledger='".$_REQUEST['Lid']."'  or A.vat_cst_ledger='".$_REQUEST['Ledgername']."' ) and  A.branch_name='".$_REQUEST['CBranch']."' and A.CompanyId='".$_SESSION['ACGCompanyId']."' ",$db);
		//echo "vat_cst_ledger-->".DB_num_rows($ResultInvoice);
    if(DB_num_rows($ResultInvoice)>0) 
	 {
 		while($RowDataInvoice = DB_fetch_array($ResultInvoice))
		{  
		if($j++%2==0)
		 $bgcolor="#CCCCCC";
		 else{
		 $bgcolor="#FFFFFF";
		 }
		 $Credit=0.00;$Debit=0.00;
		  $Credit =($RowDataInvoice['total_taxable']* $RowDataInvoice['vat_cst'] * .01); ;
		  $Debit=0;
	   ?><tr bgcolor="<?php echo $bgcolor;?>" >
	   <td><div align="center"><?php echo  $lx++;?></div></td>
		<td><?php echo $RowDataInvoice['invoice_code']; ?></td>
		<td><?php  
		 
		 		echo  $RowDataInvoice['vat_cst_ledger'];

		 ?>	  </td>
			
		 <td><div align="center"><?php  
		    echo $s->getField('accountledger','AccountsID', $RowDataInvoice['ledger_id'] ,'AccountName');      
		 
		?></div></td>
		    <td><?php echo "Invoice";//echo $s->getField('accountledger','AccountsID',$RowData['CaseBankId'],'AccountName');	 ?>		</td>
		 <td><div align="center"><?php  echo $RowDataInvoice['invoice_date']; ?></div></td>		   
		 <td><div align="center"><?php echo $Debit ;
		  if($Debit!=0 && $Debit!='')
		  $_SESSION['Trial_GrandDebit'][]= $Debit ;
		  ?></div></td>
		  <td><div align="center"><?php echo $Credit;
		   if($Credit!=0 && $Credit!='')
		   $_SESSION['Trial_GrandCredit'][]=$Credit;
		   ?></div></td>		  
	   <td><div align="center"><?php echo $Credit ?></div></td>
	   <td><div align="center">	 
	   <a href="InvoiceDetails.php?action=Edit&Lid=<?php echo $_REQUEST['Lid']  ?>&InvoiceId=<?php echo  $RowDataInvoice['invoice_id'].$rurl?>">9<img src="images/search.gif"  width="10" height="10"/></a></div></td>
		</tr>
	 
		<?php }    
	 }	 
	}
	
	
	
	if(isset($_REQUEST['Lid']) && $_REQUEST['ClientId']!=''){
	    $cid=$_REQUEST['ClientId'];
       	$ResultInvoice=DB_query("select *  from invoice A   where A.branch_name='".$_REQUEST['CBranch']."'  and A.client_id in ($cid) and CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
 		
    if(DB_num_rows($ResultInvoice)>0) 
	 {
 		while($RowDataInvoice = DB_fetch_array($ResultInvoice))
		{  
		if($j++%2==0)
		 $bgcolor="#CCCCCC";
		 else{
		 $bgcolor="#FFFFFF";
		 }
		 $Credit=0.00;$Debit=0.00;
		  $Credit =0 ;
		  $Debit=($RowDataInvoice['grand_total']);
	   ?><tr bgcolor="<?php echo $bgcolor;?>" >
	   <td><div align="center"><?php echo  $lx++;?></div></td>
		<td><?php echo $RowDataInvoice['invoice_code']; ?></td>
		<td><?php  // echo $RowDataInvoice['branch_name'];
		echo ucwords(strtolower($s->getField('locations','prefix',$RowDataInvoice['branch_name'] ,'locationname')));
		 ?>	  </td>
			
		 <td><div align="center"><?php   
		
 		  echo ucwords(strtolower($s->getField('clientmaster','id',$RowDataInvoice['client_id'],'c_name')));?>
		 </div></td>
		    <td><?php echo "Invoice";//echo $s->getField('accountledger','AccountsID',$RowData['CaseBankId'],'AccountName');	 ?>		</td>
		 <td><div align="center"><?php  echo $RowDataInvoice['invoice_date']; ?></div></td>		   
		 <td><div align="center"><?php echo $Debit ;
		  if($Debit!=0 && $Debit!='')
		  $_SESSION['Trial_GrandDebit'][]= $Debit ;
		  ?></div></td>
		  <td><div align="center"><?php echo $Credit;
		   if($Credit!=0 && $Credit!='')
		   $_SESSION['Trial_GrandCredit'][]=$Credit;
		   ?></div></td>		  
	   <td><div align="center"><?php echo $Debit ?></div></td>
	   <td><div align="center">	 
	   <a href="InvoiceDetails.php?action=Edit&Lid=<?php echo $_REQUEST['Lid']  ?>&InvoiceId=<?php echo  $RowDataInvoice['invoice_id'].$rurl?>">10<img src="images/search.gif"  width="10" height="10"/></a></div></td>
		</tr>
	 
		<?php }    
	 }	
	 
	 
	  
	}
   ?>
   
   
   

   
    <tr   bgcolor="#333333" style="color:#FFFFFF" >
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><strong>Total:</strong></td>
    <td><?php 
	
 	echo $GTDebit=array_sum($_SESSION['Trial_GrandDebit']);?></td>
    <td><?php 
	 
	
	 echo $GTCredit= array_sum($_SESSION['Trial_GrandCredit']);?></td>
    <td><?php 
	if($GTDebit!=0 && $GTCredit!=0)
	echo $GTDebit-$GTCredit;
	else if($GTDebit==0 && $GTCredit!=0)
		echo $GTCredit;
		else
			echo $GTDebit;
	 ?></td>
    <td>&nbsp;</td>
  </tr>
</table>
</form>

 </div>