<?php
include "../config/session_admin.php";
include "transaksi/eceran.php";
include "transaksi/hutang.php";
include "transaksi/hutang-grosir.php";
include "transaksi/grosir.php";
include "master/rb_user.php";
include "master/rb_lensa.php";
include "master/rb_instansi.php";
include "master/rb_dokter.php";
include "master/rb_sales.php";
include "master/rb_kategori_produk.php";
include "master/rb_supplier.php";
include "master/rb_data_optik.php";
include "master/rb_produk.php";
include "laporan/penjualan_eceran.php";
include "laporan/penjualan_grosir.php";
include "laporan/rekap_eceran_karyawan.php";
include "laporan/rekap_grosir_karyawan.php";
include "laporan/pemesanan_eceran.php";
include "laporan/pemesanan_grosir.php";
include "laporan/pembelian.php";
include "laporan/kas.php";
include "laporan/kas_tahunan.php";
include "laporan/rekap_dokter.php";
include "laporan/rekap_instansi.php";
include "laporan/laporan_pesanan.php";

if ($_GET[module]=='home'){
	echo "<div class='post_title' style='margin-bottom:10px; position:relative;'><b>Selamat Datang $_SESSION[namalengkap] : Berikut Daftar Produk yang Hampir habis dan Habis. <hr></b></div>";

	echo " <div id='container'>
			<div id='demo'>
<table class='display' id='example'>
	<thead>
		<tr><th>No</th>
			<th width=80px>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>";
			}
			echo "<th>Stok</th>
			<th style='text-align:center;'>Action</th>
		</tr>
	</thead>
	<tfoot>
		<tr style='border: 2px solid #e3e3e3;'>
			<th style='border: none;'>No</th>
			<th style='border: none;'>Kode</th>
			<th style='border: none;'>Nama Produk</th>
			<th style='border: none;'>Nama Distributor</th>
			<th style='border: none;'>Harga Jual</th>";
			if ($status == 'grosir' OR $status == 'admin'){
				echo "<th style='border: none;'>Harga Grosir</th>";
			}
			if ($status == 'admin'){
				echo "<th style='border: none;'>Harga Distributor</th>
					  <th style='border: none;'>Harga Modal</th>";
			}
			echo "<th style='border: none;'>Stok</th>
			<th style='border: none;'></th>
		</tr>
	</tfoot>";
	    $tampil = mysql_query("SELECT * FROM rb_produk left join rb_supplier on rb_produk.id_supplier=rb_supplier.id_supplier left JOIN rb_kategori_produk ON rb_produk.id_kategori=rb_kategori_produk.id_kategori where warning>=stok AND rb_kategori_produk.pesanan='Tidak' ORDER BY kode_produk DESC LIMIT 300");
$no = $posisi+1;
		echo "<tbody>";
    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]);
	  if(($no % 2)==0){
			$warna="#ffffff";
		  }
		  else{
			$warna="#E1E1E1";
		  }
	echo "
		<tr bgcolor='$warna'>
			<td class='read_only'>$no</td>
			<td style='color:blue'>$r[kode_produk]</td>";
			$cekd = mysql_num_rows(mysql_query("SELECT * FROM rb_produk_detail where id_produk='$r[id_produk]'"));
			if ($cekd >= 1){
				$d = mysql_fetch_array(mysql_query("SELECT * FROM rb_produk_detail a 
													join rb_jenis b on a.id_jenis=b.id_jenis
	    												join rb_type c on a.id_type=c.id_type where a.id_produk='$r[id_produk]'"));
            	echo "<td class='linkSysteM'><a href='#' alt='Type : $d[type] - Jenis : $d[jenis]'>$r[nama_produk]</a></td>";
			}else{
				echo "<td>$r[nama_produk]</td>";
			}
			echo "<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 ($r[stok]==0){
				echo "<td style='background:red; color:#fff; text-align:center;'>Habis</td>";
			}else{
				echo "<td style='background:#f6c51c; color:#fff; text-align:center;'>$r[stok]</td>";
			}
		            echo "<td width='90'><center><a class='linkkk' href='edit-produk-$r[id_produk].html'>Edit</a>
		                <a class='linkkk' style='color:red' href='hapus-produk-$r[id_produk].html' onclick=\"return confirm('Anda yakin ingin hapus data ini?')\">X</a></center></td>
		</tr>";
		$no++;
		}
echo "	</tbody>
 </table>
</div></div>";
}

elseif ($_GET[module]=='karyawanlapproduk'){
	$filter = $_POST[tahun].'-'.$_POST[bulan];
	$bulan = Bulan($_POST[bulan]);
	echo "<div class='post_title' style='margin-bottom:10px; position:relative;'><b>Laporan Barang Terjual (Eceran) oleh <span style='color:red'>$_POST[karyawan]</span> pada : <span style='color:red;'>$bulan - $_POST[tahun]</span><hr></b></div>
	
			<span style='float:left;'>
					Filter Karyawan : ";?><select style=' margin-right:3px; margin-bottom:5px;' ONCHANGE="location = this.options[this.selectedIndex].value;">
					<?php echo "<option value=0 selected> $_POST[karyawan] </option>";
						$tampil=mysql_query("SELECT username FROM rb_users where level='karyawan' ORDER BY username DESC");
						while($r=mysql_fetch_array($tampil)){
						echo "<option value='filterr-$r[username].html'>$r[username]</option>";
						}
			  echo "</select>";
			  ?><select style=' margin-right:3px; margin-bottom:5px;' ONCHANGE="location = this.options[this.selectedIndex].value;">
					<?php echo "<option value=0 selected>- Pilih Jenis Produk -</option>";
						$tampil=mysql_query("SELECT * FROM rb_kategori_produk ORDER BY nama_kategori");
						while($r=mysql_fetch_array($tampil)){
						echo "<option value='filterrrr-$r[id_kategori].html'>$r[nama_kategori]</option>";
						}
			  echo "</select>
			  </span>
			
				<span style='float:right; margin-right:0px;'>
					<form method=POST action='karyawan-tanggal.html'>
					<input type='hidden' name='karyawan' value='$_POST[karyawan]'>
							Periode : <select name='bulan'>
									<option value='$_POST[bulan]' selected>$bulan</option>";
									$tampil=mysql_query("SELECT substring(tanggal_pesan,6,2) as bulan FROM rb_orders GROUP BY substring(tanggal_pesan,6,2)");
									while($r=mysql_fetch_array($tampil)){
									$bulan = Bulan($r[bulan]);
									  echo "<option value=$r[bulan]>$bulan</option>";
									}	
							echo "</select>
							<select name='tahun'>
									<option value='$_POST[tahun]' selected>$_POST[tahun]</option>";
									$tampil=mysql_query("SELECT substring(tanggal_pesan,1,4) as tahun FROM rb_orders GROUP BY substring(tanggal_pesan,1,4)");
									while($r=mysql_fetch_array($tampil)){
									  echo "<option value=$r[tahun]>$r[tahun]</option>";
									}
							echo "</select>
						<input type='submit' class='submitt' value='View'>
						<a style='font-size:12px; text-decoration:none;' class='submitt' href='laporan-terjual.html'>All Periode</a>
					</form>
				</span>
			
			<div id='container'>
			<div id='demo'>
<table class='display' id='example'>
	<thead>
		<tr>
			<th>No</th>
			<th>Nama Barang</th>
			<th>Harga Jual</th>
			<th>Jumlah</th>
			<th>Sub Total</th>
			<th>Diskon</th>
			<th>Total Jual Bersih</th>
			<th>Harga Modal</th>
			<th>Tanggal Terjual</th>
			<th>Karyawan</th>
			<th>Keuntungan</th>
		</tr>
	</thead>
	<tfoot>
		<tr style='border: 2px solid #e3e3e3;'>
			<th style='border: none;'>No</th>
			<th style='border: none;'>Nama Barang</th>
			<th style='border: none;'>Harga Jual</th>
			<th style='border: none;'>Jumlah</th>
			<th style='border: none;'>Sub Total</th>
			<th style='border: none;'>Diskon</th>
			<th style='border: none;'>Total Jual Bersih</th>
			<th style='border: none;'>Harga Modal</th>
			<th style='border: none;'>Tanggal Terjual</th>
			<th style='border: none;'>Karyawan</th>
			<th style='border: none;'>Keuntungan</th>
		</tr>
	</tfoot>";
	$no=1;
	    $tampill=mysql_query("SELECT * FROM rb_orders_detail 
								left join rb_produk on rb_orders_detail.id_produk=rb_produk.id_produk 
									left join rb_orders on rb_orders_detail.id_orders=rb_orders.id_orders 
										where rb_orders_detail.id_orders like 'E%' AND rb_orders.tanggal_pesan like '$filter%' AND karyawan='$_POST[karyawan]'
											ORDER BY rb_orders_detail.id_orders");
		echo "<tbody>";
    while($r=mysql_fetch_array($tampill)){
		$tanggal_pesan=tgl_indo($r[tanggal_pesan]);
		$subtotal=$r[harga]*$r[jumlah];
		$subtotal2=$r[harga_pokok]*$r[jumlah];
		$diskon   = $r[diskon]/100 * $subtotal;
		$subtotall=$subtotal-$diskon;
		$untung=$subtotall-$subtotal2;
		$harga_pokok = format_rupiah($r[harga_pokok]);
		$harga = format_rupiah($r[harga]);
		$diskon_rp = format_rupiah($diskon);
		$untung_rp = format_rupiah($untung);
		$subtotall_rp = format_rupiah($subtotal);
		$subtotal_rp = format_rupiah($subtotall);
		
	  if(($no % 2)==0){
			$warna="#E1E1E1";
		  }
		  else{
			$warna="#ffffff";
		  }
	echo "
		<tr bgcolor='$warna'>
			<td class='read_only' style='color:blue; height:27px;'>$no</td>";
			if ($r[id_kategori]==13){
            echo "<td class='linkSysteM'><a href='#' alt='Type : $r[type] | Jenis : $r[jenis] | Ukuran : $r[ukuran]'>$r[nama_produk]</a></td>";
			}else{
			echo "<td>$r[nama_produk]</td>";
			}
			echo "<td>Rp $harga</td>
            <td>$r[jumlah]</td>
			<td>Rp $subtotall_rp</td>
			<td>$r[diskon] % (Rp $diskon_rp)</td>
			<td>Rp $subtotal_rp</td>
			<td>Rp $harga_pokok</td>
			<td>$rtanggal_pesan</td>
			<td><span style='text-transform:capitalize;'>$r[karyawan]</span></td>
			<td style=' font-weight:bold;'>Rp $untung_rp</td>
		</tr>";
		$no++;
		}
		
				$sql = "SELECT SUM(harga*jumlah) AS total_harga,
								SUM(harga*jumlah*diskon/100) AS total_diskon,
						SUM(harga_pokok*jumlah) AS total_pokok,
						SUM(jumlah) AS total_jumlah FROM rb_orders_detail
								left join rb_produk on rb_orders_detail.id_produk=rb_produk.id_produk 
									left join rb_orders on rb_orders_detail.id_orders=rb_orders.id_orders
										where rb_orders_detail.id_orders like 'E%' AND rb_orders.tanggal_pesan like '$filter%' AND karyawan='$_POST[karyawan]'";
										
		$result = mysql_query($sql) or die (mysql_error());
		$t = mysql_fetch_array($result);
		 $total_harga=format_rupiah($t[total_harga]);
		 $total_pokok=format_rupiah($t[total_pokok]);
		 $total_jumlah=format_rupiah($t[total_jumlah]);
		 $total_diskon=format_rupiah($t[total_diskon]);
		 $total_jual=$t[total_harga]-$t[total_diskon];
		 
		 $total_jual_rp=format_rupiah($total_jual);
		 $untung=$total_jual-$t[total_pokok];
		 $untung_rp=format_rupiah($untung);
	echo "
		<tr bgcolor='$warna'>
			<td class='read_only' style='background:$warna; color:$warna; height:27px;'>X</td>
			<td style='text-align:center; color:red; font-weight:bold;'>T o t a l</td>
            <td style='color:red;'></td>
            <td style='color:red;'>$total_jumlah</td>
			<td style='color:red;'>Rp $total_harga</td>
			<td style='color:red;'>Rp $total_diskon</td>
			<td style='color:red;'>Rp $total_jual_rp</td>
			<td style='color:red;'>Rp $total_pokok</td>
			<td></td>
			<td></td>
			<td style='color:red; font-weight:bold;'>Rp $untung_rp</td>
		</tr>";
echo "	</tbody>
 </table>
</div></div>";
}

elseif ($_GET[module]=='kategorikaryawanlapproduk'){
	$filter = $_POST[tahun].'-'.$_POST[bulan];
	$bulan = Bulan($_POST[bulan]);
	
	$sqle=mysql_query("SELECT * FROM rb_kategori_produk where id_kategori='$_POST[kategori]'");
	$pp=mysql_fetch_array($sqle);
	echo "<div class='post_title' style='margin-bottom:10px; position:relative;'><b>Laporan <span style='color:red'>$pp[nama_kategori]</span> Terjual (Eceran) Oleh <span style='color:red'>$_POST[karyawan]</span> pada : <span style='color:red;'>$bulan - $_POST[tahun]</span><hr></b></div>
	
			<span style='float:left;'>
					Filter Karyawan : ";
					?><select style=' margin-right:3px; margin-bottom:5px;' ONCHANGE="location = this.options[this.selectedIndex].value;">
					<?php echo "<option value=0 selected> $_POST[karyawan] </option>";
						$tampil=mysql_query("SELECT username FROM rb_users where level='karyawan' ORDER BY username DESC");
						while($r=mysql_fetch_array($tampil)){
						echo "<option value='filterr-$r[username].html'>$r[username]</option>";
						}
			  echo "</select>";
					?><select style=' margin-right:3px; margin-bottom:5px;' ONCHANGE="location = this.options[this.selectedIndex].value;">
					<?php echo "<option value=0 selected> $pp[nama_kategori] </option>";
						$tampil=mysql_query("SELECT * FROM rb_kategori_produk ORDER BY nama_kategori");
						while($r=mysql_fetch_array($tampil)){
						echo "<option value='filterrr-$_GET[username]-$r[id_kategori].html'>$r[nama_kategori]</option>";
						}
			  echo "</select></span>
			
				<span style='float:right; margin-right:0px;'>
					<form method=POST action='kategori-karyawan-tanggal.html'>
						<input type=hidden name='kategori' value='$_POST[kategori]'>
						<input type=hidden name='karyawan' value='$_POST[karyawan]'>
							Periode : <select name='bulan'>
									<option value='$_POST[bulan]' selected>$bulan</option>";
									$tampil=mysql_query("SELECT substring(tanggal_pesan,6,2) as bulan FROM rb_orders GROUP BY substring(tanggal_pesan,6,2)");
									while($r=mysql_fetch_array($tampil)){
									$bulan = Bulan($r[bulan]);
									  echo "<option value=$r[bulan]>$bulan</option>";
									}	
							echo "</select>
							<select name='tahun'>
									<option value='$_POST[tahun]' selected>$_POST[tahun]</option>";
									$tampil=mysql_query("SELECT substring(tanggal_pesan,1,4) as tahun FROM rb_orders GROUP BY substring(tanggal_pesan,1,4)");
									while($r=mysql_fetch_array($tampil)){
									  echo "<option value=$r[tahun]>$r[tahun]</option>";
									}
							echo "</select>
						<input type='submit' class='submitt' value='View'>
						<a style='font-size:12px; text-decoration:none;' class='submitt' href='laporan-terjual.html'>All Periode</a>
					</form>
				</span>
			
			<div id='container'>
			<div id='demo'>
<table class='display' id='example'>
	<thead>
		<tr>
			<th>No</th>
			<th>Nama Barang</th>
			<th>Harga Jual</th>
			<th>Jumlah</th>
			<th>Sub Total</th>
			<th>Diskon</th>
			<th>Total Jual Bersih</th>
			<th>Harga Modal</th>
			<th>Tanggal Terjual</th>
			<th>Karyawan</th>
			<th>Keuntungan</th>
		</tr>
	</thead>
	<tfoot>
		<tr style='border: 2px solid #e3e3e3;'>
			<th style='border: none;'>No</th>
			<th style='border: none;'>Nama Barang</th>
			<th style='border: none;'>Harga Jual</th>
			<th style='border: none;'>Jumlah</th>
			<th style='border: none;'>Sub Total</th>
			<th style='border: none;'>Diskon</th>
			<th style='border: none;'>Total Jual Bersih</th>
			<th style='border: none;'>Harga Modal</th>
			<th style='border: none;'>Tanggal Terjual</th>
			<th style='border: none;'>Karyawan</th>
			<th style='border: none;'>Keuntungan</th>
		</tr>
	</tfoot>";
	$no=1;
	    $tampill=mysql_query("SELECT * FROM rb_orders_detail 
								left join rb_produk on rb_orders_detail.id_produk=rb_produk.id_produk 
									left join rb_orders on rb_orders_detail.id_orders=rb_orders.id_orders 
										where rb_orders_detail.id_orders like 'E%' AND rb_orders.karyawan='$_POST[karyawan]' AND rb_produk.id_kategori='$_POST[kategori]' AND rb_orders.tanggal_pesan like '$filter%'
											ORDER BY rb_orders_detail.id_orders");
		echo "<tbody>";
    while($r=mysql_fetch_array($tampill)){
		$tanggal_pesan=tgl_indo($r[tanggal_pesan]);
		$subtotal=$r[harga]*$r[jumlah];
		$subtotal2=$r[harga_pokok]*$r[jumlah];
		$diskon   = $r[diskon]/100 * $subtotal;
		$subtotall=$subtotal-$diskon;
		$untung=$subtotall-$subtotal2;
		$harga_pokok = format_rupiah($r[harga_pokok]);
		$harga = format_rupiah($r[harga]);
		$diskon_rp = format_rupiah($diskon);
		$untung_rp = format_rupiah($untung);
		$subtotall_rp = format_rupiah($subtotal);
		$subtotal_rp = format_rupiah($subtotall);
		
	  if(($no % 2)==0){
			$warna="#E1E1E1";
		  }
		  else{
			$warna="#ffffff";
		  }
	echo "
		<tr bgcolor='$warna'>
			<td class='read_only' style='color:blue; height:27px;'>$no</td>
			<td>$r[nama_produk]</td>
            <td>Rp $harga</td>
            <td>$r[jumlah]</td>
			<td>Rp $subtotall_rp</td>
			<td>$r[diskon] % (Rp $diskon_rp)</td>
			<td>Rp $subtotal_rp</td>
			<td>Rp $harga_pokok</td>
			<td>$tanggal_pesan</td>
			<td><span style='text-transform:capitalize;'>$r[karyawan]</span></td>
			<td style=' font-weight:bold;'>Rp $untung_rp</td>
		</tr>";
		$no++;
		}
		
				$sql = "SELECT SUM(harga*jumlah) AS total_harga,
								SUM(harga*jumlah*diskon/100) AS total_diskon,
						SUM(harga_pokok*jumlah) AS total_pokok,
						SUM(jumlah) AS total_jumlah FROM rb_orders_detail
								left join rb_produk on rb_orders_detail.id_produk=rb_produk.id_produk 
									left join rb_orders on rb_orders_detail.id_orders=rb_orders.id_orders
										where rb_orders_detail.id_orders like 'E%' AND karyawan='$_POST[karyawan]' AND rb_produk.id_kategori='$_POST[kategori]' AND rb_orders.tanggal_pesan like '$filter%'";
		$result = mysql_query($sql) or die (mysql_error());
		$t = mysql_fetch_array($result);
		 $total_harga=format_rupiah($t[total_harga]);
		 $total_pokok=format_rupiah($t[total_pokok]);
		 $total_jumlah=format_rupiah($t[total_jumlah]);
		 $total_diskon=format_rupiah($t[total_diskon]);
		 $total_jual=$t[total_harga]-$t[total_diskon];
		 
		 $total_jual_rp=format_rupiah($total_jual);
		 $untung=$total_jual-$t[total_pokok];
		 $untung_rp=format_rupiah($untung);
	echo "
		<tr bgcolor='$warna'>
			<td class='read_only' style='background:$warna; color:$warna; height:27px;'>X</td>
			<td style='text-align:center; color:red; font-weight:bold;'>T o t a l</td>
            <td style='color:red;'></td>
            <td style='color:red;'>$total_jumlah</td>
			<td style='color:red;'>Rp $total_harga</td>
			<td style='color:red;'>Rp $total_diskon</td>
			<td style='color:red;'>Rp $total_jual_rp</td>
			<td style='color:red;'>Rp $total_pokok</td>
			<td></td>
			<td></td>
			<td style='color:red; font-weight:bold;'>Rp $untung_rp</td>
		</tr>";
echo "	</tbody>
 </table>
</div></div>";
}

elseif ($_GET[module]=='kategorilapproduk'){
	$filter = $_POST[tahun].'-'.$_POST[bulan];
	$bulan = Bulan($_POST[bulan]);
	$sqle=mysql_query("SELECT * FROM rb_kategori_produk where id_kategori='$_POST[kategori]'");
	$pp=mysql_fetch_array($sqle);
	echo "<div class='post_title' style='margin-bottom:10px; position:relative;'><b>Laporan <span style='color:red'>$pp[nama_kategori]</span> Terjual (Eceran) pada : <span style='color:red'>$bulan - $_POST[tahun]</span><hr></b></div>
	
			<span style='float:left;'>
					Filter Karyawan : ";?><select style=' margin-right:3px; margin-bottom:5px;' ONCHANGE="location = this.options[this.selectedIndex].value;">
					<?php echo "<option value=0 selected>- Pilih Karyawan -</option>";
						$tampil=mysql_query("SELECT username FROM rb_users where level='karyawan' ORDER BY username DESC");
						while($r=mysql_fetch_array($tampil)){
						echo "<option value='filterr-$r[username].html'>$r[username]</option>";
						}
			  echo "</select>";
			  ?><select style=' margin-right:3px; margin-bottom:5px;' ONCHANGE="location = this.options[this.selectedIndex].value;">
					<?php echo "<option value=0 selected> $pp[nama_kategori] </option>";
						$tampil=mysql_query("SELECT * FROM rb_kategori_produk ORDER BY nama_kategori");
						while($r=mysql_fetch_array($tampil)){
						echo "<option value='filterrrr-$r[id_kategori].html'>$r[nama_kategori]</option>";
						}
			  echo "</select>
			  </span>
			
				<span style='float:right; margin-right:0px;'>
					<form method=POST action='kategori-tanggal.html'>
						<input type=hidden name='kategori' value='$_POST[kategori]'>
							Periode : <select name='bulan'>
									<option value='$_POST[bulan]' selected>$bulan</option>";
									$tampil=mysql_query("SELECT substring(tanggal_pesan,6,2) as bulan FROM rb_orders GROUP BY substring(tanggal_pesan,6,2)");
									while($r=mysql_fetch_array($tampil)){
									$bulan = Bulan($r[bulan]);
									  echo "<option value=$r[bulan]>$bulan</option>";
									}	
							echo "</select>
							<select name='tahun'>
									<option value='$_POST[tahun]' selected>$_POST[tahun]</option>";
									$tampil=mysql_query("SELECT substring(tanggal_pesan,1,4) as tahun FROM rb_orders GROUP BY substring(tanggal_pesan,1,4)");
									while($r=mysql_fetch_array($tampil)){
									  echo "<option value=$r[tahun]>$r[tahun]</option>";
									}
							echo "</select>
						<input type='submit' class='submitt' value='View'>
						<a style='font-size:12px; text-decoration:none;' class='submitt' href='laporan-terjual.html'>All Periode</a>
					</form>
				</span>
			
			<div id='container'>
			<div id='demo'>
<table class='display' id='example'>
	<thead>
		<tr>
			<th>No</th>
			<th>Nama Barang</th>
			<th>Harga Jual</th>
			<th>Jumlah</th>
			<th>Sub Total</th>
			<th>Diskon</th>
			<th>Total Jual Bersih</th>
			<th>Harga Modal</th>
			<th>Tanggal Terjual</th>
			<th>Karyawan</th>
			<th>Keuntungan</th>
		</tr>
	</thead>
	<tfoot>
		<tr style='border: 2px solid #e3e3e3;'>
			<th style='border: none;'>No</th>
			<th style='border: none;'>Nama Barang</th>
			<th style='border: none;'>Harga Jual</th>
			<th style='border: none;'>Jumlah</th>
			<th style='border: none;'>Sub Total</th>
			<th style='border: none;'>Diskon</th>
			<th style='border: none;'>Total Jual Bersih</th>
			<th style='border: none;'>Harga Modal</th>
			<th style='border: none;'>Tanggal Terjual</th>
			<th style='border: none;'>Karyawan</th>
			<th style='border: none;'>Keuntungan</th>
		</tr>
	</tfoot>";
	$no=1;
	    $tampill=mysql_query("SELECT * FROM rb_orders_detail 
								left join rb_produk on rb_orders_detail.id_produk=rb_produk.id_produk 
									left join rb_orders on rb_orders_detail.id_orders=rb_orders.id_orders 
										where rb_orders_detail.id_orders like 'E%' AND rb_orders.tanggal_pesan like '$filter%' AND rb_produk.id_kategori='$_POST[kategori]'
											ORDER BY rb_orders_detail.id_orders");
		echo "<tbody>";
    while($r=mysql_fetch_array($tampill)){
		$tanggal_pesan=tgl_indo($r[tanggal_pesan]);
		$subtotal=$r[harga]*$r[jumlah];
		$subtotal2=$r[harga_pokok]*$r[jumlah];
		$diskon   = $r[diskon]/100 * $subtotal;
		$subtotall=$subtotal-$diskon;
		$untung=$subtotall-$subtotal2;
		$harga_pokok = format_rupiah($r[harga_pokok]);
		$harga = format_rupiah($r[harga]);
		$diskon_rp = format_rupiah($diskon);
		$untung_rp = format_rupiah($untung);
		$subtotall_rp = format_rupiah($subtotal);
		$subtotal_rp = format_rupiah($subtotall);
		
	  if(($no % 2)==0){
			$warna="#E1E1E1";
		  }
		  else{
			$warna="#ffffff";
		  }
	echo "
		<tr bgcolor='$warna'>
			<td class='read_only' style='color:blue; height:27px;'>$no</td>";
			if ($r[id_kategori]==13){
            echo "<td class='linkSysteM'><a href='#' alt='Type : $r[type] | Jenis : $r[jenis] | Ukuran : $r[ukuran]'>$r[nama_produk]</a></td>";
			}else{
			echo "<td>$r[nama_produk]</td>";
			}
			echo "<td>Rp $harga</td>
            <td>$r[jumlah]</td>
			<td>Rp $subtotall_rp</td>
			<td>$r[diskon] % (Rp $diskon_rp)</td>
			<td>Rp $subtotal_rp</td>
			<td>Rp $harga_pokok</td>
			<td>$tanggal_pesan</td>
			<td><span style='text-transform:capitalize;'>$r[karyawan]</span></td>
			<td style=' font-weight:bold;'>Rp $untung_rp</td>
		</tr>";
		$no++;
		}
		
				$sql = "SELECT SUM(harga*jumlah) AS total_harga,
								SUM(harga*jumlah*diskon/100) AS total_diskon,
						SUM(harga_pokok*jumlah) AS total_pokok,
						SUM(jumlah) AS total_jumlah FROM rb_orders_detail
								left join rb_produk on rb_orders_detail.id_produk=rb_produk.id_produk 
									left join rb_orders on rb_orders_detail.id_orders=rb_orders.id_orders
										where rb_orders_detail.id_orders like 'E%' AND rb_orders.tanggal_pesan like '$filter%' AND rb_produk.id_kategori='$_POST[kategori]'";
										
		$result = mysql_query($sql) or die (mysql_error());
		$t = mysql_fetch_array($result);
		 $total_harga=format_rupiah($t[total_harga]);
		 $total_pokok=format_rupiah($t[total_pokok]);
		 $total_jumlah=format_rupiah($t[total_jumlah]);
		 $total_diskon=format_rupiah($t[total_diskon]);
		 $total_jual=$t[total_harga]-$t[total_diskon];
		 
		 $total_jual_rp=format_rupiah($total_jual);
		 $untung=$total_jual-$t[total_pokok];
		 $untung_rp=format_rupiah($untung);
	echo "
		<tr bgcolor='$warna'>
			<td class='read_only' style='background:$warna; color:$warna; height:27px;'>X</td>
			<td style='text-align:center; color:red; font-weight:bold;'>T o t a l</td>
            <td style='color:red;'></td>
            <td style='color:red;'>$total_jumlah</td>
			<td style='color:red;'>Rp $total_harga</td>
			<td style='color:red;'>Rp $total_diskon</td>
			<td style='color:red;'>Rp $total_jual_rp</td>
			<td style='color:red;'>Rp $total_pokok</td>
			<td></td>
			<td></td>
			<td style='color:red; font-weight:bold;'>Rp $untung_rp</td>
		</tr>";
echo "	</tbody>
 </table>
</div></div>";
}





elseif ($_GET[module]=='karyawanlapprodukx'){
	$filter = $_POST[tahun].'-'.$_POST[bulan];
	$bulan = Bulan($_POST[bulan]);
	echo "<div class='post_title' style='margin-bottom:10px; position:relative;'><b>Laporan Barang Terjual (Grosir) oleh <span style='color:red'>$_POST[karyawan]</span> pada : <span style='color:red'>$bulan - $_POST[tahun]</span><hr></b></div>
	
			<span style='float:left;'>
					Filter Karyawan : ";?><select style=' margin-right:3px; margin-bottom:5px;' ONCHANGE="location = this.options[this.selectedIndex].value;">
					<?php echo "<option value=0 selected> $_POST[karyawan] </option>";
						$tampil=mysql_query("SELECT username FROM rb_users where level='karyawan' ORDER BY username DESC");
						while($r=mysql_fetch_array($tampil)){
						echo "<option value='filterrx-$r[username].html'>$r[username]</option>";
						}
			  echo "</select>";
			  ?><select style=' margin-right:3px; margin-bottom:5px;' ONCHANGE="location = this.options[this.selectedIndex].value;">
					<?php echo "<option value=0 selected>- Pilih Jenis Produk -</option>";
						$tampil=mysql_query("SELECT * FROM rb_kategori_produk ORDER BY nama_kategori");
						while($r=mysql_fetch_array($tampil)){
						echo "<option value='filterrrrx-$r[id_kategori].html'>$r[nama_kategori]</option>";
						}
			  echo "</select>
			  </span>
			
				<span style='float:right; margin-right:0px;'>
					<form method=POST action='karyawan-tanggalx.html'>
						<input type='hidden' name='karyawan' value='$_POST[karyawan]'>
							Periode : <select name='bulan'>
									<option value='$_POST[bulan]' selected>$bulan</option>";
									$tampil=mysql_query("SELECT substring(tanggal_pesan,6,2) as bulan FROM rb_orders_grosir GROUP BY substring(tanggal_pesan,6,2)");
									while($r=mysql_fetch_array($tampil)){
									$bulan = Bulan($r[bulan]);
									  echo "<option value=$r[bulan]>$bulan</option>";
									}	
							echo "</select>
							<select name='tahun'>
									<option value='$_POST[tahun]' selected>$_POST[tahun]</option>";
									$tampil=mysql_query("SELECT substring(tanggal_pesan,1,4) as tahun FROM rb_orders_grosir GROUP BY substring(tanggal_pesan,1,4)");
									while($r=mysql_fetch_array($tampil)){
									  echo "<option value=$r[tahun]>$r[tahun]</option>";
									}
							echo "</select>
						<input type='submit' class='submitt' value='View'>
						<a style='font-size:12px; text-decoration:none;' class='submitt' href='laporan-terjualx.html'>All Periode</a>
					</form>
				</span>
			
			<div id='container'>
			<div id='demo'>
<table class='display' id='example'>
	<thead>
		<tr>
			<th>No</th>
			<th>Nama Barang</th>
			<th>Harga Jual</th>
			<th>Jumlah</th>
			<th>Sub Total</th>
			<th>Diskon</th>
			<th>Total Jual Bersih</th>
			<th>Harga Modal</th>
			<th>Tanggal Terjual</th>
			<th>Karyawan</th>
			<th>Keuntungan</th>
		</tr>
	</thead>
	<tfoot>
		<tr style='border: 2px solid #e3e3e3;'>
			<th style='border: none;'>No</th>
			<th style='border: none;'>Nama Barang</th>
			<th style='border: none;'>Harga Jual</th>
			<th style='border: none;'>Jumlah</th>
			<th style='border: none;'>Sub Total</th>
			<th style='border: none;'>Diskon</th>
			<th style='border: none;'>Total Jual Bersih</th>
			<th style='border: none;'>Harga Modal</th>
			<th style='border: none;'>Tanggal Terjual</th>
			<th style='border: none;'>Karyawan</th>
			<th style='border: none;'>Keuntungan</th>
		</tr>
	</tfoot>";
	$no=1;
	    $tampill=mysql_query("SELECT * FROM rb_orders_detail 
								left join rb_produk on rb_orders_detail.id_produk=rb_produk.id_produk 
									left join rb_orders_grosir on rb_orders_detail.id_orders=rb_orders_grosir.id_orders
										where rb_orders_detail.id_orders like 'G%' AND rb_orders_grosir.tanggal_pesan like '$filter%' AND rb_orders_grosir.karyawan='$_POST[karyawan]'
											ORDER BY rb_orders_detail.id_orders");
		echo "<tbody>";
    while($r=mysql_fetch_array($tampill)){
		$tanggal_pesan=tgl_indo($r[tanggal_pesan]);
		$subtotal=$r[harga]*$r[jumlah];
		$subtotal2=$r[harga_pokok]*$r[jumlah];
		$diskon   = $r[diskon]/100 * $subtotal;
		$subtotall=$subtotal-$diskon;
		$untung=$subtotall-$subtotal2;
		$harga_pokok = format_rupiah($r[harga_pokok]);
		$harga = format_rupiah($r[harga]);
		$diskon_rp = format_rupiah($diskon);
		$untung_rp = format_rupiah($untung);
		$subtotall_rp = format_rupiah($subtotal);
		$subtotal_rp = format_rupiah($subtotall);
		
	  if(($no % 2)==0){
			$warna="#E1E1E1";
		  }
		  else{
			$warna="#ffffff";
		  }
	echo "
		<tr bgcolor='$warna'>
			<td class='read_only' style='color:blue; height:27px;'>$no</td>";
			if ($r[id_kategori]==13){
            echo "<td class='linkSysteM'><a href='#' alt='Type : $r[type] | Jenis : $r[jenis] | Ukuran : $r[ukuran]'>$r[nama_produk]</a></td>";
			}else{
			echo "<td>$r[nama_produk]</td>";
			}
			echo "<td>Rp $harga</td>
            <td>$r[jumlah]</td>
			<td>Rp $subtotall_rp</td>
			<td>$r[diskon] % (Rp $diskon_rp)</td>
			<td>Rp $subtotal_rp</td>
			<td>Rp $harga_pokok</td>
			<td>$rtanggal_pesan</td>
			<td><span style='text-transform:capitalize;'>$r[karyawan]</span></td>
			<td style=' font-weight:bold;'>Rp $untung_rp</td>
		</tr>";
		$no++;
		}
		
				$sql = "SELECT SUM(harga*jumlah) AS total_harga,
								SUM(harga*jumlah*diskon/100) AS total_diskon,
						SUM(harga_pokok*jumlah) AS total_pokok,
						SUM(jumlah) AS total_jumlah FROM rb_orders_detail
								left join rb_produk on rb_orders_detail.id_produk=rb_produk.id_produk 
									left join rb_orders_grosir on rb_orders_detail.id_orders=rb_orders_grosir.id_orders
										where rb_orders_detail.id_orders like 'G%' AND rb_orders_grosir.tanggal_pesan like '$filter%' AND rb_orders_grosir.karyawan='$_POST[karyawan]'";
										
		$result = mysql_query($sql) or die (mysql_error());
		$t = mysql_fetch_array($result);
		 $total_harga=format_rupiah($t[total_harga]);
		 $total_pokok=format_rupiah($t[total_pokok]);
		 $total_jumlah=format_rupiah($t[total_jumlah]);
		 $total_diskon=format_rupiah($t[total_diskon]);
		 $total_jual=$t[total_harga]-$t[total_diskon];
		 
		 $total_jual_rp=format_rupiah($total_jual);
		 $untung=$total_jual-$t[total_pokok];
		 $untung_rp=format_rupiah($untung);
	echo "
		<tr bgcolor='$warna'>
			<td class='read_only' style='background:$warna; color:$warna; height:27px;'>X</td>
			<td style='text-align:center; color:red; font-weight:bold;'>T o t a l</td>
            <td style='color:red;'></td>
            <td style='color:red;'>$total_jumlah</td>
			<td style='color:red;'>Rp $total_harga</td>
			<td style='color:red;'>Rp $total_diskon</td>
			<td style='color:red;'>Rp $total_jual_rp</td>
			<td style='color:red;'>Rp $total_pokok</td>
			<td></td>
			<td></td>
			<td style='color:red; font-weight:bold;'>Rp $untung_rp</td>
		</tr>";
echo "	</tbody>
 </table>
</div></div>";
}



elseif ($_GET[module]=='kategorikaryawanlapprodukx'){
	$filter = $_POST[tahun].'-'.$_POST[bulan];
	$bulan = Bulan($_POST[bulan]);
	$sqle=mysql_query("SELECT * FROM rb_kategori_produk where id_kategori='$_POST[kategori]'");
				$pp=mysql_fetch_array($sqle);
	echo "<div class='post_title' style='margin-bottom:10px; position:relative;'><b>Laporan <span style='color:red'>$pp[nama_kategori]</span> Terjual (Grosir) Oleh <span style='color:red'>$_POST[karyawan]</span> pada : <span style='color:red'>$bulan - $_POST[tahun]</span><hr></b></div>
	
			<span style='float:left;'>
					Filter Karyawan : ";
					?><select style=' margin-right:3px; margin-bottom:5px;' ONCHANGE="location = this.options[this.selectedIndex].value;">
					<?php echo "<option value=0 selected> $_POST[karyawan] </option>";
						$tampil=mysql_query("SELECT username FROM rb_users where level='karyawan' ORDER BY username DESC");
						while($r=mysql_fetch_array($tampil)){
						echo "<option value='filterrx-$r[username].html'>$r[username]</option>";
						}
			  echo "</select>";
					?><select style=' margin-right:3px; margin-bottom:5px;' ONCHANGE="location = this.options[this.selectedIndex].value;">
					<?php echo "<option value=0 selected> $pp[nama_kategori] </option>";
						$tampil=mysql_query("SELECT * FROM rb_kategori_produk ORDER BY nama_kategori");
						while($r=mysql_fetch_array($tampil)){
						echo "<option value='filterrrx-$_GET[username]-$r[id_kategori].html'>$r[nama_kategori]</option>";
						}
			  echo "</select></span>
			
				<span style='float:right; margin-right:0px;'>
					<form method=POST action='kategori-karyawan-tanggalx.html'>
						<input type=hidden name='kategori' value='$_POST[kategori]'>
						<input type=hidden name='karyawan' value='$_POST[karyawan]'>
							Periode : <select name='bulan'>
									<option value='$_POST[bulan]' selected>$bulan</option>";
									$tampil=mysql_query("SELECT substring(tanggal_pesan,6,2) as bulan FROM rb_orders_grosir GROUP BY substring(tanggal_pesan,6,2)");
									while($r=mysql_fetch_array($tampil)){
									$bulan = Bulan($r[bulan]);
									  echo "<option value=$r[bulan]>$bulan</option>";
									}	
							echo "</select>
							<select name='tahun'>
									<option value='$_POST[tahun]' selected>$_POST[tahun]</option>";
									$tampil=mysql_query("SELECT substring(tanggal_pesan,1,4) as tahun FROM rb_orders_grosir GROUP BY substring(tanggal_pesan,1,4)");
									while($r=mysql_fetch_array($tampil)){
									  echo "<option value=$r[tahun]>$r[tahun]</option>";
									}
							echo "</select>
						<input type='submit' class='submitt' value='View'>
						<a style='font-size:12px; text-decoration:none;' class='submitt' href='laporan-terjualx.html'>All Periode</a>
					</form>
				</span>
			
			<div id='container'>
			<div id='demo'>
<table class='display' id='example'>
	<thead>
		<tr>
			<th>No</th>
			<th>Nama Barang</th>
			<th>Harga Jual</th>
			<th>Jumlah</th>
			<th>Sub Total</th>
			<th>Diskon</th>
			<th>Total Jual Bersih</th>
			<th>Harga Modal</th>
			<th>Tanggal Terjual</th>
			<th>Karyawan</th>
			<th>Keuntungan</th>
		</tr>
	</thead>
	<tfoot>
		<tr style='border: 2px solid #e3e3e3;'>
			<th style='border: none;'>No</th>
			<th style='border: none;'>Nama Barang</th>
			<th style='border: none;'>Harga Jual</th>
			<th style='border: none;'>Jumlah</th>
			<th style='border: none;'>Sub Total</th>
			<th style='border: none;'>Diskon</th>
			<th style='border: none;'>Total Jual Bersih</th>
			<th style='border: none;'>Harga Modal</th>
			<th style='border: none;'>Tanggal Terjual</th>
			<th style='border: none;'>Karyawan</th>
			<th style='border: none;'>Keuntungan</th>
		</tr>
	</tfoot>";
	$no=1;
	    $tampill=mysql_query("SELECT * FROM rb_orders_detail 
								left join rb_produk on rb_orders_detail.id_produk=rb_produk.id_produk 
									left join rb_orders_grosir on rb_orders_detail.id_orders=rb_orders_grosir.id_orders
										where rb_orders_detail.id_orders like 'G%' AND rb_orders_grosir.karyawan='$_POST[karyawan]' AND rb_produk.id_kategori='$_POST[kategori]' AND rb_orders_grosir.tanggal_pesan like '$filter%'
											ORDER BY rb_orders_detail.id_orders");
		echo "<tbody>";
    while($r=mysql_fetch_array($tampill)){
		$tanggal_pesan=tgl_indo($r[tanggal_pesan]);
		$subtotal=$r[harga]*$r[jumlah];
		$subtotal2=$r[harga_pokok]*$r[jumlah];
		$diskon   = $r[diskon]/100 * $subtotal;
		$subtotall=$subtotal-$diskon;
		$untung=$subtotall-$subtotal2;
		$harga_pokok = format_rupiah($r[harga_pokok]);
		$harga = format_rupiah($r[harga]);
		$diskon_rp = format_rupiah($diskon);
		$untung_rp = format_rupiah($untung);
		$subtotall_rp = format_rupiah($subtotal);
		$subtotal_rp = format_rupiah($subtotall);
		
	  if(($no % 2)==0){
			$warna="#E1E1E1";
		  }
		  else{
			$warna="#ffffff";
		  }
	echo "
		<tr bgcolor='$warna'>
			<td class='read_only' style='color:blue; height:27px;'>$no</td>
			<td>$r[nama_produk]</td>
            <td>Rp $harga</td>
            <td>$r[jumlah]</td>
			<td>Rp $subtotall_rp</td>
			<td>$r[diskon] % (Rp $diskon_rp)</td>
			<td>Rp $subtotal_rp</td>
			<td>Rp $harga_pokok</td>
			<td>$tanggal_pesan</td>
			<td><span style='text-transform:capitalize;'>$r[karyawan]</span></td>
			<td style=' font-weight:bold;'>Rp $untung_rp</td>
		</tr>";
		$no++;
		}
		
				$sql = "SELECT SUM(harga*jumlah) AS total_harga,
								SUM(harga*jumlah*diskon/100) AS total_diskon,
						SUM(harga_pokok*jumlah) AS total_pokok,
						SUM(jumlah) AS total_jumlah FROM rb_orders_detail
								left join rb_produk on rb_orders_detail.id_produk=rb_produk.id_produk 
									left join rb_orders_grosir on rb_orders_detail.id_orders=rb_orders_grosir.id_orders
										where rb_orders_detail.id_orders like 'G%' AND rb_orders_grosir.karyawan='$_POST[karyawan]' AND rb_produk.id_kategori='$_POST[kategori]' AND rb_orders_grosir.tanggal_pesan like '$filter%'";
		$result = mysql_query($sql) or die (mysql_error());
		$t = mysql_fetch_array($result);
		 $total_harga=format_rupiah($t[total_harga]);
		 $total_pokok=format_rupiah($t[total_pokok]);
		 $total_jumlah=format_rupiah($t[total_jumlah]);
		 $total_diskon=format_rupiah($t[total_diskon]);
		 $total_jual=$t[total_harga]-$t[total_diskon];
		 
		 $total_jual_rp=format_rupiah($total_jual);
		 $untung=$total_jual-$t[total_pokok];
		 $untung_rp=format_rupiah($untung);
	echo "
		<tr bgcolor='$warna'>
			<td class='read_only' style='background:$warna; color:$warna; height:27px;'>X</td>
			<td style='text-align:center; color:red; font-weight:bold;'>T o t a l</td>
            <td style='color:red;'></td>
            <td style='color:red;'>$total_jumlah</td>
			<td style='color:red;'>Rp $total_harga</td>
			<td style='color:red;'>Rp $total_diskon</td>
			<td style='color:red;'>Rp $total_jual_rp</td>
			<td style='color:red;'>Rp $total_pokok</td>
			<td></td>
			<td></td>
			<td style='color:red; font-weight:bold;'>Rp $untung_rp</td>
		</tr>";
echo "	</tbody>
 </table>
</div></div>";
}

elseif ($_GET[module]=='kategorilapprodukx'){
	$filter = $_POST[tahun].'-'.$_POST[bulan];
	$bulan = Bulan($_POST[bulan]);
	$sqle=mysql_query("SELECT * FROM rb_kategori_produk where id_kategori='$_POST[kategori]'");
				$pp=mysql_fetch_array($sqle);
	echo "<div class='post_title' style='margin-bottom:10px; position:relative;'><b>Laporan <span style='color:red'>$pp[nama_kategori]</span> Terjual (Grosir) pada : <span style='color:red'>$bulan - $_POST[tahun]</span><hr></b></div>
	
			<span style='float:left;'>
					Filter Karyawan : ";?><select style=' margin-right:3px; margin-bottom:5px;' ONCHANGE="location = this.options[this.selectedIndex].value;">
					<?php echo "<option value=0 selected>- Pilih Karyawan -</option>";
						$tampil=mysql_query("SELECT username FROM rb_users where level='karyawan' ORDER BY username DESC");
						while($r=mysql_fetch_array($tampil)){
						echo "<option value='filterrx-$r[username].html'>$r[username]</option>";
						}
			  echo "</select>";
			  ?><select style=' margin-right:3px; margin-bottom:5px;' ONCHANGE="location = this.options[this.selectedIndex].value;">
					<?php echo "<option value=0 selected> $pp[nama_kategori] </option>";
						$tampil=mysql_query("SELECT * FROM rb_kategori_produk ORDER BY nama_kategori");
						while($r=mysql_fetch_array($tampil)){
						echo "<option value='filterrrrx-$r[id_kategori].html'>$r[nama_kategori]</option>";
						}
			  echo "</select>
			  </span>
			
				<span style='float:right; margin-right:0px;'>
					<form method=POST action='kategori-tanggalx.html'>
						<input type=hidden name='kategori' value='$_POST[kategori]'>
							Periode : <select name='bulan'>
									<option value='$_POST[bulan]' selected>$bulan</option>";
									$tampil=mysql_query("SELECT substring(tanggal_pesan,6,2) as bulan FROM rb_orders_grosir GROUP BY substring(tanggal_pesan,6,2)");
									while($r=mysql_fetch_array($tampil)){
									$bulan = Bulan($r[bulan]);
									  echo "<option value=$r[bulan]>$bulan</option>";
									}	
							echo "</select>
							<select name='tahun'>
									<option value='$_POST[tahun]' selected>$_POST[tahun]</option>";
									$tampil=mysql_query("SELECT substring(tanggal_pesan,1,4) as tahun FROM rb_orders_grosir GROUP BY substring(tanggal_pesan,1,4)");
									while($r=mysql_fetch_array($tampil)){
									  echo "<option value=$r[tahun]>$r[tahun]</option>";
									}
							echo "</select>
						<input type='submit' class='submitt' value='View'>
						<a style='font-size:12px; text-decoration:none;' class='submitt' href='laporan-terjualx.html'>All Periode</a>
					</form>
				</span>
			
			<div id='container'>
			<div id='demo'>
<table class='display' id='example'>
	<thead>
		<tr>
			<th>No</th>
			<th>Nama Barang</th>
			<th>Harga Jual</th>
			<th>Jumlah</th>
			<th>Sub Total</th>
			<th>Diskon</th>
			<th>Total Jual Bersih</th>
			<th>Harga Modal</th>
			<th>Tanggal Terjual</th>
			<th>Karyawan</th>
			<th>Keuntungan</th>
		</tr>
	</thead>
	<tfoot>
		<tr style='border: 2px solid #e3e3e3;'>
			<th style='border: none;'>No</th>
			<th style='border: none;'>Nama Barang</th>
			<th style='border: none;'>Harga Jual</th>
			<th style='border: none;'>Jumlah</th>
			<th style='border: none;'>Sub Total</th>
			<th style='border: none;'>Diskon</th>
			<th style='border: none;'>Total Jual Bersih</th>
			<th style='border: none;'>Harga Modal</th>
			<th style='border: none;'>Tanggal Terjual</th>
			<th style='border: none;'>Karyawan</th>
			<th style='border: none;'>Keuntungan</th>
		</tr>
	</tfoot>";
	$no=1;
	$tgl1 = tgl_pesan($_POST[tgl1]);
	$tgl2 = tgl_pesan($_POST[tgl2]);
	    $tampill=mysql_query("SELECT * FROM rb_orders_detail 
								left join rb_produk on rb_orders_detail.id_produk=rb_produk.id_produk 
									left join rb_orders_grosir on rb_orders_detail.id_orders=rb_orders_grosir.id_orders 
										where rb_orders_detail.id_orders like 'G%' AND rb_orders_grosir.tanggal_pesan like '$filter%' AND rb_produk.id_kategori='$_POST[kategori]'
											ORDER BY rb_orders_detail.id_orders");
		echo "<tbody>";
    while($r=mysql_fetch_array($tampill)){
		$tanggal_pesan=tgl_indo($r[tanggal_pesan]);
		$subtotal=$r[harga]*$r[jumlah];
		$subtotal2=$r[harga_pokok]*$r[jumlah];
		$diskon   = $r[diskon]/100 * $subtotal;
		$subtotall=$subtotal-$diskon;
		$untung=$subtotall-$subtotal2;
		$harga_pokok = format_rupiah($r[harga_pokok]);
		$harga = format_rupiah($r[harga]);
		$diskon_rp = format_rupiah($diskon);
		$untung_rp = format_rupiah($untung);
		$subtotall_rp = format_rupiah($subtotal);
		$subtotal_rp = format_rupiah($subtotall);
		
	  if(($no % 2)==0){
			$warna="#E1E1E1";
		  }
		  else{
			$warna="#ffffff";
		  }
	echo "
		<tr bgcolor='$warna'>
			<td class='read_only' style='color:blue; height:27px;'>$no</td>";
			if ($r[id_kategori]==13){
            echo "<td class='linkSysteM'><a href='#' alt='Type : $r[type] | Jenis : $r[jenis] | Ukuran : $r[ukuran]'>$r[nama_produk]</a></td>";
			}else{
			echo "<td>$r[nama_produk]</td>";
			}
			echo "<td>Rp $harga</td>
            <td>$r[jumlah]</td>
			<td>Rp $subtotall_rp</td>
			<td>$r[diskon] % (Rp $diskon_rp)</td>
			<td>Rp $subtotal_rp</td>
			<td>Rp $harga_pokok</td>
			<td>$tanggal_pesan</td>
			<td><span style='text-transform:capitalize;'>$r[karyawan]</span></td>
			<td style=' font-weight:bold;'>Rp $untung_rp</td>
		</tr>";
		$no++;
		}
		
				$sql = "SELECT SUM(harga*jumlah) AS total_harga,
								SUM(harga*jumlah*diskon/100) AS total_diskon,
						SUM(harga_pokok*jumlah) AS total_pokok,
						SUM(jumlah) AS total_jumlah FROM rb_orders_detail
								left join rb_produk on rb_orders_detail.id_produk=rb_produk.id_produk 
									left join rb_orders_grosir on rb_orders_detail.id_orders=rb_orders_grosir.id_orders
										where rb_orders_detail.id_orders like 'G%' AND rb_orders_grosir.tanggal_pesan like '$filter%' AND rb_produk.id_kategori='$_POST[kategori]'";
										
		$result = mysql_query($sql) or die (mysql_error());
		$t = mysql_fetch_array($result);
		 $total_harga=format_rupiah($t[total_harga]);
		 $total_pokok=format_rupiah($t[total_pokok]);
		 $total_jumlah=format_rupiah($t[total_jumlah]);
		 $total_diskon=format_rupiah($t[total_diskon]);
		 $total_jual=$t[total_harga]-$t[total_diskon];
		 
		 $total_jual_rp=format_rupiah($total_jual);
		 $untung=$total_jual-$t[total_pokok];
		 $untung_rp=format_rupiah($untung);
	echo "
		<tr bgcolor='$warna'>
			<td class='read_only' style='background:$warna; color:$warna; height:27px;'>X</td>
			<td style='text-align:center; color:red; font-weight:bold;'>T o t a l</td>
            <td style='color:red;'></td>
            <td style='color:red;'>$total_jumlah</td>
			<td style='color:red;'>Rp $total_harga</td>
			<td style='color:red;'>Rp $total_diskon</td>
			<td style='color:red;'>Rp $total_jual_rp</td>
			<td style='color:red;'>Rp $total_pokok</td>
			<td></td>
			<td></td>
			<td style='color:red; font-weight:bold;'>Rp $untung_rp</td>
		</tr>";
echo "	</tbody>
 </table>
</div></div>";
}


elseif ($_GET[module]=='hapuslaporang'){
	mysql_query("DELETE FROM rb_orders_grosir WHERE id_orders='$_GET[id]'");
	mysql_query("DELETE FROM rb_orders_detail WHERE id_orders='$_GET[id]'");
	echo "<script>window.alert('Sukses Menghapus Data Pemesanan $_GET[id].');
				window.location='laporan-penjualan-grosir.html'</script>";	
}

elseif ($_GET[module]=='hapuslaporan'){
	mysql_query("DELETE FROM rb_orders WHERE id_orders='$_GET[id]'");
	mysql_query("DELETE FROM rb_orders_detail WHERE id_orders='$_GET[id]'");
	mysql_query("DELETE FROM rb_resep WHERE id_orders='$_GET[id]'");
	echo "<script>window.alert('Sukses Menghapus Data Pemesanan $_GET[id].');
				window.location='laporan-penjualan.html'</script>";	
}


elseif ($_GET[module]=='semuaproduk'){
echo "<hr><span style='float:right;'>
					Filter : ";
					?><select style=' margin-right:3px; margin-bottom:5px;' ONCHANGE="location = this.options[this.selectedIndex].value;">
					<?php echo "<option value=0 selected>- Pilih Jenis Produk -</option>";
						$tampil=mysql_query("SELECT * FROM rb_kategori_produk ORDER BY nama_kategori");
						while($r=mysql_fetch_array($tampil)){
						echo "<option value='filterrr-$r[id_kategori].html'>$r[nama_kategori]</option>";
						}
			  echo "</select></span>";
	echo " <div id='container'>
			<div id='demo'>
<table class='display' id='example'>
	<thead>
		<tr>
			<th>no kode</th>
			<th>kode</th>
			<th>Nama Produk</th>
			<th>Nama Distributor</th>
			<th>Harga Jual</th>
			<th>Jenis</th>
			<th>Type</th>
			<th>Stok</th>
			<th>Warna</th>
			<th style='text-align:center;'>Action</th>
		</tr>
	</thead>
	<tfoot>
		<tr style='border: 2px solid #e3e3e3;'>
			<th style='border: none;'>no kode</th>
			<th style='border: none;'>kode</th>
			<th style='border: none;'>Nama Produk</th>
			<th style='border: none;'>Nama Distributor</th>
			<th style='border: none;'>Harga Jual</th>
			<th style='border: none;'>Jenis</th>
			<th style='border: none;'>Type</th>
			<th style='border: none;'>Stok</th>
			<th style='border: none;'>Warna</th>
			<th style='border: none;'>Action</th>
		</tr>
	</tfoot>";
		$kt = mysql_fetch_array(mysql_query("SELECT * FROM rb_kategori_produk ORDER BY rand() LIMIT 1"));
	    $tampil = mysql_query("SELECT * FROM rb_produk left join rb_supplier on rb_produk.id_supplier=rb_supplier.id_supplier where id_kategori='$kt[id_kategori]' ORDER BY id_produk DESC");
		echo "<tbody>";
    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]);
	  if(($no % 2)==0){
			$warna="#ffffff";
	  }else{
			$warna="#E1E1E1";
	  }
	echo "
		<tr bgcolor='$warna'>
			<td class='read_only'>$r[no_kode]</td>
			<td class='read_only'>$r[kode_produk]</td>";
            $cekd = mysql_num_rows(mysql_query("SELECT * FROM rb_produk_detail where id_produk='$r[id_produk]'"));
			if ($cekd >= 1){
				$d = mysql_fetch_array(mysql_query("SELECT * FROM rb_produk_detail a 
													join rb_jenis b on a.id_jenis=b.id_jenis
	    												join rb_type c on a.id_type=c.id_type where a.id_produk='$r[id_produk]'"));
            	echo "<td class='linkSysteM'><a href='#' alt='Type : $d[type] - Jenis : $d[jenis]'>$r[nama_produk]</a>
            								<a href='#' alt='SPH ($d[R_SPH]), CYL ($d[R_CYL]), AXS ($d[R_AXS]), ADD ($d[R_ADD]), PD ($d[PD])' style='background:#000; padding:2px 10px 2px 10px; color:#fff; text-decoration:none'>R</a>
            								 <a href='#' alt='SPH ($d[L_SPH]), CYL ($d[L_CYL]), AXS ($d[L_AXS]), ADD ($d[L_ADD]), PD ($d[PD2])' style='background:#000; padding:2px 10px 2px 10px; color:#fff; text-decoration:none'>L</a></td>";
			}else{
				echo "<td>$r[nama_produk]</td>";
			}
            echo "<td>$r[nama_supplier]</td>
            <td>Rp $harga</td>";
			if ($r[stok]==0){
				echo "<td style='background:red; color:#fff; text-align:center;'>Habis</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>";
			}
		            echo "<td>$r[warna]</td><td width='75'><center><a class='linkkk' href=aksi.php?module=keranjang&act=tambah&id=$r[id_produk]>Pilih</a></center></td>
		</tr>";
		}
echo "	</tbody>
 </table>
</div></div>";
}

elseif ($_GET[module]=='filterproduk'){
echo "<hr><span style='float:right;'>
					Filter/Tampilkan : ";
					$sqle=mysql_query("SELECT * FROM rb_kategori_produk where id_kategori='$_GET[produk]'");
					$pp=mysql_fetch_array($sqle);
					$cekp = mysql_num_rows(mysql_query("SELECT * FROM rb_kategori_produk where nama_kategori LIKE '%pesanan%' AND id_kategori='$_GET[produk]'"));

					?><select style=' margin-right:3px; margin-bottom:5px;' ONCHANGE="location = this.options[this.selectedIndex].value;">
					<?php echo "<option value=0 selected> $pp[nama_kategori] </option>";
						$tampil=mysql_query("SELECT * FROM rb_kategori_produk ORDER BY nama_kategori");
						while($r=mysql_fetch_array($tampil)){
						echo "<option value='filterrr-$r[id_kategori].html'>$r[nama_kategori]</option>";
						}
			  echo "</select></span>";
	echo " <div id='container'>
			<div id='demo'>
<table class='display' id='example'>
	<thead>
		<tr>
			<th>no kode</th>
			<th>kode</th>
			<th>Nama Produk</th>
			<th>Jenis</th>
			<th>Type</th>
			<th>Nama Distributor</th>
			<th>Harga Jual</th>
			";			
			if($cekp <= 0){
				echo "<th>Stok</th>";
			}
			echo "<th style='text-align:center;'>Action</th>
		</tr>
	</thead>
	<tfoot>
		<tr style='border: 2px solid #e3e3e3;'>
			<th style='border: none;'>no kode</th>
			<th style='border: none;'>kode</th>
			<th style='border: none;'>Nama Produk</th>
			<th style='border: none;'>Jenis</th>
			<th style='border: none;'>Type</th>
			<th style='border: none;'>Nama Distributor</th>
			<th style='border: none;'>Harga Jual</th>
			";
			if($cekp <= 0){
				echo "<th style='border: none;'>Stok</th>";
			}
			echo "<th style='border: none;'>Action</th>

		</tr>
	</tfoot>";
	    $tampil = mysql_query("SELECT * FROM rb_produk left join rb_supplier on rb_produk.id_supplier=rb_supplier.id_supplier where id_kategori='$_GET[produk]' ORDER BY id_produk DESC");
		echo "<tbody>";
    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]);
	  if(($no % 2)==0){
			$warna="#ffffff";
		  }
		  else{
			$warna="#E1E1E1";
		  }
	echo "
		<tr bgcolor='$warna'>
			<td class='read_only'>$r[no_kode]</td>  
			<td class='read_only'>$r[kode_produk]</td>";
            $cekd = mysql_num_rows(mysql_query("SELECT * FROM rb_produk_detail where id_produk='$r[id_produk]'"));
			if ($cekd >= 1){
				$d = mysql_fetch_array(mysql_query("SELECT * FROM rb_produk_detail a 
													join rb_jenis b on a.id_jenis=b.id_jenis
	    												join rb_type c on a.id_type=c.id_type where a.id_produk='$r[id_produk]'"));
            	echo "<td class='linkSysteM'><a href='#' alt='Type : $d[type] - Jenis : $d[jenis]'>$r[nama_produk]</a>
            								<a href='#' alt='SPH ($d[R_SPH]), CYL ($d[R_CYL]), AXS ($d[R_AXS]), ADD ($d[R_ADD]), PD ($d[PD])' style='background:#000; padding:2px 10px 2px 10px; color:#fff; text-decoration:none'>R</a>
            								 <a href='#' alt='SPH ($d[L_SPH]), CYL ($d[L_CYL]), AXS ($d[L_AXS]), ADD ($d[L_ADD]), PD ($d[PD2])' style='background:#000; padding:2px 10px 2px 10px; color:#fff; text-decoration:none'>L</a></td>";
				 echo "<td >$d[jenis]</td>
                     <td >$d[type]</td>";
			}else{
				echo "<td>$r[nama_produk]</td><td></td><td></td>";
			}
            echo "<td>$r[nama_supplier]</td>
            <td>Rp $harga</td>";
            if($cekp <= 0){
				if ($r[stok]==0){
					echo "<td style='background:red; color:#fff; text-align:center;'>Habis</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>";
				}
			}
		            echo "<td width='75'><center><a class='linkkk' href=aksi.php?module=keranjang&act=tambah&id=$r[id_produk]>Pilih</a></center></td>
		</tr>";
		}
echo "	</tbody>
 </table>
</div></div>";
}

elseif ($_GET[module]=='semuaprodukk'){
$cekp = mysql_num_rows(mysql_query("SELECT * FROM rb_kategori_produk where nama_kategori LIKE '%pesanan%' AND id_kategori='$_GET[pilih]'"));
echo "<hr><span style='float:right;'>
					Filter : ";
					?><select style=' margin-right:3px; margin-bottom:5px;' ONCHANGE="location = this.options[this.selectedIndex].value;">
					<?php echo "<option value=0 selected>- Pilih Jenis Produk -</option>";
						$tampil=mysql_query("SELECT * FROM rb_kategori_produk ORDER BY nama_kategori");
						while($r=mysql_fetch_array($tampil)){
						echo "<option value='media.php?module=semuaprodukk&pilih=$r[id_kategori]'>$r[nama_kategori]</option>";
					}

			  echo "</select></span>
<div id='container'>
<div id='demo'>
<table class='display' id='example'>
	<thead>
		<tr>
			<th>no kode</th>
			<th>kode</th>
			<th>Nama Produk</th>
			<th>Nama Distributor</th>
			<th>Harga Grosir</th>";
			if ($cekp <= 0){
				echo "<th>Stok</th>";
			}
			echo "<th style='text-align:center;'>Action</th>
		</tr>
	</thead>
	<tfoot>
		<tr style='border: 2px solid #e3e3e3;'>
			<th style='border: none;'>no kode</th>
			<th style='border: none;'>kode</th>
			<th style='border: none;'>Nama Produk</th>
			<th style='border: none;'>Nama Distributor</th>
			<th style='border: none;'>Harga Grosir</th>";
			if ($cekp <= 0){
				echo "<th style='border: none;'>Stok</th>";
			}
			echo "<th style='border: none;'>Action</th>
		</tr>
	</tfoot>";
	$kt = mysql_fetch_array(mysql_query("SELECT * FROM rb_kategori_produk ORDER BY rand() LIMIT 1"));
		if ($_GET[pilih]){
			$tampil = mysql_query("SELECT * FROM rb_produk a where a.id_kategori='$_GET[pilih]' ORDER BY a.id_produk DESC");
		}else{
	    	$tampil = mysql_query("SELECT * FROM rb_produk left join rb_supplier on rb_produk.id_supplier=rb_supplier.id_supplier where rb_produk.id_kategori='$kt[id_kategori]' ORDER BY id_produk DESC");
		}
		echo "<tbody>";
    while($r=mysql_fetch_array($tampil)){
      $tanggal=tgl_indo($r[tgl_masuk]);
      $harga=format_rupiah($r[harga_grosir]);
	  $harga_grosir=format_rupiah($r[harga_grosir]);
	  $harga_pokok=format_rupiah($r[harga_pokok]);
	  if(($no % 2)==0){
			$warna="#ffffff";
		  }
		  else{
			$warna="#E1E1E1";
		  }
	echo "
		<tr bgcolor='$warna'>
			<td class='read_only'>$r[no_kode]</td>
			<td class='read_only'>$r[kode_produk]</td>
            <td>$r[nama_produk]</td>
			<td>$r[nama_supplier]</td>
            <td>Rp $harga</td>";
            if ($cekp <= 0){
				if ($r[stok]==0){
					echo "<td style='background:red; color:#fff; text-align:center;'>Habis</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>";
				}
			}
		            echo "<td width='75'><center><a class='linkkk' href=aksii.php?module=keranjang&act=tambah&id=$r[id_produk]>Pilih</a></center></td>
		</tr>";
		}
echo "	</tbody>
 </table>
</div></div>";
}

//Rekap Penjualan Per Produk -----------------------------------------------------------------------------------------------------------------------------------------------------------------------
elseif ($_GET[module]=='rekapproduk'){
	echo "<div class='post_title' style='margin-bottom:20px; position:relative;'><b>Rekap Laporan Penjualan Produk Pada Optik<hr></b></div>
			<span style='float:right; margin-right:0px; margin-bottom:5px;'>
				<form action='tanggal.html' method='POST'> 
					<input type=text id='tgl1' name='tgl1' style='width:36%' placeholder='Dari Tanggal. . .'>
					- <input type=text id='tgl2' name='tgl2' style='width:36%' placeholder='Sampai Tanggal. . .'>
					<input type=submit value=View>
				</form>
			</span>
			
<table style='border: 2px solid #e3e3e3;'width=100%>
		<tr bgcolor='#2e2e2e'>
			<th width='20px'>No</th>
			<th>Nama Barang</th>
			<th>Distributor</th>
			<th>Jumlah Terjual</th>
			<th>Total Stok</th>
		</tr>";
$batas=10;
$halaman=$_GET['halaman'];
	if(empty($halaman))
	{
		$posisi=0;
		$halaman=1;
	}else{
		$posisi = ($halaman-1) * $batas;
	}
	    $tampill=mysql_query("SELECT * FROM rb_orders_detail 
								left join rb_produk on rb_orders_detail.id_produk=rb_produk.id_produk 
									left join rb_kategori_produk on rb_orders_detail.id_produk=rb_produk.id_produk 
										left join rb_orders on rb_orders_detail.id_orders=rb_orders.id_orders
											left join rb_supplier on rb_produk.id_supplier=rb_supplier.id_supplier 
													GROUP BY rb_orders_detail.id_produk ASC LIMIT $posisi,$batas");
    $no = $posisi+1;
	while($r=mysql_fetch_array($tampill)){	
	  if(($no % 2)==0){
			$warna="#E1E1E1";
		  }
		  else{
			$warna="#ffffff";
		  }
	echo "
		<tr bgcolor='$warna'>
			<td class='read_only' style='color:blue; height:27px;'>$no</td>
            <td>$r[nama_produk]</td>
			<td>$r[nama_supplier]</td>
			<td>$r[jumlah]</td>
			<td>$r[stok]</td>
		</tr>";
		$no++;
		}
		
				$sql = "SELECT SUM(harga*jumlah) AS total_harga,
								SUM(harga*jumlah*diskon/100) AS total_diskon,
						SUM(harga_pokok*jumlah) AS total_pokok,
						SUM(jumlah) AS total_jumlah FROM rb_produk left join rb_orders_detail on rb_produk.id_produk=rb_orders_detail.id_produk ";
		$result = mysql_query($sql) or die (mysql_error());
		$t = mysql_fetch_array($result);
		 $total_harga=format_rupiah($t[total_harga]);
		 $total_pokok=format_rupiah($t[total_pokok]);
		 $total_jumlah=format_rupiah($t[total_jumlah]);
		 $total_diskon=format_rupiah($t[total_diskon]);
		 $total_jual=$t[total_harga]-$t[total_diskon];
		 
		 $total_jual_rp=format_rupiah($total_jual);
		 $untung=$total_jual-$t[total_pokok];
		 $untung_rp=format_rupiah($untung);
echo "</table><br/>";

$tampil2="select * from rb_orders_detail GROUP BY rb_orders_detail.id_produk";
$hasil2=mysql_query($tampil2);
$jmldata=mysql_num_rows($hasil2);
$jmlhalaman=ceil($jmldata/$batas);

//link ke halaman sebelumnya (previous)
if($halaman > 1)
{
	$previous=$halaman-1;
	echo "<b><A class='hover1' HREF=page-rekap-produk-1.html><< First</A>
        <A class='hover1' HREF=page-rekap-produk-$previous.html>< Previous</A> | </b>";
}
else
{ 
	echo "<b><span class='notlink '><< First</span> <span class='notlink '>< Previous</span> | </b>";
}

$angka=($halaman > 5 ? " ...... " : " ");
for($i=$halaman-5;$i<$halaman;$i++)
{
  if ($i < 1) 
      continue;
  $angka .= "<b><a class='linkk' href=page-rekap-produk-$i.html>$i</a> </b>";
}

$angka .= " <span class='hover'><b>$halaman</b></span> ";
for($i=$halaman+1;$i<($halaman+5);$i++)
{
  if ($i > $jmlhalaman) 
      break;
  $angka .= "<b><a class='linkk' href=page-rekap-produk-$i.html>$i</A></b> ";
}

$angka .= ($halaman+5<$jmlhalaman ? " ......  
          <b><a class='linkk' href=page-rekap-produk-$jmlhalaman.html>$jmlhalaman</A> " : " </b>");

echo "$angka";

//link kehalaman berikutnya (Next)
if($halaman < $jmlhalaman)
{
	$next=$halaman+1;
	echo "<b> | <A class='hover1' HREF=page-rekap-produk-$next.html>Next ></A>
  <A class='hover1' HREF=page-rekap-produk-$jmlhalaman.html>Last >></A> </b>";
}
else
{ 
	echo "<b> | <span class='notlink '>Next ></span> <span class='notlink '>Last >></span></b>";
}
echo "<hr></p>";
}

?>