<div style="height:40px;">
	
	<button id="btnbc23prosesdatainsert_nonhib">Process Data</button>
	<b>Mohon Diperiksa Datanya Dengan Teliti Sesuai Invoice.</b>
</div>
<input type="hidden" id="hdn_noblproses_nonhib_bc40" value="<?php echo $nobl; ?>" />
<input type="hidden" id="hdn_tgblproses_nonhib_bc40" value="<?php echo $tgbl; ?>" />

<table id="listinvbl_nonhib_proses_bc40" class="scroll"></table><div id="plistinvbl_nonhib_proses_bc40" class="scroll" style="text-align:center;"></div>
<script type="text/javascript">
    
    $(document).ready(function(){
		$("#btnbc23prosesdatainsert_nonhib").button().click(function(){
			var id = jQuery("#tblbc40hdrnonhib_draft").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tblbc40hdrnonhib_draft").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};	
			
			
			var rowIDs = jQuery("#listinvbl_nonhib_proses_bc40").getDataIDs(); 
			var rowData = $("#listinvbl_nonhib_proses_bc40").getRowData();
			var k = 0;
			var urlx =  "<?php echo base_url().'exim/ct_bc40/updatestatusproses_nonhib'; ?>";
			for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = jQuery("#"+ rowIDs[i],jQuery('#listinvbl_nonhib_proses_bc40'));
				   if (rowData[i].statusx==1){	
				    
					k = 1;
					urlx =  "<?php echo base_url().'exim/ct_bc40/recalculate_new_inv_bl_nonhib'; ?>";
				   }					
			}
			
			var gridData = jQuery("#listinvbl_nonhib_proses_bc40").getRowData();
			var postData = JSON.stringify(gridData);
			var form_data={
				nobl:$('#hdn_noblproses_nonhib_bc40').val(),
				tgbl:$('#hdn_tgblproses_nonhib_bc40').val(),
				noinv:postData
			};
			
			
			
			$("#dlgbc40prosesdraftnonhib_x").dialog( "destroy" );
			$(".dlgbc40prosesdraftnonhib_x_cl").remove();
			$("body").append('<div id="dlgbc40prosesdraftnonhib_x" title="Warning" class="dlgbc40prosesdraftnonhib_x_cl"><p>Apakah anda akan Memproses Data ini Menjadi Data bc40?</p><br /></div>');
			$("#dlgbc40prosesdraftnonhib_x").dialog({
				height: 200,
				width: 350,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : urlx,
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlgbc40prosesdraftnonhib_x").dialog("close");
								$('#dlgbc40prosesdraftnonhib_x').dialog("destroy"); 
								$(".dlgbc40prosesdraftnonhib_x_cl").remove(); 
								$('#tblbc40hdrnonhib_draft').trigger('reloadGrid');
							} else { 
								alert(msg.sts+msg.desc);
								$("#dlgbc40prosesdraftnonhib_x").dialog("close");
								$('#dlgbc40prosesdraftnonhib_x').dialog("destroy"); 
								$(".dlgbc40prosesdraftnonhib_x_cl").remove(); 		

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

					}
				},
				close : function(){
					$('#dlgbc40prosesdraftnonhib_x').dialog("destroy"); 
					$(".dlgbc40prosesdraftnonhib_x_cl").remove(); 
					$("body").append('<div id="dlgbc40prosesdraftnonhib_x" title="Warning" class="dlgbc40prosesdraftnonhib_x_cl"><p>Apakah anda akan Memproses Data ini Menjadi Data bc40?</p></div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});
		});
		
		jQuery("#listinvbl_nonhib_proses_bc40").jqGrid({
			url:'<?php echo base_url().'exim/ct_bc40/loaddata_groupinv_nonhib'; ?>',
			postData:{'nobl':$('#hdn_noblproses_nonhib_bc40').val(), 'tgbl':$("#hdn_tgblproses_nonhib_bc40").val()},
			mtype : "post",
			datatype: "json",
			width: 473,
			height:300,
			colNames:['ID', 'No. Invoice', 'Date. Inv','No DOK','TGL DOK','Status','statusx'],
			colModel:[
				{name:'id_nonhib_hdr',index:'id_nonhib_hdr', width:60, sorttype:"int", hidden:true},
				{name:'noinv',index:'noinv', width:90, hidden:false},
				{name:'tglinv',index:'tglinv', width:90, hidden:false},
				{name:'nobl',index:'nobl', width:110, hidden:false},
				{name:'tgbl',index:'tgbl', width:90, hidden:false},
				{name:'status',index:'status', width:180, hidden:false},
				{name:'statusx',index:'statusx', width:180, hidden:true}
			
			],
			pager: '#plistinvbl_nonhib_proses_bc40',
			rowNum:10,
			rowList:[10,20,30],
			sortname: 'id_nonhib_hdr',
			sortorder: 'desc',
			jsonReader: { repeatitems : false },
			viewrecords: true,
			multiselect: false,
			caption: "Selected Invoice",
			gridComplete: function(){
				var rowIDs = jQuery("#listinvbl_nonhib_proses_bc40").getDataIDs(); 
				var rowData = $("#listinvbl_nonhib_proses_bc40").getRowData();
			
				for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = jQuery("#"+ rowIDs[i],jQuery('#listinvbl_nonhib_proses_bc40'));
					
					if(rowData[i].status == 'DATA ALREADY PROCESSED'){  trElement.css({"color":"red"}); }
					else if(rowData[i].status == 'INVOICE NEW ADDED'){  trElement.css({"color":"blue"}); } 
					
				}
			},
		});
		
		jQuery("#listinvbl_nonhib_proses_bc40").jqGrid('navGrid','#plistinvbl_nonhib_proses_bc40',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		

	});
		  	
</script>



	
	