<div id="container_pasi_bc271_exim" style="height:100%; margin:0px; padding:0px;overflow:'hidden'; border: 0px solid #cd0a0a">
	<div class="pane-header ui-state-active" id="pasi_bc271_exim_bar" >  
	<button type="button" id="pasi_btnfrmbc271">Edit Data</button> 
	<button type="button" id="pasi_btndeletebc271">Delete Data</button>
	<button type="button" id="pasi_btnSearchingbc271">Searching</button> 	
	<button type="button" id="pasi_btnApprovebc271">Approve/Move Data</button> 
	</div> 
	<table id="pasi_tblbc271hdr"></table> <div id="ppasi_tblbc271hdr"></div>
</div>
<div id="pasi_frmbc271hdrdlg" title="Form BC27" class="pasi_frmbc271hdrdlg_cl"></div>
<div id="pasi_frmbc271searching" title="DETAIL DOCUMENTS" class="pasi_frmbc271searching_cl"></div>
<script type="text/javascript">

    $(document).ready(function(){
	
	$(window).bind('resize', function() {  
		setTimeout(function(){
				setGridHight($("#pasi_tblbc271hdr"),$("#container_pasi_bc271_exim"),$("#pasi_bc271_exim_bar")); 
			},10); 
		});

	$("#pasi_btnfrmbc271").button();
	$("#pasi_btnApprovebc271").button();
	$("#pasi_btndeletebc271").button();

	$("#pasi_btnSearchingbc271").button().click(function(){
		$("#pasi_frmbc271searching").load('<?php echo base_url().'pasi_exim/ct_bc271/view_bc271_searching'; ?>',  {parmeter:'parameter'}, function() {
			$("#pasi_frmbc271searching").dialog({
				modal:true,
				width : 324,
				height : 212,
				buttons: {
					"Close": function() {  
						$(".ui-dialog-titlebar-close").trigger('click');  
						
					}
				},
				close : function(){
					$('#pasi_frmbc271searching').dialog("destroy");
					$(".pasi_frmbc271searching_cl").remove();
					$("body").append('<div id="pasi_frmbc271searching" title="Form BC23 From Kurir" ' + 'class="pasi_frmbc271searching_cl"></div>');
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});
		});
	});
	
	$("#pasi_btnApprovebc271").click(function(){
			var id = jQuery("#pasi_tblbc271hdr").jqGrid('getGridParam','selrow');
			
			if (id) { 
				var ret = jQuery("#pasi_tblbc271hdr").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};	
			
			if (ret.status!='DATA PROCESSED'){
				alert("Data cannot be process..!");
				return false;
			}
			
			
			var form_data = {
				id_bc271_hdr:ret.id_bc271_hdr,
				car:ret.CAR,
			};
			
			$("#dlgdatalistitem271").dialog( "destroy" );
			$(".dlgdatalistitem271_cl").remove();
			$("body").append('<div id="dlgdatalistitem271" title="Warning" class="dlgdatalistitem271_cl"><p>Apakah anda akan Memproses Data ' + ret.CAR + ' ke Inventory ?</p><br /></div>');
			$("#dlgdatalistitem271").dialog({
				height: 200,
				width: 350,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : "<?php echo base_url().'pasi_exim/ct_bc271/MoveData2Inv'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlgdatalistitem271").dialog("close");
								$('#dlgdatalistitem271').dialog("destroy"); 
								$(".dlgdatalistitem271_cl").remove(); 
								$('#pasi_tblbc271hdr').trigger('reloadGrid');
							} else { 
								alert(msg.sts+msg.desc);
								$("#dlgdatalistitem271").dialog("close");
								$('#dlgdatalistitem271').dialog("destroy"); 
								$(".dlgdatalistitem271_cl").remove(); 		

							}
						}
					});
				},
				"CANCEL": function() {
						$( "#dlgdatalistitem271" ).dialog( "close" );
						$(".dlgdatalistitem271_cl").remove();

					}
				},
				close : function(){
					$('#dlgdatalistitem271').dialog("destroy"); 
					$(".dlgdatalistitem271_cl").remove(); 
					$("body").append('<div id="dlgdatalistitem271" title="Warning" class="dlgdatalistitem271_cl"><pApakah anda akan Memproses Data ' + ret.CAR + ' ke Inventory ?</p></div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});
	
	});

	$("#pasi_btndeletebc271").button().click(function(){
		var id = jQuery("#pasi_tblbc271hdr").jqGrid('getGridParam','selrow');
		if (id) { 
			var ret = jQuery("#pasi_tblbc271hdr").jqGrid('getRowData',id);	
		} else {
			alert("Please Select Row");
			return false;
		};
		
		var form_data={
			CAR:ret.CAR
		};
		
		$("#dlgbc271indelete").dialog( "destroy" );
		$(".dlgbc271indelete_cl").remove();
		$("body").append('<div id="dlgbc271indelete" title="Warning" class="dlgbc271indelete_cl"><p>Are you sure want to delete this BC 2.7.1 ?</p><br /></div>');
		
		
		
		$("#dlgbc271indelete").dialog({
			height: 160,
			width: 250,
			modal: true,
			hide: 'Slide',
			autoOpen: 'false',
			buttons: {
				"CONFIRM": function() {
				$.ajax({
					url : "<?php echo base_url().'pasi_exim/ct_bc271/deletebc27out'; ?>",
					type : 'POST',
					dataType: 'json',
					data : form_data,
					success: function(msg){
						if (msg.sts == '00'){
							alert(msg.desc);
							$("#dlgbc271indelete").dialog("close");
							$('#dlgbc271indelete').dialog("destroy"); 
							$(".dlgbc271indelete_cl").remove(); 
							$('#pasi_tblbc271hdr').trigger('reloadGrid');

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

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

				}
			},
			close : function(){
				$('#dlgbc271indelete').dialog("destroy"); 
				$(".dlgbc271indelete_cl").remove(); 
				$("body").append('<div id="dlgbc271indelete" title="Warning" class="dlgbc271indelete_cl"><p>Are you sure want to delete this BC 2.7.1 ?</p><br /></div>');     
				
			},
			open: function(){
				$("body").unblock();
				
			}
		});
	});
	
	$("#pasi_btnfrmbc271").click(function(){
			var id = jQuery("#pasi_tblbc271hdr").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#pasi_tblbc271hdr").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};	
	/*	*/	
			if (ret.status=='DATA SENT TO INVENTORY'){
				alert("Cannot process data because has been sent to inventory!");
				return false;
			}
			
			var form_data={parmeter:'parameter',
				id_bc271_hdr:ret.id_bc271_hdr,
				car:ret.CAR,
				Nodaf:ret.Nodaf,
				KdKpbc:ret.KdKpbc,
				KdKpbcBongkar:ret.KdKpbcBongkar,
				KdKpbcAwas:ret.KdKpbcAwas,
				PasokNama:ret.PasokNama,
				PasokAlmt1:ret.PasokAlmt1,
				Moda:ret.Moda,
				KdVal:ret.KdVal,
				Cif:ret.Cif,
				Bruto:ret.Bruto,
				Netto:ret.Netto,
				NilSerah:ret.NilSerah,
				Tgldaf:ret.Tgldaf,
				UsahaNama:ret.UsahaNama,
				UsahaNPWP:ret.UsahaNPWP,
				UsahaAlamat1:ret.UsahaAlamat1,
				UsahaAlamat2:ret.UsahaAlamat2,
				UsahaSkep:ret.UsahaSkep,
				PasokAlmt2:ret.PasokAlmt2,
				PasokSkep:ret.PasokSkep,
				PasokNPWP:ret.PasokNPWP,
				NoInvoice:ret.NoInvoice,
				TgInvoice:ret.TgInvoice,
				NoPackinglist:ret.NoPackinglist,
				TgPackinglist:ret.TgPackinglist,
				NoKontrak:ret.NoKontrak,
				TgKontrak:ret.TgKontrak,
				SuratJalan:ret.SuratJalan,
				TgSuratjalan:ret.TgSuratjalan,
				SuratKep:ret.SuratKep,
				TgSuratKep:ret.TgSuratKep,
				SuratLain:ret.SuratLain,
				TgSuratLain:ret.TgSuratLain,
				NoBc27Asal:ret.NoBc27Asal,
				TgBc27Asal:ret.TgBc27Asal,
				Nopol:ret.Nopol,
				MrkNoKms:ret.MrkNoKms,
				JmlJnsKms:ret.JmlJnsKms,
				NoSeg:ret.NoSeg,
				CtBcTuj1:ret.CtBcTuj1,
				CtBcTuj2:ret.CtBcTuj2,
				Volume:ret.Volume,
				create_date:ret.create_date,
				create_by:ret.create_by,
				update_date:ret.update_date,
				update_by:ret.update_by

			};
	
	
				$("#pasi_frmbc271hdrdlg").load('<?php echo base_url().'pasi_exim/ct_bc271form'; ?>', form_data  , function() {
				$("#pasi_frmbc271hdrdlg").dialog({
					modal:true,
					width : 1000,
					height : 499,
					buttons: {
					
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
                    },
					close : function(){
						$('#pasi_frmbc271hdrdlg').dialog("destroy"); 
					    $(".pasi_frmbc271hdrdlg_cl").remove(); 
					    $("body").append('<div id="pasi_frmbc271hdrdlg" title="Form BC 271" class="pasi_frmbc271hdrdlg_cl"></div>'); 
						
					},
					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_") {
   
		setTimeout(function(){
		jQuery("#pasi_tblbc271hdr").jqGrid()[0].triggerToolbar();
			}, 50);
		} else {
			
			$(this).trigger('change');
		}
		}    
	});
	};
	
	jQuery("#pasi_tblbc271hdr").jqGrid({
			url:'<?php echo base_url().'pasi_exim/ct_bc271/loaddataheader'; ?>',
			mtype : "post",
			postData:{'q':'1'},
			datatype: "json",
			colNames:['id','CAR','NO BC 27','TGL BC 27','No','Date','Name','Address','Name','Address','KdKpbc','KdKpbcBongkar','KdKpbcAwas','Moda','Value Code','Cif','Bruto','Netto','Value','UsahaNPWP','UsahaAlamat2','UsahaSkep','PasokAlmt2','PasokSkep','PasokNPWP','NoInvoice','TgInvoice','NoPackinglist','TgPackinglist','NoKontrak','TgKontrak','SuratJalan','TgSuratjalan','SuratKep','TgSuratKep','SuratLain','TgSuratLain','Nopol','MrkNoKms','JmlJnsKms','NoSeg','CtBcTuj1','CtBcTuj2','Volume','Status','Create Date','Create By','Approve Date','Approve By'],
			colModel:[
					{name:'id_bc271_hdr',index:'id_bc27_hdr', width:60, hidden:true},
					{name:'CAR',index:'CAR', width:100, hidden:false},
					{name:'NoBc27Asal',index:'NoBc27Asal', width:95, hidden:true},
					{name:'TgBc27Asal',index:'TgBc27Asal', width:70, hidden:true},
					
					{name:'Nodaf',index:'Nodaf', width:100,align :'center',hidden:false},
					{name:'Tgldaf',index:'Tgldaf',width:100,align :'center',hidden:false},
					
					{name:'PasokNama',index:'PasokNama', width:300, hidden:false},
					{name:'PasokAlmt1',index:'PasokAlmt1',width:250, hidden:false},
					
					{name:'UsahaNama',index:'UsahaNama',width:300, hidden:false},
					{name:'UsahaAlamat1',index:'UsahaAlamat1',width:250, hidden:false},
					
					{name:'KdKpbc',index:'KdKpbc',width:60, hidden:true},
					{name:'KdKpbcBongkar',index:'KdKpbcBongkar',width:60, hidden:true},
					{name:'KdKpbcAwas',index:'KdKpbcAwas',width:60, hidden:true},					
					{name:'Moda',index:'Moda',width:60, hidden:true},
					
					{name:'KdVal',index:'KdVal',width:60,align :'center',hidden:false},
					{name:'Cif',index:'Cif',width:60, hidden:false},
					{name:'Bruto',index:'Bruto',width:60, hidden:false},
					{name:'Netto',index:'Netto',width:60, hidden:false},
					{name:'NilSerah',index:'NilSerah',width:60, hidden:false},
					
					{name:'UsahaNPWP',index:'UsahaNPWP',width:60, hidden:true},					
					{name:'UsahaAlamat2',index:'UsahaAlamat2',width:60, hidden:true},
					{name:'UsahaSkep',index:'UsahaSkep',width:60, hidden:true},
					{name:'PasokAlmt2',index:'PasokAlmt2',width:60, hidden:true},
					{name:'PasokSkep',index:'PasokSkep',width:60, hidden:true},
					{name:'PasokNPWP',index:'PasokNPWP',width:60, hidden:true},
					{name:'NoInvoice',index:'NoInvoice',width:60, hidden:true},
					{name:'TgInvoice',index:'TgInvoice',width:60, hidden:true},
					{name:'NoPackinglist',index:'NoPackinglist',width:60, hidden:true},
					{name:'TgPackinglist',index:'TgPackinglist',width:60, hidden:true},
					{name:'NoKontrak',index:'NoKontrak',width:60, hidden:true},
					{name:'TgKontrak',index:'TgKontrak',width:60, hidden:true},
					{name:'SuratJalan',index:'SuratJalan',width:60, hidden:true},
					{name:'TgSuratjalan',index:'TgSuratjalan',width:60, hidden:true},
					{name:'SuratKep',index:'SuratKep',width:60, hidden:true},
					{name:'TgSuratKep',index:'TgSuratKep',width:60, hidden:true},
					{name:'SuratLain',index:'SuratLain',width:60, hidden:true},
					{name:'TgSuratLain',index:'TgSuratLain',width:60, hidden:true},
					{name:'Nopol',index:'Nopol',width:60, hidden:true},
					{name:'MrkNoKms',index:'MrkNoKms',width:60, hidden:true},
					{name:'JmlJnsKms',index:'JmlJnsKms',width:60, hidden:true},
					{name:'NoSeg',index:'NoSeg',width:60, hidden:true},
					{name:'CtBcTuj1',index:'CtBcTuj1',width:60, hidden:true},
					{name:'CtBcTuj2',index:'CtBcTuj2',width:60, hidden:true},
					{name:'Volume',index:'Volume',width:60, hidden:true},
					
					{name:'status',index:'status',width:200, hidden:false},	
					{name:'create_date',index:'create_date',width:150, hidden:false},
					{name:'create_by',index:'create_by',width:100, hidden:false},
					{name:'update_date',index:'update_date',width:150, hidden:false},
					{name:'update_by',index:'update_by',width:100, hidden:false},
					

			],
			rowNum:10,
			rowList:[10,20,30],
			pager: '#ppasi_tblbc271hdr',
			sortname: 'id_bc271_hdr',
			viewrecords: true,
			sortorder: "desc",
			width: '',
			height: 150,
			//width: 950,
			//height:300,
			jsonReader: { repeatitems : false },
			caption:"List of BC 271 Header",
			rownumbers: true,
			shrinkToFit: false,
			afterInsertRow: function(rowid, aData){
				/*switch (aData.statusdok) {
					case 'DATA SENT':
						jQuery("#tblbc23hdr").jqGrid('setCell',rowid,'statusdok','',{color:'green'});
					break;
					case '2':
						jQuery("#tblbc23hdr").jqGrid('setCell',rowid,'statusdok','',{color:'red'});
					break;
					case '1':
						jQuery("#tblbc23hdr").jqGrid('setCell',rowid,'statusdok','',{color:'blue'});
					break;
					
				} */
			},
			gridComplete: function(){
				var rowIDs = jQuery("#pasi_tblbc271hdr").getDataIDs(); 
				var rowData = $("#pasi_tblbc271hdr").getRowData();
			
				for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = jQuery("#"+ rowIDs[i],jQuery('#pasi_tblbc271hdr'));
				   
					switch (rowData[i].status) {
						case 'DATA PROCESSED':
						   trElement.css({"color":"green"});
						break;
						
						case 'SENT TO INVENTORY CANCELED':
						   trElement.css({"color":"green"});
						break;
						
						case 'DATA SENT TO INVENTORY':
						   trElement.css({"color":"purple"});
						break;
						case 'DATA PROCESSED INVENTORY':
						   trElement.css({"color":"blue"});
						break;
						case 'APPROVED INVENTORY':
						   trElement.css({"color":"red"});
						break;
					}
				}
			},
		}); 
			
  		jQuery("#pasi_tblbc271hdr").jqGrid('setGroupHeaders', 
            { useColSpanStyle: true, groupHeaders:[
			{startColumnName: 'Nodaf', numberOfColumns: 2, titleText: '<em><center>BC</center></em>'},
			
			{startColumnName: 'PasokNama', numberOfColumns: 2, titleText: '<em><center>Buyer</center></em>'},			
			{startColumnName: 'UsahaNama', numberOfColumns: 2, titleText: '<em><center>Supplier</center></em>'},
			
			{startColumnName: 'Cif', numberOfColumns: 4, titleText: '<em><center>Valuta</center></em>'},
			{startColumnName: 'status', numberOfColumns: 3, titleText: '<em><center>Log Status</center></em>'},
			{startColumnName: 'update_date', numberOfColumns: 2, titleText: '<em><center>Log Modify</center></em>'}
        ] });   
		
		jQuery("#pasi_tblbc271hdr").jqGrid('navGrid','#ppasi_tblbc271hdr',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#pasi_tblbc271hdr").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});

		setTimeout(function(){
				setGridHight($("#pasi_tblbc271hdr"),$("#container_pasi_bc271_exim"),$("#pasi_bc271_exim_bar")); 
			},10);  


	});
		  	
</script>
