<div id="container_pasi_materialcode_set" style="height:100%; margin:0px; padding:0px;overflow:'hidden'; border: 0px solid #cd0a0a">
	<div class="pane-header ui-state-active" id="pasi_materialcode_set_bar" >    

		<button id="btngetitemrm">Get Material Code List</button>
		<button id="btninsertrm">Insert Data</button> 
		<button id="btnupdaterm">Update Data</button>
		<!-- <button id="btndeleterm">Delete Data</button> -->
	</div>
	<table id="tbl_materialcode"></table> <div id="ptbl_materialcode"></div>
</div>
<script type="text/javascript">
    
    $(document).ready(function(){
		$(window).bind('resize', function() {  
			setTimeout(function(){
				setGridHight($("#tbl_materialcode"),$("#container_pasi_materialcode_set"),$("#pasi_materialcode_set_bar")); 
			},10); 
		});


		$("#btngetitemrm").button().click(function(){
			$("#frmitemlistdlg").load('<?php echo base_url().'pasi_settings/ct_materialcode/view_materialcode_itemlist'; ?>',  {parmeter:'parameter'}, function() {
				$("#frmitemlistdlg").dialog({
					modal:true,
					width : 694,
					height : 499,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  	
						}
                    },
					close : function(){
						$('#frmitemlistdlg').dialog("destroy"); 
					    $(".frmitemlistdlg_cl").remove(); 
					    $("body").append('<div id="frmitemlistdlg" title="ITEM LIST" class="frmitemlistdlg_cl"></div>'); 	
					},
					open: function(){
						$("body").unblock();	
					}
				});
			});
		});
		$("#btnupdaterm").button().click(function(){
			var id = jQuery("#tbl_materialcode").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tbl_materialcode").jqGrid('getRowData',id);	
			} else {
				alert("Please Select Row");
				return false;
			};	
			
			var form_data={
				idx:ret.id_master_material,
				kd_brg:ret.kdbrg,
				item_no:ret.item_no,
				nama_barang:ret.nama_barang,
				satuan:ret.satuan,
				cons:ret.cons
			};			
			
			$("#frmbarangupdate_dlg").load('<?php echo base_url().'pasi_settings/ct_materialcode/view_materialcode_update'; ?>',  form_data, function() {
				$("#frmbarangupdate_dlg").dialog({
					modal:true,
					width : 350,
					height : 220,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  	
						}
                    },
					close : function(){
						$('#frmbarangupdate_dlg').dialog("destroy"); 
					    $(".frmbarangupdate_dlg_cl").remove(); 
					    $("body").append('<div id="frmbarangupdate_dlg" title="Nama Barang" class="frmbarangupdate_dlg_cl"></div>'); 
						$('#tbl_materialcode').trigger('reloadGrid');
					},
					open: function(){
						$("body").unblock();
					}
				});
			});
		});
		$("#btninsertrm").button().click(function(){
						
			$("#frmbaranginsert_dlg").load('<?php echo base_url().'pasi_settings/ct_materialcode/view_materialcode_insert'; ?>',  function() {
				$("#frmbaranginsert_dlg").dialog({
					modal:true,
					width : 350,
					height : 200,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  	
						}
                    },
					close : function(){
						$('#frmbaranginsert_dlg').dialog("destroy"); 
					    $(".frmbaranginsert_dlg_cl").remove(); 
					    $("body").append('<div id="frmbaranginsert_dlg" title="Nama Barang" class="frmbaranginsert_dlg_cl"></div>'); 
						$('#tbl_materialcode').trigger('reloadGrid');
	
					},
					open: function(){
						$("body").unblock();
						
					}
				});
			});
		});
		$("#btndeleterm").button().click(function(){
			var id = jQuery("#tbl_materialcode").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tbl_materialcode").jqGrid('getRowData',id);	
			} else {
				alert("Please Select Row");
				return false;
			};
			
			var form_data={
				idx:ret.id_master_material
			};
			
			$("#dlgmaterialdelete").dialog( "destroy" );
			$(".dlgmaterialdelete_cl").remove();
			$("body").append('<div id="dlgmaterialdelete" title="Warning" class="dlgmaterialdelete_cl"><p>Apakah anda akan menghapus kode barang ini?</p><br /></div>');
			
			
			
			$("#dlgmaterialdelete").dialog({
				height: 160,
				width: 250,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : "<?php echo base_url().'pasi_settings/ct_materialcode/deletekodebarang'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlgmaterialdelete").dialog("close");
								$('#dlgmaterialdelete').dialog("destroy"); 
								$(".dlgmaterialdelete_cl").remove(); 
								$('#tbl_materialcode').trigger('reloadGrid');

							} else { 
								alert(msg.sts+msg.desc); 
								$("#dlgmaterialdelete").dialog("close");
								$('#dlgmaterialdelete').dialog("destroy"); 
								$(".dlgmaterialdelete_cl").remove(); 

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

					}
				},
				close : function(){
					$('#dlgmaterialdelete').dialog("destroy"); 
					$(".dlgmaterialdelete_cl").remove(); 
					$("body").append('<div id="dlgmaterialdelete" title="Warning" class="dlgmaterialdelete_cl"><p>Apakah anda akan menghapus kode barang ini?</p><br /></div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});
		});
		
		jQuery("#tbl_materialcode").jqGrid({
			url:'<?php echo base_url().'pasi_settings/ct_materialcode/loadData'; ?>',
			mtype : "post",
			postData:{'q':'1'},
			datatype: "json",
			
			colNames:['id', 'Item Code','Item Number','Material Name','Unit','Create Date','Create By','Update Date','Update By','Cons'],
			colModel:[
				{name:'id_master_material',index:'id_master_material', width:60, hidden:true},
				{name:'kdbrg',index:'kdbrg', width:100, hidden:false},
				{name:'item_no',index:'item_no', width:300, hidden:false},
				{name:'nama_barang',index:'nama_barang', width:300, hidden:false},
				{name:'satuan',index:'satuan', width:100, hidden:false},
				{name:'create_date',index:'create_date', width:150,hidden:false},
				{name:'create_by',index:'create_by', width:150,hidden:false},
				{name:'update_date',index:'update_date', width:150,hidden:false},
				{name:'update_by',index:'update_by', width:150,hidden:false},
				{name:'cons',index:'cons', width:150,hidden:true},
				],
			rowNum:15,
			rowList:[15,25,35],
			pager: '#ptbl_materialcode',
			sortname: 'id_master_material',
			viewrecords: true,
			sortorder: "asc",
			width: '',
			height:100,
			jsonReader: { repeatitems : false },
			caption:"Data Master Material Code",
			rownumbers: true,
			shrinkToFit: false,
			afterInsertRow: function(){
						
			},			
			gridComplete: function(){
				
			},
		}); 
			
                        
		jQuery("#tbl_materialcode").jqGrid('navGrid','#ptbl_materialcode',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#tbl_materialcode").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : false, defaultSearch: 'cn', ignoreCase: true});
		setTimeout(function(){
			setGridHight($("#tbl_materialcode"),$("#container_pasi_materialcode_set"),$("#pasi_materialcode_set_bar")); 
		},100); 
		
}); 

		  	
</script>
<div id="frmbarangupdate_dlg" title="Nama Barang" class="frmbarangupdate_dlg_cl"></div>
<div id="frmbaranginsert_dlg" title="Nama Barang" class="frmbaranginsert_dlg_cl"></div>
<div id="frmitemlistdlg" title="ITEM LIST" class="frmitemlistdlg_cl"></div>



	
	