<div id="container_pasi_ceisa_trxinvoice" style="height:100%; margin:0px; padding:0px;overflow:'hidden'; border: 0px solid #cd0a0a">
<div class="pane-header ui-state-active" id="pasi_ceisa_trxinvoice_bar" >   
	<button type="button" id="pasi_ceisa_trxinvoice_create">Get From Oracle</button>  

</div>
<table id="pasi_ceisa_trxinvoice_tbl"></table> <div id="ppasi_ceisa_trxinvoice_tbl"></div> 

<script type="text/javascript">
    
    $(document).ready(function(){
	
	$(window).bind('resize', function() {  
		setTimeout(function(){
			setGridHight($("#pasi_ceisa_trxinvoice_tbl"),$("#container_pasi_ceisa_trxinvoice"),$("#pasi_ceisa_trxinvoice_bar")); 
		},10); 
	}); 
		 
	$("#pasi_ceisa_trxinvoice_create").button(); 
	$("#pasi_ceisa_trxinvoice_barang").button(); 

    jQuery("#pasi_ceisa_trxinvoice_create").click(function(){  
		var $dialog = jQuery('<div \>')
		 .load('<?php echo base_url().'pasi_ceisa_finance/ct_finance_aw_import/new_document_trxinvoice'; ?>')

		 .dialog({
			modal:true,
				width : 1100,
				height : 650,
				title :'IMPORT TRX trxinvoice ',
				buttons: {
						"CLOSE": function(){
							$dialog.dialog("close");  
						} ,
						"IMPORT DATA": function(){  
							var selRowIds;
							selRowIds =  $("#pasi_ceisa_finance_header_module_tbl").jqGrid('getGridParam','selarrrow');
						
							var myArray = [];
							for (var i = 0; i < selRowIds.length; i++) 
							{
								var rowId = selRowIds[i];
								var idnya =  $('#pasi_ceisa_finance_header_module_tbl').getCell(rowId, 'rID'); 
								myArray.push(idnya);
							} 
						
							if (selRowIds.length ==0){
								alert("Minimal Import 1 data ");
								exit;
							}

					 
							var form_edit = {
								bc_prefix :'Invoice',     
					 			replace_if_exists        	: $('#replace_if_existInvoice').is(':checked')==true?'1':'0',    
								lstsa  : myArray  
							}; 					

							$.ajax({    
						url:'<?php echo base_url().'pasi_ceisa_finance/ct_finance_aw_import/import_data_from_trxinvoice'; ?>',
						type : 'POST',
							data : form_edit,
							dataType: 'json',
							success: function(msg){
								if (msg.valid){
									alert(msg.stsmsg);  
									$dialog.dialog("close");  
								} else { alert(msg.stsno+msg.stsmsg);  }
							} 
						});
	

						},	
						
				},	
				close : function(){
					$dialog.dialog('destroy').remove();
					$('#pasi_ceisa_trxinvoice_tbl').trigger('reloadGrid');
				},
				open: function(){
					$("body").unblock(); 
				}		
				
			}); 			

	}); 


	jQuery("#pasi_ceisa_trxinvoice_barang").click(function(){  
  
  var mark_id = jQuery('#pasi_ceisa_trxinvoice_tbl').jqGrid('getGridParam','selrow');   
					  if(!mark_id){ alert("Select Dokumen ");exit;}    
					  var ret = jQuery("#pasi_ceisa_trxinvoice_tbl").jqGrid('getRowData',mark_id);    
		   
  var field_data={bc_prefix:'trxinvoice'
				  ,no_invoice:ret.r2
				  ,id_header:ret.rID
				  };
  
  var $dialog = jQuery('<div \>')
   .load('<?php echo base_url().'pasi_ceisa_finance/ct_finance_aw_trxinvoice/view_item'; ?>',field_data)
   .dialog({
	  modal:true,
	  width : 950,
	  height : 600,
		  title :'LIST ITEM TRANSAKSI',
		  buttons: {
			  "CLOSE": function(){
				  $dialog.dialog("close");  
			  } ,
		  
		  },
		  close : function(){
			  $dialog.dialog('destroy').remove();
			  $('#pasi_ceisa_trxinvoice_tbl').trigger('reloadGrid');
		  },
		  open: function(){
			  $("body").unblock(); 
		  }
	  }); 
}); 

    jQuery("#pasi_ceisa_trxinvoice_tbl").jqGrid({
        url:'<?php echo base_url().'pasi_ceisa_finance/ct_finance_aw/loaddata_trxinvoice'; ?>',
			mtype : "post",
			postData:{'q':'1'},
			datatype: "json",
			colNames:[
			'ID_trxinvoice', 'TRX NUMBER', 'TRX DATE','DESCRIPTION','BATCH NAME', 'HEADER CATEGORY', 'INTERFACE','CURRENCY CODE','UNIT PRICE'
			,'AMOUNT','ORIG SYSTEM BILL' ]

			,colModel:[
			{name:'rID',index:'rID', width:80, hidden:true , align :'right'}
			,{name:'r1',index:'r1', width:100, hidden:false, align :'right'}
			,{name:'r2',index:'r2', width:100, hidden:false, align :'left'} //stype: 'select', search:true, searchoptions:{searchhidden: true, value: '-100:All;0:DRAFT;1:SEND TO MODULE;2:MAPPING;3:FINISH;-1:CANCEL'}}
 			,{name:'r3',index:'r3', width:150, editable: false, align :'left'} //formatter:'checkbox',  align: "center",stype: "select", searchoptions: { value: "-100:All;1:Yes;0:No" }}
 	
     		,{name:'r8',index:'r8', width:150, hidden:false, align :'left'}
			,{name:'r9',index:'r9', width:150, hidden:false, align :'left'}
			,{name:'r4',index:'r4', width:150, hidden:false, align :'left'} //, searchoptions:{searchhidden: true,dataInit:function(el){$(el).datepicker({onSelect: function(date){jQuery("#pasi_ceisa_trxinvoice_tbl")[0].triggerToolbar();},changeMonth: true,changeYear: true,dateFormat:'dd/mm/yy', showButtonPanel: true, beforeShow: function(input) {  setTimeout(function() { var buttonPane = $(input).datepicker("widget").find( ".ui-datepicker-buttonpane" );   var btn = $('<button class="ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all" type="button">Clear</button>');   btn.unbind("click").bind("click", function () {   $.datepicker._clearDate( input );   });   btn.appendTo( buttonPane );  }, 1 );  }  });}}}	
			,{name:'r5',index:'r5', width:150, hidden:false, align :'left'}
            ,{name:'r1',index:'r1', width:150, hidden:false, align :'left'}
			,{name:'r6',index:'r6', width:150, hidden:false, align :'left'}
			,{name:'r7',index:'r7', width:150, hidden:false, align :'left'}

			
//			,{name:'r6',index:'r6', width:100, hidden:false, align :'right'}

//			,{name:'r7',index:'r7', width:80, hidden:false, align :'right'}
//			,{name:'r8',index:'r8', width:80, hidden:false, align :'right'}
		
			],
			rowNum:10,
			rowList:[10,20,30],
			pager: '#ppasi_ceisa_trxinvoice_tbl',
			sortname: 'r1',
			viewrecords: true,
			sortorder: "desc",
			width: '',
			height: 100,
			//width: 950,
			//height:300,
			jsonReader: { repeatitems : false },
			caption:"Data Transaksi trxinvoice",
			rownumbers: true,
			loadonce: false,
			shrinkToFit: false,
			multiselect: false,
			afterInsertRow: function(rowid, aData){
				/*switch (aData.statusdok) {
					case 'DATA SENT':
						jQuery("#pasi_ceisa_trxinvoice_tbl").jqGrid('setCell',rowid,'statusdok','',{color:'green'});
					break;
					case '2':
						jQuery("#pasi_ceisa_trxinvoice_tbl").jqGrid('setCell',rowid,'statusdok','',{color:'red'});
					break;
					case '1':
						jQuery("#pasi_ceisa_trxinvoice_tbl").jqGrid('setCell',rowid,'statusdok','',{color:'blue'});
					break;
					
				} */
			},
		    onSelectRow: function(rowid){ 
				var rowData = $("#pasi_ceisa_trxinvoice_tbl").getRowData(rowid); 
	/*	 		if (rowData.rg == 'Yes' ){
					$("#pasi_ceisa_trxinvoice_map_supplier").show();
				}
				else{
					$("#pasi_ceisa_trxinvoice_map_supplier").hide();
			   } */
	 
  		 	 },
			gridComplete: function(){
				var rowIDs = jQuery("#pasi_ceisa_trxinvoice_tbl").getDataIDs(); 
				var rowData = $("#pasi_ceisa_trxinvoice_tbl").getRowData();
			    
				for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = jQuery("#"+ rowIDs[i],jQuery('#pasi_ceisa_trxinvoice_tbl'));
				   
				/*	switch (rowData[i].status_2) {
						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("#pasi_ceisa_trxinvoice_tbl").jqGrid('setGroupHeaders', 
            { useColSpanStyle: true, groupHeaders:[
//			{startColumnName: 'r3', numberOfColumns: 3, titleText: '<em><center>Dokumen</center></em>'},
// 			{startColumnName: 'r4', numberOfColumns: 2, titleText: '<em><center>Total</center></em>'}, 
// 			{startColumnName: 'r6', numberOfColumns: 2, titleText: '<em><center>Create</center></em>'}, 

        ] });
		
		jQuery("#pasi_ceisa_trxinvoice_tbl").jqGrid('navGrid','#ppasi_ceisa_trxinvoice_tbl',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#pasi_ceisa_trxinvoice_tbl").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});
	
	
		
	setTimeout(function(){
			setGridHight($("#pasi_ceisa_trxinvoice_tbl"),$("#container_pasi_ceisa_trxinvoice"),$("#pasi_ceisa_trxinvoice_bar")); 
		},100); 


 



    });



</script>

	
	