<?php
$f_coa_kas = "1001";
$t_coa_kas = "1129";
$strq = "select * from mst_coa a, balance b where a.coa_autoid = b.coa_autoid 
		and (a.coa_accno between '$f_coa_kas' and  '$t_coa_kas') and b.bb_year <= '$tahun' AND b.outlet_autoid = '$outlet'";
$ccon = $conn->query($strq);
while($rsx = $ccon->fetch_assoc()){;
	$saldoawal 	= $rsx['bb_balance'];
	$coaaccno 	= $rsx['coa_accno'];
	$coadesc 	= $rsx['coa_accdesc'];
	$ngroup 	= $rsx['coa_accgroup'];
	$autoid 	= $rsx['coa_autoid'];

	$sqlsaldo_a = "select sum(b.jtd_debit) as debet1, sum(b.jtd_credit) as credit1
			 from jtheader a, jtdetail b where a.jt_autoid = b.jt_autoid and 
			a.jt_flagpost <> 'X' and b.jtd_vcdate <= '$tglakhir' and
			(b.coa_autoid = '$autoid') AND a.outlet_autoid = '$outlet'";

	$con_saldo_a = $conn->query($sqlsaldo_a) or die($sqlsaldo_a);
	$rssaldo_a = $con_saldo_a->fetch_assoc();

	$debet_a = $rssaldo_a[debet1];
	$credit_a = $rssaldo_a[credit1];

	$sqlsaldo_b = "select sum(b.jtd_debit2) as debet2, sum(b.jtd_credit2) as credit2
			 from jtheader a, jtdetail b where a.jt_autoid = b.jt_autoid and 
			a.jt_flagpost <> 'X' and b.jtd_vcdate <= '$tglakhir' and
			(b.coa_autoid2 = '$autoid')  AND a.outlet_autoid = '$outlet'";
$con_saldo_b = $conn->query($sqlsaldo_b) or die($sqlsaldo_b);
$rssaldo_b = $con_saldo_b->fetch_assoc();
	$debet_b = $rssaldo_b[debet2];
	$credit_b = $rssaldo_b[credit2];

	$sdebet = $debet_a + $debet_b;
	$scredit = $credit_a + $credit_b;

	if($ngroup==6){
	$saldoawal = $saldoawal - ($sdebet -$scredit);}
	else{$saldoawal = $saldoawal + ($sdebet -$scredit);}
	?>
<tr>
    <td class="tl"><?php echo ($coadesc);?></td>
    <td class="tr"><?php echo number_format($saldoawal);?></td>
</tr>
<?php 
$kas = $kas + $saldoawal;
}
 ?>
