<?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'];
	$kode = mysql_fetch_array(mysql_query("select max(id_presales) as maxid from  presales"));
	$maxid = $kode['maxid'];
	if($maxid == "")
	{
		$kode1 = "PRESALES1";
	
	}
	else
	{
		$total = $maxid+1;
		$kode1 = "PRESALES".$total;
	}
	if($act == 1)
	{
		$kode  = $_REQUEST['kode'];
		list($d, $e, $f)=split ("[-]", $_REQUEST['inputDate']);
		$datepicker=$f."-".$e."-".$d;
		$customer  = $_REQUEST['customer'];
		$closed  = $_REQUEST['closed'];
		$stock  = $_REQUEST['stock'];
		$description  = $_REQUEST['description'];
			
		$insert = mysql_query("insert into presales (kode_presales,presales_date,id_customer, description, user_update,closed,kode_stock) values ('$kode','$datepicker','$customer','$description','$USERNAME','$closed','$stock')");

						if($insert)
						{
						?>
								<script language="javascript">
									 alert("Add Pre Sales Success");
									document.location="presales.php";
								</script>
						<?php
						}
						else
						{
							?>
								<script language="javascript">
									alert("Add Pre Sales Failed");
									document.location="add_presales.php";
								</script>
							<?php
						}
	}

	?>
<body>
<?php include "include/head2.php"; ?>
<?php include "include/leftmenu.php"; ?>
<?php include "include/top.php"; ?>
  <h1><i class="icon-pencil"></i>Add 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="add_presales.php?act=1" 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 $kode1; ?>"  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 date('d-m-Y'); ?>">
                          </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 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 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" />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"></textarea>
                          </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>