<?php
include '../../inc/inc.koneksi.php';
$tanggal = $_POST[tanggal];

$text	= "SELECT kode_pj,tanggal,sum(jumlah) as tjumlah,sum(bayar) as tbayar FROM faktur_pj WHERE tanggal= '$tanggal' AND batal='' GROUP BY kode_pj";
$sql 	= mysql_query($text);
$tjual 	= 0;
while($r=mysql_fetch_array($sql)){
	if(tbayar>tjumlah)
		tjual=tjual+tjumlah;
	else
		tjual=tjual+tbayar;
}

$text	= "SELECT * FROM faktur_pb WHERE tanggal= '$tanggal' AND batal=''";
$sql 	= mysql_query($text);
$tbeli	=0;
while($r=mysql_fetch_array($sql)){
	$tbeli=$tbeli+$r[bayar];
}

echo "<table>
		<tr>
			<td><b>PENERIMAAN :</b></td>
		</tr>
		<tr>
			<td>- Penjualan Tunai</td>
			<td>:</td>
			<td>Rp</td>
			<td align='right'>".number_format($tjual,0)."</td>
		</tr>

		<tr>
			<td>- Penerimaan Piutang :</td>
		</tr>";
		
		$sql = "SELECT * FROM jurppi WHERE tanggal='$tanggal'";
		$query = mysql_query($sql);
		
		$tppi=0;
		while($r_data=mysql_fetch_array($query)){
			echo "<tr>
				<td></td>
				<td>- $r_data[nama_pl]</td>
				<td>Rp</td>
				<td align='right'>".number_format($r_data[dibayar],0)."</td>
			</tr>";
			$tppi=$tppi+$r_data[dibayar];
		}
		$tkm=$tjual+$tppi;
		
	echo "<tr>
			<td>Total Penerimaan</td>
			<td>:</td>
			<td>Rp</td>
			<td align='right'>".number_format($tkm,0)."</td>
		</tr>
		<br>
		
		<tr>
			<td>PENGELUARAN :</td>
		</tr>
		<tr>
			<td>- Pembelian Tunai</td>
			<td>:</td>
			<td>Rp</td>
			<td>".number_format($tbeli,0)."</td>
		</tr>
		
		<tr>
			<td>- Penerimaan Piutang :</td>
		</tr>";
		
		$sql = "SELECT * FROM jurpht WHERE tanggal='$tanggal'";
		$query = mysql_query($sql);
		
		$tpbu=0;
		while($r_data=mysql_fetch_array($query)){
			echo "<tr>
				<td></td>
				<td>- $r_data[nama_sp]</td>
				<td>Rp</td>
				<td align='right'>".number_format($r_data[dibayar],0)."</td>
			</tr>";
			$tpbu=$tpbu+$r_data[dibayar];
		}
		$tkk=$tbeli+$tpbu;
		$saldo=$tkm-$tkk;
		
		echo "<tr>
			<td>Total Pengeluaran</td>
			<td>:</td>
			<td style='border-bottom:single'>Rp</td>
			<td style='border-bottom:single' align='right'>".number_format($tkk,0)."</td>
		</tr>
		
		<tr>
			<td>Sisa Kas</td>
			<td>:</td>
			<td style='border-bottom:double'>Rp</td>
			<td style='border-bottom:double' align='right'>".number_format($saldo,0)."</td>
		</tr>
	</table>";
?>