<div style="height:40px;">
<button id="btnstgetdata">Get Loader Data</button>
<button id="btnstviewdata">View Data</button>
<button id="btnbc23prosesdata">Prosses Data</button>
<button id="btnprosesalldata">Prosses All New Data</button>
<?php if($this->session->userdata('DX_username') == 'ojah' || $this->session->userdata('DX_username') == 'admin' ){ ?>  
	<button id="btndeletedata">Cancel Data</button>				
<?php } ?>
</div>
<table id="tblst_loaddata"></table> <div id="ptblst_loaddata"></div>
<script type="text/javascript">
    
    $(document).ready(function(){
		$("#btndeletedata").button().click(function(){
			var id = jQuery("#tblst_loaddata").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tblst_loaddata").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};	
			
			
			var form_data={
				'id_vgi_hdr':ret.id_vgi_hdr
			};
			$("#dlg_st_deletedata").dialog( "destroy" );
			$(".dlg_st_deletedata_cl").remove();
			$(".dlg_st_deletedata_cl").html('');
			$("body").append('<div id="dlg_st_deletedata" title="Warning" class="dlg_st_deletedata_cl"><p>Mbak <b>' + '<?php echo $this->session->userdata('DX_username'); ?>'  + ' </b>Apakah anda yakin akan mendelete semua data berstatus new ini.???</p><br />Mohon diperiksa kembali datanya dengan baik-baik..</div>');
			$("#dlg_st_deletedata").dialog({
				height: 200,
				width: 250,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : "<?php echo base_url().'inventory/ct_stock_transfer/st_deletedata'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlg_st_deletedata").dialog("close");
								$('#dlg_st_deletedata').dialog("destroy"); 
								$(".dlg_st_deletedata_cl").remove(); 
								$('#tblsthdr').trigger('reloadGrid');
								$('#tblst_loaddata').trigger('reloadGrid');	
								
							} else { 
								alert(msg.sts+msg.desc); 
								$("#dlg_st_deletedata").dialog("close");
								$('#dlg_st_deletedata').dialog("destroy"); 
								$(".dlg_st_deletedata_cl").remove(); 
								$('#tblsthdr').trigger('reloadGrid');
								
							}
						}
					});
				},
					"CANCEL": function() {
						$( "#dlg_st_deletedata" ).dialog( "close" );

					}
				},
				close : function(){
					$('#dlg_st_deletedata').dialog("destroy"); 
					$(".dlg_st_deletedata_cl").remove(); 
					$("body").append('<div id="dlg_st_deletedata" title="Warning" class="dlg_st_deletedata_cl"><p>Apakah anda yakin akan memproses semua data berstatus new ini.???</p><br />Mohon diperiksa kembali datanya dengan baik-baik..</div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});
			
		
		});
		
		$("#btnprosesalldata").button().click(function(){
			var form_data={
				'aaaa':'bbbb'
			};
			$("#dlg_st_prosesalldata").dialog( "destroy" );
			$(".dlg_st_prosesalldata_cl").remove();
			$(".dlg_st_prosesalldata_cl").html('');
			$("body").append('<div id="dlg_st_prosesalldata" title="Warning" class="dlg_st_prosesalldata_cl"><p>Apakah anda yakin akan memproses semua data berstatus new ini.???</p><br />Mohon diperiksa kembali datanya dengan baik-baik..</div>');
			$("#dlg_st_prosesalldata").dialog({
				height: 200,
				width: 250,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : "<?php echo base_url().'inventory/ct_stock_transfer/st_alldata_process_outgoing'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlg_st_prosesalldata").dialog("close");
								$('#dlg_st_prosesalldata').dialog("destroy"); 
								$(".dlg_st_prosesalldata_cl").remove(); 
								$('#tblsthdr').trigger('reloadGrid');
								$('#tblst_loaddata').trigger('reloadGrid');	
								
							} else { 
								alert(msg.sts+msg.desc); 
								$("#dlg_st_prosesalldata").dialog("close");
								$('#dlg_st_prosesalldata').dialog("destroy"); 
								$(".dlg_st_prosesalldata_cl").remove(); 
								$('#tblsthdr').trigger('reloadGrid');
								
							}
						}
					});
				},
					"CANCEL": function() {
						$( "#dlg_st_prosesalldata" ).dialog( "close" );

					}
				},
				close : function(){
					$('#dlg_st_prosesalldata').dialog("destroy"); 
					$(".dlg_st_prosesalldata_cl").remove(); 
					$("body").append('<div id="dlg_st_prosesalldata" title="Warning" class="dlg_st_prosesalldata_cl"><p>Apakah anda yakin akan memproses semua data berstatus new ini.???</p><br />Mohon diperiksa kembali datanya dengan baik-baik..</div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});
		});
		
		$("#btnstgetdata").button().click(function(){
			$.ajax({
				url : "<?php echo base_url().'inventory/ct_stock_transfer/getdatavgi'; ?>",
				type : 'POST',
				dataType: 'json',
				data : {test:'aaa'},
				success: function(msg){
					if (msg.sts == '00'){
						
						alert(msg.desc);
						$('#tblst_loaddata').trigger('reloadGrid');
						
					} else { alert(msg.sts+msg.desc);  }
				}
			});
		
		});
		
		$("#btnstviewdata").button().click(function(){
			var id = jQuery("#tblst_loaddata").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tblst_loaddata").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};	
			
			
			$("#frmstviewvgidlg").load('<?php echo base_url().'inventory/ct_stock_transfer/view_stocktransfer_vgi_dtl'; ?>',  {parmeter:'parameter', id_vgi_hdr:ret.id_vgi_hdr}, function() {
				$("#frmstviewvgidlg").dialog({
					modal:true,
					width : 800,
					height : 530,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
                    },
					close : function(){
						$('#frmstviewvgidlg').dialog("destroy"); 
					    $(".frmstviewvgidlg_cl").remove(); 
					    $("body").append('<div id="frmstviewvgidlg" title="VGI Detail" class="frmstviewvgidlg_cl"></div>'); 
	
					},
					open: function(){
						$("body").unblock();
						
					}
				});
			});
		
		});
		$("#btnbc23prosesdata").button().click(function(){
			var id = jQuery("#tblst_loaddata").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tblst_loaddata").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};
			<!-- dari bc 23 liat di diagaram doc_in from 2-->
			var form_data = {
				id_hdr:ret.id_vgi_hdr,
				doc_in_from_id:'1' ,
				id_vgi_hdr_dtlx:ret.id_vgi_hdr
			};
			
			$.ajax({
			url : "<?php echo base_url().'inventory/ct_stock_transfer/vgi_dtl_isnull'; ?>",
			type : 'POST',
			dataType: 'json',
			data : form_data,
			success: function(msg){
				if (msg.sts == '00'){
						$("#btnstviewdata").button().click();
					
						
					} else { 
					
						prosesdataoutgoingproduksi(form_data);
								
					}
				}
			});
			
			function prosesdataoutgoingproduksi(form_data){
				
				$("#dlg_st_prosesdata").dialog( "destroy" );
				$(".dlg_st_prosesdata_cl").remove();
				$(".dlg_st_prosesdata_cl").html('');
				$("body").append('<div id="dlg_st_prosesdata" title="Warning" class="dlg_st_prosesdata_cl"><p>Apakah anda yakin akan memproses data ini.???</p><br />Mohon diperiksa kembali datanya dengan baik-baik..</div>');
				$("#dlg_st_prosesdata").dialog({
					height: 200,
					width: 250,
					modal: true,
					hide: 'Slide',
					autoOpen: 'false',
					buttons: {
						"CONFIRM": function() {
						$.ajax({
							url : "<?php echo base_url().'inventory/ct_stock_transfer/st_process_outgoing'; ?>",
							type : 'POST',
							dataType: 'json',
							data : form_data,
							success: function(msg){
								if (msg.sts == '00'){
									alert(msg.desc);
									$("#dlg_st_prosesdata").dialog("close");
									$('#dlg_st_prosesdata').dialog("destroy"); 
									$(".dlg_st_prosesdata_cl").remove(); 
									$('#tblsthdr').trigger('reloadGrid');
									$('#tblst_loaddata').trigger('reloadGrid');	
									
								} else { 
									alert(msg.sts+msg.desc); 
									$("#dlg_st_prosesdata").dialog("close");
									$('#dlg_st_prosesdata').dialog("destroy"); 
									$(".dlg_st_prosesdata_cl").remove(); 
									$('#tblsthdr').trigger('reloadGrid');
									
								}
							}
						});
					},
						"CANCEL": function() {
							$( "#dlg_st_prosesdata" ).dialog( "close" );

						}
					},
					close : function(){
						$('#dlg_st_prosesdata').dialog("destroy"); 
						$(".dlg_st_prosesdata_cl").remove(); 
						$("body").append('<div id="dlg_st_prosesdata" title="Warning" class="dlg_st_prosesdata_cl"><p>Apakah anda yakin akan memproses data ini.???</p><br />Mohon diperiksa kembali datanya dengan baik-baik..</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("#tblst_loaddata").jqGrid({
			url:'<?php echo base_url().'inventory/ct_stock_transfer/loaddatavgi'; ?>',
			mtype : "post",
			postData:{'q':'1'},
			datatype: "json",
			colNames:['ID', 'Filename', 'Date Load', 'item count','status','ISSUE_NO','REG_DATE'],
			colModel:[
				{name:'id_vgi_hdr',index:'id_vgi_hdr', width:60, hidden:true},
				{name:'from_file_name',index:'from_file_name', width:437, hidden:false},
				{name:'exec_date',index:'exec_date', width:89, hidden:false},
				{name:'itemcount',index:'itemcount', width:69, hidden:false, align:'right'},
				{name:'status',index:'status', width:89, hidden:false, formatter:myformatter},
				{name:'ISSUE_NO',index:'ISSUE_NO', width:109, hidden:false},
				{name:'REG_DATE',index:'REG_DATE', width:89, hidden:false},
			],
			rowNum:10,
			rowList:[10,20,30],
			pager: '#ptblst_loaddata',
			sortname: 'id_vgi_hdr',
			viewrecords: true,
			sortorder: "REG_DATE",
			width: 970,
			height:320,
			jsonReader: { repeatitems : false },
			caption:"DATA VGI LOADED",
			rownumbers: true,
			shrinkToFit: false,
			afterInsertRow: function(){
				
				
			}
		}); 
			
                        
		jQuery("#tblst_loaddata").jqGrid('navGrid','#ptblst_loaddata',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#tblst_loaddata").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});
		
	});
		  	
</script>
<div id="frmstviewvgidlg" title="VGI Detail" class="frmstviewvgidlg_cl"></div>



	
	