<style>
table.excel {
	border-style:ridge;
	border-width:1;
	border-collapse:collapse;
	font-family:sans-serif;
	font-size:12px;
}
table.excel thead th, table.excel tbody th {
	background:#CCCCCC;
	border-style:ridge;
	border-width:1;
	text-align: center;
	vertical-align:bottom;
}
table.excel tbody th {
	text-align:center;
	width:20px;
}
table.excel tbody td {
	vertical-align:bottom;
}
table.excel tbody td {
    padding: 0 3px;
	border: 1px solid #EEEEEE;
}
</style>

<div style="height:10px;">
	
</div>
<div id="tab_mpk_data_out" style="height:400px">
	<ul>
		<li><a id="idtab_mpk_datadata_out" href="#divtab_mpk_datadata_out">Data IN</a></li>
		<li><a id="idtab_mpk_uploaddata_out" href="#divtab_mpk_uploaddata_out">Upload Data</a></li>
		<li><a id="idtab_mpk_draftdata_out" href="#divtab_mpk_draftdata_out">Proses Uploaded Data</a></li>
		
	</ul>
	
	<div id="divtab_mpk_datadata_out" >
		<table id="tbldata_out_mpk"></table> <div id="ptbldata_out_mpk"></div>
	</div>
	<div id="divtab_mpk_uploaddata_out" >
		Upload Data Out Mesin dan Peralatan Kantor
	   <form method="post" action="" id="upload_file_data_out">
		  <label for="userfile_data_out_mpk">File</label>
		  <input type="file" name="userfile_data_out_mpk" id="userfile_data_out_mpk" size="40" />
		  <input type="submit" name="submit" id="submit" value="Upload" /><button id="btn_data_out_mpkdelet">Delete</button>
	   </form><span id="files_data_out_mpk" style="font-weight:bold;font-size:10px;"></span>
	   <hr>
	   <table id="tbluploaddata_out_mpk"></table> <div id="ptbluploaddata_out_mpk"></div>
	</div>
	<div id="divtab_mpk_draftdata_out" >
		<input type="hidden" id="hdndraftdata_out_mpk_uploadproses" />
		File yang akan diproses. Filename: <input type="text" id="txtfilenametdata_out_mpk_uploadproses" readonly="readonly"/>
		<button id="btncekfile_tdata_out_mpk_upload" >Cek File</button><button id="btnprosesfile_tdata_out_mpk_upload" >Proses File</button>
		<hr>
		<div id="div_cekfile_tdata_out_mpk_upload" >xls</div>
	</div>
	
</div>

<script type="text/javascript">
    
    $(document).ready(function(){
		$( "#tab_mpk_data_out" ).tabs();
		
		$("#btn_data_out_mpkdelet").click(function(){
			
			var id = jQuery("#tbluploaddata_out_mpk").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tbluploaddata_out_mpk").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};	
			var form_data = {
				id_data_mesin:ret.id_data_mesin,
				filename:ret.filename,
				tipe:ret.tipe
			
			};
			
			$("#dlguploaddata_out_mpk").dialog( "destroy" );
			$(".dlguploaddata_out_mpkcl").remove();
			$(".dlguploaddata_out_mpkcl").html('');
			$("body").append('<div id="dlguploaddata_out_mpk" title="Warning" class="dlguploaddata_out_mpkcl"><p>Apakah anda akan mendelete file ini?!?</p><br /> file = '+ ret.filename +'</div>');
			$("#dlguploaddata_out_mpk").dialog({
				height: 200,
				width: 250,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : "<?php echo base_url().'settings/ct_barangmesin/deletefile_file_data_mesin_out'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlguploaddata_out_mpk").dialog("close");
								$('#dlguploaddata_out_mpk').dialog("destroy"); 
								$(".dlguploaddata_out_mpkcl").remove(); 
								$('#tbluploaddata_out_mpk').trigger('reloadGrid');
							} else { 
								alert(msg.sts+' '+msg.desc); 
								$("#dlguploaddata_out_mpk").dialog("close");
								$('#dlguploaddata_out_mpk').dialog("destroy"); 
								$(".dlguploaddata_out_mpkcl").remove(); 

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

					}
				},
				close : function(){
					$('#dlguploaddata_out_mpk').dialog("destroy"); 
					$(".dlguploaddata_out_mpkcl").remove(); 
					$("body").append('<div id="dlguploaddata_out_mpk" title="Warning" class="dlguploaddata_out_mpkcl"><p>Apakah anda akan mendelete file ini?!?</p></div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});
		
		});
		
		$("#idtab_mpk_draftdata_out").click(function(){
			var id = jQuery("#tbluploaddata_out_mpk").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tbluploaddata_out_mpk").jqGrid('getRowData',id);
				
			} else {
				alert('Pilih data yang akan diproses..');
				$("#tab_mpk_data_out").tabs("select", 1);
				return false;
			};
			
			if(ret.status_upload != 'SUKSES'){
			
				alert('Data tidak bisa diproses, lihat status');
				$("#tab_mpk_data_out").tabs("select", 1);
				return false;
			
			}
			
			$("#txtfilenametdata_out_mpk_uploadproses").val(ret.filename);
			
		
		});
		
		$("#btncekfile_tdata_out_mpk_upload").click(function(){
		
			var id = jQuery("#tbluploaddata_out_mpk").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tbluploaddata_out_mpk").jqGrid('getRowData',id);
				
			} else {
				alert('Pilih data yang akan diproses');
				$("#tab_mpk_data_out").tabs("select", 1);
				return false;
			};
			
			
			if(ret.status_upload != 'SUKSES'){
			
				alert('Data tidak bisa diproses, lihat status');
				$("#tab_mpk_data_out").tabs("select", 1);
				return false;
			
			}
			 var form_data = {
				filename:ret.filename,
				
			 };
			 
			 
			 $.ajax({
				url: "<?php echo base_url().'settings/ct_barangmesin/cek_data_out_mpk'; ?>",
				type: "POST",
				data: form_data,
				success:function(result){
					$("#div_cekfile_tdata_out_mpk_upload").html(result);
				 }
				
			});
			
			
			
		});
		
		$("#btnprosesfile_tdata_out_mpk_upload").click(function(){
		
			var id = jQuery("#tbluploaddata_out_mpk").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tbluploaddata_out_mpk").jqGrid('getRowData',id);
				
			} else {
				alert('Pilih data yang akan diproses');
				$("#tab_mpk_data_out").tabs("select", 1);
				return false;
			};
			
			if(ret.status_upload != 'SUKSES'){
			
				alert('Data tidak bisa diproses, lihat status');
				$("#tab_mpk_data_out").tabs("select", 1);
				return false;
			
			}
			
			var form_data = {
				filename:ret.filename,
				tipe:ret.tipe,
				id_mesin_data_out:ret.id_data_mesin
			};
			
			$("#dlguploaddata_out_mpk_proses_").dialog( "destroy" );
			$(".dlguploaddata_out_mpk_proses_cl").remove();
			$(".dlguploaddata_out_mpk_proses_cl").html('');
			$("body").append('<div id="dlguploaddata_out_mpk_proses_" title="Warning" class="dlguploaddata_out_mpk_proses_cl"><p>Apakah anda akan memproses file ini?!?</p><br /> file = '+ ret.filename +'</div>');
			$("#dlguploaddata_out_mpk_proses_").dialog({
				height: 200,
				width: 250,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : "<?php echo base_url().'settings/ct_barangmesin/proses_mesin_data_out_add'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlguploaddata_out_mpk_proses_").dialog("close");
								$('#dlguploaddata_out_mpk_proses_').dialog("destroy"); 
								$(".dlguploaddata_out_mpk_proses_cl").remove(); 
								$('#tbluploaddata_out_mpk').trigger('reloadGrid');
								jQuery("#tbldata_out_mpk").trigger('reloadGrid');
								$("#tab_mpk_data_out").tabs("select", 0);
							} else { 
								alert(msg.sts+' '+msg.desc); 
								$("#dlguploaddata_out_mpk_proses_").dialog("close");
								$('#dlguploaddata_out_mpk_proses_').dialog("destroy"); 
								$(".dlguploaddata_out_mpk_proses_cl").remove(); 

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

					}
				},
				close : function(){
					$('#dlguploaddata_out_mpk_proses_').dialog("destroy"); 
					$(".dlguploaddata_out_mpk_proses_cl").remove(); 
					$("body").append('<div id="dlguploaddata_out_mpk_proses_" title="Warning" class="dlguploaddata_out_mpk_proses_cl"><p>Apakah anda akan memproses file ini?!?</p></div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});	
		});
		
		$('#userfile_data_out_mpk').live('change', function(){
			$('#files_data_out_mpk').html('Files: '+ $('#userfile_data_out_mpk').val() +' '); 
		});
		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_file_data_out').submit(function(e) {
				e.preventDefault();
				$.ajaxFileUpload({
				 url         :'./settings/ct_barangmesin/upload_file_data_mesin_out/',
				 secureuri      :false,
				 fileElementId  :'userfile_data_out_mpk',
				 dataType    : 'json',
				 data        : {
					'userfile_data_out_mpk'  : $('#userfile_data_out_mpk').val()
				 },
				 success  : function (data, status)
				 {
					if(data.status != 'error')
					{
					   $('#files_data_out_mpk').html('Upload File Sukses...'+ $('#userfile_data_out_mpk').val() +' ;p'); 
					   
					   
					 
					}
					alert(data.msg);
					$('#tbldata_out_mpk').trigger('reloadGrid');
					$('#tbluploaddata_out_mpk').trigger('reloadGrid');
					
				 }
		  });
		  return false;
		   });
		});
		
		jQuery("#tbluploaddata_out_mpk").jqGrid({
			url:'<?php echo base_url().'settings/ct_barangmesin/data_uploaduploadmesin_in_out'; ?>',
			mtype : "post",
			postData:{'tipedata':'MPKOUT'},
			datatype: "json",
			colNames:['ID','filename', 'date upload','status upload', 'tipe', 'create date', 'create by','path'],
			colModel:[
				{name:'id_data_mesin',index:'id_data_mesin', width:60, hidden:true},
				{name:'filename',index:'filename', width:160},
				{name:'date_upload',index:'date_upload', width:166,stype:"text",searchoptions:{sopt:['eq','cn','gt','lt'],dataInit:function(el){$(el).datepicker({changeYear: true,showButtonPanel: true,changeMonth: true,dateFormat:'dd/mm/yy'});} }},
				{name:'status_upload',index:'status_upload', width:106},
				{name:'tipe',index:'tipe', width:106},
				{name:'create_date',index:'create_date', width:166, hidden:false,stype:"text",searchoptions:{sopt:['eq','cn','gt','lt'],dataInit:function(el){$(el).datepicker({changeYear: true,showButtonPanel: true,changeMonth: true,dateFormat:'yy-mm-dd'});} }},
				{name:'create_by',index:'create_by', width:106, hidden:false},
				{name:'filepath',index:'filepath', width:106, hidden:true}
			
				],
			rowNum:10,
			rowList:[10,20,30],
			pager: '#ptbluploaddata_out_mpk',
			sortname: 'id_data_mesin',
			viewrecords: true,
			sortorder: "desc",
			width: 840,
			height:200,
			jsonReader: { repeatitems : false },
			caption:"List of Files Upload",
			rownumbers: true,
			shrinkToFit: false,
			afterInsertRow: function(){
				
				
			},			
			gridComplete: function(){
				var rowIDs = jQuery("#tbluploaddata_out_mpk").getDataIDs(); 
				var rowData = $("#tbluploaddata_out_mpk").getRowData();
			
				for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = jQuery("#"+ rowIDs[i],jQuery('#tbluploaddata_out_mpk'));
				   
					switch (rowData[i].status_upload) {
						
						case 'cancel':
						   trElement.css({"color":"green"});
						break;
						case 'Deleted':
						   trElement.css({"color":"red", "text-decoration": "line-through"});
						break;
						case 'DATA PROCESSED':
						   trElement.css({"color":"blue"});
						break;
						
						
					}
				}
			},
		}); 
		
		jQuery("#tbluploaddata_out_mpk").jqGrid('navGrid','#ptbluploaddata_out_mpk',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#tbluploaddata_out_mpk").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});
		
		
		jQuery("#tbldata_out_mpk").jqGrid({
			url:'<?php echo base_url().'settings/ct_barangmesin/data_dt_mpk_out'; ?>',
			mtype : "post",
			postData:{'q':'1'},
			datatype: "json",
			colNames:[
				'id_mpk_out'
			    ,'date'
				,'no dok in'
				,'kode barang'
			  ,'part name'
			    ,'part name customs'
			  ,'qty in'
			  ,'qty_out'
			 ,'unit in'
			  ,'unit_konversi'
			  ,'pengali'
			  ,'box'
			  ,'pack'
			  ,'harga'
			  ,'kdval'
			],
			colModel:[
				{name:'id_mpk_out',index:'id_mpk_out', width:60, hidden:true},
				{name:'date_out',index:'date_out', width:85, searchoptions:{sopt:['eq','cn','gt','lt'],dataInit:function(el){$(el).datepicker({dateFormat:'yy-mm-dd'});} }},
				{name:'no_out',index:'no_out', width:145},
				{name:'part_no',index:'part_no', width:108},
				{name:'part_name',index:'part_name', width:200, hidden:false},
				{name:'part_name_customs',index:'part_name_customs', width:200, hidden:true},
				{name:'qty_out',index:'qty_out', width:113, hidden:false, align:'right'},
				{name:'qty_out',index:'qty_out', width:113, hidden:true, align:'right'},
				{name:'unit_out',index:'unit_out', width:113, hidden:false},
				{name:'unit_konversi',index:'unit_konversi', width:113, hidden:true, align:'right'},
				{name:'pengali',index:'pengali', width:113, hidden:true, align:'right'},
				{name:'box',index:'box', width:113, hidden:true, align:'right'},
				{name:'pack',index:'pack', width:113, hidden:true, align:'right'},
				{name:'harga',index:'harga', width:113, hidden:true, align:'right'},
				{name:'kdval',index:'kdval', width:113, hidden:true, align:'right'},
				
				],
			rowNum:10,
			rowList:[10,20,30],
			pager: '#ptbldata_out_mpk',
			sortname: 'id_mpk_out',
			viewrecords: true,
			sortorder: "desc",
			width: 840,
			height:261,
			jsonReader: { repeatitems : false },
			caption:"DATA OUT MESIN DAN ALAT KANTOR",
			rownumbers: true,
			shrinkToFit: false,
			afterInsertRow: function(){
				
				
			},			
			gridComplete: function(){
				var rowIDs = jQuery("#tbldata_out_mpk").getDataIDs(); 
				var rowData = $("#tbldata_out_mpk").getRowData();
			
				for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = jQuery("#"+ rowIDs[i],jQuery('#tbldata_out_mpk'));
				   
					switch (rowData[i].status) {
						
						case 'DATA PROCESSED':
						   trElement.css({"color":"green"});
						break;
						case 'APPROVED':
						   trElement.css({"color":"red"});
						break;
					}
				}
			},
		}); 
			
                        
		jQuery("#tbldata_out_mpk").jqGrid('navGrid','#ptbldata_out_mpk',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#tbldata_out_mpk").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});
		

	});
		  	
</script>



	
	