@extends('layouts.app')
@section('title',$statement==='profit-loss'?'Profit & Loss':'Balance Sheet')
@section('content')
<div class="page-head"><div><h1>{{ $statement==='profit-loss'?'Profit & loss':'Balance sheet' }}</h1><p>Generated directly from posted journal entries.</p></div><form><div class="input-group input-group-sm"><input type="date" name="date_to" class="form-control" value="{{ request('date_to',now()->toDateString()) }}"><button class="btn btn-dark">Run</button></div></form></div><div class="card-erp"><div class="table-responsive"><table class="table table-dense"><thead><tr><th>Code</th><th>Account</th><th>Type</th><th class="text-end">Balance</th></tr></thead><tbody>@php $net=0; @endphp @foreach($accounts as $a) @php $raw=(float)($a->debit_total??0)-(float)($a->credit_total??0);$balance=in_array($a->type,['liability','equity','income'])?-$raw:$raw;$net+=$statement==='profit-loss'&&$a->type==='income'?-abs($balance):$balance; @endphp @if(abs($balance)>.004)<tr><td>{{ $a->code }}</td><td>{{ $a->name_en }}<small class="d-block text-muted" dir="rtl">{{ $a->name_ar }}</small></td><td>{{ strtoupper($a->type) }}</td><td class="text-end fw-bold">{{ number_format(abs($balance),2) }}</td></tr>@endif @endforeach</tbody><tfoot><tr><th colspan="3" class="text-end">{{ $statement==='profit-loss'?'NET RESULT':'NET BALANCE' }}</th><th class="text-end">SAR {{ number_format(abs($net),2) }}</th></tr></tfoot></table></div></div>
@endsection
