<?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'];
	$id_branch  = $_REQUEST['id_branch'];
	$tipe  = $_REQUEST['tipe'];
	
	if($act == 1)
	{
		$kode = $_REQUEST['kode'];
		$id_branch  = $_REQUEST['id_branch'];
		$tipe  = $_REQUEST['tipe'];
		$sql = mysql_query("select * from bucket_stock where barcode='$kode' and user_stock='$USERNAME'");
		if(mysql_num_rows($sql) > 0)
		{
				?>
				<script language="javascript">
                document.location="stock_ofnumb.php?id_branch=<?php echo $id_branch; ?>&tipe=<?php echo $tipe; ?>";
                </script>
				<?php
		}
		else
		{
		$insert = mysql_query("insert into bucket_stock (barcode,user_stock) values ('$kode','$USERNAME')");
		if($insert)
		{
			?>
				<script language="javascript">
                document.location="stock_ofnumb.php?id_branch=<?php echo $id_branch; ?>&tipe=<?php echo $tipe; ?>";
                </script>
				<?php
		}
		}

	}
	
	if($act == 2)
	{
		$insert = mysql_query("delete from bucket_stock where user_stock = '$USERNAME'");
		if($insert)
		{
			?>
				<script language="javascript">
                document.location="stock_ofnumb.php?id_branch=<?php echo $id_branch; ?>&tipe=<?php echo $tipe; ?>";
                </script>
				<?php
		}

	}
	?>
<body class="withvernav" onLoad="document.forms.kode.focus();">
<?php include "include/head2.php"; ?>
<?php include "include/leftmenu.php"; ?>
<?php include "include/top.php"; ?>
  <h1><i class="icon-bar-chart"></i> Stock Opname</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 class="stdform stdform2" method="post" action="stock_ofnumb.php?act=1&id_branch=<?php echo $id_branch; ?>&tipe=<?php echo $tipe; ?>" name="forms" id="forms">
                        <div class="form-group">
                          <label class="col-md-4 control-label">Barcode</label>
                          <div class="col-md-8">
                            <input type="text" class="form-control" name="kode" id="kode" >
                          </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>
                             <a href="stock_ofnumb.php?act=2" class="edit"><input name="save" type="button" class="btn btn-default" value="Clear Temp" /></a>
                          </div>
                        </div>
                      </form>
                    <?php
					$sql = mysql_query("select * from bucket_stock where user_stock = '$USERNAME'");
					if(mysql_num_rows($sql) > 0)
					{
					?>
                     <table class="table table-striped table-bordered table-hover">
                  <thead>
                    <tr>
                      <th>Barcode No.</th>
                    </tr>
                  </thead>
                  <tbody>
                        <?php
						
						while($fetch = mysql_fetch_array($sql))
						{
								$barcode = $fetch['barcode'];
					?>
                        <tr>
                          <td><?php echo $barcode; ?></td>
                       </tr>
                       <?php
						}
						
						?>
                  </tbody>
                </table>
                    </br>
         <a href="stock_ofnumb2.php?act=1&id_branch=<?php echo $id_branch; ?>&tipe=<?php echo $tipe; ?>"><input name="save" type="button" class="btn btn-default" value="Stock Sinkron" /></a>&nbsp;
         <a href="stock_ofnumb2.php?act=2&id_branch=<?php echo $id_branch; ?>&tipe=<?php echo $tipe; ?>"><input name="save" type="button" class="btn btn-default" value="Barcode Exists" /></a>&nbsp;
          <a href="stock_ofnumb2.php?act=3&id_branch=<?php echo $id_branch; ?>&tipe=<?php echo $tipe; ?>"><input name="save" type="button" class="btn btn-default" value="Stock Exists" /></a>
         <?php
					}
					?>
                    </div>
                    </div>
                    </div>
                    </div>
                    </div>
                    

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

</html>