<?php
include("../include/config.php");
require_once "../include/Database_functions.php";
?>

  <?php
  $journalid= $_GET['journalid'];
  $credittotal=0;$debittotal=0;
  $journ_arr="select a.*,(select ledgername from cf_ledger as b where b.ledgerid=a.credit) as creditledgername,(select ledgername from cf_ledger as c where c.ledgerid=a.debit) as debitledgername from cf_journal as a where a.journal_reference='$journalid'";
  $array=mysql_query($journ_arr);
  
  ?>
  <table  border="0" cellspacing="0" cellpadding="0" class="tableList" style="margin-left: 25px;">
  <tr class="heading">
<td>Ledgername</td><td>Credit</td><td>Debit</td>
</tr>
  <?php
if($array && mysql_num_rows($array)>0){

while($res=mysql_fetch_array($array))
{
if($res['creditledgername']!='')
{
$credittotal=$credittotal+$res['amount'];
$ledgername=$res['creditledgername'];
?>
<tr>
<td><?=$ledgername?></td><td><?=$res['amount']?></td><td>0</td>
</tr>
<?php
}
else
{
$debittotal=$debittotal+$res['amount'];
$ledgername=$res['debitledgername'];
?>
<tr>
<td><?=$ledgername?></td><td>0</td><td><?=$res['amount']?></td>
</tr>
<?php

}


}

}
?>
<tr class="heading">
<td>Total</td><td><?=$credittotal?></td><td><?=$debittotal?></td>
</tr>
  