<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';

$tgl_awal= $_GET['tgl_awal'];
$tgl_akhir= $_GET['tgl_akhir'];

echo "<div id='info'>
<table id='theList' width='100%'>
	<tr>
		<th>No.</th>
		<th>Kode</th>
		<th>Nama Barang</th>
		<th>Barcode</th>
		<th>Satuan</th>
		<th>Jumlah Unit</th>
		<th>Harga Jual</th>
		<th>Disc. Momen</th>
		<th>Total Harga</th>
	</tr>";
	$data1	= mysql_query("SELECT kode_pj,tanggal,nama_pl,jenis_by,nobank,jenis_kt,nokartu,count(kode_st) as totitem,user FROM faktur_pjt WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND posting='P' AND batal='' GROUP BY kode_pj");
	
	$tjumlah=0;
	$tpotong=0;
	$tedc=0;
	$tcharge=0;
	
	while($r1=mysql_fetch_array($data1)){
		$kodepj=$r1['kode_pj'];
		$jenisby=$r1['jenis_by'];
		$nobank=$r1['nobank'];
		$jeniskt=$r1['jenis_kt'];
		$nokartu=$r1['nokartu'];

		echo "<tr>				
			<td align='center'><b>Faktur</b></td>
			<td><b>$r1[kode_pj]</b></td>				
			<td align='center'><b>".jin_date_str($r1['tanggal'])."</b></td>
			<td><b>Kasir : $r1[user]</b></td>
			<td><b>Pelanggan : $r1[nama_pl]</b></td>
		</tr>";
		$query = mysql_query("SELECT * FROM faktur_pjt WHERE kode_pj='$kodepj' ");
		
		$no=1;
		$sjumlah=0;
		$spotong=0;
		$sedc=0;
		$scharge=0;
		while($r=mysql_fetch_array($query)){
			
			echo "<tr>
				<td align='center'>$no</td>
				<td align='center'>$r[kode_st]</td>
				<td>$r[nama_st]</td>
				<td>$r[barcode]</td>
				<td align='center'>$r[satuan]</td>
				<td align='right'>$r[jml_unit]</td>
				<td align='right'>".number_format($r['hg_jual'])."</td>
				<td align='center'>".number_format($r['disc_mm'])." %</td>
				<td align='right'>".number_format($r['jumlah'])."</td>
			</tr>";
			$sjumlah	=$sjumlah+$r['jumlah'];
			$spotong	=$spotong+$r['potongan'];
			$sbayar	=$sbayar+$r['bayar'];
			
			if($jenisby=='EDC') $scharge=$scharge+$r['charge_edc'];
		
			$no++;			
		}
		$netto=$sjumlah-$spotong;
		
		if($jenisby=='EDC') $sedc=$netto;
			
		echo "<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td align='right'>Jumlah</td>
			<td align='right'>".number_format($sjumlah)."</td>
		</tr>
		<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td align='right'>Potongan</td>
			<td align='right'>".number_format($spotong)."</td>
		</tr>
		<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>			
			<td align='right'>Netto</td>
			<td align='right'>".number_format($netto)."</td>
		</tr>
		<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td align='right'>Pembayaran</td>
			<td>$jenisby</td>
		</tr>";
			
		if($jenisby=='EDC'){
			echo "<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td align='right'>Rekening EDC</td>
				<td>$nobank</td>
			</tr>
			<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td align='right'>Jenis Kartu</td>
				<td>$nobank</td>
			</tr>
			<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td align='right'>Nomor Kartu</td>
				<td>$nokartu</td>
			</tr>
			<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>				
				<td align='right'>Charge EDC</td>
				<td align='right'>".number_format($scharge)."</td>
			</tr>";
		}
		$tjumlah=$tjumlah+$sjumlah;
		$tedc   =$tedc+$sedc;
		$tcharge=$tcharge+$scharge;
		$tpotong=$tpotong+$spotong;
	}
	$ttunai=$tjumlah-$tedc;
	$tsetor=$ttunai+$tcharge;
	$tnetto=$tjumlah-$tpotong;
	
	echo "<tr></tr>
	<tr>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td align='right'>Total</td>
		<td align='right'>".number_format($tjumlah)."</td>
	</tr>
	<tr>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td align='right'>Potongan</td>
		<td align='right'>".number_format($tpotong)."</td>
	</tr>
	<tr>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td align='right'>Netto</td>
		<td align='right'>".number_format($tnetto)."</td>
	</tr>
	<tr>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td align='right'>Tunai</td>
		<td align='right'>".number_format($ttunai)."</td>
	</tr>
	<tr>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td align='right'>EDC</td>
		<td align='right'>".number_format($tedc)."</td>
	</tr>
	<tr>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td align='right'>Charge EDC</td>
		<td align='right'>".number_format($tcharge)."</td>
	</tr>
	<tr>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td></td>
		<td align='right'>Total Setoran</td>
		<td align='right'>".number_format($tsetor)."</td>
	</tr>
</table>
</div>";
?>