<div id="tabbc25_scr_dtl" style="height:460px">
	<ul>
		<li><a id="idtabselling_memo_dtl" href="#divtabselling_memo_dtl">SELLING WIP (MATERIAL)</a></li>
		<li><a id="idtabselling_memo_dtl_in" href="#divtabselling_memo_dtl_in">EX BC</a></li>
		<li><a id="idtabselling_memo_dtl_out" href="#divtabselling_memo_dtl_out">FORM MEMO</a></li>
	</ul>
	<div id="divtabselling_memo_dtl" >
		<table>
			<tr>
				<td>
					<table>
						<tr>
							<td>No Register</td><td>:</td><td><input id="txt_selling_noreg_req"><input type="hidden" id="txt_selling_id_memo_req"></input></td>
						</tr>
						<tr>
							<td>Tgl Register</td><td>:</td><td><input id="txt_selling_tglreg_req" readonly="readonly" ></input>YYYY-MM-DD</td>
						</tr>
						<tr>
							<td></td><td></td><td><button id="btn_selling_req_new_hdr">New</button><button id="btn_selling_req_save_hdr">Save</button>
							<button id="btn_selling_req_del_hdr">Del</button>
							<button id="btn_selling_req_dl_hdr">XLS</button>
							</td>
						</tr>
						<tr>
							
						</tr>
					</table>
					<table id="tbl_selling_memo_hdr"></table> <div id="ptbl_selling_memo_hdr"></div>
				</td>
				<td>
					<table>
						<tr>
							<td>Qty</td><td>:</td><td><input id="txt_selling_memo_qty_dtl"></input></td>
						</tr>
						<tr>
							<td>Weight</td><td>:</td><td><input id="txt_selling_memo_weight_dtl"></input></td>
						</tr>
						<tr>
							<td></td><td></td><td><button id="btn_selling_req_delete_dtl">Delete</button><button id="btn_selling_req_save_dtl">Update</button>
							<button id="btn_selling_req_z0_dtl">Load VGI</button>
							<button id="btn_selling_req_ex_bc_dtl">Ex BC</button>
							</td>
						</tr>
						<tr>
							<td></td><td></td><td></td>
						</tr>
					</table>	
					<table id="tbl_selling_memo_dtl"></table> <div id="ptbl_selling_memo_dtl"></div>
				</td>
			</tr>
		</table>
	</div>
	<div id="divtabselling_memo_dtl_in" >
		<div style="height:35px;">
	
		</div>
		<table id="tbl_selling_memo_hdr_bc25"></table> <div id="ptbl_selling_memo_hdr_bc25"></div>
	</div>
	<div id="divtabselling_memo_dtl_out" >
		<div style="height:35px;">
	
		</div>
		<table id="tbl_selling_memo_hdr_out_view"></table> <div id="ptbl_selling_memo_hdr_out_view"></div>
	</div>

</div>
<script type="text/javascript">
	$(document).ready(function(){
		$( "#tabbc25_scr_dtl" ).tabs();	
		var datesetopt = {
			showOn: "button",
			buttonImageOnly: true,
			buttonImage: "<?php echo base_url()."assets/images/icons/16x16/timespan.png"  ?>",
			buttonText: "Tanggalan",
			dateFormat: 'yy-mm-dd'
		};
		$("#txt_selling_tglreg_req").datepicker(datesetopt);
		
		
		jQuery("#tbl_selling_memo_hdr").jqGrid({
			url:'<?php echo base_url().'production/ct_wip/tbl_wip_selling_memo'; ?>',
			mtype : "post",
			postData:{'param':'1'},
			datatype: "json",
			colNames:[
				'id_memo_selling'
			  ,'NO REG'
			  ,'TGL REG'
			  ,'NO SURAT'
			  ,'TGL SURAT'
			  ,'create date'
			  ,'create by'
			  ,'update date'
			  ,'update by'
			  ,'status'
			],
			colModel:[
				{name:'id_memo_selling',index:'id_memo_selling', width:60, hidden:true},
				{name:'no_register',index:'no_register', width:157},
				{name:'tgl_register',index:'tgl_register', width:100},
				{name:'no_surat',index:'no_surat', width:157},
				{name:'tgl_surat',index:'tgl_surat', width:100},
				{name:'create_date',index:'create_date', width:106, hidden:false},
				{name:'create_by',index:'create_by', width:106, hidden:false},
				{name:'update_date',index:'update_date', width:106, hidden:false},
				{name:'update_by',index:'update_by', width:106, hidden:true},
				{name:'status_data',index:'status_data', width:106, hidden:false}
				],
			rowNum:10,
			rowList:[10,20,30],
			pager: '#ptbl_selling_memo_hdr',
			sortname: 'id_memo_selling',
			viewrecords: true,
			sortorder: "desc",
			width: 400,
			height:250,
			jsonReader: { repeatitems : false },
			caption:"selling memo",
			rownumbers: true,
			shrinkToFit: false,
			afterInsertRow: function(){
				
				
			},			
			gridComplete: function(){
				var rowIDs = jQuery("#tbl_selling_memo_hdr").getDataIDs(); 
				var rowData = $("#tbl_selling_memo_hdr").getRowData();
			
				for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = jQuery("#"+ rowIDs[i],jQuery('#tbl_selling_memo_hdr'));
				   
					switch (rowData[i].status_data) {
						
						case 'DATA PROCESSED OUT':
						   trElement.css({"color":"green"});
						break;
						case 'APPROVED':
						   trElement.css({"color":"red"});
						break;
					}
				}
			},
			
			onSelectRow: function(id){
				var grididpr = jQuery("#tbl_selling_memo_hdr").jqGrid('getGridParam','selrow');
				 if(grididpr){
					var stret = jQuery("#tbl_selling_memo_hdr").jqGrid('getRowData',grididpr);
					var form_data={
						id_hdr:stret.id_memo_selling
					};
					jQuery("#tbl_selling_memo_dtl").jqGrid('setGridParam', { postData:form_data });
					
					$("#txt_selling_id_memo_req").val(stret.id_memo_selling);
					$("#txt_selling_noreg_req").val(stret.no_register);
					$("#txt_selling_tglreg_req").val(stret.tgl_register);
					$("#tbl_selling_memo_dtl").trigger("reloadGrid");
					
					
				
				 }
			}
			
		}); 
		 	
        jQuery("#tbl_selling_memo_hdr").jqGrid('navGrid','#ptbl_selling_memo_hdr',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#tbl_selling_memo_hdr").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});	
	
		jQuery("#tbl_selling_memo_dtl").jqGrid({
			url:'<?php echo base_url().'production/ct_wip/tbl_wip_selling_memo_dtl'; ?>',
			mtype : "post",
			postData:{'id_hdr':'1'},
			datatype: "json",
			colNames:[
				'id_memo_selling_dtl'
				,'id_memo_selling'
			  ,'part_no'
			  ,'qty'
			  ,'unit'
			  ,'weight'
			  ,'no_ex_bc'
			  ,'tgl_ex_bc'
			  ,'no_urut'
			  ,'issue_no'
			  ,'vgi_date'
			   ,'vgi_qty'
			    ,'part_name'
				 ,'part_name_customs'
			],
			colModel:[
				{name:'id_memo_selling_dtl',index:'id_memo_selling_dtl', width:60, hidden:true},
				{name:'id_memo_selling',index:'id_memo_selling', width:60, hidden:true},
				{name:'part_no',index:'part_no', width:157},
				{name:'qty',index:'qty', width:120, align:'right', formatter:'number'},
				{name:'unit',index:'unit', width:120},
				{name:'weight',index:'weight', width:120, align:'right', formatter:'number'},
				{name:'no_ex_bc',index:'no_ex_bc', width:120},
				{name:'tgl_ex_bc',index:'tgl_ex_bc', width:100},
				{name:'no_urut',index:'no_urut', width:100},
				{name:'issue_no',index:'issue_no', width:120},
				{name:'vgi_date',index:'vgi_date', width:120},
				{name:'vgi_qty',index:'vgi_qty', width:120, align:'right', formatter:'number'},
				{name:'part_name',index:'part_name', width:160},
				{name:'part_name_customs',index:'part_name_customs', width:120}
				],
			rowNum:10,
			rowList:[10,20,30],
			pager: '#ptbl_selling_memo_dtl',
			sortname: 'id_memo_selling',
			viewrecords: true,
			sortorder: "desc",
			width: 620,
			height:250,
			jsonReader: { repeatitems : false },
			caption:"selling memo DETIL ",
			rownumbers: true,
			shrinkToFit: false,
			afterInsertRow: function(){
				
				
			},			
			gridComplete: function(){
				var rowIDs = jQuery("#tbl_selling_memo_dtl").getDataIDs(); 
				var rowData = $("#tbl_selling_memo_dtl").getRowData();
			
				for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = jQuery("#"+ rowIDs[i],jQuery('#tbl_selling_memo_dtl'));
				   
					switch (rowData[i].status_data) {
						
						case 'DATA PROCESSED OUT':
						   trElement.css({"color":"green"});
						break;
						case 'APPROVED':
						   trElement.css({"color":"red"});
						break;
					}
				}
			},
			
			onSelectRow: function(id){
				var grididpr = jQuery("#tbl_selling_memo_dtl").jqGrid('getGridParam','selrow');
				 if(grididpr){
					var stret = jQuery("#tbl_selling_memo_dtl").jqGrid('getRowData',grididpr);
					
					//var form_data={
					//	id_hdr:stret.id_memo_selling_hdr
					//};
					//jQuery("#tbl_selling_memo_dtl").jqGrid('setGridParam', { postData:form_data });
					
					$("#txt_selling_memo_qty_dtl").val(stret.qty);
					$("#txt_selling_memo_weight_dtl").val(stret.weight);
				 }
					
					
					
				
				 
			}
			
		}); 
		 	
        jQuery("#tbl_selling_memo_dtl").jqGrid('navGrid','#ptbl_selling_memo_dtl',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#tbl_selling_memo_dtl").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});	
		
		
		$("#btn_selling_req_new_hdr").button().click(function(){
			$("#txt_selling_noreg_req").val("");
			$("#txt_selling_tglreg_req").val("");
			$("#txt_selling_id_memo_req").val("");
		});
		 
		$("#btn_selling_req_save_hdr").button().click(function(){
			
			
			
			var form_data={
				id_memo_selling_hdr:$("#txt_selling_id_memo_req").val(),
				txt_selling_noreg_req:$("#txt_selling_noreg_req").val(),
				txt_selling_tglreg_req:$("#txt_selling_tglreg_req").val()
				
				
			};
			
			$("#dlgselling_memo_hdr_save").dialog( "destroy" );
			$(".dlgselling_memo_hdr_savecl").remove();
			$(".dlgselling_memo_hdr_savecl").html('');
			$("body").append('<div id="dlgselling_memo_hdr_save" title="Warning" class="dlgselling_memo_hdr_savecl"><p>Apakah anda akan memproses data ini?!?</p></div>');
			$("#dlgselling_memo_hdr_save").dialog({
				height: 200,
				width: 250,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : "<?php echo base_url().'production/ct_wip/proses_save_memo_hdr'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlgselling_memo_hdr_save").dialog("close");
								$('#dlgselling_memo_hdr_save').dialog("destroy"); 
								$(".dlgselling_memo_hdr_savecl").remove(); 
								jQuery("#tbl_selling_memo_hdr").trigger('reloadGrid');
								
							} else { 
								alert(msg.sts+' '+msg.desc); 
								$("#dlgselling_memo_hdr_save").dialog("close");
								$('#dlgselling_memo_hdr_save').dialog("destroy"); 
								$(".dlgselling_memo_hdr_savecl").remove(); 
								jQuery("#tbl_selling_memo_hdr").trigger('reloadGrid');

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

					}
				},
				close : function(){
					$('#dlgselling_memo_hdr_save').dialog("destroy"); 
					$(".dlgselling_memo_hdr_savecl").remove(); 
					$("body").append('<div id="dlgselling_memo_hdr_save" title="Warning" class="dlgselling_memo_hdr_savecl"><p>Apakah anda akan memproses data ini, Data yang telah keluar akan di cancel juga?!?</p></div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});	
			
			
			
		}); 
		$("#btn_selling_req_del_hdr").button().click(function(){
			var id = jQuery("#tbl_selling_memo_hdr").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tbl_selling_memo_hdr").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};	
			var form_data = {
				id_memo_selling : ret.id_memo_selling
				
			}
				
			$("#dlgselling_memo_delete_hdr").dialog( "destroy" );
			$(".dlgselling_memo_delete_hdrcl").remove();
			$(".dlgselling_memo_delete_hdrcl").html('');
			$("body").append('<div id="dlgselling_memo_delete_hdr" title="Warning" class="dlgselling_memo_delete_hdrcl"><p>Apakah anda akan memproses data ini?!?</p></div>');
			$("#dlgselling_memo_delete_hdr").dialog({
				height: 200,
				width: 250,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : "<?php echo base_url().'production/ct_wip/proses_delete_memo_hdr'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlgselling_memo_delete_hdr").dialog("close");
								$('#dlgselling_memo_delete_hdr').dialog("destroy"); 
								$(".dlgselling_memo_delete_hdrcl").remove(); 
								jQuery("#tbl_selling_memo_dtl").trigger('reloadGrid');
								
							} else { 
								alert(msg.sts+' '+msg.desc); 
								$("#dlgselling_memo_delete_hdr").dialog("close");
								$('#dlgselling_memo_delete_hdr').dialog("destroy"); 
								$(".dlgselling_memo_delete_hdrcl").remove(); 
								jQuery("#tbl_selling_memo_dtl").trigger('reloadGrid');

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

					}
				},
				close : function(){
					$('#dlgselling_memo_delete_hdr').dialog("destroy"); 
					$(".dlgselling_memo_delete_hdrcl").remove(); 
					$("body").append('<div id="dlgselling_memo_delete_hdr" title="Warning" class="dlgselling_memo_delete_hdrcl"><p>Apakah anda akan memproses data ini?!?</p></div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});		
			
			
			
			
		}); 
		
		$("#btn_selling_req_delete_dtl").button().click(function(){
			var id = jQuery("#tbl_selling_memo_dtl").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tbl_selling_memo_dtl").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};	
			var form_data = {
				id_memo_selling_dtl : ret.id_memo_selling_dtl
				
			}
			
			$("#dlgselling_memo_delete_dtl").dialog( "destroy" );
			$(".dlgselling_memo_delete_dtlcl").remove();
			$(".dlgselling_memo_delete_dtlcl").html('');
			$("body").append('<div id="dlgselling_memo_delete_dtl" title="Warning" class="dlgselling_memo_delete_dtlcl"><p>Apakah anda akan memproses data ini?!?</p></div>');
			$("#dlgselling_memo_delete_dtl").dialog({
				height: 200,
				width: 250,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : "<?php echo base_url().'inventory/ct_selling/proses_delete_memo_dtl'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlgselling_memo_delete_dtl").dialog("close");
								$('#dlgselling_memo_delete_dtl').dialog("destroy"); 
								$(".dlgselling_memo_delete_dtlcl").remove(); 
								jQuery("#tbl_selling_memo_dtl").trigger('reloadGrid');
								
							} else { 
								alert(msg.sts+' '+msg.desc); 
								$("#dlgselling_memo_delete_dtl").dialog("close");
								$('#dlgselling_memo_delete_dtl').dialog("destroy"); 
								$(".dlgselling_memo_delete_dtlcl").remove(); 
								jQuery("#tbl_selling_memo_dtl").trigger('reloadGrid');

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

					}
				},
				close : function(){
					$('#dlgselling_memo_delete_dtl').dialog("destroy"); 
					$(".dlgselling_memo_delete_dtlcl").remove(); 
					$("body").append('<div id="dlgselling_memo_delete_dtl" title="Warning" class="dlgselling_memo_delete_dtlcl"><p>Apakah anda akan memproses data ini?!?</p></div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});	
			
		}); 
		$("#btn_selling_req_save_dtl").button().click(function(){
			var id = jQuery("#tbl_selling_memo_dtl").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tbl_selling_memo_dtl").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};	
			
			var form_data = {
				id_selling_memo_dtl : ret.id_selling_memo_dtl
				,qty : $("#txt_selling_memo_qty_dtl").val()
				,weight: $("#txt_selling_memo_weight_dtl").val()
			}
			$("#dlgselling_memo_update_dtl").dialog( "destroy" );
			$(".dlgselling_memo_update_dtlcl").remove();
			$(".dlgselling_memo_update_dtlcl").html('');
			$("body").append('<div id="dlgselling_memo_update_dtl" title="Warning" class="dlgselling_memo_update_dtlcl"><p>Apakah anda akan memproses data ini?!?</p></div>');
			$("#dlgselling_memo_update_dtl").dialog({
				height: 200,
				width: 250,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : "<?php echo base_url().'inventory/ct_selling/proses_save_memo_dtl'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlgselling_memo_update_dtl").dialog("close");
								$('#dlgselling_memo_update_dtl').dialog("destroy"); 
								$(".dlgselling_memo_update_dtlcl").remove(); 
								jQuery("#tbl_selling_memo_dtl").trigger('reloadGrid');
								
							} else { 
								alert(msg.sts+' '+msg.desc); 
								$("#dlgselling_memo_update_dtl").dialog("close");
								$('#dlgselling_memo_update_dtl').dialog("destroy"); 
								$(".dlgselling_memo_update_dtlcl").remove(); 
								jQuery("#tbl_selling_memo_dtl").trigger('reloadGrid');

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

					}
				},
				close : function(){
					$('#dlgselling_memo_update_dtl').dialog("destroy"); 
					$(".dlgselling_memo_update_dtlcl").remove(); 
					$("body").append('<div id="dlgselling_memo_update_dtl" title="Warning" class="dlgselling_memo_update_dtlcl"><p>Apakah anda akan memproses data ini?!?</p></div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});	
			
			
			
		}); 
		$("#btn_selling_req_z0_dtl").button().click(function(){
			var id = jQuery("#tbl_selling_memo_hdr").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tbl_selling_memo_hdr").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};	
			var form_data = {
				id_memo_selling : ret.id_memo_selling
				,no_register : ret.no_register
				,tgl_register : ret.tgl_register
			}	
			
			
			$("#view_selling_memo_z0_hdr").load('<?php echo base_url().'production/ct_wip/view_wip_selling_memo_vgi'; ?>',  form_data, function() {
				$("#view_selling_memo_z0_hdr").dialog({
					modal:true,
					width : 900,
					height : 499,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
                    },
					close : function(){
						$('#view_selling_memo_z0_hdr').dialog("destroy"); 
					    $(".view_selling_memo_z0_hdr_cl").remove(); 
					    $("body").append('<div id="view_selling_memo_z0_hdr" title="Z0" class="view_selling_memo_z0_hdr_cl"></div>'); 
						
					},
					open: function(){
						$("body").unblock();
						
					}
				});
			});
			
		}); 
		
		$("#btn_selling_req_dl_hdr").button().click(function(){
			var id = jQuery("#tbl_selling_memo_hdr").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tbl_selling_memo_hdr").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};	
			
			document.location.href = '<?php echo base_url().'inventory/ct_selling/selling_memo_req_dl_hdr'; ?>'+'?idnya='+ret.id_memo_selling_hdr
			
			
			
		});
		
		$("#btn_selling_req_ex_bc_dtl").button().click(function(){
			var id = jQuery("#tbl_selling_memo_dtl").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tbl_selling_memo_dtl").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};	
			
			var form_data = {
				id_selling_memo_dtl : ret.id_selling_memo_dtl
				,part_no : ret.part_no
				
			}
			
			$("#view_selling_memo_ex_bc_hdr").load('<?php echo base_url().'inventory/ct_selling/view_selling_memo_ex_bc'; ?>',  form_data, function() {
				$("#view_selling_memo_ex_bc_hdr").dialog({
					modal:true,
					width : 900,
					height : 499,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
                    },
					close : function(){
						$('#view_selling_memo_ex_bc_hdr').dialog("destroy"); 
					    $(".view_selling_memo_ex_bc_hdr_cl").remove(); 
					    $("body").append('<div id="view_selling_memo_ex_bc_hdr" title="ex_bc" class="view_selling_memo_ex_bc_hdr_cl"></div>'); 
						
					},
					open: function(){
						$("body").unblock();
						
					}
				});
			});
			
			
			
			
		});
		
		
		
	});
</script>
<div id="view_selling_memo_z0_hdr" title="Z0" class="view_selling_memo_z0_hdr_cl"></div>
<div id="view_selling_memo_ex_bc_hdr" title="ex_bc" class="view_selling_memo_ex_bc_hdr_cl"></div>
