<?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";

	$act  = $_REQUEST['act'];
	$id_presales  = $_REQUEST['id_presales'];
	$fetch = mysql_fetch_array(mysql_query("select * from presales where id_presales = '$id_presales'"));
	list($y, $m, $d)=split ("[-]",$fetch['presales_date']);
	$presales_date=$d."-".$m."-".$y;
	$id_presales = $fetch['id_presales'];
	$closed = $fetch['closed'];
	$kode_presales = $fetch['kode_presales'];
	$id_customer = $fetch['id_customer'];
	$description = $fetch['description'];
	$kode_stock = $fetch['kode_stock'];
	if($act == 1)
	{
		$id_presales  = $_REQUEST['id_presales'];
		list($d, $e, $f)=split ("[-]", $_REQUEST['inputDate']);
		$datepicker=$f."-".$e."-".$d;
		$customer  = $_REQUEST['customer'];
		$description  = $_REQUEST['description'];
		$closed  = $_REQUEST['closed'];
		$stock  = $_REQUEST['stock'];
			
		$insert = mysql_query("update presales set kode_stock='$stock',presales_date='$datepicker',id_customer='$customer', description='$description', user_update='$USERNAME',closed='$closed' where id_presales='$id_presales'");
						if($insert)
						{
						?>
								<script language="javascript">
									 alert("Edit Pre Sales Success");
									document.location="presales.php";
								</script>
						<?php
						}
						else
						{
							?>
								<script language="javascript">
									alert("Edit Pre Sales Failed");
									document.location="edit_presales.php?id_presales=<?php echo $id_presales; ?>";
								</script>
							<?php
						}
	}

	?>
<body>
<?php include "include/head2.php"; ?>
<?php include "include/leftmenu.php"; ?>
<?php include "include/top.php"; ?>
  <h1><i class="icon-search"></i>View PreSales</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="edit_presales.php?act=1&id_presales=<?php echo $id_presales; ?>" enctype="multipart/form-data" role="form" class="form-horizontal">
                        <div class="form-group">
                          <label class="col-md-4 control-label">PreSales ID</label>
                          <div class="col-md-8">
                            <input type="text" class="form-control" name="kode" id="kode"  value="<?php echo $kode_presales; ?>"  readonly="readonly" >
                          </div>
                        </div>
                   
                    <div class="form-group">
                          <label class="col-md-4 control-label">PreSales Date</label>
                          <div class="col-md-8">
                            <input type="text" class="inputDate" name="inputDate" id="inputDate" value="<?php echo $presales_date; ?>" readonly="readonly">
                          </div>
                        </div>
                        
                        
                    <div class="form-group">
                          <label class="col-md-4 control-label">Kode Customer - Nama Customer</label>
                          <div class="col-md-8">
                         <select name="customer" id="customer" class="form-control">
                                <?php if($id_customer == 0)
                            {
                            ?>
                            <option value="0" selected="selected">None</option>
                           <?php 
                            $sql3 = "select * from tbl_customer where status_customer=1 order by nama_customer";
                                              $rs3 = mysql_query($sql3);
                                              while($fetch3 = mysql_fetch_array($rs3))
                                              {
                                               ?>
                                        <option value="<?php echo $fetch3['id_customer']; ?>"><?php echo  $fetch3['kode_customer'];  ?> - <?php echo  $fetch3['nama_customer'];  ?></option>
                 
                                             
                           	<?php
											  }
						    }
                            else
                            {
                                              $sql3 = "select * from tbl_customer where status_customer=1 order by nama_customer";
                                              $rs3 = mysql_query($sql3);
                                              while($fetch3 = mysql_fetch_array($rs3))
                                              {
                                               ?>
                                         <option <?php if($fetch3['id_customer']==$id_customer) { ?> selected="selected" <?php } ?> value="<?php echo $fetch3['id_customer']; ?>"><?php echo  $fetch3['kode_customer'];  ?> - <?php echo  $fetch3['nama_customer'];  ?></option>
                                                      <?php
                                              }
							}
                                             ?>
                            </select>
                          </div>
                        </div>
                          <div class="form-group">
                          <label class="col-md-4 control-label">Type - Kode Stock - Barcode No.</label>
                          <div class="col-md-8">
                            <select name="stock" id="stock"  class="form-control">
							  <?php
                                              $sql3 ="select type,kode_stock,barcodeno,id_stock from
																																														(select 'Diamond' as type,kode_stock,barcodeno,id_stock from  inventory_diamond where id_status=3 and status_stock=1
																																														union all
																																														select 'Gold' as type,kode_stock,barcodeno,id_stock from  inventory_gold  where id_status=3 and status_stock=1
																																														union all
																																														select 'Logam Mulia' as type,kode_stock,barcodeno,id_stock from  inventory_logam  where id_status=3 and status_stock=1
																																														union all
																																														select 'Ready Item' as type,kode_stock,barcodeno,id_stock from  inventory_readyitem  where id_status=3 and status_stock=1
																																														 union all
									  select 'Cincin' as type,kode_stock,barcodeno,id_stock from  inventory_cincin  where id_status=3 and status_stock=1 							
									  union all
									  select 'Mastura' as type,kode_stock,barcodeno,id_stock from  inventory_mastura  where id_status=3 and status_stock=1
									   union all
									  select 'Liontin' as type,kode_stock,barcodeno,id_stock from  inventory_liontin  where id_status=3 and status_stock=1
									  union all
									  select 'Kerabu' as type,kode_stock,barcodeno,id_stock from  inventory_kerabu  where  id_status=3 and status_stock=1
									  union all
						select 'Gelang Kaku Gelang Rantai' as type,kode_stock,barcodeno,id_stock from  inventory_gkgr  where id_status=3 and status_stock=1
									  union all
									  select 'Rangka' as type,kode_stock,barcodeno,id_stock from  inventory_rangka  where  1) a
																																														where kode_stock not in (select kode_stock from inventory_detailsconsigment a inner join inventory_consigment b on a.id_consigment = b.id_consigment
																																														where status_consigment = 1 and user_receive = '')
																																														order by type,kode_stock,barcodeno";
                                              $rs3 = mysql_query($sql3);
                                              while($fetch3 = mysql_fetch_array($rs3))
                                              {
                                               ?>
                                        <option <?php if($fetch3['kode_stock']==$kode_stock) { ?> selected="selected" <?php } ?> value="<?php echo $fetch3['kode_stock']; ?>">  <?php echo  $fetch3['type'];  ?> - <?php echo  $fetch3['kode_stock'];  ?> - <?php echo  $fetch3['barcodeno'];  ?></option>
                                                      <?php
                                              }
                                             ?>
                            </select>
                              
                         
                          </div>
                        </div>
                          <div class="form-group">
                          <label class="col-md-4 control-label">Status</label>
                          <div class="col-md-8">
                          <label class="checkbox-inline"><input type="checkbox" name="closed" id="closed" value="1" <?php if($closed == 1) { ?> checked="checked" <?php } ?> />Closed</label>
                          </div>
                          </div>
                         <div class="form-group">
                          <label class="col-md-4 control-label">Description</label>
                          <div class="col-md-8">
                           <textarea cols="80" rows="5" name="description" id="description" class="form-control" readonly><?php echo $description; ?></textarea>
                          </div>
                        </div>
                        <div class="form-group">
                          <div class="col-md-offset-4 col-md-8">
                            <button type="reset" class="btn btn-default" onClick="document.location='javascript:history.back(-1)'" >Back</button>
                          </div>
                        </div>
                      </form>
                    </div>
                    </div>
                    </div>
                    </div>
                    </div>
                   

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

</html>