@extends('layout')

@section('js_script')
	<script src="{{ url("js/plugins/tables/datatables/extensions/buttons.min.js")}}"></script>
	<script src="{{ url("js/plugins/tables/datatables/extensions/pdfmake/pdfmake.min.js")}}"></script>
	<script src="{{ url("js/plugins/tables/datatables/extensions/pdfmake/vfs_fonts.min.min.js")}}"></script>
@endsection

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

<div class="content">
	<div class="panel panel-flat">
		<div class="panel-heading">
			<h5 class="panel-title">Jurnal</h5>
	    </div>
	    <div class="panel-body">
	    	<div class="row">
	    		<div class="col-sm-8 col-md-8">
			    	<form class="form" method="get" action="#" id="form-filter-jurnal">
			    		<div class="form-group">
			    			{{ Form::label("Tanggal", "", ['class'=>'control-label col-sm-2 col-md-2']) }}
			    			<div class="col-sm-3 col-md-3" >
				    			{{ Form::text("tanggal_awal", date("d-m-Y"), ['class'=>'form-control set_datepicker','id'=>'tanggal_awal']) }}
				    		</div>
			    			<div class="col-sm-3 col-md-3" >
				    			{{ Form::text("tanggal_akhir", date("d-m-Y"), ['class'=>'form-control set_datepicker','id'=>'tanggal_akhir']) }}
				    		</div>
			    			<div class="col-sm-2 col-md-2" >
				    			{{ Form::submit("Filter", ['class'=>'btn btn-sm btn-info']) }}
				    		</div>
				    		<div class="col-sm-2 col-md-2">
				    			<a href="javascript:void(0)" id="btn_excel" class="btn btn-sm btn-success"><i class="fa fa-file-excel-o"></i> Excel</a>
				    		</div>
				    		
			    		</div>
			    	</form>	
	    		</div>

	    		<div class="col-sm-4 col-md-4">
			    	<form class="form" action="#">
			    		<div class="form-group">
			    			<div class="col-sm-12 col-md-12 text-right">
							
							</div>
						</div>
					</form>
	    		</div>
	    		
	    		<div class="col-sm-12 col-md-12" style="margin-top: 2%;" id="div-tabel-jurnal">
	    		<div class="table-responsive">	
	    			<table class="table" id="tabel-jurnal">
	    				<thead>
	    					<tr>
	    						<th>Tanggal</th>
	    						<th>Kode</th>
	    						<th>Nama Perkiraan</th>
	    						<th>Debet</th>
	    						<th>Kredit</th>
	    					</tr>
	    				</thead>
	    				<tbody>
	    					@php
	    						$grand_total = ['D'=>0, 'K'=>0];
	    					@endphp

	    					@if(sizeOf($jurnal_umum) > 0)

	    						@foreach($jurnal_umum AS $key => $value)
	    							<tr style="background-color: #F5F5F5;">
	    								<th colspan="5">{{ "#".preg_replace('/["|"]/', ' | ', $key) }}</th>
	    								<th style="display: none;">&nbsp;</th>
	    								<th style="display: none;">&nbsp;</th>
	    								<th style="display: none;">&nbsp;</th>
	    								<th style="display: none;">&nbsp;</th>
	    							</tr>
	    							@php
	    								$sub_total = ['D'=>0, 'K'=>0];
	    							@endphp
	    							@foreach($value AS $id => $val)
		    							@php
		    								$set_nominal = ['D'=>0, 'K'=>0];
		    								$set_nominal[ $val->tipe_transaksi ] = $val->nominal*$val->kurs_jual;
		    								$sub_total[ $val->tipe_transaksi ] += $val->nominal*$val->kurs_jual;
		    								$grand_total[ $val->tipe_transaksi ] += $val->nominal*$val->kurs_jual;
		    							@endphp
	    								<tr>
	    									<td>{{ $val->tanggal_ref }}</td>
	    									<td>{{ $val->kode_perkiraan }}</td>
	    									<td>
	    										{{ $val->nama_perkiraan }}
	    										<br><span style="font-size: 10px; color: #999; font-style: italic;">{{ $val->keterangan==''? '-':$val->keterangan }}</span>
	    									</td>
	    									<td class="text-right">{{ number_format($set_nominal['D'], 2, ',', '.') }}</td>
	    									<td class="text-right">{{ number_format($set_nominal['K'], 2, ',', '.') }}</td>
	    								</tr>
	    							@endforeach
	    							@php
	    							$class = "";
	    							if($sub_total['D']!=$sub_total['K']) $class = "bg-danger";
	    							@endphp
	    							<tr class="{{$class}}">
	    								<td colspan="3" class="text-right">Sub Total</td>
	    								<th style="display: none;">&nbsp;</th>
	    								<th style="display: none;">&nbsp;</th>
			    						<td class="text-right">{{ number_format($sub_total['D'], 2, ',', '.') }}</td>
			    						<td class="text-right">{{ number_format($sub_total['K'], 2, ',', '.') }}</td>
	    							</tr>

	    						@endforeach

	    					@endif
	    				</tbody>
	    				<tfoot>
	    					<tr style="background-color: #F5F5F5;">
	    						<th colspan="3" class="text-right">Grand Total</th>
	    						<th class="text-right">{{ number_format($grand_total['D'], 2, ',', '.') }}</th>
	    						<th class="text-right">{{ number_format($grand_total['K'], 2, ',', '.') }}</th>
	    					</tr>
	    				</tfoot>
	    			</table>
	    		</div>

	    		</div>

	    	</div> <!-- end : row -->

	    </div>
	</div>
</div>

<script type="text/javascript">
	var base_url = "{{ url('/') }}";
$(document).ready(function(){
	$(".set_datepicker").datepicker({
		format : "dd-mm-yyyy",
		autoclose : true,
      	zIndexOffset : 9999,
	});

	$('#tabel-jurnal').DataTable({
		filter : false,
		ordering : false,
		paging : false,
	});

	$("#btn_excel").click(function(evt){
		window.open(base_url+'laporan/jurnal_umum/excel?tanggal_awal='+$("#tanggal_awal").val()+'&tanggal_akhir='+$("#tanggal_awal").val());
	})
});
</script>

@endsection