<html>
<head>
<script language="javascript">
	$(document).ready(function(){ 
		$("#spbdate").datepicker({
			dateFormat : "yy-mm-dd",
			changeMonth : true,
			changeYear : true,
		});
	});
	$(document).ready(function(){
		$("#reqdate").datepicker({
			dateFormat : "yy-mm-dd",
			changeMonth : true,
			changeYear : true,
		});
	});
	function openwindow1(id)
	{
		window.open("popup/popup_barang.php?loc="+id,"mywindow","menubar=1,scrollbars=1,resizable=1,width=650,height=300");
	}
	$(document).ready(function(){
		var temp = {
			source: "transaksi/manual/json_incprod.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);
				$("#doctype").val(ui.item.prod_doctype);
				$("#docno").val(ui.item.prod_docno);
				$("#docdate").val(ui.item.prod_docdate);
			},
			minLength: 1
		};
		$("#prodcode").autocomplete(temp);		
	});
	function save_click(){
		if(form.trf_reqno.value==""){
			alert("Silakan isi nomor permintaan.");
			form.trf_reqno.focus();
			return false;
		}else if((form.trf_pic.value=="") ){
			alert("Silakan isi PIC.");
			form.trf_pic.focus();
			return false;
		}else if((form.trf_desc.value=="") ){
			alert("Silakan isi keterangan.");
			form.trf_desc.focus();
			return false;
		}else if((form.tqty.value==0) ){
			alert("Silakan isi detail barang.");
			form.tqty.focus();
			return false;
		}else{
			var a = confirm("Apakah anda yakin akan menyimpan data?");
			if (a == true){
				form.action ='?page=Proses-Inc-Prod&Act=SAVE';
				form.method = 'post';
				form.submit();			
				return true;
			}
		}
	}
	function add_det_click(){
		var qtystock = $("#prodstock").val();
		var qtytrf	 = $("#trfdqty").val();
		var qtys     = eval(qtystock);
		var qtyt     = eval(qtytrf);
		if(form.prodid.value==""){
			alert("Silakan isi nama barang.");
			form.prodname.focus();
			return false;
		}else if((form.prodstock.value=="") ){
			alert("Stock tidak boleh kosong.");
			form.prodstock.focus();
			return false;
		}else if((form.trfdqty.value=="") ){
			alert("Silakan isi jumlah barang.");
			form.trfdqty.focus();
			return false; 
		}else if(qtys < qtyt ){
			alert("Jumlah stock lebih kecil dari jumlah yang dikeluarkan.");
			form.trfdqty.focus();
			return false; 
		}else{
			form.action ='?page=Proses-Inc-Prod&Act_Det=ADD_DET';
			form.method = 'post';
			form.submit();			
			return true;
		}
	}
	function delete_detail_click(hid,id){
		form.action ='?page=Proses-Inc-Prod&Act_Det=DELETE_DET&trf_id='+hid+'&id_deth='+id;
		form.method = 'post';
		form.submit();			
		return true;
	}
	function close_click(){
		form.action ='?page=Proses-Inc-Prod&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");
	}
</script>
</head>
<form action="?page=Proses-Inc-Prod" 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">HEADER TRANSFER BAHAN BAKU DAN PENOLONG</th>
	</tr>
	<tr>
	  <td width="15%">No SPB</td>
	  <td width="35%">: <input type="hidden" name="trf_id" value="<?php echo $trf_id; ?>" size="50" />
	                       <input type="text" name="trf_spbno" value="<?php echo $trf_spbno; ?>" size="45" readonly style="background-color:#CCFFFF " /></td>
	  <td width="15%">&nbsp;</td>
	  <td width="35%">&nbsp;</td>
	</tr>
	<tr>
		<td>Tanggal SPB</td>
		<td>: <input type="text" name="trf_spbdate" value="<?php if(empty($trf_spbdate)){$trf_spbdate=date('Y-m-d');} echo $trf_spbdate; ?>" size="10" id="spbdate" 
				  readonly="true" style="background-color:#CCFFFF " /> </td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
	</tr>
	<tr>
		<td>No. Permintaan</td>
		<td>: <input type="text" name="trf_reqno" value="<?php echo $trf_reqno; ?>" size="45"></td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
	</tr>
	<tr>
		<td>Tanggal Permintaan</td>
		<td>: <input type="text" name="trf_reqdate" value="<?php if(empty($trf_reqdate)){$trf_reqdate=date('Y-m-d');} echo $trf_reqdate; ?>" size="10" id="reqdate" 
				  readonly="true" style="background-color:#CCFFFF " /> 
		</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
	</tr>
	<tr>
		<td>Departemen</td>
		<td>: <select name="trf_deptid">
							<?php
							  $dataSql = mysql_query("SELECT id,dept_name FROM departement ORDER BY id ASC");
							  while ($dataRow = mysql_fetch_array($dataSql)) {
								if ($dataRow['id']== $trf_deptid) {
									$cek = " selected";
								} else { $cek=""; }
								echo "<option value='$dataRow[id]' $cek>$dataRow[dept_name]</option>";
							  }
							  $sqlData =""; 
							?>
						 </select>
		</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
	</tr>
	<tr>
		<td>PIC</td>
		<td>: <input type="text" name="trf_pic" value="<?php echo $trf_pic; ?>" size="45">
		</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
	</tr>
	<tr>
		<td>Keterangan</td>
		<td>: <textarea name="trf_desc" cols="35"><?php echo $trf_desc; ?></textarea>
		</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
	</tr>
	<tr>
		<td colspan="4">&nbsp;</td>
	</tr>
	<tr>
		<th colspan="4">DETAIL TRANSFER BAHAN BAKU DAN PENOLONG</th>
	</tr>
	<tr>
		<td colspan="4">
			<table width="100%">
				<tr>
					<td style="width:250px;">Kode/Nama Barang</td>
					<td style="width:50px;">Satuan</td>
					<td style="width:100px;">Stok</td>
					<td style="width:100px;">Jumlah</td>
					<td style="width:150px;">Keterangan</td>
					<td style="width:170px;">Action</td>
				</tr>
				<tr>
					<td><input type="hidden" name="prodid" id="prodid" style="width:300px;">
                    	<input type="hidden" name="prodprice" id="prodprice" style="width:300px;">
						<input type="hidden" name="doctype" id="doctype" style="width:300px;">
						<input type="hidden" name="docno" id="docno" style="width:300px;">
						<input type="hidden" name="docdate" id="docdate" style="width:300px;">
					    <input type="text" name="prodcode" id="prodcode" style="width:250px; 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></td>
					<td><input type="text" name="prodstock" id="prodstock" style="width:100px; text-align:right; background-color:#CCFFFF" readonly></td>
					<td><input type="text" name="trfdqty" id="trfdqty" style="width:100px; text-align:right"></td>
					<td><input type="text" name="trfddesc" style="width:100px; text-align:left"></td>
					<td><input type="button" name="Add_Detail" value="Tambah" style="cursor:pointer" onClick="add_det_click();"></td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td colspan="4">&nbsp;</td>
	</tr>
	<tr>
		<td colspan="4">
		  <?php if(empty($trf_id)){  ?>			
			<table width="100%">
				<tr>
					<th style="width:20px;" rowspan="2">No.</th>
					<th style="width:300px;" rowspan="2">Nama Barang</th>
					<th style="width:150px;" rowspan="2">Unit</th>
					<th style="width:300px;" colspan="3">Dokumen</th>
					<th style="width:150px;" rowspan="2">Jumlah</th>
                    <th style="width:150px;" rowspan="2">Harga</th>
					<th style="width:150px;" rowspan="2">Ket</th>
					<th style="width:170px;" rowspan="2">Action</th>
				</tr>
				<tr>
					<th>Jenis</th>
					<th>Nomor</th>
					<th>Tanggal</th>
				</tr>
				<?php
					$no=0; $tqty=0;
					$qd = mysql_query("SELECT a.*,b.prod_code,b.prod_name,b.prod_sat
									   FROM transfer_temp a
									   INNER JOIN product b ON b.id=a.trfd_prodid
									   WHERE a.trfd_inputby='$user_id' AND a.trfd_category=1");
					while($dt=mysql_fetch_object($qd)){	   
				    $no++;
					$tqty     = $tqty + $dt->trfd_qty; 
				?> 
				  <tr>
					<td style="width:20px;" align="center"><?=$no;?></td>
					<td style="width:300px;"><?php echo "$dt->prod_code - $dt->prod_name";?></td>
					<td style="width:150px;" align="center"><?=$dt->prod_sat;?></td>
					<td style="width:150px;" align="center"><?=$dt->trfd_doctype;?></td>
					<td style="width:150px;" align="center"><?=$dt->trfd_docno;?></td>
					<td style="width:150px;" align="center"><?=$dt->trfd_docdate;?></td>
					<td style="width:150px;" align="right"><?=number_format($dt->trfd_qty,2,'.',',');?></td>
                    <td style="width:150px;" align="right"><?=number_format($dt->trfd_price,2,'.',',');?></td>
					<td style="width:150px;" align="left"><?=$dt->trfd_desc;?></td>
					<td style="width:170px;" align="center">
						<img src="images/btn_delete.png" width="20" height="20"  border="0"  title="Hapus" style="cursor:pointer" 
						onClick="delete_detail_click('<?=$trf_id;?>','<?=$dt->id;?>');"/>
					</td>
				</tr>
				<?php } ?>
				<tr>
					<td colspan="6" align="right">Total</td>
					<td align="right"><?=number_format($tqty,2,'.',',');?><input type="hidden" name="tqty" value="<?=$tqty;?>"></td>
					<td>&nbsp;</td>
					<td>&nbsp;</td>
                    <td>&nbsp;</td>
				</tr>
			</table>
			<?php }else{ ?>
			<table width="100%">
				<tr>
					<th rowspan="2">No.</th>
					<th rowspan="2">Nama Barang</th>
					<th rowspan="2">Unit</th>
					<th colspan="3">Dokumen</th>
					<th rowspan="2">Jumlah</th>
                    <th rowspan="2">Harga</th>
					<th rowspan="2">Keterangan</th>
					<th rowspan="2">Action</th>
				</tr>
				<tr>
					<th>Jenis</th>
					<th>Nomor</th>
					<th>Tanggal</th>
				</tr>
				<?php
					$no=0; $tqty=0;
					$qd = mysql_query("SELECT a.*,b.prod_code,b.prod_name,b.prod_sat
									   FROM transfer_detailexbc a
									   INNER JOIN product b ON b.id=a.trfd_prodid
									   WHERE a.trfd_hid='$trf_id'");
					while($dt=mysql_fetch_object($qd)){	   
				    $no++;
					$tqty     = $tqty + $dt->trfd_qty; 
				?> 
				  <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="45" readonly></td>
					<td>
						<input type="text" value="<?=$dt->prod_sat;?>" size="6" readonly>
						<input type="hidden" name="trfd_prodid[<?=$dt->id;?>]" value="<?=$dt->trfd_prodid;?>" style="text-align:right ">
					</td>
					<td><input type="text" value="<?=$dt->trfd_doctype;?>" size="6" readonly></td>
					<td><input type="text" value="<?=$dt->trfd_docno;?>" size="6" readonly></td>
					<td><input type="text" value="<?=$dt->trfd_docdate;?>" size="8" readonly></td>
					<td align="left"><input type="text" size="12" name="trfd_qty[<?=$dt->id;?>]" value="<?=$dt->trfd_qty;?>" style="text-align:right "></td>
                    <td align="left"><input type="text" size="12" name="trfd_price_satuan[<?=$dt->id;?>]" value="<?=$dt->trfd_price_satuan;?>" style="text-align:right "></td>
					<td align="left"><input type="text" name="trfd_desc[<?=$dt->id;?>]" value="<?=$dt->trfd_desc;?>" size="25"></td>
					<td align="center">
						<img src="images/btn_delete.png" width="20" height="20"  border="0"  title="Hapus" style="cursor:pointer" 
						onClick="delete_detail_click('<?=$trf_id;?>','<?=$dt->id;?>');"/>
					</td>
				</tr>
				<?php } ?>
				<tr>
					<td colspan="6" align="right">Total</td>
					<td align="right"><?=number_format($tqty,2,'.',',');?>&nbsp;&nbsp;<input type="hidden" name="tqty" value="<?=$tqty;?>"></td>
					<td>&nbsp;</td>
                    <td>&nbsp;</td>
					<td>&nbsp;</td>
				</tr>		
			</table>
			<?php } ?>
		</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> 
