<?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'];
	?>
    
<body>
<?php include "include/head2.php"; ?>
<?php include "include/leftmenu.php"; ?>
<?php include "include/top.php"; ?>
  <h1><i class="icon-bar-chart"></i> Stock Opname  <?php if($act == 1) { echo "Stock Sinkron";} elseif($act == 2){ echo "Barcode Exists";} elseif($act == 3){ echo "Stock Exists";}?></h1>
</div>

   <div class="main-content">
            <div class="widget">
              <h3 class="section-title first-title"><i class="icon-table"></i> Listing Stock Opname</h3>
              <div class="widget-content-white glossed">
                <div class="padded">
                <table class="table table-striped table-bordered table-hover">
                  <thead>
                    <tr>
                      	<th>Barcode No.</th>
                     	<th>Kode Stock</th>
                    </tr>
                  </thead>
                  <tbody>
                       <?php
					 if($act == 1)
					 {
					 	//$sql = mysql_query("select kode_stock,barcodeno from (select kode_stock,barcodeno from inventory_diamond where status_stock=1 and id_status = 3 
//						union all
//						select kode_stock,barcodeno from inventory_gold where status_stock=1 and id_status = 3 
//						union all
//						select kode_stock,barcodeno from inventory_logam where status_stock=1 and id_status = 3 
//						union all
//						select kode_stock,barcodeno from inventory_readyitem where status_stock=1 and id_status = 3 ) a where barcodeno in
//						(select barcode from bucket_stock where user_stock = '$USERNAME') 
//						group by kode_stock,barcodeno
//						order by kode_stock");
						if($tipe == 1)
						{
							$sql = mysql_query("select kode_stock,barcodeno from 
							(select kode_stock,barcodeno from inventory_diamond where status_stock=1 and id_status = 3 and id_branch='$id_branch') a 
							where barcodeno in (select barcode from bucket_stock where user_stock = '$USERNAME') 
							group by kode_stock,barcodeno
							order by kode_stock");
						}
						elseif($tipe == 2)
						{
							$sql = mysql_query("select kode_stock,barcodeno from (
							select kode_stock,barcodeno from inventory_logam where status_stock=1 and id_status = 3  and id_branch='$id_branch'
							) a where barcodeno in
							(select barcode from bucket_stock where user_stock = '$USERNAME') 
							group by kode_stock,barcodeno
							order by kode_stock");
						}
						elseif($tipe == 3)
						{
							$sql = mysql_query("select kode_stock,barcodeno from (
						select kode_stock,barcodeno from inventory_gold where status_stock=1 and id_status = 3 and id_branch='$id_branch'
						) a where barcodeno in
						(select barcode from bucket_stock where user_stock = '$USERNAME') 
						group by kode_stock,barcodeno
						order by kode_stock");
						}
						elseif($tipe == 4)
						{
							$sql = mysql_query("select kode_stock,barcodeno from (
							select kode_stock,barcodeno from inventory_readyitem where status_stock=1 and id_status = 3 and id_branch='$id_branch'
							) a where barcodeno in
							(select barcode from bucket_stock where user_stock = '$USERNAME') 
							group by kode_stock,barcodeno
							order by kode_stock");
						}
						elseif($tipe == 5)
						{
							$sql = mysql_query("select kode_stock,barcodeno from (
							select kode_stock,barcodeno from inventory_cincin where status_stock=1 and id_status = 3 and id_branch='$id_branch'
							) a where barcodeno in
							(select barcode from bucket_stock where user_stock = '$USERNAME') 
							group by kode_stock,barcodeno
							order by kode_stock");
						}
						elseif($tipe == 6)
						{
							$sql = mysql_query("select kode_stock,barcodeno from (
							select kode_stock,barcodeno from inventory_mastura where status_stock=1 and id_status = 3 and id_branch='$id_branch'
							) a where barcodeno in
							(select barcode from bucket_stock where user_stock = '$USERNAME') 
							group by kode_stock,barcodeno
							order by kode_stock");
						}
						elseif($tipe == 7)
						{
							$sql = mysql_query("select kode_stock,barcodeno from (
							select kode_stock,barcodeno from inventory_liontin where status_stock=1 and id_status = 3 and id_branch='$id_branch'
							) a where barcodeno in
							(select barcode from bucket_stock where user_stock = '$USERNAME') 
							group by kode_stock,barcodeno
							order by kode_stock");
						}
						elseif($tipe == 8)
						{
							$sql = mysql_query("select kode_stock,barcodeno from (
							select kode_stock,barcodeno from inventory_kerabu where status_stock=1 and id_status = 3 and id_branch='$id_branch'
							) a where barcodeno in
							(select barcode from bucket_stock where user_stock = '$USERNAME') 
							group by kode_stock,barcodeno
							order by kode_stock");
						}
						elseif($tipe == 8)
						{
							$sql = mysql_query("select kode_stock,barcodeno from (
							select kode_stock,barcodeno from inventory_kerabu where status_stock=1 and id_status = 3 and id_branch='$id_branch'
							) a where barcodeno in
							(select barcode from bucket_stock where user_stock = '$USERNAME') 
							group by kode_stock,barcodeno
							order by kode_stock");
						}
						elseif($tipe == 9)
						{
							$sql = mysql_query("select kode_stock,barcodeno from (
							select kode_stock,barcodeno from inventory_gkgr where status_stock=1 and id_status = 3 and id_branch='$id_branch'
							) a where barcodeno in
							(select barcode from bucket_stock where user_stock = '$USERNAME') 
							group by kode_stock,barcodeno
							order by kode_stock");
						}elseif($tipe == 10)
						{
							$sql = mysql_query("select kode_stock,barcodeno from (
							select kode_stock,barcodeno from inventory_rangka where status_stock=1 and id_status = 3 and id_branch='$id_branch'
							) a where barcodeno in
							(select barcode from bucket_stock where user_stock = '$USERNAME') 
							group by kode_stock,barcodeno
							order by kode_stock");
						}
						
					 }
					 elseif($act == 2)
					 { 
		//			 	$sql = mysql_query("select a.kode_stock as kode_stock,b.barcode as barcodeno from  bucket_stock b 
//						left join 
//						(select kode_stock,barcodeno from inventory_diamond where status_stock=1 and id_status = 3 
//						union all
//						select kode_stock,barcodeno from inventory_gold where status_stock=1 and id_status = 3 
//						union all
//						select kode_stock,barcodeno from inventory_logam where status_stock=1 and id_status = 3 
//						union all
//						select kode_stock,barcodeno from inventory_readyitem where status_stock=1 and id_status = 3 ) a
//						on a.barcodeno = b.barcode and user_stock = '$USERNAME'
//						where a.kode_stock is NULL
//						group by a.kode_stock,b.barcode
//						order by a.kode_stock");
						if($tipe == 1)
						{
							$sql = mysql_query("select a.kode_stock as kode_stock,b.barcode as barcodeno from  bucket_stock b 
						left join 
						(select kode_stock,barcodeno from inventory_diamond where status_stock=1 and id_status = 3 and id_branch='$id_branch') a
						on a.barcodeno = b.barcode and user_stock = '$USERNAME'
						where a.kode_stock is NULL
						group by a.kode_stock,b.barcode
						order by a.kode_stock");
						}
						elseif($tipe == 2)
						{
							$sql = mysql_query("select a.kode_stock as kode_stock,b.barcode as barcodeno from  bucket_stock b 
						left join 
						(select kode_stock,barcodeno from inventory_logam where status_stock=1 and id_status = 3 and id_branch='$id_branch') a
						on a.barcodeno = b.barcode and user_stock = '$USERNAME'
						where a.kode_stock is NULL
						group by a.kode_stock,b.barcode
						order by a.kode_stock");
						}
						elseif($tipe == 3)
						{
							$sql = mysql_query("select a.kode_stock as kode_stock,b.barcode as barcodeno from  bucket_stock b 
						left join 
						(select kode_stock,barcodeno from inventory_gold where status_stock=1 and id_status = 3 and id_branch='$id_branch') a
						on a.barcodeno = b.barcode and user_stock = '$USERNAME'
						where a.kode_stock is NULL
						group by a.kode_stock,b.barcode
						order by a.kode_stock");
						}
						elseif($tipe == 4)
						{
							$sql = mysql_query("select a.kode_stock as kode_stock,b.barcode as barcodeno from  bucket_stock b 
						left join 
						(select kode_stock,barcodeno from inventory_readyitem where status_stock=1 and id_status = 3 and id_branch='$id_branch') a
						on a.barcodeno = b.barcode and user_stock = '$USERNAME'
						where a.kode_stock is NULL
						group by a.kode_stock,b.barcode
						order by a.kode_stock");
						}
						elseif($tipe == 5)
						{
							$sql = mysql_query("select a.kode_stock as kode_stock,b.barcode as barcodeno from  bucket_stock b 
						left join 
						(select kode_stock,barcodeno from inventory_cincin where status_stock=1 and id_status = 3 and id_branch='$id_branch') a
						on a.barcodeno = b.barcode and user_stock = '$USERNAME'
						where a.kode_stock is NULL
						group by a.kode_stock,b.barcode
						order by a.kode_stock");
						}
						elseif($tipe == 6)
						{
							$sql = mysql_query("select a.kode_stock as kode_stock,b.barcode as barcodeno from  bucket_stock b 
						left join 
						(select kode_stock,barcodeno from inventory_mastura where status_stock=1 and id_status = 3 and id_branch='$id_branch') a
						on a.barcodeno = b.barcode and user_stock = '$USERNAME'
						where a.kode_stock is NULL
						group by a.kode_stock,b.barcode
						order by a.kode_stock");
						}
						elseif($tipe == 7)
						{
							$sql = mysql_query("select a.kode_stock as kode_stock,b.barcode as barcodeno from  bucket_stock b 
						left join 
						(select kode_stock,barcodeno from inventory_liontin where status_stock=1 and id_status = 3 and id_branch='$id_branch') a
						on a.barcodeno = b.barcode and user_stock = '$USERNAME'
						where a.kode_stock is NULL
						group by a.kode_stock,b.barcode
						order by a.kode_stock");
						}
						elseif($tipe == 8)
						{
							$sql = mysql_query("select a.kode_stock as kode_stock,b.barcode as barcodeno from  bucket_stock b 
						left join 
						(select kode_stock,barcodeno from inventory_kerabu where status_stock=1 and id_status = 3 and id_branch='$id_branch') a
						on a.barcodeno = b.barcode and user_stock = '$USERNAME'
						where a.kode_stock is NULL
						group by a.kode_stock,b.barcode
						order by a.kode_stock");
						}
						elseif($tipe == 9)
						{
							$sql = mysql_query("select a.kode_stock as kode_stock,b.barcode as barcodeno from  bucket_stock b 
						left join 
						(select kode_stock,barcodeno from inventory_gkgr where status_stock=1 and id_status = 3 and id_branch='$id_branch') a
						on a.barcodeno = b.barcode and user_stock = '$USERNAME'
						where a.kode_stock is NULL
						group by a.kode_stock,b.barcode
						order by a.kode_stock");
						}
						elseif($tipe == 10)
						{
							$sql = mysql_query("select a.kode_stock as kode_stock,b.barcode as barcodeno from  bucket_stock b 
						left join 
						(select kode_stock,barcodeno from inventory_rangka where status_stock=1 and id_status = 3 and id_branch='$id_branch') a
						on a.barcodeno = b.barcode and user_stock = '$USERNAME'
						where a.kode_stock is NULL
						group by a.kode_stock,b.barcode
						order by a.kode_stock");
						}
						
						 
					 }
					 elseif($act == 3)
					 {
						// $sql = mysql_query("select kode_stock,barcodeno from (select kode_stock,barcodeno from inventory_diamond where status_stock=1 and id_status = 3 
//						union all
//						select kode_stock,barcodeno from inventory_gold where status_stock=1 and id_status = 3 
//						union all
//						select kode_stock,barcodeno from inventory_logam where status_stock=1 and id_status = 3 
//						union all
//						select kode_stock,barcodeno from inventory_readyitem where status_stock=1 and id_status = 3 ) a
//						left join bucket_stock b on a.barcodeno = b.barcode and user_stock = '$USERNAME'
//						where b.barcode is NULL
//						group by kode_stock,barcodeno
//						order by kode_stock");
						
							if($tipe == 1)
						{
							 $sql = mysql_query("select kode_stock,barcodeno from (select kode_stock,barcodeno from inventory_diamond where status_stock=1 and id_status = 3 
							and id_branch='$id_branch' ) a
							left join bucket_stock b on a.barcodeno = b.barcode and user_stock = '$USERNAME'
							where b.barcode is NULL
							group by kode_stock,barcodeno
							order by kode_stock");
						}
						elseif($tipe == 2)
						{
							 $sql = mysql_query("select kode_stock,barcodeno from (select kode_stock,barcodeno from inventory_logam where status_stock=1 and id_status = 3 
							and id_branch='$id_branch' ) a
							left join bucket_stock b on a.barcodeno = b.barcode and user_stock = '$USERNAME'
							where b.barcode is NULL
							group by kode_stock,barcodeno
							order by kode_stock");
						}
						elseif($tipe == 3)
						{
							 $sql = mysql_query("select kode_stock,barcodeno from (select kode_stock,barcodeno from inventory_gold where status_stock=1 and id_status = 3 
							and id_branch='$id_branch' ) a
							left join bucket_stock b on a.barcodeno = b.barcode and user_stock = '$USERNAME'
							where b.barcode is NULL
							group by kode_stock,barcodeno
							order by kode_stock");
						}
						elseif($tipe == 4)
						{
							 $sql = mysql_query("select kode_stock,barcodeno from (select kode_stock,barcodeno from inventory_readyitem where status_stock=1 and id_status = 3 
							and id_branch='$id_branch' ) a
							left join bucket_stock b on a.barcodeno = b.barcode and user_stock = '$USERNAME'
							where b.barcode is NULL
							group by kode_stock,barcodeno
							order by kode_stock");
						}
						elseif($tipe == 5)
						{
							 $sql = mysql_query("select kode_stock,barcodeno from (select kode_stock,barcodeno from inventory_cincin where status_stock=1 and id_status = 3 
							and id_branch='$id_branch' ) a
							left join bucket_stock b on a.barcodeno = b.barcode and user_stock = '$USERNAME'
							where b.barcode is NULL
							group by kode_stock,barcodeno
							order by kode_stock");
						}
						elseif($tipe == 6)
						{
							 $sql = mysql_query("select kode_stock,barcodeno from (select kode_stock,barcodeno from inventory_mastura where status_stock=1 and id_status = 3 
							and id_branch='$id_branch' ) a
							left join bucket_stock b on a.barcodeno = b.barcode and user_stock = '$USERNAME'
							where b.barcode is NULL
							group by kode_stock,barcodeno
							order by kode_stock");
						}
						elseif($tipe == 7)
						{
							 $sql = mysql_query("select kode_stock,barcodeno from (select kode_stock,barcodeno from inventory_liontin where status_stock=1 and id_status = 3 
							and id_branch='$id_branch' ) a
							left join bucket_stock b on a.barcodeno = b.barcode and user_stock = '$USERNAME'
							where b.barcode is NULL
							group by kode_stock,barcodeno
							order by kode_stock");
						}
						elseif($tipe == 8)
						{
							 $sql = mysql_query("select kode_stock,barcodeno from (select kode_stock,barcodeno from inventory_kerabu where status_stock=1 and id_status = 3 
							and id_branch='$id_branch' ) a
							left join bucket_stock b on a.barcodeno = b.barcode and user_stock = '$USERNAME'
							where b.barcode is NULL
							group by kode_stock,barcodeno
							order by kode_stock");
						}
						elseif($tipe == 9)
						{
							 $sql = mysql_query("select kode_stock,barcodeno from (select kode_stock,barcodeno from inventory_gkgr where status_stock=1 and id_status = 3 
							and id_branch='$id_branch' ) a
							left join bucket_stock b on a.barcodeno = b.barcode and user_stock = '$USERNAME'
							where b.barcode is NULL
							group by kode_stock,barcodeno
							order by kode_stock");
						}
						elseif($tipe == 10)
						{
							 $sql = mysql_query("select kode_stock,barcodeno from (select kode_stock,barcodeno from inventory_rangka where status_stock=1 and id_status = 3 
							and id_branch='$id_branch' ) a
							left join bucket_stock b on a.barcodeno = b.barcode and user_stock = '$USERNAME'
							where b.barcode is NULL
							group by kode_stock,barcodeno
							order by kode_stock");
						}
						

					 }
						while($fetch = mysql_fetch_array($sql))
						{
								$barcodeno = $fetch['barcodeno'];
								$kode_stock = $fetch['kode_stock'];
					?>
                        <tr class="gradeX">
                          <td><?php echo $barcodeno; ?></td>
                          <td><?php echo $kode_stock; ?></td>
                       </tr>
                       <?php
						}
						
						?>
                  </tbody>
                </table>
                 <input type="button" value=" Back " onClick="document.location='stock_ofnumb.php'" class="btn btn-default" />   
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>

    </div>
  </div>
</div>       

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

</html>