<?php include('Trial_function.php');
$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("main.php?route=JournalVoucher&TransId=".$lastid);
 }
?>
<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>Journal Voucher</h1><br />

 <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td ><div align="right">
	 
	<a href="index.php?route=JournalVoucher<?php  echo $rurl;?>"><input name="Add New Journal vocuher"  value="Add New Journal vocuher"type="button" /></a>
	</div>
	</td>
  </tr>
</table>

 <table width="100%" border="0" cellspacing="1" cellpadding="2">
  <tr>
	<th scope="col"><strong>  VoucherId</strong></th>
	<th scope="col"><strong>Branch</strong></th>
 	<th scope="col"><strong>Ledger</strong></th>
	<th scope="col"><strong>SubLedger</strong></th>
	
	<th scope="col"><strong>Created Date</strong></th>
	<th scope="col"><strong>Cebit</strong></th>
	<th scope="col"><strong>Debit</strong></th>
	<th scope="col"><strong>Amount</strong></th>
	<th scope="col"><strong>View</strong></th>
 	<th scope="col"><strong>Delete</strong></th>
  </tr>
 
  
   <?php
   if(isset($_REQUEST['Lid']))
   {
         $GetRecord = "Select * from journal_voucher_master A,journalvoucher B where B.TransId=A.voucherId and B.ledger_id='".$_REQUEST['Lid']."' group by A.voucherId ";
		   
   }else{
       $GetRecord = "Select * from journal_voucher_master A,journalvoucher B where B.TransId=A.voucherId    group by A.voucherId";
	 }
   $ResultData = DB_query($GetRecord,$db);
   $j=0;
   if(DB_num_rows($ResultData)==0)
   echo "<td colspan='3'>--No Record--</td>";
   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 $RowData['voucherId']; ?></div></td>
    <td><?php  
 	  echo $s->getField('locations','loccode', $RowData['branch'] ,'locationname');
 	 ?>	  </td>
	    
		
	
	 <td><div align="center"><?php    
     
	  echo $s->getField('accountledger','AccountsID', $RowData['ledger_id'] ,'AccountName');
	?></div></td>
		  
		   <td><div align="center"><?php     
      echo $s->getField('mastersubledger','LedgerId',$RowData['sub_ledger_id'],'SubLedgerName');

	?></div></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];//$RowData['current_amount']; ?></div></td>
	   <td><div align="center"><?php echo $val[1];//$RowData['current_amount']; ?></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?>"><img src="images/search.gif"  width="10" height="10"/></a></div></td>
	<td><div align="center"><a href="index.php?route=View_JournalVoucher&action=del&id=<?php echo  $RowData['voucherId'].$rurl ?>" onclick="return confirm('Do You Want To Delete This Record')"><img src="images/Icon_Delete.png" width="10" height="10" /></a></div></td>	
	 </tr>
	<?php }   
   ?> 
    
</table>
</form>

 