<?php
session_name("AUTHENUSER");
session_start();
$USERNAME = $_SESSION['SES_USERNAME'];
if(!session_name("AUTHENUSER"))
	{
?>
						<script language="javascript">
						 alert("Waktu Login telah habis.Silahkan Login Kembali");
						document.location="index.php";
						</script>
<?php
	}
if(!$USERNAME)
	{
?>
						<script language="javascript">
						 alert("Harap Login Dahulu.");
						document.location="index.php";
						</script>
<?php
	}
	?>
	<?php 
	include "common/config.php";
	include "include/head.php";
	?>

    <?php
	$act  = $_REQUEST['act'];
	$invoice = $_REQUEST['invoice'];
	if($act == 2)
	{
		$insert = mysql_query("insert into reprint_invoice (invoice, user_update) values ('$invoice','$USERNAME')");
		if($insert)
		{
			?>
				<script language="javascript">
                document.location="reprint_invoice.php?invoice=<?php echo $invoice; ?>";
                </script>
				<?php
		}

	}
	?>
<body>
<?php include "include/head2.php"; ?>
<?php include "include/leftmenu.php"; ?>
<?php include "include/top.php"; ?>
  <h1><i class="icon-bar-chart"></i> Reprint Invoice</h1>
</div>

<!--<ol class="breadcrumb">
  <li><a href="#">Home</a></li>
  <li><a href="#">Bread</a></li>
  <li><a href="#">Crumbs</a></li>
  <li class="active">Example</li>
</ol>-->
          <div class="main-content">
            <div class="row">
                <div class="widget">
                  <div class="widget-content-white glossed">
                    <div class="padded">
                      <form method="post" action="reprint_invoice.php" role="form" class="form-horizontal">
                        <div class="form-group">
                          <label class="col-md-4 control-label">Invoice No.</label>
                          <div class="col-md-8">
                            <input type="text" class="form-control" name="invoice" id="invoice" >
                          </div>
                        </div>
                      
                        <div class="form-group">
                          <div class="col-md-offset-4 col-md-8">
                            <button type="submit" class="btn btn-default">Submit</button>
                            <button type="reset" class="btn btn-default">Reset</button>
                          </div>
                        </div>
                      </form>
                      <?php if($invoice <> "") { ?>
                        <table class="table table-striped table-bordered table-hover">
                  <thead>
                    <tr>
                      <th>Invoice No.</th>
                            <th>Invoice Date</th>
                            <th>Sales Person</th>
                            <th>Customer Name</th>
                            <th>Details</th>
                    </tr>
                  </thead>
                  <tbody>
                 <?php
						
						$sql = mysql_query("select * from sales 
						where invoice like '%$invoice%' and status_sales = 1 order by invoice_date");
						while($fetch = mysql_fetch_array($sql))
						{
								list($y, $m, $d)=split ("[-]",$fetch['invoice_date']);
								$invoice_date=$d."-".$m."-".$y;
								$user_update = $fetch['user_update'];
								$id_customer = $fetch['id_customer'];
								$invoice = $fetch['invoice'];
								$nama  = mysql_fetch_array(mysql_query("select * from tbl_customer where id_customer  = '$id_customer'"));
					?>
                        <tr class="gradeX">
                          <td><?php echo $fetch['invoice']; ?></td>
                          <td align="left"><?php echo $invoice_date; ?></td>
                          <td align="left"><?php echo $fetch['user_update']; ?></td>
                          <td align="left"><?php echo $nama['nama_customer']; ?></td>
                         <td align="center"><a href="reprint_invoice.php?invoice=<?php echo $invoice; ?>&act=2" class="edit">Reprint Invoice</a></td>
                       </tr>
                       <?php
						}
						?>
                  </tbody>
                </table>
                <?php
					  }
					  ?>
                    </div>
                    </div>
                    </div>
                    </div>
                    </div>
                   

<?php include "include/foot.php"; ?>
<script src='assets/js/for_pages/dashboard.js'></script>
</body>

</html>