@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">Bon Bahan</li>
		</ul>
	</div>
</div>

<div class="content">
	<div class="panel panel-flat">
		<div class="panel-heading">
			<h5 class="panel-title">Form Bon Bahan</h5>
			<div class="heading-elements">
				<ul class="icons-list">
		      		<li><a data-action="collapse"></a></li>
		      	</ul>
	       	</div>
	    </div>
	    <div class="panel-body">
	    	<form class="form-horizontal" action="{{url('barangkeluar/simpan')}}" method="post" autocomplete="off" enctype="multipart/form-data">
	    	<input type="hidden" name="_token" value="{{ csrf_token() }}">
	    	<input type="hidden" name="id_barangkeluar" value="{{ $data['data']['id_barangkeluar']}}">
        	<div class="col-sm-6">
        		<div class="form-group">
        			<label class="control-label col-sm-4">Tanggal Pengambilan</label>
        			<div class="col-sm-8">
        				<input class="form-control datepicker" type="text" name="tanggal" value="{{ ($data['data']['tanggal'] == '') ? date('d-m-Y'):date('d-m-Y', strtotime($data['data']['tanggal'])) }}" placeholder="Tanggal" required/>
        			</div>
        		</div>
        		<div class="form-group hidden">
        			<label class="control-label col-sm-4">No.Spk</label>
        			<div class="col-sm-8">
        				@php if($data['data']['id_barangkeluar'] !=""){ @endphp
        				<input type="hidden" name="spk" value="{{$data['data']['id_workorder']}}">
        				<select class="form-control select-search" disabled="">
        					<option value="">-- Pilih No.Spk --</option>
        					@php foreach($data['spk'] as $d){
        					$sel = $data['data']['id_workorder'];
        					@endphp
        					<option value="{{$d->id_workorder}}" {{($d->id_workorder == $sel) ? "selected":""}}>{{ $d->nomor}}</option>
        					@php } @endphp
        				</select>
        				@php }else{@endphp
        				<select class="form-control select-search" name="spk">
        					<option value="">-- Pilih No.Spk --</option>
        					@php foreach($data['spk'] as $d){
        					$sel = $data['data']['id_workorder'];
        					@endphp
        					<option value="{{$d->id_workorder}}" {{($d->id_workorder == $sel) ? "selected":""}}>{{ $d->nomor}}</option>
        					@php } @endphp
        				</select>
        				@php } @endphp
        			</div>
        		</div>
        		<div class="form-group" style="display: none;">
        			<label class="control-label col-sm-4">No.Order</label>
        			<div class="col-sm-8">
        				@php if($data['data']['id_barangkeluar']!=""){@endphp
        				<input type="hidden" name="workorder" value="{{($data['data']['id_workorder_barang']==0) ? '':$data['data']['id_workorder_barang']}}">
        				<select class="form-control select-search" disabled="">
        					<option value="">-- Pilih Order --</option>
        					@php foreach($data['workorder'] as $row){ 
        					$sel = $data['data']['id_workorder_barang'];
        					@endphp
        					<option value="{{ $row->id_workorder_barang }}" order="{{ $row->id_workorder }}" {{ ($row->id_workorder_barang == $sel) ? "selected":"" }}  > {{ $row->no_workorder }}
        					</option>
        					@php } @endphp
        				</select>
        				@php }else{ @endphp
        				<select class="form-control select-search" name="workorder">
        					<option value="">-- Pilih Order --</option>
        					@php foreach($data['workorder'] as $row){ 
        					$sel = $data['data']['id_workorder_barang'];
        					@endphp
        					<option value="{{ $row->id_workorder_barang }}" order="{{ $row->id_workorder }}" {{ ($row->id_workorder_barang == $sel) ? "selected":"" }}  > {{ $row->no_workorder }}
        					</option>
        					@php } @endphp
        				</select>
        				@php } @endphp
        			</div>
        		</div>
        		
        		<div class="form-group">
        			<label class="control-label col-sm-4">Proses Produksi</label>
        			<div class="col-sm-8">
        				@php if($data['data']['id_barangkeluar']!=""){ @endphp
        				<input type="hidden" name="proses" value="{{$data['data']['id_proses']}}">
        				<select class="form-control select-search" disabled="">
        					<option value="">-- Pilih Produksi --</option>
        					@php foreach($data['proses'] as $row){ 
        					$sel = $data['data']['id_proses'];
        					$old = old('proses');
        					if($row->nama_proses2 == ''){

        					echo '<optgroup label="'.$row->nama_proses.'">';
        					} else {
        					@endphp
        					<option value="{{ $row->id_proses }}" {{ ($row->id_proses == $sel) ? "selected":"" }}  > {{ $row->nama_proses2.' - '.$row->nama_proses }}
        					</option>
        					@php
        					}
        					if($row->nama_proses == ''){

        					echo '</optgroup>';
        					}

        					} @endphp
        				</select>
        				@php }else{ @endphp
        				<select class="form-control select-search" name="proses" required>
        					<option value="">-- Pilih Produksi --</option>
        					@php foreach($data['proses'] as $row){ 
        					$sel = $data['data']['id_proses'];
        					$old = old('proses');
        					
        					if($row->nama_proses2 == ''){

        					echo '<optgroup label="'.$row->nama_proses.'">';
        					} else {
        					@endphp
        					<option value="{{ $row->id_proses }}" {{ ($row->id_proses == $sel) ? "selected":"" }}  > {{ $row->nama_proses2.' - '.$row->nama_proses }}
        					</option>
        					@php
        					}
        					if($row->nama_proses == ''){

        					echo '</optgroup>';
        					}

        					} @endphp
        				</select>
        				@php } @endphp
        			</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 datepicker" type="text" name="tanggal_perkiraan" value="{{ ($data['data']['tanggal_perkiraan'] == '') ? date('d-m-Y') : date('d-m-Y',strtotime($data['data']['tanggal_perkiraan'])) }}" placeholder="Tanggal" required/>
        			</div>
        		</div>
                <div class="form-group">
                    <label class="control-label col-sm-4">Lokasi Produksi </label>
                    <div class="col-sm-8">
                        <select class="form-control select-search" name="id_jenis">
                            {{-- <option value="">--- Pilih Jenis ---</option> --}}
                            @php $sel = $data['data']['jenis'];
                            foreach($data['produksi'] as $d){@endphp
                            <option value="{{$d->id_lokasi}}" {{ ($d->id_lokasi == $sel) ? "selected":"" }} >{{ $d->nama_lokasi }}</option>
                            @php } @endphp
                        </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">
        				<select class="form-control select-search" name="rekanan">
        					<option value="">-- Pilih Rekanan --</option>
        					@php foreach($data['rekanan'] as $row){
        					$sel = $data['data']['id_rekanan']; @endphp
        					<option value="@php echo $row->id_rekanan @endphp" {{ ($row->id_rekanan == $sel) ? "selected":"" }}>
        						{{$row->nama.' - '.$row->nama_kelompok}}
        					</option>
        					@php } @endphp
        				</select>
        			</div>
        		</div>
        		<div class="form-group">
        			<label class="control-label col-sm-4">Pegawai</label>
        			<div class="col-sm-8">
        				<select name="pegawai" class="form-control select-search" id="id_pegawai">
        					<option value="">--- Pilih Pegawai ---</option>
        					@php $no=1; foreach($data['pegawai'] as $row){
        					$sel = $data['data']['id_pegawai'];
        					@endphp
        						<option value="{{ $row->id_pegawai }}" {{ ($row->id_pegawai == $sel) ? "selected":""}}>{{ $row->nama_pegawai }}</option>
        					@php } @endphp
        				</select>
        			</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 class="form-group" id="btnworkorder">
        			@if (old('proses'))
				    <div class="alert alert-warning">
				    	<button type="button" class="close" data-dismiss="alert"><span>×</span><span class="sr-only">Close</span></button>
				        <i><b>*Rekanan atau Pegawai belum di isi</b></i>
				    </div>
				@endif
				  
        		</div>
        	</div>
        	

        	
        	<div class="col-sm-12 form-group">
        	<h5 class="panel-title">Detail Barang</h5>
        	 <br><a href="#" class="btn btn-success" style="margin-bottom: 1%;" id="btn_tambah_item">Tambah Barang</a></div> 
        	<div class="col-ms-12">
        	<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>Jumlah Konversi</th> -->
                    <th>Keterangan</th>
					<th class="text-center">Aksi</th>
				</tr>
			</thead>
			<tbody>
				
			</tbody>
	    </table>
        	</div>
        	
        	
             <div class="col-md-6"></div>
             <br>
             <div class="col-md-12">
             <a href="{{url('barangkeluar')}}" class="btn bg-warning-400">Kembali</a>
             <div class="form-group pull-right">
             	<button class="btn btn-primary" type="submit">Simpan</button> 
             	<!-- <button class="btn btn-primary" type="submit">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="col-sm-4 control-label">Tanggal</label>
                        <div class="col-sm-8">
                            <input type="text" name="popup_tanggal" class="form-control datepicker" value="{{ date('d-m-Y') }}" readonly>
                        </div>
                    </div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Produksi sebelumnya</label>
	      				<div class="col-sm-8">
	      					<select class="form-control select-search" name="popup_proses">
	      						<option value="">-- Pilih Produksi --</option>
        					@php foreach($data['proses_popup'] as $row){ 
        					$sel = $data['data']['id_proses'];
        					$old = old('proses');
        					if($row->nama_proses2 == ''){

        					echo '<optgroup label="'.$row->nama_proses.'">';
        					} else {
        					@endphp
        					<option value="{{ $row->id_proses }}" {{ ($row->id_proses == $sel) ? "selected":"" }}  > {{ $row->nama_proses2.' - '.$row->nama_proses }}
        					</option>
        					@php
        					}
        					if($row->nama_proses == ''){

        					echo '</optgroup>';
        					}

        					} @endphp		
	      					</select>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Warna</label>
	      				<div class="col-sm-8">
	      					<!-- <input type="text" class="form-control" id="input_warna" readonly> -->
	      					<select class="form-control select-search" name="input_warna" id="input_warna">
	      						<option value="">-- Pilih --</option>
	      						@php foreach($data['warna'] as $d){ @endphp
	      							<option value="{{ $d->id_komposisi}}" nama="{{$d->nama}}">{{$d->nama.' ('.$d->inisial.')'}}</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="">-- Pilih Gudang --</option>
	      						@php foreach($data['gudang'] as $row){
	      						
	      						@endphp
	      						<option value="{{$row->id_gudang}}" id="{{$row->id_gudang}}" nama="{{$row->nama_gudang}}">{{$row->nama_gudang}}</option>
	      						@php } @endphp
	      					</select>
	      				</div>
	      			</div>
	      			<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">
	      						
	      					</select>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Jumlah Stok</label>
	      				<div class="col-sm-8">
	      					<label class="control-label" name="popup_stok"></label>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Jumlah <!-- <b id="popup_satuanawal"></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" id="div_konversi2">
	      				<label class="control-label col-sm-4">Satuan Jumlah </label>
	      				<div class="col-sm-8">
	      					<select class="form-control select-search" name="popup_satuanawal" >
	      						<option value="">-- Pilih --</option>
	      						@php foreach($data['satuan'] as $d){@endphp
	      						<option value="{{$d->id_satuan}}" nama="{{$d->nama_satuan}}">{{$d->nama_satuan}}</option>
	      						@php } @endphp
	      					</select>		
	      				</div>
	      			</div>
                    <div class="form-group" id="div_menghasilkan">
                        <label class="control-label col-sm-4">Menghasilkan ( <b id="satuan_menghasilkan"></b> )</label>
                        <div class="col-sm-8">
                            <input type="text" name="popup_menghasilkan" class="form-control number-only" onkeyup="maksimal($(this))">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-4">Perkiraan Laporan Hasil</label>
                        <div class="col-sm-8">
                            <input type="text" name="popup_jumlahhasil" class="form-control number-only">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-4">Satuan Perkiraan Laporan Hasil</label>
                        <div class="col-sm-8">
                            <select class="form-control select-search" name="popup_satuanhasil" >
                                <option value="">-- Pilih --</option>
                                @php foreach($data['satuan'] as $d){@endphp
                                <option value="{{$d->id_satuan}}" nama="{{$d->nama_satuan}}">{{$d->nama_satuan}}</option>
                                @php } @endphp
                            </select>       
                        </div>
                    </div>
                    {{--<div class="form-group">
                        <label class="control-label col-sm-4"><b>Satuan Menghasilkan</b></label>
                        <div class="col-sm-8">
                            <select class="form-control select-search" name="popup_satuanhasil">
                                <option value="">-- Pilih --</option>
                                @php foreach($data['satuan'] as $d){@endphp
                                <option value="{{$d->id_satuan}}" nama="{{$d->nama_satuan}}">{{$d->nama_satuan}}</option>
                                @php } @endphp
                            </select>
                        </div>
                    </div> --}}
                    <div class="form-group">
                        <label class="col-sm-4 control-label">Ketarangan</label>
                        <div class="col-sm-8">
                            <textarea class="form-control" name="popup_ket"></textarea>
                        </div>
                    </div>
	      		</form>
	      	</div>
	      	<h5 id="alert_workorder"></h5>
	      	<div class="modal-footer">
	        	<button type="button" class="btn btn-primary" id="btn_popup_simpan">Simpan</button>
	      	</div>
	    </div>
	</div>
</div>

<div class="modal fade" id="exampleModal2" 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="popup2_id_table">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">Tanggal</label>
                        <div class="col-sm-8">
                            <input type="text" name="popup2_tanggal" class="form-control datepicker" value="{{ date('d-m-Y') }}" readonly>
                        </div>
                    </div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Produksi sebelumnya</label>
	      				<div class="col-sm-8">
	      					<select class="form-control select-search" name="popup2_proses">
	      						<option value="">-- Pilih Produksi --</option>
        					@php foreach($data['proses'] as $row){ 
        					$sel = $data['data']['id_proses'];
        					$old = old('proses');
        					if($row->nama_proses2 == ''){

        					echo '<optgroup label="'.$row->nama_proses.'">';
        					} else {
        					@endphp
        					<option value="{{ $row->id_proses }}" {{ ($row->id_proses == $sel) ? "selected":"" }}  > {{ $row->nama_proses2.' - '.$row->nama_proses }}
        					</option>
        					@php
        					}
        					if($row->nama_proses == ''){

        					echo '</optgroup>';
        					}

        					} @endphp		
	      					</select>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Warna</label>
	      				<div class="col-sm-8">
	      					<!-- <input type="text" class="form-control" id="input2_warna" readonly> -->
	      					<select class="form-control select-search" name="input2_warna" id="input2_warna">
	      						<option value="">-- Pilih --</option>
	      						@php foreach($data['warna'] as $d){ @endphp
	      							<option value="{{ $d->id_komposisi}}" nama="{{$d->nama}}">{{$d->nama.' ('.$d->inisial.')'}}</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="popup2_gudang">
	      						|<option value="">-- Pilih Gudang --</option>
	      						@php foreach($data['gudang'] as $row){
	      						
	      						@endphp
	      						<option value="{{$row->id_gudang}}" id="{{$row->id_gudang}}" nama="{{$row->nama_gudang}}">{{$row->nama_gudang}}</option>
	      						@php } @endphp
	      					</select>
	      				</div>
	      			</div>
	      			<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="popup2_barang">
	      						
	      					</select>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Jumlah Stok</label>
	      				<div class="col-sm-8">
	      					<label class="control-label" name="popup2_stok"></label>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Jumlah <!-- <b id="popup2_satuanawal"></b> --></label>
	      				<div class="col-sm-8">
	      					<input type="text" name="popup2_jumlah" class="form-control number-only" onkeyup="maksimal($(this));"> {{-- get_perubahan($(this), 1) --}}
	      				</div>
	      			</div>
	      			<div class="form-group" id="div_konversi2">
	      				<label class="control-label col-sm-4">Satuan Jumlah </label>
	      				<div class="col-sm-8">
	      					<select class="form-control select-search" name="popup2_satuanawal">
	      						<option value="">-- Pilih --</option>
	      						@php foreach($data['satuan'] as $d){@endphp
	      						<option value="{{$d->id_satuan}}" nama="{{$d->nama_satuan}}">{{$d->nama_satuan}}</option>
	      						@php } @endphp
	      					</select>		
	      				</div>
	      			</div>
	      			
                    <div class="form-group" id="div2_menghasilkan" style="display: none">
                        <label class="control-label col-sm-4">Menghasilkan  ( <b id="satuan2_menghasilkan"></b> )</label>
                        <div class="col-sm-8">
                            <input type="text" name="popup2_menghasilkan" class="form-control number-only" onkeyup="maksimal($(this));">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-4">Perkiraan Laporan Hasil</label>
                        <div class="col-sm-8">
                            <input type="text" name="popup2_jumlahhasil" class="form-control number-only">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-4">Satuan Perkiraan Laporan Hasil</label>
                        <div class="col-sm-8">
                            <select class="form-control select-search" name="popup2_satuanhasil" >
                                <option value="">-- Pilih --</option>
                                @php foreach($data['satuan'] as $d){@endphp
                                <option value="{{$d->id_satuan}}" nama="{{$d->nama_satuan}}">{{$d->nama_satuan}}</option>
                                @php } @endphp
                            </select>       
                        </div>
                    </div>
                    {{-- <div class="form-group">
                        <label class="control-label col-sm-4"><b>Satuan Menghasilkan</b></label>
                        <div class="col-sm-8">
                            <select class="form-control select-search" name="popup2_satuanhasil">
                                <option value="">-- Pilih --</option>
                                @php foreach($data['satuan'] as $d){@endphp
                                <option value="{{$d->id_satuan}}" nama="{{$d->nama_satuan}}">{{$d->nama_satuan}}</option>
                                @php } @endphp
                            </select>
                        </div>
                    </div>	 --}}
	      			
                    <div class="form-group">
                        <label class="col-sm-4 control-label">Ketarangan</label>
                        <div class="col-sm-8">
                            <textarea class="form-control" name="popup2_ket"></textarea>
                        </div>
                    </div>
	      			

	      		</form>
	      	</div>
	      	<h5 id="alert_workorder"></h5>
	      	<div class="modal-footer">
	        	<button type="button" class="btn btn-primary" id="btn_popup2_simpan">Simpan</button>
	      	</div>
	    </div>
	</div>
</div>

<div class="modal fade" id="exampleModal3" 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="popup3_id_table">
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Produksi sebelumnya</label>
	      				<div class="col-sm-8">
	      					<select class="form-control select-search" name="popup3_proses">
	      						<option value="">-- Pilih Produksi --</option>
        					@php foreach($data['proses'] as $row){ 
        					$sel = $data['data']['id_proses'];
        					$old = old('proses');
        					if($row->nama_proses2 == ''){

        					echo '<optgroup label="'.$row->nama_proses.'">';
        					} else {
        					@endphp
        					<option value="{{ $row->id_proses }}" {{ ($row->id_proses == $sel) ? "selected":"" }}  > {{ $row->nama_proses2.' - '.$row->nama_proses }}
        					</option>
        					@php
        					}
        					if($row->nama_proses == ''){

        					echo '</optgroup>';
        					}

        					} @endphp		
	      					</select>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Warna</label>
	      				<div class="col-sm-8">
	      					<!-- <input type="text" class="form-control" id="input2_warna" readonly> -->
	      					<select class="form-control select-search" name="input3_warna" id="input3_warna">
	      						<option value="">-- Pilih --</option>
	      						@php foreach($data['warna'] as $d){ @endphp
	      							<option value="{{ $d->id_komposisi}}" nama="{{$d->nama}}">{{$d->nama.' ('.$d->inisial.')'}}</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="popup3_gudang">
	      						|<option value="">-- Pilih Gudang --</option>
	      						@php foreach($data['gudang'] as $row){
	      						
	      						@endphp
	      						<option value="{{$row->id_gudang}}" id="{{$row->id_gudang}}" nama="{{$row->nama_gudang}}">{{$row->nama_gudang}}</option>
	      						@php } @endphp
	      					</select>
	      				</div>
	      			</div>
	      			<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="popup3_barang">
	      						
	      					</select>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Jumlah Stok</label>
	      				<div class="col-sm-8">
	      					<label class="control-label" name="popup3_stok"></label>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Jumlah <!-- <b id="popup2_satuanawal"></b> --></label>
	      				<div class="col-sm-8">
	      					<input type="text" name="popup3_jumlah" class="form-control number-only" onkeyup="maksimal($(this))">
	      				</div>
	      			</div>
	      			<div class="form-group" id="div_konversi2">
	      				<label class="control-label col-sm-4">Satuan Jumlah </label>
	      				<div class="col-sm-8">
	      					<select class="form-control select-search" name="popup3_satuanawal">
	      						<option value="">-- Pilih --</option>
	      						@php foreach($data['satuan'] as $d){@endphp
	      						<option value="{{$d->id_satuan}}" nama="{{$d->nama_satuan}}">{{$d->nama_satuan}}</option>
	      						@php } @endphp
	      					</select>		
	      				</div>
	      			</div>
	      			
                    <div class="form-group">
                        <label class="control-label col-sm-4"><b>Menghasilkan</b></label>
                        <div class="col-sm-8">
                            <input type="text" name="popup3_menghasilkan" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-sm-4"><b>Satuan Menghasilkan</b></label>
                        <div class="col-sm-8">
                            <select class="form-control select-search" name="popup3_satuanhasil">
                               <option value="">-- Pilih --</option>
                                @php foreach($data['satuan'] as $d){@endphp
                                <option value="{{$d->id_satuan}}" nama="{{$d->nama_satuan}}">{{$d->nama_satuan}}</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 class="form-control select-search" name="popup3_warna_tipe">
	      						<option value="">-- Pilih Warna --</option>
	      						<option value="1">Dasar</option>
	      						<option value="2">Streep</option>
	      					</select>
	      					<p class="pull-right" style="color:red;" id="div3_warna_cek">
	      				</div>
	      			</div>
	      			<div class="form-group hide" id="div3_warna">
	      				<label class="control-label col-sm-4"></label>
	      				<div class="col-sm-8">
	      					<input type="hidden" name="popup3_warna">
	      					<input type="text" class="form-control" id="div2_warna_stok">
	      				</div>
	      			</div> --}}

                    <div class="form-group">
                        <label class="col-sm-4 control-label">Ketarangan</label>
                        <div class="col-sm-8">
                            <textarea class="form-control" name="popup3_ket"></textarea>
                        </div>
                    </div>

	      		</form>
	      	</div>
	      	<h5 id="alert_workorder"></h5>
	      	<div class="modal-footer">
	        	<button type="button" class="btn btn-primary" id="btn_popup3_simpan">Simpan</button>
	      	</div>
	    </div>
	</div>
</div>

<input type="hidden" name="store_konversi">
<input type="hidden" name="store_rubahsatuan">


<!----Modal---->
<script type="text/javascript">
	var table_barang;
	var tb_no = parseInt(10000);
    var load_gudang = 0;
    var load_gudang2 = 0;
	$(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();


		get_barang();
        get_nomor();
		/*get_warna();*/

		var id = '{{ $data['data']['id_barangkeluar']}}';
        console.log(id);
		if(id != ''){
			get_edit(id);
			readonly('[name=tanggal]', true);
			readonly('[name=tanggal_perkiraan]', true);
		}
		var pegawai = $("[name=pegawai]").val();
		if(pegawai > 0){
			disabled('[name=rekanan]', true);	
		}else{
			disabled('[name=rekanan]', false);
		}

		var rekanan = $("[name=rekanan]").val();
		if(rekanan > 0){
			disabled('[name=pegawai]',true);	
		}else{
			disabled('[name=pegawai]',false);
		}

        $("#div_menghasilkan").hide();
        $("#satuan_menghasilkan").text('');

        $("#div2_menghasilkan").hide();
        $("#satuan2_menghasilkan").text('');

        perkiraan_hasil();
		
	})

	//--------------------------------------
	$("[name=workorder]").change(function(){
		$("[name=proses]").val('').trigger('change');
	})

	//---------------------------------------


	$("#btn_tambah_item").click(function(){
		$("[name=popup_id_table]").val('');
		$("[name=popup_proses]").val(null).trigger('change');
		$("[name=popup_gudang]").val(null).trigger('change');
		$("[name=input_warna]").val(null).trigger('change');
		$("[name=popup_barang]").html('');
		$("[name=popup_stok]").text('');
		$("[name=popup_jumlah]").val('');
        $("[name=popup_satuanawal]").val(null).trigger('change');
        $("[name=popup_menghasilkan]").val('');
        $("[name=popup_satuanhasil]").val(null).trigger('change');
		$("#div_konversi").addClass('hide');
        $("[name=store_rubahsatuan]").val('');
        $("[name=popup_jumlahhasil]").val('');
        $("[name=popup_satuanhasil]").val(null).trigger('change');

		/*$("[name=popup_jumlah_konv]").val('');*/
		$("#popup_satuanawal").text('');
		$("#popup_satuanakhir").text('');

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

		$("#exampleModal").modal({backdrop: true, keyboard: false, show: true});
        $("#exampleModal").data('bs.modal').options.backdrop = 'static';
	})

		

	$("[name=pegawai]").change(function(){
		var pegawai = $("[name=pegawai]").val();

		if(pegawai > 0){
			disabled('[name=rekanan]', true);
			
		}else{
			disabled('[name=rekanan]', false);
		}
	});

	$("[name=rekanan]").change(function(){
		var rekanan = $("[name=rekanan]").val();

		if(rekanan > 0){
			disabled('[name=pegawai]',true);
			
		}else{
			disabled('[name=pegawai]',false);
		}
	});

    $("[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_rubahsatuan]").val());

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

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

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

    function popup_jumlah(id){
        var jum = parseFloat($("#tabel_jumlah"+id).val());
        if(isNaN(jum) || jum == 0 || jum == ''){
            jum = parseFloat(0);
        }
        var nilai = parseFloat($("[name=store_rubahsatuan]").val());

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



	$("[name=spk]").change(function(){
		var c_spk = $("[name=spk]").val();

		if(c_spk > 0){
			disabled('[name=workorder]',true);
		}else{
			disabled('[name=workorder]',false);
		}
	})

	$("[name=workorder]").change(function(){
		var c_workorder = $("[name=workorder]").val();

		if(c_workorder > 0){
			disabled('[name=spk]',true);
		}else{
			disabled('[name=spk]',false);
		}
	})

    //-------------------------- Popup kosong Tambah -----------------------------------//
    $("[name=input_warna]").change(function(){
        $("[name=popup_gudang]").val(null).trigger('change');
        $("[name=popup_barang]").val(null).trigger('change');
        $("#popup_stok").text('');
    })

    $("[name=popup_proses]").change(function(){
        $("[name=input_war]").val(null).trigger('change');
        $("[name=popup_gudang]").val(null).trigger('change');
        $("[name=popup_barang]").val(null).trigger('change');
        $("#popup_stok").text('');
    })


	/* -------------------------- Pilih Proses ---------------------------------------*/

	$("[name=proses55]").change(function(){
		var id_proses = $(this).val();
		var id_workorder = $("[name=workorder]").val();
		var spk = $("[name=spk]").val();
		var gudang = $('[name=popup_gudang]').html();
		get_barang();
        if(id_proses != '' && id_workorder != ''){
			$.ajax({
			url: "{{url('barangkeluar/cek_proses')}}",
			type: "post",
			dataType: "json",
			data: {id_proses : id_proses,id_workorder : id_workorder},
			headers : {
				'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			},
			success: function(result){
				if(id_proses > '36'){
					$("#div_kualitas").removeClass('hide');
				}else{
					$("#div_kualitas").addClass('hide');
				}
				if(result.length > 0){
						table_barang.clear().draw();
						$('#btnworkorder').html('<div class="alert alert-warning" id="alert_work">'+
						    	'<button type="button" class="close" data-dismiss="alert"><span>×</span><span class="sr-only">Close</span></button>'+
						        '<i><b>*Proses '+result[0].nama_proses+' sudah dilakukan</b></i>'+
						    '</div>');
                
        
				}else if(id_proses == '25'){
						$("#alert_work").hide();
						$.ajax({
						url: "{{url('barangkeluar/get_workorder_detail')}}",
						type: "post",
						dataType: "json",
						data: {id_workorder : id_workorder},
						headers : {
							'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
						},
						success : function(respon){
							if(respon.length > 0){
								table_barang.clear().draw();
								for(i in respon){
									table_barang.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_warna'+respon[i].id+'">'+respon[i].nama_warna+'</div>',
										'<div id="list_gudang'+respon[i].id+'"></div>',
										'<div id="list_jumlah'+respon[i].id+'"></div>',
                                        '<div id="list_ket'+respon[i].id+'"></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 id="btnhapus'+respon[i].id+'" class="btn bg-danger-800" type="button" onclick="hapus($(this))"><i class="icon-eraser"></i></button></div>'+
										'<input type="hidden" name="tabel_id[]" class="tabel_id" id="tabel_id'+respon[i].id+'" value="'+respon[i].id+'">'+
										'<input type="hidden" name="tabel_idbarangkeluar[]" id="tabel_idbarangkeluar'+respon[i].id+'" value="'+respon[i].id_barang+'">'+
										'<input type="hidden" name="tabel_idbarang[]" class="id_proses_barang" id="tabel_idbarang'+respon[i].id+'" value="'+respon[i].id_barang+'">'+
										'<input type="hidden" id="tabel_jumlah'+respon[i].id+'" name="tabel_jumlah[]" value="0">'+
										'<input type="hidden" id="tabel_satuan'+respon[i].id+'" name="tabel_satuan[]">'+
										'<input type="hidden" id="tabel_jumlah_konv'+respon[i].id+'" name="tabel_jumlah_konv[]">'+
										'<input type="hidden" id="tabel_idgudang'+respon[i].id+'" name="tabel_idgudang[]">'+
										'<input type="hidden" id="tabel_warna'+respon[i].id+'" name="tabel_warna[]" value="'+respon[i].id_warna+'">'+
										'<input type="hidden" id="tabel_namawarna'+respon[i].id+'" name="tabel_namawarna[]" value="'+respon[i].nama_warna+'">'+
										'<input type="hidden" id="tabel_proses2'+respon[i].id+'" name="tabel_proses2[]">'+
                                        '<input type="hidden" id="tabel_atribut'+respon[i].id+'" name="tabel_atribut[]">'+
                                        '<input type="hidden" id="tabel_idkualitas'+respon[i].id+'" name="tabel_idkualitas[]">'+
                                        '<input type="hidden" id="tabel_idkualitas_dudul'+respon[i].id+'" name="tabel_idkualitas_dudul[]">'+
                                        '<input type="hidden" id="tabel_idlabel'+respon[i].id+'" name="tabel_idlabel[]">'+
                                        '<input type="hidden" id="tabel_idkemasan'+respon[i].id+'" name="tabel_idkemasan[]">'+
                                        '<input type="hidden" id="tabel_idkemasan_satuan'+respon[i].id+'" name="tabel_idkemasan_satuan[]">'+
                                        '<input type="hidden" id="tabel_idkemasan_sepuluh'+respon[i].id+'" name="tabel_idkemasan_sepuluh[]">'+
                                        '<input type="hidden" id="tabel_idkemasan_seratus'+respon[i].id+'" name="tabel_idkemasan_seratus[]">'+
                                        '<input type="hidden" id="tabel_idcap'+respon[i].id+'" name="tabel_idcap[]">'+
                                        '<input type="hidden" id="tabel_keterangan'+respon[i].id+'" name="tabel_keterangan[]">'
										]).draw(false);
									$('.select-search').select2();
								}

							}else{
								table_barang.clear().draw();
							}
						}
					})
						
				}else{
						$("#alert_work").hide();
						$.ajax({
						url: "{{url('barangkeluar/get_workorder_detail')}}",
						type: "post",
						dataType: "json",
						data: {id_workorder : id_workorder},
						headers : {
							'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
						},
						success : function(respon){
							if(respon.length > 0){
								table_barang.clear().draw();
								for(i in respon){
									table_barang.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_warna'+respon[i].id+'">'+respon[i].nama_warna+'</div>',
										'<div id="list_gudang'+respon[i].id+'"></div>',
										'<div id="list_jumlah'+respon[i].id+'"></div>',
                                        '<div id="list_keterangan'+respon[i].id+'"></div>',
										/*'<div id="list_jumlah_konv'+respon[i].id+'"></div>',*/
										'<div><button type="button" id="btnedit'+respon[i].id+'" class="btn bg-warning-400" onclick="edit_table2('+respon[i].id+')"><i class="icon-pencil"></i> </button><button id="btnhapus'+respon[i].id+'" class="btn bg-danger-800" type="button" onclick="hapus($(this))"><i class="icon-eraser"></i></button></div>'+
										'<input type="hidden" name="tabel_id[]" class="tabel_id" id="tabel_id'+respon[i].id+'" value="'+respon[i].id+'">'+
										'<input type="hidden" name="tabel_idbarangkeluar[]" id="tabel_idbarangkeluar'+respon[i].id+'" value="'+respon[i].id_barang+'">'+
										'<input type="hidden" name="tabel_idbarang[]" class="id_proses_barang" id="tabel_idbarang'+respon[i].id+'" value="'+respon[i].id_barang+'">'+
										'<input type="hidden" id="tabel_jumlah'+respon[i].id+'" name="tabel_jumlah[]" value="0">'+
										'<input type="hidden" id="tabel_satuan'+respon[i].id+'" name="tabel_satuan[]">'+
										'<input type="hidden" id="tabel_jumlah_konv'+respon[i].id+'" name="tabel_jumlah_konv[]">'+
										'<input type="hidden" id="tabel_idgudang'+respon[i].id+'" name="tabel_idgudang[]">'+
										'<input type="hidden" id="tabel_warna'+respon[i].id+'" name="tabel_warna[]" value="'+respon[i].id_warna+'">'+
										'<input type="hidden" id="tabel_namawarna'+respon[i].id+'" name="tabel_namawarna[]" value="'+respon[i].nama_warna+'">'+
										'<input type="hidden" id="tabel_proses2'+respon[i].id+'" name="tabel_proses2[]">'+
										'<input type="hidden" id="tabel_idcorak'+respon[i].id+'" name="tabel_idcorak[]">'+
										'<input type="hidden" id="tabel_idmotif'+respon[i].id+'" name="tabel_idmotif[]">'+
                                        '<input type="hidden" id="tabel_atribut'+respon[i].id+'" name="tabel_atribut[]">'+
                                        '<input type="hidden" id="tabel_idkualitas'+respon[i].id+'" name="tabel_idkualitas[]">'+
                                        '<input type="hidden" id="tabel_idkualitas_dudul'+respon[i].id+'" name="tabel_idkualitas_dudul[]">'+
                                        '<input type="hidden" id="tabel_idlabel'+respon[i].id+'" name="tabel_idlabel[]">'+
                                        '<input type="hidden" id="tabel_idkemasan'+respon[i].id+'" name="tabel_idkemasan[]">'+
                                        '<input type="hidden" id="tabel_idkemasan_satuan'+respon[i].id+'" name="tabel_idkemasan_satuan[]">'+
                                        '<input type="hidden" id="tabel_idkemasan_sepuluh'+respon[i].id+'" name="tabel_idkemasan_sepuluh[]">'+
                                        '<input type="hidden" id="tabel_idkemasan_seratus'+respon[i].id+'" name="tabel_idkemasan_seratus[]">'+
                                        '<input type="hidden" id="tabel_idcap'+respon[i].id+'" name="tabel_idcap[]">'+
                                        '<input type="hidden" id="tabel_keterangan'+respon[i].id+'" name="tabel_keterangan[]">'
										]).draw(false);
									$('.select-search').select2();
								}

                                if(id_proses >= '37'){
                                    table_barang.clear().draw();
                                    }

							}else{
								table_barang.clear().draw();
							}
						}
					})
				}

                

			}
		})


		}else if(id_proses != '' && spk != '' && id_workorder ==''){
		$.ajax({
			url: "{{url('barangkeluar/cek_proses_spk')}}",
			type: "post",
			dataType: "json",
			data: {id_proses : id_proses, id_workorder : spk},
			headers : {
				'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			},
			success: function(result){
				if(id_proses > '36'){
					$("#div_kualitas").removeClass('hide');
				}else{
					$("#div_kualitas").addClass('hide');
				}
				if(result.length > 0){
						table_barang.clear().draw();
						$('#btnworkorder').html('<div class="alert alert-warning" id="alert_work">'+
						    	'<button type="button" class="close" data-dismiss="alert"><span>×</span><span class="sr-only">Close</span></button>'+
						        '<i><b>*Proses '+result[0].nama_proses+' sudah dilakukan</b></i>'+
						    '</div>');
				
				}else{
						$("#alert_work").hide();
						$.ajax({
						url: "{{url('barangkeluar/get_spk_detail')}}",
						type: "post",
						dataType: "json",
						data: {id_workorder : spk},
						headers : {
							'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
						},
						success : function(respon){
							if(respon.length > 0){
								table_barang.clear().draw();
								for(i in respon){
									table_barang.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_warna'+respon[i].id+'"></div>',
										'<div id="list_gudang'+respon[i].id+'"></div>',
										'<div id="list_jumlah'+respon[i].id+'"></div>',
                                        '<div id="list_keterangan'+respon[i].id+'"></div>',
										/*'<div id="list_jumlah_konv'+respon[i].id+'"></div>',*/
										'<div><button type="button" id="btnedit'+respon[i].id+'" class="btn bg-warning-400" onclick="edit_table2('+respon[i].id+')"><i class="icon-pencil"></i> </button><button id="btnhapus'+respon[i].id+'" class="btn bg-danger-800" type="button" onclick="hapus($(this))"><i class="icon-eraser"></i></button></div>'+
										'<input type="hidden" name="tabel_id[]" class="tabel_id" id="tabel_id'+respon[i].id+'" value="'+respon[i].id+'">'+
										'<input type="hidden" name="tabel_idbarangkeluar[]" id="tabel_idbarangkeluar'+respon[i].id+'" value="'+respon[i].id_barang+'">'+
										'<input type="hidden" name="tabel_idbarang[]" class="id_proses_barang" id="tabel_idbarang'+respon[i].id+'" value="'+respon[i].id_barang+'">'+
										'<input type="hidden" id="tabel_jumlah'+respon[i].id+'" name="tabel_jumlah[]" value="0">'+
										'<input type="hidden" id="tabel_satuan'+respon[i].id+'" name="tabel_satuan[]">'+
										'<input type="hidden" id="tabel_jumlah_konv'+respon[i].id+'" name="tabel_jumlah_konv[]">'+
										'<input type="hidden" id="tabel_idgudang'+respon[i].id+'" name="tabel_idgudang[]">'+
										'<input type="hidden" id="tabel_warna'+respon[i].id+'" name="tabel_warna[]">'+
										'<input type="hidden" id="tabel_namawarna'+respon[i].id+'" name="tabel_namawarna[]">'+
										'<input type="hidden" id="tabel_proses2'+respon[i].id+'" name="tabel_proses2[]">'+
										'<input type="hidden" id="tabel_idcorak'+respon[i].id+'" name="tabel_idcorak[]">'+
										'<input type="hidden" id="tabel_idmotif'+respon[i].id+'" name="tabel_idmotif[]">'+
                                        '<input type="hidden" id="tabel_atribut'+respon[i].id+'" name="tabel_atribut[]">'+
                                        '<input type="hidden" id="tabel_idkualitas'+respon[i].id+'" name="tabel_idkualitas[]">'+
                                        '<input type="hidden" id="tabel_idkualitas_dudul'+respon[i].id+'" name="tabel_idkualitas_dudul[]">'+
                                        '<input type="hidden" id="tabel_idlabel'+respon[i].id+'" name="tabel_idlabel[]">'+
                                        '<input type="hidden" id="tabel_idkemasan'+respon[i].id+'" name="tabel_idkemasan[]">'+
                                        '<input type="hidden" id="tabel_idkemasan_satuan'+respon[i].id+'" name="tabel_idkemasan_satuan[]">'+
                                        '<input type="hidden" id="tabel_idkemasan_sepuluh'+respon[i].id+'" name="tabel_idkemasan_sepuluh[]">'+
                                        '<input type="hidden" id="tabel_idkemasan_seratus'+respon[i].id+'" name="tabel_idkemasan_seratus[]">'+
                                        '<input type="hidden" id="tabel_idcap'+respon[i].id+'" name="tabel_idcap[]">'+
                                        '<input type="hidden" id="tabel_keterangan'+respon[i].id+'" name="tabel_keterangan[]">'
										]).draw(false);
									$('.select-search').select2();
								}

                                if(id_proses >= '37'){
                                    table_barang.clear().draw();
                                    }

							}else{
								table_barang.clear().draw();
							}
						}
					})
				}
			}
		})
		

		}else{
			table_barang.clear().draw();
		}


	})

	/* -------------------------- Pilih Proses Selesai ---------------------------------------*/
	
	/* -------------------------- Gudang popup tambah ---------------------------------------*/

	$("[name=popup_gudang]").change(function(){
		var id_gudang = $(this).val();
		var id_proses = $("[name=proses]").val();
		var id_proses2 = $("[name=popup_proses]").val();
		var id_komposisi = $("[name=input_warna]").val();
		
		var id_workorder = $("[name=workorder]").val();
		var id_spk = $("[name=spk]").val();
		var spk = id_spk
		if(id_spk == 0){
			spk = "";
		}
		var workorder = id_workorder;
		if(id_workorder == 0){
			workorder = "";
		}
        if(id_gudang != 0 || id_gudang != ''){
		$.ajax({
			url: '{{ url('barangkeluar/get_barang') }}',
			type: 'post',
			dataType: 'json',
			data: {id : id_gudang, id_barang : '', id_proses : id_proses,id_komposisi:id_komposisi,id_proses2:id_proses2, spk:spk, workorder:workorder},
			headers : {
				'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			},
			success: function(respon){
				$("[name=popup_barang]").html('');
				$("[name=popup_stok]").text('');
				if(respon.length > 0){
					$("[name=popup_barang]").append('<option value="">-- Pilih Barang --</option>');
					for(i in respon){
						if(respon[i].stok > 0){
								var id_corak = ''; 
								var nama_corak = '';
								var id_motif = '';
								var nama_motif = '';
                                var id_kual = '';
                                var nama_kual = '';
                                var id_dudul = '';
                                var nama_dudul = '';
                                var id_label = '';
                                var nama_label = '';
                                var id_kemasan = '';
                                var nama_kemasan = '';
                                var id_kemasansatuan = '';
                                var nama_kemasansatuan = '';
                                var id_kemasansepuluh = '';
                                var nama_kemasansepuluh = '';
                                var id_kemasanseratus = '';
                                var nama_kemasanseratus = '';
                                var id_cap = '', nama_cap = '';
								var id_kualitas_proses = '', nama_kualitas_proses = '';
                                var id_kualitas_periksa = '', nama_kualitas_periksa = '';

                                var id_rencana = '';
                                var nama_satuanrencana = '';
                                var nama_rencana = '';
                                var jumlah_rencana = '';

							if(respon[i].id_corak != ''){
								var id_corak = respon[i].id_corak; 
								var nama_corak = ' - '+respon[i].nama_corak; 
							}
							if(respon[i].id_motif != ''){
								var id_motif = respon[i].id_motif; 
								var nama_motif = ' - '+respon[i].nama_motif; 
							}
                            if(respon[i].id_kualitas != ''){
                                var id_kual = respon[i].id_kualitas; 
                                var nama_kual = ' - '+respon[i].nama_kualitas; 
                            }
                            if(respon[i].id_kualitas_dudul != ''){
                                var id_dudul = respon[i].id_kualitas_dudul;
                                var nama_dudul = ' - Dudulan '+respon[i].kualitas_dudul;
                            }

                            if(respon[i].id_label !=''){
                                var id_label = respon[i].id_label;
                                var nama_label = ' - '+respon[i].nama_label;
                            }

                            if(respon[i].id_kemasan != ''){
                                var id_kemasan = respon[i].id_kemasan;
                                var nama_kemasan = ' - '+respon[i].nama_kemasan;
                            }

                            if(respon[i].id_kemasansatuan != ''){
                                var id_kemasansatuan = respon[i].id_kemasansatuan;
                                var nama_kemasansatuan = ' - '+respon[i].nama_kemasansatuan;
                            }

                            if(respon[i].id_kemasansepuluh != ''){
                                var id_kemasansepuluh = respon[i].id_kemasansepuluh;
                                var nama_kemasansepuluh = ' - '+respon[i].nama_kemasansepuluh;
                            }

                            if(respon[i].id_kemasanseratus != ''){
                                var id_kemasanseratus = respon[i].id_kemasanseratus;
                                var nama_kemasanseratus = ' - '+respon[i].nama_kemasanseratus;
                            }

                            if(respon[i].id_cap != ''){
                                var id_cap = respon[i].id_cap; 
                                var nama_cap = ' - '+respon[i].nama_cap; 
                            }

                            if(respon[i].id_kualitas_proses != ''){
                                var id_kualitas_proses = respon[i].id_kualitas_proses; 
                                var nama_kualitas_proses = ' - '+respon[i].nama_kualitas_proses; 
                            }

                            if(respon[i].id_kualitas_periksa != ''){
                                var id_kualitas_periksa = respon[i].id_kualitas_periksa; 
                                var nama_kualitas_periksa = ' - '+respon[i].nama_kualitas_periksa; 
                            }

                            if(respon[i].id_perubahansatuan != ''){
                                var id_rencana = respon[i].id_perubahansatuan;
                                var nama_satuanrencana = respon[i].nama_perubahansatuan;
                                var nama_rencana = ' - '+respon[i].jumlah_rencana+' '+respon[i].nama_perubahansatuan;
                                var jumlah_rencana = respon[i].jumlah_rencana;
                            }

                            $("[name=popup_barang]").append('<option value="'+respon[i].id_barang+'" barang="'+respon[i].nama_barang+'" kode="'+respon[i].kode_barang+'" satuan="'+respon[i].id_satuan+'" corak="'+id_corak+'" motif="'+id_motif+'" kualitas="'+id_kual+'" dudulan="'+id_dudul+'" label="'+id_label+'" kemasan="'+id_kemasan+'" kemasan_satuan="'+id_kemasansatuan+'" kemasan_sepuluh="'+id_kemasansepuluh+'" kemasan_seratus="'+id_kemasanseratus+'" cap="'+id_cap+'" kualitas_proses="'+id_kualitas_proses+'" kualitas_periksa="'+id_kualitas_periksa+'" rencana="'+id_rencana+'" jumlah_rencana="'+jumlah_rencana+'" nama_satuanrencana="'+nama_satuanrencana+'" sub_kategori="'+respon[i].sub_kategori+'" kategori="'+respon[i].kategori+'">'+respon[i].concat_nama+'</option>'); // respon[i].sub_kategori+' - '+respon[i].kategori+' - '+respon[i].kode_barang+' - '+respon[i].nama_barang+nama_corak+nama_motif+nama_kual+nama_dudul+nama_label+nama_kualitas_proses+nama_kualitas_periksa+nama_cap+nama_kemasan+nama_kemasansatuan+nama_kemasansepuluh+nama_kemasanseratus+nama_rencana
						}
					}
				}else{
					$("[name=popup_barang]").html('');
					$("[name=popup_barang]").append('<option value=""> Stok Kosong </option>');
				}
			},complete : function(){
                load_gudang = 1;
            }
		})
        }else{
            $("[name=popup_barang]").html('');
            $("[name=popup_stok]").text('');
        }
	})

	$("[name=popup_barang]").change(function(){
		var id_gudang = $("[name=popup_gudang]").val();
		var id_barang = $(this).val();
		var id_corak = $("[name=popup_barang] :selected").attr('corak');
		var nilai = parseInt(0);
		var id_proses = $("[name=proses]").val();
		var id_komposisi = $("[name=input_warna]").val();
		var id_proses2 = $("[name=popup_proses]").val();
		var workorder = $("[name=workorder]").val();
        var id_kualitas = $("[name=popup_barang] :selected").attr('kualitas');
        var id_dudul = $("[name=popup_barang] :selected").attr('dudulan');
        var id_motif = $("[name=popup_barang] :selected").attr('motif');
        var id_label = $("[name=popup_barang] :selected").attr('label');
        var id_kemasan = $("[name=popup_barang] :selected").attr('kemasan');
        var id_kemasansatuan = $("[name=popup_barang] :selected").attr('kemasan_satuan');
        var id_kemasansepuluh = $("[name=popup_barang] :selected").attr('kemasan_sepuluh');
        var id_kemasanseratus = $("[name=popup_barang] :selected").attr('kemasan_seratus');
        var id_cap = $("[name=popup_barang] :selected").attr('cap');
        var id_kualitas_proses = $("[name=popup_barang] :selected").attr('kualitas_proses');
        var id_kualitas_periksa = $("[name=popup_barang] :selected").attr('kualitas_periksa');
        var id_rencana = $("[name=popup_barang] :selected").attr('rencana');
        var jumlah_rencana = $("[name=popup_barang] :selected").attr('jumlah_rencana');
        var satuan = $("[name=popup_barang] :selected").attr('satuan');
		
        if(id_gudang != ''){
        $.ajax({
			url: '{{ url('barangkeluar/get_barang_hasil') }}',
			type: 'post',
			dataType: 'json',
			data: {id : id_gudang, id_barang : id_barang,id_proses : id_proses,id_komposisi:id_komposisi,id_proses2:id_proses2,id_corak:id_corak,workorder:workorder, id_kualitas:id_kualitas, id_dudul:id_dudul, id_motif:id_motif, id_label:id_label, id_kemasan:id_kemasan, id_kemasansatuan:id_kemasansatuan, id_kemasansepuluh:id_kemasansepuluh, id_kemasanseratus:id_kemasanseratus, id_cap : id_cap,  id_kualitas_proses : id_kualitas_proses, id_kualitas_periksa : id_kualitas_periksa, id_rencana : id_rencana, jumlah_rencana : jumlah_rencana, id_satuan : satuan},
			headers : {
				'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			},
			success: function(respon){
				$.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){
						// 	$("#div_konversi").removeClass('hide');

						// 	$("#popup_satuanawal").text(result[0].satuan_awal);
						// 	$("#popup_satuanakhir").text(result[0].satuan_akhir);
						// 	var n = parseFloat(result[0].nilai_akhir)/parseFloat(result[0].nilai_awal);
						// 	$("[name=store_konversi]").val(n);
						// }else{
						// 	$("#div_konversi").addClass('hide');
						// 	$("[name=popup_jumlah_konv]").val('');
						// 	$("#popup_satuanawal").text(result.satuan_awal);
						// 	$("#popup_satuanakhir").text('');				
						// }

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

				        if(id_proses == '18'){
				        	if($("#tabel_idbarang"+val).val() == id_barang && $("#tabel_status"+val).val() == 0){
				        	var jum = $("#tabel_jumlah"+val).val();
					        total += parseFloat(jum);
				        }	
				        }else{
    				        if($("#tabel_idbarang"+val).val() == id_barang && $("#tabel_warna"+val).val() == id_komposisi && $("#tabel_idcorak"+val).val() == id_corak && $("#tabel_idkualitas"+val).val()  == id_kualitas && $("#tabel_idkualitas_dudul"+val).val() == id_dudul && $("#tabel_idmotif"+val).val() == id_motif && $("#tabel_idlabel"+val).val() == id_label && $("#tabel_idkemasan"+val).val() == id_kemasan && $("#tabel_idkemasan_satuan"+val).val() == id_kemasansatuan && $("#tabel_idkemasan_sepuluh"+val).val() == id_kemasansepuluh && $("#tabel_idkemasan_seratus"+val).val() == id_kemasanseratus && $("#tabel_idcap"+val).val() == id_cap && $("#tabel_idkualitas_proses"+val).val() == id_kualitas_proses && $("#tabel_idkualitas_periksa"+val).val() == id_kualitas_periksa && $("#tabel_idrencana"+val).val() == id_rencana && $("#tabel_rencanajumlah"+val).val() == jumlah_rencana && $("#tabel_satuan"+val).val() == satuan){
    				        	
                                if($("#tabel_status"+val).val() == '0'){
                                    var jum = $("#tabel_jumlah"+val).val();
                                    total += parseFloat(jum);
                                }

                 //                var jum = $("#tabel_jumlah"+val).val();
    					        // total += parseFloat(jum);
    				        }
				        }
				    
                    /*console.log($("#tabel_warna"+val).val() +' 1 '+ id_komposisi + "\n" + $("#tabel_idcorak"+val).val() +' 2 '+ id_corak + "\n" + $("#tabel_idkualitas"+val).val() +' 3 '+ id_kualitas + "\n" + $("#tabel_idkualitas_dudul"+val).val() +' 4 '+ id_dudul + "\n" + $("#tabel_idmotif"+val).val() +' 5 '+ id_motif);*/
                    // console.log(result);
                    // console.log($("#tabel_idbarang"+val).val()+' '+$("#tabel_warna"+val).val()+' '+$("#tabel_idcorak"+val).val()+' '+$("#tabel_idkualitas"+val).val()+' '+$("#tabel_idkualitas_dudul"+val).val()+''+$("#tabel_idmotif"+val).val()+' '+$("#tabel_idlabel"+val).val()+' '+$("#tabel_idkemasan"+val).val()+' '+$("#tabel_idkemasan_satuan"+val).val()+' '+$("#tabel_idkemasan_sepuluh"+val).val()+' '+$("#tabel_idkemasan_seratus"+val).val()+' '+$("#tabel_idcap"+val).val()+' '+$("#tabel_idkualitas_proses"+val).val()+''+$("#tabel_idkualitas_periksa"+val).val()+' '+$("#tabel_idrencana"+val).val()+''+$("#tabel_rencanajumlah"+val).val());
				            
				        });
                    // console.log(id_gudang+'-gudang',id_barang+'-barang',id_proses+'-proses',id_komposisi+'warna',id_proses2+'proses_S',id_corak+'-corak',workorder+'-order',id_kualitas+'-kualitas',id_dudul+'-dudul',id_motif+'-motif', id_label+'-label',id_kemasan+'-kemasan',id_kemasansatuan+'-kemasansatuan',id_kemasansepuluh+'-kemasansepuluh',id_kemasanseratus+'kemasanseratus',id_cap+'-cap',id_kualitas_proses+'kualitas_proses',id_kualitas_periksa+'kualitas_proses', id_rencana+'kualitas_proses',jumlah_rencana+'kualitas_proses');


                        
						if(respon.length > 0){
							if($("[name=popup_id_table]").val() == ''){
								nilai = respon[0].stok-total;
							}else{
								nilai = (respon[0].stok-total)+parseFloat($("[name=popup_jumlah]").val());
							}
							$("[name=popup_stok]").text(nilai+' '+respon[0].nama_satuan);

							$("[name=popup_jumlah]").attr('min', 0);
							$("[name=popup_jumlah]").attr('max', nilai);

                            console.log(respon[0].stok+"-"+total+"-"+$("[name=popup_jumlah]").val());

                            $("[name=popup_satuanawal]").val(respon[0].id_satuan).trigger('change');
                            

                            if(respon[0].id_perubahansatuan != ''){
                                $("#div_menghasilkan").show();
                                $("#satuan_menghasilkan").text(respon[0].nama_perubahansatuan);
                                $("[name=store_rubahsatuan]").val(respon[0].jumlah_rencana);

                                $("[name=popup_menghasilkan]").attr('min', 0);
                                

                                if(respon[0].jumlah_rencana < 1){
                                    $("[name=popup_menghasilkan]").attr('max', (1/(parseFloat(respon[0].jumlah_rencana))/respon[0].stok ) );    
                                }else{
                                    $("[name=popup_menghasilkan]").attr('max', respon[0].jumlah_rencana*respon[0].stok);
                                }

                                if($("[name=popup_id_table]").val() != ''){
                                    popup_jumlah($("[name=popup_id_table]").val());
                                }
                                
                            }else{
                                $("[name=popup_menghasilkan]").val('');
                                $("#satuan_menghasilkan").text('');
                                $("#div_menghasilkan").hide();
                            }
							/*$("[name=popup_jumlah_konv]").attr('min', 0);
							$("[name=popup_jumlah_konv]").attr('max', nilai*$("[name=store_konversi]").val());*/
						}else{
                            $("#div_menghasilkan").hide();
                        }
					}
				})
			}
		})
        }
	})

	function get_barang(){
		var id_proses = $("[name=proses]").val();
		var id_gudang = $("[name=gudang]").val();
		var id_proses2 = $("[name=popup_proses]").val();
		var workorder = $("[name=workorder]").val();
		var spk = $("[name=spk]").val();
		var id_corak = $("[name=popup_barang] :selected").attr('corak');
		var id_komposisi = $("#input_warna").val();
        var id_motif = $("[name=popup_barang] :selected").attr('motif');
        var id_kualitas = $("[name=popup_barang] :selected").attr('kualitas');
        var id_dudul = $("[name=popup_barang] :selected").attr('dudulan');
        var id_label = $("[name=popup_barang] :selected").attr('label');
        var id_kemasan = $("[name=popup_barang] :selected").attr('kemasan');
        var id_kemasansatuan = $("[name=popup_barang] :selected").attr('kemasan_satuan');
        var id_kemasansepuluh = $("[name=popup_barang] :selected").attr('kemasan_sepuluh'); 
        var id_kemasanseratus = $("[name=popup_barang] :selected").attr('kemasan_seratus');
        var id_cap = $("[name=popup_barang] :selected").attr('id_cap');
        var id_kualitas_proses = $("[name=popup_barang] :selected").attr('id_kualitas_proses');
        var id_kualitas_periksa = $("[name=popup_barang] :selected").attr('id_kualitas_periksa');
        var id_rencana = $("[name=popup_kode] :selected").attr('rencana');
        var jumlah_rencana = $("[name=popup_kode] :selected").attr('jumlah_rencana');
        var id_satuan = $("[name=popup_kode] :selected").attr('satuan');
		$.ajax({
			url: '{{ url('barangkeluar/get_barang_proses') }}',
			type: 'post',
			dataType: 'json',
			data:  {id_proses:id_proses,id_gudang:id_gudang,id_proses2:id_proses2, workorder:workorder,spk:spk,id_komposisi:id_komposisi,spk:spk, id_satuan : id_satuan},
			headers : {
				'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			},
			success: function(respon){
				$("[name=popup2_barang]").html('');
				$("[name=popup2_stok]").text('');
				$("[name=popup3_barang]").html('');
				$("[name=popup3_stok]").text('');
				if(respon.length > 0){
					$("[name=popup2_barang]").append('<option value=""> -- Pilih Barang --</option>');
					$("[name=popup3_barang]").append('<option value=""> -- Pilih Barang --</option>');
					for(i in respon){
								var id_corak = ''; 
								var nama_corak = '';
								var id_motif = '';
								var nama_motif = '';
                                var id_kual = '';
                                var nama_kual = '';
                                var id_dudul = '';
                                var nama_dudul = '';
                                var id_label = '';
                                var nama_label = '';
                                var id_kemasan = '';
                                var nama_kemasan = '';
                                var id_kemasansatuan = '';
                                var nama_kemasansatuan = '';
                                var id_kemasansepuluh = '';
                                var nama_kemasansepuluh = '';
                                var id_kemasanseratus = '';
                                var nama_kemasanseratus = '';
                                var id_cap = '', nama_cap = '';
                                var id_kualitas_proses = '', nama_kualitas_proses = '';
                                var id_kualitas_periksa = '', nama_kualitas_periksa = '';
                                var id_rencana = '', nama_rencana = '', jumlah_rencana = '', nama_satuanrencana = '';
							if(respon[i].id_corak != ''){
								var id_corak = respon[i].id_corak; 
								var nama_corak = ' - '+respon[i].nama_corak; 
							}
							if(respon[i].id_motif != ''){
								var id_motif = respon[i].id_motif; 
								var nama_motif = ' - '+respon[i].nama_motif; 
							}
                            if(respon[i].id_kualitas != ''){
                                var id_kual = respon[i].id_kualitas; 
                                var nama_kual = ' - '+respon[i].nama_kualitas; 
                            }

                            if(respon[i].id_kualitas_dudul != ''){
                                var id_dudul = respon[i].id_kualitas_dudul;
                                var nama_dudul = ' - Dudulan '+respon[i].kualitas_dudul;
                            }

                            if(respon[i].id_label !=''){
                                var id_label = respon[i].id_label;
                                var nama_label = ' - '+respon[i].nama_label;
                            }

                            if(respon[i].id_kemasan != ''){
                                var id_kemasan = respon[i].id_kemasan;
                                var nama_kemasan = ' - '+respon[i].nama_kemasan;
                            }

                            if(respon[i].id_kemasansatuan != ''){
                                var id_kemasansatuan = respon[i].id_kemasansatuan;
                                var nama_kemasansatuan = ' - '+respon[i].nama_kemasansatuan
                            }

                            if(respon[i].id_kemasansepuluh != ''){
                                var id_kemasansepuluh = respon[i].id_kemasansepuluh;
                                var nama_kemasansepuluh = respon[i].nama_kemasansepuluh;
                            }

                            if(respon[i].id_kemasanseratus != ''){
                                var id_kemasanseratus = respon[i].id_kemasanseratus;
                                var nama_kemasanseratus = ' - '+respon[i].nama_kemasanseratus;
                            }

                            if(respon[i].id_cap != ''){
                                var id_cap = respon[i].id_cap; 
                                var nama_cap = ' - '+respon[i].nama_cap; 
                            }

                            if(respon[i].id_kualitas_proses != ''){
                                var id_kualitas_proses = respon[i].id_kualitas_proses; 
                                var nama_kualitas_proses = ' - '+respon[i].nama_kualitas_proses; 
                            }

                            if(respon[i].id_kualitas_periksa != ''){
                                var id_kualitas_periksa = respon[i].id_kualitas_periksa; 
                                var nama_kualitas_periksa = ' - '+respon[i].nama_kualitas_periksa; 
                            }

                            if(respon[i].id_perubahansatuan != ''){
                                var id_rencana = respon[i].id_perubahansatuan;
                                var nama_rencana = ' - Untuk '+respon[i].jumlah_rencana+' '+respon[i].nama_perubahansatuan;
                                var nama_satuanrencana = respon[i].nama_perubahansatuan;
                                var jumlah_rencana = respon[i].jumlah_rencana;
                            }

							$("[name=popup2_barang]").append('<option value="'+respon[i].id_barang+'" barang="'+respon[i].nama_barang+'" kode="'+respon[i].kode_barang+'" satuan="'+respon[i].id_satuan+'" corak="'+id_corak+'" motif="'+id_motif+'" kualitas="'+id_kual+'" dudulan="'+id_dudul+'" label="'+id_label+'" kemasan="'+id_kemasan+'" kemasan_satuan="'+id_kemasansatuan+'" kemasan_sepuluh="'+id_kemasansepuluh+'" kemasan_seratus="'+id_kemasanseratus+'" cap="'+id_cap+'"  kualitas_proses="'+id_kualitas_proses+'" kualitas_periksa="'+id_kualitas_periksa+'" rencana="'+id_rencana+'" jumlah_rencana="'+jumlah_rencana+'" nama_satuanrencana="'+nama_satuanrencana+'" sub_kategori="'+respon[i].sub_kategori+'" kategori="'+respon[i].kategori+'">'+respon[i].concat_nama+'</option>'); // respon[i].sub_kategori+' - '+respon[i].kategori+' - '+respon[i].kode_barang+' - '+respon[i].nama_barang+nama_corak+nama_motif+nama_kual+nama_kualitas_proses+nama_kualitas_periksa+nama_dudul+nama_label+nama_cap+nama_kemasan+nama_kemasansatuan+nama_kemasansepuluh+nama_kemasanseratus+nama_rencana
					}
					for(i in respon){
						$("[name=popup3_barang]").append('<option value="'+respon[i].id_barang+'" barang="'+respon[i].nama_barang+'" kode="'+respon[i].kode_barang+'" satuan="'+respon[i].id_satuan+'">'+respon[i].concat_nama+'</option>'); // respon[i].kategori+' - '+respon[i].nama_sub+' - '+respon[i].kode_barang+' - '+respon[i].nama_barang
					}
				}else{
					$("[name=popup2_barang]").html('');
					$("[name=popup2_barang]").append('<option value=""> Stok Kosong </option>');
					$("[name=popup3_barang]").html('');
					$("[name=popup3_barang]").append('<option value=""> Stok Kosong </option>');
				}


			}
		})
	}




	$("[name=popup_warna_tipe]").change(function(){
		var tipe = $(this).val();
		var id_order = $("[name=workorder]").val()
		if(id_order == ""){
			$("#div_warna_cek").text('No.order belum di isikan');
		}else{
			$("#div_warna_cek").text('');
		}
		$.ajax({
			url: '{{ url('barangkeluar/get_warna') }}',
			type: 'post',
			dataType: 'json',
			data: {tipe : tipe, id_order : id_order},
			headers : {
				'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			},
			success: function(respon){
				if(respon.length > 0){
					if(tipe == '1'){
						var id = respon[0].dasar;
						var warna = respon[0].warna_dasar+' ('+respon[0].inisial_dasar+')';
					}else{
						var id = respon[0].streep;
						var warna = respon[0].warna_streep+' ('+respon[0].inisial_streep+')';
					}
						$("#div_warna").removeClass('hide');
						$("[name=popup_warna]").val(id);
						$("#div_warna_stok").val(warna);

				}else{
						$("#div_warna").addClass('hide');
						$("[name=popup_warna]").val('');
						$("#div_warna_stok").val('');
				}
			}
		}) 
	})

	$("#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 kode_barang = $("[name=popup_barang] :selected").attr('kode');
		var nama_barang = $("[name=popup_barang] :selected").attr('barang');
		var nama_gudang = $("[name=popup_gudang] :selected").attr('nama');
		var jumlah = $("[name=popup_jumlah]").val();
		var id_satuan_jumlah = $("[name=popup_satuanawal]").val();
		var satuan_jumlah = $("[name=popup_satuanawal] :selected").attr('nama');		
		var id_warna = $("[name=input_warna]").val();
		var nama_warna = '';
		if(id_warna != '' || id_warna != 0){
			var nama_warna = $("[name=input_warna] :selected").attr("nama");
		}		
		var id_proses2 = $("[name=popup_proses]").val();
		var id_corak = $("[name=popup_barang] :selected").attr('corak');
		var id_motif = $("[name=popup_barang] :selected").attr('motif');
        var id_kualitas = $("[name=popup_barang] :selected").attr('kualitas');
        var id_kualitas_dudul = $("[name=popup_barang] :selected").attr('dudulan');
        var id_label = $('[name=popup_barang] :selected').attr('label');
        var id_kemasan = $('[name=popup_barang] :selected').attr('kemasan');
        var id_kemasansatuan = $('[name=popup_barang] :selected').attr('kemasan_satuan');
        var id_kemasansepuluh = $('[name=popup_barang] :selected').attr('kemasan_sepuluh');
        var id_kemasanseratus = $('[name=popup_barang] :selected').attr('kemasan_seratus');
        var id_cap = $('[name=popup_barang] :selected').attr('cap');
		var id_kualitas_proses = $('[name=popup_barang] :selected').attr('kualitas_proses');
        var id_kualitas_periksa = $('[name=popup_barang] :selected').attr('kualitas_periksa');
		var total = parseFloat(jumlah);
        var id_rencana = $("[name=popup_barang] :selected").attr('rencana');
        var nama_satuanrencana = $("[name=popup_barang] :selected").attr('nama_satuanrencana');
        var jumlah_rencana = $("[name=popup_barang] :selected").attr('jumlah_rencana');
        var kategori = $("[name=popup_barang] :selected").attr('kategori');
        var sub_kategori = $("[name=popup_barang] :selected").attr('sub_kategori');
        var tanggal = $("[name=popup_tanggal]").val();
        var jum_hasil = $("[name=popup_jumlahhasil]").val();
        var satuan_hasil = $("[name=popup_satuanhasil]").val();

        if(jum_hasil == '' || jum_hasil <= 0){
            jum_hasil = '0';
        }
        if(satuan_hasil == ''){
            satuan_hasil = '0';
        }
        var keterangan = $("[name=popup_ket]").val();
		
		if(id_barang != '' && jumlah != ''){
			if(id_data == ''){
				table_barang.row.add(['<div><center></center></div>',
                    '<div id="list_tanggal'+tb_no+'">'+tanggal+'</div>',
					'<div id="list_kode'+tb_no+'">'+kode_barang+'</div>',
					'<div id="list_nama'+tb_no+'">'+sub_kategori+' - '+kategori+' - '+nama_barang+'</div>',
					'<div id="list_warna'+tb_no+'">'+nama_warna+'</div>',
					'<div id="list_gudang'+tb_no+'">'+nama_gudang+'</div>',
					'<div id="list_jumlah'+tb_no+'">'+jumlah+' '+satuan_jumlah+'</div>',
                    '<div id="list_keterangan'+tb_no+'">'+keterangan+'</div>',
					/*'<div id="list_jumlah_konv'+tb_no+'">'+jumlah_konv+' '+satuan_jumlah_konv+'</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_id'+tb_no+'" name="tabel_id[]" value="">'+
					'<input type="hidden" id="tabel_idbarang'+tb_no+'" name="tabel_idbarang[]" value="'+id_barang+'">'+
					'<input type="hidden" id="tabel_idgudang'+tb_no+'" name="tabel_idgudang[]" value="'+id_gudang+'">'+
                    '<input type="hidden" id="tabel_tanggal'+tb_no+'" name="tabel_tanggal[]" value="'+tanggal+'">'+
					// '<input type="hidden" id="tabel_kodebarang'+tb_no+'" name="tabel_kodebarang[]" value="'+kode_barang+'">'+
					'<input type="hidden" id="tabel_jumlah'+tb_no+'" name="tabel_jumlah[]" value="'+jumlah+'">'+
					'<input type="hidden" id="tabel_satuan'+tb_no+'" name="tabel_satuan[]" value="'+id_satuan_jumlah+'">'+
					/*'<input type="hidden" id="tabel_jumlah_konv'+tb_no+'" name="tabel_jumlah_konv[]" value="'+jumlah_konv+'">'+*/
					'<input type="hidden" id="tabel_total'+tb_no+'" name="tabel_total[]" value="'+total+'">'+
					'<input type="hidden" id="tabel_warna'+tb_no+'" name="tabel_warna[]" value="'+id_warna+'">'+
					'<input type="hidden" id="tabel_proses2'+tb_no+'" name="tabel_proses2[]" value="'+id_proses2+'">'+
					'<input type="hidden" id="tabel_idcorak'+tb_no+'" name="tabel_idcorak[]" value="'+id_corak+'">'+
					'<input type="hidden" id="tabel_idmotif'+tb_no+'" name="tabel_idmotif[]" value="'+id_motif+'">'+
                    '<input type="hidden" id="tabel_idkualitas'+tb_no+'" name="tabel_idkualitas[]" value="'+id_kualitas+'">'+
                    '<input type="hidden" id="tabel_idkualitas_dudul'+tb_no+'" name="tabel_idkualitas_dudul[]" value="'+id_kualitas_dudul+'">'+
                    '<input type="hidden" id="tabel_idlabel'+tb_no+'" name="tabel_idlabel[]" value="'+id_label+'">'+
                    '<input type="hidden" id="tabel_idkemasan'+tb_no+'" name="tabel_idkemasan[]" value="'+id_kemasan+'">'+
                    '<input type="hidden" id="tabel_idkemasan_satuan'+tb_no+'" name="tabel_idkemasan_satuan[]" value="'+id_kemasansatuan+'">'+
                    '<input type="hidden" id="tabel_idkemasan_sepuluh'+tb_no+'" name="tabel_idkemasan_sepuluh[]" value="'+id_kemasansepuluh+'">'+
                    '<input type="hidden" id="tabel_idkemasan_seratus'+tb_no+'" name="tabel_idkemasan_seratus[]" value="'+id_kemasanseratus+'">'+
                    '<input type="hidden" id="tabel_idcap'+tb_no+'" name="tabel_idcap[]" value="'+id_cap+'">'+
                    '<input type="hidden" id="tabel_idkualitas_proses'+tb_no+'" name="tabel_idkualitas_proses[]" value="'+id_kualitas_proses+'">'+
                    '<input type="hidden" id="tabel_idkualitas_periksa'+tb_no+'" name="tabel_idkualitas_periksa[]" value="'+id_kualitas_periksa+'">'+
                    '<input type="hidden" id="tabel_idrencana'+tb_no+'" name="tabel_idrencana[]" value="'+id_rencana+'">'+
                    '<input type="hidden" id="tabel_rencanajumlah'+tb_no+'" name="tabel_rencanajumlah[]" value="'+jumlah_rencana+'">'+
                    '<input type="hidden" id="tabel_keterangan'+tb_no+'" name="tabel_keterangan[]" value="'+keterangan+'">'+
                    '<input type="hidden" id="tabel_status'+tb_no+'" name="tabel_status[]" value="0">'+
                    '<input type="hidden" id="tabel_hasilid'+tb_no+'" name="tabel_hasilid[]" value="">'+
                    '<input type="hidden" id="tabel_hasiljumlah'+tb_no+'" name="tabel_hasiljumlah[]" value="'+jum_hasil+'">'+
                    '<input type="hidden" id="tabel_hasilsatuan'+tb_no+'" name="tabel_hasilsatuan[]" value="'+satuan_hasil+'">'
					]).draw(false);
			}else{
                $("#list_tanggal"+id_data).text(tanggal);
				$("#list_kode"+id_data).text(kode_barang);
				$("#list_nama"+id_data).text(sub_kategori+' - '+kategori+' - '+nama_barang);
				$("#list_warna"+id_data).text(nama_warna);
				$("#list_gudang"+id_data).text(nama_gudang);
				$("#list_jumlah"+id_data).text(jumlah+' '+satuan_jumlah);
                $("#list_keterangan"+id_data).text(keterangan);
				
				$("#tabel_id"+id_data).val(id_data);
				$("#tabel_idbarang"+id_data).val(id_barang);
				$("#tabel_namabarang"+id_data).val(nama_barang);				
				$("#tabel_jumlah"+id_data).val(jumlah);
				$("#tabel_satuan"+id_data).val(id_satuan_jumlah);
				$("#tabel_total"+id_data).val(total);
				$("#tabel_proses2"+id_data).val(id_proses2);
				$("#tabel_warna"+id_data).val(id_warna);
				$("#tabel_idcorak"+id_data).val(id_corak);
				$("#tabel_idmotif"+id_data).val(id_motif);
                $("#tabel_idkualitas"+id_data).val(id_kualitas);
                $("#tabel_idkualitas_dudul"+id_data).val(id_kualitas_dudul);
                $("#tabel_idlabel"+id_data).val(id_label);
                $("#tabel_idkemasan"+id_data).val(id_kemasan);
                $("#tabel_idkemasan_satuan"+id_data).val(id_kemasansatuan);
                $("#tabel_idkemasan_sepuluh"+id_data).val(id_kemasansepuluh);
                $("#tabel_idkemasan_seratus"+id_data).val(id_kemasanseratus);
                $("#tabel_idcap"+id_data).val(id_cap);
                $("#tabel_idkualitas_proses"+id_data).val(id_kualitas_proses);
                $("#tabel_idkualitas_periksa"+id_data).val(id_kualitas_periksa);
                $("#tabel_idrencana"+id_data).val(id_rencana);
                $("#tabel_rencanajumlah"+id_data).val(jumlah_rencana);
                $("#tabel_keterangan"+id_data).val(keterangan);
                $("#tabel_tanggal"+id_data).val(tanggal);
                $("#tabel_hasiljumlah"+id_data).val(jum_hasil);
                $("#tabel_hasilsatuan"+id_data).val(satuan_hasil);

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

	

	function edit_table(id){	
        load_gudang = 0;
		var id_barang = $("#tabel_idbarang"+id).val();
		var id_gudang = $("#tabel_idgudang"+id).val();
		var jumlah = $("#tabel_jumlah"+id).val();
		var satuan = $("#tabel_satuan"+id).val();
		/*var jumlah_konv = $("#tabel_jumlah_konv"+id).val();*/
		var warna = $("#tabel_warna"+id).val();
        var corak = $("#tabel_idcorak"+id).val();
		var id_proses = $("[name=proses]").val();
		var id_proses2 = $("#tabel_proses2"+id).val();
		var namasatuan = $("#tabel_namasatuan"+id).val();

        var id_motif = $("#tabel_idmotif"+id).val();        
        var id_kualitas = $("#tabel_idkualitas"+id).val();
        var id_dudul = $("#tabel_idkualitas_dudul"+id).val();
        var id_label = $("#tabel_idlabel"+id).val();
        var id_kemasan = $("#tabel_idkemasan"+id).val();
        var id_kemasansatuan = $("#tabel_idkemasan_satuan"+id).val();
        var id_kemasansepuluh = $("#tabel_idkemasan_sepuluh"+id).val();
        var id_kemasanseratus = $("#tabel_idkemasan_seratus"+id).val();
        var id_cap = $("#tabel_idcap"+id).val();
        var id_kualitas_proses = $("#tabel_idkualitas_proses"+id).val();
        var id_kualitas_periksa = $("#tabel_idkualitas_periksa"+id).val();

        var id_workorder = $("#tabel_id_workorder_barang"+id).val();
        var id_spk = $("#tabel_id_workorder"+id).val();

        var id_rencana = $("#tabel_idrencana"+id).val();
        var jumlah_rencana = $("#tabel_rencanajumlah"+id).val();

        var keterangan = $("#tabel_keterangan"+id).val();
        var tanggal = $("#tabel_tanggal"+id).val();

        var jum_hasil = $("#tabel_hasiljumlah"+id).val();
        var satuan_hasil = $("#tabel_hasilsatuan"+id).val();

        var satuan = $("#tabel_satuan"+id).val();
        // if(jum_hasil == 0){
        //     jum_hasil = '';
        //     satuan_hasil = '';
        // }

		$("[name=popup_id_table]").val(id);

		var FunctionOne = function () {
		  var r = $.Deferred();
		  $("[name=popup_proses]").val(id_proses2).trigger('change');
		  $("#input_warna").val(warna).trigger('change');
		  $("[name=popup_gudang]").val(id_gudang).trigger('change');
		  setTimeout(function () {
		    r.resolve();
		  }, 4000);
		  return r;
		};

        function repeat_first(){
            if(load_gudang == 1){
                FunctionTwo();
            }else{
                setTimeout(repeat_first, 2000);
            }
        }

		var FunctionTwo = function () {
            var jum = $("[name=popup_barang]").find("option[corak='" + corak + "'][motif='" + id_motif + "'][kualitas='" + id_kualitas + "'][dudulan='" + id_dudul + "'][label='" + id_label + "'][kemasan='" + id_kemasan + "'][kemasan_satuan='" + id_kemasansatuan + "'][kemasan_sepuluh='" + id_kemasansepuluh + "'][kemasan_seratus='" + id_kemasanseratus + "'][value='"+ id_barang +"'][satuan='"+satuan+"'][cap='"+id_cap+"'][kualitas_proses='"+id_kualitas_proses+"'][kualitas_periksa='"+id_kualitas_periksa+"'][rencana='"+id_rencana+"'][jumlah_rencana='"+jumlah_rencana+"'][satuan='"+satuan+"'] "); //
            jum.prop('selected', true).trigger("change");
			// $("[name=popup_barang]").val(id_barang).trigger('change');
			$("[name=popup_jumlah]").val(jumlah);
			$("[name=popup_satuanawal]").val(satuan).trigger('change');
			$("[name=popup_tanggal]").val(tanggal);
			/*$("[name=popup2_jumlah_konv]").val(jumlah_konv);*/
			
			$("[name=popup_stok]").text(jumlah);
			$("[name=popup_jumlah]").attr('min', 0);
			$("[name=popup_jumlah]").attr('max', jumlah);
            $("[name=popup_ket]").val(keterangan);
            $("[name=popup_jumlahhasil]").val(jum_hasil);
            $("[name=popup_satuanhasil]").val(satuan_hasil).trigger('change');
            popup_jumlah(id);



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

		FunctionOne().done(repeat_first());
	}

	function edit_table3(id){
		
		var id_barang = $("#tabel_idbarang"+id).val();
		var id_gudang = $("#tabel_idgudang"+id).val();
		var jumlah = $("#tabel_jumlah"+id).val();
		var satuan = $("#tabel_satuan"+id).val();
		/*var jumlah_konv = $("#tabel_jumlah_konv"+id).val();*/
		var warna = $("#tabel_warna"+id).val();
		var id_proses = $("[name=proses]").val();
		var id_proses2 = $("#tabel_proses2"+id).val();
		var namasatuan = $("#tabel_namasatuan"+id).val();

        var keterangan = $("#tabel_keterangan"+id).val();
		
		$("[name=popup3_id_table]").val(id);

		var FunctionOne = function () {
		  var r = $.Deferred();

		  $("[name=popup3_gudang]").val(id_gudang).trigger('change');

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

		var FunctionTwo = function () {
			
			$("[name=popup3_barang]").val(id_barang).trigger('change');
			$("[name=popup3_jumlah]").val(jumlah);
			$("[name=popup3_satuanawal]").val(satuan).trigger('change');
			$("[name=popup3_proses]").val(id_proses2).trigger('change');
			/*$("[name=popup2_jumlah_konv]").val(jumlah_konv);*/
			$("#input3_warna").val(warna).trigger('change');
			$("[name=popup3_stok]").text(jumlah+' '+namasatuan);
			$("[name=popup3_jumlah]").attr('min', 0);
			$("[name=popup3_jumlah]").attr('max', jumlah);
            $("[name=popup3_ket]").text(keterangan);

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

            popup_jumlah(id);
		};

		FunctionOne().done(FunctionTwo);
	}

	/* -------------------------- Gudang popup tambah ---------------------------------------*/

	/* -------------------------- Gudang popup edit ---------------------------------------*/

	$("[name=popup2_warna_tipe]").change(function(){
		var tipe = $(this).val();
		var id_order = $("[name=workorder]").val();
		if(id_order == ""){
			$("#div2_warna_cek").text('No.order belum di isikan');
		}else{
			$("#div2_warna_cek").text('');
		}
		$.ajax({
			url: '{{ url('barangkeluar/get_warna') }}',
			type: 'post',
			dataType: 'json',
			data: {tipe : tipe, id_order : id_order},
			headers : {
				'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			},
			success: function(respon){
				if(respon.length > 0){
					if(tipe == '1'){
						var id = respon[0].dasar;
						var warna = respon[0].warna_dasar+' ('+respon[0].inisial_dasar+')';
					}else{
						var id = respon[0].streep;
						var warna = respon[0].warna_streep+' ('+respon[0].inisial_streep+')';
					}
						

						$("#div2_warna").removeClass('hide');
						$("[name=popup2_warna]").val(id);
						$("#div2_warna_stok").val(warna);
				}else{
						

						$("#div2_warna2").addClass('hide');
						$("[name=popup2_warna]").val('');
						$("#div2_warna_stok").val('');
				}
			}
		}) 
	})



	
	$("[name=popup2_gudang]").change(function(){
		var id_gudang = $(this).val();
		var id_barang =	$("[name=popup2_barang]").val();
		var nilai = parseInt(0);
		var id_proses = $("[name=proses]").val();
		var id_proses2 = $("[name=popup2_proses]").val();
		var id_komposisi = $("[name=input2_warna]").val();
		var id_workorder = $("[name=workorder]").val();
		var id_spk = $("[name=spk]").val();
		var spk = id_spk;
		if(id_spk == 0){
			spk = "";
		}
		var workorder = id_workorder;
		if(id_workorder == 0){
			workorder = "";
		}
		
		$.ajax({
			url: '{{ url('barangkeluar/get_barang') }}',
			type: 'post',
			dataType: 'json',
			data: {id_proses2 : id_proses2 ,id : id_gudang, id_barang : id_barang, id_proses : id_proses, id_komposisi : id_komposisi,spk:spk,workorder:workorder},
			headers : {
				'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			},
			success: function(respon){                
				$.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){
						// 	$("#div_konversi").removeClass('hide');

						// 	$("#popup2_satuanawal").text(result[0].satuan_awal);
						// 	$("#popup2_satuanakhir").text(result[0].satuan_akhir);
						// 	var n = parseInt(result[0].nilai_akhir)/parseInt(result[0].nilai_awal);
						// 	$("[name=store_konversi]").val(n);
						// }else{
						// 	$("#div_konversi").addClass('hide');
						// 	$("[name=popup2_jumlah_konv]").val('');
						// 	$("#popup2_satuanawal").text(result.satuan_awal);
						// 	$("#popup2_satuanakhir").text('');				
						// }

						var total = parseFloat(0);
						$('input[id^="tabel_jumlah"]').each(function() {
				             
				        var val = ($(this).attr('id'));
				        val = val.replace('tabel_jumlah', '');
				        if(id_proses > '18'){
				        	if($("#tabel_idbarang"+val).val() == id_barang && $("#tabel_warna"+val).val() == id_komposisi){
				        	var jum = $("#tabel_jumlah"+val).val();
					        total += parseFloat(jum);
				        	}	
				        }else{
				        	if($("#tabel_idbarang"+val).val() == id_barang){
				        	var jum = $("#tabel_jumlah"+val).val();
					        total += parseFloat(jum);
				        	}  
				        }

				              
				        });

                        
						if(respon.length > 0){
							if($("[name=popup2_id_table]").val() == ''){
								nilai = respon[0].stok-total;
							}else{
								nilai = (respon[0].stok-total)+parseInt($("[name=popup2_jumlah]").val());
							}
							$("[name=popup2_stok]").text(nilai+' '+respon[0].nama_satuan);
							$("[name=popup2_jumlah]").attr('min', 0);
							$("[name=popup2_jumlah]").attr('max', nilai);

							

						}else{
							$("[name=popup2_stok]").text(0);
							$("[name=popup2_jumlah]").attr('min', 0);
							$("[name=popup2_jumlah]").attr('max', 0);

							
						}
					}
				})
			}
		})
	})

	$("[name=popup2_barang]").change(function(){
		var id_gudang = $("[name=popup2_gudang]").val();
		var id_barang =	$(this).val();
		var nilai = parseInt(0);
		var id_proses = $("[name=proses]").val();
		var id_proses2 = $("[name=popup2_proses]").val();
		var id_komposisi = $("[name=input2_warna]").val();
		var id_workorder = $("[name=workorder]").val();
		var id_spk = $("[name=spk]").val();
		var spk = id_spk;
        var id_corak = $("[name=popup2_barang] :selected").attr('corak');
        var id_motif = $("[name=popup2_barang] :selected").attr('motif');
        var id_kualitas = $("[name=popup2_barang] :selected").attr('kualitas');
        var id_dudul = $("[name=popup2_barang] :selected").attr('dudulan');
        var id_label = $("[name=popup2_barang] :selected").attr('label');
        var id_kemasan = $("[name=popup2_barang] :selected").attr('kemasan');
        var id_kemasansatuan = $("[name=popup2_barang] :selected").attr('kemasan_satuan');
        var id_kemasansepuluh = $("[name=popup2_barang] :selected").attr('kemasan_sepuluh');
        var id_kemasanseratus = $("[name=popup2_barang] :selected").attr('kemasan_seratus');
        var id_cap = $("[name=popup2_barang] :selected").attr('cap');
        var id_kualitas_proses = $("[name=popup2_barang] :selected").attr('kualitas_proses');
        var id_kualitas_periksa = $("[name=popup2_barang] :selected").attr('kualitas_periksa');
        var id_rencana = $("[name=popup2_barang] :selected").attr('rencana');
        var jumlah_rencana = $("[name=popup2_barang] :selected").attr('jumlah_rencana');
        var satuan = $("[name=popup2_barang] :selected").attr('satuan');
		if(id_spk == 0){
			spk = "";
		}
		var workorder = id_workorder;
		if(id_workorder == 0){
			workorder = "";
		}
		
		$.ajax({
			url: '{{ url('barangkeluar/get_barang2') }}',
			type: 'post',
			dataType: 'json',
			//data: {id_proses2 : id_proses2 ,id : id_gudang, id_barang : id_barang, id_proses : id_proses, id_komposisi : id_komposisi,spk:spk,workorder:workorder},
            data : {id : id_gudang, id_barang : id_barang,id_proses : id_proses,id_komposisi:id_komposisi,id_proses2:id_proses2,id_corak:id_corak,workorder:workorder, id_kualitas:id_kualitas, id_dudul:id_dudul, id_motif:id_motif, id_label:id_label, id_kemasan:id_kemasan, id_kemasansatuan:id_kemasansatuan, id_kemasansepuluh:id_kemasansepuluh, id_kemasanseratus:id_kemasanseratus, id_cap : id_cap,  id_kualitas_proses : id_kualitas_proses, id_kualitas_periksa : id_kualitas_periksa, id_rencana : id_rencana, jumlah_rencana : jumlah_rencana, id_satuan : satuan},
			headers : {
				'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			},
			success: function(respon){
				$.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){
						// 	$("#div_konversi").removeClass('hide');

						// 	$("#popup2_satuanawal").text(result[0].satuan_awal);
						// 	$("#popup2_satuanakhir").text(result[0].satuan_akhir);
						// 	var n = parseInt(result[0].nilai_akhir)/parseInt(result[0].nilai_awal);
						// 	$("[name=store_konversi]").val(n);
						// }else{
						// 	$("#div_konversi").addClass('hide');
						// 	$("[name=popup2_jumlah_konv]").val('');
						// 	$("#popup2_satuanawal").text(result.satuan_awal);
						// 	$("#popup2_satuanakhir").text('');				
						// }

						/*var total = parseFloat(0);
						$('input[id^="tabel_jumlah"]').each(function() {
				              
				        var val = ($(this).attr('id'));
				        val = val.replace('tabel_jumlah', '');
				        if(id_proses > '18'){
				        	if($("#tabel_idbarang"+val).val() == id_barang && $("#tabel_warna"+val).val() == warna && $("#tabel_idcorak"+val).val() == corak && $("#tabel_idkualitas"+val).val()  == id_kualitas && $("#tabel_idkualitas_dudul"+val).val() == id_dudul && $("#tabel_idmotif"+val).val() == id_motif && $("#tabel_idlabel"+val).val() == id_label && $("#tabel_idkemasan"+val).val() == id_kemasan && $("#tabel_idkemasan_satuan"+val).val() == id_kemasansatuan && $("#tabel_idkemasan_satuan"+val).val() == id_kemasansatuan && $("#tabel_idkemasan_sepuluh"+val).val() == id_kemasansepuluh && $("#tabel_idkemasan_seratus"+val).val() == id_kemasanseratus && $("#tabel_idcap"+val).val() == id_cap){
				        	var jum = $("#tabel_jumlah"+val).val();
					        total += parseFloat(jum);
				        	}	
				        }else{
				        	if($("#tabel_idbarang"+val).val() == id_barang){
				        	var jum = $("#tabel_jumlah"+val).val();
					        total += parseFloat(jum);
				        	}
				        }
				        

				              
				        });
						if(respon.length > 0){
							if($("[name=popup2_id_table]").val() == ''){
								nilai = respon[0].stok-total;
							}else{
								nilai = (respon[0].stok-total)+parseInt($("[name=popup2_jumlah]").val());
							}

							$("[name=popup2_stok]").text(nilai+' '+respon[0].nama_satuan);
							$("[name=popup2_jumlah]").attr('min', 0);
							$("[name=popup2_jumlah]").attr('max', nilai);

							

						}else{
							$("[name=popup2_stok]").text(0);
							$("[name=popup2_jumlah]").attr('min', 0);
							$("[name=popup2_jumlah]").attr('max', 0);

							
						}*/
					}                    
				})
			}
		})
	})
	
	$("#btn_popup2_simpan").click(function(){
		var id_data = $("[name=popup2_id_table]").val();
		var id_barang = $("[name=popup2_barang]").val();
		var id_gudang = $("[name=popup2_gudang]").val();
		var kode_barang = $("[name=popup2_barang] :selected").attr('kode');
		var nama_barang = $("[name=popup2_barang] :selected").attr('barang');
		var nama_gudang = $("[name=popup2_gudang] :selected").attr('nama');
		var jumlah = $("[name=popup2_jumlah]").val();
		var id_satuan_jumlah = $("[name=popup2_satuanawal]").val();
		var satuan_jumlah = $("[name=popup2_satuanawal] :selected").attr('nama');
		
		var id_warna = $("[name=input2_warna] :selected").val();
		var nama_warna = '';
        if(id_warna != '' || id_warna != 0){
            var nama_warna = $("[name=input2_warna] :selected").attr("nama");
        }
		var id_proses2 = $("[name=popup2_proses]").val();

		var id_corak = $("[name=popup2_barang] :selected").attr('corak');
		var id_motif = $("[name=popup2_barang] :selected").attr('motif');
        var id_kualitas = $("[name=popup2_barang] :selected").attr('kualitas');
        var id_kualitas_dudul = $("[name=popup_barang] :selected").attr('dudulan');
        var id_label = $('[name=popup_barang] :selected').attr('label');
        var id_kemasan = $('[name=popup_barang] :selected').attr('kemasan');
        var id_kemasansatuan = $('[name=popup_barang] :selected').attr('kemasan_satuan');
        var id_kemasansepuluh = $('[name=popup_barang] :selected').attr('kemasan_sepuluh');
        var id_kemasanseratus = $('[name=popup_barang] :selected').attr('kemasan_seratus');
        var id_cap = $('[name=popup_barang] :selected').attr('cap');
        var id_kualitas_proses = $('[name=popup_barang] :selected').attr('kualitas_proses');
        var id_kualitas_periksa = $('[name=popup_barang] :selected').attr('kualitas_periksa');	
        var total = parseInt(jumlah);

        var keterangan = $("[name=popup2_ket]").val();
        var tanggal = $("[name=popup2_tanggal]").val();

        var jum_hasil = $("[name=popup2_jumlahhasil]").val();
        var satuan_hasil = $("[name=popup2_satuanhasils]").val();

        if(jum_hasil == '' || jum_hasil <= 0){
            jum_hasil = '0';
        }
        if(satuan_hasil == ''){
            satuan_hasil = '0';
        }

		if(id_barang != '' && jumlah != '' && jumlah != 0){
			if(id_data == ''){
				table_barang.row.add(['<div><center></center></div>',
                    '<div id="list_tanggal'+tb_no+'">'+tanggal+'</div>',
					'<div id="list_kode'+tb_no+'">'+kode_barang+'</div>',
					'<div id="list_nama'+tb_no+'">'+nama_barang+'</div>',
					'<div id="list_gudang'+tb_no+'">'+nama_gudang+'</div>',
					'<div id="list_jumlah'+tb_no+'">'+jumlah+'</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_id'+tb_no+'" name="tabel_id[]" value="">'+
					'<input type="hidden" id="tabel_idbarang'+tb_no+'" name="tabel_idbarang[]" value="'+id_barang+'">'+
					'<input type="hidden" id="tabel_idgudang'+tb_no+'" name="tabel_idgudang[]" value="'+id_gudang+'">'+
					
					'<input type="hidden" id="tabel_jumlah'+tb_no+'" name="tabel_jumlah[]" value="'+jumlah+'">'+
					'<input type="hidden" id="tabel_satuan'+tb_no+'" name="tabel_satuan[]" value="'+id_satuan_jumlah+'">'+
					'<input type="hidden" id="tabel_total'+tb_no+'" name="tabel_total[]" value="'+total+'">'+
					'<input type="hidden" id="tabel_warna'+tb_no+'" name="tabel_warna[]" value="'+id_warna+'">'+
					'<input type="hidden" id="tabel_proses2'+tb_no+'" name="tabel_proses2[]" value="'+id_proses2+'">'+
					'<input type="hidden" id="tabel_idcorak'+tb_no+'" name="tabel_idcorak[]" value="'+id_corak+'">'+
					'<input type="hidden" id="tabel_idmotif'+tb_no+'" name="tabel_idmotif[]" value="'+id_motif+'">'+
                    '<input type="hidden" id="tabel_idkualitas'+tb_no+'" name="tabel_idkualitas[]" value="'+id_kualitas+'">'+
                    '<input type="hidden" id="tabel_idkualitas_dudul'+tb_no+'" name="tabel_idkualitas_dudul[]" value="'+id_kualitas_dudul+'">'+
                    '<input type="hidden" id="tabel_idlabel'+tb_no+'" name="tabel_idlabel[]" value="'+id_label+'">'+
                    '<input type="hidden" id="tabel_idkemasan'+tb_no+'" name="tabel_idkemasan[]" value="'+id_kemasan+'">'+
                    '<input type="hidden" id="tabel_idkemasan_satuan'+tb_no+'" name="tabel_idkemasan_satuan[]" value="'+id_kemasansatuan+'">'+
                    '<input type="hidden" id="tabel_idkemasan_sepuluh'+tb_no+'" name="tabel_idkemasan_sepuluh[]" value="'+id_kemasansepuluh+'">'+
                    '<input type="hidden" id="tabel_idkemasan_seratus'+tb_no+'" name="tabel_idkemasan_seratus[]" value="'+id_kemasanseratus+'">'+
                    '<input type="hidden" id="tabel_idcap'+tb_no+'" name="tabel_idcap[]" value="'+id_cap+'">'+
                    '<input type="hidden" id="tabel_idkualitas_proses'+tb_no+'" name="tabel_idkualitas_proses[]" value="'+id_kualitas_proses+'">'+
                    '<input type="hidden" id="tabel_idkualitas_periksa'+tb_no+'" name="tabel_idkualitas_periksa[]" value="'+id_kualitas_periksa+'">'+
                    '<input type="hidden" id="tabel_keterangan'+tb_no+'" name="tabel_keterangan[]" value="'+keterangan+'">'+
                    '<input type="hidden" id="tabel_tanggal'+tb_no+'" name="tabel_tanggal[]" value="'+tanggal+'">'+
                    '<input type="hidden" id="tabel_hasilid'+tb_no+'" name="tabel_hasilid[]" value="">'+
                    '<input type="hidden" id="tabel_hasiljumlah'+tb_no+'" name="tabel_hasiljumlah[]" value="'+jum_hasil+'">'+
                    '<input type="hidden" id="tabel_hasilsatuan'+tb_no+'" name="tabel_hasilsatuan[]" value="'+satuan_hasil+'">'
					]).draw(false);

				
			}else{
                $("#list_tanggal"+id_data).text(tanggal);
				$("#list_kode"+id_data).text(kode_barang);
				$("#list_nama"+id_data).text(nama_barang);
				$("#list_warna"+id_data).text(nama_warna);
				$("#list_gudang"+id_data).text(nama_gudang);
				$("#list_jumlah"+id_data).text(jumlah+' '+satuan_jumlah);
                $("#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_warna"+id_data).val(id_warna);
				$("#tabel_namabarang"+id_data).val(nama_barang);				
				$("#tabel_jumlah"+id_data).val(jumlah);
				$("#tabel_satuan"+id_data).val(id_satuan_jumlah);
				/*$("#tabel_jumlah_konv"+id_data).val(jumlah_konv);*/
				$("#tabel_total"+id_data).val(total);
				$("#tabel_proses2"+id_data).val(id_proses2);
				$("#tabel_warna"+id_data).val(id_warna);
				$("#tabel_idcorak"+id_data).val(id_corak);
				$("#tabel_idmotif"+id_data).val(id_motif);
                $("#tabel_idkualitas"+id_data).val(id_kualitas);			
                $("#tabel_idkualitas_dudul"+id_data).val(id_kualitas_dudul);
                $("#tabel_idlabel"+id_data).val(id_label);
                $("#tabel_idkemasan"+id_data).val(id_kemasan);
                $("#tabel_idkemasan_satuan"+id_data).val(id_kemasansatuan);
                $("#tabel_idkemasan_sepuluh"+id_data).val(id_kemasansepuluh);
                $("#tabel_idkemasan_seratus"+id_data).val(id_kemasanseratus);
                $("#tabel_idcap"+id_data).val(id_cap);
                $("#tabel_idkualitas_proses"+id_data).val(id_kualitas_proses);
                $("#tabel_idkualitas_periksa"+id_data).val(id_kualitas_periksa);
                $("#tabel_keterangan"+id_data).val(keterangan);
                $("#tabel_tanggal"+id_data).val(tanggal);
                $("#tabel_hasiljumlah"+id_data).val(jum_hasil);
                $("#tabel_hasilsatuan"+id_data).val(satuan_hasil);
			}
		
		$("#exampleModal2").modal('hide');
		tb_no++;
		}
	})

	function get_barang2(id,gudang,proses,proses2,corak,komposisi,id_motif,id_kualitas,id_dudul,id_label,id_kemasan, id_kemasansatuan, id_kemasansepuluh, id_kemasanseratus, id_cap, id_kualitas_proses, id_kualitas_periksa, id_rencana, jumlah_rencana, satuan){		
		var id_workorder = $("[name=workorder]").val();
		var id_spk = $("[name=spk]").val();
		var spk = id_spk
		if(id_spk == 0){
			spk = "";
		}
		var workorder = id_workorder;
		if(id_workorder == 0){
			workorder = "";
		}
		
		$.ajax({
			url: '{{ url('barangkeluar/get_barang_prosesedit') }}',
			type: 'post',
			dataType: 'json',
			data:  {id:id,id_proses:proses,id_gudang:gudang,id_proses2:proses2, workorder:workorder,spk:spk,id_komposisi:komposisi,spk:spk, id_corak:corak, id_motif : id_motif, id_kualitas : id_kualitas, id_dudul  :id_dudul, id_label : id_label, id_kemasan:id_kemasan, id_kemasansatuan : id_kemasansatuan, id_kemasanseratus : id_kemasanseratus, id_cap : id_cap, id_kualitas_proses : id_kualitas_proses, id_kualitas_periksa : id_kualitas_periksa, id_rencana : id_rencana, jumlah_rencana : jumlah_rencana, id_satuan : satuan},
			headers : {
				'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			},
			success: function(respon){
                
				$("[name=popup2_barang]").html('');
				if(respon.length > 0){
					$("[name=popup2_barang]").append('<option value=""> -- Pilih Barang --</option>');
					$("[name=popup3_barang]").append('<option value=""> -- Pilih Barang --</option>');
					for(i in respon){
							/*	var id_corak = ''; 
								var nama_corak = '';
								var id_motif = '';
								var nama_motif = '';
                                var id_kual = '';
                                var nama_kual = '';
							if(respon[i].id_corak != ''){
								var id_corak = respon[i].id_corak; 
								var nama_corak = ' - '+respon[i].nama_corak; 
							}
							if(respon[i].id_motif != ''){
								var id_motif = respon[i].id_motif; 
								var nama_motif = ' - '+respon[i].nama_motif; 
							}
                            if(respon[i].id_kualitas != ''){
                                var id_kual = respon[i].id_kualitas; 
                                var nama_kual = ' - '+respon[i].nama_kualitas; 
                            }*/

                                var id_corak = ''; 
                                var nama_corak = '';
                                var id_motif = '';
                                var nama_motif = '';
                                var id_kual = '';
                                var nama_kual = '';
                                var id_dudul = '';
                                var nama_dudul = '';
                                var id_label = '';
                                var nama_label = '';
                                var id_kemasan = '';
                                var nama_kemasan = '';
                                var id_kemasansatuan = '';
                                var nama_kemasansatuan = '';
                                var id_kemasansepuluh = '';
                                var nama_kemasansepuluh = '';
                                var id_kemasanseratus = '';
                                var nama_kemasanseratus = '';
                                var id_cap = '', nama_cap = '';
                                var id_kualitas_proses = '', nama_kualitas_proses = '';
                                var id_kualitas_periksa = '', nama_kualitas_periksa = '';
                                var id_rencana = '', nama_rencana = '', jumlah_rencana = '', nama_satuanrencana = '' ;
                            if(respon[i].id_corak != ''){
                                var id_corak = respon[i].id_corak; 
                                var nama_corak = ' - '+respon[i].nama_corak; 
                            }
                            if(respon[i].id_motif != ''){
                                var id_motif = respon[i].id_motif; 
                                var nama_motif = ' - '+respon[i].nama_motif; 
                            }
                            if(respon[i].id_kualitas != ''){
                                var id_kual = respon[i].id_kualitas; 
                                var nama_kual = ' - '+respon[i].nama_kualitas; 
                            }

                            if(respon[i].id_kualitas_dudul != ''){
                                var id_dudul = respon[i].id_kualitas_dudul;
                                var nama_dudul = ' - Dudulan '+respon[i].kualitas_dudul;
                            }

                            if(respon[i].id_label !=''){
                                var id_label = respon[i].id_label;
                                var nama_label = ' - '+respon[i].nama_label;
                            }

                            if(respon[i].id_kemasan != ''){
                                var id_kemasan = respon[i].id_kemasan;
                                var nama_kemasan = ' - '+respon[i].nama_kemasan;
                            }

                            if(respon[i].id_kemasansatuan != ''){
                                var id_kemasansatuan = respon[i].id_kemasansatuan;
                                var nama_kemasansatuan = ' - '+respon[i].nama_kemasansatuan
                            }

                            if(respon[i].id_kemasansepuluh != ''){
                                var id_kemasansepuluh = respon[i].id_kemasansepuluh;
                                var nama_kemasansepuluh = respon[i].nama_kemasansepuluh;
                            }

                            if(respon[i].id_kemasanseratus != ''){
                                var id_kemasanseratus = respon[i].id_kemasanseratus;
                                var nama_kemasanseratus = ' - '+respon[i].nama_kemasanseratus;
                            }

                            if(respon[i].id_cap != ''){
                                var id_cap = respon[i].id_cap; 
                                var nama_cap = ' - '+respon[i].nama_cap; 
                            }

                            if(respon[i].id_kualitas_proses != ''){
                                var id_kualitas_proses = respon[i].id_kualitas_proses; 
                                var nama_kualitas_proses = ' - '+respon[i].nama_kualitas_proses; 
                            }

                            if(respon[i].id_kualitas_periksa != ''){
                                var id_kualitas_periksa = respon[i].id_kualitas_periksa; 
                                var nama_kualitas_periksa = ' - '+respon[i].nama_kualitas_periksa; 
                            }

                            if(respon[i].id_perubahansatuan != ''){
                                id_rencana = respon[i].id_perubahansatuan;
                                nama_rencana = ' - Untuk '+respon[i].jumlah_rencana+' '+respon[i].nama_perubahansatuan;
                                nama_satuanrencana = respon[i].nama_perubahansatuan;
                                jumlah_rencana = respon[i].jumlah_rencana;
                            }

							/*$("[name=popup2_barang]").append('<option value="'+respon[i].id_barang+'" barang="'+respon[i].nama_barang+'" kode="'+respon[i].kode_barang+'" satuan="'+respon[i].satuan+'" corak="'+id_corak+'" motif="'+id_motif+'">'+respon[i].kategori+' - '+respon[i].sub_kategori+' - '+respon[i].kode_barang+' - '+respon[i].nama_barang+nama_corak+nama_motif+nama_kual+'</option>');*/
                            $("[name=popup2_barang]").append('<option value="'+respon[i].id_barang+'" barang="'+respon[i].nama_barang+'" kode="'+respon[i].kode_barang+'" satuan="'+respon[i].id_satuan+'" corak="'+id_corak+'" motif="'+id_motif+'" kualitas="'+id_kual+'" dudulan="'+id_dudul+'" label="'+id_label+'" kemasan="'+id_kemasan+'" kemasan_satuan="'+id_kemasansatuan+'" kemasan_sepuluh="'+id_kemasansepuluh+'" kemasan_seratus="'+id_kemasanseratus+'" cap="'+id_cap+'" kualitas_proses="'+id_kualitas_proses+'" kualitas_periksa="'+id_kualitas_periksa+'" rencana="'+id_rencana+'" jumlah_rencana="'+jumlah_rencana+'" nama_satuanrencana="'+nama_satuanrencana+'">'+respon[i].kategori+' - '+respon[i].sub_kategori+' - '+respon[i].kode_barang+' - '+respon[i].nama_barang+nama_corak+nama_motif+nama_kual+nama_dudul+nama_label+nama_kualitas_proses+nama_kualitas_periksa+nama_cap+nama_kemasan+nama_kemasansatuan+nama_kemasansepuluh+nama_kemasanseratus+nama_rencana+'</option>');
					}
					
				}else{
					$("[name=popup2_barang]").html('');
					$("[name=popup2_barang]").append('<option value=""> Stok Kosong </option>');
					
				}


			},
            complete: function(respon){
                load_gudang2 = 1;
                console.log(load_gudang2);
            }
		})
	}

	function edit_table2(id){
        load_gudang2 = 0;
		var id_barang = $("#tabel_idbarang"+id).val();
		var id_gudang = $("#tabel_idgudang"+id).val();
		var jumlah = $("#tabel_jumlah"+id).val();
		var satuan = $("#tabel_satuan"+id).val();
        var nama_satuan = $("#tabel_nama_satuan"+id).val();
		/*var jumlah_konv = $("#tabel_jumlah_konv"+id).val();*/
		var warna = $("#tabel_warna"+id).val();
		var corak = $("#tabel_idcorak"+id).val();
		var id_proses = $("[name=proses]").val();
		var id_proses2 = $("[name=popup_proses]").val();
		var id_prosessebelum = $("#tabel_proses2"+id).val();

        var id_motif = $("#tabel_idmotif"+id).val();        
        var id_kualitas = $("#tabel_idkualitas"+id).val();
        var id_dudul = $("#tabel_idkualitas_dudul"+id).val();
        var id_label = $("#tabel_idlabel"+id).val();
        var id_kemasan = $("#tabel_idkemasan"+id).val();
        var id_kemasansatuan = $("#tabel_idkemasan_satuan"+id).val();
        var id_kemasansepuluh = $("#tabel_idkemasan_sepuluh"+id).val();
        var id_kemasanseratus = $("#tabel_idkemasan_seratus"+id).val();
        var id_cap = $("#tabel_idcap"+id).val();
        var id_kualitas_proses = $("#tabel_idkualitas_proses"+id).val();
        var id_kualitas_periksa = $("#tabel_idkualitas_periksa"+id).val();

        var id_workorder = $("#tabel_id_workorder_barang"+id).val();
        var id_spk = $("#tabel_id_workorder"+id).val();

        var id_rencana = $("#tabel_idrencana"+id).val();
        var jumlah_rencana = $("#tabel_rencanajumlah"+id).val();

        var keterangan = $("#tabel_keterangan"+id).val();
        var tanggal = $("#tabel_tanggal"+id).val();

        var jum_hasil = $("#tabel_hasiljumlah"+id).val();
        var satuan_hasil = $("#tabel_hasilsatuan"+id).val();

        var satuan = $("#tabel_satuan"+id).val();
        // if(jum_hasil == 0){
        //     jum_hasil = '';
        //     satuan_hasil = '';
        // }

		$("[name=popup2_id_table]").val(id);  
        $("[name=popup2_proses]").val(id_prosessebelum).trigger('change');  

		
		var FunctionOne = function () {
		  var r = $.Deferred();
		  $("#input2_warna").val(warna).trigger('change');
		  $("[name=popup2_gudang]").val(id_gudang).trigger('change');

          get_barang2(id,id_gudang,id_proses,id_prosessebelum,corak,warna,id_motif,id_kualitas,id_dudul,id_label,id_kemasan, id_kemasansatuan, id_kemasansepuluh, id_kemasanseratus, id_cap, id_kualitas_proses, id_kualitas_periksa, id_rencana, jumlah_rencana, satuan);
		  setTimeout(function () {
		    r.resolve();
		  }, 3000);
		  return r;
		};

        function repeat_first(){
            if(load_gudang2 == 1){
                FunctionTwo();
            }else{
                setTimeout(repeat_first, 2000);
            }
        }

        function repeat_last(){
            if(load_gudang2 == 1){
                Function_last();
            }else{
                setTimeout(repeat_last, 2000);
            }
        }

		var FunctionTwo = function () {
            load_gudang2 = 0;
			$.ajax({
			url: '{{ url('barangkeluar/get_barang2') }}',
			type: 'post',
			dataType: 'json',
			//data: {id : id_gudang, id_barang : id_barang, id_proses : id_proses, workorder:id_workorder},
            data : {id : id_gudang, id_barang : id_barang,id_proses : id_proses,id_komposisi:warna,id_proses2:id_prosessebelum,id_corak:corak,workorder:id_workorder, id_kualitas:id_kualitas, id_dudul:id_dudul, id_motif:id_motif, id_label:id_label, id_kemasan:id_kemasan, id_kemasansatuan:id_kemasansatuan, id_kemasansepuluh:id_kemasansepuluh, id_kemasanseratus:id_kemasanseratus, id_cap : id_cap,  id_kualitas_proses : id_kualitas_proses, id_kualitas_periksa : id_kualitas_periksa, id_rencana : id_rencana, jumlah_rencana : jumlah_rencana, id_satuan : satuan},
			headers : {
				'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			},
			success: function(respon){
                        var c_jumlah = parseFloat(jumlah);
						if(respon.length > 0){
							if($("[name=popup2_id_table]").val() == ''){
								nilai = parseFloat(respon[0].stok); 
							}else{
								/*nilai = (respon[0].stok-total)+parseFloat(jumlah);*/                                
                                if(c_jumlah > 0){
                                    nilai = parseFloat(respon[0].stok)+parseFloat(jumlah);
                                }else{
                                    nilai = c_jumlah;
                                }
							}

							$("[name=popup2_stok]").text(nilai+' '+respon[0].nama_satuan);
							$("[name=popup2_jumlah]").attr('min', 0);
							$("[name=popup2_jumlah]").attr('max', nilai);
                            
						}else{
							$("[name=popup2_stok]").text(c_jumlah+' '+nama_satuan);
							$("[name=popup2_jumlah]").attr('min', 0);
							$("[name=popup2_jumlah]").attr('max', c_jumlah);
                            console.log(c_jumlah)
						}
			},
            complete: function(respon){
                load_gudang2 = 1;
                repeat_last();
            }
		  })   
		};

        var Function_last = function(){
            var jum = $("[name=popup2_barang]").find("option[corak='" + corak + "'][motif='" + id_motif + "'][kualitas='" + id_kualitas + "'][dudulan='" + id_dudul + "'][label='" + id_label + "'][kemasan='" + id_kemasan + "'][kemasan_satuan='" + id_kemasansatuan + "'][kemasan_sepuluh='" + id_kemasansepuluh + "'][kemasan_seratus='" + id_kemasanseratus + "'][value='"+ id_barang +"'][satuan='"+satuan+"'][cap='"+id_cap+"'][kualitas_proses='"+id_kualitas_proses+"'][kualitas_periksa='"+id_kualitas_periksa+"'][rencana='"+id_rencana+"'][jumlah_rencana='"+jumlah_rencana+"'][satuan='"+satuan+"'] "); //
            jum.prop('selected', true).trigger("change");
            console.log("Jumlah "+jum.length);
            // console.log("id barang "+id_barang+"\nid satuan "+satuan+"\nid corak "+corak+"\nid komposisi "+warna+"\nid kualitas "+id_kualitas+"\nid dudul "+id_dudul+"\nid motif "+id_motif+"\nid label "+id_label+"\nid kemasan "+id_kemasan+"\nid kemasan_satuan "+id_kemasansatuan+"\nid kemasan_sepuluh "+id_kemasansepuluh+"\nid kemasan_seratus "+id_kemasanseratus+"\ncap "+id_cap+"\nid kualitas proses "+id_kualitas_proses+"\nid kualitas periksa "+id_kualitas_periksa); 

            // $("[name=popup2_barang]").val(id_barang).trigger('change');
            $("[name=input2_barang]").val(id_barang);
            $("[name=popup2_jumlah]").val(jumlah);
            $("[name=popup2_satuanawal]").val(satuan).trigger('change');
            $("[name=popup2_ket]").val(keterangan);
            $("[name=popup2_tanggal]").val(tanggal);

            $("[name=popup2_jumlahhasil]").val(jum_hasil);
            $("[name=popup2_satuanhasils]").val(satuan_hasil).trigger('change');
            /*$("[name=popup2_jumlah_konv]").val(jumlah_konv);*/
            

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

		FunctionOne().done(repeat_first());
	}

	/* -------------------------- Gudang popup edit selesai ---------------------------------------*/


	function hapus(d){
	table_barang.row(d.parents('tr')).remove().draw();
	// get_jum();
	//  alert(d);
	}

	function get_edit(id){
		$.ajax({
			url: "{{ url('barangkeluar/get_edit')}} ",
			type: 'post',
			data: {id : id,},
			headers : {
				'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			},
			success: function(respon){
				if(respon.length > 0){
					for(i in respon){
                                var id_corak = ''; 
                                var nama_corak = '';
                                var id_motif = '';
                                var nama_motif = '';
                                var id_kual = '';
                                var nama_kual = '';
                                var id_dudul = '';
                                var nama_dudul = '';
                                var id_label = '';
                                var nama_label = '';
                                var id_kemasan = '';
                                var nama_kemasan = '';
                                var id_kemasansatuan = '';
                                var nama_kemasansatuan = '';
                                var id_kemasansepuluh = '';
                                var nama_kemasansepuluh = '';
                                var id_kemasanseratus = '';
                                var nama_kemasanseratus = '';
                                var id_cap = '', nama_cap = '';
                                var id_kualitas_proses = '', nama_kualitas_proses = '';
                                var id_kualitas_periksa = '', nama_kualitas_periksa = '';
                                var id_perubahansatuan = '', nama_perubahansatuan, jumlah_rencana='';
                            if(respon[i].id_corak != ''){
                                var id_corak = respon[i].id_corak; 
                                var nama_corak = ' - '+respon[i].nama_corak; 
                            }
                            if(respon[i].id_motif != ''){
                                var id_motif = respon[i].id_motif; 
                                var nama_motif = ' - '+respon[i].nama_motif; 
                            }
                            if(respon[i].id_kualitas != ''){
                                var id_kual = respon[i].id_kualitas; 
                                var nama_kual = ' - '+respon[i].nama_kualitas; 
                            }

                            if(respon[i].id_kualitas_dudul != ''){
                                var id_dudul = respon[i].id_kualitas_dudul;
                                var nama_dudul = ' - Dudulan '+respon[i].nama_kualitas_dudul;
                            }

                            if(respon[i].id_label !=''){
                                var id_label = respon[i].id_label;
                                var nama_label = ' - '+respon[i].nama_label;
                            }

                            if(respon[i].id_kemasan != ''){
                                var id_kemasan = respon[i].id_kemasan;
                                var nama_kemasan = ' - '+respon[i].nama_kemasan;
                            }

                            if(respon[i].id_kemasansatuan != ''){
                                var id_kemasansatuan = respon[i].id_kemasansatuan;
                                var nama_kemasansatuan = ' - '+respon[i].nama_kemasansatuan
                            }

                            if(respon[i].id_kemasansepuluh != ''){
                                var id_kemasansepuluh = respon[i].id_kemasansepuluh;
                                var nama_kemasansepuluh = ' - '+respon[i].nama_kemasansepuluh;
                            }

                            if(respon[i].id_kemasanseratus != ''){
                                var id_kemasanseratus = respon[i].id_kemasanseratus;
                                var nama_kemasanseratus = ' - '+respon[i].nama_kemasanseratus;
                            }

                            if(respon[i].id_cap != ''){
                                var id_cap = respon[i].id_cap; 
                                var nama_cap = ' - '+respon[i].nama_cap; 
                            }
                            if(respon[i].id_perubahansatuan != ''){
                                var id_perubahansatuan = respon[i].id_perubahansatuan; 
                                var nama_perubahansatuan = respon[i].nama_perubahansatuan;
                                var jumlah_rencana = ' - '+respon[i].jumlah_rencana; 
                            }
						table_barang.row.add(['<div><center></center></div>',
                            '<div id="list_tanggal'+respon[i].id+'">'+respon[i].tanggal_proses+'</div>',
							'<div id="list_kode'+respon[i].id+'">'+respon[i].kode_barang+'</div>',
							'<div id="list_nama'+respon[i].id+'">'+respon[i].namabarang_kategori+' - '+respon[i].nama_barang+nama_corak+nama_motif+nama_dudul+nama_label+nama_kemasan+nama_cap+nama_kemasansatuan+nama_kemasansepuluh+nama_kemasanseratus+'</div>',
							'<div id="list_warna'+respon[i].id+'">'+respon[i].nama_komposisi+'</div>',
							'<div id="list_gudang'+respon[i].id+'">'+respon[i].nama_gudang+'</div>',
							'<div id="list_jumlah'+respon[i].id+'">'+respon[i].jumlah+' '+respon[i].satuan_jumlah+'</div>',
                            '<div id="list_keterangan'+respon[i].id+'">'+respon[i].keterangan+'</div>',
							/*'<div id="list_jumlah_konv'+respon[i].id+'">'+respon[i].jumlah_konv+' '+respon[i].satuan_jumlah_konv+'</div>',*/
							'<div><button type="button" class="btn bg-warning-400" onclick="edit_table2('+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" name="tabel_id[]" id="tabel_id'+respon[i].id+'" value="'+respon[i].id+'">'+
							'<input type="hidden" name="tabel_idbarangkeluar[]" id="tabel_idbarangkeluar'+respon[i].id+'" value="'+respon[i].id_barangkeluar+'">'+
							'<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_satuan[]" id="tabel_satuan'+respon[i].id+'" value="'+respon[i].id_satuan_jumlah+'">'+
                            '<input type="hidden" name="tabel_nama_satuan[]" id="tabel_nama_satuan'+respon[i].id+'" value="'+respon[i].satuan_jumlah+'">'+
							'<input type="hidden" name="tabel_jumlah_konv[]" id="tabel_jumlah_konv'+respon[i].id+'" value="'+respon[i].jumlah_konv+'">'+
							'<input type="hidden" id="tabel_warna'+respon[i].id+'" name="tabel_warna[]" value="'+respon[i].id_komposisi+'">'+
							'<input type="hidden" id="tabel_namawarna'+respon[i].id+'" name="tabel_namawarna[]" value="'+respon[i].nama_komposisi+'">'+
							'<input type="hidden" id="tabel_proses2'+respon[i].id+'" name="tabel_proses2[]" value="'+respon[i].id_proses_sebelum+'">'+
							'<input type="hidden" id="tabel_namasatuan'+respon[i].id+'" name="tabel_namasatuan[]" value="'+respon[i].satuan_jumlah+'">'+
							'<input type="hidden" id="tabel_idcorak'+respon[i].id+'" name="tabel_idcorak[]" value="'+respon[i].id_corak+'">'+
							'<input type="hidden" id="tabel_idmotif'+respon[i].id+'" name="tabel_idmotif[]" value="'+respon[i].id_motif+'">'+
                            '<input type="hidden" id="tabel_idkualitas'+respon[i].id+'" name="tabel_idkualitas[]" value="'+respon[i].id_kualitas+'">'+
                            '<input type="hidden" id="tabel_idkualitas_dudul'+respon[i].id+'" name="tabel_idkualitas_dudul[]" value="'+respon[i].id_kualitas_dudul+'">'+
                            '<input type="hidden" id="tabel_idlabel'+respon[i].id+'" name="tabel_idlabel[]" value="'+respon[i].id_label+'">'+
                            '<input type="hidden" id="tabel_idkemasan'+respon[i].id+'" name="tabel_idkemasan[]" value="'+respon[i].id_kemasan+'">'+
                            '<input type="hidden" id="tabel_idkemasan_satuan'+respon[i].id+'" name="tabel_idkemasan_satuan[]" value="'+respon[i].id_kemasansatuan+'">'+
                            '<input type="hidden" id="tabel_idkemasan_sepuluh'+respon[i].id+'" name="tabel_idkemasan_sepuluh[]" value="'+respon[i].id_kemasansepuluh+'">'+
                            '<input type="hidden" id="tabel_idkemasan_seratus'+respon[i].id+'" name="tabel_idkemasan_seratus[]" value="'+respon[i].id_kemasanseratus+'">'+
                            '<input type="hidden" id="tabel_idcap'+respon[i].id+'" name="tabel_idcap[]" value="'+respon[i].id_cap+'">'+
                            '<input type="hidden" id="tabel_idkualitas_proses'+respon[i].id+'" name="tabel_idkualitas_proses[]" value="'+respon[i].id_kualitas_proses+'">'+
                            '<input type="hidden" id="tabel_idkualitas_periksa'+respon[i].id+'" name="tabel_idkualitas_periksa[]" value="'+respon[i].id_kualitas_periksa+'">'+
                            '<input type="hidden" id="tabel_id_workorder_barang'+respon[i].id+'" name="tabel_id_workorder_barang[]" value="'+respon[i].id_workorder+'">'+
                            '<input type="hidden" id="tabel_id_workorder'+respon[i].id+'" name="tabel_id_workorder[]" value="'+respon[i].id_spk+'">'+
                            '<input type="hidden" id="tabel_idrencana'+respon[i].id+'" name="tabel_idrencana[]" value="'+id_perubahansatuan+'">'+
                            '<input type="hidden" id="tabel_rencanajumlah'+respon[i].id+'" name="tabel_rencanajumlah[]" value="'+jumlah_rencana+'">'+
                            '<input type="hidden" id="tabel_keterangan'+respon[i].id+'" name="tabel_keterangan[]" value="'+respon[i].keterangan+'">'+
                            '<input type="hidden" id="tabel_tanggal'+respon[i].id+'" name="tabel_tanggal[]" value="'+respon[i].tanggal_proses+'">'+
                            '<input type="hidden" id="tabel_status'+respon[i].id+'" name="tabel_status[]" value="'+respon[i].status_barang+'">'+
                            '<input type="hidden" id="tabel_hasilid'+respon[i].id+'" name="tabel_hasilid[]" value="'+respon[i].id_keluarhasil+'">'+
                            '<input type="hidden" id="tabel_hasiljumlah'+respon[i].id+'" name="tabel_hasiljumlah[]" value="'+respon[i].hasil+'">'+
                            '<input type="hidden" id="tabel_hasilsatuan'+respon[i].id+'" name="tabel_hasilsatuan[]" value="'+respon[i].id_satuanhasil+'">'
							]).draw(false);
					}

					// get_jum();
				}
				
			}
		})
	}

	$("#btn_popup3_simpan").click(function(){
		var id_data = $("[name=popup3_id_table]").val();
		var id_barang = $("[name=popup3_barang]").val();
		var id_gudang = $("[name=popup3_gudang]").val();
		var kode_barang = $("[name=popup3_barang] :selected").attr('kode');
		var nama_barang = $("[name=popup3_barang] :selected").attr('barang');
		var nama_gudang = $("[name=popup3_gudang] :selected").attr('nama');
		var jumlah = $("[name=popup3_jumlah]").val();
		
		var id_satuan_jumlah = $("[name=popup3_satuanawal]").val();
		var satuan_jumlah = $("[name=popup3_satuanawal] :selected").attr('nama');
		
		var id_warna = $("[name=input3_warna] :selected").val();
		var nama_warna = $("[name=input3_warna] :selected").attr('nama');
		var id_proses2 = $("[name=popup3_proses]").val();

        var keterangan = $("[name=popup3_ket]").val();
		
		var total = parseInt(jumlah);

		if(id_barang != '' && jumlah != '' && jumlah != 0 && id_warna != ""){
			if(id_data == ''){
				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_gudang'+tb_no+'">'+nama_gudang+'</div>',
					'<div id="list_jumlah'+tb_no+'">'+jumlah+'</div>',
                    '<div id="list_keterangan'+tb_no+'">'+keterangan+'</div>',
					/*'<div id="list_jumlah_konv'+tb_no+'">'+jumlah_konv+'</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_id'+tb_no+'" name="tabel_id[]" value="">'+
					'<input type="hidden" id="tabel_idbarang'+tb_no+'" name="tabel_idbarang[]" value="'+id_barang+'">'+
					'<input type="hidden" id="tabel_idgudang'+tb_no+'" name="tabel_idgudang[]" value="'+id_gudang+'">'+
					// '<input type="hidden" id="tabel_kodebarang'+tb_no+'" name="tabel_kodebarang[]" value="'+kode_barang+'">'+
					/*'<input type="hidden" id="tabel_jumlah_konv'+tb_no+'" name="tabel_jumlah_konv[]" value="'+jumlah_konv+'">'+*/
					'<input type="hidden" id="tabel_jumlah'+tb_no+'" name="tabel_jumlah[]" value="'+jumlah+'">'+
					'<input type="hidden" id="tabel_satuan'+tb_no+'" name="tabel_satuan[]" value="'+id_satuan_jumlah+'">'+
					'<input type="hidden" id="tabel_total'+tb_no+'" name="tabel_total[]" value="'+total+'">'+
					'<input type="hidden" id="tabel_warna'+tb_no+'" name="tabel_warna[]" value="'+id_warna+'">'+
					'<input type="hidden" id="tabel_proses2'+tb_no+'" name="tabel_proses2[]">'+
					'<input type="hidden" id="tabel_idcorak'+tb_no+'" name="tabel_idcorak[]">'+
					'<input type="hidden" id="tabel_idmotif'+tb_no+'" name="tabel_idmotif[]">'+
                    '<input type="hidden" id="tabel_idkualitas'+tb_no+'" name="tabel_idkualitas[]">'+
                    '<input type="hidden" id="tabel_keterangan'+tb_no+'" name="tabel_keterangan[]" value="'+keterangan+'">'
					]).draw(false);

				
			}else{
				$("#list_kode"+id_data).text(kode_barang);
				$("#list_nama"+id_data).text(nama_barang);
				$("#list_warna"+id_data).text(nama_warna);
				$("#list_gudang"+id_data).text(nama_gudang);
				$("#list_jumlah"+id_data).text(jumlah+' '+satuan_jumlah);
                $("#list_keterangan"+id_data).text(keterangan);
				/*$("#list_jumlah_konv"+id_data).text(jumlah_konv+' '+satuan_jumlah_konv);*/
				/*$("#list_volume"+id_data).text(volume+' '+satuan_volume);*/

				$("#tabel_id"+id_data).val(id_data);
				$("#tabel_idbarang"+id_data).val(id_barang);
				$("#tabel_idgudang"+id_data).val(id_gudang);
				$("#tabel_warna"+id_data).val(id_warna);
				$("#tabel_namabarang"+id_data).val(nama_barang);				
				$("#tabel_jumlah"+id_data).val(jumlah);
				$("#tabel_satuan"+id_data).val(id_satuan_jumlah);
				/*$("#tabel_jumlah_konv"+id_data).val(jumlah_konv);*/
				$("#tabel_total"+id_data).val(total);
				$("#tabel_proses2"+id_data).val(id_proses2);
                $("#tabel_keterangan"+id_data).val(keterangan);
			

			}
		
		$("#exampleModal3").modal('hide');
		tb_no++;
		}
	})

    //-- perubahan satuan
    function get_perubahan(id,status){
        var satuan = '';
        var jumlah = '';
        var satuan_hasil = '';
        var jumlah_hasil = '';
        var motif = '';
        var corak = '';
        var proses = $("[name=proses]").val();
        var lokasi = $("[name=id_jenis").val();
        if($("[name=popup2_satuanawal]").val() != '' || $("[name=popup2_jumlah]").val() != ''){
        var satuan = $("[name=popup2_satuanawal]").val();        
        var jumlah = $("[name=popup2_jumlah]").val();
        }
        if($("[name=popup2_satuanhasil]").val() != '' || $("[name=popup2_menghasilkan]").val() != ''){
        var satuan_hasil = $("[name=popup2_satuanhasil]").val();
        var jumlah_hasil = $("[name=popup2_menghasilkan]").val();
        }
        if($("[name=popup_motif]").val() != ''){
        var motif = $("[name=popup2_motif]").val();
        }
        if($("[name=popup_corak]").val() != ''){
        var corak = $("[name=popup2_corak]").val();
        }
        console.log($("[name=popup2_satuanhasil]").val());
        $.ajax({
            type : "POST",
            dataType : "json",
            data : {jumlah : jumlah, satuan : satuan, jumlah_hasil: jumlah_hasil, satuan_hasil : satuan_hasil, motif : motif,  motif_barang : corak, proses : proses, lokasi : lokasi},
            url : "{{url('barangkeluar/get_perubahansatuan')}}",
            headers : {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            },
            success: function(result){
                if(result.status == 1){
                    var jum_bagi = parseFloat(jumlah)/parseFloat(result.data.jumlah_satuanawal);
                    var jum_hasil = parseFloat(jum_bagi)*parseFloat(result.data.jumlah_satuanperubahan);
                    var jum_awal = parseFloat(jumlah_hasil)*parseFloat(result.data.jumlah_satuanawal);
                    var n = parseInt(jum_hasil)+' '+result.data.nama_satuanperubahan;   
                    if(status == 1){
                        $("[name=popup2_menghasilkan]").val(parseFloat(jum_hasil.toFixed(2)));
                    }else{
                        $("[name=popup2_jumlah]").val(parseFloat(jum_awal.toFixed(2))).trigger('keyup');
                    }
                }else{
                    $("[name=popup2_menghasilkan]").val('');
                    $("[name=popup2_jumlah]").val('');
                }
            }
            
        })
    }

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


    }

    $("[name=id_jenis]").change(function(){
        get_nomor();
    })

    $("[name=proses]").change(function(){
        var val = parseInt($(this).val());
        var id_proses = [{{ implode(",", setup_perkiraanhasil()) }}];

        if(isInArray(val, id_proses) == true){
            $("[name=popup_jumlahhasil]").parent().parent().show();
            $("[name=popup_satuanhasil]").parent().parent().show();
            $("[name=popup2_jumlahhasil]").parent().parent().show();
            $("[name=popup2_satuanhasil]").parent().parent().show();
        }else{
            $("[name=popup_jumlahhasil]").parent().parent().hide();
            $("[name=popup_satuanhasil]").parent().parent().hide();
            $("[name=popup2_jumlahhasil]").parent().parent().hide();
            $("[name=popup2_satuanhasil]").parent().parent().hide();
        }
    })

    function perkiraan_hasil(){
        var val = parseInt($("[name=proses]").val());
        var id_proses = [{{ implode(",", setup_perkiraanhasil()) }}];

        if(isInArray(val, id_proses) == true){
            $("[name=popup_jumlahhasil]").parent().parent().show();
            $("[name=popup_satuanhasil]").parent().parent().show();
            $("[name=popup2_jumlahhasil]").parent().parent().show();
            $("[name=popup2_satuanhasil]").parent().parent().show();
        }else{
            $("[name=popup_jumlahhasil]").parent().parent().hide();
            $("[name=popup_satuanhasil]").parent().parent().hide();
            $("[name=popup2_jumlahhasil]").parent().parent().hide();
            $("[name=popup2_satuanhasil]").parent().parent().hide();
        }
    }

    function isInArray(value, array) {
        return array.indexOf(value) > -1;
    }
</script>

@endsection