<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="tabdata_scrap_bahanbaku_sta" style="height:400px">
	<ul>
		<li><a id="idtabdata_scrap_bahanbaku_sta" href="#divtabdata_scrap_bahanbaku_sta">Upload Data</a></li>
		<li><a id="idtabdata_scrap_bahanbaku_sta_draft" href="#divtabdata_scrap_bahanbaku_sta_draft">Proses Uploaded Data</a></li>
		
	</ul>
	
	<div id="divtabdata_scrap_bahanbaku_sta" >
		Upload Sisa dan Scrap
	   <form method="post" action="" id="upload_file_scrap_bahanbaku_sta">
		  <label for="userfile_scrap_bahanbaku_sta">File</label>
		  <input type="file" name="userfile_scrap_bahanbaku_sta" id="userfile_scrap_bahanbaku_sta" size="40" />
		  <input type="submit" name="submit" id="submit" value="Upload" /><button id="btn_scrap_bahanbaku_stadelet">Delete</button>
	   </form><span id="files_scrap_bahanbaku_sta" style="font-weight:bold;font-size:10px;"></span>
		<div style="position:absolute;top:47px;left:470px">
		   <input id="part_no_scr" placeholder="Part No" />
		   <input id="part_name_scr" placeholder="Part Name"/>
		   <button id="btn_scrap_update">Update/Insert</button>
		</div>
		   <hr>
	   <table id="tbluploadscrap_bahanbaku_sta"></table> <div id="ptbluploadscrap_bahanbaku_sta"></div>
	</div>
	<div id="divtabdata_scrap_bahanbaku_sta_draft" >
		<input type="hidden" id="hdndrafscrap_bahanbaku_sta_uploadproses" />
		File yang akan diproses. Filename: <input type="text" id="txtfilenamescrap_bahanbaku_sta_uploadproses" readonly="readonly"/>
		<button id="btncekfile_scrap_bahanbaku_sta_upload" >Cek File</button><button id="btnprosesfile_scrap_bahanbaku_sta_upload" >Proses File</button>
		<hr>
		<div id="div_cekfile_scrap_bahanbaku_sta_upload" >xls</div>
	</div>
	
</div>
<script type="text/javascript">
    
    $(document).ready(function(){
		$( "#tabdata_scrap_bahanbaku_sta" ).tabs();
		$("#btn_scrap_bahanbaku_stadelet").click(function(){
			var id = jQuery("#tbluploadscrap_bahanbaku_sta").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tbluploadscrap_bahanbaku_sta").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};	
			var form_data = {
				id_scrap_upload:ret.id_scrap_upload,
				filename:ret.filename,
				tipe:ret.tipe
			
			};
			
			$("#dlguploadscrap_bahanbaku_sta").dialog( "destroy" );
			$(".dlguploadscrap_bahanbaku_stacl").remove();
			$(".dlguploadscrap_bahanbaku_stacl").html('');
			$("body").append('<div id="dlguploadscrap_bahanbaku_sta" title="Warning" class="dlguploadscrap_bahanbaku_stacl"><p>Apakah anda akan mendelete file ini?!?</p><br /> file = '+ ret.filename +'</div>');
			$("#dlguploadscrap_bahanbaku_sta").dialog({
				height: 200,
				width: 250,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : "<?php echo base_url().'inventory/ct_scrap/deletefile_scrap_bahanbaku_sta'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlguploadscrap_bahanbaku_sta").dialog("close");
								$('#dlguploadscrap_bahanbaku_sta').dialog("destroy"); 
								$(".dlguploadscrap_bahanbaku_stacl").remove(); 
								$('#tbluploadscrap_bahanbaku_sta').trigger('reloadGrid');
							} else { 
								alert(msg.sts+' '+msg.desc); 
								$("#dlguploadscrap_bahanbaku_sta").dialog("close");
								$('#dlguploadscrap_bahanbaku_sta').dialog("destroy"); 
								$(".dlguploadscrap_bahanbaku_stacl").remove(); 
								$('#tbluploadscrap_bahanbaku_sta').trigger('reloadGrid');

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

					}
				},
				close : function(){
					$('#dlguploadscrap_bahanbaku_sta').dialog("destroy"); 
					$(".dlguploadscrap_bahanbaku_stacl").remove(); 
					$("body").append('<div id="dlguploadscrap_bahanbaku_sta" title="Warning" class="dlguploadscrap_bahanbaku_stacl"><p>Apakah anda akan mendelete file ini?!?</p></div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});
		
		});
		
		
		
		
		$("#idtabdata_scrap_bahanbaku_sta_draft").click(function(){
			var id = jQuery("#tbluploadscrap_bahanbaku_sta").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tbluploadscrap_bahanbaku_sta").jqGrid('getRowData',id);
				
			} else {
				alert('Pilih data yang akan diproses');
				$("#tabdata_scrap_bahanbaku_sta").tabs("select", 0);
				return false;
			};
			
			if(ret.status_upload != 'SUKSES'){
			
				alert('Data tidak bisa diproses, lihat status');
				$("#tabdata_scrap_bahanbaku_sta").tabs("select", 0);
				return false;
			
			}
			
			$("#txtfilenamescrap_bahanbaku_sta_uploadproses").val(ret.filename);
			
		
		});
		
		$("#btncekfile_scrap_bahanbaku_sta_upload").click(function(){
		
			var id = jQuery("#tbluploadscrap_bahanbaku_sta").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tbluploadscrap_bahanbaku_sta").jqGrid('getRowData',id);
				
			} else {
				alert('Pilih data yang akan diproses');
				$("#tabdata_scrap_bahanbaku_sta").tabs("select", 1);
				return false;
			};
			
			
			if(ret.status_upload != 'SUKSES'){
			
				alert('Data tidak bisa diproses, lihat status');
				$("#tabdata_scrap_bahanbaku_sta").tabs("select", 1);
				return false;
			
			}
			 var form_data = {
				filename:ret.filename,
				
			 };
			 
			 
			$.ajax({
				url: "<?php echo base_url().'inventory/ct_scrap/cek_data_scrap_bahanbaku_sta'; ?>",
				type: "POST",
				data: form_data,
				success:function(result){
					$("#div_cekfile_scrap_bahanbaku_sta_upload").html(result);
				 }
				
			});
			
			
			
		});
		
		$("#btnprosesfile_scrap_bahanbaku_sta_upload").click(function(){
		
			var id = jQuery("#tbluploadscrap_bahanbaku_sta").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tbluploadscrap_bahanbaku_sta").jqGrid('getRowData',id);
				
			} else {
				alert('Pilih data yang akan diproses');
				$("#tabdata_scrap_bahanbaku_sta").tabs("select", 1);
				return false;
			};
			
			if(ret.status_upload != 'SUKSES'){
			
				alert('Data tidak bisa diproses, lihat status');
				$("#tabdata_scrap_bahanbaku_sta").tabs("select", 1);
				return false;
			
			}
			
			var form_data = {
				id_scrap_upload:ret.id_scrap_upload,
				filename:ret.filename,
				tipe:ret.tipe
			
			};
			
			$("#dlguploadscrap_bahanbaku_sta_proses_").dialog( "destroy" );
			$(".dlguploadscrap_bahanbaku_sta_proses_cl").remove();
			$(".dlguploadscrap_bahanbaku_sta_proses_cl").html('');
			$("body").append('<div id="dlguploadscrap_bahanbaku_sta_proses_" title="Warning" class="dlguploadscrap_bahanbaku_sta_proses_cl"><p>Apakah anda akan memproses file ini?!?</p><br /> file = '+ ret.filename +'</div>');
			$("#dlguploadscrap_bahanbaku_sta_proses_").dialog({
				height: 200,
				width: 250,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : "<?php echo base_url().'inventory/ct_scrap/proses_data_scrap_bahanbaku_sta'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlguploadscrap_bahanbaku_sta_proses_").dialog("close");
								$('#dlguploadscrap_bahanbaku_sta_proses_').dialog("destroy"); 
								$(".dlguploadscrap_bahanbaku_sta_proses_cl").remove(); 
								$('#tbluploadscrap_bahanbaku_sta').trigger('reloadGrid');
								$('#tbl_scrap_bahanbaku_sta').trigger('reloadGrid');
								$("#tabdata_scrap_bahanbaku_sta").tabs("select", 0);
							} else { 
								alert(msg.sts+' '+msg.desc); 
								$("#dlguploadscrap_bahanbaku_sta_proses_").dialog("close");
								$('#dlguploadscrap_bahanbaku_sta_proses_').dialog("destroy"); 
								$(".dlguploadscrap_bahanbaku_sta_proses_cl").remove(); 

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

					}
				},
				close : function(){
					$('#dlguploadscrap_bahanbaku_sta_proses_').dialog("destroy"); 
					$(".dlguploadscrap_bahanbaku_sta_proses_cl").remove(); 
					$("body").append('<div id="dlguploadscrap_bahanbaku_sta_proses_" title="Warning" class="dlguploadscrap_bahanbaku_sta_proses_cl"><p>Apakah anda akan memproses file ini?!?</p></div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});	
		});
		
		$('#userfile_scrap_bahanbaku_sta').live('change', function(){
			$('#files_scrap_bahanbaku_sta').html('Files: '+ $('#userfile_scrap_bahanbaku_sta').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_scrap_bahanbaku_sta').submit(function(e) {
				e.preventDefault();
				$.ajaxFileUpload({
				 url         :'./inventory/ct_scrap/upload_file_scrapbahanbaku_sta/',
				 secureuri      :false,
				 fileElementId  :'userfile_scrap_bahanbaku_sta',
				 dataType    : 'json',
				 data        : {
					'userfile_scrap_bahanbaku_sta'  : $('#userfile_scrap_bahanbaku_sta').val()
				 },
				 success  : function (data, status)
				 {
					if(data.status != 'error')
					{
					   $('#files_scrap_bahanbaku_sta').html('Upload File Sukses...'+ $('#userfile_scrap_bahanbaku_sta').val() +' ;p'); 
					}
					alert(data.msg);
					$('#tbluploadscrap_bahanbaku_sta').trigger('reloadGrid');
					
				 }
		  });
		  return false;
		   });
		});
		
		jQuery("#tbluploadscrap_bahanbaku_sta").jqGrid({
			url:'<?php echo base_url().'inventory/ct_scrap/data_uploadscrap_bahanbaku_sta'; ?>',
			mtype : "post",
			postData:{'q':'1'},
			datatype: "json",
			colNames:['ID','filename', 'date upload','status upload', 'tipe', 'create date', 'create by','path'],
			colModel:[
				{name:'id_scrap_upload',index:'id_scrap_upload', 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({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({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: '#ptbluploadscrap_bahanbaku_sta',
			sortname: 'id_scrap_upload',
			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("#tbluploadscrap_bahanbaku_sta").getDataIDs(); 
				var rowData = $("#tbluploadscrap_bahanbaku_sta").getRowData();
			
				for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = jQuery("#"+ rowIDs[i],jQuery('#tbluploadscrap_bahanbaku_sta'));
				   
					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("#tbluploadscrap_bahanbaku_sta").jqGrid('navGrid','#ptbluploadscrap_bahanbaku_sta',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#tbluploadscrap_bahanbaku_sta").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});	
		
		
		$("#btn_scrap_update").click(function(){
			var form_data = {
				part_no_scr : $("#part_no_scr").val(),
				part_name_scr: $("#part_name_scr").val()
			
			};
			$("#update_masterscrap").dialog( "destroy" );
			$(".update_masterscrapcl").remove();
			$(".update_masterscrapcl").html('');
			$("body").append('<div id="update_masterscrap" title="Warning" class="update_masterscrapcl"><p>Apakah anda akan melakukan Update Data Scrap?</p><br /> -> '+ $("#part_no_scr").val().toUpperCase() +'<br />Harap Periksa Baik2 karena perubahan hanya satu kali</div>');
			$("#update_masterscrap").dialog({
				height: 200,
				width: 350,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url :"<?php echo base_url().'inventory/ct_scrap/update_masterscrap'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#update_masterscrap").dialog("close");
								$('#update_masterscrap').dialog("destroy"); 
								$(".update_masterscrapcl").remove(); 
								$(".update_masterscrapcl").html('');
								$('#tblbc23hdr').trigger('reloadGrid');
							
							} else { 
								alert(msg.sts+msg.desc);
								$("#update_masterscrap").dialog("close");
								$('#update_masterscrap').dialog("destroy"); 
								$(".update_masterscrapcl").remove(); 		

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

					}
				},
				close : function(){
					$('#update_masterscrap').dialog("destroy"); 
					$(".update_masterscrapcl").remove(); 
					$("body").append('<div id="update_masterscrap" title="Warning" class="update_masterscrapcl"><p>Apakah anda akan melakukan Update Data Scrap ini?</p><br />Harap Periksa Baik2 karena perubahan hanya satu kali</div>');     
					$(".update_masterscrapcl").html('');
				},
				open: function(){
					$("body").unblock();
					
				}
			});		
			
			
		
		});
		
		
	});
		  	
</script>



	
	


	
	


	
	