<?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";
?>
	<script language="javascript">
function intFormat(n)
{
var
regex = /(\d)((\d{3},?)+)$/;

n = n.split(',').join('');

while(regex.test(n))
{
n = n.replace(regex, '$1,$2');
}

return n;
}

function numFormat(n)
{
var
pointReg = /([\d,\.]*)\.(\d*)$/, f;

if(pointReg.test(n))
{
f = RegExp.$2;
return intFormat(RegExp.$1) + '.' + f;
}
return intFormat(n);
}
</script>
<?php
	$act  = $_REQUEST['act'];
	$id_stock  = $_REQUEST['id_stock'];
	$fetch = mysql_fetch_array(mysql_query("select * from inventory_gold where id_stock = '$id_stock'"));
	$kode_stock  = $fetch['kode_stock'];
	$id_supplier = $fetch['id_supplier'];
	$cbprice  = $fetch['cbprice'];
	$barcodeno  = $fetch['barcodeno'];
	$weight  = $fetch['weight'];
	$combineitem  = $fetch['combineitem'];
	$kadar  = $fetch['kadar'];
	$description  = $fetch['description'];
	$id_status  = $fetch['id_status'];
	$id_branch  = $fetch['id_branch'];
	$picture = $fetch['picture'];
	$loc = "gold/";
	$all = $loc.$picture; 
	if($fetch['date_stock'] == '')
								{
								$date_stock = '';
								}
								else
								{
								list($d, $e, $f)=split ("[-]", $fetch['date_stock']);
								$date_stock   =$f."-".$e."-".$d;
								}
	$kurs2 = mysql_fetch_array(mysql_query("select usd from tbl_usd order by date_update desc limit 1"));
	$usd = $kurs2['usd'];
	if($act == 1)
	{
		$id_stock  = $_REQUEST['id_stock'];
		$cbprice = str_replace(",","", $_REQUEST['cbprice']);
		$supplier  = $_REQUEST['supplier'];
		$barcode  = $_REQUEST['barcode'];
		$weight  = $_REQUEST['weight'];
		$combine  = $_REQUEST['combine'];
		$kadar  = $_REQUEST['kadar'];
		$description  = $_REQUEST['description'];
		$uploaddir = 'readyitem/';
		$uploadfile = $uploaddir.$_FILES['file']['name'];
		$filename = $_FILES['file']['name']; 		//echo $_FILES['file']['name']; exit;
		
			
			if($filename != "")
			{
				if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 1000000))
				{
				  if ($_FILES["file"]["error"] > 0)
					{
						echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
					}
					else
					{
						move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile);
			$insert = mysql_query("update inventory_gold set id_supplier= '$supplier',cbprice='$cbprice',weight='$weight',barcodeno='$barcode',combineitem='$combine',kadar='$kadar',picture='$filename',description='$description',user_update='$USERNAME' where id_stock='$id_stock'");
						if($insert)
						{
						?>
								<script language="javascript">
									 alert("Edit Gold Success");
									document.location="update_gold.php?id_stock=<?php echo $id_stock; ?>";
								</script>
						<?php
						}
						else
						{
							?>
								<script language="javascript">
									alert("Edit Gold Failed");
									document.location="update_gold.php?id_stock=<?php echo $id_stock; ?>";
								</script>
							<?php
						}
					}
				}
				else
				{
				?>
								<script language="javascript">
									alert("Image format invalid");
									document.location="update_gold.php?id_stock=<?php echo $id_stock; ?>";
								</script>
				<?php
				}
			}
			else
			{
						$insert = mysql_query("update inventory_gold set id_supplier= '$supplier',cbprice='$cbprice',weight='$weight',barcodeno='$barcode',combineitem='$combine',kadar='$kadar',description='$description',user_update='$USERNAME' where id_stock='$id_stock'");
						if($insert)
						{
						?>
								<script language="javascript">
									 alert("Edit Gold Success");
									document.location="update_gold.php?id_stock=<?php echo $id_stock; ?>";
								</script>
						<?php
						}
						else
						{
							?>
								<script language="javascript">
									alert("Edit Gold Failed");
									document.location="update_gold.php?id_stock=<?php echo $id_stock; ?>";
								</script>
							<?php
						}
			}
	}
?>
<body class="withvernav">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0" />
<script src="js/tinymce2/tinymce.dev.js"></script>
<script src="js/tinymce2/plugins/table/plugin.dev.js"></script>
<script>
	tinymce.init({
		selector: "textarea#description",
		theme: "modern",
		plugins: [
			"advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker",
			"searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
			"save table contextmenu directionality emoticons template paste"
		],
		content_css: "css/development.css",
		add_unload_trigger: false,

		toolbar1: "save newdocument fullpage | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | styleselect formatselect fontselect fontsizeselect",
		toolbar2: "cut copy paste | searchreplace | bullist numlist | outdent indent blockquote | undo redo | link unlink anchor image media help code | inserttime preview | forecolor backcolor",
		toolbar3: "table | hr removeformat | sub sup | charmap emoticons | print fullscreen | ltr rtl | spellchecker | visualchars nonbreaking template pagebreak restoredraft | insertfile insertimage",
		menubar: false,
		toolbar_items_size: 'small',

		style_formats: [
			{title: 'Bold text', inline: 'b'},
			{title: 'Red text', inline: 'span', styles: {color: '#ff0000'}},
			{title: 'Red header', block: 'h1', styles: {color: '#ff0000'}},
			{title: 'Example 1', inline: 'span', classes: 'example1'},
			{title: 'Example 2', inline: 'span', classes: 'example2'},
			{title: 'Table styles'},
			{title: 'Table row 1', selector: 'tr', classes: 'tablerow1'}
		],

		templates: [
			{title: 'My template 1', description: 'Some fancy template 1', content: 'My html'},
			{title: 'My template 2', description: 'Some fancy template 2', url: 'development.html'}
		]
	});
</script>
<?php include "include/head2.php"; ?>
<?php include "include/leftmenu.php"; ?>
<?php include "include/top.php"; ?>
  <h1><i class="icon-gears (alias)"></i> View Inventory Gold</h1>
</div>

<!--<ol class="breadcrumb">
  <li><a href="#">Home</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="row">
                <div class="widget">
                  <div class="widget-content-white glossed">
                    <div class="padded">
                      <form method="post" action="update_gold.php?act=1&id_stock=<?php echo $id_stock; ?>"  enctype="multipart/form-data" role="form" class="form-horizontal">
                        <div class="form-group">
                          <label class="col-md-4 control-label">Stock ID</label>
                          <div class="col-md-8">
                            <input type="text" class="form-control" name="kode" id="kode"  value="<?php echo $kode_stock; ?>"  readonly="readonly">
                          </div>
                          </div>
                           <div class="form-group">
                          <label class="col-md-4 control-label">Kode Supplier -  Nama Supplier</label>
                          <div class="col-md-8"><select name="supplier" id="supplier" class="form-control">
                               <?php
                                              $sql3 = "select * from tbl_supplier where id_supplier='$id_supplier' order by nama_supplier,kode_supplier";
                                              $rs3 = mysql_query($sql3);
                                              while($fetch3 = mysql_fetch_array($rs3))
                                              {
                                               ?>
                                          <option <?php if($fetch3['id_supplier']==$id_supplier) { ?> selected="selected" <?php } ?> value="<?php echo $fetch3['id_supplier']; ?>"><?php echo  $fetch3['kode_supplier'];  ?> - <?php echo  $fetch3['nama_supplier'];  ?></option>
                                                      <?php
                                              }
                                             ?>
                            </select>
                          </div>
                        </div>
                         <div class="form-group">
                          <label class="col-md-4 control-label">Kadar</label>
                          <div class="col-md-8">
                            <input type="text" class="form-control" name="kadar" id="kadar" value="<?php echo $kadar; ?>" readonly>
                          </div>
                          </div>
                           <div class="form-group">
                          <label class="col-md-4 control-label">Barcode No.</label>
                          <div class="col-md-8">
                            <input type="text" class="form-control" name="barcode" id="barcode" value="<?php echo $barcodeno; ?>" readonly="readonly" >
                          </div>
                          </div>
                           <div class="form-group">
                          <label class="col-md-4 control-label">Kurs</label>
                          <div class="col-md-8">
                            <input type="text" class="form-control" name="usd" id="usd" value="<?php echo $usd; ?>" readonly="readonly" >
                          </div>
                          </div>
                           <div class="form-group">
                          <label class="col-md-4 control-label">CB Price</label>
                          <div class="col-md-8">
                            <input type="text" class="form-control" name="cbprice" id="cbprice" value="<?php  echo number_format($cbprice, 0, ',', ','); ?>"  onKeyUp="this.value = numFormat(this.value)" readonly >
                          </div>
                          </div>
                         
                          <div class="form-group">
                          <label class="col-md-4 control-label">Weight (in gram)</label>
                          <div class="col-md-8">
                            <input type="text" class="form-control" name="weight" id="weight" value="<?php echo $weight; ?>" readonly  >
                          </div>
                          </div>
                           <div class="form-group">
                          <label class="col-md-4 control-label">Combine Item No.</label>
                          <div class="col-md-8">
                            <input type="text" class="form-control" name="combine" id="combine" value="<?php echo $combineitem; ?>" readonly >
                          </div>
                          </div>
                          <div class="form-group">
                          <label class="col-md-4 control-label">Status Inventory</label>
                          <div class="col-md-8"><select name="status" id="status" class="form-control">
                               <?php
                                              $sql3 = "select * from tbl_status where id_status='$id_status' ";
                                              $rs3 = mysql_query($sql3);
                                              while($fetch3 = mysql_fetch_array($rs3))
                                              {
                                               ?>
                                        <option <?php if($fetch3['id_status']==$id_status) { ?> selected="selected" <?php } ?> value="<?php echo $fetch3['id_status']; ?>"><?php echo  $fetch3['status'];  ?></option>
                                                      <?php
                                              }
                                             ?>
                            </select>
                          </div>
                        </div>
                         <div class="form-group">
                          <label class="col-md-4 control-label">Date Stock</label>
                          <div class="col-md-8">
                            <input type="text" class="form-control" name="combine" id="combine" value="<?php echo $date_stock; ?>" readonly >
                          </div>
                          </div>
                         <div class="form-group">
                          <label class="col-md-4 control-label">Branch ID</label>
                          <div class="col-md-8"><select name="id_branch" id="id_branch" class="form-control">
                            <?php if($id_branch == NULL)
                            {
                            ?>
                            <option value="">Head Office</option>
                           	<?php
						    }
                            else
                            {
                                              $sql3 = "select *
											  from tbl_branch where id_branch='$id_branch' order by nama_branch";
                                              $rs3 = mysql_query($sql3);
                                              while($fetch3 = mysql_fetch_array($rs3))
                                              {
                                               ?>
                                        <option <?php if($fetch3['id_branch']==$id_branch) { ?> selected="selected" <?php } ?> value="<?php echo $fetch3['id_branch']; ?>"><?php echo  $fetch3['nama_branch'];  ?></option>
                                                      <?php
                                              }
                                             
                            }
							?>
                            </select>
                          </div>
                        </div>
                        <?php if($picture <> "")
							 {
							?>
                           <div class="form-group">
                          <label class="col-md-4 control-label">Picture *max file 1MB and format file only JPEG/GIF</label>
                          <div class="col-md-8">
                          <a class="image" href="gold/<?php echo $picture; ?>">
							<img src="<?php echo $all; ?>" alt="" height="69" width="117"/></a>&nbsp;
                        
                          </div>
                        </div>
                         <?php
							 }
							 ?>
                         <div class="form-group">
                          <label class="col-md-4 control-label">Description</label>
                          <div class="col-md-8">
                          <textarea rows="15" cols="80"  class="form-control"  readonly><?php echo $description; ?></textarea>
                          </div>
                        </div>
                        <div class="form-group">
                          <div class="col-md-offset-4 col-md-8">
                           <input type="button" value=" Back " class="btn btn-default" onClick="document.location='javascript:history.back(-1)'" />
                          </div>
                        </div>
                      </form>
                    </div>
                    </div>
                    </div>
                    </div>
                    </div>
                   

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

</html>