<!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.dataTables.js"></script>
<script type="text/javascript" language="javascript">
	$(document).ready(function(){ 
		$("#fromdate").datepicker({
			dateFormat : "yy-mm-dd",
			changeMonth : true,
			changeYear : true,
		});
	});
	$(document).ready(function(){
		$("#todate").datepicker({
			dateFormat : "yy-mm-dd",
			changeMonth : true,
			changeYear : true,
		});
	});
	$(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 print_click(po_no){
		window.open("transaksi/purchasing/print_purchase_order.php?po_no="+po_no,"mywindow","menubar=1,scrollbars=1,resizable=1,width=1020,height=1000");
	}
	function print_click_excel(po_no){
		window.open("transaksi/purchasing/print_purchase_order_excel.php?po_no="+po_no,"mywindow","menubar=1,scrollbars=1,resizable=1,width=1020,height=1000");
	}
	function add_click(){
		form.action ='?page=Proses-Purchase-Order&Act=ADD';
		form.method = 'post';
		form.submit();		
		return true;
	}
	function posting_click(id,code){
		form.action ='?page=Proses-Purchase-Order&Act=POSTING&po_id='+id+'&po_no='+code;
		form.method = 'post';
		form.submit();		
		return true;
	}
	function detail_click(id,po_no){
		form.action ='?page=Proses-Purchase-Order&Act=DETAIL&po_id='+id+'&po_no'+po_no;
		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-Purchase-Order&Act=DELETE&po_id='+id+'&po_no='+code;
			form.method = 'post';
			form.submit();		
			return true;
		}	
	}
	function upload_click(){
		form.action ='?page=Proses-Upload-Purchase-Order&Act=ADD';
		form.method = 'post';
		form.submit();		
		return true;
	}
	function search_click(){
		form.action ='?page=Data-Purchase-Order';
		form.method = 'post';
		form.submit();		
		return true;
	}
	function excel_click(){
		form.action ='./transaksi/purchasing/excel_po_purchasing.php';
		form.method = 'post';
		form.submit();		
		return true;
	}
</script>
<?php
	$fromdate	 = isset($_REQUEST['fromdate'])?$_REQUEST['fromdate']:$start_date;
	$todate     = isset($_REQUEST['todate'])?$_REQUEST['todate']:$end_date; 	
?>
<form action="?page=Data-Purchase-Order" method="post" name="form" enctype="multipart/form-data">
<table width="100%" border="0" cellspacing="1" cellpadding="1">
  <tr>
	<td colspan="9" align="center"><h1><b>DATA PURCHASE ORDER PURCHASING</b></h1></td>
  </tr>
  <tr>
	<td colspan="9">
    	<img src="images/btn_add.png" height="30" width="30" title="Tambah Manual" border="0" style="cursor:pointer" onclick="add_click();" />
		<img src="images/btn_import.png" height="30" width="30" title="Upload via Excel" border="0" style="cursor:pointer" onclick="upload_click();" />
    </td>
  </tr>
  <tr>
	  <td colspan="9">Periode :
	      <input type="text" id="fromdate" name="fromdate" size="9" value="<?=$fromdate;?>" style="border-collapse:inherit"  readonly="true">&nbsp;s/d&nbsp;
	      <input type="text" id="todate" name="todate" size="9" value="<?=$todate;?>" style="border-collapse:inheri" readonly="true">
	      <input type="button" name="cari" value="CARI" style="cursor:pointer" onclick="search_click();">
		  <input type="button" name="excel" value="EXCEL" style="cursor:pointer" onclick="excel_click();">
		</td>
	</tr>
</table>
<table id="myTables" class="display" cellpadding="0" cellspacing="0">
	<thead>  
  <tr>
	<th>No</th>
	<th>Tipe PO</th>
	<th>No PO</th>
	<th>Tanggal PO</th>
	<th>Nama</th>
	<th>PIC</th>
	<th>Currency</th>
	<th>Tanggal Kirim</th>
	<th>Tanggal Jatuh Tempo</th>
	<th>Ship To</th>
	<th>Status</th>
	<th>Action</th>
  </tr>
  </thead>
	<tbody>
  <?php
	$no=1;
	$qd = mysql_query("SELECT a.*, b.sup_name, c.cust_name FROM purchase_order a LEFT JOIN supplier b ON b.id=a.po_idsupp
		  LEFT JOIN customer c ON c.id=a.po_idcust
		  WHERE a.po_status <> 100 AND a.po_date BETWEEN '$fromdate' AND '$todate' AND po_type='Purchasing' ORDER BY a.id DESC");
	while($dd=mysql_fetch_object($qd)){		
	   if($dd->po_status==10){$status = "Baru";}else{$status = "Posting";}
	   if($dd->po_type=="Purchasing"){$names = $dd->sup_name;}else{$names = $dd->cust_name;}
	?> 
	  <tr onmouseover="setTrColor(this, '#FF9900');">
		<td align="center"><?=$no;?>.</td>
		<td align="left"><?=$dd->po_type;?></td>
		<td align="center"><?=$dd->po_no;?></td>
		<td align="center"><?=$dd->po_date;?></td>
		<td align="left"><?=$names;?></td>
		<td><?=$dd->po_pic;?></td>
		<td align="center"><?=$dd->po_currency;?></td>
		<td align="center"><?=$dd->po_deldate;?></td>
		<td align="center"><?=$dd->po_duedate;?></td>
		<td align="center"><?=$dd->po_shipto;?></td>
		<td align="center"><?=$status;?></td>
		<td align="center">
			<?php if ($dd->po_status==10){ ?>
				<img src="images/btn_posting.png" width="20" height="20" border="0" title="Posting" style="cursor:pointer" onclick="posting_click('<?=$dd->id;?>', '<?=$dd->po_no;?>');" />
				<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->po_no;?>');" />
			<?php }else { ?>
				<img src="images/btn_print.png" height="20" width="20" title="PDF" border="0" style="cursor:pointer" onclick="print_click('<?=$dd->po_no;?>');" />
				<img src="images/btn_import.png" height="20" width="20" title="Excel" border="0" style="cursor:pointer" onclick="print_click_excel('<?=$dd->po_no;?>');" />
			<?php } ?>
		</td>
	  </tr>
  <?php $no++; }  ?>
	</tbody>
</table>
</form>
