<div id="container_incoming_inv" style="height:100%; margin:0px; padding:0px;overflow:'hidden'; border: 0px solid #cd0a0a">
	<div class="pane-header ui-state-active" id="incoming_inv_bar" >  
		 <button id="btnincomingcreate" style="color:#FF0000;" >Process Data BC</button>
		 <button id="btnincomingdataviewdtl" >View Data</button>
		 <button id="btnincomingapproved" >Approval</button>
		 <button id="btnincomingdatagudang" >Gudang BB</button>
		 <button id="btnincomingsearch" >Search</button>	
		 <button id="btnincoming_adj_qty" >Qty Adj</button>	
	 </div>
<table id="tblincominghdr"></table> <div id="ptblincominghdr"></div>
</div>
<script type="text/javascript">
  
    $(document).ready(function(){
		$(window).bind('resize', function() {  
			setTimeout(function(){
				setGridHight($("#tblincominghdr"),$("#container_incoming_inv"),$("#incoming_inv_bar")); 
			},10); 
		});
		$("#btnincomingdatagudang").button().click(function(){
			$("#frmincomingdatagudangdlg").load('<?php echo base_url().'inventory/ct_incomingitem/view_incoming_data_gudang'; ?>',  {parmeter:'parameter'}, function() {
			
				$("#frmincomingdatagudangdlg").dialog({
					modal:true,
					width : 790,
					height : 500,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
                    },
					close : function(){
						$('#frmincomingdatagudangdlg').dialog("destroy"); 
					    $(".frmincomingdatagudangdlg_cl").remove(); 
					    $("body").append('<div id="frmincomingdatagudangdlg" title="DATA GUDANG BAHAN BAKU" class="frmincomingdatagudangdlg_cl"></div>'); 

					},
					open: function(){
						$("body").unblock();
						
					}
				});
			});		
			
		
		});
		
		$("#btnincomingcreate").button().click(function(){
			$("#frmincomingcreatedlg").load('<?php echo base_url().'inventory/ct_incomingitem/viewcreatedata_incoming'; ?>',  {parmeter:'parameter'}, function() {
			
				$("#frmincomingcreatedlg").dialog({
					modal:true,
					width : 990,
					height : 530,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
                    },
					close : function(){
						$('#frmincomingcreatedlg').dialog("destroy"); 
					    $(".frmincomingcreatedlg_cl").remove(); 
					    $("body").append('<div id="frmincomingcreatedlg" title="INCOMING ITEMS" class="frmincomingcreatedlg_cl"></div>'); 
						$('#tblincominghdr').trigger('reloadGrid');
	
					},
					open: function(){
						$("body").unblock();
						
					}
				});
			});		
		});
		
		$("#btnincomingdataviewdtl").button().click(function(){
			var id = jQuery("#tblincominghdr").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tblincominghdr").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};

			var form_data={id_incominghdr:ret.id_data_in_hdr};
			
			$("#frmincoming_dtl_dlg").load('<?php echo base_url().'inventory/ct_incomingitem/view_incoming_dtl'; ?>',  form_data, function() {
				$("#frmincoming_dtl_dlg").dialog({
					modal:true,
					width : 800,
					height : 500,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
                    },
						
                    
					close : function(){
						$('#frmincoming_dtl_dlg').dialog("destroy"); 
					    $(".frmincoming_dtl_dlg_cl").remove(); 
					    $("body").append('<div id="frmincoming_dtl_dlg" title="DATA DETAIL INCOMING ITEMS" class="frmincoming_dtl_dlg_cl"></div>'); 
	
					},
					open: function(){
						$("body").unblock();
						
					}
				});
			});	 	
		
		});
		
		$("#btnincomingapproved").button().click(function(){
			var id = jQuery("#tblincominghdr").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tblincominghdr").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};
			
		
			if (ret.doc_in_from_name == 'BC27'){
				ret.doc_in_from_name = 'BC271';
			};
			
			var form_data = {
				parmeter:'parameter', 
				idx:ret.id_data_in_hdr, 
				doc_in_from_id:ret.doc_in_from_id,
				idterkait:ret.id_terkait,
				typedok:ret.doc_in_from_name, 
				doc_in_no:ret.doc_in_no, 
				doc_in_date:ret.doc_in_date,
				noinv:ret.nobl,
				tginv:ret.tglbl,
				
				
			};
			$("#frmincomingapproved_dlg").load('<?php echo base_url().'inventory/ct_incomingitem/view_incoming_approved'; ?>', form_data , function() {
			
				$("#frmincomingapproved_dlg").dialog({
					modal:true,
					width : 490,
					height : 280,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
												
                    },
					close : function(){
						$('#frmincomingapproved_dlg').dialog("destroy"); 
					    $(".frmincomingapproved_dlg_cl").remove(); 
					    $("body").append('<div id="frmincomingapproved_dlg" title="INCOMING ITEMS APPROVAL" class="frmincomingapproved_dlg_cl"></div>'); 
						$('#tblincominghdr').trigger('reloadGrid');
	
					},
					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_") {
                // in case of searching toolbar
					setTimeout(function(){
					jQuery("#tblincominghdr").jqGrid()[0].triggerToolbar();
						}, 50);
					} else {
						// refresh the filter in case of
						// searching dialog
						$(this).trigger('change');
					}
				}    
			});
		};
		
		jQuery("#tblincominghdr").jqGrid({
			url:'<?php echo base_url().'inventory/ct_incomingitem/loaddata'; ?>',
			mtype : "post",
			postData:{'q':'1'},
			datatype: "json",
			colNames:['ID','Invoice No','Invoice Date','CAR','Incoming No', 'Incoming Date','Type Doc', 'id_bc_in_hdr', 'id_terkait', 'noinv', 'tginv','NO BC','TGL BC', 'nobl/nogroup', 'tglbl/tglgroup','status', 'doc_in_from_id'],
			colModel:[
				{name:'id_data_in_hdr',index:'id_data_in_hdr', width:60, hidden:true},
				{name:'DokNo',index:'DokNo', width:190},
				{name:'DokTg',index:'DokTg', width:106,stype:"text",searchoptions:{dataInit:datePick, att:{title:'Select Date'}}},
				{name:'CAR',index:'CAR', width:190},
				{name:'doc_in_no',index:'doc_in_no', width:160},
				{name:'doc_in_date',index:'doc_in_date', width:106,stype:"text",searchoptions:{dataInit:datePick, att:{title:'Select Date'}}},
				{name:'doc_in_from_name',index:'doc_in_from_name', width:106},
				{name:'id_bc_in_hdr',index:'id_bc_in_hdr', width:106, hidden:true},
				{name:'id_terkait',index:'id_terkait', width:106, hidden:true},
				{name:'noinv',index:'noinv', width:106, hidden:true},
				{name:'tginv',index:'tginv', width:106, hidden:true, stype:"text",searchoptions:{dataInit:datePick, att:{title:'Select Date'}}},
				{name:'BC23No',index:'BC23No', width:106, hidden:false},
				{name:'BC23Tg',index:'BC23Tg', width:106, hidden:false, stype:"text",searchoptions:{dataInit:datePick, att:{title:'Select Date'}}},
				{name:'nobl',index:'nobl', width:106, hidden:false},
				{name:'tglbl',index:'tglbl', width:106, hidden:false, stype:"text",searchoptions:{dataInit:datePick, att:{title:'Select Date'}}},
				{name:'status',index:'status', width:106},
				{name:'doc_in_from_id',index:'doc_in_from_id', width:106, hidden:true},
				],
			rowNum:10,
			rowList:[10,20,30],
			pager: '#ptblincominghdr',
			sortname: 'tbl_data_in_hdr.doc_in_no',
			viewrecords: true,
			sortorder: "desc",
			width: '',
			height:100,
			jsonReader: { repeatitems : false },
			caption:"List of Incoming Items",
			rownumbers: true,
			shrinkToFit: false,
			afterInsertRow: function(){
				
				
			},			
			gridComplete: function(){
				var rowIDs = jQuery("#tblincominghdr").getDataIDs(); 
				var rowData = $("#tblincominghdr").getRowData();
			
				for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = jQuery("#"+ rowIDs[i],jQuery('#tblincominghdr'));
				   
					switch (rowData[i].status) {
						
						case 'DATA PROCESSED':
						   trElement.css({"color":"green"});
						break;
						case 'APPROVED':
						   trElement.css({"color":"red"});
						break;
					}
				}
			},
		}); 
			
                        
		jQuery("#tblincominghdr").jqGrid('navGrid','#ptblincominghdr',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#tblincominghdr").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});

		setTimeout(function(){
			setGridHight($("#tblincominghdr"),$("#container_incoming_inv"),$("#incoming_inv_bar")); 
		},10); 
	
		$("#btnincomingsearch").button().click(function(){
			$("#search_incomingitemsearch_dlg").load('<?php echo base_url().'inventory/ct_incomingitem/view_incomingitem_search'; ?>',  {parmeter:'parameter'}, function() {
				$("#search_incomingitemsearch_dlg").dialog({
					modal:true,
					width : 600,
					height : 220,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
                    },
					close : function(){
						$('#search_incomingitemsearch_dlg').dialog("destroy"); 
					    $(".search_incomingitemsearch_dlg_cl").remove(); 
					    $("body").append('<div id="search_incomingitemsearch_dlg" title="PENCARIAN PERIODE TANGGAL" class="search_incomingitemsearch_dlg_cl"></div>'); 
						
					},
					open: function(){
						$("body").unblock();
						
					}
				});
			});	
		
		});
		$("#btnincoming_adj_qty").button().click(function(){
			var id = jQuery("#tblincominghdr").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tblincominghdr").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};

			var form_data={id_incominghdr:ret.id_data_in_hdr};
			
			
			$("#frmincoming_adj_dtl_dlg").load('<?php echo base_url().'inventory/ct_incomingitem/view_incoming_dtl_adj'; ?>',  form_data, function() {
				$("#frmincoming_adj_dtl_dlg").dialog({
					modal:true,
					width : 800,
					height : 500,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
                    },
						
                    
					close : function(){
						$('#frmincoming_adj_dtl_dlg').dialog("destroy"); 
					    $(".frmincoming_adj_dtl_dlg_cl").remove(); 
					    $("body").append('<div id="frmincoming_adj_dtl_dlg" title="DATA DETAIL INCOMING ITEMS" class="frmincoming_adj_dtl_dlg_cl"></div>'); 
	
					},
					open: function(){
						$("body").unblock();
						
					}
				});
			});	 
			
			
		});
	});
	
		  	
</script>
<div id="frmincomingcreatedlg" title="INCOMING ITEMS" class="frmincomingcreatedlg_cl"></div>
<div id="frmincomingapproved_dlg" title="INCOMING ITEMS APPROVAL" class="frmincomingapproved_dlg_cl"></div>
<div id="frmincoming_dtl_dlg" title="DATA DETAIL INCOMING ITEMS" class="frmincoming_dtl_dlg_cl"></div>
<div id="frmincomingdatagudangdlg" title="DATA GUDANG BAHAN BAKU" class="frmincomingdatagudangdlg_cl"></div>
<div id="search_incomingitemsearch_dlg" title="PENCARIAN PERIODE TANGGAL" class="search_incomingitemsearch_dlg_cl"></div>
<div id="frmincoming_adj_dtl_dlg" title="DATA DETAIL INCOMING ITEMS" class="frmincoming_adj_dtl_dlg_cl"></div>
		
	