@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">Bill of Material</li>
		</ul>
	</div>
</div>

<div class="content">
	<div class="panel panel-flat">
		<div class="panel-heading">
			<h5 class="panel-title">Bill of Material</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" autocomplete="off" action="{{url('bom/simpan')}}" method="post" enctype="multipart/form-data">
	    		<input type="hidden" name="_token" value="{{ csrf_token() }}">
	    		<input type="hidden" name="id_bom" value="{{ $data['data']['id_bom']}}">
	    		<div class="col-sm-6">
	    			<div class="form-group">
	    				<label class="control-label col-sm-4">Tanggal</label>
	    				<div class="col-sm-8">
	    					<input type="text" name="tanggal" class="form-control datepicker" value="{{ ($data['data']['tanggal'] == '') ? date('d-m-Y'):date('d-m-Y', strtotime($data['data']['tanggal'])) }}">
	    				</div>
	    			</div>
	    			<!-- <div class="form-group">
	    			<label class="control-label col-sm-4">No.SPK</label>
	    			<div class="col-sm-8">
	    				<select class="form-control select-search" name="proses">
	    					<option value="">--- Pilih Produksi ---</option>
	    					@php $sel = $data['data']['id_workorder']; 
	    					foreach($data['spk'] as $d){@endphp
	    					<option value="{{$d->id_workorder}}">{{$d->nomor.' (Nomor SPK)'}}</option>	    					
	    					@php } @endphp
	    				</select>
	    			</div>
	    			</div>

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

	    			<div class="form-group">
        			<label class="control-label col-sm-4">No.Spk</label>
        			<div class="col-sm-8">
        				@php if($data['data']['id_bom'] !=""){ @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">
        			<label class="control-label col-sm-4">No.Order</label>
        			<div class="col-sm-8">
        				@php if($data['data']['id_bom']!=""){@endphp
        				<input type="hidden" name="workorder" value="{{$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" required>
        					<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>	
	    		<div class="col-sm-6"></div>
	    	<!-- <div class="col-sm-12 form-group">
	    		
	    	</div> -->
	    	<div class="col-sm-12 form-group">
	    		<a href="#" class="btn btn-success" id="btn_tambah_item_keluar">Tambah</a>
	        	<h5 class="panel-title">Input</h5>
	        	<div class="col-ms-12 table-responsive">
		        	<table class="table table-stripped" id="table_barang">
				    	<thead>
							<tr>
								<th>No</th>
								<th>Proses</th>
								<th>Kode Barang</th>
								<th>Nama Barang</th>
								<th>Warna</th>
								<th>Jumlah</th>
								<th>Satuan</th>
								<th>Harga</th>
								<th>Corak</th>
								<th>Motif</th>
								<th>Kualitas</th>
								<th>Dudulan</th>
								<th>Label</th>
								<th>Cap</th>
								<th>Kemasan</th>
								<th>Kemasan Satuan</th>
								<th>Kemasan 10 Potong</th>
								<th>Kemasan Dus Ball</th>
								<th></th>
							</tr>
						</thead>
						<tbody>
							
						</tbody>
				    </table>
	        	</div>
        	</div>

        	
        	<div class="col-sm-12 form-group">
        		<a href="#" class="btn btn-success" id="btn_tambah_item_masuk">Tambah</a>
	        	<h5 class="panel-title">Output</h5>
	        	<div class="col-ms-12 table-responsive">
		        	<table class="table table-stripped" id="table_masuk">
				    	<thead>
							<tr>
								<th>No</th>
								<th>Proses</th>
								<th>Kode Barang</th>
								<th>Nama Barang</th>
								<th>Warna</th>
								<th>Jumlah</th>
								<th>Satuan</th>
								<th>Harga</th>
								<th>Corak</th>
								<th>Motif</th>
								<th>Kualitas</th>
								<th>Dudulan</th>
								<th>Label</th>
								<th>Cap</th>
								<th>Kemasan</th>
								<th>Kemasan Satuan</th>
								<th>Kemasan 10 Potong</th>
								<th>Kemasan Dus Ball</th>
								<th></th>
							</tr>
						</thead>
						<tbody>
							
						</tbody>
				    </table>
	        	</div>
        	</div>

        	<div class="col-sm-12 form-group">
        		<a href="#" class="btn btn-success" id="btn_tambah_item_upah">Tambah</a>
	        	<h5 class="panel-title">Upah</h5>
	        	<div class="col-ms-12 table-responsive">
		        	<table class="table table-stripped" id="table_upah">
				    	<thead>
							<tr>
								<th>No.</th>
	        					<th>Proses</th>
	        					<th>Upah</th>
	        					<th></th>
							</tr>
						</thead>
						<tbody>
							
						</tbody>
				    </table>
	        	</div>
	        	<br>
             <div class="col-md-12">
             <a href="{{url('bom')}}" 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>
         </form>
        	</div>
        	
	    </div>
	</div>
</div>

<!---Modal--->

<div class="modal fade" id="exampleModal_keluar" 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_keluar_table">
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Proses</label>
	      				<div class="col-sm-8">
	      			 	<select class="form-control select-search" name="popup_proses">
	      			 		<option value="">--- Pilih Proses ---</option>
	      			 		@php foreach($data['proses'] as $row){ 
        					if($row->nama_proses2 == ''){
        					echo '<optgroup label="'.$row->nama_proses.'">';
        					} else {
        					@endphp
        					<option value="{{ $row->id_proses }}" nama="{{$row->nama_proses}}"> {{ $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">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</b></label>
	      				<div class="col-sm-8">
	      			 	<input type="text" name="popup_jumlah" class="form-control number-only">
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Satuan</b></label>
	      				<div class="col-sm-8">
	      			 		<select class="form-control select-search" name="popup_satuan">
	      			 			@foreach($data['satuan'] as $s){
	      			 				<option value="{{ $s->id_satuan }}" name="{{ $s->nama_satuan }}">{{ $s->nama_satuan }}</option>
	      			 			@endforeach 
	      			 		</select>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Harga</label>
	      				<div class="col-sm-8">
	      			 	<input type="text" name="popup_harga" class="form-control number-only">
	      			 	<p class="pull-right" id="help_popup_harga"></p>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Warna</label>
	      				<div class="col-sm-8">
	      					<input type="hidden" name="popup_idkomposisi">
	      			 		<select name="popup_komposisi" class="form-control select-search">
	      			 			<option value="" name="Tanpa Warna">Tanpa Warna</option>
	      			 			@foreach($data['warna'] as $w){
	      			 			<option value="{{ $w->id_komposisi }}" name="{{ $w->nama }}">{{ $w->nama.' ('.$w->inisial.')' }}</option>
	      			 			@endforeach
	      			 		</select>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Corak</label>
	      				<div class="col-sm-8">	      					
	      			 		<select name="popup_corak" class="form-control select-search">
	      			 		</select>
	      				</div>
	      			</div>
	      			<div class="form-group" id="div_motif">
	      				<label class="control-label col-sm-4">Motif</label>
	      				<div class="col-sm-8">	      					
	      			 		<select name="popup_motif" class="form-control select-search">
	      			 		</select>
	      				</div>
	      			</div>	    
	      			<div class="form-group" id="div_kualitas">
	      				<label class="control-label col-sm-4">Kualitas</label>
	      				<div class="col-sm-8">	
	      			 		<select name="popup_kual" class="form-control select-search">
	      			 			
	      			 		</select>
	      				</div>
	      			</div>
	      			<div class="form-group" id="div_dudul">
	      				<label class="control-label col-sm-4">Kualitas Dudulan</label>
	      				<div class="col-sm-8">	
	      			 		<select name="popup_dudul" class="form-control select-search">
	      			 			<option value="" nama="">-- Pilih Dudulan --</option>
	      			 			<option value="1" nama="Baik">Baik</option>
	      			 			<option value="2" nama="Jelek">Jelek</option>
	      			 		</select>
	      				</div>
	      			</div>	 
	      			<div class="form-group" id="div_label">
	      				<label class="control-label col-sm-4">Label</label>
	      				<div class="col-sm-8">	
	      			 		<select name="popup_label" class="form-control select-search">
	      			 			
	      			 		</select>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Cap</label>
	      				<div class="col-sm-8">	
	      			 		<select name="popup_cap" class="form-control select-search">
	      			 			
	      			 		</select>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Kemasan Awal</label>
	      				<div class="col-sm-8">	
	      			 		<select name="popup_kemasan" class="form-control select-search">
	      			 			
	      			 		</select>
	      				</div>
	      			</div>
	      			<div class="form-group" id="div_kemasansatuan">
	      				<label class="control-label col-sm-4">Kemasan Satuan</label>
	      				<div class="col-sm-8">	
	      			 		<select name="popup_kemasansatuan" class="form-control select-search">
	      			 			
	      			 		</select>
	      				</div>
	      			</div>
	      			<div class="form-group" id="div_kemasansepuluh">
	      				<label class="control-label col-sm-4">Kemasan 10 Potong</label>
	      				<div class="col-sm-8">	
	      			 		<select name="popup_kemasansepuluh" class="form-control select-search">
	      			 			
	      			 		</select>
	      				</div>
	      			</div>

	      			<div class="form-group" id="div_kemasanseratus">
	      				<label class="control-label col-sm-4">Kemasan Dosball</label>
	      				<div class="col-sm-8">	
	      			 		<select name="popup_kemasanseratus" class="form-control select-search">
	      			 			
	      			 		</select>
	      				</div>
	      			</div>
	      		</form>
	      	</div>
	      	<div class="modal-footer">
	        	<button type="button" class="btn btn-primary" id="btn_popup_simpan_keluar">Simpan</button>
	      	</div>
	    </div>
	</div>
</div>


<!-- EndModal -->

<!-- Modal -->

<div class="modal fade" id="exampleModal_masuk" 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_masuk_table">
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Proses</label>
	      				<div class="col-sm-8">
	      			 	<select class="form-control select-search" name="popup2_proses">
	      			 		<option value="">--- Pilih Proses ---</option>
	      			 		@php foreach($data['proses'] as $row){ 
        					if($row->nama_proses2 == ''){
        					echo '<optgroup label="'.$row->nama_proses.'">';
        					} else {
        					@endphp
        					<option value="{{ $row->id_proses }}" nama="{{$row->nama_proses}}"> {{ $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">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</b></label>
	      				<div class="col-sm-8">
	      			 	<input type="text" name="popup2_jumlah" class="form-control number-only">
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Satuan</b></label>
	      				<div class="col-sm-8">
	      			 		<select class="form-control select-search" name="popup2_satuan">
	      			 			@foreach($data['satuan'] as $s){
	      			 				<option value="{{ $s->id_satuan }}" name="{{ $s->nama_satuan }}">{{ $s->nama_satuan }}</option>
	      			 			@endforeach 
	      			 		</select>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Harga</label>
	      				<div class="col-sm-8">
	      			 	<input type="text" name="popup2_harga" class="form-control number-only">
	      			 	<p class="pull-right" id="help_popup2_harga"></p>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Warna</label>
	      				<div class="col-sm-8">
	      					<input type="hidden" name="popup2_idkomposisi">
	      			 		<select name="popup2_komposisi" class="form-control select-search">
	      			 			<option value="" name="Tanpa Warna">Tanpa Warna</option>
	      			 			@foreach($data['warna'] as $w){
	      			 			<option value="{{ $w->id_komposisi }}" name="{{ $w->nama }}">{{ $w->nama.' ('.$w->inisial.')' }}</option>
	      			 			@endforeach
	      			 		</select>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Corak</label>
	      				<div class="col-sm-8">	      					
	      			 		<select name="popup2_corak" class="form-control select-search">
	      			 		</select>
	      				</div>
	      			</div>
	      			<div class="form-group" id="div_motif">
	      				<label class="control-label col-sm-4">Motif</label>
	      				<div class="col-sm-8">	      					
	      			 		<select name="popup2_motif" class="form-control select-search">
	      			 		</select>
	      				</div>
	      			</div>	    
	      			<div class="form-group" id="div_kualitas">
	      				<label class="control-label col-sm-4">Kualitas</label>
	      				<div class="col-sm-8">	
	      			 		<select name="popup2_kual" class="form-control select-search">
	      			 			
	      			 		</select>
	      				</div>
	      			</div>
	      			<div class="form-group" id="div_dudul">
	      				<label class="control-label col-sm-4">Kualitas Dudulan</label>
	      				<div class="col-sm-8">	
	      			 		<select name="popup2_dudul" class="form-control select-search">
	      			 			<option value="" nama="">-- Pilih Dudulan --</option>
	      			 			<option value="1" nama="Baik">Baik</option>
	      			 			<option value="2" nama="Jelek">Jelek</option>
	      			 		</select>
	      				</div>
	      			</div>	 
	      			<div class="form-group" id="div_label">
	      				<label class="control-label col-sm-4">Label</label>
	      				<div class="col-sm-8">	
	      			 		<select name="popup2_label" class="form-control select-search">
	      			 			
	      			 		</select>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Cap</label>
	      				<div class="col-sm-8">	
	      			 		<select name="popup2_cap" class="form-control select-search">
	      			 			
	      			 		</select>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Kemasan Awal</label>
	      				<div class="col-sm-8">	
	      			 		<select name="popup2_kemasan" class="form-control select-search">
	      			 			
	      			 		</select>
	      				</div>
	      			</div>
	      			<div class="form-group" id="div_kemasansatuan">
	      				<label class="control-label col-sm-4">Kemasan Satuan</label>
	      				<div class="col-sm-8">	
	      			 		<select name="popup2_kemasansatuan" class="form-control select-search">
	      			 			
	      			 		</select>
	      				</div>
	      			</div>
	      			<div class="form-group" id="div_kemasansepuluh">
	      				<label class="control-label col-sm-4">Kemasan 10 Potong</label>
	      				<div class="col-sm-8">	
	      			 		<select name="popup2_kemasansepuluh" class="form-control select-search">
	      			 			
	      			 		</select>
	      				</div>
	      			</div>

	      			<div class="form-group" id="div_kemasanseratus">
	      				<label class="control-label col-sm-4">Kemasan Dosball</label>
	      				<div class="col-sm-8">	
	      			 		<select name="popup2_kemasanseratus" class="form-control select-search">
	      			 			
	      			 		</select>
	      				</div>
	      			</div>
	      		</form>
	      	</div>
	      	<div class="modal-footer">
	        	<button type="button" class="btn btn-primary" id="btn_popup_simpan_masuk">Simpan</button>
	      	</div>
	    </div>
	</div>
</div>


<!-- EndModal -->
<!-- Modal -->

<div class="modal fade" id="exampleModal_upah" 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_upah_table">
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Proses</label>
	      				<div class="col-sm-8">
	      			 	<select class="form-control select-search" name="popup3_proses">
	      			 		<option value="">--- Pilih Proses ---</option>
	      			 		@php foreach($data['proses'] as $row){ 
        					if($row->nama_proses2 == ''){
        					echo '<optgroup label="'.$row->nama_proses.'">';
        					} else {
        					@endphp
        					<option value="{{ $row->id_proses }}" nama="{{$row->nama_proses}}"> {{ $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">upah</label>
	      				<div class="col-sm-8">
	      			 	<input type="text" name="popup3_upah" class="form-control number-only">
	      			 	<p class="pull-right" id="help_popup3_upah"></p>
	      				</div>
	      			</div>	      			
	      		</form>
	      	</div>
	      	<div class="modal-footer">
	        	<button type="button" class="btn btn-primary" id="btn_popup_simpan_upah">Simpan</button>
	      	</div>
	    </div>
	</div>
</div>


<!-- EndModal -->

<script type="text/javascript">
	$("#btn_tambah_item_keluar").click(function(){
		$("[name=popup_id_keluar_table]").val('');
		$("[name=popup_proses]").val(null).trigger('change');
		$("[name=popup_barang]").val(null).trigger('change');
		$("[name=popup_jumlah]").val('');
		$("[name=popup_satuan]").val(null).trigger('change');
		$("[name=popup_upah]").val('');
		$("[name=popup_harga]").val('');
		$("#help_popup_harga").text('');
		$("[name=popup_kualitas]").val(null).trigger('change');
		$("[name=popup_komposisi]").val(null).trigger('change');
		$("[name=popup_corak]").val(null).trigger('change');
		$("[name=popup_motif]").val(null).trigger('change');
		$("[name=popup_kual]").val(null).trigger('change');
		$("[name=popup_dudul]").val(null).trigger('change');
		$("[name=popup_label]").val(null).trigger('change');
		$("[name=popup_cap]").val(null).trigger('change');
		$("[name=popup_kemasan]").val(null).trigger('change');
		$("[name=popup_kemasansatuan]").val(null).trigger('change');
		$("[name=popup_kemasansepuluh]").val(null).trigger('change');
		$("[name=popup_kemasanseratus]").val(null).trigger('change');

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

	$("#btn_tambah_item_masuk").click(function(){
		$("[name=popup_id_masuk_table]").val('');
		$("[name=popup2_proses]").val(null).trigger('change');
		$("[name=popup2_barang]").val(null).trigger('change');
		$("[name=popup2_jumlah]").val('');
		$("[name=popup2_satuan]").val(null).trigger('change');
		$("[name=popup2_harga]").val('');
		$("#help_popup2_harga").text('');
		$("[name=popup2_kualitas]").val(null).trigger('change');
		$("[name=popup2_komposisi]").val(null).trigger('change');
		$("[name=popup2_corak]").val(null).trigger('change');
		$("[name=popup2_motif]").val(null).trigger('change');
		$("[name=popup2_kual]").val(null).trigger('change');
		$("[name=popup2_dudul]").val(null).trigger('change');
		$("[name=popup2_label]").val(null).trigger('change');
		$("[name=popup2_cap]").val(null).trigger('change');
		$("[name=popup2_kemasan]").val(null).trigger('change');
		$("[name=popup2_kemasansatuan]").val(null).trigger('change');
		$("[name=popup2_kemasansepuluh]").val(null).trigger('change');
		$("[name=popup2_kemasanseratus]").val(null).trigger('change');

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

	$("#btn_tambah_item_upah").click(function(){
		$("[name=popup_id_upah_table]").val('');
		$("[name=popup3_proses]").val(null).trigger('change');
		$("[name=popup3_upah]").val('');
		$("#help_popup3_upah").text('');

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

	$("[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);
		}
	})



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

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

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

		var id = "{{$data['data']['id_bom']}}";
		if(id != ''){
			get_edit_keluar(id);
			get_edit_masuk(id);
			get_edit_upah(id);
		}
		
        get_barang();
        get_kualitas();
        get_corak();
        get_motif();
        get_label();
        get_kemasan();
        get_cap();

        get_kemasansatuan();
        get_kemasansepuluh();
        get_dosball();
		

	})
	
	function get_motif(){
			$.ajax({
				url: '{{ url('bom/get_motif_kualitas') }}',
				success: function(respon){
					//--- input ---//
					$("[name=popup_motif]").html('');
					$("[name=popup_motif]").append('<option value="" nama="">--- Pilih motif ---</option>');
					if(respon.length > 0){
						for(i in respon){
							$("[name=popup_motif]").append('<option value="'+respon[i].id_motif+'" nama="'+respon[i].nama_motif+'">'+respon[i].nama_motif+'</option>');
						}
					}
					//--- Output ---//
					$("[name=popup2_motif]").html('');
					$("[name=popup2_motif]").append('<option value="" nama="">--- Pilih motif ---</option>');
					if(respon.length > 0){
						for(i in respon){
							$("[name=popup2_motif]").append('<option value="'+respon[i].id_motif+'" nama="'+respon[i].nama_motif+'">'+respon[i].nama_motif+'</option>');
						}
					}


				}
			})
		}

	function get_cap(){
		$.ajax({
			url: '{{ url('bom/get_barangbykat') }}',
			type: 'post',
			dataType: 'json',
			headers : {
				'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			},
			data: {id : '38'},
			success: function(respon){
				//--- Input ---//
				$("[name=popup_cap]").html('');
				$("[name=popup_cap]").append('<option value="" nama="">--- Pilih ---</option>')
				if(respon.length > 0){
					for(i in respon){
						$("[name=popup_cap]").append('<option value="'+respon[i].id_barang+'" nama="'+respon[i].nama_barang+'">'+respon[i].nama_barang+'</option>');
					}
				}

				//--- Output ---/
				$("[name=popup2_cap]").html('');
				$("[name=popup2_cap]").append('<option value="" nama="">--- Pilih ---</option>')
				if(respon.length > 0){
					for(i in respon){
						$("[name=popup2_cap]").append('<option value="'+respon[i].id_barang+'" nama="'+respon[i].nama_barang+'">'+respon[i].nama_barang+'</option>');
					}
				}
			}
		})
	}

	function get_label(){
		$.ajax({
			url: '{{ url('bom/get_barangbykat') }}',
			type: 'post',
			dataType: 'json',
			headers : {
				'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			},
			data: {id : '31'},
			success: function(respon){
				//--- Input ---//
				$("[name=popup_label]").html('');
				$("[name=popup_label]").append('<option value="" nama="">--- Pilih ---</option>')
				if(respon.length > 0){
					for(i in respon){
						$("[name=popup_label]").append('<option value="'+respon[i].id_barang+'" nama="'+respon[i].nama_barang+'" kode="'+respon[i].kode_barang+'">'+respon[i].nama_barang+'</option>');
					}
				}
				//--- Output ---//
				$("[name=popup2_label]").html('');
				$("[name=popup2_label]").append('<option value="" nama="">--- Pilih ---</option>')
				if(respon.length > 0){
					for(i in respon){
						$("[name=popup2_label]").append('<option value="'+respon[i].id_barang+'" nama="'+respon[i].nama_barang+'" kode="'+respon[i].kode_barang+'">'+respon[i].nama_barang+'</option>');
					}
				}

			}
		})
	}

	function get_kemasan(){
		$.ajax({
			url: '{{ url('bom/get_kemasan') }}',
			success: function(respon){
				//--- Input ---//
				$("[name=popup_kemasan]").html('');
				$("[name=popup_kemasan]").append('<option value="" nama="">--- Pilih ---</option>')
				if(respon.length > 0){
					for(i in respon){
						$("[name=popup_kemasan]").append('<option value="'+respon[i].id+'" nama="'+respon[i].nama_barang+'">'+respon[i].nama_barang+'</option>');
					}
				}

				//--- Output ---//
				$("[name=popup2_kemasan]").html('');
				$("[name=popup2_kemasan]").append('<option value="" nama="">--- Pilih ---</option>')
				if(respon.length > 0){
					for(i in respon){
						$("[name=popup2_kemasan]").append('<option value="'+respon[i].id+'" nama="'+respon[i].nama_barang+'">'+respon[i].nama_barang+'</option>');
					}
				}
			}
		})
	}

	function get_kemasansatuan(){
		$.ajax({
			url: '{{ url('bom/get_barangbykat') }}',
			type: 'post',
			dataType: 'json',
			headers : {
				'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			},
			data: {id : '30'},
			success: function(respon){
				//--- Input ---/
				$("[name=popup_kemasansatuan]").html('');
				$("[name=popup_kemasansatuan]").append('<option value="" nama="">--- Pilih ---</option>')
				if(respon.length > 0){
					for(i in respon){
						$("[name=popup_kemasansatuan]").append('<option value="'+respon[i].id_barang+'" nama="'+respon[i].nama_barang+'">'+respon[i].nama_barang+'</option>');
					}
				}

				//--- output ---//
				$("[name=popup2_kemasansatuan]").html('');
				$("[name=popup2_kemasansatuan]").append('<option value="" nama="">--- Pilih ---</option>')
				if(respon.length > 0){
					for(i in respon){
						$("[name=popup2_kemasansatuan]").append('<option value="'+respon[i].id_barang+'" nama="'+respon[i].nama_barang+'">'+respon[i].nama_barang+'</option>');
					}
				}
			}
		})
	}

	function get_kemasansepuluh(){
		$.ajax({
			url: '{{ url('bom/get_kemasansatuan') }}',
			success: function(respon){
				//--- Input ---//
				$("[name=popup_kemasansepuluh]").html('');
				$("[name=popup_kemasansepuluh]").append('<option value="" nama="">--- Pilih ---</option>')
				if(respon.length > 0){
					for(i in respon){
						$("[name=popup_kemasansepuluh]").append('<option value="'+respon[i].id+'" nama="'+respon[i].nama_barang+'">'+respon[i].nama_barang+'</option>');
					}
				}

				//--- Output ---//
				$("[name=popup2_kemasansepuluh]").html('');
				$("[name=popup2_kemasansepuluh]").append('<option value="" nama="">--- Pilih ---</option>')
				if(respon.length > 0){
					for(i in respon){
						$("[name=popup2_kemasansepuluh]").append('<option value="'+respon[i].id+'" nama="'+respon[i].nama_barang+'">'+respon[i].nama_barang+'</option>');
					}
				}
			}
		})
	}

	function get_dosball(){
		$.ajax({
			url: '{{ url('bom/get_barangbykat') }}',
			type: 'post',
			dataType: 'json',
			headers : {
				'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			},
			data: {id : '36'},
			success: function(respon){
				//--- Input ---//
				$("[name=popup_kemasanseratus]").html('');
				$("[name=popup_kemasanseratus]").append('<option value="" nama="">--- Pilih ---</option>')
				if(respon.length > 0){
					for(i in respon){
						$("[name=popup_kemasanseratus]").append('<option value="'+respon[i].id_barang+'" nama="'+respon[i].nama_barang+'">'+respon[i].nama_barang+'</option>');
					}
				}

				//--- Output ---//
				$("[name=popup2_kemasanseratus]").html('');
				$("[name=popup2_kemasanseratus]").append('<option value="" nama="">--- Pilih ---</option>')
				if(respon.length > 0){
					for(i in respon){
						$("[name=popup2_kemasanseratus]").append('<option value="'+respon[i].id_barang+'" nama="'+respon[i].nama_barang+'">'+respon[i].nama_barang+'</option>');
					}
				}
			}
		})
	}


	function get_kualitas(){
		$.ajax({
			url: '{{ url('bom/get_kualitas') }}',
			success: function(respon){
				//--- Input ---//
				$("[name=popup_kual]").html('');
				$("[name=popup_kual]").append('<option value="" nama="">--- Pilih Kualitas ---</option>')
				if(respon.length > 0){
					for(i in respon){
						$("[name=popup_kual]").append('<option value="'+respon[i].id_kualitas+'" nama="'+respon[i].nama_kualitas+'">'+respon[i].nama_kualitas+'</option>');
					}
				}

				//--- Output ---//
				$("[name=popup2_kual]").html('');
				$("[name=popup2_kual]").append('<option value="" nama="">--- Pilih Kualitas ---</option>')
				if(respon.length > 0){
					for(i in respon){
						$("[name=popup2_kual]").append('<option value="'+respon[i].id_kualitas+'" nama="'+respon[i].nama_kualitas+'">'+respon[i].nama_kualitas+'</option>');
					}
				}
			}
		})
	}	

	function get_barang(){
		$.ajax({
			url: '{{ url('bom/get_barang') }}',
			success: function(respon){
				//--- Input ---//
				$("[name=popup_barang]").html('');
				$("[name=popup_barang]").append('<option value="">--- Pilih Barang ---</option>')
				if(respon.length > 0){
					for(i in respon){
						$("[name=popup_barang]").append('<option value="'+respon[i].id_barang+'" nama="'+respon[i].nama_barang+'" kode="'+respon[i].kode_barang+'" satuan="'+respon[i].satuan+'">'+respon[i].kategori+' - '+respon[i].nama_sub+' - '+respon[i].kode_barang+' - '+respon[i].nama_barang+'</option>');
					}
				}

				//--- Output ---//
				$("[name=popup2_barang]").html('');
				$("[name=popup2_barang]").append('<option value="">--- Pilih Barang ---</option>')
				if(respon.length > 0){
					for(i in respon){
						$("[name=popup2_barang]").append('<option value="'+respon[i].id_barang+'" nama="'+respon[i].nama_barang+'" kode="'+respon[i].kode_barang+'" satuan="'+respon[i].satuan+'">'+respon[i].kategori+' - '+respon[i].nama_sub+' - '+respon[i].kode_barang+' - '+respon[i].nama_barang+'</option>');
					}
				}
			}
		})
	}

	function get_corak(){
		$.ajax({
			url: '{{ url('bom/get_motif') }}',
			success: function(respon){
				//--- Input ---//
				$("[name=popup_corak]").html('');
				$("[name=popup_corak]").append('<option value="" nama="">--- Pilih corak ---</option>');
				if(respon.length > 0){
					for(i in respon){
						$("[name=popup_corak]").append('<option value="'+respon[i].id_motif_barang+'" nama="'+respon[i].motif_keterangan+'">'+respon[i].motif_keterangan+'</option>');
					}
				}

				//--- Output ---//
				$("[name=popup2_corak]").html('');
				$("[name=popup2_corak]").append('<option value="" nama="">--- Pilih corak ---</option>');
				if(respon.length > 0){
					for(i in respon){
						$("[name=popup2_corak]").append('<option value="'+respon[i].id_motif_barang+'" nama="'+respon[i].motif_keterangan+'">'+respon[i].motif_keterangan+'</option>');
					}
				}
			}
		})
	}

	//------ Input Barang Keluar ----------------------------------------------------------------------------------//	

	$("[name=popup_harga]").keyup(function(){
		var id = $(this).val();
		$("#help_popup_harga").text(curr(id));
	})

	$("#btn_popup_simpan_keluar").click(function(){
		var id_data = $("[name=popup_id_keluar_table]").val();
		var id_barang = $("[name=popup_barang]").val();
		var kode_barang = $("[name=popup_barang] :selected").attr('kode');
		var nama_barang = $("[name=popup_barang] :selected").attr('nama');
		var id_proses = $("[name=popup_proses").val();
		var nama_proses = $("[name=popup_proses] :selected").attr("nama");
		var upah = $("[name=popup_upah]").val();
		var jumlah = $("[name=popup_jumlah]").val();
		var harga = $("[name=popup_harga").val();
		
		var satuan = $("[name=popup_satuan]").val();
		var nama_satuan = $("[name=popup_satuan] :selected").attr('name');

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

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

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

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

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

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

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

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

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

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

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

		if(id_barang != '' && jumlah != '' && jumlah != 0 && harga != '' && harga != 0 && satuan != ''){
			if(id_data == ''){
				table_barang.row.add(['<div><center></center></div>',
					'<div id="list_proses'+tb_no+'">'+nama_proses+'</div>',
					'<div id="list_kode'+tb_no+'">'+kode_barang+'</div>',
					'<div id="list_nama'+tb_no+'">'+nama_barang+'</div>',
					'<div id="list_komposisi'+tb_no+'">'+komposisi+'</div>',
					'<div id="list_jumlah'+tb_no+'">'+jumlah+'</div>',
					'<div id="list_namasatuan'+tb_no+'">'+nama_satuan+'</div>',
					'<div id="list_harga'+tb_no+'">'+curr(harga)+'</div>',
					'<div id="list_corak'+tb_no+'">'+corak+'</div>',
					'<div id="list_motif'+tb_no+'">'+motif+'</div>',
					'<div id="list_kualitas'+tb_no+'">'+kualitas+'</div>',
					'<div id="list_dudul'+tb_no+'">'+dudul+'</div>',
					'<div id="list_label'+tb_no+'">'+label+'</div>',
					'<div id="list_cap'+tb_no+'">'+nama_cap+'</div>',
					'<div id="list_kemasan'+tb_no+'">'+kemasan+'</div>',
					'<div id="list_kemasansatuan'+tb_no+'">'+kemasan_satuan+'</div>',
					'<div id="list_kemasansepuluh'+tb_no+'">'+kemasan_sepuluh+'</div>',
					'<div id="list_kemasanseratus'+tb_no+'">'+kemasan_seratus+'</div>',
					'<div><button type="button" class="btn bg-warning-400" onclick="edit_table_keluar('+tb_no+')"><i class="icon-pencil"></i> </button><button class="btn bg-danger-800" type="button"  onclick="hapus_keluar($(this))""><i class="icon-eraser"></i></button></div>'+
					'<input type="hidden" id="tabel_idtable'+tb_no+'" name="tabel_idtable[]" value="">'+
					'<input type="hidden" name="tabel_id[]" class="tabel_id" id="tabel_id'+tb_no+'" value="'+tb_no+'">'+
					'<input type="hidden" name="tabel_idbarang[]" id="tabel_idbarang'+tb_no+'" value="'+id_barang+'">'+
					'<input type="hidden" name="tabel_harga[]" id="tabel_harga'+tb_no+'" value="'+harga+'">'+
					'<input type="hidden" name="tabel_jumlah[]" id="tabel_jumlah'+tb_no+'" value="'+jumlah+'">'+
					'<input type="hidden" name="tabel_komposisi[]" id="tabel_komposisi'+tb_no+'" value="'+komposisi+'">'+
					'<input type="hidden" name="tabel_idkomposisi[]" id="tabel_idkomposisi'+tb_no+'" value="'+id_komposisi+'">'+
					'<input type="hidden" name="tabel_idsatuan[]" id="tabel_idsatuan'+tb_no+'" value="'+satuan+'">'+
					'<input type="hidden" name="tabel_idcorak[]" id="tabel_idcorak'+tb_no+'" value="'+id_corak+'">'+
					'<input type="hidden" name="tabel_idmotif[]" id="tabel_idmotif'+tb_no+'" value="'+id_motif+'">'+
					'<input type="hidden" name="tabel_idkualitas[]" id="tabel_idkualitas'+tb_no+'" value="'+id_kualitas+'">'+
					'<input type="hidden" name="tabel_iddudul[]" id="tabel_iddudul'+tb_no+'" value="'+id_dudul+'">'+
					'<input type="hidden" name="tabel_idlabel[]" id="tabel_idlabel'+tb_no+'" value="'+id_label+'">'+
					'<input type="hidden" name="tabel_idkemasan[]" id="tabel_idkemasan'+tb_no+'" value="'+id_kemasan+'">'+
					'<input type="hidden" name="tabel_idkemasansatuan[]" id="tabel_idkemasansatuan'+tb_no+'" value="'+id_kemasansatuan+'">'+
					'<input type="hidden" name="tabel_idkemasansepuluh[]" id="tabel_idkemasansepuluh'+tb_no+'" value="'+id_kemasansepuluh+'">'+
					'<input type="hidden" name="tabel_idkemasanseratus[]" id="tabel_idkemasanseratus'+tb_no+'" value="'+id_kemasanseratus+'">'+
					'<input type="hidden" name="tabel_idcap[]" id="tabel_idcap'+tb_no+'" value="'+id_cap+'">'+
					'<input type="hidden" name="tabel_kode[]" id="tabel_kode'+tb_no+'" value="'+kode_barang+'">'+
					'<input type="hidden" name="tabel_nama[]" id="tabel_nama'+tb_no+'" value="'+nama_barang+'">'+
					'<input type="hidden" name="tabel_namasatuan[]" id="tabel_namasatuan'+tb_no+'" value="'+nama_satuan+'">'+
					'<input type="hidden" name="tabel_idproses[]" id="tabel_idproses'+tb_no+'" value="'+id_proses+'">'+
					'<input type="hidden" name="tabel_namaproses[]" id="tabel_namaproses'+tb_no+'" value="'+nama_proses+'">'
							
					]).draw(false);
					tb_no++;
			}else{
				$("#list_proses"+id_data);
				$("#list_kode"+id_data).text(kode_barang);
				$("#list_nama"+id_data).text(nama_barang);
				$("#list_komposisi"+id_data).text(komposisi);
				$("#list_jumlah"+id_data).text(jumlah);
				$("#list_namasatuan"+id_data).text(nama_satuan);
				$("#list_harga"+id_data).text(harga);
				$("#list_corak"+id_data).text(corak);
				$("#list_motif"+id_data).text(motif);
				$("#list_kualitas"+id_data).text(kualitas);
				$("#list_dudul"+id_data).text(dudul);
				$("#list_label"+id_data).text(label);
				$("#list_cap"+id_data).text(nama_cap);
				$("#list_kemasan"+id_data).text(kemasan);
				$("#list_kemasansatuan"+id_data).text(kemasan_satuan);
				$("#list_kemasansepuluh"+id_data).text(kemasan_sepuluh);
				$("#list_kemasanseratus"+id_data).text(kemasan_seratus);

				$("#tabel_id"+id_data).val(id_data);
				$("#tabel_idbarang"+id_data).val(id_barang);
				$("#tabel_kode"+id_data).val(kode_barang);
				$("#tabel_nama"+id_data).val(nama_barang);
				$("#tabel_idproses"+id_data).val(id_proses);
				$("#tabel_namaproses"+id_data).val(nama_proses);
				$("#tabel_harga"+id_data).val(harga);				
				
				$("#tabel_jumlah"+id_data).val(jumlah);
				$("#tabel_idsatuan"+id_data).val(satuan);
				$("#tabel_namasatuan"+id_data).val(nama_satuan);

				$("#tabel_idkomposisi"+id_data).val(id_komposisi);
				$("#tabel_komposisi"+id_data).val(komposisi);
				$("#tabel_idcorak"+id_data).val(id_corak);
				$("#tabel_idmotif"+id_data).val(id_motif);
				$("#tabel_idkualitas"+id_data).val(id_kualitas);
				$("#tabel_iddudul"+id_data).val(id_dudul);
				$("#tabel_idlabel"+id_data).val(id_label);				
				$("#tabel_idcap"+id_data).val(id_cap);	
				$("#tabel_idkemasan"+id_data).val(id_kemasan);
				$("#tabel_idkemasansatuan"+id_data).val(id_kemasansatuan);
				$("#tabel_idkemasansepuluh"+id_data).val(id_kemasansepuluh);
				$("#tabel_idkemasanseratus"+id_data).val(id_kemasanseratus);
				
			}
		
		$("#exampleModal_keluar").modal('hide');
		
		}
	})

	function edit_table_keluar(id){
		var id_proses = $("#tabel_idproses"+id).val();
		var id_barang = $("#tabel_idbarang"+id).val();
		var harga = $("#tabel_harga"+id).val();
		var jumlah = $("#tabel_jumlah"+id).val();
		var satuan = $("#tabel_idsatuan"+id).val();
		var komposisi = $("#tabel_komposisi"+id).val();
		var id_komposisi = $("#tabel_idkomposisi"+id).val();

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

		$("[name=popup_id_keluar_table]").val(id);
		$("[name=popup_proses]").val(id_proses).trigger('change');
		$("[name=popup_barang]").val(id_barang).trigger('change');
		$("[name=popup_jumlah]").val(jumlah);
		$("[name=popup_harga]").val(harga);
		$("#help_popup_harga").text(curr(harga));		
		$("[name=popup_corak]").val(id_corak).trigger('change');
		$("[name=popup_motif]").val(id_motif).trigger('change');
		$("[name=popup_kual]").val(id_kualitas).trigger('change');
		$("[name=popup_dudul]").val(id_dudul).trigger('change');
		$("[name=popup_label]").val(id_label).trigger('change');
		$("[name=popup_kemasan]").val(id_kemasan).trigger('change');
		$("[name=popup_kemasansatuan]").val(id_kemasansatuan).trigger('change');
		$("[name=popup_kemasansepuluh]").val(id_kemasansepuluh).trigger('change');
		$("[name=popup_kemasanseratus]").val(id_kemasanseratus).trigger('change');
		$("[name=popup_cap]").val(id_cap).trigger('change');
		$("[name=popup_satuan]").val(satuan).trigger('change');
		$("[name=popup_komposisi]").val(id_komposisi).trigger('change');

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

	function hapus_keluar(d){
		table_barang.row(d.parents('tr')).remove().draw();
	}

	function get_edit_keluar(id){
		$.ajax({
			url: '{{url('bom/get_edit_keluar')}}',
			type: 'POST',
			dataType: 'json',
			headers : {
				'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			},
			data: {id:id},
			success: function(respon){
				if(respon.length > 0){
					for(i in respon){
						table_barang.row.add(['<div><center></center></div>',
							'<div id="list_proses'+respon[i].id_bom_keluar+'">'+respon[i].nama_proses+'</div>',
							'<div id="list_kode'+respon[i].id_bom_keluar+'">'+respon[i].kode_barang+'</div>',
							'<div id="list_nama'+respon[i].id_bom_keluar+'">'+respon[i].nama_barang+'</div>',
							'<div id="list_komposisi'+respon[i].id_bom_keluar+'">'+respon[i].nama_komposisi+'</div>',
							'<div id="list_jumlah'+respon[i].id_bom_keluar+'">'+respon[i].jumlah+'</div>',
							'<div id="list_namasatuan'+respon[i].id_bom_keluar+'">'+respon[i].nama_satuan+'</div>',
							'<div id="list_harga'+respon[i].id_bom_keluar+'">'+curr(respon[i].harga)+'</div>',
							'<div id="list_corak'+respon[i].id_bom_keluar+'">'+respon[i].nama_corak+'</div>',
							'<div id="list_motif'+respon[i].id_bom_keluar+'">'+respon[i].nama_motif+'</div>',
							'<div id="list_kualitas'+respon[i].id_bom_keluar+'">'+respon[i].nama_kualitas+'</div>',
							'<div id="list_dudul'+respon[i].id_bom_keluar+'">'+respon[i].kualitas_dudul+'</div>',
							'<div id="list_label'+respon[i].id_bom_keluar+'">'+respon[i].nama_label+'</div>',
							'<div id="list_cap'+respon[i].id_bom_keluar+'">'+respon[i].nama_cap+'</div>',
							'<div id="list_kemasan'+respon[i].id_bom_keluar+'">'+respon[i].nama_kemasan+'</div>',
							'<div id="list_kemasansatuan'+respon[i].id_bom_keluar+'">'+respon[i].nama_kemasansatuan+'</div>',
							'<div id="list_kemasansepuluh'+respon[i].id_bom_keluar+'">'+respon[i].nama_kemasansepuluh+'</div>',
							'<div id="list_kemasanseratus'+respon[i].id_bom_keluar+'">'+respon[i].nama_kemasanseratus+'</div>',
							'<div><button type="button" class="btn bg-warning-400" onclick="edit_table_keluar('+respon[i].id_bom_keluar+')"><i class="icon-pencil"></i> </button><button class="btn bg-danger-800" type="button"  onclick="hapus_keluar($(this))""><i class="icon-eraser"></i></button></div>'+
							'<input type="hidden" id="tabel_idtable'+respon[i].id_bom_keluar+'" name="tabel_idtable[]" value="">'+
							'<input type="hidden" name="tabel_id[]" class="tabel_id" id="tabel_id'+respon[i].id_bom_keluar+'" value="'+respon[i].id_bom_keluar+'">'+
							'<input type="hidden" name="tabel_idbarang[]" id="tabel_idbarang'+respon[i].id_bom_keluar+'" value="'+respon[i].id_barang+'">'+
							'<input type="hidden" name="tabel_harga[]" id="tabel_harga'+respon[i].id_bom_keluar+'" value="'+respon[i].harga+'">'+
							'<input type="hidden" name="tabel_jumlah[]" id="tabel_jumlah'+respon[i].id_bom_keluar+'" value="'+respon[i].jumlah+'">'+
							'<input type="hidden" name="tabel_komposisi[]" id="tabel_komposisi'+respon[i].id_bom_keluar+'" value="'+respon[i].nama_komposisi+'">'+
							'<input type="hidden" name="tabel_idkomposisi[]" id="tabel_idkomposisi'+respon[i].id_bom_keluar+'" value="'+respon[i].id_komposisi+'">'+
							'<input type="hidden" name="tabel_idsatuan[]" id="tabel_idsatuan'+respon[i].id_bom_keluar+'" value="'+respon[i].id_satuan+'">'+
							'<input type="hidden" name="tabel_idcorak[]" id="tabel_idcorak'+respon[i].id_bom_keluar+'" value="'+respon[i].id_corak+'">'+
							'<input type="hidden" name="tabel_idmotif[]" id="tabel_idmotif'+respon[i].id_bom_keluar+'" value="'+respon[i].id_motif+'">'+
							'<input type="hidden" name="tabel_idkualitas[]" id="tabel_idkualitas'+respon[i].id_bom_keluar+'" value="'+respon[i].id_kualitas+'">'+
							'<input type="hidden" name="tabel_iddudul[]" id="tabel_iddudul'+respon[i].id_bom_keluar+'" value="'+respon[i].id_kualitas_dudul+'">'+
							'<input type="hidden" name="tabel_idlabel[]" id="tabel_idlabel'+respon[i].id_bom_keluar+'" value="'+respon[i].id_label+'">'+
							'<input type="hidden" name="tabel_idkemasan[]" id="tabel_idkemasan'+respon[i].id_bom_keluar+'" value="'+respon[i].id_kemasan+'">'+
							'<input type="hidden" name="tabel_idkemasansatuan[]" id="tabel_idkemasansatuan'+respon[i].id_bom_keluar+'" value="'+respon[i].id_kemasansatuan+'">'+
							'<input type="hidden" name="tabel_idkemasansepuluh[]" id="tabel_idkemasansepuluh'+respon[i].id_bom_keluar+'" value="'+respon[i].id_kemasansepuluh+'">'+
							'<input type="hidden" name="tabel_idkemasanseratus[]" id="tabel_idkemasanseratus'+respon[i].id_bom_keluar+'" value="'+respon[i].id_kemasanseratus+'">'+
							'<input type="hidden" name="tabel_idcap[]" id="tabel_idcap'+respon[i].id_bom_keluar+'" value="'+respon[i].id_cap+'">'+
							'<input type="hidden" name="tabel_kode[]" id="tabel_kode'+respon[i].id_bom_keluar+'" value="'+respon[i].kode_barang+'">'+
							'<input type="hidden" name="tabel_nama[]" id="tabel_nama'+respon[i].id_bom_keluar+'" value="'+respon[i].nama_barang+'">'+
							'<input type="hidden" name="tabel_namasatuan[]" id="tabel_namasatuan'+respon[i].id_bom_keluar+'" value="'+respon[i].nama_satuan+'">'+
							'<input type="hidden" name="tabel_idproses[]" id="tabel_idproses'+respon[i].id_bom_keluar+'" value="'+respon[i].id_proses+'">'+
							'<input type="hidden" name="tabel_namaproses[]" id="tabel_namaproses'+respon[i].id_bom_keluar+'" value="'+respon[i].nama_proses+'">'
									]).draw(false);
					}
				}
			}
		})
	}

	//--------- End Input Barang Keluar ------------------------------------------------------------------------------------//


	//--------- Output Barang Masuk ----------------------------------------------------------------------------------------//
	$("[name=popup2_harga]").keyup(function(){
		var id = $(this).val();
		$("#help_popup2_harga").text(curr(id));
	})

	$("#btn_popup_simpan_masuk").click(function(){
		var id_data = $("[name=popup_id_masuk_table]").val();
		var id_barang = $("[name=popup2_barang]").val();
		var kode_barang = $("[name=popup2_barang] :selected").attr('kode');
		var nama_barang = $("[name=popup2_barang] :selected").attr('nama');
		var id_proses = $("[name=popup2_proses]").val();
		var nama_proses = $("[name=popup2_proses] :selected").attr('nama');
		var jumlah = $("[name=popup2_jumlah]").val();
		var harga = $("[name=popup2_harga").val();
		
		var satuan = $("[name=popup2_satuan]").val();
		var nama_satuan = $("[name=popup2_satuan] :selected").attr('name');

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

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

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

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

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

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

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

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

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

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

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

		if(id_barang != '' && jumlah != '' && jumlah != 0 && harga != '' && harga != 0 && satuan != ''){
			if(id_data == ''){
				table_masuk.row.add(['<div><center></center></div>',
					'<div id="list2_proses'+tb_no+'">'+nama_proses+'</div>',
					'<div id="list2_kode'+tb_no+'">'+kode_barang+'</div>',
					'<div id="list2_nama'+tb_no+'">'+nama_barang+'</div>',
					'<div id="list2_komposisi'+tb_no+'">'+komposisi+'</div>',
					'<div id="list2_jumlah'+tb_no+'">'+jumlah+'</div>',
					'<div id="list2_namasatuan'+tb_no+'">'+nama_satuan+'</div>',
					'<div id="list2_harga'+tb_no+'">'+curr(harga)+'</div>',
					'<div id="list2_corak'+tb_no+'">'+corak+'</div>',
					'<div id="list2_motif'+tb_no+'">'+motif+'</div>',
					'<div id="list2_kualitas'+tb_no+'">'+kualitas+'</div>',
					'<div id="list2_dudul'+tb_no+'">'+dudul+'</div>',
					'<div id="list2_label'+tb_no+'">'+label+'</div>',
					'<div id="list2_cap'+tb_no+'">'+nama_cap+'</div>',
					'<div id="list2_kemasan'+tb_no+'">'+kemasan+'</div>',
					'<div id="list2_kemasansatuan'+tb_no+'">'+kemasan_satuan+'</div>',
					'<div id="list2_kemasansepuluh'+tb_no+'">'+kemasan_sepuluh+'</div>',
					'<div id="list2_kemasanseratus'+tb_no+'">'+kemasan_seratus+'</div>',
					'<div><button type="button" class="btn bg-warning-400" onclick="edit_table_masuk('+tb_no+')"><i class="icon-pencil"></i> </button><button class="btn bg-danger-800" type="button"  onclick="hapus_masuk($(this))""><i class="icon-eraser"></i></button></div>'+
					'<input type="hidden" id="tabel_idtable_masuk'+tb_no+'" name="tabel_idtable_masuk[]" value="">'+
					'<input type="hidden" name="tabel2_id[]" class="tabel2_id" id="tabel2_id'+tb_no+'" value="'+tb_no+'">'+
					'<input type="hidden" name="tabel2_idbarang[]" id="tabel2_idbarang'+tb_no+'" value="'+id_barang+'">'+
					'<input type="hidden" name="tabel2_harga[]" id="tabel2_harga'+tb_no+'" value="'+harga+'">'+
					'<input type="hidden" name="tabel2_jumlah[]" id="tabel2_jumlah'+tb_no+'" value="'+jumlah+'">'+
					'<input type="hidden" name="tabel2_komposisi[]" id="tabel2_komposisi'+tb_no+'" value="'+komposisi+'">'+
					'<input type="hidden" name="tabel2_idkomposisi[]" id="tabel2_idkomposisi'+tb_no+'" value="'+id_komposisi+'">'+
					'<input type="hidden" name="tabel2_idsatuan[]" id="tabel2_idsatuan'+tb_no+'" value="'+satuan+'">'+
					'<input type="hidden" name="tabel2_idcorak[]" id="tabel2_idcorak'+tb_no+'" value="'+id_corak+'">'+
					'<input type="hidden" name="tabel2_idmotif[]" id="tabel2_idmotif'+tb_no+'" value="'+id_motif+'">'+
					'<input type="hidden" name="tabel2_idkualitas[]" id="tabel2_idkualitas'+tb_no+'" value="'+id_kualitas+'">'+
					'<input type="hidden" name="tabel2_iddudul[]" id="tabel2_iddudul'+tb_no+'" value="'+id_dudul+'">'+
					'<input type="hidden" name="tabel2_idlabel[]" id="tabel2_idlabel'+tb_no+'" value="'+id_label+'">'+
					'<input type="hidden" name="tabel2_idkemasan[]" id="tabel2_idkemasan'+tb_no+'" value="'+id_kemasan+'">'+
					'<input type="hidden" name="tabel2_idkemasansatuan[]" id="tabel2_idkemasansatuan'+tb_no+'" value="'+id_kemasansatuan+'">'+
					'<input type="hidden" name="tabel2_idkemasansepuluh[]" id="tabel2_idkemasansepuluh'+tb_no+'" value="'+id_kemasansepuluh+'">'+
					'<input type="hidden" name="tabel2_idkemasanseratus[]" id="tabel2_idkemasanseratus'+tb_no+'" value="'+id_kemasanseratus+'">'+
					'<input type="hidden" name="tabel2_idcap[]" id="tabel2_idcap'+tb_no+'" value="'+id_cap+'">'+
					'<input type="hidden" name="tabel2_kode[]" id="tabel2_kode'+tb_no+'" value="'+kode_barang+'">'+
					'<input type="hidden" name="tabel2_nama[]" id="tabel2_nama'+tb_no+'" value="'+nama_barang+'">'+
					'<input type="hidden" name="tabel2_namasatuan[]" id="tabel2_namasatuan'+tb_no+'" value="'+nama_satuan+'">'+
					'<input type="hidden" name="tabel2_idproses[]" id="tabel2_idproses'+tb_no+'" value="'+id_proses+'">'+
					'<input type="hidden" name="tabel2_namaproses[]" id="tabel2_namaproses'+tb_no+'" value="'+nama_proses+'">'
							
					]).draw(false);
					tb_no++;
			}else{
				$("#list2_proses"+id_data).text(nama_proses);
				$("#list2_kode"+id_data).text(kode_barang);
				$("#list2_nama"+id_data).text(nama_barang);
				$("#list2_komposisi"+id_data).text(komposisi);
				$("#list2_jumlah"+id_data).text(jumlah);
				$("#list2_namasatuan"+id_data).text(nama_satuan);
				$("#list2_harga"+id_data).text(curr(harga));
				$("#list2_corak"+id_data).text(corak);
				$("#list2_motif"+id_data).text(motif);
				$("#list2_kualitas"+id_data).text(kualitas);
				$("#list2_dudul"+id_data).text(dudul);
				$("#list2_label"+id_data).text(label);
				$("#list2_cap"+id_data).text(nama_cap);
				$("#list2_kemasan"+id_data).text(kemasan);
				$("#list2_kemasansatuan"+id_data).text(kemasan_satuan);
				$("#list2_kemasansepuluh"+id_data).text(kemasan_sepuluh);
				$("#list2_kemasanseratus"+id_data).text(kemasan_seratus);

				$("#tabel2_id"+id_data).val(id_data);
				$("#tabel2_idproses"+id_data).val(id_proses);
				$("#tabel2_namaproses"+id_data).val(nama_proses);
				$("#tabel2_idbarang"+id_data).val(id_barang);
				$("#tabel2_kode"+id_data).val(kode_barang);
				$("#tabel2_nama"+id_data).val(nama_barang);
				$("#tabel2_harga"+id_data).val(harga);				
				
				$("#tabel2_jumlah"+id_data).val(jumlah);
				$("#tabel2_idsatuan"+id_data).val(satuan);
				$("#tabel2_namasatuan"+id_data).val(nama_satuan);

				$("#tabel2_idkomposisi"+id_data).val(id_komposisi);
				$("#tabel2_komposisi"+id_data).val(komposisi);
				$("#tabel2_idcorak"+id_data).val(id_corak);
				$("#tabel2_idmotif"+id_data).val(id_motif);
				$("#tabel2_idkualitas"+id_data).val(id_kualitas);
				$("#tabel2_iddudul"+id_data).val(id_dudul);
				$("#tabel2_idlabel"+id_data).val(id_label);				
				$("#tabel2_idcap"+id_data).val(id_cap);	
				$("#tabel2_idkemasan"+id_data).val(id_kemasan);
				$("#tabel2_idkemasansatuan"+id_data).val(id_kemasansatuan);
				$("#tabel2_idkemasansepuluh"+id_data).val(id_kemasansepuluh);
				$("#tabel2_idkemasanseratus"+id_data).val(id_kemasanseratus);
				
			}
		
		$("#exampleModal_masuk").modal('hide');
		
		}
	})

	function edit_table_masuk(id){
		var id_proses = $("#tabel2_idproses"+id).val();
		var id_barang = $("#tabel2_idbarang"+id).val();
		var harga = $("#tabel2_harga"+id).val();
		var jumlah = $("#tabel2_jumlah"+id).val();
		var satuan = $("#tabel2_idsatuan"+id).val();
		var komposisi = $("#tabel2_komposisi"+id).val();
		var id_komposisi = $("#tabel2_idkomposisi"+id).val();

		var id_corak = $("#tabel2_idcorak"+id).val();
		var id_motif = $("#tabel2_idmotif"+id).val();
		var id_kualitas = $("#tabel2_idkualitas"+id).val();
		var id_dudul = $("#tabel2_iddudul"+id).val();
		var id_label = $("#tabel2_idlabel"+id).val();
		var id_kemasan = $("#tabel2_idkemasan"+id).val();
		var id_kemasansatuan = $("#tabel2_idkemasansatuan"+id).val();
		var id_kemasansepuluh = $("#tabel2_idkemasansepuluh"+id).val();
		var id_kemasanseratus = $("#tabel2_idkemasanseratus"+id).val();
		var id_cap = $("#tabel2_idcap"+id).val();

		$("[name=popup_id_masuk_table]").val(id);
		$("[name=popup2_proses").val(id_proses).trigger('change');
		$("[name=popup2_barang]").val(id_barang).trigger('change');
		$("[name=popup2_jumlah]").val(jumlah);
		$("[name=popup2_harga]").val(harga);
		$("#help_popup2_harga").text(curr(harga));		
		$("[name=popup2_corak]").val(id_corak).trigger('change');
		$("[name=popup2_motif]").val(id_motif).trigger('change');
		$("[name=popup2_kual]").val(id_kualitas).trigger('change');
		$("[name=popup2_dudul]").val(id_dudul).trigger('change');
		$("[name=popup2_label]").val(id_label).trigger('change');
		$("[name=popup2_kemasan]").val(id_kemasan).trigger('change');
		$("[name=popup2_kemasansatuan]").val(id_kemasansatuan).trigger('change');
		$("[name=popup2_kemasansepuluh]").val(id_kemasansepuluh).trigger('change');
		$("[name=popup2_kemasanseratus]").val(id_kemasanseratus).trigger('change');
		$("[name=popup2_cap]").val(id_cap).trigger('change');
		$("[name=popup2_satuan]").val(satuan).trigger('change');
		$("[name=popup2_komposisi]").val(id_komposisi).trigger('change');

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

	function hapus_masuk(d){
		table_masuk.row(d.parents('tr')).remove().draw();
	}


	function get_edit_masuk(id){
		$.ajax({
			url: '{{url('bom/get_edit_masuk')}}',
			type: 'POST',
			dataType: 'json',
			headers : {
				'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			},
			data: {id:id},
			success: function(respon){
				if(respon.length > 0){
					for(i in respon){
						table_masuk.row.add(['<div><center></center></div>',
							'<div id="list2_proses'+respon[i].id_bom_masuk+'">'+respon[i].nama_proses+'</div>',
							'<div id="list2_kode'+respon[i].id_bom_masuk+'">'+respon[i].kode_barang+'</div>',
							'<div id="list2_nama'+respon[i].id_bom_masuk+'">'+respon[i].nama_barang+'</div>',
							'<div id="list2_komposisi'+respon[i].id_bom_masuk+'">'+respon[i].nama_komposisi+'</div>',
							'<div id="list2_jumlah'+respon[i].id_bom_masuk+'">'+respon[i].jumlah+'</div>',
							'<div id="list2_namasatuan'+respon[i].id_bom_masuk+'">'+respon[i].nama_satuan+'</div>',
							'<div id="list2_harga'+respon[i].id_bom_masuk+'">'+curr(respon[i].harga)+'</div>',
							'<div id="list2_corak'+respon[i].id_bom_masuk+'">'+respon[i].nama_corak+'</div>',
							'<div id="list2_motif'+respon[i].id_bom_masuk+'">'+respon[i].nama_motif+'</div>',
							'<div id="list2_kualitas'+respon[i].id_bom_masuk+'">'+respon[i].nama_kualitas+'</div>',
							'<div id="list2_dudul'+respon[i].id_bom_masuk+'">'+respon[i].kualitas_dudul+'</div>',
							'<div id="list2_label'+respon[i].id_bom_masuk+'">'+respon[i].nama_label+'</div>',
							'<div id="list2_cap'+respon[i].id_bom_masuk+'">'+respon[i].nama_cap+'</div>',
							'<div id="list2_kemasan'+respon[i].id_bom_masuk+'">'+respon[i].nama_kemasan+'</div>',
							'<div id="list2_kemasansatuan'+respon[i].id_bom_masuk+'">'+respon[i].nama_kemasansatuan+'</div>',
							'<div id="list2_kemasansepuluh'+respon[i].id_bom_masuk+'">'+respon[i].nama_kemasansepuluh+'</div>',
							'<div id="list2_kemasanseratus'+respon[i].id_bom_masuk+'">'+respon[i].nama_kemasanseratus+'</div>',
							'<div><button type="button" class="btn bg-warning-400" onclick="edit_table_masuk('+respon[i].id_bom_masuk+')"><i class="icon-pencil"></i> </button><button class="btn bg-danger-800" type="button"  onclick="hapus_masuk($(this))""><i class="icon-eraser"></i></button></div>'+
							'<input type="hidden" id="tabel2_idtable'+respon[i].id_bom_masuk+'" name="tabel2_idtable[]" value="">'+
							'<input type="hidden" name="tabel2_id[]" class="tabel2_id" id="tabel2_id'+respon[i].id_bom_masuk+'" value="'+respon[i].id_bom_masuk+'">'+
							'<input type="hidden" name="tabel2_idbarang[]" id="tabel2_idbarang'+respon[i].id_bom_masuk+'" value="'+respon[i].id_barang+'">'+
							'<input type="hidden" name="tabel2_harga[]" id="tabel2_harga'+respon[i].id_bom_masuk+'" value="'+respon[i].harga+'">'+
							'<input type="hidden" name="tabel2_jumlah[]" id="tabel2_jumlah'+respon[i].id_bom_masuk+'" value="'+respon[i].jumlah+'">'+
							'<input type="hidden" name="tabel2_komposisi[]" id="tabel2_komposisi'+respon[i].id_bom_masuk+'" value="'+respon[i].nama_komposisi+'">'+
							'<input type="hidden" name="tabel2_idkomposisi[]" id="tabel2_idkomposisi'+respon[i].id_bom_masuk+'" value="'+respon[i].id_komposisi+'">'+
							'<input type="hidden" name="tabel2_idsatuan[]" id="tabel2_idsatuan'+respon[i].id_bom_masuk+'" value="'+respon[i].id_satuan+'">'+
							'<input type="hidden" name="tabel2_idcorak[]" id="tabel2_idcorak'+respon[i].id_bom_masuk+'" value="'+respon[i].id_corak+'">'+
							'<input type="hidden" name="tabel2_idmotif[]" id="tabel2_idmotif'+respon[i].id_bom_masuk+'" value="'+respon[i].id_motif+'">'+
							'<input type="hidden" name="tabel2_idkualitas[]" id="tabel2_idkualitas'+respon[i].id_bom_masuk+'" value="'+respon[i].id_kualitas+'">'+
							'<input type="hidden" name="tabel2_iddudul[]" id="tabel2_iddudul'+respon[i].id_bom_masuk+'" value="'+respon[i].id_kualitas_dudul+'">'+
							'<input type="hidden" name="tabel2_idlabel[]" id="tabel2_idlabel'+respon[i].id_bom_masuk+'" value="'+respon[i].id_label+'">'+
							'<input type="hidden" name="tabel2_idkemasan[]" id="tabel2_idkemasan'+respon[i].id_bom_masuk+'" value="'+respon[i].id_kemasan+'">'+
							'<input type="hidden" name="tabel2_idkemasansatuan[]" id="tabel2_idkemasansatuan'+respon[i].id_bom_masuk+'" value="'+respon[i].id_kemasansatuan+'">'+
							'<input type="hidden" name="tabel2_idkemasansepuluh[]" id="tabel2_idkemasansepuluh'+respon[i].id_bom_masuk+'" value="'+respon[i].id_kemasansepuluh+'">'+
							'<input type="hidden" name="tabel2_idkemasanseratus[]" id="tabel2_idkemasanseratus'+respon[i].id_bom_masuk+'" value="'+respon[i].id_kemasanseratus+'">'+
							'<input type="hidden" name="tabel2_idcap[]" id="tabel2_idcap'+respon[i].id_bom_masuk+'" value="'+respon[i].id_cap+'">'+
							'<input type="hidden" name="tabel2_kode[]" id="tabel2_kode'+respon[i].id_bom_masuk+'" value="'+respon[i].kode_barang+'">'+
							'<input type="hidden" name="tabel2_nama[]" id="tabel2_nama'+respon[i].id_bom_masuk+'" value="'+respon[i].nama_barang+'">'+
							'<input type="hidden" name="tabel2_namasatuan[]" id="tabel2_namasatuan'+respon[i].id_bom_masuk+'" value="'+respon[i].nama_satuan+'">'+
							'<input type="hidden" name="tabel2_idproses[]" id="tabel2_idproses'+respon[i].id_bom_masuk+'" value="'+respon[i].id_proses+'">'+
							'<input type="hidden" name="tabel2_namaproses[]" id="tabel2_namaproses'+respon[i].id_bom_masuk+'" value="'+respon[i].nama_proses+'">'
								]).draw(false);
					}
				}
			}
		})
	}

	//--------- End Output Barang Masuk ------------------------------------------------------------------------------------//

	//--------- Upah Produksi ----------------------------------------------------------------------------------------------//

	$("[name=popup3_upah").keyup(function(){
		var id = $(this).val();
		$("#help_popup3_upah").text(curr(id)); 
	})

	$("#btn_popup_simpan_upah").click(function(){
		var id_data = $("[name=popup_id_upah_table]").val();
		var id_proses = $("[name=popup3_proses]").val();
		var nama_proses = $("[name=popup3_proses] :selected").attr('nama');
		var upah = $("[name=popup3_upah]").val();

		if(id_proses != '' && upah != '' && upah != 0){
			if(id_data == ''){
				table_upah.row.add(['<div><center></center></div>',
					'<div id="list3_proses'+tb_no+'">'+nama_proses+'</div>',
					'<div id="list3_upah'+tb_no+'">'+curr(upah)+'</div>',
					'<div><button type="button" class="btn bg-warning-400" onclick="edit_table_upah('+tb_no+')"><i class="icon-pencil"></i> </button><button class="btn bg-danger-800" type="button"  onclick="hapus_upah($(this))""><i class="icon-eraser"></i></button></div>'+
					'<input type="hidden" id="tabel_idtable_upah'+tb_no+'" name="tabel_idtable_upah[]" value="">'+
					'<input type="hidden" name="tabel3_id[]" class="tabel3_id" id="tabel3_id'+tb_no+'" value="'+tb_no+'">'+
					'<input type="hidden" name="tabel3_idproses[]" id="tabel3_idproses'+tb_no+'" value="'+id_proses+'">'+
					'<input type="hidden" name="tabel3_namaproses[]" id="tabel3_namaproses'+tb_no+'" value="'+nama_proses+'">'+
					'<input type="hidden" name="tabel3_upah[]" id="tabel3_upah'+tb_no+'" value="'+upah+'">'
					]).draw(false);
					tb_no++;
			}else{
				$("#list3_proses"+id_data).val(id_proses);
				$("#list3_harga"+id_data).val(curr(upah));

				$("#tabel3_id"+id_data).val(id_data);
				$("#tabel3_idproses"+id_data).val(id_proses);
				$("#tabel3_namaproses"+id_data).val(nama_proses);
				$("#tabel3_upah"+id_data).val(upah);
			}
			$("#exampleModal_upah").modal('hide');
		}
	})

	function edit_table_upah(id){
		var id_proses = $("#tabel3_idproses"+id).val();
		var upah = $("#tabel3_upah"+id).val();

		console.log(id_proses);
		$("[name=popup_id_upah_table]").val(id);
		$("[name=popup3_proses]").val(id_proses).trigger('change');
		$("[name=popup3_upah]").val(upah);
		$("#help_popup3_upah").text(curr(upah));

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

	function hapus_upah(d){
		table_upah.row(d.parents('tr')).remove().draw();
	}

	function get_edit_upah(id){
		$.ajax({
			url: '{{url('bom/get_edit_upah')}}',
			type: 'POST',
			dataType: 'json',
			headers : {
				'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			},
			data: {id:id},
			success: function(respon){
				if(respon.length > 0){
					for(i in respon){
						table_upah.row.add(['<div><center></center></div>',
							'<div id="list3_proses'+respon[i].id_bom_upah+'">'+respon[i].nama_proses+'</div>',
							'<div id="list3_upah'+respon[i].id_bom_upah+'">'+curr(respon[i].upah)+'</div>',
							'<div><button type="button" class="btn bg-warning-400" onclick="edit_table_upah('+respon[i].id_bom_upah+')"><i class="icon-pencil"></i> </button><button class="btn bg-danger-800" type="button"  onclick="hapus_upah($(this))""><i class="icon-eraser"></i></button></div>'+
							'<input type="hidden" id="tabel_idtable_upah'+respon[i].id_bom_upah+'" name="tabel_idtable_upah[]" value="">'+
							'<input type="hidden" name="tabel3_id[]" class="tabel3_id" id="tabel3_id'+respon[i].id_bom_upah+'" value="'+respon[i].id_bom_upah+'">'+
							'<input type="hidden" name="tabel3_idproses[]" id="tabel3_idproses'+respon[i].id_bom_upah+'" value="'+respon[i].id_proses+'">'+
							'<input type="hidden" name="tabel3_namaproses[]" id="tabel3_namaproses'+respon[i].id_bom_upah+'" value="'+respon[i].nama_proses+'">'+
							'<input type="hidden" name="tabel3_upah[]" id="tabel3_upah'+respon[i].id_bom_upah+'" value="'+respon[i].upah+'">'
								]).draw(false);
					}
				}
			}
		})
	}

	//--------- End Upah Produksi ------------------------------------------------------------------------------------------//

	

</script>
@endsection