@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> Inventori</a></li>
			<li class="active">Pengembalian Barang Produksi</li>
		</ul>
	</div>
</div>

<div class="content">
	<div class="panel panel-flat">
		<div class="panel-heading">
			<h5 class="panel-title">Pengembalian Barang Produksi</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 dataTable table-stripped">
	    	<thead>
				<tr>
					<th>No</th>
					<th>Nomor</th>
					<th>Nomor Order</th>
					<th>Tanggal</th>
					<th>Pemroses</th>
					<th>Proses Produksi</th>
					<th>Keterangan</th>
                    <th>Status</th>
					<th class="text-center"></th>
				</tr>
			</thead>
			<tbody>
				
			</tbody>
	    </table>
	</div>
</div>
<script type="text/javascript">
	var table;
	$(document).ready(function(){
		table = $(".dataTable").DataTable({
			processing: true,
	        serverSide: true,
	        ajax: '{{ url('terimakembali/get_kembali') }}',
	        columns: [
	            {data: 'rownum', name: 'rownum', orderable: false, searchable: false, render : function(data, type, row, meta){
			  		
			  		return meta.row+1 + ' ' + row.checkbox;
			  	}, className: 'text-center'},
			  	{data: 'nomor', name: 'nomor'},
			  	{data: 'no_workorder', name: 'no_workorder'},
	            {data: 'tanggal', name: 'tanggal'},
	            {data: 'posisi', name: 'posisi'},
	            {data: 'nama_proses', name: 'nama_proses'},
	            {data: 'keterangan', name: 'keterangan'},
	            {data: 'status', name: 'status'},
	            {data: 'aksi', name: 'aksi', orderable: false, searchable: false}
	        ],
	        "order": [[ 7, "desc" ]]
		});

	})

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

		var rowcollection =  table.$("#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);

		});

		// console.log(rows_selected.length);

		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('terimakembali/simpan_terimamulti') }}',
			type: 'post',
			dataType: 'json',
			data: {id : val, jenis : jenis},
			headers : {
				'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
			},
			success: function(respon){
				table.ajax.reload();
			}
		})
	}

</script>
@endsection