<div style="height:40px;">
	<div style="top:30px;position:absolute;">
	<button id="btnupdateitem">UPDATE UNKNOWN PART</button>
	<button id="btnrecalculatepart">Re-CALCULATE</button>
	<?php if($this->session->userdata('DX_username') == 'admin' || $this->session->userdata('DX_username') == 'yayan' || $this->session->userdata('DX_username') == 'nurhadi' || $this->session->userdata('DX_username') == 'ojah'){ ?>
		<span style="padding-left:10px" /><input id="inputdatapartnumber"></input> <button id="btnupdate_partnumber_bc23" >Update Part</button>
	<?php } ?>
	</div>
</div>
<input type="hidden" id="hdnidinv_hdr" value="<?php echo $id_inv_hdr; ?>"/>
<input type="hidden" id="hdnidbc23noinv" value="<?php echo $noinv; ?>"/>
<input type="hidden" id="hdnidbc23hdr" value="<?php echo $idhdrbc23; ?>" />
<table id="tblinv_draftbc23_dtl"></table> <div id="ptblinv_draftbc23_dtl"></div>
<script type="text/javascript">
    
    $(document).ready(function(){
		$("#btnrecalculatepart").button().click(function(){ 
			var id = jQuery("#tblinv_draftbc23_dtl").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tblinv_draftbc23_dtl").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};	
			
			var form_data = {
				part_number: ret.part_number,
				id_dtl: ret.id_bc_in_dtl_partnumber,
				inv_dtl: ret.inv_dtl,
				inv_hdr_id: ret.inv_hdr_id,
				noinv: ret.noinv,
				id_hdr:$("#hdnidbc23hdr").val()
			};
			
			$("#dlgcalculatepart").dialog( "destroy" );
			$(".dlgcalculatepart_cl").remove();
			$(".dlgcalculatepart_cl").html('');
			$("body").append('<div id="dlgcalculatepart" title="Warning" class="dlgcalculatepart_cl"><p>Apakah anda akan melakukan kalkulasi ulang data ini..?</p><br />Mohon diperiksa kembali datanya..Nomor Seri Akan Berubah!!</div>');
			$("#dlgcalculatepart").dialog({
				height: 200,
				width: 250,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : "<?php echo base_url().'exim/ct_bc23_view_dtl/recalculatepart'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlgcalculatepart").dialog("close");
								$('#dlgcalculatepart').dialog("destroy"); 
								$(".dlgcalculatepart_cl").remove(); 
								jQuery("#tblbc23detilitems").trigger('reloadGrid');
							} else { 
								alert(msg.sts+msg.desc); 
								$("#dlgcalculatepart").dialog("close");
								$('#dlgcalculatepart').dialog("destroy"); 
								$(".dlgcalculatepart_cl").remove(); 
								jQuery("#tblbc23detilitems").trigger('reloadGrid');
							}
						}
					});
				},
					"CANCEL": function() {
						$( "#dlgcalculatepart" ).dialog( "close" );

					}
				},
				close : function(){
					$('#dlgcalculatepart').dialog("destroy"); 
					$(".dlgcalculatepart_cl").remove(); 
					$("body").append('<div id="dlgcalculatepart" title="Warning" class="dlgcalculatepart_cl"><p>Apakah anda akan melakukan kalkulasi ulang data ini?</p><br />Mohon diperiksa kembali datanya..Nomor Seri Akan Berubah!!</div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});
		});
		$("#btnupdateitem").button().click(function(){
			
			var id = jQuery("#tblinv_draftbc23_dtl").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tblinv_draftbc23_dtl").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};	
			
			var form_data = {
				part_no: ret.part_number
			
			};
			
			$.ajax({
				url : "<?php echo base_url().'exim/ct_bc23_view_dtl/cekstatusparths'; ?>",
				type : 'POST',
				dataType: 'json',
				data : form_data,
				success: function(msg){
					if (msg.sts == '00'){
						loaddataparths($("#inv_hdr_idbc23").val(), $("#bc23noinv").val(), ret.part_number, ret.inv_dtl,ret.id_dtl, ret.part_name_customs
								 ,msg.id,msg.part_name,msg.hs_code,msg.bm,msg.cek_price);
					} else {  
						loaddataparths($("#inv_hdr_idbc23").val(), $("#bc23noinv").val(), ret.part_number, ret.inv_dtl,ret.id_bc_in_dtl_partnumber, ret.part_name_customs
								 ,msg.id,msg.part_name,msg.hs_code,msg.bm,msg.cek_price);
						
					};
				}
			});
			
			function loaddataparths(id_inv_hdr, noinv, part_number,inv_dtl, id_bc_in_dtl_partnumber, part_name_customs, idx,part_name,hs_code,bm,cek_price){
				var form_data={
					id_inv_hdr:id_inv_hdr, 
					'noinv':noinv,
					part_number:part_number, 
					inv_dtl:inv_dtl,
					id_dtl:id_bc_in_dtl_partnumber, 
					part_name_customs:part_name_customs, 
					idx:idx,
					part_name:part_name,
					hs_code:hs_code,
					bm:bm,
					cek_price:cek_price
				};
				
				$("#frmupdatepartnumberbc23_dlg").load('<?php echo base_url().'exim/ct_bc23_view_dtl/updatepartnumber'; ?>', form_data , function() {
					$("#frmupdatepartnumberbc23_dlg").dialog({
						modal:true,
						width : 1000,
						height : 450,
						buttons: {
							"Close": function() {  
								$(".ui-dialog-titlebar-close").trigger('click');  
								
							}
						},
						close : function(){
							$('#frmupdatepartnumberbc23_dlg').dialog("destroy"); 
							$(".frmupdatepartnumberbc23_dlg_cl").remove(); 
							$("body").append('<div id="frmupdatepartnumberbc23_dlg" title="UPDATE PART NUMBER" class="frmupdatepartnumberbc23_dlg_cl"></div>'); 
		
						},
						open: function(){
							$("body").unblock();
							
						}
					});
				});
			};		
				
		});
		
		jQuery("#tblinv_draftbc23_dtl").jqGrid({
			url:'<?php echo base_url().'exim/ct_bc23_view_dtl/datapartnumberbc23'; ?>',
			mtype : "post",
			postData:{'q':'1', 'id_inv_hdrx':$("#hdnidinv_hdr").val(), nonoinvbc23:$("#hdnidbc23noinv").val(), 'idbc23hdr':$("#hdnidbc23hdr").val() },
			datatype: "json",
			colNames:['id_bc_in_dtl_partnumber','inv_dtl' , 'inv_hdr_id', 'noinv','car' ,'nobc','tglbc','seri detil','part number',
						'part name','part name customs', 'qty', 'unit','harga' ,'kdval', 'box','pack'],
			colModel:[
				{name:'id_bc_in_dtl_partnumber',index:'id_bc_in_dtl_partnumber', width:60, hidden:true},
				{name:'inv_dtl',index:'inv_dtl', width:60, hidden:true},
				{name:'inv_hdr_id',index:'inv_hdr_id', width:119, hidden:true},
				{name:'noinv',index:'noinv', width:106, hidden:false},
				{name:'car',index:'car', width:160, hidden:true},
				{name:'nobc',index:'nobc', width:80, hidden:true,  align:'right', formatter:'number'},
				{name:'tglbc',index:'tglbc', width:50, hidden:true},
				{name:'seri_detil',index:'seri_detil', width:90, hidden:true,  align:'right'},
				{name:'part_number',index:'part_number', width:131, hidden:false},
				{name:'part_name',index:'part_name', width:151, hidden:false},
				{name:'part_name_customs',index:'part_name_customs', width:190, hidden:false},
				{name:'qty',index:'qty', width:131, hidden:false,align:'right', formatter:'number', formatoptions: { decimalPlaces: 4 }},
				{name:'unit',index:'unit', width:50, hidden:false},
				{name:'harga',index:'harga', width:50, hidden:false, align:'right'},
				{name:'kdval',index:'kdval', width:50, hidden:false, align:'right'},
				{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_draftbc23_dtl',
			sortname: 'id_bc_in_dtl_partnumber',
			viewrecords: true,
			sortorder: "asc",
			width: 970,
			height:310,
			jsonReader: { repeatitems : false },
			caption:"INVOICE ITEMS DATA",
			rownumbers: true,
			shrinkToFit: false,
			afterInsertRow: function(){
				
				
			},
			onSelectRow:  function(ids) {
				var ret = jQuery("#tblinv_draftbc23_dtl").jqGrid('getRowData',ids);
				$("#inputdatapartnumber").val(ret.part_number);
			
			} 
		}); 
			
                        
		jQuery("#tblinv_draftbc23_dtl").jqGrid('navGrid','#ptblinv_draftbc23_dtl',{edit:false,add:false,del:false,view:true, search:true}, {height:175, width:250});
		jQuery("#tblinv_draftbc23_dtl").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});
	
		$("#btnupdate_partnumber_bc23").button().click(function(){
			var id = jQuery("#tblinv_draftbc23_dtl").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tblinv_draftbc23_dtl").jqGrid('getRowData',id);
				
			} else {
				
				alert("Silahkan Pilih Data");
				//$('#tabdocbc23_dtl').tabs({ selected: 0 });
				return false;
			};	
			
		
			$("#dlgupdate_partnumber_bc23").dialog( "destroy" );
			$(".dlgupdate_partnumber_bc23_cl").remove();
			$(".dlgupdate_partnumber_bc23_cl").html('');
			
			$("body").append('<div id="dlgupdate_partnumber_bc23" title="Warning" class="dlgupdate_partnumber_bc23_cl"><p>Apakah anda akan melakukan <b>UPDATE</b> part number ini?!?</p><br /><b>JANGAN LUPA UPDATE DATA PEMASUKANNYA JUGA YA!</b></div>');
			
			var form_data = {
				id_bc_in_hdr:$("#hdnidbc23hdr").val(),
				id_bc_in_dtl_partnumber:ret.id_bc_in_dtl_partnumber,
				inputdatapartnumber:$("#inputdatapartnumber").val()
			};
			
			
			$("#dlgupdate_partnumber_bc23").dialog({
				height: 160,
				width: 250,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : "<?php echo base_url().'exim/ct_bc23_view_dtl/update_partnumber_bc23'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlgupdate_partnumber_bc23").dialog("close");
								$('#dlgupdate_partnumber_bc23').dialog("destroy"); 
								$(".dlgupdate_partnumber_bc23_cl").remove(); 
								$(".dlgupdate_partnumber_bc23_cl").html('');
								$('#tblinv_draftbc23_dtl').trigger('reloadGrid');

							} else { 
								alert(msg.sts+msg.desc); 
								$("#dlgupdate_partnumber_bc23").dialog("close");
								$('#dlgupdate_partnumber_bc23').dialog("destroy"); 
								$(".dlgupdate_partnumber_bc23_cl").remove(); 

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

					}
				},
				close : function(){
					$('#dlgupdate_partnumber_bc23').dialog("destroy"); 
					$(".dlgupdate_partnumber_bc23_cl").remove(); 
					$("body").append('<div id="dlgupdate_partnumber_bc23" title="Warning" class="dlgupdate_partnumber_bc23_cl"><p>Apakah anda akan melakukan <b>UPDATE</b> part number ini?!?</p><br /><b>JANGAN LUPA UPDATE DATA PEMASUKANNYA JUGA YA!</b></div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});
		});
		
	});
		  	
</script>
<div id="frmupdatepartnumberbc23_dlg" title="UPDATE PART NUMBER" class="frmupdatepartnumberbc23_dlg_cl">


	
	