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

		<button id="btngetitemfg">Get Finish Good Code List</button>
		<button id="btninsertfg">Insert Data</button> 
		<button id="btnupdatefg">Update Data</button>
		<button id="btndeletefg">Delete Data</button>
	</div>
	<table id="tbl_finishgoodcode"></table> <div id="ptbl_finishgoodcode"></div>
</div>
<script type="text/javascript">
    
    $(document).ready(function(){
		$(window).bind('resize', function() {  
			setTimeout(function(){
				setGridHight($("#tbl_finishgoodcode"),$("#container_pasi_finishgoodcode_set"),$("#pasi_finishgoodcode_set_bar")); 
			},10); 
		});


		$("#btngetitemfg").button().click(function(){
			$("#frmfinishgoodlistdlg").load('<?php echo base_url().'pasi_settings/ct_finishgoodcode/view_finishgoodcode_itemlist'; ?>',  {parmeter:'parameter'}, function() {
				$("#frmfinishgoodlistdlg").dialog({
					modal:true,
					width : 694,
					height : 499,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
                    },
					close : function(){
						$('#frmfinishgoodlistdlg').dialog("destroy"); 
					    $(".frmfinishgoodlistdlg_cl").remove(); 
					    $("body").append('<div id="frmfinishgoodlistdlg" title="ITEM LIST" class="frmfinishgoodlistdlg_cl"></div>'); 
						
					},
					open: function(){
						$("body").unblock();
						
					}
				});
			});
		});

		$("#btnupdatefg").button().click(function(){
			var id = jQuery("#tbl_finishgoodcode").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tbl_finishgoodcode").jqGrid('getRowData',id);	
			} else {
				alert("Please Select Row");
				return false;
			};	
			
			var form_data={
				idx:ret.id_master_finishgood,
				kd_brg:ret.kdbrg,
				nama_barang:ret.nama_barang,
				satuan:ret.satuan
			};			
			
			$("#frmfgupdate_dlg").load('<?php echo base_url().'pasi_settings/ct_finishgoodcode/view_finishgoodcode_update'; ?>',  form_data, function() {
				$("#frmfgupdate_dlg").dialog({
					modal:true,
					width : 350,
					height : 200,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  	
						}
                    },
					close : function(){
						$('#frmfgupdate_dlg').dialog("destroy"); 
					    $(".frmfgupdate_dlg_cl").remove(); 
					    $("body").append('<div id="frmfgupdate_dlg" title="Nama Barang" class="frmfgupdate_dlg_cl"></div>'); 
					},
					open: function(){
						$("body").unblock();
					}
				});
			});
		});
		$("#btninsertfg").button().click(function(){
						
			$("#frmfginsert_dlg").load('<?php echo base_url().'pasi_settings/ct_finishgoodcode/view_finishgoodcode_insert'; ?>',  function() {
				$("#frmfginsert_dlg").dialog({
					modal:true,
					width : 350,
					height : 200,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  	
						}
                    },
					close : function(){
						$('#frmfginsert_dlg').dialog("destroy"); 
					    $(".frmfginsert_dlg_cl").remove(); 
					    $("body").append('<div id="frmfginsert_dlg" title="Nama Barang" class="frmfginsert_dlg_cl"></div>'); 
	
					},
					open: function(){
						$("body").unblock();
						
					}
				});
			});
		});
		$("#btndeletefg").button().click(function(){
			var id = jQuery("#tbl_finishgoodcode").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tbl_finishgoodcode").jqGrid('getRowData',id);	
			} else {
				alert("Please Select Row");
				return false;
			};
			
			var form_data={
				idx:ret.id_master_finishgood
			};
			
			$("#dlgfgdelete").dialog( "destroy" );
			$(".dlgfgdelete_cl").remove();
			$("body").append('<div id="dlgfgdelete" title="Warning" class="dlgfgdelete_cl"><p>Apakah anda akan menghapus kode barang ini?</p><br /></div>');
			
			
			
			$("#dlgfgdelete").dialog({
				height: 160,
				width: 250,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : "<?php echo base_url().'pasi_settings/ct_finishgoodcode/deletekodebarang'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlgfgdelete").dialog("close");
								$('#dlgfgdelete').dialog("destroy"); 
								$(".dlgfgdelete_cl").remove(); 
								$('#tbl_finishgoodcode').trigger('reloadGrid');

							} else { 
								alert(msg.sts+msg.desc); 
								$("#dlgfgdelete").dialog("close");
								$('#dlgfgdelete').dialog("destroy"); 
								$(".dlgfgdelete_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_finishgoodcode").jqGrid({
			url:'<?php echo base_url().'pasi_settings/ct_finishgoodcode/loadData'; ?>',
			mtype : "post",
			postData:{'q':'1'},
			datatype: "json",
			
			colNames:['id', 'Item Code','Finish Good Name','Unit','Create Date','Create By','Update Date','Update By'],
			colModel:[
			
				{name:'id_master_finishgood',index:'id_master_finishgood', width:60, hidden:true},
				{name:'kdbrg',index:'kdbrg', width:100, 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},
				
				],
			rowNum:15,
			rowList:[15,25,35],
			pager: '#ptbl_finishgoodcode',
			sortname: 'id_master_finishgood',
			viewrecords: true,
			sortorder: "asc",
			width: '',
			height:100,
			jsonReader: { repeatitems : false },
			caption:"Data Master Finish Goods Code",
			rownumbers: true,
			shrinkToFit: false,
			afterInsertRow: function(){
						
			},			
			gridComplete: function(){
				
			},
		}); 
			
                        
		jQuery("#tbl_finishgoodcode").jqGrid('navGrid','#ptbl_finishgoodcode',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#tbl_finishgoodcode").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : false, defaultSearch: 'cn', ignoreCase: true});
		setTimeout(function(){
			setGridHight($("#tbl_finishgoodcode"),$("#container_pasi_finishgoodcode_set"),$("#pasi_finishgoodcode_set_bar")); 
		},100); 
		
}); 

		  	
</script>
<div id="frmfgupdate_dlg" title="Nama Barang" class="frmfgupdate_dlg_cl"></div>
<div id="frmfginsert_dlg" title="Nama Barang" class="frmfginsert_dlg_cl"></div>
<div id="frmfinishgoodlistdlg" title="ITEM LIST" class="frmfinishgoodlistdlg_cl"></div>



	
	