<div style="height:40px;">
<button id="btnbc23execdata">Get Loader Data</button>
<button id="btnbc23viewdata">View Data</button>
<button id="btnbc23summarydata">View Summary</button>
<button id="btnbc23addbldata">Add AWB/BL</button>
<button id="btnbc23prosesdata">Prosses Data</button>
<button id="btnbc23cekrevisihib">Cek Revisi Inv.</button>

</div>
<table id="tblbc23hdr_draft"></table> <div id="ptblbc23hdr_draft"></div>
<div id="div_cek_invhib_detil_null" style="color:red"><?php echo $test ?></div>
<input type="hidden" id="hdnlastcarbc23" />
<script type="text/javascript">
    
    $(document).ready(function(){
		$("#btnbc23addbldata").button().click(function(){
			$("#bc23_addbldata_dlg").load('<?php echo base_url().'exim/ct_inv_draft/view_bc23_addbldata'; ?>',  {parmeter:'parameter'}, function() {
				$("#bc23_addbldata_dlg").dialog({
					modal:true,
					width : 900,
					height : 550,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
                    },
					close : function(){
						$('#bc23_addbldata_dlg').dialog("destroy"); 
					    $(".bc23_addbldata_dlg_cl").remove(); 
					    $("body").append('<div id="bc23_addbldata_dlg" title="ADD DATA BL/AWB" class="bc23_addbldata_dlg_cl"></div>'); 
	
					},
					open: function(){
						$("body").unblock();
						
					}
				});
			});
		
		});
		
		
		$("#btnbc23lastchar").button().click(function(){
			$.ajax({
				url : "<?php echo base_url().'exim/ct_bc23_draft/ceklastcar'; ?>",
				type : 'POST',
				success: function(msg){
					alert(msg);
				}
			});
		
		
		});
		
		$("#btnbc23summarydata").button().click(function(){
			var id = jQuery("#tblbc23hdr_draft").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tblbc23hdr_draft").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};	
			
			if (ret.nobl == '-') {
				alert("Silahkan bikin awb terlebih dahulu");
				return false;
			}
			
			var form_data = {parmeter:'parameter', nobl:ret.nobl, tgbl:ret.tgbl};
			
			$("#frminvdtl_summary_dlg_h").load('<?php echo base_url().'exim/ct_inv_detil_draft/view_inv_summary'; ?>', form_data, function() {
				$("#frminvdtl_summary_dlg_h").dialog({
					modal:true,
					width : 600,
					height : 530,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
                    },
					close : function(){
						$('#frminvdtl_summary_dlg_h').dialog("destroy"); 
					    $(".frminvdtl_summary_dlg_h_cl").remove(); 
					    $("body").append('<div id="frminvdtl_summary_dlg_h" title="INVOICE DATA SUMMARY DETAIL" class="frminvdtl_summary_dlg_h_cl"></div>'); 
	
					},
					open: function(){
						$("body").unblock();
						
					}
				});
			});
		
		});
		
		
		
		$("#btnbc23viewdata").button().click(function(){
			var id = jQuery("#tblbc23hdr_draft").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tblbc23hdr_draft").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};	
			
			$("#frminvdtl_dlg").load('<?php echo base_url().'exim/ct_inv_detil_draft'; ?>',  {parmeter:'parameter', id_inv_hdr:ret.inv_hdr_id}, function() {
				$("#frminvdtl_dlg").dialog({
					modal:true,
					width : 1000,
					height : 530,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
                    },
					close : function(){
						$('#frminvdtl_dlg').dialog("destroy"); 
					    $(".frminvdtl_dlg_cl").remove(); 
					    $("body").append('<div id="frminvdtl_dlg" title="INVOICE DATA DETAIL" class="frminvdtl_dlg_cl"></div>'); 
	
					},
					open: function(){
						$("body").unblock();
						
					}
				});
			});	
			
		});
		
		$("#btnbc23execdata").button().click(function(){
			
			$("#inv_datauploaded_dlg").load('<?php echo base_url().'exim/ct_inv_draft/view_inv_datauploaded'; ?>',  {parmeter:'parameter'}, function() {
				$("#inv_datauploaded_dlg").dialog({
					modal:true,
					width : 890,
					height : 490,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
                    },
					close : function(){
						$('#inv_datauploaded_dlg').dialog("destroy"); 
					    $(".inv_datauploaded_dlg_cl").remove(); 
					    $("body").append('<div id="inv_datauploaded_dlg" title="DATA INVOICE YANG DIUPLOAD" class="inv_datauploaded_dlg_cl"></div>'); 
	
					},
					open: function(){
						$("body").unblock();
						
					}
				});
			});	
			
			
			/*$.ajax({
				url : "<?php echo base_url().'exim/ct_inv_draft/cekloaderbc23'; ?>",
				type : 'POST',
				dataType: 'json',
				data : {test:'aaa'},
				success: function(msg){
					if (msg.sts == '00'){
						
						alert(msg.desc);
						$('#tblbc23hdr_draft').trigger('reloadGrid');
						
					} else { alert(msg.sts+msg.desc);  }
				}
			}); */
		
		});
		
		$("#btnbc23prosesdata").button().click(function(){
			var id = jQuery("#tblbc23hdr_draft").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tblbc23hdr_draft").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};
			if (ret.nobl == '-'){
				alert("Silahkan bikin BL terlebih dahulu");
				return false;
			}	
			var form_data = {nobl:ret.nobl, tgbl:ret.tgbl};
			
			$("#bc23_insertproses_dlg").load('<?php echo base_url().'exim/ct_inv_draft/view_bc23_prosesinsertinv'; ?>', form_data , function() {
				$("#bc23_insertproses_dlg").dialog({
					modal:true,
					width : 500,
					height : 500,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
                    },
					close : function(){
						$('#bc23_insertproses_dlg').dialog("destroy"); 
					    $(".bc23_insertproses_dlg_cl").remove(); 
					    $("body").append('<div id="bc23_insertproses_dlg" title="PROSES DATA" class="bc23_insertproses_dlg_cl"></div>'); 
	
					},
					open: function(){
						$("body").unblock();
						
					}
				});
			});
		
		});
		
		$("#btnbc23cekrevisihib").button().click(function(){
					
		
		});
		
		function myformatter ( cellvalue, options, rowObject )
		{
			if (cellvalue == "New")
				 return '<font color="red">' + cellvalue + '</font>';//or use classes
			else
				 return '<font color="blue">' + cellvalue + '</font>';//or use classes
		}
		
		var datePick = function (el) {
			$(el).datepicker({
				changeYear: true,
				changeMonth: true,
				showButtonPanel: true,
				onSelect: function () {
					
					if (this.id.substr(0, 3) === "gs_") {
               
					setTimeout(function(){
					jQuery("#tblbc23hdr_draft").jqGrid()[0].triggerToolbar();
						}, 50);
					} else {
						
						$(this).trigger('change');
					}
				}    
			});
		};
		
		jQuery("#tblbc23hdr_draft").jqGrid({
			url:'<?php echo base_url().'exim/ct_inv_draft/loaddata'; ?>',
			mtype : "post",
			postData:{'q':'1'},
			datatype: "json",
			colNames:['ID', 'No. Invoice', 'Date. Inv','Supp. Code', 'Supp. Name', 'Container', 'Vessel','No BL/AWB','TGL BL/AWB','Date Load', 'Status'],
			colModel:[
				{name:'inv_hdr_id',index:'inv_hdr_id', width:60, hidden:true},
				{name:'r3',index:'r3', width:89, hidden:false},
				{name:'r5',index:'r5', width:89, hidden:false},
				{name:'r2',index:'r2', width:70, hidden:false},
				{name:'supplier_name',index:'supplier_name', width:180, hidden:false},
				{name:'r4',index:'r4', width:95, hidden:false},
				{name:'r20',index:'r20', width:75, hidden:false},
				{name:'nobl',index:'nobl', width:85, hidden:false},
				{name:'tgbl',index:'tgbl', width:75, hidden:false,stype:"text",searchoptions:{dataInit:datePick, att:{title:'Select Date'}}},
				{name:'date_create',index:'date_create', width:114, hidden:false},
				{name:'status_inv',index:'status_inv', width:75, hidden:false, formatter:myformatter,stype:"select",editoptions:{value:"-:;0:New;1:Not New;2:All"}},
				
			],
			rowNum:10,
			rowList:[10,20,30],
			pager: '#ptblbc23hdr_draft',
			sortname: 'inv_hdr_id',
			viewrecords: true,
			sortorder: "asc",
			width: 970,
			height:250,
			jsonReader: { repeatitems : false },
			caption:"INVOICE DATA",
			rownumbers: true,
			shrinkToFit: false,
			afterInsertRow: function(){
				
					
			},
			gridComplete: function(){
				var rowIDs = jQuery("#tblbc23hdr_draft").getDataIDs(); 
				var rowData = $("#tblbc23hdr_draft").getRowData();
			
				for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = jQuery("#"+ rowIDs[i],jQuery('#tblbc23hdr_draft'));
					
					if(rowData[i].nobl != '-'){  trElement.css({"color":"blue"}); }
					
				}
			},
		}); 
			
              
		jQuery("#tblbc23hdr_draft").jqGrid('navGrid','#ptblbc23hdr_draft',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#tblbc23hdr_draft").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});
		
		
	});
	
		  	
</script>

<div id="frminvdtl_dlg" title="INVOICE DATA DETAIL" class="frminvdtl_dlg_cl"></div>
<div id="frminvdtl_summary_dlg_h" title="INVOICE DATA SUMMARY DETAIL" class="frminvdtl_summary_dlg_h_cl"></div>
<div id="bc23_addbldata_dlg" title="ADD DATA BL/AWB" class="bc23_addbldata_dlg_cl"></div>
<div id="bc23_insertproses_dlg" title="PROSES DATA" class="bc23_insertproses_dlg_cl"></div>
<div id="inv_datauploaded_dlg" title="DATA INVOICE YANG DIUPLOAD" class="inv_datauploaded_dlg_cl"></div>



	
	