<html>
<head>
<script type="text/javascript"  language="javascript">
	$(document).ready(function(){
		$("#bpbdate").datepicker({
			dateFormat : "yy-mm-dd",
			changeMonth : true,
			changeYear : true,
		});
	});
	$(document).ready(function(){
		$("#invdate").datepicker({
			dateFormat : "yy-mm-dd",
			changeMonth : true,
			changeYear : true,
		});
	});
	$(document).ready(function(){
		$("#docdate").datepicker({
			dateFormat : "yy-mm-dd",
			changeMonth : true,
			changeYear : true,
		});
	});
	$(document).ready(function(){
		$("#tglaju").datepicker({
			dateFormat : "yy-mm-dd",
			changeMonth : true,
			changeYear : true,
		});
	});
	function openwindow()
	{
		window.open("popup/popup_supp.php?","mywindow","menubar=1,scrollbars=1,resizable=1,width=600,height=250");
	}
	function openwindow1()
	{
		window.open("popup/popup_barang.php?","mywindow","menubar=1,scrollbars=1,resizable=1,width=600,height=250");
	}
	function pilih(id){
		var y  = document.getElementById("inch_purpid");		
		$.ajax({type: "POST",
			url: "transaksi/manual/load_purpose.php", 
			data: "docid="+id,
			success: function(result){			
			y.innerHTML="<option value='0'>PILIH</option>";
			arr_data = result.split("XX");
			if(id==1){ /*BC 2.3 */
				var option = document.createElement("option");
					option.text = arr_data[1];
					option.value = arr_data[0];
					y.add(option);
				var option = document.createElement("option");
					option.text = arr_data[3];
					option.value = arr_data[2];
					y.add(option);						
			}else if(id==3){ /*BC 2.6.2 */
				var option = document.createElement("option");
					option.text = arr_data[1];
					option.value = arr_data[0];
					y.add(option);
				var option = document.createElement("option");
					option.text = arr_data[3];
					option.value = arr_data[2];
					y.add(option);						
			}else if(id==4){ /*BC 2.7 */
				var option = document.createElement("option");
					option.text = arr_data[1];
					option.value = arr_data[0];
					y.add(option);
				var option = document.createElement("option");
					option.text = arr_data[3];
					option.value = arr_data[2];
					y.add(option);						
			}else if(id==5){ /*BC 4.0 */
				var option = document.createElement("option");
					option.text = arr_data[1];
					option.value = arr_data[0];
					y.add(option);					
			}
		}});
	}
	$(document).ready(function(){
		var inc = {
			source: "transaksi/manual/json_prodinc.php",					
			select: function(event, ui){
				$("#prodcode").val(ui.item.prod_code); 
				$("#prodid").val(ui.item.prod_id); 
				$("#prodsat").val(ui.item.prod_sat); 
			},
			minLength: 1
		};
		$("#prodcode").autocomplete(inc);		
	});	
	function currency_click(currency){
		/*$.ajax({type: "POST",
			url: "transaksi/interface/load_price_rate.php", 
			data: "curr="+currency,
			success: function(result){
			arr_data = result;			
			$("#n_rate").val(arr_data);		
		}});*/
		var fdate    = $("#docdate").val();
		var qty		 = $("#incdqty").val();
		var price	 = $("#incdprice").val();
		//var rate     = $("#n_rate").val();	
		//if(currency=="IDR"){
			var total 	 = eval(qty)*eval(price);
			$("#incdamount").val(total);
			//var totalusd = 0;
			//$("#n_usd").val(totalusd);
		//}else{
			//alert("Rate otomastis dari master rate");
			//var total 	 = 0;
			//$("#incdamount").val(total);
			//var totalusd = eval(qty)*eval(price);
			//$("#n_usd").val(totalusd);
		//}
	 }
	 function save_click(){
		var a = confirm("Apakah anda yakin akan menyimpan data?");
		if (a == true){
			form.action ='?page=Proses-Terima-Barang&Act=SAVE';
			form.method = 'post';
			form.submit();			
			return true;
		}
	}
	function add_det_click(){
		form.action ='?page=Proses-Terima-Barang&Act_Det=ADD_DETM';
		form.method = 'post';
		form.submit();			
		return true;
	}
	function delete_detail_click(id){
		form.action ='?page=Proses-Terima-Barang&Act_Det=DELETE_DETM&id_deth='+id;
		form.method = 'post';
		form.submit();			
		return true;
	}
	function close_click(){
		form.action ='?page=Proses-Terima-Barang&Act=CLOSE'
		form.method = 'post';
		form.submit();		
		return true;
	}
	function popup_item(){
		window.open("popup/popup_item.php?","mywindow","menubar=1,scrollbars=1,resizable=1,width=650,height=250");
	}
	function pono_click(po_no){
		form.action ='?page=Proses-Terima-Barang&Act=SEL_PO&po_no='+po_no
		form.method = 'post';
		form.submit();		
		return true;
	}
	function pop_addwh(){
		window.open("transaksi/manual/popup_addwh.php?","mywindow","menubar=1,scrollbars=1,resizable=1,width=400,height=600");
	}
</script>
</head>
<form action="#" 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">TERIMA BARANG</th>
	</tr>
	<tr>
	  <td width="15%">Ref# No. PO</td>
	  <td width="35%">: 
	  	<input type="hidden" name="inch_id" value="<?php echo $inch_id; ?>" size="50" />
		<input type="hidden" name="inch_currency" value="<?php echo $inch_currency; ?>" size="50" />
	  	<?php if(empty($inch_id)){ ?>
		<select name="po_no" onChange="pono_click(this.value);">
		  <option value="10" selected="selected">PILIH</option> 
			<?php
			  $dataSql = mysql_query("SELECT po_no FROM purchase_order WHERE po_status=20 ORDER BY  po_no ASC");
			  while ($dataRow = mysql_fetch_array($dataSql)) {
				if ($dataRow['po_no']== $po_no) {
					$cek = " selected";
				} else { $cek=""; }
				echo "<option value='$dataRow[po_no]' $cek>$dataRow[po_no]</option>";
			  }
			  $sqlData ="";
			?>
		 </select>
		 <?php }else{ ?>
		 <select name="po_no" onChange="pono_click(this.value);" disabled="disabled">
		  <option value="10" selected="selected">PILIH</option> 
			<?php
			  $dataSql = mysql_query("SELECT po_no FROM purchase_order WHERE po_status=20 ORDER BY  po_no ASC");
			  while ($dataRow = mysql_fetch_array($dataSql)) {
				if ($dataRow['po_no']== $po_no) {
					$cek = " selected";
				} else { $cek=""; }
				echo "<option value='$dataRow[po_no]' $cek>$dataRow[po_no]</option>";
			  }
			  $sqlData ="";
			?>
		 </select>
		 <?php } ?>
	  </td>
	  <td width="15%">&nbsp;</td>
	  <td width="35%">&nbsp;</td>
	</tr>
    <tr>
	  <td>No Masuk</td>
	  <td>: <input type="text" name="inch_bpbno" value="<?php echo $inch_bpbno; ?>" size="20" style="background-color:#CCFFFF" readonly></td>
	  <td>No DO</td>
	  <td>: <input type="text" name="inch_dono" value="<?php echo $inch_dono; ?>" size="20"></td>
	</tr>
	<tr>
		<td>Tanggal Masuk</td>
		<td>: <input type="text" name="inch_bpbdate" value="<?php if(empty($inch_bpbdate)){$inch_bpbdate=$date;} echo $inch_bpbdate; ?>" size="12" id="bpbdate" 
				  readonly="true" style="background-color:#CCFFFF " /> </td>
		<td>Jenis Dokumen</td>
		<td>: <input type="text" name="inch_doctype" value="<?php echo $inch_doctype; ?>" size="20"></td>
	</tr>
	<tr>
		<td>Pemasok</td>
		<td>: <input type="text" name="sup_name" value="<?php echo $sup_name; ?>" size="30" readonly style="background-color:#CCFFFF " /></td>
		<td>Tujuan</td>
		<td>: </td>
	</tr>
	<tr>
		<td>No Invoice</td>
		<td>: <input type="text" name="inch_invno" value="<?=$inch_invno;?>"></td>
		<td>No Dokumen</td>
		<td>: <input type="text" name="inch_docno" size="6" maxlength="6" value="<?=$inch_docno;?>"></td>
	</tr>
	<tr>
		<td>Tanggal Invoice</td>
		<td>: <input type="text" name="inch_invdate" value="<?php if(empty($inch_invdate)){$inch_invdate=$date;} echo $inch_invdate; ?>" size="12" id="invdate" 
				  readonly="true" style="background-color:#CCFFFF " />
		</td>
		<td>Tanggal Dokumen</td>
		<td>: <input type="text" name="inch_docdate" value="<?php if(empty($inch_docdate)){$inch_docdate=$date;} echo $inch_docdate; ?>" size="12" id="docdate" 
				  readonly="true" style="background-color:#CCFFFF " /></td>
	</tr>
	<tr>
		<td>No Aju</td>
		<td>: <input type="text" name="no_aju" size="6" maxlength="6" value="<?=$no_aju;?>"></td>
		<td>Tanggal Aju</td>
		<td>: <input type="text" name="tgl_aju" value="<?php if(empty($tgl_aju)){$tgl_aju=$date;} echo $tgl_aju; ?>" size="12" id="tglaju" 
				  readonly="true" style="background-color:#CCFFFF " /></td>
	</tr>    
	<tr>
		<td colspan="4">&nbsp;</td>
	</tr>    
	<tr>
		<th colspan="4">DETAIL TERIMA BARANG</th>
	</tr>
	<tr>
		<td colspan="4">
			<table width="100%">
				<tr>
					<th align="center" rowspan="2">No.</th>
					<th align="center" rowspan="2">Nama Barang</th>
					<th align="center" rowspan="2">Unit</th>
					<th align="center" colspan="2">Jumlah</th>
                    <!--<th align="center" rowspan="2">Gudang</th>-->
				</tr>
				<tr>
					<th align="center">Dokumen</th>
					<th align="center">Aktual</th>
				</tr>
				<?php
					$no=0; $tqty=0; $tprice=0; $tamount=0; $tweight=0;
					$qd = mysql_query("SELECT a.*, b.prod_code,b.prod_name,b.prod_sat
									   FROM incoming_detail a
									   INNER JOIN product b ON b.id=a.incd_prodid
						   			   WHERE a.incd_hid='$inch_id'");
					while($dt=mysql_fetch_object($qd)){	   
				    $no++;
				?> 
				  <tr>
					<td align="center"><?=$no;?><input type="hidden" name="id_det[<?=$dt->id;?>]" value="<?=$dt->id;?>"></td>
					<td><input type="text" value="<?php echo "$dt->prod_code - $dt->prod_name";?>" size="80" readonly style="text-align:left; background-color:#CCFFFF;"></td>
					<td align="center"><input type="text" value="<?=$dt->prod_sat;?>" size="8" readonly style="text-align:center; background-color:#CCFFFF;"></td>
					<td align="right"><input type="text" name="incd_qty[<?=$dt->id;?>]" value="<?=$dt->incd_qty;?>" size="15" readonly style="text-align:right"></td>
					<td align="right">
						<input type="text" name="incd_qty_temp[<?=$dt->id;?>]" value="<?=$dt->incd_qty;?>" size="15" style="text-align:right">
						<input type="hidden" name="incd_price[<?=$dt->id;?>]" value="<?=$dt->incd_price;?>" size="15" style="text-align:right">
					</td>
                    <!--<td align="right">
						<select name="incd_whid[<?=$dt->id;?>]">
                           <option value="0" selected="selected">PILIH</option> 
                            <?php
                              $dataSql = mysql_query("SELECT id, mw_name FROM master_warehouse WHERE mw_status=10 ORDER BY id ASC");
                              while ($dataRow = mysql_fetch_array($dataSql)){
                                echo "<option value='$dataRow[id]'>$dataRow[mw_name]</option>";
                              }
                              $sqlData ="";
                            ?>
                        </select>&nbsp;
						<a href="javascript: pop_addwh();"><img src="images/pop_add.png" height="15" width="15" title="Tambah" border="0" /></a>	
					</td>-->
				</tr>
				<?php } ?>				
			</table>
		</td>
	</tr>
	<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>
</html> 
