<div style="height:2px;">
	
</div>
<div id="viewprosesscrap_out" >
<button id="btnviewdataoutscrap" >View Data Out</button>
<table>
	<td><table id="tbl_scrap_bahanbaku_out"></table> <div id="ptbl_scrap_bahanbaku_out"></div></td>
	<td align="center">
		<div style="width:96">
		Pilih Data, Isikan No Dok Out dan Tanggal Dok Out.
		Lalu Proses.
		<br /><br />No Dok Out<input id="txtno_scrap_out"  />
		<br /><br />Tg Dok Out<input id="txttgl_scrap_out" readonly="readonly" />
		<br /><br /><button id="btnselectscrap_bahanbaku_out" >Select Data Scrap >></button>
		<br /><br /><button id="btnprosesscrap_bahanbaku_out" ><< Proses Add Group >></button>
		<br /><br /><button id="btncancelscrap_bahanbaku_out" >Cancel</button>
		</div>
	</td>
	<td>
		<table id="listgroupscrap_out"></table><div id="plistgroupscrap_out"></div>
	</td>
</table>
</div>
<div id="data_scrap_out" >
<button id="btnbackprosesdataoutscrap" >Back To Proses</button>
<br />
<table id="tbl_scrap_bahanbaku_out_view"></table> <div id="ptbl_scrap_bahanbaku_out_view"></div>

</div>
<script type="text/javascript">
    
    $(document).ready(function(){
		var datesetopt = {
			showOn: "button",
			buttonImageOnly: true,
			buttonImage: "<?php echo base_url()."assets/images/icons/16x16/timespan.png"  ?>",
			buttonText: "Tanggalan",
			dateFormat: 'mm/dd/yy'
		};
		
		
		
		$("#btnviewdataoutscrap").button().click(function(){
			
			$("#viewprosesscrap_out").fadeOut();
			$("#data_scrap_out").fadeIn();
			jQuery("#tbl_scrap_bahanbaku_out_view").trigger('reloadGrid');
		
		});
		
		$("#btnbackprosesdataoutscrap").button().click(function(){
			$("#viewprosesscrap_out").fadeIn();
			$("#data_scrap_out").fadeOut();
		
		});
		
		$("#txttgl_scrap_out").datepicker(datesetopt);
		
		$("#data_scrap_out").hide();
		
		$("#btnselectscrap_bahanbaku_out").button().click(function(){
			
			var rowIds = $('#listgroupscrap_out').jqGrid('getDataIDs');
			for(var i=0,len=rowIds.length;i<len;i++){
				var currRow = rowIds[i];
				$('#listgroupscrap_out').jqGrid('delRowData', currRow);
			}	
			
			var selr; 
			selr = jQuery("#tbl_scrap_bahanbaku_out").jqGrid('getGridParam','selarrrow'); 
			if(selr.length) {
				for(var i=0;i<selr.length;i++)
				{
					var myrow = jQuery('#tbl_scrap_bahanbaku_out').jqGrid('getRowData',selr[i]);
					var idgroupinvadd =  $.jgrid.randId();
					jQuery("#listgroupscrap_out").jqGrid('addRowData', idgroupinvadd, {
						id_scrap_out:myrow.id_scrap,
						part_no:myrow.part_no,
						part_name:myrow.part_name,
						qty:myrow.qty,
						unit:myrow.unit
					});
					
				}
			}
		
		
		});
		$("#btnprosesscrap_bahanbaku_out").button().click(function(){
			var rowdatagrid = jQuery("#listgroupscrap_out").jqGrid('getGridParam', 'records');
			if(rowdatagrid < 1){
				alert('pilih data terlebih dahulu');
				return false;
			}
			if($.trim($("#txtno_scrap_out").val())==''){
				alert('Isikan Dok No data terlebih dahulu');
				return false;
			
			}
			if($("#txttgl_scrap_out").val()==''){
				alert('Isikan Tg Dok No data terlebih dahulu');
				return false;
			
			}
			var gridData = jQuery("#listgroupscrap_out").getRowData();
			var postData = JSON.stringify(gridData);
			var form_data={
				no_scrap_out:$("#txtno_scrap_out").val(),
				tgl_scrap_out:$("#txttgl_scrap_out").val(),
				datadiff:postData
			};
			
			$("#dlgscrap_out_proses").dialog( "destroy" );
			$(".dlgscrap_out_prosescl").remove();
			$(".dlgscrap_out_prosescl").html('');
			$("body").append('<div id="dlgscrap_out_proses" title="Warning" class="dlgscrap_out_prosescl"><p>Apakah anda akan memproses data ini?!?</p></div>');
			$("#dlgscrap_out_proses").dialog({
				height: 200,
				width: 250,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : "<?php echo base_url().'inventory/ct_scrap/prosesgroupscrap_out'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlgscrap_out_proses").dialog("close");
								$('#dlgscrap_out_proses').dialog("destroy"); 
								$(".dlgscrap_out_prosescl").remove(); 
								$('#tblscrap_out_proses').trigger('reloadGrid');
								jQuery("#tbl_scrap_bahanbaku").trigger('reloadGrid');
							} else { 
								alert(msg.sts+' '+msg.desc); 
								$("#dlgscrap_out_proses").dialog("close");
								$('#dlgscrap_out_proses').dialog("destroy"); 
								$(".dlgscrap_out_prosescl").remove(); 
								$('#tblscrap_out_proses').trigger('reloadGrid');
								jQuery("#tbl_scrap_bahanbaku").trigger('reloadGrid');

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

					}
				},
				close : function(){
					$('#dlgscrap_out_proses').dialog("destroy"); 
					$(".dlgscrap_out_prosescl").remove(); 
					$("body").append('<div id="dlgscrap_out_proses" title="Warning" class="dlgscrap_out_prosescl"><p>Apakah anda akan memproses data ini?!?</p></div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});
		
			
		
		
		});
		
		$("#btncancelscrap_bahanbaku_out").button();
		
		var  typebahan = 'SCRAPBB';
		var form_data1 = {
			'typebahanx':typebahan,
			'test':'aa'
		
		};
		
		jQuery("#tbl_scrap_bahanbaku_out").jqGrid({
			url:'<?php echo base_url().'inventory/ct_scrap/loaddatascrap_out'; ?>',
			mtype : "post",
			postData:form_data1,
			datatype: "json",
			colNames:[
				'id_scrap'
			  ,'DATE SCRAP'
			  ,'KODE BARANG'
			  ,'NAMA BARANG SCRAP'
			  ,'PART NAME CUSTOMS'
			  ,'QTY'
			  ,'UNIT'
			  ,'unit_konversi'
			  ,'pengali'
			  ,'netto'
			  ,'brutto'
			  ,'typebahan'
			  ,'create date'
			  ,'create by'
			  ,'update date'
			  ,'update by'
			  ,'status'
			],
			colModel:[
				{name:'id_scrap',index:'id_scrap', width:60, hidden:true},
				{name:'date_scrap',index:'date_scrap', width:85, searchoptions:{sopt:['eq','cn','gt','lt'],dataInit:function(el){$(el).datepicker({dateFormat:'yy-mm-dd'});} }},
				{name:'part_no',index:'part_no', width:50},
				{name:'part_name',index:'part_name', width:97},
				{name:'part_name_customs',index:'part_name_customs', width:200, hidden:true},
				{name:'qty',index:'qty', width:78, hidden:false, align:'right'},
				{name:'unit',index:'unit', width:78, hidden:false},
				{name:'unit_konversi',index:'unit_konversi', width:106, hidden:true},
				{name:'pengali',index:'pengali', width:106, hidden:true},
				{name:'netto',index:'netto', width:106, hidden:true},
				{name:'brutto',index:'brutto', width:106, hidden:true},
				{name:'typebahan',index:'typebahan', width:106, hidden:true},
				{name:'create_date',index:'create_date', width:106, hidden:true},
				{name:'create_by',index:'create_by', width:106, hidden:false},
				{name:'update_date',index:'update_date', width:106, hidden:false},
				{name:'update_by',index:'update_by', width:106, hidden:true},
				{name:'status',index:'status', width:106, hidden:false}
				],
			rowNum:10,
			rowList:[10,20,30],
			pager: '#ptbl_scrap_bahanbaku_out',
			sortname: 'id_scrap',
			viewrecords: true,
			sortorder: "desc",
			width: 450,
			height:281,
			jsonReader: { repeatitems : false },
			caption:"daftar scrap masuk",
			rownumbers: true,
			shrinkToFit: false,
			multiselect: true,	
			afterInsertRow: function(){
			
				
			},			
			gridComplete: function(){
				var rowIDs = jQuery("#tbl_scrap_bahanbaku").getDataIDs(); 
				var rowData = $("#tbl_scrap_bahanbaku").getRowData();
			
				for (var i = 0; i < rowData.length; i++) 
				{
				   var trElement = jQuery("#"+ rowIDs[i],jQuery('#tbl_scrap_bahanbaku'));
				   
					switch (rowData[i].status) {
						
						case 'DATA PROCESSED':
						   trElement.css({"color":"green"});
						break;
						case 'APPROVED':
						   trElement.css({"color":"red"});
						break;
					}
				}
			},
		}); 
		 	
        jQuery("#tbl_scrap_bahanbaku_out").jqGrid('navGrid','#ptbl_scrap_bahanbaku_out',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#tbl_scrap_bahanbaku_out").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});	
        
		jQuery("#listgroupscrap_out").jqGrid({
			url:'<?php echo base_url().'inventory/ct_scrap/loaddata_scrap_out_list'; ?>',
			postData:{a:'a',xax:'song'},
			mtype : "post",
			datatype: "json",
			width: 280,
			height:320,
			colNames:[
				'id_scrap_out'
			  ,'date_scrap'
			  ,'Kode Barang'
			  ,'Nama Barang'
			  ,'part_name_customs'
			  ,'qty'
			  ,'unit'
			  ,'unit_konversi'
			  ,'pengali'
			  ,'netto'
			  ,'brutto'
			  ,'typebahan'
			  ,'create_date'
			  ,'create_by'
			  ,'update_date'
			  ,'update_by'
			  ,'no_dok_out'
			  ,'id_scrap'
			],
			colModel:[
				{name:'id_scrap_out',index:'id_scrap_out', width:60, sorttype:"int", hidden:true},
				{name:'date_scrap',index:'date_scrap', width:85, hidden:true,searchoptions:{sopt:['eq','cn','gt','lt'],dataInit:function(el){$(el).datepicker({dateFormat:'yy-mm-dd'});} }},
				{name:'part_no',index:'part_no', width:76},
				{name:'part_name',index:'part_name', width:102},
				{name:'part_name_customs',index:'part_name_customs', width:200, hidden:true},
				{name:'qty',index:'qty', width:80, hidden:false, align:'right'},
				{name:'unit',index:'unit', width:80, hidden:false},
				{name:'unit_konversi',index:'unit_konversi', width:106, hidden:true},
				{name:'pengali',index:'pengali', width:106, hidden:true},
				{name:'netto',index:'netto', width:106, hidden:true},
				{name:'brutto',index:'brutto', width:106, hidden:true},
				{name:'typebahan',index:'typebahan', width:106, hidden:true},
				{name:'create_date',index:'create_date', width:106, hidden:true},
				{name:'create_by',index:'create_by', width:106, hidden:true},
				{name:'update_date',index:'update_date', width:106, hidden:true},
				{name:'update_by',index:'update_by', width:106, hidden:true},
				{name:'no_dok_out',index:'no_dok_out', width:106, hidden:true},
				{name:'id_scrap',index:'id_scrap', width:106, hidden:true}
				
			],
			pager: '#plistgroupscrap_out',
			rowNum:10,
			rowList:[10,40,100],
			sortname: 'id_scrap_out',
			sortorder: 'desc',
			jsonReader: { repeatitems : false },
			viewrecords: true,
			shrinkToFit: false,
			multiselect: false,
			caption: "Selected Data Out"
		});
		jQuery("#listgroupscrap_out").jqGrid('navGrid','#plistgroupscrap_out',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		
		jQuery("#tbl_scrap_bahanbaku_out_view").jqGrid({
			url:'<?php echo base_url().'inventory/ct_scrap/loaddata_scrap_out'; ?>',
			postData:{a:'a'},
			mtype : "post",
			datatype: "json",
			width: 850,
			height:290,
			colNames:[
				'id_scrap_out'
				,'No. Dok Out'
			  ,'date'
			  ,'Kode Barang'
			  ,'Nama Barang'
			  ,'part_name_customs'
			  ,'qty'
			  ,'unit'
			  ,'unit_konversi'
			  ,'pengali'
			  ,'netto'
			  ,'brutto'
			  ,'typebahan'
			  ,'create_date'
			  ,'create_by'
			  ,'update_date'
			  ,'update_by'
			  
			  ,'id_scrap'
			],
			colModel:[
				{name:'id_scrap_out',index:'id_scrap_out', width:60, sorttype:"int", hidden:true},
				{name:'no_dok_out',index:'no_dok_out', width:106, hidden:false},
				{name:'date_scrap',index:'date_scrap', width:85, hidden:false,searchoptions:{sopt:['eq','cn','gt','lt'],dataInit:function(el){$(el).datepicker({dateFormat:'yy-mm-dd'});} }},
				{name:'part_no',index:'part_no', width:76},
				{name:'part_name',index:'part_name', width:191},
				{name:'part_name_customs',index:'part_name_customs', width:200, hidden:true},
				{name:'qty',index:'qty', width:126, hidden:false, align:'right'},
				{name:'unit',index:'unit', width:132, hidden:false},
				{name:'unit_konversi',index:'unit_konversi', width:106, hidden:true},
				{name:'pengali',index:'pengali', width:106, hidden:true},
				{name:'netto',index:'netto', width:106, hidden:true},
				{name:'brutto',index:'brutto', width:106, hidden:true},
				{name:'typebahan',index:'typebahan', width:106, hidden:true},
				{name:'create_date',index:'create_date', width:106, hidden:true},
				{name:'create_by',index:'create_by', width:106, hidden:true},
				{name:'update_date',index:'update_date', width:106, hidden:true},
				{name:'update_by',index:'update_by', width:106, hidden:true},
				{name:'id_scrap',index:'id_scrap', width:106, hidden:true}
				
			],
			pager: '#ptbl_scrap_bahanbaku_out_view',
			rowNum:10,
			rowList:[10,40,100],
			sortname: 'id_scrap_out',
			sortorder: 'desc',
			jsonReader: { repeatitems : false },
			viewrecords: true,
			shrinkToFit: false,
			multiselect: false,
			caption: "Selected Data Out"
		});
		jQuery("#tbl_scrap_bahanbaku_out_view").jqGrid('navGrid','#ptbl_scrap_bahanbaku_out_view',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#tbl_scrap_bahanbaku_out_view").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});	
        
		
	});
		  	
</script>