@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> Keuangan</a></li>
			<li class="active">Jurnal Penyesuaian Sewa</li>
		</ul>
	</div>
</div>

<div class="content">
	<div class="row">
		<div class="col-lg-12">
			@if(Session::has('flash_message_error'))
	    	<div class="alert alert-danger no-border">
				<button type="button" class="close" data-dismiss="alert"><span>×</span><span class="sr-only">Close</span></button>
				{!! session('flash_message_error') !!}
				<!-- <span class="text-semibold">Well done!</span> You successfully read <a href="#" class="alert-link">this important</a> alert message. -->
		    </div>
		    @elseif(Session::has('flash_message_success'))
		    <div class="alert alert-success no-border">
				<button type="button" class="close" data-dismiss="alert"><span>×</span><span class="sr-only">Close</span></button>
				{!! session('flash_message_success') !!}
				<!-- <span class="text-semibold">Well done!</span> You successfully read <a href="#" class="alert-link">this important</a> alert message. -->
		    </div>
		    @endif
		</div>
	</div>
	<div class="panel panel-flat">
		<div class="panel-heading">
			<h5 class="panel-title">Jurnal Penyesuaian Sewa</h5>

			<div class="heading-elements">
		      	<a href="{{ route('js.createPenyesuaianSewa') }}" class="btn btn-xs btn-primary"><i class="icon-plus2"></i> Tambah</a>
	       	</div>
	    </div>
	    <div class="panel-body">


	    <table class="table datatable-basic table-striped table_jurnal_sewa">
	    	<thead>
				<tr>
					<th class="text-center">Tanggal Jurnal</th>
					<th class="text-center">No. Jurnal</th>
					<th class="text-center">No. Faktur</th>
					<th class="text-center">Nama Penyedia/Pemilik</th>
					<th class="text-center">Aksi</th>
				</tr>
			</thead>
			<tbody>

			</tbody>
	    </table>
	    
	    </div>
	</div>
</div>

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

	$(document).ready(function(){
		loadTable();
	})

	function loadTable()
	{
		table = $(".table_jurnal_sewa").DataTable({
			processing: true,
	        serverSide: true,
	        deferRender: true,
	        ajax: '{{ route('js.getDataJurnalPenyesuaianSewa') }}',
	        columns: [
	            {data: 'tanggal_jurnal', name: 'tanggal_jurnal', render : function(tanggal_jurnal){
	            	return moment(tanggal_jurnal).format("DD-MM-YYYY");
	            }},
	            {data: 'nomor_jurnal', name: 'nomor_jurnal'},
	            {data: 'no_faktur', name: 'no_faktur'},
	            {data: 'nama_penyedia', name: 'nama_penyedia'},
	            {data: 'aksi', name: 'aksi', orderable: false, searchable: false}
	        ],
	        order : false,
	        createdRow: function(row, data, index) {
				$( row ).attr('data-id', data['id_jsh']);
				$( 'td', row ).eq(4).addClass('text-center');
            }
		});
	}

	function deleteJurnal(id)
	{
		swal({
			title: 'Anda yakin akan menghapus data ini?',
			type: 'warning',
			showCancelButton: true,
			confirmButtonColor: '#3085d6',
			cancelButtonColor: '#d33',
			confirmButtonText: 'Ya',
			cancelButtonText: 'Tidak',
		}).then((result) => {
		 	if(result.value){
		 		$.ajax({
					url: "{{ url('jurnal-penyesuaian-sewa/delete')}}/"+id,
					type: 'get',
					success: function(response){
						if (response.status == "Success") {
							table.ajax.reload();
							swal({
								icon: "success",
								title: response.message,
								type: 'success'
							})
						} else {
							swal({
								icon: "error",
								title: response.message,
								type: 'error'
							})
						}
					}
				})
		 	}
		})
	}
</script>

@endsection