<?php
session_start();
include_once "../../include/config.php";
include_once "../../function/inc_function.php";

$datetime 	= get_datetime();
$date		= get_date();
$time		= get_time();
$user_id  	= $_SESSION['USER_ID'];
$Act  		= isset($_REQUEST['Act']) ? $_REQUEST['Act'] : '';
$doch_id	= isset($_REQUEST['doch_id']) ? $_REQUEST['doch_id'] : '';
$docd_id	= isset($_REQUEST['docd_id']) ? $_REQUEST['docd_id'] : '';
if(!empty($doch_id)){
$dh = mysql_fetch_object(mysql_query("SELECT * FROM document WHERE id='$doch_id'"));
	$doch_regno		= $dh->doch_regno;
	$doch_date		= $dh->doch_date;
	$doch_custid	= $dh->doch_custid;
	$nm_penerima	= $dh->nm_penerima;
	$doch_invno		= $dh->doch_invno;
	$doch_dono	    = $dh->doch_dono;
	$doch_doctype   = $dh->doch_doctype;
	$doch_docno		= $dh->doch_docno;
	$doch_docdate	= $dh->doch_docdate;
	$doch_attn		= $dh->doch_attn;
	$doch_idtypeout = $dh->doch_idtypeout;
	$doch_desc		= $dh->doch_desc;
	$doch_idpayment	= $dh->doch_idpayment;
	$doch_subtotal	= $dh->doch_subtotal;
	$doch_discount	= $dh->doch_discount;
	$doch_ppn		= $dh->doch_ppn;
	$doch_grandtotal = $dh->doch_grandtotal;
	$doch_idttd		= $dh->doch_idttd;
	$doch_idjabatan	= $dh->doch_idjabatan;
}else{
	$doch_regno		= isset($_REQUEST['doch_regno']) ? $_REQUEST['doch_regno'] : get_nodocument();
	$doch_date		= isset($_REQUEST['doch_date']) ? $_REQUEST['doch_date'] : $date;
	$doch_custid	= isset($_REQUEST['doch_custid']) ? $_REQUEST['doch_custid'] : '';
	$nm_penerima	= isset($_REQUEST['nm_penerima']) ? $_REQUEST['nm_penerima'] : '';
	$doch_invno		= isset($_REQUEST['doch_invno']) ? $_REQUEST['doch_invno'] : '';
	$doch_dono	    = isset($_REQUEST['doch_dono']) ? $_REQUEST['doch_dono'] : '';
	$doch_doctype   = isset($_REQUEST['doch_doctype']) ? $_REQUEST['doch_doctype'] : '';
	$doch_docno		= isset($_REQUEST['doch_docno']) ? $_REQUEST['doch_docno'] : '';
	$doch_docdate	= isset($_REQUEST['doch_docdate']) ? $_REQUEST['doch_docdate'] : $date;
	$doch_attn		= isset($_REQUEST['doch_attn']) ? $_REQUEST['doch_attn'] : '';
	$doch_idtypeout = isset($_REQUEST['doch_idtypeout']) ? $_REQUEST['doch_idtypeout'] : 0;
	$doch_desc		= isset($_REQUEST['doch_desc']) ? $_REQUEST['doch_desc'] : '';
	$doch_idpayment	= isset($_REQUEST['doch_idpayment']) ? $_REQUEST['doch_idpayment'] : 0;
	$doch_subtotal	= isset($_REQUEST['doch_subtotal']) ? $_REQUEST['doch_subtotal'] : '';
	$doch_discount	= isset($_REQUEST['doch_discount']) ? $_REQUEST['doch_discount'] : 0;
	$doch_ppn		= isset($_REQUEST['doch_ppn']) ? $_REQUEST['doch_ppn'] : 0;
	$doch_grandtotal = isset($_REQUEST['doch_grandtotal']) ? $_REQUEST['doch_grandtotal'] : 0;
	$doch_idttd		= isset($_REQUEST['doch_idttd']) ? $_REQUEST['doch_idttd'] : 0;
	$doch_idjabatan	= isset($_REQUEST['doch_idjabatan']) ? $_REQUEST['doch_idjabatan'] : 0;
}
if($Act=="ADD"){
	$docd_prodid 	= $_REQUEST['prodid'];
	$docd_qty 		= $_REQUEST['docd_qty'];
	$docd_price 	= $_REQUEST['docd_price'];
	$docd_currency 	= $_REQUEST['docd_currency'];
	$docd_weight 	= $_REQUEST['docd_weight'];
	$docd_buyerpo 	= $_REQUEST['docd_buyerpo'];
	$docd_total 	= $_REQUEST['docd_total'];
	$docd_gross 	= $_REQUEST['docd_gross'];
	$docd_box 		= $_REQUEST['docd_box'];
	$docd_pallet 	= $_REQUEST['docd_pallet'];
	if(empty($doch_id)){
		#Insert Temp
		mysql_query("INSERT INTO document_temp SET docd_prodid='$docd_prodid', docd_qty='$docd_qty', docd_price='$docd_price', docd_currency='$docd_currency',
		docd_weight='$docd_weight', docd_buyerpo='$docd_buyerpo', docd_total='$docd_total', docd_gross='$docd_gross', docd_box='$docd_box', docd_pallet='$docd_pallet',
		docd_userid='$user_id'");
	}else{
		#Insert Detail
		mysql_query("INSERT INTO document_detai SET docd_hid='$doch_id', docd_prodid='$docd_prodid', docd_qty='$docd_qty', docd_price='$docd_price', docd_currency='$docd_currency',
		docd_weight='$docd_weight', docd_buyerpo='$docd_buyerpo', docd_total='$docd_total', docd_gross='$docd_gross', docd_box='$docd_box', docd_pallet='$docd_pallet'");
	}
}	
if($Act=="DEL"){
	if(empty($doch_id)){
		#Delete Temp
		mysql_query("DELETE FROM document_temp WHERE id='$docd_id'");
	}else{
		#Delete Temp
		mysql_query("DELETE FROM document_detail WHERE id='$docd_id'");
	}
}
?>
<html>
<head>
<link rel='stylesheet' type='text/css' href='../../include/css/display_styles.css' />	
<!--Date Picker-->
<link type="text/css" rel="stylesheet" href="../../include/jq/datepicker/themes/ui-lightness/ui.all.css" />
<script src="../../include/jq/datepicker/jquery-1.8.0.min.js"></script>
<script src="../../include/jq/datepicker/ui/ui.core.js"></script>
<script src="../../include/jq/datepicker/ui/ui.datepicker.js"></script>
<script src="../../include/jq/datepicker/ui/i18n/ui.datepicker-id.js"></script>
<!--Toggle-->
<link rel="stylesheet" type="text/css" media="screen" href="../../include/jq/toggle/jquery-ui-1.8.16.custom.css" />
<script src="../../include/jq/toggle/jquery-1.5.2.min.js" type="text/javascript"></script>
<script src="../../include/jq/toggle/jquery-ui-1.8.16.custom.min.js" type="text/javascript"></script>
<script type="text/javascript">
	$(document).ready(function(){
		$("#docdate").datepicker({
			dateFormat : "yy-mm-dd",
			changeMonth : true,
			changeYear : true,
		});
	});
	$(document).ready(function(){
		var out = {
			source: "../../transaksi/manual/json_dokumen.php",					
			select: function(event, ui){
				$("#prodcode").val(ui.item.prod_code); 
				$("#prodid").val(ui.item.prod_id); 
				$("#prodsat").val(ui.item.prod_sat); 
				$("#prodstock").val(ui.item.prod_stock);
				$("#prodprice").val(ui.item.prod_price);
				$("#prodcurr").val(ui.item.prod_curr);
			},
			minLength: 1
		};
		$("#prodcode").autocomplete(out);		
	});	
	$(document).ready(function(){
		var cust = {
			source: "../../transaksi/manual/json_customer.php",					
			select: function(event, ui){
				$("#doch_custid").val(ui.item.cust_id); 
				$("#nm_penerima").val(ui.item.cust_name); 
			},
			minLength: 1
		};
		$("#nm_penerima").autocomplete(cust);		
	});	
	function format_number(bilangan){
		var	number_string = bilangan.toString(),
		split	= number_string.split('.'),
		sisa 	= split[0].length % 2,
		rupiah 	= split[0].substr(0, sisa),
		ribuan 	= split[0].substr(sisa).match(/\d{1,3}/gi);
			
		if (ribuan) {
			separator = sisa ? ',' : '';
			rupiah += separator + ribuan.join(',');
		}
		rupiah = split[1] != undefined ? rupiah + '.' + split[1] : rupiah;
		return rupiah;
	} 
	function ppncheck_click(){
		var check	 = document.getElementById("doch_ppncheck"); 
		var stotal	 = $("#doch_subtotal").val();		
		if (check.checked == true){
			var ppn = eval(stotal)*0.1;
		} else {
			var ppn = 0;
		}
		var gtotal = eval(stotal) + eval(ppn);
		$("#doch_ppn").val(ppn);
		$("#doch_ppnd").val(format_number(ppn));
		$("#doch_grandtotal").val(gtotal);
		$("#doch_grandtotald").val(format_number(gtotal));
	}
	function price_click(){
		var qty		 = $("#docd_qty").val();
		var price	 = $("#prodprice").val();
		var total 	 = eval(qty)*eval(price);
		$("#docd_total").val(total);		
	 }
	 function add_click(doch_id){
	 	if(form.prodid.value==""){
			alert("Silakan isi kode barang.");
			form.prodcode.focus();
			return false;
		}else if(form.docd_buyerpo.value==""){
			alert("Silakan isi buyer PO.");
			form.docd_buyerpo.focus();
			return false;
		}else if(form.docd_qty.value==""){
			alert("Silakan isi qty.");
			form.docd_qty.focus();
			return false;
		}else if(form.docd_price.value==""){
			alert("Silakan isi harga.");
			form.docd_price.focus();
			return false;
		}else if(form.docd_currency.value==0){
			alert("Silakan isi currency.");
			form.docd_currency.focus();
			return false;
		}/*else if(form.docd_weight.value==""){
			alert("Silakan isi netto.");
			form.docd_weight.focus();
			return false;
		}else if(form.docd_gross.value==""){
			alert("Silakan isi gross.");
			form.docd_gross.focus();
			return false;
		}else if(form.docd_box.value==""){
			alert("Silakan isi box.");
			form.docd_box.focus();
			return false;
		}else if(form.docd_pallet.value==""){
			alert("Silakan isi jumlah pallet.");
			form.docd_pallet.focus();
			return false;
		}*/else{
			form.action ='add_dokumen.php?Act=ADD&doch_id='+doch_id;
			form.method = 'post';
			form.submit();			
			return true;
		}	
 	 }
	 function delete_click(docd_id,doch_id){
	 		form.action ='add_dokumen.php?Act=DEL&docd_id='+docd_id+'&doch_id='+doch_id;
			form.method = 'post';
			form.submit();			
			return true;
	 }
	 function save_click(){
		if(form.doch_idtypeout.value==0){
			alert("Silakan isi jenis pengeluaran.");
			form.doch_idtypeout.focus();
			return false;
		}else if(form.nm_penerima.value==""){
			alert("Silakan isi nama penerima.");
			form.nm_penerima.focus();
			return false;
		}else if((form.doch_invno.value=="") ){
			alert("Silakan isi nomor invoice.");
			form.doch_invno.focus();
			return false;
		}else if((form.doch_dono.value=="") ){
			alert("Silakan isi nomor DO.");
			form.doch_dono.focus();
			return false;
		}else if((form.doch_doctype.value==0) ){
			alert("Silakan pilih jenis dokumen.");
			form.doch_doctype.focus();
			return false;
		}else if((form.doch_docno.value=="") ){
			alert("Silakan isi nomor dokumen.");
			form.doch_docno.focus();
			return false;
		}else if((form.doch_attn.value=="") ){
			alert("Silakan isi Up/Att.");
			form.doch_attn.focus();
			return false;
		}else if((form.doch_desc.value=="") ){
			alert("Silakan isi catatan.");
			form.doch_desc.focus();
			return false;
		}else if((form.doch_subtotal.value==0) ){
			alert("Silakan isi detail barang.");
			form.doch_subtotal.focus();
			return false;
		}else if((form.doch_idpayment.value==0) ){
			alert("Silakan isi tipe payment.");
			form.doch_idpayment.focus();
			return false;
		}else if((form.doch_idttd.value==0) ){
			alert("Silakan isi ttd.");
			form.doch_idttd.focus();
			return false;
		}else if((form.doch_idjabatan.value==0) ){
			alert("Silakan isi jabatan.");
			form.doch_idjabatan.focus();
			return false;
		}else{
			var a = confirm("Apakah anda yakin akan menyimpan data?");
			if (a == true){
				form.action ='proses_dokumen.php?Act=SAVE';
				form.method = 'post';
				form.submit();			
				return true;
			}
		}
	}	
	function close_click(){
		window.close();
	}
	function popup_item(){
		window.open("../../popup/popup_item.php?","mywindow","menubar=1,scrollbars=1,resizable=1,width=600,height=250");
	}
</script>
</head>
<body>
<div id='page'><div id='content'><div id="post">
<form action="?page=Proses-Dokumen" method="post" name="form" target="_self" enctype="multipart/form-data">
<table width="100%" cellpadding="2" cellspacing="1" class="table-list" style="margin-top:0px;">
	<tr>
	  <th colspan="4" align="left">HEADER PLAN PENGELUARAN</th>
	</tr>
	<tr>
	  <td width="15%">Jenis Pengeluaran</td>
	  <td width="35%">: 
	  	<input type="hidden" name="doch_id" value="<?php echo $doch_id; ?>" size="50" />
		<select name="doch_idtypeout">
		  <option value="0" selected="selected">PILIH</option> 
			<?php
			  $dataSql = mysql_query("SELECT id,out_type FROM outgoing_type WHERE out_status=10 ORDER BY  id ASC");
			  while ($dataRow = mysql_fetch_array($dataSql)) {
				if ($dataRow['id']== $doch_idtypeout) {
					$cek = " selected";
				} else { $cek=""; }
				echo "<option value='$dataRow[id]' $cek>$dataRow[out_type]</option>";
			  }
			  $sqlData ="";
			?>
		 </select>
	  </td>
	  <td width="15%">Up/Pic/Attn</td>
	  <td width="35%">: <input type="text" name="doch_attn" value="<?php echo $doch_attn; ?>" size="25"></td>
	</tr>
	<tr>
		<td>No. Registrasi</td>
		<td>: <input type="text" name="doch_regno" value="<?php echo $doch_regno; ?>" size="15" readonly="true" style="background-color:#CCFFFF " /> </td>
		<td>Jenis Dokumen</td>
		<td>: <select name="doch_doctype">
				  <option value="0" selected="selected">PILIH</option> 
					<?php
					  $dataSql = mysql_query("SELECT doc_type FROM document_type WHERE doc_status=2 ORDER BY  id ASC");
					  while ($dataRow = mysql_fetch_array($dataSql)) {
						if ($dataRow['doc_type']== $doch_doctype) {
							$cek = " selected";
						} else { $cek=""; }
						echo "<option value='$dataRow[doc_type]' $cek>$dataRow[doc_type]</option>";
					  }
					  $sqlData ="";
					?>
			 </select>
		</td>
	</tr>
	<tr>
		<td>No DO</td>
		<td>: <input type="text" name="doch_dono" value="<?php echo $doch_dono; ?>" size="25" /></td>
		<td>No Dokumen</td>
		<td>: <input type="text" name="doch_docno" value="<?php echo $doch_docno; ?>" size="6" /></td>
	</tr>
	<tr>
		<td>Penerima Barang</td>
		<td>: 
			<input type="hidden" name="doch_custid" id="doch_custid" value="<?=$doch_custid;?>" size="50" />
			<input type="text" name="nm_penerima" id="nm_penerima" value="<?=$nm_penerima;?>" size="50" style="background-color:#CCFFFF" />
		</td>
		<td>Tanggal Dokumen</td>
		<td>: <input type="text" name="doch_docdate" value="<?php if(empty($doch_docdate)){$doch_docdate=$date;} echo $doch_docdate; ?>" size="12" id="docdate" 
				  readonly="true" style="background-color:#CCFFFF " /></td>
	</tr>
	<tr>
		<td>No. Invoice</td>
		<td>: <input type="text" name="doch_invno" value="<?php echo $doch_invno; ?>" size="25" /></td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
	</tr>
	<tr>
		<td>Catatan</td>
		<td colspan="3">: <textarea name="doch_desc" class="textarea-field" cols="100"><?php echo $doch_desc; ?></textarea></td>
	</tr>
	<tr>
		<td colspan="4">&nbsp;</td>
	</tr>
	<tr>
		<th colspan="4" align="left">DETAIL DATA BARANG</th>
	</tr>
	<tr>
		<td colspan="4">
			<table width="100%">
				<tr>
					<td align="center">Kode Barang</td>								
					<td align="center">Satuan</td>
					<td align="center">BuyerPO</td>
					<td align="center">Qty</td>
					<td align="center">Harga</td>	
					<td align="center">Curr</td>				
					<td align="center">Total</td>					
					<td align="center">Nett</td>
					<td align="center">Gross</td>
					<td align="center">Box</td>
					<td align="center">Pallet</td>
					<td align="center">Action</td>
				</tr>
				<tr>
					<td>
						<input type="hidden" name="prodid" id="prodid" style="width:300px;">
						<input type="text" name="prodcode" id="prodcode" style="width:200px; background-color:#CCFFFF" >
						<img src="../../images/popup.png" height="15" width="15" title="Popup Item Master" style="cursor:pointer" border="0" onClick="popup_item();" />
					</td>
					<td>
						<input type="text" name="prodsat" id="prodsat" style="width:50px; text-align:left; background-color:#CCFFFF" readonly="true">
						<input type="hidden" name="prodstock" id="prodstock" style="width:50px; text-align:right; background-color:#CCFFFF" readonly="true">
					</td>
					<td><input type="text" name="docd_buyerpo" id="docd_buyerpo" size="15"></td>
					<td><input type="text" name="docd_qty" id="docd_qty" size="5" style="text-align:right" onBlur="price_click()"></td>
					<td><input type="text" name="docd_price" id="prodprice" size="10" style="text-align:right"  onBlur="price_click()"></td>
					<td>
						<!--<input type="text" name="docd_currency" id="prodcurr" size="5" style="text-align:center">-->
						<select name="docd_currency" id="prodcurr">
							<option value="0" selected>PILIH</option>
							<?php
							  $dataSql = mysql_query("SELECT currency FROM currency ORDER BY id ASC");
							  while ($dataRow = mysql_fetch_array($dataSql)) {
								echo "<option value='$dataRow[currency]' $cek>$dataRow[currency]</option>";
							  }
							  $sqlData =""; 
							?>
						 </select>
					</td>
					<td><input type="text" name="docd_total" id="docd_total" size="10" style="text-align:right"></td>
					<td><input type="text" name="docd_weight" id="docd_weight" size="6" value="0" style="text-align:right"></td>
					<td><input type="text" name="docd_gross" id="docd_gross" size="6" value="0" style="text-align:right"></td>
					<td><input type="text" name="docd_box" id="docd_box" size="6" value="0" style="text-align:right"></td>
					<td><input type="text" name="docd_pallet" id="docd_pallet" size="6" value="0" style="text-align:right"></td>
					<td><input type="button" name="Add" value="Add" onClick="add_click('<?=$doch_id;?>');"></td>
				</tr>
			</table>
		</td>
	</tr>	
	<tr>
		<td colspan="4">&nbsp;</td>
	</tr>
	<?php if(!empty($doch_id)){ ?>		
	<tr>
		<td colspan="4">
			<table width="100%">
				<tr>
					<td align="center">No.</td>
					<td align="center">Nama Barang</td>
					<td align="center">Kode</td>
					<td align="center">Satuan</td>
					<td align="center">Buyer PO</td>
					<td align="center">Harga</td>
					<td align="center">Qty</td>
					<td align="center">Total</td>
					<td align="center">Curr</td>
					<td align="center">Nett</td>
					<td align="center">Gross</td>
					<td align="center">Box</td>
					<td align="center">Pallet</td>
					<td align="center">Act</td>
				</tr>
				<?php
				    $no=0; $tqty=0; $ptotal=0; $tnet=0; $tgros=0;
					$qd = mysql_query("SELECT a.*,b.prod_code, b.prod_name, b.prod_sat
									   FROM document_detail a
									   INNER JOIN product b ON b.id=a.docd_prodid
						   			   WHERE a.docd_hid='$doch_id'");
					while($dt=mysql_fetch_object($qd)){	   
				    $no++;					
					$tnet    = $tnet + $dt->docd_weight;
					$tgros   = $tgros + $dt->docd_gross;
					$tqty    = $tqty + $dt->docd_qty;
					$pprice  = $dt->docd_qty * $dt->docd_price;
					$ptotal  = $ptotal + $pprice;					
				?> 
				  <tr>
					<td align="center"><?=$no;?>.</td>
					<td><?=$dt->prod_name;?></td>
					<td align="left"><?=$dt->prod_code;?></td>
					<td align="center"><?=$dt->prod_sat;?></td>
					<td align="center"><?=$dt->docd_buyerpo;?></td>
					<td align="right"><?=number_format($dt->docd_price,2,'.',',');?></td>
					<td align="right"><?=number_format($dt->docd_qty,2,'.',',');?></td>
					<td align="right"><?=number_format($pprice,2,'.',',');?></td>
					<td align="center"><?=$dt->docd_currency;?></td>
					<td align="right"><?=number_format($dt->docd_weight,2,'.',',');?></td>
					<td align="right"><?=number_format($dt->docd_gross,2,'.',',');?></td>
					<td align="right"><?=$dt->docd_box;?></td>
					<td align="center">(120X100X14) X <?=$dt->docd_pallet;?></td>
					<td align="center">
						<img src="../../images/btn_delete.png" height="20" width="20" title="Hapus" border="0" style="cursor:pointer" 
						onclick="delete_click('<?=$dt->id;?>','<?=$doch_id;?>');" />
					</td>
				</tr>
				<?php } 
					$ppn    = $ptotal * 0.1; 
					$gtotal = $ptotal + $ppn; 
				?>
				<tr>
					<td colspan="7" align="right">Sub Total</td>
					<td align="right"><?=number_format($ptotal,2,'.',',');?>
						<input type="hidden" name="doch_subtotal" id="doch_subtotal" value="<?=$ptotal;?>" size="15" style="text-align:right">
					</td>
					<td>&nbsp;</td>
					<td align="right"><?=number_format($tnet,2,'.',',');?></td>
					<td align="right"><?=number_format($tgros,2,'.',',');?></td>
					<td colspan="3" align="right">Total qty : <?=number_format($tqty,2,'.',',');?></td>
				</tr>
				<tr>
					<td colspan="2" align="right">Payment : </td>
					<td colspan="4" align="left">
						<select name="doch_idpayment" id="doch_idpayment">
							<option value="0" selected="selected">PILIH</option> 
							<?php
							  $dataSql = mysql_query("SELECT id, pay_type FROM payment_type WHERE pay_status=10 ORDER BY  id ASC");
							  while ($dataRow = mysql_fetch_array($dataSql)) {
								if ($dataRow['id']== $doch_idpayment) {
									$cek = " selected";
								} else { $cek=""; }
								echo "<option value='$dataRow[id]' $cek>$dataRow[pay_type]</option>";
							  }
							  $sqlData ="";
							?>
						 </select>
					</td>
					<td align="right">Discount</td>
					<td align="right">
						<input type="text" name="doch_discount" id="doch_discount" value="<?=$doch_discount;?>" size="15" style="text-align:right">
					</td>
					<td colspan="6">&nbsp;</td>
				</tr>
				<tr>
					<td colspan="7" align="right">PPN <input type="checkbox" name="doch_ppncheck" id="doch_ppncheck" checked="checked" onClick="ppncheck_click();"></td>
					<td align="right">
						<input type="hidden" name="doch_ppn" id="doch_ppn" value="<?=$ppn;?>" readonly="true" size="15" style="text-align:right">
						<input type="text" name="doch_ppnd" id="doch_ppnd" value="<?=number_format($ppn,2,'.',',');?>" readonly="true" size="15" style="text-align:right">
					</td>
					<td colspan="6" align="right">
						Ttd : 
						<select name="doch_idttd" id="doch_idttd">
							<option value="0" selected="selected">PILIH</option> 
							<?php
							  $dataSql = mysql_query("SELECT id, ttd_name FROM tandatangan WHERE ttd_status=10 ORDER BY  id ASC");
							  while ($dataRow = mysql_fetch_array($dataSql)) {
								if ($dataRow['id']== $doch_idttd) {
									$cek = " selected";
								} else { $cek=""; }
								echo "<option value='$dataRow[id]' $cek>$dataRow[ttd_name]</option>";
							  }
							  $sqlData ="";
							?>
						 </select>
					</td>
				</tr>
				<tr>
					<td colspan="7" align="right">Grand Total</td>
					<td align="right">
						<input type="hidden" name="doch_grandtotal" id="doch_grandtotal" value="<?=$gtotal;?>" readonly="true" size="15" style="text-align:right">
						<input type="text" name="doch_grandtotald" id="doch_grandtotald" value="<?=number_format($gtotal,2,'.',',');?>" readonly="true" size="15" style="text-align:right">
					</td>
					<td colspan="6" align="right">
						Jabatan :
						<select name="doch_idjabatan" id="doch_idjabatan">
							<option value="0" selected="selected">PILIH</option> 
							<?php
							  $dataSql = mysql_query("SELECT id, jab_name FROM jabatan WHERE jab_status=10 ORDER BY  id ASC");
							  while ($dataRow = mysql_fetch_array($dataSql)) {
								if ($dataRow['id']== $doch_idjabatan) {
									$cek = " selected";
								} else { $cek=""; }
								echo "<option value='$dataRow[id]' $cek>$dataRow[jab_name]</option>";
							  }
							  $sqlData ="";
							?>
						 </select>
					</td>
				</tr>
			</table>
		</td>
	</tr>
	<?php }else{ ?>
	<tr>
		<td colspan="4">
			<table width="100%">
				<tr>
					<td align="center">No.</td>
					<td align="center">Nama Barang</td>
					<td align="center">Kode</td>
					<td align="center">Satuan</td>
					<td align="center">Buyer PO</td>
					<td align="center">Harga</td>
					<td align="center">Qty</td>
					<td align="center">Total</td>
					<td align="center">Curr</td>
					<td align="center">Nett</td>
					<td align="center">Gross</td>
					<td align="center">Box</td>
					<td align="center">Pallet</td>
					<td align="center">Act</td>
				</tr>
				<?php
				    $no=0; $tqty=0; $ptotal=0; $tnet=0; $tgros=0;
					$qd = mysql_query("SELECT a.*,b.prod_code, b.prod_name, b.prod_sat
									   FROM document_temp a
									   INNER JOIN product b ON b.id=a.docd_prodid
						   			   WHERE a.docd_userid='$user_id'");
					while($dt=mysql_fetch_object($qd)){	   
				    $no++;					
					$tnet    = $tnet + $dt->docd_weight;
					$tgros   = $tgros + $dt->docd_gross;
					$tqty    = $tqty + $dt->docd_qty;
					$pprice  = $dt->docd_qty * $dt->docd_price;
					$ptotal  = $ptotal + $pprice;					
				?> 
				  <tr>
					<td align="center"><?=$no;?>.</td>
					<td><?=$dt->prod_name;?></td>
					<td align="left"><?=$dt->prod_code;?></td>
					<td align="center"><?=$dt->prod_sat;?></td>
					<td align="center"><?=$dt->docd_buyerpo;?></td>
					<td align="right"><?=number_format($dt->docd_price,2,'.',',');?></td>
					<td align="right"><?=number_format($dt->docd_qty,2,'.',',');?></td>
					<td align="right"><?=number_format($pprice,2,'.',',');?></td>
					<td align="center"><?=$dt->docd_currency;?></td>
					<td align="right"><?=number_format($dt->docd_weight,2,'.',',');?></td>
					<td align="right"><?=number_format($dt->docd_gross,2,'.',',');?></td>
					<td align="right"><?=$dt->docd_box;?></td>
					<td align="center">(120X100X14) X <?=$dt->docd_pallet;?></td>
					<td align="center">
						<img src="../../images/btn_delete.png" height="20" width="20" title="Hapus" border="0" style="cursor:pointer" 
						onclick="delete_click('<?=$dt->id;?>','<?=$doch_id;?>');" />
					</td>
				</tr>
				<?php } 
					$ppn    = $ptotal * 0.1; 
					$gtotal = $ptotal + $ppn; 
				?>
				<tr>
					<td colspan="7" align="right">Sub Total</td>
					<td align="right"><?=number_format($ptotal,2,'.',',');?>
						<input type="hidden" name="doch_subtotal" id="doch_subtotal" value="<?=$ptotal;?>" size="15" style="text-align:right">
					</td>
					<td>&nbsp;</td>
					<td align="right"><?=number_format($tnet,2,'.',',');?></td>
					<td align="right"><?=number_format($tgros,2,'.',',');?></td>
					<td colspan="3" align="right">Total qty : <?=number_format($tqty,2,'.',',');?></td>
				</tr>
				<tr>
					<td colspan="2" align="right">Payment : </td>
					<td colspan="4" align="left">
						<select name="doch_idpayment" id="doch_idpayment">
							<option value="0" selected="selected">PILIH</option> 
							<?php
							  $dataSql = mysql_query("SELECT id, pay_type FROM payment_type WHERE pay_status=10 ORDER BY  id ASC");
							  while ($dataRow = mysql_fetch_array($dataSql)) {
								if ($dataRow['id']== $doch_idpayment) {
									$cek = " selected";
								} else { $cek=""; }
								echo "<option value='$dataRow[id]' $cek>$dataRow[pay_type]</option>";
							  }
							  $sqlData ="";
							?>
						 </select>
					</td>
					<td align="right">Discount</td>
					<td align="right">
						<input type="text" name="doch_discount" id="doch_discount" value="<?=$doch_discount;?>" size="15" style="text-align:right">
					</td>
					<td colspan="6">&nbsp;</td>
				</tr>
				<tr>
					<td colspan="7" align="right">PPN <input type="checkbox" name="doch_ppncheck" id="doch_ppncheck" checked="checked" onClick="ppncheck_click();"></td>
					<td align="right">
						<input type="hidden" name="doch_ppn" id="doch_ppn" value="<?=$ppn;?>" readonly="true" size="15" style="text-align:right">
						<input type="text" name="doch_ppnd" id="doch_ppnd" value="<?=number_format($ppn,2,'.',',');?>" readonly="true" size="15" style="text-align:right">
					</td>
					<td colspan="6" align="right">
						Ttd : 
						<select name="doch_idttd" id="doch_idttd">
							<option value="0" selected="selected">PILIH</option> 
							<?php
							  $dataSql = mysql_query("SELECT id, ttd_name FROM tandatangan WHERE ttd_status=10 ORDER BY  id ASC");
							  while ($dataRow = mysql_fetch_array($dataSql)) {
								if ($dataRow['id']== $doch_idttd) {
									$cek = " selected";
								} else { $cek=""; }
								echo "<option value='$dataRow[id]' $cek>$dataRow[ttd_name]</option>";
							  }
							  $sqlData ="";
							?>
						 </select>
					</td>
				</tr>
				<tr>
					<td colspan="7" align="right">Grand Total</td>
					<td align="right">
						<input type="hidden" name="doch_grandtotal" id="doch_grandtotal" value="<?=$gtotal;?>" readonly="true" size="15" style="text-align:right">
						<input type="text" name="doch_grandtotald" id="doch_grandtotald" value="<?=number_format($gtotal,2,'.',',');?>" readonly="true" size="15" style="text-align:right">
					</td>
					<td colspan="6" align="right">
						Jabatan :
						<select name="doch_idjabatan" id="doch_idjabatan">
							<option value="0" selected="selected">PILIH</option> 
							<?php
							  $dataSql = mysql_query("SELECT id, jab_name FROM jabatan WHERE jab_status=10 ORDER BY  id ASC");
							  while ($dataRow = mysql_fetch_array($dataSql)) {
								if ($dataRow['id']== $doch_idjabatan) {
									$cek = " selected";
								} else { $cek=""; }
								echo "<option value='$dataRow[id]' $cek>$dataRow[jab_name]</option>";
							  }
							  $sqlData ="";
							?>
						 </select>
					</td>
				</tr>
			</table>
		</td>
	</tr>
	<?php } ?>
	<tr>
		<td colspan="4">&nbsp;</td>
	</tr>
	<tr>
		<td colspan="4" align="center">
			<input type="button" name="btnSave" value="SIMPAN" style="cursor:pointer;" onClick="save_click();">
			<input type="button" value="BATAL" name="batal" style="cursor:pointer"  onClick="close_click();" />
		</td>
    </tr>
</table>
</form>
</div></div></div>
</body>
</html> 
