<div style="height:40px;">
	<button id="btnprosesdownload_kurir" >Proses Data</button>
</div>
<div>
	<table id="tbldownloadkurir"></table> <div id="ptbldownloadkurir"></div>   
</div>
<script type="text/javascript">
    
    $(document).ready(function(){
		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("#tbluploadkurir").jqGrid()[0].triggerToolbar();
						}, 50);
					} else {
						// refresh the filter in case of
						// searching dialog
						$(this).trigger('change');
					}
				}    
			});
		};
		jQuery("#tbldownloadkurir").jqGrid({
			url:'<?php echo base_url().'exim/ct_upload_kurir/data_uploadkurir'; ?>',
			mtype : "post",
			postData:{'q':'1'},
			datatype: "json",
			colNames:['ID','filename', 'date upload','status upload', 'tipe', 'create date', 'create by'],
			colModel:[
				{name:'id_kurir_upload',index:'id_kurir_upload', width:60, hidden:true},
				{name:'filename',index:'filename', 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: '#ptbldownloadkurir',
			sortname: 'id_kurir_upload',
			viewrecords: true,
			sortorder: "desc",
			width: 780,
			height:300,
			jsonReader: { repeatitems : false },
			caption:"List of Files Upload",
			rownumbers: true,
			shrinkToFit: false,
			afterInsertRow: function(){
				
				
			},			
			gridComplete: function(){
				var rowIDs = jQuery("#tbldownloadkurir").getDataIDs(); 
				var rowData = $("#tbldownloadkurir").getRowData();
			
				for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = jQuery("#"+ rowIDs[i],jQuery('#tbldownloadkurir'));
				   
					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("#tbldownloadkurir").jqGrid('navGrid','#ptbldownloadkurir',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#tbldownloadkurir").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});
		
		
		$("#btnprosesdownload_kurir").button().click(function(){
			var id = jQuery("#tbldownloadkurir").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tbldownloadkurir").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row Invoice");
				return false;
			};	
			
			if( ret.status_upload != 'SUKSES') {
			
			    alert("Data tidak dapat di proses..Lihat status");
				return false;
			};		
			
			var form_data;
			form_data = {
				id_kurir_upload:ret.id_kurir_upload
			
			};
			
			$("#dlg_proses_inv_kurir_bc23").dialog( "destroy" );
			$(".dlg_proses_inv_kurir_bc23_cl").remove();
			$(".dlg_proses_inv_kurir_bc23_cl").html('');
			$("body").append('<div id="dlg_proses_inv_kurir_bc23" title="Warning" class="dlg_proses_inv_kurir_bc23_cl"><p>Apakah anda yakin akan memproses data mesin sparepart  '+ ret.filename +'..?</p><br />Mohon diperiksa kembali datanya.</div>');
			$("#dlg_proses_inv_kurir_bc23").dialog({
				height: 200,
				width: 250,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : "<?php echo base_url().'exim/ct_bc23/proses_kurirbc23'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlg_proses_inv_kurir_bc23").dialog("close");
								$('#dlg_proses_inv_kurir_bc23').dialog("destroy"); 
								$(".dlg_proses_inv_kurir_bc23_cl").remove(); 
								$(".dlg_proses_inv_kurir_bc23_cl").html('');
								//jQuery("#tbl_proses_inv_mesinsparepart_hdr").trigger('reloadGrid');
								
							} else { 
								alert(msg.sts+msg.desc); 
								$("#dlg_proses_inv_kurir_bc23").dialog("close");
								$('#dlg_proses_inv_kurir_bc23').dialog("destroy"); 
								$(".dlg_proses_inv_kurir_bc23_cl").remove(); 
								
							}
						}
					});
				},
					"CANCEL": function() {
						$( "#dlg_proses_inv_kurir_bc23" ).dialog( "close" );

					}
				},
				close : function(){
					$('#dlg_proses_inv_kurir_bc23').dialog("destroy"); 
					$(".dlg_proses_inv_kurir_bc23_cl").remove(); 
					//$("body").append('<div id="dlg_proses_inv_kurir_bc23" title="Warning" class="dlg_proses_inv_kurir_bc23_cl"><p>Apakah anda yakin akan memproses data mesin sparepart  '+ ret.filename  +'..?</p><br />Mohon diperiksa kembali datanya.</div>.</div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});
			
		
		});

	});
		  	
</script>



	
	