@php
	function isNegative($number) {
		if ($number < 0) {
			return "(".currency(abs($number)).")";
		} else {
			return currency($number);
		}
	}

	function currency($number) {
		return number_format($number, 2, ',', '.');
	}
@endphp
<table>
	<thead>
		<tr>
			<td colspan="5" style="text-align: center; font-weight: bold;">CV. KETJUBUNG</td>
		</tr>
		<tr>
			<td colspan="5" style="text-align: center; font-weight: normal; font-style: italic;">Jurnal Umum</td>
		</tr>
		<tr>
			<td colspan="5" style="text-align: center; font-weight: normal; font-style: italic;">Periode : {{ $periode }}</td>
		</tr>
	</thead>
</table>

<table border="1">
	<thead>
		<tr>
			<th>Tanggal</th>
            <th>Akun</th>
            <th>Keterangan</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>
					<td colspan="5" style="text-align: center;">{{ "#".preg_replace('/["|"]/', ' | ', $key) }}</td>
				</tr>
				@php
					$sub_total = ['D'=>0, 'K'=>0];
				@endphp
				@foreach($value['detail'] 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>{{ date_db($val->tanggal_ref, true, 2) }}</td>
						<td>{{ $val->kode_perkiraan }}</td>
						<td>
							{{ $val->nama_perkiraan }} {{ $val->keterangan==''? '':"(".$val->keterangan.")" }}
						</td>
						<td style="text-align: right;">{{ isNegative($set_nominal['D']) }}</td>
						<td style="text-align: right;">{{ isNegative($set_nominal['K']) }}</td>
					</tr>
				@endforeach
				<tr>
					<td colspan="3" style="text-align: right;">Sub Total</td>
					<td style="text-align: right;">{{ isNegative($sub_total['D']) }}</td>
					<td style="text-align: right;">{{ isNegative($sub_total['K']) }}</td>
				</tr>
			@endforeach

		@endif
	</tbody>
</table>