<?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  = $_REQUEST['id'];
	$fetch = mysql_fetch_array(mysql_query("select * from inventory_consigment where id_consigment = '$id'"));
	$kode_consigment = $fetch['kode_consigment'];
	list($y, $m, $d)=split ("[-]",$fetch['tgl_consigment']);
	$tgl_consigment=$d."-".$m."-".$y;
	$id_branchfrom = $fetch['id_branchfrom'];
	$id_branchto = $fetch['id_branchto'];
	
	if($act == 1)
	{
		$id  = $_REQUEST['id']; //echo $id; exit;
		$branchfrom  = $_REQUEST['branchfrom'];
		$branchto  = $_REQUEST['branchto'];
		list($d, $e, $f)=split ("[-]", $_REQUEST['item']);
		$item=$d; //echo $item; exit;

		$insert = mysql_query("insert into inventory_detailsconsigment (id_consigment,kode_stock,id_branchfrom,user_update) values ('$id','$item','$branchfrom','$USERNAME')");
		$update = mysql_query("update inventory_diamond set id_status = 2,user_update ='$USERNAME' where kode_stock = '$item'");
		$update1 = mysql_query("update inventory_gold set id_status = 2,user_update ='$USERNAME' where kode_stock = '$item'");
		$update2 = mysql_query("update inventory_logam set id_status = 2,user_update ='$USERNAME' where kode_stock = '$item'");
		$update3 = mysql_query("update inventory_readyitem set id_status = 2,user_update ='$USERNAME' where kode_stock = '$item'");
		
		$update4 = mysql_query("update inventory_cincin set id_status = 2,user_update ='$USERNAME' where kode_stock = '$item'");
		$update5 = mysql_query("update inventory_mastura set id_status = 2,user_update ='$USERNAME' where kode_stock = '$item'");
		$update6 = mysql_query("update inventory_liontin set id_status = 2,user_update ='$USERNAME' where kode_stock = '$item'");
		$update7 = mysql_query("update inventory_kerabu set id_status = 2,user_update ='$USERNAME' where kode_stock = '$item'");
		$update8 = mysql_query("update inventory_gkgr set id_status = 2,user_update ='$USERNAME' where kode_stock = '$item'");
		$update9 = mysql_query("update inventory_rangka set id_status = 2,user_update ='$USERNAME' where kode_stock = '$item'");
						if($insert)
						{
						?>
								<script language="javascript">
									 //alert("Add Logam Mulia Success");
									document.location="add_consigment2.php?id=<?php echo $id; ?>";
								</script>
						<?php
						}
						else
						{
							?>
								<script language="javascript">
									//alert("Add Logam Mulia Failed");
									document.location="add_consigment.php?id=<?php echo $id; ?>";
								</script>
							<?php
						}
	}

	?>
<body>
<?php include "include/head2.php"; ?>
<?php include "include/leftmenu.php"; ?>
<?php include "include/top.php"; ?>
<script type="text/javascript" src="js/jquery-1.3.2.js"></script>
<script type='text/javascript' src='js/jquery.autocomplete.js'></script>
<link rel="stylesheet" type="text/css" href="css/jquery.autocomplete.css" />
<script type="text/javascript">
$().ready(function() {
	$("#item").autocomplete("search_consigment.php?id_branchfrom=<?php echo $id_branchfrom; ?>", {
		width: 260,
		matchContains: true,
		//mustMatch: true,
		//minChars: 0,
		//multiple: true,
		//highlight: false,
		//multipleSeparator: ",",
		selectFirst: false
	});
});
</script>

  <h1><i class="icon-pencil"></i> Add Consignment Input</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="add_consigment2.php?act=1&id=<?php echo $id; ?>">
                        <div class="form-group">
                        <div class="col-md-6"> 
                            <label>Consignment ID</label>
                            </div>
                                <div class="col-md-6"> 
                                 <input type="text" class="form-control" name="kode"   id="kode" value="<?php echo $kode_consigment; ?>"  readonly="readonly" >
                                </div>
                        </div>
                        <div class="form-group">
                        <div class="col-md-6"> 
                            <label>Consignment Date</label>
                            </div>
                                <div class="col-md-6"> 
                                 <input type="text" class="inputDate2" name="inputDate2"  value="<?php echo $tgl_consigment; ?>" id="inputDate2" readonly >
                                </div>
                        </div>
                         
                         <div class="form-group">
                        <div class="col-md-6"> 
                            <label>From Branch</label>
                            </div>
                                <div class="col-md-6"> 
                                <select name="branchfrom" id="branchfrom" class="form-control">
                            <?php if($id_branchfrom == 0)
                            {
                            ?>
                            <option value="0">Head Office</option>
                           	<?php
						    }
                            else
                            {
                                              $sql3 = "select *
											  from tbl_branch where id_branch='$id_branchfrom' 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
                                              }
                                             ?>
                                              <?php
                            }
							?>
                            </select>
                                </div>
                        </div>
                         <div class="form-group">
                        <div class="col-md-6"> 
                            <label>To Branch</label>
                            </div>
                                <div class="col-md-6"> 
                                <select name="to" id="to" class="form-control">
                               <?php
                                              $sql3 = "select * from tbl_branch where id_branch='$id_branchto' 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>
                        </div>
                        <div class="form-group">
                        <div class="col-md-6"> 
                            <label>Stock No. - Inventory Type - Barcode No.</label>
                            </div>
                                <div class="col-md-6"> 
                                 <input name="item" type="text" class="form-control" id="item" /> 
                                </div>
                        </div>
                        <button class="btn btn-primary" type="submit">Submit</button>
                        <button class="btn btn-default" type="reset">Reset</button>
                      </form>
                    </div>
             </div>
              <?php
					$sql = mysql_query("select * from  inventory_detailsconsigment
						where status = 1 and id_consigment='$id'");
					if(mysql_num_rows($sql)>0)
					{
					?>
              <div class="widget-content-white glossed">
                <div class="padded">
                <table class="table table-striped table-bordered table-hover">
                   <thead>
                        <tr>
                       		<th>Type Inventory</th>
                            <th>Kode Stock</th>
                            <th>Barcode No.</th>
                        </tr>
                    </thead>
                    <tbody>
                      <?php
						$sql = mysql_query("select * from  inventory_detailsconsigment
						where status = 1 and id_consigment='$id'");
						while($fetch = mysql_fetch_array($sql))
						{
								$kode_stock = $fetch['kode_stock'];
								  $sql2 = "select type,kode_stock,barcodeno,id_stock from
								  (select 'Diamond' as type,kode_stock,barcodeno,id_stock from  inventory_diamond where status_stock=1
								  union all
								  select 'Gold' as type,kode_stock,barcodeno,id_stock from  inventory_gold  where status_stock=1
								  union all
								  select 'Logam Mulia' as type,kode_stock,barcodeno,id_stock from  inventory_logam  where status_stock=1
								  union all
								  select 'Ready Item' as type,kode_stock,barcodeno,id_stock from  inventory_readyitem  where status_stock=1
								   union all
									  select 'Cincin' as type,kode_stock,barcodeno,id_stock from  inventory_cincin  where status_stock=1 							
									  union all
									  select 'Mastura' as type,kode_stock,barcodeno,id_stock from  inventory_mastura  where status_stock=1
									   union all
									  select 'Liontin' as type,kode_stock,barcodeno,id_stock from  inventory_liontin  where status_stock=1
									  union all
									  select 'Kerabu' as type,kode_stock,barcodeno,id_stock from  inventory_kerabu  where  status_stock=1
									  union all
						select 'GKGR' as type,kode_stock,barcodeno,id_stock from  inventory_gkgr  where status_stock=1
									  union all
									  select 'Rangka' as type,kode_stock,barcodeno,id_stock from  inventory_rangka  where status_stock=1) a
								  where kode_stock = '$kode_stock'
								  order by type,kode_stock,barcodeno";
								$fetch2 = mysql_fetch_array(mysql_query($sql2));
					?>
                        <tr>
                        	<td><?php echo $fetch2['type']; ?></td>
                          <td><?php echo $fetch2['kode_stock']; ?></td>
                          <td><?php echo $fetch2['barcodeno']; ?></td>
                       </tr>
                       <?php
						}
						?>
                  </tbody>
                </table>
                <form class="stdform stdform2" method="post" action="consigment.php" name = "frm2">
                     <p class="stdformbutton">
                        	<button  class="btn btn-primary">Done</button>
                        </p>
                         </form>
                </div>
              </div>
              <?php
			  }
			  ?>
            </div>
          </div>
        </div>
      </div>

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

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

</html>