@extends ('layouts/template')

@section('content')

    <div class="p-3 mcp-theme-1" id="processing-bill-matrix">

        <div class="card">

            <div class="card-header px-3 py-2">
                <div class="font-weight-bold text-nowrap mb-2">
                    <i class="fas fa-user"></i>
                    Bills Under Processing
                </div>
            </div>
            <div class="card-body p-0">
                <table class="table table-sm table-condensed table-hover p-0 m-0">
                    <thead class="bg-light">
                    <tr>
                        <th class="border-bottom-0 border-top-0 pl-3">Context</th>
                        <th class="border-bottom-0 border-top-0">Effective Date</th>
                        <th class="border-bottom-0 border-top-0">Role</th>
                        <th class="border-bottom-0 border-top-0">Client</th>
                        <th class="border-bottom-0 border-top-0">Code</th>
                        <th class="border-bottom-0 border-top-0">Context</th>
                        <th class="border-bottom-0 border-top-0">Units</th>
                        <th class="border-bottom-0 border-top-0">Verified?</th>
                        <th class="border-bottom-0 border-top-0">Expected Amount</th>
                    </tr>
                    </thead>
                    <tbody>
                    @foreach ($bills as $row)
                        <?php
                        $role = '';
                        $amount = 0;
                        if($row->hcp_pro_id === $pro->id) {
                            $role = 'HCP';
                            $amount = $row->hcp_expected_payment_amount;
                        }
                        elseif($row->cm_pro_id === $pro->id) {
                            $role = 'CM';
                            $amount = $row->cm_expected_payment_amount;
                        }
                        elseif($row->rme_pro_id === $pro->id) {
                            $role = 'RME';
                            $amount = $row->rme_expected_payment_amount;
                        }
                        elseif($row->rmm_pro_id === $pro->id) {
                            $role = 'RMM';
                            $amount = $row->rmm_expected_payment_amount;
                        }
                        elseif($row->generic_pro_id === $pro->id) {
                            $role = 'GENERIC';
                            $amount = $row->generic_pro_expected_payment_amount;
                        }
                        ?>
                        <tr>
                            <td class="pl-3">
                                @if($row->note)
                                    <a href="/patients/view/{{ $row->client->uid }}/notes/view/{{ $row->note->uid }}">
                                        Note Link
                                    </a>
                                @elseif($row->client)
                                    <a href="/patients/view/{{ $row->client->uid }}">
                                        Chart
                                    </a>
                                @else
                                    Admin.
                                @endif
                            </td>
                            <td>{{friendly_date($row->effective_date)}}</td>
                            <td>{{$role}}</td>
                            <td>
                                @if($row->client)
                                    {{$row->client->name_last}}, {{$row->client->name_first}}
                                @endif
                            </td>
                            <td>{{$row->code}}</td>
                            <td>
                                @if($row->generic_target_entity_type)
                                    {{$row->generic_target_entity_type}}
                                @endif
                            </td>
                            <td>{{str_contains($row->code, 'Treatment Services') || str_contains($row->code, 'Administrative Services') ? ceil((float) $row->number_of_units * 60) . ' mins' : $row->number_of_units}}</td>
                            <td>{!! $row->is_verified ? 'Yes<br>' . friendly_date($row->marked_verified_at, true) : 'No' !!} </td>
                            <td>
                                {{number_format($amount, 2)}}
                            </td>
                        </tr>
                    @endforeach
                    </tbody>
                </table>
            </div>
        </div>
        <div class="mt-3">
            {{$bills->withQueryString()->links()}}
        </div>
    </div>
@endsection
