 <div style="height:40px; width: 1000px;">
	 <button id="btnincomingfgcreate" style="color:#FF0000;" >Process Incoming</button>
	 <button id="btnincomingfgdataviewdtl" >View Data</button>
	 <button id="btnincomingfgapproved" >Approval</button><span style="padding-left:50px" /><button id="btnincomingfgupload">Upload FG IN</button>
	 <button id="btnincomingfgstock">View FG Stock</button>
	
 </div>
<table id="tblincomingfghdr"></table> <div id="ptblincomingfghdr"></div>
<script type="text/javascript">
  
    $(document).ready(function(){
		
		$("#btnincomingfgstock").button().click(function(){
			var form_data ={
				parmeter:'parameter'
			};
			$("#frmfg_stock_load_dlg").load('<?php echo base_url().'inventory/ct_fg/view_fg_load_stock'; ?>', form_data , function() {
			
				$("#frmfg_stock_load_dlg").dialog({
					modal:true,
					width : 800,
					height : 530,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
                    },
					close : function(){
						$('#frmfg_stock_load_dlg').dialog("destroy"); 
					    $(".frmfg_stock_load_dlg_cl").remove(); 
					    $("body").append('<div id="frmfg_stock_load_dlg" title="STOCK FINISH GOOD" class="frmfg_stock_load_dlg_cl"></div>'); 
						$('#tblincomingfghdr').trigger('reloadGrid');
	
					},
					open: function(){
						$("body").unblock();
						
					}
				});
			});		
				
		});
		
		$("#btnincomingfgcreate").button().click(function(){
			$("#frmincomingfgcreatedlg").load('<?php echo base_url().'inventory/ct_fg/view_fg_load_data'; ?>',  {parmeter:'parameter'}, function() {
			
				$("#frmincomingfgcreatedlg").dialog({
					modal:true,
					width : 980,
					height : 530,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
                    },
					close : function(){
						$('#frmincomingfgcreatedlg').dialog("destroy"); 
					    $(".frmincomingfgcreatedlg_cl").remove(); 
					    $("body").append('<div id="frmincomingfgcreatedlg" title="INCOMING ITEMS" class="frmincomingfgcreatedlg_cl"></div>'); 
						$('#tblincomingfghdr').trigger('reloadGrid');
	
					},
					open: function(){
						$("body").unblock();
						
					}
				});
			});		
		});
		
		$("#btnincomingfgupload").button().click(function(){
			
			$("#frmincomingfguploaddlg").load('<?php echo base_url().'inventory/ct_fg/view_fg_uploadfg'; ?>',  {parmeter:'parameter'}, function() {
				$("#frmincomingfguploaddlg").dialog({
					modal:true,
					width : 930,
					height : 500,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
                    },
					close : function(){
						$('#frmincomingfguploaddlg').dialog("destroy"); 
					    $(".frmincomingfguploaddlg_cl").remove(); 
					    $("body").append('<div id="frmincomingfguploaddlg" title="UPLOAD FINISH GOOD INCOMING DATA" class="frmincomingfguploaddlg_cl"></div>'); 
						<!-- $('#tblbc23hdr').trigger('reloadGrid'); -->
	
					},
					open: function(){
						$("body").unblock();
						
					}
				});
			});
		
		});
		
		$("#btnincomingfgdataviewdtl").button().click(function(){
			var id = jQuery("#tblincomingfghdr").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tblincomingfghdr").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};
			var form_data={id_incominghdr:ret.id_data_in_hdr};
			
			$("#frmincomingfg_dtl_dlg").load('<?php echo base_url().'inventory/ct_fg/view_fg_dtl'; ?>',  form_data, function() {
				$("#frmincomingfg_dtl_dlg").dialog({
					modal:true,
					width : 800,
					height : 500,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
                    },
						
                    
					close : function(){
						$('#frmincomingfg_dtl_dlg').dialog("destroy"); 
					    $(".frmincomingfg_dtl_dlg_cl").remove(); 
					    $("body").append('<div id="frmincomingfg_dtl_dlg" title="DATA DETAIL INCOMING ITEMS ASSY (FINISH GOOD)" class="frmincomingfg_dtl_dlg_cl"></div>'); 
	
					},
					open: function(){
						$("body").unblock();
						
					}
				});
			});	 	
		
		});
		
		$("#btnincomingfgapproved").button().click(function(){
			var id = jQuery("#tblincomingfghdr").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tblincomingfghdr").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};
			var form_data = {
				parmeter:'parameter', 
				idx:ret.id_data_in_hdr, 
				doc_in_from_id:ret.doc_in_from_id,
				idterkait:ret.id_terkait,
				typedok:ret.doc_in_from_name, 
				doc_in_no:ret.doc_in_no, 
				doc_in_date:ret.doc_in_date
				
				
			};
			$("#frmincomingfgapproved_dlg").load('<?php echo base_url().'inventory/ct_fg/view_fg_approved'; ?>', form_data , function() {
			
				$("#frmincomingfgapproved_dlg").dialog({
					modal:true,
					width : 490,
					height : 280,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
												
                    },
					close : function(){
						$('#frmincomingfgapproved_dlg').dialog("destroy"); 
					    $(".frmincomingfgapproved_dlg_cl").remove(); 
					    $("body").append('<div id="frmincomingfgapproved_dlg" title="INCOMING ITEMS APPROVAL" class="frmincomingfgapproved_dlg_cl"></div>'); 
						$('#tblincomingfghdr').trigger('reloadGrid');
	
					},
					open: function(){
						$("body").unblock();
						
					}
				});
			});			
		
		});
		
		
		
		var datePick = function (el) {
			$(el).datepicker({
				changeYear: true,
				changeMonth: true,
				showButtonPanel: true,
				onSelect: function () {
					
					if (this.id.substr(0, 3) === "gs_") {
                // in case of searching toolbar
					setTimeout(function(){
					jQuery("#tblincomingfghdr").jqGrid()[0].triggerToolbar();
						}, 50);
					} else {
						// refresh the filter in case of
						// searching dialog
						$(this).trigger('change');
					}
				}    
			});
		};
		
		jQuery("#tblincomingfghdr").jqGrid({
			url:'<?php echo base_url().'inventory/ct_fg/loadDataGrid'; ?>',
			mtype : "post",
			postData:{'q':'1'},
			datatype: "json",
			colNames:['ID','Incoming No', 'Incoming Date','Type Doc', 'doc_in_from_id', 'id_terkait', 'status'],
			colModel:[
				{name:'id_data_in_hdr',index:'id_data_in_hdr', width:60, hidden:true},
				{name:'doc_in_no',index:'doc_in_no', width:160},
				{name:'doc_in_date',index:'doc_in_date', width:106,stype:"text",searchoptions:{dataInit:datePick, att:{title:'Select Date'}}},
				{name:'doc_in_from_name',index:'doc_in_from_name', width:106},
				{name:'doc_in_from_id',index:'doc_in_from_id', width:106, hidden:true},
				{name:'id_terkait',index:'id_terkait', width:106, hidden:true},
				{name:'status',index:'status', width:106},
				],
			rowNum:10,
			rowList:[10,20,30],
			pager: '#ptblincomingfghdr',
			sortname: 'tbl_data_in_hdr.id_data_in_hdr',
			viewrecords: true,
			sortorder: "desc",
			width: 960,
			height:300,
			jsonReader: { repeatitems : false },
			caption:"List of Incoming Items",
			rownumbers: true,
			shrinkToFit: false,
			afterInsertRow: function(){
				
				
			},			
			gridComplete: function(){
				var rowIDs = jQuery("#tblincomingfghdr").getDataIDs(); 
				var rowData = $("#tblincomingfghdr").getRowData();
			
				for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = jQuery("#"+ rowIDs[i],jQuery('#tblincomingfghdr'));
				   
					switch (rowData[i].status) {
						
						case 'DATA PROCESSED':
						   trElement.css({"color":"green"});
						break;
						case 'APPROVED':
						   trElement.css({"color":"red"});
						break;
					}
				}
			},
		}); 
			
                        
		jQuery("#tblincomingfghdr").jqGrid('navGrid','#ptblincomingfghdr',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#tblincomingfghdr").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : false, defaultSearch: 'cn', ignoreCase: true});
		
	});
	
		  	
</script>
<div id="frmincomingfgcreatedlg" title="INCOMING ITEMS FINISH GOOD (ASSY)" class="frmincomingfgcreatedlg_cl"></div>
<div id="frmincomingfgapproved_dlg" title="INCOMING ITEMS APPROVAL" class="frmincomingfgapproved_dlg_cl"></div>
<div id="frmincomingfg_dtl_dlg" title="DATA DETAIL INCOMING ITEMS ASSY (FINISH GOOD)" class="frmincomingfg_dtl_dlg_cl"></div>
<div id="frmincomingfguploaddlg" title="UPLOAD FINISH GOOD INCOMING DATA" class="frmincomingfguploaddlg_cl"></div>
<div id="frmfg_stock_load_dlg" title="STOCK FINISH GOOD" class="frmfg_stock_load_dlg_cl"></div>

		
	