<div style="height:30px;">
	<button id="btninvsummary">View Summary Inv</button>Part Number : <input id="part_number_inv" type="text" />
	<?php if($this->session->userdata('DX_username') == 'admin' || $this->session->userdata('DX_username') == 'yayan' || $this->session->userdata('DX_username') == 'ojah'){ ?>
		<button id="btnupdateinvpartnumber">Update Part</button>
	<?php }; ?>
</div>
<input type="hidden" id="hdnidinv_hdr" value="<?php echo $id_inv_hdr; ?>"/>
<table id="tblinv_draft_dtl"></table> <div id="ptblinv_draft_dtl"></div>
<div id="div_part_null_hib" style="color:red"><?php echo $test; ?></div>
<script type="text/javascript">
    
    $(document).ready(function(){
    		$("#btnupdateinvpartnumber").click(function(){
			var id = jQuery("#tblinv_draft_dtl").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tblinv_draft_dtl").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};	
			
			var form_data = {
				
				inv_hdr_idxxx:ret.inv_hdr_id,
				part_number_invxxx:$("#part_number_inv").val(),
				inv_dtlxxx:ret.inv_dtl
			
			};
						
			$("#update_partinv_bc23_manual").dialog( "destroy" );
			$(".update_partinv_bc23_manualcl").remove();
			$(".update_partinv_bc23_manualcl").html('');
			$("body").append('<div id="update_partinv_bc23_manual" title="Warning" class="update_partinv_bc23_manualcl"><p>PAK YAYAN/PAK NUR Apakah anda akan Memproses Data ini?</p><br />Harap Periksa Baik2 karena perubahan hanya satu kali</div>');
			$("#update_partinv_bc23_manual").dialog({
				height: 200,
				width: 350,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url :"<?php echo base_url().'exim/ct_inv_detil_draft/update_part_inv'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#update_partinv_bc23_manual").dialog("close");
								$('#update_partinv_bc23_manual').dialog("destroy"); 
								$(".update_partinv_bc23_manualcl").remove(); 
								$(".update_partinv_bc23_manualcl").html('');
								$('#tblinv_draft_dtl').trigger('reloadGrid');
								
							} else { 
								alert(msg.sts+msg.desc);
								$("#update_partinv_bc23_manual").dialog("close");
								$('#update_partinv_bc23_manual').dialog("destroy"); 
								$(".update_partinv_bc23_manualcl").remove(); 		

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

					}
				},
				close : function(){
					$('#update_partinv_bc23_manual').dialog("destroy"); 
					$(".update_partinv_bc23_manualcl").remove(); 
					$("body").append('<div id="update_partinv_bc23_manual" title="Warning" class="update_partinv_bc23_manualcl"><p>Apakah anda akan Memproses Data ini Menjadi Data BC23?</p></div>');     
					$(".update_partinv_bc23_manualcl").html('');
				},
				open: function(){
					$("body").unblock();
					
				}
			});	
		
		});
		$("#btninvsummary").button().click(function(){
			var form_data =  {q:'1', id_inv_hdr:$("#hdnidinv_hdr").val()};
			$("#frminvdtl_summary_dlg").load('<?php echo base_url().'exim/ct_inv_detil_draft/view_inv_summary1'; ?>', form_data, function() {
				$("#frminvdtl_summary_dlg").dialog({
					modal:true,
					width : 600,
					height : 530,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
                    },
					close : function(){
						$('#frminvdtl_summary_dlg').dialog("destroy"); 
					    $(".frminvdtl_summary_dlg_cl").remove(); 
					    $("body").append('<div id="frminvdtl_summary_dlg" title="INVOICE DATA SUMMARY DETAIL" class="frminvdtl_summary_dlg_cl"></div>'); 
	
					},
					open: function(){
						$("body").unblock();
						
					}
				});
			});
		});	
		
		jQuery("#tblinv_draft_dtl").jqGrid({
			url:'<?php echo base_url().'exim/ct_inv_detil_draft/loaddata'; ?>',
			mtype : "post",
			postData:{'q':'1', 'id_inv_hdrx':<?php echo $id_inv_hdr; ?>},
			datatype: "json",
			colNames:['ID','ID Hdr' , 'Part Number', 'Part Name','Part Name Customs' ,'Qty', 'UOM', 'Unit Price', 'Val','Total Amount' ,'Box', 'Pack'],
			colModel:[
				{name:'inv_dtl',index:'inv_dtl', width:60, hidden:true},
				{name:'inv_hdr_id',index:'inv_hdr_id', width:60, hidden:true},
				{name:'r15',index:'r15', width:119, hidden:false},
				{name:'part_name',index:'part_name', width:184, hidden:false},
				{name:'part_name_customs',index:'part_name_customs', width:160, hidden:false},
				{name:'qty',index:'qty', width:80, hidden:false,  align:'right', formatter:'number', formatoptions: { decimalPlaces: 4 }},
				{name:'r7',index:'r7', width:50, hidden:false},
				{name:'amount',index:'amount', width:90, hidden:false,  align:'right'},
				{name:'kdval',index:'kdval', width:50, hidden:false},
				{name:'totalamount',index:'totalamount', width:90, hidden:false,  align:'right', formatter:'number', formatoptions: { decimalPlaces: 4 }},
				{name:'box',index:'box', width:50, hidden:false, align:'right'},
				{name:'pack',index:'pack', width:50, hidden:false, align:'right'},
			],
			rowNum:15,
			rowList:[15,30,40],
			pager: '#ptblinv_draft_dtl',
			sortname: 'inv_dtl',
			viewrecords: true,
			sortorder: "asc",
			width: 970,
			height:280,
			jsonReader: { repeatitems : false },
			caption:"INVOICE ITEMS DATA",
			rownumbers: true,
			shrinkToFit: false,
			afterInsertRow: function(){
				
				
			},
			onSelectRow: function(ids) { 
				var ret = jQuery("#tblinv_draft_dtl").jqGrid('getRowData',ids);
				$("#part_number_inv").val(ret.r15);	
					
			}
		}); 
			
                        
		jQuery("#tblinv_draft_dtl").jqGrid('navGrid','#ptblinv_draft_dtl',{edit:false,add:false,del:false,view:true, search:true}, {height:175, width:250});
		jQuery("#tblinv_draft_dtl").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});
	

	});
		  	
</script>

<div id="frminvdtl_summary_dlg" title="INVOICE DATA SUMMARY DETAIL" class="frminvdtl_summary_dlg_cl"></div>


	
	