@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">Persetujuan Transfer Barang Keluar</li>
		</ul>
	</div>
</div>

<div class="content">
	<div class="panel panel-flat">
		<div class="panel-heading">
			<h5 class="panel-title">Persetujuan Transfer Barang Keluar</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_verifikasi">Verifikasi</button>
	    </div>
	    <table class="table table_trans table-stripped">
	    	<thead>
				<tr>
					<th>No</th>
					<th>Gudang Awal</th>
					<th>Gudang Tujuan</th>
					<th>Tanggal</th>
					<th class="text-center">Status</th>
					<th class="text-center">Aksi</th>
				</tr>
			</thead>
			<tbody>
				
				
			</tbody>
	    </table>
	</div>
</div>

{{-- <div class="checkbox">
	<div class="checker border-primary-600">
		<span class="checked">
			<input type="checkbox" class="control-primary" name="">
		</span>
		
	</div>
</div> --}}
<script type="text/javascript">

	var table_trans;

	$(document).ready(function(){
		table_trans = $(".table_trans").DataTable({
			processing: true,
	        serverSide: true,
	        ajax: '{{ url('persetujuangudang/get_data') }}',
	        columns: [
	            {data: 'awal', name: 'awal', orderable: false, searchable: false, render : function(data, type, row, meta){
	            	var check = '';
	            	if(row.status_id == 0){
	            		check = '<input type="checkbox" id="check_verifikasi" class="styled" value="'+row.id_transfergudang+'" jenis="'+row.rownum+'">';
	            	}
			  		return meta.row+1+' '+check;
			  	}},
	            {data: 'awal', name: 'awal'},
	            {data: 'tujuan', name: 'tujuan'},
	            {data: 'tanggal', name: 'tanggal'},
	            {data: 'status', name: 'status'},
	            {data: 'aksi', name: 'aksi', orderable: false, searchable: false}
	        ],
	        "order": [[ 4, "desc" ]]
		});
		
	})

	$("#btn_verifikasi").click(function(){
		var rows_selected = [];
		var jenis_selected = [];

		var rowcollection =  table_trans.$("#check_verifikasi:checked", {"page": "all"});
		rowcollection.each(function(index,elem){
		    var checkbox_value = $(elem).val();
		    var jenis = $(elem).attr('jenis');	

		    rows_selected.push(checkbox_value);
		    jenis_selected.push(jenis);
		
		})

		if(rows_selected.length > 0){

			swal({
				title: 'Anda yakin akan memverifikasi data ini?',
				type: 'warning',
				showCancelButton: true,
				confirmButtonColor: '#3085d6',
				cancelButtonColor: '#d33',
				confirmButtonText: 'Ya',
				cancelButtonText: 'Tidak',
			}).then((result) => {
			 	if(result.value){
					kirim_data(rows_selected, jenis_selected);	 		
			 	}
			})
		}else{
			notif_checkbox();
		}
	})

	function kirim_data(val, jenis){
		$.ajax({
			url: '{{ url('persetujuangudang/simpan_multi') }}',
			type: 'post',
			dataType: 'json',
			data: {id : val, jenis : jenis},
			headers : {
				'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			},
			success: function(respon){
				table_trans.ajax.reload();
			}
		})
	}
</script>


@endsection