<div style="height:10px;">
	<input type="hidden" id="txt_idbc261_exim_hdr" />
	<input type="hidden" id="txt_idbc261_bc_asal" />
</div>
<div id="tabperhitungan_exim" style="height:420px">
	<ul>
		<li><a id="idtabperhitungan_exim_fileuploaded" href="#divtabperhitungan_exim_fileuploaded">File Perhitungan Exim Uploaded</a></li>
		<li><a id="idtabperhitungan_exim_viewdata" href="#divtabperhitungan_exim_viewdata">Proses & View Data</a></li>
		<li><a id="idtabprosesbc261" href="#divtabprosesbc261">Proses BC261</a></li>
	</ul>
	<div id="divtabperhitungan_exim_fileuploaded">
		<h1>Upload File Perhitungan Exim</h1>
		<form method="post" action="" id="upload_file_perhitungan_exim">
		  <label for="userfileperhitungan_exim">File</label>
		  <input type="file" name="userfileperhitungan_exim" id="userfileperhitungan_exim" size="40" />
		  <input type="submit" name="submit" id="submit" value="Upload" />
		</form>
		<h2>Files</h2>
		<hr>
		
		<div id="files_perhitungan_exim" style="font-weight:bold;font-size:17px;"></div>
		<table id="tbltabperhitungan_exim"></table> <div id="ptbltabperhitungan_exim"></div>   	
	</div>
	<div id="divtabperhitungan_exim_viewdata">
		
		<div>
			<table>
				<tr>
					<td>NO. KONTRAK</td>
					<td>:</td>
					<td><input type="text" id="txtnokontrak" style="width:200px"/></td>
					<td>TGL. KONTRAK</td>
					<td>:</td>
					<td><input type="text" id="txttglkontrak" placeholder="yyyy-mm-dd"/></td>
				</tr>
				<tr>
					<td>Nama Subkon</td>
					<td>:</td>
					<td><input type="text" id="txtnamasubkontrak" style="width:200px"/></td>
					<td>Almt. Subkon</td>
					<td>:</td>
					<td><input type="text" id="txtalmtsubkontrak" style="width:320px"/></td>
				</tr>
				<tr>
					<td>Custom Bond</td>
					<td>:</td>
					<td><input type="number" min="0"  id="txtcustombond" style="text-align:right" /></td>
					<td>Hari Subkon</td>
					<td>:</td>
					<td><input type="number" id="txtharisubkon" min="0" style="text-align:right"/></td>
				</tr>
				<tr>
					<td>Kurs</td>
					<td>:</td>
					<td><input type="number" id="txtkurs"  min="0" style="text-align:right"/></td>
					<td>Kd Val</td>
					<td>:</td>
					<td><input type="text" id="txtkdval" style="text-align:right"/></td>
				</tr>
				<tr>
					<td>Jenis Brg Jadi</td>
					<td>:</td>
					<td><input type="text" id="txtjenisbarangjadi" style="width:200px"/></td>
					<td>NPWP Subkon</td>
					<td>:</td>
					<td><input type="text" id="txtnpwpsubkontrak" /></td>
				</tr>
			</table>
			<button id="btnbc261prosessubkon" >Proses</button><button id="btnbc261viewdataexcel" >View Data Excel</button><span id="bc261filename"></span><button id="btnbc261deldataexcel" >Del</button>
			<hr />
			<table id="tblbc261_perhitungan_exim_hdr"></table> <div id="ptblbc261_perhitungan_exim_hdr"></div>
		</div>
		
		
	</div>
	<div id="divtabprosesbc261">
		<div>
			<table>
			<tr>
				<td>No BC:<input type="text" id="bc261_no" />TG BC:<input type="text" id="bc261_tg" /><button id="btnsearchbc261_add">Cari</button><button id="btnprosesbc261">Proses</button></td>
				<td></td>
				<td><span id="span_notg_kontrak"></span></td>
			</tr>
			<tr>
				<td><table id="tblbc261_perhitungan_exim_dtlx"></table> <div id="ptblbc261_perhitungan_exim_dtlx"></div></td>
				<td><input type="text" id="bc261_jml_keluar" style="width:60px"/><br /><button id="btnadd_jml_keluar_bc261">Add >></button><br /><button id="btndel_jml_keluar_bc261">del</button></td>
				<td><table id="tbl_bc261_modul_asal_bc"></table> <div id="ptbl_bc261_modul_asal_bc"></td>
			</tr>
		</table>
		</div>
	</div>
</div>
<script type="text/javascript">

//-->
	
	
    $(document).ready(function(){
		$("#tabperhitungan_exim").tabs();
		
		var datesetopt = {
			showOn: "button",
			buttonImageOnly: true,
			buttonImage: "<?php echo base_url()."assets/images/icons/16x16/timespan.png"  ?>",
			buttonText: "Tanggalan",
			dateFormat: 'yy-mm-dd'
		};
		
		$("#txttglkontrak").datepicker(datesetopt);
		$("#bc261_tg").datepicker(datesetopt);
		function refresh_files()
		{
		   $.get('<?php echo base_url().'loaderfiles/exim/perhitungan_exim'; ?>')
		   .success(function (data){
			  $('#files_perhitungan_exim').html(data);
		   });
		};
		$('#userfilekurir').live('change', function(){
			$('#files_perhitungan_exim').html('<p>'+ $('#userfileperhitungan_exim').val() +'</p>'); 
		});
		
		jQuery.extend({
			handleError: function( s, xhr, status, e ) {
			// If a local callback was specified, fire it
				if ( s.error )
					s.error( xhr, status, e );
				// If we have some XML response text (e.g. from an AJAX call) then log it in the console
				else if(xhr.responseText)
					console.log(xhr.responseText);
			}
		});
		
		$(function() {
			$('#upload_file_perhitungan_exim').submit(function(e) {
				e.preventDefault();
				$.ajaxFileUpload({
				 url         :'./exim/ct_bc261/upload_file_perhitungan_exim/',
				 secureuri      :false,
				 fileElementId  :'userfileperhitungan_exim',
				 dataType    : 'json',
				 data        : {
					'userfileperhitungan_exim'  : $('#userfileperhitungan_exim').val()
				 },
				 success  : function (data, status)
				 {
					if(data.status != 'error')
					{
					   $('#files_kurir').html('<p>Upload File Sukses...'+ $('#userfileperhitungan_exim').val() +'</p>'); 
					   jQuery("#tbltabperhitungan_exim").trigger('reloadGrid');
					 
					}
					alert(data.msg);
				 }
		  });
		  return false;
		   });
		});
		
		
		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("#tbluploadparths").jqGrid()[0].triggerToolbar();
						}, 50);
					} else {
						// refresh the filter in case of
						// searching dialog
						$(this).trigger('change');
					}
				}    
			});
		};
		
		jQuery("#tbltabperhitungan_exim").jqGrid({
			url:'<?php echo base_url().'exim/ct_bc261/data_upload_perhitungan_exim'; ?>',
			mtype : "post",
			postData:{'q':'1'},
			datatype: "json",
			colNames:['ID','filename', 'date upload','status upload', 'tipe', 'create date', 'create by'],
			colModel:[
				{name:'id_upload_perhitungan_exim',index:'id_upload_perhitungan_exim', width:60, hidden:true},
				{name:'filename',index:'filename', width:160},
				{name:'date_upload',index:'date_upload', width:166,stype:"text",searchoptions:{dataInit:datePick, att:{title:'Select Date'}}},
				{name:'status_upload',index:'status_upload', width:106},
				{name:'tipe',index:'tipe', width:106},
				{name:'create_date',index:'create_date', width:166, hidden:false,stype:"text",searchoptions:{dataInit:datePick, att:{title:'Select Date'}}},
				{name:'create_by',index:'create_by', width:106, hidden:false},
			
				],
			rowNum:10,
			rowList:[10,20,30],
			pager: '#ptbltabperhitungan_exim',
			sortname: 'id_upload_perhitungan_exim',
			viewrecords: true,
			sortorder: "desc",
			height:210,
			jsonReader: { repeatitems : false },
			caption:"List of Files Upload",
			rownumbers: true,
			shrinkToFit: false,
			afterInsertRow: function(){
				
				
			},			
			gridComplete: function(){
				var rowIDs = jQuery("#tbltabperhitungan_exim").getDataIDs(); 
				var rowData = $("#tbltabperhitungan_exim").getRowData();
			
				for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = jQuery("#"+ rowIDs[i],jQuery('#tbltabperhitungan_exim'));
				   
					switch (rowData[i].status_upload) {
						
						case 'cancel':
						   trElement.css({"color":"green"});
						break;
						case 'Deleted':
						   trElement.css({"color":"red", "text-decoration": "line-through"});
						break;
						case 'DATA PROCESSED':
						   trElement.css({"color":"blue"});
						break;
						
						
					}
				}
			}
		}); 
		
		jQuery("#tbltabperhitungan_exim").jqGrid('navGrid','#ptbltabperhitungan_exim',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#tbltabperhitungan_exim").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : false, defaultSearch: 'cn', ignoreCase: true});
		
		jQuery("#tblbc261_perhitungan_exim_hdr").jqGrid({
			url:'<?php echo base_url().'exim/ct_bc261/data_tblbc261_perhitungan_exim_hdr'; ?>',
			mtype : "post",
			postData:{'q':'1'},
			datatype: "json",
			colNames:[
				'id_bc261_exim_hdr'
				,'NPWPTUJU'
				,'NAMATUJU'
				,'ALMTTUJU'
				,'NOKONTRAK'
				,'TGLKONTRAK'
				,'custom_bond'
				,'kurs'
				,'kdval'
				,'jml_hari_kerja'
				,'periode_awal'
				,'periode_akhir'
				,'jenis_pekerjaan'
				,'status_data'
				,'create_date'
				,'create_by'
				,'update_date'
				,'update_by'
			],
			colModel:[
				{name:'id_bc261_exim_hdr',index:'id_bc261_exim_hdr', width:160, hidden:true},
				{name:'NPWPTUJU',index:'NPWPTUJU', width:160},
				{name:'NAMATUJU',index:'NAMATUJU', width:160},
				{name:'ALMTTUJU',index:'ALMTTUJU', width:160},
				{name:'NOKONTRAK',index:'NOKONTRAK', width:160},
				{name:'TGLKONTRAK',index:'TGLKONTRAK', width:160,stype:"text",searchoptions:{dataInit:datePick, att:{title:'Select Date'}}},
				{name:'custom_bond',index:'custom_bond', width:160, align:'right', formatter:'number',formatoptions: { decimalPlaces: 2 }},
				{name:'kurs',index:'kurs', width:160, align:'right', formatter:'number',formatoptions: { decimalPlaces: 2 }},
				{name:'kdval',index:'kdval', width:160},
				{name:'jml_hari_kerja',index:'jml_hari_kerja', align:'right', formatter:'number',formatoptions: { decimalPlaces: 0 }},
				{name:'periode_awal',index:'periode_awal', width:160},
				{name:'periode_akhir',index:'periode_akhir', width:160},
				{name:'jenis_pekerjaan',index:'jenis_pekerjaan', width:160},
				{name:'status_data',index:'status_data', width:160},
				{name:'create_date',index:'create_date', width:160},
				{name:'create_by',index:'create_by', width:160},
				{name:'update_date',index:'update_date', width:160},
				{name:'update_by',index:'update_by', width:160}
			
				],
			rowNum:10,
			rowList:[10,20,30],
			pager: '#ptblbc261_perhitungan_exim_hdr',
			sortname: 'id_bc261_exim_hdr',
			viewrecords: true,
			sortorder: "desc",
			height:150,
			width:840,
			jsonReader: { repeatitems : false },
			caption:"DATA PROSES EXCEL PERHITUNGAN EXIM ",
			rownumbers: true,
			shrinkToFit: false,
			afterInsertRow: function(){
				
				
			},			
			gridComplete: function(){
				var rowIDs = jQuery("#tblbc261_perhitungan_exim_hdr").getDataIDs(); 
				var rowData = $("#tblbc261_perhitungan_exim_hdr").getRowData();
			
				for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = jQuery("#"+ rowIDs[i],jQuery('#tblbc261_perhitungan_exim_hdr'));
				   
					switch (rowData[i].status_data) {
						
						case 'cancel':
						   trElement.css({"color":"green"});
						break;
						case 'Deleted':
						   trElement.css({"color":"red", "text-decoration": "line-through"});
						break;
						case 'DATA PROCESSED':
						   trElement.css({"color":"blue"});
						break;
						
						
					}
				}
			},
			onSelectRow: function(ids) { 
				var ret = jQuery("#tblbc261_perhitungan_exim_hdr").jqGrid('getRowData',ids);
				$("#txtnokontrak").val(ret.NOKONTRAK);
				$("#txttglkontrak").val(ret.TGLKONTRAK),
				$("#txtnamasubkontrak").val(ret.NAMATUJU);
				$("#txtalmtsubkontrak").val(ret.ALMTTUJU);
				$("#txtcustombond").val(ret.custom_bond);
				$("#txtharisubkon").val(ret.jml_hari_kerja);
				$("#txtkurs").val(ret.kurs);
				$("#txtkdval").val(ret.kdval);
				$("#txtjenisbarangjadi").val(ret.jenis_pekerjaan);
				$("#txtnpwpsubkontrak").val(ret.NPWPTUJU);
				$("#txt_idbc261_exim_hdr").val(ret.id_bc261_exim_hdr);
				/* delete from_data.aju;
				delete from_data.no_aju;
				delete from_data.tg_aju; */
				$("#span_notg_kontrak").html("No/TG Kontrak: " + ret.NOKONTRAK + " | " +  ret.TGLKONTRAK);
				jQuery("#tblbc261_perhitungan_exim_dtlx").jqGrid('setGridParam', { postData:{'q':'1','id_bc261_exim_hdr':function () { return $("#txt_idbc261_exim_hdr").val() } } });
				$("#tblbc261_perhitungan_exim_dtlx").trigger("reloadGrid");
				jQuery("#tbl_bc261_modul_asal_bc").jqGrid('setGridParam', { postData:{'q':'1','id_bc261_exim_hdr':function () { return $("#txt_idbc261_exim_hdr").val() }, 'aju':'' } });
				$("#tbl_bc261_modul_asal_bc").trigger("reloadGrid");
				
				
			}	
		}); 
		
		jQuery("#tblbc261_perhitungan_exim_hdr").jqGrid('navGrid','#ptblbc261_perhitungan_exim_hdr',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#tblbc261_perhitungan_exim_hdr").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : false, defaultSearch: 'cn', ignoreCase: true});
		
		
		
	  	$("#idtabperhitungan_exim_viewdata").click(function(){
		
			var id = jQuery("#tbltabperhitungan_exim").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tbltabperhitungan_exim").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row Data yang di upload");
				$('#tabperhitungan_exim').tabs({ selected: 0 });
				return false;
			};
			$("#bc261filename").html(ret.filename);
			
		});
		
		$("#btnbc261prosessubkon").click(function(){
			if($.trim($("#txtnokontrak").val()) == '' || $("#txtnokontrak").val() == null){
				alert("nokontrak must be filled out");
				return false;
			} 	
			if($.trim($("#txttglkontrak").val()) == '' || $("#txttglkontrak").val() == null){
				alert("txttglkontrak must be filled out");
				return false;
			} 	
			if($.trim($("#txtnamasubkontrak").val()) == '' || $("#txtnamasubkontrak").val() == null){
				alert("txtnamasubkontrak must be filled out");
				return false;
			} 	
			if($.trim($("#txtalmtsubkontrak").val()) == '' || $("#txtalmtsubkontrak").val() == null){
				alert("txtalmtsubkontrak must be filled out");
				return false;
			} 	
			if($.trim($("#txtcustombond").val()) == '' || $("#txtcustombond").val() == null){
				alert("txtcustombond must be filled out");
				return false;
			} 	
			if($.trim($("#txtharisubkon").val()) == '' || $("#txtharisubkon").val() == null){
				alert("txtharisubkon must be filled out");
				return false;
			} 	
			if($.trim($("#txtkurs").val()) == '' || $("#txtkurs").val() == null){
				alert("txtkurs must be filled out");
				return false;
			} 	
			if($.trim($("#txtkdval").val()) == '' || $("#txtkdval").val() == null){
				alert("txtkdval must be filled out");
				return false;
			} 	
			
			var id = jQuery("#tbltabperhitungan_exim").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tbltabperhitungan_exim").jqGrid('getRowData',id);
				
			} else {
				alert('Pilih data yang akan diproses');
				$('#tabperhitungan_exim').tabs({ selected: 0 });
				return false;
			};
			
			
			if(ret.status_upload != 'SUKSES'){
			
				alert('Data tidak bisa diproses, lihat status');
				return false;
			
			}
			
			var form_data = {
				id_upload_perhitungan_exim:ret.id_upload_perhitungan_exim,
				filename:ret.filename,
				txtnokontrak:$("#txtnokontrak").val(),
				txttglkontrak:$("#txttglkontrak").val(),
				txtnamasubkontrak:$("#txtnamasubkontrak").val(),
				txtalmtsubkontrak:$("#txtalmtsubkontrak").val(),
				txtcustombond:$("#txtcustombond").val(),
				txtharisubkon:$("#txtharisubkon").val(),
				txtkurs:$("#txtkurs").val(),
				txtkdval:$("#txtkdval").val(),
				txtjenisbarangjadi:$("#txtjenisbarangjadi").val(),
				txtnpwpsubkontrak:$("#txtnpwpsubkontrak").val()
				
			
			};
			
			$("#dlg_perhitungan_exim").dialog( "destroy" );
			$(".dlg_perhitungan_eximcl").remove();
			$(".dlg_perhitungan_eximcl").html('');
			$("body").append('<div id="dlg_perhitungan_exim" title="Warning" class="dlg_perhitungan_eximcl"><p>Apakah anda akan memproses file ini?!?</p><br /> file = '+ ret.filename +'</div>');
			$("#dlg_perhitungan_exim").dialog({
				height: 200,
				width: 250,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : "<?php echo base_url().'exim/ct_bc261/proses_perhitungan_exim'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlg_perhitungan_exim").dialog("close");
								$('#dlg_perhitungan_exim').dialog("destroy"); 
								$(".dlg_perhitungan_eximcl").remove(); 
								$('#tbltabperhitungan_exim').trigger('reloadGrid');
								$('#tblbc261_perhitungan_exim_hdr').trigger('reloadGrid');
		
								
							} else { 
								alert(msg.sts+' '+msg.desc); 
								$("#dlg_perhitungan_exim").dialog("close");
								$('#dlg_perhitungan_exim').dialog("destroy"); 
								$(".dlg_perhitungan_eximcl").remove(); 

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

					}
				},
				close : function(){
					$('#dlg_perhitungan_exim').dialog("destroy"); 
					$(".dlg_perhitungan_eximcl").remove(); 
					$("body").append('<div id="dlg_perhitungan_exim" title="Warning" class="dlg_perhitungan_eximcl"><p>Apakah anda akan memproses file ini?!?</p></div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});
		
		});
		
		$("#btnbc261deldataexcel").click(function(){
			var id = jQuery("#tblbc261_perhitungan_exim_hdr").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tblbc261_perhitungan_exim_hdr").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row Data Header");
				return false;
			};
			
			if(ret.status_data != 'New'){
				alert("Waduh Data tidak bisa didelete, soalnya status bukan New");
				return false;
			
			};
			
			var form_data = {
				id_delbc261_perhitungan_exim:ret.id_bc261_exim_hdr
			}
			
			$("#dlg_del_perhitungan_exim").dialog( "destroy" );
			$(".dlg_del_perhitungan_eximcl").remove();
			$(".dlg_del_perhitungan_eximcl").html('');
			$("body").append('<div id="dlg_del_perhitungan_exim" title="Warning" class="dlg_del_perhitungan_eximcl"><p>Apakah anda akan <b>men-delete data ini</b> ?!?</p><br /> Please Dech! </div>');
			$("#dlg_del_perhitungan_exim").dialog({
				height: 200,
				width: 250,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : "<?php echo base_url().'exim/ct_bc261/proses_del_perhitungan_exim'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlg_del_perhitungan_exim").dialog("close");
								$('#dlg_del_perhitungan_exim').dialog("destroy"); 
								$(".dlg_del_perhitungan_eximcl").remove(); 
								$('#tbltabperhitungan_exim').trigger('reloadGrid');
								$('#tblbc261_perhitungan_exim_hdr').trigger('reloadGrid');
		
								
							} else { 
								alert(msg.sts+' '+msg.desc); 
								$("#dlg_del_perhitungan_exim").dialog("close");
								$('#dlg_del_perhitungan_exim').dialog("destroy"); 
								$(".dlg_del_perhitungan_eximcl").remove(); 

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

					}
				},
				close : function(){
					$('#dlg_del_perhitungan_exim').dialog("destroy"); 
					$(".dlg_del_perhitungan_eximcl").remove(); 
					$("body").append('<div id="dlg_del_perhitungan_exim" title="Warning" class="dlg_del_perhitungan_eximcl"><p>Apakah anda akan memproses file ini?!?</p></div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});
				
			
			
			
		});
		
		$("#btnbc261viewdataexcel").click(function(){
			var id = jQuery("#tblbc261_perhitungan_exim_hdr").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tblbc261_perhitungan_exim_hdr").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row Data Header");
				return false;
			};
			
			var form_data = {
				id_bc261_exim_hdr:ret.id_bc261_exim_hdr
			};
			
			$("#frmbc261_view_perhitunganexim_dtl").load('<?php echo base_url().'exim/ct_bc261/view_bc261_perhitungan_exim_dtl'; ?>', form_data, function() {
				$("#frmbc261_view_perhitunganexim_dtl").dialog({
					modal:true,
					width : 950,
					height : 530,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
                    },
					close : function(){
						$('#frmbc261_view_perhitunganexim_dtl').dialog("destroy"); 
					    $(".frmbc261_view_perhitunganexim_dtl_cl").remove(); 
					    $("body").append('<div id="frmbc261_view_perhitunganexim_dtl" title="DETIL PERHITUNGAN EXIM YANG DIUPLOAD" class="frmbc261_view_perhitunganexim_dtl_cl"></div>'); 
						$('#tblbc261hdr').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("#tbluploadparths").jqGrid()[0].triggerToolbar();
						}, 50);
					} else {
						// refresh the filter in case of
						// searching dialog
						$(this).trigger('change');
					}
				}    
			});
		};
		
		jQuery("#tblbc261_perhitungan_exim_dtlx").jqGrid({
			url:'<?php echo base_url().'exim/ct_bc261/data_tblbc261_perhitungan_exim_dtl'; ?>',
			mtype : "post",
			postData:{'q':'1','id_bc261_exim_hdr':function () { return $("#txt_idbc261_exim_hdr").val() } },
			datatype: "json",
			colNames:[
				'id_bc261_exim_dtl'
				,'id_bc261_exim_hdr'
				,'assy_code'
				,'assy_name'
				,'kd brg'
				,'part name customs'
				,'part_number'
				,'qty'
				,'unit'
				,'ex_aju'
				,'ex_nodaft'
				,'ex_tgdaft'
				,'ex_nourut'
				,'harga_satuan'
				,'total_usd'
				,'nilai_pabean'
				,'hs'
				,'bm'
				,'ppn'
				,'pph'
				,'vendor'
				,'qty_modul'
				,'qty_dipakai'

			],
			colModel:[
				{name:'id_bc261_exim_dtl',index:'id_bc261_exim_dtl', width:160, hidden:true},
				{name:'id_bc261_exim_hdr',index:'id_bc261_exim_hdr', width:160, hidden:true},
				{name:'assy_code',index:'assy_code', width:160, hidden:true},
				{name:'assy_name',index:'assy_name', width:160, hidden:true},
				{name:'kode_barang',index:'kode_barang', width:60},
				{name:'part_name_customs',index:'part_name_customs', width:110},
				{name:'part_number',index:'part_number', width:160, hidden:true},
				{name:'qty',index:'qty', width:100, align:'right', formatter:'number',formatoptions: { decimalPlaces: 2 }},
				{name:'unit',index:'unit', width:60},
				{name:'ex_aju',index:'ex_aju', width:190, hidden:false},
				{name:'ex_nodaft',index:'ex_nodaft', width:160, hidden:false},
				{name:'ex_tgdaft',index:'ex_tgdaft', width:160, hidden:false},
				{name:'ex_nourut',index:'ex_nourut', width:160, hidden:false},
				{name:'harga_satuan',index:'harga_satuan', width:160, hidden:false, align:'right', formatter:'number',formatoptions: { decimalPlaces: 2 }},
				{name:'total_usd',index:'total_usd', width:160, hidden:true},
				{name:'nilai_pabean',index:'nilai_pabean', width:160, hidden:true},
				{name:'hs',index:'hs', width:160, hidden:false},
				{name:'bm',index:'bm', width:160, hidden:false},
				{name:'ppn',index:'ppn', width:160, hidden:false},
				{name:'pph',index:'pph', width:160, hidden:false},
				{name:'vendor',index:'vendor', width:160, hidden:false},
				{name:'qty_modul',index:'qty_modul', width:160, hidden:false,align:'right', formatter:'number',formatoptions: { decimalPlaces: 2 }},
				{name:'qty_dipakai',index:'qty_dipakai', width:160, hidden:false,align:'right', formatter:'number',formatoptions: { decimalPlaces: 2 }}
			
				],
			rowNum:10,
			rowList:[10,20,30],
			pager: '#ptblbc261_perhitungan_exim_dtlx',
			sortname: 'id_bc261_exim_hdr',
			viewrecords: true,
			sortorder: "desc",
			height:250,
			width:400,
			jsonReader: { repeatitems : false },
			caption:"DATA DETIL BAHAN BAKU",
			rownumbers: true,
			shrinkToFit: false,
			afterInsertRow: function(){
				
				
			},			
			gridComplete: function(){
				var rowIDs = jQuery("#tblbc261_perhitungan_exim_dtlx").getDataIDs(); 
				var rowData = $("#tblbc261_perhitungan_exim_dtlx").getRowData();
			
				for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = jQuery("#"+ rowIDs[i],jQuery('#tblbc261_perhitungan_exim_dtl'));
				   
					switch (rowData[i].status_data) {
						
						case 'cancel':
						   trElement.css({"color":"green"});
						break;
						case 'Deleted':
						   trElement.css({"color":"red", "text-decoration": "line-through"});
						break;
						case 'DATA PROCESSED':
						   trElement.css({"color":"blue"});
						break;
						
						
					}
				}
			},
			onSelectRow: function(ids) { 
				var ret = jQuery("#tblbc261_perhitungan_exim_dtlx").jqGrid('getRowData',ids);
				$("#bc261_jml_keluar").val(ret.qty);
				jQuery("#tbl_bc261_modul_asal_bc").jqGrid('setGridParam', { postData:{'q':'1','id_bc261_exim_hdr':function () { return $("#txt_idbc261_exim_hdr").val() }, 'id_bc261_exim_dtl':ret.id_bc261_exim_dtl } });
				$("#tbl_bc261_modul_asal_bc").trigger("reloadGrid");
				
			}	
		});
		
		jQuery("#tblbc261_perhitungan_exim_dtlx").jqGrid('navGrid','#ptblbc261_perhitungan_exim_dtlx',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#tblbc261_perhitungan_exim_dtlx").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : false, defaultSearch: 'cn', ignoreCase: true});
		
		jQuery("#tbl_bc261_modul_asal_bc").jqGrid({
			url:'<?php echo base_url().'exim/ct_bc261/data_tblbc261_perhitungan_exim_asal_bc'; ?>',
			mtype : "post",
			postData:{'q':'1','id_bc261_exim_hdr':function () { return $("#txt_idbc261_exim_hdr").val() } },
			datatype: "json",
			colNames:[ 'id_bc261_bc_asal'
					,'id_bc261_exim_dtl'
					,'id_bc261_exim_hdr'
					,'assy_code'
					,'assy_name'
					,'part_name_customs'
					,'part_number'
					,'kode_barang'
					,'qty_modul'
					,'qty '
					,'no aju'
					,'tgl aju'
					,'ex_aju'
					,'ex_nodaft'
					,'ex_tgdaft'
					,'ex_nourut'
					,'harga_satuan'
					,'total_usd'
					,'nilai_pabean'
					,'bm'
					,'ppn'
					,'pph'
					,'vendor'
					,'hs'
					,'status'
					],
			colModel:[
				{name:'id_bc261_bc_asal',index:'id_bc261_bc_asal', width:160, hidden:true},
				{name:'id_bc261_exim_dtl',index:'id_bc261_exim_dtl', width:160, hidden:true},
				{name:'id_bc261_exim_hdr',index:'id_bc261_exim_hdr', width:160, hidden:true},
				{name:'assy_code',index:'assy_code', width:160, hidden:true},
				{name:'assy_name',index:'assy_name', width:160, hidden:true},
				{name:'part_name_customs',index:'part_name_customs', width:160, hidden:true},
				{name:'part_number',index:'part_number', width:160, hidden:true},
				{name:'kode_barang',index:'kode_barang', width:80, hidden:false},
				{name:'qty_modul',index:'qty_modul', width:160, hidden:true, align:'right', formatter:'number',formatoptions: { decimalPlaces: 2 }},
				{name:'qty_dipakai',index:'qty_dipakai', width:90, hidden:false, align:'right', formatter:'number',formatoptions: { decimalPlaces: 2 }},
				{name:'no_aju',index:'no_aju', width:70, hidden:false},
				{name:'tg_aju',index:'tg_aju', width:100, hidden:false},
				{name:'ex_aju',index:'ex_aju', width:160, hidden:true},
				{name:'ex_nodaft',index:'ex_nodaft', width:160, hidden:true},
				{name:'ex_tgdaft',index:'ex_tgdaft', width:160, hidden:true},
				{name:'ex_nourut',index:'ex_nourut', width:160, hidden:true},
				{name:'harga_satuan',index:'harga_satuan', width:160, hidden:true},
				{name:'total_usd',index:'total_usd', width:160, hidden:true},
				{name:'nilai_pabean',index:'nilai_pabean', width:160, hidden:true},
				{name:'bm',index:'bm', width:160, hidden:true},
				{name:'ppn',index:'ppn', width:160, hidden:true},
				{name:'pph',index:'pph', width:160, hidden:true},
				{name:'vendor',index:'vendor', width:160, hidden:true},
				{name:'hs',index:'hs', width:160, hidden:true},
				{name:'status_data',index:'status_data', width:160, hidden:false}
			],
			rowNum:10,
			rowList:[10,20,30],
			pager: '#ptbl_bc261_modul_asal_bc',
			sortname: 'id_bc261_bc_asal',
			viewrecords: true,
			sortorder: "asc",
			width: 370,
			height:250,
			jsonReader: { repeatitems : false },
			caption:"DATA PENGELUARAN BC",
			rownumbers: true,
			shrinkToFit: false,
			gridComplete: function(){
				var rowIDs = jQuery("#tbl_bc261_modul_asal_bc").getDataIDs(); 
				var rowData = $("#tbl_bc261_modul_asal_bc").getRowData();
			
				for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = jQuery("#"+ rowIDs[i],jQuery('#tbl_bc261_modul_asal_bc'));
				   
					switch (rowData[i].status_data) {
						
						case 'cancel':
						   trElement.css({"color":"green"});
						break;
						case 'DATA PROCCESSED INVENTORY':
						   trElement.css({"color":"red"});
						break;
						case 'DATA PROCESSED':
						   trElement.css({"color":"blue"});
						break;
						
						
					}
				}
			},
			onSelectRow: function(ids) { 
				var ret = jQuery("#tbl_bc261_modul_asal_bc").jqGrid('getRowData',ids);
				$("#bc261_jml_keluar").val(ret.qty_dipakai);
				$("#txt_idbc261_bc_asal").val(ret.id_bc261_bc_asal);
				$("#bc261_no").val(ret.no_aju);
				$("#bc261_tg").val(ret.tg_aju);
				
			}	
		}); 
		
		jQuery("#tbl_bc261_modul_asal_bc").jqGrid('navGrid','#ptbl_bc261_modul_asal_bc',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#tbl_bc261_modul_asal_bc").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : false, defaultSearch: 'cn', ignoreCase: true});
		
		$("#btndel_jml_keluar_bc261").click(function(){
			var id = jQuery("#tbl_bc261_modul_asal_bc").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tbl_bc261_modul_asal_bc").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row BC ASAL");
				return false;
	
			};
			
			if(ret.status_data !=  'NEW'){
				alert("DATA TIDAK BISA DI DELETE");
				return false;
				
			} 
			
			var form_data = {
				id_hdrx:ret.id_bc261_bc_asal
			
			};
			
			$.ajax({
				url : "<?php echo base_url().'exim/ct_bc261/del_jml_bc'; ?>",
				type : 'POST',
				dataType: 'json',
				data : form_data,
				success: function(msg){
					if (msg.sts == '00'){
						alert(msg.desc);
						$('#tbl_bc261_modul_asal_bc').trigger('reloadGrid');
						
						
					} else { 
						alert(msg.sts+' '+msg.desc); 
						
					}
				}
			});
			
		});
		
		$("#btnadd_jml_keluar_bc261").click(function(){
			var id = jQuery("#tblbc261_perhitungan_exim_hdr").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tblbc261_perhitungan_exim_hdr").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row Data Header");
				$('#tabperhitungan_exim').tabs({ selected: 1 });
				return false;
	
			};
			
			var idx = jQuery("#tblbc261_perhitungan_exim_dtlx").jqGrid('getGridParam','selrow');
			if (idx) { 
				var retx = jQuery("#tblbc261_perhitungan_exim_dtlx").jqGrid('getRowData',idx);
				
			} else {
				alert("Please Select Row Data Header");
				return false;
			};
			
			if($.trim($("#bc261_no").val()) == '' && $.trim($("#bc261_tg").val()) == '' ){
				alert("Isikan Dahulu NO dan TGL BC nya");
				return false;
				
			}
			
			var form_data = {
				id_hdrx:ret.id_bc261_exim_hdr,id_dtlx: retx.id_bc261_exim_dtl,qtyx:$("#bc261_jml_keluar").val(),
				bc261_no:$("#bc261_no").val(), 	bc261_tg:$("#bc261_tg").val()	
			
			};
			
			$.ajax({
				url : "<?php echo base_url().'exim/ct_bc261/add_jml_bc'; ?>",
				type : 'POST',
				dataType: 'json',
				data : form_data,
				success: function(msg){
					if (msg.sts == '00'){
						alert(msg.desc);
						$('#tbl_bc261_modul_asal_bc').trigger('reloadGrid');
						
						
					} else { 
						alert(msg.sts+' '+msg.desc); 
						
					}
				}
			});
			
		});
		
		$("#btnprosesbc261").click(function(){
			if($.trim($("#bc261_no").val()) == '' && $.trim($("#bc261_tg").val()) == '' ){
				alert("Isikan Dahulu NO dan TGL BC nya");
				return false;
				
			}
			
			var from_data = {
			'q':'1'
			,'id_bc261_exim_hdr':function () { return $("#txt_idbc261_exim_hdr").val() } 
			,'no_aju':$.trim($("#bc261_no").val())
			,'tg_aju':$.trim($("#bc261_tg").val())
			,'aju':'ya'
			};
			
			jQuery("#tbl_bc261_modul_asal_bc").jqGrid('setGridParam', { postData:from_data });
			$("#tbl_bc261_modul_asal_bc").trigger("reloadGrid");
			
			var jmldata = jQuery("#tbl_bc261_modul_asal_bc").jqGrid('getGridParam', 'reccount');
			if(jmldata == 0){
				alert("Isikan Dahulu NO dan TGL BC dan DATA-DATA nya (itu lho masih kosong), atau coba cari no dan tgl BC yang lain");
				return false;
			
			}
			
					
			var from_dataxx = {
				'q':'1'
				,'id_bc261_exim_hdr':function () { return $("#txt_idbc261_exim_hdr").val() } 
				,'no_aju':$.trim($("#bc261_no").val())
				,'tg_aju':$.trim($("#bc261_tg").val())
				
			};
			$("#dlg_proses_bc261").dialog( "destroy" );
			$(".dlg_proses_bc261cl").remove();
			$(".dlg_proses_bc261cl").html('');
			$("body").append('<div id="dlg_proses_bc261" title="Warning" class="dlg_proses_bc261cl"><p>Apakah anda akan <b>melakukan Proses data ini</b> ?!?</p><br />NO/TGL BC:<b>'+ $.trim($("#bc261_no").val()) + ' ' + $.trim($("#bc261_tg").val()) + '</b><br>'+ $("#span_notg_kontrak").html() +'  </div>');
			$("#dlg_proses_bc261").dialog({
				height: 200,
				width: 250,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : "<?php echo base_url().'exim/ct_bc261/proses_data_bc261'; ?>",
						type : 'POST',
						dataType: 'json',
						data : from_dataxx,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlg_proses_bc261").dialog("close");
								$('#dlg_proses_bc261').dialog("destroy"); 
								$(".dlg_proses_bc261cl").remove(); 
								$('#tbltabperhitungan_exim').trigger('reloadGrid');
								$('#tblbc261_perhitungan_exim_hdr').trigger('reloadGrid');
								$('#tbl_bc261_modul_asal_bc').trigger('reloadGrid');
		
								
							} else { 
								alert(msg.sts+' '+msg.desc); 
								$("#dlg_proses_bc261").dialog("close");
								$('#dlg_proses_bc261').dialog("destroy"); 
								$(".dlg_proses_bc261cl").remove(); 

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

					}
				},
				close : function(){
					$('#dlg_proses_bc261').dialog("destroy"); 
					$(".dlg_proses_bc261cl").remove(); 
					$("body").append('<div id="dlg_proses_bc261" title="Warning" class="dlg_proses_bc261cl"><p>Apakah anda akan memproses file ini?!?</p></div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});
		
		});		
		$("#btnsearchbc261_add").click(function(){
			if($.trim($("#bc261_no").val()) == '' && $.trim($("#bc261_tg").val()) == '' ){
				alert("Isikan Dahulu NO dan TGL BC nya");
				return false;
				
			}
			
			var from_data = {
			'q':'1'
			,'id_bc261_exim_hdr':function () { return $("#txt_idbc261_exim_hdr").val() } 
			,'no_aju':$.trim($("#bc261_no").val())
			,'tg_aju':$.trim($("#bc261_tg").val())
			,'aju':'ya'
			};
			
			jQuery("#tbl_bc261_modul_asal_bc").jqGrid('setGridParam', { postData:from_data });
			$("#tbl_bc261_modul_asal_bc").trigger("reloadGrid");
			
			
		
		});		
	});
		  	
</script>

<div id="frmbc261_view_perhitunganexim_dtl" title="DETIL PERHITUNGAN EXIM YANG DIUPLOAD" class="frmbc261_view_perhitunganexim_dtl_cl"></div>



	
	