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

<div class="content">
	<div class="panel panel-flat">
		<div class="panel-heading">
			<h5 class="panel-title">Jurnal Lain</h5>

			<div class="heading-elements">
		      	<a href="{{ url('jurnal_lain/tambah_jurnal_lain') }}" class="btn btn-xs btn-success"><i class="icon-plus2"></i> Tambah</a>
	       	</div>
	    </div>
	    <div class="panel-body">


	    <table class="table datatable-basic table-striped" id="tabel-jurnal-lain">
	    	<thead>
				<tr>
					<th>No</th>
					<th>No. Transaksi</th>
					<th>Tanggal</th>
					<th>Debet</th>
					<th>Kredit</th>
					<th>&nbsp;</th>
				</tr>
			</thead>
			<tbody>

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

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

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

	function loadTabelJurnalLain() {
		tabelJurnalLain = $("#tabel-jurnal-lain").DataTable({
			processing: true,
	        serverSide: true,
	        ajax: "{{ url('jurnal_lain/data_jurnal_lain') }}",
	        columns: [
	            {data: 'rownum', name: 'rownum', orderable: false, searchable: false, render : function(data, type, row, meta){
			  		return meta.row+1;
			  	}},
	            {data: 'nomor_jurnal', name: 'nomor_jurnal'},
	            {data: 'tanggal_jurnal', name: 'tanggal_jurnal'},
	            {data: 'total_debet', name: 'total_debet', render: function(total_debet){
	            	return curr(total_debet);
	            }},
	            {data: 'total_kredit', name: 'total_kredit', render: function(total_kredit){
	            	return curr(total_kredit);
	            }},
	            {data: 'aksi', name: 'aksi', orderable: false, searchable: false}
	        ],
	        createdRow: function(row, data, index) {
				$(row).attr('data-idjurnallain', data['id']);
				$('td', row).eq(3).attr('align','right'); // 6 is index of column
				$('td', row).eq(4).attr('align','right'); // 6 is index of column
                    
            },
		});
	}

	function btnDeleteJurnallain(this_) {
		var id_jurnallain = this_.parents("tr").data("idjurnallain");
		
		swal({
			title: 'Anda yakin akan menghapus data ini?',
			text : 'Menghapus data akan mempengaruhi transaksi Anda.',
			type: 'warning',
			showCancelButton: true,
			confirmButtonColor: '#d33',
			cancelButtonColor: '#3085d6',
			confirmButtonText: 'Hapus',
			cancelButtonText: 'Batal',
		}).then((result) => {
			
		 	if(result.value){
		 		$.ajax({
					url: "{{ url('jurnal_lain/hapus_jurnal_lain')}} ",
					type: 'post',
					data: {id : id_jurnallain},
					headers : {
						'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
					},
					success: function(respon){
						location.reload();
					}
				})
		 	}
		})
	}

</script>

@endsection