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

	
	if ($_SESSION['nama'] == ''){
		header('Location:index.php');
	}
	else{
?>
<html>
 
  <body class="hold-transition skin-blue sidebar-mini layout-boxed">
    <div class="wrapper">
		<?php include "../header.php";?>
      
		<?php include "../menu.php";?>

      <!-- Content Wrapper. Contains page content -->
      <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
          <h1>
            Invoice
			<?php
				$inv = $_GET[id];
				$noord = str_pad($inv, 4, "0", STR_PAD_LEFT);
				echo"<small>#$noord</small>";
			?>
          </h1>
          <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            <li><a href="#">Pembelian</a></li>
            <li class="active">Return Invoice</li>
          </ol>
        </section>

        <div class="pad margin no-print">
          <div class="callout callout-info" style="margin-bottom: 0!important;">
            <h4><i class="fa fa-info"></i> Note:</h4>
            This page has been enhanced for printing. Click the print button at the bottom of the invoice to test.
          </div>
        </div>

        <!-- Main content -->
        <section class="invoice">
         
          <!-- info row -->
          <div class="row invoice-info">
			<div class="col-xs-12">
			  <h2 class="page-header">
				<i class="fa fa-shopping-cart" ></i> Retur Pembelian
			  </h2>
			</div><!-- /.col -->
            <div class="col-sm-12 invoice-col">
			<?php
			  $custid 	=  mysql_result(mysql_query("select cust from belitax where billno = $inv "),0);
			  $cust 	=  mysql_result(mysql_query("select nama from supplier where id = $custid"),0);
			  $alamat	=  mysql_result(mysql_query("select alamat from supplier where id = $custid"),0);
			  $telp		=  mysql_result(mysql_query("select telp from supplier where id = $custid"),0);
			  $tgl 		=  mysql_result(mysql_query("select billdate from belitax where billno = $inv"),0) ;
			  $billdate =  tgl_ind($tgl);
			  $inv 		= $_GET['id'];
			  $noord 	= "AA".substr($tgl,2,2).substr($tgl,5,2)." ".str_pad($inv, 4, "0", STR_PAD_LEFT);
			  
				
				echo"
				<div class='col-sm-4 invoice-col'>
				Tanggal<br>Nomor<br>Kepada Yth
				</div>
				<div class='col-sm-8 invoice-col'>
				$billdate<br>$noord<br>$cust<br> &nbsp;$alamat
				</div>
				
				";

			  ?>
            </div><!-- /.col -->
           
            
          </div><!-- /.row -->

          <!-- Table row -->
          <div class="row">
            <div class="col-xs-12 table-responsive">
              <table class="table table-striped">
                <thead>
                  <tr>
                    <th>No</th>
                    <th>Product</th>
					<th>Qty</th>
                    <th>Harga@</th>
					<th>Disc(%)</th>
                    <th>Jumlah</th>
                  </tr>
                </thead>
                <tbody>
				<?php
				$i = 0;
				$cek = mysql_query("Select * from belitaxdetail where billno = $inv order by billno desc,id asc");
				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] * -1);
					$disc = format_rupiah($r[disc]);
					$tot = format_rupiah(($r[qty] * ($r[harga] -($r[harga] * $r[disc] / 100))));
					echo"
					  <tr>
						<td>$i</td>
						<td>$produk</td>
						<td>$qty</td>
						<td>$uprice</td>
						<td>$disc</td>
						<td>$tot</td>
					  </tr>";
				}
				?>
                </tbody>
              </table>
            </div><!-- /.col -->
          </div><!-- /.row -->

          <div class="row">
            <!-- accepted payments column -->
            <div class="col-xs-6">
			<div class="table-responsive">
                <table class="table">
                  <tr>
                    <th style="width:50%">Tanda Terima<br><br><br>______________</th>
					<th style="width:50%">Hormat Kami<br><br><br>GATRATANI</th>
                  </tr>

				 
                </table>
            </div>
			</div><!-- /.col -->
            <div class="col-xs-6">
              <div class="table-responsive">
                <table class="table">
                  <tr>
                    <th style="width:50%">Subtotal:</th>
					<?php
						$grand = format_rupiah(mysql_result(mysql_query("select sum( -1 * qty*(harga - (harga * disc / 100))) from belitaxdetail where billno = $inv "),0));
						echo"<td>$grand</td>";
					?>
                  </tr>
				 
                </table>
              </div>
            </div><!-- /.col -->
          </div><!-- /.row -->

          <!-- this row will not appear when printing -->
          <div class="row no-print">
            <div class="col-xs-12">
			<?php
			  echo"
              <a href='invoice-print.php?id=$inv' target='_blank' class='btn btn-default'><i class='fa fa-print'></i> Print</a>";
			?>
			  <!--
              <button class="btn btn-success pull-right"><i class="fa fa-credit-card"></i> Submit Payment</button>
              <button class="btn btn-primary pull-right" style="margin-right: 5px;"><i class="fa fa-download"></i> Generate PDF</button>
			  -->
            </div>
          </div>
        </section><!-- /.content -->
        <div class="clearfix"></div>
      </div><!-- /.content-wrapper -->
      <?php include "../footer.php";?>
		

      <!-- Control Sidebar -->
      <aside class="control-sidebar control-sidebar-dark">

        <!-- Tab panes -->
        <div class="tab-content">
          <!-- Home tab content -->
          <div class="tab-pane" id="control-sidebar-home-tab">

          </div><!-- /.tab-pane -->

        </div>
      </aside>

     
      <!-- Add the sidebar's background. This div must be placed
           immediately after the control sidebar -->
      <div class="control-sidebar-bg"></div>
    </div><!-- ./wrapper -->

    <!-- jQuery 2.1.4 -->
    <script src="../../plugins/jQuery/jQuery-2.1.4.min.js"></script>
    <!-- Bootstrap 3.3.5 -->
    <script src="../../bootstrap/js/bootstrap.min.js"></script>
    <!-- FastClick -->
    <script src="../../plugins/fastclick/fastclick.min.js"></script>
    <!-- AdminLTE App -->
    <script src="../../dist/js/app.min.js"></script>
    <!-- AdminLTE for demo purposes -->
    <script src="../../dist/js/demo.js"></script>
  </body>
</html>
<?php 
	}
?>