<?php include("../../include/dbconnect.php");


if($filename2 == '')
{

	?>
    	<script language="javascript">
		alert("You have closed the Main Program Browser before saving the data, due to that Data won't be saved. Please login");
        </script>
    <?
	exit;

}


?>

<title>Transaction View</title>
</head>
<body background="images/blater01.gif" topmargin=0>
<center> 
<form name='myform2' >
<?
	mysqli_query($conn,"truncate $filename2");

	$query= "insert into $filename2(acctcode,date,narration,dbamt,cramt,type,invno,compcode,branch_code,trans_id,account_year) select acctcode,date,narration,dbamt,cramt,type,invno,compcode,branch_code,trans_id,account_year from  ledger where compcode = '$compcode' and branch_code = '$branch' and trans_id = '$trans_id' and account_year = '$account_year' ";
	mysqli_query($conn,$query) or die(mysqli_error());
	
?> 


<tr >





<table width="809">
  <tr  bgcolor="#A4A4FF">

<td width="49" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Sl No&nbsp;</b></font></td>
<td width="64" height="31" align="left" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Date&nbsp;</b></font></td>
<td width="216" height="31" align="left" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>GL Head&nbsp;</b></font></td>
<td width="238" height="31" align="left" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Description&nbsp;</b></font></td>
<td width="64" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Debit</b></font></td>
<td width="55" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Credit</b></font></td>
<td width="46" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Type</b></font></td>
<td width="41" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Trans.Id</b></font></td>

<?

$netdb = 0;
$netcr=0;
$slno=1;
$result = mysqli_query($conn,"select acctcode,date,narration,dbamt,cramt,type,trans_id,record,date from  $filename2 ") or die(mysqli_error());
while($row = mysqli_fetch_row($result))
{
	$acctcode = $row[0];
	$date = british($row[1]);
	$narration = $row[2];
	$dbamt = $row[3];
	$cramt = $row[4];
	$type = $row[5];
	$trans_id = $row[6];
	$record = $row[7];
	$mdt = british($row[8]);
	$netdb = $netdb+$dbamt;
	$netcr = $netcr + $cramt;

	$prodname = mysqli_fetch_array(mysqli_query($conn,"select description from acctmast where acctcode = '$acctcode'")) or die(mysqli_error());
	?>
	<tr  bgcolor="#D7D7FF">
	<td width="49" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?echo($slno);?></a></b></font></td>
	<td width="64" height="31" align="left" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=$mdt?></b></font></td>
	<td width="216" height="31" align="left" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=$prodname['description']?></b></font></td>
	<td width="238" height="31" align="left" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=$narration?></b></font></td>
	<td width="64" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=$dbamt?></b></font></td>
	<td width="55" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=$cramt?></b></font></td>
	<td width="46" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=$type?></b></font></td>
	<td width="41" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=$trans_id?></b></font></td>

	</tr>
	
	<?
	$slno++;
}


if($ledgclosing < 0)
{
	$gtotal = $op +$ledgclosing+$nettot;
}
elseif($ledgclosing >= 0)
{
	$gtotal = $op -$ledgclosing+$nettot;
}
if($gtotal < 0)
{
	$gtotal= $gtotal*-1;
	$amt = $gtotal.'&nbsp;&nbsp;CR';
}
elseif($gtotal >0)
{
	$amt = $gtotal.'&nbsp;&nbsp;DR';
}
$aresult = mysqli_query($conn,"select sum(dbamt) from  $filename2   ") or die(mysqli_error());
$arow = mysqli_fetch_row($aresult);
$tpayments = $arow[0];	

$aresult = mysqli_query($conn,"select sum(cramt) from  $filename2   ") or die(mysqli_error());
$arow = mysqli_fetch_row($aresult);
$treceipts = $arow[0];	



?>

<tr  bgcolor="#D7D7FF">
<td  colspan="4" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b>Total</b></font></td>
<td width="64" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=number_format($netdb,2)?></b></font></td>
<td width="64" height="31" align="right" ><font color="#003366" size="1" face="Verdana, Arial, Helvetica, sans-serif"><b><?=number_format($netcr,2)?></b></font></td>
<td colspan="2"></td>
</tr>



</table>

</form>
<font size=1> 
<br><br><font size=1><center><a href= "javascript:window.close();">Close Window</a></center></font>
</font> 

