@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">Stock Opname</li>
		</ul>
	</div>
</div>

<div class="content">
	<div class="panel panel-flat">
		<div class="panel-heading">
			<h5 class="panel-title">Stock Opname</h5>
			<div class="heading-elements">
				<ul class="icons-list">
		      		<li><a data-action="collapse"></a></li>
		      	</ul>
	       	</div>
	    </div>
	    <div class="panel-body">
	    	<a href="{{ url('opname/tambah')}}" class="btn btn-success" style="margin-bottom: 1%;">Tambah</a>
	    </div>

	    <table class="table table_opname table-stripped">
	    	<thead>
				<tr>
					<th>No</th>
					<th>Tanggal</th>
					<th>Gudang</th>
					<th>Keterangan</th>
					<th class="text-center"></th>
				</tr>
			</thead>
			<tbody>
			</tbody>
	    </table>
	</div>
</div>

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

	$(document).ready(function(){
		table_opname = $(".table_opname").DataTable({
			processing: true,
	        serverSide: true,
	        ajax: '{{ url('opname/get_data') }}',
	        columns: [
	            {data: 'rownum', name: 'rownum', orderable: false, searchable: false, render : function(data, type, row, meta){
			  		return meta.row+1;
			  	}},
	            {data: 'tanggal', name: 'tanggal'},
	            {data: 'nama_gudang', name: 'nama_gudang'},
	            {data: 'keterangan', name: 'keterangan'},
	            {data: 'aksi', name: 'aksi', orderable: false, searchable: false}
	        ],
		});
		
	})

		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('opname/hapus')}} ",
					type: 'post',
					data: {id : id},
					headers : {
						'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
					},
					success: function(respon){
						table_opname.ajax.reload();
					}
				})
		 	}
		})
	}
</script>
@endsection