<script type="text/javascript">
    $(function() {
        $("#theList tr:even").addClass("stripe1");
        $("#theList tr:odd").addClass("stripe2");

        $("#theList tr").hover(
            function() {
                $(this).toggleClass("highlight");
            },
            function() {
                $(this).toggleClass("highlight");
            }
        );
    });
</script>

<?php
include '../../inc/inc.koneksi.php';
include '../../inc/fungsi_tanggal.php';

$tglawal = $_GET['tglawal'];
$tglakhir= $_GET['tglakhir'];
$kodecab = $_GET['kodecab'];

$kas = '111'.$kodecab;

$jsalawal=0;
    
$sql1=mysql_query("SELECT * FROM akun_bb WHERE noakun='$kas'");
$r1=mysql_fetch_assoc($sql1);
$saldo = $r1['saldo']+$r1['mutasi_db']-$r1['mutasi_kd'];
        
$sql= mysql_query("SELECT noakun,sum(debet) as jdebet,sum(kredit) as jkredit FROM rekapjur WHERE tanggal>='$tglawal' AND noakun='$kas'");
$r  = mysql_fetch_assoc($sql);
$jdebet = $r['jdebet'];
$jkredit= $r['jkredit'];
$salawal= $saldo-$jdebet+$jkredit;

echo "<table width='100%' style='font:12PX arial'>
    <tr>
        <td width='79%'><b>SALDO AWAL</b></td>
        <td width='3%'>Rp</td>
	    <td width='15%' align='right'>".number_format($salawal,0)."</td>
	    <td width='2%'></td>
    </tr>
</table>
<br>

<table width='100%' style='font:12PX arial'>
    <tr>
        <td><b>PENERIMAAN :</b></td>
    </tr>
    <tr>
        <td>Penjualan Tunai</td>
    </tr>
</table>

<table width='100%' style='font:12PX arial'>";
    $jual=0;
    $sql=mysql_query("SELECT sum(debet) as jdebet,user FROM rekapjur WHERE tanggal BETWEEN '$tglawal' AND '$tglakhir' AND jurnal='PJL' AND noakun='11101' AND kode_cab='$kodecab' GROUP BY user");
    
    while($r=mysql_fetch_array($sql)){
        echo "<tr>
            <td width='4%'></td>
            <td width='36%'>- $r[user]</td>
            <td width='3%'>Rp</td>
            <td width='15%' align='right'>".number_format($r['jdebet'],0)."</td>
            <td width='3%'></td>
            <td width='15%'></td>
            <td width='3%'></td>
            <td width='15%'></td>
        </tr>";
        $jual=$jual+$r['jdebet'];
    }
    echo "<tr>
        <td width='4%'></td>
        <td width='36%'></td>
        <td width='3%' style='border-top:1px double'></td>
        <td width='15%' style='border-top:1px double'></td>
        <td width='3%'></td>
        <td width='15%'></td>
        <td width='3%'></td>
        <td width='15%'></td>
    </tr>
    <tr>
        <td></td>
        <td></td>
        <td></td>
        <td>Jumlah</td>
        <td>Rp</td>
        <td align='right'>".number_format($jual,0)."</td>
        <td></td>
        <td></td>
    </tr>
</table>

<table width='100%' style='font:12PX arial'>
    <tr>
        <td>Penerimaan Piutang</td>
    </tr>
</table>

<table width='100%' style='font:12PX arial'>";
    $jppi=0;
    $sql=mysql_query("SELECT kode_pl,nama_pl,sum(tunai) as jtunai FROM jurppi WHERE tanggal BETWEEN '$tglawal' AND '$tglakhir' AND kode_cab='$kodecab' AND batal='' AND posting='P' GROUP BY kode_pl");
    
    while($r=mysql_fetch_array($sql)){
        echo "<tr>
            <td width='4%'></td>
            <td width='36%'>- $r[kode_pl] : $r[nama_pl]</td>
            <td width='3%'>Rp</td>
            <td width='15%' align='right'>".number_format($r['jtunai'],0)."</td>
            <td width='3%'></td>
            <td width='15%'></td>
            <td width='3%'></td>
            <td width='15%'></td>
        </tr>";
        $jppi=$jppi+$r['jtunai'];
    }
    echo "<tr>
        <td width='4%'></td>
        <td width='36%'></td>
        <td width='3%' style='border-top:1px double'></td>
        <td width='15%' style='border-top:1px double'></td>
        <td width='3%'></td>
        <td width='15%'></td>
        <td width='3%'></td>
        <td width='15%'></td>
    </tr>
    <tr>
        <td></td>
        <td></td>
        <td></td>
        <td>Jumlah</td>
        <td>Rp</td>
        <td align='right'>".number_format($jppi,0)."</td>
        <td></td>
        <td></td>
    </tr>
</table>

<table width='100%' style='font:12PX arial'>
    <tr>
        <td>Pengambilan Tunai Bank</td>
    </tr>
</table>

<table width='100%' style='font:12PX arial'>";
    
    $sql=mysql_query("SELECT noakun,naakun,sum(jumlah) as tjumlah FROM jurkm WHERE tanggal BETWEEN '$tglawal' AND '$tglakhir' AND concat(substr(noakun,1,4))='1113' AND kode_cab='$kodecab' AND posting='P' GROUP BY noakun");
    $jkmbank=0;
    while($r=mysql_fetch_array($sql)){
        echo "<tr>
            <td width='4%'></td>
            <td width='36%'>- $r[naakun]</td>
            <td width='3%'>Rp</td>
            <td width='15%'align='right'>".number_format($r['tjumlah'],0)."</td>
            <td width='3%'></td>
            <td width='15%'></td>
            <td width='3%'></td>
            <td width='15%'></td>
        </tr>";
        $jkmbank=$jkmbank+$r['tjumlah'];
    }
    $sql=mysql_query("SELECT nobank,namabank,sum(jumlah) as tjumlah FROM jurbk WHERE tanggal BETWEEN '$tglawal' AND '$tglakhir' AND noakun='$kas' AND posting='P' GROUP BY nobank");
    
    while($r=mysql_fetch_array($sql)){
        echo "<tr>
            <td width='4%'></td>
            <td width='36%'>- $r[namabank]</td>
            <td width='3%'>Rp</td>
            <td width='15%'align='right'>".number_format($r['tjumlah'],0)."</td>
            <td width='3%'></td>
            <td width='15%'></td>
            <td width='3%'></td>
            <td width='15%'></td>
        </tr>";
        $jkmbank=$jkmbank+$r['tjumlah'];
    }
    echo "<tr>
        <td width='4%'></td>
        <td width='36%'></td>
        <td width='3%' style='border-top:1px double'></td>
        <td width='15%' style='border-top:1px double'></td>
        <td width='3%'></td>
        <td width='15%'></td>
        <td width='3%'></td>
        <td width='15%'></td>
    </tr>
    <tr>
        <td></td>
        <td></td>
        <td></td>
        <td>Jumlah</td>
        <td>Rp</td>
        <td align='right'>".number_format($jkmbank,0)."</td>
        <td></td>
        <td></td>
    </tr>
</table>

<table width='100%' style='font:12PX arial'>
    <tr>
        <td>Penerimaan Lainnya</td>
    </tr>
</table>

<table width='100%' style='font:12PX arial'>";
    
    $sql=mysql_query("SELECT noakun,naakun,sum(jumlah) as tjumlah FROM jurkm WHERE tanggal BETWEEN '$tglawal' AND '$tglakhir' AND !(concat(substr(noakun,1,4))='1113') AND kode_cab='$kodecab' AND posting='P' GROUP BY noakun");
    $jkmlain=0;
    while($r=mysql_fetch_array($sql)){
        echo "<tr>
            <td width='4%'></td>
            <td width='36%'>- $r[naakun]</td>
            <td width='3%'>Rp</td>
            <td width='15%' align='right'>".number_format($r['tjumlah'],0)."</td>
            <td width='3%'></td>
            <td width='15%'></td>
            <td width='3%'></td>
            <td width='15%'></td>
        </tr>";
        $jkmlain=$jkmlain+$r['tjumlah'];
    }
    echo "<tr>
        <td width='4%'></td>
        <td width='36%'></td>
        <td width='3%' style='border-top:1px double'></td>
        <td width='15%' style='border-top:1px double'></td>
        <td width='3%'></td>
        <td width='15%'></td>
        <td width='3%'></td>
        <td width='15%'></td>
    </tr>
    <tr>
        <td></td>
        <td></td>
        <td></td>
        <td>Jumlah</td>
        <td>Rp</td>
        <td align='right'>".number_format($jkmlain,0)."</td>
        <td></td>
        <td></td>
    </tr>
</table>

<table width='100%' style='font:12PX arial'>
    <tr>
        <td>Penyesuaian dan Koreksi</td>
    </tr>
</table>

<table width='100%' style='font:12PX arial'>";
    
    $sql = mysql_query("SELECT * FROM jurnalum WHERE tanggal BETWEEN '$tglawal' AND '$tglakhir' AND noakun='$kas' AND kode_dk='D' AND posting='P' ");
    $jkmju=0;
    while($r=mysql_fetch_array($sql)){
        echo "<tr>
            <td width='4%'></td>
            <td width='36%'>- $r[keterangan]</td>
            <td width='3%'>Rp</td>
            <td width='15%' align='right'>".number_format($r['debet'],0)."</td>
            <td width='3%'></td>
            <td width='15%'></td>
            <td width='3%'></td>
            <td width='15%'></td>
        </tr>";
        $jkmju=$jkmju+$r['debet'];
    }
    echo "<tr>
        <td width='4%'></td>
        <td width='36%'></td>
        <td width='3%' style='border-top:1px double'></td>
        <td width='15%' style='border-top:1px double'></td>
        <td width='3%'></td>
        <td width='15%'></td>
        <td width='3%'></td>
        <td width='15%'></td>
    </tr>
    <tr>
        <td></td>
        <td></td>
        <td></td>
        <td>Jumlah</td>
        <td>Rp</td>
        <td align='right'>".number_format($jkmju,0)."</td>
        <td></td>
        <td></td>
    </tr>
</table>";
$jkm=$jual+$jppi+$jkmbank+$jkmpkk+$jkmlain+$jkmju;
$salakhir=$salawal+$jkm;

echo "<table width='100%' style='font:12PX arial'>
    <tr>
        <td width='40%'>Jumlah Penerimaan</td>
        <td width='3%'></td>
        <td width='15%'></td>
        <td width='3%'></td>
        <td width='15%'></td>
        <td width='3%' style='border-top:1px double'>Rp</td>
        <td width='13%' align='right' style='border-top:1px double'>".number_format($jkm,0)."</td>
        <td width='2%'> +</td>
    </tr>
    <tr>
        <td>Jumlah Saldo Awal + Penerimaan</td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td style='border-top:1px double'>Rp</td>
        <td align='right' style='border-top:1px double'>".number_format($salakhir,0)."</td>
        <td></td>
    </tr>
</table>
<br>

<table width='100%' style='font:12PX arial'>
    <tr>
        <td><b>PENGELUARAN :</b></td>
    </tr>
    <tr>
        <td>Pembelian Tunai</td>
    </tr>
</table>";

if($kodecab=='01'){
    echo "<table width='100%' style='font:12PX arial'>";
        $sql=mysql_query("SELECT kode_sup,nama_sup,sum(bayar) as jbayar FROM faktur_pb WHERE tanggal BETWEEN '$tglawal' AND '$tglakhir' AND !(bayar=0) AND AND batal=''AND posting='P' GROUP BY kode_sup");
        $beli=0;
        while($r=mysql_fetch_array($sql)){
            echo "<tr>
                <td width='4%'></td>
                <td width='36%'>- $r[nama_sup]</td>
                <td width='3%'>Rp</td>
                <td width='15%' align='right'>".number_format($r['jbayar'],0)."</td>
                <td width='3%'></td>
                <td width='15%'></td>
                <td width='3%'></td>
                <td width='15%'></td>
            </tr>";
            $beli=$beli+$r['jbayar'];
        }
        echo "<tr>
            <td width='4%'></td>
            <td width='36%'></td>
            <td width='3%' style='border-top:1px double'></td>
            <td width='15%' style='border-top:1px double'></td>
            <td width='3%'></td>
            <td width='15%'></td>
            <td width='3%'></td>
            <td width='15%'></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td>Jumlah</td>
            <td>Rp</td>
            <td align='right'>".number_format($beli,0)."</td>
            <td></td>
            <td></td>
        </tr>
    </table>";
}

echo "<table width='100%' style='font:12PX arial'>
    <tr>
        <td>Pembayaran Hutang</td>
    </tr>
</table>

<table width='100%' style='font:12PX arial'>";
    $sql=mysql_query("SELECT noakun,nobp,namabp,sum(jumlah) as tjumlah,sum(diskon) as tdiskon FROM jurkk WHERE tanggal BETWEEN '$tglawal' AND '$tglakhir' AND concat(substr(noakun,1,3))='211' AND kode_cab='$kodecab' AND posting='P' GROUP BY nobp");
    $jhutang=0;
    while($r=mysql_fetch_array($sql)){
        $jumlah=$r['tjumlah']-$r['tdiskon'];
        
        echo "<tr>
            <td width='4%'></td>
            <td width='36%'>- $r[namabp]</td>
            <td width='3%'>Rp</td>
            <td width='15%' align='right'>".number_format($jumlah,0)."</td>
            <td width='3%'></td>
            <td width='15%'></td>
            <td width='3%'></td>
            <td width='15%'></td>
        </tr>";
        $jhutang=$jhutang+$jumlah;
    }
    echo "<tr>
        <td width='4%'></td>
        <td width='36%'></td>
        <td width='3%' style='border-top:1px double'></td>
        <td width='15%' style='border-top:1px double'></td>
        <td width='3%'></td>
        <td width='15%'></td>
        <td width='3%'></td>
        <td width='15%'></td>
    </tr>
    <tr>
        <td></td>
        <td></td>
        <td></td>
        <td>Jumlah</td>
        <td>Rp</td>
        <td align='right'>".number_format($jhutang,0)."</td>
        <td></td>
        <td></td>
    </tr>
</table>

<table width='100%' style='font:12PX arial'>
    <tr>
        <td>Setoran Tunai</td>
    </tr>
</table>

<table width='100%' style='font:12PX arial'>";
    $jkkbank=0;
    $sql=mysql_query("SELECT noakun,naakun,sum(jumlah) as tjumlah FROM jurkk WHERE tanggal BETWEEN '$tglawal' AND '$tglakhir' AND concat(substr(noakun,1,4))='1113' AND kode_cab='$kodecab' AND posting='P' GROUP BY noakun");
    
    while($r=mysql_fetch_array($sql)){
        echo "<tr>
            <td width='4%'></td>
            <td width='36%'>- $r[naakun]</td>
            <td width='3%'>Rp</td>
            <td width='15%'align='right'>".number_format($r['tjumlah'],0)."</td>
            <td width='3%'></td>
            <td width='15%'></td>
            <td width='3%'></td>
            <td width='15%'></td>
        </tr>";
        $jkkbank=$jkkbank+$r['tjumlah'];
    }
    
    $sql=mysql_query("SELECT nobank,namabank,sum(jumlah) as tjumlah FROM jurbm WHERE tanggal BETWEEN '$tglawal' AND '$tglakhir' AND noakun='$kas' AND kode_cab='$kodecab' AND posting='P' GROUP BY nobank");
    while($r=mysql_fetch_array($sql)){
        echo "<tr>
            <td width='4%'></td>
            <td width='36%'>- $r[namabank]</td>
            <td width='3%'>Rp</td>
            <td width='15%'align='right'>".number_format($r['tjumlah'],0)."</td>
            <td width='3%'></td>
            <td width='15%'></td>
            <td width='3%'></td>
            <td width='15%'></td>
        </tr>";
        $jkkbank=$jkkbank+$r['tjumlah'];
    }
    echo "<tr>
        <td width='4%'></td>
        <td width='36%'></td>
        <td width='3%' style='border-top:1px double'></td>
        <td width='15%' style='border-top:1px double'></td>
        <td width='3%'></td>
        <td width='15%'></td>
        <td width='3%'></td>
        <td width='15%'></td>
    </tr>
    <tr>
        <td></td>
        <td></td>
        <td></td>
        <td>Jumlah</td>
        <td>Rp</td>
        <td align='right'>".number_format($jkkbank,0)."</td>
        <td></td>
        <td></td>
    </tr>
</table>

<table width='100%' style='font:12PX arial'>
    <tr>
        <td>Pengeluaran Lainnya</td>
    </tr>
</table>

<table width='100%' style='font:12PX arial'>";
    $sql=mysql_query("SELECT noakun,naakun,sum(jumlah) as tjumlah FROM jurkk WHERE tanggal BETWEEN '$tglawal' AND '$tglakhir' AND !(concat(substr(noakun,1,4))='1113') AND !(concat(substr(noakun,1,3))='211') AND kode_cab='$kodecab' AND posting='P' GROUP BY noakun");
    $jkklain=0;
    while($r=mysql_fetch_array($sql)){
        echo "<tr>
            <td width='4%'></td>
            <td width='36%'>- $r[naakun]</td>
            <td width='3%'>Rp</td>
            <td width='15%'align='right'>".number_format($r['tjumlah'],0)."</td>
            <td width='3%'></td>
            <td width='15%'></td>
            <td width='3%'></td>
            <td width='15%'></td>
        </tr>";
        $jkklain=$jkklain+$r['tjumlah'];
    }
    echo "<tr>
        <td width='4%'></td>
        <td width='36%'></td>
        <td width='3%' style='border-top:1px double'></td>
        <td width='15%' style='border-top:1px double'></td>
        <td width='3%'></td>
        <td width='15%'></td>
        <td width='3%'></td>
        <td width='15%'></td>
    </tr>
    <tr>
        <td></td>
        <td></td>
        <td></td>
        <td>Jumlah</td>
        <td>Rp</td>
        <td align='right'>".number_format($jkklain,0)."</td>
        <td></td>
        <td></td>
    </tr>
</table>

<table width='100%' style='font:12PX arial'>
    <tr>
        <td>Penyesuaian dan Koreksi</td>
    </tr>
</table>

<table width='100%' style='font:12PX arial'>";
    $jkkju=0;
    $sql = mysql_query("SELECT * FROM jurnalum WHERE tanggal BETWEEN '$tglawal' AND '$tglakhir' AND noakun='$kas' AND kode_dk='K' AND posting='P'");
    
    while($r=mysql_fetch_array($sql)){
        echo "<tr>
            <td width='4%'></td>
            <td width='36%'>- $r[keterangan]</td>
            <td width='3%'>Rp</td>
            <td width='15%' align='right'>".number_format($r['kredit'],0)."</td>
            <td width='3%'></td>
            <td width='15%'></td>
            <td width='3%'></td>
            <td width='15%'></td>
        </tr>";
        $jkkju=$jkkju+$r['kredit'];
    }
    echo "<tr>
        <td width='4%'></td>
        <td width='36%'></td>
        <td width='3%' style='border-top:1px double'></td>
        <td width='15%' style='border-top:1px double'></td>
        <td width='3%'></td>
        <td width='15%'></td>
        <td width='3%'></td>
        <td width='15%'></td>
    </tr>
    <tr>
        <td></td>
        <td></td>
        <td></td>
        <td>Jumlah</td>
        <td style='border-bottom:1px double'>Rp</td>
        <td style='border-bottom:1px double' align='right'>".number_format($jkkju,0)."</td>
        <td></td>
        <td></td>
    </tr>
</table>";
$jkk=$beli+$jhutang+$jkkbank+$jkkpkk+$jkklain+$jkkju;
$salakhir=$salakhir-$jkk;

echo "<table width='100%' style='font:12PX arial'>
    <tr>
        <td width='40%'>Jumlah Pengeluaran</td>
        <td width='3%'></td>
        <td width='15%'></td>
        <td width='3%'></td>
        <td width='15%'></td>
        <td width='3%'>Rp</td>
        <td width='15%' align='right'>".number_format($jkk,0)."</td>
        <td width='2%'> -</td>
    </tr>
    <tr>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td style='border-top:1px double'></td>
        <td style='border-top:1px double'></td>
    </tr>
</table>";

$sql1=mysql_query("SELECT * FROM akun_bb WHERE noakun='$kas'");
$r1  =mysql_fetch_assoc($sql1);
$saldo = $r1['saldo']+$r1['mutasi_db']-$r1['mutasi_kd'];
        
$sql= mysql_query("SELECT noakun,sum(debet) as jdebet,sum(kredit) as jkredit FROM rekapjur WHERE tanggal>'$tglakhir' AND noakun='$kas'");
$r  = mysql_fetch_assoc($sql);
$jdebet  = $r['jdebet'];
$jkredit = $r['jkredit'];
$salakhir= $saldo-$jdebet+$jkredit;

echo "<table width='100%' style='font:12PX arial'>
    <tr>
        <td width='79%'><b>SALDO AKHIR</b></td>
        <td width='3%'>Rp</td>
	    <td width='15%' align='right'>".number_format($salakhir,0)."</td>
	    <td width='2%'></td>
    </tr>
</table>
<hr>";
?>