<?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_returnsales  = $_REQUEST['id_returnsales'];
	$inventory  = $_REQUEST['inventory'];
	if($act == 3)
	{
		$delete = mysql_query("update return_sales set status_returnsales = 2,user_update  = '$USERNAME' where id_returnsales='$id_returnsales'");
		if($delete)
		{
				?>
				<script language="javascript">
                alert("Delete Return Sales Success");
                document.location="return_sales.php";
                </script>
				<?php
			}
			else
			{
				?>
				<script language="javascript">
                alert("Delete Return Sales Failed");
                document.location="return_sales.php";
                </script>
				<?php	
			}
	}
		elseif($act == 4)
	{
		$delete = mysql_query("update return_sales set status_returnsales = 3,user_update  = '$USERNAME' where id_returnsales='$id_returnsales'");
		if($delete)
		{
			if($inventory == "Diamond")
			{
				?>
				<script language="javascript">
                document.location="add_diamond.php";
                </script>
				<?php
			}
			elseif($inventory == "Gold")
			{
				?>
				<script language="javascript">
                document.location="add_gold.php";
                </script>
				<?php
			}
				elseif($inventory == "LogamMulia")
			{
				?>
				<script language="javascript">
                document.location="add_logam.php";
                </script>
				<?php
			}
				elseif($inventory == "ReadyItem")
			{
				?>
				<script language="javascript">
                document.location="add_readyitem.php";
                </script>
				<?php
			}
			elseif($inventory == "Cincin")
			{
				?>
				<script language="javascript">
                document.location="add_cincin.php";
                </script>
				<?php
			}
			elseif($inventory == "Mastura")
			{
				?>
				<script language="javascript">
                document.location="add_mastura.php";
                </script>
				<?php
			}
			elseif($inventory == "Liontin")
			{
				?>
				<script language="javascript">
                document.location="add_liontin.php";
                </script>
				<?php
			}
			elseif($inventory == "Kerabu")
			{
				?>
				<script language="javascript">
                document.location="add_kerabu.php";
                </script>
				<?php
			}
			elseif($inventory == "GKGR")
			{
				?>
				<script language="javascript">
                document.location="add_gkgr.php";
                </script>
				<?php
			}
			elseif($inventory == "Rangka")
			{
				?>
				<script language="javascript">
                document.location="add_rangka.php";
                </script>
				<?php
			}
		}
			else
			{
				?>
				<script language="javascript">
                alert("Input Inventory Failed");
                document.location="return_sales.php";
                </script>
				<?php	
			}
	}
	?>
<body>
<?php include "include/head2.php"; ?>
<?php include "include/leftmenu.php"; ?>
<?php include "include/top.php"; ?>
  <h1><i class="icon-bar-chart"></i> Return Sales</h1>
</div>

<ol class="breadcrumb">
  <li><a href="add_returnsales.php?act=2">Add Return Sales</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> List Return Sales</h3>
              <div class="widget-content-white glossed">
                <div class="padded">
                <table class="table table-striped table-bordered table-hover">
                  <thead>
                     <tr>
                         	 <th>Kode Return Sales</th>
                            <th>Tanggal Return Sales</th>
                           <th>Customer No. - Customer Name</th>
                 
                             <th>Sales Name</th>
                             <th>Kode Stock</th>
                             <th>Details</th>
                        </tr>
                  </thead>
                  <tbody>
                    <?php
						$sql = mysql_query("select *
						from  return_sales a
						left join tbl_customer b on a.id_customer  = b.id_customer
						where status_returnsales in ('1') order by id_returnsales");
						while($fetch = mysql_fetch_array($sql))
						{
								$id_returnsales = $fetch['id_returnsales'];
								list($y, $m, $d)=split ("[-]",$fetch['date_returnsales']);
								$date_returnsales=$d."-".$m."-".$y;
								$inventory = $fetch['inventory'];
									$kode_stock = $fetch['kode_stock'];
								$status_sales = $fetch['status_sales'];
					?>
                        <tr class="gradeX">
                          	<td><a href="view_returnsales.php?id_returnsales=<?php echo $id_returnsales; ?>"><?php echo $fetch['kode_returnsales'];?></a></td>
                            <td><?php echo $date_returnsales;?></td>
                            <td><?php echo $fetch['kode_customer'];?> - <?php echo $fetch['nama_customer'];?></td>
                           
                            <td><?php echo $fetch['user_update'];?></td>
                             <td>
                                 
                                 
                               <?php
                            $int = filter_var($kode_stock, FILTER_SANITIZE_NUMBER_INT);
                            $int2 = preg_replace('/[^A-Z]/', '', $kode_stock);
                            
                            //echo $int2; 
                            
                              if($int2=="M")
                              {
                                ?>
                                  <a href="view_mastura.php?id_stock=<?php echo $int; ?>"><?php echo $kode_stock; ?></a>
                                <?php
                              }
                              else if($int2 =="GKGR")
                              {
                                ?>
                                  <a href="view_gkgr.php?id_stock=<?php echo $int; ?>"><?php echo $kode_stock; ?></a>
                                <?php
                              }
                            else if($int2=="R")
                              {
                                ?>
                                  <a href="view_readyitem.php?id_stock=<?php echo $int; ?>"><?php echo $kode_stock; ?></a>
                                <?php
                              }
                            else if($int2=="G")
                              {
                                ?>
                                  <a href="view_gold.php?id_stock=<?php echo $int; ?>"><?php echo $kode_stock; ?></a>
                                <?php
                              }
                            else if($int2=="LM")
                              {
                                ?>
                                  <a href="view_logam.php?id_stock=<?php echo $int; ?>"><?php echo $kode_stock; ?></a>
                                <?php
                              }
                            else if($int2=="D")
                              {
                                ?>
                                  <a href="view_diamont.php?id_stock=<?php echo $int; ?>"><?php echo $kode_stock; ?></a>
                                <?php
                              }
                            else if($int2=="C")
                              {
                                ?>
                                  <a href="view_cincin.php?id_stock=<?php echo $int; ?>"><?php echo $kode_stock; ?></a>
                                <?php
                              }
                            else if($int2=="A")
                              {
                                ?>
                                  <a href="view_liontin.php?id_stock=<?php echo $int; ?>"><?php echo $kode_stock; ?></a>
                                <?php
                              }
                            else if($int2=="K")
                              {
                                ?>
                                  <a href="view_kerabu.php?id_stock=<?php echo $int; ?>"><?php echo $kode_stock; ?></a>
                                <?php
                              }
                            else if($int2=="R")
                              {
                                ?>
                                  <a href="view_rangka.php?id_stock=<?php echo $int; ?>"><?php echo $kode_stock; ?></a>
                                <?php
                              }
                              ?>  
                                 
                                 
                                 
                                 </td>
                             <td class="actions aligncenter"><!--<a href="return_sales.php?act=4&id_returnsales=<?php echo $id_returnsales; ?>&inventory=<?php echo $inventory; ?>">Input Inventory</a>&nbsp;|&nbsp;--><a href="return_sales.php?act=3&id_returnsales=<?php echo $id_returnsales; ?>">Delete</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>