<!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 province = patientBilling.healthFacilityForAddress.city.province.description|default('') %}
    {% set postalCode = patientBilling.healthFacilityForAddress.postalCode.description|default('') %}
    <div style="width:100%; height: 90px; position: relative;">
        {% if patientBilling.payerType != 'Financing' %}
            <div style="width:50%; float: left;">
                {#<p style="font-size:16px; font-weight:500; margin-top:0; margin-bottom:5px;"><b>{{ company.description|default('') }}</b></p>#}
                <p style="font-size:16px; font-weight:500; margin-top:0; margin-bottom:5px;"><b>{{ company.description|default('') }}</b></p>
                {#<p style="font-size:16px; font-weight:500; margin-top:0; margin-bottom:5px;"><b>{{ branch.description|default('') }}</b></p>#}
                <p style=" margin:3px 0; font-size: 12px;">{{ street }}</p>
                <p style=" margin:3px 0; font-size: 12px;">{{ city }} {{ ', '~province }} {{ postalCode }}</p>
                <p style=" margin:3px 0; font-size: 12px;">{{ branch.concatenatedPhoneNo|default('') }}</p>
                <p style=" margin:3px 0; font-size: 12px;">{{ branch.concatenatedMobileNo|default('') }}</p>
                <p style=" margin:3px 0; font-size: 12px;">{{ branch.email|default('') }}</p>
                <p style=" margin:3px 0; font-size: 12px;">{{ branch.emailTwo|default('') }}</p>
                <p style=" margin:3px 0; font-size: 12px;">{{ branch.emailThree|default('') }}</p>
            </div>
        {% else %}
            {% set financingCompany = patientBilling.patientPaymentFinancing.financingCompany %}
            <div style="width:50%; float: left;">
                <p style="font-size:18px; font-weight:500; margin-top:0; margin-bottom:5px;"><b>{{ financingCompany.description }}</b></p>
                <p style=" margin:3px 0;">{{ financingCompany.street }}</p>
                <p style=" margin:3px 0;">{{ financingCompany.city.description }} {{ financingCompany.postalCode.description }}</p>
                <p style=" margin:3px 0;">{{ financingCompany.concatenatedPhoneNo|default('') }}</p>
                <p style=" margin:3px 0;">{{ financingCompany.concatenatedMobileNo|default('') }}</p>
                <p style=" margin:3px 0;">{{ financingCompany.concatenatedEmail|default('') }}</p>
                {#<p style="margin-top:8px; margin-bottom:0; font-size:18px; color: darkblue; font-weight:500;">INVOICE</p>#}
            </div>
        {% endif %}
        <div style="width:50%; height:auto; float: right; text-align: right;">
            {% if patientBilling.payerType != 'Financing' %}
                <img src="{{ app.request.getSchemeAndHttpHost() ~ company.photoWebPath|default('') }}" style="width: 85%;"/>
            {% else %}
                <img src="{{ app.request.getSchemeAndHttpHost() ~ patientBilling.patientPaymentFinancing.financingCompany.photoWebPath is defined and patientBilling.patientPaymentFinancing.financingCompany.photoWebPath is not empty ? app.request.getSchemeAndHttpHost() ~ patientBilling.patientPaymentFinancing.financingCompany.photoWebPath : '/uploads/company/photo/'~patientBilling.patient.healthFacility.company.parsedPhotoDescription|default('') }}" style="width: 60%;"/>
            {% endif %}
        </div>
    </div>
    <br>
    <br>
    <br>
    <div style="width:100%; height: 135px; position: relative;">
        <div style="width:50%; height: 155px; float:left;">
            <div style="box-sizing: border-box; height:auto; width: auto;">
                <div style="width: auto; padding: 5px; background-color: {{ company.description|default('') in ['DSRC Calgary', 'DSRC Edmonton'] ? '#cacaca' : ''  }};">
                    <p style="font-size:15px; margin:0; color: {{ company.description|default('') not in ['DSRC Calgary', 'DSRC Edmonton'] ? '#000' : 'black'  }};"><strong>INVOICE TO</strong></p>
                </div>
                <div style="padding: 5px;">
                    <p style="margin:0; margin-bottom:5px; color:#366289;"><strong>{{ patient.firstName }} {{ patient.lastName }}</strong></p>
                    <p style="margin:0; margin-bottom:2px; font-size: 12px;">{{ patient.street }}</p>
                    <p style="margin:0; margin-bottom:2px; font-size: 12px;">{{ patient.city.description|default('') ~ ', ' ~ patient.city.province.description|default('') }}</p>
                    <p style="margin:0; margin-bottom:2px; font-size: 12px;">{{ patient.postalCode.description|default('') }}</p>
                </div>
            </div>
        </div>
        <br>
        <div style="width:50%; height: 155px; float:right;">
            <div style="width:100%; float:left; box-sizing:border-box; padding-left: 50px;">
                <!--  <div style="height:35px;">

                 </div> -->
                <p style="font-size:12px; font-weight:500; margin-top:0; margin-bottom:7px;"><strong>INVOICE #</strong> : {{ patientBilling.invoiceNo ? patientBilling.invoiceNo : patientBilling.prevSysInvoiceNo }}</p>
                <p style="font-size:12px; font-weight:500; margin-top:0; margin-bottom:7px;"><strong>DATE</strong> : {{ patientBilling.billingDateAsString|date('F j, Y') }}</p>
            </div>
        </div>
    </div>

    <table width="100%" style="border-collapse: collapse;">
        <thead>
        <tr style="border-bottom: 1px #676767;">
            {#<td style="background-color:#cacaca; font-size:15px; padding: 5px;"><strong>DATE</strong></td>
            <td style="background-color:#cacaca; font-size:15px; padding: 5px;"><strong>ACTIVITY</strong></td>#}
            <td style="background-color: {{ company.description|default('') in ['DSRC Calgary', 'DSRC Edmonton'] ? '#cacaca' : ''  }}; border-bottom: {{ company.description|default('') in ['DSRC Calgary', 'DSRC Edmonton'] ? 'none' : 'solid 1px #000'  }}; font-size:13px; padding: 5px; color:#000;"><strong>Description</strong></td>
            <td style="background-color: {{ company.description|default('') in ['DSRC Calgary', 'DSRC Edmonton'] ? '#cacaca' : ''  }}; border-bottom: {{ company.description|default('') in ['DSRC Calgary', 'DSRC Edmonton'] ? 'none' : 'solid 1px #000'  }}; font-size:13px; padding: 5px; text-align: right; color:#000;"><strong>Quantity</strong></td>
            <td style="background-color: {{ company.description|default('') in ['DSRC Calgary', 'DSRC Edmonton'] ? '#cacaca' : ''  }}; border-bottom: {{ company.description|default('') in ['DSRC Calgary', 'DSRC Edmonton'] ? 'none' : 'solid 1px #000'  }}; font-size:13px; padding: 5px; text-align: right; color:#000;"><strong>Rate</strong></td>
            <td style="background-color: {{ company.description|default('') in ['DSRC Calgary', 'DSRC Edmonton'] ? '#cacaca' : ''  }}; border-bottom: {{ company.description|default('') in ['DSRC Calgary', 'DSRC Edmonton'] ? 'none' : 'solid 1px #000'  }}; font-size:13px; padding: 5px; text-align: right; color:#000;"><strong>Amount</strong></td>
        </tr>
        </thead>
        <tbody>
        {% set totalReturnAmt = 0 %}
        {% set status = '' %}
        {% 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('') %}

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

            {% set pc = pbb.patientChart %}
            {% set description = pbb.description %}
            {% 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="font-size:12px;">{{ pc.chartDateAsString|default('') }}</td>
                <td style="font-size:12px;">{{ pc ? 'Services' : 'Misc.' }}</td>#}
                <td style="padding:5px; font-size:12px;">{{ description }}</td>
                <td style="padding:5px; text-align: right; font-size:12px;">{{ pbb.invoicequantity|number_format(0, '.', ',') }}</td>
                <td style="padding:5px; text-align: right; font-size:12px;">{{ pbb.invoiceprice|number_format(2, '.', ',') }}</td>
                <td style="padding:5px; text-align: right; font-size:12px;">{{ pbb.invoiceamount|number_format(2, '.', ',') }}</td>
            </tr>
        {% endfor %}
        {#<tr>
            <td style="height: 30px;"></td>
        </tr>
        <tr>
            <td colspan="3" style="text-align: right;">Total:</td>
            <td style="text-align: right; border-top: 2px solid #aaaaaa;">{{ patientBilling.amountDue|number_format(2, '.', ',') }}</td>
        </tr>
        <tr>
            <td style="height: 20px;"></td>
        </tr>
        <tr>
            <td colspan="3" style="text-align: right;">Payment Made:</td>
            <td style="text-align: right;">{{ patientBilling.amountPaid|number_format(2, '.', ',') }}</td>
        </tr>
        <tr>
            {% if constant('RxconnexionBundle\\Entity\\PatientBillingEntity::PAYER_TYPE_FINANCING') == patientBilling.payerType %}
                <td colspan="3" style="text-align: right;">Balance Due(Financing):</td>
            {% else %}
                <td colspan="3" style="text-align: right;">Balance Due:</td>
            {% endif %}
            <td style="text-align: right; border-top: 4px double #aaaaaa; font-weight: 600; font-size: 18px;">{{ patientBilling.amountBalance|number_format(2, '.', ',') }}</td>
        </tr>#}
        </tbody>
    </table>
    <table width="100%" style="border-collapse: collapse; margin-top: 20px;">
        <thead>
        <tr style="border-bottom: 1px solid #000;">
            <td style="background-color: {{ company.description|default('') in ['DSRC Calgary', 'DSRC Edmonton'] ? '#cacaca' : ''  }}; border: {{ company.description|default('') in ['DSRC Calgary', 'DSRC Edmonton'] ? 'none' : 'none'  }}; font-size:12px; padding: 5px; text-align: left;"><strong>Date</strong></td>
            <td style="background-color: {{ company.description|default('') in ['DSRC Calgary', 'DSRC Edmonton'] ? '#cacaca' : ''  }}; border: {{ company.description|default('') in ['DSRC Calgary', 'DSRC Edmonton'] ? 'none' : 'none'  }}; font-size:12px; padding: 5px; text-align: center;"><strong>Payment</strong></td>
            <td style="background-color: {{ company.description|default('') in ['DSRC Calgary', 'DSRC Edmonton'] ? '#cacaca' : ''  }}; border: {{ company.description|default('') in ['DSRC Calgary', 'DSRC Edmonton'] ? 'none' : 'none'  }}; font-size:12px; padding: 5px; text-align: right;"><strong>Amount</strong></td>
        </tr>
        </thead>
        <tbody>
        {% 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="text-align: left; font-size: 12px;">{{ payDate }}</td>
                <td style="text-align: center; font-size: 12px;">{{ payType }}</td>
                <td style="text-align: right; font-size: 12px;">{{ amount|number_format(2, '.', ',') }}</td>
            </tr>
        {% endfor %}
        <tr>
            <td style="height: 30px;"></td>
        </tr>
        <tr>
            <td colspan="2" style="text-align: right;">Total:</td>
            {#<td style="text-align: right; border-top: 1px solid #000000;">{{ patientBilling.patientBillingRefunds|length > 0 or isReturn == 1 ? (patientBilling.amountDue + totalReturnAmt - patientBilling.amountRefunded|default(0))|number_format(2, '.', ',') : patientBilling.amountDue|number_format(2, '.', ',') }}</td>#}
            <td style="text-align: right; border-top: 1px solid #000000;">{{ patientBilling.invoiceAmountDue|number_format(2, '.', ',') }}</td>
        </tr>
        <tr>
            <td style="height: 20px;"></td>
        </tr>
        <tr>
            <td colspan="2" style="text-align: right;">Payment Made:</td>
            <td style="text-align: right;">{{ patientBilling.amountPaid|number_format(2, '.', ',') }}</td>
        </tr>
        <tr>
            {% if constant('RxconnexionBundle\\Entity\\PatientBillingEntity::PAYER_TYPE_FINANCING') == patientBilling.payerType %}
                <td colspan="2" style="text-align: right;">Balance Due:</td>
            {% else %}
                <td colspan="2" style="text-align: right;">Balance Due:</td>
            {% endif %}

            {#<td style="text-align: right; border-top: 1px solid #000000; font-weight: 600; font-size: 18px;">{{ patientBilling.patientBillingRefunds|length > 0 or isReturn == 1 ? (patientBilling.amountBalance + totalReturnAmt - patientBilling.amountRefunded|default(0))|number_format(2, '.', ',') : patientBilling.amountBalance|number_format(2, '.', ',') }}</td>#}
            <td style="text-align: right; border-top: 1px solid #000000; font-weight: 600; font-size: 18px;">{{ patientBilling.invoiceAmountBalance|number_format(2, '.', ',') }}</td>
        </tr>
        </tbody>
    </table>

    <div style="width:50%; height: 155px; float:left;">
        <br>
        <p>{{ patientBilling.note }}</p>
        <!--  <h5>ALL SALES ARE FINAL</h5> -->
    </div>
</div>
</body>
</html>
