<script type="text/javascript">	
	window.print();
</script>

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

    session_start();
    
	$bulanaw= $_GET['bulanaw'];
    $bulanak= $_GET['bulanak'];
    $tahun  = $_GET['tahun'];
    $kodesp = $_GET['kodesp'];
	$namasp = $_GET['namasp'];
    $kodegr = $_GET['kodegr'];
    $namagr = $_GET['namagr'];
    $cari   = $_GET['cari'];
    $user   = $_SESSION['namauser'];
    $nafile = 'pbpj_'.$user;
    
    if($bulanaw=='01') $cblaw='JANUARI';
    else if($bulanaw=='02') $cblaw='FEBRUARI';
    else if($bulanaw=='03') $cblaw='MARET';
    else if($bulanaw=='04') $cblaw='APRIL';
    else if($bulanaw=='05') $cblaw='MEI';
    else if($bulanaw=='06') $cblaw='JUNI';
    else if($bulanaw=='07') $cblaw='JULI';
    else if($bulanaw=='08') $cblaw='AGUSTUS';
    else if($bulanaw=='09') $cblaw='SEPTEMBER';
    else if($bulanaw=='10') $cblaw='OKTOBER';
    else if($bulanaw=='11') $cblaw='NOVEMBER';
    else if($bulanaw=='12') $cblaw='DESEMBER';
    
    if($bulanak=='01') $cblak='JANUARI';
    else if($bulanak=='02') $cblak='FEBRUARI';
    else if($bulanak=='03') $cblak='MARET';
    else if($bulanak=='04') $cblak='APRIL';
    else if($bulanak=='05') $cblak='MEI';
    else if($bulanak=='06') $cblak='JUNI';
    else if($bulanak=='07') $cblak='JULI';
    else if($bulanak=='08') $cblak='AGUSTUS';
    else if($bulanak=='09') $cblak='SEPTEMBER';
    else if($bulanak=='10') $cblak='OKTOBER';
    else if($bulanak=='11') $cblak='NOVEMBER';
    else if($bulanak=='12') $cblak='DESEMBER';
    
    $query2 = mysql_query("SELECT * FROM company");
	$r2		= mysql_fetch_assoc($query2);
	$kop1 	= $r2['nama1'];
	$kop2 	= $r2['nama2'];
	$kop3 	= $r2['alamat'];
	
	echo "<table width='100%'>
		<tr>
			<td style='font:12px Verdana'>$kop1</td> 
		</tr>
		<tr>
			<td style='font:12px Verdana'>$kop2</td>
		</tr>
		<tr>
			<td style='font:12px Verdana'>$kop3</td>
		</tr>
	</table>
	<br>
	<table width='100%'>
	    <tr>
	        <td align='center' style='font:14px Verdana'><b>ANALISA PEMBELIAN DAN PENJUALAN</b></td>
	    </tr>
	    <tr>
		    <td align='center' style='font:14px Verdana'><b>BULAN : $cblaw SAMPAI DENGAN $cblak $tahun</b></td>
        </tr>";
        
        if(!$cari==''){
            echo "<tr>
                <td align='center' style='font:14px Verdana'><b>PENCARIAN $cari</b></td>
            </tr>";
        }
        if(!$kodegr==''){
            echo "<tr>
                <td align='center' style='font:14px Verdana'><b>KELOMPOK : $namagr</b></td>
            </tr>";
        }
        if(!$kodesp==''){
            echo "<tr>
                <td align='center' style='font:14px Verdana'><b>SUPPLIER : $namasp</b></td>
            </tr>";
        }
    echo "</table>
    <br>
    
<table width='100%' border='1' style='border-collapse:collapse;font:12px verdana'>
	<tr>
		<th>No.</th>
		<th>Bulan</th>
		<th>Pembelian</th>
		<th>Penjualan</th>
		<th>Surplus/ Devisit</th>
		<th>Prosen</th>
	</tr>";
	$sql=mysql_query("SELECT * FROM $nafile WHERE 1");

	$tbeli=0;$tjual=0;$tsurpdev=0;
	$no=1;
	while($r=mysql_fetch_array($sql)){
	    echo "<tr>
    		<td align='center'>$no</td>
    		<td align='right'>$r[bulan]</td>
		    <td align='right'>".number_format($r['pembelian'])."</td>
		    <td align='right'>".number_format($r['penjualan'])."</td>
		    <td align='right'>".number_format($r['surpdev'])."</td>
    		<td align='right'>".number_format($r['prosen'],2)."</td>
		</tr>";
		$tbeli=$tbeli+$r['pembelian'];
		$tjual=$tjual+$r['penjualan'];
		$tsurpdev=$tsurpdev+$r['surpdev'];
		$no++;
	}
	$tprosen=$tsurpdev/$tbeli;
	
	echo "<tr>
		<td></td>
	    <td align='right'>Total</td>
		<td align='right'>".number_format($tbeli)."</td>
		<td align='right'>".number_format($tjual)."</td>
		<td align='right'>".number_format($tsurpdev)."</td>
    	<td align='right'>".number_format($tprosen,2)."</td>
	</tr>
</table>";
?>