<div id="container_pasi_scrap_prod" style="height:100%; margin:0px; padding:0px;overflow:'hidden'; border: 0px solid #cd0a0a">
	<div class="pane-header ui-state-active" id="pasi_scrap_prod_bar" >   
	<p style="padding-bottom:10px">FORM INPUT DATA SCRAP PRODUKSI</p> 
   	<span>PERIODE : <input type="text" id="tglawallaporanbarangscrap" size=15 value=""/>  S.D <input type="text" id="tglakhirlaporanbarangscrap" size=15 value=""/> <span style="padding-left:20px;" /></span>
	<span style="padding-left:20px;">Jenis Scrap</span> 
 	<select name="txtjnsscrap" id="txtjnsscrap" style="width:100px" >
		<option value="-"></option>
		<?php 
			
			 $i=0;
			 foreach($jenisscrap as $r){
			
				echo '<option value="'.$r->r1.'">'.$r->r2.'</option>';
				$i++;
			}
		?>
	</select>
 	<input type="text" id="txtjmlscrap" style="background-color:#FFFF00;width:100px"/>
	<span style="padding-left:20px" /><button id='btnhtgscrap' style="background-color:#FFFF00;height:25px" >Procces</button> 
	</div>
<table id="tblscrap"></table> <div id="ptblscrap"></div>
</div> 
	
<script type="text/javascript">
    
    $(document).ready(function(){
		$(window).bind('resize', function() {  
			setTimeout(function(){
				setGridHight($("#tblscrap"),$("#container_pasi_scrap_prod"),$("#pasi_scrap_prod_bar")); 
			},10); 
		});
	
		$("#tglawallaporanbarangscrap").datepicker({ dateFormat: 'dd/mm/yy' });
		$("#tglakhirlaporanbarangscrap").datepicker({ dateFormat: 'dd/mm/yy' });
		
		$("#btnhtgscrap").button().click(function(){
		
			if($("#tglawallaporanbarangscrap").val() == ''){
				alert('Periode Awal Tidak Boleh Kosong');
				return false;
			}

			if($("#tglakhirlaporanbarangscrap").val() == ''){
				alert('Periode Akhir Tidak Boleh Kosong');
				return false;
			}
			if($("#txtjnsscrap").val() == '-'){
				alert('Jenis Scrap Tidak Boleh Kosong');
				return false;
			};
			
			if($("#txtjmlscrap").val() == ''){
				alert('Jumlah Scrap Tidak Boleh Kosong');
				return false;
			}
			
			var form_data = {
				tglawal:$("#tglawallaporanbarangscrap").val(),
				tglakhir:$("#tglakhirlaporanbarangscrap").val(),
				jnsscrap:$("#txtjnsscrap").val(),
				jmlscrap:$("#txtjmlscrap").val(),
			};
			
			$("#dlg_hitungscrap").dialog( "destroy" );
			$(".dlg_hitungscrap_cl").remove();
			$("body").append('<div id="dlg_hitungscrap" title="Warning" class="dlg_hitungscrap_cl"><p>Apakah anda yakin akan memproses data ini?.</div>.</div>');
			$("#dlg_hitungscrap").dialog({
				height: 200,
				width: 250,
				modal: true,
				hide: 'Slide',
				autoOpen: 'false',
				buttons: {
					"CONFIRM": function() {
					$.ajax({
						url : "<?php echo base_url().'pasi_production/ct_scrap/insert_data_scrap'; ?>",
						type : 'POST',
						dataType: 'json',
						data : form_data,
						success: function(msg){
							if (msg.sts == '00'){
								alert(msg.desc);
								$("#dlg_hitungscrap").dialog("close");
								$('#dlg_hitungscrap').dialog("destroy"); 
								$(".dlg_hitungscrap_cl").remove(); 
								$('#tblscrap').trigger('reloadGrid');

 								$("#tglawallaporanbarangscrap").val('');
								$("#tglakhirlaporanbarangscrap").val('');
								$("#txtjnsscrap").val('');
								$("#txtjmlscrap").val('');
								 
	
							} else { 
								alert(msg.sts+msg.desc); 
								$("#dlg_hitungscrap").dialog("close");
								$('#dlg_hitungscrap').dialog("destroy"); 
								$(".dlg_hitungscrap_cl").remove();
								$('#tblscrap').trigger('reloadGrid');
									
							}
						}
					});
				},
					"CANCEL": function() {
						$( "#dlg_hitungscrap" ).dialog( "close" );

					}
				},
				close : function(){
					$('#dlg_hitungscrap').dialog("destroy"); 
					$(".dlg_hitungscrap_cl").remove(); 
					$("body").append('<div id="dlg_hitungscrap" title="Warning" class="dlg_hitungscrap_cl"><p>Apakah anda yakin akan memproses data ini?.</div>.</div>');     
					
				},
				open: function(){
					$("body").unblock();
					
				}
			});
			
		
		});
		
		jQuery("#tblscrap").jqGrid({
			url:'<?php echo base_url().'pasi_production/ct_scrap/loadData'; ?>',
			mtype : "post",
			postData:{'q':'1'},
			datatype: "json",
			
			colNames:['id', 'Tanggal Awal','Tanggal Akhir','Total PVC','Total Copper','Total Wire','Total Kemasan','Create Date','Create By','Update Date','Update By','Status'],
			colModel:[
			
				{name:'id_real_scrap_hdr',index:'id_real_scrap_hdr', width:60, hidden:true},
				{name:'date_start',index:'date_start', width:100},
				{name:'date_end',index:'date_end', width:100},
				{name:'total_pvc',index:'total_pvc', width:130, hidden:false},
				{name:'total_copper',index:'total_copper', width:130,hidden:false},
				{name:'total_wire',index:'total_wire', width:130,hidden:false},
				{name:'total_scrapkemasan',index:'total_scrapkemasan', width:130,hidden:false},
				{name:'create_date',index:'create_date', width:150,hidden:false},
				{name:'create_by',index:'create_by', width:150,hidden:false},
				{name:'update_date',index:'update_date', width:150,hidden:false},	
				{name:'update_by',index:'update_by', width:150,hidden:false},
				{name:'status',index:'status', width:150,hidden:false},
				],
			rowNum:10,
			rowList:[10,20,30],
			pager: '#ptblscrap',
			sortname: 'id_real_scrap_hdr',
			viewrecords: true,
			sortorder: "desc",
			width: '',
			height:100,
			jsonReader: { repeatitems : false },
			caption:"Data Scrap",
			rownumbers: true,
			
			shrinkToFit: false,
			afterInsertRow: function(){
			
			},			
			gridComplete: function(){
				
			},
			
			
		})
			
                        
		jQuery("#tblscrap").jqGrid('navGrid','#ptblscrap',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#tblscrap").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});
		setTimeout(function(){
			setGridHight($("#tblscrap"),$("#container_pasi_scrap_prod"),$("#pasi_scrap_prod_bar")); 
		},100); 

	});
		  	
</script>


	
	