<style>

</style>

<div style="height:10px;" id="alatkantor_set_bar" >    
</div>

<div style="height:10px;"  >    
<table>
<tr>
	<td>
		<table id="tbl_bahanpenolong_memo_scrap_dtl"></table> <div id="ptbl_bahanpenolong_memo_scrap_dtl"></div>
	</td>
	<td>
		<span id="id_memo_scrap_name"></span>
		<hr />
		<table>
			<tr>
				<td style="vertical-align: middle;">KODE SCRAP</td><td>:</td><td><input id="kode_scrap"  /></td>
			</tr>
			<tr>
				<td style="vertical-align: middle;">NAMA SCRAP</td><td>:</td><td><input id="nama_scrap" readonly="readonly" /></td>
			</tr>
			<tr>
				<td style="vertical-align: middle;">QTY</td><td>:</td><td><input style="text-align: right;" id="qty_scrap"></input></td>
			</tr>
			<tr>
				<td style="vertical-align: middle;">JM KEMAS</td><td>:</td><td><input style="text-align: right;" id="jmkemas_scrap"></input></td>
			</tr>
			<tr>
				<td style="vertical-align: middle;">JN KEMAS</td><td>:</td><td><input style="text-transform: uppercase;"id="jnkemas_scrap"></input></td>
			</tr>
			<tr>
				<td style="vertical-align: middle;">NETTO</td><td>:</td><td><input style="text-align: right;" id="netto_scrap"></input></td>
			</tr>
			<tr>
				<td style="vertical-align: middle;">BRUTO</td><td>:</td><td><input  style="text-align: right;" id="bruto_scrap"></input></td>
			</tr>
			<tr>
				<td style="vertical-align: middle;">HARGA</td><td>:</td><td><input style="text-align: right;" id="harga_scrap"></input></td>
			</tr>
			<tr>
				<td style="vertical-align: middle;"></td><td></td><td><button id="id_save_memo_scrap" >SAVE</button>&nbsp 
				</td>
			</tr>
		</table>
	</td>
</tr>
</table>
<table id="tbl_bahanpenolong_memo_scrap"></table> <div id="ptbl_bahanpenolong_memo_scrap"></div>
</div>

<script type="text/javascript">
    
	
    $(document).ready(function(){
		
		$("#qty_scrap").number(true,4,'.',' ');
		$("#jmkemas_scrap").number(true,4,'.',' ');
		$("#netto_scrap").number(true,4,'.',' ');
		$("#bruto_scrap").number(true,4,'.',' ');	
		$("#harga_scrap").number(true,4,'.',' ');			
		jQuery("#tbl_bahanpenolong_memo_scrap").jqGrid({
			url:'<?php echo base_url().'settings/ct_barangbahanpenolong/data_bahanpenolong_memo_Allx'; ?>',
			mtype : "post",
			postData:{'q':'1', status_data:function(){ return 'NEW'; },fill:function(){ return 'SCRAP'; } },
			datatype: "json",
			colNames:[
			'id_memo', 
			'nomor memo',
			'tgl_memo', 
			'npwp_pembeli', 'kode_pembeli','nama_pembeli','harga_penyerahan','tipe_out','id_ceisa_hdr', '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:'tipe_out',index:'tipe_out', width:84,hidden:false},
				{name:'id_ceisa_hdr',index:'id_ceisa_hdr', width:105, hidden:true},
				{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_bahanpenolong_memo_scrap',
			sortname: 'id_memo',
			viewrecords: true,
			sortorder: "desc",
			width: '',
			height:90,
			jsonReader: { repeatitems : false },
			caption:"DATA MEMO SCRAP",
			rownumbers: true,
			shrinkToFit: false,
			afterInsertRow: function(){
				
				
			},			
			gridComplete: function(){
				var rowIDs = jQuery("#tbl_bahanpenolong_memo_scrap").getDataIDs(); 
				var rowData = $("#tbl_bahanpenolong_memo_scrap").getRowData();
			
				for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = jQuery("#"+ rowIDs[i],jQuery('#tbl_bahanpenolong_memo_scrap'));
				   
					switch (rowData[i].status_data) {
						
						case 'PROSESEXIM':
						   trElement.css({"color":"green"});
						break;
						case 'PROCESSEDBC':
						   trElement.css({"color":"red"});
						break;
						
					}
				}
				 
			},
			onSelectRow: function(id){
				var grididpr = jQuery("#tbl_bahanpenolong_memo_scrap").jqGrid('getGridParam','selrow');
				 if(grididpr){
					 var stret = jQuery("#tbl_bahanpenolong_memo_scrap").jqGrid('getRowData',grididpr);
					var form_data={'q':'1', id_memo_bp:function(){ return stret.id_memo },fill:function(){ return 'SCRAP' } }
					jQuery("#tbl_bahanpenolong_memo_scrap_dtl").jqGrid('setGridParam', { postData:form_data });
					$("#tbl_bahanpenolong_memo_scrap_dtl").trigger("reloadGrid");
					  
					
				 }
			}
		}); 
			
                        
		jQuery("#tbl_bahanpenolong_memo_scrap").jqGrid('navGrid','#ptbl_bahanpenolong_memo_scrap',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#tbl_bahanpenolong_memo_scrap").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});
		jQuery("#tbl_bahanpenolong_memo_scrap").jqGrid('bindKeys', {"onEnter":function( rowid ) { 
			//alert("You enter a row with id:"+rowid)
			} 
		});
		
		jQuery("#tbl_bahanpenolong_memo_scrap_dtl").jqGrid({
			url:'<?php echo base_url().'settings/ct_barangbahanpenolong/data_bahanpenolong_memo_scrap'; ?>',
			mtype : "post",
			postData:{'q':'1', id_memo_bp:function(){ return '0' },fill:function(){ return 'SCRAP' } },
			datatype: "json",
			colNames:[
			'id_bp_out_dtl', 
			'part_no',
			'part_name', 
			'qty'
			,'uom'
			,'kode_scrap'
			,'nama_scrap'
			,'qty_scrap'
			,'bruto scrap'
			,'netto scrap'
			,'harga'
			,'jm kemas'
			,'jn kemas'
			,'id_memo'
			],
			colModel:[
				{name:'id_bp_out_dtl',index:'id_bp_out_dtl', width:60, hidden:true},
				{name:'part_no',index:'part_no', width:99},
				{name:'part_name',index:'part_name', width:120},
				{name:'qty',index:'qty', width:90, hidden:false, align:'right'},
				{name:'uom',index:'uom', width:80,hidden:false},
				{name:'kode_scrap',index:'kode_scrap', width:105,hidden:false},
				{name:'nama_scrap',index:'nama_scrap', width:105,hidden:false},
				{name:'qty_scrap',index:'qty_scrap', width:105,hidden:false},
				{name:'bruto_scrap',index:'bruto_scrap', width:105,hidden:false},
				{name:'netto_scrap',index:'netto_scrap', width:105,hidden:false},
				{name:'harga_scrap',index:'harga_scrap', width:105,hidden:false},
				{name:'jmkemas_scrap',index:'jmkemas_scrap', width:105,hidden:false},
				{name:'jnkemas_scrap',index:'jnkemas_scrap', width:105,hidden:false},
				{name:'id_memo_bp',index:'id_memo_bp', width:105,hidden:true}
				
				],
			rowNum:20,
			rowList:[20,50,100],
			pager: '#ptbl_bahanpenolong_memo_scrap_dtl',
			sortname: 'tbl_bahanpenolong_out.id_bp_out_dtl',
			viewrecords: true,
			sortorder: "desc",
			width: 800,
			height:240,
			jsonReader: { repeatitems : false },
			//caption:"Data Bahan Penolong",
			rownumbers: true,
			shrinkToFit: false,
			afterInsertRow: function(){
				
				
			},			
			gridComplete: function(){
				var rowIDs = jQuery("#tbl_bahanpenolong_memo_scrap_dtl").getDataIDs(); 
				var rowData = $("#tbl_bahanpenolong_memo_scrap_dtl").getRowData();
			
				for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = jQuery("#"+ rowIDs[i],jQuery('#tbl_bahanpenolong_memo_scrap_dtl'));
				   
					switch (rowData[i].status_data) {
						
						//case 'PROSESEXIM':
						 //  trElement.css({"color":"green"});
						//break;
						//case 'PROCESSEDBC':
						//   trElement.css({"color":"red"});
						//break;
						
					}
				}
				$("#tbl_bahanpenolong_memo_scrap_dtl").setSelection(1, true);
				var colSum1 = jQuery("#tbl_bahanpenolong_memo_scrap_dtl").jqGrid('getCol', 'qty_scrap', false, 'sum');
				var colSum2 = jQuery("#tbl_bahanpenolong_memo_scrap_dtl").jqGrid('getCol', 'bruto_scrap', false, 'sum');
				var colSum3 = jQuery("#tbl_bahanpenolong_memo_scrap_dtl").jqGrid('getCol', 'netto_scrap', false, 'sum');
				jQuery("#tbl_bahanpenolong_memo_scrap_dtl").jqGrid('footerData', 'set', { 'qty_scrap': colSum1, 'bruto_scrap':colSum2, 'netto_scrap':colSum3});

			},
			onSelectRow: function(id){
				var grididpr = jQuery("#tbl_bahanpenolong_memo_scrap_dtl").jqGrid('getGridParam','selrow');
				 if(grididpr){
					var ret = jQuery("#tbl_bahanpenolong_memo_scrap_dtl").jqGrid('getRowData',grididpr);
					$("#id_memo_scrap_name").html(" PART NO : <b>" + ret.part_no + " </b><br />PART NAME : <b> " + ret.part_name + "</b> <BR /> QTY :<b> " + ret.qty + "</b>")	
					$("#kode_scrap").val(ret.kode_scrap);
					$("#nama_scrap").val(ret.nama_scrap) ;
					$("#qty_scrap").val(ret.qty_scrap) ;
					$("#jmkemas_scrap").val(ret.jmkemas_scrap);
					$("#jnkemas_scrap").val(ret.jnkemas_scrap);
					$("#netto_scrap").val(ret.netto_scrap);
					$("#bruto_scrap").val(ret.bruto_scrap);
					$("#harga_scrap").val(ret.harga_scrap);
				 }
			},
			footerrow : true
		}); 
			
                        
		jQuery("#tbl_bahanpenolong_memo_scrap_dtl").jqGrid('navGrid','#ptbl_bahanpenolong_memo_scrap_dtl',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#tbl_bahanpenolong_memo_scrap_dtl").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});
		jQuery("#tbl_bahanpenolong_memo_scrap_dtl").jqGrid('bindKeys', {"onEnter":function( rowid ) { 
			//alert("You enter a row with id:"+rowid)
			} 
		});
		
		$("#kode_scrap").autocomplete('<?php echo base_url().'settings/ct_barangbahanpenolong/autocomplete_kode_scrap'; ?>', {
			dataType: 'json',
			max: 50,
			width:400,
			parse: function(data) {
				var rows = new Array();
				data = data;
				if(data.length == 0){
					$("#kode_scrap").val('');
					$("#nama_scrap").val('');
					return false;
				}
				for(var i=0; i<data.length; i++){
					rows[i] = { data:data[i],
						value:data[i].part_no,
						result:data[i].part_name
					};
				}
				return rows;
			},
			formatItem: function(row, i, max) {
				return row.part_no+ ', ' +row.part_name+ ', ' + row.part_name_customs+ ', ' + row.hs_code;
			},
			formatResult: function (row, i, max) {eval("row=" + row); return row.kode_scrap;},

			extraParams: {
				part_no: function () { return $("#kode_scrap").val() }
			},cache: false
		}).flushCache();
		$("#kode_scrap").result(function(event, row, formatted) {

			$("#kode_scrap").val(row.part_no);
			$("#nama_scrap").val(row.part_name);
			


		});
		
		$("#id_save_memo_scrap").button().click(function(){
			var id = jQuery("#tbl_bahanpenolong_memo_scrap_dtl").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tbl_bahanpenolong_memo_scrap_dtl").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				return false;
			};	
			
			
			
			var form_data = {
				part_no:$("#kode_scrap").val()
				,part_name:$("#nama_scrap").val() 
				,qty_scrap :$("#qty_scrap").val() 
				,jmkemas_scrap :$("#jmkemas_scrap").val()
				,jnkemas_scrap :$("#jnkemas_scrap").val().toUpperCase()
				,netto_scrap :$("#netto_scrap").val()
				,bruto_scrap:$("#bruto_scrap").val()
				,id_memo_bp:ret.id_memo_bp
				,id_bp_out_dtl:ret.id_bp_out_dtl
				,harga_scrap:$("#harga_scrap").val()
			}
			
			$.ajax({
				url : "<?php echo base_url().'settings/ct_barangbahanpenolong/update_memo_scrap_bahanpenolong'; ?>",
				type : 'POST',
				dataType: 'json',
				data : form_data,
				success: function(msg){
					if (msg.sts == '00'){
						alert(msg.desc);

						$('#tbl_bahanpenolong_memo_scrap_dtl').trigger('reloadGrid');
						

					} else { 
						alert(msg.sts+msg.desc); 
						
					}
				}
			});
				
			
		});
		
	
		
	});
		  	
</script>
<div id="frm_create_memo_bahanpenolong" title="BAHAN PENOLONG MEMO" class="frm_create_memo_bahanpenolong_cl"></div>

	
	