<!DOCTYPE html>
<?php 
	session_start();
	@ob_start();
	include "../../config/koneksi.php";
	include "../../config/fungsi_rupiah.php";
	include "../../config/fungsi_indotgl.php";

?>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>GATRATANI | Invoice</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
        <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body onload="window.print();">
    <div class="wrapper">
      <!-- Main content -->
      <section class="invoice">
        <!-- title row -->
        
        <!-- info row -->
        <div class="row invoice-info">
			<div class="col-xs-12">
			  <h2 class="page-header">
				<i class="fa fa-shopping-cart" ></i> SALE INVOICE
			  </h2>
			</div><!-- /.col -->
			
			 <div class="col-sm-12 ">
			<?php
			  $inv = $_GET['id'];
			  $tgl = mysql_result(mysql_query("select billdate from jualcstax where billno = $inv"),0);
			  $noord = "EE".substr($tgl,2,2).substr($tgl,5,2)." ".str_pad($inv, 4, "0", STR_PAD_LEFT);
			  $custid 	=  mysql_result(mysql_query("select cust from jualcstax where billno = $inv"),0);
			  $cust 	=  mysql_result(mysql_query("select nama from customer where id = $custid"),0);
			  $alamat	=  mysql_result(mysql_query("select alamat from customer where id = $custid"),0);
			  $telp		=  mysql_result(mysql_query("select telp from customer where id = $custid"),0);
			  $billdate = tgl_ind($tgl);
				
				
				echo "<table style='width:100%'>
						<tr>
							<td width='15%'>Tanggal </td>
							<td width='2%'>: </td>
							<td width='83%'> $billdate</td>
						</tr>
						<tr>
							<td>Nomor </td>
							<td>: </td>
							<td> $noord</td>
						</tr>
						<tr>
							<td>Kepada Yth, </td>
							<td>&nbsp </td>
							<td>$cust<br>$alamat</td>
						</tr>
					  </table>
				";
			
			
			  ?>
            </div><!-- /.col -->
        </div><!-- /.row -->

        <!-- Table row -->
        <div class="row">
          <div class="col-xs-12 table-responsive">
            <table style="width:100%">
              <thead>
                <tr>
                    <th height=20px>No</th>
                    <th align="left">Product</th>
					<th align='center'>Qty</th>
                    <th align = 'right'>Harga@</th>
					<th >Disc(%)</th>
                    <th align = 'right' >Jumlah</th>
                </tr>
              </thead>
             <tbody>
				<?php
				$i = 0;
				$cek = mysql_query("Select * from jualcstaxdetail where billno = $inv order by billno desc");
				while ($r=mysql_fetch_array($cek)){	
					$i = $i + 1;
					$produk = mysql_result(mysql_query("select produk from produk where id = $r[produk]"),0);
					$uprice = format_rupiah($r[harga]);
					$qty = format_rupiah($r[qty]);
					$disc = format_rupiah($r[disc]);
					$tot = format_rupiah(($r[qty] * ($r[harga] -($r[harga] * $r[disc] / 100))));
					echo"
					  <tr>
						<td height=20px width='5%' align = center>$i</td>
						<td width='45%'>$produk</td>
						<td width='5%' align = center>$qty</td>
						<td width='20%' align=right>$uprice</td>
						<td width='5%' align = center>$disc</td>
						<td width='20%' align=right>$tot</td>
					  </tr>";
				}
				
				
				for ($j = $i + 1; $j <= 10; $j++) {
					echo"
					  <tr>
						<td> &nbsp; </td>
						<td> </td>
						<td align='center'> &nbsp;</td>
						<td align=right> &nbsp;</td>
						<td align = 'center'>&nbsp; </td>
						<td align=right>&nbsp; </td>
					  </tr>";
				} 
				?>
             </tbody>
            </table>
          </div><!-- /.col -->
        </div><!-- /.row --> 
<hr align="center" color="black">
        <div class="row">
          <!-- accepted payments column -->
          <div>
			<div class="table-responsive">
                <table  style="width:100%">
                  <tr>
                    <td width='30%'>Tanda Terima</th>
					<td width='30%'>Hormat Kami</th>
					<?php
						$diskonn = mysql_result(mysql_query("select diskon from jualcstax where billno = $inv"),0);
						if ($diskonn > 0){
							$grandd = mysql_result(mysql_query("select sum(qty*(harga - (harga * disc / 100))) from jualcstaxdetail where billno = $inv"),0);
							$grand = format_rupiah($grandd);
							$diskonn2 = format_rupiah($diskonn);
							$grandt = format_rupiah($grandd - $diskonn);
							echo"<td width='40%' align ='right'>Subtotal : $grand <br>
																Disc &nbsp;&nbsp;&nbsp;	: $diskonn2<br>
																Grandtotal : $grandt</td>";
						}else{
							$grand = format_rupiah(mysql_result(mysql_query("select sum(qty*(harga - (harga * disc / 100))) from jualcstaxdetail where billno = $inv"),0));
							echo"<td width='40%' align ='right'>Subtotal : $grand</td>";
						}
					?>
                  </tr>

				 
                </table>
            </div>
          </div><!-- /.col -->
         
        </div><!-- /.row -->
      </section><!-- /.content -->
    </div><!-- ./wrapper -->

    <!-- AdminLTE App -->
	<style>

    body {
      font-family:Courier New;
	  font-weight: bold;
    }
	th {
		border-top: 1px solid black;
		border-bottom: 1px solid black;
	}
    </style>
    <script src="../../dist/js/app.min.js"></script>
  </body>
</html>
