<div style="height:40px;">
<button id="btnstgetdatafg">Get Loader Data</button>
<button id="btnstviewdatafg">View Data</button>
<button id="btnbc23prosesdatafg">Prosses Data</button>	
</div>
<table id="tblstfg_loaddata"></table> <div id="ptblstfg_loaddata"></div>
<script type="text/javascript">
    
    $(document).ready(function(){
		$("#btnstgetdatafg").button().click(function(){
			var form_data={
				'a':'a'
			
			};
			
			$("#dlg_uploadedfgin").dialog( "destroy" );
			$(".dlg_uploadedfgincl").remove();
			$("body").append('<div id="dlg_uploadedfgin" title="Warning" class="dlg_uploadedfgincl"><p>Apakah anda akan memproses data incoming finish good?!?</p></div>');
			$("#dlg_uploadedfgin").dialog({
				height: 200,
				width: 250,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : "<?php echo base_url().'inventory/ct_fg/get_fg_load_data'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlg_uploadedfgin").dialog("close");
								$('#dlg_uploadedfgin').dialog("destroy"); 
								$(".dlg_uploadedfgincl").remove(); 
								$('#tblstfg_loaddata').trigger('reloadGrid');
							} else { 
								alert(msg.sts+' '+msg.desc); 
								$("#dlg_uploadedfgin").dialog("close");
								$('#dlg_uploadedfgin').dialog("destroy"); 
								$(".dlg_uploadedfgincl").remove(); 

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

					}
				},
				close : function(){
					$('#dlg_uploadedfgin').dialog("destroy"); 
					$(".dlg_uploadedfgincl").remove(); 
					$("body").append('<div id="dlg_uploadedfgin" title="Warning" class="dlg_uploadedfgincl"><p>Apakah anda akan memproses data incoming finish good?!?</p></div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});

			
			// var form_data={
				// 'test':'test'
			// };
			
			// $("#view_incoming_fg_uploaded_dlg").load('<?php echo base_url().'inventory/ct_fg/view_fg_data_uploaded'; ?>',  form_data, function() {
				// $("#view_incoming_fg_uploaded_dlg").dialog({
					// modal:true,
					// width : 760,
					// height : 460,
					// buttons: {
                        // "Close": function() {  
							// $(".ui-dialog-titlebar-close").trigger('click');  
							
						// }
                    // },
					// close : function(){
						// $('#view_incoming_fg_uploaded_dlg').dialog("destroy"); 
					    // $(".view_incoming_fg_uploaded_dlg_cl").remove(); 
					    // $("body").append('<div id="view_incoming_fg_uploaded_dlg" title="FG Incoming Data Uploaded" class="view_incoming_fg_uploaded_dlg_cl"></div>'); 
	
					// },
					// open: function(){
						// $("body").unblock();
						
					// }
				// });
			// });
			
		
			/* $.ajax({
				url : "<?php echo base_url().'inventory/ct_fg/get_fg_load_data'; ?>",
				type : 'POST',
				dataType: 'json',
				data : {test:'aaa'},
				success: function(msg){
					if (msg.sts == '00'){
						
						alert(msg.desc);
						$('#tblstfg_loaddata').trigger('reloadGrid');
						
					} else { alert(msg.sts+msg.desc);  }
				}
			}); */
		
		});
		
		$("#btnstviewdatafg").button().click(function(){
			var id = jQuery("#tblstfg_loaddata").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tblstfg_loaddata").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};	
			var form_data = {parmeter:'parameter', id_incoming_fg_hdr:ret.id_incoming_fg_hdr}
			
			$("#view_tbl_incoming_fg_dlg").load('<?php echo base_url().'inventory/ct_fg/view_fg_view_load_dtl'; ?>',  form_data, function() {
				$("#view_tbl_incoming_fg_dlg").dialog({
					modal:true,
					width : 990,
					height : 530,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
                    },
					close : function(){
						$('#view_tbl_incoming_fg_dlg').dialog("destroy"); 
					    $(".view_tbl_incoming_fg_dlg_cl").remove(); 
					    $("body").append('<div id="view_tbl_incoming_fg_dlg" title="FG Incoming Detail Load" class="view_tbl_incoming_fg_dlg_cl"></div>'); 
	
					},
					open: function(){
						$("body").unblock();
						
					}
				});
			});
		
		});
		$("#btnbc23prosesdatafg").button().click(function(){
			var id = jQuery("#tblstfg_loaddata").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tblstfg_loaddata").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};
			<!-- dari produksi (finishgood) liat di diagaram doc_in from 2-->
			var form_data = {
				id_incoming_fg_hdr:ret.id_incoming_fg_hdr,
				doc_in_from_id:'1' ,
				incoming_date:ret.incoming_date
				
			};
			
			$("#prosesdatafg_dlg").dialog( "destroy" );
			$(".prosesdatafg_dlg_cl").remove();
			$("body").append('<div id="prosesdatafg_dlg" title="Warning" class="prosesdatafg_dlg_cl"><p>Apakah anda akan Memproses Data  Menjadi Data Incoming Finish Good?</p><br /></div>');
			$("#prosesdatafg_dlg").dialog({
				height: 200,
				width: 350,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : "<?php echo base_url().'inventory/ct_fg/proses_incoming_fg'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#prosesdatafg_dlg").dialog("close");
								$('#prosesdatafg_dlg').dialog("destroy"); 
								$(".prosesdatafg_dlg_cl").remove(); 
								$('#tblstfg_loaddata').trigger('reloadGrid');
							} else { 
								alert(msg.sts+msg.desc);
								$("#prosesdatafg_dlg").dialog("close");
								$('#prosesdatafg_dlg').dialog("destroy"); 
								$(".prosesdatafg_dlg_cl").remove(); 		

							}
						}
					});
				},
				"CANCEL": function() {
						$( "#prosesdatafg_dlg" ).dialog( "close" );
						$(".prosesdatafg_dlg_cl").remove();

					}
				},
				close : function(){
					$('#prosesdatafg_dlg').dialog("destroy"); 
					$(".prosesdatafg_dlg_cl").remove(); 
					$("body").append('<div id="prosesdatafg_dlg" title="Warning" class="prosesdatafg_dlg_cl"><p>Apakah anda akan Memproses Data  Menjadi Data Finish Good?</p></div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});
				
		
		});
		
		function myformatter ( cellvalue, options, rowObject )
		{
			if (cellvalue == "new")
				 return '<font color="red">' + cellvalue + '</font>';//or use classes
			else
				 return '<font color="blue">' + cellvalue + '</font>';//or use classes
		}
		
		jQuery("#tblstfg_loaddata").jqGrid({
			url:'<?php echo base_url().'inventory/ct_fg/data_fg_load_data'; ?>',
			mtype : "post",
			postData:{'q':'1'},
			datatype: "json",
			colNames:['ID', 'Data In','Data In', 'Date Load', 'Incoming Date', 'Item Count', 'Total Item','status'],
			colModel:[
				{name:'id_incoming_fg_hdr',index:'id_incoming_fg_hdr', width:60, hidden:true},
				{name:'from_file_name',index:'from_file_name', width:437, hidden:true},
				{name:'from_file_name2',index:'from_file_name2', width:437, hidden:false},
				{name:'exec_date',index:'exec_date', width:89, hidden:false},
				{name:'incoming_date',index:'incoming_date', width:89, hidden:false},
				{name:'countrow',index:'countrow', width:89, hidden:false, align:'right'},
				{name:'itemcount',index:'itemcount', width:89, hidden:false, align:'right'},
				{name:'status',index:'status', width:89, hidden:false, formatter:myformatter},
				
				
			],
			rowNum:10,
			rowList:[10,20,30],
			pager: '#ptblstfg_loaddata',
			sortname: 'id_incoming_fg_hdr',
			viewrecords: true,
			sortorder: "asc",
			width: 960,
			height:320,
			jsonReader: { repeatitems : false },
			caption:"DATA INCOMING FINISHGOOD (ASSY) LOADED",
			rownumbers: true,
			shrinkToFit: false,
			afterInsertRow: function(){
				
				
			}
		}); 
			
                        
		jQuery("#tblstfg_loaddata").jqGrid('navGrid','#ptblstfg_loaddata',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		
	});
		  	
</script>
<div id="view_tbl_incoming_fg_dlg" title="FG Incoming Detail Load" class="view_tbl_incoming_fg_dlg_cl"></div>
<div id="view_incoming_fg_uploaded_dlg" title="FG Incoming Data Uploaded" class="view_incoming_fg_uploaded_dlg_cl"></div>



	
	