@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_atm/simpan_tenun') }}" autocomplete="off">
	    	<input type="hidden" name="_token" value="{{ csrf_token() }}">
	    	<input type="hidden" name="id_barangmasuk" value="{{ $data['d_kemasan']['id_barangmasuk'] }}">
	    	<input type="hidden" name="id_barangkeluar" value="">
	    	<input type="hidden" name="barangkeluar" value="">
	    	<input type="hidden" name="id_lokasi" value="{{ $data['detail']->id_lokasi }}">
        	<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'] == '') ? date('d-m-Y'):$data['d_kemasan']['tanggal'] }}" 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">No. SPK</label>
        			<div class="col-sm-8">
        				<input class="form-control" type="text" name="no_workorder" placeholder="" value="{{ $data['detail']->no_workorder_barang }}" 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 class="form-group">
        			<label class="control-label col-sm-4">Status SPK</label>
        			<div class="col-sm-8"> @php $status_wo = $data['detail']->status_workorder; @endphp
        				<select class="form-control select-search" name="status_workorder">
        					<option value="0" {{ ($status_wo == 0) ? "selected":"" }}>Belum Selesai</option>
        					<option value="1" {{ ($status_wo == 1) ? "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">Mesin</label>
        			<div class="col-sm-8">
        				
        				<input class="form-control" type="text" name="mesin" placeholder="" value="{{ $data['detail']->nama_mesin }}" 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">No. Order</label>
        			<div class="col-sm-8">
        				<input class="form-control" type="text" name="no_workorder_barang" placeholder="" value="{{ $data['detail']->no_workorder_barang_bb }}" 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>
        	<input type="hidden" name="id_rekanan" value="{{ $data['detail']->id_rekanan }}">
        	<input type="hidden" name="id_mesin" value="{{ $data['detail']->id_mesin }}">

        	<input type="hidden" name="id_workorder_barang" value="{{ $data['detail']->id_workorder_barang_bb }}">
        	
        	<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>Tanggal</th>
								<th>Kode Barang</th>
								<th>Nama Barang</th>
								<th>Warna</th>
								<th>Gudang</th>
								<th>Jumlah</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['barang_keluar'] as $d) 
							<tr>
								<td>{{$no++}}</td>
								<th>{{ tgl_full($d->tanggal, '') }}</th>
								<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_kualitas_proses }}</td>
								<td>{{ $d->nama_corak }}</td>
								<td>{{ $d->nama_motif }}</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>
            
            <div class="col-sm-12 form-group table-responsive">
	        	<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>Jumlah</th>
								<th>Satuan</th>
								<th>Gudang</th>								
								<th>Motif</th>
								<th>Warna</th>
								<th>Panjang (cm)</th>
								<th>Lebar (cm)</th>
								<th>Pick</th>
								<th>Kualitas Tenun</th>
								<th>Kualitas Proses</th>
								<th>Aksi</th>
							</tr>
						</thead>
			    	</table>
        	</div>
        	<div class="col-sm-12">
        	<a href="{{url('barangmasuk_atm')}}" class="btn bg-warning-400">Kembali</a>
            <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">
	      			<input type="hidden" name="popup_idlist">
	      			<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 </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</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 }}" nama="{{ $s->nama_satuan }}">{{ $s->nama_satuan }}</option>
	      			 			@php
		      			 		}
		      			 		@endphp
	      			 		</select>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<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">
	      				<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="" nama="Tanpa Warna">Tanpa Warna</option>
	      			 			@php
	      			 			foreach($data['warna'] as $w){ @endphp
	      			 				<option value="{{ $w->id_komposisi }}" nama="{{ $w->nama }}">{{ $w->nama.' ('.$w->inisial.')' }}</option>
	      			 			@php
		      			 		}
		      			 		@endphp
	      			 		</select>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Panjang (cm)</label>
	      				<div class="col-sm-8">	
	      			 		<input type="text" name="popup_panjang" class="form-control number-only">
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Lebar (cm)</label>
	      				<div class="col-sm-8">	
	      			 		<input type="text" name="popup_lebar" class="form-control number-only">
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Pick</label>
	      				<div class="col-sm-8">	
	      			 		<input type="text" name="popup_pick" class="form-control number-only">
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Kualitas Tenun</label>
	      				<div class="col-sm-8">	
	      			 		<select name="popup_kualitas" 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">
	      				<label class="control-label col-sm-4">Kualitas Proses</label>
	      				<div class="col-sm-8">	
	      			 		<select name="popup_kualitas_proses" 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> 
	      			<!---- Shift ---->
	        		<div class="form-group">
	        			<label class="control-label col-sm-4">Shit</label>
	        			<div class="col-sm-8">
	        				<select class="form-control select-search" name="popup_shift">
	        					
	        				</select>
	        			</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">
<input type="hidden" name="store_idproses" placeholder="" value="{{ $data['detail']->id_proses }}"/>
<input type="hidden" name="store_namaproses" placeholder="" value="{{ strtolower($data['detail']->nama_proses) }}"/>
<input type="hidden" name="store_idbarangkeluar" value="{{ $data['detail']->id_barangkeluar }}">

<script type="text/javascript">
	$("#btn_tambah_item").click(function(){
		$("[name=popup_id_table]").val('');
		$("[name=popup_idlist]").val('');
		$("[name=popup_barang]").val(null).trigger('change');
		$("[name=popup_gudang]").val(null).trigger('change');
		$("[name=popup_jumlah]").val('');
		$("[name=popup_upah]").val('');
		$("[name=popup_panjang]").val('');
		$("[name=popup_lebar]").val('');
		$("[name=popup_pick]").val('');
		$("[name=popup_kualitas]").val(null).trigger('change');
		$("[name=popup_satuan]").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_komposisi]").val(null).trigger('change');
		$("[name=popup_kualitas_proses]").val(null).trigger('change');
		$("[name=popup_shift]").val(null).trigger('change');

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

	var table_barang;
	var table_hasil;
	var tb_no = parseInt(10000);
	var tb_get = parseInt(20000);
	var id_proses;
	var nama_proses;
	var id;
	var proses;
	var id_mesin = {{ $data['detail']->id_mesin }};

	$(document).ready(function(){
		table_barang = $("#table_barang").DataTable();
		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();

        id = $("[name=id_barangmasuk]").val();
        id_proses = $("[name=store_idproses]").val();
        nama_proses = $("[name=store_namaproses]").val();
        if(id == ''){
        	get_proses($("[name=store_idbarangkeluar]").val(), id_proses);
        }else{
        	get_edit(id);
        }
        get_shift();

        get_nomor();
	})

	// --- shift ------
	function get_shift(){
		$.ajax({
			url: '{{ url('barangmasuk_atm/get_shift') }}',
			data: {id_mesin : id_mesin},
			success: function(respon){
				$("[name=popup_shift]").html('');
				$("[name=popup_shift]").append('<option value="">--- Pilih shift ---</option>');
				if(respon.length > 0){
					for(i in respon){
						$("[name=popup_shift]").append('<option value="'+respon[i].id_shift+'" nama="'+respon[i].nama_shift+'" jam="'+respon[i].jam+'">'+respon[i].nama_shift+' ('+respon[i].jam_masuk+' - '+respon[i].jam_pulang+')</option>');
					}
				}
			}
		})
	}

	$("#btn_popup_simpan").click(function(){
		var id_data = $("[name=popup_id_table]").val();
		var id_list = $("[name=popup_idlist]").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('nama');

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

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

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

		var panjang = $("[name=popup_panjang]").val();
		var lebar = $("[name=popup_lebar]").val();
		var pick = $("[name=popup_pick]").val();

		var id_kualitas_proses = $("[name=popup_kualitas_proses]").val();
		var nama_kualitas_proses = $("[name=popup_kualitas_proses] :selected").attr('nama');

		// shift
		var id_shift = $("[name=popup_shift]").val();
		var nama_shift = $("[name=popup_shift] :selected").attr('nama');
		var jam_masuk = $("[name=popup_shift] :selected").attr('masuk');
		var jam_pulang = $("[name=popup_shift] :selected").attr('pulang');

		if(id_barang != '' && jumlah != '' && id_gudang != '' && satuan != '' && motif != ''){


			if(id_list == ''){
				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_jumlah'+tb_no+'">'+jumlah+'</div>',
							'<div id="list_namasatuan'+tb_no+'">'+nama_satuan+'</div>',
							'<div id="list_gudang'+tb_no+'">'+nama_gudang+'</div>',
							'<div id="list_motif'+tb_no+'">'+motif+'</div>',
							'<div id="list_komposisi'+tb_no+'">'+nama_komposisi+'</div>',
							'<div id="list_panjang'+tb_no+'">'+panjang+'</div>',
							'<div id="list_lebar'+tb_no+'">'+lebar+'</div>',
							'<div id="list_pick'+tb_no+'">'+pick+'</div>',
							'<div id="list_kualitas'+tb_no+'">'+kualitas+'</div>',
							'<div id="list_kualitas_proses'+tb_no+'">'+nama_kualitas_proses+'</div>',
							'<div><button type="button" id="btnedit'+tb_no+'" 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_idsatuan[]" id="tabel_idsatuan'+tb_no+'" value="'+satuan+'">'+
							'<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_panjang[]" id="tabel_panjang'+tb_no+'" value="'+panjang+'">'+
							'<input type="hidden" name="tabel_lebar[]" id="tabel_lebar'+tb_no+'" value="'+lebar+'">'+
							'<input type="hidden" name="tabel_pick[]" id="tabel_pick'+tb_no+'" value="'+pick+'">'+
							'<input type="hidden" name="tabel_idkualitas_proses[]" id="tabel_idkualitas_proses'+tb_no+'" value="'+id_kualitas_proses+'">'+
							'<input type="hidden" name="tabel_idkomposisi[]" id="tabel_idkomposisi'+tb_no+'" value="'+komposisi+'">'+
							'<input type="hidden" name="tabel_idshift[]" id="tabel_idshift'+tb_no+'" value="'+id_shift+'">'+
							'<input type="hidden" name="tabel_namashift[]" id="tabel_namashift'+tb_no+'" value="'+nama_shift+'">'
							]).draw(false);

				tb_no++;
			}else{
				$("#list_kode"+id_list).text(kode_barang);
				$("#list_nama"+id_list).text(nama_barang);
				$("#list_motif"+id_list).text(motif);
				$("#list_gudang"+id_list).text(nama_gudang);
				$("#list_jumlah"+id_list).text(jumlah);
				$("#list_namasatuan"+id_list).text(nama_satuan);
				$("#list_kualitas"+id_list).text(kualitas);
				$("#list_panjang"+id_list).text(panjang);
				$("#list_lebar"+id_list).text(lebar);
				$("#list_pick"+id_list).text(pick);
				$("#list_kualitas_proses"+id_list).text(nama_kualitas_proses);
				$("#list_komposisi"+id_list).text(nama_komposisi);
				

				$("#tabel_id"+id_list).val(id_list);
				$("#tabel_idbarang"+id_list).val(id_barang);
				$("#tabel_idgudang"+id_list).val(id_gudang);
				$("#tabel_namabarang"+id_list).val(nama_barang);				
				$("#tabel_idmotif"+id_list).val(id_motif);
				$("#tabel_jumlah"+id_list).val(jumlah);
				$("#tabel_idsatuan"+id_list).val(satuan);
				$("#tabel_idkualitas"+id_list).val(id_kualitas);
				$("#tabel_panjang"+id_list).val(panjang);
				$("#tabel_lebar"+id_list).val(lebar);
				$("#tabel_pick"+id_list).val(pick);
				$("#tabel_idkualitas_proses"+id_list).val(id_kualitas_proses);
				$("#tabel_idkomposisi"+id_list).val(komposisi);

				//--- shift
				$("#tabel_idshift"+id_list).val(id_shift);
				$("#tabel_namashift"+id_list).val(nama_shift);


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

	function get_proses(id,proses){
		
		$.ajax({
			url: "{{ url('barangmasuk_atm/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'+tb_get+'"></div>',
							'<div id="list_nama'+tb_get+'"></div>',
							'<div id="list_jumlah'+tb_get+'"></div>',
							'<div id="list_namasatuan'+tb_get+'"></div>',
							'<div id="list_gudang'+tb_get+'"></div>',
							'<div id="list_motif'+tb_get+'">'+respon[i].nama_motif+'</div>',
							'<div id="list_komposisi'+tb_get+'">'+respon[i].nama_komposisi+'</div>',
							'<div id="list_panjang'+tb_get+'"></div>',
							'<div id="list_lebar'+tb_get+'"></div>',
							'<div id="list_pick'+tb_get+'"></div>',
							'<div id="list_kualitas'+tb_get+'"></div>',
							'<div id="list_kualitas_proses'+tb_get+'"></div>',

							'<div><button type="button" id="btnedit'+tb_get+'" class="btn bg-warning-400" onclick="edit_table('+tb_get+')"><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_get+'" name="tabel_idtable[]" value="">'+
							'<input type="hidden" name="tabel_id[]" class="tabel_id" id="tabel_id'+tb_get+'" value="'+tb_get+'">'+
							'<input type="hidden" name="tabel_idbarang[]" id="tabel_idbarang'+tb_get+'" value="">'+
							'<input type="hidden" name="tabel_idgudang[]" id="tabel_idgudang'+tb_get+'" value="">'+
							'<input type="hidden" name="tabel_jumlah[]" id="tabel_jumlah'+tb_get+'" value="">'+
							'<input type="hidden" name="tabel_idsatuan[]" id="tabel_idsatuan'+tb_get+'" value="">'+
							'<input type="hidden" name="tabel_idmotif[]" id="tabel_idmotif'+tb_get+'" value="'+respon[i].id_motif+'">'+
							'<input type="hidden" name="tabel_idkualitas[]" id="tabel_idkualitas'+tb_get+'" value="">'+
							'<input type="hidden" name="tabel_panjang[]" id="tabel_panjang'+tb_get+'" value="">'+
							'<input type="hidden" name="tabel_lebar[]" id="tabel_lebar'+tb_get+'" value="">'+
							'<input type="hidden" name="tabel_pick[]" id="tabel_pick'+tb_get+'" value="">'+
							'<input type="hidden" name="tabel_idkualitas_proses[]" id="tabel_idkualitas_proses'+tb_get+'" value="">'+
							'<input type="hidden" name="tabel_idkomposisi[]" id="tabel_idkomposisi'+tb_get+'" value="'+respon[i].id_komposisi+'">'+
							'<input type="hidden" name="tabel_idshift[]" id="tabel_idshift'+tb_get+'" value="">'+
							'<input type="hidden" name="tabel_namashift[]" id="tabel_namashift'+tb_get+'" value="">'
							
							]).draw(false);
							$('.select-search').select2();
					}

				}
				
			}
		})
	}

	function edit_table(id){
		var tabel_id = $("#tabel_id"+id).val();
		var tabel_idbarang = $("#tabel_idbarang"+id).val();
		var tabel_idgudang = $("#tabel_idgudang"+id).val();
		var tabel_namabarang = $("#tabel_namabarang"+id).val();
		var tabel_idmotif = $("#tabel_idmotif"+id).val();
		var tabel_jumlah = $("#tabel_jumlah"+id).val();
		var tabel_idsatuan = $("#tabel_idsatuan"+id).val();
		var tabel_idkualitas = $("#tabel_idkualitas"+id).val();
		var tabel_panjang = $("#tabel_panjang"+id).val();
		var tabel_lebar = $("#tabel_lebar"+id).val();
		var tabel_pick = $("#tabel_pick"+id).val();
		var tabel_idkualitasproses = $("#tabel_idkualitas_proses"+id).val();
		var tabel_idkomposisi = $("#tabel_idkomposisi"+id).val();

		//--- Shift
		var id_shift = $("#tabel_idshift"+id).val();
		var nama_shift = $("#tabel_namashift"+id).val();


		$("[name=popup_idlist]").val(id);
		$("[name=popup_barang]").val(tabel_idbarang).trigger('change');
		$("[name=popup_gudang]").val(tabel_idgudang).trigger('change');
		$("[name=popup_jumlah]").val(tabel_jumlah);
		$("[name=popup_panjang]").val(tabel_panjang);
		$("[name=popup_lebar]").val(tabel_lebar);
		$("[name=popup_pick]").val(tabel_pick);
		$("[name=popup_kualitas]").val(tabel_idkualitas).trigger('change');
		$("[name=popup_satuan]").val(tabel_idsatuan).trigger('change');
		$("[name=popup_komposisi]").val(tabel_id).trigger('change');
		$("[name=popup_motif]").val(tabel_idmotif).trigger('change');
		$("[name=popup_kualitas_proses]").val(tabel_idkualitasproses).trigger('change');
		$("[name=popup_komposisi]").val(tabel_idkomposisi).trigger('change');

		//-- Shift
		$("[name=popup_shift]").val(id_shift).trigger('change');

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

	function get_edit(id){
		$.ajax({
			url: '{{ url('barangmasuk_atm/get_tenunedit') }}',
			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+'">'+respon[i].kode_barang+'</div>',
							'<div id="list_nama'+respon[i].id+'">'+respon[i].nama_barang+'</div>',
							'<div id="list_jumlah'+respon[i].id+'">'+respon[i].jumlah+'</div>',
							'<div id="list_namasatuan'+respon[i].id+'">'+respon[i].nama_satuan+'</div>',
							'<div id="list_gudang'+respon[i].id+'">'+respon[i].nama_gudang+'</div>',
							'<div id="list_motif'+respon[i].id+'">'+respon[i].nama_motif+'</div>',
							'<div id="list_komposisi'+respon[i].id+'">'+respon[i].nama_komposisi+'</div>',
							'<div id="list_panjang'+respon[i].id+'">'+respon[i].panjang+'</div>',
							'<div id="list_lebar'+respon[i].id+'">'+respon[i].lebar+'</div>',
							'<div id="list_pick'+respon[i].id+'">'+respon[i].pick+'</div>',
							'<div id="list_kualitas'+respon[i].id+'">'+respon[i].nama_kualitas+'</div>',
							'<div id="list_kualitas_proses'+respon[i].id+'">'+respon[i].nama_kualitas_proses+'</div>',

							'<div><button type="button" id="btnedit'+respon[i].id+'" class="btn bg-warning-400" onclick="edit_table('+respon[i].id+')"><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+'" name="tabel_idtable[]" value="'+respon[i].id+'">'+
							'<input type="hidden" name="tabel_id[]" class="tabel_id" id="tabel_id'+respon[i].id+'" value="'+respon[i].id+'">'+
							'<input type="hidden" name="tabel_idbarang[]" id="tabel_idbarang'+respon[i].id+'" value="'+respon[i].id_barang+'">'+
							'<input type="hidden" name="tabel_idgudang[]" id="tabel_idgudang'+respon[i].id+'" value="'+respon[i].id_gudang+'">'+
							'<input type="hidden" name="tabel_jumlah[]" id="tabel_jumlah'+respon[i].id+'" value="'+respon[i].jumlah+'">'+
							'<input type="hidden" name="tabel_idsatuan[]" id="tabel_idsatuan'+respon[i].id+'" value="'+respon[i].id_satuan+'">'+
							'<input type="hidden" name="tabel_idmotif[]" id="tabel_idmotif'+respon[i].id+'" value="'+respon[i].id_motif+'">'+
							'<input type="hidden" name="tabel_idkualitas[]" id="tabel_idkualitas'+respon[i].id+'" value="'+respon[i].id_kualitas+'">'+
							'<input type="hidden" name="tabel_panjang[]" id="tabel_panjang'+respon[i].id+'" value="'+respon[i].panjang+'">'+
							'<input type="hidden" name="tabel_lebar[]" id="tabel_lebar'+respon[i].id+'" value="'+respon[i].lebar+'">'+
							'<input type="hidden" name="tabel_pick[]" id="tabel_pick'+respon[i].id+'" value="'+respon[i].pick+'">'+
							'<input type="hidden" name="tabel_idkualitas_proses[]" id="tabel_idkualitas_proses'+respon[i].id+'" value="'+respon[i].id_kualitas_proses+'">'+
							'<input type="hidden" name="tabel_idkomposisi[]" id="tabel_idkomposisi'+respon[i].id+'" value="'+respon[i].id_komposisi+'">'+
							'<input type="hidden" name="tabel_idshift[]" id="tabel_idshift'+respon[i].id+'" value="'+respon[i].id_shift+'">'+
							'<input type="hidden" name="tabel_namashift[]" id="tabel_namashift'+respon[i].id+'" value="'+respon[i].nama_shift+'">'

							]).draw(false);
					}
				}
			}
		})
	}

	function get_nomor(this_){
        //var tgl = this_.val();
        var id_lokasi = {{ $data['detail']->id_lokasi }};
        $.ajax({
            url: "{{ url('barangmasuk_atm/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);
            }
        })


    }

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

</script>
@endsection