@extends('layout')


@section('content')

<div class="page-header page-header-default">
	<div class="breadcrumb-line">
		<ul class="breadcrumb">
			<li><a href="#"><i class="icon-home2 position-left"></i> Inventori</a></li>
			<li class="active">Saldo Awal</li>
		</ul>
	</div>
</div>

<div class="content">
	<div class="panel panel-flat">
		<div class="panel-heading">
			<h5 class="panel-title">Saldo Awal</h5>
			<div class="heading-elements">
				<ul class="icons-list">
		      		<li><a data-action="collapse"></a></li>
		      	</ul>
	       	</div>
	    </div>
	    <div class="panel-body">
	    	<button class="btn btn-primary" type="button" id="btn_tambah_saldoawal">Tambah</button>
	    </div>
	    <div class="table-responsive">
	    <table class="table table-stripped table_saldoawal">
				    	<thead>
							<tr>
								<th>No</th>
								<th></th>
								<th>Kode Barang</th>
								<th>Nama Barang</th>
								<th>Tanggal</th>
			                    <th>Jumlah Saldo Awal</th>
			                    <th>Satuan</th>
			                    <th>Jumlah Rencana</th>
			                    <th>Satuan Rencana</th>
			                    <th>Keterangan</th>
			                    <th>Nama Gudang</th>
			                    <th>Proses Produksi</th>
			                    <th>Warna</th>
			                    <th>Kualitas Proses</th>
			                    <th>Corak</th>
			                    <th>Motif</th>
			                    <th>No. Order</th>
			                    <th>Kualitas Tenun</th>
			                    <th>Dudulan</th>
			                    <th>Kualitas Periksa</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 id="body_setor">
						</tbody>
			  </table>
			</div>
	</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" id="form_saldoawal">
	      			<input type="hidden" name="popup_id_table">
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Barang</label>
	      				<div class="col-sm-8">
	      			 	<select class="form-control select-search" name="popup_barang">
	      			 		
	      			 	</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">
	      			 		
	      			 	</select>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Proses Produksi</label>
	      				<div class="col-sm-8">
	      			 	<select class="form-control select-search" name="popup_proses">
	      			 		<option value="">-- Pilih Produksi --</option>
        					@php foreach($data['proses'] as $row){ 
        					if($row->nama_proses2 == ''){

        					echo '<optgroup label="'.$row->nama_proses.'">';
        					} else {
        					@endphp
        					<option value="{{ $row->id_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">Kualitas</label>
	      				<div class="col-sm-8">	
	      			 		<select name="popup_kualitas" class="form-control select-search">

	      			 		</select>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Warna</label>
	      				<div class="col-sm-8">
	      			 		<select name="popup_komposisi" 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_order">
	      				<label class="control-label col-sm-4">No. Order</label>
	      				<div class="col-sm-8">	      					
	      			 		<select name="popup_order" class="form-control select-search">
	      			 		</select>
	      				</div>
	      			</div>	    
	      			<div class="form-group" id="div_kualitas">
	      				<label class="control-label col-sm-4">Kualitas Tenun</label>
	      				<div class="col-sm-8">	
	      			 		<select name="popup_kual" class="form-control select-search">
	      			 			
	      			 		</select>
	      				</div>
	      			</div>
	      			<div class="form-group" id="div_dudul">
	      				<label class="control-label col-sm-4">Kualitas Dudulan</label>
	      				<div class="col-sm-8">	
	      			 		<select name="popup_dudul" class="form-control select-search">
	      			 			<option value="" nama="">-- Pilih Dudulan --</option>
	      			 			<option value="1" nama="Baik">Baik</option>
	      			 			<option value="2" nama="Jelek">Jelek</option>
	      			 		</select>
	      				</div>
	      			</div>
	      			<div class="form-group" id="div_kualitas">
	      				<label class="control-label col-sm-4">Kualitas Periksa</label>
	      				<div class="col-sm-8">	
	      			 		<select name="popup_periksa" class="form-control select-search">
	      			 			
	      			 		</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>

	      			<hr/>
	      			<h5>Saldo Awal</h5>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Jumlah</label>
	      				<div class="col-sm-8">
	      			 	<input type="text" name="popup_jumlah" class="form-control number-only">
	      			 	<p class="help-block pull-right" id="jum_saldoawal"></p>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Satuan</label>
	      				<div class="col-sm-8">
	      			 		<select class="form-control select-search" name="popup_satuan">
	      			 			 
	      			 		</select>
	      				</div>
	      			</div>
	      			<div class="form-group">
	      				<label class="control-label col-sm-4"><b>Mengahasilkan</b></label>
	      				<div class="col-sm-8">
	      					<input type="text" name="popup_menghasilkan" class="form-control number-only">
	      					<p class="help-block pull-right" id="jum_menghasilkan"></p>
	      				</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_satuanmenghasilkan">
	      			 			 
	      			 		</select>
	      				</div>
	      			</div>	
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Tanggal</label>
	      				<div class="col-sm-8">
	      					<input type="text" name="popup_tanggal" class="form-control datepicker" value="{{ date("d-m-Y") }}">
	      				</div>
	      			</div> 
	      			<div class="form-group">
	      				<label class="control-label col-sm-4">Keterangan</label>
	      				<div class="col-sm-8">
	      					<textarea class="form-control" name="popup_ket">
	      						
	      					</textarea>
	      				</div>
	      			</div>      				
	      		</form>
	      	</div>
	      	<div class="modal-footer">
	        	<button type="button" class="btn btn-primary" id="btn_popup_simpan">Simpan</button>
	      	</div>
	    </div>
	</div>
</div>

<script type="text/javascript">
	var tabel_saldoawal;

	$(document).ready(function(){
		tabel_saldoawal = $(".table_saldoawal").DataTable({
			scrollX: true,
			processing: true,
	        serverSide: true,
	        searchDelay: 3000,
	        ajax: '{{ url('saldoawal_barang/get_data') }}',
	        columns: [
	            {data: 'rownum', name: 'rownum', orderable: false, searchable: false, render : function(data, type, full, meta){
			  		return meta.row+1;
			  	}},
			  	{data: 'aksi2', name: 'aksi2', orderable: false, searchable: false},
	            {data: 'kode_barang', name: 'kode_barang'},
	            {data: 'nama_barang', name: 'nama_barang'},
	            {data: 'tanggal', name: 'tanggal'},
	            {data: 'jumlah_saldoawal', name: 'jumlah_saldoawal'},
	            {data: 'nama_satuan', name: 'nama_satuan'},
	            {data: 'jumlah_rencana', name: 'jumlah_rencana'},
	            {data: 'nama_perubahansatuan', name: 'nama_perubahansatuan'},
	            {data: 'keterangan', name: 'keterangan'},
	            {data: 'nama_gudang', name: 'nama_gudang'},
	            {data: 'nama_proses', name: 'nama_proses'},
	            {data: 'nama_komposisi', name: 'nama_komposisi'},
	            {data: 'nama_kualitas_proses', name: 'nama_kualitas_proses'},
	            {data: 'nama_corak', name: 'nama_corak'},
	            {data: 'nama_motif', name: 'nama_motif'},
	            {data: 'no_workorder_barang', name: 'no_workorder_barang'},
	            {data: 'nama_kualitas', name: 'nama_kualitas'},
	            {data: 'kualitas_dudul', name: 'kualitas_dudul'},
	            {data: 'nama_kualitas_periksa', name: 'nama_kualitas_periksa'},
	            {data: 'nama_label', name: 'nama_label'},
	            {data: 'nama_cap', name: 'nama_cap'},
	            {data: 'nama_kemasan', name: 'nama_kemasan'},
	            {data: 'nama_kemasansatuan', name: 'nama_kemasansatuan'},
	            {data: 'nama_kemasansepuluh', name: 'nama_kemasansepuluh'},
	            {data: 'nama_kemasanseratus', name: 'nama_kemasanseratus'},
	            {data: 'aksi', name: 'aksi', orderable: false, searchable: false}
	        ],
	       	createdRow: function(row, data, index) {                     
                      $('td', row).eq(23).attr('nowrap','nowrap'); // 6 is index of column
                    },
		});

		get_barang();
	})

	$("#btn_tambah_saldoawal").click(function(){
		$("[name=popup_id_table]").val('');
		$("[name=popup_barang]").val(null).trigger('change');
		$("[name=popup_gudang]").val(null).trigger('change');
		$("[name=popup_proses]").val(null).trigger('change');
		$("[name=popup_jumlah]").val('');
		$("[name=popup_upah]").val('');
		$("[name=popup_kual]").val(null).trigger('change');
		$("[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_order]").val("").trigger('change');
		$("[name=popup_dudul]").val(null).trigger('change');
		$("[name=popup_label]").val(null).trigger('change');
		$("[name=popup_cap]").val(null).trigger('change');
		$("[name=popup_kemasan]").val(null).trigger('change');
		$("[name=popup_kemasansatuan]").val(null).trigger('change');
		$("[name=popup_kemasansepuluh]").val(null).trigger('change');
		$("[name=popup_kemasanseratus]").val(null).trigger('change');
		$("[name=popup_periksa]").val(null).trigger('change');
		$("[name=popup_keterangan]").val('');

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


		$("[name=popup_jumlah]").attr('placeholder', '');
		$("[name=popup_jumlah]").attr('min',0);
		$("[name=popup_jumlah]").removeAttr('max');
		$("[name=popup_ket]").val("");
		get_order(2);

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

	$("[name=popup_jumlah]").keyup(function(){
		var jum = $("[name=popup_jumlah]").val();
		$("#jum_saldoawal").text(format_angka(jum));	
	})

	$("[name=popup_menghasilkan]").keyup(function(){
		var jum = $("[name=popup_menghasilkan]").val();
		$("#jum_menghasilkan").text(format_angka(jum));
	})

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

				$("[name=popup_gudang]").html('');
				$("[name=popup_gudang]").append('<option value="">--- Pilih Gudang ---</option>');
				if(respon.responseJSON.gudang.length > 0){
					for(i in respon.responseJSON.gudang){
						$("[name=popup_gudang]").append('<option value="'+respon.responseJSON.gudang[i].id_gudang+'" nama="'+respon.responseJSON.gudang[i].nama_gudang+'">'+respon.responseJSON.gudang[i].nama_gudang+'</option>');
					}
				}

				$("[name=popup_motif]").html('');
				$("[name=popup_motif]").append('<option value="" nama="">--- Pilih motif ---</option>');
				if(respon.responseJSON.motif.length > 0){
					for(i in respon.responseJSON.motif){
						$("[name=popup_motif]").append('<option value="'+respon.responseJSON.motif[i].id_motif+'" nama="'+respon.responseJSON.motif[i].nama_motif+'">'+respon.responseJSON.motif[i].nama_motif+'</option>');
					}
				}

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

				$("[name=popup_satuan]").html('');
				$("[name=popup_satuan]").append('<option value="">--- Pilih Satuan ---</option>');
				if(respon.responseJSON.satuan.length > 0){
					for(i in respon.responseJSON.satuan){
						$("[name=popup_satuan]").append('<option value="'+respon.responseJSON.satuan[i].id_satuan+'" nama="'+respon.responseJSON.satuan[i].nama_satuan+'">'+respon.responseJSON.satuan[i].nama_satuan+'</option>');
					}
				}

				$("[name=popup_satuanmenghasilkan]").html('');
				$("[name=popup_satuanmenghasilkan]").append('<option value="">--- Pilih Satuan ---</option>');
				if(respon.responseJSON.satuan.length > 0){
					for(i in respon.responseJSON.satuan){
						$("[name=popup_satuanmenghasilkan]").append('<option value="'+respon.responseJSON.satuan[i].id_satuan+'" nama="'+respon.responseJSON.satuan[i].nama_satuan+'">'+respon.responseJSON.satuan[i].nama_satuan+'</option>');
					}
				}

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

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

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

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

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

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


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

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

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


			}
		})
	}

	function get_order(id){
		$.ajax({
			url: '{{ url('saldoawal_barang/get_spk/') }}'+'/'+id,
			dataType: 'json',
			success: function(respon){
				$("[name=popup_order]").html('');
				$("[name=popup_order]").append('<option value="">--- Pilih No. Order ---</option>');

				if(respon.length > 0){
					for(i in respon){
						$("[name=popup_order]").append('<option value="'+respon[i].id_workorder_barang+'">'+respon[i].no_workorder+'</option>');
					}
				}
			},
			complete : function(respon){

			}
		})
	}

	function edit(id){

		var kualitas = $("#table_idkualitas"+id).val();

		var FunctionOne = function (){
			var r = $.Deferred();
			
			get_order(1);
			
			setTimeout(function () {
        		r.resolve();
        	}, 3000);
        	return r;
		}

		var FunctionTwo = function () {
        	$("[name=popup_id_table]").val($("#table_id"+id).val());
			$("[name=popup_barang]").val($("#table_idbarang"+id).val()).trigger('change');
			$("[name=popup_gudang]").val($("#table_idgudang"+id).val()).trigger('change');
			$("[name=popup_proses]").val($("#table_idproses"+id).val()).trigger('change');
			$("[name=popup_kualitas]").val($("#table_idkualitas_proses"+id).val()).trigger('change');
			$("[name=popup_komposisi]").val($("#table_idkomposisi"+id).val()).trigger('change');
			$("[name=popup_motif]").val($("#table_idmotif"+id).val()).trigger('change');
			$("[name=popup_corak]").val($("#table_idcorak"+id).val()).trigger('change');
			$("[name=popup_dudul]").val($("#table_idkualitas_dudul"+id).val()).trigger('change');
			$("[name=popup_kual]").val($("#table_idkualitas"+id).val()).trigger('change');
			$("[name=popup_label]").val($("#table_idlabel"+id).val()).trigger('change');
			$("[name=popup_cap]").val($("#table_idcap"+id).val()).trigger('change');
			$("[name=popup_kemasan]").val($("#table_idkemasan"+id).val()).trigger('change');
			$("[name=popup_kemasansatuan]").val($("#table_idkemasansatuan"+id).val()).trigger('change');
			$("[name=popup_kemasansepuluh]").val($("#table_idkemasansepuluh"+id).val()).trigger('change');
			$("[name=popup_kemasanseratus]").val($("#table_idkemasanseratus"+id).val()).trigger('change');
			$("[name=popup_periksa]").val($("#table_idkualitas_periksa"+id).val()).trigger('change');
			$("[name=popup_tanggal]").val($("#table_tanggal"+id).val()).trigger('change');
			$("[name=popup_ket]").val($("#table_keterangan"+id).val()).trigger('change');
			$("[name=popup_jumlah]").val($("#table_jumlah"+id).val());
			$("[name=popup_satuan]").val($("#table_idsatuan"+id).val()).trigger('change');
			$("[name=popup_menghasilkan]").val($("#table_jumlahrencana"+id).val()).trigger('change');
			$("[name=popup_satuanmenghasilkan]").val($("#table_idsatuanperubahan"+id).val()).trigger('change');
			$("[name=popup_order]").val($("#table_workorderbarang"+id).val()).trigger('change');


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

	$("#btn_popup_simpan").click(function(){
		var id = $("[name=popup_id_table]").val();
		var id_barang = $("[name=popup_barang]").val();
		var jumlah = $("[name=popup_jumlah]").val();
		var satuan = $("[name=popup_satuan]").val();
		if(id_barang != '' && jumlah != '' && satuan != ''){
			$.ajax({
				url: "{{ url('saldoawal_barang/simpan') }}",
				type: 'post',
				dataType: 'json',
				headers : {
					'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
				},
				data: $("#form_saldoawal").serialize(),
				success: function(respon){
					tabel_saldoawal.ajax.reload();
					$("#exampleModal").modal('hide');
				}
			})
		}
	})

	function hapus(id){
		swal({
			title: 'Anda yakin akan menghapus item ini?',
			type: 'warning',
			showCancelButton: true,
			confirmButtonColor: '#3085d6',
			cancelButtonColor: '#d33',
			confirmButtonText: 'Ya',
			cancelButtonText: 'Tidak',
		}).then((result) => {
		 	if(result.value){
		 		$.ajax({
					url: "{{ url('saldoawal_barang/hapus')}} ",
					type: 'post',
					data: {id : id},
					headers : {
						'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
					},
					success: function(respon){
						tabel_saldoawal.ajax.reload();
					}
				})
		 	}
		})
	}
</script>

@endsection