<div id="tabprod_finishgood2" style="height:100%; margin:0px; padding:0px;overflow:'hidden'; border: 0px solid #cd0a0a">
	<div id="tabprod_finishgood" style="height:100%;margin:0px; padding:0px;">
		<ul>
			<li><a id="btnfinishgood_in" href="#divfinishgood_in">FINISHGOOD IN</a></li>
			<li><a id="btnfinishgood_out" href="#divfinishgood_out">FINISHGOOD OUT</a></li> 
		</ul> 
		<div id="divfinishgood_in">
			<div class="pane-header ui-state-active" id="divfinishgood_in_bar" >    
				<p>PERIODE : <input type="text" id="tglawalfg_in" size=15 value="<?php echo  date('m/d/Y'); ?>" readonly="readonly"/>  S.D <input type="text" id="tglakhirfg_in" size=15 value="<?php echo  date('m/d/Y'); ?>" readonly="readonly"/> 
				<button id="btnsearchfinnishgood_in">Search</button><span style="padding-left:20px"/><input type="text" id="nilfgin" style="text-align:right" class="numeric"/>
				<?php if($this->session->userdata('DX_username') == 'admin' || $this->session->userdata('DX_username') == 'yayan' || $this->session->userdata('DX_username') == 'ojah' || $this->session->userdata('DX_username') == 'gyt' || $this->session->userdata('DX_username') == 'tri' ){ ?>
					<button id="btnupdatefinnishgood_in">Update</button>
				<?php }; ?>
				<button id="btndatafinnishgood_in_out">Rekap In Out Per Assy</button>	
			</div>
			<table id="grdfinishgood_in"></table> <div id="pgrdfinishgood_in"> </div>	 
		</div> 
		<div id="divfinishgood_out" >
			<div class="pane-header ui-state-active" id="divfinishgood_out_bar" >    
			<p>PERIODE : <input type="text" id="tglawalfg_out" size=15 value="<?php echo  date('m/d/Y'); ?>" readonly="readonly"/>  S.D <input type="text" id="tglakhirfg_out" size=15 value="<?php echo  date('m/d/Y'); ?>" readonly="readonly"/> 
			<button id="btnsearchfinnishgood_out">Search</button>
			<?php if($this->session->userdata('DX_username') == 'adminx' || $this->session->userdata('DX_username') == 'yayanx' || $this->session->userdata('DX_username') == 'ojahx' || $this->session->userdata('DX_username') == 'gytx' || $this->session->userdata('DX_username') == 'trix' ){ ?>
				<button id="proses_hn001">HN001 PROSES </button>
			<?php }; ?>
			<button id="btnfinnishgood_out_return">Return FG</button>	
			</div>
			<table id="grdfinishgood_out"></table> <div id="pgrdfinishgood_out"> </div>	
		</div> 
	</div>	
</div>	
	<script type="text/javascript">
    
    $(document).ready(function(){
	var tabprod_finishgood_active_tab=0;
		$("#tabprod_finishgood" ).tabs({                                                                  
            select:function(event,ui){    
				tabprod_finishgood_active_tab=ui.index;      
				if (tabprod_finishgood_active_tab==0){
					setTimeout(function(){
						setGridHight($("#grdfinishgood_in"),$("#tabprod_finishgood"),$("#divfinishgood_in_bar"),$("#tabprod_finishgood .ui-tabs-nav").height()+30); 
					},100); 
				}else if (tabprod_finishgood_active_tab==1){
					setTimeout(function(){
						setGridHight($("#grdfinishgood_out"),$("#tabprod_finishgood"),$("#divfinishgood_out_bar"),$("#tabprod_finishgood .ui-tabs-nav").height()+30); 
					},100); 
				}
			}                                                                          
         });   
	
 	$(window).bind('resize', function() {  
			if (tabprod_finishgood_active_tab==0){
				setTimeout(function(){
					setGridHight($("#grdfinishgood_in"),$("#tabprod_finishgood"),$("#divfinishgood_in_bar"),$("#tabprod_finishgood .ui-tabs-nav").height()+30); 
				},100); 
			}else if (tabprod_finishgood_active_tab==1){
				setTimeout(function(){
					setGridHight($("#grdfinishgood_out"),$("#tabprod_finishgood"),$("#divfinishgood_out_bar"),$("#tabprod_finishgood .ui-tabs-nav").height()+30); 
				},100); 
			}
	});
		
	$("input.numeric").numeric();
	
			var currentDate = new Date(); 
		var datesetopt = {
			showOn: "button",
			buttonImageOnly: true,
			buttonImage: "<?php echo base_url()."assets/images/icons/16x16/timespan.png"  ?>",
			buttonText: "Tanggalan",
			dateFormat: 'mm/dd/yy'
		};
		
		$("#nilfgin").numeric();
		
		$("#tglawalfg_in").datepicker(datesetopt);
		$("#tglakhirfg_in").datepicker(datesetopt);
		$("#tglawalfg_out").datepicker(datesetopt);
		$("#tglakhirfg_out").datepicker(datesetopt);
		
		 
		
		$("#btnsearchfinnishgood_in").click(function(){
			var form_data={
				tglawalfg_in:$("#tglawalfg_in").val(), tglakhirfg_in:$("#tglakhirfg_in").val()
			};
			jQuery("#grdfinishgood_in").jqGrid('setGridParam', { postData:form_data });
			$("#grdfinishgood_in").trigger("reloadGrid");
			
		});
		
		$("#btnupdatefinnishgood_in").click(function(){
		
			var id = jQuery("#grdfinishgood_in").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#grdfinishgood_in").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};	
			
			var form_data={
				id_fg_in:ret.id_data_in_dtl,
				qty_in : ret.qty_in,
				qty_in_baru:$("#nilfgin").val()
			};
			
			$("#update_part_finishgood_in").dialog( "destroy" );
			$(".update_part_finishgood_incl").remove();
			$(".update_part_finishgood_incl").html('');
			$("body").append('<div id="update_part_finishgood_in" title="Warning" class="update_part_finishgood_incl"><p>Apakah anda akan Memproses Update Finish Good IN dari ?<br /><strong>' + ret.qty_in + ' menjadi ' + $("#nilfgin").val() + '</strong></p><br />Harap Periksa Baik2 karena perubahan hanya satu kali</div>');
			$("#update_part_finishgood_in").dialog({
				height: 200,
				width: 350,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url :"<?php echo base_url().'production/ct_fg/update_part_finishgood_in'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#update_part_finishgood_in").dialog("close");
								$('#update_part_finishgood_in').dialog("destroy"); 
								$(".update_part_finishgood_incl").remove(); 
								$(".update_part_finishgood_incl").html('');
								$('#grdfinishgood_in').trigger('reloadGrid');
							
							} else { 
								alert(msg.sts+msg.desc);
								$("#update_part_finishgood_in").dialog("close");
								$('#update_part_finishgood_in').dialog("destroy"); 
								$(".update_part_finishgood_incl").remove(); 		

							}
						}
					});
				},
				"CANCEL": function() {
						$( "#update_part_finishgood_in" ).dialog( "close" );

					}
				},
				close : function(){
					$('#update_part_finishgood_in').dialog("destroy"); 
					$(".update_part_finishgood_incl").remove(); 
					$("body").append('<div id="update_part_finishgood_in" title="Warning" class="update_part_finishgood_incl"><p>Apakah anda akan Memproses Update Data Part Yang Kosong?</p></div>');     
					$(".update_part_finishgood_incl").html('');
				},
				open: function(){
					$("body").unblock();
					
				}
			});	
		
		});
		
		$("#btnsearchfinnishgood_out").click(function(){
			var form_data={
				tglawalfg_out:$("#tglawalfg_out").val(), tglakhirfg_out:$("#tglakhirfg_out").val()
			};
			jQuery("#grdfinishgood_out").jqGrid('setGridParam', { postData:form_data });
			$("#grdfinishgood_out").trigger("reloadGrid");
			
		});
		
		jQuery("#grdfinishgood_in").jqGrid({
				url:'<?php echo base_url().'production/ct_fg/loaddatafg_in'; ?>',
				datatype: "json",
				mtype: 'POST',
				postData:{'a':'a', tglawalfg_in:$("#tglawalfg_in").val(), tglakhirfg_in:$("#tglakhirfg_in").val()},
				colNames:['id_data_in_dtl','doc in no', 'doc in date','Assy code', 'Assy No','Assy Name','Jml','Satuan'  ],
				colModel:[
					{name:'id_data_in_dtl',index:'id_data_in_dtl', width:98,  align:"center", hidden:true},
					{name:'doc_in_no',index:'doc_in_no', width:98,  align:"center"},
					{name:'doc_in_date',index:'doc_in_date', width:146,  align:"left"},
					{name:'part_no',index:'part_no', width:120,  align:"left"},
					{name:'part_name',index:'part_name', width:204, align:"left"},
					{name:'part_name_customs',index:'part_name_customs', width:204, align:"left"},
					{name:'qty_in',index:'qty_in', width:82, align:"right"},
					{name:'unit_in',index:'unit_in', width:118}
					
				],  
				rowNum:10,
				rowList:[10,20,30],
				pager: '#pgrdfinishgood_in',
				sortname: 'doc_in_date',
				viewrecords: true,
				sortorder: "desc",
				width: '',
				height:100,
				shrinkToFit: false,
				jsonReader: { repeatitems : false },
			    caption:"FINISH GOOD IN",
			//	rownumbers: true,
				onSelectRow: function(id){
					var stret = jQuery("#grdfinishgood_in").jqGrid('getRowData',id);
					$("#nilfgin").val(stret.qty_in);
					
				} 
			
		}); 
			
		jQuery("#grdfinishgood_in").jqGrid('navGrid','#pgrdfinishgood_in',{edit:false,add:false,del:false,view:true});
		jQuery("#grdfinishgood_in").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});	
			setTimeout(function(){
				setGridHight($("#grdfinishgood_in"),$("#tabprod_finishgood"),$("#divfinishgood_in_bar"),$("#tabprod_finishgood .ui-tabs-nav").height()+30); 
			},200); 
			
		jQuery("#grdfinishgood_out").jqGrid({
				url:'<?php echo base_url().'production/ct_fg/loaddatafg_out1'; ?>',
				datatype: "json",
				mtype: 'POST',
				postData:{'a':'a', tglawalfg_out:$("#tglawalfg_out").val(), tglakhirfg_out:$("#tglakhirfg_out").val()},
				colNames:['doc out no', 'doc out date','Assy code', 'Assy No','Assy Name','Jml','Satuan','Tipe','CAR/NOBC' 
					,'doc_out_to_id'
					,'bc_id_out_hdr'
					,'id_data_out_hdr'
					,'id_data_out_dtl'
					,'id_terkait'
				],
				colModel:[
					{name:'doc_out_no',index:'doc_out_no', width:98,  align:"center"},
					{name:'doc_out_date',index:'doc_out_date', width:98,  align:"left"},
					{name:'assy_code',index:'assy_code', width:120,  align:"left"},
					{name:'part_number',index:'part_number', width:204, align:"left"},
					{name:'part_name_customs',index:'part_name_customs', width:204, align:"left"},
					{name:'qty',index:'qty', width:82, align:"right"},
					{name:'unit_out',index:'unit_out', width:98},
					{name:'Typedok2',index:'Typedok2', width:98},
					{name:'CAR2',index:'CAR2', width:258},
					{name:'doc_out_to_id',index:'doc_out_to_id', width:98},
					{name:'bc_id_out_hdr',index:'bc_id_out_hdr', width:98},
					{name:'id_data_out_hdr',index:'id_data_out_hdr', width:98},
					{name:'id_data_out_dtl',index:'id_data_out_dtl', width:98},
					{name:'id_terkait',index:'id_terkait', width:98},
					
				],  
				rowNum:10,
				rowList:[10,20,30],
				pager: '#pgrdfinishgood_out',
				sortname: 'doc_out_date',
				viewrecords: true,
				sortorder: "desc",
				width: '',
				height:100,
				shrinkToFit: false,
				jsonReader: { repeatitems : false },
			    caption:"FINISH GOOD OUT",
			//	rownumbers: true,
			
			}); 
			
		jQuery("#grdfinishgood_out").jqGrid('navGrid','#pgrdfinishgood_out',{edit:false,add:false,del:false,view:true});
		jQuery("#grdfinishgood_out").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});
		
		setTimeout(function(){
			setGridHight($("#grdfinishgood_out"),$("#tabprod_finishgood"),$("#divfinishgood_out_bar"),$("#tabprod_finishgood .ui-tabs-nav").height() +30); 
		},200); 
		
		$("#btndatafinnishgood_in_out").click(function(){
			var id = jQuery("#grdfinishgood_in").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#grdfinishgood_in").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};	
			
			document.location.href = '<?php echo base_url().'production/ct_fg/download_stock_card2'; ?>'+'?tglawal='+$("#tglawalfg_in").val()+'&tglakhir='+$("#tglakhirfg_in").val()+'&part_no='+ret.part_no
			
			
			
		});
		
		$("#proses_hn001").click(function(){
			var id = jQuery("#grdfinishgood_out").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#grdfinishgood_out").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};	
			
			//if (ret.assy_code.toUpperCase() != 'HN001' ){
				//alert("DATA BUKAN HN001");
				//return false;				
			//}	
			
			var form_data={
				doc_out_to_id:ret.doc_out_to_id,
				bc_id_out_hdr:ret.bc_id_out_hdr,
				id_data_out_hdr:ret.id_data_out_hdr,
				id_data_out_dtl:ret.id_data_out_dtl
				
			};
			
			$("#dlg_update_bc25_hn001").dialog( "destroy" );
			$(".dlg_update_bc25_hn001cl").remove();
			$(".dlg_update_bc25_hn001cl").html('');
			$("body").append('<div id="dlg_update_bc25_hn001" title="Warning" class="dlg_update_bc25_hn001cl"><p>Apakah anda akan memproses HN001 data ini?!?</p><br /> Type Doc BC = '+ ret.Typedok2 + ' ' + ret.CAR2 + ' dll (Lihat No Dokumennya)<br /><b>Pikirkanlah baik2</b></div>');
			$("#dlg_update_bc25_hn001").dialog({
				height: 200,
				width: 250,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
										
					$.ajax({
						url : "<?php echo base_url().'production/ct_fg/replace_hn001'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlg_update_bc25_hn001").dialog("close");
								$('#dlg_update_bc25_hn001').dialog("destroy"); 
								$(".dlg_update_bc25_hn001cl").remove(); 
								$('#grdfinishgood_out').trigger('reloadGrid');
								
								
							} else { 
								alert(msg.sts+' '+msg.desc); 
								$("#dlg_update_bc25_hn001").dialog("close");
								$('#dlg_update_bc25_hn001').dialog("destroy"); 
								$(".dlg_update_bc25_hn001cl").remove(); 

							}
						}
					});
				},
					"CANCEL": function() {
						$( "#dlg_update_bc25_hn001" ).dialog( "close" );

					}
				},
				close : function(){
					$('#dlg_update_bc25_hn001').dialog("destroy"); 
					$(".dlg_update_bc25_hn001cl").remove(); 
					$("body").append('<div id="dlg_update_bc25_hn001" title="Warning" class="dlg_update_bc25_hn001cl"><p>Apakah anda akan peng-cancel-an data ini?!?</p></div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});	
			
		
		});
		
		
		$("#btnfinnishgood_out_return").click(function(){
			var id = jQuery("#grdfinishgood_out").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#grdfinishgood_out").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};	
			var form_data = {
				id_data_out_hdr:ret.id_data_out_hdr
				,id_data_out_dtl: ret.id_data_out_dtl
				,part_number:ret.part_number
				,part_name_customs:ret.part_name_customs
				,assy_code:ret.assy_code
				,qty:ret.qty
				,out_date:ret.doc_out_date
				,tgl_awal : $("#tglawalfg_out").val()
				,tgl_akhir : $("#tglakhirfg_out").val()
			}
			
			$("#returnfg_dlg").load('<?php echo base_url().'production/ct_fg/view_returnfg'; ?>',  form_data, function() {
				$("#returnfg_dlg").dialog({
					modal:true,
					width : 900,
					height : 580,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
                    },
					close : function(){
						$('#returnfg_dlg').dialog("destroy"); 
					    $(".returnfg_dlg_cl").remove(); 
					    $("body").append('<div id="returnfg_dlg" title="PENCARIAN PERIODE TANGGAL" class="returnfg_dlg_cl"></div>'); 
						
					},
					open: function(){
						$("body").unblock();
						
					}
				});
			});	
		});


	});
		  	
</script>
<div id="returnfg_dlg" title="PENCARIAN PERIODE TANGGAL" class="returnfg_dlg_cl"></div>


	
	