<div style="height:2px;">
	<input type="hidden" id="id_scrapxxx" value="<?php echo $id_scrap;  ?>" readonly = "readonly" />
	
	<input type="hidden" id="id_scrap_outxx" readonly = "readonly" />
	
	
</div>
<div>
	<table border="0" >
		<tr>
			<td>Tgl Scrap</td><td>:</td><td><input id="date_scrap_in" value="<?php echo $date_scrap;  ?>" style="width:80px;" readonly = "readonly" /></td>
			<td>Part No </td><td>:</td><td><input id="part_no_in" value="<?php echo $part_no;  ?>" style="width:80px;"  readonly = "readonly"/></td>
			<td>Part Name </td><td>:</td><td><input id="part_name_in" value="<?php echo $part_name;  ?>" style="width:160px;"  readonly = "readonly"/></td>
			<td>Qty IN </td><td>:</td><td><input id="qty_in" value="<?php echo $qty;  ?>" style="width:80px;"  readonly = "readonly"/></td>
		</tr>
		
	</table>
	<span><b>DATA PENGELUARAN</b></span>
	<table border="0" >
		<tr>
			<td>No Keluar</td><td>:</td><td><input id="no_scrap"  style="width:90px;"/></td>
			<td>Tgl Keluar</td><td>:</td><td><input id="date_scrap"  style="width:80px;"/></td>
		</tr>
		<tr>
			<td>No Dok</td><td>:</td><td><input id="no_dok_out"  style="width:80px;"/></td>
			<td>Tgl Dok</td><td>:</td><td><input id="tg_dok_out"  style="width:80px;"/></td>
		</tr>
		<tr>
			<td>Qty Out</td><td>:</td><td><input id="qty"  style="width:80px;text-align: right;" /></td>
			<td colspan='3'>
				<div>
					<button id="addscrapout" > add </button>
					<button id="savescrapout" > save </button>
					<button id="delscrapout" > delete </button>
				</div>
			</td>
		</tr>
	</table>
	<hr />
	<table id="tbl_scrap_out_view1"></table> <div id="ptbl_scrap_out_view1"></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: 'yy-mm-dd'
		};
		$("#date_scrap").datepicker(datesetopt);
		$("#tg_dok_out").datepicker(datesetopt);
		
		jQuery("#tbl_scrap_out_view1").jqGrid({
			url:'<?php echo base_url().'inventory/ct_scrap/loaddata_scrap_out'; ?>',
			postData:{idxscx:$("#id_scrapxxx").val()},
			mtype : "post",
			datatype: "json",
			width: 860,
			height:200,
			colNames:[
				'id_scrap_out'
				,'No. Dok Out'
				,'Tgl. Dok Out'
				,'No. Out'
			  ,'Tgl Out'
			  ,'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:'tg_dok_out',index:'tg_dok_out', width:85, hidden:false},
				{name:'no_scrap',index:'no_scrap', 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_out_view1',
			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",
			onSelectRow: function(ids) { 
				 var ret = jQuery("#tbl_scrap_out_view1").jqGrid('getRowData',ids);
				 $("#id_scrap_outxx").val(ret.id_scrap_out);
				 $("#no_dok_out").val(ret.no_dok_out);
				 $("#tg_dok_out").val(ret.tg_dok_out);
				 $("#no_scrap").val(ret.no_scrap);
				 $("#date_scrap").val(ret.date_scrap);
				 $("#qty").val(ret.qty);
				 
			}
		});
		
		
		
		jQuery("#tbl_scrap_out_view1").jqGrid('navGrid','#ptbl_scrap_out_view1',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#tbl_scrap_out_view1").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});	
        
		$("#addscrapout").button().click(function(){
			 $("#id_scrap_outxx").val('');
			 $("#no_dok_out").val('');
			 $("#tg_dok_out").val('');
			 $("#no_scrap").val('');
			 $("#date_scrap").val('');
			 $("#qty").val('');
			 $("#no_scrap").focus();
		
			
		});
		
		$("#savescrapout").button().click(function(){
			if ($("#id_scrap_outxx").val() == ''){
				var cmd = 'ADD'
			} else {
				var cmd = 'UPDATE'
			}
			var form_data = {
				id_scrap_outxx : $("#id_scrap_outxx").val()
				,no_dok_out  : $("#no_dok_out").val().toUpperCase()
				,tg_dok_out  : $("#tg_dok_out").val()
				,no_scrap  : $("#no_scrap").val().toUpperCase()
				,date_scrap  : $("#date_scrap").val()
				,qty:$("#qty").val()
				,id_scrapxxx:$("#id_scrapxxx").val()
				,part_no_in:$("#part_no_in").val()
				,part_name_in:$("#part_name_in").val()
				,command:cmd 
				
			}
			
			$("#dlg_scrapt_out_updatel").dialog( "destroy" );
			$(".dlg_scrapt_out_updatel_cl").remove();
			$("body").append('<div id="dlg_scrapt_out_updatel" title="Warning" class="dlg_scrapt_out_updatel_cl"><p>Apakah anda akan melakukan ' + cmd + ' data scrap ini?!?</p><br /></div>');
			$("#dlg_scrapt_out_updatel").dialog({
				height: 200,
				width: 250,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : "<?php echo base_url().'inventory/ct_scrap/update_scrap_out'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlg_scrapt_out_updatel").dialog("close");
								$('#dlg_scrapt_out_updatel').dialog("destroy"); 
								$(".dlg_scrapt_out_updatel_cl").remove(); 
								$('#tbl_scrap_out_view1').trigger('reloadGrid');
								$("body").append('<div id="dlg_scrapt_out_updatel" title="Warning" class="dlg_scrapt_out_updatel_cl"></div>');
			

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

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

					}
				},
				close : function(){
					$('#dlg_scrapt_out_updatel').dialog("destroy"); 
					$(".dlg_scrapt_out_updatel_cl").remove(); 
					$("body").append('<div id="dlg_scrapt_out_updatel" title="Warning" class="dlg_scrapt_out_updatel_cl"><p>Apakah anda akan melakukan insert part hs ini?!?</p><br /></div>');     
					$('#tbl_scrap_bahanbaku').trigger('reloadGrid');
				},
				open: function(){
					$("body").unblock();
					
				}
			});
		});
		
		$("#delscrapout").button().click(function(){
			var id = jQuery("#tbl_scrap_out_view1").jqGrid('getGridParam','selrow');
			if (id) { 
				var ret = jQuery("#tbl_scrap_out_view1").jqGrid('getRowData',id);
				
			} else {
				alert("Please Select Row");
				
				return false;
			};	
			
			var cmd = 'DELETE'
			
			var form_data = {
				id_scrap_outxx : $("#id_scrap_outxx").val()
				,no_dok_out  : $("#no_dok_out").val().toUpperCase()
				,tg_dok_out  : $("#tg_dok_out").val()
				,no_scrap  : $("#no_scrap").val().toUpperCase()
				,date_scrap  : $("#date_scrap").val()
				,qty:$("#qty").val()
				,id_scrapxxx:$("#id_scrapxxx").val()
				,part_no_in:$("#part_no_in").val()
				,part_name_in:$("#part_name_in").val()
				,command:cmd 
				
			}
			
			$("#dlg_scrapt_out_delete").dialog( "destroy" );
			$(".dlg_scrapt_out_delete_cl").remove();
			$("body").append('<div id="dlg_scrapt_out_delete" title="Warning" class="dlg_scrapt_out_delete_cl"><p>Apakah anda akan melakukan ' + cmd + ' data scrap ini?!?</p><br /></div>');
			$("#dlg_scrapt_out_delete").dialog({
				height: 200,
				width: 250,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : "<?php echo base_url().'inventory/ct_scrap/update_scrap_out'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlg_scrapt_out_delete").dialog("close");
								$('#dlg_scrapt_out_delete').dialog("destroy"); 
								$(".dlg_scrapt_out_delete_cl").remove(); 
								$('#tbl_scrap_out_view1').trigger('reloadGrid');
								$("body").append('<div id="dlg_scrapt_out_delete" title="Warning" class="dlg_scrapt_out_delete_cl"></div>');
			

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

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

					}
				},
				close : function(){
					$('#dlg_scrapt_out_delete').dialog("destroy"); 
					$(".dlg_scrapt_out_delete_cl").remove(); 
					$("body").append('<div id="dlg_scrapt_out_delete" title="Warning" class="dlg_scrapt_out_delete_cl"><p>Apakah anda akan melakukan insert part hs ini?!?</p><br /></div>'); 
					$('#tbl_scrap_bahanbaku').trigger('reloadGrid');
					
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});
			
		});
		
		
	});
		  	
</script>