<?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_presales  = $_REQUEST['id_presales'];
	if($act == 3)
	{
		$delete = mysql_query("update presales set status_presales = 2,user_update  = '$USERNAME' where id_presales='$id_presales'");
		if($delete)
		{
				?>
				<script language="javascript">
                alert("Delete Pre Sales Success");
                document.location="presales.php";
                </script>
				<?php
			}
			else
			{
				?>
				<script language="javascript">
                alert("Delete Pre Sales Failed");
                document.location="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> PreSales Input</h1>
</div>

<ol class="breadcrumb">
  <li><a href="add_presales.php">Add PreSales</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="widget">
              <h3 class="section-title first-title"><i class="icon-table"></i> Listing PreSales</h3>
              <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>Kode Stock</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,a.kode_stock
						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'];
								$kode_presales = $fetch['kode_presales'];
								$kode_stock = $fetch['kode_stock'];
								$closed = $fetch['closed'];
								$status = $fetch['status'];
								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 echo $fetch['kode_stock'];?></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>
            </div>
          </div>
        </div>
      </div>

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

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

</html>