@extends('layout')


@section('content')

<div class="page-header page-header-default">
	<div class="breadcrumb-line">
		<ul class="breadcrumb">
			<li><a href="index.html"><i class="icon-home2 position-left"></i> Inventori</a></li>
			<li class="active">Opname Produksi</li>
		</ul>
	</div>
</div>

<div class="content">
	<div class="panel panel-flat">
		<div class="panel-heading">
			<h5 class="panel-title">Form Opname Produksi</h5>
			<div class="heading-elements">
				<ul class="icons-list">
		      		<li><a data-action="collapse"></a></li>
		      	</ul>
	       	</div>
	    </div>
	    <div class="panel-body">
	    	<form class="form-horizontal" action="{{ url('opnameproduksi/simpan')}}" method="post" autocomplete="off">
	    	<input type="hidden" name="_token" value="{{ csrf_token() }}">
	    	<input type="hidden" name="id_opname" value="{{ $data['header']['id_opname'] }}">
        	<div class="col-sm-6">
        		<div class="form-group">
        			<label class="control-label col-sm-4">Tanggal</label>
        			<div class="col-sm-8">
        				<input class="form-control datepicker" type="text" name="tanggal" value="{{ ($data['header']['tanggal_full'] == '') ? date('d-m-Y'):$data['header']['tanggal_full'] }}" required/>
        			</div>
        		</div>
        		<div class="form-group">
        			<label class="control-label col-sm-4">Lokasi</label>
        			<div class="col-sm-8"> @php $id_lok = $data['header']['id_lokasi'] @endphp
        				<select class="form-control select-search" name="lokasi" id="lokasi">
        					@foreach($data['lokasi'] as $l){
        						<option value="{{ $l->id_lokasi }}" {{ ($id_lok == $l->id_lokasi) ? "selected":"" }} >{{ $l->nama_lokasi }}</option>
        					}
        					@endforeach
        				</select>
        			</div>
        		</div>
        		<div class="form-group">
        			<label class="control-label col-sm-4">Keterangan</label>
        			<div class="col-sm-8">
        				<textarea class="form-control" rows="2" name="keterangan">{{ $data['header']['keterangan'] }}</textarea>
        			</div>
        		</div>
        		
        	</div>
        	<div class="col-sm-6">
				    		
        	</div>

        	
        	<div class="col-sm-12 form-group">
        	<h5 class="panel-title">Detail Barang</h5>
        	<a class="btn bg-success" id="btn_tambah_item">Tambah</a>
        	<div class="col-ms-12">
        	<table class="table table-stripped" id="tabel_data">
	    	<thead>
				<tr>
					<th>No</th>
					<th>Nama Barang</th>
					<th>Proses</th>
					<th>Jumlah</th>
					<th>Corak</th>
					<th>Motif</th>
					<th>Keterangan</th>	
					<th>Aksi</th>			
				</tr>
			</thead>
				<tbody>
					
				</tbody>
	    	</table>
        	</div>
        	
             <div class="col-md-6"></div>
             <br>
             <div class="col-md-12">
             	<a href="{{url('opnameproduksi')}}" class="btn bg-warning-400">Kembali</a>
             <div class="form-group pull-right">
             	<!-- ($data['data']->status == '0') ?'<button class="btn btn-primary" type="submit">Simpan</button>':'' -->
             	
             	<button class="btn btn-primary" type="submit">Simpan</button>
           
             	<!-- <button class="btn btn-primary" type="submit">Simpan</button> -->
             </div>
         </div>
	    </div>
	    </form>
	</div>
</div>

<!---Modal--->
<div class="modal fade" id="exampleModal" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
	<div class="modal-dialog modal-lg" role="document">
	    <div class="modal-content">
	    	<div class="modal-header">
	    		<h5 class="modal-title" id="exampleModalLabel">Data</h5>
	    		<button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">&times;</span></button>
	      	</div>
	      	<div class="modal-body">
	      		<form class="form-horizontal" autocomplete="off">
	      			<input type="hidden" name="popup_id">
	      			<input type="hidden" name="popup_idtabel">
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Pegawai</label>
	      				<div class="col-sm-8">
	      					<select class="form-control select-search" name="popup_pegawai" id="popup_pegawai">
	      						<option value=""> -- Tidak Ada -- </option>
	      						@php
	      						      						
	      						foreach($data['pegawai'] as $g){
	      						@endphp
	      							<option value="{{ $g->id_pegawai }}" nama="{{ $g->nama_pegawai }}">{{ $g->nama_pegawai }}</option>
	      						@php
	      						}
	      						@endphp
	      					</select>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Rekanan</label>
	      				<div class="col-sm-8">
	      					<select class="form-control select-search" name="popup_rekanan" id="popup_rekanan">
	      						<option value=""> -- Tidak Ada -- </option>
	      						@foreach($data['rekanan'] as $g){
	      							<option value="{{ $g->id_rekanan }}" nama="{{ $g->nama }}">{{ $g->nama." - ".$g->nama_kelompok }}</option>
	      						}
	      						@endforeach
	      					</select>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Mesin</label>
	      				<div class="col-sm-8">
	      					<select class="form-control select-search" name="popup_mesin" id="popup_mesin">
	      						<option value=""> -- Tidak Ada -- </option>
	      						@foreach($data['mesin'] as $g){
	      							<option value="{{ $g->id_mesin }}" nama="{{ $g->nama }}">{{ $g->nama }}</option>
	      						}
	      						@endforeach
	      					</select>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Proses</label>
	      				<div class="col-sm-8">
	      					<select class="form-control select-search" name="popup_proses" id="popup_proses">
	      						<option value=""> -- Pilih Proses -- </option>
	      						@foreach($data['proses'] as $g){
	      							<option value="{{ $g->id_proses }}" nama="{{ $g->nama_proses }}">{{ $g->nama_proses }}</option>
	      						}
	      						@endforeach
	      					</select>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Nama Barang</label>
	      				<div class="col-sm-8">
	      					<select class="form-control select-search" name="popup_barang" id="popup_barang">

	      					</select>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Jumlah Stok</label>
	      				<div class="col-sm-8">
	      					<label class="control-label" id="popup_stok"></label>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Selisih</label>
	      				<div class="col-sm-8">
	      					<label class="control-label" id="popup_selisih"></label>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Jumlah</label>
	      				<div class="col-sm-8">
	      					<input type="text" class="form-control number-only" name="popup_jumlah" id="popup_jumlah"></label>
	      					<p class="help-block pull-right" id="help_jumlah"></p>
	      				</div>
	      			</div> 
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Keterangan</label>
	      				<div class="col-sm-8">
	      					<textarea class="form-control" rows="2" name="popup_ket" id="popup_ket"></textarea>
	      				</div>
	      			</div>
	      		</form>
	      	</div>
	      	<div class="modal-footer">
	        	<button type="button" class="btn btn-primary" id="btn_popup_simpan">Simpan</button>
	      	</div>
	    </div>
	</div>
</div>

<input type="hidden" id="store_barang" name="jum_data" value="">
<input type="hidden" id="store_edit" name="store_edit" value="0">


<script type="text/javascript">
	$("#btn_tambah_item").click(function(){
		$("[name=popup_id]").val('');
		$("[name=popup_idtabel]").val('');
		$("[name=popup_proses]").val('').trigger('change');
		$("[name=popup_barang]").html('');
		$("#popup_stok").text('');
		$("#popup_selisih").text('');
		$("[name=popup_jumlah]").val('');
		$("[name=popup_ket]").val('');
		$("[name=jum_data]").val('0');
		$("#help_jumlah").text('');
		$("[name=popup_pegawai]").val('1').trigger("change");
		$("#popup_rekanan").val('').trigger("change");
		$("#popup_mesin").val('').trigger("change");
		$("#store_edit").val('0');

	//	readonly("#popup_jumlah", false);
	//	readonly("#popup_ket", false);
		$("#btn_popup_simpan").show();

		$("#exampleModal").modal('show');

		stok_barang = 0;
		selisih = 0;
	})
	var table;
	var tb_no = parseInt(10000);
	var id_opname = $("[name=id_opname]").val();
	var stok_barang = '0';
	var selisih = 0;

	var status_barang = 0;

	var value = "";
	var sisa = "";
	var id_barang = "";
	var id_gudang = "";
	var id_proses = "";
	var id_komposisi = "";
	var id_corak = "";
	var id_motif = "";
	var id_workorder = "";
	var id_kualitas = "";
	var id_kualitas_dudul = "";
	var id_label = "";
	var id_kemasan = "";
	var id_kemasansatuan = "";
	var id_kemasansepuluh = "";
	var id_kemasanseratus = "";
	var id_cap = "";
	var id_kualitas_proses = "";
	var id_kualitas_periksa = "";
	var id_perubahansatuan = "";
	var jumlah_rencana = "";
	var id_satuan_hasil = "";
	var id_proses_sekarang = "";
	var jumlah = "";
	var selisih = "";
	var sisa = "";
	var keterangan = "";
	var id_satuan = "";
	var id_pegawai = "";
	var id_rekanan = "";
	var id_mesin = "";

	$(document).ready(function(){
		table = $("#tabel_data").DataTable({
			"paging": false
		});
		table.on( 'order.dt search.dt', function () {
            table.column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {
                cell.innerHTML = i+1;
            } );
        } ).draw();

		if(id_opname != ''){
			get_edit(id_opname);
		}

		$("#popup_pegawai").val(1).trigger("change");
		$("#popup_rekanan").val('').trigger("change");
		$("#popup_mesin").val('').trigger("change");

		$("[name=popup_pegawai]").change(function(){
		if($(this).val() != ''){
			disabled('[name=popup_rekanan]', true);
			$('[name=popup_rekanan]').attr('required', false);
			disabled('[name=popup_mesin]', true);
			$('[name=popup_mesin]').attr('required', false);
		}else{
			disabled('[name=popup_rekanan]', false);
			$('[name=popup_rekanan]').attr('required', true);
			disabled('[name=popup_mesin]', false);
			$('[name=popup_mesin]').attr('required', true);
		}
	})

	$("[name=popup_rekanan]").change(function(){
		if($(this).val() != ''){
			disabled('[name=popup_pegawai]', true);
			$('[name=popup_pegawai]').attr('required', false);
			disabled('[name=popup_mesin]', true);
			$('[name=popup_mesin]').attr('required', false);
		}else{
			disabled('[name=popup_pegawai]', false);
			$('[name=popup_pegawai]').attr('required', true);
			disabled('[name=popup_mesin]', false);
			$('[name=popup_mesin]').attr('required', true);
		}
	})

	$("[name=popup_mesin]").change(function(){
		if($(this).val() != ''){
			disabled('[name=popup_pegawai]', true);
			$('[name=popup_pegawai]').attr('required', false);
			disabled('[name=popup_rekanan]', true);
			$('[name=popup_rekanan]').attr('required', false);
		}else{
			disabled('[name=popup_pegawai]', false);
			$('[name=popup_pegawai]').attr('required', true);
			disabled('[name=popup_rekanan]', false);
			$('[name=popup_rekanan]').attr('required', true);
		}
	})

	})

	$("#popup_proses").change(function(){
		clear_status();
		var id_proses = $(this).val();
		var id_pegawai = $("#popup_pegawai").val();
		var id_rekanan = $("#popup_rekanan").val();
		var id_mesin = $("#popup_mesin").val();
		if(id_proses != ''){
			$.ajax({
				url : '{{ url('opnameproduksi/get_barang') }}',
				dataType : 'json',
				data : { id_proses : id_proses, jenis : 0 , id_pegawai : id_pegawai, id_rekanan : id_rekanan, id_mesin : id_mesin},
				success : function(respon){
					if(respon.length > 0){
						$("#popup_barang").html("");
						$("#popup_barang").append('<option value="">-- Pilih Barang --</option>');
						for( i in respon ){
							$("#popup_barang").append('<option value="'+respon[i].id+'" sisa="'+respon[i].sisa+'" id_barang="'+respon[i].id_barang+'" nama_barang="'+respon[i].nama_barang+'" id_gudang="'+respon[i].id_gudang+'" id_proses="'+respon[i].id_proses+'" nama_proses="'+respon[i].nama_proses+'" id_komposisi="'+respon[i].id_warna+'" inisial_komposisi="'+respon[i].inisial_komposisi+'" id_corak="'+respon[i].id_corak+'" nama_corak="'+respon[i].nama_corak+'" id_motif="'+respon[i].id_motif+'" nama_motif="'+respon[i].nama_motif+'" id_workorder="'+respon[i].id_workorder_barang+'" nama_workorder="'+respon[i].no_workorder_barang+'" id_kualitas="'+respon[i].id_kualitas+'" id_kualitas_dudul="'+respon[i].id_kualitas_dudul+'" id_label="'+respon[i].id_label+'" id_kemasan="'+respon[i].id_kemasan+'" id_kemasansatuan="'+respon[i].id_kemasansatuan+'" id_kemasansepuluh="'+respon[i].id_kemasansepuluh+'" id_kemasanseratus="'+respon[i].id_kemasanseratus+'" id_cap="'+respon[i].id_cap+'" id_kualitas_proses="'+respon[i].id_kualitas_proses+'" id_kualitas_periksa="'+respon[i].id_kualitas_periksa+'" id_perubahansatuan="'+respon[i].id_perubahansatuan+'" jumlah_rencana="'+respon[i].jumlah_rencana+'" id_satuan_hasil="'+respon[i].id_satuan_hasil+'" inisial_satuan="'+respon[i].inisial_satuan+'" id_proses_sekarang="'+respon[i].id_proses_sekarang+'" proses_sekarang="'+respon[i].nama_proses_sekarang+'" id_satuan="'+respon[i].id_satuan+'" id_pegawai="'+respon[i].id_pegawai+'" id_rekanan="'+respon[i].id_rekanan+'" id_mesin="'+respon[i].id_mesin+'"> '+respon[i].concat_nama+' </option>');	
						}
					}else{
						$("#popup_barang").html("");
						$("#popup_barang").append('<option value=""> Data Kosong </option>');
					}
				},
				complete: function(res){
					if($("#store_edit").val() != 0){
						test_lanjutan($("#store_edit").val());
					}
				}
			})
		}else{
			$("[name=popup_barang]").html('');
		}
		
	})

	$("#popup_barang").change(function(){
		clear_status();
		var id = $(this).val();
		var id_data = $("[name=popup_id]").val();


		var value = $("#popup_barang").val();
		var sisa = $("#popup_barang :selected").attr('sisa'); 
		var id_barang = $("#popup_barang :selected").attr('id_barang'); 
		var nama_barang = $("#popup_barang :selected").attr('nama_barang');
		var id_gudang = $("#popup_barang :selected").attr('id_gudang');
		var id_proses = $("#popup_barang :selected").attr('id_proses');
		var nama_proses = $("#popup_barang :selected").attr('nama_proses');
		var id_komposisi = $("#popup_barang :selected").attr('id_komposisi');
		var inisial_komposisi = $("#popup_barang :selected").attr('inisial_komposisi');
		var id_corak = $("#popup_barang :selected").attr('id_corak');
		var nama_corak = $("#popup_barang :selected").attr('nama_corak');
		var id_motif = $("#popup_barang :selected").attr('id_motif');
		var nama_motif = $("#popup_barang :selected").attr('nama_motif');
		var id_workorder = $("#popup_barang :selected").attr('id_workorder');
		var nama_workorder = $("#popup_barang :selected").attr('nama_workorder');
		var id_kualitas = $("#popup_barang :selected").attr('id_kualitas');
		var id_kualitas_dudul = $("#popup_barang :selected").attr('id_kualitas_dudul');
		var id_label = $("#popup_barang :selected").attr('id_label');
		var id_kemasan = $("#popup_barang :selected").attr('id_kemasan');
		var id_kemasansatuan = $("#popup_barang :selected").attr('id_kemasansatuan');
		var id_kemasansepuluh = $("#popup_barang :selected").attr('id_kemasansepuluh');
		var id_kemasanseratus = $("#popup_barang :selected").attr('id_kemasanseratus');
		var id_cap = $("#popup_barang :selected").attr('id_cap');
		var id_kualitas_proses = $("#popup_barang :selected").attr('id_kualitas_proses');
		var id_kualitas_periksa = $("#popup_barang :selected").attr('id_kualitas_periksa');
		var id_perubahansatuan = $("#popup_barang :selected").attr('id_perubahansatuan');
		var jumlah_rencana = $("#popup_barang :selected").attr('jumlah_rencana');
		var id_satuan_hasil = $("#popup_barang :selected").attr('id_satuan_hasil');
		var inisial_satuan = $("#popup_barang :selected").attr('inisial_satuan');
		var id_proses_sekarang = $("#popup_barang :selected").attr('id_proses_sekarang');
		var nama_proses_sekarang = $("#popup_barang :selected").attr('proses_sekarang');
		var id_satuan = $("#popup_barang :selected").attr('id_satuan');
		var id_pegawai = $("#popup_barang :selected").attr('id_pegawai');
		var id_rekanan = $("#popup_barang :selected").attr('id_rekanan');
		var id_mesin = $("#popup_barang :selected").attr('id_mesin');

		stok_barang = $("#popup_barang :selected").attr('sisa');

		var total = parseFloat(0);

		$('input[id^="tabel_jumlah"]').each(function(){
			var val = ($(this).attr('id'));
			val = val.replace('tabel_jumlah', '');

			if($("#tabel_idbarang"+val).val() == id_barang && $("#tabel_idproses"+val).val() == id_proses && $("#tabel_idgudang"+val).val() == id_gudang && $("#tabel_idkomposisi"+val).val() == id_komposisi && $("#tabel_idcorak"+val).val() == id_corak && $("#tabel_idmotif"+val).val() == id_motif && $("#tabel_idworkorder"+val).val() == id_workorder && $("#tabel_idkualitas"+val).val() == id_kualitas && $("#tabel_idkualitasdudul"+val).val() == id_kualitas_dudul && $("#tabel_idlabel"+val).val() == id_label && $("#tabel_idkemasan"+val).val() == id_kemasan && $("#tabel_idkemasansatuan"+val).val() == id_kemasansatuan && $("#tabel_idkemasansepuluh"+val).val() == id_kemasansepuluh && $("#tabel_idkemasanseratus"+val).val() == id_kemasanseratus && $("#tabel_idcap"+val).val() == id_cap && $("#tabel_idkualitasproses"+val).val() == id_kualitas_proses && $("#tabel_idkualitasperiksa"+val).val() == id_kualitas_periksa && $("#tabel_idperubahansatuan"+val).val() == id_perubahansatuan && $("#tabel_rencanajumlah"+val).val() == jumlah_rencana && $("#tabel_idsatuanhasil"+val).val() == id_satuan_hasil && $("#tabel_idprosessekarang"+val).val() == id_proses_sekarang && $("#tabel_idpegawai"+val).val() == id_pegawai && $("#tabel_idrekanan"+val).val() == id_rekanan && $("#tabel_idmesin"+val).val() == id_mesin){
					// var jum = $("#tabel_jumlah"+val).val();
					// jum = parseFloat(jum);
					// stok_barang = parseFloat(stok_barang);
				 //    total += parseFloat(jum);
				//    console.log("Satuan "+jum+" | Stok Barang "+stok_barang+"\n");
				//	total = (jum-stok_barang)+stok_barang;
					
					if(id_data == ''){
						$("#popup_stok").text("Barang Sudah Diopname");
						// readonly("#popup_jumlah", true);
						// readonly("#popup_ket", true);
						$("#btn_popup_simpan").hide();
						status_barang = 1;
					}else{
						status_barang = 0;
						// readonly("#popup_jumlah", false);
						// readonly("#popup_ket", false);
						$("#btn_popup_simpan").show();
					}
			}
		})

		if(id != '' && status_barang == 0){
			// var nilai_sekarang = $("#popup_jumlah").val();

			// if(total > 0 && id_data == ''){
			// 	stok_barang = total;
			// }else if(total > 0 && id_data != ''){
			// 	if(total == nilai_sekarang){
			// 		stok_barang = stok_barang;
			// 	}else{
			// 		stok_barang = total-nilai_sekarang;
			// 	}
			// }

			stok_barang = $("#popup_barang :selected").attr('sisa');

		//	console.log(" Total "+total+" | Stok Barang "+stok_barang+" | Nilai Sekaran "+nilai_sekarang);
			var nama_sat = $("#popup_barang :selected").attr('inisial_satuan');
			$("#popup_stok").text(stok_barang+" "+nama_sat);
		}else{

		}


	})

	$("#popup_jumlah").keyup(function(){
		var sekarang = $("#popup_jumlah").val();
		if(sekarang == ''){
			sekarang = 0;
		}
		selisih =  sekarang - stok_barang;

		console.log(sekarang+" - "+stok_barang+" - "+selisih);
		
		$("#popup_selisih").text(format_angka(selisih));
		$("#help_jumlah").text(format_angka(sekarang));
	})

	$("#btn_popup_simpan").click(function(){
		var jumlah_ = $("#popup_jumlah").val();
		var id_ = $("[name=popup_id]").val();
		var keterangan_ = $("[name=popup_ket]").val();

		var value_ = $("#popup_barang").val();
		var sisa_ = $("#popup_barang :selected").attr('sisa'); 
		var id_barang_ = $("#popup_barang :selected").attr('id_barang'); 
		var nama_barang_ = $("#popup_barang :selected").attr('nama_barang');
		var id_gudang_ = $("#popup_barang :selected").attr('id_gudang');
		var id_proses_ = $("#popup_barang :selected").attr('id_proses');
		var nama_proses_ = $("#popup_barang :selected").attr('nama_proses');
		var id_komposisi_ = $("#popup_barang :selected").attr('id_komposisi');
		var inisial_komposisi_ = $("#popup_barang :selected").attr('inisial_komposisi');
		var id_corak_ = $("#popup_barang :selected").attr('id_corak');
		var nama_corak_ = $("#popup_barang :selected").attr('nama_corak');
		var id_motif_ = $("#popup_barang :selected").attr('id_motif');
		var nama_motif_ = $("#popup_barang :selected").attr('nama_motif');
		var id_workorder_ = $("#popup_barang :selected").attr('id_workorder');
		var nama_workorder_ = $("#popup_barang :selected").attr('nama_workorder');
		var id_kualitas_ = $("#popup_barang :selected").attr('id_kualitas');
		var id_kualitas_dudul_ = $("#popup_barang :selected").attr('id_kualitas_dudul');
		var id_label_ = $("#popup_barang :selected").attr('id_label');
		var id_kemasan_ = $("#popup_barang :selected").attr('id_kemasan');
		var id_kemasansatuan_ = $("#popup_barang :selected").attr('id_kemasansatuan');
		var id_kemasansepuluh_ = $("#popup_barang :selected").attr('id_kemasansepuluh');
		var id_kemasanseratus_ = $("#popup_barang :selected").attr('id_kemasanseratus');
		var id_cap_ = $("#popup_barang :selected").attr('id_cap');
		var id_kualitas_proses_ = $("#popup_barang :selected").attr('id_kualitas_proses');
		var id_kualitas_periksa_ = $("#popup_barang :selected").attr('id_kualitas_periksa');
		var id_perubahansatuan_ = $("#popup_barang :selected").attr('id_perubahansatuan');
		var jumlah_rencana_ = $("#popup_barang :selected").attr('jumlah_rencana');
		var id_satuan_hasil_ = $("#popup_barang :selected").attr('id_satuan_hasil');
		var inisial_satuan_ = $("#popup_barang :selected").attr('inisial_satuan');
		var id_proses_sekarang_ = $("#popup_barang :selected").attr('id_proses_sekarang');
		var nama_proses_sekarang_ = $("#popup_barang :selected").attr('proses_sekarang');
		var id_satuan_ = $("#popup_barang :selected").attr('id_satuan');
		var id_pegawai_ = $("#popup_barang :selected").attr('id_pegawai');
		var id_rekanan_ = $("#popup_barang :selected").attr('id_rekanan');
		var id_mesin_ = $("#popup_barang :selected").attr('id_mesin');

		if(jumlah_ != ''){
			if(id_ == ''){
				table.row.add(['<div><center></center></div>',
					'<div id="list_namabarang'+tb_no+'">'+nama_barang_+'</div>',
					'<div id="list_namaproses'+tb_no+'">'+nama_proses_sekarang_+'</div>',
					'<div id="list_jumlah'+tb_no+'">'+format_angka(jumlah_)+'</div>',
					'<div id="list_namacorak'+tb_no+'">'+nama_corak_+'</div>',
					'<div id="list_namamotif'+tb_no+'">'+nama_motif_+'</div>',
					'<div id="list_keterangan'+tb_no+'">'+keterangan_+'</div>',
					'<div class="btn-group"><button type="button" class="btn bg-warning-400 btn-xs" onclick="edit_table('+tb_no+')"><i class="icon-pencil"></i> </button><button class="btn bg-danger-800 btn-xs" type="button" onclick="hapus_table($(this))"><i class="icon-eraser"></i></button></div>'+
					'<input type="hidden" id="tabel_id'+tb_no+'" name="tabel_id[]" value="">'+
					'<input type="hidden" id="tabel_idlist'+tb_no+'" name="tabel_idlist[]" value="'+value_+'">'+
					'<input type="hidden" id="tabel_idbarang'+tb_no+'" name="tabel_idbarang[]" value="'+id_barang_+'">'+
					'<input type="hidden" id="tabel_idgudang'+tb_no+'" name="tabel_idgudang[]" value="'+id_gudang_+'">'+
					'<input type="hidden" id="tabel_idproses'+tb_no+'" name="tabel_idproses[]" value="'+id_proses_+'">'+
					'<input type="hidden" id="tabel_idkomposisi'+tb_no+'" name="tabel_idkomposisi[]" value="'+id_komposisi_+'">'+
					'<input type="hidden" id="tabel_idcorak'+tb_no+'" name="tabel_idcorak[]" value="'+id_corak_+'">'+
					'<input type="hidden" id="tabel_idmotif'+tb_no+'" name="tabel_idmotif[]" value="'+id_motif_+'">'+
					'<input type="hidden" id="tabel_idworkorder'+tb_no+'" name="tabel_idworkorder[]" value="'+id_workorder_+'">'+
					'<input type="hidden" id="tabel_idkualitas'+tb_no+'" name="tabel_idkualitas[]" value="'+id_kualitas_+'">'+
					'<input type="hidden" id="tabel_idkualitasdudul'+tb_no+'" name="tabel_idkualitasdudul[]" value="'+id_kualitas_dudul_+'">'+
					'<input type="hidden" id="tabel_idlabel'+tb_no+'" name="tabel_idlabel[]" value="'+id_label_+'">'+
					'<input type="hidden" id="tabel_idkemasan'+tb_no+'" name="tabel_idkemasan[]" value="'+id_kemasan_+'">'+
					'<input type="hidden" id="tabel_idkemasansatuan'+tb_no+'" name="tabel_idkemasansatuan[]" value="'+id_kemasansatuan_+'">'+
					'<input type="hidden" id="tabel_idkemasansepuluh'+tb_no+'" name="tabel_idkemasansepuluh[]" value="'+id_kemasansepuluh_+'">'+
					'<input type="hidden" id="tabel_idkemasanseratus'+tb_no+'" name="tabel_idkemasanseratus[]" value="'+id_kemasanseratus_+'">'+
					'<input type="hidden" id="tabel_idcap'+tb_no+'" name="tabel_idcap[]" value="'+id_cap_+'">'+
					'<input type="hidden" id="tabel_idkualitasproses'+tb_no+'" name="tabel_idkualitasproses[]" value="'+id_kualitas_proses_+'">'+
					'<input type="hidden" id="tabel_idkualitasperiksa'+tb_no+'" name="tabel_idkualitasperiksa[]" value="'+id_kualitas_periksa_+'">'+
					'<input type="hidden" id="tabel_idperubahansatuan'+tb_no+'" name="tabel_idperubahansatuan[]" value="'+id_perubahansatuan_+'">'+
					'<input type="hidden" id="tabel_rencanajumlah'+tb_no+'" name="tabel_rencanajumlah[]" value="'+jumlah_rencana_+'">'+
					'<input type="hidden" id="tabel_idprosessekarang'+tb_no+'" name="tabel_idprosessekarang[]" value="'+id_proses_sekarang_+'">'+
					'<input type="hidden" id="tabel_keterangan'+tb_no+'" name="tabel_keterangan[]" value="'+keterangan_+'">'+
					'<input type="hidden" id="tabel_jumlah'+tb_no+'" name="tabel_jumlah[]" value="'+jumlah_+'">'+
					'<input type="hidden" id="tabel_selisih'+tb_no+'" name="tabel_selisih[]" value="'+selisih+'">'+
					'<input type="hidden" id="tabel_sisa'+tb_no+'" name="tabel_sisa[]" value="'+sisa_+'">'+
					'<input type="hidden" id="tabel_idsatuanhasil'+tb_no+'" name="tabel_idsatuanhasil[]" value="'+id_satuan_hasil_+'">'+
					'<input type="hidden" id="tabel_idsatuan'+tb_no+'" name="tabel_idsatuan[]" value="'+id_satuan_+'">'+
					'<input type="hidden" id="tabel_idpegawai'+tb_no+'" name="tabel_idpegawai[]" value="'+id_pegawai_+'">'+
					'<input type="hidden" id="tabel_idrekanan'+tb_no+'" name="tabel_idrekanan[]" value="'+id_rekanan_+'">'+
					'<input type="hidden" id="tabel_idmesin'+tb_no+'" name="tabel_idmesin[]" value="'+id_mesin_+'">'
					]).draw(false);

				tb_no++;
				
			}else{
				$("#list_namabarang"+id_).text(nama_barang_);
				$("#list_namaproses"+id_).text(nama_proses_sekarang_);
				$("#list_jumlah"+id_).text(format_angka(jumlah_));
				$("#list_namacorak"+id_).text(nama_corak_);
				$("#list_namamotif"+id_).text(nama_motif_);
				$("#list_keterangan"+id_).text(keterangan_);

				
				$("#tabel_idlist"+id_).val(value_);
				$("#tabel_idbarang"+id_).val(id_barang_);
				$("#tabel_idgudang"+id_).val(id_gudang_);
				$("#tabel_idproses"+id_).val(id_proses_);
				$("#tabel_idkomposisi"+id_).val(id_komposisi_);
				$("#tabel_idcorak"+id_).val(id_corak_);
				$("#tabel_idmotif"+id_).val(id_motif_);
				$("#tabel_idworkorder"+id_).val(id_workorder_);
				$("#tabel_idkualitas"+id_).val(id_kualitas_);
				$("#tabel_idkualitasdudul"+id_).val(id_kualitas_dudul_);
				$("#tabel_idlabel"+id_).val(id_label_);
				$("#tabel_idkemasan"+id_).val(id_kemasan_);
				$("#tabel_idkemasansatuan"+id_).val(id_kemasansatuan_);
				$("#tabel_idkemasansepuluh"+id_).val(id_kemasansepuluh_);
				$("#tabel_idkemasanseratus"+id_).val(id_kemasanseratus_);
				$("#tabel_idcap"+id_).val(id_cap_);
				$("#tabel_idkualitasproses"+id_).val(id_kualitas_proses_);
				$("#tabel_idkualitasperiksa"+id_).val(id_kualitas_periksa_);
				$("#tabel_idperubahansatuan"+id_).val(id_perubahansatuan_);
				$("#tabel_rencanajumlah"+id_).val(jumlah_rencana_);
				$("#tabel_idprosessekarang"+id_).val(id_proses_sekarang_);
				$("#tabel_keterangan"+id_).val(keterangan_);
				$("#tabel_jumlah"+id_).val(jumlah_);
				$("#tabel_sisa"+id_).val(sisa);
				$("#tabel_selisih"+id_).val(selisih);
				$("#tabel_idsatuanhasil"+id_).val(id_satuan_hasil_);
				$("#tabel_idsatuan"+id_).val(id_satuan_);
				$("#tabel_idpegawai"+id_).val(id_pegawai_);
				$("#tabel_idrekanan"+id_).val(id_rekanan_);
				$("#tabel_idmesin"+id_).val(id_mesin_);
			}

			$("#exampleModal").modal('hide');
		}
	})

	function edit_table(id){
		var id_pegawai = $("#tabel_idpegawai"+id).val();
		var id_rekanan = $("#tabel_idrekanan"+id).val();
		var id_mesin = $("#tabel_idmesin"+id).val();
		var id_proses_sekarang = $("#tabel_idprosessekarang"+id).val();
		var id_ = $("#tabel_id"+id).val();
		$("[name=popup_id]").val(id);

		get_table(id);
		
		console.log(id_proses_sekarang);

		var FunctionOne = function () {
			var r = $.Deferred();
			
			$("#popup_pegawai").val(id_pegawai).trigger('change');
			$("#popup_rekanan").val(id_rekanan).trigger('change');
			$("#popup_mesin").val(id_mesin).trigger('change');
			$("#popup_proses").val(id_proses_sekarang).trigger('change');
			$("#store_edit").val(id);

			setTimeout(function () {
					r.resolve();
				}, 4000);
			return r;
		};

		var FunctionTwo = function () {
			var r = $.Deferred();
			console.log(id_ + " | " + id_opname);
			if(id_ != '' && id_opname != ''){
				$.ajax({
					url : '{{ url('opnameproduksi/get_barang') }}',
					dataType : 'json',
					data : { id_proses : id_proses, jenis : 1 , id_pegawai : id_pegawai, id_rekanan : id_rekanan, id_mesin : id_mesin},
					success : function(respon){
						$("#popup_barang").html("");

						var test =	$("[name=popup_barang]").find("option[value='"+ value +"'] [sisa='"+ sisa +"'] [id_barang='"+ id_barang +"'] [nama_barang='"+ nama_barang +"'] [id_gudang='"+ id_gudang +"'] [id_proses='"+ id_proses +"'] [nama_proses='"+ nama_proses +"'] [id_komposisi='"+ id_komposisi +"'] [inisial_komposisi='"+ inisial_komposisi +"'] [id_corak='"+ id_corak +"'] [nama_corak='"+ nama_corak +"'] [id_motif='"+ id_motif +"'] [nama_motif='"+ nama_motif +"'] [id_workorder='"+ id_workorder +"'] [nama_workorder='"+ nama_workorder +"'] [id_kualitas='"+ id_kualitas +"'] [id_kualitas_dudul='"+ id_kualitas_dudul +"'] [id_label='"+ id_label +"'] [id_kemasan='"+ id_kemasan +"'] [id_kemasansatuan='"+ id_kemasansatuan +"'] [id_kemasansepuluh='"+ id_kemasansepuluh +"'] [id_kemasanseratus='"+ id_kemasanseratus +"'] [id_cap='"+ id_cap +"'] [id_kualitas_proses='"+ id_kualitas_proses +"'] [id_kualitas_periksa='"+ id_kualitas_periksa +"'] [id_perubahansatuan='"+ id_perubahansatuan +"'] [jumlah_rencana='"+ jumlah_rencana +"'] [id_satuan_hasil='"+ id_satuan_hasil +"'] [inisial_satuan='"+ inisial_satuan +"'] [id_proses_sekarang='"+ id_proses_sekarang +"'] [proses_sekarang='"+ proses_sekarang +"'] [proses_sekarang='"+ proses_sekarang +"'] [id_pegawai='"+ id_pegawai +"'] [id_rekanan='"+ id_rekanan +"'] [id_mesin='"+ id_mesin +"']");

					//	console.log(test);
					},
					complete: function(res){
						FunctionLast();
					}
				})
			}else{
				FunctionLast();
			}
			
			setTimeout(function () {
					r.resolve();
				}, 3000);
			return r;
		};

		var FunctionLast = function () {
			var r = $.Deferred();
			var test = $("[name=popup_barang]").find("option[id_barang='"+ id_barang +"'][id_proses='"+ id_proses +"'][id_gudang='"+ id_gudang +"'][id_komposisi='"+ id_komposisi +"'][id_corak='"+ id_corak +"'][id_motif='"+ id_motif +"'][id_workorder='"+ id_workorder +"'][id_kualitas='"+ id_kualitas +"'][id_kualitas_dudul='"+ id_kualitas_dudul +"'][id_label='"+ id_label +"'][id_kemasan='"+ id_kemasan +"'][id_kemasansatuan='"+ id_kemasansatuan +"'][id_kemasansepuluh='"+ id_kemasansepuluh +"'][id_kemasanseratus='"+ id_kemasanseratus +"'][id_cap='"+ id_cap +"'][id_kualitas_proses='"+ id_kualitas_proses +"'][id_kualitas_periksa='"+ id_kualitas_periksa +"'][id_perubahansatuan='"+ id_perubahansatuan +"'][jumlah_rencana='"+ jumlah_rencana +"'][id_satuan_hasil='"+ id_satuan_hasil +"'][id_proses_sekarang='"+ id_proses_sekarang +"'][id_pegawai='"+ id_pegawai +"'] [id_rekanan='"+ id_rekanan +"'] [id_mesin='"+ id_mesin +"'] ");

			//	$("[name=popup_barang]").find("option[id_barang='"+ id_barang +"']  [id_gudang='"+ id_gudang +"'] [id_proses='"+ id_proses +"'] [id_komposisi='"+ id_komposisi +"'] [id_corak='"+ id_corak +"']  [id_motif='"+ id_motif +"']  [id_workorder='"+ id_workorder +"']  [id_kualitas='"+ id_kualitas +"'] [id_kualitas_dudul='"+ id_kualitas_dudul +"'] [id_label='"+ id_label +"'] [id_kemasan='"+ id_kemasan +"'] [id_kemasansatuan='"+ id_kemasansatuan +"'] [id_kemasansepuluh='"+ id_kemasansepuluh +"'] [id_kemasanseratus='"+ id_kemasanseratus +"'] [id_cap='"+ id_cap +"'] [id_kualitas_proses='"+ id_kualitas_proses +"'] [id_kualitas_periksa='"+ id_kualitas_periksa +"'] [id_perubahansatuan='"+ id_perubahansatuan +"'] [jumlah_rencana='"+ jumlah_rencana +"'] [id_satuan_hasil='"+ id_satuan_hasil +"'] [id_proses_sekarang='"+ id_proses_sekarang +"'] ").prop('selected', true).trigger('change');


			//	console.log("Value -> "+value+" - Sisa -> "+sisa+" - id_barang -> "+id_barang+" - id_gudang -> "+id_gudang+" - id_proses -> "+id_proses+" - id_komposisi -> "+id_komposisi+" - id_corak -> "+id_corak+" - id_motif -> "+id_motif+" - id_workorder -> "+id_workorder+" - id_kualitas -> "+id_kualitas+" - id_kualitas_dudul -> "+id_kualitas_dudul+" - id_label -> "+id_label+" - id_kemasan -> "+id_kemasan+" - id_kemasansatuan -> "+id_kemasansatuan+" - id_kemasansepuluh -> "+id_kemasansepuluh+" - id_kemasanseratus -> "+id_kemasanseratus+" - id_cap -> "+id_cap+" - id_kualitas_proses -> "+id_kualitas_proses+" - id_kualitas_periksa -> "+id_kualitas_periksa+" - id_perubahansatuan -> "+id_perubahansatuan+" - jumlah_rencana -> "+jumlah_rencana+" - id_satuan_hasil -> "+id_satuan_hasil+" - id_proses_sekarang -> "+id_proses_sekarang);
			//console.log(test.length);
			test.prop('selected', true).trigger('change');
			
			$("#popup_stok").text(sisa);
			$("#popup_selisih").text(selisih);
			$("#popup_jumlah").val(jumlah);
			$("#help_jumlah").text(format_angka(jumlah));
			$("#keterangan").text(keterangan);
			
			setTimeout(function () {
					r.resolve();
				}, 3000);
			return r;
		};

		FunctionOne();

		// $("#exampleModal").modal('show');
	}

	function test_lanjutan(id){
		var id_pegawai = $("#tabel_idpegawai"+id).val();
		var id_rekanan = $("#tabel_idrekanan"+id).val();
		var id_mesin = $("#tabel_idmesin"+id).val();
		var id_proses_sekarang = $("#tabel_idprosessekarang"+id).val();
		var id_ = $("#tabel_id"+id).val();
		$("[name=popup_id]").val(id);


		var id_proses2 = $("#popup_proses").val();

		get_table(id);

		if(id_ != '' && id_opname != ''){
				$.ajax({
					url : '{{ url('opnameproduksi/get_barang') }}',
					dataType : 'json',
					data : { id_proses : id_proses2, jenis : 1, id_pegawai : id_pegawai, id_rekanan : id_rekanan, id_mesin : id_mesin},
					success : function(respon){
					
						var test = $("[name=popup_barang]").find("option[id_barang='"+ id_barang +"'][id_proses='"+ id_proses +"'][id_gudang='"+ id_gudang +"'][id_komposisi='"+ id_komposisi +"'][id_corak='"+ id_corak +"'][id_motif='"+ id_motif +"'][id_workorder='"+ id_workorder +"'][id_kualitas='"+ id_kualitas +"'][id_kualitas_dudul='"+ id_kualitas_dudul +"'][id_label='"+ id_label +"'][id_kemasan='"+ id_kemasan +"'][id_kemasansatuan='"+ id_kemasansatuan +"'][id_kemasansepuluh='"+ id_kemasansepuluh +"'][id_kemasanseratus='"+ id_kemasanseratus +"'][id_cap='"+ id_cap +"'][id_kualitas_proses='"+ id_kualitas_proses +"'][id_kualitas_periksa='"+ id_kualitas_periksa +"'][id_perubahansatuan='"+ id_perubahansatuan +"'][jumlah_rencana='"+ jumlah_rencana +"'][id_satuan_hasil='"+ id_satuan_hasil +"'][id_proses_sekarang='"+ id_proses_sekarang +"'][id_pegawai='"+ id_pegawai +"'][id_rekanan='"+ id_rekanan +"'][id_mesin='"+ id_mesin +"']");

						console.log(test.length);

						if(test.length == 0){
							for( i in respon ){

								if(respon[i].id_barang == id_barang && respon[i].id_proses == id_proses && respon[i].id_gudang == id_gudang && respon[i].id_warna == id_komposisi && respon[i].id_corak == id_corak && respon[i].id_motif == id_motif && respon[i].id_workorder_barang == id_workorder && respon[i].id_kualitas == id_kualitas && respon[i].id_kualitas_dudul == id_kualitas_dudul && respon[i].id_label == id_label && respon[i].id_kemasan == id_kemasan && respon[i].id_kemasansatuan == id_kemasansatuan && respon[i].id_kemasansepuluh == id_kemasansepuluh && respon[i].id_kemasanseratus == id_kemasanseratus && respon[i].id_cap == id_cap && respon[i].id_kualitas_proses == id_kualitas_proses && respon[i].id_kualitas_periksa == id_kualitas_periksa && respon[i].id_perubahansatuan == id_perubahansatuan && respon[i].jumlah_rencana == jumlah_rencana && respon[i].id_satuan_hasil == id_satuan_hasil && respon[i].id_proses_sekarang == id_proses_sekarang && respon[i].id_pegawai == id_pegawai && respon[i].id_rekanan == id_rekanan && respon[i].id_mesin == id_mesin){

										$("#popup_barang").append('<option value="'+respon[i].id+'" sisa="'+respon[i].sisa+'" id_barang="'+respon[i].id_barang+'" nama_barang="'+respon[i].nama_barang+'" id_gudang="'+respon[i].id_gudang+'" id_proses="'+respon[i].id_proses+'" nama_proses="'+respon[i].nama_proses+'" id_komposisi="'+respon[i].id_warna+'" inisial_komposisi="'+respon[i].inisial_komposisi+'" id_corak="'+respon[i].id_corak+'" nama_corak="'+respon[i].nama_corak+'" id_motif="'+respon[i].id_motif+'" nama_motif="'+respon[i].nama_motif+'" id_workorder="'+respon[i].id_workorder_barang+'" nama_workorder="'+respon[i].no_workorder_barang+'" id_kualitas="'+respon[i].id_kualitas+'" id_kualitas_dudul="'+respon[i].id_kualitas_dudul+'" id_label="'+respon[i].id_label+'" id_kemasan="'+respon[i].id_kemasan+'" id_kemasansatuan="'+respon[i].id_kemasansatuan+'" id_kemasansepuluh="'+respon[i].id_kemasansepuluh+'" id_kemasanseratus="'+respon[i].id_kemasanseratus+'" id_cap="'+respon[i].id_cap+'" id_kualitas_proses="'+respon[i].id_kualitas_proses+'" id_kualitas_periksa="'+respon[i].id_kualitas_periksa+'" id_perubahansatuan="'+respon[i].id_perubahansatuan+'" jumlah_rencana="'+respon[i].jumlah_rencana+'" id_satuan_hasil="'+respon[i].id_satuan_hasil+'" inisial_satuan="'+respon[i].inisial_satuan+'" id_proses_sekarang="'+respon[i].id_proses_sekarang+'" proses_sekarang="'+respon[i].nama_proses_sekarang+'" id_satuan="'+respon[i].id_satuan+'" id_pegawai="'+respon[i].id_pegawai+'" id_rekanan="'+respon[i].id_rekanan+'" id_mesin="'+respon[i].id_mesin+'"> '+respon[i].concat_nama+' </option>');	
								}else{
									//	console.log("TIDAK ADA \n");
								}
							}
						}
						
					},
					complete: function(res){
						FunctionLast();
					}
				})
			}else{
				FunctionLast();
			}

		function FunctionLast(){
			var test = $("[name=popup_barang]").find("option[id_barang='"+ id_barang +"'][id_proses='"+ id_proses +"'][id_gudang='"+ id_gudang +"'][id_komposisi='"+ id_komposisi +"'][id_corak='"+ id_corak +"'][id_motif='"+ id_motif +"'][id_workorder='"+ id_workorder +"'][id_kualitas='"+ id_kualitas +"'][id_kualitas_dudul='"+ id_kualitas_dudul +"'][id_label='"+ id_label +"'][id_kemasan='"+ id_kemasan +"'][id_kemasansatuan='"+ id_kemasansatuan +"'][id_kemasansepuluh='"+ id_kemasansepuluh +"'][id_kemasanseratus='"+ id_kemasanseratus +"'][id_cap='"+ id_cap +"'][id_kualitas_proses='"+ id_kualitas_proses +"'][id_kualitas_periksa='"+ id_kualitas_periksa +"'][id_perubahansatuan='"+ id_perubahansatuan +"'][jumlah_rencana='"+ jumlah_rencana +"'][id_satuan_hasil='"+ id_satuan_hasil +"'][id_proses_sekarang='"+ id_proses_sekarang +"'][id_pegawai='"+ id_pegawai +"'][id_rekanan='"+ id_rekanan +"'][id_mesin='"+ id_mesin +"']");
			
		//	console.log("Value -> "+value+" - Sisa -> "+sisa+" - id_barang -> "+id_barang+" - id_gudang -> "+id_gudang+" - id_proses -> "+id_proses+" - id_komposisi -> "+id_komposisi+" - id_corak -> "+id_corak+" - id_motif -> "+id_motif+" - id_workorder -> "+id_workorder+" - id_kualitas -> "+id_kualitas+" - id_kualitas_dudul -> "+id_kualitas_dudul+" - id_label -> "+id_label+" - id_kemasan -> "+id_kemasan+" - id_kemasansatuan -> "+id_kemasansatuan+" - id_kemasansepuluh -> "+id_kemasansepuluh+" - id_kemasanseratus -> "+id_kemasanseratus+" - id_cap -> "+id_cap+" - id_kualitas_proses -> "+id_kualitas_proses+" - id_kualitas_periksa -> "+id_kualitas_periksa+" - id_perubahansatuan -> "+id_perubahansatuan+" - jumlah_rencana -> "+jumlah_rencana+" - id_satuan_hasil -> "+id_satuan_hasil+" - id_proses_sekarang -> "+id_proses_sekarang);

			console.log(test.length);
			test.prop('selected', true).trigger('change');
			
			stok_barang = sisa;
			$("#popup_stok").text(sisa);
			$("#popup_selisih").text(selisih);
			$("#popup_jumlah").val(jumlah);
			$("#help_jumlah").text(format_angka(jumlah));
			$("#popup_ket").val(keterangan);

		//	console.log(sisa+" | "+selisih+" | ");
		}

		$("#exampleModal").modal('show');
	}

	function hapus_table(d){
		table.row(d.parents('tr')).remove().draw();	
	}

	function get_table(id){
		value = $("#tabel_idlist"+id).val();
		sisa = $("#tabel_sisa"+id).val();
		id_barang = $("#tabel_idbarang"+id).val();
		id_gudang = $("#tabel_idgudang"+id).val();
		id_proses = $("#tabel_idproses"+id).val();
		id_komposisi = $("#tabel_idkomposisi"+id).val();
		id_corak = $("#tabel_idcorak"+id).val();
		id_motif = $("#tabel_idmotif"+id).val();
		id_workorder = $("#tabel_idworkorder"+id).val();
		id_kualitas = $("#tabel_idkualitas"+id).val();
		id_kualitas_dudul = $("#tabel_idkualitasdudul"+id).val();
		id_label = $("#tabel_idlabel"+id).val();
		id_kemasan = $("#tabel_idkemasan"+id).val();
		id_kemasansatuan = $("#tabel_idkemasansatuan"+id).val();
		id_kemasansepuluh = $("#tabel_idkemasansepuluh"+id).val();
		id_kemasanseratus = $("#tabel_idkemasanseratus"+id).val();
		id_cap = $("#tabel_idcap"+id).val();
		id_kualitas_proses = $("#tabel_idkualitasproses"+id).val();
		id_kualitas_periksa = $("#tabel_idkualitasperiksa"+id).val();
		id_perubahansatuan = $("#tabel_idperubahansatuan"+id).val();
		jumlah_rencana = $("#tabel_rencanajumlah"+id).val();
		id_satuan_hasil = $("#tabel_idsatuanhasil"+id).val();
		id_proses_sekarang = $("#tabel_idprosessekarang"+id).val();
		jumlah = $("#tabel_jumlah"+id).val();
		selisih = $("#tabel_selisih"+id).val();
		sisa = $("#tabel_sisa"+id).val();
		keterangan = $("#tabel_keterangan"+id).val();
		id_satuan = $("#tabel_idsatuan"+id).val();
		id_pegawai = $("#tabel_idpegawai"+id).val();
		id_rekanan = $("#tabel_idrekanan"+id).val();
		id_mesin = $("#tabel_idmesin"+id).val();
	}


	function get_edit(id){
		$.ajax({
			url : '{{ url('opnameproduksi/get_edit') }}',
			dataType : 'json',
			data : { id : id },
			success : function(respon){
				if(respon.length > 0){
					for(i in respon){
						table.row.add(['<div><center></center></div>',
							'<div id="list_namabarang'+respon[i].id_detail+'">'+respon[i].nama_barang+'</div>',
							'<div id="list_namaproses'+respon[i].id_detail+'">'+respon[i].nama_proses_sekarang+'</div>',
							'<div id="list_jumlah'+respon[i].id_detail+'">'+format_angka(respon[i].jumlah_opname)+'</div>',
							'<div id="list_namacorak'+respon[i].id_detail+'">'+respon[i].nama_corak+'</div>',
							'<div id="list_namamotif'+respon[i].id_detail+'">'+respon[i].nama_motif+'</div>',
							'<div id="list_keterangan'+respon[i].id_detail+'">'+respon[i].ket_proses+'</div>',
							'<div class="btn-group"><button type="button" class="btn bg-warning-400 btn-xs" onclick="edit_table('+respon[i].id_detail+')"><i class="icon-pencil"></i> </button><button class="btn bg-danger-800 btn-xs" type="button" onclick="hapus_table($(this))"><i class="icon-eraser"></i></button></div>'+
							'<input type="hidden" id="tabel_id'+respon[i].id_detail+'" name="tabel_id[]" value="'+respon[i].id_detail+'">'+
							'<input type="hidden" id="tabel_idlist'+respon[i].id_detail+'" name="tabel_idlist[]" value="">'+
							'<input type="hidden" id="tabel_idbarang'+respon[i].id_detail+'" name="tabel_idbarang[]" value="'+respon[i].id_barang+'">'+
							'<input type="hidden" id="tabel_idgudang'+respon[i].id_detail+'" name="tabel_idgudang[]" value="'+respon[i].id_gudang+'">'+
							'<input type="hidden" id="tabel_idproses'+respon[i].id_detail+'" name="tabel_idproses[]" value="'+respon[i].id_proses+'">'+
							'<input type="hidden" id="tabel_idkomposisi'+respon[i].id_detail+'" name="tabel_idkomposisi[]" value="'+respon[i].id_warna+'">'+
							'<input type="hidden" id="tabel_idcorak'+respon[i].id_detail+'" name="tabel_idcorak[]" value="'+respon[i].id_corak+'">'+
							'<input type="hidden" id="tabel_idmotif'+respon[i].id_detail+'" name="tabel_idmotif[]" value="'+respon[i].id_motif+'">'+
							'<input type="hidden" id="tabel_idworkorder'+respon[i].id_detail+'" name="tabel_idworkorder[]" value="'+respon[i].id_workorder_barang+'">'+
							'<input type="hidden" id="tabel_idkualitas'+respon[i].id_detail+'" name="tabel_idkualitas[]" value="'+respon[i].id_kualitas+'">'+
							'<input type="hidden" id="tabel_idkualitasdudul'+respon[i].id_detail+'" name="tabel_idkualitasdudul[]" value="'+respon[i].id_kualitas_dudul+'">'+
							'<input type="hidden" id="tabel_idlabel'+respon[i].id_detail+'" name="tabel_idlabel[]" value="'+respon[i].id_label+'">'+
							'<input type="hidden" id="tabel_idkemasan'+respon[i].id_detail+'" name="tabel_idkemasan[]" value="'+respon[i].id_kemasan+'">'+
							'<input type="hidden" id="tabel_idkemasansatuan'+respon[i].id_detail+'" name="tabel_idkemasansatuan[]" value="'+respon[i].id_kemasansatuan+'">'+
							'<input type="hidden" id="tabel_idkemasansepuluh'+respon[i].id_detail+'" name="tabel_idkemasansepuluh[]" value="'+respon[i].id_kemasansepuluh+'">'+
							'<input type="hidden" id="tabel_idkemasanseratus'+respon[i].id_detail+'" name="tabel_idkemasanseratus[]" value="'+respon[i].id_kemasanseratus+'">'+
							'<input type="hidden" id="tabel_idcap'+respon[i].id_detail+'" name="tabel_idcap[]" value="'+respon[i].id_cap+'">'+
							'<input type="hidden" id="tabel_idkualitasproses'+respon[i].id_detail+'" name="tabel_idkualitasproses[]" value="'+respon[i].id_kualitas_proses+'">'+
							'<input type="hidden" id="tabel_idkualitasperiksa'+respon[i].id_detail+'" name="tabel_idkualitasperiksa[]" value="'+respon[i].id_kualitas_periksa+'">'+
							'<input type="hidden" id="tabel_idperubahansatuan'+respon[i].id_detail+'" name="tabel_idperubahansatuan[]" value="'+respon[i].id_perubahansatuan+'">'+
							'<input type="hidden" id="tabel_rencanajumlah'+respon[i].id_detail+'" name="tabel_rencanajumlah[]" value="'+respon[i].jumlah_rencana+'">'+
							'<input type="hidden" id="tabel_idprosessekarang'+respon[i].id_detail+'" name="tabel_idprosessekarang[]" value="'+respon[i].id_proses_sekarang+'">'+
							'<input type="hidden" id="tabel_keterangan'+respon[i].id_detail+'" name="tabel_keterangan[]" value="'+respon[i].ket_proses+'">'+
							'<input type="hidden" id="tabel_jumlah'+respon[i].id_detail+'" name="tabel_jumlah[]" value="'+respon[i].jumlah_opname+'">'+
							'<input type="hidden" id="tabel_selisih'+respon[i].id_detail+'" name="tabel_selisih[]" value="'+respon[i].jumlah_selisih+'">'+
							'<input type="hidden" id="tabel_sisa'+respon[i].id_detail+'" name="tabel_sisa[]" value="'+respon[i].jumlah_stok+'">'+
							'<input type="hidden" id="tabel_idsatuanhasil'+respon[i].id_detail+'" name="tabel_idsatuanhasil[]" value="'+respon[i].id_satuan_hasil+'">'+
							'<input type="hidden" id="tabel_idsatuan'+respon[i].id_detail+'" name="tabel_idsatuan[]" value="'+respon[i].id_satuan+'">'+
							'<input type="hidden" id="tabel_idrekanan'+respon[i].id_detail+'" name="tabel_idrekanan[]" value="'+respon[i].id_rekanan+'">'+
							'<input type="hidden" id="tabel_idpegawai'+respon[i].id_detail+'" name="tabel_idpegawai[]" value="'+respon[i].id_pegawai+'">'+
							'<input type="hidden" id="tabel_idmesin'+respon[i].id_detail+'" name="tabel_idmesin[]" value="'+respon[i].id_mesin+'">'
							]).draw(false);	
					}
				}else{

				}
			}
		})
	}

	function clear_status(){
		status_barang = 0;
		$("#popup_stok").text("");
		readonly("#popup_jumlah", false);
		readonly("#popup_ket", false);
		$("#btn_popup_simpan").show();
	}

</script>

@endsection