@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> Produksi</a></li>
			<li class="active">Laporan Hasil</li>
		</ul>
	</div>
</div>

<div class="content">
	<div class="panel panel-flat">
		<div class="panel-heading">
			<h5 class="panel-title">Form Input Laporan Hasil</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" id="form_submit" method="post" action="{{ url('barangmasuk_kemasan/simpan') }}" autocomplete="off">
	    	<input type="hidden" name="_token" value="{{ csrf_token() }}">
	    	<input type="hidden" name="id_barangmasuk" value="{{ $data['d_kemasan']['id_barangmasuk_kemasan'] }}">
	    	<input type="hidden" name="id_barangkeluar" value="{{$data['detail']->id_barangkeluar_kemasan }}">
	    	<input type="hidden" name="id_lokasi" value="{{$data['detail']->id_lokasi }}">
	    	<input type="hidden" name="barangkeluar" value="">
        	<div class="col-sm-6">
        		<div class="form-group">
        			<label class="control-label col-sm-4">Tanggal Selesai</label>
        			<div class="col-sm-8">
        				<input class="form-control datepicker" type="text" name="tanggal" placeholder="Tanggal" value="{{ ($data['d_kemasan']['tanggal'] != '') ? $data['d_kemasan']['tanggal']:date('d-m-Y') }}" required/>
        			</div>
        		</div>
        		<div class="form-group">
        			<label class="control-label col-sm-4">Tanggal Pengambilan</label>
        			<div class="col-sm-8">
        				<input class="form-control" type="text" name="tanggal_pengambilan" placeholder="" value="{{ tgl_full($data['detail']->tanggal, '') }}" readonly/>
        			</div>
        		</div>
        		<div class="form-group">
        			<label class="control-label col-sm-4">Tanggal Perkiraan Selesai</label>
        			<div class="col-sm-8">
        				<input class="form-control" type="text" name="tanggal_perkiraan" placeholder="" value="{{ tgl_full($data['detail']->tanggal_perkiraan, '') }}" readonly/>
        			</div>
        		</div>

        		<div class="form-group">
        			<label class="control-label col-sm-4">Status Proses</label>
        			<div class="col-sm-8"> @php $status = $data['detail']->status; @endphp
        				<select class="form-control select-search" name="status_proses">
        					<option value="0" {{ ($status != '2') ? "selected":"" }}>Belum Selesai</option>
        					<option value="1" {{ ($status == '2') ? "selected":"" }}>Selesai</option>
        				</select>
        			</div>
        		</div>
        	</div>
        	<div class="col-sm-6">
        		<div class="form-group">
        			<label class="control-label col-sm-4">Rekanan</label>
        			<div class="col-sm-8">
        				
        				<input class="form-control" type="text" name="rekanan" placeholder="" value="{{$data['detail']->nama_rekanan.' - '.$data['detail']->nama_kelompok }}" readonly/>
        			</div>
        		</div>
        		<div class="form-group">
        			<label class="control-label col-sm-4">Pegawai</label>
        			<div class="col-sm-8">
        				
        				<input class="form-control" type="text" name="pegawai" placeholder="" value="{{$data['detail']->nama_pegawai }}" readonly/>
        			</div>
        		</div>
        		<div class="form-group">
        			<label class="control-label col-sm-4">Proses Produksi</label>
        			<div class="col-sm-8">
        				<input class="form-control" type="text" name="proses" placeholder="" value="{{$data['detail']->nama_proses }}" readonly/>
        			</div>
        		</div>
        		<div class="form-group">
                    <label class="control-label col-sm-4">Nomor</label>
                    <div class="col-sm-3">
                        <input type="text" name="nomor" class="form-control">
                    </div>
                    <div class="col-sm-5">
                        <input type="text" name="nomor_ext" class="form-control">
                    </div>
                </div>
        	</div>
        	
        	<div class="col-sm-12 form-group">
	        	<h5 class="panel-title">Barang Diambil</h5>
	        	<div class="col-ms-12 table-responsive">
		        	<table class="table table-stripped" id="table_barang">
				    	<thead>
							<tr>
								<th>No</th>
								<th>Kode Barang</th>
								<th>Nama Barang</th>
								<th>Warna</th>
								<th>Gudang</th>
								<th>Jumlah</th>
								<th>Satuan</th>
								<th>Kualitas Produksi</th>
								<th>Corak</th>
								<th>Motif</th>
								<th>No. Workorder</th>
								<th>Kualitas</th>
								<th>Dudulan</th>
								<th>Label</th>
								<th>Cap</th>
								<th>Kemasan</th>
								<th>Kemasan Satuan</th>
								<th>Kemasan 10 Potong</th>
								<th>Kemasan Dus Ball</th>
							</tr>
						</thead>
						<tbody>
							@php $no=1; @endphp
							@foreach($data['barang_keluar'] as $d) 
							<tr>
								<td>{{$no++}}</td>
								<td>{{ $d->kode_barang }}</td>
								<td>{{ $d->nama_barang }}</td>
								<td>{{ $d->nama_komposisi }}</td>
								<td>{{ $d->nama_gudang }}</td>
								<td>{{ $d->jumlah }}</td>
								<td>{{ $d->nama_satuan }}</td>
								<td>{{ $d->nama_kualitas_proses }}</td>
								<td>{{ $d->nama_corak }}</td>
								<td>{{ $d->nama_motif }}</td>
								<td>{{ $d->no_workorder_barang }}</td>
								<td>{{ $d->nama_kualitas }}</td>
								<td>{{ $d->kualitas_dudul }}</td>
								<td>{{ $d->nama_label }}</td>
								<td>{{ $d->nama_cap }}</td>
								<td>{{ $d->nama_kemasan }}</td>
								<td>{{ $d->nama_kemasansatuan }}</td>
								<td>{{ $d->nama_kemasansepuluh }}</td>
								<td>{{ $d->nama_kemasanseratus }}</td>
							</tr>
							@endforeach
						</tbody>
				    </table>
	        	</div>
        	</div>

        	@php if($data['detail']->status == '3' AND count($data['sisa']) > 0){  @endphp
        	<div class="col-sm-12 form-group">
	        	<h5 class="panel-title">Belum Diserahkan</h5>
	        	<div class="col-sm-12 table-responsive">
		        	<table class="table table-stripped" id="table_sisa">
				    	<thead>
							<tr>
								<th>No</th>
								<th>Kode Barang</th>
								<th>Nama Barang</th>
								<th>Warna</th>
								<th>Gudang</th>
								<th>Jumlah</th>
								<th>Satuan</th>
								<th>Kualitas Produksi</th>
								<th>Corak</th>
								<th>Motif</th>
								<th>Kualitas</th>
								<th>Dudulan</th>
								<th>Label</th>
								<th>Cap</th>
								<th>Kemasan</th>
								<th>Kemasan Satuan</th>
								<th>Kemasan 10 Potong</th>
								<th>Kemasan Dus Ball</th>
								
							</tr>
						</thead>
						<tbody>
							@php $no=1; @endphp
							@foreach($data['sisa'] as $s) 
							<tr>
								<td>{{$no++}}</td>
								<td>{{ $s['kode_barang'] }}</td>
								<td>{{ $s['nama_barang'] }}</td>
								<td>{{ $s['nama_komposisi'] }}</td>
								<td>{{ $s['nama_gudang'] }}</td>
								<td>{{ $s['stok'] }}</td>
								<td>{{ $s['nama_satuan'] }}</td>
								<td>{{ $s['nama_kualitas_proses'] }}</td>
								<td>{{ $s['nama_corak'] }}</td>
								<td>{{ $s['nama_motif'] }}</td>
								<td>{{ $s['nama_kualitas'] }}</td>
								<td>{{ $s['kualitas_dudul'] }}</td>
								<td>{{ $s['nama_label'] }}</td>
								<td>{{ $s['nama_cap'] }}</td>
								<td>{{ $s['nama_kemasan'] }}</td>
								<td>{{ $s['nama_kemasansatuan'] }}</td>
								<td>{{ $s['nama_kemasansepuluh'] }}</td>
								<td>{{ $s['nama_kemasanseratus'] }}</td>
								
							</tr>
							@endforeach
						</tbody>
				    </table>
	        	</div>
        	</div>

        	@php }	@endphp
            
            <div class="col-sm-12 form-group">
	        	<h5 class="panel-title">Barang Disetor</h5>
	        	<br><a href="#" class="btn btn-success" style="margin-bottom: 1%;" id="btn_tambah_item">Tambah Barang</a>
		        	<table class="table table-stripped" id="table_hasil">
				    	<thead>
							<tr>
								<th>No</th>
								<th>Kode Barang</th>
								<th>Nama Barang</th>
								<th>Warna</th>
								<th>Jumlah</th>
								<th>Satuan</th>
								<th>Gudang</th>
								<th>Corak</th>
								<th>Keterangan</th>
								<th>Aksi</th>
							</tr>
						</thead>
						<tbody id="body_setor">
						</tbody>
			    	</table>
        	</div>
        	<div class="col-sm-12">
        	
            <div class="form-group pull-right">
             	<button class="btn btn-primary" type="submit" id="btn_simpan">Simpan</button>
            </div>
            </div>
	    </div>


		<input type="hidden" name="td_total" class="form-control">
		<input type="hidden" name="td_netto" class="form-control">
	    </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_table">
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Barang</label>
	      				<div class="col-sm-8">
		      			 	<select class="form-control select-search" name="popup_barang">
		      			 		<option value="" nama="">--- Pilih ---</option>
		      			 		@php
		      			 		foreach($data['barang'] as $b){ @endphp
		      			 			<option value="{{ $b->id }}" nama="{{ $b->nama_barang }}" kode="{{ $b->kode_barang }}" satuan="{{ $b->id_satuan }}">{{ $b->nama_kategori.' - '.$b->nama_sub.' - '.$b->kode_barang.' - '.$b->nama_barang }}</option>
		      			 		@php
		      			 		}
		      			 		@endphp	
		      			 	</select>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Gudang</label>
	      				<div class="col-sm-8">
	      			 	<select class="form-control select-search" name="popup_gudang">
	      			 			<option value="" nama="">--- Pilih ---</option>
		      			 		@php
		      			 		foreach($data['gudang'] as $b){ @endphp
		      			 			<option value="{{ $b->id_gudang }}" nama="{{ $b->nama_gudang }}">{{ $b->nama_gudang }}</option>
		      			 		@php
		      			 		}
		      			 		@endphp
	      			 	</select>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Jumlah {{-- <b id="div_satuanjumlah"> --}}</b></label>
	      				<div class="col-sm-8">
	      			 	<input type="text" name="popup_jumlah" class="form-control number-only" onkeyup="maksimal($(this))">
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Satuan {{-- <b id="div_satuanjumlah"> --}}</b></label>
	      				<div class="col-sm-8">
	      			 		<select class="form-control select-search" name="popup_satuan">
	      			 			<option value="" nama="">--- Pilih ---</option>
	      			 			@php
	      			 			foreach($data['satuan'] as $s){ @endphp
	      			 				<option value="{{ $s->id_satuan }}" name="{{ $s->nama_satuan }}">{{ $s->nama_satuan }}</option>
	      			 			@php
		      			 		}
		      			 		@endphp
	      			 		</select>
	      				</div>
	      			</div>

	      			{{-- <div class="form-group">
	      				<label class="control-label col-sm-4">No. Workorder</b></label>
	      				<div class="col-sm-8">
	      			 		<select class="form-control select-search" name="popup_workorder">
	      			 			<option value="" nama="">--- Pilih ---</option>
	      			 			@php
	      			 			foreach($data['workorder'] as $s){ @endphp
	      			 				<option value="{{ $s->id_workorder_barang }}" name="{{ $s->no_workorder }}">{{ $s->no_workorder }}</option>
	      			 			@php
		      			 		}
		      			 		@endphp
	      			 		</select>
	      				</div>
	      			</div> --}}

	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Kualitas Proses</label>
	      				<div class="col-sm-8">	
	      			 		<select name="popup_kualitas" class="form-control select-search">
	      			 			<option value="" nama="">--- Pilih ---</option>
	      			 			@php
	      			 			foreach($data['kualitas_proses'] as $s){ @endphp
	      			 				<option value="{{ $s->id_kualitas }}" nama="{{ $s->nama_kualitas }}">{{ $s->nama_kualitas }}</option>
	      			 			@php
		      			 		}
		      			 		@endphp
	      			 		</select>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Warna</label>
	      				<div class="col-sm-8">
	      					<input type="hidden" name="popup_idkomposisi">
	      			 	{{-- 	<input type="text" name="popup_komposisi" class="form-control"> --}}
	      			 		<select name="popup_komposisi" class="form-control select-search">
	      			 			<option value="" name="Tanpa Warna">Tanpa Warna</option>
	      			 			@php
	      			 			foreach($data['warna'] as $w){ @endphp
	      			 				<option value="{{ $w->id_komposisi }}" name="{{ $w->nama }}">{{ $w->nama.' ('.$w->inisial.')' }}</option>
	      			 			@php
		      			 		}
		      			 		@endphp
	      			 		</select>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Corak</label>
	      				<div class="col-sm-8">
	      			 		<select name="popup_corak" class="form-control select-search">
	      			 			<option value="" nama="">--- Pilih ---</option>
	      			 			@php
	      			 			foreach($data['corak'] as $w){ @endphp
	      			 				<option value="{{ $w->id_motif_barang }}" nama="{{ $w->motif_keterangan }}">{{ $w->motif_keterangan }}</option>
	      			 			@php
		      			 		}
		      			 		@endphp
	      			 		</select>
	      				</div>
	      			</div>

	      			<div class="form-group" id="div_motif">
	      				<label class="control-label col-sm-4">Motif</label>
	      				<div class="col-sm-8"> 
	      			 		<select name="popup_motif" class="form-control select-search">
	      			 			<option value="" nama="">--- Pilih ---</option>
	      			 			@php
	      			 			foreach($data['motif'] as $w){ @endphp
	      			 				<option value="{{ $w->id_motif }}" nama="{{ $w->nama_motif }}">{{ $w->nama_motif }}</option>
	      			 			@php
		      			 		}
		      			 		@endphp
	      			 		</select>
	      				</div>
	      			</div>
	      			<div class="form-group" id="div_motif">
	      				<label class="control-label col-sm-4">No. Order</label>
	      				<div class="col-sm-8"> 
	      			 		<select name="popup_order" class="form-control select-search">
	      			 			<option value="" nama="">--- Pilih ---</option>
	      			 			@php
	      			 			foreach($data['wo_barang'] as $w){ @endphp
	      			 				<option value="{{ $w->id_workorder_barang }}" nama="{{ $w->no_workorder_barang }}">{{ $w->no_workorder_barang }}</option>
	      			 			@php
		      			 		}
		      			 		@endphp
	      			 		</select>
	      				</div>
	      			</div>  
	      			<div class="form-group" id="div_kualitas">
	      				<label class="control-label col-sm-4">Kualitas Tenun</label>
	      				<div class="col-sm-8">	
	      			 		<select name="popup_kual" class="form-control select-search">
	      			 			<option value="" nama="">--- Pilih ---</option>
	      			 			@php
	      			 			foreach($data['kualitas_tenun'] as $k1){ 
	      			 				@endphp
	      			 				<option value="{{ $k1->id_kualitas }}" nama="{{ $k1->nama_kualitas }}">{{ $k1->nama_kualitas }}</option>
	      			 			@php
		      			 		}
		      			 		@endphp 
	      			 		</select>
	      				</div>
	      			</div>
	      			<div class="form-group" id="div_dudul">
	      				<label class="control-label col-sm-4">Kualitas Dudulan</label>
	      				<div class="col-sm-8">	
	      			 		<select name="popup_dudul" class="form-control select-search">
	      			 			<option value="" nama="">-- Pilih Dudulan --</option>
	      			 			<option value="1" nama="Baik">Baik</option>
	      			 			<option value="2" nama="Jelek">Jelek</option>
	      			 		</select>
	      				</div>
	      			</div>
	      			<div class="form-group" id="div_kualitas">
	      				<label class="control-label col-sm-4">Kualitas Periksa</label>
	      				<div class="col-sm-8">	
	      			 		<select name="popup_periksa" class="form-control select-search">
	      			 			<option value="" nama="">--- Pilih ---</option>
	      			 			@php
	      			 			foreach($data['kualitas_periksa'] as $s){ @endphp
	      			 				<option value="{{ $s->id_kualitas }}" nama="{{ $s->nama_kualitas }}">{{ $s->nama_kualitas }}</option>
	      			 			@php
		      			 		}
		      			 		@endphp 
	      			 		</select>
	      				</div>
	      			</div> 
	      			<div class="form-group" id="div_label">
	      				<label class="control-label col-sm-4">Label</label>
	      				<div class="col-sm-8">	
	      			 		<select name="popup_label" class="form-control select-search">
	      			 			<option value="" nama="">--- Pilih ---</option>
	      			 			@php
	      			 			foreach($data['barang_label'] as $s){ @endphp
	      			 				<option value="{{ $s->id }}" nama="{{ $s->nama_barang }}" kode="{{ $s->kode_barang }}">{{ $s->nama_barang }}</option>
	      			 			@php
		      			 		}
		      			 		@endphp 
	      			 		</select>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Cap</label>
	      				<div class="col-sm-8">	
	      			 		<select name="popup_cap" class="form-control select-search">
	      			 			<option value="" nama="">--- Pilih ---</option>
	      			 			@php
	      			 			foreach($data['barang_cap'] as $s){ @endphp
	      			 				<option value="{{ $s->id }}" nama="{{ $s->nama_barang }}" kode="{{ $s->kode_barang }}">{{ $s->nama_barang }}</option>
	      			 			@php
		      			 		}
		      			 		@endphp
	      			 		</select>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Kemasan Awal</label>
	      				<div class="col-sm-8">	
	      			 		<select name="popup_kemasan" class="form-control select-search">
	      			 			<option value="" nama="">--- Pilih ---</option>
	      			 			@php
	      			 			foreach($data['barang_awal'] as $s){ @endphp
	      			 				<option value="{{ $s->id }}" nama="{{ $s->nama_barang }}" kode="{{ $s->kode_barang }}">{{ $s->nama_barang }}</option>
	      			 			@php
		      			 		}
		      			 		@endphp
	      			 		</select>
	      				</div>
	      			</div>
	      			<div class="form-group" id="div_kemasansatuan">
	      				<label class="control-label col-sm-4">Kemasan Satuan</label>
	      				<div class="col-sm-8">	
	      			 		<select name="popup_kemasansatuan" class="form-control select-search">
	      			 			<option value="" nama="">--- Pilih ---</option>
	      			 			@php
	      			 			foreach($data['barang_satuan'] as $s){ @endphp
	      			 				<option value="{{ $s->id }}" nama="{{ $s->nama_barang }}" kode="{{ $s->kode_barang }}">{{ $s->nama_barang }}</option>
	      			 			@php
		      			 		}
		      			 		@endphp
	      			 		</select>
	      				</div>
	      			</div>
	      			<div class="form-group" id="div_kemasansepuluh">
	      				<label class="control-label col-sm-4">Kemasan 10 Potong</label>
	      				<div class="col-sm-8">	
	      			 		<select name="popup_kemasansepuluh" class="form-control select-search">
	      			 			<option value="" nama="">--- Pilih ---</option>
	      			 			@php
	      			 			foreach($data['barang_satuan'] as $s){ @endphp
	      			 				<option value="{{ $s->id }}" nama="{{ $s->nama_barang }}" kode="{{ $s->kode_barang }}">{{ $s->nama_barang }}</option>
	      			 			@php
		      			 		}
		      			 		@endphp
	      			 		</select>
	      				</div>
	      			</div>

	      			<div class="form-group" id="div_kemasanseratus">
	      				<label class="control-label col-sm-4">Kemasan Dosball</label>
	      				<div class="col-sm-8">	
	      			 		<select name="popup_kemasanseratus" class="form-control select-search">
	      			 			<option value="" nama="">--- Pilih ---</option>
	      			 			@php
	      			 			foreach($data['barang_dos'] as $s){ @endphp
	      			 				<option value="{{ $s->id }}" nama="{{ $s->nama_barang }}" kode="{{ $s->kode_barang }}">{{ $s->nama_barang }}</option>
	      			 			@php
		      			 		}
		      			 		@endphp
	      			 		</select>
	      				</div>
	      			</div>

	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Keterangan</b></label>
	      				<div class="col-sm-8">
	      			 		<textarea class="form-control" name="popup_keterangan"></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" name="store_konversi">

<script type="text/javascript">

	$("#btn_tambah_item").click(function(){
		$("[name=popup_id_table]").val('');
		$("[name=popup_barang]").val(null).trigger('change');
		$("[name=popup_gudang]").val(null).trigger('change');
		$("[name=popup_jumlah]").val('');
		$("[name=popup_jumlah]").removeAttr('max');
		$("[name=popup_upah]").val('');
		$("[name=popup_kualitas]").val(null).trigger('change');
		$("[name=popup_komposisi]").val(null).trigger('change');
		$("[name=popup_corak]").val(null).trigger('change');
		$("[name=popup_motif]").val(null).trigger('change');
		$("[name=popup_workorder]").val(null).trigger('change');
		$("[name=popup_kual]").val(null).trigger('change');
		$("[name=popup_dudul]").val(null).trigger('change');
		$("[name=popup_label]").val(null).trigger('change');
		$("[name=popup_cap]").val(null).trigger('change');
		$("[name=popup_kemasan]").val(null).trigger('change');
		$("[name=popup_kemasansatuan]").val(null).trigger('change');
		$("[name=popup_kemasansepuluh]").val(null).trigger('change');
		$("[name=popup_kemasanseratus]").val(null).trigger('change');
		$("[name=popup_order]").val(null).trigger('change');
		$("[name=popup_keterangan]").val('');
		$("#exampleModal").modal('show');
	})

	var table_barang;
	var table_hasil;
	var table_sisa;
	var tb_no = parseInt(10000);
	var id_proses;
	var nama_proses;
	var id;
	var proses;

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

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

        table_sisa = $("#table_sisa").DataTable({
			"paging": false
		});
		table_sisa.on( 'order.dt search.dt', function () {
            table_sisa.column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {
                cell.innerHTML = i+1;
            } );
        } ).draw();
        
        store_barangmasuk = $("[name=id_barangmasuk]").val();
        store_barangkeluar = $("[name=id_barangkeluar]").val();
        if(store_barangmasuk == ''){
        	get_proses(store_barangkeluar);
        }else{
        	get_edit(store_barangmasuk);
        }

        get_nomor();

	})


	$("#btn_popup_simpan").click(function(){
		var id_data = $("[name=popup_id_table]").val();
		var id_barang = $("[name=popup_barang]").val();
		var id_gudang = $("[name=popup_gudang]").val();
		var id_upah = $("[name=popup_idupah]").val();
		var kode_barang = $("[name=popup_barang] :selected").attr('kode');
		var nama_barang = $("[name=popup_barang] :selected").attr('nama');
		var nama_gudang = $("[name=popup_gudang] :selected").attr('nama');
		var upah = $("[name=popup_upah]").val();
		var jumlah = $("[name=popup_jumlah]").val();
		
		var satuan = $("[name=popup_satuan]").val();
		var nama_satuan = $("[name=popup_satuan] :selected").attr('name');

		var id_komposisi = $("[name=popup_komposisi]").val();
		var komposisi = $("[name=popup_komposisi] :selected").attr('name');

		var id_corak = $("[name=popup_corak]").val();
		var corak = $("[name=popup_corak] :selected").attr('nama');

		var id_motif = $("[name=popup_motif]").val();
		var motif = $("[name=popup_motif] :selected").attr('nama');

		var id_kualitas = $("[name=popup_kual]").val();
		var kualitas = $("[name=popup_kual] :selected").attr('nama');

		var id_dudul = $("[name=popup_dudul]").val();
		var dudul = $("[name=popup_dudul] :selected").attr('nama');	

		var id_label = $("[name=popup_label]").val();
		var label = $("[name=popup_label] :selected").attr('nama');

		var id_kemasan = $("[name=popup_kemasan]").val();
		var kemasan = $("[name=popup_kemasan] :selected").attr('nama');	

		var id_kemasansatuan = $("[name=popup_kemasansatuan]").val();
		var kemasan_satuan = $("[name=popup_kemasansatuan] :selected").attr('nama');	

		var id_kemasansepuluh = $("[name=popup_kemasansepuluh]").val();
		var kemasan_sepuluh = $("[name=popup_kemasansepuluh] :selected").attr('nama');

		var id_kemasanseratus = $("[name=popup_kemasanseratus]").val();
		var kemasan_seratus = $("[name=popup_kemasanseratus] :selected").attr('nama');

		var id_cap = $("[name=popup_cap]").val();
		var nama_cap = $("[name=popup_cap] :selected").attr('nama');		

		var id_workorder = $("[name=popup_workorder]").val();
		var nama_workorder = $("[name=popup_workorder] :selected").attr('nama');

		var id_workorder_barang = $("[name=popup_order]").val();

		var id_kualitasproses = $("[name=popup_kualitas]").val();

		var id_kualitasperiksa = $("[name=popup_periksa]").val();

		var keterangan = $("[name=popup_keterangan]").val();


		if(id_barang != '' && jumlah != '' && jumlah != 0 && id_gudang != '' && satuan != ''){
			if(id_data == ''){
				table_hasil.row.add(['<div><center></center></div>',
					'<div id="list_kode'+tb_no+'">'+kode_barang+'</div>',
					'<div id="list_nama'+tb_no+'">'+nama_barang+'</div>',
					'<div id="list_komposisi'+tb_no+'">'+komposisi+'</div>',
					'<div id="list_jumlah'+tb_no+'">'+jumlah+'</div>',
					// '<div id="list_jumlah_konv'+tb_no+'">'+jumlah_konv+'</div>',
					'<div id="list_namasatuan'+tb_no+'">'+nama_satuan+'</div>',
					'<div id="list_gudang'+tb_no+'">'+nama_gudang+'</div>',
					'<div id="list_corak'+tb_no+'">'+corak+'</div>',
					'<div id="list_keterangan'+tb_no+'">'+keterangan+'</div>',
					'<div><button type="button" class="btn bg-warning-400" onclick="edit_table('+tb_no+')"><i class="icon-pencil"></i> </button><button class="btn bg-danger-800" type="button"  onclick="hapus($(this))""><i class="icon-eraser"></i></button></div>'+
					'<input type="hidden" id="tabel_idtable'+tb_no+'" name="tabel_idtable[]" value="">'+
					'<input type="hidden" name="tabel_id[]" class="tabel_id" id="tabel_id'+tb_no+'" value="'+tb_no+'">'+
							'<input type="hidden" name="tabel_idbarang[]" id="tabel_idbarang'+tb_no+'" value="'+id_barang+'">'+
							'<input type="hidden" name="tabel_idgudang[]" id="tabel_idgudang'+tb_no+'" value="'+id_gudang+'">'+
							'<input type="hidden" name="tabel_jumlah[]" id="tabel_jumlah'+tb_no+'" value="'+jumlah+'">'+

							'<input type="hidden" name="tabel_komposisi[]" id="tabel_komposisi'+tb_no+'" value="'+komposisi+'">'+
							'<input type="hidden" name="tabel_idkomposisi[]" id="tabel_idkomposisi'+tb_no+'" value="'+id_komposisi+'">'+
							'<input type="hidden" name="tabel_idsatuan[]" id="tabel_idsatuan'+tb_no+'" value="'+satuan+'">'+
							'<input type="hidden" name="tabel_idcorak[]" id="tabel_idcorak'+tb_no+'" value="'+id_corak+'">'+
							'<input type="hidden" name="tabel_idmotif[]" id="tabel_idmotif'+tb_no+'" value="'+id_motif+'">'+
							'<input type="hidden" name="tabel_idkualitas[]" id="tabel_idkualitas'+tb_no+'" value="'+id_kualitas+'">'+
							'<input type="hidden" name="tabel_iddudul[]" id="tabel_iddudul'+tb_no+'" value="'+id_dudul+'">'+
							'<input type="hidden" name="tabel_idlabel[]" id="tabel_idlabel'+tb_no+'" value="'+id_label+'">'+
							'<input type="hidden" name="tabel_idkemasan[]" id="tabel_idkemasan'+tb_no+'" value="'+id_kemasan+'">'+
							'<input type="hidden" name="tabel_idkemasansatuan[]" id="tabel_idkemasansatuan'+tb_no+'" value="'+id_kemasansatuan+'">'+
							'<input type="hidden" name="tabel_idkemasansepuluh[]" id="tabel_idkemasansepuluh'+tb_no+'" value="'+id_kemasansepuluh+'">'+
							'<input type="hidden" name="tabel_idkemasanseratus[]" id="tabel_idkemasanseratus'+tb_no+'" value="'+id_kemasanseratus+'">'+
							'<input type="hidden" name="tabel_idcap[]" id="tabel_idcap'+tb_no+'" value="'+id_cap+'">'+
							'<input type="hidden" name="tabel_idkualitasproses[]" id="tabel_idkualitasproses'+tb_no+'" value="'+id_kualitasproses+'">'+
							'<input type="hidden" name="tabel_idkualitasperiksa[]" id="tabel_idkualitasperiksa'+tb_no+'" value="'+id_kualitasperiksa+'">'+
							'<input type="hidden" name="tabel_idworkorder[]" id="tabel_idworkorder'+tb_no+'" value="'+id_workorder_barang+'">'+
							'<input type="hidden" name="tabel_idperubahansatuan[]" id="tabel_idperubahansatuan'+tb_no+'" value="">'+
							'<input type="hidden" name="tabel_rencanajumlah[]" id="tabel_rencanajumlah'+tb_no+'" value="">'+
							'<input type="hidden" name="tabel_keterangan[]" id="tabel_keterangan'+tb_no+'" value="'+keterangan+'">'+

							'<input type="hidden" name="tabel_kode[]" id="tabel_kode'+tb_no+'" value="'+kode_barang+'">'+
							'<input type="hidden" name="tabel_nama[]" id="tabel_nama'+tb_no+'" value="'+nama_barang+'">'+
							'<input type="hidden" name="tabel_namasatuan[]" id="tabel_namasatuan'+tb_no+'" value="'+nama_satuan+'">'+
							'<input type="hidden" name="tabel_namagudang[]" id="tabel_namagudang'+tb_no+'" value="'+nama_gudang+'">'
							
					]).draw(false);
					tb_no++;
			}else{
				$("#list_kode"+id_data).text(kode_barang);
				$("#list_nama"+id_data).text(nama_barang);
				$("#list_komposisi"+id_data).text(komposisi);
				$("#list_gudang"+id_data).text(nama_gudang);
				$("#list_upah"+id_data).text(upah);
				$("#list_jumlah"+id_data).text(jumlah);
				$("#list_namasatuan"+id_data).text(nama_satuan);
				$("#list_corak"+id_data).text(corak);
				$("#list_motif"+id_data).text(motif);
				$("#list_kualitas"+id_data).text(kualitas);
				$("#list_dudul"+id_data).text(dudul);
				$("#list_keterangan"+id_data).text(keterangan);

				$("#tabel_id"+id_data).val(id_data);
				$("#tabel_idbarang"+id_data).val(id_barang);
				$("#tabel_idgudang"+id_data).val(id_gudang);
				$("#tabel_namabarang"+id_data).val(nama_barang);				
				
				$("#tabel_jumlah"+id_data).val(jumlah);
				$("#tabel_idsatuan"+id_data).val(satuan);
				$("#tabel_idkomposisi"+id_data).val(id_komposisi);
				$("#tabel_komposisi"+id_data).val(komposisi);
				$("#tabel_idcorak"+id_data).val(id_corak);
				$("#tabel_idmotif"+id_data).val(id_motif);
				$("#tabel_idkualitas"+id_data).val(id_kualitas);
				$("#tabel_iddudul"+id_data).val(id_dudul);
				$("#tabel_idlabel"+id_data).val(id_label);
				$("#tabel_idkemasan"+id_data).val(id_kemasan);
				$("#tabel_idkemasansatuan"+id_data).val(id_kemasansatuan);
				$("#tabel_idkemasansepuluh"+id_data).val(id_kemasansepuluh);
				$("#tabel_idkemasanseratus"+id_data).val(id_kemasanseratus);
				$("#tabel_idcap"+id_data).val(id_cap);
				$("#tabel_keterangan"+id_data).val(keterangan);
				
				$("#tabel_idkualitasproses"+id_data).val(id_kualitasproses);
				$("#tabel_idkualitasperiksa"+id_data).val(id_kualitasperiksa);
				$("#tabel_idworkorder"+id_data).val(id_workorder_barang);

				$("#tabel_kode"+id_data).val(kode_barang);
				$("#tabel_nama"+id_data).val(nama_barang);
				$("#tabel_namagudang"+id_data).val(nama_gudang);
				$("#tabel_namasatuan"+id_data).val(nama_satuan);
				
			}
		
		$("#exampleModal").modal('hide');
		/*
		get_jum();*/
		}
	})

	function edit_table(id){
		var id_barang = $("#tabel_idbarang"+id).val();
		var id_gudang = $("#tabel_idgudang"+id).val();
		var jumlah = $("#tabel_jumlah"+id).val();

		var satuan = $("#tabel_idsatuan"+id).val();
		var komposisi = $("#tabel_komposisi"+id).val();
		var id_komposisi = $("#tabel_idkomposisi"+id).val();

		var id_corak = $("#tabel_idcorak"+id).val();
		var id_motif = $("#tabel_idmotif"+id).val();
		var id_kualitas = $("#tabel_idkualitas"+id).val();
		var id_dudul = $("#tabel_iddudul"+id).val();
		var id_label = $("#tabel_idlabel"+id).val();
		var id_kemasan = $("#tabel_idkemasan"+id).val();
		var id_kemasansatuan = $("#tabel_idkemasansatuan"+id).val();
		var id_kemasansepuluh = $("#tabel_idkemasansepuluh"+id).val();
		var id_kemasanseratus = $("#tabel_idkemasanseratus"+id).val();
		var id_cap = $("#tabel_idcap"+id).val();
		var id_kualitasproses = $("#tabel_idkualitasproses"+id).val();
		var id_kualitasperiksa = $("#tabel_idkualitasperiksa"+id).val();
		var id_workorder_barang = $("#tabel_idworkorder"+id).val();
		var keterangan = $("#tabel_keterangan"+id).val();
		

		var stok = $("#tabel_stok"+id).val();

		$("[name=popup_id_table]").val(id);
		$("[name=popup_barang]").val(id_barang).trigger('change');
		$("[name=popup_gudang]").val(id_gudang).trigger('change');
		$("[name=popup_jumlah]").val(jumlah);
		if(id_proses != 44 && nama_proses != 'potong'){
			$("[name=popup_jumlah]").attr('placeholder', stok);
			$("[name=popup_jumlah]").attr('min',0);
			$("[name=popup_jumlah]").attr('max',stok);	
		}
		
		$("[name=popup_corak]").val(id_corak).trigger('change');
		$("[name=popup_motif]").val(id_motif).trigger('change');
		$("[name=popup_kual]").val(id_kualitas).trigger('change');
		$("[name=popup_dudul]").val(id_dudul).trigger('change');
		$("[name=popup_label]").val(id_label).trigger('change');
		$("[name=popup_kemasan]").val(id_kemasan).trigger('change');
		$("[name=popup_kemasansatuan]").val(id_kemasansatuan).trigger('change');
		$("[name=popup_kemasansepuluh]").val(id_kemasansepuluh).trigger('change');
		$("[name=popup_kemasanseratus]").val(id_kemasanseratus).trigger('change');
		$("[name=popup_cap]").val(id_cap).trigger('change');
		$("[name=popup_order]").val(id_workorder_barang).trigger('change');
		$("[name=popup_keterangan]").val(keterangan);
		

		$("[name=popup_satuan]").val(satuan).trigger('change');
		$("[name=popup_komposisi]").val(id_komposisi).trigger('change');
		$("[name=popup_kualitas]").val(id_kualitasproses).trigger('change');
		$("[name=popup_periksa]").val(id_kualitasperiksa).trigger('change');


		console.log(id_komposisi);


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

	function get_proses(id,proses){
		var gudang = $('[name=proses_gudang]').html();
		var kualitas = $('[name=proses_kualitas]').html();
		
		$.ajax({
			url: "{{ url('barangmasuk_kemasan/get_proses')}} ",
			type: 'post',
			data: {id : id, proses:proses},
			dataType : 'json',
			headers : {
				'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			},
			success: function(respon){
				
				if(respon.length > 0){
					for(i in respon){
						
						table_hasil.row.add(['<div><center></center></div>',
							'<div id="list_kode'+respon[i].id_barangkeluar_kb+'">'+respon[i].kode_barang+'</div>',
							'<div id="list_nama'+respon[i].id_barangkeluar_kb+'">'+respon[i].nama_barang+'</div>',
							'<div id="list_komposisi'+respon[i].id_barangkeluar_kb+'">'+respon[i].nama_komposisi+'</div>',
							'<div id="list_jumlah'+respon[i].id_barangkeluar_kb+'"></div>',
							// '<div id="list_jumlah_konv'+respon[i].id_barangkeluar_kb+'"></div>',
							'<div id="list_namasatuan'+respon[i].id_barangkeluar_kb+'"></div>',
							'<div id="list_gudang'+respon[i].id_barangkeluar_kb+'"></div>',
							'<div id="list_corak'+respon[i].id_barangkeluar_kb+'">'+respon[i].nama_corak+'</div>',
							'<div id="list_keterangan'+respon[i].id_barangkeluar_kb+'">'+respon[i].keterangan+'</div>',
							'<div><button type="button" id="btnedit'+respon[i].id_barangkeluar_kb+'" class="btn bg-warning-400" onclick="edit_table('+respon[i].id_barangkeluar_kb+')"><i class="icon-pencil"></i> </button> <button class="btn bg-danger-800" type="button" onclick="hapus($(this))"><i class="icon-eraser"></i></button></div>'+
							'<input type="hidden" id="tabel_idtable'+respon[i].id_barangkeluar_kb+'" name="tabel_idtable[]" value="">'+
							'<input type="hidden" name="tabel_id[]" class="tabel_id" id="tabel_id'+respon[i].id_barangkeluar_kb+'" value="'+respon[i].id_barangkeluar_kb+'">'+
							'<input type="hidden" name="tabel_idbarang[]" id="tabel_idbarang'+respon[i].id_barangkeluar_kb+'" value="'+respon[i].id_barang+'">'+
							'<input type="hidden" name="tabel_idgudang[]" id="tabel_idgudang'+respon[i].id_barangkeluar_kb+'">'+
							'<input type="hidden" name="tabel_jumlah[]" id="tabel_jumlah'+respon[i].id_barangkeluar_kb+'" value="'+respon[i].stok+'">'+
							'<input type="hidden" name="tabel_jumlah_konv[]" id="tabel_jumlah_konv'+respon[i].id_barangkeluar_kb+'">'+
							'<input type="hidden" name="tabel_stok[]" id="tabel_stok'+respon[i].id_barangkeluar_kb+'" value="'+respon[i].stok+'">'+
							'<input type="hidden" name="tabel_stok_konv[]" id="tabel_stok_konv'+respon[i].id_barangkeluar_kb+'" value="'+respon[i].jumlah_konversi+'">'+
							'<input type="hidden" name="tabel_satuanjumlah[]" id="tabel_satuanjumlah'+respon[i].id_barangkeluar_kb+'" value="'+respon[i].satuan_jumlah+'">'+
							'<input type="hidden" name="tabel_satuanjumlah_konv[]" id="tabel_satuanjumlah_konv'+respon[i].id_barangkeluar_kb+'" value="'+respon[i].satuanjumlah_konversi+'">'+
							'<input type="hidden" name="tabel_komposisi[]" id="tabel_komposisi'+respon[i].id_barangkeluar_kb+'" value="'+respon[i].nama_komposisi+'">'+
							'<input type="hidden" name="tabel_idkomposisi[]" id="tabel_idkomposisi'+respon[i].id_barangkeluar_kb+'" value="'+respon[i].id_komposisi+'">'+
							'<input type="hidden" name="tabel_idsatuan[]" id="tabel_idsatuan'+respon[i].id_barangkeluar_kb+'" value="">'+
							'<input type="hidden" name="tabel_idcorak[]" id="tabel_idcorak'+respon[i].id_barangkeluar_kb+'" value="'+respon[i].id_corak+'">'+
							'<input type="hidden" name="tabel_idmotif[]" id="tabel_idmotif'+respon[i].id_barangkeluar_kb+'" value="'+respon[i].id_motif+'">'+
							'<input type="hidden" name="tabel_idkualitas[]" id="tabel_idkualitas'+respon[i].id_barangkeluar_kb+'" value="'+respon[i].id_kualitas+'">'+
							'<input type="hidden" name="tabel_iddudul[]" id="tabel_iddudul'+respon[i].id_barangkeluar_kb+'" value="'+respon[i].id_kualitas_dudul+'">'+
							'<input type="hidden" name="tabel_idlabel[]" id="tabel_idlabel'+respon[i].id_barangkeluar_kb+'" value="'+respon[i].id_label+'">'+
							'<input type="hidden" name="tabel_idkemasan[]" id="tabel_idkemasan'+respon[i].id_barangkeluar_kb+'" value="'+respon[i].id_kemasan+'">'+
							'<input type="hidden" name="tabel_idkemasansatuan[]" id="tabel_idkemasansatuan'+respon[i].id_barangkeluar_kb+'" value="'+respon[i].id_kemasansatuan+'">'+
							'<input type="hidden" name="tabel_idkemasansepuluh[]" id="tabel_idkemasansepuluh'+respon[i].id_barangkeluar_kb+'" value="'+respon[i].id_kemasansepuluh+'">'+
							'<input type="hidden" name="tabel_idkemasanseratus[]" id="tabel_idkemasanseratus'+respon[i].id_barangkeluar_kb+'" value="'+respon[i].id_kemasanseratus+'">'+
							'<input type="hidden" name="tabel_idcap[]" id="tabel_idcap'+respon[i].id_barangkeluar_kb+'" value="'+respon[i].id_cap+'">'+
							'<input type="hidden" name="tabel_idkualitasproses[]" id="tabel_idkualitasproses'+respon[i].id_barangkeluar_kb+'" value="'+respon[i].id_kualitas_proses+'">'+
							'<input type="hidden" name="tabel_idkualitasperiksa[]" id="tabel_idkualitasperiksa'+respon[i].id_barangkeluar_kb+'" value="'+respon[i].id_kualitas_periksa+'">'+
							'<input type="hidden" name="tabel_idworkorder[]" id="tabel_idworkorder'+respon[i].id_barangkeluar_kb+'" value="'+respon[i].id_workorder_barang+'">'+
							'<input type="hidden" name="tabel_idperubahansatuan[]" id="tabel_idperubahansatuan'+respon[i].id_barangkeluar_kb+'" value="'+respon[i].id_perubahansatuan+'">'+
							'<input type="hidden" name="tabel_rencanajumlah[]" id="tabel_rencanajumlah'+respon[i].id_barangkeluar_kb+'" value="'+respon[i].jumlah_rencana+'">'+
							'<input type="hidden" name="tabel_keterangan[]" id="tabel_keterangan'+respon[i].id_barangkeluar_kb+'" value="'+respon[i].keterangan+'">'+

							'<input type="hidden" name="tabel_kode[]" id="tabel_kode'+respon[i].id_barangkeluar_kb+'" value="'+respon[i].kode_barang+'">'+
							'<input type="hidden" name="tabel_nama[]" id="tabel_nama'+respon[i].id_barangkeluar_kb+'" value="'+respon[i].nama_barang+'">'+
							'<input type="hidden" name="tabel_namasatuan[]" id="tabel_namasatuan'+respon[i].id_barangkeluar_kb+'" value="">'+
							'<input type="hidden" name="tabel_namagudang[]" id="tabel_namagudang'+respon[i].id_barangkeluar_kb+'" value="">'
							
							]).draw(false);
							$('.select-search').select2();
							/*$("#tabel_jumlah"+respon[i].id).keyup(function(){
								var p_jml = $(this).parents('tr').find('.tabel_jumlah').val();
								var p_upah = $(this).parents('tr').find('.tabel_upah').val();
								var id = $(this).parents('tr').find('.tabel_id').val();
								get_proses_jml(p_jml,p_upah,id);
								
							})*/
					}

				}
				
			}
		})
	}

	function get_edit(id){
		$.ajax({
			url: '{{ url('barangmasuk_kemasan/get_edit') }}',
			type: 'post',
			dataType: 'json',
			data: { id : id },
			headers : {
				'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			},
			success: function(respon){
				if(respon.length > 0){
					for(i in respon){
						
						table_hasil.row.add(['<div><center></center></div>',
							'<div id="list_kode'+respon[i].id_barangmasuk_kb+'">'+respon[i].kode_barang+'</div>',
							'<div id="list_nama'+respon[i].id_barangmasuk_kb+'">'+respon[i].nama_barang+'</div>',
							'<div id="list_komposisi'+respon[i].id_barangmasuk_kb+'">'+respon[i].nama_komposisi+'</div>',
							'<div id="list_jumlah'+respon[i].id_barangmasuk_kb+'">'+respon[i].jumlah+'</div>',
							// '<div id="list_jumlah_konv'+respon[i].id_barangmasuk_kb+'"></div>',
							'<div id="list_namasatuan'+respon[i].id_barangmasuk_kb+'">'+respon[i].nama_satuan+'</div>',
							'<div id="list_gudang'+respon[i].id_barangmasuk_kb+'">'+respon[i].nama_gudang+'</div>',
							'<div id="list_corak'+respon[i].id_barangmasuk_kb+'">'+respon[i].nama_corak+'</div>',
							'<div id="list_keterangan'+respon[i].id_barangmasuk_kb+'">'+respon[i].keterangan+'</div>',
							'<div><button type="button" id="btnedit'+respon[i].id_barangmasuk_kb+'" class="btn bg-warning-400" onclick="edit_table('+respon[i].id_barangmasuk_kb+')"><i class="icon-pencil"></i> </button> <button class="btn bg-danger-800" type="button" onclick="hapus($(this))"><i class="icon-eraser"></i></button></div>'+
							'<input type="hidden" id="tabel_idtable'+respon[i].id_barangmasuk_kb+'" name="tabel_idtable[]" value="'+respon[i].id_barangmasuk_kb+'">'+
							'<input type="hidden" name="tabel_id[]" class="tabel_id" id="tabel_id'+respon[i].id_barangmasuk_kb+'" value="'+respon[i].id_barangmasuk_kb+'">'+
							'<input type="hidden" name="tabel_idbarang[]" id="tabel_idbarang'+respon[i].id_barangmasuk_kb+'" value="'+respon[i].id_barang+'">'+
							'<input type="hidden" name="tabel_idgudang[]" id="tabel_idgudang'+respon[i].id_barangmasuk_kb+'" value="'+respon[i].id_gudang+'">'+
							'<input type="hidden" name="tabel_jumlah[]" id="tabel_jumlah'+respon[i].id_barangmasuk_kb+'" value="'+respon[i].jumlah+'">'+
							'<input type="hidden" name="tabel_jumlah_konv[]" id="tabel_jumlah_konv'+respon[i].id_barangmasuk_kb+'">'+
							'<input type="hidden" name="tabel_stok[]" id="tabel_stok'+respon[i].id_barangmasuk_kb+'" value="'+respon[i].jumlah+'">'+
							'<input type="hidden" name="tabel_stok_konv[]" id="tabel_stok_konv'+respon[i].id_barangmasuk_kb+'" value="'+respon[i].jumlah_konversi+'">'+
							'<input type="hidden" name="tabel_satuanjumlah[]" id="tabel_satuanjumlah'+respon[i].id_barangmasuk_kb+'" value="'+respon[i].satuan_jumlah+'">'+
							'<input type="hidden" name="tabel_satuanjumlah_konv[]" id="tabel_satuanjumlah_konv'+respon[i].id_barangmasuk_kb+'" value="'+respon[i].satuanjumlah_konversi+'">'+
							'<input type="hidden" name="tabel_komposisi[]" id="tabel_komposisi'+respon[i].id_barangmasuk_kb+'" value="'+respon[i].nama_komposisi+'">'+
							'<input type="hidden" name="tabel_idkomposisi[]" id="tabel_idkomposisi'+respon[i].id_barangmasuk_kb+'" value="'+respon[i].id_komposisi+'">'+
							'<input type="hidden" name="tabel_idsatuan[]" id="tabel_idsatuan'+respon[i].id_barangmasuk_kb+'" value="'+respon[i].id_satuan+'">'+
							'<input type="hidden" name="tabel_idcorak[]" id="tabel_idcorak'+respon[i].id_barangmasuk_kb+'" value="'+respon[i].id_corak+'">'+
							'<input type="hidden" name="tabel_idmotif[]" id="tabel_idmotif'+respon[i].id_barangmasuk_kb+'" value="'+respon[i].id_motif+'">'+
							'<input type="hidden" name="tabel_idkualitas[]" id="tabel_idkualitas'+respon[i].id_barangmasuk_kb+'" value="'+respon[i].id_kualitas+'">'+
							'<input type="hidden" name="tabel_iddudul[]" id="tabel_iddudul'+respon[i].id_barangmasuk_kb+'" value="'+respon[i].id_kualitas_dudul+'">'+
							'<input type="hidden" name="tabel_idlabel[]" id="tabel_idlabel'+respon[i].id_barangmasuk_kb+'" value="'+respon[i].id_label+'">'+
							'<input type="hidden" name="tabel_idkemasan[]" id="tabel_idkemasan'+respon[i].id_barangmasuk_kb+'" value="'+respon[i].id_kemasan+'">'+
							'<input type="hidden" name="tabel_idkemasansatuan[]" id="tabel_idkemasansatuan'+respon[i].id_barangmasuk_kb+'" value="'+respon[i].id_kemasansatuan+'">'+
							'<input type="hidden" name="tabel_idkemasansepuluh[]" id="tabel_idkemasansepuluh'+respon[i].id_barangmasuk_kb+'" value="'+respon[i].id_kemasansepuluh+'">'+
							'<input type="hidden" name="tabel_idkemasanseratus[]" id="tabel_idkemasanseratus'+respon[i].id_barangmasuk_kb+'" value="'+respon[i].id_kemasanseratus+'">'+
							'<input type="hidden" name="tabel_idcap[]" id="tabel_idcap'+respon[i].id_barangmasuk_kb+'" value="'+respon[i].id_cap+'">'+
							'<input type="hidden" name="tabel_idkualitasproses[]" id="tabel_idkualitasproses'+respon[i].id_barangmasuk_kb+'" value="'+respon[i].id_kualitas_proses+'">'+
							'<input type="hidden" name="tabel_idkualitasperiksa[]" id="tabel_idkualitasperiksa'+respon[i].id_barangmasuk_kb+'" value="'+respon[i].id_kualitas_periksa+'">'+
							'<input type="hidden" name="tabel_idworkorder[]" id="tabel_idworkorder'+respon[i].id_barangmasuk_kb+'" value="'+respon[i].id_workorder_barang+'">'+
							'<input type="hidden" name="tabel_idperubahansatuan[]" id="tabel_idperubahansatuan'+respon[i].id_barangmasuk_kb+'" value="'+respon[i].id_perubahansatuan+'">'+
							'<input type="hidden" name="tabel_rencanajumlah[]" id="tabel_rencanajumlah'+respon[i].id_barangmasuk_kb+'" value="'+respon[i].jumlah_rencana+'">'+
							'<input type="hidden" name="tabel_keterangan[]" id="tabel_keterangan'+respon[i].id_barangmasuk_kb+'" value="'+respon[i].keterangan+'">'+

							'<input type="hidden" name="tabel_kode[]" id="tabel_kode'+respon[i].id_barangmasuk_kb+'" value="'+respon[i].kode_barang+'">'+
							'<input type="hidden" name="tabel_nama[]" id="tabel_nama'+respon[i].id_barangmasuk_kb+'" value="'+respon[i].nama_barang+'">'+
							'<input type="hidden" name="tabel_namasatuan[]" id="tabel_namasatuan'+respon[i].id_barangmasuk_kb+'" value="">'+
							'<input type="hidden" name="tabel_namagudang[]" id="tabel_namagudang'+respon[i].id_barangmasuk_kb+'" value="">'
							
							]).draw(false);
							$('.select-search').select2();
							/*$("#tabel_jumlah"+respon[i].id).keyup(function(){
								var p_jml = $(this).parents('tr').find('.tabel_jumlah').val();
								var p_upah = $(this).parents('tr').find('.tabel_upah').val();
								var id = $(this).parents('tr').find('.tabel_id').val();
								get_proses_jml(p_jml,p_upah,id);
								
							})*/
					}

				}
			}
		})
	}

	function hapus(d){
		table_hasil.row(d.parents('tr')).remove().draw();
	}

	function get_konversi(id_barang){
		$.ajax({
			url: "{{ url('barangkeluar/get_konversi')}} ",
			type: 'post',
			data: {id : id_barang},
			headers : {
				'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			},
			success: function(result){
				if(result.length > 0){
					var n = parseInt(result[0].nilai_akhir)/parseInt(result[0].nilai_awal);
					$("[name=store_konversi]").val(n);
				}else{
					
				}
			}
		})
	}

	$("[name=popup_jumlah]").keyup(function(){
		var jum = parseFloat($("[name=popup_jumlah]").val());
		if(isNaN(jum) || jum == 0 || jum == ''){
			jum = parseFloat(0);
		}
		var nilai = parseFloat($("[name=store_konversi]").val());

		var tot = jum*nilai;
		$("[name=popup_jumlah_konv]").val(tot);
	})

	$("[name=popup_jumlah_konv]").keyup(function(){
		var jum = parseFloat($("[name=popup_jumlah]").val());
		if(isNaN(jum) || jum == 0 || jum == ''){
			jum = parseFloat(0);
		}
		var nilai = parseFloat($("[name=store_konversi]").val());

		var tot = jum*nilai;
		$("[name=popup_jumlah]").val(tot);
	})

	function get_nomor(this_){
        //var tgl = this_.val();
        var id_lokasi = {{$data['detail']->id_lokasi }};
        $.ajax({
            url: "{{ url('barangmasuk_kemasan/get_nomor') }}",
            type: 'get',
            dataType: 'json',
            data: {id : $("[name=id_barangmasuk]").val() , tgl : '', id_lokasi : id_lokasi},
            success: function(respon){
                $("[name=nomor").val(respon.nomor);
                $("[name=nomor_ext]").val(respon.faktur);
            }
        })


    }
</script>
@endsection