<?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'];
	$kode = mysql_fetch_array(mysql_query("select max(id_consigment) as maxid from inventory_consigment"));
	$maxid = $kode['maxid'];
	if($maxid == "")
	{
		$kode1 = "CONSIG1";
	
	}
	else
	{
		$total = $maxid+1;
		$kode1 = "CONSIG".$total;
	}
	if($act == 1)
	{
		$kode  = $_REQUEST['kode'];
		list($d, $e, $f)=split ("[-]", $_REQUEST['inputDate2']);
		$datepicker=$f."-".$e."-".$d;
		$branchfrom  = $_REQUEST['branchfrom'];
		$branchto  = $_REQUEST['branchto'];
			
		$insert = mysql_query("insert into inventory_consigment (kode_consigment,tgl_consigment,id_branchfrom, id_branchto, user_update) values ('$kode','$datepicker','$branchfrom','$branchto','$USERNAME')");
						if($insert)
						{
							$maxid = mysql_fetch_array(mysql_query("select max(id_consigment) as maxkode from inventory_consigment"));
							$id = $maxid['maxkode'];
						?>
								<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";
								</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 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_consigment.php?act=1">
                        <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 $kode1; ?>"  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 date('d-m-Y'); ?>" id="inputDate2" >
                                </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">
                            <option value="">Head Office</option>
                               <?php
                                              $sql3 = "select * from tbl_branch where status_branch=1 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>To Branch</label>
                            </div>
                                <div class="col-md-6"> 
                                 <select name="branchto" id="branchto" class="form-control">
                               <?php
                                              $sql3 = "select * from tbl_branch where status_branch=1 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>
                        <button class="btn btn-primary" type="submit">Submit</button>
                        <button class="btn btn-default" type="reset">Reset</button>
                      </form>
                    </div>
             </div>
              <?php if(($customer <> "") || ($description <> "") || ($sales <> "") || ($datepicker1 <> "")){?>
              <div class="widget-content-white glossed">
                <div class="padded">
                <table class="table table-striped table-bordered table-hover">
                   <thead>
                        <tr>
                       		 <th>Kode PreSales</th>
                            <th>Tanggal PreSales</th>
                            <th>Customer No. - Customer Name</th>
                             <th>>Closed</th>
                            <th>Sales Name</th>
                            <th>Description</th>
                            <th>Details</th>
                        </tr>
                    </thead>
                    <tbody>
                     <?php
						$sql = mysql_query("select a.id_presales,a.closed,a.kode_presales,a.presales_date,b.kode_customer,b.nama_customer,a.user_update,a.description ,a.status
						from  presales a
						left join tbl_customer b on a.id_customer  = b.id_customer
						where status_presales = 1 and status = 'Parent' order by id_presales");
						while($fetch = mysql_fetch_array($sql))
						{
								$id_presales = $fetch['id_presales'];
								$closed = $fetch['closed'];
								$kode_presales = $fetch['kode_presales'];
								list($y, $m, $d)=split ("[-]",$fetch['presales_date']);
								$presales_date=$d."-".$m."-".$y;
					?>
                        <tr class="gradeX">
                          	<td><a href="view_presales2.php?id_presales=<?php echo $id_presales; ?>"><?php echo $fetch['kode_presales'];?></a></td>
                            <td><?php echo $presales_date;?></td>
                            <td><?php echo $fetch['kode_customer'];?> - <?php echo $fetch['nama_customer'];?></td>
                            <td><?php if($closed == 0) { echo "No"; } else { echo "Yes"; }?></td>
                            <td><?php echo $fetch['user_update'];?></td>
                            <td><?php echo $fetch['description'];?></td>
                            <td class="actions aligncenter"><a href="view_presales.php?id=<?php echo $id_presales; ?>&kode=<?php echo $kode_presales; ?>">View</a></td>
                        </tr>
                        <?php
						}
						?>
                  </tbody>
                </table>
                </div>
              </div>
              <?php
			  }
			  ?>
            </div>
          </div>
        </div>
      </div>

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

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

</html>