<div style="height:40px;">
<input type="hidden" id="id_konv_part" />
<table>
	<tr><td>PART-NO HS</td><td>:</td><td><input id="part_no" readonly="readonly" value="<?php echo $part_no;  ?>"/></td></tr>
	<tr><td>PART-NO2 HS</td><td>:</td><td><input id="part_no2" readonly="readonly"  value="<?php echo $part_no2;  ?>"/></td></tr>
	<tr><td>PART ARTICLE_CODE</td><td>:</td><td><input id="article_code" onkeyup="javascript:return cUpper(this);" /></td></tr>
</table>
<div>
<!-- <button id="konv_part_new">NEW</button> -->
<button id="konv_part_save">SAVE</button><button id="konv_part_del">DELETE</button></div>
<table id="tbl_data_part_hs_article"></table> <div id="ptbl_data_part_hs_article"></div>   	
</div>
<script type="text/javascript">
    function cUpper(cObj)
	{
		cObj.value=cObj.value.toUpperCase();
	}	
    $(document).ready(function(){
		jQuery("#tbl_data_part_hs_article").jqGrid({
			url:'<?php echo base_url().'settings/ct_barangbahanbaku/tbl_data_part_hs_article'; ?>',
			mtype : "post",
			postData:{'q':'1'},
			datatype: "json",
			colNames:['ID','PART NO', 'PART NO2','PART ARTICLE CODE'],
			colModel:[
				{name:'id_konv_part',index:'id_konv_part', width:60, hidden:true},
				{name:'part_no',index:'part_no', width:120},
				{name:'part_no2',index:'part_no2', width:160},
				{name:'article_code',index:'article_code', width:190}
			
				],
			rowNum:20,
			rowList:[20,50100],
			pager: '#ptbl_data_part_hs_article',
			sortname: 'id_konv_part',
			viewrecords: true,
			sortorder: "desc",
			width: '',
			height:200,
			jsonReader: { repeatitems : false },
			caption:"DATA PART & ARTICLE CODE",
			rownumbers: true,
			shrinkToFit: false,
			afterInsertRow: function(){
				
				
			},			
			gridComplete: function(){
				var rowIDs = jQuery("#tbl_data_part_hs_article").getDataIDs(); 
				var rowData = $("#tbl_data_part_hs_article").getRowData();
			
				
			},
			onSelectRow: function(ids) {
				var ret = jQuery("#tbl_data_part_hs_article").jqGrid('getRowData',ids);
				$("#id_konv_part").val(ret.id_konv_part);
				$("#part_no").val(ret.part_no);
				$("#part_no2").val(ret.part_no2);
				$("#article_code").val(ret.article_code);
			}	
		}); 
		
		jQuery("#tbl_data_part_hs_article").jqGrid('navGrid','#ptbl_data_part_hs_article',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#tbl_data_part_hs_article").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : false, defaultSearch: 'cn', ignoreCase: true});
		
		$("#konv_part_new").click(function(){
			$("#id_konv_part").val("");
			$("#part_no").val("");
			$("#part_no2").val("");
			$("#article_code").val("");
			jQuery("#tbl_data_part_hs_article").jqGrid('resetSelection');
			$("#part_no").focus();
		});
		
		$("#konv_part_save").click(function(){
			if($("#id_konv_part").val() != ''){
				var upd = " UPDATE ";
			} else {
				var upd = " PENAMBAHAN ";
			}
			var form_data  = {
				id_konv_part:$("#id_konv_part").val(),
				part_no:$("#part_no").val(),
				part_no2:$("#part_no2").val(),
				article_code:$("#article_code").val()
			}
			$("#dlgkonv_part").dialog( "destroy" );
			$(".dlgkonv_partcl").remove();
			$(".dlgkonv_partcl").html('');
			$("body").append('<div id="dlgkonv_part" title="Warning" class="dlgkonv_partcl"><p>Apakah anda akan melakukan' +  upd + ' DATA KONVERSI PARTNO VS ARTICLECODE?</p><br /></div>');
			$("#dlgkonv_part").dialog({
				height: 200,
				width: 350,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url :'<?php echo base_url().'settings/ct_barangbahanbaku/update_konv_part'; ?>',
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlgkonv_part").dialog("close");
								$('#dlgkonv_part').dialog("destroy"); 
								$(".dlgkonv_partcl").remove(); 
								$('#tbl_data_part_hs_article').trigger('reloadGrid');
							} else { 
								alert(msg.sts+msg.desc);
								$("#dlgkonv_part").dialog("close");
								$('#dlgkonv_part').dialog("destroy"); 
								$(".dlgkonv_partcl").remove(); 		

							}
						}
					});
				},
				"CANCEL": function() {
						$( "#dlgkonv_part" ).dialog( "close" );

					}
				},
				close : function(){
					$('#dlgkonv_part').dialog("destroy"); 
					$(".dlgkonv_partcl").remove(); 
					$("body").append('<div id="dlgkonv_part" title="Warning" class="dlgkonv_partcl"><p>APAKAH ANDA AKANMELAKUKAN UPDATE?</p></div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});
			
			
		});
		
		$("#konv_part_del").click(function(){
			
			if($("#id_konv_part").val() != ''){
				var upd = " DELETE ";
			} else {
				alert("ID TIDAK BOLEH KOSONG, PILIH DAHULU DATANYA");
				return false;
			}
			var form_data  = {
				id_konv_part:$("#id_konv_part").val()
			}
			$("#dlgkonv_part_del").dialog( "destroy" );
			$(".dlgkonv_part_delcl").remove();
			$(".dlgkonv_part_delcl").html('');
			$("body").append('<div id="dlgkonv_part_del" title="Warning" class="dlgkonv_part_delcl"><p>Apakah anda akan melakukan' +  upd + ' DATA KONVERSI PART ARTICLE?</p><br /></div>');
			$("#dlgkonv_part_del").dialog({
				height: 200,
				width: 350,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url :'<?php echo base_url().'settings/ct_barangbahanbaku/konv_part_del'; ?>',
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlgkonv_part_del").dialog("close");
								$('#dlgkonv_part_del').dialog("destroy"); 
								$(".dlgkonv_part_delcl").remove(); 
								$('#tbl_data_part_hs_article').trigger('reloadGrid');
							} else { 
								alert(msg.sts+msg.desc);
								$("#dlgkonv_part_del").dialog("close");
								$('#dlgkonv_part_del').dialog("destroy"); 
								$(".dlgkonv_part_delcl").remove(); 		

							}
						}
					});
				},
				"CANCEL": function() {
						$( "#dlgkonv_part_del" ).dialog( "close" );

					}
				},
				close : function(){
					$('#dlgkonv_part_del').dialog("destroy"); 
					$(".dlgkonv_part_delcl").remove(); 
					$("body").append('<div id="dlgkonv_part_del" title="Warning" class="dlgkonv_part_delcl"><p>Apakah anda akan Memproses?</p></div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});
		
		});

	});
		  	
</script>



	
	