<?php 
  session_start();
  error_reporting(0);
  ?>
<head>
<title>Print Nota Grosir - Optik Minang Solok</title>
<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;
}
#kiri{
width:50%;
float:left;
}

#kanan{
width:50%;
float:right;
padding-top:20px;
margin-bottom:9px;
}
</style>
</head>

<body onload="window.print()">
<?php 
  include "../config/koneksi.php";
  include "../config/fungsi_indotgl.php";
  include "../config/class_paging.php";
  include "../config/library.php";
  include "../config/fungsi_rupiah.php";

  $tampil=mysql_query("SELECT * FROM rb_orders_grosir where id_orders='$_GET[id]'");
  $pt=mysql_fetch_array($tampil);
  $tanggal_pesan=tgl_indo($pt[tanggal_pesan]);
  
echo "<center><h2>OPTIK MINANG SOLOK <span style='color:red; font-size:12px;'>Grosir</span><br/>
				Nota/Bukti Pembelian Grosir pada Optik Minang Solok</h2>
				<p style='margin-top:-16px;'>Jl.K.H. Ahmad Dahlan No 140 B Solok, No Telephone : (0755) 21060</p></center><hr/>
				
		  <div id='kiri'>
		    <table style='border:none;' width=100%><br/>
			  <tr><td width='130px;'><b>No Pesanan</b></td><td>: &nbsp;$pt[id_orders]</td></tr>
			  <tr><td><b>Nama Pemesan</b></td>     <td>: &nbsp;$pt[nama_pemesan]</td></tr>
			  <tr><td><b>Alamat</b></td>     <td>: &nbsp;$pt[alamat]</td></tr>
			</table>
		  </div>
		
		  <div id='kanan'>
			<table style='border:none;' width='100%' >  
			  <tr><td width='130px;'><b>Telepon</b></td>       <td>: &nbsp;$pt[telpon]</td></tr>
			  <tr><td><b>Perusahaan</b></td>   <td>: &nbsp;$pt[perusahaan]</td></tr>
			  <tr><td><b>Tanggal Pesan</b></td>   <td>: &nbsp;$tanggal_pesan</td></tr>
			</table>
		  </div>";

	echo " <br/><table cellpadding=2 width=100% border:1px>
          <tr bgcolor='#000' style='color:#fff'>
				<th>No</th>
				<th>Nama Produk</th>
				<th>Jumlah</th>
				<th>Harga</th>
				<th>Total Harga</th></tr>";
	  $no =1;

    $tampill = mysql_query("SELECT * FROM rb_orders_detail 
							left join rb_produk on rb_orders_detail.id_produk=rb_produk.id_produk 
									where rb_orders_detail.id_orders='$_GET[id]'");
    while($s=mysql_fetch_array($tampill)){
	$subtotall   = $s[harga_grosir] * $s[jumlah];
    $subtotalll   = $s[diskon]/100 * $s[harga_grosir] * $s[jumlah];
	$subtotal 	 =  $subtotall -  $subtotalll;
    $total       = $total + $subtotal;  
      echo "<tr bgcolor=$warna><td class='td'>$no</td>
                <td class='td'>$s[nama_produk]</td>
				<td class='td'>$s[jumlah] </td>
				<td class='td'>Rp ".format_rupiah($s[harga_grosir])."</td>
				<td class='td'>Rp ".format_rupiah($subtotal)."</td></tr>";
	$no++;			
	}
	$tot = mysql_fetch_array(mysql_query("SELECT sum((a.jumlah*b.harga_grosir) - ((a.diskon/100)* (a.jumlah*b.harga_grosir))) as total FROM  rb_orders_detail a left join rb_produk b on a.id_produk=b.id_produk where a.id_orders='$_GET[id]'"));
	$bhu = mysql_fetch_array(mysql_query("SELECT sum(bayar_sisa) as byrhutang FROM rb_sisa where id_orders='$_GET[id]'"));
	$sisa = ($pt[jumlah_bayar] - $tot[total]) + $bhu[byrhutang];

	echo "<tr>
  			<td class='td' colspan=4 style='text-align:right'>Total Rp</td>
  			<td class='td' colspan=5 align=right>".format_rupiah($tot[total])."</td>
  		</tr>
  		<tr>
  			<td class='td' colspan=4 style='text-align:right'>Sub Total Rp</td>
  			<td class='td' colspan=5 align=right>".format_rupiah($tot[total]-$pt[diskon])."</td>
  		</tr>
  		<tr>
  			<td class='td' colspan=4 style='text-align:right'>Diskon</td>
  			<td class='td' colspan=5 align=right>".format_rupiah($pt[diskon])."</td>
  		</tr>
  		<tr>
  			<td class='td' colspan=4 style='text-align:right'>Jumlah Bayar Rp</td>
  			<td class='td' colspan=5 align=right>".format_rupiah($pt[jumlah_bayar])."</td>
  		</tr>
  		
  		<tr>
  			<td class='td' colspan=4 style='text-align:right'>Sisa Rp</td>
  			<td class='td' colspan=5 align=right>".format_rupiah($sisa+$pt[diskon])."</td>
  		</tr>";
	    echo "</table>
	<tr><td><br/><span style='float:right; text-align:center;'> Optik Minang Solok, $tgl_sekarang <br/>
								Karyawan<br/></br></br>
								(.............................................)
								<br/>$_SESSION[namalengkap]</span></td></tr>";
?>