@extends('layouts.app')
@section('title', __('medaccounting::lang.general_ledger'))
@section('content')
<section class="content-header"><h1>@lang('medaccounting::lang.general_ledger')</h1></section>
<section class="content">
    @php
        $accountSelect = '<div class="form-group"><label>' . __('medaccounting::lang.account') . '</label> '
            . '<select name="account_id" class="form-control input-sm"><option value="">' . __('medaccounting::lang.select_account') . '</option>';
        foreach ($accounts as $id => $label) {
            $accountSelect .= '<option value="' . $id . '" ' . ((int) $accountId === (int) $id ? 'selected' : '') . '>' . e($label) . '</option>';
        }
        $accountSelect .= '</select></div> ';
    @endphp
    @include('medaccounting::reports.partials.filter', [
        'action' => route('medacc.reports.general_ledger'),
        'extraSelect' => $accountSelect,
    ])

    @if($account)
    @component('components.widget', ['class' => 'box-primary', 'title' => $account->code . ' — ' . $account->name])
        <p>
            <strong>@lang('medaccounting::lang.opening_balance'):</strong> {{ number_format($opening, 2) }}
            &nbsp;|&nbsp;
            <strong>@lang('medaccounting::lang.closing_balance'):</strong> {{ number_format($closing, 2) }}
        </p>
        <table class="table table-bordered table-striped">
            <thead><tr>
                <th>@lang('medaccounting::lang.date')</th>
                <th>@lang('medaccounting::lang.entry_no')</th>
                <th>@lang('medaccounting::lang.description')</th>
                <th class="text-right">@lang('medaccounting::lang.debit')</th>
                <th class="text-right">@lang('medaccounting::lang.credit')</th>
                <th class="text-right">@lang('medaccounting::lang.running_balance')</th>
            </tr></thead>
            <tbody>
            @forelse($lines as $l)
                <tr>
                    <td>{{ \Carbon\Carbon::parse($l->date)->format('Y-m-d') }}</td>
                    <td>{{ $l->entry_no }}</td>
                    <td>{{ $l->line_desc ?: $l->je_desc }}</td>
                    <td class="text-right">{{ (float) $l->debit > 0 ? number_format($l->debit, 2) : '' }}</td>
                    <td class="text-right">{{ (float) $l->credit > 0 ? number_format($l->credit, 2) : '' }}</td>
                    <td class="text-right">{{ number_format($l->running, 2) }}</td>
                </tr>
            @empty
                <tr><td colspan="6" class="text-center text-muted">@lang('medaccounting::lang.no_data')</td></tr>
            @endforelse
            </tbody>
        </table>
    @endcomponent
    @else
        <p class="text-muted">@lang('medaccounting::lang.select_account')</p>
    @endif
</section>
@endsection
