<?php
/** @var App\Models\CareMonth $careMonth */
/** @var App\Models\Pro $pro */
?>
@extends ('layouts.patient')

@section('inner-content')

    <?php
    $shortCutsObject = [];
    foreach ($pro->allShortcuts() as $shortcut) {

        // %replaceables%
        $shortcut->text = str_replace("%AGE%", $patient->age_in_years, $shortcut->text);
        $shortcut->text = str_replace("%GENDER%", $patient->sex, $shortcut->text);
        $shortcut->text = str_replace("%NAME%", $patient->displayName(), $shortcut->text);

        $shortCutsObject[] = [
            "name" => $shortcut->shortcut,
            "value" => $shortcut->text
        ];
    }
    ?>
    <script>window.userShortcuts = <?= json_encode($shortCutsObject); ?>;</script>

    @if($patient->has_mcp_done_onboarding_visit !== 'YES')
        <div class="pt-2 d-flex align-items-start">
            <h6 class="my-0 text-secondary d-flex align-items-start">
                <a href="/patients/view/{{ $patient->uid }}/care-months" class="small text-decoration-none mr-3">
                    <i class="fa fa-chevron-left"></i>
                </a>
                <div>
                    <div>
                        <span class="text-dark font-weight-bold">Care Month</span>&nbsp;for&nbsp;<span class="text-dark font-weight-bold">{{friendly_month($careMonth->start_date)}}</span>
                    </div>
                    <div class="text-dark d-inline-flex align-items-center mt-2">
                                    <span class="mr-2">
                                        <i class="fa fa-exclamation-triangle"></i>
                                        MCP Onboarding Visit Pending
                                    </span>
                        <div moe>
                            <a start show>Update</a>
                            <form url="/api/client/updateMcpOnboardingVisitInfo" class="mcp-theme-1">
                                <input type="hidden" name="uid" value="{{$patient->uid}}">
                                <div class="mb-2">
                                    <select name="hasMcpDoneOnboardingVisit"
                                            class="form-control form-control-sm"
                                            onchange="toggleDisabledAsNeeded(this, 'YES', 'if-visit-done')">
                                        <option value="">-- Select Status --</option>
                                        <option value="YES" {{ $patient->has_mcp_done_onboarding_visit === 'YES' ? 'selected' : '' }}>YES</option>
                                        <option value="NO" {{ $patient->has_mcp_done_onboarding_visit === 'NO' ? 'selected' : '' }}>NO</option>
                                        <option value="UNKNOWN" {{ $patient->has_mcp_done_onboarding_visit === 'UNKNOWN' ? 'selected' : '' }}>UNKNOWN</option>
                                    </select>
                                </div>
                                <div class="mb-2">
                                    <input type="date" class="if-visit-done form-control form-control-sm" disabled name="mcpOnboardingVisitDate" max="{{ date('Y-m-d') }}">
                                </div>
                                <div class="mb-2">
                                    <select name="mcpOnboardingVisitNoteUid" disabled
                                            class="form-control form-control-sm if-visit-done"
                                            onchange="toggleVisibilityAsNeeded(this, '', 'if-note-outside-system')">
                                        <option value="">-- Visit Note --</option>
                                        <?php $notes = \App\Models\Note::where('client_id', $patient->id)->get() ?>
                                        @foreach ($notes as $note)
                                            @if(!empty($note->title) && $note->client_id === $patient->id && !$note->is_cancelled)
                                                <option value="{{$note->uid}}">{{$note->title}}</option>
                                            @endif
                                        @endforeach
                                    </select>
                                </div>
                                <div class="mb-2 if-note-outside-system">
                                                <textarea class="form-control form-control-sm"
                                                          name="reasonOnboardingVisitNoteOutsideSystem"
                                                          placeholder="Visit note outside the system reason"></textarea>
                                </div>
                                <div>
                                    <button submit class="btn btn-sm btn-primary mr-1">Submit</button>
                                    <button cancel class="btn btn-sm btn-default border">Cancel</button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </h6>
        </div>
    @else

    <div id="care-month-container">
        <div class="pt-2 d-flex align-items-start">
            <h6 class="my-0 text-secondary d-flex align-items-start">
                <a href="/patients/view/{{ $patient->uid }}/care-months" class="small text-decoration-none mr-3">
                    <i class="fa fa-chevron-left"></i>
                </a>
                <div>
                    <div>
                        <span class="text-dark font-weight-bold font-size-14">Care Month</span>&nbsp;for&nbsp;<span class="text-dark font-weight-bold">{{friendly_month($careMonth->start_date)}}</span>
                    </div>
                    {{--@if(!$careMonth->is_tm_this_month)
                        <div moe class="mt-2">
                            <a start show>Mark as Transitional Month</a>
                            <form url="/api/careMonth/setIsTmThisMonthToTrue">
                                <input type="hidden" name="uid" value="{{ $careMonth->uid }}">
                                <p>Mark this care month as <b>Transitional Month</b>?</p>
                                <div class="d-flex align-items-center">
                                    <button class="btn btn-sm btn-primary mr-2" submit>Yes</button>
                                    <button class="btn btn-sm btn-default mr-2 border" cancel>No</button>
                                </div>
                            </form>
                        </div>
                    @endif--}}
                </div>
            </h6>
            {{--<div class="d-flex align-items-start ml-auto text-secondary">
                <div class="d-inline-flex align-items-start">
                    <div>
                        <div class="mr-3 text-sm-incl-children">
                            <span class="d-inline-block minutes-label">RMM</span>
                            <span class="font-weight-bold text-dark text-nowrap">
                                {{time_in_hrminsec($careMonth->rm_total_time_in_seconds_by_rmm_pro)}}
                            </span>
                        </div>
                        <div class="mr-3 text-sm-incl-children">
                            <span class="d-inline-block minutes-label">RME</span>
                            <span class="font-weight-bold text-dark text-nowrap">
                                {{time_in_hrminsec($careMonth->rm_total_time_in_seconds_by_rme_pro)}}
                            </span>
                        </div>
                        <div class="mr-3 text-sm-incl-children">
                            <span class="d-inline-block minutes-label">MCP</span>
                            <span class="font-weight-bold text-dark text-nowrap">
                                {{time_in_hrminsec($careMonth->rm_total_time_in_seconds_by_mcp)}}
                            </span>
                        </div>
                    </div>
                    <div class="ml-3 text-sm-incl-children">
                        <div class="">RM Total</div>
                        <div class="font-weight-bold text-dark text-nowrap">{{time_in_hrminsec($careMonth->rm_total_time_in_seconds)}}</div>
                    </div>
                </div>
                <div class="d-inline-flex align-items-start border-left pl-3 ml-3">
                    <div>
                        <div class="mr-3 text-sm-incl-children">
                            <span class="d-inline-block minutes-label">CM</span>
                            <span class="font-weight-bold text-dark text-nowrap">
                                {{time_in_hrminsec($careMonth->cm_total_time_in_seconds_by_cm_pro)}}
                            </span>
                        </div>
                        <div class="mr-3 text-sm-incl-children">
                            <span class="d-inline-block minutes-label">MCP</span>
                            <span class="font-weight-bold text-dark text-nowrap">
                                {{time_in_hrminsec($careMonth->cm_total_time_in_seconds_by_mcp)}}
                            </span>
                        </div>
                    </div>
                    <div class="ml-3 text-sm-incl-children">
                        <div class="">CM Total</div>
                        <div class="font-weight-bold text-dark text-nowrap">{{time_in_hrminsec($careMonth->cm_total_time_in_seconds)}}</div>
                    </div>
                </div>
            </div>--}}
        </div>

        <hr class="m-negator mb-0">

        <div class="row m-negator bg-light py-1 text-sm-incl-children">
            <div class="col-3 pl-3-5">
                <span class="text-secondary">MCP:</span>
                <span class="text-nowrap">{{ $careMonth->mcp ? $careMonth->mcp->displayName() : '-' }}</span>
            </div>
            <div class="col-3">
                <span class="text-secondary">RMM:</span>
                <span class="text-nowrap">{{ $careMonth->rmmPro ? $careMonth->rmmPro->displayName() : '-' }}</span>
            </div>
            <div class="col-3">
                <span class="text-secondary">RME:</span>
                <span class="text-nowrap">{{ $careMonth->rmePro ? $careMonth->rmePro->displayName() : '-' }}</span>
            </div>
            {{--<div class="col-3">
                <span class="text-secondary">CM:</span>
                <span class="text-nowrap">{{ $careMonth->cmPro ? $careMonth->cmPro->displayName() : '-' }}</span>
            </div>--}}
        </div>

        <hr class="m-negator mt-0">

        <?php
        $entries = $careMonth->entries;

        $cmBills = $careMonth->getBillsOfType('CM');
        $activeCMBill = false;
        $cancelledCMBills = new \Illuminate\Support\Collection();
        foreach ($cmBills as $cmBill) {
            if(!$cmBill->is_cancelled && $careMonth->cm_bill_id === $cmBill->id) {
                $activeCMBill = $cmBill;
            }
            else if($cmBill->is_cancelled) {
                $cancelledCMBills->add($cmBill);
            }
        }

        $rmBills = $careMonth->getBillsOfType('RM');
        $activeRMBill = false;
        $cancelledRMBills = new \Illuminate\Support\Collection();
        foreach ($rmBills as $rmBill) {
            if(!$rmBill->is_cancelled && $careMonth->rm_bill_id === $rmBill->id) {
                $activeRMBill = $rmBill;
            }
            else if($rmBill->is_cancelled) {
                $cancelledRMBills->add($rmBill);
            }
        }
        ?>

        <?php $vitalLabels = ['Ht. (in.)','Wt. (lbs.)','Temp. (F)','Pulse','Resp.','Pulse Ox.','SBP','DBP','Smoking Status', 'BMI']; ?>

        <div class="row mb-3">
            <div class="col-12">
                <div class="mt-0">
                    <div class="d-flex align-items-center mb-2">
                        <h6 class="my-0 font-weight-bold text-dark">Measurements</h6>
                        <span class="mx-2 text-secondary">|</span>
                        <div moe>
                            <a start show class="py-0 font-weight-normal">Add</a>
                            <form url="/api/measurement/create">
                                <input type="hidden" name="clientUid" value="{{ $patient->uid }}">
                                <div class="mb-2">
                                    <input required autofocus type="text" class="form-control form-control-sm" name="label" value="" placeholder="Type">
                                </div>
                                <div class="mb-2">
                                    <input required type="text" class="form-control form-control-sm" name="value" value="" placeholder="Value">
                                </div>
                                <div class="mb-2">
                                    <input required type="date" class="form-control form-control-sm" name="effectiveDate" max="{{ date('Y-m-d') }}" value="{{ date('Y-m-d') }}">
                                </div>
                                <div class="d-flex align-items-center">
                                    <button class="btn btn-sm btn-primary mr-2" submit>Save</button>
                                    <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                </div>
                            </form>
                        </div>
                        @if(0 && $pro->pro_type === 'ADMIN')
                            <span class="mx-2 text-secondary">|</span>
                            <div moe>
                                <a start show class="py-0 font-weight-normal text-secondary">+ BP BDT Measurement</a>
                                <form url="/api/bdtMeasurement/create">
                                    <div class="mb-2">
                                        <input autofocus type="text" class="form-control form-control-sm" name="imei" value="987987987983" placeholder="imei">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="ts" value="1600727786754" placeholder="ts">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="batteryVoltage" value="6308" placeholder="batteryVoltage">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="signalStrength" value="85" placeholder="signalStrength">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="valueTare" value="" placeholder="valueTare">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="valueWeight" value="" placeholder="valueWeight">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="valueSystolic" value="20700" placeholder="valueSystolic">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="valueDiastolic" value="9700" placeholder="valueDiastolic">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="valuePulse" value="64" placeholder="valuePulse">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="valueUnit" value="" placeholder="valueUnit">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="valueIrregular" value="0" placeholder="valueIrregular">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="rssi" value="71" placeholder="rssi">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="deviceId" value="86011204403081" placeholder="deviceId">
                                    </div>
                                    <input type="hidden" name="secret" value="LTZS20QAFE">
                                    <div class="d-flex align-items-center">
                                        <button class="btn btn-sm btn-primary mr-2" submit>Save</button>
                                        <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                    </div>
                                </form>
                            </div>
                            <span class="mx-2 text-secondary">|</span>
                            <div moe>
                                <a start show class="py-0 font-weight-normal text-secondary">+ Weight BDT Measurement</a>
                                <form url="/api/bdtMeasurement/create">
                                    <div class="mb-2">
                                        <input autofocus type="text" class="form-control form-control-sm" name="imei" value="987987987984" placeholder="imei">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="ts" value="1600727786754" placeholder="ts">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="batteryVoltage" value="6308" placeholder="batteryVoltage">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="signalStrength" value="85" placeholder="signalStrength">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="valueTare" value="0" placeholder="valueTare">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="valueWeight" value="61400" placeholder="valueWeight">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="valueSystolic" value="" placeholder="valueSystolic">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="valueDiastolic" value="" placeholder="valueDiastolic">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="valuePulse" value="" placeholder="valuePulse">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="valueUnit" value="1" placeholder="valueUnit">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="valueIrregular" value="" placeholder="valueIrregular">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="rssi" value="78" placeholder="rssi">
                                    </div>
                                    <div class="mb-2">
                                        <input type="text" class="form-control form-control-sm" name="deviceId" value="86528404866623" placeholder="deviceId">
                                    </div>
                                    <input type="hidden" name="secret" value="LTZS20QAFE">
                                    <div class="d-flex align-items-center">
                                        <button class="btn btn-sm btn-primary mr-2" submit>Save</button>
                                        <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                    </div>
                                </form>
                            </div>
                        @endif
                    </div>
                    <div class="row mb-3 d-none">
                        <div class="col-9">
                            <div id="caremonth-measurements-calendar">

                            </div>
                        </div>
                        <div class="col-3">
                            <span class="font-size-14">
                                Days with measurements: <b class="font-size-14 {{$careMonth->number_of_days_with_remote_measurements >= 16 ? 'text-success' : 'text-warning-mellow'}}">
                                    {{$careMonth->number_of_days_with_remote_measurements}}
                                    @if($careMonth->number_of_days_with_remote_measurements >= 16)
                                        <i class="fa fa-check font-size-13"></i>
                                    @else
                                        <i class="fa fa-exclamation-triangle font-size-13"></i>
                                    @endif
                                    <span class="ml-1 text-secondary text-sm font-weight-normal">(16 needed)</span>
                                </b>
                            </span>
                            @if($careMonth->number_of_days_with_remote_measurements < 16)
                                <div class="alert alert-warning p-2 mt-3">
                                    Need <b>{{16 - $careMonth->number_of_days_with_remote_measurements}} more days</b> with measurements before RM becomes billable.
                                </div>
                            @endif
                        </div>
                    </div>
                    <table class="table table-striped table-sm table-bordered mt-2 mb-0">
                        <thead>
                        <tr>
                            <th class="px-2 text-secondary">Effective Date</th>
                            <th class="px-2 text-secondary w-25">Category</th>
                            <th class="px-2 text-secondary w-25">Value</th>
                        </tr>
                        </thead>
                        <tbody>
                        @php
                            $measurementsInCareMonth = $patient->measurementsInCareMonth($careMonth);
                            $plottableMeasurements = [];
                        @endphp
                        @foreach($measurementsInCareMonth as $measurement)
                            @if(!empty($measurement->label) && !in_array($measurement->label, ["SBP", "DBP"]) && !$measurement->is_cellular_zero)
                                <tr>
                                    <td class="px-2">
                                        @if($measurement->ts)
                                            <?php $timestampInSec = floor($measurement->ts/1000); ?>
                                            {{ friendly_date_time_short_with_tz_from_timestamp($timestampInSec, 'EASTERN') }}
                                        @else
                                            {{ friendly_date_time_short_with_tz($measurement->effective_date, true, 'EASTERN') }}
                                        @endif
                                        EST
                                    </td>
                                    <td class="px-2">{{ $measurement->label }}</td>
                                    <td class="px-2">
                                        @if($measurement->is_cellular_zero)
                                            <i class="font-size-11 fa fa-rss"></i>
                                        @elseif($measurement->label === 'BP')
                                            {{ $measurement->sbp_mm_hg }}/{{ $measurement->dbp_mm_hg }} mmHg
                                        @elseif($measurement->label === 'Wt. (lbs.)')
                                            {{ round(floatval($measurement->numeric_value), 2) }} lbs
                                        @else
                                            {{ $measurement->value }}
                                        @endif
                                    </td>
                                </tr>

                                <?php
                                if ($measurement->ts) {
                                    $timestampInSec = floor($measurement->ts / 1000);
                                    $measurement->start = postgres_date_time_short_with_tz_from_timestamp($timestampInSec, 'EASTERN');
                                } else {
                                    $measurement->start = postgres_date_time_short_with_tz($measurement->effective_date, true, 'EASTERN');
                                }
                                $measurement->title = '';
                                if ($measurement->label === 'BP') {
                                    $measurement->title .= 'BP ' . $measurement->sbp_mm_hg . '/' . $measurement->dbp_mm_hg . ' mmHg';
                                } elseif ($measurement->label === 'Wt. (lbs.)') {
                                    $measurement->title .= 'Weight ' . round(floatval($measurement->numeric_value), 2) . ' lbs';
                                } else {
                                    $measurement->title .= $measurement->value;
                                }
                                $plottableMeasurements[] = $measurement;
                                ?>

                            @endif
                        @endforeach
                        @if(!$patient->measurements || !count($patient->measurements) === 0)
                            <tr>
                                <td class="text-secondary p-0 border-0">
                                    No items to show
                                </td>
                            </tr>
                        @endif
                        </tbody>
                    </table>
                </div>
            </div>
        </div>

        {{-- BDT Measurements --}}
        {{-- <hr class="m-negator mt-4 mb-3">

        <div class="row mb-3">
            <div class="col-12">
                <div class="d-flex align-items-center">
                    <h6 class="my-0 text-secondary font-weight-bold text-dark lh-24px">Cellular Measurements</h6>
                </div>
                <table class="table table-striped table-sm table-bordered mt-2 mb-0">
                    @if($patient->measurements && count($patient->measurements))
                        <thead>
                        <tr>
                            <th class="px-2 text-secondary">Created</th>
                            <th class="px-2 text-secondary w-25">Category</th>
                            <th class="px-2 text-secondary w-25">Value</th>
                            <th class="px-2 text-secondary">Status</th>
                            <th class="px-2 text-secondary">Memo</th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach($patient->deviceMeasurements as $measurement)
                            <tr>
                                <td class="px-2">{{ friendly_date_time($measurement->created_at) }}</td>
                                <td class="px-2">{{ $measurement->measurement->device_category }}</td>
                                <td class="px-2">
                                    @if($measurement->measurement->device_category === 'WEIGHT')
                                        <b>{{ round($measurement->measurement->value_weight / 1000, 1) }} Kg</b>
                                    @elseif($measurement->measurement->device_category === 'BP')
                                        <b>{{ $measurement->measurement->systolic_bp_in_mm_hg }}/{{ $measurement->measurement->diastolic_bp_in_mm_hg }} mmHg</b>
                                    @endif
                                </td>
                                <td class="px-2">
                                    <span>
                                        <span>{{ $measurement->status }}</span>
                                        <span moe class="ml-2" relative>
                                            <a href="#" start show><i class="fa fa-edit text-primary"></i></a>
                                            <form url="/api/clientBdtMeasurement/updateStatus" right>
                                                <input type="hidden" name="uid" value="{{ $measurement->uid }}">
                                                <div class="mb-2">
                                                    <select name="status" class="form-control form-control-sm" required>
                                                        <option value="">-- select --</option>
                                                        <option {{$measurement->status === 'NEW' ? 'selected' : ''  }} value="NEW">NEW</option>
                                                        <option {{$measurement->status === 'ACCEPTED' ? 'selected' : ''  }} value="ACCEPTED">ACCEPTED</option>
                                                        <option {{$measurement->status === 'REJECTED' ? 'selected' : ''  }} value="REJECTED">REJECTED</option>
                                                    </select>
                                                </div>
                                                <div class="mb-2">
                                                    <input type="text" name="statusMemo" placeholder="Status memo" class="form-control form-control-sm">
                                                </div>
                                                <div class="d-flex align-items-center">
                                                    <button class="btn btn-sm btn-primary mr-2" submit>Save</button>
                                                    <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                                </div>
                                            </form>
                                        </span>
                                    </span>
                                </td>
                                <td class="px-2">
                                    {{ $measurement->status_memo }}
                                </td>
                            </tr>
                        @endforeach
                        </tbody>
                    @else
                        <tbody>
                        <tr>
                            <td class="text-secondary p-3">No device measurements for this patient</td>
                        </tr>
                        </tbody>
                    @endif
                </table>
            </div>
        </div> --}}

        <hr class="m-negator mt-4 mb-3">

        {{-- rm reasons --}}
        <div class="mb-2">
            @include('app/patient/care-month/rm-reasons')
        </div>

        <hr class="m-negator mt-0 mb-3">

        @if($pro->pro_type === 'ADMIN')
            <div class="pb-3">
                <div class="ml-auto d-inline-flex align-items-center">

                    <span class="text-secondary font-weight-bold">Pro:&nbsp;</span>
                    <b>{{$careMonth->mcp ? $careMonth->mcp->displayName() : '-'}}</b>

                    <span class="mx-3 text-secondary">|</span>
                    <span>
                        <span class="text-secondary font-weight-bold">Payer (1°): </span>
                        <b>{{$careMonth->companyProPayer && $careMonth->companyProPayer->payer ? $careMonth->companyProPayer->payer->name : '-'}}</b>
                        <span moe class="ml-1">
                            <a class="text-primary" href="" show start><i class="fa fa-edit"></i></a>
                            <form url="/api/careMonth/putCompanyProPayer">
                                <input type="hidden" name="uid" value="{{$careMonth->uid}}">
                                <div class="mb-2">
                                    <select name="companyProPayerUid" class="form-control form-control-sm">
                                        <option value="">-- select --</option>
                                        @foreach($careMonth->mcp->companyProPayers as $companyProPayer)
                                            <option value="{{$companyProPayer->uid}}">{{$companyProPayer->company->name}} / {{$companyProPayer->payer->name}}</option>
                                        @endforeach
                                    </select>
                                </div>
                                <div class="mb-0">
                                    <button class="btn btn-success btn-sm" submit>Submit</button>
                                    <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                </div>
                            </form>
                        </span>
                        @if($careMonth->companyProPayer && $careMonth->companyProPayer->payer)
                            <span moe class="ml-1">
                                <a class="text-danger" href="" show start><i class="fa fa-trash-alt"></i></a>
                                <form url="/api/careMonth/wipeCompanyProPayer">
                                    <input type="hidden" name="uid" value="{{$careMonth->uid}}">
                                    <p>Wipe payer from this care month?</p>
                                    <div class="mb-0">
                                        <button class="btn btn-primary btn-sm" submit>Submit</button>
                                        <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                    </div>
                                </form>
                            </span>
                        @endif
                    </span>

                    <span class="mx-3 text-secondary">|</span>
                    <span>
                        <span class="text-secondary font-weight-bold">Payer (2°): </span>
                        <b>-</b>
                    </span>

                    <span class="mx-3 text-secondary">|</span>
                    <span>
                        <span class="text-secondary font-weight-bold">Location: </span><b>{{$careMonth->companyLocation ? $careMonth->companyLocation->line1 . ', ' . $careMonth->companyLocation->city : '-'}}</b>
                        <span moe class="ml-1">
                            <a class="text-primary" href="" show start><i class="fa fa-edit"></i></a>
                            <form url="/api/careMonth/putCompanyLocation">
                                <input type="hidden" name="uid" value="{{$careMonth->uid}}">
                                <div class="mb-2">
                                    <select name="companyLocationUid" class="form-control form-control-sm">
                                        <option value="">-- select --</option>
                                        @if($careMonth->company && $careMonth->company->locations)
                                            @foreach($careMonth->company->locations as $location)
                                                <option value="{{$location->uid}}">{{$location->line1 . ', ' . $location->city}}</option>
                                            @endforeach
                                        @endif
                                    </select>
                                </div>
                                <div class="mb-0">
                                    <button class="btn btn-success btn-sm" submit>Submit</button>
                                    <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                </div>
                            </form>
                        </span>
                        @if($careMonth->companyLocation)
                            <span moe class="ml-1">
                                <a class="text-danger" href="" show start><i class="fa fa-trash-alt"></i></a>
                                <form url="/api/careMonth/wipeCompanyLocation">
                                    <input type="hidden" name="uid" value="{{$careMonth->uid}}">
                                    <p>Wipe location from this care month?</p>
                                    <div class="mb-0">
                                        <button class="btn btn-primary btn-sm" submit>Submit</button>
                                        <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                    </div>
                                </form>
                            </span>
                        @endif
                    </span>
                </div>
            </div>
        @endif

        <hr class="m-negator mt-0 mb-3">

        {{-- RM --}}
        <div class="row">
            <div class="col-12">
                @if($careMonth->is_client_enrolled_in_rm)
                    <div class="d-flex align-items-center">
                        <h6 class="my-0 text-secondary font-weight-bold text-dark lh-24px">Time Entries</h6>
                        @if(!$activeRMBill)
                            <span class="mx-2 text-secondary">|</span>
                            <span moe large>
                                <a start show class="py-0 mb-3">Add</a>
                                <form url="/api/careMonthEntry/createForRm">
                                    <input type="hidden" name="careMonthUid" value="{{ $careMonth->uid }}">
                                    <div class="mb-2">
                                        <div class="row">
                                            <div class="col-4 pr-0">
                                                <select class="form-control form-control-sm w-100" name="proUid" provider-search data-pro-uid="{{ @$pro->uid }}"
                                                        required>
                                                    <option value="">-- Select Pro --</option>
                                                    @foreach($pros as $iPro)
                                                        <option {{ $iPro->uid === $pro->uid ? 'selected' : '' }}
                                                                value="{{ $iPro->uid }}">{{ $iPro->displayName() }}</option>
                                                    @endforeach
                                                </select>
                                            </div>
                                            <div class="col-4 pr-0">
                                                <?php
                                                $sD = strtotime($careMonth->start_date);
                                                $y = date('Y', $sD);
                                                $m = date('m', $sD);
                                                $d = date('t', $sD);
                                                $yCurrent = date('Y');
                                                $mCurrent = date('m');
                                                $isToday = false;
                                                if($y === $yCurrent && $m === $mCurrent) {
                                                    $d = date('d');
                                                    $isToday = true;
                                                }
                                                ?>
                                                <input autofocus type="date" min="{{ date($y . '-' . $m . '-01') }}" max="{{ date($y . '-' . $m . '-' . $d) }}"
                                                       value="{{date('Y-m-d')}}"
                                                       class="form-control form-control-sm w-100" name="effectiveDate"
                                                       placeholder="Effective Date" required>
                                            </div>
                                            <div class="col-4">
                                                <input type="number" min="0" max="5400" class="form-control form-control-sm w-100 cm-time-value" name="timeInMinutes"
                                                       value="" placeholder="Time (mins.)" required>
                                            </div>
                                        </div>
                                    </div>
                                    {{--<div class="mb-2">
                                        <div class="row">
                                            <div class="col-4 pr-0 d-flex align-items-center">
                                                <div class="d-flex align-items-center">
                                                    <span>Time Specific:</span>
                                                    <input type="checkbox" name="isTimeSpecific" class="ml-1"
                                                           onchange="enableTimeSpecificFields(this.checked, 'rm-time-value', 'rm-time-range')">
                                                </div>
                                            </div>
                                            <div class="col-4 pr-0">
                                                <input type="time" class="form-control form-control-sm rm-time-range" name="startingTime"
                                                       value="" placeholder="Starting Time" disabled>
                                            </div>
                                            <div class="col-4">
                                                <input type="time" class="form-control form-control-sm rm-time-range" name="endingTime"
                                                       value="" placeholder="Ending Time" disabled>
                                            </div>
                                        </div>
                                    </div>--}}
                                    {{--@include('app/entry-templates/rm/default')--}}
                                    <div class="mb-2">
                                        <div class="row">
                                            <div class="col-12">
                                                <div cm-rte data-content="Reviewed/managed patient measurements" data-name="contentText"></div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="d-flex align-items-center">
                                        <button class="btn btn-sm btn-primary mr-2" submit>Save</button>
                                        <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                    </div>
                                </form>
                            </span>
                            {{--<span class="mx-2 text-secondary">|</span>
                            <span moe>
                                <a start show class="py-0 mb-3 text-danger">Un-Enroll</a>
                                <form url="/api/careMonth/setIsClientEnrolledInRmToFalse">
                                    <input type="hidden" name="uid" value="{{ $careMonth->uid }}">
                                    <p class="small">Are you sure you want to un-enroll this client from RM?</p>
                                    <div class="d-flex align-items-center">
                                        <button class="btn btn-sm btn-danger mr-2" submit>Yes</button>
                                        <button class="btn btn-sm btn-default mr-2 border" cancel>No</button>
                                    </div>
                                </form>
                            </span>--}}
                        @else
                            <span class="mx-2 text-secondary">|</span>
                            <span class="text-secondary">Can't modify since a bill exists</span>
                        @endif
                    </div>
                    <table class="table table-striped table-sm table-bordered mt-2 mb-0">
                        <thead>
                        <tr>
                            <th class="px-2 text-secondary border-bottom-0">Effective Date</th>
                            <th class="px-2 text-secondary border-bottom-0">Time</th>
                            <th class="px-2 text-secondary border-bottom-0">Created</th>
                            <th class="px-2 text-secondary border-bottom-0 w-50">Details</th>
                            <th class="px-2 text-secondary border-bottom-0 delete-column">&nbsp;</th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach($entries as $entry)
                            @if(!$entry->is_removed && $entry->cm_or_rm === "RM")
                                <tr>
                                    <td class="px-2">
                                        <div class="font-weight-bold">{{friendly_date_time($entry->effective_date, false)}}</div>
                                    </td>
                                    <td class="px-2">
                                        {{time_in_hrminsec($entry->time_in_seconds)}}
                                    </td>
                                    <td class="px-2">
                                        {{friendly_date_time($entry->created_at)}}
                                    </td>
                                    <td class="px-2">
                                        <div class="text-secondary in-table-markup">{!! $entry->content_text !!}</div>
<!--                                        <div class="text-secondary text-sm">{{$entry->content_detail}}</div>-->
                                    </td>
                                    <td class="px-2 text-center delete-column">
                                        @if(!$activeRMBill)
                                            <div moe relative>
                                                <a start show><i class="on-hover-opaque fa fa-trash-alt text-danger"></i></a>
                                                <form url="/api/careMonthEntry/remove" right>
                                                    <input type="hidden" name="uid" value="{{ $entry->uid }}">
                                                    <p class="small">Are you sure you want to delete this RM entry?</p>
                                                    <div class="d-flex align-items-center">
                                                        <button class="btn btn-sm btn-danger mr-2" submit>Delete</button>
                                                        <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                                    </div>
                                                </form>
                                            </div>
                                        @else
                                            <a href="#" class="text-secondary" title="Can't modify since a bill exists"><i class="on-hover-opaque fa fa-trash-alt"></i></a>
                                        @endif
                                    </td>
                                </tr>
                            @endif
                        @endforeach
                        </tbody>
                    </table>
                @else
                    <h6 class="mb-2 text-secondary font-weight-bold text-dark lh-24px">Time Entries</h6>
                    <div class="alert alert-secondary mt-2 mb-0">
                        <b>{{ $patient->displayName() }}</b> is currently not enrolled in <b>RM</b>.
                        <span moe class="">
                            <a start show class="font-weight-bold">Enroll Now</a>
                            <form url="/api/careMonth/setIsClientEnrolledInRmToTrue">
                                <input type="hidden" name="uid" value="{{ $careMonth->uid }}">
                                <p class="small">Enroll this client in RM?</p>
                                <div class="d-flex align-items-center">
                                    <button class="btn btn-sm btn-primary mr-2" submit>Yes</button>
                                    <button class="btn btn-sm btn-default mr-2 border" cancel>No</button>
                                </div>
                            </form>
                        </span>
                    </div>
                @endif
            </div>

            {{-- CM --}}
            <?php /*
            @if($careMonth->is_tm_this_month)
                <div class="col-6">
                    <div class="d-flex align-items-center">
                        <h6 class="my-0 text-secondary font-weight-bold text-dark lh-24px">CM Time Entries</h6>
                    </div>
                    <div class="alert alert-secondary mb-0 mt-2">
                        This care month has been marked as <b>Transitional Month</b>.
                        <span moe class="">
                        <a start show class="font-weight-bold">Undo</a>
                        <form url="/api/careMonth/setIsTmThisMonthToFalse">
                            <input type="hidden" name="uid" value="{{ $careMonth->uid }}">
                            <p>Undo mark as <b>Transitional Month</b>?</p>
                            <div class="d-flex align-items-center">
                                <button class="btn btn-sm btn-primary mr-2" submit>Yes</button>
                                <button class="btn btn-sm btn-default mr-2 border" cancel>No</button>
                            </div>
                        </form>
                    </span>
                    </div>
                </div>
            @else
                @if($careMonth->is_client_enrolled_in_cm)
                    <div class="col-6">
                        <div class="d-flex align-items-center">
                            <h6 class="my-0 text-secondary font-weight-bold text-dark lh-24px">CM Time Entries</h6>
                            @if(!$activeCMBill)
                                <span class="mx-2 text-secondary">|</span>
                                <span moe large relative>
                                    <a start show class="py-0 mb-3">Add</a>
                                    <form url="/api/careMonthEntry/createForCm" right>
                                        <input type="hidden" name="careMonthUid" value="{{ $careMonth->uid }}">
                                        <div class="mb-2">
                                            <div class="row">
                                                <div class="col-4 pr-0">
                                                    <select class="form-control form-control-sm w-100" name="proUid">
                                                        <option value="">-- Select Pro --</option>
                                                        @foreach($pros as $iPro)
                                                            <option {{ $iPro->uid === $pro->uid ? 'selected' : '' }}
                                                                    value="{{ $iPro->uid }}">{{ $iPro->displayName() }}</option>
                                                        @endforeach
                                                    </select>
                                                </div>
                                                <div class="col-4 pr-0">
                                                    <?php
                                                    $sD = strtotime($careMonth->start_date);
                                                    $y = date('Y', $sD);
                                                    $m = date('m', $sD);
                                                    $d = date('t', $sD);
                                                    $yCurrent = date('Y');
                                                    $mCurrent = date('m');
                                                    if($y === $yCurrent && $m === $mCurrent) {
                                                        $d = date('d');
                                                    }
                                                    ?>
                                                    <input autofocus type="date" min="{{ date($y . '-' . $m . '-01') }}" max="{{ date($y . '-' . $m . '-' . $d) }}"
                                                           class="form-control form-control-sm w-100" name="effectiveDate"
                                                           placeholder="Effective Date">
                                                </div>
                                                <div class="col-4">
                                                    <input type="number" min="0" max="5400" class="form-control form-control-sm w-100 cm-time-value" name="timeInSeconds"
                                                           value="" placeholder="Time in Seconds">
                                                </div>
                                            </div>
                                        </div>
                                        <div class="mb-2">
                                            <div class="row">
                                                <div class="col-4 pr-0 d-flex align-items-center">
                                                    <div class="d-flex align-items-center">
                                                        <span>Time Specific:</span>
                                                        <input type="checkbox" name="isTimeSpecific" class="ml-1"
                                                               onchange="enableTimeSpecificFields(this.checked, 'cm-time-value', 'cm-time-range')">
                                                    </div>
                                                </div>
                                                <div class="col-4 pr-0">
                                                    <input type="time" class="form-control form-control-sm cm-time-range" name="startingTime"
                                                           value="" placeholder="Starting Time" disabled>
                                                </div>
                                                <div class="col-4">
                                                    <input type="time" class="form-control form-control-sm cm-time-range" name="endingTime"
                                                           value="" placeholder="Ending Time" disabled>
                                                </div>
                                            </div>
                                        </div>
                                        @include('app/entry-templates/cm/default')
                                        <div class="d-flex align-items-center">
                                            <button class="btn btn-sm btn-primary mr-2" submit>Save</button>
                                            <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                        </div>
                                    </form>
                                </span>
                                <span class="mx-2 text-secondary">|</span>
                                <span moe>
                                    <a start show class="py-0 mb-3 text-danger">Un-Enroll</a>
                                    <form url="/api/careMonth/setIsClientEnrolledInCmToFalse">
                                        <input type="hidden" name="uid" value="{{ $careMonth->uid }}">
                                        <p class="small">Are you sure you want to un-enroll this client from CM?</p>
                                        <div class="d-flex align-items-center">
                                            <button class="btn btn-sm btn-danger mr-2" submit>Yes</button>
                                            <button class="btn btn-sm btn-default mr-2 border" cancel>No</button>
                                        </div>
                                    </form>
                                </span>
                            @else
                                <span class="mx-2 text-secondary">|</span>
                                <span class="text-secondary">Can't modify since a bill exists</span>
                            @endif
                        </div>
                        <table class="table table-striped table-sm table-bordered mt-2 mb-0">
                            <thead>
                            <tr>
                                <th class="px-2 text-secondary border-bottom-0">Effective Date</th>
                                <th class="px-2 text-secondary border-bottom-0">Time</th>
                                <th class="px-2 text-secondary border-bottom-0 w-50">Details</th>
                                <th class="px-2 text-secondary border-bottom-0 delete-column">&nbsp;</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($entries as $entry)
                                @if(!$entry->is_removed && $entry->cm_or_rm === "CM")
                                    <tr>
                                        <td class="px-2">
                                            <div class="font-weight-bold">{{friendly_date_time($entry->effective_date, false)}}</div>
                                            <div class="small text-secondary">Created: {{friendly_date_time($entry->created_at)}}</div>
                                        </td>
                                        <td class="px-2">
                                            {{time_in_hrminsec($entry->time_in_seconds)}}
                                        </td>
                                        <td class="px-2">
                                            <div class="text-secondary text-s">{!! $entry->content_text !!}</div>
                                            {{--<div class="text-secondary text-sm">{{$entry->content_detail}}</div>--}}
                                        </td>
                                        <td class="px-2 text-center delete-column">
                                            @if(!$activeCMBill)
                                                <div moe relative>
                                                    <a start show><i class="on-hover-opaque fa fa-trash-alt text-danger"></i></a>
                                                    <form url="/api/careMonthEntry/remove" right>
                                                        <input type="hidden" name="uid" value="{{ $entry->uid }}">
                                                        <p class="small">Are you sure you want to delete this CM entry?</p>
                                                        <div class="d-flex align-items-center">
                                                            <button class="btn btn-sm btn-danger mr-2" submit>Delete</button>
                                                            <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                                        </div>
                                                    </form>
                                                </div>
                                            @else
                                                <a href="#" class="text-secondary" title="Can't modify since a bill exists"><i class="on-hover-opaque fa fa-trash-alt"></i></a>
                                            @endif
                                        </td>
                                    </tr>
                                @endif
                            @endforeach
                            </tbody>
                        </table>
                    </div>
                @else
                    <div class="col-6">
                        <h6 class="mb-3 text-secondary font-weight-bold text-dark">CM Time Entries</h6>
                        <div class="alert alert-secondary mb-0">
                            <b>{{ $patient->displayName() }}</b> is currently not enrolled in <b>CM</b>.
                            <span moe class="">
                            <a start show class="font-weight-bold">Enroll Now</a>
                            <form url="/api/careMonth/setIsClientEnrolledInCmToTrue">
                                <input type="hidden" name="uid" value="{{ $careMonth->uid }}">
                                <p class="small">Enroll this client in CM?</p>
                                <div class="d-flex align-items-center">
                                    <button class="btn btn-sm btn-primary mr-2" submit>Yes</button>
                                    <button class="btn btn-sm btn-default mr-2 border" cancel>No</button>
                                </div>
                            </form>
                        </span>
                        </div>
                    </div>
                @endif
            @endif
            */ ?>
        </div>

        @if($careMonth->number_of_days_with_remote_measurements >= 16)

            <hr class="m-negator mt-4 mb-3">

            {{--<div class="row">

                <!-- rm bills -->
                <div class="col-12">
                    @if($careMonth->is_client_enrolled_in_rm)
                        <div class="d-flex align-items-center">
                            <h6 class="my-0 text-secondary font-weight-bold text-dark">RM Bill
                                @if($activeRMBill && !$activeRMBill->is_signed_by_hcp)
                                    <span class="small ml-1 text-secondary">(HCP Sign Pending)</span>
                                @else
                                    @if($activeRMBill)
                                        <span class="small ml-1 text-secondary">(Signed by HCP)</span>
                                    @endif
                                @endif
                            </h6>
                            @if($activeRMBill === false)
                                <span class="mx-2 text-secondary">|</span>
                                <div moe>
                                    <a start show class="py-0 mb-3">Generate</a>
                                    <form url="/api/careMonth/generateBillForRm">
                                        <input type="hidden" name="uid" value="{{ $careMonth->uid }}">
                                        <div class="mb-2">
                                            <select class="form-control" name="rmCode">
                                                <option value="">-- Select RM Code --</option>
                                                @if($rmCodes && count($rmCodes))
                                                    @foreach($rmCodes as $rmRate)
                                                        <option value="{{ $rmRate }}">{{ $rmRate }}</option>
                                                    @endforeach
                                                @endif
                                            </select>
                                        </div>
                                        <div class="mb-2">
                                            <textarea name="memo" id="" cols="30" rows="5" placeholder="Memo" class="form-control form-control-sm"></textarea>
                                        </div>
                                        <div class="d-flex align-items-center">
                                            <button class="btn btn-sm btn-primary mr-2" submit>Generate</button>
                                            <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                        </div>
                                    </form>
                                </div>
                            @else
                                @if(!$activeRMBill->is_signed_by_hcp && $activeRMBill->hcp_pro_id === $pro->id)
                                <span class="mx-2 text-secondary">|</span>
                                <div moe>
                                    <a start show class="py-0 mb-3 text-success">Sign as HCP</a>
                                    <form url="/api/bill/signAsHcp">
                                        <input type="hidden" name="uid" value="{{ $activeRMBill->uid }}">
                                        <p class="small">Sign this RM bill as HCP?</p>
                                        <div class="d-flex align-items-center">
                                            <button class="btn btn-sm btn-success mr-2" submit>Sign</button>
                                            <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                        </div>
                                    </form>
                                </div>
                                @endif
                                <span class="mx-2 text-secondary">|</span>
                                <div moe relative>
                                    <a start show class="py-0 mb-3 text-danger">Cancel</a>
                                    <form url="/api/bill/markCancelled" right>
                                        <input type="hidden" name="uid" value="{{ $activeRMBill->uid }}">
                                        <p class="small mb-2">Are you sure you want to cancel this RM bill?</p>
                                        <div class="mb-2">
                                            <textarea name="memo" id="" cols="30" rows="5" placeholder="Memo" class="memo-textarea form-control form-control-sm"></textarea>
                                        </div>
                                        <div class="d-flex align-items-center">
                                            <button class="btn btn-sm btn-danger mr-2" submit>Yes</button>
                                            <button class="btn btn-sm btn-default mr-2 border" cancel>No</button>
                                        </div>
                                    </form>
                                </div>
                            @endif
                        </div>
                        @if($activeRMBill !== false)
                            <div class="border bg-white p-2 mt-2">
                                <div class="">
                                    Code: <span class="font-weight-bold text-dark">{{ $activeRMBill->code }}</span>
                                    <div class="small text-secondary">Memo: {{$activeRMBill->memo}}</div>
                                    <div class="small text-secondary">Created: {{friendly_date_time($activeRMBill->created_at)}}</div>
                                </div>
                                <div class="font-weight-bold text-dark mt-2 mb-1"></div>
                                @if($activeRMBill->hcp_pro_id === $pro->id)
                                    <div class="d-flex align-items-center">
                                        @if($activeRMBill->has_hcp_been_paid)
                                            <span class="text-dark">Received HCP Amount: </span>
                                            <span class="font-weight-bold text-success ml-2">${{ $activeRMBill->hcp_payment_amount }}</span>
                                        @else
                                            <span class="text-dark">Expected HCP Amount: </span>
                                            <span class="font-weight-bold text-dark ml-2">{{ $activeRMBill->hcp_expected_payment_amount ? '$' . $activeRMBill->hcp_expected_payment_amount : '-' }}</span>
                                            <span class="ml-auto">
                                                @if($activeRMBill->is_signed_by_hcp)
                                                    <div class="text-secondary ml-3 text-sm"><i class="fa fa-check"></i> Signed</div>
                                                @else
                                                    <div class="text-primary ml-3">
                                                        <div moe class="text-dark">
                                                            <a start show class="py-0 mb-3 text-primary text-sm">
                                                                <i class="fa fa-exclamation-triangle"></i> Sign Pending
                                                            </a>
                                                            <form url="/api/bill/signAsHcp">
                                                                <input type="hidden" name="uid" value="{{ $activeRMBill->uid }}">
                                                                <p class="small">Sign this RM bill as HCP?</p>
                                                                <div class="d-flex align-items-center">
                                                                    <button class="btn btn-sm btn-success mr-2" submit>Sign</button>
                                                                    <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                                                </div>
                                                            </form>
                                                        </div>
                                                    </div>
                                                @endif
                                            </span>
                                        @endif
                                    </div>
                                @endif
                                @if($activeRMBill->rmm_pro_id === $pro->id)
                                    <div class="d-flex align-items-center">
                                        @if($activeRMBill->has_rmm_been_paid)
                                            <span class="text-dark">Received RMM Pro Amount: </span>
                                            <span class="font-weight-bold text-success ml-2">${{ $activeRMBill->rmm_payment_amount }}</span>
                                        @else
                                            <span class="text-dark">Expected RMM Pro Amount: </span>
                                            <span class="font-weight-bold text-dark ml-2">{{ $activeRMBill->rmm_expected_payment_amount ? '$' . $activeRMBill->rmm_expected_payment_amount : '-' }}</span>
                                            <span class="ml-auto">
                                                @if($activeRMBill->is_signed_by_rmm)
                                                    <div class="text-secondary ml-3 text-sm"><i class="fa fa-check"></i> Signed</div>
                                                @else
                                                    <div class="text-primary ml-3">
                                                        <div moe class="text-dark">
                                                            <a start show class="py-0 mb-3 text-primary text-sm">
                                                                <i class="fa fa-exclamation-triangle"></i> Sign Pending
                                                            </a>
                                                            <form url="/api/bill/signAsRmm">
                                                                <input type="hidden" name="uid" value="{{ $activeRMBill->uid }}">
                                                                <p class="small">Sign this RM bill as RMM Pro?</p>
                                                                <div class="d-flex align-items-center">
                                                                    <button class="btn btn-sm btn-success mr-2" submit>Sign</button>
                                                                    <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                                                </div>
                                                            </form>
                                                        </div>
                                                    </div>
                                                @endif
                                            </span>
                                        @endif
                                    </div>
                                @endif
                                @if($activeRMBill->rme_pro_id === $pro->id)
                                    <div class="d-flex align-items-center">
                                        @if($activeRMBill->has_rme_been_paid)
                                            <span class="text-success">Received RME Pro Amount: </span>
                                            <span class="font-weight-bold text-dark ml-2">${{ $activeRMBill->rme_payment_amount }}</span>
                                        @else
                                            <span class="text-dark">Expected RME Pro Amount: </span>
                                            <span class="font-weight-bold text-dark ml-2">{{ $activeRMBill->rme_expected_payment_amount ? '$' . $activeRMBill->rme_expected_payment_amount : '-' }}</span>
                                            <span class="ml-auto">
                                                @if($activeRMBill->is_signed_by_rme)
                                                    <div class="text-secondary ml-3 text-sm"><i class="fa fa-check"></i> Signed</div>
                                                @else
                                                    <div class="text-primary ml-3">
                                                        <div moe class="text-dark">
                                                            <a start show class="py-0 mb-3 text-primary text-sm">
                                                                <i class="fa fa-exclamation-triangle"></i> Sign Pending
                                                            </a>
                                                            <form url="/api/bill/signAsRme">
                                                                <input type="hidden" name="uid" value="{{ $activeRMBill->uid }}">
                                                                <p class="small">Sign this RM bill as RME Pro?</p>
                                                                <div class="d-flex align-items-center">
                                                                    <button class="btn btn-sm btn-success mr-2" submit>Sign</button>
                                                                    <button class="btn btn-sm btn-default mr-2 border" cancel>Cancel</button>
                                                                </div>
                                                            </form>
                                                        </div>
                                                    </div>
                                                @endif
                                            </span>
                                        @endif
                                    </div>
                                @endif
                            </div>
                        @endif
                        <!-- cancelled rm bills -->
                        @if(count($cancelledRMBills))
                            @foreach($cancelledRMBills as $cancelledBill)
                                <div class="border bg-light p-2 mt-2 on-hover-opaque mb-3">
                                    <div class="d-flex">
                                        <div class="">
                                            Code: <span class="font-weight-bold text-dark">{{ $cancelledBill->code }}</span>
                                            <div class="small text-secondary">Memo: {{$cancelledBill->memo}}</div>
                                            <div class="small text-secondary">Created: {{friendly_date_time($cancelledBill->created_at)}}</div>
                                        </div>
                                        <div class="ml-auto text-secondary font-weight-bold">CANCELLED BILL</div>
                                    </div>
                                    <div class="font-weight-bold text-dark mt-2 mb-1"></div>
                                    @if($cancelledBill->hcp_pro_id === $pro->id)
                                        <div class="d-flex align-items-center">
                                            @if($cancelledBill->has_hcp_been_paid)
                                                <span class="text-dark">Received HCP Amount: </span>
                                                <span class="font-weight-bold text-success ml-2">${{ $cancelledBill->hcp_payment_amount }}</span>
                                            @else
                                                <span class="text-dark">Expected HCP Amount: </span>
                                                <span class="font-weight-bold text-dark ml-2">{{ $cancelledBill->hcp_expected_payment_amount ? '$' . $cancelledBill->hcp_expected_payment_amount : '-' }}</span>
                                            @endif
                                        </div>
                                    @endif
                                    @if($cancelledBill->rmm_pro_id === $pro->id)
                                        <div class="d-flex align-items-center">
                                            @if($cancelledBill->has_rmm_been_paid)
                                                <span class="text-dark">Received RMM Pro Amount: </span>
                                                <span class="font-weight-bold text-success ml-2">${{ $cancelledBill->rmm_payment_amount }}</span>
                                            @else
                                                <span class="text-dark">Expected RMM Pro Amount: </span>
                                                <span class="font-weight-bold text-dark ml-2">{{ $cancelledBill->rmm_expected_payment_amount ? '$' . $cancelledBill->rmm_expected_payment_amount : '-' }}</span>
                                            @endif
                                        </div>
                                    @endif
                                    @if($cancelledBill->rme_pro_id === $pro->id)
                                        <div class="d-flex align-items-center">
                                            @if($cancelledBill->has_rme_been_paid)
                                                <span class="text-success">Received RME Pro Amount: </span>
                                                <span class="font-weight-bold text-dark ml-2">${{ $cancelledBill->rme_payment_amount }}</span>
                                            @else
                                                <span class="text-dark">Expected RME Pro Amount: </span>
                                                <span class="font-weight-bold text-dark ml-2">{{ $cancelledBill->rme_expected_payment_amount ? '$' . $cancelledBill->rme_expected_payment_amount : '-' }}</span>
                                            @endif
                                        </div>
                                    @endif
                                </div>
                            @endforeach
                        @endif
                    @endif
                </div>

            </div>

            <hr class="m-negator mt-4 mb-3">--}}




            {{-- bills --}}
            @if($pro->pro_type === 'ADMIN' || ($careMonth->mcp && $pro->id === $careMonth->mcp->id))
                @if($careMonth->bills->count())
                    <div class="">
                        <div class="d-flex align-items-center mb-2">
                            <p class="font-weight-bold font-size-13 m-0">RM Bills</p>
                            @include('app/patient/care-month/_create-bill')
                        </div>

                        @if($pro->pro_type === 'ADMIN')
                            <table class="table table-sm tabe-striped mb-0 table-bordered">
                                <thead class="bg-light">
                                <tr class="text-secondary">
                                    <?php /* <th class="border-bottom-0"></th> */ ?>
                                    <th class="border-bottom-0">Date</th>
                                    <th class="border-bottom-0">Service</th>
                                    <th class="border-bottom-0">Billable</th>
                                    <th class="border-bottom-0">HCP</th>
                                    <th class="border-bottom-0">Total</th>
                                    <th class="border-bottom-0">Sign</th>
                                    <th class="border-bottom-0">Bal Post Date</th>
                                    <th class="border-bottom-0">Verification</th>
                                    <th class="border-bottom-0">Cancellation</th>
                                    <th class="border-bottom-0">Payment</th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach ($careMonth->bills as $bill)
                                    <tr class="{{$bill->is_cancelled ? 'bg-light text-secondary' : ''}}">
                                        <?php /* <td class="p-0">
                                            <table class="table-striped table-sm table-condensed border border-left-0 border-top-0 border-bottom-0">
                                                <tbody>
                                                    <tr><td>collected_amount</td><td>{{$bill->collected_amount}}</td></tr>
                                                    <tr><td>effective_date</td><td>{{$bill->effective_date}}</td></tr>
                                                    <tr><td>has_hcp_been_paid</td><td>{{$bill->has_hcp_been_paid}}</td></tr>
                                                    <tr><td>hcp_expected_payment_amount</td><td>{{$bill->hcp_expected_payment_amount}}</td></tr>
                                                    <tr><td>hcp_payment_amount</td><td>{{$bill->hcp_payment_amount}}</td></tr>
                                                    <tr><td>is_cancelled</td><td>{{$bill->is_cancelled}}</td></tr>
                                                    <tr><td>hcp_payment_pro_transaction_id</td><td>{{$bill->hcp_payment_pro_transaction_id}}</td></tr>
                                                    <tr><td>balance_post_date</td><td>{{$bill->balance_post_date}}</td></tr>
                                                    <tr><td>is_verified</td><td>{{$bill->is_verified}}</td></tr>
                                                    <tr><td>is_cancellation_acknowledged</td><td>{{$bill->is_cancellation_acknowledged}}</td></tr>
                                                    <tr><td>is_cancelled_by_administrator</td><td>{{$bill->is_cancelled_by_administrator}}</td></tr>
                                                    <tr><td>total_expected</td><td>{{$bill->total_expected}}</td></tr>
                                                    <tr><td>total_paid</td><td>{{$bill->total_paid}}</td></tr>
                                                </tbody>
                                            </table>
                                        </td> */ ?>
                                        <td class="text-nowrap">{{friendlier_date_time($bill->effective_date, false)}}</td>
                                        <td>{{$bill->code}}</td>
                                        <td class="">
                                            @if(strpos(strtolower($bill->code), 'treatment services') !== FALSE)
                                                <?php
                                                $totalSeconds = $bill->number_of_units * 3600;
                                                $remainder = $totalSeconds % 60;
                                                if ($remainder !== 0) {
                                                    if ($remainder < 30) {
                                                        $totalSeconds = $totalSeconds - $remainder;
                                                    }
                                                    else {
                                                        $totalSeconds = $totalSeconds + (60 - $remainder);
                                                    }
                                                }
                                                ?>
                                                {{ time_in_hrminsec($totalSeconds) }}
                                            @else
                                                @if(!!$bill->number_of_units)
                                                    {{ $bill->number_of_units }} unit(s)
                                                @else
                                                    -
                                                @endif
                                            @endif
                                        </td>
                                        <td class="">
                                            <div class="text-nowrap font-weight-bold text-secondary">{{ $bill->hcp->displayName() }} (HCP)</div>
                                            <div class="text-nowrap mt-1">
                                                <span class="text-secondary">Paid: </span>
                                                <span>{{ $bill->has_hcp_been_paid ? 'Yes' : 'No' }}</span>
                                            </div>
                                            @if(!$bill->has_hcp_been_paid)
                                                <div class="text-nowrap mt-1">
                                                    <span class="text-secondary">Expected: </span>
                                                    <span class="font-weight-bold">${{ $bill->hcp_expected_payment_amount }}</span>
                                                </div>
                                            @else
                                                <div class="text-nowrap mt-1">
                                                    <span class="text-secondary">Amount: </span>
                                                    <span class="font-weight-bold">${{ $bill->hcp_payment_amount }}</span>
                                                </div>
                                            @endif
                                            @if($bill->ally)
                                                <hr>
                                                <div class="text-nowrap font-weight-bold text-secondary">{{ $bill->ally->displayName() }} (NA)</div>
                                                <div class="text-nowrap mt-1">
                                                    <span class="text-secondary">Paid: </span>
                                                    <span>{{ $bill->has_na_been_paid ? 'Yes' : 'No' }}</span>
                                                </div>
                                                @if(!$bill->has_na_been_paid)
                                                    <div class="text-nowrap mt-1">
                                                        <span class="text-secondary">Expected: </span>
                                                        <span class="font-weight-bold">${{ $bill->na_expected_payment_amount }}</span>
                                                    </div>
                                                @else
                                                    <div class="text-nowrap mt-1">
                                                        <span class="text-secondary">Amount: </span>
                                                        <span class="font-weight-bold">${{ $bill->na_payment_amount }}</span>
                                                    </div>
                                                @endif
                                            @endif

                                        </td>
                                        <td class="pr-3">
                                            @if($bill->has_hcp_been_paid)
                                                <span class="text-secondary">Paid. </span>
                                                <span class="font-weight-bold">${{ friendly_money($bill->total_paid) }}</span>
                                            @else
                                                <span class="text-secondary">Exp. </span>
                                                <span class="font-weight-bold">{{ $bill->total_expected ? '$' . friendly_money($bill->total_expected) : '-' }}</span>
                                            @endif
                                        </td>
                                        <td>
                                            @if(!$bill->is_cancelled)
                                                @if($bill->is_signed_by_hcp)
                                                    <span class="d-block text-secondary text-nowrap">
                                                            <i class="fa fa-check"></i>
                                                            HCP Signed
                                                        </span>
                                                @else
                                                    <span moe
                                                          class="d-block {{ $bill->hcp_pro_id !== $pro->id ? 'moe-disabled' : '' }}"
                                                          title="{{ $bill->hcp_pro_id !== $pro->id ? 'Only the bill\'s HCP can sign' : '' }}">
                                                        <a class="" href="" show start>Sign As HCP</a>
                                                        <form url="/api/bill/signAsHcp">
                                                            <input type="hidden" name="uid" value="{{$bill->uid}}">
                                                            <p>Sign this bill as HCP?</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>
                                                    </span>
                                                @endif
                                            @endif
                                        </td>
                                        <td>
                                            @if(!$bill->is_cancelled)
                                                <span class="d-block" moe>
                                                    <a class="" href="" show start>
                                                        {{$bill->balance_post_date ? friendlier_date_time($bill->balance_post_date, false) : '(not set)' }}
                                                    </a>
                                                    <form url="/api/bill/updateBalancePostDate">
                                                        <input type="hidden" name="uid" value="{{$bill->uid}}">
                                                        <p>Update Balance Post Date</p>
                                                        <div class="mb-0">
                                                            <input type="date" class="text form-control form-control-sm" name="balancePostDate" value="{{$bill->balance_post_date}}" placeholder="balance post date"><br>
                                                            <button class="btn btn-success btn-sm" submit>Submit</button>
                                                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                                        </div>
                                                    </form>
                                                </span>
                                            @endif
                                        </td>
                                        <td> <!-- verification -->
                                            @if($pro->pro_type === 'ADMIN' && !$bill->is_cancelled)
                                                @if(!$bill->is_verified)
                                                    <div class="text-warning-mellow font-weight-bold">Not Verified</div>
                                                    <span class="d-block mt-1" moe>
                                                        <a href="" show start>Mark Verified</a>
                                                        <form url="/api/bill/markAsVerified">
                                                            <input type="hidden" name="uid" value="{{$bill->uid}}">
                                                            <p>Mark As Verfified?</p>
                                                            <div class="mb-0">
                                                                <button class="btn btn-success btn-sm" submit>Submit</button>
                                                                <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                                            </div>
                                                        </form>
                                                    </span>
                                                @else
                                                    <div class="text-success font-weight-bold"><i class="fa fa-check"></i> Verified</div>
                                                    <span class="d-block mt-1" moe>
                                                        <a class="" href="" show start>Undo</a>
                                                        <form url="/api/bill/undoMarkAsVerified">
                                                            <input type="hidden" name="uid" value="{{$bill->uid}}">
                                                            <p>Undo Mark As Verfified?</p>
                                                            <div class="mb-0">
                                                                <button class="btn btn-success btn-sm" submit>Submit</button>
                                                                <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                                            </div>
                                                        </form>
                                                    </span>
                                                @endif
                                            @endif
                                        </td>
                                        <td>  <!-- cancellation -->
                                            @if($bill->is_cancelled)
                                                <div class="text-warning-mellow font-weight-bold">Cancelled</div>
                                                @if($bill->cancellation_memo)
                                                    <div class="text-dark text-sm font-italic my-1">{{$bill->cancellation_memo}}</div>
                                                @endif
                                                @if($bill->is_cancelled_by_administrator)
                                                    <div class="text-secondary text-sm">(by Administrator)</div>
                                                @endif
                                                <div moe class="mt-1">
                                                    <a class="" href="" show start>Update Memo</a>
                                                    <form url="/api/bill/updateCancellationMemo">
                                                        <input type="hidden" name="uid" value="{{$bill->uid}}">
                                                        <p>Update Cancellation Memo</p>
                                                        <div class="mb-2">
                                                            <textarea class="text form-control form-control-sm" name="cancellationMemo" placeholder="">{{$bill->cancellation_memo ? $bill->cancellation_memo : 'Insufficient documentation for billable service.'}}</textarea>
                                                        </div>
                                                        <div>
                                                            <button class="btn btn-success btn-sm" submit>Submit</button>
                                                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                                        </div>
                                                    </form>
                                                </div>
                                            @else
                                                <span class="d-block" moe relative="">
                                                    <a class="text-danger" href="" show start>Cancel</a>
                                                    <form url="/api/bill/markCancelled" right="">
                                                        <input type="hidden" name="uid" value="{{$bill->uid}}">
                                                        <p class="mb-2">Cancel this bill?</p>
                                                        <div class="mb-2">
                                                            <label class="mb-1 text-secondary">Cancellation Memo</label>
                                                            <textarea type="text" name="memo" placeholder="Memo" class="form-control form-control-sm">Insufficient documentation for billable service.</textarea>
                                                        </div>
                                                        <div class="mb-0">
                                                            <button class="btn btn-danger btn-sm" submit>Yes</button>
                                                            <button class="btn btn-default border btn-sm" cancel>No</button>
                                                        </div>
                                                    </form>
                                                </span>
                                            @endif

                                            @if($bill->is_cancelled && !$bill->is_cancellation_acknowledged)
                                                <div class="mt-2 text-secondary">
                                                    <i class="fa fa-exclamation-triangle"></i>
                                                    Not Acknowledged
                                                </div>
                                                <div class="d-block mt-1" moe>
                                                    <a class="" href="" show start>Ack. Cancellation</a>
                                                    <form url="/api/bill/acknowledgeCancellation">
                                                        <input type="hidden" name="uid" value="{{$bill->uid}}">
                                                        <p>Acknowledge Cancellation?</p>
                                                        <div class="mb-0">
                                                            {{--<input type="text" class="text form-control form-control-sm" name="cancellationMemo" value="{{$bill->cancellation_memo}}" placeholder=""><br>--}}
                                                            <button class="btn btn-primary btn-sm" submit>Submit</button>
                                                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                                        </div>
                                                    </form>
                                                </div>
                                            @endif

                                            @if($bill->is_cancellation_acknowledged && !$careMonth->is_billing_marked_done)
                                                <div class="mt-2 text-secondary">
                                                    <i class="fa fa-check"></i>
                                                    Acknowledged
                                                </div>
                                                <div class="d-block mt-1" moe>
                                                    <a class="" href="" show start>Undo Cancellation Ack.</a>
                                                    <form url="/api/bill/undoAcknowledgeCancellation">
                                                        <input type="hidden" name="uid" value="{{$bill->uid}}">
                                                        <p>Undo Acknowledge Cancellation?</p>
                                                        <div class="mb-0">
                                                            <button class="btn btn-success btn-sm" submit>Submit</button>
                                                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                                        </div>
                                                    </form>
                                                </div>
                                            @endif

                                        </td>
                                        <td> <!-- submit payment -->
                                            <div class="my-1">
                                                @if(!$bill->is_cancelled && !$bill->has_hcp_been_paid)
                                                    <span class="d-block" moe relative="">
                                                        <a class="font-weight-bold" href="" show start>Submit Payment For HCP</a>
                                                        <form url="/api/bill/payHcpAmount" right>
                                                            <input type="hidden" name="uid" value="{{$bill->uid}}">
                                                            <p>Submit Payment</p>
                                                            <div class="mb-0">
                                                                <input type="text" class="text form-control form-control-sm" name="hcpPaymentAmount" value="{{$bill->hcp_expected_payment_amount}}" placeholder="amount"><br>
                                                                <button class="btn btn-success btn-sm" submit>Submit</button>
                                                                <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                                            </div>
                                                        </form>
                                                    </span>
                                                @endif
                                            </div>
                                            <div class="my-1">
                                                @if(!$bill->is_cancelled && !$bill->has_na_been_paid && $bill->ally)
                                                    <span class="d-block" moe relative="">
                                                        <a class="font-weight-bold" href="" show start>Submit Payment For NA</a>
                                                        <form url="/api/bill/payNaAmount" right>
                                                            <input type="hidden" name="uid" value="{{$bill->uid}}">
                                                            <p>Submit Payment For NA</p>
                                                            <div class="mb-0">
                                                                <input type="text" class="text form-control form-control-sm" name="naPaymentAmount" value="{{$bill->na_expected_payment_amount}}" placeholder="amount"><br>
                                                                <button class="btn btn-success btn-sm" submit>Submit</button>
                                                                <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                                            </div>
                                                        </form>
                                                    </span>
                                                @endif
                                            </div>
                                        </td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                        @else
                            <table class="table table-sm tabe-striped mb-3 border-left border-right border-bottom">
                                <thead class="bg-light">
                                <tr>
                                    <th class="border-bottom-0 pl-3">HCP</th>
                                    <th class="border-bottom-0 w-25 pl-3">Service</th>
                                    {{--<th class="border-bottom-0 w-25 pl-2">Reason</th>--}}
                                    <th class="border-bottom-0 pl-3">Billable</th>
                                    <th class="border-bottom-0 pl-2">Amount</th>
                                    <th class="border-bottom-0"></th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach ($careMonth->bills as $bill)
                                    <tr>
                                        <td class="pl-3">{{ $bill->hcp->displayName() }}</td>
                                        <td class="pl-3 {{ $bill->is_cancelled ? 'text-secondary' : '' }}">{{$bill->code}}</td>
                                        {{--<td class="pl-2">
                                            {{ $bill->reason1 }}
                                            <div class="text-secondary small">{{ $bill->reason2 }}</div>
                                        </td>--}}
                                        <td class="pl-3">
                                            @if(strpos(strtolower($bill->code), 'treatment services') !== FALSE)
                                                <?php
                                                $totalSeconds = $bill->number_of_units * 3600;
                                                $remainder = $totalSeconds % 60;
                                                if ($remainder !== 0) {
                                                    if ($remainder < 30) {
                                                        $totalSeconds = $totalSeconds - $remainder;
                                                    }
                                                    else {
                                                        $totalSeconds = $totalSeconds + (60 - $remainder);
                                                    }
                                                }
                                                ?>
                                                {{ time_in_hrminsec($totalSeconds) }}
                                            @else
                                                @if(!!$bill->number_of_units)
                                                    {{ $bill->number_of_units }} unit(s)
                                                @else
                                                    -
                                                @endif
                                            @endif
                                        </td>
                                        <td class="pl-2">
                                            @if($bill->has_hcp_been_paid)
                                                <span class="text-dark">Processed:</span><span class="font-weight-bold text-success ml-2">${{ $bill->hcp_payment_amount }}</span>
                                            @else
                                                <span class="text-dark">Expected:</span><span class="font-weight-bold text-dark ml-2">{{ $bill->hcp_expected_payment_amount ? '$' . $bill->hcp_expected_payment_amount : '-' }}</span>
                                            @endif
                                        </td>
                                        <td>
                                            <div class="d-flex align-items-center">
                                                @if(!$bill->is_cancelled)
                                                    @if($bill->is_signed_by_hcp)
                                                        <span class="d-block text-secondary">
                                                            <i class="fa fa-check"></i>
                                                            HCP Signed
                                                        </span>
                                                    @else
                                                        <span moe
                                                              class="d-block {{ $bill->hcp_pro_id !== $pro->id ? 'moe-disabled' : '' }}"
                                                              title="{{ $bill->hcp_pro_id !== $pro->id ? 'Only the bill\'s HCP can sign' : '' }}">
                                                            <a class="" href="" show start>Sign</a>
                                                            <form url="/api/bill/signAsHcp">
                                                                <input type="hidden" name="uid" value="{{$bill->uid}}">
                                                                <p>Sign this bill as HCP?</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>
                                                        </span>
                                                    @endif
                                                @endif
                                                @if(!$bill->has_hcp_been_paid && $pro->pro_type === 'ADMIN')
                                                    <span class="mx-2 text-secondary">|</span>
                                                    <span class="d-block" moe>
                                                        <a class="text-danger" href="" show start>Submit Payment</a>
                                                        <form url="/api/bill/payHcpAmount">
                                                            <input type="hidden" name="uid" value="{{$bill->uid}}">
                                                            <p>Submit payment:</p>
                                                            <div class="mb-0">
                                                                <input type="text" class="text form-control form-control-sm" name="hcpPaymentAmount" value="{{$bill->hcp_expected_payment_amount}}" placeholder="amount"><br>
                                                                <button class="btn btn-success btn-sm" submit>Submit</button>
                                                                <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                                            </div>
                                                        </form>
                                                    </span>
                                                @endif
                                                @if($bill->is_cancelled)
                                                    <span class="mx-2 text-secondary">|</span>
                                                    <span class="d-block text-secondary">
                                                        Cancelled
                                                    </span>
                                                @else
                                                    <span class="mx-2 text-secondary">|</span>
                                                    <span class="d-block" moe>
                                                        <a class="text-danger" href="" show start>Cancel</a>
                                                        <form url="/api/bill/markCancelled" right>
                                                            <input type="hidden" name="uid" value="{{$bill->uid}}">
                                                            <p>Cancel this bill?</p>
                                                            <div class="mb-0">
                                                                <button class="btn btn-danger btn-sm" submit>Yes</button>
                                                                <button class="btn btn-default border btn-sm" cancel>No</button>
                                                            </div>
                                                        </form>
                                                    </span>
                                                @endif
                                            </div>
                                        </td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                        @endif
                    </div>
                @else
                    <div class="d-flex">
                        <p class="font-weight-bold mb-0">No bills in this care month</p>
                        @include('app/patient/care-month/_create-bill')
                    </div>
                @endif
            @endif


            <hr class="m-negator mt-4 mb-3">

            {{-- claims --}}
            @if($pro->pro_type === 'ADMIN')
                @if($careMonth->claims->count())
                    <div class="">
                        <div class="d-flex align-items-center mb-2">
                            <p class="font-weight-bold m-0">Claims</p>
                            @include('app/patient/care-month/_create-claim')
                            <div class="ml-auto">
                                <select class="form-control form-control-sm"
                                        onchange="fastLoad('{{route('patients.view.care-months.view.dashboard', ['patient' => $patient, 'careMonth' => $careMonth])}}?claims-filter=' + this.value)">
                                    <option value="active" {{!request('claims-filter') || request('claims-filter') === 'active' ? 'selected' : ''}}>Active Claims</option>
                                    <option value="all" {{request('claims-filter') === 'all' ? 'selected' : ''}}>All Claims</option>
                                </select>
                            </div>
                        </div>

                        <table class="table table-sm tabe-striped mb-3 border-left border-right border-bottom">
                            <thead class="bg-light">
                            <tr>
                                <th class="border-bottom-0 pl-2">IID</th>
                                <th class="border-bottom-0">Details</th>
                                <th class="border-bottom-0">Current Version</th>
                                <th class="border-bottom-0">Status</th>
                                <th class="border-bottom-0">Submissions</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach ($careMonth->claims as $claim)
                                @if($claim->status !== 'CANCELLED' || request('claims-filter') === 'all')
                                    <tr class="bg-secondary on-hover-opaque">
                                        <td colspan="5" class="pt-0 pb-1"></td>
                                    </tr>
                                    <tr class="{{ $claim->status === 'CANCELLED' ? 'text-secondary bg-light on-hover-opaque' : '' }}">
                                        <td class="pl-2">
                                            <div>{{ $claim->iid }}</div>
                                            @if($claim->status === 'CANCELLED')
                                                <div class="text-secondary font-weight-bold text-sm mt-1">[CANCELLED]</div>
                                            @else
                                                <div moe class="text-left mt-1" title="Cancel Claim">
                                                    <a class="" href="" show start>Cancel</a>
                                                    <form url="/api/claim/updateStatus">
                                                        <input type="hidden" name="uid" value="{{$claim->uid}}">
                                                        <input type="hidden" name="status" value="CANCELLED">
                                                        <p>Cancel this claim?</p>
                                                        <div class="mb-2">
                                                            <label for="" class="control-label">Cancellation Memo</label>
                                                            <textarea name="memo" class="form-control"></textarea>
                                                        </div>
                                                        <div class="mb-0">
                                                            <button class="btn btn-primary btn-sm" submit>Submit</button>
                                                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                                        </div>
                                                    </form>
                                                </div>
                                            @endif
                                        </td>
                                        <td class="p-0 border-left border-right">
                                            @if($claim->lines->count())
                                                <table class="table table-sm table-condensed border-0 mb-0">
                                                    <thead>
                                                    <tr class="bg-light">
                                                        <th class="border-0">CPT</th>
                                                        <th class="border-0">DOS</th>
                                                        <th class="border-0">ICDs</th>
                                                    </tr>
                                                    </thead>
                                                    <tbody class="pb-3">
                                                    @foreach($claim->lines as $line)
                                                        <tr class="claim-line">
                                                            <td>{{$line->cpt}}</td>
                                                            <td class="text-nowrap">{{friendlier_date($line->date_of_service)}}</td>
                                                            <td>
                                                                @if(count($line->claimLineIcds))
                                                                    @foreach($line->claimLineIcds as $icd)
                                                                        <div>
                                                                            <b class="c-pointer border-secondary border-bottom" title="{{$icd->description}}">{{$icd->code}}</b>
                                                                        </div>
                                                                    @endforeach
                                                                @else
                                                                    <p>No ICDs set</p>
                                                                @endif
                                                            </td>
                                                        </tr>
                                                    @endforeach
                                                    </tbody>
                                                </table>
                                            @else
                                                <p>No lines for this claim</p>
                                            @endif
                                        </td>
                                        <td class="border-right">
                                            {{$claim->currentVersion ? friendlier_date_time($claim->currentVersion->created_at) : '-'}}
                                        </td>
                                        <td class="border-right p-0">

                                            <!-- status -->
                                            <div class="p-1 border-bottom">
                                                <div>
                                                    {{$claim->status ? $claim->status : '(not set)'}}
                                                    @if($claim->status !== 'CANCELLED')
                                                        <span moe class="d-inline-block text-left ml-1" title="Update Status">
                                                                <a class="" href="" show start><i class="fa fa-edit"></i></a>
                                                                <form url="/api/claim/updateStatus">
                                                                    <input type="hidden" name="uid" value="{{$claim->uid}}">
                                                                    <div class="mb-2">
                                                                        <label for="" class="control-label">Status</label>
                                                                        <select name="status" class="form-control form-control-sm" required>
                                                                            <option value="">-- select --</option>
                                                                            <option value="NEW" {{$claim->status === 'NEW' ? 'selected' : ''}}>New</option>
                                                                            <option value="PROCESSING" {{$claim->status === 'PROCESSING' ? 'selected' : ''}}>Processing</option>
                                                                            <option value="SUBMITTED" {{$claim->status === 'SUBMITTED' ? 'selected' : ''}}>Submitted</option>
                                                                        </select>
                                                                    </div>
                                                                    <div class="mb-2">
                                                                        <label for="" class="control-label">Status Memo</label>
                                                                        <textarea name="memo" class="form-control"></textarea>
                                                                    </div>
                                                                    <div class="mb-0">
                                                                        <button class="btn btn-primary btn-sm" submit>Submit</button>
                                                                        <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                                                    </div>
                                                                </form>
                                                            </span>
                                                    @endif
                                                </div>
                                                @if($claim->status_memo)
                                                    <div class="text-secondary font-italic text-sm">{{$claim->status_memo}}</div>
                                                @endif
                                            </div>

                                            <!-- payer, company, location -->
                                            {{--
                                            <div class="p-1">
                                                <div class="mt-1">
                                                    <span class="text-secondary text-sm">Payer (1°): </span>
                                                    <b>{{$claim->primaryPayer ? $claim->primaryPayer->name : '-'}}</b>
                                                    @if($claim->status !== 'CANCELLED')
                                                        <span moe class="ml-1">
                                                                <a class="text-primary" href="" show start><i class="fa fa-edit"></i></a>
                                                                <form url="/api/claim/putPrimaryPayer">
                                                                    <input type="hidden" name="uid" value="{{$claim->uid}}">
                                                                    <div class="mb-2">
                                                                        <select name="primaryPayerUid" class="form-control form-control-sm">
                                                                            <option value="">-- select --</option>
                                                                            @foreach($note->hcpPro->companyProPayers as $companyProPayer)
                                                                                <option value="{{$companyProPayer->payer->uid}}"
                                                                                        {{$claim->primaryPayer && $claim->primaryPayer->uid === $companyProPayer->payer->uid ? 'selected' : ''}}>{{$companyProPayer->payer->name}}</option>
                                                                            @endforeach
                                                                        </select>
                                                                    </div>
                                                                    <div class="mb-0">
                                                                        <button class="btn btn-primary btn-sm" submit>Submit</button>
                                                                        <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                                                    </div>
                                                                </form>
                                                            </span>
                                                        @if($claim->primaryPayer)
                                                            <span moe class="ml-1">
                                                                <a class="text-danger" href="" show start><i class="fa fa-trash-alt"></i></a>
                                                                <form url="/api/claim/wipePrimaryPayer">
                                                                    <input type="hidden" name="uid" value="{{$claim->uid}}">
                                                                    <p>Wipe payer from this claim?</p>
                                                                    <div class="mb-0">
                                                                        <button class="btn btn-primary btn-sm" submit>Submit</button>
                                                                        <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                                                    </div>
                                                                </form>
                                                            </span>
                                                        @endif
                                                    @endif
                                                </div>

                                                <div class="mt-1">
                                                    <span class="text-secondary text-sm">Payer (2°): </span>
                                                    <b>-</b>
                                                </div>

                                                <div class="mt-1">
                                                    <span class="text-secondary text-sm">Company: </span>
                                                    <b>{{$claim->companyPro && $claim->companyPro->company ? $claim->companyPro->company->name : '-'}}</b>
                                                    @if($claim->status !== 'CANCELLED')
                                                        <span moe class="ml-1">
                                                                <a class="text-primary" href="" show start><i class="fa fa-edit"></i></a>
                                                                <form url="/api/claim/putCompanyPro">
                                                                    <input type="hidden" name="uid" value="{{$claim->uid}}">
                                                                    <div class="mb-2">
                                                                        <select name="companyProUid" class="form-control form-control-sm">
                                                                            <option value="">-- select --</option>
                                                                            @foreach($note->hcpPro->companyProPayers as $companyProPayer)
                                                                                <option value="{{$companyProPayer->companyPro->uid}}"
                                                                                        {{$claim->companyPro && $claim->companyPro->uid === $companyProPayer->companyPro->uid ? 'selected' : ''}}>{{$companyProPayer->company->name}}</option>
                                                                            @endforeach
                                                                        </select>
                                                                    </div>
                                                                    <div class="mb-0">
                                                                        <button class="btn btn-primary btn-sm" submit>Submit</button>
                                                                        <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                                                    </div>
                                                                </form>
                                                            </span>
                                                        @if($claim->companyPro && $claim->companyPro->company)
                                                            <span moe class="ml-1">
                                                                    <a class="text-danger" href="" show start><i class="fa fa-trash-alt"></i></a>
                                                                    <form url="/api/claim/wipeCompanyPro">
                                                                        <input type="hidden" name="uid" value="{{$claim->uid}}">
                                                                        <p>Wipe company from this claim?</p>
                                                                        <div class="mb-0">
                                                                            <button class="btn btn-primary btn-sm" submit>Submit</button>
                                                                            <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                                                        </div>
                                                                    </form>
                                                                </span>
                                                        @endif
                                                    @endif
                                                </div>

                                                <div class="mt-1">
                                                    <span class="text-secondary text-sm">Location: </span>
                                                    <b>{{$claim->companyLocation ? $claim->companyLocation->line1 . ', ' . $claim->companyLocation->city : '-'}}</b>
                                                    @if($claim->status !== 'CANCELLED')
                                                        <span moe class="ml-1">
                                                                <a class="text-primary" href="" show start><i class="fa fa-edit"></i></a>
                                                                <form url="/api/claim/putCompanyLocation">
                                                                    <input type="hidden" name="uid" value="{{$claim->uid}}">
                                                                    <div class="mb-2">
                                                                        <select name="companyLocationUid" class="form-control form-control-sm">
                                                                            <option value="">-- select --</option>
                                                                            @if($claim->company && $claim->company->locations)
                                                                                @foreach($claim->company->locations as $location)
                                                                                    <option value="{{$location->uid}}"
                                                                                            {{$claim->companyLocation && $claim->companyLocation->uid === $location->uid ? 'selected' : ''}}>
                                                                                        {{$location->line1 . ', ' . $location->city}}
                                                                                    </option>
                                                                                @endforeach
                                                                            @endif
                                                                        </select>
                                                                    </div>
                                                                    <div class="mb-0">
                                                                        <button class="btn btn-success btn-sm" submit>Submit</button>
                                                                        <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                                                    </div>
                                                                </form>
                                                            </span>
                                                        @if($claim->companyLocation)
                                                            <span moe class="ml-1">
                                                                <a class="text-danger" href="" show start><i class="fa fa-trash-alt"></i></a>
                                                                <form url="/api/claim/wipeCompanyLocation">
                                                                    <input type="hidden" name="uid" value="{{$claim->uid}}">
                                                                    <p>Wipe location from this claim?</p>
                                                                    <div class="mb-0">
                                                                        <button class="btn btn-primary btn-sm" submit>Submit</button>
                                                                        <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                                                    </div>
                                                                </form>
                                                            </span>
                                                        @endif
                                                    @endif
                                                </div>
                                            </div>
                                            --}}
                                        </td>
                                        <td class="p-0 border-left border-right">
                                            <table class="table table-sm table-condensed border-0 mb-0">
                                                @if($claim->status !== 'CANCELLED')
                                                    <thead>
                                                    <tr class="">
                                                        <th colspan="3" class="border-top-0 border-bottom">
                                                            <div>
                                                                    <span moe class="d-block" title="Submit Claim">
                                                                        <a class="" href="" show start>Generate Submission to Payer (1°)</a>
                                                                        <form url="/api/mbClaim/createFromClaimForPrimaryPayer">
                                                                            <input type="hidden" name="claimUid" value="{{$claim->uid}}">
                                                                            <p>Generate Submission?</p>
                                                                            <div class="mb-0">
                                                                                <button class="btn btn-primary btn-sm" submit>Submit</button>
                                                                                <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                                                            </div>
                                                                        </form>
                                                                    </span>
                                                            </div>
                                                        </th>
                                                    </tr>
                                                    </thead>
                                                @endif
                                                @if(count($claim->mbClaims))
                                                    <thead>
                                                    <tr class="bg-light">
                                                        <th class="border-0">Created</th>
                                                        <th class="border-0">Status</th>
                                                        <th class="border-0">&nbsp;</th>
                                                    </tr>
                                                    </thead>
                                                    <tbody class="pb-3">
                                                    @foreach($claim->mbClaims as $mbClaim)
                                                        <tr>
                                                            <td>
                                                                @if($mbClaim->claim_version_id !== $claim->current_version_id)
                                                                    <i class="fa fa-exclamation-triangle text-warning-mellow text-sm" title="This submission was generated using an older version of the claim"></i>
                                                                @else
                                                                    <i class="fa fa-asterisk text-secondary text-sm" title="This submission is up to date"></i>
                                                                @endif
                                                                <a native target="_blank"
                                                                   open-in-stag-popup
                                                                   title="Submission Details"
                                                                   href="{{route('mb-claim', ['patient' => $patient, 'mbClaim' => $mbClaim])}}">
                                                                    {{ friendlier_date_time($mbClaim->created_at) }}
                                                                </a>
                                                            </td>
                                                            <td>
                                                                {{$mbClaim->status}}
                                                                @if($mbClaim->status_memo)
                                                                    <div class="font-italic text-secondary text-sm">{{$mbClaim->status_memo}}</div>
                                                                @endif
                                                            </td>
                                                            <td class="text-right pr-2">
                                                                     <span moe relative title="Submit Claim">
                                                                        <a class="" href="" show start><i class="fa fa-edit"></i></a>
                                                                        <form url="/api/mbClaim/updateStatus" right>
                                                                            <input type="hidden" name="uid" value="{{$mbClaim->uid}}">
                                                                            <div class="form-group">
                                                                                <label for="" class="control-label">Status</label>
                                                                                <select name="status" class="form-control form-control-sm" required>
                                                                                    <option value="">-- select --</option>
                                                                                    <option value="NEW" {{$mbClaim->status === 'NEW' ? 'selected' : ''}}>New</option>
                                                                                    <option value="PROCESSING" {{$mbClaim->status === 'PROCESSING' ? 'selected' : ''}}>Processing</option>
                                                                                    <option value="SUBMITTED" {{$mbClaim->status === 'SUBMITTED' ? 'selected' : ''}}>Submitted</option>
                                                                                </select>
                                                                            </div>
                                                                            <div class="form-group">
                                                                                <label for="" class="control-label">Status Memo</label>
                                                                                <textarea name="memo" class="form-control"></textarea>
                                                                            </div>
                                                                            <div class="mb-0">
                                                                                <button class="btn btn-primary btn-sm" submit>Submit</button>
                                                                                <button class="btn btn-default border btn-sm" cancel>Cancel</button>
                                                                            </div>
                                                                        </form>
                                                                    </span>
                                                                <a class="ml-1" target="_blank" native href="/api/mbClaim/downloadEDI/{{$mbClaim->uid}}" show start><i class="fa fa-file-download"></i></a>
                                                                <a class="ml-1 text-success" href="" show start><i class="fa fa-arrow-right"></i></a>
                                                            </td>
                                                        </tr>
                                                    @endforeach
                                                    </tbody>
                                                @else
                                                    <tbody>
                                                    <tr>
                                                        <td colspan="3">
                                                            <p class="p-1 text-secondary m-0">No submissions in this claim</p>
                                                        </td>
                                                    </tr>
                                                    </tbody>
                                                @endif
                                            </table>
                                        </td>
                                    </tr>
                                @endif
                            @endforeach
                            </tbody>
                        </table>
                    </div>
                @else
                    <div class="d-flex">
                        <p class="font-weight-bold mb-0">No claims in this care month</p>
                        @include('app/patient/care-month/_create-claim')
                    </div>
                @endif
            @endif

        @endif


    </div>

    <link href='/fullcalendar-5.3.2/lib/main.css' rel='stylesheet' />
    <script src='/fullcalendar-5.3.2/lib/main.js'></script>
    <script>
        (function() {
            function init() {
                $('#care-month-container [cm-rte]').each(function() {

                    $(this).wrap(
                        $('<div class="border-left border-right rte-holder"/>')
                            .attr('data-shortcuts', '')
                    );

                    // give a unique id to this editor instance
                    var editorID = Math.ceil(Math.random() * 99999), fieldName = $(this).attr('data-name');

                    var el = this;
                    var existingContent = $(el).attr('data-content');
                    var quill = new Quill(el, {
                        theme: 'snow',
                        modules: stagQuillConfig
                    });

                    var toolbar = $(quill.container).prev('.ql-toolbar');

                    // add button for new shortcut
                    var newSCButton = $('<button class="btn bg-white btn-sm btn-default text-primary w-auto px-2 border py-0 ' +
                        'text-sm add-shortcut" data-editor-id="' + editorID + '">+ Shortcut</button>');
                    toolbar.append(newSCButton);

                    quill.root.innerHTML = existingContent;

                    $('<input type="hidden" name="' + fieldName + '">').val(existingContent).insertAfter(el);

                    quill.on('text-change', function(delta, oldDelta, source) {
                        $(el).next('[name="' + fieldName + '"]').val(quill.root.innerHTML);
                    });

                    $(quill.container)
                        .find('.ql-editor[contenteditable]')
                        .attr('data-field', fieldName)
                        .attr('data-editor-id', editorID)
                        .attr('with-shortcuts', 1);

                });

                // init calendar view
                @if(count($plottableMeasurements))
                $('#caremonth-measurements-calendar').closest('.d-none').removeClass('d-none');
                let measurementsCalendar = new FullCalendar.Calendar($('#caremonth-measurements-calendar')[0], {
                    headerToolbar: false,
                    initialView: 'dayGridMonth',
                    initialDate: '{{ date('Y-m-d', strtotime($careMonth->created_at)) }}',
                    navLinks: false,
                    dayMaxEvents: false,
                    slotMinTime: '00:00',
                    slotMaxTime: '23:59',
                    scrollTime: '06:00:00',
                    slotDuration: '00:15:00',
                    events: function(info, successCallback, failureCallback) {
                        successCallback({!! json_encode($plottableMeasurements) !!});
                    },
                    eventClassNames: function(arg) {
                        let classes = [];
                        if (arg.event.extendedProps.label === 'Wt. (lbs.)') {
                            classes.push('m-weight');
                        }
                        if (arg.event.extendedProps.label === 'BP') {
                            classes.push('m-bp');
                        }
                        return classes;
                    },
                    eventClick: function(info) {
                        // self.selectedEvent = info.event;
                        // self.showEditAppointmentModal();
                    }
                });

                window.setTimeout(() => { measurementsCalendar.render();}, 10);

                @endif
            }

            addMCInitializer('care-month-dashboard', init, '#care-month-container');

        }).call(window);
    </script>

    @endif
@endsection
