<div style="height:40px;">
	<button id="btnbc40prosesdatainsert">Process Data</button>
</div>
<input type="hidden" id="hdn_noblproses" value="<?php echo $nobl; ?>" />
<input type="hidden" id="hdn_tgblproses" value="<?php echo $tgbl; ?>" />

<table id="listinvbl_proses" class="scroll"></table><div id="plistinvbl_proses" class="scroll" style="text-align:center;"></div>
<script type="text/javascript">
    
    $(document).ready(function(){
		$("#btnbc40prosesdatainsert").button().click(function(){
			var id = jQuery("#tblbc40hdr_draft").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tblbc40hdr_draft").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};	
			
			
			var rowIDs = jQuery("#listinvbl_proses").getDataIDs(); 
			var rowData = $("#listinvbl_proses").getRowData();
			var k = 0;
			var urlx =  "<?php echo base_url().'exim/ct_bc40/updatestatusproses'; ?>";
			for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = jQuery("#"+ rowIDs[i],jQuery('#listinvbl_proses'));
				   if (rowData[i].status_invx==1){	
					k = 1;
					urlx =  "<?php echo base_url().'exim/ct_bc40/recalculate_new_inv_bl'; ?>";
				   }					
			}
			
			var gridData = jQuery("#listinvbl_proses").getRowData();
			var postData = JSON.stringify(gridData);
			var form_data={
				nobl:$('#hdn_noblproses').val(),
				tgbl:$('#hdn_tgblproses').val(),
				noinv:postData
			};
			
			
			
			$("#dlgbc40prosesdraft_x").dialog( "destroy" );
			$(".dlgbc40prosesdraft_xcl").remove();
			$(".dlgbc40prosesdraft_xcl").html('');
			$("body").append('<div id="dlgbc40prosesdraft_x" title="Warning" class="dlgbc40prosesdraft_xcl"><p>Apakah anda akan Memproses Data ini Menjadi Data bc40?</p><br /></div>');
			$("#dlgbc40prosesdraft_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);
								$("#dlgbc40prosesdraft_x").dialog("close");
								$('#dlgbc40prosesdraft_x').dialog("destroy"); 
								$(".dlgbc40prosesdraft_xcl").remove(); 
								$('#tblbc40hdr_draft').trigger('reloadGrid');
							} else { 
								alert(msg.sts+msg.desc);
								$("#dlgbc40prosesdraft_x").dialog("close");
								$('#dlgbc40prosesdraft_x').dialog("destroy"); 
								$(".dlgbc40prosesdraft_xcl").remove(); 		

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

					}
				},
				close : function(){
					$('#dlgbc40prosesdraft_x').dialog("destroy"); 
					$(".dlgbc40prosesdraft_xcl").remove(); 
					$("body").append('<div id="dlgbc40prosesdraft_x" title="Warning" class="dlgbc40prosesdraft_xcl"><p>Apakah anda akan Memproses Data ini Menjadi Data bc40?</p></div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});
		
		});
		
		jQuery("#listinvbl_proses").jqGrid({
			url:'<?php echo base_url().'exim/ct_bc40/loaddatanonobl'; ?>',
			postData:{'nobl':$('#hdn_noblproses').val(), 'tgbl':$('#hdn_tgblproses').val()},
			mtype : "post",
			datatype: "json",
			width: 473,
			height:300,
			colNames:['inv_hdr_id', 'Inv No', 'BL/AWB', 'Tgl BL/AWB','Status','sts'],
			colModel:[
				{name:'inv_hdr_id',index:'inv_hdr_id', width:60, sorttype:"int", hidden:true},
				{name:'invno',index:'invno', width:90},
				{name:'blawbno',index:'blawbno', width:90},
				{name:'tglblawb',index:'tglblawb', width:90},
				{name:'status_inv',index:'status_inv', width:90},
				{name:'status_invx',index:'status_invx', width:90, hidden:true},
			
			],
			pager: '#plistinvbl_proses',
			rowNum:10,
			rowList:[10,20,30],
			sortname: 'inv_hdr_id',
			sortorder: 'desc',
			viewrecords: true,
			multiselect: false,
			jsonReader: { repeatitems : false },
			caption: "Selected Invoice",
			gridComplete: function(){
				var rowIDs = jQuery("#listinvbl_proses").getDataIDs(); 
				var rowData = $("#listinvbl_proses").getRowData();
			
				for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = jQuery("#"+ rowIDs[i],jQuery('#listinvbl_proses'));
					
					if(rowData[i].status_inv == 'DATA ALREADY PROCESSED'){  trElement.css({"color":"red"}); }
					else if(rowData[i].status_inv == 'INVOICE NEW ADDED'){  trElement.css({"color":"blue"}); } 
					
				}
			},
		});
		
		

	});
		  	
</script>



	
	