
<div id="container_pasi_ceisa_bc_out<?php echo $bc_prefix;  ?>_sa_tbl_sa_list2" style="height:100%; margin:0px; padding:0px;overflow:'hidden'; border: 0px solid #cd0a0a">
	<div class="pane-header ui-state-active" id="pasi_ceisa_bc_out<?php echo $bc_prefix;  ?>_sa_tbl_sa_list2_bar" >
	<table>
		<tr>
			<td>LIST SA    </td>
			<td style="padding-left:20px">
				<button type="button" id="pasi_ceisa_bc_<?php echo $bc_prefix;  ?>_out_sa_add">Add</button>  
				<button type="button" id="pasi_ceisa_bc_<?php echo $bc_prefix;  ?>_out_sa_delete">Delete</button>  
			</td>
		</tr> 
	</table> 
</div>
<table id="pasi_ceisa_bc_out<?php echo $bc_prefix;  ?>_sa_tbl_sa_list2"></table> <div id="ppasi_ceisa_bc_out<?php echo $bc_prefix;  ?>_sa_tbl_sa_list2"></div>
</div> 

<script type="text/javascript">
 	
    $(document).ready(function(){ 
	
	
		var ceisa_bc_out<?php echo $bc_prefix;  ?>_cust_code='<?php echo $cust_code;  ?>';
		$(window).bind('resize', function() {  
			setTimeout(function(){
	 			setGridHight($("#pasi_ceisa_bc_out<?php echo $bc_prefix;  ?>_sa_tbl_sa_list2"),$("#container_pasi_ceisa_bc_out<?php echo $bc_prefix;  ?>_sa_tbl_sa_list2"),$("#pasi_ceisa_bc_out<?php echo $bc_prefix;  ?>_sa_tbl_sa_list2_bar")); 
			},10); 
		});  
		
   $("#pasi_ceisa_bc_<?php echo $bc_prefix;  ?>_out_sa_add").button(); 
	$("#pasi_ceisa_bc_<?php echo $bc_prefix;  ?>_out_sa_delete").button();  
		
    jQuery("#pasi_ceisa_bc_<?php echo $bc_prefix;  ?>_out_sa_add").click(function(){  
		var $dialog = jQuery('<div \>')
		 .load('<?php echo base_url().'pasi_ceisa_bc_out/ct_pasi_ceisa_bc_out_from_sa'; ?>',{bc_prefix:'<?php echo $bc_prefix;  ?>',cust_code:'<?php echo $cust_code;  ?>',id_header:'<?php echo $id_header;  ?>',mode:'1'})
		 .dialog({
			modal:true,
			width : 600,
			height : 400,
			title :'ADD SA',
				buttons: {
					"CLOSE": function(){
						$dialog.dialog("close");  
					} ,
					"ADD SA": function(){ 
					 	var selRowIds;
							 selRowIds =  $("#pasi_ceisa_bc_out<?php echo $bc_prefix;  ?>_sa_tbl_sa_list").jqGrid('getGridParam','selarrrow'); 
							if (selRowIds.length ==0){
								 alert("Harus memiliki minimal 1 SA, pilih SA");
								 exit;
							 } 
							var myArray = [];
							for (var i = 0; i < selRowIds.length; i++) 
							{
								var rowId = selRowIds[i];
								var idnya =  $('#pasi_ceisa_bc_out<?php echo $bc_prefix;  ?>_sa_tbl_sa_list').getCell(rowId, 'rID'); 
								myArray.push(idnya);
							} 
					 
							var form_edit = {
									bc_prefix :'<?php echo $bc_prefix;  ?>',      
									id_header :'<?php echo $id_header;  ?>',       
									lstsa  : myArray  
							}; 
							
							$.ajax({    
							url:'<?php echo base_url().'pasi_ceisa_bc_out/ct_pasi_ceisa_bc_out_from_sa/add_sa'; ?>',
							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_bc_out<?php echo $bc_prefix;  ?>_sa_tbl_sa_list2').trigger('reloadGrid'); 
				},
				open: function(){
					$("body").unblock(); 
				}
			}); 
	}); 
	
	
    jQuery("#pasi_ceisa_bc_<?php echo $bc_prefix;  ?>_out_sa_delete").click(function(){  
		 
					 	var selRowIds;
							 selRowIds =  $("#pasi_ceisa_bc_out<?php echo $bc_prefix;  ?>_sa_tbl_sa_list2").jqGrid('getGridParam','selarrrow'); 
							if (selRowIds.length ==0){
								 alert("Harus memiliki minimal 1 SA, pilih SA");
								 exit;
							 } 
							var myArray = [];
							for (var i = 0; i < selRowIds.length; i++) 
							{
								var rowId = selRowIds[i];
								var idnya =  $('#pasi_ceisa_bc_out<?php echo $bc_prefix;  ?>_sa_tbl_sa_list2').getCell(rowId, 'rID'); 
								myArray.push(idnya);
							} 
					 
							var form_edit = {
									bc_prefix :'<?php echo $bc_prefix;  ?>',      
									id_header :'<?php echo $id_header;  ?>',       
									lstsa  : myArray  
							}; 
							
							$.ajax({    
							url:'<?php echo base_url().'pasi_ceisa_bc_out/ct_pasi_ceisa_bc_out_from_sa/delete_sa'; ?>',
							type : 'POST',
								data : form_edit,
								dataType: 'json',
								success: function(msg){
									if (msg.valid){
										$('#pasi_ceisa_bc_out<?php echo $bc_prefix;  ?>_sa_tbl_sa_list2').trigger('reloadGrid');
										alert(msg.stsmsg);    
									} else { alert(msg.stsno+msg.stsmsg);  }
								} 
							}); 
				 
	}); 
	
		
		
		jQuery("#pasi_ceisa_bc_out<?php echo $bc_prefix;  ?>_sa_tbl_sa_list2").jqGrid({
			url:'<?php echo base_url().'pasi_ceisa_master/ct_pasi_sa/loaddata'; ?>',
			datatype: "json",
			mtype : "post",
			postData:{	id_header:'<?php echo $id_header;  ?>'
						,cust_code:'<?php echo $cust_code;  ?>'
						,bc_prefix:'<?php echo $bc_prefix;  ?>'
						,mode :'0'
						},
	 		colNames:[
					'dt_sa_sa_id','SA','CUST CODE','Invoice\'S','Item\'S','dt_sa_file_data_id'
			  		]
			,colModel:[
					{name:'rID',index:'rID', width:80, hidden:true, align :'right'}
					,{name:'r1',index:'r1', width:220, hidden:false, align :'right'}
					,{name:'r2',index:'r2', width:80, hidden:false, align :'right'}
					,{name:'r3',index:'r3', width:70, hidden:false, align :'right'}
					,{name:'r4',index:'r4', width:55, hidden:false, align :'right'}
					,{name:'r5',index:'r5', width:65, hidden:true, align :'right'}  
					],
		//	rowNum:-1,
			multiselect: true, 
			rowNum:100,
		 	rowList:[10,20,30,50,100,200],
	 		pager: '#ppasi_ceisa_bc_out<?php echo $bc_prefix;  ?>_sa_tbl_sa_list2',
			sortname: 'r1',
			viewrecords: true,
			sortorder: "desc",
			width: '',
			height: 100,
			//width: 950,
			//height:300,
			jsonReader: { repeatitems : false }, 
			rownumbers: true,
			loadonce: false,
			shrinkToFit: false, 
			afterInsertRow: function(rowid, aData){
				/*switch (aData.statusdok) {
					case 'DATA SENT':
						jQuery("#pasi_ceisa_bc_out<?php echo $bc_prefix;  ?>_sa_tbl_sa_list2").jqGrid('setCell',rowid,'statusdok','',{color:'green'});
					break;
					case '2':
						jQuery("#pasi_ceisa_bc_out<?php echo $bc_prefix;  ?>_sa_tbl_sa_list2").jqGrid('setCell',rowid,'statusdok','',{color:'red'});
					break;
					case '1':
						jQuery("#pasi_ceisa_bc_out<?php echo $bc_prefix;  ?>_sa_tbl_sa_list2").jqGrid('setCell',rowid,'statusdok','',{color:'blue'});
					break;
					
				} */
			},
			gridComplete: function(){
				var rowIDs = jQuery("#pasi_ceisa_bc_out<?php echo $bc_prefix;  ?>_sa_tbl_sa_list2").getDataIDs(); 
				var rowData = $("#pasi_ceisa_bc_out<?php echo $bc_prefix;  ?>_sa_tbl_sa_list2").getRowData();
			
				for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = jQuery("#"+ rowIDs[i],jQuery('#pasi_ceisa_bc_out<?php echo $bc_prefix;  ?>_sa_tbl_sa_list2'));
				   
					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_bc_out<?php echo $bc_prefix;  ?>_sa_tbl_sa_list2").jqGrid('navGrid','#ppasi_ceisa_bc_out<?php echo $bc_prefix;  ?>_sa_tbl_sa_list2',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#pasi_ceisa_bc_out<?php echo $bc_prefix;  ?>_sa_tbl_sa_list2").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});
		 
	
	setTimeout(function(){
	 		setGridHight($("#pasi_ceisa_bc_out<?php echo $bc_prefix;  ?>_sa_tbl_sa_list2"),$("#container_pasi_ceisa_bc_out<?php echo $bc_prefix;  ?>_sa_tbl_sa_list2"),$("#pasi_ceisa_bc_out<?php echo $bc_prefix;  ?>_sa_tbl_sa_list2_bar")); 
	},100); 
	});
		  	
</script>

	
	