<?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'];
	
	?>

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


   <div class="main-content">
   
            <div class="widget">
            <div class="widget-content-white glossed">
                    <div class="padded">
                      <form role="form" class="form-horizontal" method="post" action="report_inventory.php?inventory=<?php echo $inventory; ?>&act=1">
                        <div class="form-group">
                            <label>Inventory</label>
                               <select name="inventory" id="inventory" class="form-control">
                              <option value="Diamond" <?php if($inventory == "Diamond") { ?> selected="selected" <?php } ?>>Diamond</option>
                              <option value="Gold" <?php if($inventory == "Gold") { ?> selected="selected" <?php } ?>>Gold</option>
                              <option value="LogamMulia" <?php if($inventory == "LogamMulia") { ?> selected="selected" <?php } ?>>LogamMulia</option>
                               <option value="ReadyItem" <?php if($inventory == "ReadyItem") { ?> selected="selected" <?php } ?>>ReadyItem</option>
                              <option value="Services" <?php if($inventory == "Services") { ?> selected="selected" <?php } ?>>Services</option>
                                <option value="Cincin" <?php if($inventory == "Cincin") { ?> selected="selected" <?php } ?>>Cincin</option>
                           <option value="Mastura" <?php if($inventory == "Mastura") { ?> selected="selected" <?php } ?>>Mastura</option>
                           <option value="Liontin" <?php if($inventory == "Liontin") { ?> selected="selected" <?php } ?>>Liontin</option>
                            <option value="Kerabu" <?php if($inventory == "Kerabu") { ?> selected="selected" <?php } ?>>Kerabu</option>
                           <option value="GKGR" <?php if($inventory == "GKGR") { ?> selected="selected" <?php } ?>>Gelang Kaku Gelang Rantai</option>
                           <option value="Rangka" <?php if($inventory == "Rangka") { ?> selected="selected" <?php } ?>>Rangka</option>
                            </select>
                        </div>
                       <div class="form-group">
                          <label>Branch</label>
                            <select class="form-control" name="branch" id="branch">
                             <option  value="" selected>All Branch</option>
                              <?php
                                              $sql3 = "select * from tbl_branch where status_branch=1 order by nama_branch";
                                              $rs3 = mysql_query($sql3);
                                              while($fetch3 = mysql_fetch_array($rs3))
                                              {
                                               ?>
                                          <option  value="<?php echo $fetch3['id_branch']; ?>"><?php echo $fetch3['nama_branch']; ?></option>
                                                      <?php
                                              }
                                             ?>
                            </select>
                        </div>
                        <button class="btn btn-primary" type="submit">Submit</button>
                        <button class="btn btn-default" type="reset">Reset</button>
                      </form>
                    </div>
             </div>
              <?php if($act == 1) {
				  $inventory  = $_REQUEST['inventory'];
				$branch  = $_REQUEST['branch']; 
	 			?>
              <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>Stock ID</th>
                            <th>Branch</th>
                            <th>Supplier Name</th>
                    </tr>
                  </thead>
                  <tbody>
                     <?php
						//$inventory = $_REQUEST['inventory'];
						if($branch == 0)
						{
						$sql = mysql_query("select * from
								  (select 'Diamond' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch from  inventory_diamond where status_stock=1 and id_status = 3
								  union all
								  select 'Gold' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch from  inventory_gold  where status_stock=1 and id_status = 3
								  union all
								  select 'LogamMulia' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch from  inventory_logam  where status_stock=1 and id_status = 3
								  union all
								  select 'ReadyItem' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch from  inventory_readyitem  where status_stock=1 and id_status = 3
								   union all
									  select 'Cincin' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch from  inventory_cincin  where status_stock=1  and id_status = 3							
									  union all
									  select 'Mastura' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch from  inventory_mastura  where status_stock=1 and id_status = 3
									   union all
									  select 'Liontin' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch from  inventory_liontin  where status_stock=1 and id_status = 3
									  union all
									  select 'Kerabu' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch from  inventory_kerabu  where  status_stock=1 and id_status = 3
									  union all
										select 'GKGR' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch from  inventory_gkgr  where status_stock=1 and id_status = 3
									  union all
									  select 'Rangka' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch from  inventory_rangka  where status_stock=1 and id_status = 3) a
									inner join tbl_supplier c on a.id_supplier = c.id_supplier
									left join tbl_branch d on a.id_branch = d.id_branch
									where a.type = '$inventory'
								  order by a.id_stock");
			  }
			  else
			  {
				  $sql = mysql_query("select * from
								  (select 'Diamond' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch from  inventory_diamond where status_stock=1 and id_status = 3
								  union all
								  select 'Gold' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch from  inventory_gold  where status_stock=1 and id_status = 3
								  union all
								  select 'LogamMulia' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch from  inventory_logam  where status_stock=1 and id_status = 3
								  union all
								  select 'ReadyItem' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch from  inventory_readyitem  where status_stock=1 and id_status = 3
								   union all
									  select 'Cincin' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch from  inventory_cincin  where status_stock=1  and id_status = 3							
									  union all
									  select 'Mastura' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch from  inventory_mastura  where status_stock=1 and id_status = 3
									   union all
									  select 'Liontin' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch from  inventory_liontin  where status_stock=1 and id_status = 3
									  union all
									  select 'Kerabu' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch from  inventory_kerabu  where  status_stock=1 and id_status = 3
									  union all
										select 'GKGR' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch from  inventory_gkgr  where status_stock=1 and id_status = 3
									  union all
									  select 'Rangka' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch from  inventory_rangka  where status_stock=1 and id_status = 3) a
									inner join tbl_supplier c on a.id_supplier = c.id_supplier
									left join tbl_branch d on a.id_branch = d.id_branch and status_branch = 1
									where a.type = '$inventory' and a.id_branch = '$branch'
								  order by a.id_stock");
			  }
						while($fetch = mysql_fetch_array($sql))
						{
								$barcodeno = $fetch['barcodeno'];
								$kode_stock = $fetch['kode_stock'];
								$status = $fetch['status'];
								$id_branch = $fetch['id_branch'];
								$nama_branch = $fetch['nama_branch'];
								$nama_supplier = $fetch['nama_supplier'];
								list($y, $m, $d)=split ("[-]",$fetch['orderform_date']);
								$orderform_date=$d."-".$m."-".$y;
								if($id_branch == 0)
								{
									$branch = "Head Office";
								}
								else
								{
									$branch = $nama_branch;
								}
								
					?>
                      <tr class="gradeX">
                        <td><?php echo $barcodeno; ?></td>
                          <td><?php echo $fetch['kode_stock'];?></td>
                          <td><?php echo $branch; ?></td>
                          <td><?php echo $fetch['nama_supplier'];?></td>
                       </tr>
                       <?php
						}
						
						?>
                  </tbody>
                </table>
                </div>
              </div>
              <?php
			  }
			  ?>
            </div>
          </div>
        </div>
      </div>

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

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

</html>