{% set patient = patientPayment.patient %}
{% set patientBilling = patientPayment.patientBilling %}
<!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>Payment No. {{ patientPayment.paymentNoParsed }}</title>
</head>
<body style="font-family:'Arial'; font-size:15px;">
<div style="width: 816px; height: 1056px; box-sizing:border-box; padding:80px; margin: 0 auto; box-shadow:3px 1px 10px 1px; margin-top:25px;">
    {% set branch = patientPayment.patientBilling.healthFacilityForAddress|default('') %}
    {% set company = patientPayment.patientBilling.healthFacilityForAddress.company|default('') %}
    {% set street = patientPayment.patientBilling.healthFacilityForAddress.street|default('') %}
    {% set city = patientPayment.patientBilling.healthFacilityForAddress.city.desciption|default('') %}
    {% set postalCode = patientPayment.patientBilling.healthFacilityForAddress.postalCode.desciption|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_payment_receipt_print', {id: patientPayment.idEncoded}) }}">Download</a>
        </div>
    {% endif %}
    <div style="width:100%; height: 150px; position: relative;">
        {% if patientBilling.payerType != 'Financing' %}
        <div style="width: 60%; height: 100%; float: left; text-align: left;">
            <img src="{{ app.request.getSchemeAndHttpHost() ~ company.photoWebPath|default('') }}" style="width: 40%;"/>
            <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>
        </div>
        <div style="width: 40%; height: 100%; float: right; text-align: right;">
            <h2 style="margin:0; margin-bottom:20px;">PAYMENT RECEIPT</h2>
            <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;">{{ patientPayment.payDateAsString }}</td>
                </tr>
                <tr>
                    <td style="padding-right: 30px; text-align: left;">REFERENCE #:</td>
                    <td style="text-align: center; border: 1px solid #000; padding: 0 5px;">{{ patientPayment.id }}</td>
                </tr>
            </table>
        </div>
    </div>
    <div style="width: 100%; margin-bottom: 10px; margin-top: 20px">
        <div style="background-color: #717171; padding:5px 15px; width: 50%; height: 20px; color:#fff;"><strong>RECEIVED FROM</strong></div>
        <p style="margin:0;">{{ patient.fullName }}</p>
        <!--  <p style="margin:0;">[Company Name Name]</p>
        <p style="margin:0;">[Street Address]</p>
        <p style="margin:0;">[City, State Zip]</p>
        <p style="margin:0;">[Phone]</p> -->
    </div>
     {% endif %}
     <div style="width: 100%;">
          <table width="100%" style="border-collapse: collapse;">
              <thead style="background-color: #717171; text-align: center; border: solid 1px #717171;">
                  <td style="padding: 5px; color:#fff;"><strong>INVOICE NO</strong></td>
                  <td style="padding: 5px; color:#fff;"><strong>INVOICE DATE</strong></td>
                  <td style="padding: 5px; color:#fff;"><strong>DUE DATE</strong></td>
                  <td style="padding: 5px; color:#fff;"><strong>ORIGINAL AMOUNT</strong></td>
                  <td style="padding: 5px; color:#fff;"><strong>BALANCE</strong></td>
                  <td style="padding: 5px; color:#fff;"><strong>PAYMENT</strong></td>
              </thead>
              <tbody style="border:1px solid #717171;">
                  <tr>
                    <td>{{ patientBilling.invoiceNo }}</td>
                      <td style="padding: 5px;">{{ patientBilling.billingDateAsString }}</td>
                      <td style="padding: 5px;">{{ patientBilling.dueDateAsString }}</td>
                      <td style="text-align: right; padding: 5px;">{{ patientPayment.billDueAmount|number_format(2, '.', ',') }}</td>
                      <td style="text-align: right; padding: 5px;">{{ patientPayment.billBalAmount|number_format(2, '.', ',') }}</td>
                      <td style="text-align: right; padding: 5px;">{{ patientPayment.amount|number_format(2, '.', ',') }}</td>
                  </tr>
              </tbody>
          </table>
         <h4 style="margin-bottom: 0">Breakdown</h4>
         <table style="width:100%; border-collapse: collapse;">
             <thead style="background-color: #717171; border: solid 1px #717171;">
             <tr style="border-bottom: 1px dashed #676767;">
                 <td style="padding: 5px; color:#fff;">Item</td>
                 <td style="text-align: right; padding: 5px; color:#fff;">Qty</td>
                 {#<td style="text-align: right; padding: 5px; color:#fff;">Balance</td>#}
                 <td style="text-align: right; padding: 5px; color:#fff;">Amount</td>
             </tr>
             </thead>
             <tbody style="border:1px solid #717171;">
                {% for ppb in patientPayment.patientPaymentBreakdowns if ppb.amount > 0 %}
                 {% set pbb = ppb.patientBillingBreakdown %}
                 {% set isReturn = pbb.status == constant('RxconnexionBundle\\Entity\\PatientBillingBreakdownEntity::STATUS_RETURN') ? true : false %}
                 {% if pbb.type == constant('RxconnexionBundle\\Entity\\PatientBillingBreakdownEntity::TYPE_CHART_PROCEDURE') %}
                     {% set item = pbb.patientChart.idAndChartDateAndChartType|default('') %}
                 {% elseif pbb.type == constant('RxconnexionBundle\\Entity\\PatientBillingBreakdownEntity::TYPE_ITEM') %}
                     {% set item = pbb.item.description|default('') %}
                 {% elseif pbb.type == constant('RxconnexionBundle\\Entity\\PatientBillingBreakdownEntity::TYPE_OTHER') %}
                     {% set item = pbb.description %}
                 {% else %}
                     {% set item = '' %}
                 {% endif %}
                 <tr {{ isReturn == true ? 'style="text-decoration: line-through;cursor:help;color:#666" title="This Invoice Item is returned" ' }} >
                     <td style="padding: 5px;">{{ item }}</td>
                     <td style="text-align: right; padding: 5px;">{{ pbb.quantity }}</td>
                     {# TODO: DO NOT ALLOW NEGATIVE BALANCE IN FLUSH OF REFUND #}
                     {#<td style="text-align: right; padding: 5px;">{{ (pbb.amountBalance < 0 ? 0 : pbb.amountBalance)|number_format(2, '.', ',') }}</td>#}
                     <td style="text-align: right; padding: 5px;">{{ ppb.amount|number_format(2, '.', ',') }}</td>
                 </tr>
             {% endfor %}
             </tbody>
         </table>
    </div>
    <div style="width: 100%; margin-top:20px;">
        <div style="width: 40%; float: left;">
            <div style="width: 100%; height: 100px; padding:15px;">
                <h5>Payment : {{ patientPayment.payTypeForPrint }}</h5>
                <h5>All Sales are Final</h5>
            </div>
        </div>
        <div style="width: 60%; float: right; text-align: right;">
            <table style="width:100%;">
                {#<tr>
                    <td>Amount Credited:</td>
                    <td style="text-align: right;">0.00</td>
                </tr>#}
                <tr>
                    <td><h2><strong>TOTAL</strong></h2></td>
                    <td style="text-align: right;"><h2><strong>{{ patientPayment.amount|number_format(2, '.', ',') }}</strong></h2></td>
                </tr>
            </table>
        </div>
    </div>
</div>
</body>
</html>