@extends ('layouts/template')

@section('content')

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

        <div class="card-header px-3 py-2 d-flex align-items-center">
            <strong class="mr-4">
                <i class="fas fa-user-injured"></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-condensed 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 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="">
                            <a href="/patients/view/{{ $bill->client->uid }}">{{ $bill->client->displayName() }}</a>
                        </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>
                            <?php
                            $roles = [];
                            if($bill->hcp_pro_id === $pro->id) $roles[] = 'HCP';
                            if($bill->cm_pro_id === $pro->id) $roles[] = 'CM';
                            if($bill->rme_pro_id === $pro->id) $roles[] = 'RME';
                            if($bill->rmm_pro_id === $pro->id) $roles[] = 'RMM';
                            $roles = implode("<br>", $roles);
                            ?>
                            {!! $roles !!}
                        </td>
                        <td>
                            @if($bill->hcp_pro_id === $pro->id)
                                @if($bill->has_hcp_been_paid)
                                    <div>
                                        <span class="text-dark">HCP Received:</span>
                                        <span class="font-weight-bold text-success ml-2">${{ $bill->hcp_payment_amount }}</span>
                                    </div>
                                @else
                                    <div>
                                        <span class="text-dark">HCP Expected:</span>
                                        <span class="font-weight-bold text-dark ml-2">{{ $bill->hcp_expected_payment_amount ? '$' . $bill->hcp_expected_payment_amount : '-' }}</span>
                                    </div>
                                @endif
                            @endif
                            @if($bill->cm_pro_id === $pro->id)
                                @if($bill->has_cm_been_paid)
                                    <div>
                                        <span class="text-dark">CM Received:</span>
                                        <span class="font-weight-bold text-success ml-2">${{ $bill->cm_payment_amount }}</span>
                                    </div>
                                @else
                                    <div>
                                        <span class="text-dark">CM Expected:</span>
                                        <span class="font-weight-bold text-dark ml-2">{{ $bill->cm_expected_payment_amount ? '$' . $bill->cm_expected_payment_amount : '-' }}</span>
                                    </div>
                                @endif
                            @endif
                            @if($bill->rmm_pro_id === $pro->id)
                                @if($bill->has_rmm_been_paid)
                                    <div>
                                        <span class="text-dark">RMM Received:</span>
                                        <span class="font-weight-bold text-success ml-2">${{ $bill->rmm_payment_amount }}</span>
                                    </div>
                                @else
                                    <div>
                                        <span class="text-dark">RMM Expected:</span>
                                        <span class="font-weight-bold text-dark ml-2">{{ $bill->rmm_expected_payment_amount ? '$' . $bill->rmm_expected_payment_amount : '-' }}</span>
                                    </div>
                                @endif
                            @endif
                            @if($bill->rme_pro_id === $pro->id)
                                @if($bill->has_rme_been_paid)
                                    <div>
                                        <span class="text-dark">RME Received:</span>
                                        <span class="font-weight-bold text-success ml-2">${{ $bill->rme_payment_amount }}</span>
                                    </div>
                                @else
                                    <div>
                                        <span class="text-dark">RME Expected:</span>
                                        <span class="font-weight-bold text-dark ml-2">{{ $bill->rme_expected_payment_amount ? '$' . $bill->rme_expected_payment_amount : '-' }}</span>
                                    </div>
                                @endif
                            @endif
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
        </div>
    </div>
    </div>

@endsection
