@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>
                RM Bills to Sign
            </strong>
            @if($pro->is_hcp && $bills && count($bills))
            <div moe="" relative class="ml-auto">
                <a class="font-weight-bold" href="#" show start>Sign All Bills</a>
                <form url="/api/bill/signAllPendingForRM" right>
                    <p>Sign all bills?</p>
                    <div class="mb-0">
                        <button class="btn btn-success btn-sm" submit="">Sign</button>
                        <button class="btn btn-default border btn-sm" cancel="">Cancel</button>
                    </div>
                </form>
            </div>
            @endif
        </div>
        <div class="card-body p-0">

            <table class="table table-sm table-striped table-hover p-0 m-0">
                <thead class="bg-light">
                <tr>
                    <th class="px-3 border-0">Eff. Date</th>
                    <th class="border-0">Patient</th>
                    <th class="border-0">Context</th>
                    <th class="border-0">Measurement Days</th>
                    <th class="border-0">Role</th>
                    <th class="border-0">Amount</th>
                    <th class="border-0"></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->effective_date, false) }}
                        </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="/practice-management/remote-monitoring?m={{month_part_from_date($bill->careMonth->start_date)}}&y={{year_part_from_date($bill->careMonth->start_date)}}&c={{$bill->client->uid}}">
                                    <b>{{ friendly_month($bill->careMonth->start_date) }}</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 class="">
                            <span class="d-inline-block width-30px">{{$bill->careMonth->number_of_days_with_remote_measurements ?: '0'}}</span>
                            <span class="">
                                <?php $moreMDNeeded = 16 - $bill->careMonth->number_of_days_with_remote_measurements; ?>
                                </span>
                        </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>
                        <td>
                            <div moe="" relative>
                                <a class="" href="#" show="" start="">Sign Bill</a>
                                <form url="/api/bill/signGlobal" right="">
                                    <input type="hidden" name="uid" value="{{$bill->uid}}">
                                    <p>Sign this bill?</p>
                                    <div class="mb-0">
                                        <button class="btn btn-success btn-sm" submit="">Sign</button>
                                        <button class="btn btn-default border btn-sm" cancel="">Cancel</button>
                                    </div>
                                </form>
                            </div>
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
        </div>
    </div>
    </div>

@endsection
