@extends ('layouts/template')

@section('content')
    <div class="p-3 mcp-theme-1">
        <div class="card">
            <div class="card-header p-3 d-flex align-items-center">
                <strong class="mr-4">
                    <i class="fas fa-user-injured"></i>
                    Financial Transactions
                </strong>
                <div class="ml-auto">
                    <span class="">
                        <strong>Current Balance:</strong> ${{ $pro->balance }}
                    </span>&nbsp;
                    <span>
                        <?php $lastPayment = $pro->lastPayment(); ?>
                        <strong>Last Payment:</strong>
                        {{ $lastPayment ? '$' . $lastPayment->amount . ' (' . friendly_date_time($lastPayment->created_at, false) . ')' : '-' }}
                    </span>
                </div>
            </div>
            <div class="card-body p-0">
                <table class="table table-sm table-condensed p-0 m-0" style="table-layout: fixed">
                    <thead class="bg-light">
                        <tr>
                            <th class="px-3 border-0">Date</th>
                            <th class="border-0">Type</th>
                            <th class="border-0">Client</th>
                            <th class="border-0">Note</th>
                            {{--<th class="border-0">Reason</th>--}}
                            <th class="border-0">Memo</th>
                            <th class="border-0">Amount</th>
                            <th class="border-0">Balance</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($transactions as $transaction)
                            <tr>
                                <td class="px-3">
                                    {{ friendly_date_time($transaction->created_at, true) }}
                                </td>
                                <td>
                                    {{ $transaction->plus_or_minus === 'PLUS' ? 'Credit' : 'Debit' }}
                                </td>
                                <td>
                                    @if($transaction->client)
                                    <a href="/patients/view/{{ $transaction->client->uid }}">
                                        <b>{{ implode(", ", [$transaction->client->name_last, $transaction->client->name_first]) }}</b>
                                    </a>
                                    @else
                                        -
                                    @endif
                                </td>
                                <td>
                                    @if($transaction->bill && $transaction->bill->note)
                                        @if($transaction->bill->note->noteTemplate)
                                            {{ $transaction->bill->note->noteTemplate->title }}
                                        @endif
                                        <a href="{{route('patients.view.notes.view.dashboard', ['patient'=>$transaction->client, 'note'=>$transaction->bill->note])}}">Go to note</a>
                                    @endif
                                </td>
                                {{--<td>
                                    <a href="/patients/view/{{ $transaction->client->uid }}/care-months/view/{{ $transaction->bill->careMonth->uid }}">
                                        <b>{{ friendly_month($transaction->bill->careMonth->start_date) }}</b>
                                    </a>
                                </td>
                                <td>
                                    <b>{{ $transaction->bill->code }}</b>
                                    <div class="text-secondary text-sm">Created: {{ friendly_date_time($transaction->bill->created_at, true) }}</div>
                                </td>--}}
                                {{--<td class="stag-no-wrap-td">
                                    @if($transaction->bill)
                                        @if($transaction->bill->careMonth)
                                            <b>{{ $transaction->bill->code }}</b>
                                            -
                                            <a href="/patients/view/{{ $transaction->client->uid }}/care-months/view/{{ $transaction->bill->careMonth->uid }}">
                                                <b>{{ friendly_month($transaction->bill->careMonth->start_date) }}</b>
                                            </a>
                                        @elseif($transaction->bill->note)
                                            <b>{{ $transaction->bill->code }}</b>
                                            -
                                            <a href="/patients/view/{{ $transaction->client->uid }}/notes/view/{{ $transaction->bill->note->uid }}">
                                                <b>Note</b>
                                            </a>
                                        @endif
                                        @if(!empty($transaction->bill->reason1))
                                        <div class="text-secondary text-sm stag-no-wrap" title="{{ $transaction->bill->reason1 }}">{{ $transaction->bill->reason1 }}</div>
                                        @endif
                                    @else
                                        -
                                    @endif
                                </td>--}}
                                <td>{{ $transaction->custom_memo ? $transaction->custom_memo : '-' }}</td>
                                <td>${{ $transaction->amount }}</td>
                                <td>${{ $transaction->resulting_balance }}</td>
                            </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>
        </div>
    </div>
@endsection
