
<div class="pane-header ui-state-active" id="alatkantor_set_bar" >    
	<button id="btn_alatkantor_create_memo">DATA BARU</button>
	<button id="btn_alatkantor_update_memo">UPDATE DATA</button>
	<button id="btn_alatkantor_scap_memo">PROSES SCRAP</button>
	<button id="btn_alatkantor_kirim_exim_memo">KIRIM EXIM</button>
	
</div>
<table id="tbl_alatkantor_memo"></table> <div id="ptbl_alatkantor_memo"></div>

<script type="text/javascript">
    
	
    $(document).ready(function(){
		
		
		jQuery("#tbl_alatkantor_memo").jqGrid({
			url:'<?php echo base_url().'settings/ct_barangmesin/data_alatkantor_memo_Allx'; ?>',
			mtype : "post",
			postData:{'q':'1'},
			datatype: "json",
			colNames:[
			'id_memo', 
			'nomor memo',
			'tgl_memo', 
			'npwp_pembeli', 'kode_pembeli','nama_pembeli','nil_invoice','id_ceisa_hdr','tipe_out', 'bc_no'
			, 'tgl_bc','car'
			,'ndpbm'
			,'bruto'
			,'kdval'
			,'status'
			, 'create_date','create_by','update_date','update_by',
			
			],
			colModel:[
				{name:'id_memo',index:'id_memo', width:60, hidden:true},
				{name:'nomor_memo',index:'nomor_memo', width:159},
				{name:'tgl_memo',index:'tgl_memo', width:90},
				{name:'npwp_pembeli',index:'npwp_pembeli', width:105, hidden:false},
				{name:'kode_pembeli',index:'kode_pembeli', width:105,hidden:false},
				{name:'nama_pembeli',index:'nama_pembeli', width:195,hidden:false},
				{name:'harga_penyerahan',index:'harga_penyerahan', width:105, hidden:false, align:"right"},
				{name:'id_ceisa_hdr',index:'id_ceisa_hdr', width:105, hidden:true},
				{name:'tipe_out',index:'tipe_out', width:84,hidden:false},
				{name:'bc_no',index:'bc_no', width:105},
				{name:'tgl_bc',index:'tgl_bc', width:105},
				{name:'car',index:'car', width:137},
				{name:'ndpbm',index:'ndpbm', width:105},
				{name:'bruto',index:'bruto', width:105},
				{name:'kdval',index:'kdval', width:105},
				{name:'status_data',index:'status_data', width:105, hidden:false},
				{name:'create_date',index:'create_date', width:84,hidden:false},
				{name:'create_by',index:'create_by', width:84,hidden:false},
				{name:'update_date',index:'update_date', width:84,hidden:false},
				{name:'update_by',index:'update_by', width:84,hidden:false},
				],
			rowNum:20,
			rowList:[20,50,100],
			pager: '#ptbl_alatkantor_memo',
			sortname: 'id_memo',
			viewrecords: true,
			sortorder: "desc",
			width: '',
			height:300,
			jsonReader: { repeatitems : false },
			caption:"Data Bahan Penolong",
			rownumbers: true,
			shrinkToFit: false,
			afterInsertRow: function(){
				
				
			},			
			gridComplete: function(){
				var rowIDs = jQuery("#tbl_alatkantor_memo").getDataIDs(); 
				var rowData = $("#tbl_alatkantor_memo").getRowData();
			
				for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = jQuery("#"+ rowIDs[i],jQuery('#tbl_alatkantor_memo'));
				   
					switch (rowData[i].status_data) {
						
						case 'PROSESEXIM':
						   trElement.css({"color":"green"});
						break;
						case 'PROCESSEDBC':
						   trElement.css({"color":"blue"});
						break;
						
						
					}
				}
			},
		}); 
			
                        
		jQuery("#tbl_alatkantor_memo").jqGrid('navGrid','#ptbl_alatkantor_memo',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#tbl_alatkantor_memo").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});
		
		
		
		$("#btn_alatkantor_create_memo").button().click(function(){
			$("#frm_create_memo_alatkantor").load('<?php echo base_url().'settings/ct_barangmesin/view_alatkantor_memo_update'; ?>',  {
				parmeter:'parameter',
				command : 'CREATE'
				
				}, function() {
				$("#frm_create_memo_alatkantor").dialog({
					modal:true,
					width : 900,
					height : 600,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
                    },
					close : function(){
						$('#frm_create_memo_alatkantor').dialog("destroy"); 
					    $(".frm_create_memo_alatkantor_cl").remove(); 
					    $("body").append('<div id="frm_create_memo_alatkantor" title="BAHAN ALAT KANTOR MEMO" class="frm_create_memo_alatkantor_cl"></div>'); 
						
					},
					open: function(){
						$("body").unblock();
						
					}
				});
			});
			
		});
		
		$("#btn_alatkantor_update_memo").button().click(function(){
			var id = jQuery("#tbl_alatkantor_memo").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tbl_alatkantor_memo").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};	
			
			var form_data = {
				id_memo:ret.id_memo
				,command:'UPDATE'
			}
			
			$("#frm_create_memo_alatkantor").load('<?php echo base_url().'settings/ct_barangmesin/view_alatkantor_memo_update'; ?>', 
			form_data , function() {
				$("#frm_create_memo_alatkantor").dialog({
					modal:true,
					width : 900,
					height : 600,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
                    },
					close : function(){
						$('#frm_create_memo_alatkantor').dialog("destroy"); 
					    $(".frm_create_memo_alatkantor_cl").remove(); 
					    $("body").append('<div id="frm_create_memo_alatkantor" title="BAHAN PENOLONG MEMO" class="frm_create_memo_alatkantor_cl"></div>'); 
						
					},
					open: function(){
						$("body").unblock();
						
					}
				});
			});
				
			
		});
		
		$("#btn_alatkantor_kirim_exim_memo").button().click(function(){
			var id = jQuery("#tbl_alatkantor_memo").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tbl_alatkantor_memo").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};	
			
			
			
			if (ret.status_data == 'NEW'){
				var cmd = "PROSESEXIM";
				var cmt = "PROSESEXIM";
			} else if (ret.status_data == 'PROSESEXIM'){
				var cmd = 'NEW'
				var cmt = 'PEMBATALAN PROSESEXIM'
			} else {
				alert("DATA SUDAH DI PROSES");
				return false;
			}	
			
			var form_data = {
				id_memo:ret.id_memo
				,status_data : cmd
				,command:'UPDATE'
			}
			
			$("#dlg_alatkantor_memo_update_exim").dialog( "destroy" );
			$(".dlg_alatkantor_memo_update_exim_cl").remove();
			$("body").append('<div id="dlg_alatkantor_memo_update_exim" title="Warning" class="dlg_alatkantor_memo_update_exim_cl"><p>Apakah anda akan melakukan ' + cmt + ' data memo ini?!?</p><br /></div>');
			$("#dlg_alatkantor_memo_update_exim").dialog({
				height: 200,
				width: 250,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : "<?php echo base_url().'settings/ct_barangmesin/update_memo_exim'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlg_alatkantor_memo_update_exim").dialog("close");
								$('#dlg_alatkantor_memo_update_exim').dialog("destroy"); 
								$(".dlg_alatkantor_memo_update_exim_cl").remove(); 
								$('#tbl_alatkantor_memo').trigger('reloadGrid');
								$('#tbl_alatkantor_memo_dtl').trigger('reloadGrid');
								$("#id_bp_out_dtl").val(msg.id_bp_out_dtl);
								$("body").append('<div id="dlg_alatkantor_memo_update_exim" title="Warning" class="dlg_alatkantor_memo_update_exim_cl"></div>');
			

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

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

					}
				},
				close : function(){
					$('#dlg_alatkantor_memo_update_exim').dialog("destroy"); 
					$(".dlg_alatkantor_memo_update_exim_cl").remove(); 
					$("body").append('<div id="dlg_alatkantor_memo_update_exim" title="Warning" class="dlg_alatkantor_memo_update_exim_cl"><p>Apakah anda akan melakukan insert part hs ini?!?</p><br /></div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});
			
		});
		
		$("#btn_alatkantor_scap_memo").button().click(function(){
			var id = jQuery("#tbl_alatkantor_memo").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tbl_alatkantor_memo").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};	
			
			if(ret.tipe_out != "SCRAP"){
				
				alert("BUKAN MEMO SCRAP");
				return false;
			}
			
			var form_data = {
				id_memo:ret.id_memo
				,command:'UPDATE'
			}
			
			$("#frm_create_memo_alatkantor").load('<?php echo base_url().'settings/ct_barangmesin/view_alatkantor_memo_scrap'; ?>', 
			form_data , function() {
				$("#frm_create_memo_alatkantor").dialog({
					modal:true,
					width : 1100,
					height : 630,
					buttons: {
                        "Close": function() {  
							$(".ui-dialog-titlebar-close").trigger('click');  
							
						}
                    },
					close : function(){
						$('#frm_create_memo_alatkantor').dialog("destroy"); 
					    $(".frm_create_memo_alatkantor_cl").remove(); 
					    $("body").append('<div id="frm_create_memo_alatkantor" title="ALAT kANTOR MEMO SCRAP" class="frm_create_memo_alatkantor_cl"></div>'); 
						
					},
					open: function(){
						$("body").unblock();
						
					}
				});
			});
			
			
		});
			
		
	});
		  	
</script>
<div id="frm_create_memo_alatkantor" title="ALAT KANTOR MEMO" class="frm_create_memo_alatkantor_cl"></div>
<div id="frm_create_memo_alatkantor" title="ALAT KANTOR MEMO SCRAP" class="frm_create_memo_alatkantor_cl">
	
	