<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_prodinc.php",					
			select: function(event, ui){
				$("#prodid").val(ui.item.prod_id); 
				$("#prodsat").val(ui.item.prod_sat); 
			},
			minLength: 1
		};
		$("#prodcode").autocomplete(temp);		
	});
	function save_click(){
		if((form.pb_pic.value=="") ){
			alert("Silakan isi PIC.");
			form.pb_pic.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-Permintaan-Barang&Act=SAVE';
				form.method = 'post';
				form.submit();			
				return true;
			}
		}
	}
	function add_det_click(){
		if(form.prodid.value==""){
			alert("Silakan isi nama barang.");
			form.prodname.focus();
			return false;
		}else if((form.pbd_qty.value=="") ){
			alert("Silakan isi jumlah barang.");
			form.pbd_qty.focus();
			return false; 
		}else{
			form.action ='?page=Proses-Permintaan-Barang&Act_Det=ADD_DET';
			form.method = 'post';
			form.submit();			
			return true;
		}
	}
	function delete_detail_click(id){
		form.action ='?page=Proses-Permintaan-Barang&Act_Det=DELETE_DET&id_deth='+id;
		form.method = 'post';
		form.submit();			
		return true;
	}
	function close_click(){
		form.action ='?page=Proses-Permintaan-Barang&Act=CLOSE'
		form.method = 'post';
		form.submit();		
		return true;
	}
</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">HEADER PERMINTAAN BARANG</th>
	</tr>
	<tr>
	  <td width="15%">No permintaan</td>
	  <td width="35%">: <input type="hidden" name="pb_id" value="<?php echo $pb_id; ?>" size="50" />
	                       <input type="text" name="pb_no" value="<?php echo $pb_no; ?>" size="45" readonly style="background-color:#CCFFFF " /></td>
	  <td width="15%">&nbsp;</td>
	  <td width="35%">&nbsp;</td>
	</tr>
	<tr>
		<td>Tanggal LP</td>
		<td>: <input type="text" name="pb_date" value="<?php if(empty($pb_date)){$pb_date=date('Y-m-d');} echo $pb_date; ?>" size="10" id="spbdate" 
				  readonly="true" style="background-color:#CCFFFF " /> </td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
	</tr>
	<!--<tr>
		<td>Project</td>
		<td>: <input type="text" name="pb_project" value="<?php echo $pb_project; ?>" 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="pb_deptid">
							<?php
							  $dataSql = mysql_query("SELECT id,dept_name FROM departement ORDER BY id ASC");
							  while ($dataRow = mysql_fetch_array($dataSql)) {
								if ($dataRow['id']== $pb_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="pb_pic" value="<?php echo $pb_pic; ?>" size="45">
		</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
	</tr>
	<tr>
		<td>Keterangan</td>
		<td>: <textarea name="pb_desc" cols="35"><?php echo $pb_desc; ?></textarea>
		</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
	</tr>
	<tr>
		<td colspan="4">&nbsp;</td>
	</tr>
	<tr>
		<th colspan="4">DETAIL BARANG</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;">Jumlah</td>
					<td style="width:170px;">Action</td>
				</tr>
				<tr>
					<td><input type="hidden" name="prodid" id="prodid" style="width:300px;">
					    <input type="text" name="prodcode" id="prodcode" style="width:250px; background-color:#CCFFFF">
						<!--<a href="javascript: openwindow1('1');"><img src="images/popup.png" height="15" width="15" title="Tambah" border="0" /></a>-->
					</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="pbd_qty" style="width:100px; text-align:right"></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($pb_id)){  ?>			
			<table width="100%">
				<tr>
					<th>No.</th>
					<th>Nama Barang</th>
					<th>Unit</th>
					<th>Jumlah</th>
					<th>Action</th>
				</tr>
				<?php
					$no=0; $tqty=0;
					$qd = mysql_query("SELECT a.*,b.prod_code,b.prod_name,b.prod_sat
									   FROM permintaan_barang_temp a
									   INNER JOIN product b ON b.id=a.pbd_prodid
									   WHERE a.pbd_inputby='$user_id' ORDER BY a.id ASC");
					while($dt=mysql_fetch_object($qd)){	   
				    $no++;
					$tqty     = $tqty + $dt->pbd_qty; 
				?> 
				  <tr>
					<td align="center"><?=$no;?></td>
					<td><?php echo "$dt->prod_code - $dt->prod_name";?></td>
					<td align="center"><?=$dt->prod_sat;?></td>
					<td align="right"><?=number_format($dt->pbd_qty,2,',','.');?></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('<?=$dt->id;?>');"/>
					</td>
				</tr>
				<?php } ?>
				<tr>
					<td colspan="3" 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>
				</tr>
			</table>
			<?php }else{ ?>
			<table width="100%">
				<tr>
					<th>No.</th>
					<th>Nama Barang</th>
					<th>Unit</th>
					<th>Jumlah</th>
					<th>Action</th>
				</tr>
				<?php
				   $no=0; $tqty=0;
					$qd = mysql_query("SELECT a.*,b.prod_code,b.prod_name,b.prod_sat
									   FROM permintaan_barang_detail a
									   INNER JOIN product b ON b.id=a.pbd_prodid
									   WHERE a.pbd_hid='$pb_id' ORDER BY a.id ASC");
					while($dt=mysql_fetch_object($qd)){	   
				    $no++;				   				
					$tqty     = $tqty + $dt->pbd_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="70" readonly></td>
					<td><input type="text" value="<?=$dt->prod_sat;?>" size="10" readonly></td>
					<td align="left"><input type="text" name="scrdqty[<?=$dt->id;?>]" value="<?=$dt->pbd_qty;?>" style="text-align:right "></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('<?=$dt->id;?>');"/>
					</td>
				</tr>
				<?php } ?>
				<tr>
					<td colspan="3" 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>
				</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> 
