<?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'];
	$kode  = $_REQUEST['kode'];
	$id  = $_REQUEST['id'];
	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-search"></i> View PreSales</h1>
</div>
   <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' and a.id_presales = '$id' 
						union all
						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 in (select kode_presales from presales where id_presales = '$id') ");
						while($fetch = mysql_fetch_array($sql))
						{
								$id_presales = $fetch['id_presales'];
								$kode_presales = $fetch['kode_presales'];
								$closed = $fetch['closed'];
									$kode_stock = $fetch['kode_stock'];
								$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="edit_presales.php?id_presales=<?php echo $id_presales; ?>" class="edit">Edit</a> &nbsp; <a href="view_presales.php?id_presales=<?php echo $id_presales; ?>&act=3" class="edit">Delete</a></td>
                        </tr>
                        <?php
						}
						?>
                  </tbody>
                </table>
                </br> 
                         <a href="add_presales2.php?kode_presales=<?php echo $kode; ?>" class="btn btn-default"><span>Add PreSales</span></a>
             
                </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>