@if($pro->pro_type === 'ADMIN')
<div class="p-3 border-bottom screen-only" data-non-segment-section="Payments">
    <div>
        <h2 class="d-inline-block font-weight-bold text-secondary">Payments Received</h2>
        <div moe class="ml-1 d-inline-block">
            <a class="text-danger" href="" show start><i class="fa fa-plus"></i> Add payment received</a>
            <form url="/api/receivedPayment/createForNote">
                <input type="hidden" name="noteUid" value="{{$note->uid}}">
                <div class="mb-2">
                    <label class="mb-1 text-secondary">Service Code</label>
                    <input type="text" name="serviceCode" placeholder="Service code"
                              class="form-control form-control-sm"></input>
                </div>
                <div class="mb-2">
                    <label class="mb-1 text-secondary">Modifier</label>
                    <input type="text" name="modifier" placeholder="Modifier"
                           class="form-control form-control-sm"></input>
                </div>
                <div class="mb-2">
                    <label class="mb-1 text-secondary">Charged Amount</label>
                    <input type="number" step=".01" name="chargedAmount" placeholder="Charged Amount"
                           class="form-control form-control-sm"></input>
                </div>
                <div class="mb-2">
                    <label class="mb-1 text-secondary">Charged Amount Status</label>
                    <select type="text" name="chargedAmountStatus" placeholder="Charged Amount Status"
                           class="form-control form-control-sm">
                        <option value="NEW">New</option>
                        <option value="PENDING">Pending</option>
                        <option value="SUBMITTED">Submitted</option>
                    </select>
                </div>
                <div class="mb-2">
                    <label class="mb-1 text-secondary">Allowed Amount</label>
                    <input type="number" step=".01" name="allowedAmount" placeholder="Allowed Amount"
                           class="form-control form-control-sm"></input>
                </div>
                <div class="mb-2">
                    <label class="mb-1 text-secondary">Primary Insurance</label>
                    <input type="number" step=".01" name="primaryInsuranceAmount" placeholder="Primary Insurance"
                           class="form-control form-control-sm"></input>
                </div>
                <div class="mb-2">
                    <label class="mb-1 text-secondary">Primary Insurance Payment Status</label>
                    <select type="text" name="primaryAmountStatus" placeholder="Primary Insurance Payment Status"
                            class="form-control form-control-sm">
                        <option value="PAID">Paid</option>
                        <option value="DENIED">Denied</option>
                        <option value="APPEALED">Appealed</option>
                        <option value="REJECTED">Rejected</option>
                        <option value="PAYMENT_RECEIVED">Payment Received</option>
                        <option value="WAIVED">Waived</option>
                    </select>
                </div>
                <div class="mb-2">
                    <label class="mb-1 text-secondary">Secondary Insurance</label>
                    <input type="number" step=".01" name="secondaryInsuranceAmount" placeholder="Secondary Insurance"
                           class="form-control form-control-sm"></input>
                </div>
                <div class="mb-2">
                    <label class="mb-1 text-secondary">Secondary Insurance Payment Status</label>
                    <select type="text" name="secondaryAmountStatus" placeholder="Secondary Insurance Payment Status"
                            class="form-control form-control-sm">
                        <option value="PAID">Paid</option>
                        <option value="DENIED">Denied</option>
                        <option value="APPEALED">Appealed</option>
                        <option value="REJECTED">Rejected</option>
                        <option value="PAYMENT_RECEIVED">Payment Received</option>
                        <option value="WAIVED">Waived</option>
                    </select>
                </div>
                <div class="mb-2">
                    <label class="mb-1 text-secondary">Patient Responsibility</label>
                    <input type="number" step=".01" name="patientResponsibilityAmount" placeholder="Patient Responsibility Amount"
                           class="form-control form-control-sm"></input>
                </div>
                <div class="mb-2">
                    <label class="mb-1 text-secondary">Patient Responsibility Payment Status</label>
                    <select type="text" name="patientResponsibilityAmountStatus" placeholder="Patient Responsibility Payment Status"
                            class="form-control form-control-sm">
                        <option value="PAID">Paid</option>
                        <option value="DENIED">Denied</option>
                        <option value="APPEALED">Appealed</option>
                        <option value="REJECTED">Rejected</option>
                        <option value="PAYMENT_RECEIVED">Payment Received</option>
                        <option value="WAIVED">Waived</option>
                    </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>
        </div>
        <div class="d-flex justify-content-center align-items-start">
            <table class="mr-2 w-75 flex-grow-1 table-bordered table-condensed table-sm table-striped">
                <thead>
                    <tr>
                        <th>Service Code</th>
                        <th>Charged Amount</th>
                        <th>Allowed Amount</th>
                        <th>Adjustment</th>
                        <th>Primary Insurance</th>
                        <th>Secondary Insurance</th>
                        <th>Patient Responsiblity</th>
                        <th>Balance</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                @foreach($note->receivedPayments as $rp)
                <tr>
                    <td class="text-secondary">
                        {{$rp->service_code}}({{$rp->modifier}})
                    </td>
                    <td>{{friendly_money($rp->charged_amount)}} ({{$rp->charged_amount_status}})</td>
                    <td>${{friendly_money($rp->allowed_amount)}}</td>
                    <td>${{friendly_money($rp->adjustment)}}</td>
                    <td>{{friendly_money($rp->primary_insurance_amount)}} ({{$rp->primary_amount_status}})</td>
                    <td>{{friendly_money($rp->secondary_insurance_amount)}} ({{$rp->secondary_amount_status}})</td>
                    <td>{{friendly_money($rp->patient_responsibility_amount)}} ({{$rp->patient_responsibility_amount_status}})</td>
                    <td>{{friendly_money($rp->balance)}}</td>
                    <td>
                        @if($rp->is_active)
                            <i class="fa fa-check"></i>
                            <div moe class="ml-1 d-inline-block">
                                <a class="text-danger" href="" show start> Deactivate</a>
                                <form url="/api/receivedPayment/deactivate">
                                    <input type="hidden" name="uid" value="{{$rp->uid}}">
                                    <div class="mb-2">
                                        <label class="mb-1 text-secondary">Memo</label>
                                        <textarea type="text" name="memo" placeholder="Source memo"
                                                  class="form-control form-control-sm"></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>

                            <i class="fa fa-check"></i>
                            <div moe class="ml-1 d-inline-block">
                                <a class="text-danger" href="" show start> Update</a>
                                <form url="/api/receivedPayment/deactivate">
                                    <input type="hidden" name="uid" value="{{$rp->uid}}">
                                    <div class="mb-2">
                                        <label class="mb-1 text-secondary">Service Code</label>
                                        <input type="text" name="serviceCode" placeholder="Service code"
                                               class="form-control form-control-sm" value="{{$rp->service_code}}"></input>
                                    </div>
                                    <div class="mb-2">
                                        <label class="mb-1 text-secondary">Modifier</label>
                                        <input type="text" name="modifier" placeholder="Modifier"
                                               class="form-control form-control-sm" value="{{$rp->modifier}}"></input>
                                    </div>
                                    <div class="mb-2">
                                        <label class="mb-1 text-secondary">Charged Amount</label>
                                        <input type="number" step=".01" name="chargedAmount" placeholder="Charged Amount"
                                               class="form-control form-control-sm" value="{{$rp->charged_amount}}"></input>
                                    </div>
                                    <div class="mb-2">
                                        <label class="mb-1 text-secondary">Charged Amount Status</label>
                                        <select type="text" name="chargedAmountStatus" placeholder="Charged Amount Status"
                                                class="form-control form-control-sm">
                                            <option {{$rp->charged_amount_status == 'NEW'? 'checked':'' }} value="NEW">New</option>
                                            <option {{$rp->charged_amount_status == 'PENDING'? 'checked':'' }} value="PENDING">Pending</option>
                                            <option {{$rp->charged_amount_status == 'SUBMITTED'? 'checked':'' }} value="SUBMITTED">Submitted</option>
                                        </select>
                                    </div>
                                    <div class="mb-2">
                                        <label class="mb-1 text-secondary">Allowed Amount</label>
                                        <input type="number" step=".01" name="allowedAmount" placeholder="Allowed Amount"
                                               class="form-control form-control-sm" value="{{$rp->allowed_amount}}"></input>
                                    </div>
                                    <div class="mb-2">
                                        <label class="mb-1 text-secondary">Primary Insurance</label>
                                        <input type="number" step=".01" name="primaryInsuranceAmount" placeholder="Primary Insurance"
                                               class="form-control form-control-sm" value="{{$rp->primary_insurance_amount}}"></input>
                                    </div>
                                    <div class="mb-2">
                                        <label class="mb-1 text-secondary">Primary Insurance Payment Status</label>
                                        <select type="text" name="primaryAmountStatus" placeholder="Primary Insurance Payment Status"
                                                class="form-control form-control-sm">
                                            <option {{$rp->primary_amount_status == 'PAID'? 'checked' : ''}} value="PAID">Paid</option>
                                            <option {{$rp->primary_amount_status == 'DENIED'? 'checked' : ''}} value="DENIED">Denied</option>
                                            <option {{$rp->primary_amount_status == 'APPEALED'? 'checked' : ''}} value="APPEALED">Appealed</option>
                                            <option {{$rp->primary_amount_status == 'REJECTED'? 'checked' : ''}} value="REJECTED">Rejected</option>
                                            <option {{$rp->primary_amount_status == 'PAYMENT_RECEIVED'? 'checked' : ''}} value="PAYMENT_RECEIVED">Payment Received</option>
                                            <option {{$rp->primary_amount_status == 'WAIVED'? 'checked' : ''}} value="WAIVED">Waived</option>
                                        </select>
                                    </div>
                                    <div class="mb-2">
                                        <label class="mb-1 text-secondary">Secondary Insurance</label>
                                        <input type="number" step=".01" name="secondaryInsuranceAmount" placeholder="Secondary Insurance"
                                               class="form-control form-control-sm" value="{{$rp->secondary_insurance_amount}}"></input>
                                    </div>
                                    <div class="mb-2">
                                        <label class="mb-1 text-secondary">Secondary Insurance Payment Status</label>
                                        <select type="text" name="secondaryAmountStatus" placeholder="Secondary Insurance Payment Status"
                                                class="form-control form-control-sm">
                                            <option {{$rp->secondary_amount_status == 'PAID' ? 'checked': ''}} value="PAID">Paid</option>
                                            <option {{$rp->secondary_amount_status == 'DENIED' ? 'checked': ''}} value="DENIED">Denied</option>
                                            <option {{$rp->secondary_amount_status == 'APPEALED' ? 'checked': ''}} value="APPEALED">Appealed</option>
                                            <option {{$rp->secondary_amount_status == 'REJECTED' ? 'checked': ''}} value="REJECTED">Rejected</option>
                                            <option {{$rp->secondary_amount_status == 'PAYMENT_RECEIVED' ? 'checked': ''}} value="PAYMENT_RECEIVED">Payment Received</option>
                                            <option {{$rp->secondary_amount_status == 'WAIVED' ? 'checked': ''}} value="WAIVED">Waived</option>
                                        </select>
                                    </div>
                                    <div class="mb-2">
                                        <label class="mb-1 text-secondary">Patient Responsibility</label>
                                        <input type="number" step=".01" name="patientResponsibilityAmount" placeholder="Patient Responsibility Amount"
                                               class="form-control form-control-sm" value="{{$rp->patient_responsibility_amount}}"></input>
                                    </div>
                                    <div class="mb-2">
                                        <label class="mb-1 text-secondary">Patient Responsibility Payment Status</label>
                                        <select type="text" name="patientResponsibilityAmountStatus" placeholder="Patient Responsibility Payment Status"
                                                class="form-control form-control-sm">
                                            <option {{$rp->patient_responsibility_status == 'PAID' ? 'checked': ''}} value="PAID">Paid</option>
                                            <option {{$rp->patient_responsibility_status == 'DENIED' ? 'checked': ''}} value="DENIED">Denied</option>
                                            <option {{$rp->patient_responsibility_status == 'APPEALED' ? 'checked': ''}} value="APPEALED">Appealed</option>
                                            <option {{$rp->patient_responsibility_status == 'REJECTED' ? 'checked': ''}} value="REJECTED">Rejected</option>
                                            <option {{$rp->patient_responsibility_status == 'PAYMENT_RECEIVED' ? 'checked': ''}} value="PAYMENT_RECEIVED">Payment Received</option>
                                            <option {{$rp->patient_responsibility_status == 'WAIVED' ? 'checked': ''}} value="WAIVED">Waived</option>
                                        </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>
                            </div>

                        @else
                            <i class="fa fa-cancel"></i>
                            <div moe class="ml-1 d-inline-block">
                                <a class="text-danger" href="" show start> Reactivate</a>
                                <form url="/api/receivedPayment/reactivate">
                                    <input type="hidden" name="uid" value="{{$rp->uid}}">
                                    <div class="mb-2">
                                        <label class="mb-1 text-secondary">Memo</label>
                                        <textarea type="text" name="memo" placeholder="Source memo"
                                                class="form-control form-control-sm"></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>
                </tr>
                @endforeach
                @if(!count($note->receivedPayments))
                    <tr>
                        <td colspan="9">No records found!</td>
                    </tr>
                @endif
                </tbody>
            </table>
            <table class="w-25 flex-grow-1 table-bordered table-condensed table-sm table-striped">
                <tbody>
                <tr>
                    <td class="text-secondary">Bill Total Exp.</td>
                    <td>${{friendly_money($note->bill_total_expected)}}</td>
                </tr>
                <tr>
                    <td class="text-secondary">Is Billing Closed</td>
                    <td>{{$note->is_bill_closed ? 'Yes' : 'No'}}</td>
                </tr>
                <tr>
                    <td class="text-secondary">Bill Summary</td>
                    <td>{{$note->bill_summary ? $note->bill_summary : '-'}}</td>
                </tr>
                <tr>
                    <td class="text-secondary">Bill Total Paid</td>
                    <td>${{friendly_money($note->bill_total_paid)}}</td>
                </tr>
                <tr>
                    <td class="text-secondary">Billing Closed At</td>
                    <td>{{friendlier_date_time($note->bill_closed_at)}}</td>
                </tr>
                <tr>
                    <td class="text-secondary">Payments Received Total</td>
                    <td>{{friendly_money($note->received_payments_total)}}</td>
                </tr>
                <tr>
                    <td class="text-secondary">Gross margin</td>
                    <td>{{friendly_money($note->gross_margin)}}</td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>
@endif
