<?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 include 'include/head.php'?>  
    <?php
	$act  = $_REQUEST['act'];
	$id_stock  = $_REQUEST['id_stock'];
	if($act == 3)
	{
		$reason  = $_REQUEST['reason']; 
		$id_stock  = $_REQUEST['id_stock'];
		$delete = mysql_query("update inventory_logam set status_stock = 2,user_update  = '$USERNAME',reasondelete = '$reason', date_update = '$tanggal_update' where id_stock='$id_stock'");
		if($delete)
		{
				?>
				<script language="javascript">
                alert("Delete Logam Mulia Success");
                document.location="inventory_logam.php";
                </script>
				<?php
			}
			else
			{
				?>
				<script language="javascript">
                alert("Delete Logam Mulia Failed");
                document.location="inventory_logam.php";
                </script>
				<?php	
			}
	}
	elseif($act == 2)
	{
		$id_stock  = $_REQUEST['id_stock'];
	?>
	<form action="inventory_logam.php?act=3&id_stock=<?php echo $id_stock; ?>" method="post">
                            <textarea name="reason" id="reason"onBlur="if (this.value == '') {this.value = 'Input Reason';}" onFocus="if (this.value == 'Input Reason') {this.value = '';}">Input Reason</textarea>
                        </br>
                         </br>
                            <button type="submit" class="btn btn-default">Submit</button>
                         
                        
    
    </form>
    
	<?php
	}
	else
	{
	?>
<body>
<?php include "include/head2.php"; ?>
<?php include "include/leftmenu.php"; ?>
<?php include "include/top.php"; ?>
  <h1><i class="icon-gears (alias)"></i> Inventory Logam Mulia</h1>
</div>

<ol class="breadcrumb">
  <li><a href="add_logam.php">Add Inventory Logam Mulia</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="widget">
              <h3 class="section-title first-title"><i class="icon-table"></i> Listing Inventory Logam Mulia</h3>
              <div class="widget-content-white glossed">
                <div class="padded">
                <table class="table table-striped table-bordered table-hover">
                  <thead>
                    <tr>
                     <th>Stock ID</th>
                            <th>Kode - Nama Supplier</th>
                           <th>Weight</th>
                            <th>Status</th>
                            <th>Branch ID</th>
                            <th>Indicator Inventory</th>
                            <th colspan="3"></th>
                    </tr>
                  </thead>
                  <tbody>
                <?php
						$sql = mysql_query("select *,datediff(now(),a.date_update) as hari from inventory_logam a
						inner join tbl_status b on a.id_status = b.id_status
						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 status_stock = 1 and a.id_status not in (4,6) order by a.id_stock");
						$sql1 = ("select *,datediff(now(),a.date_update) as hari from inventory_logam a
						inner join tbl_status b on a.id_status = b.id_status
						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 status_stock = 1 and a.id_status not in (4,6) order by a.id_stock");
						$jumlah=mysql_num_rows($sql);
						$limit=50;
						$offset=$_GET[offset];
						if (empty($offset))
						{ $offset = 0;
							}
						$halaman=intval($jumlah/$limit);
						if($jumlah%$limit)
						{ $halaman++;
						}
						$item=$sql1." LIMIT $offset, $limit";
						$item2=mysql_query($item);
						while($fetch = mysql_fetch_array($item2))
						{
								$id_stock = $fetch['id_stock'];
								$id_branch = $fetch['id_branch'];
								$kode_stock = $fetch['kode_stock'];
								$barcodeno = $fetch['barcodeno'];
								$description  = $fetch['description'];
								$weight  = $fetch['weight'];
								$cbprice  = $fetch['cbprice'];
								$lbprice  = $fetch['lbprice'];
								if($id_branch == NULL)
								{
									$branch = 'Head Office';
								}
								else
								{
									$branch = $fetch['nama_branch'];
								}
								$hari = $fetch['hari'];
								$fetch2 = mysql_fetch_array(mysql_query("select * from tbl_indicator"));
								$green = $fetch2['green'];
								$red = $fetch2['red'];
								if($hari <= $green)
								{
								$loc = "images/green.jpg";;
								}
								elseif(($hari > $green) and ($hari < $red))
								{
								$loc = "images/yellow.jpg";;
								}
								elseif($hari >= $red)
								{
								$loc = "images/red.jpg";;
								}
								if($fetch['date_stock'] == '')
								{
								$date_stock = '';
								}
								else
								{
								list($d, $e, $f)=split ("[-]", $fetch['date_stock']);
								$date_stock   =$f."-".$e."-".$d;
								}
					?>
                        <tr>
                          	<td><a href="view_logam.php?id_stock=<?php echo $id_stock; ?>"><?php echo $fetch['kode_stock'];?></a></td>
                            <td><?php echo $fetch['kode_supplier'];?> - <?php echo $fetch['nama_supplier'];?></td>
                            <td><?php echo $fetch['weight'];?></td>
                            <td><?php echo $fetch['status'];?></td>
                            <td><?php echo $branch;?></td>
                            <td><img src="<?php echo $loc; ?>" alt="" height="20" width="50"/></td>
                             <td><a href="printfont.php?barcodeno=<?php echo $barcodeno; ?>&cbprice=<?php echo $cbprice; ?>&lbprice=<?php echo $lbprice; ?>&weight=<?php echo $weight; ?>&description=<?php echo $description; ?>" class="btn btn-default btn-xs"  title="Print" alt="Print"><i class="icon-copy"></i></a></td>
                        
                          <td><a href="update_logam.php?id_stock=<?php echo $id_stock; ?>" class="btn btn-default btn-xs"  title="Edit" alt="Edit"><i class="icon-pencil"></i></a></td>
                       
                          <td><a href="inventory_logam.php?act=2&id_stock=<?php echo $id_stock; ?>" class="btn btn-default btn-xs"  title="Delete" alt="Delete"><i class="icon-remove"></i></a></td>
                        </tr>
                        <?php
						}
						?>
                  </tbody>
                </table>
                    Page : <?php
						for($i=1; $i<=$halaman; $i++)
						{ $newoffset=$limit*($i-1);
						if($offset!=$newoffset)
						{ echo "&nbsp;<a href=\"".$_SERVER['PHP_SELF']."?act=1&offset=$newoffset&halamanke=$i&customer=$_REQUEST[customer]\">$i</a>&nbsp;|";
						}
						else
						{ echo "&nbsp;$i&nbsp;|";
						}
						}
						?>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>

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

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