<?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_sales  = $_REQUEST['id_sales'];
	if($act == 3)
	{
		$delete = mysql_query("update sales set status_sales = 2,user_update  = '$USERNAME' where id_sales='$id_sales'");
		if($delete)
		{
				?>
				<script language="javascript">
                alert("Delete Sales Success");
                document.location="sales.php";
                </script>
				<?php
			}
			else
			{
				?>
				<script language="javascript">
                alert("Delete Sales Failed");
                document.location="sales.php";
                </script>
				<?php	
			}
	}
	?>
<script type="text/javascript">

// JK Pop up image viewer script- By JavaScriptKit.com
// Visit JavaScript Kit (http://javascriptkit.com)
// for free JavaScript tutorials and scripts
// This notice must stay intact for use

var popbackground="white" //specify backcolor or background image for pop window
var windowtitle="Image Window"  //pop window title

function detectexist(obj){
return (typeof obj !="undefined")
}

function jkpopimage(imgpath, popwidth, popheight, textdescription){

function getpos(){
leftpos=(detectexist(window.screenLeft))? screenLeft+document.body.clientWidth/2-popwidth/2 : detectexist(window.screenX)? screenX+innerWidth/2-popwidth/2 : 0
toppos=(detectexist(window.screenTop))? screenTop+document.body.clientHeight/2-popheight/2 : detectexist(window.screenY)? screenY+innerHeight/2-popheight/2 : 0
if (window.opera){
leftpos-=screenLeft
toppos-=screenTop
}
}

getpos()
var winattributes='width='+popwidth+',height='+popheight+',resizable=yes,left='+leftpos+',top='+toppos
var bodyattribute=(popbackground.indexOf(".")!=-1)? 'background="'+popbackground+'"' : 'bgcolor="'+popbackground+'"'
if (typeof jkpopwin=="undefined" || jkpopwin.closed)
jkpopwin=window.open("","",winattributes)
else{
//getpos() //uncomment these 2 lines if you wish subsequent popups to be centered too
//jkpopwin.moveTo(leftpos, toppos)
jkpopwin.resizeTo(popwidth, popheight+30)
}
jkpopwin.document.open()
jkpopwin.document.write('<html><title>'+windowtitle+'</title><body '+bodyattribute+'><img src="'+imgpath+'" style="margin-bottom: 0.5em"></html>')
jkpopwin.document.close()
jkpopwin.focus()
}

</script>
<body>
<?php include "include/head2.php"; ?>
<?php include "include/leftmenu.php"; ?>
<?php include "include/top.php"; ?>
  <h1><i class="icon-shopping-cart"></i> Sales</h1>
</div>

<ol class="breadcrumb">
  <li><a href="add_sales.php?act=3">Add 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> Listing Sales</h3>
              <form method="post" action="sales.php?act=1"  role="form" class="form-horizontal">
              <table class="table table-striped table-bordered table-hover">
                  <tr>
                    <td><input type="text" class="form-control" name="customer" id="customer" value="NamaCustomer" onBlur="if (this.value == '') {this.value = 'NamaCustomer';}" onFocus="if (this.value == 'NamaCustomer') {this.value = '';}"></td>
                 
                    <td> <button type="submit" class="btn btn-default">Search</button></td>
                  </tr>
                </table>

              </form>
              <div class="widget-content-white glossed">
                <div class="padded">
                <table class="table table-striped table-bordered table-hover">
                  <thead>
                     <tr>
                         	 <th>Invoice No.</th>
                            <th>Invoice Date</th>
                            <th>Customer No. - Customer Name</th>
                 
                             <th>Sales Name</th>
                        
                             <th colspan="2"></th>
                        </tr>
                  </thead>
                  <tbody>
                      <?php
					  	$act = $_REQUEST['act'];
						
						
						if($act == 1)
						{
							$customer = $_REQUEST['customer'];
							$sql = mysql_query("select *
							from  sales a
							left join tbl_customer b on a.id_customer  = b.id_customer
							where status_sales in ('1','3') and nama_customer like '%$customer%'  order by id_sales");
							$sql1 = "select *
							from  sales a
							left join tbl_customer b on a.id_customer  = b.id_customer
							where status_sales in ('1','3') and nama_customer like '%$customer%'  order by id_sales";
						}
						else
						{
							$sql = mysql_query("select *
							from  sales a
							left join tbl_customer b on a.id_customer  = b.id_customer
							where status_sales in ('1','3') order by id_sales");
							$sql1 = "select *
							from  sales a
							left join tbl_customer b on a.id_customer  = b.id_customer
							where status_sales in ('1','3') order by id_sales";
						}
						$jumlah=mysql_num_rows($sql);
						$limit=50;
						$offset=$_GET[offset];
						if (empty($offset))
						{ $offset = 0;
							}
						$halaman=intval($jumlah/$limit);
						if($jumlah%$limit)
						{ $halaman++;
						}
						
						
						$item=$sql1." LIMIT $offset, $limit";
						
						//echo $rrr; exit;
						$item2=mysql_query($item);
						
						
						while($fetch = mysql_fetch_array($item2))
						{
								$id_sales = $fetch['id_sales'];
								list($y, $m, $d)=split ("[-]",$fetch['invoice_date']);
								$invoice_date=$d."-".$m."-".$y;
								$inventory = $fetch['inventory'];
								$status_sales = $fetch['status_sales'];
								$fetch2 = mysql_fetch_array(mysql_query("select * from salesdetails where id_sales='$id_sales'"));
								$barcodeno = $fetch2['barcode'];
								
								
					?>
                        <tr>
                          	<td><a href="view_sales.php?id_sales=<?php echo $id_sales; ?>"><?php echo $fetch['invoice'];?></a></td>
                            <td><?php echo $invoice_date;?></td>
                            <td><?php echo $fetch['kode_customer'];?> - <?php echo $fetch['nama_customer'];?></td>
              
                            <td><?php echo $fetch['user_update'];?></td>

                             <td class="actions aligncenter"><?php if($status_sales <> '3') {?><a href="edit_sales.php?id_sales=<?php echo $id_sales; ?>"class="btn btn-default btn-xs"><i class="icon-pencil"></i> edit</a> <!--</td>
                             <td class="actions aligncenter"><a href="sales.php?act=3&id_sales=<?php echo $id_sales; ?>" class="btn btn-default btn-xs"> <i class="icon-remove"></i> delete</a>--><?php } ?></td>
                        </tr>
                        <?php
						}
						?>
                  </tbody>
                </table>
                Page : <?php
						for($i=1; $i<=$halaman; $i++)
						{ $newoffset=$limit*($i-1);
						if($offset!=$newoffset)
						{ echo "&nbsp;<a href=\"".$_SERVER['PHP_SELF']."?act=1&offset=$newoffset&halamanke=$i&customer=$_REQUEST[customer]\">$i</a>&nbsp;|";
						}
						else
						{ echo "&nbsp;$i&nbsp;|";
						}
						}
						?>
                </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>