<div id="tabdata_img_surat_jalan_ar_c_ar" style="height:100%; margin:0px; padding:0px;overflow:'hidden'; border: 0px solid #cd0a0a">
	<div id="tabdata_img_surat_jalan_ar" style="height:100%;margin:0px; padding:0px;">
		<ul> 
			<li><a id="tab_img_surat_jalan_data_ar" href="#div_tab_img_surat_jalan_data_ar">DATA SURAT JALAN</a></li>
			<li><a id="tab_img_surat_jalan_data_ar_trx" href="#div_img_surat_jalan_data_ar_trx">IMAGE UPLOADED</a></li>
		</ul>
		<div id="div_tab_img_surat_jalan_data_ar" >
			<div class="pane-header ui-state-active" id="div_tab_img_surat_jalan_data_bar_ar" >    
				<form method="post" action="" id="upload_fileinv_ar">
				  <label for="img_surat_jalan_upload_ar">Image</label>
				  <input type="file" name="img_surat_jalan_upload_ar" id="img_surat_jalan_upload_ar" size="40" />
				  <input type="submit" name="submit_ar" id="submit_image_ar" value="upload" />
			   </form> 
				
			</div>
			<table id="tbl_img_surat_jalan_ar"></table> <div id="ptbl_img_surat_jalan_ar"></div>
		</div>
		<div id="div_img_surat_jalan_data_ar_trx" >
			<div class="pane-header ui-state-active" id="div_img_surat_jalan_data_trx_bar_ar" >    
				<button id="btn_img_surat_jalan_delete_ar" >DELETE</button> 
			</div>
			<table id="tbl_img_surat_jalan_ar_upload"></table> <div id="ptbl_img_surat_jalan_ar_upload"></div>
			
		</div>
	</div>
</div>
<script type="text/javascript">
    
    $(document).ready(function(){ 
		var tabdata_img_surat_jalan_ar_active_tab=0;
		setTimeout(function(){
			setGridHight($("#tbl_img_surat_jalan_ar"),$("#tabdata_img_surat_jalan_ar"),$("#div_tab_img_surat_jalan_data_bar_ar"),$("#tabdata_img_surat_jalan_ar .ui-tabs-nav").height()+30); 
		},20); 
		$("#tabdata_img_surat_jalan_ar" ).tabs({                                                                  
            select:function(event,ui){    
			
				tabdata_img_surat_jalan_ar_active_tab=ui.index;   
				
		 		if (tabdata_img_surat_jalan_ar_active_tab==0){
					setTimeout(function(){
						setGridHight($("#tbl_img_surat_jalan_ar"),$("#tabdata_img_surat_jalan_ar"),$("#div_tab_img_surat_jalan_data_bar_ar"),$("#tabdata_img_surat_jalan_ar .ui-tabs-nav").height()+30); 
					},20); 
				}else if (tabdata_img_surat_jalan_ar_active_tab==1){
					setTimeout(function(){
						setGridHight($("#tbl_img_surat_jalan_ar_upload"),$("#tabdata_img_surat_jalan_ar"),$("#div_img_surat_jalan_data_trx_bar_ar"),$("#tabdata_img_surat_jalan_ar .ui-tabs-nav").height()+30); 
					},20); 
				}
			}                                                                          
         });   		
			 
			 
		$(window).bind('resize', function() {  
				if (tabdata_img_surat_jalan_ar_active_tab==0){
					setTimeout(function(){
						setGridHight($("#tbl_img_surat_jalan_ar"),$("#tabdata_img_surat_jalan_ar"),$("#div_tab_img_surat_jalan_data_bar_ar"),$("#tabdata_img_surat_jalan_ar .ui-tabs-nav").height()+30); 
					},100); 
				}else if (tabdata_img_surat_jalan_ar_active_tab==1){
					setTimeout(function(){
						setGridHight($("#tbl_acc_img_surat_jalan_trx"),$("#tabdata_img_surat_jalan_ar"),$("#div_img_surat_jalan_data_trx_bar_ar"),$("#tabdata_img_surat_jalan_ar .ui-tabs-nav").height()+30); 
					},100); 
				}
		});
		
		jQuery.extend({
			handleError: function( s, xhr, status, e ) {
			// If a local callback was specified, fire it
			if ( s.error )
				s.error( xhr, status, e );
			// If we have some XML response text (e.g. from an AJAX call) then log it in the console
			else if(xhr.responseText)
				console.log(xhr.responseText);
			}
		});
		$(function() {
			$('#upload_fileinv_ar').submit(function(e) {
				var id = jQuery("#tbl_img_surat_jalan_ar").jqGrid('getGridParam','selrow');
				if (id) { 
					var ret = jQuery("#tbl_img_surat_jalan_ar").jqGrid('getRowData',id);
					
				} else {
					alert("Please Select Row");
					return false;
				};
				
				
			  //alert("test");
			  e.preventDefault();
			  $.ajaxFileUpload({
				 url         :'./accounting_report/ct_accounting_report/upload_file/',
				 secureuri      :false,
				 fileElementId  :'img_surat_jalan_upload_ar',
				 dataType    : 'json',
				 data        : {
					'userfile'  : $('#img_surat_jalan_upload_ar').val(),
					'tipe' : 'SJ_AR',
					'no_inv':ret.CARRIER,
					'tgl_inv':ret.TGDAFT,
					'fileElementId':'img_surat_jalan_upload_ar',
					'folder':'surat_jalan_ar'
				 },
				 success  : function (data, status)
				 {
					if(data.status != 'error')
					{
					   //alert('<p>Data Sukses...'+ $('#img_surat_jalan_upload').val() +'</p>'); 
					   jQuery("#tbl_img_surat_jalan_ar_upload").trigger("reloadGrid");
					 
					}
					alert(data.msg);
				 }
			  });
			  return false;
			});
		});

		
		
		
		var form_upload = {
			
		}
		jQuery("#tbl_img_surat_jalan_ar").jqGrid({
			url:'<?php echo base_url().'accounting_report/ct_accounting_report/data_surat_jalan_ar'; ?>',
			mtype : "post",
			postData:{'q':'1'},
			datatype: "json",
			colNames:
			[
			
			'SA',
			'CARRIER', 
			'NODAFT'
			, 'TGDAFT'
			,'NilInv'
			,'KdVal'
			,'typedok'
			
			
			],
			colModel:[
				
				{name:'bc_in_from_in',index:'bc_in_from_in', width:120},
				{name:'CARRIER',index:'CARRIER', width:90},
				{name:'NODAFT',index:'NODAFT', width:120, hidden:false},
				{name:'TGDAFT',index:'TGDAFT', width:90,hidden:false},
				{name:'NilInv',index:'NilInv', width:90,hidden:false, align:'right', formatter:'number'},
				{name:'KdVal',index:'KdVal', width:90,hidden:false},
				{name:'typedok',index:'typedok', width:90,hidden:false},
				
				],
			rowNum:20,
			rowList:[20,50,100],
			pager: '#ptbl_img_surat_jalan_ar',
			sortname: 'TGDAFT',
			viewrecords: true,
			sortorder: "desc",
			width: '',
			height:300,
			jsonReader: { repeatitems : false },
			caption:"Data Surat jalan",
			rownumbers: true,
			shrinkToFit: false,
			afterInsertRow: function(){
				
				
			},			
			gridComplete: function(){
				var rowIDs = jQuery("#tbl_img_surat_jalan_ar").getDataIDs(); 
				var rowData = $("#tbl_img_surat_jalan_ar").getRowData();
			
				for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = jQuery("#"+ rowIDs[i],jQuery('#tbl_img_surat_jalan_ar'));
				   
					switch (rowData[i].status_data) {
						
						case 'PROSESEXIM':
						   trElement.css({"color":"green"});
						break;
						case 'PROCESSEDBC':
						   trElement.css({"color":"blue"});
						break;
						
						
					}
				}
			},
		}); 
			
                        
		jQuery("#tbl_img_surat_jalan_ar").jqGrid('navGrid','#ptbl_img_surat_jalan_ar',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#tbl_img_surat_jalan_ar").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});
		
		
		jQuery("#tbl_img_surat_jalan_ar_upload").jqGrid({
			url:'<?php echo base_url().'accounting_report/ct_accounting_report/data_upload_inv'; ?>',
			mtype : "post",
			postData:{'q':'1', 'tipe':function () { return 'SJ_AR'; }},
			datatype: "json",
			colNames:
			[
			'',
			'no_inv',
			'tgl_inv', 
			'amount_inv'
			, 'link'
			,'create_by'
			,'create_date'
			,'update_by'
			,'update_date'
			,'tipe','x'
		
			
			],
			colModel:[
				{name:'id_upload_inv',index:'id_upload_inv', width:60, hidden:true},
				{name:'no_inv',index:'no_inv', width:120},
				{name:'tgl_inv',index:'tgl_inv', width:90},
				{name:'amount_inv',index:'amount_inv', width:90,hidden:false, align:'right', formatter:'number',hidden:true},
				{name:'folder',index:'folder', width:190,hidden:false},
				{name:'create_by',index:'create_by', width:250,hidden:false},
				{name:'create_date',index:'create_date', width:105,hidden:false},
				{name:'update_by',index:'update_by', width:84,hidden:false},
				{name:'update_date',index:'update_date', width:84,hidden:false},
				{name:'tipe',index:'tipe', width:60, hidden:true},
				{name:'filename',index:'filename', width:60, hidden:true}
				],
			rowNum:20,
			rowList:[20,50,100],
			pager: '#ptbl_img_surat_jalan_ar_upload',
			sortname: 'id_upload_inv',
			viewrecords: true,
			sortorder: "desc",
			width: '',
			height:300,
			jsonReader: { repeatitems : false },
			caption:"Data Image",
			rownumbers: true,
			shrinkToFit: false,
			afterInsertRow: function(){
				
				
			},			
			gridComplete: function(){
				var rowIDs = jQuery("#tbl_img_surat_jalan_ar_upload").getDataIDs(); 
				var rowData = $("#tbl_img_surat_jalan_ar_upload").getRowData();
			
				for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = jQuery("#"+ rowIDs[i],jQuery('#tbl_img_surat_jalan_ar_upload'));
				   
					switch (rowData[i].status_data) {
						
						case 'PROSESEXIM':
						   trElement.css({"color":"green"});
						break;
						case 'PROCESSEDBC':
						   trElement.css({"color":"blue"});
						break;
						
						
					}
				}
			},
		}); 
			
                        
		jQuery("#tbl_img_surat_jalan_ar_upload").jqGrid('navGrid','#ptbl_img_surat_jalan_ar_upload',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#tbl_img_surat_jalan_ar_upload").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});
		
		$("#btn_img_surat_jalan_upload").button().click(function(){
			
			
			
		});
		
		
		$("#btn_img_surat_jalan_delete_ar").button().click(function(){
			
			var id = jQuery("#tbl_img_surat_jalan_ar_upload").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tbl_img_surat_jalan_ar_upload").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};	
			var form_data = {
				id_upload_inv:ret.id_upload_inv,
				folder:ret.folder,
				tipe:ret.tipe,
				filename:ret.filename
			
			};
			$("#dlgimg_surat_jalan_upload_ar").dialog( "destroy" );
			$(".dlgimg_surat_jalan_upload_arcl").remove();
			$("body").append('<div id="dlgimg_surat_jalan_upload_ar" title="Warning" class="dlgimg_surat_jalan_upload_arcl"><p>Apakah anda akan mendelete data ini?!?</p><br /> data = '+ ret.filename +'</div>');
			$("#dlgimg_surat_jalan_upload_ar").dialog({
				height: 200,
				width: 250,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : "<?php echo base_url().'accounting_report/ct_accounting_report/delete_upload_inv';?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlgimg_surat_jalan_upload_ar").dialog("close");
								$('#dlgimg_surat_jalan_upload_ar').dialog("destroy"); 
								$(".dlgimg_surat_jalan_upload_arcl").remove(); 
								$('#tbl_img_surat_jalan_ar_upload').trigger('reloadGrid');
							} else { 
								alert(msg.sts+msg.desc); 
								$("#dlgimg_surat_jalan_upload_ar").dialog("close");
								$('#dlgimg_surat_jalan_upload_ar').dialog("destroy"); 
								$(".dlgimg_surat_jalan_upload_arcl").remove(); 

							}
						}
					});
				},
					"CANCEL": function() {
						$( "#dlgimg_surat_jalan_upload_ar" ).dialog( "close" );

					}
				},
				close : function(){
					$('#dlgimg_surat_jalan_upload_ar').dialog("destroy"); 
					$(".dlgimg_surat_jalan_upload_arcl").remove(); 
					$("body").append('<div id="dlgimg_surat_jalan_upload_ar" title="Warning" class="dlgimg_surat_jalan_upload_arcl"><p>Apakah anda akan mendelete data ini?!?</p></div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});
	
		
		
		});
		
		
		$("#submit_image").click(function(){
			var id = jQuery("#tbl_img_surat_jalan_ar").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tbl_img_surat_jalan_ar").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};
			
			
		});
		
	
	
	});
</script>