@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="4" style="text-align: center; font-weight: bold;">CV. KETJUBUNG</td>
		</tr>
		<tr>
			<td colspan="4" style="text-align: center; font-weight: normal; font-style: italic;">Neraca Saldo</td>
		</tr>
		<tr>
			<td colspan="4" style="text-align: center; font-weight: normal; font-style: italic;">Periode : {{ $periode }}</td>
		</tr>
	</thead>
</table>

<table border="1">
	<tbody>
		<tr>
			<th style="text-align: center;">Kode Akun</th>
            <th style="text-align: center;">Nama Akun</th>
            <th style="text-align: center;">Debet</th>
            <th style="text-align: center;">Kredit</th>
		</tr>
		@php
			$total_debet = 0;
			$total_kredit = 0;
		@endphp
		@if(sizeOf($neraca_saldo) > 0)
			@foreach($neraca_saldo AS $key => $value)
				@php
					$total_debet += $value['D'];
					$total_kredit += $value['K'];
				@endphp
				<tr>
					<td style="text-align: left;">{{ $value['kode_perkiraan'] }}</td>
					<td>{{ $value['nama_perkiraan'] }}</td>
					<td style="text-align: right;">{{ isNegative($value['D']) }}</td>
					<td style="text-align: right;">{{ isNegative($value['K']) }}</td>
				</tr>
			@endforeach
			<tr>
				<td colspan="2" style="text-align: center; font-weight: bold;">Total</td>
				<td style="text-align: right;">{{ isNegative($total_debet) }}</td>
				<td style="text-align: right;">{{ isNegative($total_kredit) }}</td>
			</tr>
		@endif
	</tbody>
</table>