<div style="height:40px;">
	<input type="text" id="tglawalbc23mesincar" size=15 value='<?php echo date('Y-m-d'); ?>' readonly="readonly"/> S.D <input type="text" id="tglakhirbc23mesincar" size=15 value='<?php echo date('Y-m-d'); ?>' readonly="readonly"/>
	<button id="btnsearchdatebc23mesin">Search Date</button>	
	<span style="padding-left:10px"/><input type="text" id="txtbc23mesinsearchcar" /><button id="btnbc23searchcar">Search car</button><button id="btnprosesdatebc23mesin">Proses</button> 
</div>
<table id="tbl_bc23_mesin"></table> <div id="ptbl_bc23_mesin"></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'
		};
		
		$("#tglawalbc23mesincar").datepicker(datesetopt);
		$("#tglakhirbc23mesincar").datepicker(datesetopt); 
		$("#btnsearchdatebc23mesin").button().click(function(){
			$("#txtbc23searchcar").val('');
			var form_data = {'q':'1', 'tglawalbc23car':$("#tglawalbc23mesincar").val(), 'tglakhirbc23car':$("#tglakhirbc23mesincar").val(), 'car':''};
			jQuery("#tbl_bc23_mesin").jqGrid('setGridParam', { postData:form_data });
			$("#tbl_bc23_mesin").trigger("reloadGrid");
		
		});
		
		$("#btnbc23searchcar").button().click(function(){
		    var car = $("#txtbc23mesinsearchcar").val();
			var form_data = {'q':'1', 'car':car};
			jQuery("#tbl_bc23_mesin").jqGrid('setGridParam', { postData:form_data });
			$("#tbl_bc23_mesin").trigger("reloadGrid");
		
		});
		
		
		
		$("#btnprosesdatebc23mesin").button().click(function(){
			var id = jQuery("#tbl_bc23_mesin").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tbl_bc23_mesin").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};
			
			
			var form_data={
				carproses_matchbc23:ret.CAR
			};
			
			$("#dlgbc23_mesin").dialog( "destroy" );
			$(".dlgbc23_mesincl").remove();
			$(".dlgbc23_mesincl").html('');
			$("body").append('<div id="dlgbc23_mesin" title="Warning" class="dlgbc23_mesincl"><p>Apakah anda akan Memproses Data ini ke Modul BC23?!?</p><br /> CAR  = '+ ret.CAR +'</div>');
			$("#dlgbc23_mesin").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_mesin").dialog("close");
								$('#dlgbc23_mesin').dialog("destroy"); 
								$(".dlgbc23_mesincl").remove(); 
								$('#tbl_bc23_mesin').trigger('reloadGrid');
							} else { 
								alert(msg.sts+msg.desc); 
								$("#dlgbc23_mesin").dialog("close");
								$('#dlgbc23_mesin').dialog("destroy"); 
								$(".dlgbc23_mesincl").remove(); 

							}
						}
					});
				},
					"CANCEL": function() {
						$( "#dlgbc23_mesin" ).dialog( "close" );
								
					}
				},
				close : function(){
					$('#dlgbc23_mesin').dialog("destroy"); 
					$(".dlgbc23_mesincl").remove(); 
					$("body").append('<div id="dlgbc23_mesin" title="Warning" class="dlgbc23_mesincl"><p>Apakah anda akan Memproses Data ini ke Modul BC23?!?</p></div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});
			
		});
			
		jQuery("#tbl_bc23_mesin").jqGrid({
			url:'<?php echo base_url().'exim/ct_bc23/loaddatabc23mesin'; ?>',
			mtype : "post",
			postData:{'q':'1', 'tglawalbc23car':$("#tglawalbc23mesincar").val(), 'tglakhirbc23car':$("#tglakhirbc23mesincar").val()},
			datatype: "json",
			colNames:[ 'CAR',
						'TG AJU'
						,'DOK NO'
						,'DOK TG'
						,'STS'
						,'car'
					],
			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}
			],
			rowNum:10,
			rowList:[10,20,30],
			pager: '#ptbl_bc23_mesin',
			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_mesin").getDataIDs(); 
				var rowData = $("#tbl_bc23_mesin").getRowData();
			
				for (var i = 0; i < rowData.length; i++) 
				{
				    var trElement = jQuery("#"+ rowIDs[i],jQuery('#tbl_bc23_mesin'));
					
					switch (rowData[i].carx) {
						case '':
						   trElement.css({"color":"green"});
						break;
					default:
						trElement.css({"color":"red"});	
						
						
					}
				}
			},
		}); 
		
		jQuery("#tbl_bc23_mesin").jqGrid('navGrid','#ptbl_bc23_mesin',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#tbl_bc23_mesin").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});
		

	});
		  	
</script>



	
	