<?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"> -->
                    <table class="table table-bordered">
                  <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");
                                  */
                            
                            $sql = mysql_query("select * from
								  (select 'Diamond' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch, status_stock, id_status from  inventory_diamond where id_status IN (3,4)
								  union all
								  select 'Gold' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch, status_stock, id_status from  inventory_gold  where id_status IN (3,4)
								  union all
								  select 'LogamMulia' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch, status_stock, id_status from  inventory_logam  where id_status IN (3,4)
								  union all
								  select 'ReadyItem' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch, status_stock, id_status from  inventory_readyitem  where id_status IN (3,4)
								   union all
									  select 'Cincin' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch, status_stock, id_status from  inventory_cincin  where id_status IN (3,4)					
									  union all
									  select 'Mastura' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch, status_stock, id_status from  inventory_mastura  where id_status IN (3,4)
									   union all
									  select 'Liontin' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch, status_stock, id_status from  inventory_liontin  where id_status IN (3,4)
									  union all
									  select 'Kerabu' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch, status_stock, id_status from  inventory_kerabu  where id_status IN (3,4)
									  union all
										select 'GKGR' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch, status_stock, id_status from  inventory_gkgr  where id_status IN (3,4)
									  union all
									  select 'Rangka' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch, status_stock, id_status from  inventory_rangka where id_status IN (3,4)) 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");
                                  */
                  $sql = mysql_query("select * from
								  (select 'Diamond' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch, status_stock, id_status from  inventory_diamond where id_status IN (3,4)
								  union all
								  select 'Gold' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch, status_stock, id_status from  inventory_gold  where id_status IN (3,4)
								  union all
								  select 'LogamMulia' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch, status_stock, id_status from  inventory_logam  where id_status IN (3,4)
								  union all
								  select 'ReadyItem' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch, status_stock, id_status from  inventory_readyitem  where id_status IN (3,4)
								   union all
									  select 'Cincin' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch, status_stock, id_status from  inventory_cincin  where id_status IN (3,4)					
									  union all
									  select 'Mastura' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch, status_stock, id_status from  inventory_mastura  where id_status IN (3,4)
									   union all
									  select 'Liontin' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch, status_stock, id_status from  inventory_liontin  where id_status IN (3,4)
									  union all
									  select 'Kerabu' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch, status_stock, id_status from  inventory_kerabu  where id_status IN (3,4)
									  union all
										select 'GKGR' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch, status_stock, id_status from  inventory_gkgr  where id_status IN (3,4)
									  union all
									  select 'Rangka' as type,kode_stock,barcodeno,id_stock,id_supplier,id_branch, status_stock, id_status from  inventory_rangka  where id_status IN (3,4)) 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'];
                                $type=$fetch['type'];
								$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;
								}
                            
                                if($fetch['status_stock']=="1" && $fetch['id_status']<>"4")
                                {
                                    $kelas="";
                                    $kelas2="";
                                }
                                else if($fetch['status_stock']=="2")
                                {
                                    $kelas="style='color:#ff0000'";
                                    $kelas2=" bgcolor='#ddd'";
                                }
                                else if($fetch['id_status']=="4")
                                {
                                    $kelas="style='color:#7f6eca'";
                                    $kelas2=" bgcolor='#e52e2e'";
                                }
                            
                           // echo $fetch['id_status'];  
								
					?>
                      <tr class="gradeX"  <?php echo $kelas2; ?>>
                        <td <?php echo $kelas; ?>  ><?php echo $barcodeno."-".$fetch['status_stock']."-".$fetch['id_status']; ?></td>
                          <td >
                              <?php
                              if($type=="Mastura")
                              {
                                ?>
                                  <a href="view_mastura.php?id_stock=<?php echo $fetch['id_stock']; ?>"><?php echo $kode_stock; ?></a>
                                <?php
                              }
                              else if($type=="GKGR")
                              {
                                ?>
                                  <a href="view_gkgr.php?id_stock=<?php echo $fetch['id_stock']; ?>"><?php echo $kode_stock; ?></a>
                                <?php
                              }
                            else if($type=="ReadyItem")
                              {
                                ?>
                                  <a href="view_readyitem.php?id_stock=<?php echo $fetch['id_stock']; ?>"><?php echo $kode_stock; ?></a>
                                <?php
                              }
                            else if($type=="Gold")
                              {
                                ?>
                                  <a href="view_gold.php?id_stock=<?php echo $fetch['id_stock']; ?>"><?php echo $kode_stock; ?></a>
                                <?php
                              }
                            else if($type=="LogamMulia")
                              {
                                ?>
                                  <a href="view_logam.php?id_stock=<?php echo $fetch['id_stock']; ?>"><?php echo $kode_stock; ?></a>
                                <?php
                              }
                            else if($type=="Diamond")
                              {
                                ?>
                                  <a href="view_diamond.php?id_stock=<?php echo $fetch['id_stock']; ?>"><?php echo $kode_stock; ?></a>
                                <?php
                              }
                            else if($type=="Cincin")
                              {
                                ?>
                                  <a href="view_cincin.php?id_stock=<?php echo $fetch['id_stock']; ?>"><?php echo $kode_stock; ?></a>
                                <?php
                              }
                            else if($type=="Liontin")
                              {
                                ?>
                                  <a href="view_liontin.php?id_stock=<?php echo $fetch['id_stock']; ?>"><?php echo $kode_stock; ?></a>
                                <?php
                              }
                            else if($type=="Kerabu")
                              {
                                ?>
                                  <a href="view_kerabu.php?id_stock=<?php echo $fetch['id_stock']; ?>"><?php echo $kode_stock; ?></a>
                                <?php
                              }
                            else if($type=="Rangka")
                              {
                                ?>
                                  <a href="view_rangka.php?id_stock=<?php echo $fetch['id_stock']; ?>"><?php echo $kode_stock; ?></a>
                                <?php
                              }
                              ?>
                            </td>
                          <td <?php echo $kelas; ?>  ><?php echo $branch; ?></td>
                          <td <?php echo $kelas; ?>  ><?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>