<?php
include_once "library/inc.sesadmin.php";
include_once "library/inc.library.php";
include_once "library/inc.connection.php";

$SqlPeriode = ""; $startTgl=""; $endTgl="";

# Set Tanggal skrg
$tglStart 	= isset($_POST['cmbTglStart']) ? $_POST['cmbTglStart'] : date('d-m-Y');
$tglEnd 	= isset($_POST['cmbTglEnd']) ? $_POST['cmbTglEnd'] : date('d-m-Y');

# Jika Nomor Page (halaman) diklik
if($_GET) {
	if (isset($_POST['btnShow'])) {
		$SqlPeriode = "AND ( transaksi.tgl_transaksi BETWEEN '".InggrisTgl($_POST['cmbTglStart'])."' AND '".InggrisTgl($_POST['cmbTglEnd'])."')";
	}
	else {
		$startTgl 	= isset($_GET['startTgl']) ? $_GET['startTgl'] : $tglStart;
		$endTgl 	= isset($_GET['endTgl']) ? $_GET['endTgl'] : $tglEnd; 
		$SqlPeriode = " AND ( transaksi.tgl_transaksi BETWEEN '".InggrisTgl($startTgl)."' AND '".InggrisTgl($endTgl)."')";
	}
}

# UNTUK PAGING (PEMBAGIAN HALAMAN)
$row = 20;
$hal = isset($_GET['hal']) ? $_GET['hal'] : 0;
$pageSql = "SELECT transaksi.tgl_transaksi, transaksi_item.*, siswa.nama_siswa 
			 FROM transaksi, transaksi_item, siswa
			 WHERE transaksi.no_transaksi = transaksi_item.no_transaksi
			 AND transaksi_item.nis 	 = siswa.nis 	$SqlPeriode ";
$pageQry = mysql_query($pageSql, $koneksidb) or die ("error paging: ".mysql_error());
$jml	 = mysql_num_rows($pageQry);
$max	 = ceil($jml/$row);
?>
<form action="?page=Rekap-Transaksi" method="post" name="form1" target="_self" id="form1">
  <table width="850" border="0"  class="table-list">
    <tr>
      <td colspan="3" align="center" Style="font-size:25px;">REKAP TRANSAKSI HARIAN </td>
    </tr>
    <tr>
      <td width="300" align="right"><strong>Periode </strong></td>
      <td width="5"><strong>:</strong></td>
      <td width="500"><?php echo form_tanggal("cmbTglStart",$tglStart); ?> s/d <?php echo form_tanggal("cmbTglEnd",$tglEnd); ?>
      <input name="btnShow" type="submit" value=" Tampilkan " /></td>
    </tr>
  </table>
</form>
<table class="table-list" width="850" border="1" cellspacing="0" cellpadding="2">
  <tr>
    <td width="20" align="center" bgcolor="#CCCCCC"><b>NO</b></td>
    <td width="40" align="center" bgcolor="#CCCCCC"><strong>TANGGAL</strong></td>
    <td width="40" align="center" bgcolor="#CCCCCC"><b>NIS</b></td>
    <td width="175" align="center" bgcolor="#CCCCCC"><b>NAMA</b></td>  
    <td width="125" align="center" bgcolor="#CCCCCC"><b>PEMBAYARAN</b></td>
    <td width="50" align="center" bgcolor="#CCCCCC"><b>BANYAK</b></td>
    <td width="50" align="center" bgcolor="#CCCCCC"><b>PENERIMA</b></td>
  </tr>
	<?php
	# Query utama. Query ini sama dg yg dipakai Paging di atas
	$dataSql = "SELECT transaksi.tgl_transaksi, transaksi.userid, transaksi_item.*, siswa.nama_siswa, bulan.keterangan 	
			 FROM transaksi, transaksi_item, siswa, bulan
			 WHERE transaksi.no_transaksi = transaksi_item.no_transaksi AND transaksi_item.kode_bayar=bulan.kode
			 AND transaksi_item.nis 	 = siswa.nis 	$SqlPeriode 
				ORDER BY transaksi.tgl_transaksi, siswa.nis, transaksi_item.kode_bayar ASC";
	$dataQry = mysql_query($dataSql, $koneksidb) or die ("Error Query".mysql_error());
	$nomor = 0; $totalBayar = 0;
	while ($dataRow = mysql_fetch_array($dataQry)) {
		$totalBayar = $totalBayar + intval($dataRow['banyak']);
		$nomor++;
	?>
  <tr>
    <td align="center"><?php echo $nomor; ?></td>
    <td align="center"><?php echo IndonesiaTgl($dataRow['tgl_transaksi']); ?></td>
    <td align="center"><?php echo $dataRow['nis']; ?></td>
    <td align="left"><?php echo $dataRow['nama_siswa']; ?></td>
    <td align="left"><?php echo $dataRow['keterangan']; ?></td>
    <td align="right"><?php echo format_angka($dataRow['banyak']); ?></td>
    <td align="center"><?php echo $dataRow['userid']; ?></td>
  </tr>
  
  <?php } ?>
  
  <tr>
    <td colspan="5" align="right"><b>JUMLAH PEMASUKAN     :</b> </td>
	<td align="right"><?php echo format_angka($totalBayar); ?></td>
	<td align="center" bgcolor="#FFFFCC"><a href="?page=Rekap-Transaksi-Cetak&mulai=<?php echo $tglStart; ?>&sampai=<?php echo $tglEnd; ?>" target="_self"><img src="images/print.png" width="40" height="25" border="0" /></a></td>
  </tr>
</table>
