 <div style="height:40px;">
	 <button id="btnbc27pre" style="color:#FF0000;">Get Data</button>
	 <button id="btnbc27viewdtl" >View Data</button>
	 <button id="btnbc27approvedata" >Approve/Move Data</button>


 </div>
<table id="tblbc27hdr"></table> <div id="ptblbc27hdr"></div>
<script type="text/javascript">
  
    $(document).ready(function(){
		
		
		$("#btnbc27viewdtl").button().click(function(){
			var id = jQuery("#tblbc27hdr").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tblbc27hdr").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};	
			var form_data={
				parmeter:'parameter',
				id_sa_hdr:ret.id_sa_hdr,
				bc27No:ret.bc27No,
				bc27Tg:ret.bc27Tg,
				bc27NAJU:ret.bc27NAJU,
				bc27TGAJU:ret.bc27TGAJU,
				SA_NO:ret.SA_NO
				
			};
			$("#frmbc27viewdtldlg").load('<?php echo base_url().'exim/ct_bc27/view_bc27_dtl'; ?>', form_data , function() {
			
				$("#frmbc27viewdtldlg").dialog({
					modal:true,
					width : 890,
					height : 530,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
                    },
					close : function(){
						$('#frmbc27viewdtldlg').dialog("destroy"); 
					    $(".frmbc27viewdtldlg_cl").remove(); 
					    $("body").append('<div id="frmbc27viewdtldlg" title="DETAIL DOCUMENTS" class="frmbc27viewdtldlg_cl"></div>'); 
						$('#tblbc27hdr').trigger('reloadGrid');
	
					},
					open: function(){
						$("body").unblock();
						
					}
				});
			});		
			
		});
		
		
		$("#btnbc27approvedata").button().click(function(){
			var id = jQuery("#tblbc27hdr").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tblbc27hdr").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};

			if (ret.statusdok == 'DATA BARU'){  
				alert("Kirim Dahulu Data Ke Modul bc27 Untuk Mendapat CAR(Send to modul)");
				return false; };

					
			$("#frmbc27movedlg").load('<?php echo base_url().'exim/ct_bc27_view_dtl/view_bc27_move'; ?>',  {parmeter:'parameter', idhdrbc27:ret.id_bc_in_hdr, inv_hdr_idbc27:ret.nobl, 'noinv':ret.nobl, nobc27:ret.bc27No}, function() {
			
				$("#frmbc27movedlg").dialog({
					modal:true,
					width : 980,
					height : 490,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
                    },
					close : function(){
						$('#frmbc27movedlg').dialog("destroy"); 
					    $(".frmbc27movedlg_cl").remove(); 
					    $("body").append('<div id="frmbc27movedlg" title="MOVE DATA" class="frmbc27movedlg_cl"></div>'); 
						$('#tblbc27hdr').trigger('reloadGrid');
	
					},
					open: function(){
						$("body").unblock();
						
					}
				});
			});
		
		});
		
		$("#btnbc27pre").button().click(function(){
			$("#frmbc27invdlg").load('<?php echo base_url().'exim/ct_bc27/view_bc27_getdata'; ?>',  {parmeter:'parameter'}, function() {
				$("#frmbc27invdlg").dialog({
					modal:true,
					width : 731,
					height : 461,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
                    },
					close : function(){
						$('#frmbc27invdlg').dialog("destroy"); 
					    $(".frmbc27invdlg_cl").remove(); 
					    $("body").append('<div id="frmbc27invdlg" title="LOAD SA DATA" class="frmbc27invdlg_cl"></div>'); 
						$('#tblbc27hdr').trigger('reloadGrid');
	
					},
					open: function(){
						$("body").unblock();
						
					}
				});
			});
		});	
		
		var datePick = function (el) {
			$(el).datepicker({
				changeYear: true,
				changeMonth: true,
				showButtonPanel: true,
				onSelect: function () {
					
					if (this.id.substr(0, 3) === "gs_") {
               
					setTimeout(function(){
					jQuery("#tblbc27hdr").jqGrid()[0].triggerToolbar();
						}, 50);
					} else {
						
						$(this).trigger('change');
					}
				}    
			});
		};
		
		jQuery("#tblbc27hdr").jqGrid({
			url:'<?php echo base_url().'exim/ct_bc27/loaddata'; ?>',
			mtype : "post",
			postData:{'q':'1'},
			datatype: "json",
			colNames:[
				'id_sa_hdr'
			  ,'SA NO'
			  ,'NPWP PEMBELI'
			  ,'NAMA PEMBELI'
			  ,'bc27No'
			  ,'bc27Tg'
			  ,'bc27NAJU'
			  ,'bc27TGAJU'
			  ,'JML INV'
			  ,'status'
			  ,'create date'
			  ,'create by'
			  ,'update date'
			  ,'update by'
			
			],
			colModel:[
				{name:'id_sa_hdr',index:'id_sa_hdr', width:60, hidden:true},
				{name:'SA_NO',index:'SA_NO', width:162, hidden:false},
				{name:'NPWP_PEMBELI',index:'NPWP_PEMBELI', width:193, hidden:false},
				{name:'NAMA_PEMBELI',index:'NAMA_PEMBELI', width:200, hidden:false},
				{name:'bc27No',index:'bc27No', width:200, hidden:false},
				{name:'bc27Tg',index:'bc27Tg', width:100, hidden:false},
				{name:'bc27NAJU',index:'bc27NAJU', width:100, hidden:false},
				{name:'bc27TGAJU',index:'bc27TGAJU', width:100, hidden:false},
				{name:'jml_inv',index:'jml_inv', width:84, hidden:false, align:'right'},
				{name:'status',index:'status', width:184, hidden:false},
				{name:'create_date',index:'create_date', width:164, hidden:false},
				{name:'create_by',index:'create_by', width:109, hidden:false},
				{name:'update_date',index:'update_date', width:164, hidden:false},
				{name:'update_by',index:'update_by', width:109, hidden:false},
				
			
			],
			rowNum:10,
			rowList:[10,20,30],
			pager: '#ptblbc27hdr',
			sortname: 'id_sa_hdr',
			viewrecords: true,
			sortorder: "desc",
			width: 960,
			height:280,
			jsonReader: { repeatitems : false },
			caption:"List of bc27 Header",
			rownumbers: true,
			shrinkToFit: false,
			afterInsertRow: function(rowid, aData){
				/*switch (aData.statusdok) {
					case 'DATA SENT':
						jQuery("#tblbc27hdr").jqGrid('setCell',rowid,'statusdok','',{color:'green'});
					break;
					case '2':
						jQuery("#tblbc27hdr").jqGrid('setCell',rowid,'statusdok','',{color:'red'});
					break;
					case '1':
						jQuery("#tblbc27hdr").jqGrid('setCell',rowid,'statusdok','',{color:'blue'});
					break;
					
				} */
			},
			gridComplete: function(){
				var rowIDs = jQuery("#tblbc27hdr").getDataIDs(); 
				var rowData = $("#tblbc27hdr").getRowData();
			
				for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = jQuery("#"+ rowIDs[i],jQuery('#tblbc27hdr'));
				   
					switch (rowData[i].statusdok) {
						case 'DATA PROCESSED':
						   trElement.css({"color":"green"});
						break;
						
						case 'SENT TO INVENTORY CANCELED':
						   trElement.css({"color":"green"});
						break;
						
						case 'DATA SENT TO INVENTORY':
						   trElement.css({"color":"purple"});
						break;
						case 'DATA PROCESSED INVENTORY':
						   trElement.css({"color":"blue"});
						break;
						case 'APPROVED INVENTORY':
						   trElement.css({"color":"red"});
						break;
					}
				}
			},
		}); 
			
                        
		jQuery("#tblbc27hdr").jqGrid('navGrid','#ptblbc27hdr',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#tblbc27hdr").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : false, defaultSearch: 'cn', ignoreCase: true});
	
		
	});
	
		  	
</script>
<div id="frmbc27invdlg" title="LOAD DATA SA" class="frmbc27invdlg_cl"></div>
<div id="frmbc27viewdtldlg" title="DETAIL DOCUMENTS" class="frmbc27viewdtldlg_cl"></div>
<div id="frmgetdatahdrbc27_dlg" title="GET DATA FROM MODUL" class="frmgetdatahdrbc27_dlg_cl"></div>
<div id="frmbc27movedlg" title="MOVE DATA" class="frmbc27movedlg_cl"></div>
<div id="frmbc27invnonhibdlg" title="INVOICE DATA NON HIB" class="frmbc27invnonhibdlg_cl"></div>

		
	