<script type="text/javascript">	
	window.print();
</script>
<?php
	include '../../inc/inc.koneksi.php';	
	include '../../inc/fungsi_tanggal.php';

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

	$tjumlah=0;
	$tdiskon=0;
	$thutang=0;
	$tkurang=0;
	
	if($kasir=='')
		$ckasir='KESELURUHAN';
	else $ckasir='KASIR $kasir';
	
	$sql2= mysql_query("SELECT * FROM company");
	while($r2=mysql_fetch_array($sql2)){
		$kop1 = $r2['nama1'];
		$kop2 = $r2['nama2'];
		$kop3 = $r2['alamat'];
	}
	
	echo "<table width='100%'>
		<tr>
			<td style='font:11px arial;line-height:80%'><b>$kop1</b></td>
		</tr>
		<tr>
			<td style='font:11px arial;line-height:80%'>$kop2</td>
		</tr>
		<tr>
			<td style='font:11px arial;line-height:80%'>$kop3</td>
		</tr>
	</table>

	<table width='100%' >
		<tr>
			<td align='center' style='font:15px arial'><b>DAFTAR PENJUALAN $ckasir</td>
		</tr>
		<tr>
			<td align='center' style='font:15px arial'><b>TANGGAL : ".jin_date_str($tgl_awal)." S/D ".jin_date_str($tgl_akhir)."</b></td>
		</tr>
	</table>
	<br>
	
<table width='100%' border='1' style='border-collapse:collapse;font:11px arial'>
	<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>";
		
	If(!empty($kasir))
		$query1	= "SELECT kode_pj,tanggal,nama_pl,count(kode_st) as totitem,user FROM faktur_pj WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND concat(substr(waktu,12,8)) BETWEEN '11:00:00' AND '15:00:00' AND user LIKE '%$kasir' AND posting='P' AND batal='' GROUP BY kode_pj";
	else $query1= "SELECT kode_pj,tanggal,nama_pl,count(kode_st) as totitem,user FROM faktur_pj WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND concat(substr(waktu,12,8)) BETWEEN '11:00:00' AND '15:00:00' AND posting='P' AND batal='' GROUP BY kode_pj";	
	$data1	= mysql_query($query1);
	
	$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_pj 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>";
?>