<div id="container_pasi_ceisa_master_file_sa" style="height:100%; margin:0px; padding:0px;overflow:'hidden'; border: 0px solid #cd0a0a">
	<div class="pane-header ui-state-active" id="pasi_ceisa_master_file_sa_bar" >  
		<button type="button" id="pasi_ceisa_master_file_sa_add">Sync File</button> 
		<button type="button" id="pasi_ceisa_master_file_sa_prosses">Prosses File</button> 
		<button type="button" id="pasi_ceisa_master_file_sa_delete">Delete File</button> 
	</div>
<table id="pasi_ceisa_master_file_sa_tbl"></table> <div id="ppasi_ceisa_master_file_sa_tbl"></div>
</div> 

<script type="text/javascript">
    
    $(document).ready(function(){
		$(window).bind('resize', function() {  
			setTimeout(function(){
				setGridHight($("#pasi_ceisa_master_file_sa_tbl"),$("#container_pasi_ceisa_master_file_sa"),$("#pasi_ceisa_master_file_sa_bar")); 
			},10); 
		}); 
		
	$("#pasi_ceisa_master_file_sa_add").button();
	$("#pasi_ceisa_master_file_sa_prosses").button(); 
	$("#pasi_ceisa_master_file_sa_delete").button(); 
	 
	$("#pasi_ceisa_master_file_sa_add").button().click(function(){  
		if (window.FormData) {  
			var $dialog =  $('<div />')
							.html(' <div class="ui-layout-content ui-widget-content-panel">\
										<table width="100%" border="0"> \
											<tr>\
												<td>File: </td>\
												<td><div align="center">:</div></td>\
												<td>\
												<input id="pasi_sa_file_name"  name="pasi_sa_file_name"  type="file" style="width:100%" >\
												</td>\
											</tr>\
										</table>\
								   </div>\
									<div class="pane-footer ui-state-default"></div> ') 
								.dialog({
								 modal:true,
									width : 550,
									height : 150,
									title :'UPLOAD FILE SA',
									buttons: {
										"CLOSE": function(){
												$dialog.dialog("close");   
										},
										"UPLOAD": function() {  
										var formData = new FormData();
											formData.append('file', $('input[type=file]')[0].files[0]);  
										 	$.ajax({
												type: 'POST',
												url : '<?php echo base_url().'pasi_ceisa_master/ct_pasi_file_sa/upload_file'; ?>' ,                
												data: formData,
												dataType : 'json',
												async :false,
												processData: false,
												contentType: false,
												success: function(msg){
													if (msg.valid==true){
														alert(msg.stsmsg);
														$dialog.dialog("close");   
													}else{ 
															alert(msg.stsmsg);
													}
												}
											}).done(function() { 
											
											}); 
										}
									},
									close : function(){
										$dialog.dialog('destroy').remove(); 
										jQuery("#pasi_ceisa_master_file_sa_tbl").trigger('reloadGrid');
									},
									open: function(){
										$("body").unblock(); 
									}
								}); 
				}else{
					console.log('browser not support or  javascript disable');
				}  
			}); 
	 
	jQuery("#pasi_ceisa_master_file_sa_prosses").click(function(){
			var mark_id = jQuery('#pasi_ceisa_master_file_sa_tbl').jqGrid('getGridParam','selrow');   
			if(!mark_id){ alert("Select SA ");} 
			else {
				var ret = jQuery("#pasi_ceisa_master_file_sa_tbl").jqGrid('getRowData',mark_id);    
				var $dialog = jQuery('<div \>')
				 .html(' <div class="ui-layout-content ui-widget-content-panel">\
										 Apakah file akan di prosses ? \
								   </div>\
									<div class="pane-footer ui-state-default"></div> ')
				 .dialog({
					modal:true,
					width : 300,
					height : 150,
						title :'PROSSES FIE',
						buttons: {
										"CLOSE": function(){
											$dialog.dialog("close");  
										},
										"PROSSES": function() {  
								 			var form_data = {
											file_data_id 	: ret.rID
											};
											$.ajax({    
												url:'<?php echo base_url().'pasi_ceisa_master/ct_pasi_file_sa/prosses_file'; ?>',
												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_master_file_sa_tbl').trigger('reloadGrid');
						},
						open: function(){
							$("body").unblock(); 
						}
					});
			} 
	});
	 
	jQuery("#pasi_ceisa_master_file_sa_tbl").jqGrid({
			url:'<?php echo base_url().'pasi_ceisa_master/ct_pasi_file_sa/loaddata'; ?>',
			mtype : "post",
			postData:{'q':'<?php echo base_url().'pasi_ceisa_master/ct_pasi_file_sa/loaddata'; ?>'},
			datatype: "json",
			colNames:[
			'file_data_id','file_type_id','Status','file_name','file_url'
			,'status_file_id','Date','By'
			,'date','by'
			]
			 
			,colModel:[
			{name:'rID',index:'rID', width:80, hidden:true, align :'right'}
			,{name:'r1',index:'r1', width:80, hidden:true, align :'right'} 
			,{name:'r7',index:'r7', width:80, stype: 'select', search:true, searchoptions:{searchhidden: true, value: '-100:All;0:SUKSES;1:PROCESSED'}}
 			,{name:'r2',index:'r2', width:200, hidden:false, align :'left'}
			,{name:'r3',index:'r3', width:350, hidden:false, align :'left'}
			
			,{name:'r6',index:'r6', width:80, hidden:true, align :'right'}
			,{name:'r8',index:'r8', width:100, hidden:false, align :'left', searchoptions:{searchhidden: true,dataInit:function(el){$(el).datepicker({onSelect: function(date){jQuery("#pasi_dt_file")[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:'r9',index:'r9', width:80, hidden:false, align :'left'}
	
			,{name:'r4',index:'r4', width:100, hidden:false, align :'left', searchoptions:{searchhidden: true,dataInit:function(el){$(el).datepicker({onSelect: function(date){jQuery("#pasi_dt_file")[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:80, hidden:false, align :'left'}
			
	 
			],
			rowNum:10,
			rowList:[10,20,30],
			pager: '#ppasi_ceisa_master_file_sa_tbl',
			sortname: 'r1',
			viewrecords: true,
			sortorder: "desc",
			width: '',
			height: 100,
			//width: 950,
			//height:300,
			jsonReader: { repeatitems : false },
			caption:"Data File SA",
			rownumbers: true,
			loadonce: false,
			shrinkToFit: false,
			multiselect: false,
			afterInsertRow: function(rowid, aData){
				/*switch (aData.statusdok) {
					case 'DATA SENT':
						jQuery("#pasi_ceisa_master_file_sa_tbl").jqGrid('setCell',rowid,'statusdok','',{color:'green'});
					break;
					case '2':
						jQuery("#pasi_ceisa_master_file_sa_tbl").jqGrid('setCell',rowid,'statusdok','',{color:'red'});
					break;
					case '1':
						jQuery("#pasi_ceisa_master_file_sa_tbl").jqGrid('setCell',rowid,'statusdok','',{color:'blue'});
					break;
					
				} */
			},
			gridComplete: function(){
				var rowIDs = jQuery("#pasi_ceisa_master_file_sa_tbl").getDataIDs(); 
				var rowData = $("#pasi_ceisa_master_file_sa_tbl").getRowData();
			
				for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = jQuery("#"+ rowIDs[i],jQuery('#pasi_ceisa_master_file_sa_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_master_file_sa_tbl").jqGrid('setGroupHeaders', 
            { useColSpanStyle: true, groupHeaders:[
			{startColumnName: 'r2', numberOfColumns: 2, titleText: '<em><center>FILE</center></em>'},
			{startColumnName: 'r8', numberOfColumns: 2, titleText: '<em><center>Status</center></em>'},
			{startColumnName: 'r4', numberOfColumns: 2, titleText: '<em><center>Create</center></em>'}, 
        ] });
			               
		jQuery("#pasi_ceisa_master_file_sa_tbl").jqGrid('navGrid','#ppasi_ceisa_master_file_sa_tbl',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#pasi_ceisa_master_file_sa_tbl").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});
	
	
		
	setTimeout(function(){
			setGridHight($("#pasi_ceisa_master_file_sa_tbl"),$("#container_pasi_ceisa_master_file_sa"),$("#pasi_ceisa_master_file_sa_bar")); 
		},100); 
	});
		  	
</script>

	
	