<div id="container_prod_plan" style="height:100%; margin:0px; padding:0px;overflow:'hidden'; border: 0px solid #cd0a0a">
	<div class="pane-header ui-state-active" id="prod_plan_bar" >   
		<button id="btngetdatabom">GET DATA B.O.M</button>
		<button id="btnviewdetailbom">VIEW DETAIL B.O.M</button>
	</div>
	<table id="tblbomhdr"></table> <div id="ptblbomhdr"></div>
</div>

<script type="text/javascript">

$(document).ready(function(){
		$(window).bind('resize', function() {  
			setTimeout(function(){
				setGridHight($("#tblbomhdr"),$("#container_prod_plan"),$("#prod_plan_bar")); 
			},10); 
		});

		$("#btngetdatabom").button().click(function(){
			$("#dlgdatabom").dialog( "destroy" );
			$(".dlgdatabom_cl").remove();
			$("body").append('<div id="dlgdatabom" title="Warning" class="dlgdatabom_cl"><p>Apakah anda akan Memproses Data  Menjadi Data BOM?</p><br /></div>');
			$("#dlgdatabom").dialog({
				height: 200,
				width: 350,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : "<?php echo base_url().'production/ct_planprod/getadataloaderbom'; ?>",
						type : 'POST',
						dataType: 'json',
						data : {test:'test'},
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlgdatabom").dialog("close");
								$('#dlgdatabom').dialog("destroy"); 
								$(".dlgdatabom_cl").remove(); 
								$('#tblbomhdr').trigger('reloadGrid');
							} else { 
								alert(msg.sts+msg.desc);
								$("#dlgdatabom").dialog("close");
								$('#dlgdatabom').dialog("destroy"); 
								$(".dlgdatabom_cl").remove(); 		

							}
						}
					});
				},
				"CANCEL": function() {
						$( "#dlgdatabom" ).dialog( "close" );
						$(".dlgdatabom_cl").remove();

					}
				},
				close : function(){
					$('#dlgdatabom').dialog("destroy"); 
					$(".dlgdatabom_cl").remove(); 
					$("body").append('<div id="dlgdatabom" title="Warning" class="dlgdatabom_cl"><p>Apakah anda akan Memproses Data  Menjadi Data BOM?</p></div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});
		
		});
		
		$("#btnviewdetailbom").button().click(function(){
			var id = jQuery("#tblbomhdr").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tblbomhdr").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};

			var form_data={id_bom_hdr:ret.ASSY_CODE};
			
			$("#frmviewbomdtl_dlg").load('<?php echo base_url().'production/ct_planprod/view_planprod_bom'; ?>',  form_data, function() {
				$("#frmviewbomdtl_dlg").dialog({
					modal:true,
					width : 800,
					height : 500,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
                    },
						
                    
					close : function(){
						$('#frmviewbomdtl_dlg').dialog("destroy"); 
					    $(".frmviewbomdtl_dlg_cl").remove(); 
					    $("body").append('<div id="frmviewbomdtl_dlg" title="DATA DETAIL BOM" class="frmviewbomdtl_dlg_cl"></div>'); 
	
					},
					open: function(){
						$("body").unblock();
						
					}
				});
			});	 	
		
		});
		
		var datePick = function (el) {
			$(el).datepicker({
				changeYear: true,
				changeMonth: true,
				showButtonPanel: true,
				onSelect: function () {
					
					if (this.id.substr(0, 3) === "gs_") {
               
					setTimeout(function(){
					jQuery("#tblbomhdr").jqGrid()[0].triggerToolbar();
						}, 50);
					} else {
						
						$(this).trigger('change');
					}
				}    
			});
		};
		
		jQuery("#tblbomhdr").jqGrid({
			url:'<?php echo base_url().'production/ct_planprod/loaddatabom'; ?>',
			mtype : "post",
			postData:{'q':'1'},
			datatype: "json",
			colNames:['ID', 'ASSY CODE','ASSY NO', 'FILENAME', 'ITEM COUNT', 'EXEC DATE' ],
			colModel:[
				{name:'id_bom_hdr',index:'id_bom_hdr', width:60, hidden:true},
				{name:'ASSY_CODE',index:'ASSY_CODE', width:112},
				{name:'ASSY_NO',index:'ASSY_NO', width:230},
				{name:'filename',index:'filename', width:362},
				{name:'itemcount',index:'itemcount', width:98, align:'right'},
				{name:'dateexec',index:'dateexec', width:98,stype:"text",searchoptions:{dataInit:datePick, att:{title:'Select Date'}}}
				],
			rowNum:15,
			rowList:[15,20,30,40,50],
			pager: '#ptblbomhdr',
			sortname: 'id_bom_hdr',
			viewrecords: true,
			sortorder: "asc",
			width: '',
			height:100,
			jsonReader: { repeatitems : false },
			caption:"DATA B.O.M",
			rownumbers: true,
			shrinkToFit: false,
			afterInsertRow: function(){
				
				
			},			
			gridComplete: function(){
				
			},
		}); 
		
		jQuery("#tblbomhdr").jqGrid('navGrid','#ptblbomhdr',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#tblbomhdr").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : false, defaultSearch: 'cn', ignoreCase: true});

		setTimeout(function(){
				setGridHight($("#tblbomhdr"),$("#container_prod_plan"),$("#prod_plan_bar")); 
		},10); 

        
});


</script>
<div id="frmviewbomdtl_dlg" title="DATA DETAIL BOM" class="frmviewbomdtl_dlg_cl"></div>
</body>

</html> 
        

