<div style="height:10px;">
</div>
   SUPPLIER
   <form method="post" action="" id="upload_file_supplier">
      <label for="userfilesupplier">Data</label>
      <input type="file" name="userfilesupplier" id="userfilesupplier" size="40" />
      <input type="submit" name="submit" id="submit" value="Send Data" /><button id="btnsupplierdelet">Delete</button>
   </form>Data List:<span id="files_supplier" style="font-weight:bold;font-size:10px;"></span>
   <hr>
   <table id="tbluploadsupplier"></table> <div id="ptbluploadsupplier"></div>   
   
<script type="text/javascript">
    
    $(document).ready(function(){
	   
		function refresh_files()
		{
		   $.get('<?php echo base_url().'loaderfiles/invoice/supplier'; ?>')
		   .success(function (data){
			  $('#files_supplier').html(data);
		   });
		};
		$('#userfilesupplier').live('change', function(){
			$('#files_supplier').html('<p>'+ $('#userfilesupplier').val() +'</p>'); 
		});
		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_supplier').submit(function(e) {
				e.preventDefault();
				$.ajaxFileUpload({
				 url         :'./settings/ct_supplier/upload_file_supplier/',
				 secureuri      :false,
				 fileElementId  :'userfilesupplier',
				 dataType    : 'json',
				 data        : {
					'userfilesupplier'  : $('#userfilesupplier').val()
				 },
				 success  : function (data, status)
				 {
					if(data.status != 'error')
					{
					   $('#files_supplier').html('<p style=""color:red">Upload File Sukses...'+ $('#userfilesupplier').val() +'</p>'); 
					   
					 
					}
					jQuery("#tbluploadsupplier").trigger('reloadGrid');
					alert(data.msg);
				 }
		  });
		  return false;
		   });
		});
		
		var datePick = function (el) {
			$(el).datepicker({
				changeYear: true,
				changeMonth: true,
				showButtonPanel: true,
				onSelect: function () {
					
					if (this.id.substr(0, 3) === "gs_") {
                // in case of searching toolbar
					setTimeout(function(){
					jQuery("#tbluploadsupplier").jqGrid()[0].triggerToolbar();
						}, 50);
					} else {
						// refresh the filter in case of
						// searching dialog
						$(this).trigger('change');
					}
				}    
			});
		};
		
		
		$("#btnsupplierdelet").click(function(){
			var id = jQuery("#tbluploadsupplier").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tbluploadsupplier").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};	
			var form_data = {
				id_supplier_upload:ret.id_supplier_upload,
				filename:ret.filename,
				tipe:ret.tipe
			
			};
			
			$("#dlgdeletefilesupplier").dialog( "destroy" );
			$(".dlgdeletefilesuppliercl").remove();
			$("body").append('<div id="dlgdeletefilesupplier" title="Warning" class="dlgdeletefilesuppliercl"><p>Apakah anda akan mendelete data ini?!?</p><br /> data = '+ ret.filename +'</div>');
			$("#dlgdeletefilesupplier").dialog({
				height: 200,
				width: 250,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : "<?php echo base_url().'settings/ct_supplier/deletefile_supplier'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlgdeletefilesupplier").dialog("close");
								$('#dlgdeletefilesupplier').dialog("destroy"); 
								$(".dlgdeletefilesuppliercl").remove(); 
								$('#tbluploadsupplier').trigger('reloadGrid');
							} else { 
								alert(msg.sts+' '+msg.desc); 
								$("#dlgdeletefilesupplier").dialog("close");
								$('#dlgdeletefilesupplier').dialog("destroy"); 
								$(".dlgdeletefilesuppliercl").remove(); 

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

					}
				},
				close : function(){
					$('#dlgdeletefilesupplier').dialog("destroy"); 
					$(".dlgdeletefilesuppliercl").remove(); 
					$("body").append('<div id="dlgdeletefilesupplier" title="Warning" class="dlgdeletefilesuppliercl"><p>Apakah anda akan mendelete file ini?!?</p></div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});
		
		});
		
		jQuery("#tbluploadsupplier").jqGrid({
			url:'<?php echo base_url().'settings/ct_supplier/data_uploadsupplier'; ?>',
			mtype : "post",
			postData:{'q':'1'},
			datatype: "json",
			colNames:['ID','Data','Data2', 'date ','status ', 'tipe', 'create date', 'create by'],
			colModel:[
				{name:'id_supplier_upload',index:'id_supplier_upload', width:60, hidden:true},
				{name:'filename',index:'filename', width:160, hidden:true},
				{name:'filename2',index:'filename2', width:160},
				{name:'date_upload',index:'date_upload', width:166,stype:"text",searchoptions:{dataInit:datePick, att:{title:'Select Date'}}},
				{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:{dataInit:datePick, att:{title:'Select Date'}}},
				{name:'create_by',index:'create_by', width:106, hidden:false},
			
				],
			rowNum:10,
			rowList:[10,20,30],
			pager: '#ptbluploadsupplier',
			sortname: 'id_supplier_upload',
			viewrecords: true,
			sortorder: "desc",
			width: 900,
			height:220,
			jsonReader: { repeatitems : false },
			caption:"List data",
			rownumbers: true,
			shrinkToFit: false,
			afterInsertRow: function(){
				
				
			},			
			gridComplete: function(){
				var rowIDs = jQuery("#tbluploadsupplier").getDataIDs(); 
				var rowData = $("#tbluploadsupplier").getRowData();
			
				for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = jQuery("#"+ rowIDs[i],jQuery('#tbluploadsupplier'));
				   
					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("#tbluploadsupplier").jqGrid('navGrid','#ptbluploadsupplier',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#tbluploadsupplier").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : false, defaultSearch: 'cn', ignoreCase: true});
		
		

	});
		  	
</script>

