<div style="height:40px;">
	<span>Kode Vendor</span><input id="txtnamavendor" /> &nbsp; &nbsp; <button id="btnbc23prosesdatainsert_coo">Process Data</button>
</div>
<input type="hidden" id="hdn_noblproses_coo" value="<?php echo $nobl; ?>" />
<input type="hidden" id="hdn_tgblproses_coo" value="<?php echo $tgbl; ?>" />

<table id="listinvbl_proses_bc23_coo" class="scroll"></table><div id="plistinvbl_proses_bc23_coo" class="scroll" style="text-align:center;"></div>
<script type="text/javascript">
    
    $(document).ready(function(){
		$("#btnbc23prosesdatainsert_coo").button().click(function(){
			var id = jQuery("#tbl_data_coo_inv_bc23").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tbl_data_coo_inv_bc23").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};	
			
			if($.trim($("#txtnamavendor").val()) == ''){
				alert("Silahkan Pilih atau masukan Kode Vendor");
				return false;
			}
			
			var rowIDs = jQuery("#listinvbl_proses_bc23_coo").getDataIDs(); 
			var rowData = $("#listinvbl_proses_bc23_coo").getRowData();
			var urlx =  "<?php echo base_url().'exim/ct_inv_draft/updatestatusproses_coo'; ?>";
			
			var gridData = jQuery("#listinvbl_proses_bc23_coo").getRowData();
			var postData = JSON.stringify(gridData);
			var form_data={
				nobl:$('#hdn_noblproses_coo').val(),
				tgbl:$('#hdn_tgblproses_coo').val(),
				kode_vendor:$('#txtnamavendor').val(),
				noinv:postData,
				typebc : function(){
					return 'BC23';
				}
			};
			
			
			
			$("#dlgbc23prosesdraft_x_coo_").dialog( "destroy" );
			$(".dlgbc23prosesdraft_x_coo_cl").remove();
			$(".dlgbc23prosesdraft_x_coo_cl").html('');
			$("body").append('<div id="dlgbc23prosesdraft_x_coo_" title="Warning" class="dlgbc23prosesdraft_x_coo_cl"><p>Apakah anda akan Memproses Data ini Menjadi Data BC23?</p><br /></div>');
			$("#dlgbc23prosesdraft_x_coo_").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);
								$("#dlgbc23prosesdraft_x_coo_").dialog("close");
								$('#dlgbc23prosesdraft_x_coo_').dialog("destroy"); 
								$(".dlgbc23prosesdraft_x_coo_cl").remove(); 
								$('#tbl_data_coo_inv_bc23').trigger('reloadGrid');
							} else { 
								alert(msg.sts+msg.desc);
								$("#dlgbc23prosesdraft_x_coo_").dialog("close");
								$('#dlgbc23prosesdraft_x_coo_').dialog("destroy"); 
								$(".dlgbc23prosesdraft_x_coo_cl").remove(); 		

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

					}
				},
				close : function(){
					$('#dlgbc23prosesdraft_x_coo_').dialog("destroy"); 
					$(".dlgbc23prosesdraft_x_coo_cl").remove(); 
					$("body").append('<div id="dlgbc23prosesdraft_x_coo_" title="Warning" class="dlgbc23prosesdraft_x_coo_cl"><p>Apakah anda akan Memproses Data ini Menjadi Data BC23?</p></div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});
		
		});
		
		jQuery("#listinvbl_proses_bc23_coo").jqGrid({
			url:'<?php echo base_url().'exim/ct_inv_draft/loaddatanonobl_coo'; ?>',
			postData:{'nobl':$('#hdn_noblproses_coo').val(), 'tgbl':$("#hdn_tgblproses_coo").val()},
			mtype : "post",
			datatype: "json",
			width: 460,
			height:320,
			colNames:['id_coo_data', 'Inv No', 'BL/AWB', 'Tgl BL/AWB', 'vendor','Status'],
			colModel:[
				{name:'id_coo_data',index:'id_coo_data', width:60, sorttype:"int", hidden:true},
				{name:'invno',index:'invno', width:120},
				{name:'blawbno',index:'blawbno', width:140},
				{name:'tglblawb',index:'tglblawb', width:90},
				{name:'vendor',index:'vendor', width:90},
				{name:'status_inv',index:'status_inv', width:190}	
			
			],
			pager: '#plistinvbl_bc23_coo',
			rowNum:10,
			rowList:[10,20,30],
			sortname: 'id_coo_data',
			sortorder: 'desc',
			viewrecords: true,
			multiselect: false,
			jsonReader: { repeatitems : false },
			caption: "Selected Invoice",
			shrinkToFit: false,
			gridComplete: function(){
				var rowIDs = jQuery("#listinvbl_proses_bc23_coo").getDataIDs(); 
				var rowData = $("#listinvbl_proses_bc23_coo").getRowData();
			
				for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = jQuery("#"+ rowIDs[i],jQuery('#listinvbl_proses_bc23_coo'));
					
					if(rowData[i].status_inv == 'BCPROSES'){  trElement.css({"color":"red"}); }
					else if(rowData[i].status_inv == 'INVOICE NEW ADDED'){  trElement.css({"color":"blue"}); } 
					
				}
			},
			onSelectRow: function(ids) {
				var ret = jQuery("#listinvbl_proses_bc23_coo").jqGrid('getRowData',ids);
				$( "#txtnamavendor" ).val(ret.vendor);
				
			}
		});
		
		

	});
		  	
</script>



	
	