<?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
		$id_sales  = $_REQUEST['id_sales'];
		$act  = $_REQUEST['act'];
		$fetch = mysql_fetch_array(mysql_query("select * from  sales where id_sales='$id_sales'"));
		$inventory = $fetch['inventory'];
		$id_customer = $fetch['id_customer'];
		list($y, $m, $d)=split ("[-]",$fetch['invoice_date']);
		$invoice_date=$d."-".$m."-".$y;
		$invoice = $fetch['invoice'];
		if($act == 1)
		{
			$customer = $_REQUEST['customer'];
			$id_sales  = $_REQUEST['id_sales'];
			list($d, $e, $f)=split ("[-]", $_REQUEST['inputDate']);
			$datepicker=$f."-".$e."-".$d;
			$insert = mysql_query("update sales set invoice_date='$datepicker',id_customer='$customer', user_update ='$USERNAME' where id_sales='$id_sales'");
			$fetch1 = mysql_fetch_array(mysql_query("select * from  sales where id_sales='$id_sales'"));
			$inventory = $fetch1['inventory'];
						if($insert)
						{
							if($inventory == "Services")
							{
						?>
								<script language="javascript">
									 alert("Edit Sales Success");
									document.location="add_salesdetails.php?act=3&id=<?php echo $id_sales; ?>";
								</script>
						<?php
							}
							else
							{
								?>
								<script language="javascript">
									 alert("Edit Sales Success");
									document.location="add_salesdetails.php?act=4&id=<?php echo $id_sales; ?>&inventory=<?php echo $inventory; ?>";
								</script>
						<?php
							}
						}
						else
						{
							?>
								<script language="javascript">
									alert("Add Sales Failed");
									document.location="edit_sales.php?id_sales=<?php echo $id_sales; ?>";
								</script>
							<?php
						}
		}
		
	?>
<body>
<?php include "include/head2.php"; ?>
<?php include "include/leftmenu.php"; ?>
<?php include "include/top.php"; ?>
  <h1><i class="icon-shopping-cart"></i>Edit Sales</h1>
</div>
          <div class="main-content">
            <div class="row">
                <div class="widget">
                  <div class="widget-content-white glossed">
                    <div class="padded">
                      <form method="post" action="edit_sales.php?id_sales=<?php echo $id_sales; ?>&act=1" role="form" class="form-horizontal">
                        <div class="form-group">
                          <label class="col-md-4 control-label" class="form-control">Inventory</label>
                          <div class="col-md-8">
                            <select name="inventory1" id="inventory1" class="form-control">
                              <option value="Diamond" <?php if($inventory == "Diamond") { ?> selected="selected" <?php } ?>>Diamond</option>
                              <option value="Gold" <?php if($inventory == "Gold") { ?> selected="selected" <?php } ?>>Gold</option>
                              <option value="LogamMulia" <?php if($inventory == "LogamMulia") { ?> selected="selected" <?php } ?>>LogamMulia</option>
                               <option value="ReadyItem" <?php if($inventory == "ReadyItem") { ?> selected="selected" <?php } ?>>ReadyItem</option>
                              <option value="Services" <?php if($inventory == "Services") { ?> selected="selected" <?php } ?>>Services</option>
                                <option value="Cincin" <?php if($inventory == "Cincin") { ?> selected="selected" <?php } ?>>Cincin</option>
                           <option value="Mastura" <?php if($inventory == "Mastura") { ?> selected="selected" <?php } ?>>Mastura</option>
                           <option value="Liontin" <?php if($inventory == "Liontin") { ?> selected="selected" <?php } ?>>Liontin</option>
                            <option value="Kerabu" <?php if($inventory == "Kerabu") { ?> selected="selected" <?php } ?>>Kerabu</option>
                           <option value="GKGR" <?php if($inventory == "GKGR") { ?> selected="selected" <?php } ?>>Gelang Kaku Gelang Rantai</option>
                           <option value="Rangka" <?php if($inventory == "Rangka") { ?> selected="selected" <?php } ?>>Rangka</option>
                            </select>
                          </div>
                        </div>
                    <div class="form-group">
                          <label class="col-md-4 control-label">Invoice No.</label>
                          <div class="col-md-8">
                            <input type="text" name="kode" id="kode" class="form-control" value="<?php echo $invoice; ?>"  readonly="readonly" >
                          </div>
                        </div>
                    <div class="form-group">
                          <label class="col-md-4 control-label">Invoice Date</label>
                          <div class="col-md-8">
                            <input type="text" class="inputDate" name="inputDate" id="inputDate" value="<?php echo $invoice_date; ?>">
                          </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">
                              <option value="0">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 <?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">
                          <div class="col-md-offset-4 col-md-8">
                            <button type="submit" class="btn btn-default">Submit</button>
                            <button type="reset" class="btn btn-default">Reset</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>