<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 save_click(){
		if((form.wonb_no.value=="") ){
			alert("Silakan isi nomor wo.");
			form.wonb_no.focus();
			return false;
		}else if((form.wonb_pic.value=="") ){
			alert("Silakan isi PIC.");
			form.wonb_pic.focus();
			return false;
		}else if((form.wonb_desc.value=="") ){
			alert("Silakan isi keterangan.");
			form.wonb_desc.focus();
			return false;
		}else if((form.wonb_deptid.value=="") ){
			alert("Silakan pilih departement.");
			form.wonb_deptid.focus();
			return false;
		}else{
			var a = confirm("Apakah anda yakin akan menyimpan data?");
			if (a == true){
				form.action ='?page=Proses-Work-Order-Non-Bom&Act=SAVE';
				form.method = 'post';
				form.submit();			
				return true;
			}
		}
	}
	function close_click(){
		form.action ='?page=Proses-Work-Order-Non-Bom&Act=CLOSE'
		form.method = 'post';
		form.submit();		
		return true;
	}
	function woqty_click(wo_prodid){
		form.action ='?page=Proses-Work-OrderM&Act=GET_BOM&wo_prodid='+wo_prodid;
		form.method = 'post';
		form.submit();		
		return true;
	}
	function item_click(){
		$(document).ready(function(){
			var temp = {
				source: "transaksi/manual/json_wo_manual.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); 
					$("#priceunit").val(ui.item.priceunit);
				},
				minLength: 1
			};
			$("#prodcode").autocomplete(temp);		
		});
	}
	function add_det_click(){
		var qtystock = $("#prodstock").val();
		var qtytrf	 = $("#wonbdqty").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.wonbdqty.value=="") ){
			alert("Silakan isi jumlah barang.");
			form.wonbdqty.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-Work-Order-Non-Bom&Act_Det=ADD_DET';
			form.method = 'post';
			form.submit();			
			return true;
		}
	}
	function delete_detail_click(wonbid,id){
		form.action ='?page=Proses-Work-Order-Non-Bom&Act_Det=DELETE_DET&wonb_id='+wonbid+'&id_deth='+id;
		form.method = 'post';
		form.submit();			
		return true;
	}
	function itemh_click(){
		$(document).ready(function(){
			var temp = {
				source: "transaksi/manual/json_wo_header.php",					
				select: function(event, ui){
					$("#prodcodeh").val(ui.item.prod_code); 
					$("#prodidh").val(ui.item.prod_id); 
					$("#prodsath").val(ui.item.prod_sat);
				},
				minLength: 1
			};
			$("#prodcodeh").autocomplete(temp);		
		});
	}
</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">WORK ORDER NON BOM</th>
	</tr>
	<tr>
	  <td width="15%">No Work Order</td>
	  <td width="35%">: <input type="hidden" name="wonb_id" value="<?php echo $wonb_id; ?>" size="50" />
      					<input type="hidden" name="bom_id" value="<?php echo $bom_id; ?>" size="50" />
	                    <?php if(!empty($wonb_id)){?>
						<input type="text" name="wonb_no" value="<?php echo $wonb_no; ?>" size="20" style="background-color:#CCFFFF " />
						<?php }else{ ?>
                        <input type="text" name="wonb_no" value="<?php echo $wonb_no; ?>" size="20" style="background-color:#CCFFFF " />
                        <?php } ?>
	  </td>
	  <td width="15%">&nbsp;</td>
	  <td width="35%">&nbsp;</td>
	</tr>
	<tr>
		<td>Tanggal WO</td>
		<td>: <input type="text" name="wonb_date" value="<?php if(empty($wonb_date)){$wonb_date=date('Y-m-d');} echo $wonb_date; ?>" size="10" id="spbdate" 
				  readonly="true" style="background-color:#CCFFFF " /> </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="wonb_deptid">
				<?php
                  $dataSql = mysql_query("SELECT id,dept_name FROM departement ORDER BY id ASC");
                  while ($dataRow = mysql_fetch_array($dataSql)) {
                    if ($dataRow['id']== $wonb_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="wonb_pic" value="<?php echo $wonb_pic; ?>" size="45">
		</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
	</tr>
     <!--<tr>
		<td>Plan</td>
		<td>: <select name="wo_whid" id="wo_whid">
        		<option value="0" selected>PILIH</option>
				<?php
                  $dataSql = mysql_query("SELECT id,wh_name FROM warehouse WHERE wh_status=10 ORDER BY id ASC");
                  while ($dataRow = mysql_fetch_array($dataSql)) {
                    if ($dataRow['id']== $wo_whid) {
                        $cek = " selected";
                    } else { $cek=""; }
                    echo "<option value='$dataRow[id]' $cek>$dataRow[wh_name]</option>";
                  }
                  $sqlData =""; 
                ?>
             </select>            
		</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
	</tr>-->
	<tr>
		<td>Keterangan</td>
		<td>: <textarea name="wonb_desc" cols="35"><?php echo $wonb_desc; ?></textarea>
		</td>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
	</tr>
	<tr>
		<td colspan="4">&nbsp;</td>
	</tr>
	<tr>
		<th colspan="4">DETAIL BAHAN BAKU & PENOLONG</th>
	</tr>	
	<tr>
		<td colspan="4">
			<table width="100%">
				<tr>
					<!--<td style="width:150px;">Stock Barang</td>-->
                    <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:170px;">Action</td>
				</tr>
				<tr>
					<!--<td>
                    	<select name="skat" id="skat">
                            <option value="0" selected="selected">PILIH</option>
                            <option value="1">Stock Bahan Baku</option>
                            <option value="2">Stock Barang Jadi</option>                            
                         </select>
					</td>-->
                    <td><input type="hidden" name="prodid" id="prodid" style="width:300px;">
					    <input type="text" name="prodcode" id="prodcode" style="width:250px; background-color:#CCFFFF" onKeyPress="item_click();">
						<input type="hidden" name="priceunit" id="priceunit">
						<!--<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="wonbdqty" id="wonbdqty" 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($wonb_id)){  ?>	
			<table width="100%">
				<tr>
					<th style="width:20px;">No.</th>
					<th style="width:300px;">Nama Barang</th>					
                    <th style="width:150px;">Jumlah</th>
					<th style="width:150px;">Unit</th>
					<th style="width:150px;">Action</th>
				</tr>
				<?php
					$no=0; $tqty=0; $ttprice=0;
					$qd = mysql_query("SELECT a.*,b.prod_code,b.prod_name,b.prod_sat
									   FROM workorder_nonbom_temp a
									   INNER JOIN product b ON b.id=a.wonbd_prodid
									   WHERE a.wonbd_inputby='$user_id' AND a.wonbd_status=10");
					while($dd=mysql_fetch_array($qd)){	 
						$no++;
						/* 
						$tprice  = $dd['wod_qty']*$dd['wod_price_satuan'];
						$ttprice = $ttprice + $tprice; */
				?> 
				  <tr>
					<td style="width:20px;" align="center"><?=$no;?></td>
					<td style="width:300px;"><?php echo "$dd[prod_code] - $dd[prod_name]";?></td>					
                    <td style="width:150px;" align="right"><?=number_format($dd['wonbd_qty'],2,'.',',');?></td>
					<td style="width:150px;" align="center"><?=$dd['prod_sat'];?> </td>	
					<td style="width:150px;" align="center">
				<img src="images/btn_delete.png" width="20" height="20"  border="0"  title="Hapus" style="cursor:pointer" onClick="delete_detail_click('<?=$wonb_id;?>','<?=$dd['id'];?>');"/>
					</td>					
				</tr>
				<?php } ?>
			</table>	
			<?php }else{ ?>	
			<table width="100%">
				<tr>
					<th style="width:20px;">No.</th>
					<th style="width:300px;">Nama Barang</th>					
                    <th style="width:150px;">Jumlah</th>
					<th style="width:150px;">Unit</th>
					<th style="width:150px;">Action</th>
				</tr>
				<?php
					$no=0; $tqty=0; $ttprice=0;
					$qd = mysql_query("SELECT a.*,b.prod_code,b.prod_name,b.prod_sat
									   FROM workorder_nonbom_detail a
									   INNER JOIN product b ON b.id=a.wonbd_prodid
									   WHERE a.wonbd_hid='$wonb_id'");
					while($dd=mysql_fetch_array($qd)){	 
						$no++;
				?> 
				  <tr>
					<td style="width:20px;" align="center"><?=$no;?></td>
					<td style="width:300px;"><?php echo "$dd[prod_code] - $dd[prod_name]";?></td>					
                    <td style="width:150px;" align="right">
						<input type="hidden" name="id_det[<?=$dd['id'];?>]" value="<?=$dd['id'];?>">
						<input type="text" name="wonbd_qty[<?=$dd['id'];?>]" value="<?=$dd['wonbd_qty'];?>" style="text-align:right">
					</td>
					<td style="width:150px;" align="center"><?=$dd['prod_sat'];?> </td>	
					<td style="width:150px;" align="center">
				<img src="images/btn_delete.png" width="20" height="20"  border="0"  title="Hapus" style="cursor:pointer" onClick="delete_detail_click('<?=$wonb_id;?>','<?=$dd['id'];?>');"/>
					</td>					
				</tr>
				<?php } ?>
			</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> 