<!DOCTYPE html>
<html class="no-js" lang="en" dir="ltr">
<head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Invoice No. {{ patientBilling.invoiceNo }}</title>
</head>
<body style="font-family:'Arial'; font-size:15px;">
<div style="width: 816px; height: 1056px; box-sizing:border-box; padding:80px; padding-top:30px; margin: 0 auto; box-shadow:3px 1px 10px 1px;">
    {% set patient = patientBilling.patient %}
    {% set branch = patientBilling.healthFacilityForAddress|default('') %}
    {% set company = patientBilling.healthFacilityForAddress.company|default('') %}
    {% set street = patientBilling.healthFacilityForAddress.street|default('') %}
    {% set city = patientBilling.healthFacilityForAddress.city.description|default('') %}
    {% set postalCode = patientBilling.healthFacilityForAddress.postalCode.description|default('') %}
    {% if hasPrintBtn is defined and hasPrintBtn %}
        <div style="text-align: right; margin-bottom: 25px;">
            <a style="display: inline-block; padding: 10px 20px; border: 1px solid #e0e0e0; border-radius: 3px; color: #353535;" href="{{ path('patient_billing_invoice_print', {id: patientBilling.idEncoded}) }}">Download</a>
        </div>
    {% endif %}
    <div style="width:100%; height: 200px; position: relative;">
        <div style="width: 60%; height: 100%; float: left; text-align: left;">
            {% if patientBilling.payerType != 'Financing' %}
                <img src="{{ app.request.getSchemeAndHttpHost() ~ company.photoWebPath|default('') }}" style="width: 40%;"/>
            {% else %}
            {% endif %}
            <h3 style="margin:0;"><strong>{{ company.description|default('') }}</strong></h3>
            <p style="margin:0;"><i>"Your premium CPAP provider"</i></p>
            <p style="margin:0;">{{ street }}</p>
            <p style="margin:0;">{{ city }} {{ postalCode }}</p>
            <p style="margin:0;">Phone : {{ branch.concatenatedPhoneNo|default('') }}</p>
            <p style="margin:0;">Fax : {{ branch.concatenatedMobileNo|default('') }}</p>
            <p style="margin:0;">Email : {{ branch.concatenatedEmail|default('') }}</p>
        </div>
        <div style="width: 40%; height: 100%; float: right; text-align: right;">
            <h1 style="margin:0; margin-bottom:20px;">INVOICE</h1>
            <table style="float: right;">
                <tr style="margin:0;">
                    <td style="padding-right: 30px; text-align: left;">DATE:</td>
                    <td style="text-align: center; border: 1px solid #000; padding: 0 5px; background-color: #cacaca;">{{ patientBilling.billingDateAsString|date('F j, Y') }}</td>
                </tr>
                <tr>
                    <td style="padding-right: 30px; text-align: left;">INVOICE #:</td>
                    <td style="text-align: center; border: 1px solid #000; padding: 0 5px;">{{ patientBilling.invoiceNo ? patientBilling.invoiceNo : patientBilling.prevSysInvoiceNo }}</td>
                </tr>
                <tr>
                    <td style="padding-right: 30px; text-align: left;">CUSTOMER ID:</td>
                    <td style="text-align: center; border: 1px solid #000; padding: 0 5px;">{{ patient.id }}</td>
                </tr>
            </table>
        </div>
    </div>
    <div style="width: 100%; margin-bottom: 10px;">
        <div style="background-color: #717171; padding:5px 15px; width: 50%; height: 20px; color:#fff;"><strong>BILL TO</strong></div>
        <p style="margin:0;"><strong>{{ patient.fullName }}</strong></p>
        {#<p style="margin:0;">[Company Name Name]</p>#}
        <p style="margin:0;">{{ patient.street }}</p>
        <p style="margin:0;">{{ patient.city.description|default('') ~ ', ' ~ patient.city.province.description|default('') ~ ' ' ~ patient.postalCode.description('') }}</p>
        <p style="margin:0;">{{ patient.concatenatedPhoneNo }}</p>
    </div>
    <div style="width: 100%;">
        <table width="100%" style="border-collapse: collapse;">
            <thead style="background-color: #717171; text-align: center;">
            <td style="padding: 5px; color:#fff;"><strong>DESCRIPTION</strong></td>
            <td style="padding: 5px; color:#fff;text-align: right"><strong>QUANTITY</strong></td>
            <td style="padding: 5px; color:#fff;text-align: right"><strong>RATE</strong></td>
            <td style="padding: 5px; color:#fff;text-align: right"><strong>AMOUNT</strong></td>
            </thead>
            <tbody style="border:1px solid #717171;">
            {% set status = '' %}
            {% set totalReturnAmt = 0 %}
            {% set isReturn = 0 %}

            {#{% set refundAmt = 0 %}#}
            {#{% if patientBilling.patientBillingRefunds|length > 0 %}#}
                {#{% for refunds in patientBilling.patientBillingRefunds %}#}
                    {#{% set refundAmt = refundAmt + refunds.amount %}#}
                {#{% endfor %}#}
            {#{% endif %}#}

            {% for pbb in patientBilling.patientBillingBreakdowns %}
                {% set status = pbb.status|default('') %}
                {% set pc = pbb.patientChart %}
                {% set description = pbb.description %}

                {% if status == 'Return' %}
                    {% set isReturn = 1 %}
                    {% set totalReturnAmt = totalReturnAmt + pbb.amount %}
                {% endif %}

                {% if constant('RxconnexionBundle\\Entity\\PatientBillingBreakdownEntity::TYPE_CHART_PROCEDURE') == pbb.type %}
                    {% set description = pbb.chartProcedure.description %}
                {% elseif constant('RxconnexionBundle\\Entity\\PatientBillingBreakdownEntity::TYPE_ITEM') == pbb.type %}
                    {% set description = pbb.item.description %}
                {% endif %}
                
                <tr>
                    <td style="padding:5px; ">{{ description }}</td>
                    <td style="border-left:1px solid #717171; padding:5px; text-align: right; font-size:15px;">{{ pbb.invoicequantity|number_format(0, '.', ',') }}</td>
                    <td style="border-left:1px solid #717171; padding:5px; text-align: right; font-size:15px;">{{ pbb.invoiceprice|number_format(2, '.', ',') }}</td>
                    <td style="border-left:1px solid #717171; padding:5px; text-align: right;">{{ pbb.invoiceamount|number_format(2, '.', ',') }}</td>
                </tr>
            {% endfor %}
            </tbody>
        </table>
    </div>
    <div style="width: 100%; padding-top: 20px;">
        <table width="100%" style="border-collapse: collapse;">
            <thead style="background-color: #717171; text-align: center;">
            <td style="padding: 5px; color:#fff;"><strong>DATE</strong></td>
            <td style="padding: 5px; color:#fff;"><strong>PAYMENT</strong></td>
            <td style="padding: 5px; color:#fff;"><strong>AMOUNT</strong></td>
            </thead>
            <tbody style="border:1px solid #717171;">
            {% for pp in patientBilling.patientPayments if pp.paymentStatus != constant('RxconnexionBundle\\Entity\\PatientPaymentEntity::PAYMENT_STATUS_VOID') %}
                {% set payType = pp.payTypeForPrint %}
                {% set amount = pp.amount %}
                {% set payDate = pp.payDateAsString|date('F j, Y') %}
                <tr>
                    <td style="border-right:1px solid #717171; text-align: center;">{{ payDate }}</td>
                    <td style="text-align: center;">{{ payType }}</td>
                    <td style="border-left:1px solid #717171; text-align: right;">{{ amount|number_format(2, '.', ',') }}</td>
                </tr>
            {% endfor %}
            </tbody>
        </table>
    </div>
    <div style="width: 100%; margin-top:20px;">
        {#<div style="width: 60%; float: left;">
            <div style="width: 100%; height: auto; border: 1px solid #717171;">
                <div style="width:95%; height: 20px; padding:3px 10px; color:#fff; background-color: #717171;">
                    <strong>OTHER COMMENTS</strong>
                </div>
                <div style="width: 100%; padding:15px;">
                    <div>{{ patientBilling.comment|raw }}</div>
                </div>
            </div>
        </div>#}
        <div style="width: 40%; float: right;">
            <table width="100%" style="border-collapse: collapse;">
                <tr style="text-align: right;">
                    <td style="width:15px;">&nbsp;</td>
                    <td>Subtotal</td>
                    <td style="width: 20px;">&#36;</td>
                    {#<td style="width: 100px;">{{ patientBilling.patientBillingRefunds|length > 0 or isReturn == 1 ? (patientBilling.amountDue + totalReturnAmt)|number_format(2, '.', ',') : patientBilling.amountDue|number_format(2, '.', ',') }}</td>#}
                    <td style="width: 100px;">{{ patientBilling.invoiceamountDue|number_format(2, '.', ',') }}</td>
                </tr>
                <tr style="text-align: right;">
                    <td style="width:15px;">&nbsp;</td>
                    <td>Payment</td>
                    <td style="width: 20px;">&#36;</td>
                    <td style="width: 100px;">{{ patientBilling.amountPaid|number_format(2, '.', ',') }}</td>
                </tr>
                {#<tr style="text-align: right;">
                    <td>Taxable</td>
                    <td style="width: 20px;">&#36;</td>
                    <td style="width: 100px;">0</td>
                </tr>
                <tr style="text-align: right;">
                    <td>Tax Rate</td>
                    <td style="width: 20px;">#}{#&#36;#}{#</td>
                    <td style="width: 100px;">0%</td>
                </tr>
                <tr style="text-align: right;">
                    <td>Tax Due</td>
                    <td style="width: 20px;">&#36;</td>
                    <td style="width: 100px;">0</td>
                </tr>
                <tr style="text-align: right;">
                    <td>Other</td>
                    <td style="width: 20px;">&#36;</td>
                    <td style="width: 100px; border-bottom:3px solid #000;">0</td>
                </tr>#}

                <tr style="text-align: right;">
                    <td style="width:35px;">&nbsp;</td>
                    <td style="border-top: 3px solid #000;"><strong>TOTAL DUE</strong></td>
                    <td style="width: 20px; border-top: 3px solid #000;"><strong>&#36;</strong></td>
                    {#<td style="width: 100px; background-color: #cacaca; border-top: 3px solid #000;"><strong>{{ patientBilling.patientBillingRefunds|length > 0 or isReturn == 1 ? (patientBilling.amountBalance + totalReturnAmt - patientBilling.amountRefunded|default(0))|number_format(2, '.', ',') : patientBilling.amountBalance|number_format(2, '.', ',') }}</strong></td>#}
                    <td style="width: 100px; background-color: #cacaca; border-top: 3px solid #000;"><strong>{{ patientBilling.invoiceamountBalance|number_format(2, '.', ',') }}</strong></td>
                </tr>
            </table>
        </div>
    </div>

    <div style="width:50%; height: 155px; float:left;">
        <br>
        <br>
        <p>{{ patientBilling.note }}</p>
        <h5>ALL SALES ARE FINAL</h5>
    </div>
    {% if branch.phoneNo|default('') != '' and branch.email|default('') != '' %}
        <div style="width: 100%; margin-top: 300px; text-align: center;">
            <h5>If you have questions about this invoice please contact:</h5>
            <h5>{{ branch.description|default('') ~ ', ' ~ branch.phoneNo|default('') ~ ', ' ~ branch.email|default('') }}</h5>
            <p><i>Thank you for your business!</i></p>
        </div>
    {% elseif branch.phoneNo|default('') != '' and branch.email|default('') == '' %}
        <div style="width: 100%; margin-top: 200px; text-align: center;">
            <h5>If you have questions about this invoice please contact:</h5>
            <h5>{{ branch.description|default('') ~ ', ' ~ branch.phoneNo|default('') }}</h5>
            <p><i>Thank you for your business!</i></p>
        </div>
    {% elseif branch.phoneNo|default('') == '' and branch.email|default('') != '' %}
        <div style="width: 100%; margin-top: 200px; text-align: center;">
            <h5>If you have questions about this invoice please contact:</h5>
            <h5>{{ branch.description|default('') ~ ', ' ~ branch.email|default('') }}</h5>
            <p><i>Thank you for your business!</i></p>
        </div>
    {% endif %}
</div>
</body>
</html>