<style type="text/css">
table.xgridtable {
	font-family: verdana,arial,sans-serif;
	font-size:11px;
	color:#333333;
	border-width: 1px;
	border-color: #666666;
	border-collapse: collapse;
}
table.xgridtable th {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #666666;
	background-color: #dedede;
}
table.xgridtable td {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #666666;
	background-color: #ffffff;
}
</style>
<div style="height:40px;">
	<input type="text" id="tglawalbc23car" size=15 value='<?php echo date('Y-m-d'); ?>' readonly="readonly"/> S.D <input type="text" id="tglakhirbc23car" size=15 value='<?php echo date('Y-m-d'); ?>' readonly="readonly"/>
	<button id="btnsearchdatebc23">Search Date</button>	
	<span style="padding-left:10px"/><input type="text" id="txtbc23searchcar" /><button id="btnbc23searchcar">Search car</button><button id="btnprosesdatebc23">Proses</button><button id="btnmatchcekdokbc23">cek dokumen</button>  
</div>
<table id="tbl_bc23_macthing"></table> <div id="ptbl_bc23_macthing"></div>
<script type="text/javascript">
    
    $(document).ready(function(){
		var currentDate = new Date(); 
		var datesetopt = {
			showOn: "button",
			buttonImageOnly: true,
			buttonImage: "<?php echo base_url()."assets/images/icons/16x16/timespan.png"  ?>",
			buttonText: "Tanggalan",
			dateFormat: 'yy-mm-dd'
		};
		
		$("#tglawalbc23car").datepicker(datesetopt);
		$("#tglakhirbc23car").datepicker(datesetopt); 
		$("#btnsearchdatebc23").button().click(function(){
			$("#txtbc23searchcar").val('');
			var form_data = {'q':'1', 'tglawalbc23car':$("#tglawalbc23car").val(), 'tglakhirbc23car':$("#tglakhirbc23car").val(), 'car':''};
			jQuery("#tbl_bc23_macthing").jqGrid('setGridParam', { postData:form_data });
			$("#tbl_bc23_macthing").trigger("reloadGrid");
		
		});
		
		$("#btnbc23searchcar").button().click(function(){
		    var car = $("#txtbc23searchcar").val();
			var form_data = {'q':'1', 'car':car};
			jQuery("#tbl_bc23_macthing").jqGrid('setGridParam', { postData:form_data });
			$("#tbl_bc23_macthing").trigger("reloadGrid");
		
		});
		
		/* $('#txtbc23searchcar').keypress(function(event){
 
			var keycode = (event.keyCode ? event.keyCode : event.which);
			if(keycode == '13'){
				var form_data = {'q':'1', 'car':$("#txtbc23searchcar").val()};
				jQuery("#tbl_bc23_macthing").jqGrid('setGridParam', { postData:form_data });
				$("#tbl_bc23_macthing").trigger("reloadGrid");
			}
		 
		}); */
		
		$("#btnmatchcekdokbc23").button().click(function(){
			var id = jQuery("#tbl_bc23_macthing").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tbl_bc23_macthing").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};	
			
			var form_data= {
				car:ret.CAR
				
			}
			
			
			
			$.ajax({
				url : "<?php echo base_url().'exim/ct_bc23/cekdokmacthing'; ?>",
				type : 'POST',
				dataType: 'json',
				data : form_data,
				success: function(msg){
					$("#dlgdokmatchingbc23").dialog( "destroy" );
					$(".dlgdokmatchingbc23cl").remove();
					$(".dlgdokmatchingbc23cl").html('');
					//console.log(msg);
					var json_obj = $.parseJSON(msg);//parse JSON
					var tbl="<table class='xgridtable'><tr><td>DOK NO</td><td>DOK KODE</td><td>DOK TGL</td></tr>";
					$.each(msg, function(i, value) {
						tbl+="<tr><td>"+value.dokno+"</td>"+"<td>"+value.dokkd+"</td>"+"<td>"+value.doktg+"</td>"+"</tr>"
					});
					tbl+="</table>"
					
					$("body").append('<div id="dlgdokmatchingbc23" title="DOK BC23" class="dlgdokmatchingbc23cl">'
					  +	tbl
					  + '</div>');
					$("#dlgdokmatchingbc23").dialog({
						height: 400,
						width: 350,
						modal: true,
						hide: 'Slide',
						autoOpen: 'false',
						buttons: {
						
						"CLOSE": function() {
								$( "#dlgdokmatchingbc23" ).dialog( "close" );

							}
						},
						close : function(){
							$('#dlgdokmatchingbc23').dialog("destroy"); 
							$(".dlgdokmatchingbc23cl").remove(); 
							$("body").append('<div id="dlgdokmatchingbc23" title="DOK BC23" class="dlgdokmatchingbc23cl">'
							
							+ '</div>');     
							$(".dlgdokmatchingbc23cl").html('');
						},
						open: function(){
							$("body").unblock();
							
						}
					});			
				}
			});
			
			
		
		
		});
		
		
		$("#btnprosesdatebc23").button().click(function(){
			var id = jQuery("#tbl_bc23_macthing").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tbl_bc23_macthing").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};
			
			
			var form_data={
				carproses_matchbc23:ret.CAR, jnsbarang:ret.jnsbarang
			};
			
			$("#dlgbc23_macthing").dialog( "destroy" );
			$(".dlgbc23_macthingcl").remove();
			$(".dlgbc23_macthingcl").html('');
			$("body").append('<div id="dlgbc23_macthing" title="Warning" class="dlgbc23_macthingcl"><p>Apakah anda akan Memproses Data ini ke Modul BC23?!?</p><br /> CAR  = '+ ret.CAR +'</div>');
			$("#dlgbc23_macthing").dialog({
				height: 200,
				width: 250,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : "<?php echo base_url().'exim/ct_bc23/proses_bc23'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlgbc23_macthing").dialog("close");
								$('#dlgbc23_macthing').dialog("destroy"); 
								$(".dlgbc23_macthingcl").remove(); 
								$('#tbl_bc23_macthing').trigger('reloadGrid');
							} else { 
								alert(msg.sts+msg.desc); 
								$("#dlgbc23_macthing").dialog("close");
								$('#dlgbc23_macthing').dialog("destroy"); 
								$(".dlgbc23_macthingcl").remove(); 

							}
						}
					});
				},
					"CANCEL": function() {
						$( "#dlgbc23_macthing" ).dialog( "close" );
								
					}
				},
				close : function(){
					$('#dlgbc23_macthing').dialog("destroy"); 
					$(".dlgbc23_macthingcl").remove(); 
					$("body").append('<div id="dlgbc23_macthing" title="Warning" class="dlgbc23_macthingcl"><p>Apakah anda akan Memproses Data ini ke Modul BC23?!?</p></div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});
			
		});
		
		jQuery("#tbl_bc23_macthing").jqGrid({
			url:'<?php echo base_url().'exim/ct_bc23/datamodul_detil'; ?>',
			mtype : "post",
			postData:{'q':'1', 'tglawalbc23car':$("#tglawalbc23car").val(), 'tglakhirbc23car':$("#tglakhirbc23car").val()},
			datatype: "json",
			colNames:[ 'CAR',
						'TG AJU'
						,'DOK NO'
						,'DOK TG'
						,'STS'
						,'car'
						,'JNS-DOK'
					],
			colModel:[
				{name:'CAR',index:'CAR', width:189, hidden:false},
				{name:'xdate',index:'xdate', width:89, hidden:false},
				{name:'dokno',index:'dokno', width:189, hidden:false},
				{name:'doktg',index:'doktg', width:89, hidden:false},
				{name:'sts',index:'sts', width:89, hidden:false},
				{name:'carx',index:'carx', width:189, hidden:true},
				{name:'jnsbarang',index:'jnsbarang', width:89, hidden:false},
				
				
			],
			rowNum:10,
			rowList:[10,20,30],
			pager: '#ptbl_bc23_macthing',
			sortname: 'car',
			viewrecords: true,
			sortorder: "asc",
			width: 770,
			height:280,
			jsonReader: { repeatitems : false },
			caption:"DATA CAR MODUL",
			rownumbers: true,
			shrinkToFit: false,
			afterInsertRow: function(){
				
				
			},
			gridComplete: function(){
				var rowIDs = jQuery("#tbl_bc23_macthing").getDataIDs(); 
				var rowData = $("#tbl_bc23_macthing").getRowData();
			
				for (var i = 0; i < rowData.length; i++) 
				{
				    var trElement = jQuery("#"+ rowIDs[i],jQuery('#tbl_bc23_macthing'));
					
					switch (rowData[i].carx) {
						case '':
						   trElement.css({"color":"green"});
						break;
					default:
						trElement.css({"color":"red"});	
						
						
					}
				}
			},
		}); 
		
		jQuery("#tbl_bc23_macthing").jqGrid('navGrid','#ptbl_bc23_macthing',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#tbl_bc23_macthing").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});
		
		

	});
		  	
</script>



	
	