<?php 
session_start();
error_reporting(0);
  include "../config/koneksi.php";
  include "../config/fungsi_indotgl.php";
  include "../config/library.php";
  include "../config/fungsi_rupiah.php";
$sqle=mysql_query("SELECT * FROM rb_kategori_produk where id_kategori='$_GET[id]'");
$p=mysql_fetch_array($sqle); 
if ($_SESSION[leveluser]=='karyawan' AND $_SESSION[status]=='biasa'){
    $status = 'kasir';
}elseif ($_SESSION[leveluser]=='karyawan' AND $_SESSION[status]=='grosir'){
    $status = 'grosir';
}elseif ($_SESSION[leveluser]=='admin' AND $_SESSION[status]=='biasa'){
    $status = 'admin';
}
$cekp = mysql_num_rows(mysql_query("SELECT * FROM rb_kategori_produk where nama_kategori LIKE '%pesanan%' AND id_kategori='$_GET[id]'"));
?>
<head>
<title>Print - Data Semua <?php echo "$p[nama_kategori]"; ?></title>
</head>
<style>
.input1 {
	height: 20px;
	font-size: 12px;
	padding-left: 5px;
	margin: 5px 0px 0px 5px;
	width: 97%;
	border: none;
	color: red;
}
table {
	border: 1px solid #cecece;
}
td {
	border: 1px solid #cecece;
}
</style>
<body onload="window.print()">
<?php 
  
echo "<center><h2 style='margin-bottom:0px;'>LAPORAN SEMUA DATA <span style='text-transform:uppercase;'>$p[nama_kategori]</span></h2>
Jl.K.H. Ahmad Dahlan No 140 B Solok, No Telephone : (0755) 21060, Sumatra Barat
</center><hr/><br/>";
    echo "<table border='1' cellspacing='0' cellpadding=10 width=100%>
          <tr>
			<th>kode</th>
			<th>Nama Produk</th>
			<th>Nama Distributor</th>
			<th width='100px'>Harga Jual</th>";
			if ($status == 'grosir' OR $status == 'admin'){
				echo "<th width='100px'>Harga Grosir</th>";
			}
			if ($status == 'admin'){
				echo "<th width='100px'>Harga Distributor</th>
					  <th width='100px'>Harga Modal</th>";
			}
			if ($cekp <= 0){
				echo "<th>Stok</th>";
			}
			if ($status == 'admin'){
				echo "<th width='100px'>Total Modal</th>";
			}
			echo "
		   </tr>";
    
	$tampil = mysql_query("SELECT * FROM rb_produk left join rb_supplier on rb_produk.id_supplier=rb_supplier.id_supplier where id_kategori='$_GET[id]' ORDER BY id_produk DESC");
		$no=1;
    while($r=mysql_fetch_array($tampil)){
      $tanggal=tgl_indo($r[tgl_masuk]);
      $harga=format_rupiah($r[harga]);
	  $harga_grosir=format_rupiah($r[harga_grosir]);
	  $harga_pokok=format_rupiah($r[harga_pokok]);
	  $harga_distributor=format_rupiah($r[harga_distributor]);
	  
	  $totpokok=$r[harga_pokok]*$r[stok];
	  $totpokok_rp=format_rupiah($totpokok);
	  if(($no % 2)==0){
			$warna="#ffffff";
		  }
		  else{
			$warna="#E1E1E1";
		  }
      echo "
		<tr bgcolor='$warna'>
			<td class='read_only' style='color:blue'>$r[kode_produk]</td>
            <td>$r[nama_produk]</td>
			<td>$r[nama_supplier]</td>
            <td>Rp $harga</td>";
            if ($status == 'grosir' OR $status == 'admin'){
				echo "<td>Rp $harga_grosir</td>";
			}
			if ($status == 'admin'){
				echo "<td>Rp $harga_distributor</td>
					  <td>Rp $harga_pokok</td>";
			}
			if ($cekp <= 0){
				if ($r[stok]==0){
					echo "<td style='background:red; color:#fff; text-align:center;'>0</td>";
				}elseif ($r[stok]<=$r[warning]){
					echo "<td style='background:#f6c51c; color:#fff; text-align:center;'>$r[stok]</td>";
				}else{
					echo "<td style='text-align:center'>$r[stok]</td>";
				}
			}
			if ($status == 'admin'){
		        echo "<td>Rp $totpokok_rp</td>";
		    }
			
		echo "</tr>";
      $no++;
    }
    echo "</table>";
?>