<?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_stock  = $_REQUEST['id_stock'];
	if($act == 3)
	{
		$reason  = $_REQUEST['reason']; 
		$id_stock  = $_REQUEST['id_stock'];
		$delete = mysql_query("update inventory_liontin 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 Liontin Success");
                document.location="inventory_liontin.php";
                </script>
				<?php
			}
			else
			{
				?>
				<script language="javascript">
                alert("Delete Liontin Failed");
                document.location="inventory_liontin.php";
                </script>
				<?php	
			}
	}
	elseif($act == 2)
	{
		$id_stock  = $_REQUEST['id_stock'];
	?>
	<form action="inventory_liontin.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
	{
	?>
  <script type="text/javascript">

// JK Pop up image viewer script- By JavaScriptKit.com
// Visit JavaScript Kit (http://javascriptkit.com)
// for free JavaScript tutorials and scripts
// This notice must stay intact for use

var popbackground="white" //specify backcolor or background image for pop window
var windowtitle="Image Window"  //pop window title

function detectexist(obj){
return (typeof obj !="undefined")
}

function jkpopimage(imgpath, popwidth, popheight, textdescription){

function getpos(){
leftpos=(detectexist(window.screenLeft))? screenLeft+document.body.clientWidth/2-popwidth/2 : detectexist(window.screenX)? screenX+innerWidth/2-popwidth/2 : 0
toppos=(detectexist(window.screenTop))? screenTop+document.body.clientHeight/2-popheight/2 : detectexist(window.screenY)? screenY+innerHeight/2-popheight/2 : 0
if (window.opera){
leftpos-=screenLeft
toppos-=screenTop
}
}

getpos()
var winattributes='width='+popwidth+',height='+popheight+',resizable=yes,left='+leftpos+',top='+toppos
var bodyattribute=(popbackground.indexOf(".")!=-1)? 'background="'+popbackground+'"' : 'bgcolor="'+popbackground+'"'
if (typeof jkpopwin=="undefined" || jkpopwin.closed)
jkpopwin=window.open("","",winattributes)
else{
//getpos() //uncomment these 2 lines if you wish subsequent popups to be centered too
//jkpopwin.moveTo(leftpos, toppos)
jkpopwin.resizeTo(popwidth, popheight+30)
}
jkpopwin.document.open()
jkpopwin.document.write('<html><title>'+windowtitle+'</title><body '+bodyattribute+'><img src="'+imgpath+'" style="margin-bottom: 0.5em"></html>')
jkpopwin.document.close()
jkpopwin.focus()
}

</script>   
<body>
<?php include "include/head2.php"; ?>
<?php include "include/leftmenu.php"; ?>
<?php include "include/top.php"; ?>
  <h1><i class="icon-gears (alias)"></i> Inventory Liontin</h1>
</div>

<ol class="breadcrumb">
  <li><a href="add_liontin.php">Add Inventory Liontin</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 Liontin</h3>
              <!--<form method="post" action="inventory_liontin.php?act=1"  role="form" class="form-horizontal">
              <table class="table table-striped table-bordered table-hover">
                  <tr>
                    <td><input type="text" class="form-control" name="barcode" id="barcode" value="BarcodeNo" onBlur="if (this.value == '') {this.value = 'BarcodeNo';}" onFocus="if (this.value == 'BarcodeNo') {this.value = '';}"></td>
                  <td><input type="text" class="form-control" name="item" id="item" value="NamaItem" onBlur="if (this.value == '') {this.value = 'NamaItem';}" onFocus="if (this.value == 'NamaItem') {this.value = '';}"></td>
                    <td> <button type="submit" class="btn btn-default">Search</button></td>
                  </tr>
                </table>

              </form>-->
              <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>Status</th>
                            <th>Branch ID</th>
                            <th>Indicator Inventory</th>
                             <th>Price</th>
                             <th>Picture</th>
                            <th colspan="4"></th>
                    </tr>
                  </thead>
                  <tbody>
                     <?php
					 	$act = $_REQUEST['act'];
						if($act == 1)
						{
							$item = $_REQUEST['item'];
							$barcode = $_REQUEST['barcode'];
							$sql = mysql_query("select *,datediff(now(),a.date_update) as hari from inventory_liontin 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_liontin 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");
						}
						else
						{
							$sql = mysql_query("select *,datediff(now(),a.date_update) as hari from inventory_liontin 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_liontin 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'];
								$barcodeno = $fetch['barcodeno'];
								$kode_stock = $fetch['kode_stock'];
								$description  = $fetch['description'];
								$weight  = $fetch['weight'];
								$picture = $fetch['picture'];
								$loc = "liontin/";
								$all = $loc.$picture; 
								$fetch2 = mysql_fetch_array(mysql_query("select sum(price*weight) as sumweight,sum(workmanship) as sumworkmanship,
								sum(cost) as sumcost,sum(gold) as sumgold, sum(logistic) as sumlogistic from  inventory_custom a
								inner join tbl_diamonds b on a.id_diamonds = b.id_diamonds where kode_stock='$kode_stock'"));
								$fetch4 = mysql_fetch_array(mysql_query("SELECT usd FROM tbl_gold where date_update in (SELECT MAX( date_update ) from tbl_gold )"));
								$msprice = $fetch2['sumweight'] + $fetch2['sumlogistic'] + $fetch2['sumworkmanship']+ $fetch2['sumcost'] 
								+ ($fetch2['sumgold']*$fetch4['usd']);						    							    
								$fetch3 = mysql_fetch_array(mysql_query("select * from tbl_cblb"));
								$cbprice  = $msprice + ($fetch3['cbprice'] *$msprice);
								$lbprice  = $cbprice + ($fetch3['lbprice'] *$cbprice);
								if($msprice == "")
								{
									$msprice  = $fetch['msprice'];
									$lbprice  = $fetch['lbprice'];
									$cbprice  = $fetch['cbprice'];
									$simbol = 1;
								}
								$rows = mysql_num_rows(mysql_query("select * from inventory_custom where kode_stock='$kode_stock'"));
								if($rows > 0)
								{
										$price  = 'Custom';
								}
								else
								{
									$price  = '';
								}
								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 class="ui-datepicker-header" <?php if($simbol <> 1) { ?> <?php } ?>><a href="view_liontin.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['status'];?></td>
                            <td><?php echo $branch;?></td>
                            <td><img src="<?php echo $loc; ?>" alt="" height="20" width="50"/></td>
                             <td align="right"><?php  echo number_format($cbprice, 0, ',', ','); ?></td>
                               <td align="center"><a href="<?php echo $all; ?>" onClick="jkpopimage('<?php echo $all;?>', 640, 480); return false">
							<img src="<?php echo $all; ?>" alt="" height="30" width="30"/></a></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_liontin.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_liontin.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>
                       
                          <td><a href="custom_inventory.php?kode_stock=<?php echo $kode_stock; ?>&tipe=4" class="btn btn-default btn-xs" title="Custom" alt="Custom"><i class=" icon-folder-close-alt"></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>