<div style="height:40px;">	
	<button id="btngroupinv" >Group Invoice</button>
</div>
<table>
	<td><table id="tbl_invbc30" ></table> <div id="ptbl_invbc30" style="text-align:center;"></div></td>
	<td align="center"><br /><br /><button id="btnselectInv" >Select Invoice >></button>
	<br /><br /><button id="btncancelInv30" >Cancel</button>
	</td>
	<td><table id="listbc30" class="scroll"></table> <div id="plistbc30" style="text-align:center;"></div></td>
</table>
<script type="text/javascript">
    
    $(document).ready(function(){
	
		$("#btnselectInv").button().click(function(){
		
			var rowIds = $('#listbc30').jqGrid('getDataIDs');
			for(var i=0,len=rowIds.length;i<len;i++){
				var currRow = rowIds[i];
				$('#listbc30').jqGrid('delRowData', currRow);
			}	
			
			var selr; 
			selr = jQuery("#tbl_invbc30").jqGrid('getGridParam','selarrrow'); 
			if(selr.length) {
			for(var i=0;i<selr.length;i++)
				{				
					var myrow = jQuery('#tbl_invbc30').jqGrid('getRowData',selr[i]);
					var idbladd =  $.jgrid.randId();
					
					var no_invoicex, tgl_invoicex, etd_portx, cust_codex, order_nox, part_nox, cust_part_nox, kindx, wsizex, article_codex, mpqx, qtyx, coilx, pricex, amountx, weightx
					
					if (myrow.No_Invoice != '-'){
						no_invoicex = myrow.No_Invoice;
						
					} else { no_invoicex = $('#no_invoicexxx').val();  }	
		
					if (myrow.Tgl_Invoice != '-'){
						tgl_invoicex = myrow.Tgl_Invoice;
						
					} else { tgl_invoicex = $('#tgl_invoicexx').val();  }			

					if (myrow.ETD_Port != '-'){
						etd_portx = myrow.ETD_Port;
						
					} else { etd_portx = $('#etd_portxx').val();  }	
		
					if (myrow.Cust_Code != '-'){
						cust_codex = myrow.Cust_Code;
						
					} else { cust_codex = $('#cust_codexx').val();  }			

					if (myrow.Order_No != '-'){
						order_nox = myrow.Order_No;
						
					} else { order_nox = $('#order_noxx').val();  }	
		
					if (myrow.Part_No != '-'){
						part_nox = myrow.Part_No;
						
					} else { part_nox = $('#part_noxx').val();  }			

					if (myrow.Cust_Part_No != '-'){
						cust_part_nox = myrow.Cust_Part_No;
						
					} else { cust_part_nox = $('#cust_part_noxx').val();  }	
		
					if (myrow.Kind != '-'){
						kindx = myrow.Kind;
						
					} else { kindx = $('#kindxx').val();  }			

					if (myrow.WSize != '-'){
						wsizex = myrow.WSize;
						
					} else { wsizex = $('#wsizexx').val();  }	
		
					if (myrow.Article_Code != '-'){
						article_codex = myrow.Article_Code;
						
					} else { article_codex = $('#article_codexx').val();  }					

					if (myrow.Mpq != '-'){
						mpqx = myrow.Mpq;
						
					} else { mpqx = $('#mpqx').val();  }	
		
					if (myrow.Qty != '-'){
						qtyx = myrow.Qty;
						
					} else { qtyx = $('#qtyxx').val();  }				

					if (myrow.Coil != '-'){
						coilx = myrow.Coil;
						
					} else { coilx = $('#coilxx').val();  }	
		
					if (myrow.Price != '-'){
						pricex = myrow.Price;
						
					} else { pricex = $('#pricexx').val();  }							

					if (myrow.Amount != '-'){
						amountx = myrow.Amount;
						
					} else { amountx = $('#amountxx').val();  }	
		
					if (myrow.Weight != '-'){
						weightx = myrow.Weight;
						
					} else { weightx = $('#weightxx').val();  }							
					
					jQuery("#listbc30").jqGrid('addRowData', idbladd, {
						id_bc30_invoice:myrow.id_bc30_invoice,
						No_Invoice2:no_invoicex,
						Tgl_Invoice2:tgl_invoicex,
						ETD_Port2:etd_portx,
						Cust_Code2:cust_codex,
						Order_No2:order_nox,
						Part_No2:part_nox,
						Cust_Part_No2:cust_part_nox,
						Kind2:kindx,
						WSize2:wsizex,
						Article_Code2:article_codex,
						Mpq2:mpqx,
						Qty2:qtyx,
						Coil2:coilx,
						Price2:pricex,
						Amount2:amountx,
						Weight2:weightx,
					});			
				}
			}					
		});

		$("#btngroupinv").button().click(function(){

			var rowdatagrid = jQuery("#listbc30").jqGrid('getGridParam', 'records');
			
			if(rowdatagrid == 0){
				alert('pilih data terlebih dahulu');
				return false;
			}
			
			var gridData = jQuery("#listbc30").getRowData();
			var postData = JSON.stringify(gridData);
			var form_data={
				datadiff:postData
			};
			
			$.ajax({
				url : "<?php echo base_url().'pasi_exim/ct_bc30/prosesdatainv'; ?>",
				type : 'POST',
				dataType: 'json',
				data : form_data,
				success: function(msg){
	
					if (msg.sts == '00'){
						$('#listbc30').jqGrid("clearGridData", true).trigger("reloadGrid");
						$('#tbl_invbc30').trigger('reloadGrid');
						$('#tblbc30hdr').trigger('reloadGrid');
						alert(msg.desc);

						
					} else { alert(msg.sts+msg.desc);  }
					
					
				}
			});
		});

		$("#btncancelInv30").button().click(function(){		
	
			jQuery('#listbc30').jqGrid("clearGridData", true).trigger("reloadGrid");
			
		});

		jQuery("#tbl_invbc30").jqGrid({
			url:'<?php echo base_url().'pasi_exim/ct_bc30/loadDataInvoice'; ?>',
			mtype : "post",
			postData:{'q':'1'},
			datatype: "json",
			
			colNames:['id', 'No.Invoice','Tgl.Invoice','ETD_Port','Cust_Code','Order_No','Part_No','Cust_Part_No','Kind','WSize','Article_Code','Mpq','Qty','Coil','Price','Amount','Weight'],
			colModel:[
				{name:'id_bc30_invoice',index:'id_bc30_invoice', width:60, hidden:true},
				{name:'No_Invoice',index:'No_Invoice', width:87},
				{name:'Tgl_Invoice',index:'Tgl_Invoice', width:109},
				{name:'ETD_Port',index:'ETD_Port', width:271, hidden:false},
				{name:'Cust_Code',index:'Cust_Code', width:95,hidden:false},
				{name:'Order_No',index:'Order_No', width:104,hidden:false},
				{name:'Part_No',index:'Part_No', width:118,hidden:false},
				{name:'Cust_Part_No',index:'Cust_Part_No', width:95,hidden:false},
				{name:'Kind',index:'Kind', width:157,hidden:false},	
				{name:'WSize',index:'WSize', width:128,hidden:false},
				{name:'Article_Code',index:'Article_Code', width:124,hidden:false},
				{name:'Mpq',index:'Mpq', width:84, hidden:false},
				{name:'Qty',index:'Qty', width:281,hidden:false},
				{name:'Coil',index:'Coil', width:521,hidden:false},
				{name:'Price',index:'Price', width:119,hidden:false},
				{name:'Amount',index:'Amount', width:166,hidden:false},
				{name:'Weight',index:'Weight', width:101,hidden:false},


				],
			rowNum:5000,
			rowList:[5000,10000,2000],
			pager: '#ptbl_invbc30',
			sortname: 'id_bc30_invoice',
			viewrecords: true,
			sortorder: "asc",
			width: 500,
			height:150,
			jsonReader: { repeatitems : false },
			caption:"Data Invoice BC 30",
			rownumbers: true,
			loadonce: false,
			shrinkToFit: false,
			multiselect: true,
			afterInsertRow: function(){
				
				
			},			
			gridComplete: function(){
				
			},
			
			
		})
			                
		jQuery("#tbl_invbc30").jqGrid('navGrid','#ptbl_invbc30',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#tbl_invbc30").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});
		
		
		jQuery("#listbc30").jqGrid({
			mtype : "post",
			datatype: "json",
			
			colNames:['id', 'No.Invoice','Tgl.Invoice','ETD_Port','Cust_Code','Order_No','Part_No','Cust_Part_No','Kind','WSize','Article_Code','Mpq','Qty','Coil','Price','Amount','Weight'],
			colModel:[
				{name:'id_bc30_invoice',index:'id_bc30_invoice', width:60, hidden:true},
				{name:'No_Invoice2',index:'No_Invoice2', width:127},
				{name:'Tgl_Invoice2',index:'Tgl_Invoice2', width:109},
				{name:'ETD_Port2',index:'ETD_Port2', width:271, hidden:false},
				{name:'Cust_Code2',index:'Cust_Code2', width:95,hidden:false},
				{name:'Order_No2',index:'Order_No2', width:104,hidden:false},
				{name:'Part_No2',index:'Part_No2', width:118,hidden:false},
				{name:'Cust_Part_No2',index:'Cust_Part_No2', width:95,hidden:false},
				{name:'Kind2',index:'Kind2', width:157,hidden:false},	
				{name:'WSize2',index:'WSize2', width:128},
				{name:'Article_Code2',index:'Article_Code2', width:124},
				{name:'Mpq2',index:'Mpq2', width:84, hidden:false},
				{name:'Qty2',index:'Qty2', width:281,hidden:false},
				{name:'Coil2',index:'Coil2', width:521,hidden:false},
				{name:'Price2',index:'Price2', width:119,hidden:false},
				{name:'Amount2',index:'Amount2', width:166,hidden:false},
				{name:'Weight2',index:'Weight2', width:101,hidden:false},


			],
			pager: '#plistbc30',
			rowNum:5000,
			rowList:[5000,10000,20000],
			sortname: 'id_bc30_invoice',
			sortorder: 'asc',
			width: 500,
			height:150,
			jsonReader: { repeatitems : false },
			viewrecords: true,
			multiselect: true,
			loadonce: false,
			shrinkToFit: false,
			caption: "Selected Data to BC Process"
		});
		
		jQuery("#listbc30").jqGrid('navGrid','#plistbc30',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#listbc30").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});
	});	  	
</script>
<div id="frmitemlistdlg" title="ITEM LIST" class="frmitemlistdlg_cl"></div>



	
	