@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">Pengembalian Barang</li>
		</ul>
	</div>
</div>

<div class="content">
	<div class="panel panel-flat">
		<div class="panel-heading">
			<h5 class="panel-title">Form Input Pengembalian Barang</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('kembaliseluruh/simpan') }}" autocomplete="off">
	    	<input type="hidden" name="_token" value="{{ csrf_token() }}">
	    	<input type="hidden" name="id_kembalibarang" value="{{ $data['form_data']['id_kembali'] }}">
	    	<div class="col-sm-6">
	    		<div class="form-group">
		    		<label class="control-label col-sm-4">Tanggal</label>
		    		<div class="col-sm-8">
		    			<input type="text" name="tanggal" id="tanggal" class="form-control datepicker" value="{{ ($data['form_data']['tanggal'] == '') ? date('d-m-Y'):$data['form_data']['tanggal'] }}" required>
		    		</div>
	        	</div>
	        	<div class="form-group">
		    		<label class="control-label col-sm-4">Lokasi</label>
		    		<div class="col-sm-8"> @php $id_lokasi =  $data['form_data']['id_lokasi'] @endphp
		    			<select name="lokasi" id="lokasi" class="form-control select-search">
		    				@foreach($data['lokasi'] as $d)
		    					<option value="{{ $d->id_lokasi }}" {{ ($d->id_lokasi == $id_lokasi) ? "selected":"" }}>{{ $d->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['form_data']['keterangan'] }}</textarea>
        			</div>
        		</div>
	    	</div>

        	<div class="col-sm-6">
        		
        	</div>
        	

        	<div class="col-sm-12 form-group">
	        	<h5 class="panel-title">Barang Dikembalikan</h5>
	        	<br><a href="#" class="btn btn-success" style="margin-bottom: 1%;" id="btn_tambah_kembali">Tambah Barang</a>
	        		<div class="table-responsive">
		        	<table class="table table-stripped" id="table_kembali">
				    	<thead>
							<tr>
								<th>No</th>
								<th>Kode Barang</th>
								<th>Nama Barang</th>
								<th>Warna</th>
								<th>Jumlah</th>
								<th>Satuan</th>
								<th>Hasil</th>
								<th>Satuan Hasil</th>
								<th>Gudang</th>
								<th>Corak</th>
								<th>Aksi</th>
							</tr>
						</thead>
						<tbody id="body_setor">
						</tbody>
			    	</table>
			    	</div>
        	</div>

        	<div class="col-sm-12">
        	
            <div class="form-group pull-right">
             	<button class="btn btn-primary" type="submit" id="btn_simpan" style="display: none">Simpan</button>
            </div>
            </div>
	    </div>
	    
	</div>
</div>

</form>

<!---Modal--->

<div class="modal fade" id="modal_kembali" 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_idtable_kembali">
	      			<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_kembali">
		      			 		<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">Proses</label>
	      				<div class="col-sm-8">
		      			 	<select class="form-control select-search" name="popup_proses_kembali">
		      			 		<option value="" nama="">--- Pilih ---</option>
		      			 		@php
		      			 		foreach($data['proses'] as $b){ @endphp
		      			 			<option value="{{ $b->id_proses }}" nama="{{ $b->nama_proses }}">{{ $b->nama_proses }}</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_kembali">
	      			 			<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">Kualitas Proses</label>
	      				<div class="col-sm-8">	
	      			 		<select name="popup_kualitas_kembali" 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">
	      					
	      			 	
	      			 		<select name="popup_komposisi_kembali" 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_kembali" 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_kembali" 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_kualitas">
	      				<label class="control-label col-sm-4">Kualitas Tenun</label>
	      				<div class="col-sm-8">	
	      			 		<select name="popup_kual_kembali" 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_kembali" 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_kembali" 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_kembali" 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_kembali" 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_kembali" 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_kembali" 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_kembali" 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_kembali" 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" style="display: none;">
	      				<label class="control-label col-sm-4">Keterangan</b></label>
	      				<div class="col-sm-8">
	      			 		<textarea class="form-control" name="popup_keterangan_kembali"></textarea>
	      				</div>
	      			</div>
	      			<hr>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Jumlah</b></label>
	      				<div class="col-sm-8">
	      			 	<input type="text" name="popup_jumlah_kembali" class="form-control number-only" onkeyup="maksimal($(this))">
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Satuan</b></label>
	      				<div class="col-sm-8">
	      			 		<select class="form-control select-search" name="popup_satuan_kembali">
	      			 			<option value="">---- Pilih Satuan ----</option>
	      			 			@foreach($data['satuan'] as $s){
	      			 				<option value="{{ $s->id_satuan }}" name="{{ $s->nama_satuan }}">{{ $s->nama_satuan }}</option>
	      			 			@endforeach 
	      			 		</select>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Menghasilkan</label>
	      				<div class="col-sm-8">
	      					<input type="text" name="popup_menghasilkan_kembali" class="form-control" onkeyup="maksimal($(this))">
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Satuan Menghasilkan</label>
	      				<div class="col-sm-8">
	      					<select class="form-control select-search" name="popup_satuanhasil_kembali">
	      						<option value="">---- Pilih Satuan ----</option>
	      						@foreach($data['satuan'] as $s){
	      			 				<option value="{{ $s->id_satuan }}" name="{{ $s->nama_satuan }}">{{ $s->nama_satuan }}</option>
	      			 			@endforeach 
	      					</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_rubahsatuan">
<input type="hidden" name="store_jumedit">

<script type="text/javascript">

	var table_barang;
	var tb_no = parseInt(10000);
	var id_proses;
	var nama_proses;
	var id;
	var proses;
	var id_kembali;
	var store_idbarangkeluar = '';
	var store_jenis = '';
	$(document).ready(function(){
		table_barang = $("#table_kembali").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();

		$("#btn_simpan").show();

		var id_kembali = $("[name=id_kembalibarang]").val();
		if(id_kembali != ''){
			get_edit(id_kembali);
		}
        
	})

	$("#btn_tambah_kembali").click(function(){
		get_clear();
		$("#modal_kembali").modal('show');
	})

	
	$("#btn_popup_simpan").click(function(){
		var id_table = $("[name=popup_idtable_kembali]").val();
    	var id_kolom = $("[name=popup_idtable_kembali]").val();
    	var id_barangkeluar = 0;
    	var id_jenis = $("[name=popup_idjenis]").val();
    	var id_proses = $("[name=popup_proses_kembali]").val();

    	var id_barang = $("[name=popup_barang_kembali]").val();
    	var nama_barang = $("[name=popup_barang_kembali] :selected").attr('nama');
    	var kode_barang = $("[name=popup_barang_kembali] :selected").attr('kode');
    	
    	var id_gudang = $("[name=popup_gudang_kembali]").val();
    	var nama_gudang = $("[name=popup_gudang_kembali] :selected").attr('nama');
    	var id_kualitas = $("[name=popup_kualitas_kembali]").val(); //proses
    	
    	var id_komposisi = $("[name=popup_komposisi_kembali]").val();
    	var nama_komposisi = $("[name=popup_komposisi_kembali] :selected").attr('name');
    	
    	var id_corak = $("[name=popup_corak_kembali]").val();
    	var nama_corak = $("[name=popup_corak_kembali] :selected").attr('nama');
    	var id_motif = $("[name=popup_motif_kembali]").val();
    	var id_order = $("[name=popup_order_kembali]").val();
    	var id_tenun = $("[name=popup_kual_kembali]").val();
    	var id_dudul = $("[name=popup_dudul_kembali]").val();
    	var id_periksa = $("[name=popup_periksa_kembali]").val();
    	var id_label = $("[name=popup_label_kembali]").val();
    	var id_cap = $("[name=popup_cap_kembali]").val();
    	var id_kemasan = $("[name=popup_kemasan_kembali]").val();
    	var id_kemasansatuan = $("[name=popup_kemasansatuan_kembali]").val();
    	var id_kemasansepuluh = $("[name=popup_kemasansepuluh_kembali]").val();
    	var id_kemasanseratus = $("[name=popup_kemasanseratus_kembali]").val();
    	
    	var workorder = 0;
    	var spk = 0;


    	var id_satuan = $("[name=popup_satuan_kembali]").val();
    	var nama_satuan = $("[name=popup_satuan_kembali] :selected").attr('name');
    	
    	var keterangan = $("[name=popup_keterangan_kembali]").val();

    	var id_perubahansatuan = $("[name=popup_satuanhasil_kembali]").val();

    	var jumlah = $("[name=popup_jumlah_kembali]").val();
    	var jumlah_hasil = $("[name=popup_menghasilkan_kembali]").val();

		var jumlah_perubahan = '';
		var tampil_jp = 0;
		
		var satuan_perubahan = '';
		var nama_satuanperubahan = '';

    	if($("[name=popup_menghasilkan_kembali]").val() != '' && $("[name=popup_menghasilkan_kembali]").val() != '0'){
			var satuan_perubahan = $("[name=popup_satuanhasil_kembali]").val();
			var nama_satuanperubahan = $("[name=popup_satuanhasil_kembali] :selected").attr('name');

			jumlah_perubahan = parseFloat(jumlah_hasil)/parseFloat(jumlah);
			jumlah_perubahan = number_test(jumlah_perubahan);
			tampil_jp = parseFloat(jumlah)*parseFloat(jumlah_perubahan);
			tampil_jp = number_test(tampil_jp);
		}

		if(id_barang != '' && id_gudang != '' && jumlah != '' && jumlah != 0 && id_satuan != ''){
			if(id_kolom == ''){
				table_barang.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+'">'+nama_komposisi+'</div>',
					'<div id="list_jumlah'+tb_no+'">'+jumlah+'</div>',
					'<div id="list_namasatuan'+tb_no+'">'+nama_satuan+'</div>',					
					'<div id="list_perubahan'+tb_no+'">'+tampil_jp+'</div>',
					'<div id="list_namasatuan_perubahan'+tb_no+'">'+nama_satuanperubahan+'</div>',	
					'<div id="list_gudang'+tb_no+'">'+nama_gudang+'</div>',
					'<div id="list_corak'+tb_no+'">'+nama_corak+'</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_idbarangkeluar[]" id="tabel_idbarangkeluar'+tb_no+'" value="'+id_barangkeluar+'">'+
							'<input type="hidden" name="tabel_jenis[]" id="tabel_jenis'+tb_no+'" value="'+id_jenis+'">'+

							'<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_proses[]" id="tabel_proses'+tb_no+'" value="'+id_proses+'">'+
							'<input type="hidden" name="tabel_jumlah[]" id="tabel_jumlah'+tb_no+'" value="'+jumlah+'">'+
							'<input type="hidden" name="tabel_perubahanjumlah[]" id="tabel_perubahanjumlah'+tb_no+'" value="'+jumlah_perubahan+'">'+
							'<input type="hidden" name="tabel_komposisi[]" id="tabel_komposisi'+tb_no+'" value="'+nama_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="'+id_satuan+'">'+
							'<input type="hidden" name="tabel_idsatuan_perubahan[]" id="tabel_idsatuan_perubahan'+tb_no+'" value="'+satuan_perubahan+'">'+
							'<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_tenun+'">'+
							'<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_workorder[]" id="tabel_workorder'+tb_no+'" value="'+workorder+'">'+
							'<input type="hidden" name="tabel_spk[]" id="tabel_spk'+tb_no+'" value="'+spk+'">'+
							'<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_kualitas+'">'+
							'<input type="hidden" name="tabel_idkualitasperiksa[]" id="tabel_idkualitasperiksa'+tb_no+'" value="'+id_periksa+'">'+
							'<input type="hidden" name="tabel_keterangan[]" id="tabel_keterangan'+tb_no+'" value="'+keterangan+'">']).draw(false);
					tb_no++;
			}else{
				$("#list_kode"+id_kolom).text(kode_barang);
				$("#list_nama"+id_kolom).text(nama_barang);
				$("#list_komposisi"+id_kolom).text(nama_komposisi);
				$("#list_jumlah"+id_kolom).text(jumlah);
				$("#list_namasatuan"+id_kolom).text(nama_satuan);
				$("#list_perubahan"+id_kolom).text(tampil_jp);
				$("#list_namasatuan_perubahan"+id_kolom).text(nama_satuanperubahan);
				$("#list_gudang"+id_kolom).text(nama_gudang);
				$("#list_corak"+id_kolom).text(nama_corak);

				$("#tabel_idbarangkeluar"+id_kolom).val(id_barangkeluar);
				$("#tabel_jenis"+id_kolom).val(id_jenis);
				$("#tabel_idbarang"+id_kolom).val(id_barang);
				$("#tabel_idgudang"+id_kolom).val(id_gudang);
				$("#tabel_proses"+id_kolom).val(id_proses);
				$("#tabel_jumlah"+id_kolom).val(jumlah);

				$("#tabel_perubahanjumlah"+id_kolom).val(jumlah_perubahan);
				$("#tabel_komposisi"+id_kolom).val(nama_komposisi);
				$("#tabel_idkomposisi"+id_kolom).val(id_komposisi);
				$("#tabel_idsatuan"+id_kolom).val(id_satuan);
				$("#tabel_idsatuan_perubahan"+id_kolom).val(satuan_perubahan);
				$("#tabel_idcorak"+id_kolom).val(id_corak);
				$("#tabel_idmotif"+id_kolom).val(id_motif);
				$("#tabel_idkualitas"+id_kolom).val(id_tenun);
				$("#tabel_iddudul"+id_kolom).val(id_dudul);
				$("#tabel_idlabel"+id_kolom).val(id_label);
				$("#tabel_idkemasan"+id_kolom).val(id_kemasan);
				$("#tabel_idkemasansatuan"+id_kolom).val(id_kemasansatuan);
				$("#tabel_idkemasansepuluh"+id_kolom).val(id_kemasansepuluh);
				$("#tabel_idkemasanseratus"+id_kolom).val(id_kemasanseratus);
				$("#tabel_workorder"+id_kolom).val(workorder);
				$("#tabel_spk"+id_kolom).val(spk);
				$("#tabel_idcap"+id_kolom).val(id_cap);
				$("#tabel_idkualitasproses"+id_kolom).val(id_kualitas);
				$("#tabel_idkualitasperiksa"+id_kolom).val(id_periksa);
				$("#tabel_keterangan"+id_kolom).val(keterangan);

			}

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

	function edit_table(id){
		//var idtable = $("#tabel_idtable"+id).val();
		var id = $("#tabel_id"+id).val();
		var id_barangkeluar = $("#tabel_idbarangkeluar"+id).val();
		var id_jenis = $("#tabel_jenis"+id).val();

		var id_barang = $("#tabel_idbarang"+id).val();
		var id_gudang = $("#tabel_idgudang"+id).val();
		var id_proses = $("#tabel_proses"+id).val();

		var id_kualitasproses = $("#tabel_idkualitasproses"+id).val();
		var id_komposisi = $("#tabel_idkomposisi"+id).val();

		var jumlah = $("#tabel_jumlah"+id).val();
		var id_corak = $("#tabel_idcorak"+id).val();
		var id_motif = $("#tabel_idmotif"+id).val();
		var workorder = $("#tabel_workorder"+id).val();
		var id_kualitas = $("#tabel_idkualitas"+id).val();
		var id_dudul = $("#tabel_iddudul"+id).val();
		var id_kualitasperiksa = $("#tabel_idkualitasperiksa"+id).val();
		var id_label = $("#tabel_idlabel"+id).val();
		var id_cap = $("#tabel_idcap"+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 keterangan = $("#tabel_keterangan"+id).val();

		var jumlah = $("#tabel_jumlah"+id).val();
		var satuan = $("#tabel_idsatuan"+id).val();
			

		
		console.log(id);
	
		$("[name=popup_idtable_kembali]").val(id);
    	$("[name=popup_idkolom]").val(id);    	
    	$("[name=popup_idbb]").val(id_barangkeluar);
    	$("[name=popup_idjenis]").val(id_jenis);
    	$("[name=store_jumedit]").val(jumlah);
    	$("[name=popup_barang_pilih]").find("option[id_bb = '"+id_barangkeluar+"']").prop('selected', true).trigger('change');

    	$("[name=popup_proses_kembali]").val(id_proses).trigger("change");

    	
    	
    	$("[name=popup_barang_kembali]").val(id_barang).trigger("change");    	
    	$("[name=popup_gudang_kembali]").val(id_gudang).trigger("change");    	
    	$("[name=popup_kualitas_kembali]").val(id_kualitasproses).trigger("change"); //proses    	
    	$("[name=popup_komposisi_kembali]").val(id_komposisi).trigger("change");    	
    	
    	$("[name=popup_corak_kembali]").val(id_corak).trigger("change");
    	
    	$("[name=popup_motif_kembali]").val(id_motif).trigger("change");
    	$("[name=popup_order_kembali]").val(workorder).trigger("change");
    	$("[name=popup_kual_kembali]").val(id_kualitas).trigger("change");
    	$("[name=popup_dudul_kembali]").val(id_dudul).trigger("change");
    	$("[name=popup_periksa_kembali]").val(id_kualitasperiksa).trigger("change");
    	$("[name=popup_label_kembali]").val(id_label).trigger("change");
    	$("[name=popup_cap_kembali]").val(id_cap).trigger("change");
    	$("[name=popup_kemasan_kembali]").val(id_kemasan).trigger("change");
    	$("[name=popup_kemasansatuan_kembali]").val(id_kemasansatuan).trigger("change");
    	$("[name=popup_kemasansepuluh_kembali]").val(id_kemasansepuluh).trigger("change");
    	$("[name=popup_kemasanseratus_kembali]").val(id_kemasanseratus).trigger("change");
    	
    	
    	$("[name=popup_satuan_kembali]").val(satuan).trigger("change"); 	    	
    	$("[name=popup_keterangan_kembali]").val(keterangan);
    	$("[name=popup_jumlah_kembali]").val(jumlah);

    	//--- Perubahan satuan
		var satuan_perubahan = $("#tabel_idsatuan_perubahan"+id).val();
		var jumlah_perubahan = $("#tabel_perubahanjumlah"+id).val();


		if(satuan_perubahan != '' || satuan_perubahan != 0){
			

			var tampil_jp = 0;
			tampil_jp = parseFloat(jumlah)*parseFloat(jumlah_perubahan);
			tampil_jp = number_test(tampil_jp);

			$("[name=popup_menghasilkan_kembali]").val(tampil_jp);
			$("[name=popup_satuanhasil_kembali]").val(satuan_perubahan).trigger('change');
		}else{
			
			$("[name=popup_menghasilkan_kembali]").val('');
			$("[name=popup_satuanhasil_kembali]").val('11').trigger('change');
				
		}
		
		$("#modal_kembali").modal('show');

	}


	function get_edit(id){
		$.ajax({
			url: "{{ url('kembaliseluruh/get_edit') }}",
			type: 'get',
			dataType: "json",
			data: { id : id },
			success : function(respon){
				if(respon.length > 0){
					for(i in respon){
						var tampil_jp = 0;
						
						var satuan_perubahan = '';
						var nama_satuanperubahan = '';

				    	if(respon[i].id_perubahansatuan != ''){
							var satuan_perubahan = respon[i].id_perubahansatuan;
							var nama_satuanperubahan = respon[i].nama_perubahansatuan;

							tampil_jp = parseFloat(respon[i].jumlah)*parseFloat(respon[i].jumlah_rencana);
							tampil_jp = number_test(tampil_jp);
						}

						table_barang.row.add(['<div><center></center></div>',
							'<div id="list_kode'+respon[i].id_kembali_barang+'">'+respon[i].kode_barang+'</div>',
							'<div id="list_nama'+respon[i].id_kembali_barang+'">'+respon[i].nama_barang+'</div>',
							'<div id="list_komposisi'+respon[i].id_kembali_barang+'">'+respon[i].nama_komposisi+'</div>',
							'<div id="list_jumlah'+respon[i].id_kembali_barang+'">'+respon[i].jumlah+'</div>',
							'<div id="list_namasatuan'+respon[i].id_kembali_barang+'">'+respon[i].nama_satuan+'</div>',					
							'<div id="list_perubahan'+respon[i].id_kembali_barang+'">'+tampil_jp+'</div>',
							'<div id="list_namasatuan_perubahan'+respon[i].id_kembali_barang+'">'+respon[i].nama_perubahansatuan+'</div>',	
							'<div id="list_gudang'+respon[i].id_kembali_barang+'">'+respon[i].nama_gudang+'</div>',
							'<div id="list_corak'+respon[i].id_kembali_barang+'">'+respon[i].nama_corak+'</div>',
							'<div><button type="button" class="btn bg-warning-400" onclick="edit_table('+respon[i].id_kembali_barang+')"><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_kembali_barang+'" name="tabel_idtable[]" value="'+respon[i].id_kembali_barang+'">'+
							'<input type="hidden" name="tabel_id[]" class="tabel_id" id="tabel_id'+respon[i].id_kembali_barang+'" value="'+respon[i].id_kembali_barang+'">'+
							'<input type="hidden" name="tabel_idbarangkeluar[]" id="tabel_idbarangkeluar'+respon[i].id_kembali_barang+'" value="'+respon[i].id+'">'+
							'<input type="hidden" name="tabel_jenis[]" id="tabel_jenis'+respon[i].id_kembali_barang+'" value="'+store_jenis+'">'+

							'<input type="hidden" name="tabel_idbarang[]" id="tabel_idbarang'+respon[i].id_kembali_barang+'" value="'+respon[i].id_barang+'">'+
							'<input type="hidden" name="tabel_idgudang[]" id="tabel_idgudang'+respon[i].id_kembali_barang+'" value="'+respon[i].id_gudang+'">'+
							'<input type="hidden" name="tabel_proses[]" id="tabel_proses'+respon[i].id_kembali_barang+'" value="'+respon[i].id_proses+'">'+
							'<input type="hidden" name="tabel_jumlah[]" id="tabel_jumlah'+respon[i].id_kembali_barang+'" value="'+respon[i].jumlah+'">'+
							'<input type="hidden" name="tabel_perubahanjumlah[]" id="tabel_perubahanjumlah'+respon[i].id_kembali_barang+'" value="'+respon[i].jumlah_rencana+'">'+
							'<input type="hidden" name="tabel_komposisi[]" id="tabel_komposisi'+respon[i].id_kembali_barang+'" value="'+respon[i].nama_komposisi+'">'+
							'<input type="hidden" name="tabel_idkomposisi[]" id="tabel_idkomposisi'+respon[i].id_kembali_barang+'" value="'+respon[i].id_komposisi+'">'+
							'<input type="hidden" name="tabel_idsatuan[]" id="tabel_idsatuan'+respon[i].id_kembali_barang+'" value="'+respon[i].id_satuan+'">'+
							'<input type="hidden" name="tabel_idsatuan_perubahan[]" id="tabel_idsatuan_perubahan'+respon[i].id_kembali_barang+'" value="'+respon[i].id_perubahansatuan+'">'+
							'<input type="hidden" name="tabel_idcorak[]" id="tabel_idcorak'+respon[i].id_kembali_barang+'" value="'+respon[i].id_corak+'">'+
							'<input type="hidden" name="tabel_idmotif[]" id="tabel_idmotif'+respon[i].id_kembali_barang+'" value="'+respon[i].id_motif+'">'+
							'<input type="hidden" name="tabel_idkualitas[]" id="tabel_idkualitas'+respon[i].id_kembali_barang+'" value="'+respon[i].id_kualitas+'">'+
							'<input type="hidden" name="tabel_iddudul[]" id="tabel_iddudul'+respon[i].id_kembali_barang+'" value="'+respon[i].id_kualitas_dudul+'">'+
							'<input type="hidden" name="tabel_idlabel[]" id="tabel_idlabel'+respon[i].id_kembali_barang+'" value="'+respon[i].id_label+'">'+
							'<input type="hidden" name="tabel_idkemasan[]" id="tabel_idkemasan'+respon[i].id_kembali_barang+'" value="'+respon[i].id_kemasan+'">'+
							'<input type="hidden" name="tabel_idkemasansatuan[]" id="tabel_idkemasansatuan'+respon[i].id_kembali_barang+'" value="'+respon[i].id_kemasansatuan+'">'+
							'<input type="hidden" name="tabel_idkemasansepuluh[]" id="tabel_idkemasansepuluh'+respon[i].id_kembali_barang+'" value="'+respon[i].id_kemasansepuluh+'">'+
							'<input type="hidden" name="tabel_idkemasanseratus[]" id="tabel_idkemasanseratus'+respon[i].id_kembali_barang+'" value="'+respon[i].id_kemasanseratus+'">'+
							'<input type="hidden" name="tabel_workorder[]" id="tabel_workorder'+respon[i].id_kembali_barang+'" value="'+respon[i].id_workorder_barang+'">'+
							'<input type="hidden" name="tabel_spk[]" id="tabel_spk'+respon[i].id_kembali_barang+'" value="'+respon[i].id_workorder+'">'+
							'<input type="hidden" name="tabel_idcap[]" id="tabel_idcap'+respon[i].id_kembali_barang+'" value="'+respon[i].id_cap+'">'+
							'<input type="hidden" name="tabel_idkualitasproses[]" id="tabel_idkualitasproses'+respon[i].id_kembali_barang+'" value="'+respon[i].id_kualitas_proses+'">'+
							'<input type="hidden" name="tabel_idkualitasperiksa[]" id="tabel_idkualitasperiksa'+respon[i].id_kembali_barang+'" value="'+respon[i].id_kualitas_periksa+'">'+
							'<input type="hidden" name="tabel_keterangan[]" id="tabel_keterangan'+respon[i].id_kembali_barang+'" value="">']).draw(false);

					}
				}else{

				}
			}
		})
	}

    function get_clear(){
    	$("[name=popup_idtable_kembali]").val('');
    	$("[name=popup_idkolom]").val('');
    	$("[name=popup_barang_pilih]").val('').trigger('change');
    	$("[name=popup_proses_kembali]").val('').trigger('change');
    	$("[name=popup_barang_kembali]").val('').trigger('change');
    	$("[name=popup_gudang_kembali]").val('').trigger('change');
    	$("[name=popup_kualitas_kembali]").val('').trigger('change');
    	$("[name=popup_komposisi_kembali]").val('').trigger('change');
    	$("[name=popup_corak_kembali]").val('').trigger('change');
    	$("[name=popup_motif_kembali]").val('').trigger('change');
    	$("[name=popup_order_kembali]").val('').trigger('change');
    	$("[name=popup_kual_kembali]").val('').trigger('change');
    	$("[name=popup_dudul_kembali]").val('').trigger('change');
    	$("[name=popup_periksa_kembali]").val('').trigger('change');
    	$("[name=popup_label_kembali]").val('').trigger('change');
    	$("[name=popup_cap_kembali]").val('').trigger('change');
    	$("[name=popup_kemasan_kembali]").val('').trigger('change');
    	$("[name=popup_kemasansatuan_kembali]").val('').trigger('change');
    	$("[name=popup_kemasansepuluh_kembali]").val('').trigger('change');
    	$("[name=popup_kemasanseratus_kembali]").val('').trigger('change');
    	$("[name=popup_satuan_kembali]").val('').trigger('change');
    	$("[name=popup_satuanhasil_kembali]").val('').trigger('change');

    	$("[name=popup_jumlah_kembali]").val('');
    	$("[name=popup_menghasilkan_kembali]").val('');

    	$("[name=popup_keterangan_kembali]").val('');
    }

    function hapus(d){
		table_barang.row(d.parents('tr')).remove().draw();
	}
</script>
@endsection