<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="function/dataTables/media/css/demo_page.css">
<link rel="stylesheet" href="function/dataTables/media/css/demo_table_jui.css">
<link rel="stylesheet" href="function/dataTables/media/themes/smoothness/jquery-ui-1.8.4.custom.css">
<script type="text/javascript" src="function/dataTables/media/js/jquery.js"></script>
<script type="text/javascript" src="function/dataTables/media/js/jquery.dataTables.js"></script>
<script type="text/javascript" language="javascript">
	$(document).ready( function () {
		var oTable = $('#myTables').dataTable( {
			 "sDom": 'R<"H"lfr>t<"F"ip>',
			 "bJQueryUI": true,
			 "sPaginationType": "full_numbers",
			 "iDisplayLength" :10
		});
	});		
	function setTrColor(obj, color)
	{
		obj.style.backgroundColor=color;
		obj.onmouseout = function(){
				obj.style.backgroundColor=''; 
		}
	}
	function add_click(){
		form.action ='?page=Proses-Stock-Awal&Act=ADD';
		form.method = 'post';
		form.submit();		
		return true;
	}
	function detail_click(id){
		form.action ='?page=Proses-Stock-Awal&Act=DETAIL&stock_id='+id;
		form.method = 'post';
		form.submit();		
		return true;
	}
	function import_click(){
		form.action ='?page=Proses-Stock-Awal&Act=UPL';
		form.method = 'post';
		form.submit();		
		return true;
	}
	function template_click(){
		form.action ='./master_data/stock/template_stock_awal.php';
		form.method = 'post';
		form.submit();		
		return true;
	}
	function export_click(){
		form.action ='./master_data/stock/export_stock_awal.php';
		form.method = 'post';
		form.submit();		
		return true;
	}	
	function delete_click(id,code){
		var a = confirm("Apakah anda yakin akan menghapus data?");
		if (a == true){
			form.action ='?page=Proses-Stock-Awal&Act=DELETE&stock_id='+id+'&prod_code='+code;
			form.method = 'post';
			form.submit();		
			return true;
		}	
	}
	function search_click(){
		form.action ='?page=Data-Stock-Awal&Act=SEARCH';
		form.method = 'post';
		form.submit();		
		return true;
	}
</script>
<?php
	$prod_cat  = isset($_REQUEST['prod_cat']) ? $_REQUEST['prod_cat'] : 1;
	/*if(isset($_REQUEST['Act'])=="SEARCH"){
		$search    = "a.prod_cat=$prod_cat";
	}else{
		$search    = "a.prod_cat=1";
	}*/
?>
<form method="post" name="form" enctype="multipart/form-data">
<table width="100%">
	<tr>
		<th colspan="8">DATA SALDO AWAL</th>
	</tr>
	<tr>
		<td colspan="8">&nbsp;</td>		
	</tr>
	<tr>
		<td colspan="8">
			<img src="images/btn_add.png" height="30" width="30" title="Tambah Manual" border="0" style="cursor:pointer" onclick="add_click();" />	
			<!--<img src="images/template_excel.png" height="30" width="30" title="Format Excel" border="0" style="cursor:pointer" onclick="template_click();" />
			<img src="images/btn_import.png" height="30" width="30" title="Upload Excel" border="0" style="cursor:pointer" onclick="import_click('<?=$user_id;?>');" />
			<img src="images/btn_export.png" height="30" width="30" title="Download Excel" border="0" style="cursor:pointer" onclick="export_click();" />-->		
		</td>	
	</tr>
	<tr>
		<td colspan="8">
			Kategori : <select name="prod_cat" class="form_select">	
					<?php
					  $dataSql = mysql_query("SELECT * FROM product_category ORDER BY id ASC");
					  while ($dataRow = mysql_fetch_array($dataSql)) {
						if ($dataRow['id']== $prod_cat) {
							$cek = " selected";
						} else { $cek=""; }
						echo "<option value='$dataRow[id]' $cek>$dataRow[prod_cat]</option>";
					  }
					  $sqlData ="";
					?>
				</select>
			<input type="button" name="search" value="CARI" style="cursor:pointer" onclick="search_click();">		
		</td>
	</tr>
</table>
<table id="myTables" class="display" cellpadding="0" cellspacing="0">
	<thead>
	<tr>
		<th>No.</th>
		<th>Tanggal</th>
		<th>Jenis</th>
		<th>Nomor</th>
		<th>Tgl Dok</th>
		<th>Kode Barang</th>
		<th>Nama Barang</th>
		<th>Satuan</th>
		<th>Jumlah</th>
		<th>Lokasi</th>
		<th>Lokasi Detail</th>
		<th>Action</th>
	</tr>
		</thead>
	<tbody>
	<?php		
		$month = substr($start_date, 5,2);
		$year = substr($start_date, 0,4);
	  	$no=1;
		$qd = mysql_query("SELECT a.*, b.prod_code, b.prod_name, b.prod_sat, c.prod_cat, d.mw_name FROM stock a INNER JOIN product b ON b.id=a.stock_prodid
		                   INNER JOIN product_category c ON c.id=b.prod_cat LEFT JOIN master_warehouse d ON d.id=a.stock_whid WHERE a.stock_status=10 AND MONTH(a.stock_date)=$month AND YEAR(a.stock_date)=$year 
						   AND b.prod_cat='$prod_cat' ORDER BY c.id, b.prod_code ASC");
		while($dd=mysql_fetch_object($qd)){	
			if($dd->stock_loc==1){
				$loc = "Gudang Bahan Baku";
			}elseif($dd->stock_loc==2){
				$loc = "Gudang Produksi/WIP";
			}if($dd->stock_loc==3){
				$loc = "Gudang FG & Scrap";
			}if($dd->stock_loc==4){
				$loc = "Gudang Mesin/Area Produksi";
			}	
		?> 
		   <tr onmouseover="setTrColor(this, '#FF9900');">
			<td align="center"><?=$no;?>.</td>
			<td align="left"><?=$dd->stock_date;?></td>
			<td align="center"><?=$dd->stock_doctype;?></td>
			<td align="center"><?=$dd->stock_docno;?></td>
			<td align="center"><?=$dd->stock_docdate;?></td>
			<td align="left"><?=$dd->prod_code;?></td>
			<td align="left"><?=$dd->prod_name;?></td>
			<td align="left"><?=$dd->prod_sat;?></td>
			<td align="right"><?=number_format($dd->stock_qty,2,'.',',');?></td>
			<td align="left"><?=$loc;?></td>
			<td align="left"><?=$dd->mw_name;?></td>
			<td align="center">
	<img src="images/btn_edit.png" width="20" height="20"  border="0"  title="Edit" style="cursor:pointer" onclick="detail_click('<?=$dd->id;?>');"  />
	<img src="images/btn_delete.png" width="20" height="20"  border="0"  title="Hapus" style="cursor:pointer" onclick="delete_click('<?=$dd->id;?>','<?=$dd->prod_code;?>');"  />
			</td>
		  </tr>
      <?php $no++; }  ?>	
	  </tbody>
</table>
</form>