<div id="container_pasi_ceisa_belibc27" style="height:100%; margin:0px; padding:0px;overflow:'hidden'; border: 0px solid #cd0a0a">
<div class="pane-header ui-state-active" id="pasi_ceisa_belibc27_bar" >   
	<button type="button" id="pasi_ceisa_belibc27_create">Get From AW System</button>  
	<button type="button" id="pasi_ceisa_belibc27_barang">View Barang</button>  
	<button type="button" id="pasi_ceisa_belibc27_module">Create Draft</button> 
	<button type="button" id="pasi_ceisa_belibc27_canceldraft">Cancel draft</button>  
	<button type="button" id="pasi_ceisa_belibc27_canceldokumen">Cancel Dokumen</button> 
</div>
<table id="pasi_ceisa_belibc27_tbl"></table> <div id="ppasi_ceisa_belibc27_tbl"></div> 

<script type="text/javascript">
    
    $(document).ready(function(){
	
	$(window).bind('resize', function() {  
		setTimeout(function(){
			setGridHight($("#pasi_ceisa_belibc27_tbl"),$("#container_pasi_ceisa_belibc27"),$("#pasi_ceisa_belibc27_bar")); 
		},10); 
	}); 
		 
	$("#pasi_ceisa_belibc27_create").button(); 
	$("#pasi_ceisa_belibc27_barang").button(); 
	$("#pasi_ceisa_belibc27_module").button(); 
	$("#pasi_ceisa_belibc27_canceldraft").button(); 
	$("#pasi_ceisa_belibc27_canceldokumen").button(); 

    jQuery("#pasi_ceisa_belibc27_create").click(function(){  
		var $dialog = jQuery('<div \>')
		 .load('<?php echo base_url().'aw_beli/ct_aw_beli_load/new_import_bc27'; ?>')

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

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

							$.ajax({    
						url:'<?php echo base_url().'aw_beli/ct_aw_beli_save/import_data_bc27'; ?>',
						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_belibc27_tbl').trigger('reloadGrid');
				},
				open: function(){
					$("body").unblock(); 
				}		
				
			}); 			

	}); 


	jQuery("#pasi_ceisa_belibc27_module").click(function(){  
  
  var mark_id = jQuery('#pasi_ceisa_belibc27_tbl').jqGrid('getGridParam','selrow');   
  if(!mark_id){ alert("Select Dokumen ");} 
  else {
	  var ret = jQuery("#pasi_ceisa_belibc27_tbl").jqGrid('getRowData',mark_id);    
	  var $dialog = jQuery('<div \>')
	   .html(' <div class="ui-layout-content ui-widget-content-panel">\
							   Apakah dokumen akan di prosses ? \
						 </div>\
						  <div class="pane-footer ui-state-default"></div> ')
	   .dialog({
		  modal:true,
		  width : 300,
		  height : 150,
			  title :'PROSSES DATA',
			  buttons: {
							  "CLOSE": function(){
								  $dialog.dialog("close");  
							  },
							  "PROSSES": function() {   

								  var selRowIds;
								  selRowIds =  $("#pasi_ceisa_belibc27_tbl").jqGrid('getGridParam','selarrrow');
							  
								  var myArray = [];
								  for (var i = 0; i < selRowIds.length; i++) 
								  {
									  var rowId = selRowIds[i];
									  var idnya =  $('#pasi_ceisa_belibc27_tbl').getCell(rowId, 'rID'); 
									  myArray.push(idnya);
								  } 

								   var form_data = {
								  id_header 	: ret.rID,
								  replace_if_exists        	: $('#replace_if_exist27').is(':checked')==true?'1':'0',    
								  lstsa  : ret.rID,  
								  bc_prefix:'27'
								  };
								  $.ajax({    
									  url:'<?php echo base_url().'aw_beli/ct_aw_beli_save/prosses_data_bc27'; ?>',
									  type : 'POST',
										  data : form_data,
										  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_belibc27_tbl').trigger('reloadGrid');
			  },
			  open: function(){
				  $("body").unblock(); 
			  }
		  });
  } 
}); 





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


jQuery("#pasi_ceisa_belibc27_canceldokumen").click(function(){  
			var $dialog =  $('<div />')
				.html(' <div class="ui-layout-content ui-widget-content-panel" style="margin-top:10px"> \
				<table class="tablefixed" > \
				<input type="hidden" id="doc_in_id23"> \
							<tr> \
							<td class="td100">Info Cancel</td> \
							  <td width="10"><div align="center">:</div></td> \
								<td colspan="3"><input name="txt_ciesa_bc_40_info_cancel" type="text" id="txt_ciesa_bc_40_info_cancel" style="width:100%;text-align:left;" /></td> \
							</tr> \
						</table> \
				</div>\
				<div class="pane-footer ui-state-default" />')
			 .dialog({
				modal:true,
				width : 500,
				height : 150,
				title :'CANCEL DOKUMENT bc27',
				buttons: {
					"CLOSE": function(){
						$dialog.dialog("close");  
					} ,
					"CANCEL DOCUMENT": function(){ 
							var mark_id = jQuery('#pasi_ceisa_belibc27_tbl').jqGrid('getGridParam','selrow');   
						 	if(!mark_id){ alert("Pililh dokumen yang akan di cancel");exit;}    
								var ret = jQuery("#pasi_ceisa_belibc27_tbl").jqGrid('getRowData',mark_id);    
						 	var form_edit = {      
									id_header  : ret.rID,
									status_info  : $('#txt_ciesa_bc_40_info_cancel').val()  
							}; 
							
							$.ajax({    
							url:'<?php echo base_url().'aw_beli/ct_aw_beli_save/cancel_document_bc27'; ?>',
							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_belibc27_tbl').trigger('reloadGrid');
				},
				open: function(){
				$("body").unblock(); 
				}
			}); 
	}); 



	jQuery("#pasi_ceisa_belibc27_canceldraft").click(function(){  
			var $dialog =  $('<div />')
				.html(' <div class="ui-layout-content ui-widget-content-panel" style="margin-top:10px"> \
				<table class="tablefixed" > \
				<input type="hidden" id="doc_in_id27"> \
							<tr> \
							<td class="td100">Info Cancel</td> \
							  <td width="10"><div align="center">:</div></td> \
								<td colspan="3"><input name="txt_ciesa_bc_27_info_canceldraft" type="text" id="txt_ciesa_bc_40_info_canceldraft" style="width:100%;text-align:left;" /></td> \
							</tr> \
						</table> \
				</div>\
				<div class="pane-footer ui-state-default" />')
			 .dialog({
				modal:true,
				width : 500,
				height : 150,
				title :'CANCEL DRAFT BC27',
				buttons: {
					"CLOSE": function(){
						$dialog.dialog("close");  
					} ,
					"CANCEL DRAFT": function(){ 
							var mark_id = jQuery('#pasi_ceisa_belibc27_tbl').jqGrid('getGridParam','selrow');   
						 	if(!mark_id){ alert("Pilih draft yang akan di cancel");exit;}    
								var ret = jQuery("#pasi_ceisa_belibc27_tbl").jqGrid('getRowData',mark_id);    
						 	var form_edit = {      
									id_header  : ret.rID,
									nomor_ked : ret.r10,
									status_info  : $('#txt_ciesa_bc_40_info_cancel').val()  
							}; 
							
							$.ajax({    
							url:'<?php echo base_url().'aw_beli/ct_aw_beli_save/cancel_draft_bc27'; ?>',
							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_belibc27_tbl').trigger('reloadGrid');
				},
				open: function(){
				$("body").unblock(); 
				}
			}); 
	}); 



	//-------------load data
    jQuery("#pasi_ceisa_belibc27_tbl").jqGrid({
        url:'<?php echo base_url().'aw_beli/ct_aw_beli_data/viewdata_bc27'; ?>',
			mtype : "post",
			postData:{'q':'1'},
			datatype: "json",
			colNames:[
			'beli_ID_HEADER','beli_status_id','Nomor KED','G','Nomor Dokumen','Tanggal Dokumen','Nama'
			,'Alamat','Status','Nama','Tanggal']

			,colModel:[
			{name:'rID',index:'rID', width:80, hidden:true , align :'right'}
			,{name:'r2',index:'r2', width:80, hidden:true, align :'right'}
			,{name:'r10',index:'r10', width:150, 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:40, editable: false, formatter:'checkbox',  align: "center",stype: "select", searchoptions: { value: "-100:All;1:Yes;0:No" }}
 	
     		,{name:'r8',index:'r8', width:190, hidden:false, align :'left'}
			,{name:'r9',index:'r9', width:190, 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_belibc27_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:190, hidden:false, align :'left'}
            ,{name:'r1',index:'r1', width:100, hidden:false, align :'left'}
			,{name:'r6',index:'r6', width:100, hidden:false, align :'left'}
			,{name:'r7',index:'r7', width:100, hidden:false, align :'left'}

 
		
			],
			rowNum:10,
			rowList:[10,20,30],
			pager: '#ppasi_ceisa_belibc27_tbl',
			sortname: 'r1',
			viewrecords: true,
			sortorder: "desc",
			width: '',
			height: 100,
			//width: 950,
			//height:300,
			jsonReader: { repeatitems : false },
			caption:"Data Invoice Pembelian (BC27)",
			rownumbers: true,
			loadonce: false,
			shrinkToFit: false,
			multiselect: false,
			afterInsertRow: function(rowid, aData){
 
			},
		    onSelectRow: function(rowid){ 
				var rowData = $("#pasi_ceisa_belibc27_tbl").getRowData(rowid); 
	/*	 		if (rowData.rg == 'Yes' ){
					$("#pasi_ceisa_belibc27_map_supplier").show();
				}
				else{
					$("#pasi_ceisa_belibc27_map_supplier").hide();
			   } */
	 
  		 	 },
			gridComplete: function(){
				var rowIDs = jQuery("#pasi_ceisa_belibc27_tbl").getDataIDs(); 
				var rowData = $("#pasi_ceisa_belibc27_tbl").getRowData();
			    
				for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = jQuery("#"+ rowIDs[i],jQuery('#pasi_ceisa_belibc27_tbl'));
				   
 
				}
			}, 
		}); 
		
		jQuery("#pasi_ceisa_belibc27_tbl").jqGrid('setGroupHeaders', 
            { useColSpanStyle: true, groupHeaders:[
			{startColumnName: 'r3', numberOfColumns: 3, titleText: '<em><center>Dokumen</center></em>'},
 			{startColumnName: 'r4', numberOfColumns: 2, titleText: '<em><center>Supplier</center></em>'}, 
 			{startColumnName: 'r6', numberOfColumns: 2, titleText: '<em><center>Create</center></em>'}, 

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


 


    });



</script>

	
	