@extends ('layouts/template')

@section('content')

    <div class="p-3 mcp-theme-1">
    <div class="card">

        <div class="card-header px-2 py-1 d-flex align-items-center">
            <strong class="mr-4">
                <i class="fas fa-user"></i>
                Bills
            </strong>
            <select class="ml-auto max-width-300px form-control form-control-sm" onchange="fastLoad('/practice-management/bills/' + this.value, true, false, false)">
                <option value="" {{ $filter === '' ? 'selected' : '' }}>All bills</option>
                <option value="not-yet-signed" {{ $filter === 'not-yet-signed' ? 'selected' : '' }}>Bills not yet signed</option>
                <option value="previous" {{ $filter === 'previous' ? 'selected' : '' }}>Previous Bills (signed)</option>
            </select>
        </div>
        <div class="card-body p-0">

            <table class="table table-sm table-striped p-0 m-0">
                <thead class="bg-light">
                <tr>
                    <th class="px-3 border-0">Created</th>
                    <th class="border-0">Patient</th>
                    <th class="border-0">Pro</th>
                    <th class="border-0 w-50">Context</th>
                    <th class="border-0">Role</th>
                    <th class="border-0">Amount</th>
                </tr>
                </thead>
                <tbody>
                @foreach ($bills as $bill)
                    <tr class="{{ $bill->is_cancelled ? 'cancelled-item always-clickable' : '' }}">
                        <td class="px-3">
                            {{ friendly_date_time($bill->created_at, true) }}
                        </td>
                        <td class="">
                            @if($bill->client)
                            <a href="/patients/view/{{ $bill->client->uid }}">{{ $bill->client->displayName() }}</a>
                            @endif
                        </td>
                        <td class="">
                            @if($bill->hcp)
                                {{ $bill->hcp->displayName() }}
                            @elseif($bill->genericPro)
                                {{ $bill->genericPro->displayName() }}
                            @endif
                        </td>
                        <td class="stag-no-wrap-td">
                            @if($bill->careMonth)
                                <b>{{ $bill->code }}</b>
                                -
                                <a href="/patients/view/{{ $bill->client->uid }}/care-months/view/{{ $bill->careMonth->uid }}">
                                    <b>{{ friendly_month($bill->careMonth->start_date) }}</b>
                                </a>
                            @elseif($bill->note)
                                <b>{{ $bill->code }}</b>
                                -
                                <a href="/patients/view/{{ $bill->client->uid }}/notes/view/{{ $bill->note->uid }}">
                                    <b>Note</b>
                                </a>
                            @endif
                            @if(!empty($bill->reason1))
                                <div class="text-secondary text-sm stag-no-wrap" title="{{ $bill->reason1 }}">{{ $bill->reason1 }}</div>
                            @endif
                        </td>
                        <td>
                            @if($bill->hcp)
                                HCP
                            @elseif($bill->genericPro)
                                GENERIC
                            @endif
                        </td>
                        <td>
                            @if($bill->hcp_pro_id && ($pro->pro_type === 'ADMIN' || $bill->hcp_pro_id === $pro->id))
                                @if($bill->has_hcp_been_paid)
                                    <div>
                                        <span class="text-dark">Received:</span>
                                        <span class="font-weight-bold text-success ml-2">${{ friendly_money($bill->hcp_payment_amount) }}</span>
                                    </div>
                                @else
                                    <div>
                                        <span class="text-dark">Expected:</span>
                                        <span class="font-weight-bold text-dark ml-2">{{ $bill->hcp_expected_payment_amount ? '$' . friendly_money($bill->hcp_expected_payment_amount) : '-' }}</span>
                                    </div>
                                @endif
                            @endif
                            @if($bill->generic_pro_id && ($pro->pro_type === 'ADMIN' || $bill->generic_pro_id === $pro->id))
                                @if($bill->has_generic_pro_been_paid)
                                    <div>
                                        <span class="text-dark">Received:</span>
                                        <span class="font-weight-bold text-success ml-2">${{ friendly_money($bill->generic_pro_payment_amount) }}</span>
                                    </div>
                                @else
                                    <div>
                                        <span class="text-dark">Expected:</span>
                                        <span class="font-weight-bold text-dark ml-2">{{ $bill->generic_pro_expected_payment_amount ? '$' . friendly_money($bill->generic_pro_expected_payment_amount) : '-' }}</span>
                                    </div>
                                @endif
                            @endif
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>

            <div class="mx-3 mt-3">
                {{$bills->withQueryString()->links()}}
            </div>
        </div>
    </div>
    </div>

@endsection
